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 char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???";
31 MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh)
33 return new MEDFileMeshStruct(mesh);
36 std::size_t MEDFileMeshStruct::getHeapMemorySize() const
39 for(std::vector< std::vector<int> >::const_iterator it0=_geo_types_distrib.begin();it0!=_geo_types_distrib.end();it0++)
40 ret+=(*it0).capacity()*sizeof(int);
41 ret+=_geo_types_distrib.capacity()*sizeof(std::vector<int>);
45 MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh)
47 std::vector<int> levs=mesh->getNonEmptyLevels();
48 _name=mesh->getName();
49 _nb_nodes=mesh->getNumberOfNodes();
50 _geo_types_distrib.resize(levs.size());
51 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
53 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mLev=mesh->getGenMeshAtLevel(*lev);
54 _geo_types_distrib[-(*lev)]=mLev->getDistributionOfTypes();
58 int MEDFileMeshStruct::getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const throw(INTERP_KERNEL::Exception)
61 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++,j--)
63 std::size_t sz=(*it1).size();
65 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : internal error in code !");
66 std::size_t nbGeo=sz/3;
67 for(std::size_t i=0;i<nbGeo;i++)
68 if((*it1)[3*i]==(int)t)
71 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : The specified geometric type is not present in the mesh structure !");
74 int MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const throw(INTERP_KERNEL::Exception)
76 for(std::vector< std::vector<int> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
78 std::size_t sz=(*it1).size();
80 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !");
81 std::size_t nbGeo=sz/3;
82 for(std::size_t i=0;i<nbGeo;i++)
83 if((*it1)[3*i]==(int)t)
86 throw INTERP_KERNEL::Exception("The specified geometric type is not present in the mesh structure !");
89 int MEDFileMeshStruct::getNumberOfLevs() const
91 return (int)_geo_types_distrib.size();
94 int MEDFileMeshStruct::getNumberOfGeoTypesInLev(int relativeLev) const throw(INTERP_KERNEL::Exception)
96 int pos(-relativeLev);
97 if(pos<0 || pos>=_geo_types_distrib.size())
98 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : invalid level specified !");
99 std::size_t sz=_geo_types_distrib[pos].size();
101 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : internal error in code !");
107 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
111 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)
113 _pfl->setName(c.c_str());
116 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
118 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
119 checkInRange(nbOfEnt,1,globs);
122 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
124 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
125 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
126 checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
129 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
132 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
134 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
135 const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
136 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
137 checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
140 std::string MEDFileField1TSStructItem2::getPflName() const
142 return _pfl->getName();
145 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
147 if(!_pfl->isAllocated())
149 if(_pfl->getName().empty())
152 return globs->getProfile(_pfl->getName().c_str());
159 * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
160 * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
162 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
164 _nb_of_entity=nbOfEntity;
165 if(_pfl->getName().empty())
167 if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
168 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !");
174 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
175 const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
177 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
178 pfl->checkAllIdsInRange(0,nbOfEntity);
182 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const char *pflName) const
184 if(startExp!=_start_end.first)
188 if(getPflName()!=pflName)
190 startExp=_start_end.second;
194 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception)
196 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
197 //idem for _loc. It is not an effective attribute for support comparison.
198 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
201 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
203 if(_geo_type!=other._geo_type)
205 if(_nb_of_entity!=other._nb_of_entity)
207 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
209 if(_pfl->getName().empty() && other._pfl->getName().empty())
211 const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
212 return pfl1->isEqualWithoutConsideringStr(*pfl2);
215 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
217 return isCellSupportEqual(other,globs);
221 * \a objs must be non empty. \a objs should contain items having same geometric type.
223 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
226 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
228 return MEDFileField1TSStructItem2(*objs[0]);
229 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
230 int nbEntityRef(objs[0]->_nb_of_entity);
231 std::size_t sz(objs.size());
232 std::vector<const DataArrayInt *> arrs(sz);
233 for(std::size_t i=0;i<sz;i++)
235 const MEDFileField1TSStructItem2 *obj(objs[i]);
236 if(gt!=obj->_geo_type)
237 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
238 if(nbEntityRef!=obj->_nb_of_entity)
239 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
240 if(obj->_pfl->getName().empty())
241 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
242 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
244 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
246 int oldNbTuples(arr->getNumberOfTuples());
247 arr=arr->buildUnique();
248 if(oldNbTuples!=arr->getNumberOfTuples())
249 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
250 if(arr->isIdentity() && oldNbTuples==nbEntityRef)
252 std::pair<int,int> p(0,nbEntityRef);
254 MEDFileField1TSStructItem2 ret(gt,p,a,b);
255 ret._nb_of_entity=nbEntityRef;
260 arr->setName(NEWLY_CREATED_PFL_NAME);
261 std::pair<int,int> p(0,oldNbTuples);
263 MEDFileField1TSStructItem2 ret(gt,p,a,b);
264 ret._nb_of_entity=nbEntityRef;
270 std::size_t MEDFileField1TSStructItem2::getHeapMemorySize() const
273 const DataArrayInt *pfl(_pfl);
275 ret+=pfl->getHeapMemorySize();
276 ret+=_loc.capacity();
282 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
286 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
292 int nbOfEnt=mst->getNumberOfNodes();
294 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
295 _items[0].checkInRange(nbOfEnt,1,globs);
300 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
301 (*it).checkWithMeshStructForCells(mst,globs);
306 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
307 (*it).checkWithMeshStructForGaussNE(mst,globs);
312 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
313 (*it).checkWithMeshStructForGaussPT(mst,globs);
317 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
321 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception)
323 if(_type!=other._type)
325 if(_items.size()!=other._items.size())
327 for(std::size_t i=0;i<_items.size();i++)
328 if(!(_items[i]==other._items[i]))
333 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
335 if(_type!=other._type)
337 if(_items.size()!=other._items.size())
339 for(std::size_t i=0;i<_items.size();i++)
340 if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
345 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
347 if(_type!=other._type)
349 if(_items.size()!=other._items.size())
351 for(std::size_t i=0;i<_items.size();i++)
352 if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
357 bool MEDFileField1TSStructItem::isEntityCell() const
368 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
369 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
371 INTERP_KERNEL::NormalizedCellType _geo_type;
374 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
377 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
378 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
380 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
382 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
384 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
386 (*it0).second.push_back(i);
388 if(m.size()==_items.size())
390 MEDFileField1TSStructItem ret(*this);
394 std::size_t sz(m.size());
395 std::vector< MEDFileField1TSStructItem2 > items(sz);
398 const std::vector<std::size_t>& ids=m[i].second;
399 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
400 for(std::size_t j=0;j<ids.size();j++)
401 objs[j]=&_items[ids[j]];
402 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
404 MEDFileField1TSStructItem ret(ON_CELLS,items);
410 * \a this is expected to be ON_CELLS and simplified.
412 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
414 if(other._type!=ON_NODES)
415 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
416 if(other._items.size()!=1)
417 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
419 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
420 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
421 if(otherNodeIt.getPflName().empty())
425 return theFirstLevFull==0;
429 const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
430 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
432 int nbOfNodes(meshSt->getNumberOfNodes());
433 if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
434 {//on all nodes also !
437 return theFirstLevFull==0;
439 std::vector<bool> nodesFetched(nbOfNodes,false);
440 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
441 return cpyPfl->isFittingWith(nodesFetched);
445 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const throw(INTERP_KERNEL::Exception)
448 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
450 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
451 int nbOfLevs(meshSt->getNumberOfLevs());
453 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
454 std::vector<int> levs(nbOfLevs);
457 std::set<INTERP_KERNEL::NormalizedCellType> gts;
458 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
460 if(!(*it).getPflName().empty())
462 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
463 if(gts.find(gt)!=gts.end())
464 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
466 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
469 for(int i=0;i<nbOfLevs;i++)
470 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
471 { theFirstLevFull=-i; return true; }
475 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const throw(INTERP_KERNEL::Exception)
477 if(i<0 || i>=_items.size())
478 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
482 std::size_t MEDFileField1TSStructItem::getHeapMemorySize() const
485 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
486 ret+=(*it).getHeapMemorySize();
487 ret+=_items.size()*sizeof(MEDFileField1TSStructItem2);
491 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
493 std::vector<INTERP_KERNEL::NormalizedCellType> a0;
494 std::vector<const DataArrayInt *> a1;
497 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
499 a0[i]=(*it).getGeo();
500 a1[i]=(*it).getPfl(globs);
501 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
503 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
508 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst) throw(INTERP_KERNEL::Exception)
510 return new MEDFileField1TSStruct(ref,mst);
513 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
515 _already_checked.push_back(BuildItemFrom(ref,mst));
518 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) throw(INTERP_KERNEL::Exception)
520 if(_already_checked.empty())
521 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
522 _already_checked.back().checkWithMeshStruct(mst,globs);
525 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const throw(INTERP_KERNEL::Exception)
527 MEDFileField1TSStructItem b(BuildItemFrom(other,mst));
528 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
537 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
539 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception)
541 if(_already_checked.empty())
542 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
543 MEDFileField1TSStructItem b(BuildItemFrom(other,meshSt));
544 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
545 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
546 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
548 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
549 if((*it).isComputed())
554 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
555 ret=this1.isCellSupportEqual(other1,other);
557 _already_checked.push_back(this1);
560 ret=_already_checked[found].isCellSupportEqual(other1,other);
562 _already_checked.push_back(b);
566 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception)
568 if(_already_checked.empty())
569 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
570 if(!_already_checked[0].isEntityCell())
571 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : only available on cell entities !");
572 MEDFileField1TSStructItem other1(BuildItemFrom(other,meshSt));
575 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
576 if((*it).isComputed())
581 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
582 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
584 _already_checked.push_back(this1);
587 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
589 _already_checked.push_back(other1);
593 std::size_t MEDFileField1TSStruct::getHeapMemorySize() const
596 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
597 ret+=(*it).getHeapMemorySize();
598 ret+=_already_checked.capacity()*sizeof(MEDFileField1TSStructItem);
602 MEDFileField1TSStructItem MEDFileField1TSStruct::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
605 std::vector< MEDFileField1TSStructItem2 > anItems;
607 std::vector< std::vector<std::string> > pfls,locs;
608 std::vector< std::vector<TypeOfField> > typesF;
609 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
610 std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(0,geoTypes,typesF,pfls,locs);
611 std::size_t nbOfGeoTypes(geoTypes.size());
613 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
615 for(std::size_t i=0;i<nbOfGeoTypes;i++)
617 std::size_t sz=typesF[i].size();
618 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
619 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
625 for(std::size_t j=0;j<sz;j++)
627 if(atype==typesF[i][j])
628 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
630 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
633 MEDFileField1TSStructItem ret(atype,anItems);
634 ret.checkWithMeshStruct(meshSt,ref);
638 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
640 if(_already_checked.empty())
641 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
642 int pos0(-1),pos1(-1);
643 if(presenceOfCellDiscr(pos0))
645 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
646 if(presenceOfPartialNodeDiscr(pos1))
647 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
652 if(!presenceOfPartialNodeDiscr(pos1))
653 {//we have only all nodes, no cell definition info -> level 0;
654 std::vector<int> levs(1,0);
655 return MEDMeshMultiLev::New(mst->getTheMesh(),levs);
658 return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
662 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
665 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
667 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
671 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
674 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
680 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
681 * 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.
683 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const throw(INTERP_KERNEL::Exception)
685 std::size_t refSz(std::numeric_limits<std::size_t>::max());
688 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
690 if((*it).getType()!=ON_NODES)
693 std::size_t sz((*it).getNumberOfItems());
699 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
704 * Returns true if presence in \a this of discretization ON_NODES.
705 * If true is returned the pos of the first element containing the single subpart.
707 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const throw(INTERP_KERNEL::Exception)
710 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
712 if((*it).getType()==ON_NODES)
714 std::size_t sz((*it).getNumberOfItems());
717 if(!(*it)[0].getPflName().empty())
718 { pos=i; return true; }
721 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
729 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception)
731 return new MEDFileFastCellSupportComparator(m,ref);
734 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
737 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
738 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
739 int nbPts=ref->getNumberOfTS();
740 _f1ts_cmps.resize(nbPts);
741 for(int i=0;i<nbPts;i++)
743 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
744 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
745 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
749 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySize() const
752 const MEDFileMeshStruct *mst(_mesh_comp);
754 ret+=mst->getHeapMemorySize();
755 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
757 const MEDFileField1TSStruct *cur(*it);
759 ret+=cur->getHeapMemorySize()+sizeof(MEDFileField1TSStruct);
761 ret+=_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>);
765 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception)
767 int nbPts=other->getNumberOfTS();
768 if(nbPts!=(int)_f1ts_cmps.size())
770 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
771 throw INTERP_KERNEL::Exception(oss.str().c_str());
773 for(int i=0;i<nbPts;i++)
775 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
776 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
777 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
783 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception)
785 int nbPts=other->getNumberOfTS();
786 if(nbPts!=(int)_f1ts_cmps.size())
788 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
789 throw INTERP_KERNEL::Exception(oss.str().c_str());
791 for(int i=0;i<nbPts;i++)
793 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
794 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
800 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
802 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
804 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
805 throw INTERP_KERNEL::Exception(oss.str().c_str());
807 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
810 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
811 throw INTERP_KERNEL::Exception(oss.str().c_str());
813 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
816 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
818 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
820 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
821 throw INTERP_KERNEL::Exception(oss.str().c_str());
823 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
824 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
825 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
830 std::size_t MEDMeshMultiLev::getHeapMemorySize() const
835 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
838 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
839 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
841 return MEDUMeshMultiLev::New(um,levs);
842 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
844 return MEDCMeshMultiLev::New(cm,levs);
845 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
847 return MEDCurveLinearMeshMultiLev::New(clm,levs);
848 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
851 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception)
854 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
855 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
857 return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
858 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
860 return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
861 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
863 return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
864 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
867 MEDMeshMultiLev *MEDMeshMultiLev::NewOnlyOnNode(const MEDFileMesh *m, const DataArrayInt *pflOnNode) throw(INTERP_KERNEL::Exception)
869 std::vector<int> levs(1,0);
870 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,levs));
871 ret->selectPartOfNodes(pflOnNode);
875 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
879 _node_reduction=const_cast<DataArrayInt*>(nr);
882 bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
884 if(fst.getType()==ON_NODES)
886 if(fst.getNumberOfItems()!=1)
887 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::isFastlyTheSameStruct : unexpected situation for nodes !");
888 const MEDFileField1TSStructItem2& p(fst[0]);
889 std::string pflName(p.getPflName());
890 const DataArrayInt *nr(_node_reduction);
891 if(pflName.empty() && !nr)
893 if(pflName==nr->getName())
899 std::size_t sz(fst.getNumberOfItems());
900 if(sz!=_geo_types.size())
903 for(std::size_t i=0;i<sz;i++)
905 const MEDFileField1TSStructItem2& p(fst[i]);
906 if(!p.isFastlyEqual(strt,_geo_types[i],getPflNameOfId(i).c_str()))
913 DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const throw(INTERP_KERNEL::Exception)
915 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(const_cast<DataArray *>(vals)); ret->incrRef();
916 if(isFastlyTheSameStruct(fst,globs))
919 // return constructDataArray(fst,globs,vals);
923 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
925 std::size_t sz(_pfls.size());
927 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
928 const DataArrayInt *pfl(_pfls[id]);
930 return std::string("");
931 return pfl->getName();
934 MEDMeshMultiLev::MEDMeshMultiLev()
938 MEDMeshMultiLev::MEDMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):_geo_types(gts),_nb_entities(nbEntities)
940 std::size_t sz(_geo_types.size());
941 if(sz!=pfls.size() || sz!=nbEntities.size())
942 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
944 for(std::size_t i=0;i<sz;i++)
948 _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
952 MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):_pfls(other._pfls),_geo_types(other._geo_types),_nb_entities(other._nb_entities),_node_reduction(other._node_reduction)
958 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
960 return new MEDUMeshMultiLev(m,levs);
963 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs)
966 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
967 std::vector<MEDCoupling1GTUMesh *> v;
968 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
970 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
971 v.insert(v.end(),vTmp.begin(),vTmp.end());
973 std::size_t sz(v.size());
976 _geo_types.resize(sz);
977 for(std::size_t i=0;i<sz;i++)
979 MEDCoupling1GTUMesh *obj(v[i]);
983 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
985 _geo_types[i]=obj->getCellModelEnum();
989 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception)
991 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
994 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
996 std::size_t sz(gts.size());
998 for(std::size_t i=0;i<sz;i++)
1000 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
1007 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception)
1009 if(!pflNodes || !pflNodes->isAllocated())
1011 std::size_t sz(_parts.size());
1012 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
1013 std::vector< const DataArrayInt *> aa(sz);
1014 for(std::size_t i=0;i<sz;i++)
1017 const DataArrayInt *pfl(_pfls[i]);
1018 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
1020 m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1021 DataArrayInt *cellIds=0;
1022 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1023 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
1024 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1026 a[i]=m2->getNodeIdsInUse(tmp); aa[i]=a[i];
1028 _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1030 _pfls[i]=cellIdsSafe;
1032 _node_reduction=DataArrayInt::Aggregate(aa);
1033 _node_reduction->sort(true);
1034 _node_reduction=_node_reduction->buildUnique();
1037 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const throw(INTERP_KERNEL::Exception)
1039 return new MEDUMeshMultiLev(*this);
1042 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts)
1046 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
1054 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev()
1058 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
1062 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes) throw(INTERP_KERNEL::Exception)
1064 if(!pflNodes || !pflNodes->isAllocated())
1066 std::vector<int> ngs(getNodeGridStructure());
1067 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1068 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
1069 m->setNodalConnectivity(conn);
1070 const DataArrayInt *pfl(_pfls[0]);
1073 m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1075 DataArrayInt *cellIds=0;
1076 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1077 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
1078 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1080 _node_reduction=m2->getNodeIdsInUse(tmp);
1082 _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1084 _pfls[0]=cellIdsSafe;
1087 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other)
1093 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
1095 return new MEDCMeshMultiLev(m,levs);
1098 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception)
1100 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
1103 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs)
1106 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
1107 if(levs.size()!=1 || levs[0]!=0)
1108 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
1109 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1110 _coords.resize(mdim);
1111 for(int i=0;i<mdim;i++)
1113 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1115 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1120 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(gts,pfls,nbEntities)
1123 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
1124 if(gts.size()!=1 || pfls.size()!=1)
1125 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1126 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1128 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1129 _coords.resize(mdim);
1130 for(int i=0;i<mdim;i++)
1132 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1134 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1139 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other)
1143 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const throw(INTERP_KERNEL::Exception)
1145 std::vector<int> ret(_coords.size());
1146 for(std::size_t i=0;i<_coords.size();i++)
1147 ret[i]=_coords[i]->getNumberOfTuples();
1151 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const throw(INTERP_KERNEL::Exception)
1153 const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
1154 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1155 std::vector<int> cgs,ngs(getNodeGridStructure());
1156 cgs.resize(ngs.size());
1157 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1160 std::vector< std::pair<int,int> > cellParts;
1161 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1163 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1165 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1166 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1168 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
1169 for(std::size_t i=0;i<_coords.size();i++)
1170 coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
1171 ret->_coords=coords;
1176 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1177 for(std::size_t i=0;i<ngs.size();i++)
1178 m->setCoordsAt(i,_coords[i]);
1179 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1180 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1181 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1183 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1189 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1191 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1198 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
1200 return new MEDCurveLinearMeshMultiLev(m,levs);
1203 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities) throw(INTERP_KERNEL::Exception)
1205 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1208 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1211 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1212 if(levs.size()!=1 || levs[0]!=0)
1213 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1214 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1216 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1219 _structure=m->getMesh()->getNodeGridStructure();
1222 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDStructuredMeshMultiLev(gts,pfls,nbEntities)
1225 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1226 if(gts.size()!=1 || pfls.size()!=1)
1227 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1228 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1230 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1231 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1233 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1236 _structure=m->getMesh()->getNodeGridStructure();
1239 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1243 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const throw(INTERP_KERNEL::Exception)
1248 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const throw(INTERP_KERNEL::Exception)
1250 const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
1251 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1252 std::vector<int> cgs,ngs(getNodeGridStructure());
1253 cgs.resize(ngs.size());
1254 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1257 std::vector< std::pair<int,int> > cellParts,nodeParts;
1258 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1260 nodeParts=cellParts;
1261 std::vector<int> st(ngs.size());
1262 for(std::size_t i=0;i<ngs.size();i++)
1264 nodeParts[i].second++;
1265 st[i]=nodeParts[i].second-nodeParts[i].first;
1267 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1268 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1270 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1271 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1273 ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1279 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1280 m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1281 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1282 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1283 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1285 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1291 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1293 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }