1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
22 #define __MEDCOUPLINGNORMALIZEDUNSTRUCTUREDMESH_TXX__
24 #include "MEDCouplingNormalizedUnstructuredMesh.hxx"
25 #include "InterpKernelAssert.hxx"
27 #include "MEDCouplingUMesh.hxx"
28 #include "MEDCoupling1GTUMesh.hxx"
29 #include "MEDCouplingMemArray.hxx"
33 template<int SPACEDIM,int MESHDIM>
34 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::MEDCouplingNormalizedUnstructuredMesh(const MEDCoupling::MEDCouplingPointSet *mesh):_mesh(mesh)
41 template<int SPACEDIM,int MESHDIM>
42 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getBoundingBox(double *boundingBox) const
44 for(int i=0;i<SPACEDIM;i++)
46 boundingBox[i]=std::numeric_limits<double>::max();
47 boundingBox[SPACEDIM+i]=-std::numeric_limits<double>::max();
49 const MEDCoupling::DataArrayDouble *array=_mesh->getCoords();
50 const double *ptr=array->getConstPointer();
51 mcIdType nbOfPts=ToIdType(array->getNbOfElems())/SPACEDIM;
52 for(int j=0;j<SPACEDIM;j++)
54 const double *work=ptr+j;
55 for(mcIdType i=0;i<nbOfPts;i++,work+=SPACEDIM)
57 if(boundingBox[j]>*work)
59 if(boundingBox[j+SPACEDIM]<*work)
60 boundingBox[j+SPACEDIM]=*work;
65 template<int SPACEDIM,int MESHDIM>
66 INTERP_KERNEL::NormalizedCellType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getTypeOfElement(mcIdType eltId) const
68 return _mesh->getTypeOfCell(eltId);
71 template<int SPACEDIM,int MESHDIM>
72 mcIdType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodesOfElement(mcIdType eltId) const
74 return _mesh->getNumberOfNodesInCell(eltId);
77 template<int SPACEDIM,int MESHDIM>
78 mcIdType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfElements() const
80 return ToIdType(_mesh->getNumberOfCells());
83 template<int SPACEDIM,int MESHDIM>
84 mcIdType MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getNumberOfNodes() const
86 return _mesh->getNumberOfNodes();
89 template<int SPACEDIM,int MESHDIM>
90 const mcIdType *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityPtr() const
92 return _conn_for_interp;
95 template<int SPACEDIM,int MESHDIM>
96 const double *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getCoordinatesPtr() const
98 const MEDCoupling::DataArrayDouble *array=_mesh->getCoords();
99 return array->getConstPointer();
102 template<int SPACEDIM,int MESHDIM>
103 const mcIdType *MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::getConnectivityIndexPtr() const
105 return _conn_index_for_interp;
108 template<int SPACEDIM,int MESHDIM>
109 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::releaseTempArrays()
111 delete [] _conn_for_interp;
112 delete [] _conn_index_for_interp;
114 _conn_index_for_interp=0;
117 template<int SPACEDIM,int MESHDIM>
118 MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::~MEDCouplingNormalizedUnstructuredMesh()
125 template<int SPACEDIM,int MESHDIM>
126 void MEDCouplingNormalizedUnstructuredMesh<SPACEDIM,MESHDIM>::prepare()
128 IKAssert(_mesh->getSpaceDimension()==SPACEDIM);
129 const MEDCoupling::MEDCouplingUMesh *m1(dynamic_cast<const MEDCoupling::MEDCouplingUMesh *>(_mesh));
132 mcIdType nbOfCell=ToIdType(m1->getNumberOfCells());
133 mcIdType initialConnSize=ToIdType(m1->getNodalConnectivity()->getNbOfElems());
134 _conn_for_interp=new mcIdType[initialConnSize-nbOfCell];
135 _conn_index_for_interp=new mcIdType[nbOfCell+1];
136 _conn_index_for_interp[0]=0;
137 const mcIdType *work_conn=m1->getNodalConnectivity()->getConstPointer()+1;
138 const mcIdType *work_conn_index=m1->getNodalConnectivityIndex()->getConstPointer();
139 mcIdType *work_conn_for_interp=_conn_for_interp;
140 mcIdType *work_conn_index_for_interp=_conn_index_for_interp;
141 for(mcIdType i=0;i<nbOfCell;i++)
143 mcIdType nbOfValsToCopy=work_conn_index[1]-work_conn_index[0]-1;
144 work_conn_for_interp=std::copy(work_conn,work_conn+nbOfValsToCopy,work_conn_for_interp);
145 work_conn_index_for_interp[1]=work_conn_index_for_interp[0]+nbOfValsToCopy;
147 work_conn+=nbOfValsToCopy+1;
148 work_conn_index_for_interp++;
152 const MEDCoupling::MEDCoupling1DGTUMesh *m2(dynamic_cast<const MEDCoupling::MEDCoupling1DGTUMesh *>(_mesh));
155 mcIdType nbOfCell=ToIdType(m2->getNumberOfCells());
156 _conn_index_for_interp=new mcIdType[nbOfCell+1];
157 const mcIdType *conni(m2->getNodalConnectivityIndex()->begin());
158 std::copy(conni,conni+nbOfCell+1,_conn_index_for_interp);
159 _conn_for_interp=new mcIdType[m2->getNodalConnectivity()->getNumberOfTuples()];
160 std::copy(m2->getNodalConnectivity()->begin(),m2->getNodalConnectivity()->end(),_conn_for_interp);
163 const MEDCoupling::MEDCoupling1SGTUMesh *m3(dynamic_cast<const MEDCoupling::MEDCoupling1SGTUMesh *>(_mesh));
166 mcIdType nbOfCell=ToIdType(m3->getNumberOfCells()),nbNodesPerCell(m3->getNumberOfNodesPerCell());
167 _conn_index_for_interp=new mcIdType[nbOfCell+1]; _conn_index_for_interp[0]=0;
168 mcIdType *work(_conn_index_for_interp);
169 for(mcIdType i=0;i<nbOfCell;i++,work++)
170 work[1]=work[0]+nbNodesPerCell;
171 _conn_for_interp=new mcIdType[m3->getNodalConnectivity()->getNumberOfTuples()];
172 std::copy(m3->getNodalConnectivity()->begin(),m3->getNodalConnectivity()->end(),_conn_for_interp);
175 throw INTERP_KERNEL::Exception("MEDCouplingNormalizedUnstructuredMesh::prepare : Unrecognized unstructured mesh ! Type must be in MEDCouplingUMesh, MEDCoupling1DGTUMesh, MEDCoupling1SGTUMesh !");