1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "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 char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???";
34 MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh)
36 return new MEDFileMeshStruct(mesh);
39 std::size_t MEDFileMeshStruct::getHeapMemorySizeWithoutChildren() const
42 for(std::vector< std::vector<int> >::const_iterator it0=_geo_types_distrib.begin();it0!=_geo_types_distrib.end();it0++)
43 ret+=(*it0).capacity()*sizeof(int);
44 ret+=_geo_types_distrib.capacity()*sizeof(std::vector<int>);
48 std::vector<const BigMemoryObject *> MEDFileMeshStruct::getDirectChildren() const
50 return std::vector<const BigMemoryObject *>();
53 MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh)
55 std::vector<int> levs(mesh->getNonEmptyLevels());
56 _name=mesh->getName();
57 _nb_nodes=mesh->getNumberOfNodes();
58 _geo_types_distrib.resize(levs.size());
59 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
60 _geo_types_distrib[-(*lev)]=mesh->getDistributionOfTypes(*lev);
63 int MEDFileMeshStruct::getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
66 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++,j--)
68 std::size_t sz=(*it1).size();
70 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : internal error in code !");
71 std::size_t nbGeo=sz/3;
72 for(std::size_t i=0;i<nbGeo;i++)
73 if((*it1)[3*i]==(int)t)
76 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : The specified geometric type is not present in the mesh structure !");
79 int MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
81 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
83 std::size_t sz=(*it1).size();
85 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !");
86 std::size_t nbGeo=sz/3;
87 for(std::size_t i=0;i<nbGeo;i++)
88 if((*it1)[3*i]==(int)t)
91 throw INTERP_KERNEL::Exception("The specified geometric type is not present in the mesh structure !");
94 int MEDFileMeshStruct::getNumberOfLevs() const
96 return (int)_geo_types_distrib.size();
99 int MEDFileMeshStruct::getNumberOfGeoTypesInLev(int relativeLev) const
101 int pos(-relativeLev);
102 if(pos<0 || pos>=(int)_geo_types_distrib.size())
103 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : invalid level specified !");
104 std::size_t sz=_geo_types_distrib[pos].size();
106 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : internal error in code !");
112 std::size_t MEDMeshMultiLev::getHeapMemorySizeWithoutChildren() const
117 std::vector<const BigMemoryObject *> MEDMeshMultiLev::getDirectChildren() const
119 return std::vector<const BigMemoryObject *>();
122 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs)
125 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
126 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
128 return MEDUMeshMultiLev::New(um,levs);
129 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
131 return MEDCMeshMultiLev::New(cm,levs);
132 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
134 return MEDCurveLinearMeshMultiLev::New(clm,levs);
135 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
138 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
141 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
142 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
144 return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
145 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
147 return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
148 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
150 return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
151 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
154 MEDMeshMultiLev *MEDMeshMultiLev::NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode)
156 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,m->getNonEmptyLevels()));
157 ret->selectPartOfNodes(pflOnNode);
161 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
165 _node_reduction=const_cast<DataArrayInt*>(nr);
168 bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const
170 if(fst.getType()==ON_NODES)
172 if(fst.getNumberOfItems()!=1)
173 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::isFastlyTheSameStruct : unexpected situation for nodes !");
174 const MEDFileField1TSStructItem2& p(fst[0]);
175 std::string pflName(p.getPflName());
176 const DataArrayInt *nr(_node_reduction);
177 if(pflName.empty() && !nr)
179 if(pflName==nr->getName())
185 std::size_t sz(fst.getNumberOfItems());
186 if(sz!=_geo_types.size())
189 for(std::size_t i=0;i<sz;i++)
191 const MEDFileField1TSStructItem2& p(fst[i]);
192 if(!p.isFastlyEqual(strt,_geo_types[i],getPflNameOfId(i).c_str()))
199 DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
201 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(const_cast<DataArray *>(vals)); ret->incrRef();
202 if(isFastlyTheSameStruct(fst,globs))
205 return constructDataArray(fst,globs,vals);
209 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
210 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
212 void MEDMeshMultiLev::retrieveFamilyIdsOnCells(DataArrayInt *& famIds, bool& isWithoutCopy) const
214 const DataArrayInt *fids(_cell_fam_ids);
216 { famIds=0; isWithoutCopy=true; return ; }
217 std::size_t sz(_geo_types.size());
218 bool presenceOfPfls(false);
219 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
221 const DataArrayInt *pfl(_pfls[i]);
226 { famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef(); isWithoutCopy=_cell_fam_ids_nocpy; return ; }
227 //bad luck the slowest part
229 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
230 std::vector< const DataArrayInt *> ret(sz);
232 for(std::size_t i=0;i<sz;i++)
234 const DataArrayInt *pfl(_pfls[i]);
235 int lgth(_nb_entities[i]);
238 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(fids->selectByTupleId2(start,start+lgth,1));
239 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
243 retSafe[i]=fids->selectByTupleId2(start,start+lgth,1);
248 famIds=DataArrayInt::Aggregate(ret);
252 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
253 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
255 void MEDMeshMultiLev::retrieveNumberIdsOnCells(DataArrayInt *& numIds, bool& isWithoutCopy) const
257 const DataArrayInt *nids(_cell_num_ids);
259 { numIds=0; isWithoutCopy=true; return ; }
260 std::size_t sz(_geo_types.size());
261 bool presenceOfPfls(false);
262 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
264 const DataArrayInt *pfl(_pfls[i]);
269 { numIds=const_cast<DataArrayInt *>(nids); numIds->incrRef(); isWithoutCopy=_cell_num_ids_nocpy; return ; }
270 //bad luck the slowest part
272 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
273 std::vector< const DataArrayInt *> ret(sz);
275 for(std::size_t i=0;i<sz;i++)
277 const DataArrayInt *pfl(_pfls[i]);
278 int lgth(_nb_entities[i]);
281 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(nids->selectByTupleId2(start,start+lgth,1));
282 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
286 retSafe[i]=nids->selectByTupleId2(start,start+lgth,1);
291 numIds=DataArrayInt::Aggregate(ret);
295 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
296 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
298 void MEDMeshMultiLev::retrieveFamilyIdsOnNodes(DataArrayInt *& famIds, bool& isWithoutCopy) const
300 const DataArrayInt *fids(_node_fam_ids);
302 { famIds=0; isWithoutCopy=true; return ; }
303 const DataArrayInt *nr(_node_reduction);
307 famIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
311 isWithoutCopy=_node_fam_ids_nocpy;
312 famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef();
317 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
318 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
320 void MEDMeshMultiLev::retrieveNumberIdsOnNodes(DataArrayInt *& numIds, bool& isWithoutCopy) const
322 const DataArrayInt *fids(_node_num_ids);
324 { numIds=0; isWithoutCopy=true; return ; }
325 const DataArrayInt *nr(_node_reduction);
329 numIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
333 isWithoutCopy=_node_num_ids_nocpy;
334 numIds=const_cast<DataArrayInt *>(fids); numIds->incrRef();
338 void MEDMeshMultiLev::setFamilyIdsOnCells(DataArrayInt *famIds, bool isNoCopy)
340 _cell_fam_ids=famIds;
343 _cell_fam_ids_nocpy=isNoCopy;
346 void MEDMeshMultiLev::setNumberIdsOnCells(DataArrayInt *numIds, bool isNoCopy)
348 _cell_num_ids=numIds;
351 _cell_num_ids_nocpy=isNoCopy;
354 void MEDMeshMultiLev::setFamilyIdsOnNodes(DataArrayInt *famIds, bool isNoCopy)
356 _node_fam_ids=famIds;
359 _node_fam_ids_nocpy=isNoCopy;
362 void MEDMeshMultiLev::setNumberIdsOnNodes(DataArrayInt *numIds, bool isNoCopy)
364 _node_num_ids=numIds;
367 _node_num_ids_nocpy=isNoCopy;
370 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
372 std::size_t sz(_pfls.size());
373 if(id<0 || id>=(int)sz)
374 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
375 const DataArrayInt *pfl(_pfls[id]);
377 return std::string("");
378 return pfl->getName();
382 * Returns the number of cells having geometric type \a t.
383 * The profiles are **NOT** taken into account here.
385 int MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
387 std::size_t sz(_nb_entities.size());
388 for(std::size_t i=0;i<sz;i++)
390 return _nb_entities[i];
391 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
394 int MEDMeshMultiLev::getNumberOfNodes() const
399 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
401 if(fst.getType()==ON_NODES)
403 if(fst.getNumberOfItems()!=1)
404 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
405 const MEDFileField1TSStructItem2& p(fst[0]);
406 std::string pflName(p.getPflName());
407 const DataArrayInt *nr(_node_reduction);
408 if(pflName.empty() && !nr)
409 return vals->deepCpy();
410 if(pflName.empty() && nr)
411 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
412 if(!pflName.empty() && nr)
414 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
415 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(nr->deepCpy());
416 p1->sort(true); p2->sort(true);
417 if(!p1->isEqualWithoutConsideringStr(*p2))
418 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 3 !");
419 p1=DataArrayInt::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
420 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
421 ret->renumberInPlace(p1->begin());
424 if(!pflName.empty() && !nr)
426 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
428 if(!p1->isIdentity() || p1->getNumberOfTuples()!=getNumberOfNodes())
429 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
430 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
431 ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
434 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
438 std::size_t sz(fst.getNumberOfItems());
439 std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
440 if(s.size()!=_geo_types.size())
441 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
442 std::vector< const DataArray *> arr(s.size());
443 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arrSafe(s.size());
445 int nc(vals->getNumberOfComponents());
446 std::vector<std::string> compInfo(vals->getInfoOnComponents());
447 for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
449 const DataArrayInt *thisP(_pfls[iii]);
450 std::vector<const MEDFileField1TSStructItem2 *> ps;
451 for(std::size_t i=0;i<sz;i++)
453 const MEDFileField1TSStructItem2& p(fst[i]);
458 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
461 int nbi(ps[0]->getNbOfIntegrationPts(globs));
462 const DataArrayInt *otherP(ps[0]->getPfl(globs));
463 const std::pair<int,int>& strtStop(ps[0]->getStartStop());
464 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
465 if(!thisP && !otherP)
467 arrSafe[iii]=ret; arr[iii]=ret;
472 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
473 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(thisP->deepCpy());
474 p2->transformWithIndArr(p1->begin(),p1->end());
475 //p1=p2->getIdsNotEqual(-1);
476 //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
477 ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
478 arrSafe[iii]=ret; arr[iii]=ret;
483 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->deepCpy());
485 p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
486 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,p1);
487 ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
488 arrSafe[iii]=ret; arr[iii]=ret;
491 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
495 std::vector< const DataArrayInt * >otherPS(ps.size());
496 std::vector< const DataArray * > arr2(ps.size());
497 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arr2Safe(ps.size());
498 std::vector< const DataArrayInt * > nbis(ps.size());
499 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > nbisSafe(ps.size());
501 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
503 int nbi((*it2)->getNbOfIntegrationPts(globs));
504 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
505 const std::pair<int,int>& strtStop((*it2)->getStartStop());
506 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
508 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
509 arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
510 nbisSafe[jj]=DataArrayInt::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
511 nbis[jj]=nbisSafe[jj];
513 MEDCouplingAutoRefCountObjectPtr<DataArray> arr3(DataArray::Aggregate(arr2));
514 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherP(DataArrayInt::Aggregate(otherPS));
515 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbis(DataArrayInt::Aggregate(nbis));
516 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
517 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1;
519 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,thisP);
521 p1=otherP->deepCpy();
522 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbisN(zenbis->renumber(p1->begin()));
523 zenbisN->computeOffsets2();
525 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
527 //int nbi((*it2)->getNbOfIntegrationPts(globs));
528 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
529 const std::pair<int,int>& strtStop((*it2)->getStartStop());
530 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
532 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(otherPfl->deepCpy());
533 p2->transformWithIndArr(otherPN->begin(),otherPN->end());
534 p2->transformWithIndArr(p1->begin(),p1->end());
535 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsN(p2->buildExplicitArrByRanges(zenbisN));
536 arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
538 arrSafe[iii]=arr3; arr[iii]=arr3;
542 return DataArray::Aggregate(arr);
546 MEDMeshMultiLev::MEDMeshMultiLev():_nb_nodes(0),_cell_fam_ids_nocpy(false)
550 MEDMeshMultiLev::MEDMeshMultiLev(int nbNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):_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)
552 std::size_t sz(_geo_types.size());
553 if(sz!=pfls.size() || sz!=nbEntities.size())
554 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
556 for(std::size_t i=0;i<sz;i++)
560 _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
564 MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):RefCountObject(other),_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)
570 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
572 return new MEDUMeshMultiLev(m,levs);
575 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs)
578 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
579 std::vector<MEDCoupling1GTUMesh *> v;
580 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
582 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
583 v.insert(v.end(),vTmp.begin(),vTmp.end());
585 std::size_t sz(v.size());
588 _geo_types.resize(sz);
589 _nb_entities.resize(sz);
590 for(std::size_t i=0;i<sz;i++)
592 MEDCoupling1GTUMesh *obj(v[i]);
596 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
598 _geo_types[i]=obj->getCellModelEnum();
599 _nb_entities[i]=obj->getNumberOfCells();
601 // ids fields management
602 _cell_fam_ids_nocpy=(levs.size()==1);
603 if(_cell_fam_ids_nocpy)
605 const DataArrayInt *tmp(m->getFamilyFieldAtLevel(levs[0]));
609 _cell_fam_ids=(const_cast<DataArrayInt *>(tmp));
614 std::vector<const DataArrayInt *> tmps(levs.size());
616 for(std::size_t i=0;i<levs.size();i++)
618 tmps[i]=m->getFamilyFieldAtLevel(levs[i]);
623 _cell_fam_ids=DataArrayInt::Aggregate(tmps);
625 _cell_num_ids_nocpy=(levs.size()==1);
626 if(_cell_num_ids_nocpy)
628 const DataArrayInt *tmp(m->getNumberFieldAtLevel(levs[0]));
632 _cell_num_ids=(const_cast<DataArrayInt *>(tmp));
637 std::vector<const DataArrayInt *> tmps(levs.size());
639 for(std::size_t i=0;i<levs.size();i++)
641 tmps[i]=m->getNumberFieldAtLevel(levs[i]);
646 _cell_num_ids=DataArrayInt::Aggregate(tmps);
649 _node_fam_ids_nocpy=true;
651 const DataArrayInt *tmp(m->getFamilyFieldAtLevel(1));
655 _node_fam_ids=(const_cast<DataArrayInt *>(tmp));
658 _node_num_ids_nocpy=true;
660 const DataArrayInt *tmp(m->getNumberFieldAtLevel(1));
664 _node_num_ids=(const_cast<DataArrayInt *>(tmp));
669 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
671 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
674 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->getNumberOfNodes(),gts,pfls,nbEntities)
676 std::size_t sz(gts.size());
678 throw INTERP_KERNEL::Exception("constructor of MEDUMeshMultiLev : number of different geo type must be >= 1 !");
679 unsigned dim(INTERP_KERNEL::CellModel::GetCellModel(gts[0]).getDimension());
681 bool isSameDim(true),isNoPfl(true);
682 for(std::size_t i=0;i<sz;i++)
684 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
685 if(INTERP_KERNEL::CellModel::GetCellModel(gts[i]).getDimension()!=dim)
693 // ids fields management
694 int lev((int)dim-m->getMeshDimension());
695 if(isSameDim && isNoPfl && m->getGeoTypesAtLevel(lev)==gts)//optimized part
697 _cell_fam_ids_nocpy=true;
698 const DataArrayInt *famIds(m->getFamilyFieldAtLevel(lev));
700 { _cell_fam_ids=const_cast<DataArrayInt*>(famIds); famIds->incrRef(); }
701 _cell_num_ids_nocpy=true;
702 const DataArrayInt *numIds(m->getNumberFieldAtLevel(lev));
704 { _cell_num_ids=const_cast<DataArrayInt*>(numIds); numIds->incrRef(); }
705 _node_fam_ids_nocpy=true;
706 famIds=m->getFamilyFieldAtLevel(1);
708 { _node_fam_ids=const_cast<DataArrayInt*>(famIds); famIds->incrRef(); }
709 _node_num_ids_nocpy=true;
710 numIds=m->getNumberFieldAtLevel(1);
712 { _node_num_ids=const_cast<DataArrayInt*>(numIds); numIds->incrRef(); }
716 _cell_fam_ids_nocpy=false;
717 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > famIdsSafe(sz);
718 std::vector<const DataArrayInt *> famIds(sz);
720 for(std::size_t i=0;i<sz;i++)
722 famIdsSafe[i]=m->extractFamilyFieldOnGeoType(gts[i]);
723 famIds[i]=famIdsSafe[i];
728 _cell_fam_ids=DataArrayInt::Aggregate(famIds);
729 _cell_num_ids_nocpy=false;
730 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > numIdsSafe(sz);
731 std::vector<const DataArrayInt *> numIds(sz);
733 for(std::size_t i=0;i<sz;i++)
735 numIdsSafe[i]=m->extractNumberFieldOnGeoType(gts[i]);
736 numIds[i]=numIdsSafe[i];
741 _cell_num_ids=DataArrayInt::Aggregate(numIds);
742 // node ids management
743 _node_fam_ids_nocpy=true;
744 const DataArrayInt *nodeFamIds(m->getFamilyFieldAtLevel(1));
746 { _node_fam_ids=const_cast<DataArrayInt*>(nodeFamIds); nodeFamIds->incrRef(); }
747 _node_num_ids_nocpy=true;
748 const DataArrayInt *nodeNumIds(m->getNumberFieldAtLevel(1));
750 { _node_num_ids=const_cast<DataArrayInt*>(nodeNumIds); nodeNumIds->incrRef(); }
753 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
755 if(!pflNodes || !pflNodes->isAllocated())
757 std::size_t sz(_parts.size());
758 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
759 std::vector< const DataArrayInt *> aa(sz);
760 for(std::size_t i=0;i<sz;i++)
763 const DataArrayInt *pfl(_pfls[i]);
764 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
766 m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
767 DataArrayInt *cellIds=0;
768 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
769 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
770 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
772 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m2->getNodeIdsInUse(tmp));
773 a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
775 _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
777 _pfls[i]=cellIdsSafe;
779 _node_reduction=DataArrayInt::Aggregate(aa);
780 _node_reduction->sort(true);
781 _node_reduction=_node_reduction->buildUnique();
784 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
786 return new MEDUMeshMultiLev(*this);
789 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts)
793 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
797 _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
798 _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
799 _pfls.resize(1); _pfls[0]=0;
803 * 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.
804 * 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.
806 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const
809 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : empty array !");
810 if(!(const MEDCoupling1GTUMesh *)_parts[0])
811 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : first part is null !");
812 const DataArrayDouble *tmp(_parts[0]->getCoords());
814 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
815 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
816 int szBCE(0),szD(0),szF(0);
819 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
821 const MEDCoupling1GTUMesh *cur(*it);
823 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
825 const DataArrayInt *pfl(_pfls[iii]);
826 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
828 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
830 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
832 int curNbCells(cur->getNumberOfCells());
834 if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
835 szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
839 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(cur->computeEffectiveNbOfNodesPerCell());
840 szD+=tmp2->accumulate(0)+curNbCells;
841 szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
844 MEDCouplingAutoRefCountObjectPtr<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
845 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()); c->alloc(szBCE,1); int *cPtr(c->getPointer());
846 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d(DataArrayInt::New()); d->alloc(szD,1); int *dPtr(d->getPointer());
847 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> e(DataArrayInt::New()),f(DataArrayInt::New()); int *ePtr(0),*fPtr(0);
849 { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
852 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
854 const MEDCoupling1GTUMesh *cur(*it);
856 const DataArrayInt *pfl(_pfls[iii]);
857 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
859 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
861 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
863 int curNbCells(cur->getNumberOfCells());
864 int gt((int)cur->getCellModelEnum());
865 if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
866 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
867 unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
869 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
870 std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
871 const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
872 const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
873 const int *connPtr(cur->getNodalConnectivity()->begin());
875 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
878 int nnpc(scur->getNumberOfNodesPerCell());
879 for(int i=0;i<curNbCells;i++,connPtr+=nnpc)
882 dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
883 *cPtr++=k; k+=nnpc+1;
886 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
890 const int *connIPtr(dcur->getNodalConnectivityIndex()->begin());
891 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
893 for(int i=0;i<curNbCells;i++,connIPtr++)
895 *dPtr++=connIPtr[1]-connIPtr[0];
896 dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
897 *cPtr++=k; k+=connIPtr[1]-connIPtr[0];
902 for(int i=0;i<curNbCells;i++,connIPtr++)
904 std::set<int> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
905 *dPtr++=(int)s.size();
906 dPtr=std::copy(s.begin(),s.end(),dPtr);
907 *cPtr++=k; k+=(int)s.size()+1;
912 connIPtr=dcur->getNodalConnectivityIndex()->begin();
913 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
914 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
918 for(int i=0;i<curNbCells;i++,connIPtr++)
920 int nbFace(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1);
922 const int *work(connPtr+connIPtr[0]);
923 for(int j=0;j<nbFace;j++)
925 const int *work2=std::find(work,connPtr+connIPtr[1],-1);
926 *fPtr++=std::distance(work,work2);
927 fPtr=std::copy(work,work2,fPtr);
930 *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
937 reorderNodesIfNecessary(a,d,0);
939 reorderNodesIfNecessary(a,d,f);
940 if(a->getNumberOfComponents()!=3)
941 a=a->changeNbOfComponents(3,0.);
942 coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
944 { faceLocations=0; faces=0; }
946 { faceLocations=e.retn(); faces=f.retn(); }
947 return tmp==((DataArrayDouble *)a);
950 void MEDUMeshMultiLev::reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const
952 const DataArrayInt *nr(_node_reduction);
955 int sz(coords->getNumberOfTuples());
956 std::vector<bool> b(sz,false);
957 const int *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
961 for(int i=0;i<nb && work!=endW;i++,work++)
963 if(*work>=0 && *work<sz)
966 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
969 if(polyhedNodalConnVTK)
971 work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
975 for(int i=0;i<nb && work!=endW;i++)
978 for(int j=0;j<nb2 && work!=endW;j++,work++)
980 if(*work>=0 && *work<sz)
983 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
988 int szExp(std::count(b.begin(),b.end(),true));
989 if(szExp!=nr->getNumberOfTuples())
990 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
992 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(DataArrayInt::New()); o2n->alloc(sz,1);
993 int *o2nPtr(o2n->getPointer());
995 for(int i=0;i<sz;i++,o2nPtr++)
996 if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
997 const int *o2nPtrc(o2n->begin());
998 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
999 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> perm(DataArrayInt::FindPermutationFromFirstToSecond(n2o,nr));
1000 const int *permPtr(perm->begin());
1001 int *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
1005 for(int i=0;i<nb && work2!=endW2;i++,work2++)
1006 *work2=permPtr[o2nPtrc[*work2]];
1008 if(polyhedNodalConnVTK)
1010 work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
1014 for(int i=0;i<nb && work2!=endW2;i++)
1017 for(int j=0;j<nb2 && work2!=endW2;j++,work2++)
1018 *work2=permPtr[o2nPtrc[*work2]];
1022 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1027 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev()
1031 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector<int>& lev)
1033 // ids fields management
1034 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1035 const DataArrayInt *tmp(0);
1036 tmp=m->getFamilyFieldAtLevel(0);
1040 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1042 tmp=m->getNumberFieldAtLevel(0);
1046 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1049 _node_fam_ids_nocpy=true; _node_num_ids_nocpy=true;
1051 tmp=m->getFamilyFieldAtLevel(1);
1055 _node_fam_ids=const_cast<DataArrayInt *>(tmp);
1057 tmp=m->getNumberFieldAtLevel(1);
1061 _node_num_ids=const_cast<DataArrayInt *>(tmp);
1065 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(nbOfNodes,gts,pfls,nbEntities)
1067 // ids fields management
1068 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1069 const DataArrayInt *tmp(0);
1070 tmp=m->getFamilyFieldAtLevel(0);
1074 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1076 tmp=m->getNumberFieldAtLevel(0);
1080 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1083 _node_fam_ids_nocpy=true; _node_num_ids_nocpy=true;
1085 tmp=m->getFamilyFieldAtLevel(1);
1089 _node_fam_ids=const_cast<DataArrayInt *>(tmp);
1091 tmp=m->getNumberFieldAtLevel(1);
1095 _node_num_ids=const_cast<DataArrayInt *>(tmp);
1099 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
1101 if(!pflNodes || !pflNodes->isAllocated())
1103 std::vector<int> ngs(getNodeGridStructure());
1104 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1105 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
1106 m->setNodalConnectivity(conn);
1107 const DataArrayInt *pfl(_pfls[0]);
1110 m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1112 DataArrayInt *cellIds=0;
1113 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1114 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
1115 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1117 _node_reduction=m2->getNodeIdsInUse(tmp);
1119 _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1121 _pfls[0]=cellIdsSafe;
1124 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other)
1130 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
1132 return new MEDCMeshMultiLev(m,levs);
1135 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1137 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
1140 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1143 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
1144 if(levs.size()!=1 || levs[0]!=0)
1145 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
1146 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1147 _coords.resize(mdim);
1148 for(int i=0;i<mdim;i++)
1150 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1152 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1157 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)
1160 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
1161 if(gts.size()!=1 || pfls.size()!=1)
1162 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1163 int mdim(m->getMeshDimension());
1164 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
1166 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1167 _coords.resize(mdim);
1168 for(int i=0;i<mdim;i++)
1170 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1172 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1173 _coords[i]=elt; _coords[i]->incrRef();
1177 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1181 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const
1183 std::vector<int> ret(_coords.size());
1184 for(std::size_t i=0;i<_coords.size();i++)
1185 ret[i]=_coords[i]->getNumberOfTuples();
1189 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1191 const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
1192 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1193 std::vector<int> cgs,ngs(getNodeGridStructure());
1194 cgs.resize(ngs.size());
1195 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1198 std::vector< std::pair<int,int> > cellParts;
1199 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1200 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1202 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1204 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1205 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1207 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
1208 for(std::size_t i=0;i<_coords.size();i++)
1209 coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
1210 ret->_coords=coords;
1211 ret2=(MEDCMeshMultiLev *)ret; ret2->incrRef();
1215 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1216 for(std::size_t i=0;i<ngs.size();i++)
1217 m->setCoordsAt(i,_coords[i]);
1218 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1219 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1220 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1222 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1223 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1225 const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1228 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1229 ret2->setFamilyIdsOnCells(tmp,false);
1233 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1234 ret2->setNumberIdsOnCells(tmp,false);
1241 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1243 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1248 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays() const
1250 std::size_t sz(_coords.size());
1251 std::vector< DataArrayDouble * > ret(sz);
1252 for(std::size_t i=0;i<sz;i++)
1254 ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1262 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1264 return new MEDCurveLinearMeshMultiLev(m,levs);
1267 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1269 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1272 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1275 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1276 if(levs.size()!=1 || levs[0]!=0)
1277 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1278 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1280 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1283 _structure=m->getMesh()->getNodeGridStructure();
1286 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)
1289 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1290 if(gts.size()!=1 || pfls.size()!=1)
1291 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1292 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1294 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1295 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1297 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1300 _structure=m->getMesh()->getNodeGridStructure();
1303 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1307 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1312 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1314 const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
1315 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1316 std::vector<int> cgs,ngs(getNodeGridStructure());
1317 cgs.resize(ngs.size());
1318 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1321 std::vector< std::pair<int,int> > cellParts,nodeParts;
1322 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret2;
1323 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1325 nodeParts=cellParts;
1326 std::vector<int> st(ngs.size());
1327 for(std::size_t i=0;i<ngs.size();i++)
1329 nodeParts[i].second++;
1330 st[i]=nodeParts[i].second-nodeParts[i].first;
1332 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1333 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1335 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1336 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1338 ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1340 ret2=(MEDCurveLinearMeshMultiLev *)ret; ret2->incrRef();
1344 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1345 m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1346 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1347 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1348 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1350 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1351 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1353 const DataArrayInt *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1356 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1357 ret2->setFamilyIdsOnCells(tmp,false);
1361 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1362 ret2->setNumberIdsOnCells(tmp,false);
1368 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1370 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1375 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct) const
1377 nodeStrct=_structure;
1378 const DataArrayDouble *coo(_coords);
1380 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1381 coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1386 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1390 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)
1392 _pfl->setName(c.c_str());
1395 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1397 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1398 checkInRange(nbOfEnt,1,globs);
1401 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1403 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1404 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1405 checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1408 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1411 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1413 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1414 const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1415 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1416 checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1419 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1423 if(getPflName().empty())
1424 return (_start_end.second-_start_end.first)/_nb_of_entity;
1426 return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples();
1430 const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1431 return loc.getNumberOfGaussPoints();
1435 std::string MEDFileField1TSStructItem2::getPflName() const
1437 return _pfl->getName();
1440 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1442 if(!_pfl->isAllocated())
1444 if(_pfl->getName().empty())
1447 return globs->getProfile(_pfl->getName().c_str());
1454 * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
1455 * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1457 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1459 _nb_of_entity=nbOfEntity;
1460 if(_pfl->getName().empty())
1462 if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1463 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !");
1469 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1470 const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
1472 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1473 pfl->checkAllIdsInRange(0,nbOfEntity);
1477 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const char *pflName) const
1479 if(startExp!=_start_end.first)
1483 if(getPflName()!=pflName)
1485 startExp=_start_end.second;
1489 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception)
1491 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1492 //idem for _loc. It is not an effective attribute for support comparison.
1493 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1496 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1498 if(_geo_type!=other._geo_type)
1500 if(_nb_of_entity!=other._nb_of_entity)
1502 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1504 if(_pfl->getName().empty() && other._pfl->getName().empty())
1506 const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1507 return pfl1->isEqualWithoutConsideringStr(*pfl2);
1510 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1512 return isCellSupportEqual(other,globs);
1516 * \a objs must be non empty. \a objs should contain items having same geometric type.
1518 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1521 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1523 return MEDFileField1TSStructItem2(*objs[0]);
1524 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1525 int nbEntityRef(objs[0]->_nb_of_entity);
1526 std::size_t sz(objs.size());
1527 std::vector<const DataArrayInt *> arrs(sz);
1528 for(std::size_t i=0;i<sz;i++)
1530 const MEDFileField1TSStructItem2 *obj(objs[i]);
1531 if(gt!=obj->_geo_type)
1532 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1533 if(nbEntityRef!=obj->_nb_of_entity)
1534 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1535 if(obj->_pfl->getName().empty())
1536 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1537 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1539 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
1541 int oldNbTuples(arr->getNumberOfTuples());
1542 arr=arr->buildUnique();
1543 if(oldNbTuples!=arr->getNumberOfTuples())
1544 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1545 if(arr->isIdentity() && oldNbTuples==nbEntityRef)
1547 std::pair<int,int> p(0,nbEntityRef);
1549 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1550 ret._nb_of_entity=nbEntityRef;
1555 arr->setName(NEWLY_CREATED_PFL_NAME);
1556 std::pair<int,int> p(0,oldNbTuples);
1558 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1559 ret._nb_of_entity=nbEntityRef;
1565 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1567 std::size_t ret(_loc.capacity());
1571 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildren() const
1573 std::vector<const BigMemoryObject *> ret;
1574 const DataArrayInt *pfl(_pfl);
1582 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1586 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1592 int nbOfEnt=mst->getNumberOfNodes();
1593 if(_items.size()!=1)
1594 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1595 _items[0].checkInRange(nbOfEnt,1,globs);
1600 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1601 (*it).checkWithMeshStructForCells(mst,globs);
1606 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1607 (*it).checkWithMeshStructForGaussNE(mst,globs);
1612 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1613 (*it).checkWithMeshStructForGaussPT(mst,globs);
1617 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1621 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception)
1623 if(_type!=other._type)
1625 if(_items.size()!=other._items.size())
1627 for(std::size_t i=0;i<_items.size();i++)
1628 if(!(_items[i]==other._items[i]))
1633 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1635 if(_type!=other._type)
1637 if(_items.size()!=other._items.size())
1639 for(std::size_t i=0;i<_items.size();i++)
1640 if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1645 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1647 if(_type!=other._type)
1649 if(_items.size()!=other._items.size())
1651 for(std::size_t i=0;i<_items.size();i++)
1652 if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1657 bool MEDFileField1TSStructItem::isEntityCell() const
1668 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1669 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1671 INTERP_KERNEL::NormalizedCellType _geo_type;
1674 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1677 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1678 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1680 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1682 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1684 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1686 (*it0).second.push_back(i);
1688 if(m.size()==_items.size())
1690 MEDFileField1TSStructItem ret(*this);
1694 std::size_t sz(m.size());
1695 std::vector< MEDFileField1TSStructItem2 > items(sz);
1698 const std::vector<std::size_t>& ids=m[i].second;
1699 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1700 for(std::size_t j=0;j<ids.size();j++)
1701 objs[j]=&_items[ids[j]];
1702 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1704 MEDFileField1TSStructItem ret(ON_CELLS,items);
1710 * \a this is expected to be ON_CELLS and simplified.
1712 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1714 if(other._type!=ON_NODES)
1715 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1716 if(other._items.size()!=1)
1717 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1718 int theFirstLevFull;
1719 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1720 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1721 if(otherNodeIt.getPflName().empty())
1725 return theFirstLevFull==0;
1729 const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1730 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
1732 int nbOfNodes(meshSt->getNumberOfNodes());
1733 if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
1734 {//on all nodes also !
1737 return theFirstLevFull==0;
1739 std::vector<bool> nodesFetched(nbOfNodes,false);
1740 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1741 return cpyPfl->isFittingWith(nodesFetched);
1745 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1748 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1750 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1751 int nbOfLevs(meshSt->getNumberOfLevs());
1753 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1754 std::vector<int> levs(nbOfLevs);
1756 std::set<INTERP_KERNEL::NormalizedCellType> gts;
1757 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1759 if(!(*it).getPflName().empty())
1761 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1762 if(gts.find(gt)!=gts.end())
1763 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1765 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1768 for(int i=0;i<nbOfLevs;i++)
1769 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
1770 { theFirstLevFull=-i; return true; }
1774 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const throw(INTERP_KERNEL::Exception)
1776 if(i>=_items.size())
1777 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
1781 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
1783 std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
1787 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildren() const
1789 std::vector<const BigMemoryObject *> ret;
1790 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1791 ret.push_back(&(*it));
1795 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
1797 std::size_t sz(_items.size());
1798 std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
1799 std::vector<const DataArrayInt *> a1(sz);
1800 std::vector<int> a2(sz);
1802 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1804 a0[i]=(*it).getGeo();
1805 a1[i]=(*it).getPfl(globs);
1806 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
1808 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
1811 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
1814 std::vector< MEDFileField1TSStructItem2 > anItems;
1816 std::vector< std::vector<std::string> > pfls,locs;
1817 std::vector< std::vector<TypeOfField> > typesF;
1818 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1819 std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(0,geoTypes,typesF,pfls,locs);
1820 std::size_t nbOfGeoTypes(geoTypes.size());
1822 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
1824 for(std::size_t i=0;i<nbOfGeoTypes;i++)
1826 std::size_t sz=typesF[i].size();
1827 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
1828 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
1834 for(std::size_t j=0;j<sz;j++)
1836 if(atype==typesF[i][j])
1837 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
1839 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
1842 MEDFileField1TSStructItem ret(atype,anItems);
1843 ret.checkWithMeshStruct(meshSt,ref);
1849 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
1851 return new MEDFileField1TSStruct(ref,mst);
1854 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
1856 _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
1859 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1861 if(_already_checked.empty())
1862 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
1863 _already_checked.back().checkWithMeshStruct(mst,globs);
1866 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
1868 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
1869 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
1878 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
1880 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
1882 if(_already_checked.empty())
1883 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
1884 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
1885 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
1886 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
1887 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
1889 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1890 if((*it).isComputed())
1895 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
1896 ret=this1.isCellSupportEqual(other1,other);
1898 _already_checked.push_back(this1);
1901 ret=_already_checked[found].isCellSupportEqual(other1,other);
1903 _already_checked.push_back(b);
1908 * \param [in] other - a field with only one spatial discretization : ON_NODES.
1910 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
1912 if(_already_checked.empty())
1913 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
1914 MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
1915 if(_already_checked[0].isEntityCell())
1918 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1919 if((*it).isComputed())
1924 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
1925 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
1927 _already_checked.push_back(this1);
1930 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
1932 _already_checked.push_back(other1);
1936 return _already_checked[0].isNodeSupportEqual(other1,other);
1939 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
1941 std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
1945 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildren() const
1947 std::vector<const BigMemoryObject *> ret;
1948 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
1949 ret.push_back(&(*it));
1953 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
1955 if(_already_checked.empty())
1956 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
1957 int pos0(-1),pos1(-1);
1958 if(presenceOfCellDiscr(pos0))
1960 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
1961 if(presenceOfPartialNodeDiscr(pos1))
1962 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
1967 if(!presenceOfPartialNodeDiscr(pos1))
1968 {//we have only all nodes, no cell definition info -> all existing levels !;
1969 return MEDMeshMultiLev::New(mst->getTheMesh(),mst->getTheMesh()->getNonEmptyLevels());
1972 return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
1976 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
1979 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
1981 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
1982 if(a0!=c0 || a1!=c1)
1985 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
1988 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
1994 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
1995 * 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.
1997 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
1999 std::size_t refSz(std::numeric_limits<std::size_t>::max());
2002 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2004 if((*it).getType()!=ON_NODES)
2007 std::size_t sz((*it).getNumberOfItems());
2009 { pos=i; refSz=sz; }
2013 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
2018 * Returns true if presence in \a this of discretization ON_NODES.
2019 * If true is returned the pos of the first element containing the single subpart.
2021 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
2024 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2026 if((*it).getType()==ON_NODES)
2028 std::size_t sz((*it).getNumberOfItems());
2031 if(!(*it)[0].getPflName().empty())
2032 { pos=i; return true; }
2035 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
2043 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2045 return new MEDFileFastCellSupportComparator(m,ref);
2048 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2051 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
2052 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
2053 int nbPts=ref->getNumberOfTS();
2054 _f1ts_cmps.resize(nbPts);
2055 for(int i=0;i<nbPts;i++)
2057 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
2058 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
2059 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
2063 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
2065 std::size_t ret(_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>));
2069 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildren() const
2071 std::vector<const BigMemoryObject *> ret;
2072 const MEDFileMeshStruct *mst(_mesh_comp);
2075 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
2077 const MEDFileField1TSStruct *cur(*it);
2084 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
2086 int nbPts=other->getNumberOfTS();
2087 if(nbPts!=(int)_f1ts_cmps.size())
2089 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2090 throw INTERP_KERNEL::Exception(oss.str().c_str());
2092 for(int i=0;i<nbPts;i++)
2094 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2095 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
2096 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
2102 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
2104 int nbPts=other->getNumberOfTS();
2105 if(nbPts!=(int)_f1ts_cmps.size())
2107 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2108 throw INTERP_KERNEL::Exception(oss.str().c_str());
2110 for(int i=0;i<nbPts;i++)
2112 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2113 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
2119 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2121 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2123 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2124 throw INTERP_KERNEL::Exception(oss.str().c_str());
2126 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2129 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
2130 throw INTERP_KERNEL::Exception(oss.str().c_str());
2132 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
2135 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2137 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
2139 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
2140 throw INTERP_KERNEL::Exception(oss.str().c_str());
2142 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2143 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
2144 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);