-// Copyright (C) 2007-2016 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
#include <vector>
#include <limits>
+unsigned char MEDCOUPLING2VTKTYPETRADUCER[INTERP_KERNEL::NORM_MAXTYPE+1]={1,3,21,5,9,7,22,34,23,28,35,MEDCOUPLING2VTKTYPETRADUCER_NONE,MEDCOUPLING2VTKTYPETRADUCER_NONE,MEDCOUPLING2VTKTYPETRADUCER_NONE,10,14,13,MEDCOUPLING2VTKTYPETRADUCER_NONE,12,MEDCOUPLING2VTKTYPETRADUCER_NONE,24,MEDCOUPLING2VTKTYPETRADUCER_NONE,16,27,MEDCOUPLING2VTKTYPETRADUCER_NONE,26,MEDCOUPLING2VTKTYPETRADUCER_NONE,29,32,MEDCOUPLING2VTKTYPETRADUCER_NONE,25,42,36,4};
+
namespace INTERP_KERNEL
{
const char *CellModel::CELL_TYPES_REPR[]={"NORM_POINT1", "NORM_SEG2", "NORM_SEG3", "NORM_TRI3", "NORM_QUAD4",// 0->4
"", "", "", "", "",//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());
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];
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)
_sons_con[1][0]=3; _sons_con[1][1]=5; _sons_con[1][2]=4; _sons_con[1][3]=11; _sons_con[1][4]=10; _sons_con[1][5]=9; _nb_of_sons_con[1]=6;
_sons_con[2][0]=0; _sons_con[2][1]=3; _sons_con[2][2]=4; _sons_con[2][3]=1; _sons_con[2][4]=12; _sons_con[2][5]=9; _sons_con[2][6]=13; _sons_con[2][7]=6; _nb_of_sons_con[2]=8;
_sons_con[3][0]=1; _sons_con[3][1]=4; _sons_con[3][2]=5; _sons_con[3][3]=2; _sons_con[3][4]=13; _sons_con[3][5]=10; _sons_con[3][6]=14; _sons_con[3][7]=7; _nb_of_sons_con[3]=8;
- _sons_con[4][0]=2; _sons_con[4][1]=4; _sons_con[4][2]=5; _sons_con[4][3]=0; _sons_con[4][4]=14; _sons_con[4][5]=11; _sons_con[4][6]=12; _sons_con[4][7]=8; _nb_of_sons_con[4]=8; _quadratic=true;
+ _sons_con[4][0]=2; _sons_con[4][1]=5; _sons_con[4][2]=3; _sons_con[4][3]=0; _sons_con[4][4]=14; _sons_con[4][5]=11; _sons_con[4][6]=12; _sons_con[4][7]=8; _nb_of_sons_con[4]=8; _quadratic=true;
_little_sons_con[0][0]=0; _little_sons_con[0][1]=1; _little_sons_con[0][2]=6; _nb_of_little_sons=9;
_little_sons_con[1][0]=1; _little_sons_con[1][1]=2; _little_sons_con[1][2]=7;
_little_sons_con[2][0]=2; _little_sons_con[2][1]=0; _little_sons_con[2][2]=8;
_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;
/*!
* Equivalent to getNumberOfSons except that this method deals with dynamic type.
*/
- unsigned CellModel::getNumberOfSons2(const int *conn, int lgth) const
+ unsigned CellModel::getNumberOfSons2(const mcIdType *conn, mcIdType lgth) const
{
if(!isDynamic())
return getNumberOfSons();
if(_dim==2)
{
if(_type==NORM_POLYGON)
- return lgth;
+ return FromIdType<unsigned>(lgth);
else
- return lgth/2;
+ return FromIdType<unsigned>(lgth/2);
}
else if(_dim==1)
- return lgth;//NORM_POLYL
+ return FromIdType<unsigned>(lgth);//NORM_POLYL
else
- return std::count(conn,conn+lgth,-1)+1;
+ return (unsigned)std::count(conn,conn+lgth,-1)+1;
}
- unsigned CellModel::getNumberOfEdgesIn3D(const int *conn, int lgth) const
+ unsigned CellModel::getNumberOfEdgesIn3D(const mcIdType *conn, mcIdType lgth) const
{
if(!isDynamic())
return _nb_of_little_sons;
else//polyhedron
- return (lgth-std::count(conn,conn+lgth,-1))/2;
+ return FromIdType<unsigned>(lgth-ToIdType(std::count(conn,conn+lgth,-1)/2));
}
-
+
/*!
* \sa fillMicroEdgeNodalConnectivity
*/
else
throw INTERP_KERNEL::Exception("CellModel::getNumberOfMacroEdges : not supported by dynamic type !");
}
-
+
NormalizedCellType CellModel::getCorrespondingPolyType() const
{
switch(getDimension())
/*!
* \b WARNING this method do not manage correctly types that return true at the call of isDynamic. Use fillSonCellNodalConnectivity2 instead.
*/
- unsigned CellModel::fillSonCellNodalConnectivity(int sonId, const int *nodalConn, int *sonNodalConn) const
+ unsigned CellModel::fillSonCellNodalConnectivity(int sonId, const mcIdType *nodalConn, mcIdType *sonNodalConn) const
{
unsigned nbOfTurnLoop=_nb_of_sons_con[sonId];
const unsigned *sonConn=_sons_con[sonId];
return nbOfTurnLoop;
}
- unsigned CellModel::fillSonCellNodalConnectivity2(int sonId, const int *nodalConn, int lgth, int *sonNodalConn, NormalizedCellType& typeOfSon) const
+ unsigned CellModel::fillSonCellNodalConnectivity2(int sonId, const mcIdType *nodalConn, mcIdType lgth, mcIdType *sonNodalConn, NormalizedCellType& typeOfSon) const
{
typeOfSon=getSonType2(sonId);
if(!isDynamic())
sonNodalConn[1]=nodalConn[(sonId+1)%lgth];
return 2;
}
- else
+ else // NORM_QPOLYG
{
sonNodalConn[0]=nodalConn[sonId];
sonNodalConn[1]=nodalConn[(sonId+1)%(lgth/2)];
}
else if(_dim==3)
{//polyedron
- const int *where=nodalConn;
+ const mcIdType *where=nodalConn;
for(int i=0;i<sonId;i++)
{
where=std::find(where,nodalConn+lgth,-1);
where++;
}
- const int *where2=std::find(where,nodalConn+lgth,-1);
+ const mcIdType *where2=std::find(where,nodalConn+lgth,-1);
std::copy(where,where2,sonNodalConn);
- return where2-where;
+ return (unsigned)(where2-where);
}
else
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
*/
- unsigned CellModel::fillSonCellNodalConnectivity4(int sonId, const int *nodalConn, int lgth, int *sonNodalConn, NormalizedCellType& typeOfSon) const
+ unsigned CellModel::fillSonCellNodalConnectivity4(int sonId, const mcIdType *nodalConn, mcIdType lgth, mcIdType *sonNodalConn, NormalizedCellType& typeOfSon) const
{
if(_type==NORM_HEXA8)
{
return fillSonCellNodalConnectivity2(sonId,nodalConn,lgth,sonNodalConn,typeOfSon);
}
- unsigned CellModel::fillSonEdgesNodalConnectivity3D(int sonId, const int *nodalConn, int lgth, int *sonNodalConn, NormalizedCellType& typeOfSon) const
+ unsigned CellModel::fillSonEdgesNodalConnectivity3D(int sonId, const mcIdType *nodalConn, mcIdType lgth, mcIdType *sonNodalConn, NormalizedCellType& typeOfSon) const
{
if(!isDynamic())
{
}
}
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 !");
}
/*!
* \sa getNumberOfMicroEdges
*/
- unsigned CellModel::fillMicroEdgeNodalConnectivity(int sonId, const int *nodalConn, int *sonNodalConn, NormalizedCellType& typeOfSon) const
+ unsigned CellModel::fillMicroEdgeNodalConnectivity(int sonId, const mcIdType *nodalConn, mcIdType *sonNodalConn, NormalizedCellType& typeOfSon) const
{
if(isQuadratic())
{
}
}
- void CellModel::changeOrientationOf2D(int *nodalConn, unsigned int sz) const
+ void CellModel::changeOrientationOf2D(mcIdType *nodalConn, unsigned int sz) const
{
if(sz<1)
return ;
if(!isQuadratic())
{
- std::vector<int> tmp(sz-1);
+ std::vector<mcIdType> tmp(sz-1);
std::copy(nodalConn+1,nodalConn+sz,tmp.rbegin());
std::copy(tmp.begin(),tmp.end(),nodalConn+1);
}
else
{
unsigned int sz2(sz/2);
- std::vector<int> tmp0(sz2-1),tmp1(sz2);
+ std::vector<mcIdType> tmp0(sz2-1),tmp1(sz2);
std::copy(nodalConn+1,nodalConn+sz2,tmp0.rbegin());
std::copy(nodalConn+sz2,nodalConn+sz,tmp1.rbegin());
std::copy(tmp0.begin(),tmp0.end(),nodalConn+1);
}
}
- void CellModel::changeOrientationOf1D(int *nodalConn, unsigned int sz) const
+ void CellModel::changeOrientationOf1D(mcIdType *nodalConn, unsigned int sz) const
{
if(!isDynamic())
{
}
else
{
- std::vector<int> tmp(sz-1);
+ std::vector<mcIdType> tmp(sz-1);
std::copy(nodalConn+1,nodalConn+sz,tmp.rbegin());
std::copy(tmp.begin(),tmp.end(),nodalConn+1);
}
*/
//================================================================================
- unsigned CellModel::getNumberOfNodesConstituentTheSon2(unsigned sonId, const int *nodalConn, int lgth) const
+ unsigned CellModel::getNumberOfNodesConstituentTheSon2(unsigned sonId, const mcIdType *nodalConn, mcIdType lgth) const
{
if(!isDynamic())
return getNumberOfNodesConstituentTheSon(sonId);
}
else if(_dim==3)
{//polyedron
- const int *where=nodalConn;
+ const mcIdType *where=nodalConn;
for(unsigned int i=0;i<sonId;i++)
{
where=std::find(where,nodalConn+lgth,-1);
where++;
}
- const int *where2=std::find(where,nodalConn+lgth,-1);
- return where2-where;
+ const mcIdType *where2=std::find(where,nodalConn+lgth,-1);
+ return (unsigned)(where2-where);
}
else
throw INTERP_KERNEL::Exception("CellModel::getNumberOfNodesConstituentTheSon2 : no sons on NORM_POLYL !");
* If not an exception will be thrown.
* @return True if two cells have same orientation, false if not.
*/
- bool CellModel::getOrientationStatus(unsigned lgth, const int *conn1, const int *conn2) const
+ bool CellModel::getOrientationStatus(mcIdType lgth, const mcIdType *conn1, const mcIdType *conn2) const
{
if(_dim!=1 && _dim!=2)
throw INTERP_KERNEL::Exception("CellModel::getOrientationStatus : invalid dimension ! Must be 1 or 2 !");
if(!_quadratic)
{
- std::vector<int> tmp(2*lgth);
- std::vector<int>::iterator it=std::copy(conn1,conn1+lgth,tmp.begin());
+ std::vector<mcIdType> tmp(2*lgth);
+ std::vector<mcIdType>::iterator it=std::copy(conn1,conn1+lgth,tmp.begin());
std::copy(conn1,conn1+lgth,it);
it=std::search(tmp.begin(),tmp.end(),conn2,conn2+lgth);
if(it==tmp.begin())
return true;
if(it!=tmp.end())
return _dim!=1;
- std::vector<int>::reverse_iterator it2=std::search(tmp.rbegin(),tmp.rend(),conn2,conn2+lgth);
+ std::vector<mcIdType>::reverse_iterator it2=std::search(tmp.rbegin(),tmp.rend(),conn2,conn2+lgth);
if(it2!=tmp.rend())
return false;
throw INTERP_KERNEL::Exception("CellModel::getOrientationStatus : Request of orientation status of non equal connectively cells !");
{
if(_dim!=1)
{
- std::vector<int> tmp(lgth);
- std::vector<int>::iterator it=std::copy(conn1,conn1+lgth/2,tmp.begin());
+ std::vector<mcIdType> tmp(lgth);
+ std::vector<mcIdType>::iterator it=std::copy(conn1,conn1+lgth/2,tmp.begin());
std::copy(conn1,conn1+lgth/2,it);
it=std::search(tmp.begin(),tmp.end(),conn2,conn2+lgth/2);
- int d=std::distance(tmp.begin(),it);
+ std::size_t d=std::distance(tmp.begin(),it);
if(it==tmp.end())
return false;
it=std::copy(conn1+lgth/2,conn1+lgth,tmp.begin());
it=std::search(tmp.begin(),tmp.end(),conn2,conn2+lgth);
if(it==tmp.end())
return false;
- int d2=std::distance(tmp.begin(),it);
+ std::size_t d2=std::distance(tmp.begin(),it);
return d==d2;
}
else
{
- int p=(lgth+1)/2;
- std::vector<int> tmp(2*p);
- std::vector<int>::iterator it=std::copy(conn1,conn1+p,tmp.begin());
+ mcIdType p=(lgth+1)/2;
+ std::vector<mcIdType> tmp(2*p);
+ std::vector<mcIdType>::iterator it=std::copy(conn1,conn1+p,tmp.begin());
std::copy(conn1,conn1+p,it);
it=std::search(tmp.begin(),tmp.end(),conn2,conn2+p);
- int d=std::distance(tmp.begin(),it);
+ std::size_t d=std::distance(tmp.begin(),it);
if(it==tmp.end())
return false;
tmp.resize(2*p-2);
it=std::search(tmp.begin(),tmp.end(),conn2+p,conn2+lgth);
if(it==tmp.end())
return false;
- int d2=std::distance(tmp.begin(),it);
+ std::size_t d2=std::distance(tmp.begin(),it);
return d==d2;
}
}
}
-
+
DiameterCalculator *CellModel::buildInstanceOfDiameterCalulator(int spaceDim) const
{
switch(_type)