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
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDCouplingUMeshDesc.hxx"
22 #include "CellModel.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
29 using namespace ParaMEDMEM;
31 MEDCouplingUMeshDesc::MEDCouplingUMeshDesc():_mesh_dim(-2),_desc_connec(0),_desc_connec_index(0),
32 _nodal_connec_face(0),_nodal_connec_face_index(0)
36 MEDCouplingUMeshDesc::~MEDCouplingUMeshDesc()
39 _desc_connec->decrRef();
40 if(_desc_connec_index)
41 _desc_connec_index->decrRef();
42 if(_nodal_connec_face)
43 _nodal_connec_face->decrRef();
44 if(_nodal_connec_face_index)
45 _nodal_connec_face_index->decrRef();
48 MEDCouplingUMeshDesc *MEDCouplingUMeshDesc::New()
50 return new MEDCouplingUMeshDesc;
53 MEDCouplingUMeshDesc *MEDCouplingUMeshDesc::New(const char *meshName, int meshDim)
55 MEDCouplingUMeshDesc *ret=new MEDCouplingUMeshDesc;
56 ret->setName(meshName);
57 ret->setMeshDimension(meshDim);
61 std::size_t MEDCouplingUMeshDesc::getHeapMemorySize() const
65 ret+=_desc_connec->getHeapMemorySize();
66 if(_desc_connec_index)
67 ret+=_desc_connec_index->getHeapMemorySize();
68 if(_nodal_connec_face)
69 ret+=_nodal_connec_face->getHeapMemorySize();
70 if(_nodal_connec_face_index)
71 ret+=_nodal_connec_face_index->getHeapMemorySize();
72 return MEDCouplingPointSet::getHeapMemorySize()+ret;
76 MEDCouplingMesh *MEDCouplingUMeshDesc::deepCpy() const
78 throw INTERP_KERNEL::Exception("Not implemented yet !");
82 void MEDCouplingUMeshDesc::checkCoherency() const throw(INTERP_KERNEL::Exception)
84 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator iter=_types.begin();iter!=_types.end();iter++)
86 if((int)INTERP_KERNEL::CellModel::GetCellModel(*iter).getDimension()!=_mesh_dim)
88 std::ostringstream message;
89 message << "MeshDesc invalid because dimension is " << _mesh_dim << " and there is presence of cell(s) with type " << (*iter);
90 throw INTERP_KERNEL::Exception(message.str().c_str());
95 void MEDCouplingUMeshDesc::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
100 void MEDCouplingUMeshDesc::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
102 checkCoherency1(eps);
105 void MEDCouplingUMeshDesc::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
106 DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception)
108 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::checkDeepEquivalWith : not implemented yet !");
111 void MEDCouplingUMeshDesc::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
112 DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception)
114 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::checkDeepEquivalOnSameNodesWith : not implemented yet !");
117 void MEDCouplingUMeshDesc::setMeshDimension(unsigned meshDim)
123 int MEDCouplingUMeshDesc::getNumberOfCells() const
125 if(_desc_connec_index)
126 return _desc_connec_index->getNumberOfTuples()-1;
128 throw INTERP_KERNEL::Exception("Unable to get number of cells because no connectivity specified !");
131 int MEDCouplingUMeshDesc::getNumberOfFaces() const
133 if(_nodal_connec_face_index)
134 return _nodal_connec_face_index->getNumberOfTuples()-1;
136 throw INTERP_KERNEL::Exception("Unable to get number of faces because no connectivity specified !");
139 int MEDCouplingUMeshDesc::getCellMeshLength() const
141 return _desc_connec->getNbOfElems();
144 int MEDCouplingUMeshDesc::getFaceMeshLength() const
146 return _nodal_connec_face->getNbOfElems();
149 INTERP_KERNEL::NormalizedCellType MEDCouplingUMeshDesc::getTypeOfCell(int cellId) const
151 const int *desc_connec=_desc_connec->getConstPointer();
152 const int *desc_connec_index=_desc_connec_index->getConstPointer();
153 return (INTERP_KERNEL::NormalizedCellType)desc_connec[desc_connec_index[cellId]+1];
156 std::set<INTERP_KERNEL::NormalizedCellType> MEDCouplingUMeshDesc::getAllGeoTypes() const
161 DataArrayInt *MEDCouplingUMeshDesc::giveCellsWithType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception)
163 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::giveCellsWithType : not implemented yet !");
166 DataArrayInt *MEDCouplingUMeshDesc::computeNbOfNodesPerCell() const throw(INTERP_KERNEL::Exception)
168 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::computeNbOfNodesPerCell : not implemented yet !");
171 int MEDCouplingUMeshDesc::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
173 const int *desc_connec=_desc_connec->getConstPointer();
174 const int *desc_connec_index=_desc_connec_index->getConstPointer();
175 int nbOfCells=getNumberOfCells();
177 for(int i=0;i<nbOfCells;i++)
178 if((INTERP_KERNEL::NormalizedCellType) desc_connec[desc_connec_index[i]]==type)
183 void MEDCouplingUMeshDesc::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
185 throw INTERP_KERNEL::Exception("Not implemented yet !");
188 std::string MEDCouplingUMeshDesc::simpleRepr() const
190 std::string ret("Unstructured mesh with descending connectivity : ");
196 std::string MEDCouplingUMeshDesc::advancedRepr() const
198 std::string ret("Unstructured mesh with descending connectivity : ");
204 void MEDCouplingUMeshDesc::setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx)
206 DataArrayInt::SetArrayIn(descConn,_desc_connec);
207 DataArrayInt::SetArrayIn(descConnIndex,_desc_connec_index);
208 DataArrayInt::SetArrayIn(nodalFaceConn,_nodal_connec_face);
209 DataArrayInt::SetArrayIn(nodalFaceConnIndx,_nodal_connec_face_index);
213 std::vector<int> MEDCouplingUMeshDesc::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
215 throw INTERP_KERNEL::Exception("Not implemented yet !");
218 DataArrayInt *MEDCouplingUMeshDesc::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
220 throw INTERP_KERNEL::Exception("Not implemented yet !");
223 void MEDCouplingUMeshDesc::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
225 throw INTERP_KERNEL::Exception("Not implemented yet !");
228 void MEDCouplingUMeshDesc::getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
230 MEDCouplingPointSet::getTinySerializationInformation(tinyInfoD,tinyInfo,littleStrings);
231 tinyInfo.push_back(getMeshDimension());
232 tinyInfo.push_back(getNumberOfNodes());
233 tinyInfo.push_back(getNumberOfCells());
234 tinyInfo.push_back(getCellMeshLength());
235 tinyInfo.push_back(getNumberOfFaces());
236 tinyInfo.push_back(getFaceMeshLength());
239 bool MEDCouplingUMeshDesc::isEmptyMesh(const std::vector<int>& tinyInfo) const
241 return tinyInfo[5]<=0;
244 void MEDCouplingUMeshDesc::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const
246 std::vector<int> tinyInfoTmp(tinyInfo.begin()+1,tinyInfo.end());
247 MEDCouplingPointSet::resizeForUnserialization(tinyInfoTmp,a1,a2,littleStrings);
248 a1->alloc(tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7]+tinyInfo[6]+1,1);
251 void MEDCouplingUMeshDesc::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const
253 MEDCouplingPointSet::serialize(a1,a2);
255 a1=DataArrayInt::New();
256 a1->alloc(getCellMeshLength()+getNumberOfCells()+1+getFaceMeshLength()+getNumberOfFaces()+1,1);
257 int *ptA1=a1->getPointer();
258 const int *descConn=_desc_connec->getConstPointer();
259 const int *descConnIndex=_desc_connec_index->getConstPointer();
260 const int *faceConn=_nodal_connec_face->getConstPointer();
261 const int *faceConnIndex=_nodal_connec_face_index->getConstPointer();
262 ptA1=std::copy(descConn,descConn+getCellMeshLength(),ptA1);
263 ptA1=std::copy(descConnIndex,descConnIndex+getNumberOfCells()+1,ptA1);
264 ptA1=std::copy(faceConn,faceConn+getFaceMeshLength(),ptA1);
265 std::copy(faceConnIndex,faceConnIndex+getNumberOfFaces()+1,ptA1);
268 void MEDCouplingUMeshDesc::unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& littleStrings)
270 std::vector<int> tinyInfoTmp(tinyInfo.begin()+1,tinyInfo.end());
271 MEDCouplingPointSet::unserialization(tinyInfoD,tinyInfoTmp,a1,a2,littleStrings);
273 const int *recvBuffer=a1->getConstPointer();
274 DataArrayInt *descConn=DataArrayInt::New();
275 descConn->alloc(tinyInfo[5],1);
276 std::copy(recvBuffer,recvBuffer+tinyInfo[5],descConn->getPointer());
277 DataArrayInt *descConnIndex=DataArrayInt::New();
278 descConnIndex->alloc(tinyInfo[4]+1,1);
279 std::copy(recvBuffer+tinyInfo[5],recvBuffer+tinyInfo[5]+tinyInfo[4]+1,descConnIndex->getPointer());
280 DataArrayInt *faceConn=DataArrayInt::New();
281 faceConn->alloc(tinyInfo[7],1);
282 std::copy(recvBuffer+tinyInfo[5]+tinyInfo[4]+1,recvBuffer+tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7],faceConn->getPointer());
283 DataArrayInt *faceConnIndex=DataArrayInt::New();
284 faceConnIndex->alloc(tinyInfo[6]+1,1);
285 std::copy(recvBuffer+tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7],
286 recvBuffer+tinyInfo[5]+tinyInfo[5]+1+tinyInfo[7]+tinyInfo[6]+1,faceConnIndex->getPointer());
287 setConnectivity(descConn,descConnIndex,faceConn,faceConnIndex);
289 descConnIndex->decrRef();
291 faceConnIndex->decrRef();
292 setMeshDimension(tinyInfo[2]);
295 DataArrayInt *MEDCouplingUMeshDesc::getCellsInBoundingBox(const double *bbox, double eps) const
297 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elems=DataArrayInt::New(); elems->alloc(0,1);
298 int dim=getSpaceDimension();
299 double* elem_bb=new double[2*dim];
300 const int* conn = _desc_connec->getConstPointer();
301 const int* conn_index= _desc_connec_index->getConstPointer();
302 const int* face = _nodal_connec_face->getConstPointer();
303 const int* face_index= _nodal_connec_face_index->getConstPointer();
304 const double* coords = getCoords()->getConstPointer();
305 int nbOfCells=getNumberOfCells();
306 for ( int ielem=0; ielem<nbOfCells;ielem++ )
308 for (int i=0; i<dim; i++)
310 elem_bb[i*2]=std::numeric_limits<double>::max();
311 elem_bb[i*2+1]=-std::numeric_limits<double>::max();
314 for (int jface=conn_index[ielem]+1; jface<conn_index[ielem+1]; jface++)//+1 due to offset of cell type.
316 int iface=conn[jface];
317 for(int inode=face_index[iface]+1;inode<face_index[iface+1];inode++)
319 int node=face[inode];
320 for (int idim=0; idim<dim; idim++)
322 if ( coords[node*dim+idim] < elem_bb[idim*2] )
324 elem_bb[idim*2] = coords[node*dim+idim] ;
326 if ( coords[node*dim+idim] > elem_bb[idim*2+1] )
328 elem_bb[idim*2+1] = coords[node*dim+idim] ;
333 if(intersectsBoundingBox(elem_bb, bbox, dim, eps))
334 elems->pushBackSilent(ielem);
340 DataArrayInt *MEDCouplingUMeshDesc::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox &bbox, double eps)
342 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elems=DataArrayInt::New(); elems->alloc(0,1);
343 int dim=getSpaceDimension();
344 double* elem_bb=new double[2*dim];
345 const int* conn = _desc_connec->getConstPointer();
346 const int* conn_index= _desc_connec_index->getConstPointer();
347 const int* face = _nodal_connec_face->getConstPointer();
348 const int* face_index= _nodal_connec_face_index->getConstPointer();
349 const double* coords = getCoords()->getConstPointer();
350 int nbOfCells=getNumberOfCells();
351 for ( int ielem=0; ielem<nbOfCells;ielem++ )
353 for (int i=0; i<dim; i++)
355 elem_bb[i*2]=std::numeric_limits<double>::max();
356 elem_bb[i*2+1]=-std::numeric_limits<double>::max();
359 for (int jface=conn_index[ielem]+1; jface<conn_index[ielem+1]; jface++)//+1 due to offset of cell type.
361 int iface=conn[jface];
362 for(int inode=face_index[iface]+1;inode<face_index[iface+1];inode++)
364 int node=face[inode];
365 for (int idim=0; idim<dim; idim++)
367 if ( coords[node*dim+idim] < elem_bb[idim*2] )
369 elem_bb[idim*2] = coords[node*dim+idim] ;
371 if ( coords[node*dim+idim] > elem_bb[idim*2+1] )
373 elem_bb[idim*2+1] = coords[node*dim+idim] ;
378 if (intersectsBoundingBox(bbox, elem_bb, dim, eps))
379 elems->pushBackSilent(ielem);
385 DataArrayInt *MEDCouplingUMeshDesc::mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes)
387 throw INTERP_KERNEL::Exception("Not implemented yet !");
388 areNodesMerged=false;
392 DataArrayInt *MEDCouplingUMeshDesc::mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes)
394 throw INTERP_KERNEL::Exception("Not implemented yet !");
395 areNodesMerged=false;
399 void MEDCouplingUMeshDesc::tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception)
401 throw INTERP_KERNEL::Exception("Not implemented yet !");
404 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelf2(int start, int end, int step, bool keepCoords) const throw(INTERP_KERNEL::Exception)
406 throw INTERP_KERNEL::Exception("Not implemented yet !");
410 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const
412 throw INTERP_KERNEL::Exception("Not implemented yet !");
416 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
418 throw INTERP_KERNEL::Exception("Not implemented yet !");
422 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
424 throw INTERP_KERNEL::Exception("Not implemented yet !");
428 DataArrayInt *MEDCouplingUMeshDesc::simplexize(int policy) throw(INTERP_KERNEL::Exception)
430 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::simplexize : Not implemented yet !");
433 DataArrayInt *MEDCouplingUMeshDesc::findBoundaryNodes() const
435 throw INTERP_KERNEL::Exception("Not implemented yet !");
438 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildBoundaryMesh(bool keepCoords) const
440 throw INTERP_KERNEL::Exception("Not implemented yet !");
444 MEDCouplingUMesh *MEDCouplingUMeshDesc::buildUnstructured() const throw(INTERP_KERNEL::Exception)
446 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::buildUnstructured : not implemented yet !");
449 void MEDCouplingUMeshDesc::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
451 throw INTERP_KERNEL::Exception("Available for UMesh desc but not implemented yet !");
454 void MEDCouplingUMeshDesc::renumberNodes(const int *newNodeNumbers, int newNbOfNodes)
456 MEDCouplingPointSet::renumberNodes(newNodeNumbers,newNbOfNodes);
457 throw INTERP_KERNEL::Exception("Not implemented yet !");
460 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::getMeasureField(bool isAbs) const
462 throw INTERP_KERNEL::Exception("Not implemented yet !");
466 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::getMeasureFieldOnNode(bool isAbs) const
468 throw INTERP_KERNEL::Exception("Not implemented yet !");
472 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::buildOrthogonalField() const
474 if(getMeshDimension()!=2)
475 throw INTERP_KERNEL::Exception("Expected a cmesh with meshDim == 2 !");
476 throw INTERP_KERNEL::Exception("Not implemented yet !");
480 DataArrayInt *MEDCouplingUMeshDesc::zipCoordsTraducer()
482 throw INTERP_KERNEL::Exception("Not implemented yet !");
486 void MEDCouplingUMeshDesc::computeTypes()
488 if(_desc_connec && _desc_connec_index)
491 const int *conn=_desc_connec->getConstPointer();
492 const int *connIndex=_desc_connec_index->getConstPointer();
493 int nbOfElem=_desc_connec_index->getNbOfElems()-1;
494 for(const int *pt=connIndex;pt!=connIndex+nbOfElem;pt++)
495 _types.insert((INTERP_KERNEL::NormalizedCellType)conn[*pt]);
499 void MEDCouplingUMeshDesc::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
501 if(!_desc_connec || !_desc_connec_index || !_nodal_connec_face || !_nodal_connec_face_index || !_coords)
502 throw INTERP_KERNEL::Exception("full connectivity and coordinates not set in unstructured mesh.");
505 MEDCouplingMesh *MEDCouplingUMeshDesc::mergeMyselfWith(const MEDCouplingMesh *other) const
507 throw INTERP_KERNEL::Exception("Not implemented yet !");
511 DataArrayDouble *MEDCouplingUMeshDesc::getBarycenterAndOwner() const
513 throw INTERP_KERNEL::Exception("Not implemented yet !");
517 int MEDCouplingUMeshDesc::getCellContainingPoint(const double *pos, double eps) const
519 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getCellContainingPoint : not implemented yet !");
522 void MEDCouplingUMeshDesc::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception)
524 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::writeVTKLL : not implemented yet !");
527 std::string MEDCouplingUMeshDesc::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
529 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getVTKDataSetType : not implemented yet !");