From: bangerth Date: Wed, 25 Oct 2006 01:58:27 +0000 (+0000) Subject: Various cleanups. In particular static initialization of the map at the beginning... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84d74e138f7a939c05f0de1254777ccfb2eda73f;p=dealii-svn.git Various cleanups. In particular static initialization of the map at the beginning of the program. git-svn-id: https://svn.dealii.org/trunk@14082 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/fe/fe_q.cc b/deal.II/deal.II/source/fe/fe_q.cc index ceb3474d86..fc284daade 100644 --- a/deal.II/deal.II/source/fe/fe_q.cc +++ b/deal.II/deal.II/source/fe/fe_q.cc @@ -1243,7 +1243,7 @@ FE_Q::initialize_embedding () // value is somewhat // fuzzy, but it works // for - // 1e-14*degree*dim, + // 1e-14*(degree^dim)*dim, // which is kind of // reasonable given // that we compute the @@ -1257,15 +1257,15 @@ FE_Q::initialize_embedding () // growth in // degree*dim, times a // small constant. - if (std::fabs(cell_value) < 2e-14*this->degree*dim) + if (std::fabs(cell_value) < 2e-14*std::pow(1.*this->degree,dim)*dim) cell_interpolation(j, i) = 0.; else cell_interpolation(j, i) = cell_value; - if (std::fabs(subcell_value) < 2e-14*this->degree*dim) + if (std::fabs(subcell_value) < 2e-14*std::pow(1.*this->degree,dim)*dim) subcell_interpolation(j, i) = 0.; else - if (std::fabs(subcell_value-1) < 2e-14*this->degree*dim) + if (std::fabs(subcell_value-1) < 2e-14*std::pow(1.*this->degree,dim)*dim) subcell_interpolation(j, i) = 1.; else // we have put our @@ -1317,7 +1317,7 @@ FE_Q::initialize_embedding () double sum = 0; for (unsigned int col=0; coldofs_per_cell; ++col) sum += this->prolongation[child](row,col); - Assert (std::fabs(sum-1.) < 2e-14*this->degree*dim, + Assert (std::fabs(sum-1.) < 2e-14*std::pow(1.*this->degree,dim)*dim, ExcInternalError()); } } diff --git a/deal.II/deal.II/source/fe/fe_tools.cc b/deal.II/deal.II/source/fe/fe_tools.cc index e85980f887..82aefc0b5b 100644 --- a/deal.II/deal.II/source/fe/fe_tools.cc +++ b/deal.II/deal.II/source/fe/fe_tools.cc @@ -50,19 +50,75 @@ DEAL_II_NAMESPACE_OPEN namespace { -// have a lock that guarantees that at most one thread is changing and -// accessing the fe_name_map variable. make this lock local to this file. + // a function that returns the + // default set of finite element + // names and factory objects for + // them. used to initialize + // fe_name_map below + std::map * > + get_default_fe_names () + { + std::map * > + default_map; + + default_map["FE_Q_Hierarchical"] + = new FETools::FEFactory >; + default_map["FE_ABF"] + = new FETools::FEFactory >; + default_map["FE_RaviartThomas"] + = new FETools::FEFactory >; + default_map["FE_RaviartThomasNodal"] + = new FETools::FEFactory >; + default_map["FE_Nedelec"] + = new FETools::FEFactory >; + default_map["FE_DGPNonparametric"] + = new FETools::FEFactory >; + default_map["FE_DGP"] + = new FETools::FEFactory >; + default_map["FE_DGPMonomial"] + = new FETools::FEFactory >; + default_map["FE_DGQ"] + = new FETools::FEFactory >; + default_map["FE_Q"] + = new FETools::FEFactory >; + + return default_map; + } + + + + // have a lock that guarantees that + // at most one thread is changing + // and accessing the fe_name_map + // variable. make this lock local + // to this file. Threads::ThreadMutex fe_name_map_lock; -// This is the map used by FETools::get_fe_from_name and -// FETools::add_fe_name. Since FEFactoryBase has a template parameter -// dim, it could not be a member variable of FETools. On the other -// hand, it is only accessed by functions in this file, so it is safe -// to make it a static variable here. It must be static so that we can -// link several dimensions together. + // This is the map used by + // FETools::get_fe_from_name and + // FETools::add_fe_name. Since + // FEFactoryBase has a template + // parameter dim, it could not be a + // member variable of FETools. On + // the other hand, it is only + // accessed by functions in this + // file, so it is safe to make it a + // static variable here. It must be + // static so that we can link + // several dimensions together. + // + // it is initialized at program + // start time using the function + // above. because at this time + // there are no threads running, + // there are no thread-safety + // issues here std::map > > - fe_name_map; + const FETools::FEFactoryBase * > + fe_name_map + = get_default_fe_names (); } @@ -1424,7 +1480,7 @@ FETools::add_fe_name(const std::string& parameter_name, // Insert the normalized name into // the map - fe_name_map.insert(std::make_pair(name, boost::shared_ptr >(factory))); + fe_name_map[name] = factory; } @@ -1432,37 +1488,6 @@ template FiniteElement * FETools::get_fe_from_name (const std::string ¶meter_name) { - // First, make sure that the - // standard map from names to - // element factories has been - // filled by checking for one of - // the elements. -//TODO: Make this threadsafe - if (fe_name_map.find(std::string("FE_Q_Hierarchical")) - == fe_name_map.end()) - { - add_fe_name (std::string("FE_Q_Hierarchical"), - new FEFactory >()); - add_fe_name (std::string("FE_ABF"), - new FEFactory >()); - add_fe_name (std::string("FE_RaviartThomas"), - new FEFactory >()); - add_fe_name (std::string("FE_RaviartThomasNodal"), - new FEFactory >()); - add_fe_name (std::string("FE_Nedelec"), - new FEFactory >()); - add_fe_name (std::string("FE_DGPNonparametric"), - new FEFactory >()); - add_fe_name (std::string("FE_DGP"), - new FEFactory >()); - add_fe_name (std::string("FE_DGPMonomial"), - new FEFactory >()); - add_fe_name (std::string("FE_DGQ"), - new FEFactory >()); - add_fe_name (std::string("FE_Q<2>(4)"), - new FEFactory >()); - } - // Create a version of the name // string where all template // parameters are eliminated. @@ -1484,8 +1509,9 @@ FETools::get_fe_from_name (const std::string ¶meter_name) if (name.at(pos1+1) != 'd') Assert (name.at(pos1+1) == dimchar, ExcInvalidFEName(name)); - } else - Assert(pos2-pos1 == 4, ExcInvalidFEName(name)); + } + else + Assert(pos2-pos1 == 4, ExcInvalidFEName(name)); // If pos1==pos2, then we are // probably at the end of the @@ -1499,34 +1525,34 @@ FETools::get_fe_from_name (const std::string ¶meter_name) for (unsigned int pos = name.find("^dim"); pos < name.size(); pos = name.find("^dim")) - { - name.erase(pos+2, 2); - } + name.erase(pos+2, 2); // Replace all occurences of "^d" // by using the actual dimension for (unsigned int pos = name.find("^d"); pos < name.size(); pos = name.find("^d")) - { - name.at(pos+1) = '0' + dim; - } - FiniteElement* fe; + name.at(pos+1) = '0' + dim; + try { - fe = get_fe_from_name_aux (name); + FiniteElement *fe = get_fe_from_name_aux (name); + + // Make sure the auxiliary function + // ate up all characters of the name. + AssertThrow (name.size() == 0, + ExcInvalidFEName(parameter_name + + std::string(" extra characters after " + "end of name"))); + return fe; } - catch (std::string errline) + catch (const std::string &errline) { AssertThrow(false, ExcInvalidFEName(parameter_name + std::string(" at ") + errline)); + return 0; } - // Make sure the auxiliary function - // ate up all characters of the name. - AssertThrow (name.size() == 0, ExcInvalidFEName(parameter_name - + std::string(" extra characters after end of name"))); - return fe; } @@ -1708,8 +1734,8 @@ FETools::get_fe_from_name_aux (std::string &name) // is just adding an element Threads::ThreadMutex::ScopedLock lock (fe_name_map_lock); - typename std::map > >::const_iterator + typename std::map*> + ::const_iterator entry = fe_name_map.find(name_part); AssertThrow (entry != fe_name_map.end(), ExcInvalidFEName(name)); // Now, just the (degree)