Salome HOME
Implementation of MEDCoupling1SGTUMesh.computeTriangleHeight and DataArrayDouble...
[tools/medcoupling.git] / src / INTERP_KERNEL / CellModel.cxx
index 96b97b2f50b0f13c54c2afddbfef70c8d9b059a5..0ded2eb3b81224f257ca7a801ca60081096f70ee 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -43,14 +43,11 @@ namespace INTERP_KERNEL
                                             "", "", "", "", "",//35->39
                                             "NORM_ERROR"};
 
-  std::map<NormalizedCellType,CellModel> CellModel::_map_of_unique_instance;
-
   const CellModel& CellModel::GetCellModel(NormalizedCellType type)
   {
-    if(_map_of_unique_instance.empty())
-      buildUniqueInstance();
-    const std::map<NormalizedCellType,CellModel>::iterator iter=_map_of_unique_instance.find(type);
-    if(iter==_map_of_unique_instance.end())
+    const std::map<NormalizedCellType,CellModel>& map_unique = GetMapOfUniqueInstance();
+    const std::map<NormalizedCellType,CellModel>::const_iterator iter=map_unique.find(type);
+    if(iter==map_unique.end())
       {
         std::ostringstream stream; stream << "no cellmodel for normalized type " << type;
         throw Exception(stream.str().c_str());
@@ -58,6 +55,14 @@ namespace INTERP_KERNEL
     return (*iter).second;
   }
 
+  const std::map<NormalizedCellType,CellModel>& CellModel::GetMapOfUniqueInstance()
+  {
+    static std::map<NormalizedCellType,CellModel> map_of_unique_instance;
+    if(map_of_unique_instance.empty())
+      BuildUniqueInstance(map_of_unique_instance);
+    return map_of_unique_instance;
+  }
+
   const char *CellModel::getRepr() const
   {
     return CELL_TYPES_REPR[(int)_type];
@@ -82,34 +87,34 @@ namespace INTERP_KERNEL
     return b1 || b2;
   }
 
-  void CellModel::buildUniqueInstance()
+  void CellModel::BuildUniqueInstance(std::map<NormalizedCellType,CellModel>& map_unique)
   {
-    _map_of_unique_instance.insert(std::make_pair(NORM_POINT1,CellModel(NORM_POINT1)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_SEG2,CellModel(NORM_SEG2)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_SEG3,CellModel(NORM_SEG3)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_SEG4,CellModel(NORM_SEG4)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TRI3,CellModel(NORM_TRI3)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_QUAD4,CellModel(NORM_QUAD4)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TRI6,CellModel(NORM_TRI6)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TRI7,CellModel(NORM_TRI7)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_QUAD8,CellModel(NORM_QUAD8)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_QUAD9,CellModel(NORM_QUAD9)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TETRA4,CellModel(NORM_TETRA4)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_HEXA8,CellModel(NORM_HEXA8)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PYRA5,CellModel(NORM_PYRA5)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PENTA6,CellModel(NORM_PENTA6)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TETRA10,CellModel(NORM_TETRA10)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_HEXGP12,CellModel(NORM_HEXGP12)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PYRA13,CellModel(NORM_PYRA13)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PENTA15,CellModel(NORM_PENTA15)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PENTA18,CellModel(NORM_PENTA18)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_HEXA20,CellModel(NORM_HEXA20)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_HEXA27,CellModel(NORM_HEXA27)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_POLYGON,CellModel(NORM_POLYGON)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_POLYHED,CellModel(NORM_POLYHED)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_QPOLYG,CellModel(NORM_QPOLYG)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_POLYL,CellModel(NORM_POLYL)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_ERROR,CellModel(NORM_ERROR)));
+    map_unique.insert(std::make_pair(NORM_POINT1,CellModel(NORM_POINT1)));
+    map_unique.insert(std::make_pair(NORM_SEG2,CellModel(NORM_SEG2)));
+    map_unique.insert(std::make_pair(NORM_SEG3,CellModel(NORM_SEG3)));
+    map_unique.insert(std::make_pair(NORM_SEG4,CellModel(NORM_SEG4)));
+    map_unique.insert(std::make_pair(NORM_TRI3,CellModel(NORM_TRI3)));
+    map_unique.insert(std::make_pair(NORM_QUAD4,CellModel(NORM_QUAD4)));
+    map_unique.insert(std::make_pair(NORM_TRI6,CellModel(NORM_TRI6)));
+    map_unique.insert(std::make_pair(NORM_TRI7,CellModel(NORM_TRI7)));
+    map_unique.insert(std::make_pair(NORM_QUAD8,CellModel(NORM_QUAD8)));
+    map_unique.insert(std::make_pair(NORM_QUAD9,CellModel(NORM_QUAD9)));
+    map_unique.insert(std::make_pair(NORM_TETRA4,CellModel(NORM_TETRA4)));
+    map_unique.insert(std::make_pair(NORM_HEXA8,CellModel(NORM_HEXA8)));
+    map_unique.insert(std::make_pair(NORM_PYRA5,CellModel(NORM_PYRA5)));
+    map_unique.insert(std::make_pair(NORM_PENTA6,CellModel(NORM_PENTA6)));
+    map_unique.insert(std::make_pair(NORM_TETRA10,CellModel(NORM_TETRA10)));
+    map_unique.insert(std::make_pair(NORM_HEXGP12,CellModel(NORM_HEXGP12)));
+    map_unique.insert(std::make_pair(NORM_PYRA13,CellModel(NORM_PYRA13)));
+    map_unique.insert(std::make_pair(NORM_PENTA15,CellModel(NORM_PENTA15)));
+    map_unique.insert(std::make_pair(NORM_PENTA18,CellModel(NORM_PENTA18)));
+    map_unique.insert(std::make_pair(NORM_HEXA20,CellModel(NORM_HEXA20)));
+    map_unique.insert(std::make_pair(NORM_HEXA27,CellModel(NORM_HEXA27)));
+    map_unique.insert(std::make_pair(NORM_POLYGON,CellModel(NORM_POLYGON)));
+    map_unique.insert(std::make_pair(NORM_POLYHED,CellModel(NORM_POLYHED)));
+    map_unique.insert(std::make_pair(NORM_QPOLYG,CellModel(NORM_QPOLYG)));
+    map_unique.insert(std::make_pair(NORM_POLYL,CellModel(NORM_POLYL)));
+    map_unique.insert(std::make_pair(NORM_ERROR,CellModel(NORM_ERROR)));
   }
 
   CellModel::CellModel(NormalizedCellType type):_type(type)
@@ -413,7 +418,7 @@ namespace INTERP_KERNEL
           _sons_type[0]=NORM_QUAD9; _sons_type[1]=NORM_QUAD9; _sons_type[2]=NORM_QUAD9; _sons_type[3]=NORM_QUAD9; _sons_type[4]=NORM_QUAD9; _sons_type[5]=NORM_QUAD9;
           _sons_con[0][0]=0; _sons_con[0][1]=1; _sons_con[0][2]=2; _sons_con[0][3]=3; _sons_con[0][4]=8; _sons_con[0][5]=9; _sons_con[0][6]=10; _sons_con[0][7]=11; _sons_con[0][8]=20; _nb_of_sons_con[0]=9;
           _sons_con[1][0]=4; _sons_con[1][1]=7; _sons_con[1][2]=6; _sons_con[1][3]=5; _sons_con[1][4]=15; _sons_con[1][5]=14; _sons_con[1][6]=13; _sons_con[1][7]=12; _sons_con[1][8]=25; _nb_of_sons_con[1]=9;
-          _sons_con[2][0]=0; _sons_con[2][1]=4; _sons_con[2][2]=5; _sons_con[2][3]=1; _sons_con[2][4]=16; _sons_con[2][5]=12; _sons_con[2][6]=17; _sons_con[2][7]=8; _sons_con[2][8]=21; _nb_of_sons_con[2]=9;   
+          _sons_con[2][0]=0; _sons_con[2][1]=4; _sons_con[2][2]=5; _sons_con[2][3]=1; _sons_con[2][4]=16; _sons_con[2][5]=12; _sons_con[2][6]=17; _sons_con[2][7]=8; _sons_con[2][8]=21; _nb_of_sons_con[2]=9;
           _sons_con[3][0]=1; _sons_con[3][1]=5; _sons_con[3][2]=6; _sons_con[3][3]=2; _sons_con[3][4]=17; _sons_con[3][5]=13; _sons_con[3][6]=18; _sons_con[3][7]=9; _sons_con[3][8]=22; _nb_of_sons_con[3]=9;
           _sons_con[4][0]=2; _sons_con[4][1]=6; _sons_con[4][2]=7; _sons_con[4][3]=3; _sons_con[4][4]=18; _sons_con[4][5]=14; _sons_con[4][6]=19; _sons_con[4][7]=10; _sons_con[4][8]=23; _nb_of_sons_con[4]=9;
           _sons_con[5][0]=3; _sons_con[5][1]=7; _sons_con[5][2]=4; _sons_con[5][3]=0; _sons_con[5][4]=19; _sons_con[5][5]=15; _sons_con[5][6]=16; _sons_con[5][7]=11; _sons_con[5][8]=24; _nb_of_sons_con[5]=9;
@@ -475,7 +480,7 @@ namespace INTERP_KERNEL
     else//polyhedron
       return FromIdType<unsigned>(lgth-ToIdType(std::count(conn,conn+lgth,-1)/2));
   }
-  
+
   /*!
    * \sa fillMicroEdgeNodalConnectivity
    */
@@ -497,7 +502,7 @@ namespace INTERP_KERNEL
     else
       throw INTERP_KERNEL::Exception("CellModel::getNumberOfMacroEdges : not supported by dynamic type !");
   }
-  
+
   NormalizedCellType CellModel::getCorrespondingPolyType() const
   {
     switch(getDimension())
@@ -599,7 +604,7 @@ namespace INTERP_KERNEL
           throw INTERP_KERNEL::Exception("CellModel::fillSonCellNodalConnectivity2 : no sons on NORM_POLYL !");
       }
   }
-  
+
   /*!
    * Equivalent to CellModel::fillSonCellNodalConnectivity2 except for HEXA8 where the order of sub faces is not has MED file numbering for transformation HEXA8->HEXA27
    */
@@ -635,7 +640,7 @@ namespace INTERP_KERNEL
           }
       }
     else
-      throw INTERP_KERNEL::Exception("CellModel::fillSonEdgesNodalConnectivity3D : not implemented yet for NORM_POLYHED !");   
+      throw INTERP_KERNEL::Exception("CellModel::fillSonEdgesNodalConnectivity3D : not implemented yet for NORM_POLYHED !");
   }
 
   /*!
@@ -826,7 +831,7 @@ namespace INTERP_KERNEL
           }
       }
   }
-  
+
   DiameterCalculator *CellModel::buildInstanceOfDiameterCalulator(int spaceDim) const
   {
     switch(_type)