1 // Copyright (C) 2007-2015 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 "MEDCouplingFieldDiscretization.hxx"
26 #include "CellModel.hxx"
28 using namespace ParaMEDMEM;
30 const unsigned char MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE[MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE_LGTH]=
31 {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};
33 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};
35 const char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???";
37 MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh)
39 return new MEDFileMeshStruct(mesh);
42 std::size_t MEDFileMeshStruct::getHeapMemorySizeWithoutChildren() const
45 for(std::vector< std::vector<int> >::const_iterator it0=_geo_types_distrib.begin();it0!=_geo_types_distrib.end();it0++)
46 ret+=(*it0).capacity()*sizeof(int);
47 ret+=_geo_types_distrib.capacity()*sizeof(std::vector<int>);
51 std::vector<const BigMemoryObject *> MEDFileMeshStruct::getDirectChildrenWithNull() const
53 return std::vector<const BigMemoryObject *>();
56 MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh)
58 std::vector<int> levs(mesh->getNonEmptyLevels());
59 _name=mesh->getName();
60 _nb_nodes=mesh->getNumberOfNodes();
63 _geo_types_distrib.resize(-(*std::min_element(levs.begin(),levs.end()))+1);
64 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
65 _geo_types_distrib[-(*lev)]=mesh->getDistributionOfTypes(*lev);
69 int MEDFileMeshStruct::getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
72 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++,j--)
74 std::size_t sz=(*it1).size();
76 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : internal error in code !");
77 std::size_t nbGeo=sz/3;
78 for(std::size_t i=0;i<nbGeo;i++)
79 if((*it1)[3*i]==(int)t)
82 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : The specified geometric type is not present in the mesh structure !");
86 * \sa MEDFileMeshStruct::doesManageGeoType
88 int MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
90 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
92 std::size_t sz=(*it1).size();
94 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !");
95 std::size_t nbGeo=sz/3;
96 for(std::size_t i=0;i<nbGeo;i++)
97 if((*it1)[3*i]==(int)t)
100 throw INTERP_KERNEL::Exception("The specified geometric type is not present in the mesh structure !");
104 * \sa MEDFileMeshStruct::getNumberOfElemsOfGeoType
106 bool MEDFileMeshStruct::doesManageGeoType(INTERP_KERNEL::NormalizedCellType t) const
108 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
110 std::size_t sz=(*it1).size();
112 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::doesManageGeoType : internal error in code !");
113 std::size_t nbGeo=sz/3;
114 for(std::size_t i=0;i<nbGeo;i++)
115 if((*it1)[3*i]==(int)t)
121 void MEDFileMeshStruct::appendIfImplicitType(INTERP_KERNEL::NormalizedCellType t)
123 if(!_mesh->hasImplicitPart())
124 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::appendIfImplicitType : by default no implicit geo type can be appended !");
125 static const char MSG[]="MEDFileMeshStruct::appendIfImplicitType : the distribution does not looks like structured standard !";
126 if(_geo_types_distrib.size()!=1)
127 throw INTERP_KERNEL::Exception(MSG);
128 std::size_t sz(_geo_types_distrib[0].size());
130 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::appendIfImplicitType : internal error in code !");
131 std::size_t nbGeo(sz/3);
133 throw INTERP_KERNEL::Exception(MSG);
134 std::vector<int> arr(3); arr[0]=(int)t; arr[1]=_mesh->buildImplicitPartIfAny(t); arr[2]=-1;
135 _geo_types_distrib.push_back(arr);
139 int MEDFileMeshStruct::getNumberOfLevs() const
141 return (int)_geo_types_distrib.size();
144 int MEDFileMeshStruct::getNumberOfGeoTypesInLev(int relativeLev) const
146 int pos(-relativeLev);
147 if(pos<0 || pos>=(int)_geo_types_distrib.size())
148 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : invalid level specified !");
149 std::size_t sz=_geo_types_distrib[pos].size();
151 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : internal error in code !");
157 std::size_t MEDMeshMultiLev::getHeapMemorySizeWithoutChildren() const
162 std::vector<const BigMemoryObject *> MEDMeshMultiLev::getDirectChildrenWithNull() const
164 return std::vector<const BigMemoryObject *>();
167 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs)
170 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
171 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
173 return MEDUMeshMultiLev::New(um,levs);
174 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
176 return MEDCMeshMultiLev::New(cm,levs);
177 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
179 return MEDCurveLinearMeshMultiLev::New(clm,levs);
180 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
183 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
186 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
187 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
189 return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
190 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
192 return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
193 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
195 return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
196 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
199 MEDMeshMultiLev *MEDMeshMultiLev::NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode)
201 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,m->getNonEmptyLevels()));
202 ret->selectPartOfNodes(pflOnNode);
206 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
210 _node_reduction=const_cast<DataArrayInt*>(nr);
213 void MEDMeshMultiLev::setCellReduction(const DataArrayInt *cr)
216 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::setCellReduction : can be used only for single geo type mesh !");
217 _pfls[0]=const_cast<DataArrayInt*>(cr);
222 bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const
224 if(fst.getType()==ON_NODES)
226 if(fst.getNumberOfItems()!=1)
227 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::isFastlyTheSameStruct : unexpected situation for nodes !");
228 const MEDFileField1TSStructItem2& p(fst[0]);
229 std::string pflName(p.getPflName());
230 const DataArrayInt *nr(_node_reduction);
231 if(pflName.empty() && !nr)
233 if(!pflName.empty() && !nr)
235 if(pflName==nr->getName())
241 std::size_t sz(fst.getNumberOfItems());
242 if(sz!=_geo_types.size())
245 for(std::size_t i=0;i<sz;i++)
247 const MEDFileField1TSStructItem2& p(fst[i]);
248 if(!p.isFastlyEqual(strt,_geo_types[i],getPflNameOfId(i).c_str()))
255 DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
257 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(const_cast<DataArray *>(vals)); ret->incrRef();
258 if(isFastlyTheSameStruct(fst,globs))
261 return constructDataArray(fst,globs,vals);
265 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
266 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
268 void MEDMeshMultiLev::retrieveFamilyIdsOnCells(DataArrayInt *& famIds, bool& isWithoutCopy) const
270 const DataArrayInt *fids(_cell_fam_ids);
272 { famIds=0; isWithoutCopy=true; return ; }
273 std::size_t sz(_geo_types.size());
274 bool presenceOfPfls(false);
275 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
277 const DataArrayInt *pfl(_pfls[i]);
282 { famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef(); isWithoutCopy=_mesh->isObjectInTheProgeny(famIds); return ; }
283 //bad luck the slowest part
285 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
286 std::vector< const DataArrayInt *> ret(sz);
288 for(std::size_t i=0;i<sz;i++)
290 const DataArrayInt *pfl(_pfls[i]);
291 int lgth(_nb_entities[i]);
294 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(fids->selectByTupleId2(start,start+lgth,1));
295 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
299 retSafe[i]=fids->selectByTupleId2(start,start+lgth,1);
304 famIds=DataArrayInt::Aggregate(ret);
308 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
309 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
311 void MEDMeshMultiLev::retrieveNumberIdsOnCells(DataArrayInt *& numIds, bool& isWithoutCopy) const
313 const DataArrayInt *nids(_cell_num_ids);
315 { numIds=0; isWithoutCopy=true; return ; }
316 std::size_t sz(_geo_types.size());
317 bool presenceOfPfls(false);
318 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
320 const DataArrayInt *pfl(_pfls[i]);
325 { numIds=const_cast<DataArrayInt *>(nids); numIds->incrRef(); isWithoutCopy=_mesh->isObjectInTheProgeny(numIds); return ; }
326 //bad luck the slowest part
328 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
329 std::vector< const DataArrayInt *> ret(sz);
331 for(std::size_t i=0;i<sz;i++)
333 const DataArrayInt *pfl(_pfls[i]);
334 int lgth(_nb_entities[i]);
337 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(nids->selectByTupleId2(start,start+lgth,1));
338 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
342 retSafe[i]=nids->selectByTupleId2(start,start+lgth,1);
347 numIds=DataArrayInt::Aggregate(ret);
351 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
352 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
354 void MEDMeshMultiLev::retrieveFamilyIdsOnNodes(DataArrayInt *& famIds, bool& isWithoutCopy) const
356 const DataArrayInt *fids(_node_fam_ids);
358 { famIds=0; isWithoutCopy=true; return ; }
359 const DataArrayInt *nr(_node_reduction);
363 famIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
367 famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef();
368 isWithoutCopy=_mesh->isObjectInTheProgeny(famIds);
373 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
374 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
376 void MEDMeshMultiLev::retrieveNumberIdsOnNodes(DataArrayInt *& numIds, bool& isWithoutCopy) const
378 const DataArrayInt *fids(_node_num_ids);
380 { numIds=0; isWithoutCopy=true; return ; }
381 const DataArrayInt *nr(_node_reduction);
385 numIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
389 numIds=const_cast<DataArrayInt *>(fids); numIds->incrRef();
390 isWithoutCopy=_mesh->isObjectInTheProgeny(numIds);
394 std::vector< INTERP_KERNEL::NormalizedCellType > MEDMeshMultiLev::getGeoTypes() const
399 void MEDMeshMultiLev::setFamilyIdsOnCells(DataArrayInt *famIds)
401 _cell_fam_ids=famIds;
406 void MEDMeshMultiLev::setNumberIdsOnCells(DataArrayInt *numIds)
408 _cell_num_ids=numIds;
413 void MEDMeshMultiLev::setFamilyIdsOnNodes(DataArrayInt *famIds)
415 _node_fam_ids=famIds;
420 void MEDMeshMultiLev::setNumberIdsOnNodes(DataArrayInt *numIds)
422 _node_num_ids=numIds;
427 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
429 std::size_t sz(_pfls.size());
430 if(id<0 || id>=(int)sz)
431 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
432 const DataArrayInt *pfl(_pfls[id]);
434 return std::string("");
435 return pfl->getName();
439 * Returns the number of cells having geometric type \a t.
440 * The profiles are **NOT** taken into account here.
442 int MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
444 std::size_t sz(_nb_entities.size());
445 for(std::size_t i=0;i<sz;i++)
447 return _nb_entities[i];
448 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
451 int MEDMeshMultiLev::getNumberOfNodes() const
456 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
458 if(fst.getType()==ON_NODES)
460 if(fst.getNumberOfItems()!=1)
461 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
462 const MEDFileField1TSStructItem2& p(fst[0]);
463 std::string pflName(p.getPflName());
464 const DataArrayInt *nr(_node_reduction);
465 if(pflName.empty() && !nr)
466 return vals->deepCpy();
467 if(pflName.empty() && nr)
468 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
469 if(!pflName.empty() && nr)
471 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
472 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(nr->deepCpy());
473 p1->sort(true); p2->sort(true);
474 if(!p1->isEqualWithoutConsideringStr(*p2))
475 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : it appears that a profile on nodes does not cover the cells correctly !");
476 p1=DataArrayInt::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
477 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
478 ret->renumberInPlace(p1->begin());
481 if(!pflName.empty() && !nr)
483 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
485 if(!p1->isIdentity() || p1->getNumberOfTuples()!=getNumberOfNodes())
486 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
487 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
488 ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
491 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
495 std::size_t sz(fst.getNumberOfItems());
496 std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
497 if(s.size()!=_geo_types.size())
498 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
499 std::vector< const DataArray *> arr(s.size());
500 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arrSafe(s.size());
502 int nc(vals->getNumberOfComponents());
503 std::vector<std::string> compInfo(vals->getInfoOnComponents());
504 for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
506 const DataArrayInt *thisP(_pfls[iii]);
507 std::vector<const MEDFileField1TSStructItem2 *> ps;
508 for(std::size_t i=0;i<sz;i++)
510 const MEDFileField1TSStructItem2& p(fst[i]);
515 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
518 int nbi(ps[0]->getNbOfIntegrationPts(globs));
519 const DataArrayInt *otherP(ps[0]->getPfl(globs));
520 const std::pair<int,int>& strtStop(ps[0]->getStartStop());
521 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
522 if(!thisP && !otherP)
524 arrSafe[iii]=ret; arr[iii]=ret;
529 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
530 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(thisP->deepCpy());
531 p2->transformWithIndArr(p1->begin(),p1->end());
532 //p1=p2->getIdsNotEqual(-1);
533 //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
534 ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
535 arrSafe[iii]=ret; arr[iii]=ret;
540 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->deepCpy());
542 p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
543 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,p1);
544 ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
545 arrSafe[iii]=ret; arr[iii]=ret;
548 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
552 std::vector< const DataArrayInt * >otherPS(ps.size());
553 std::vector< const DataArray * > arr2(ps.size());
554 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arr2Safe(ps.size());
555 std::vector< const DataArrayInt * > nbis(ps.size());
556 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > nbisSafe(ps.size());
558 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
560 int nbi((*it2)->getNbOfIntegrationPts(globs));
561 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
562 const std::pair<int,int>& strtStop((*it2)->getStartStop());
563 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
565 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
566 arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
567 nbisSafe[jj]=DataArrayInt::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
568 nbis[jj]=nbisSafe[jj];
570 MEDCouplingAutoRefCountObjectPtr<DataArray> arr3(DataArray::Aggregate(arr2));
571 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherP(DataArrayInt::Aggregate(otherPS));
572 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbis(DataArrayInt::Aggregate(nbis));
573 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
574 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1;
576 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,thisP);
578 p1=otherP->deepCpy();
579 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbisN(zenbis->renumber(p1->begin()));
580 zenbisN->computeOffsets2();
582 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
584 //int nbi((*it2)->getNbOfIntegrationPts(globs));
585 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
586 const std::pair<int,int>& strtStop((*it2)->getStartStop());
587 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
589 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(otherPfl->deepCpy());
590 p2->transformWithIndArr(otherPN->begin(),otherPN->end());
591 p2->transformWithIndArr(p1->begin(),p1->end());
592 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsN(p2->buildExplicitArrByRanges(zenbisN));
593 arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
595 arrSafe[iii]=arr3; arr[iii]=arr3;
599 return DataArray::Aggregate(arr);
604 * This method is called to add NORM_POINT1 cells in \a this so that orphan nodes in \a verticesToAdd will be fetched.
606 void MEDMeshMultiLev::appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr)
608 int nbOfVertices(verticesToAdd->getNumberOfTuples());
609 std::size_t sz(_pfls.size());
611 _geo_types.resize(sz+1,INTERP_KERNEL::NORM_POINT1);
612 _nb_entities.resize(sz+1,nbOfVertices);
613 _node_reduction=nr; nr->incrRef();
614 _nb_nodes+=nbOfVertices;
615 const DataArrayInt *cf(_cell_fam_ids),*cn(_cell_num_ids),*nf(_node_fam_ids),*nn(_node_num_ids);
618 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp;
619 std::vector<const DataArrayInt *> a(2);
622 tmp=nf->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
625 tmp=DataArrayInt::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
628 _cell_fam_ids=DataArrayInt::Aggregate(a);
632 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp;
633 std::vector<const DataArrayInt *> a(2);
636 tmp=nn->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
639 tmp=DataArrayInt::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
642 _cell_num_ids=DataArrayInt::Aggregate(a);
646 MEDMeshMultiLev::MEDMeshMultiLev(const MEDFileMesh *mesh):_mesh(mesh),_nb_nodes(0)
650 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)
652 std::size_t sz(_geo_types.size());
653 if(sz!=pfls.size() || sz!=nbEntities.size())
654 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
656 for(std::size_t i=0;i<sz;i++)
660 _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
664 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_num_ids(other._cell_num_ids),_node_fam_ids(other._node_fam_ids),_node_num_ids(other._node_num_ids)
670 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
672 return new MEDUMeshMultiLev(m,levs);
675 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs):MEDMeshMultiLev(m)
678 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
679 std::vector<MEDCoupling1GTUMesh *> v;
680 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
682 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
683 v.insert(v.end(),vTmp.begin(),vTmp.end());
685 std::size_t sz(v.size());
688 _coords=m->getCoords(); _coords->incrRef();
692 _geo_types.resize(sz);
693 _nb_entities.resize(sz);
694 for(std::size_t i=0;i<sz;i++)
696 MEDCoupling1GTUMesh *obj(v[i]);
700 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
702 _geo_types[i]=obj->getCellModelEnum();
703 _nb_entities[i]=obj->getNumberOfCells();
705 // ids fields management
706 bool cellFamIdsNoCpy(levs.size()==1);
709 const DataArrayInt *tmp(m->getFamilyFieldAtLevel(levs[0]));
713 _cell_fam_ids=(const_cast<DataArrayInt *>(tmp));
718 std::vector<const DataArrayInt *> tmps(levs.size());
720 for(std::size_t i=0;i<levs.size();i++)
722 tmps[i]=m->getFamilyFieldAtLevel(levs[i]);
726 if(f && !tmps.empty())
727 _cell_fam_ids=DataArrayInt::Aggregate(tmps);
729 bool cellNumIdsNoCpy(levs.size()==1);
732 const DataArrayInt *tmp(m->getNumberFieldAtLevel(levs[0]));
736 _cell_num_ids=(const_cast<DataArrayInt *>(tmp));
741 std::vector<const DataArrayInt *> tmps(levs.size());
743 for(std::size_t i=0;i<levs.size();i++)
745 tmps[i]=m->getNumberFieldAtLevel(levs[i]);
749 if(n && !tmps.empty())
750 _cell_num_ids=DataArrayInt::Aggregate(tmps);
754 const DataArrayInt *tmp(m->getFamilyFieldAtLevel(1));
758 _node_fam_ids=(const_cast<DataArrayInt *>(tmp));
762 const DataArrayInt *tmp(m->getNumberFieldAtLevel(1));
766 _node_num_ids=(const_cast<DataArrayInt *>(tmp));
771 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
773 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
776 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)
778 std::size_t sz(gts.size());
780 throw INTERP_KERNEL::Exception("constructor of MEDUMeshMultiLev : number of different geo type must be >= 1 !");
781 unsigned dim(INTERP_KERNEL::CellModel::GetCellModel(gts[0]).getDimension());
783 bool isSameDim(true),isNoPfl(true);
784 for(std::size_t i=0;i<sz;i++)
786 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
787 if(INTERP_KERNEL::CellModel::GetCellModel(gts[i]).getDimension()!=dim)
795 // ids fields management
796 int lev((int)dim-m->getMeshDimension());
797 if(isSameDim && isNoPfl && m->getGeoTypesAtLevel(lev)==gts)//optimized part
799 const DataArrayInt *famIds(m->getFamilyFieldAtLevel(lev));
801 { _cell_fam_ids=const_cast<DataArrayInt*>(famIds); famIds->incrRef(); }
802 const DataArrayInt *numIds(m->getNumberFieldAtLevel(lev));
804 { _cell_num_ids=const_cast<DataArrayInt*>(numIds); numIds->incrRef(); }
805 famIds=m->getFamilyFieldAtLevel(1);
807 { _node_fam_ids=const_cast<DataArrayInt*>(famIds); famIds->incrRef(); }
808 numIds=m->getNumberFieldAtLevel(1);
810 { _node_num_ids=const_cast<DataArrayInt*>(numIds); numIds->incrRef(); }
814 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > famIdsSafe(sz);
815 std::vector<const DataArrayInt *> famIds(sz);
817 for(std::size_t i=0;i<sz;i++)
819 famIdsSafe[i]=m->extractFamilyFieldOnGeoType(gts[i]);
820 famIds[i]=famIdsSafe[i];
825 _cell_fam_ids=DataArrayInt::Aggregate(famIds);
826 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > numIdsSafe(sz);
827 std::vector<const DataArrayInt *> numIds(sz);
829 for(std::size_t i=0;i<sz;i++)
831 numIdsSafe[i]=m->extractNumberFieldOnGeoType(gts[i]);
832 numIds[i]=numIdsSafe[i];
837 _cell_num_ids=DataArrayInt::Aggregate(numIds);
838 // node ids management
839 const DataArrayInt *nodeFamIds(m->getFamilyFieldAtLevel(1));
841 { _node_fam_ids=const_cast<DataArrayInt*>(nodeFamIds); nodeFamIds->incrRef(); }
842 const DataArrayInt *nodeNumIds(m->getNumberFieldAtLevel(1));
844 { _node_num_ids=const_cast<DataArrayInt*>(nodeNumIds); nodeNumIds->incrRef(); }
847 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
849 if(!pflNodes || !pflNodes->isAllocated())
851 std::size_t sz(_parts.size());
852 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
853 std::vector< const DataArrayInt *> aa(sz);
854 for(std::size_t i=0;i<sz;i++)
856 const DataArrayInt *pfl(_pfls[i]);
857 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
859 m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
860 DataArrayInt *cellIds=0;
861 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
862 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
863 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
865 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m2->getNodeIdsInUse(tmp));
866 a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
868 _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
870 _pfls[i]=cellIdsSafe;
873 _node_reduction=DataArrayInt::Aggregate(aa);//general case
875 _node_reduction=pflNodes->deepCpy();//case where no cells in read mesh.
876 _node_reduction->sort(true);
877 _node_reduction=_node_reduction->buildUnique();
878 if(_node_reduction->getNumberOfTuples()==pflNodes->getNumberOfTuples())
879 return ;//This is the classical case where the input node profile corresponds perfectly to a subset of cells in _parts
880 if(_node_reduction->getNumberOfTuples()>pflNodes->getNumberOfTuples())
881 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::selectPartOfNodes : internal error in MEDCoupling during cell select from a list of nodes !");
882 // Here the cells available in _parts is not enough to cover all the nodes in pflNodes. So adding vertices cells in _parts...
883 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> pflNodes2(pflNodes->deepCpy());
884 pflNodes2->sort(true);
885 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diff(pflNodes2->buildSubstractionOptimized(_node_reduction));
886 appendVertices(diff,pflNodes2);
889 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
891 return new MEDUMeshMultiLev(*this);
894 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts),_coords(other._coords)
898 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
902 _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
903 _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
904 _pfls.resize(1); _pfls[0]=0;
908 * To be called only once ! Because due to some optimizations (sometimes aggressive) the internal state can be changed...
909 * 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.
910 * 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.
912 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const
914 const DataArrayDouble *tmp(0);
918 tmp=_parts[0]->getCoords();
920 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
921 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
922 int szBCE(0),szD(0),szF(0);
925 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
927 const MEDCoupling1GTUMesh *cur(*it);
929 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
931 const DataArrayInt *pfl(_pfls[iii]);
932 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
934 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
936 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
938 int curNbCells(cur->getNumberOfCells());
940 if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
941 szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
945 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(cur->computeEffectiveNbOfNodesPerCell());
946 szD+=tmp2->accumulate(0)+curNbCells;
947 szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
950 MEDCouplingAutoRefCountObjectPtr<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
951 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()); c->alloc(szBCE,1); int *cPtr(c->getPointer());
952 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d(DataArrayInt::New()); d->alloc(szD,1); int *dPtr(d->getPointer());
953 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> e(DataArrayInt::New()),f(DataArrayInt::New()); int *ePtr(0),*fPtr(0);
955 { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
958 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
960 const MEDCoupling1GTUMesh *cur(*it);
962 const DataArrayInt *pfl(_pfls[iii]);
963 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
965 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
967 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
969 int curNbCells(cur->getNumberOfCells());
970 int gt((int)cur->getCellModelEnum());
971 if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
972 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
973 unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
975 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
976 std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
977 const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
978 const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
979 const int *connPtr(cur->getNodalConnectivity()->begin());
981 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
984 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA27)
986 int nnpc(scur->getNumberOfNodesPerCell());
987 for(int i=0;i<curNbCells;i++,connPtr+=nnpc)
990 dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
991 *cPtr++=k; k+=nnpc+1;
996 for(int i=0;i<curNbCells;i++,connPtr+=27)
999 for(int j=0;j<27;j++,dPtr++)
1000 *dPtr=connPtr[HEXA27_PERM_ARRAY[j]];
1005 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1009 const int *connIPtr(dcur->getNodalConnectivityIndex()->begin());
1010 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1012 for(int i=0;i<curNbCells;i++,connIPtr++)
1014 *dPtr++=connIPtr[1]-connIPtr[0];
1015 dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
1016 *cPtr++=k; k+=connIPtr[1]-connIPtr[0]+1;
1021 for(int i=0;i<curNbCells;i++,connIPtr++)
1023 std::set<int> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
1024 *dPtr++=(int)s.size();
1025 dPtr=std::copy(s.begin(),s.end(),dPtr);
1026 *cPtr++=k; k+=(int)s.size()+1;
1031 connIPtr=dcur->getNodalConnectivityIndex()->begin();
1032 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1033 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1037 for(int i=0;i<curNbCells;i++,connIPtr++)
1039 int nbFace(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1);
1041 const int *work(connPtr+connIPtr[0]);
1042 for(int j=0;j<nbFace;j++)
1044 const int *work2=std::find(work,connPtr+connIPtr[1],-1);
1045 *fPtr++=std::distance(work,work2);
1046 fPtr=std::copy(work,work2,fPtr);
1049 *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
1056 reorderNodesIfNecessary(a,d,0);
1058 reorderNodesIfNecessary(a,d,f);
1059 if(a->getNumberOfComponents()!=3)
1060 a=a->changeNbOfComponents(3,0.);
1061 coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
1063 { faceLocations=0; faces=0; }
1065 { faceLocations=e.retn(); faces=f.retn(); }
1066 return _mesh->isObjectInTheProgeny(coords);
1069 void MEDUMeshMultiLev::reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const
1071 const DataArrayInt *nr(_node_reduction);
1074 if(nodalConnVTK->empty() && !polyhedNodalConnVTK)
1076 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1079 int sz(coords->getNumberOfTuples());
1080 std::vector<bool> b(sz,false);
1081 const int *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
1085 for(int i=0;i<nb && work!=endW;i++,work++)
1087 if(*work>=0 && *work<sz)
1090 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
1093 if(polyhedNodalConnVTK)
1095 work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
1099 for(int i=0;i<nb && work!=endW;i++)
1102 for(int j=0;j<nb2 && work!=endW;j++,work++)
1104 if(*work>=0 && *work<sz)
1107 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
1112 int szExp(std::count(b.begin(),b.end(),true));
1113 if(szExp!=nr->getNumberOfTuples())
1114 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
1116 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(DataArrayInt::New()); o2n->alloc(sz,1);
1117 int *o2nPtr(o2n->getPointer());
1119 for(int i=0;i<sz;i++,o2nPtr++)
1120 if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
1121 const int *o2nPtrc(o2n->begin());
1122 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
1123 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> perm(DataArrayInt::FindPermutationFromFirstToSecond(n2o,nr));
1124 const int *permPtr(perm->begin());
1125 int *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
1129 for(int i=0;i<nb && work2!=endW2;i++,work2++)
1130 *work2=permPtr[o2nPtrc[*work2]];
1132 if(polyhedNodalConnVTK)
1134 work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
1138 for(int i=0;i<nb && work2!=endW2;i++)
1141 for(int j=0;j<nb2 && work2!=endW2;j++,work2++)
1142 *work2=permPtr[o2nPtrc[*work2]];
1146 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1150 void MEDUMeshMultiLev::appendVertices(const DataArrayInt *verticesToAdd, DataArrayInt *nr)
1152 int nbOfCells(verticesToAdd->getNumberOfTuples());//it is not a bug cells are NORM_POINT1
1153 MEDMeshMultiLev::appendVertices(verticesToAdd,nr);
1154 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> elt(MEDCoupling1SGTUMesh::New("",INTERP_KERNEL::NORM_POINT1));
1155 elt->allocateCells(nbOfCells);
1156 for(int i=0;i<nbOfCells;i++)
1158 int pt(verticesToAdd->getIJ(i,0));
1159 elt->insertNextCell(&pt,&pt+1);
1162 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::appendVertices : parts are empty !");
1163 elt->setCoords(_parts[0]->getCoords());
1164 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> elt2((MEDCoupling1SGTUMesh *)elt); elt2->incrRef();
1165 _parts.push_back(elt2);
1170 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector<int>& lev):MEDMeshMultiLev(m),_is_internal(true)
1172 initStdFieldOfIntegers(m);
1175 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)
1177 initStdFieldOfIntegers(m);
1180 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other),_is_internal(true),_face_fam_ids(other._face_fam_ids),_face_num_ids(other._face_num_ids)
1184 void MEDStructuredMeshMultiLev::initStdFieldOfIntegers(const MEDFileStructuredMesh *m)
1186 // ids fields management
1187 const DataArrayInt *tmp(0);
1188 tmp=m->getFamilyFieldAtLevel(0);
1192 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1194 tmp=m->getNumberFieldAtLevel(0);
1198 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1202 tmp=m->getFamilyFieldAtLevel(1);
1206 _node_fam_ids=const_cast<DataArrayInt *>(tmp);
1208 tmp=m->getNumberFieldAtLevel(1);
1212 _node_num_ids=const_cast<DataArrayInt *>(tmp);
1215 tmp=m->getFamilyFieldAtLevel(-1);
1219 _face_fam_ids=const_cast<DataArrayInt *>(tmp);
1221 tmp=m->getNumberFieldAtLevel(-1);
1225 _face_num_ids=const_cast<DataArrayInt *>(tmp);
1229 void MEDStructuredMeshMultiLev::moveFaceToCell() const
1231 const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_fam_ids=_face_fam_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_fam_ids=0;
1232 const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_num_ids=_face_num_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_num_ids=0;
1235 bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const
1238 if(_geo_types.empty())
1240 if(_geo_types.size()!=1)
1241 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase only one geo types supported at most supported for the moment !");
1242 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(_mesh->getMeshDimension()));
1243 if(_geo_types[0]==gt)
1245 MEDCoupling1GTUMesh *facesIfPresent((static_cast<const MEDFileStructuredMesh *>(_mesh))->getImplicitFaceMesh());
1248 const DataArrayInt *pfl(0),*nr(_node_reduction);
1251 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> facesIfPresent2(facesIfPresent); facesIfPresent->incrRef();
1253 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret2(new MEDUMeshMultiLev(*this,facesIfPresent2));
1255 ret2->setCellReduction(pfl);
1257 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for node reduction on implicit unstructured mesh.");
1262 void MEDStructuredMeshMultiLev::dealWithImplicitUnstructuredMesh(const MEDFileMesh *m)
1264 const DataArrayInt *tmp(0);
1265 tmp=m->getFamilyFieldAtLevel(-1);
1269 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1271 tmp=m->getNumberFieldAtLevel(-1);
1275 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1279 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
1281 if(!pflNodes || !pflNodes->isAllocated())
1283 std::vector<int> ngs(getNodeGridStructure());
1284 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1285 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
1286 m->setNodalConnectivity(conn);
1287 const DataArrayInt *pfl(_pfls[0]);
1290 m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1292 DataArrayInt *cellIds=0;
1293 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1294 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
1295 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1297 _node_reduction=m2->getNodeIdsInUse(tmp);
1299 _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1301 _pfls[0]=cellIdsSafe;
1306 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
1308 return new MEDCMeshMultiLev(m,levs);
1311 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1313 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
1316 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1319 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
1320 if(levs.size()!=1 || levs[0]!=0)
1321 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
1322 int sdim(m->getSpaceDimension());
1323 _coords.resize(sdim);
1324 for(int i=0;i<sdim;i++)
1326 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1328 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1334 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)
1337 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
1338 if(gts.size()!=1 || pfls.size()!=1)
1339 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1340 int mdim(m->getMeshDimension());
1341 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
1344 _coords.resize(mdim);
1345 for(int i=0;i<mdim;i++)
1347 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1349 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1350 _coords[i]=elt; _coords[i]->incrRef();
1354 dealWithImplicitUnstructuredMesh(m);
1357 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1361 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const
1363 std::vector<int> ret(_coords.size());
1364 for(std::size_t i=0;i<_coords.size();i++)
1365 ret[i]=_coords[i]->getNumberOfTuples();
1369 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1371 MEDMeshMultiLev *retSpecific(0);
1372 if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1374 const DataArrayInt *pfl(0),*nr(_node_reduction);
1377 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1378 std::vector<int> cgs,ngs(getNodeGridStructure());
1379 cgs.resize(ngs.size());
1380 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1383 std::vector< std::pair<int,int> > cellParts;
1384 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1385 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1387 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1388 ret->_is_internal=false;
1390 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1391 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1393 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
1394 for(std::size_t i=0;i<_coords.size();i++)
1395 coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
1396 ret->_coords=coords;
1397 ret2=(MEDCMeshMultiLev *)ret; ret2->incrRef();
1401 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1402 for(std::size_t i=0;i<ngs.size();i++)
1403 m->setCoordsAt(i,_coords[i]);
1404 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1405 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1406 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1408 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1409 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1411 const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1414 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1415 ret2->setFamilyIdsOnCells(tmp);
1419 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1420 ret2->setNumberIdsOnCells(tmp);
1427 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1429 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1435 * \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.
1437 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays(bool& isInternal) const
1439 isInternal=_is_internal;
1440 std::size_t sz(_coords.size());
1441 std::vector< DataArrayDouble * > ret(sz);
1442 for(std::size_t i=0;i<sz;i++)
1444 ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1452 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1454 return new MEDCurveLinearMeshMultiLev(m,levs);
1457 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1459 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1462 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1465 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1466 if(levs.size()!=1 || levs[0]!=0)
1467 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1468 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1470 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1473 _structure=m->getMesh()->getNodeGridStructure();
1476 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)
1479 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1480 if(gts.size()!=1 || pfls.size()!=1)
1481 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1482 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1485 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1487 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1490 _structure=m->getMesh()->getNodeGridStructure();
1493 dealWithImplicitUnstructuredMesh(m);
1496 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1500 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1505 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1507 MEDMeshMultiLev *retSpecific(0);
1508 if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1510 const DataArrayInt *pfl(0),*nr(_node_reduction);
1513 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1514 std::vector<int> cgs,ngs(getNodeGridStructure());
1515 cgs.resize(ngs.size());
1516 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1519 std::vector< std::pair<int,int> > cellParts,nodeParts;
1520 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1521 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1523 nodeParts=cellParts;
1524 std::vector<int> st(ngs.size());
1525 for(std::size_t i=0;i<ngs.size();i++)
1527 nodeParts[i].second++;
1528 st[i]=nodeParts[i].second-nodeParts[i].first;
1530 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1531 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1532 ret->_is_internal=false;
1534 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1535 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1537 ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1539 ret2=(MEDCurveLinearMeshMultiLev *)ret; ret2->incrRef();
1543 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1544 m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1545 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1546 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1547 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1549 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1550 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1552 const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1555 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1556 ret2->setFamilyIdsOnCells(tmp);
1560 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1561 ret2->setNumberIdsOnCells(tmp);
1567 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1569 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1574 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct, bool& isInternal) const
1576 isInternal=_is_internal;
1577 nodeStrct=_structure;
1578 const DataArrayDouble *coo(_coords);
1580 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1581 coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1586 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1590 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)
1592 _pfl->setName(c.c_str());
1595 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1597 if(!mst->doesManageGeoType(_geo_type))
1599 MEDFileMeshStruct *mstUnConstCasted(const_cast<MEDFileMeshStruct *>(mst));
1600 mstUnConstCasted->appendIfImplicitType(_geo_type);
1602 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1603 checkInRange(nbOfEnt,1,globs);
1606 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1608 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1609 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1610 checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1613 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1616 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1618 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1619 const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1620 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1621 checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1624 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1628 if(getPflName().empty())
1629 return (_start_end.second-_start_end.first)/_nb_of_entity;
1631 return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples();
1635 const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1636 return loc.getNumberOfGaussPoints();
1640 std::string MEDFileField1TSStructItem2::getPflName() const
1642 return _pfl->getName();
1645 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1647 if(!_pfl->isAllocated())
1649 if(_pfl->getName().empty())
1652 return globs->getProfile(_pfl->getName().c_str());
1659 * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
1660 * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1662 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1664 _nb_of_entity=nbOfEntity;
1665 if(_pfl->getName().empty())
1667 if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1668 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of field !");
1674 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1675 const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
1677 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1678 pfl->checkAllIdsInRange(0,nbOfEntity);
1682 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const std::string& pflName) const
1684 if(startExp!=_start_end.first)
1688 if(getPflName()!=pflName)
1690 startExp=_start_end.second;
1694 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const
1696 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1697 //idem for _loc. It is not an effective attribute for support comparison.
1698 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1701 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1703 if(_geo_type!=other._geo_type)
1705 if(_nb_of_entity!=other._nb_of_entity)
1707 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1709 if(_pfl->getName().empty() && other._pfl->getName().empty())
1711 const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1712 return pfl1->isEqualWithoutConsideringStr(*pfl2);
1715 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1717 return isCellSupportEqual(other,globs);
1721 * \a objs must be non empty. \a objs should contain items having same geometric type.
1723 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1726 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1728 return MEDFileField1TSStructItem2(*objs[0]);
1729 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1730 int nbEntityRef(objs[0]->_nb_of_entity);
1731 std::size_t sz(objs.size());
1732 std::vector<const DataArrayInt *> arrs(sz);
1733 for(std::size_t i=0;i<sz;i++)
1735 const MEDFileField1TSStructItem2 *obj(objs[i]);
1736 if(gt!=obj->_geo_type)
1737 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1738 if(nbEntityRef!=obj->_nb_of_entity)
1739 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1740 if(obj->_pfl->getName().empty())
1741 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1742 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1744 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
1746 int oldNbTuples(arr->getNumberOfTuples());
1747 arr=arr->buildUnique();
1748 if(oldNbTuples!=arr->getNumberOfTuples())
1749 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1750 if(arr->isIdentity() && oldNbTuples==nbEntityRef)
1752 std::pair<int,int> p(0,nbEntityRef);
1754 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1755 ret._nb_of_entity=nbEntityRef;
1760 arr->setName(NEWLY_CREATED_PFL_NAME);
1761 std::pair<int,int> p(0,oldNbTuples);
1763 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1764 ret._nb_of_entity=nbEntityRef;
1770 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1772 std::size_t ret(_loc.capacity());
1776 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildrenWithNull() const
1778 std::vector<const BigMemoryObject *> ret;
1779 ret.push_back((const DataArrayInt *)_pfl);
1785 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1789 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1795 int nbOfEnt=mst->getNumberOfNodes();
1796 if(_items.size()!=1)
1797 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1798 _items[0].checkInRange(nbOfEnt,1,globs);
1803 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1804 (*it).checkWithMeshStructForCells(mst,globs);
1809 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1810 (*it).checkWithMeshStructForGaussNE(mst,globs);
1815 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1816 (*it).checkWithMeshStructForGaussPT(mst,globs);
1820 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1824 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const
1826 if(_type!=other._type)
1828 if(_items.size()!=other._items.size())
1830 for(std::size_t i=0;i<_items.size();i++)
1831 if(!(_items[i]==other._items[i]))
1836 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1838 if(_type!=other._type)
1840 if(_items.size()!=other._items.size())
1842 for(std::size_t i=0;i<_items.size();i++)
1843 if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1848 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1850 if(_type!=other._type)
1852 if(_items.size()!=other._items.size())
1854 for(std::size_t i=0;i<_items.size();i++)
1855 if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1860 bool MEDFileField1TSStructItem::isEntityCell() const
1871 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1872 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1874 INTERP_KERNEL::NormalizedCellType _geo_type;
1877 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1880 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1881 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1883 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1885 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1887 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1889 (*it0).second.push_back(i);
1891 if(m.size()==_items.size())
1893 MEDFileField1TSStructItem ret(*this);
1897 std::size_t sz(m.size());
1898 std::vector< MEDFileField1TSStructItem2 > items(sz);
1901 const std::vector<std::size_t>& ids=m[i].second;
1902 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1903 for(std::size_t j=0;j<ids.size();j++)
1904 objs[j]=&_items[ids[j]];
1905 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1907 MEDFileField1TSStructItem ret(ON_CELLS,items);
1913 * \a this is expected to be ON_CELLS and simplified.
1915 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1917 if(other._type!=ON_NODES)
1918 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1919 if(other._items.size()!=1)
1920 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1921 int theFirstLevFull;
1922 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1923 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1924 if(otherNodeIt.getPflName().empty())
1928 return theFirstLevFull==0;
1932 const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1933 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
1935 int nbOfNodes(meshSt->getNumberOfNodes());
1936 if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
1937 {//on all nodes also !
1940 return theFirstLevFull==0;
1942 std::vector<bool> nodesFetched(nbOfNodes,false);
1943 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1944 return cpyPfl->isFittingWith(nodesFetched);
1948 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1951 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1953 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1954 int nbOfLevs(meshSt->getNumberOfLevs());
1956 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1957 std::vector<int> levs(nbOfLevs);
1959 std::set<INTERP_KERNEL::NormalizedCellType> gts;
1960 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1962 if(!(*it).getPflName().empty())
1964 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1965 if(gts.find(gt)!=gts.end())
1966 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1968 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1971 for(int i=0;i<nbOfLevs;i++)
1972 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
1973 { theFirstLevFull=-i; return true; }
1977 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const
1979 if(i>=_items.size())
1980 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
1984 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
1986 std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
1990 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildrenWithNull() const
1992 std::vector<const BigMemoryObject *> ret;
1993 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1994 ret.push_back(&(*it));
1998 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2000 std::size_t sz(_items.size());
2001 std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
2002 std::vector<const DataArrayInt *> a1(sz);
2003 std::vector<int> a2(sz);
2005 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
2007 a0[i]=(*it).getGeo();
2008 a1[i]=(*it).getPfl(globs);
2009 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
2011 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
2014 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStructItem::getGeoTypes(const MEDFileMesh *m) const
2016 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2019 if(!_items.empty() && _items[0].getPflName().empty())
2022 return m->getAllGeoTypes();
2029 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2031 INTERP_KERNEL::NormalizedCellType elt((*it).getGeo());
2032 std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it2(std::find(ret.begin(),ret.end(),elt));
2039 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
2041 std::vector< MEDFileField1TSStructItem2 > anItems;
2043 std::vector< std::vector<std::string> > pfls,locs;
2044 std::vector< std::vector<TypeOfField> > typesF;
2045 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2046 std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(std::string(),geoTypes,typesF,pfls,locs);
2047 std::size_t nbOfGeoTypes(geoTypes.size());
2049 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
2050 if(typesF[0].empty())
2051 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 bis !");
2052 TypeOfField atype(typesF[0][0]);
2053 for(std::size_t i=0;i<nbOfGeoTypes;i++)
2055 std::size_t sz=typesF[i].size();
2056 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
2057 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
2059 for(std::size_t j=0;j<sz;j++)
2061 if(atype==typesF[i][j])
2062 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
2064 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
2067 MEDFileField1TSStructItem ret(atype,anItems);
2070 ret.checkWithMeshStruct(meshSt,ref);
2072 catch(INTERP_KERNEL::Exception& e)
2074 std::ostringstream oss; oss << e.what() << " (" << MEDCouplingFieldDiscretization::GetTypeOfFieldRepr(ret.getType()) << ")";
2075 throw INTERP_KERNEL::Exception(oss.str().c_str());
2082 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2084 return new MEDFileField1TSStruct(ref,mst);
2087 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2089 _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
2092 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
2094 if(_already_checked.empty())
2095 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
2096 _already_checked.back().checkWithMeshStruct(mst,globs);
2099 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
2101 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
2102 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2111 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
2113 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2115 if(_already_checked.empty())
2116 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
2117 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2118 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
2119 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
2120 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
2122 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2123 if((*it).isComputed())
2128 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2129 ret=this1.isCellSupportEqual(other1,other);
2131 _already_checked.push_back(this1);
2134 ret=_already_checked[found].isCellSupportEqual(other1,other);
2136 _already_checked.push_back(b);
2141 * \param [in] other - a field with only one spatial discretization : ON_NODES.
2143 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2145 if(_already_checked.empty())
2146 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
2147 MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2148 if(_already_checked[0].isEntityCell())
2151 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2152 if((*it).isComputed())
2157 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2158 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
2160 _already_checked.push_back(this1);
2163 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
2165 _already_checked.push_back(other1);
2169 return _already_checked[0].isNodeSupportEqual(other1,other);
2172 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
2174 std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
2178 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildrenWithNull() const
2180 std::vector<const BigMemoryObject *> ret;
2181 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2182 ret.push_back(&(*it));
2186 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2188 if(_already_checked.empty())
2189 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
2190 int pos0(-1),pos1(-1);
2191 if(presenceOfCellDiscr(pos0))
2193 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
2194 if(presenceOfPartialNodeDiscr(pos1))
2195 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
2200 if(!presenceOfPartialNodeDiscr(pos1))
2201 {//we have only all nodes, no cell definition info -> all existing levels !;
2202 return MEDMeshMultiLev::New(mst->getTheMesh(),mst->getTheMesh()->getNonEmptyLevels());
2205 return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
2209 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
2212 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
2214 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
2215 if(a0!=c0 || a1!=c1)
2218 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
2221 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
2226 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStruct::getGeoTypes(const MEDFileMesh *m) const
2228 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2229 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2231 std::vector<INTERP_KERNEL::NormalizedCellType> ret2((*it).getGeoTypes(m));
2232 for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator it2=ret2.begin();it2!=ret2.end();it2++)
2234 if(*it2==INTERP_KERNEL::NORM_ERROR)
2236 std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it3(std::find(ret.begin(),ret.end(),*it2));
2238 ret.push_back(*it2);
2245 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
2246 * 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.
2248 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
2250 std::size_t refSz(std::numeric_limits<std::size_t>::max());
2253 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2255 if((*it).getType()!=ON_NODES)
2258 std::size_t sz((*it).getNumberOfItems());
2260 { pos=i; refSz=sz; }
2264 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
2269 * Returns true if presence in \a this of discretization ON_NODES.
2270 * If true is returned the pos of the first element containing the single subpart.
2272 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
2275 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2277 if((*it).getType()==ON_NODES)
2279 std::size_t sz((*it).getNumberOfItems());
2282 if(!(*it)[0].getPflName().empty())
2283 { pos=i; return true; }
2286 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
2294 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2296 return new MEDFileFastCellSupportComparator(m,ref);
2299 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2302 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
2303 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
2304 int nbPts=ref->getNumberOfTS();
2305 _f1ts_cmps.resize(nbPts);
2306 for(int i=0;i<nbPts;i++)
2308 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
2311 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
2312 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
2314 catch(INTERP_KERNEL::Exception& e)
2316 std::ostringstream oss; oss << "Problem in field with name \"" << ref->getName() << "\"" << std::endl;
2317 oss << "More Details : " << e.what();
2318 throw INTERP_KERNEL::Exception(oss.str().c_str());
2323 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
2325 std::size_t ret(_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>));
2329 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildrenWithNull() const
2331 std::vector<const BigMemoryObject *> ret;
2332 const MEDFileMeshStruct *mst(_mesh_comp);
2335 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
2336 ret.push_back((const MEDFileField1TSStruct *)*it);
2340 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
2342 int nbPts=other->getNumberOfTS();
2343 if(nbPts!=(int)_f1ts_cmps.size())
2345 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2346 throw INTERP_KERNEL::Exception(oss.str().c_str());
2348 for(int i=0;i<nbPts;i++)
2350 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2351 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
2352 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
2358 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
2360 int nbPts=other->getNumberOfTS();
2361 if(nbPts!=(int)_f1ts_cmps.size())
2363 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2364 throw INTERP_KERNEL::Exception(oss.str().c_str());
2366 for(int i=0;i<nbPts;i++)
2368 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2369 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
2375 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2377 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2379 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2380 throw INTERP_KERNEL::Exception(oss.str().c_str());
2382 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2385 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
2386 throw INTERP_KERNEL::Exception(oss.str().c_str());
2388 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
2391 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2393 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
2395 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
2396 throw INTERP_KERNEL::Exception(oss.str().c_str());
2398 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2399 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
2400 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
2403 int MEDFileFastCellSupportComparator::getNumberOfTS() const
2405 return _f1ts_cmps.size();
2408 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileFastCellSupportComparator::getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const
2410 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2412 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2413 throw INTERP_KERNEL::Exception(oss.str().c_str());
2415 const MEDFileField1TSStruct *elt(_f1ts_cmps[timeStepId]);
2418 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " points to a NULL pointer !";
2419 throw INTERP_KERNEL::Exception(oss.str().c_str());
2421 return elt->getGeoTypes(m);