1 // Copyright (C) 2007-2012 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.
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
20 #include "MEDCouplingUMeshDesc.hxx"
21 #include "CellModel.hxx"
22 #include "MEDCouplingMemArray.hxx"
27 using namespace ParaMEDMEM;
29 MEDCouplingUMeshDesc::MEDCouplingUMeshDesc():_mesh_dim(-2),_desc_connec(0),_desc_connec_index(0),
30 _nodal_connec_face(0),_nodal_connec_face_index(0)
34 MEDCouplingUMeshDesc::~MEDCouplingUMeshDesc()
37 _desc_connec->decrRef();
38 if(_desc_connec_index)
39 _desc_connec_index->decrRef();
40 if(_nodal_connec_face)
41 _nodal_connec_face->decrRef();
42 if(_nodal_connec_face_index)
43 _nodal_connec_face_index->decrRef();
46 MEDCouplingUMeshDesc *MEDCouplingUMeshDesc::New()
48 return new MEDCouplingUMeshDesc;
51 MEDCouplingUMeshDesc *MEDCouplingUMeshDesc::New(const char *meshName, int meshDim)
53 MEDCouplingUMeshDesc *ret=new MEDCouplingUMeshDesc;
54 ret->setName(meshName);
55 ret->setMeshDimension(meshDim);
59 MEDCouplingMesh *MEDCouplingUMeshDesc::deepCpy() const
61 throw INTERP_KERNEL::Exception("Not implemented yet !");
65 void MEDCouplingUMeshDesc::checkCoherency() const throw(INTERP_KERNEL::Exception)
67 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator iter=_types.begin();iter!=_types.end();iter++)
69 if((int)INTERP_KERNEL::CellModel::GetCellModel(*iter).getDimension()!=_mesh_dim)
71 std::ostringstream message;
72 message << "MeshDesc invalid because dimension is " << _mesh_dim << " and there is presence of cell(s) with type " << (*iter);
73 throw INTERP_KERNEL::Exception(message.str().c_str());
78 void MEDCouplingUMeshDesc::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
83 void MEDCouplingUMeshDesc::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
88 void MEDCouplingUMeshDesc::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
89 DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception)
91 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::checkDeepEquivalWith : not implemented yet !");
94 void MEDCouplingUMeshDesc::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
95 DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception)
97 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::checkDeepEquivalOnSameNodesWith : not implemented yet !");
100 void MEDCouplingUMeshDesc::setMeshDimension(unsigned meshDim)
106 int MEDCouplingUMeshDesc::getNumberOfCells() const
108 if(_desc_connec_index)
109 return _desc_connec_index->getNumberOfTuples()-1;
111 throw INTERP_KERNEL::Exception("Unable to get number of cells because no connectivity specified !");
114 int MEDCouplingUMeshDesc::getNumberOfFaces() const
116 if(_nodal_connec_face_index)
117 return _nodal_connec_face_index->getNumberOfTuples()-1;
119 throw INTERP_KERNEL::Exception("Unable to get number of faces because no connectivity specified !");
122 int MEDCouplingUMeshDesc::getCellMeshLength() const
124 return _desc_connec->getNbOfElems();
127 int MEDCouplingUMeshDesc::getFaceMeshLength() const
129 return _nodal_connec_face->getNbOfElems();
132 INTERP_KERNEL::NormalizedCellType MEDCouplingUMeshDesc::getTypeOfCell(int cellId) const
134 const int *desc_connec=_desc_connec->getConstPointer();
135 const int *desc_connec_index=_desc_connec_index->getConstPointer();
136 return (INTERP_KERNEL::NormalizedCellType)desc_connec[desc_connec_index[cellId]+1];
139 std::set<INTERP_KERNEL::NormalizedCellType> MEDCouplingUMeshDesc::getAllGeoTypes() const
144 int MEDCouplingUMeshDesc::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
146 const int *desc_connec=_desc_connec->getConstPointer();
147 const int *desc_connec_index=_desc_connec_index->getConstPointer();
148 int nbOfCells=getNumberOfCells();
150 for(int i=0;i<nbOfCells;i++)
151 if((INTERP_KERNEL::NormalizedCellType) desc_connec[desc_connec_index[i]]==type)
156 void MEDCouplingUMeshDesc::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
158 throw INTERP_KERNEL::Exception("Not implemented yet !");
161 std::string MEDCouplingUMeshDesc::simpleRepr() const
163 std::string ret("Unstructured mesh with descending connectivity : ");
169 std::string MEDCouplingUMeshDesc::advancedRepr() const
171 std::string ret("Unstructured mesh with descending connectivity : ");
177 void MEDCouplingUMeshDesc::setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx)
179 DataArrayInt::SetArrayIn(descConn,_desc_connec);
180 DataArrayInt::SetArrayIn(descConnIndex,_desc_connec_index);
181 DataArrayInt::SetArrayIn(nodalFaceConn,_nodal_connec_face);
182 DataArrayInt::SetArrayIn(nodalFaceConnIndx,_nodal_connec_face_index);
186 std::vector<int> MEDCouplingUMeshDesc::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
188 throw INTERP_KERNEL::Exception("Not implemented yet !");
191 DataArrayInt *MEDCouplingUMeshDesc::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
193 throw INTERP_KERNEL::Exception("Not implemented yet !");
196 void MEDCouplingUMeshDesc::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
198 throw INTERP_KERNEL::Exception("Not implemented yet !");
201 void MEDCouplingUMeshDesc::getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
203 MEDCouplingPointSet::getTinySerializationInformation(tinyInfoD,tinyInfo,littleStrings);
204 tinyInfo.push_back(getMeshDimension());
205 tinyInfo.push_back(getNumberOfNodes());
206 tinyInfo.push_back(getNumberOfCells());
207 tinyInfo.push_back(getCellMeshLength());
208 tinyInfo.push_back(getNumberOfFaces());
209 tinyInfo.push_back(getFaceMeshLength());
212 bool MEDCouplingUMeshDesc::isEmptyMesh(const std::vector<int>& tinyInfo) const
214 return tinyInfo[5]<=0;
217 void MEDCouplingUMeshDesc::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const
219 std::vector<int> tinyInfoTmp(tinyInfo.begin()+1,tinyInfo.end());
220 MEDCouplingPointSet::resizeForUnserialization(tinyInfoTmp,a1,a2,littleStrings);
221 a1->alloc(tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7]+tinyInfo[6]+1,1);
224 void MEDCouplingUMeshDesc::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const
226 MEDCouplingPointSet::serialize(a1,a2);
228 a1=DataArrayInt::New();
229 a1->alloc(getCellMeshLength()+getNumberOfCells()+1+getFaceMeshLength()+getNumberOfFaces()+1,1);
230 int *ptA1=a1->getPointer();
231 const int *descConn=_desc_connec->getConstPointer();
232 const int *descConnIndex=_desc_connec_index->getConstPointer();
233 const int *faceConn=_nodal_connec_face->getConstPointer();
234 const int *faceConnIndex=_nodal_connec_face_index->getConstPointer();
235 ptA1=std::copy(descConn,descConn+getCellMeshLength(),ptA1);
236 ptA1=std::copy(descConnIndex,descConnIndex+getNumberOfCells()+1,ptA1);
237 ptA1=std::copy(faceConn,faceConn+getFaceMeshLength(),ptA1);
238 std::copy(faceConnIndex,faceConnIndex+getNumberOfFaces()+1,ptA1);
241 void MEDCouplingUMeshDesc::unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& littleStrings)
243 std::vector<int> tinyInfoTmp(tinyInfo.begin()+1,tinyInfo.end());
244 MEDCouplingPointSet::unserialization(tinyInfoD,tinyInfoTmp,a1,a2,littleStrings);
246 const int *recvBuffer=a1->getConstPointer();
247 DataArrayInt *descConn=DataArrayInt::New();
248 descConn->alloc(tinyInfo[5],1);
249 std::copy(recvBuffer,recvBuffer+tinyInfo[5],descConn->getPointer());
250 DataArrayInt *descConnIndex=DataArrayInt::New();
251 descConnIndex->alloc(tinyInfo[4]+1,1);
252 std::copy(recvBuffer+tinyInfo[5],recvBuffer+tinyInfo[5]+tinyInfo[4]+1,descConnIndex->getPointer());
253 DataArrayInt *faceConn=DataArrayInt::New();
254 faceConn->alloc(tinyInfo[7],1);
255 std::copy(recvBuffer+tinyInfo[5]+tinyInfo[4]+1,recvBuffer+tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7],faceConn->getPointer());
256 DataArrayInt *faceConnIndex=DataArrayInt::New();
257 faceConnIndex->alloc(tinyInfo[6]+1,1);
258 std::copy(recvBuffer+tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7],
259 recvBuffer+tinyInfo[5]+tinyInfo[5]+1+tinyInfo[7]+tinyInfo[6]+1,faceConnIndex->getPointer());
260 setConnectivity(descConn,descConnIndex,faceConn,faceConnIndex);
262 descConnIndex->decrRef();
264 faceConnIndex->decrRef();
265 setMeshDimension(tinyInfo[2]);
268 void MEDCouplingUMeshDesc::getCellsInBoundingBox(const double *bbox, double eps, std::vector<int>& elems) const
270 int dim=getSpaceDimension();
271 double* elem_bb=new double[2*dim];
272 const int* conn = _desc_connec->getConstPointer();
273 const int* conn_index= _desc_connec_index->getConstPointer();
274 const int* face = _nodal_connec_face->getConstPointer();
275 const int* face_index= _nodal_connec_face_index->getConstPointer();
276 const double* coords = getCoords()->getConstPointer();
277 int nbOfCells=getNumberOfCells();
278 for ( int ielem=0; ielem<nbOfCells;ielem++ )
280 for (int i=0; i<dim; i++)
282 elem_bb[i*2]=std::numeric_limits<double>::max();
283 elem_bb[i*2+1]=-std::numeric_limits<double>::max();
286 for (int jface=conn_index[ielem]+1; jface<conn_index[ielem+1]; jface++)//+1 due to offset of cell type.
288 int iface=conn[jface];
289 for(int inode=face_index[iface]+1;inode<face_index[iface+1];inode++)
291 int node=face[inode];
292 for (int idim=0; idim<dim; idim++)
294 if ( coords[node*dim+idim] < elem_bb[idim*2] )
296 elem_bb[idim*2] = coords[node*dim+idim] ;
298 if ( coords[node*dim+idim] > elem_bb[idim*2+1] )
300 elem_bb[idim*2+1] = coords[node*dim+idim] ;
305 if (intersectsBoundingBox(elem_bb, bbox, dim, eps))
307 elems.push_back(ielem);
313 void MEDCouplingUMeshDesc::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox &bbox, double eps, std::vector<int>& elems)
315 int dim=getSpaceDimension();
316 double* elem_bb=new double[2*dim];
317 const int* conn = _desc_connec->getConstPointer();
318 const int* conn_index= _desc_connec_index->getConstPointer();
319 const int* face = _nodal_connec_face->getConstPointer();
320 const int* face_index= _nodal_connec_face_index->getConstPointer();
321 const double* coords = getCoords()->getConstPointer();
322 int nbOfCells=getNumberOfCells();
323 for ( int ielem=0; ielem<nbOfCells;ielem++ )
325 for (int i=0; i<dim; i++)
327 elem_bb[i*2]=std::numeric_limits<double>::max();
328 elem_bb[i*2+1]=-std::numeric_limits<double>::max();
331 for (int jface=conn_index[ielem]+1; jface<conn_index[ielem+1]; jface++)//+1 due to offset of cell type.
333 int iface=conn[jface];
334 for(int inode=face_index[iface]+1;inode<face_index[iface+1];inode++)
336 int node=face[inode];
337 for (int idim=0; idim<dim; idim++)
339 if ( coords[node*dim+idim] < elem_bb[idim*2] )
341 elem_bb[idim*2] = coords[node*dim+idim] ;
343 if ( coords[node*dim+idim] > elem_bb[idim*2+1] )
345 elem_bb[idim*2+1] = coords[node*dim+idim] ;
350 if (intersectsBoundingBox(bbox, elem_bb, dim, eps))
352 elems.push_back(ielem);
358 DataArrayInt *MEDCouplingUMeshDesc::mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes)
360 throw INTERP_KERNEL::Exception("Not implemented yet !");
361 areNodesMerged=false;
365 DataArrayInt *MEDCouplingUMeshDesc::mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes)
367 throw INTERP_KERNEL::Exception("Not implemented yet !");
368 areNodesMerged=false;
372 void MEDCouplingUMeshDesc::tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception)
374 throw INTERP_KERNEL::Exception("Not implemented yet !");
377 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelf2(int start, int end, int step, bool keepCoords) const throw(INTERP_KERNEL::Exception)
379 throw INTERP_KERNEL::Exception("Not implemented yet !");
383 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const
385 throw INTERP_KERNEL::Exception("Not implemented yet !");
389 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
391 throw INTERP_KERNEL::Exception("Not implemented yet !");
395 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
397 throw INTERP_KERNEL::Exception("Not implemented yet !");
401 DataArrayInt *MEDCouplingUMeshDesc::simplexize(int policy) throw(INTERP_KERNEL::Exception)
403 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::simplexize : Not implemented yet !");
406 DataArrayInt *MEDCouplingUMeshDesc::findBoundaryNodes() const
408 throw INTERP_KERNEL::Exception("Not implemented yet !");
411 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildBoundaryMesh(bool keepCoords) const
413 throw INTERP_KERNEL::Exception("Not implemented yet !");
417 MEDCouplingUMesh *MEDCouplingUMeshDesc::buildUnstructured() const throw(INTERP_KERNEL::Exception)
419 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::buildUnstructured : not implemented yet !");
422 void MEDCouplingUMeshDesc::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
424 throw INTERP_KERNEL::Exception("Available for UMesh desc but not implemented yet !");
427 void MEDCouplingUMeshDesc::renumberNodes(const int *newNodeNumbers, int newNbOfNodes)
429 MEDCouplingPointSet::renumberNodes(newNodeNumbers,newNbOfNodes);
430 throw INTERP_KERNEL::Exception("Not implemented yet !");
433 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::getMeasureField(bool isAbs) const
435 throw INTERP_KERNEL::Exception("Not implemented yet !");
439 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::getMeasureFieldOnNode(bool isAbs) const
441 throw INTERP_KERNEL::Exception("Not implemented yet !");
445 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::buildOrthogonalField() const
447 if(getMeshDimension()!=2)
448 throw INTERP_KERNEL::Exception("Expected a cmesh with meshDim == 2 !");
449 throw INTERP_KERNEL::Exception("Not implemented yet !");
453 DataArrayInt *MEDCouplingUMeshDesc::zipCoordsTraducer()
455 throw INTERP_KERNEL::Exception("Not implemented yet !");
459 void MEDCouplingUMeshDesc::computeTypes()
461 if(_desc_connec && _desc_connec_index)
464 const int *conn=_desc_connec->getConstPointer();
465 const int *connIndex=_desc_connec_index->getConstPointer();
466 int nbOfElem=_desc_connec_index->getNbOfElems()-1;
467 for(const int *pt=connIndex;pt!=connIndex+nbOfElem;pt++)
468 _types.insert((INTERP_KERNEL::NormalizedCellType)conn[*pt]);
472 void MEDCouplingUMeshDesc::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
474 if(!_desc_connec || !_desc_connec_index || !_nodal_connec_face || !_nodal_connec_face_index || !_coords)
475 throw INTERP_KERNEL::Exception("full connectivity and coordinates not set in unstructured mesh.");
478 MEDCouplingMesh *MEDCouplingUMeshDesc::mergeMyselfWith(const MEDCouplingMesh *other) const
480 throw INTERP_KERNEL::Exception("Not implemented yet !");
484 DataArrayDouble *MEDCouplingUMeshDesc::getBarycenterAndOwner() const
486 throw INTERP_KERNEL::Exception("Not implemented yet !");
490 int MEDCouplingUMeshDesc::getCellContainingPoint(const double *pos, double eps) const
492 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getCellContainingPoint : not implemented yet !");
495 void MEDCouplingUMeshDesc::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception)
497 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::writeVTKLL : not implemented yet !");
500 std::string MEDCouplingUMeshDesc::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
502 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getVTKDataSetType : not implemented yet !");