1 // Copyright (C) 2007-2014 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 #include "MEDFileFieldOverView.hxx"
22 #include "MEDFileField.hxx"
23 #include "MEDFileMesh.hxx"
25 #include "CellModel.hxx"
27 using namespace ParaMEDMEM;
29 const unsigned char MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE[MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH]=
30 {1,3,21,5,9,7,22,34,23,28,255,255,255,255,10,14,13,255,12,255,24,255,16,27,255,26,255,29,255,255,25,42,36,4};
32 const unsigned char MEDMeshMultiLev::HEXA27_PERM_ARRAY[27]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,24,22,21,23,20,25,26};
34 const char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???";
36 MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh)
38 return new MEDFileMeshStruct(mesh);
41 std::size_t MEDFileMeshStruct::getHeapMemorySizeWithoutChildren() const
44 for(std::vector< std::vector<int> >::const_iterator it0=_geo_types_distrib.begin();it0!=_geo_types_distrib.end();it0++)
45 ret+=(*it0).capacity()*sizeof(int);
46 ret+=_geo_types_distrib.capacity()*sizeof(std::vector<int>);
50 std::vector<const BigMemoryObject *> MEDFileMeshStruct::getDirectChildren() const
52 return std::vector<const BigMemoryObject *>();
55 MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh)
57 std::vector<int> levs(mesh->getNonEmptyLevels());
58 _name=mesh->getName();
59 _nb_nodes=mesh->getNumberOfNodes();
62 _geo_types_distrib.resize(-(*std::min_element(levs.begin(),levs.end()))+1);
63 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
64 _geo_types_distrib[-(*lev)]=mesh->getDistributionOfTypes(*lev);
68 int MEDFileMeshStruct::getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
71 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++,j--)
73 std::size_t sz=(*it1).size();
75 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : internal error in code !");
76 std::size_t nbGeo=sz/3;
77 for(std::size_t i=0;i<nbGeo;i++)
78 if((*it1)[3*i]==(int)t)
81 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : The specified geometric type is not present in the mesh structure !");
85 * \sa MEDFileMeshStruct::doesManageGeoType
87 int MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
89 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
91 std::size_t sz=(*it1).size();
93 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !");
94 std::size_t nbGeo=sz/3;
95 for(std::size_t i=0;i<nbGeo;i++)
96 if((*it1)[3*i]==(int)t)
99 throw INTERP_KERNEL::Exception("The specified geometric type is not present in the mesh structure !");
103 * \sa MEDFileMeshStruct::getNumberOfElemsOfGeoType
105 bool MEDFileMeshStruct::doesManageGeoType(INTERP_KERNEL::NormalizedCellType t) const
107 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
109 std::size_t sz=(*it1).size();
111 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::doesManageGeoType : internal error in code !");
112 std::size_t nbGeo=sz/3;
113 for(std::size_t i=0;i<nbGeo;i++)
114 if((*it1)[3*i]==(int)t)
120 void MEDFileMeshStruct::appendIfImplicitType(INTERP_KERNEL::NormalizedCellType t)
122 if(!_mesh->hasImplicitPart())
123 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::appendIfImplicitType : by default no implicit geo type can be appended !");
124 static const char MSG[]="MEDFileMeshStruct::appendIfImplicitType : the distribution does not looks like structured standard !";
125 if(_geo_types_distrib.size()!=1)
126 throw INTERP_KERNEL::Exception(MSG);
127 std::size_t sz(_geo_types_distrib[0].size());
129 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::appendIfImplicitType : internal error in code !");
130 std::size_t nbGeo(sz/3);
132 throw INTERP_KERNEL::Exception(MSG);
133 std::vector<int> arr(3); arr[0]=(int)t; arr[1]=_mesh->buildImplicitPartIfAny(t); arr[2]=-1;
134 _geo_types_distrib.push_back(arr);
138 int MEDFileMeshStruct::getNumberOfLevs() const
140 return (int)_geo_types_distrib.size();
143 int MEDFileMeshStruct::getNumberOfGeoTypesInLev(int relativeLev) const
145 int pos(-relativeLev);
146 if(pos<0 || pos>=(int)_geo_types_distrib.size())
147 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : invalid level specified !");
148 std::size_t sz=_geo_types_distrib[pos].size();
150 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : internal error in code !");
156 std::size_t MEDMeshMultiLev::getHeapMemorySizeWithoutChildren() const
161 std::vector<const BigMemoryObject *> MEDMeshMultiLev::getDirectChildren() const
163 return std::vector<const BigMemoryObject *>();
166 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs)
169 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
170 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
172 return MEDUMeshMultiLev::New(um,levs);
173 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
175 return MEDCMeshMultiLev::New(cm,levs);
176 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
178 return MEDCurveLinearMeshMultiLev::New(clm,levs);
179 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
182 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
185 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
186 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
188 return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
189 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
191 return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
192 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
194 return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
195 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
198 MEDMeshMultiLev *MEDMeshMultiLev::NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode)
200 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,m->getNonEmptyLevels()));
201 ret->selectPartOfNodes(pflOnNode);
205 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
209 _node_reduction=const_cast<DataArrayInt*>(nr);
212 bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const
214 if(fst.getType()==ON_NODES)
216 if(fst.getNumberOfItems()!=1)
217 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::isFastlyTheSameStruct : unexpected situation for nodes !");
218 const MEDFileField1TSStructItem2& p(fst[0]);
219 std::string pflName(p.getPflName());
220 const DataArrayInt *nr(_node_reduction);
221 if(pflName.empty() && !nr)
223 if(!pflName.empty() && !nr)
225 if(pflName==nr->getName())
231 std::size_t sz(fst.getNumberOfItems());
232 if(sz!=_geo_types.size())
235 for(std::size_t i=0;i<sz;i++)
237 const MEDFileField1TSStructItem2& p(fst[i]);
238 if(!p.isFastlyEqual(strt,_geo_types[i],getPflNameOfId(i).c_str()))
245 DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
247 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(const_cast<DataArray *>(vals)); ret->incrRef();
248 if(isFastlyTheSameStruct(fst,globs))
251 return constructDataArray(fst,globs,vals);
255 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
256 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
258 void MEDMeshMultiLev::retrieveFamilyIdsOnCells(DataArrayInt *& famIds, bool& isWithoutCopy) const
260 const DataArrayInt *fids(_cell_fam_ids);
262 { famIds=0; isWithoutCopy=true; return ; }
263 std::size_t sz(_geo_types.size());
264 bool presenceOfPfls(false);
265 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
267 const DataArrayInt *pfl(_pfls[i]);
272 { famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef(); isWithoutCopy=_cell_fam_ids_nocpy; return ; }
273 //bad luck the slowest part
275 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
276 std::vector< const DataArrayInt *> ret(sz);
278 for(std::size_t i=0;i<sz;i++)
280 const DataArrayInt *pfl(_pfls[i]);
281 int lgth(_nb_entities[i]);
284 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(fids->selectByTupleId2(start,start+lgth,1));
285 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
289 retSafe[i]=fids->selectByTupleId2(start,start+lgth,1);
294 famIds=DataArrayInt::Aggregate(ret);
298 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
299 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
301 void MEDMeshMultiLev::retrieveNumberIdsOnCells(DataArrayInt *& numIds, bool& isWithoutCopy) const
303 const DataArrayInt *nids(_cell_num_ids);
305 { numIds=0; isWithoutCopy=true; return ; }
306 std::size_t sz(_geo_types.size());
307 bool presenceOfPfls(false);
308 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
310 const DataArrayInt *pfl(_pfls[i]);
315 { numIds=const_cast<DataArrayInt *>(nids); numIds->incrRef(); isWithoutCopy=_cell_num_ids_nocpy; return ; }
316 //bad luck the slowest part
318 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
319 std::vector< const DataArrayInt *> ret(sz);
321 for(std::size_t i=0;i<sz;i++)
323 const DataArrayInt *pfl(_pfls[i]);
324 int lgth(_nb_entities[i]);
327 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(nids->selectByTupleId2(start,start+lgth,1));
328 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
332 retSafe[i]=nids->selectByTupleId2(start,start+lgth,1);
337 numIds=DataArrayInt::Aggregate(ret);
341 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
342 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
344 void MEDMeshMultiLev::retrieveFamilyIdsOnNodes(DataArrayInt *& famIds, bool& isWithoutCopy) const
346 const DataArrayInt *fids(_node_fam_ids);
348 { famIds=0; isWithoutCopy=true; return ; }
349 const DataArrayInt *nr(_node_reduction);
353 famIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
357 isWithoutCopy=_node_fam_ids_nocpy;
358 famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef();
363 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
364 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
366 void MEDMeshMultiLev::retrieveNumberIdsOnNodes(DataArrayInt *& numIds, bool& isWithoutCopy) const
368 const DataArrayInt *fids(_node_num_ids);
370 { numIds=0; isWithoutCopy=true; return ; }
371 const DataArrayInt *nr(_node_reduction);
375 numIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
379 isWithoutCopy=_node_num_ids_nocpy;
380 numIds=const_cast<DataArrayInt *>(fids); numIds->incrRef();
384 std::vector< INTERP_KERNEL::NormalizedCellType > MEDMeshMultiLev::getGeoTypes() const
389 void MEDMeshMultiLev::setFamilyIdsOnCells(DataArrayInt *famIds, bool isNoCopy)
391 _cell_fam_ids=famIds;
394 _cell_fam_ids_nocpy=isNoCopy;
397 void MEDMeshMultiLev::setNumberIdsOnCells(DataArrayInt *numIds, bool isNoCopy)
399 _cell_num_ids=numIds;
402 _cell_num_ids_nocpy=isNoCopy;
405 void MEDMeshMultiLev::setFamilyIdsOnNodes(DataArrayInt *famIds, bool isNoCopy)
407 _node_fam_ids=famIds;
410 _node_fam_ids_nocpy=isNoCopy;
413 void MEDMeshMultiLev::setNumberIdsOnNodes(DataArrayInt *numIds, bool isNoCopy)
415 _node_num_ids=numIds;
418 _node_num_ids_nocpy=isNoCopy;
421 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
423 std::size_t sz(_pfls.size());
424 if(id<0 || id>=(int)sz)
425 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
426 const DataArrayInt *pfl(_pfls[id]);
428 return std::string("");
429 return pfl->getName();
433 * Returns the number of cells having geometric type \a t.
434 * The profiles are **NOT** taken into account here.
436 int MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
438 std::size_t sz(_nb_entities.size());
439 for(std::size_t i=0;i<sz;i++)
441 return _nb_entities[i];
442 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
445 int MEDMeshMultiLev::getNumberOfNodes() const
450 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
452 if(fst.getType()==ON_NODES)
454 if(fst.getNumberOfItems()!=1)
455 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
456 const MEDFileField1TSStructItem2& p(fst[0]);
457 std::string pflName(p.getPflName());
458 const DataArrayInt *nr(_node_reduction);
459 if(pflName.empty() && !nr)
460 return vals->deepCpy();
461 if(pflName.empty() && nr)
462 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
463 if(!pflName.empty() && nr)
465 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
466 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(nr->deepCpy());
467 p1->sort(true); p2->sort(true);
468 if(!p1->isEqualWithoutConsideringStr(*p2))
469 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : it appears that a profile on nodes does not cover the cells correctly !");
470 p1=DataArrayInt::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
471 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
472 ret->renumberInPlace(p1->begin());
475 if(!pflName.empty() && !nr)
477 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
479 if(!p1->isIdentity() || p1->getNumberOfTuples()!=getNumberOfNodes())
480 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
481 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
482 ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
485 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
489 std::size_t sz(fst.getNumberOfItems());
490 std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
491 if(s.size()!=_geo_types.size())
492 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
493 std::vector< const DataArray *> arr(s.size());
494 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arrSafe(s.size());
496 int nc(vals->getNumberOfComponents());
497 std::vector<std::string> compInfo(vals->getInfoOnComponents());
498 for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
500 const DataArrayInt *thisP(_pfls[iii]);
501 std::vector<const MEDFileField1TSStructItem2 *> ps;
502 for(std::size_t i=0;i<sz;i++)
504 const MEDFileField1TSStructItem2& p(fst[i]);
509 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
512 int nbi(ps[0]->getNbOfIntegrationPts(globs));
513 const DataArrayInt *otherP(ps[0]->getPfl(globs));
514 const std::pair<int,int>& strtStop(ps[0]->getStartStop());
515 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
516 if(!thisP && !otherP)
518 arrSafe[iii]=ret; arr[iii]=ret;
523 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
524 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(thisP->deepCpy());
525 p2->transformWithIndArr(p1->begin(),p1->end());
526 //p1=p2->getIdsNotEqual(-1);
527 //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
528 ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
529 arrSafe[iii]=ret; arr[iii]=ret;
534 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->deepCpy());
536 p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
537 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,p1);
538 ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
539 arrSafe[iii]=ret; arr[iii]=ret;
542 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
546 std::vector< const DataArrayInt * >otherPS(ps.size());
547 std::vector< const DataArray * > arr2(ps.size());
548 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arr2Safe(ps.size());
549 std::vector< const DataArrayInt * > nbis(ps.size());
550 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > nbisSafe(ps.size());
552 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
554 int nbi((*it2)->getNbOfIntegrationPts(globs));
555 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
556 const std::pair<int,int>& strtStop((*it2)->getStartStop());
557 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
559 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
560 arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
561 nbisSafe[jj]=DataArrayInt::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
562 nbis[jj]=nbisSafe[jj];
564 MEDCouplingAutoRefCountObjectPtr<DataArray> arr3(DataArray::Aggregate(arr2));
565 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherP(DataArrayInt::Aggregate(otherPS));
566 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbis(DataArrayInt::Aggregate(nbis));
567 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
568 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1;
570 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,thisP);
572 p1=otherP->deepCpy();
573 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbisN(zenbis->renumber(p1->begin()));
574 zenbisN->computeOffsets2();
576 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
578 //int nbi((*it2)->getNbOfIntegrationPts(globs));
579 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
580 const std::pair<int,int>& strtStop((*it2)->getStartStop());
581 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
583 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(otherPfl->deepCpy());
584 p2->transformWithIndArr(otherPN->begin(),otherPN->end());
585 p2->transformWithIndArr(p1->begin(),p1->end());
586 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsN(p2->buildExplicitArrByRanges(zenbisN));
587 arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
589 arrSafe[iii]=arr3; arr[iii]=arr3;
593 return DataArray::Aggregate(arr);
598 * This method is called to add NORM_POINT1 cells in \a this so that orphan nodes in \a verticesToAdd will be fetched.
600 void MEDMeshMultiLev::appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr)
602 int nbOfVertices(verticesToAdd->getNumberOfTuples());
603 std::size_t sz(_pfls.size());
605 _geo_types.resize(sz+1,INTERP_KERNEL::NORM_POINT1);
606 _nb_entities.resize(sz+1,nbOfVertices);
607 _node_reduction=nr; nr->incrRef();
608 _nb_nodes+=nbOfVertices;
609 const DataArrayInt *cf(_cell_fam_ids),*cn(_cell_num_ids),*nf(_node_fam_ids),*nn(_node_num_ids);
612 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp;
613 std::vector<const DataArrayInt *> a(2);
616 tmp=nf->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
619 tmp=DataArrayInt::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
622 _cell_fam_ids=DataArrayInt::Aggregate(a);
623 _cell_fam_ids_nocpy=false;
627 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp;
628 std::vector<const DataArrayInt *> a(2);
631 tmp=nn->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
634 tmp=DataArrayInt::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
637 _cell_num_ids=DataArrayInt::Aggregate(a);
638 _cell_num_ids_nocpy=false;
642 MEDMeshMultiLev::MEDMeshMultiLev(const MEDFileMesh *mesh):_mesh(mesh),_nb_nodes(0),_cell_fam_ids_nocpy(false)
646 MEDMeshMultiLev::MEDMeshMultiLev(const MEDFileMesh *mesh, int nbNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):_mesh(mesh),_geo_types(gts),_nb_entities(nbEntities),_nb_nodes(nbNodes),_cell_fam_ids_nocpy(false),_cell_num_ids_nocpy(false),_node_fam_ids_nocpy(false),_node_num_ids_nocpy(false)
648 std::size_t sz(_geo_types.size());
649 if(sz!=pfls.size() || sz!=nbEntities.size())
650 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
652 for(std::size_t i=0;i<sz;i++)
656 _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
660 MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):RefCountObject(other),_mesh(other._mesh),_pfls(other._pfls),_geo_types(other._geo_types),_nb_entities(other._nb_entities),_node_reduction(other._node_reduction),_nb_nodes(other._nb_nodes),_cell_fam_ids(other._cell_fam_ids),_cell_fam_ids_nocpy(other._cell_fam_ids_nocpy),_cell_num_ids(other._cell_num_ids),_cell_num_ids_nocpy(other._cell_num_ids_nocpy),_node_fam_ids(other._node_fam_ids),_node_fam_ids_nocpy(other._node_fam_ids_nocpy),_node_num_ids(other._node_num_ids),_node_num_ids_nocpy(other._node_num_ids_nocpy)
666 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
668 return new MEDUMeshMultiLev(m,levs);
671 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs):MEDMeshMultiLev(m)
674 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
675 std::vector<MEDCoupling1GTUMesh *> v;
676 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
678 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
679 v.insert(v.end(),vTmp.begin(),vTmp.end());
681 std::size_t sz(v.size());
684 _coords=m->getCoords(); _coords->incrRef();
688 _geo_types.resize(sz);
689 _nb_entities.resize(sz);
690 for(std::size_t i=0;i<sz;i++)
692 MEDCoupling1GTUMesh *obj(v[i]);
696 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
698 _geo_types[i]=obj->getCellModelEnum();
699 _nb_entities[i]=obj->getNumberOfCells();
701 // ids fields management
702 _cell_fam_ids_nocpy=(levs.size()==1);
703 if(_cell_fam_ids_nocpy)
705 const DataArrayInt *tmp(m->getFamilyFieldAtLevel(levs[0]));
709 _cell_fam_ids=(const_cast<DataArrayInt *>(tmp));
714 std::vector<const DataArrayInt *> tmps(levs.size());
716 for(std::size_t i=0;i<levs.size();i++)
718 tmps[i]=m->getFamilyFieldAtLevel(levs[i]);
722 if(f && !tmps.empty())
723 _cell_fam_ids=DataArrayInt::Aggregate(tmps);
725 _cell_num_ids_nocpy=(levs.size()==1);
726 if(_cell_num_ids_nocpy)
728 const DataArrayInt *tmp(m->getNumberFieldAtLevel(levs[0]));
732 _cell_num_ids=(const_cast<DataArrayInt *>(tmp));
737 std::vector<const DataArrayInt *> tmps(levs.size());
739 for(std::size_t i=0;i<levs.size();i++)
741 tmps[i]=m->getNumberFieldAtLevel(levs[i]);
745 if(n && !tmps.empty())
746 _cell_num_ids=DataArrayInt::Aggregate(tmps);
749 _node_fam_ids_nocpy=true;
751 const DataArrayInt *tmp(m->getFamilyFieldAtLevel(1));
755 _node_fam_ids=(const_cast<DataArrayInt *>(tmp));
758 _node_num_ids_nocpy=true;
760 const DataArrayInt *tmp(m->getNumberFieldAtLevel(1));
764 _node_num_ids=(const_cast<DataArrayInt *>(tmp));
769 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
771 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
774 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
776 std::size_t sz(gts.size());
778 throw INTERP_KERNEL::Exception("constructor of MEDUMeshMultiLev : number of different geo type must be >= 1 !");
779 unsigned dim(INTERP_KERNEL::CellModel::GetCellModel(gts[0]).getDimension());
781 bool isSameDim(true),isNoPfl(true);
782 for(std::size_t i=0;i<sz;i++)
784 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
785 if(INTERP_KERNEL::CellModel::GetCellModel(gts[i]).getDimension()!=dim)
793 // ids fields management
794 int lev((int)dim-m->getMeshDimension());
795 if(isSameDim && isNoPfl && m->getGeoTypesAtLevel(lev)==gts)//optimized part
797 _cell_fam_ids_nocpy=true;
798 const DataArrayInt *famIds(m->getFamilyFieldAtLevel(lev));
800 { _cell_fam_ids=const_cast<DataArrayInt*>(famIds); famIds->incrRef(); }
801 _cell_num_ids_nocpy=true;
802 const DataArrayInt *numIds(m->getNumberFieldAtLevel(lev));
804 { _cell_num_ids=const_cast<DataArrayInt*>(numIds); numIds->incrRef(); }
805 _node_fam_ids_nocpy=true;
806 famIds=m->getFamilyFieldAtLevel(1);
808 { _node_fam_ids=const_cast<DataArrayInt*>(famIds); famIds->incrRef(); }
809 _node_num_ids_nocpy=true;
810 numIds=m->getNumberFieldAtLevel(1);
812 { _node_num_ids=const_cast<DataArrayInt*>(numIds); numIds->incrRef(); }
816 _cell_fam_ids_nocpy=false;
817 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > famIdsSafe(sz);
818 std::vector<const DataArrayInt *> famIds(sz);
820 for(std::size_t i=0;i<sz;i++)
822 famIdsSafe[i]=m->extractFamilyFieldOnGeoType(gts[i]);
823 famIds[i]=famIdsSafe[i];
828 _cell_fam_ids=DataArrayInt::Aggregate(famIds);
829 _cell_num_ids_nocpy=false;
830 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > numIdsSafe(sz);
831 std::vector<const DataArrayInt *> numIds(sz);
833 for(std::size_t i=0;i<sz;i++)
835 numIdsSafe[i]=m->extractNumberFieldOnGeoType(gts[i]);
836 numIds[i]=numIdsSafe[i];
841 _cell_num_ids=DataArrayInt::Aggregate(numIds);
842 // node ids management
843 _node_fam_ids_nocpy=true;
844 const DataArrayInt *nodeFamIds(m->getFamilyFieldAtLevel(1));
846 { _node_fam_ids=const_cast<DataArrayInt*>(nodeFamIds); nodeFamIds->incrRef(); }
847 _node_num_ids_nocpy=true;
848 const DataArrayInt *nodeNumIds(m->getNumberFieldAtLevel(1));
850 { _node_num_ids=const_cast<DataArrayInt*>(nodeNumIds); nodeNumIds->incrRef(); }
853 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
855 if(!pflNodes || !pflNodes->isAllocated())
857 std::size_t sz(_parts.size());
858 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
859 std::vector< const DataArrayInt *> aa(sz);
860 for(std::size_t i=0;i<sz;i++)
862 const DataArrayInt *pfl(_pfls[i]);
863 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
865 m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
866 DataArrayInt *cellIds=0;
867 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
868 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
869 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
871 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m2->getNodeIdsInUse(tmp));
872 a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
874 _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
876 _pfls[i]=cellIdsSafe;
879 _node_reduction=DataArrayInt::Aggregate(aa);//general case
881 _node_reduction=pflNodes->deepCpy();//case where no cells in read mesh.
882 _node_reduction->sort(true);
883 _node_reduction=_node_reduction->buildUnique();
884 if(_node_reduction->getNumberOfTuples()==pflNodes->getNumberOfTuples())
885 return ;//This is the classical case where the input node profile corresponds perfectly to a subset of cells in _parts
886 if(_node_reduction->getNumberOfTuples()>pflNodes->getNumberOfTuples())
887 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::selectPartOfNodes : internal error in MEDCoupling during cell select from a list of nodes !");
888 // Here the cells available in _parts is not enough to cover all the nodes in pflNodes. So adding vertices cells in _parts...
889 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflNodes2(pflNodes->deepCpy());
890 pflNodes2->sort(true);
891 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diff(pflNodes2->buildSubstractionOptimized(_node_reduction));
892 appendVertices(diff,pflNodes2);
895 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
897 return new MEDUMeshMultiLev(*this);
900 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts),_coords(other._coords)
904 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
908 _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
909 _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
910 _pfls.resize(1); _pfls[0]=0;
914 * If returned value is false output pointer \a coords is not the internal pointer. If returned value is true output pointer \a coords is directly the internal pointer.
915 * If true is returned, the \a coords output parameter should be used with care (non const method call) to avoid to change the internal state of MEDFileUMesh instance.
917 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const
919 const DataArrayDouble *tmp(0);
923 tmp=_parts[0]->getCoords();
925 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
926 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
927 int szBCE(0),szD(0),szF(0);
930 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
932 const MEDCoupling1GTUMesh *cur(*it);
934 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
936 const DataArrayInt *pfl(_pfls[iii]);
937 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
939 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
941 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
943 int curNbCells(cur->getNumberOfCells());
945 if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
946 szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
950 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(cur->computeEffectiveNbOfNodesPerCell());
951 szD+=tmp2->accumulate(0)+curNbCells;
952 szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
955 MEDCouplingAutoRefCountObjectPtr<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
956 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()); c->alloc(szBCE,1); int *cPtr(c->getPointer());
957 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d(DataArrayInt::New()); d->alloc(szD,1); int *dPtr(d->getPointer());
958 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> e(DataArrayInt::New()),f(DataArrayInt::New()); int *ePtr(0),*fPtr(0);
960 { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
963 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
965 const MEDCoupling1GTUMesh *cur(*it);
967 const DataArrayInt *pfl(_pfls[iii]);
968 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
970 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
972 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
974 int curNbCells(cur->getNumberOfCells());
975 int gt((int)cur->getCellModelEnum());
976 if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
977 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
978 unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
980 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
981 std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
982 const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
983 const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
984 const int *connPtr(cur->getNodalConnectivity()->begin());
986 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
989 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA27)
991 int nnpc(scur->getNumberOfNodesPerCell());
992 for(int i=0;i<curNbCells;i++,connPtr+=nnpc)
995 dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
996 *cPtr++=k; k+=nnpc+1;
1001 for(int i=0;i<curNbCells;i++,connPtr+=27)
1004 for(int j=0;j<27;j++,dPtr++)
1005 *dPtr=connPtr[HEXA27_PERM_ARRAY[j]];
1010 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1014 const int *connIPtr(dcur->getNodalConnectivityIndex()->begin());
1015 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1017 for(int i=0;i<curNbCells;i++,connIPtr++)
1019 *dPtr++=connIPtr[1]-connIPtr[0];
1020 dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
1021 *cPtr++=k; k+=connIPtr[1]-connIPtr[0];
1026 for(int i=0;i<curNbCells;i++,connIPtr++)
1028 std::set<int> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
1029 *dPtr++=(int)s.size();
1030 dPtr=std::copy(s.begin(),s.end(),dPtr);
1031 *cPtr++=k; k+=(int)s.size()+1;
1036 connIPtr=dcur->getNodalConnectivityIndex()->begin();
1037 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1038 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1042 for(int i=0;i<curNbCells;i++,connIPtr++)
1044 int nbFace(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1);
1046 const int *work(connPtr+connIPtr[0]);
1047 for(int j=0;j<nbFace;j++)
1049 const int *work2=std::find(work,connPtr+connIPtr[1],-1);
1050 *fPtr++=std::distance(work,work2);
1051 fPtr=std::copy(work,work2,fPtr);
1054 *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
1061 reorderNodesIfNecessary(a,d,0);
1063 reorderNodesIfNecessary(a,d,f);
1064 if(a->getNumberOfComponents()!=3)
1065 a=a->changeNbOfComponents(3,0.);
1066 coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
1068 { faceLocations=0; faces=0; }
1070 { faceLocations=e.retn(); faces=f.retn(); }
1071 return tmp==((DataArrayDouble *)a);
1074 void MEDUMeshMultiLev::reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const
1076 const DataArrayInt *nr(_node_reduction);
1079 if(nodalConnVTK->empty() && !polyhedNodalConnVTK)
1081 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1084 int sz(coords->getNumberOfTuples());
1085 std::vector<bool> b(sz,false);
1086 const int *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
1090 for(int i=0;i<nb && work!=endW;i++,work++)
1092 if(*work>=0 && *work<sz)
1095 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
1098 if(polyhedNodalConnVTK)
1100 work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
1104 for(int i=0;i<nb && work!=endW;i++)
1107 for(int j=0;j<nb2 && work!=endW;j++,work++)
1109 if(*work>=0 && *work<sz)
1112 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
1117 int szExp(std::count(b.begin(),b.end(),true));
1118 if(szExp!=nr->getNumberOfTuples())
1119 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
1121 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(DataArrayInt::New()); o2n->alloc(sz,1);
1122 int *o2nPtr(o2n->getPointer());
1124 for(int i=0;i<sz;i++,o2nPtr++)
1125 if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
1126 const int *o2nPtrc(o2n->begin());
1127 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
1128 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> perm(DataArrayInt::FindPermutationFromFirstToSecond(n2o,nr));
1129 const int *permPtr(perm->begin());
1130 int *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
1134 for(int i=0;i<nb && work2!=endW2;i++,work2++)
1135 *work2=permPtr[o2nPtrc[*work2]];
1137 if(polyhedNodalConnVTK)
1139 work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
1143 for(int i=0;i<nb && work2!=endW2;i++)
1146 for(int j=0;j<nb2 && work2!=endW2;j++,work2++)
1147 *work2=permPtr[o2nPtrc[*work2]];
1151 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1155 void MEDUMeshMultiLev::appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr)
1157 int nbOfCells(verticesToAdd->getNumberOfTuples());//it is not a bug cells are NORM_POINT1
1158 MEDMeshMultiLev::appendVertices(verticesToAdd,nr);
1159 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> elt(MEDCoupling1SGTUMesh::New("",INTERP_KERNEL::NORM_POINT1));
1160 elt->allocateCells(nbOfCells);
1161 for(int i=0;i<nbOfCells;i++)
1163 int pt(verticesToAdd->getIJ(i,0));
1164 elt->insertNextCell(&pt,&pt+1);
1167 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::appendVertices : parts are empty !");
1168 elt->setCoords(_parts[0]->getCoords());
1169 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> elt2((MEDCoupling1SGTUMesh *)elt); elt2->incrRef();
1170 _parts.push_back(elt2);
1175 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m):MEDMeshMultiLev(m),_is_internal(true)
1179 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector<int>& lev):MEDMeshMultiLev(m),_is_internal(true)
1181 // ids fields management
1182 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1183 const DataArrayInt *tmp(0);
1184 tmp=m->getFamilyFieldAtLevel(0);
1188 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1190 tmp=m->getNumberFieldAtLevel(0);
1194 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1197 _node_fam_ids_nocpy=true; _node_num_ids_nocpy=true;
1199 tmp=m->getFamilyFieldAtLevel(1);
1203 _node_fam_ids=const_cast<DataArrayInt *>(tmp);
1205 tmp=m->getNumberFieldAtLevel(1);
1209 _node_num_ids=const_cast<DataArrayInt *>(tmp);
1213 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, int nbOfNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(m,nbOfNodes,gts,pfls,nbEntities),_is_internal(true)
1215 // ids fields management
1216 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1217 const DataArrayInt *tmp(0);
1218 tmp=m->getFamilyFieldAtLevel(0);
1222 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1224 tmp=m->getNumberFieldAtLevel(0);
1228 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1231 _node_fam_ids_nocpy=true; _node_num_ids_nocpy=true;
1233 tmp=m->getFamilyFieldAtLevel(1);
1237 _node_fam_ids=const_cast<DataArrayInt *>(tmp);
1239 tmp=m->getNumberFieldAtLevel(1);
1243 _node_num_ids=const_cast<DataArrayInt *>(tmp);
1247 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other),_is_internal(true)
1251 bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const
1254 if(_geo_types.empty())
1256 if(_geo_types.size()!=1)
1257 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase only one geo types supported at most supported for the moment !");
1258 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(_mesh->getMeshDimension()));
1259 if(_geo_types[0]==gt)
1261 MEDCoupling1GTUMesh *facesIfPresent((static_cast<const MEDFileStructuredMesh *>(_mesh))->getImplicitFaceMesh());
1264 const DataArrayInt *pfl(0),*nr(_node_reduction);
1267 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> facesIfPresent2(facesIfPresent); facesIfPresent->incrRef();
1268 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret2(new MEDUMeshMultiLev(*this,facesIfPresent2));
1270 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for profile on implicit unstructured mesh.");
1272 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for node reduction on implicit unstructured mesh.");
1277 void MEDStructuredMeshMultiLev::dealWithImplicitUnstructuredMesh(const MEDFileMesh *m)
1279 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1280 const DataArrayInt *tmp(0);
1281 tmp=m->getFamilyFieldAtLevel(-1);
1285 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1287 tmp=m->getNumberFieldAtLevel(-1);
1291 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1295 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
1297 if(!pflNodes || !pflNodes->isAllocated())
1299 std::vector<int> ngs(getNodeGridStructure());
1300 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1301 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
1302 m->setNodalConnectivity(conn);
1303 const DataArrayInt *pfl(_pfls[0]);
1306 m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1308 DataArrayInt *cellIds=0;
1309 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1310 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
1311 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1313 _node_reduction=m2->getNodeIdsInUse(tmp);
1315 _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1317 _pfls[0]=cellIdsSafe;
1322 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
1324 return new MEDCMeshMultiLev(m,levs);
1327 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1329 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
1332 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1335 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
1336 if(levs.size()!=1 || levs[0]!=0)
1337 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
1338 int sdim(m->getSpaceDimension());
1339 _coords.resize(sdim);
1340 for(int i=0;i<sdim;i++)
1342 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1344 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1350 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
1353 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
1354 if(gts.size()!=1 || pfls.size()!=1)
1355 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1356 int mdim(m->getMeshDimension());
1357 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
1360 _coords.resize(mdim);
1361 for(int i=0;i<mdim;i++)
1363 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1365 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1366 _coords[i]=elt; _coords[i]->incrRef();
1370 dealWithImplicitUnstructuredMesh(m);
1373 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1377 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const
1379 std::vector<int> ret(_coords.size());
1380 for(std::size_t i=0;i<_coords.size();i++)
1381 ret[i]=_coords[i]->getNumberOfTuples();
1385 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1387 MEDMeshMultiLev *retSpecific(0);
1388 if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1390 const DataArrayInt *pfl(0),*nr(_node_reduction);
1393 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1394 std::vector<int> cgs,ngs(getNodeGridStructure());
1395 cgs.resize(ngs.size());
1396 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1399 std::vector< std::pair<int,int> > cellParts;
1400 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1401 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1403 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1404 ret->_is_internal=false;
1406 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1407 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1409 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
1410 for(std::size_t i=0;i<_coords.size();i++)
1411 coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
1412 ret->_coords=coords;
1413 ret2=(MEDCMeshMultiLev *)ret; ret2->incrRef();
1417 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1418 for(std::size_t i=0;i<ngs.size();i++)
1419 m->setCoordsAt(i,_coords[i]);
1420 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1421 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1422 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1424 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1425 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1427 const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1430 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1431 ret2->setFamilyIdsOnCells(tmp,false);
1435 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1436 ret2->setNumberIdsOnCells(tmp,false);
1443 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1445 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1451 * \a param [out] isInternal if true the returned pointers are those in main data structure. If false those pointers have been built espacially for that method.
1453 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays(bool& isInternal) const
1455 isInternal=_is_internal;
1456 std::size_t sz(_coords.size());
1457 std::vector< DataArrayDouble * > ret(sz);
1458 for(std::size_t i=0;i<sz;i++)
1460 ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1468 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1470 return new MEDCurveLinearMeshMultiLev(m,levs);
1473 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1475 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1478 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1481 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1482 if(levs.size()!=1 || levs[0]!=0)
1483 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1484 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1486 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1489 _structure=m->getMesh()->getNodeGridStructure();
1492 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
1495 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1496 if(gts.size()!=1 || pfls.size()!=1)
1497 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1498 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1501 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1503 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1506 _structure=m->getMesh()->getNodeGridStructure();
1509 dealWithImplicitUnstructuredMesh(m);
1512 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1516 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1521 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1523 MEDMeshMultiLev *retSpecific(0);
1524 if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1526 const DataArrayInt *pfl(0),*nr(_node_reduction);
1529 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1530 std::vector<int> cgs,ngs(getNodeGridStructure());
1531 cgs.resize(ngs.size());
1532 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1535 std::vector< std::pair<int,int> > cellParts,nodeParts;
1536 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1537 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1539 nodeParts=cellParts;
1540 std::vector<int> st(ngs.size());
1541 for(std::size_t i=0;i<ngs.size();i++)
1543 nodeParts[i].second++;
1544 st[i]=nodeParts[i].second-nodeParts[i].first;
1546 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1547 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1548 ret->_is_internal=false;
1550 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1551 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1553 ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1555 ret2=(MEDCurveLinearMeshMultiLev *)ret; ret2->incrRef();
1559 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1560 m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1561 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1562 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1563 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1565 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1566 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1568 const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1571 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1572 ret2->setFamilyIdsOnCells(tmp,false);
1576 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1577 ret2->setNumberIdsOnCells(tmp,false);
1583 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1585 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1590 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct, bool& isInternal) const
1592 isInternal=_is_internal;
1593 nodeStrct=_structure;
1594 const DataArrayDouble *coo(_coords);
1596 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1597 coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1602 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1606 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2(INTERP_KERNEL::NormalizedCellType a, const std::pair<int,int>& b, const std::string& c, const std::string& d):_geo_type(a),_start_end(b),_pfl(DataArrayInt::New()),_loc(d),_nb_of_entity(-1)
1608 _pfl->setName(c.c_str());
1611 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1613 if(!mst->doesManageGeoType(_geo_type))
1615 MEDFileMeshStruct *mstUnConstCasted(const_cast<MEDFileMeshStruct *>(mst));
1616 mstUnConstCasted->appendIfImplicitType(_geo_type);
1618 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1619 checkInRange(nbOfEnt,1,globs);
1622 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1624 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1625 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1626 checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1629 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1632 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1634 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1635 const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1636 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1637 checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1640 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1644 if(getPflName().empty())
1645 return (_start_end.second-_start_end.first)/_nb_of_entity;
1647 return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples();
1651 const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1652 return loc.getNumberOfGaussPoints();
1656 std::string MEDFileField1TSStructItem2::getPflName() const
1658 return _pfl->getName();
1661 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1663 if(!_pfl->isAllocated())
1665 if(_pfl->getName().empty())
1668 return globs->getProfile(_pfl->getName().c_str());
1675 * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
1676 * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1678 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1680 _nb_of_entity=nbOfEntity;
1681 if(_pfl->getName().empty())
1683 if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1684 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !");
1690 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1691 const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
1693 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1694 pfl->checkAllIdsInRange(0,nbOfEntity);
1698 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const std::string& pflName) const
1700 if(startExp!=_start_end.first)
1704 if(getPflName()!=pflName)
1706 startExp=_start_end.second;
1710 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const
1712 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1713 //idem for _loc. It is not an effective attribute for support comparison.
1714 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1717 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1719 if(_geo_type!=other._geo_type)
1721 if(_nb_of_entity!=other._nb_of_entity)
1723 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1725 if(_pfl->getName().empty() && other._pfl->getName().empty())
1727 const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1728 return pfl1->isEqualWithoutConsideringStr(*pfl2);
1731 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1733 return isCellSupportEqual(other,globs);
1737 * \a objs must be non empty. \a objs should contain items having same geometric type.
1739 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1742 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1744 return MEDFileField1TSStructItem2(*objs[0]);
1745 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1746 int nbEntityRef(objs[0]->_nb_of_entity);
1747 std::size_t sz(objs.size());
1748 std::vector<const DataArrayInt *> arrs(sz);
1749 for(std::size_t i=0;i<sz;i++)
1751 const MEDFileField1TSStructItem2 *obj(objs[i]);
1752 if(gt!=obj->_geo_type)
1753 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1754 if(nbEntityRef!=obj->_nb_of_entity)
1755 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1756 if(obj->_pfl->getName().empty())
1757 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1758 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1760 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
1762 int oldNbTuples(arr->getNumberOfTuples());
1763 arr=arr->buildUnique();
1764 if(oldNbTuples!=arr->getNumberOfTuples())
1765 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1766 if(arr->isIdentity() && oldNbTuples==nbEntityRef)
1768 std::pair<int,int> p(0,nbEntityRef);
1770 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1771 ret._nb_of_entity=nbEntityRef;
1776 arr->setName(NEWLY_CREATED_PFL_NAME);
1777 std::pair<int,int> p(0,oldNbTuples);
1779 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1780 ret._nb_of_entity=nbEntityRef;
1786 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1788 std::size_t ret(_loc.capacity());
1792 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildren() const
1794 std::vector<const BigMemoryObject *> ret;
1795 const DataArrayInt *pfl(_pfl);
1803 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1807 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1813 int nbOfEnt=mst->getNumberOfNodes();
1814 if(_items.size()!=1)
1815 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1816 _items[0].checkInRange(nbOfEnt,1,globs);
1821 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1822 (*it).checkWithMeshStructForCells(mst,globs);
1827 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1828 (*it).checkWithMeshStructForGaussNE(mst,globs);
1833 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1834 (*it).checkWithMeshStructForGaussPT(mst,globs);
1838 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1842 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const
1844 if(_type!=other._type)
1846 if(_items.size()!=other._items.size())
1848 for(std::size_t i=0;i<_items.size();i++)
1849 if(!(_items[i]==other._items[i]))
1854 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1856 if(_type!=other._type)
1858 if(_items.size()!=other._items.size())
1860 for(std::size_t i=0;i<_items.size();i++)
1861 if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1866 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1868 if(_type!=other._type)
1870 if(_items.size()!=other._items.size())
1872 for(std::size_t i=0;i<_items.size();i++)
1873 if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1878 bool MEDFileField1TSStructItem::isEntityCell() const
1889 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1890 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1892 INTERP_KERNEL::NormalizedCellType _geo_type;
1895 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1898 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1899 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1901 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1903 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1905 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1907 (*it0).second.push_back(i);
1909 if(m.size()==_items.size())
1911 MEDFileField1TSStructItem ret(*this);
1915 std::size_t sz(m.size());
1916 std::vector< MEDFileField1TSStructItem2 > items(sz);
1919 const std::vector<std::size_t>& ids=m[i].second;
1920 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1921 for(std::size_t j=0;j<ids.size();j++)
1922 objs[j]=&_items[ids[j]];
1923 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1925 MEDFileField1TSStructItem ret(ON_CELLS,items);
1931 * \a this is expected to be ON_CELLS and simplified.
1933 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1935 if(other._type!=ON_NODES)
1936 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1937 if(other._items.size()!=1)
1938 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1939 int theFirstLevFull;
1940 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1941 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1942 if(otherNodeIt.getPflName().empty())
1946 return theFirstLevFull==0;
1950 const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1951 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
1953 int nbOfNodes(meshSt->getNumberOfNodes());
1954 if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
1955 {//on all nodes also !
1958 return theFirstLevFull==0;
1960 std::vector<bool> nodesFetched(nbOfNodes,false);
1961 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1962 return cpyPfl->isFittingWith(nodesFetched);
1966 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1969 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1971 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1972 int nbOfLevs(meshSt->getNumberOfLevs());
1974 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1975 std::vector<int> levs(nbOfLevs);
1977 std::set<INTERP_KERNEL::NormalizedCellType> gts;
1978 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1980 if(!(*it).getPflName().empty())
1982 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1983 if(gts.find(gt)!=gts.end())
1984 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1986 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1989 for(int i=0;i<nbOfLevs;i++)
1990 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
1991 { theFirstLevFull=-i; return true; }
1995 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const
1997 if(i>=_items.size())
1998 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
2002 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
2004 std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
2008 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildren() const
2010 std::vector<const BigMemoryObject *> ret;
2011 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2012 ret.push_back(&(*it));
2016 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2018 std::size_t sz(_items.size());
2019 std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
2020 std::vector<const DataArrayInt *> a1(sz);
2021 std::vector<int> a2(sz);
2023 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
2025 a0[i]=(*it).getGeo();
2026 a1[i]=(*it).getPfl(globs);
2027 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
2029 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
2032 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStructItem::getGeoTypes(const MEDFileMesh *m) const
2034 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2037 if(!_items.empty() && _items[0].getPflName().empty())
2040 return m->getAllGeoTypes();
2047 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2049 INTERP_KERNEL::NormalizedCellType elt((*it).getGeo());
2050 std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it2(std::find(ret.begin(),ret.end(),elt));
2057 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
2060 std::vector< MEDFileField1TSStructItem2 > anItems;
2062 std::vector< std::vector<std::string> > pfls,locs;
2063 std::vector< std::vector<TypeOfField> > typesF;
2064 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2065 std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(std::string(),geoTypes,typesF,pfls,locs);
2066 std::size_t nbOfGeoTypes(geoTypes.size());
2068 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
2070 for(std::size_t i=0;i<nbOfGeoTypes;i++)
2072 std::size_t sz=typesF[i].size();
2073 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
2074 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
2080 for(std::size_t j=0;j<sz;j++)
2082 if(atype==typesF[i][j])
2083 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
2085 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
2088 MEDFileField1TSStructItem ret(atype,anItems);
2089 ret.checkWithMeshStruct(meshSt,ref);
2095 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2097 return new MEDFileField1TSStruct(ref,mst);
2100 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2102 _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
2105 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
2107 if(_already_checked.empty())
2108 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
2109 _already_checked.back().checkWithMeshStruct(mst,globs);
2112 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
2114 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
2115 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2124 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
2126 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2128 if(_already_checked.empty())
2129 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
2130 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2131 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
2132 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
2133 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
2135 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2136 if((*it).isComputed())
2141 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2142 ret=this1.isCellSupportEqual(other1,other);
2144 _already_checked.push_back(this1);
2147 ret=_already_checked[found].isCellSupportEqual(other1,other);
2149 _already_checked.push_back(b);
2154 * \param [in] other - a field with only one spatial discretization : ON_NODES.
2156 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2158 if(_already_checked.empty())
2159 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
2160 MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2161 if(_already_checked[0].isEntityCell())
2164 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2165 if((*it).isComputed())
2170 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2171 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
2173 _already_checked.push_back(this1);
2176 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
2178 _already_checked.push_back(other1);
2182 return _already_checked[0].isNodeSupportEqual(other1,other);
2185 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
2187 std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
2191 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildren() const
2193 std::vector<const BigMemoryObject *> ret;
2194 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2195 ret.push_back(&(*it));
2199 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2201 if(_already_checked.empty())
2202 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
2203 int pos0(-1),pos1(-1);
2204 if(presenceOfCellDiscr(pos0))
2206 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
2207 if(presenceOfPartialNodeDiscr(pos1))
2208 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
2213 if(!presenceOfPartialNodeDiscr(pos1))
2214 {//we have only all nodes, no cell definition info -> all existing levels !;
2215 return MEDMeshMultiLev::New(mst->getTheMesh(),mst->getTheMesh()->getNonEmptyLevels());
2218 return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
2222 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
2225 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
2227 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
2228 if(a0!=c0 || a1!=c1)
2231 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
2234 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
2239 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStruct::getGeoTypes(const MEDFileMesh *m) const
2241 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2242 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2244 std::vector<INTERP_KERNEL::NormalizedCellType> ret2((*it).getGeoTypes(m));
2245 for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator it2=ret2.begin();it2!=ret2.end();it2++)
2247 if(*it2==INTERP_KERNEL::NORM_ERROR)
2249 std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it3(std::find(ret.begin(),ret.end(),*it2));
2251 ret.push_back(*it2);
2258 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
2259 * If true is returned the pos of the easiest is returned. The easiest is the first element in \a this having the less splitted subparts.
2261 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
2263 std::size_t refSz(std::numeric_limits<std::size_t>::max());
2266 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2268 if((*it).getType()!=ON_NODES)
2271 std::size_t sz((*it).getNumberOfItems());
2273 { pos=i; refSz=sz; }
2277 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
2282 * Returns true if presence in \a this of discretization ON_NODES.
2283 * If true is returned the pos of the first element containing the single subpart.
2285 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
2288 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2290 if((*it).getType()==ON_NODES)
2292 std::size_t sz((*it).getNumberOfItems());
2295 if(!(*it)[0].getPflName().empty())
2296 { pos=i; return true; }
2299 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
2307 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2309 return new MEDFileFastCellSupportComparator(m,ref);
2312 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2315 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
2316 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
2317 int nbPts=ref->getNumberOfTS();
2318 _f1ts_cmps.resize(nbPts);
2319 for(int i=0;i<nbPts;i++)
2321 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
2322 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
2323 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
2327 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
2329 std::size_t ret(_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>));
2333 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildren() const
2335 std::vector<const BigMemoryObject *> ret;
2336 const MEDFileMeshStruct *mst(_mesh_comp);
2339 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
2341 const MEDFileField1TSStruct *cur(*it);
2348 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
2350 int nbPts=other->getNumberOfTS();
2351 if(nbPts!=(int)_f1ts_cmps.size())
2353 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2354 throw INTERP_KERNEL::Exception(oss.str().c_str());
2356 for(int i=0;i<nbPts;i++)
2358 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2359 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
2360 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
2366 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
2368 int nbPts=other->getNumberOfTS();
2369 if(nbPts!=(int)_f1ts_cmps.size())
2371 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2372 throw INTERP_KERNEL::Exception(oss.str().c_str());
2374 for(int i=0;i<nbPts;i++)
2376 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2377 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
2383 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2385 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2387 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2388 throw INTERP_KERNEL::Exception(oss.str().c_str());
2390 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2393 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
2394 throw INTERP_KERNEL::Exception(oss.str().c_str());
2396 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
2399 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2401 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
2403 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
2404 throw INTERP_KERNEL::Exception(oss.str().c_str());
2406 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2407 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
2408 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
2411 int MEDFileFastCellSupportComparator::getNumberOfTS() const
2413 return _f1ts_cmps.size();
2416 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileFastCellSupportComparator::getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const
2418 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2420 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2421 throw INTERP_KERNEL::Exception(oss.str().c_str());
2423 const MEDFileField1TSStruct *elt(_f1ts_cmps[timeStepId]);
2426 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " points to a NULL pointer !";
2427 throw INTERP_KERNEL::Exception(oss.str().c_str());
2429 return elt->getGeoTypes(m);