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"
28 using namespace ParaMEDMEM;
30 MEDCouplingUMeshDesc::MEDCouplingUMeshDesc():_mesh_dim(-2),_desc_connec(0),_desc_connec_index(0),
31 _nodal_connec_face(0),_nodal_connec_face_index(0)
35 MEDCouplingUMeshDesc::~MEDCouplingUMeshDesc()
38 _desc_connec->decrRef();
39 if(_desc_connec_index)
40 _desc_connec_index->decrRef();
41 if(_nodal_connec_face)
42 _nodal_connec_face->decrRef();
43 if(_nodal_connec_face_index)
44 _nodal_connec_face_index->decrRef();
47 MEDCouplingUMeshDesc *MEDCouplingUMeshDesc::New()
49 return new MEDCouplingUMeshDesc;
52 MEDCouplingUMeshDesc *MEDCouplingUMeshDesc::New(const char *meshName, int meshDim)
54 MEDCouplingUMeshDesc *ret=new MEDCouplingUMeshDesc;
55 ret->setName(meshName);
56 ret->setMeshDimension(meshDim);
60 MEDCouplingMesh *MEDCouplingUMeshDesc::deepCpy() const
62 throw INTERP_KERNEL::Exception("Not implemented yet !");
66 void MEDCouplingUMeshDesc::checkCoherency() const throw(INTERP_KERNEL::Exception)
68 for(std::set<INTERP_KERNEL::NormalizedCellType>::const_iterator iter=_types.begin();iter!=_types.end();iter++)
70 if((int)INTERP_KERNEL::CellModel::GetCellModel(*iter).getDimension()!=_mesh_dim)
72 std::ostringstream message;
73 message << "MeshDesc invalid because dimension is " << _mesh_dim << " and there is presence of cell(s) with type " << (*iter);
74 throw INTERP_KERNEL::Exception(message.str().c_str());
79 void MEDCouplingUMeshDesc::checkCoherency1(double eps) const throw(INTERP_KERNEL::Exception)
84 void MEDCouplingUMeshDesc::checkCoherency2(double eps) const throw(INTERP_KERNEL::Exception)
89 void MEDCouplingUMeshDesc::checkDeepEquivalWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
90 DataArrayInt *&cellCor, DataArrayInt *&nodeCor) const throw(INTERP_KERNEL::Exception)
92 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::checkDeepEquivalWith : not implemented yet !");
95 void MEDCouplingUMeshDesc::checkDeepEquivalOnSameNodesWith(const MEDCouplingMesh *other, int cellCompPol, double prec,
96 DataArrayInt *&cellCor) const throw(INTERP_KERNEL::Exception)
98 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::checkDeepEquivalOnSameNodesWith : not implemented yet !");
101 void MEDCouplingUMeshDesc::setMeshDimension(unsigned meshDim)
107 int MEDCouplingUMeshDesc::getNumberOfCells() const
109 if(_desc_connec_index)
110 return _desc_connec_index->getNumberOfTuples()-1;
112 throw INTERP_KERNEL::Exception("Unable to get number of cells because no connectivity specified !");
115 int MEDCouplingUMeshDesc::getNumberOfFaces() const
117 if(_nodal_connec_face_index)
118 return _nodal_connec_face_index->getNumberOfTuples()-1;
120 throw INTERP_KERNEL::Exception("Unable to get number of faces because no connectivity specified !");
123 int MEDCouplingUMeshDesc::getCellMeshLength() const
125 return _desc_connec->getNbOfElems();
128 int MEDCouplingUMeshDesc::getFaceMeshLength() const
130 return _nodal_connec_face->getNbOfElems();
133 INTERP_KERNEL::NormalizedCellType MEDCouplingUMeshDesc::getTypeOfCell(int cellId) const
135 const int *desc_connec=_desc_connec->getConstPointer();
136 const int *desc_connec_index=_desc_connec_index->getConstPointer();
137 return (INTERP_KERNEL::NormalizedCellType)desc_connec[desc_connec_index[cellId]+1];
140 std::set<INTERP_KERNEL::NormalizedCellType> MEDCouplingUMeshDesc::getAllGeoTypes() const
145 int MEDCouplingUMeshDesc::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType type) const
147 const int *desc_connec=_desc_connec->getConstPointer();
148 const int *desc_connec_index=_desc_connec_index->getConstPointer();
149 int nbOfCells=getNumberOfCells();
151 for(int i=0;i<nbOfCells;i++)
152 if((INTERP_KERNEL::NormalizedCellType) desc_connec[desc_connec_index[i]]==type)
157 void MEDCouplingUMeshDesc::getNodeIdsOfCell(int cellId, std::vector<int>& conn) const
159 throw INTERP_KERNEL::Exception("Not implemented yet !");
162 std::string MEDCouplingUMeshDesc::simpleRepr() const
164 std::string ret("Unstructured mesh with descending connectivity : ");
170 std::string MEDCouplingUMeshDesc::advancedRepr() const
172 std::string ret("Unstructured mesh with descending connectivity : ");
178 void MEDCouplingUMeshDesc::setConnectivity(DataArrayInt *descConn, DataArrayInt *descConnIndex, DataArrayInt *nodalFaceConn, DataArrayInt *nodalFaceConnIndx)
180 DataArrayInt::SetArrayIn(descConn,_desc_connec);
181 DataArrayInt::SetArrayIn(descConnIndex,_desc_connec_index);
182 DataArrayInt::SetArrayIn(nodalFaceConn,_nodal_connec_face);
183 DataArrayInt::SetArrayIn(nodalFaceConnIndx,_nodal_connec_face_index);
187 std::vector<int> MEDCouplingUMeshDesc::getDistributionOfTypes() const throw(INTERP_KERNEL::Exception)
189 throw INTERP_KERNEL::Exception("Not implemented yet !");
192 DataArrayInt *MEDCouplingUMeshDesc::checkTypeConsistencyAndContig(const std::vector<int>& code, const std::vector<const DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
194 throw INTERP_KERNEL::Exception("Not implemented yet !");
197 void MEDCouplingUMeshDesc::splitProfilePerType(const DataArrayInt *profile, std::vector<int>& code, std::vector<DataArrayInt *>& idsInPflPerType, std::vector<DataArrayInt *>& idsPerType) const throw(INTERP_KERNEL::Exception)
199 throw INTERP_KERNEL::Exception("Not implemented yet !");
202 void MEDCouplingUMeshDesc::getTinySerializationInformation(std::vector<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const
204 MEDCouplingPointSet::getTinySerializationInformation(tinyInfoD,tinyInfo,littleStrings);
205 tinyInfo.push_back(getMeshDimension());
206 tinyInfo.push_back(getNumberOfNodes());
207 tinyInfo.push_back(getNumberOfCells());
208 tinyInfo.push_back(getCellMeshLength());
209 tinyInfo.push_back(getNumberOfFaces());
210 tinyInfo.push_back(getFaceMeshLength());
213 bool MEDCouplingUMeshDesc::isEmptyMesh(const std::vector<int>& tinyInfo) const
215 return tinyInfo[5]<=0;
218 void MEDCouplingUMeshDesc::resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const
220 std::vector<int> tinyInfoTmp(tinyInfo.begin()+1,tinyInfo.end());
221 MEDCouplingPointSet::resizeForUnserialization(tinyInfoTmp,a1,a2,littleStrings);
222 a1->alloc(tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7]+tinyInfo[6]+1,1);
225 void MEDCouplingUMeshDesc::serialize(DataArrayInt *&a1, DataArrayDouble *&a2) const
227 MEDCouplingPointSet::serialize(a1,a2);
229 a1=DataArrayInt::New();
230 a1->alloc(getCellMeshLength()+getNumberOfCells()+1+getFaceMeshLength()+getNumberOfFaces()+1,1);
231 int *ptA1=a1->getPointer();
232 const int *descConn=_desc_connec->getConstPointer();
233 const int *descConnIndex=_desc_connec_index->getConstPointer();
234 const int *faceConn=_nodal_connec_face->getConstPointer();
235 const int *faceConnIndex=_nodal_connec_face_index->getConstPointer();
236 ptA1=std::copy(descConn,descConn+getCellMeshLength(),ptA1);
237 ptA1=std::copy(descConnIndex,descConnIndex+getNumberOfCells()+1,ptA1);
238 ptA1=std::copy(faceConn,faceConn+getFaceMeshLength(),ptA1);
239 std::copy(faceConnIndex,faceConnIndex+getNumberOfFaces()+1,ptA1);
242 void MEDCouplingUMeshDesc::unserialization(const std::vector<double>& tinyInfoD, const std::vector<int>& tinyInfo, const DataArrayInt *a1, DataArrayDouble *a2, const std::vector<std::string>& littleStrings)
244 std::vector<int> tinyInfoTmp(tinyInfo.begin()+1,tinyInfo.end());
245 MEDCouplingPointSet::unserialization(tinyInfoD,tinyInfoTmp,a1,a2,littleStrings);
247 const int *recvBuffer=a1->getConstPointer();
248 DataArrayInt *descConn=DataArrayInt::New();
249 descConn->alloc(tinyInfo[5],1);
250 std::copy(recvBuffer,recvBuffer+tinyInfo[5],descConn->getPointer());
251 DataArrayInt *descConnIndex=DataArrayInt::New();
252 descConnIndex->alloc(tinyInfo[4]+1,1);
253 std::copy(recvBuffer+tinyInfo[5],recvBuffer+tinyInfo[5]+tinyInfo[4]+1,descConnIndex->getPointer());
254 DataArrayInt *faceConn=DataArrayInt::New();
255 faceConn->alloc(tinyInfo[7],1);
256 std::copy(recvBuffer+tinyInfo[5]+tinyInfo[4]+1,recvBuffer+tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7],faceConn->getPointer());
257 DataArrayInt *faceConnIndex=DataArrayInt::New();
258 faceConnIndex->alloc(tinyInfo[6]+1,1);
259 std::copy(recvBuffer+tinyInfo[5]+tinyInfo[4]+1+tinyInfo[7],
260 recvBuffer+tinyInfo[5]+tinyInfo[5]+1+tinyInfo[7]+tinyInfo[6]+1,faceConnIndex->getPointer());
261 setConnectivity(descConn,descConnIndex,faceConn,faceConnIndex);
263 descConnIndex->decrRef();
265 faceConnIndex->decrRef();
266 setMeshDimension(tinyInfo[2]);
269 void MEDCouplingUMeshDesc::getCellsInBoundingBox(const double *bbox, double eps, std::vector<int>& elems) const
271 int dim=getSpaceDimension();
272 double* elem_bb=new double[2*dim];
273 const int* conn = _desc_connec->getConstPointer();
274 const int* conn_index= _desc_connec_index->getConstPointer();
275 const int* face = _nodal_connec_face->getConstPointer();
276 const int* face_index= _nodal_connec_face_index->getConstPointer();
277 const double* coords = getCoords()->getConstPointer();
278 int nbOfCells=getNumberOfCells();
279 for ( int ielem=0; ielem<nbOfCells;ielem++ )
281 for (int i=0; i<dim; i++)
283 elem_bb[i*2]=std::numeric_limits<double>::max();
284 elem_bb[i*2+1]=-std::numeric_limits<double>::max();
287 for (int jface=conn_index[ielem]+1; jface<conn_index[ielem+1]; jface++)//+1 due to offset of cell type.
289 int iface=conn[jface];
290 for(int inode=face_index[iface]+1;inode<face_index[iface+1];inode++)
292 int node=face[inode];
293 for (int idim=0; idim<dim; idim++)
295 if ( coords[node*dim+idim] < elem_bb[idim*2] )
297 elem_bb[idim*2] = coords[node*dim+idim] ;
299 if ( coords[node*dim+idim] > elem_bb[idim*2+1] )
301 elem_bb[idim*2+1] = coords[node*dim+idim] ;
306 if (intersectsBoundingBox(elem_bb, bbox, dim, eps))
308 elems.push_back(ielem);
314 void MEDCouplingUMeshDesc::getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox &bbox, double eps, std::vector<int>& elems)
316 int dim=getSpaceDimension();
317 double* elem_bb=new double[2*dim];
318 const int* conn = _desc_connec->getConstPointer();
319 const int* conn_index= _desc_connec_index->getConstPointer();
320 const int* face = _nodal_connec_face->getConstPointer();
321 const int* face_index= _nodal_connec_face_index->getConstPointer();
322 const double* coords = getCoords()->getConstPointer();
323 int nbOfCells=getNumberOfCells();
324 for ( int ielem=0; ielem<nbOfCells;ielem++ )
326 for (int i=0; i<dim; i++)
328 elem_bb[i*2]=std::numeric_limits<double>::max();
329 elem_bb[i*2+1]=-std::numeric_limits<double>::max();
332 for (int jface=conn_index[ielem]+1; jface<conn_index[ielem+1]; jface++)//+1 due to offset of cell type.
334 int iface=conn[jface];
335 for(int inode=face_index[iface]+1;inode<face_index[iface+1];inode++)
337 int node=face[inode];
338 for (int idim=0; idim<dim; idim++)
340 if ( coords[node*dim+idim] < elem_bb[idim*2] )
342 elem_bb[idim*2] = coords[node*dim+idim] ;
344 if ( coords[node*dim+idim] > elem_bb[idim*2+1] )
346 elem_bb[idim*2+1] = coords[node*dim+idim] ;
351 if (intersectsBoundingBox(bbox, elem_bb, dim, eps))
353 elems.push_back(ielem);
359 DataArrayInt *MEDCouplingUMeshDesc::mergeNodes(double precision, bool& areNodesMerged, int& newNbOfNodes)
361 throw INTERP_KERNEL::Exception("Not implemented yet !");
362 areNodesMerged=false;
366 DataArrayInt *MEDCouplingUMeshDesc::mergeNodes2(double precision, bool& areNodesMerged, int& newNbOfNodes)
368 throw INTERP_KERNEL::Exception("Not implemented yet !");
369 areNodesMerged=false;
373 void MEDCouplingUMeshDesc::tryToShareSameCoordsPermute(const MEDCouplingPointSet& other, double epsilon) throw(INTERP_KERNEL::Exception)
375 throw INTERP_KERNEL::Exception("Not implemented yet !");
378 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelf2(int start, int end, int step, bool keepCoords) const throw(INTERP_KERNEL::Exception)
380 throw INTERP_KERNEL::Exception("Not implemented yet !");
384 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelf(const int *start, const int *end, bool keepCoords) const
386 throw INTERP_KERNEL::Exception("Not implemented yet !");
390 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildPartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
392 throw INTERP_KERNEL::Exception("Not implemented yet !");
396 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildFacePartOfMySelfNode(const int *start, const int *end, bool fullyIn) const
398 throw INTERP_KERNEL::Exception("Not implemented yet !");
402 DataArrayInt *MEDCouplingUMeshDesc::simplexize(int policy) throw(INTERP_KERNEL::Exception)
404 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::simplexize : Not implemented yet !");
407 DataArrayInt *MEDCouplingUMeshDesc::findBoundaryNodes() const
409 throw INTERP_KERNEL::Exception("Not implemented yet !");
412 MEDCouplingPointSet *MEDCouplingUMeshDesc::buildBoundaryMesh(bool keepCoords) const
414 throw INTERP_KERNEL::Exception("Not implemented yet !");
418 MEDCouplingUMesh *MEDCouplingUMeshDesc::buildUnstructured() const throw(INTERP_KERNEL::Exception)
420 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::buildUnstructured : not implemented yet !");
423 void MEDCouplingUMeshDesc::renumberCells(const int *old2NewBg, bool check) throw(INTERP_KERNEL::Exception)
425 throw INTERP_KERNEL::Exception("Available for UMesh desc but not implemented yet !");
428 void MEDCouplingUMeshDesc::renumberNodes(const int *newNodeNumbers, int newNbOfNodes)
430 MEDCouplingPointSet::renumberNodes(newNodeNumbers,newNbOfNodes);
431 throw INTERP_KERNEL::Exception("Not implemented yet !");
434 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::getMeasureField(bool isAbs) const
436 throw INTERP_KERNEL::Exception("Not implemented yet !");
440 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::getMeasureFieldOnNode(bool isAbs) const
442 throw INTERP_KERNEL::Exception("Not implemented yet !");
446 MEDCouplingFieldDouble *MEDCouplingUMeshDesc::buildOrthogonalField() const
448 if(getMeshDimension()!=2)
449 throw INTERP_KERNEL::Exception("Expected a cmesh with meshDim == 2 !");
450 throw INTERP_KERNEL::Exception("Not implemented yet !");
454 DataArrayInt *MEDCouplingUMeshDesc::zipCoordsTraducer()
456 throw INTERP_KERNEL::Exception("Not implemented yet !");
460 void MEDCouplingUMeshDesc::computeTypes()
462 if(_desc_connec && _desc_connec_index)
465 const int *conn=_desc_connec->getConstPointer();
466 const int *connIndex=_desc_connec_index->getConstPointer();
467 int nbOfElem=_desc_connec_index->getNbOfElems()-1;
468 for(const int *pt=connIndex;pt!=connIndex+nbOfElem;pt++)
469 _types.insert((INTERP_KERNEL::NormalizedCellType)conn[*pt]);
473 void MEDCouplingUMeshDesc::checkFullyDefined() const throw(INTERP_KERNEL::Exception)
475 if(!_desc_connec || !_desc_connec_index || !_nodal_connec_face || !_nodal_connec_face_index || !_coords)
476 throw INTERP_KERNEL::Exception("full connectivity and coordinates not set in unstructured mesh.");
479 MEDCouplingMesh *MEDCouplingUMeshDesc::mergeMyselfWith(const MEDCouplingMesh *other) const
481 throw INTERP_KERNEL::Exception("Not implemented yet !");
485 DataArrayDouble *MEDCouplingUMeshDesc::getBarycenterAndOwner() const
487 throw INTERP_KERNEL::Exception("Not implemented yet !");
491 int MEDCouplingUMeshDesc::getCellContainingPoint(const double *pos, double eps) const
493 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getCellContainingPoint : not implemented yet !");
496 void MEDCouplingUMeshDesc::writeVTKLL(std::ostream& ofs, const std::string& cellData, const std::string& pointData) const throw(INTERP_KERNEL::Exception)
498 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::writeVTKLL : not implemented yet !");
501 std::string MEDCouplingUMeshDesc::getVTKDataSetType() const throw(INTERP_KERNEL::Exception)
503 throw INTERP_KERNEL::Exception("MEDCouplingUMeshDesc::getVTKDataSetType : not implemented yet !");