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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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 MEDFileFieldGlobs *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::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception)
184 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
185 //idem for _loc. It is not an effective attribute for support comparison.
186 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
189 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
191 if(_geo_type!=other._geo_type)
193 if(_nb_of_entity!=other._nb_of_entity)
195 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
197 if(_pfl->getName().empty() && other._pfl->getName().empty())
199 const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
200 return pfl1->isEqualWithoutConsideringStr(*pfl2);
203 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
205 return isCellSupportEqual(other,globs);
209 * \a objs must be non empty. \a objs should contain items having same geometric type.
211 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception)
214 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
216 return MEDFileField1TSStructItem2(*objs[0]);
217 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
218 int nbEntityRef(objs[0]->_nb_of_entity);
219 std::size_t sz(objs.size());
220 std::vector<const DataArrayInt *> arrs(sz);
221 for(std::size_t i=0;i<sz;i++)
223 const MEDFileField1TSStructItem2 *obj(objs[i]);
224 if(gt!=obj->_geo_type)
225 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
226 if(nbEntityRef!=obj->_nb_of_entity)
227 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
228 if(obj->_pfl->getName().empty())
229 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
230 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
232 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
234 int oldNbTuples(arr->getNumberOfTuples());
235 arr=arr->buildUnique();
236 if(oldNbTuples!=arr->getNumberOfTuples())
237 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
238 if(arr->isIdentity() && oldNbTuples==nbEntityRef)
240 std::pair<int,int> p(0,nbEntityRef);
242 MEDFileField1TSStructItem2 ret(gt,p,a,b);
243 ret._nb_of_entity=nbEntityRef;
248 arr->setName(NEWLY_CREATED_PFL_NAME);
249 std::pair<int,int> p(0,oldNbTuples);
251 MEDFileField1TSStructItem2 ret(gt,p,a,b);
252 ret._nb_of_entity=nbEntityRef;
258 std::size_t MEDFileField1TSStructItem2::getHeapMemorySize() const
261 const DataArrayInt *pfl(_pfl);
263 ret+=pfl->getHeapMemorySize();
264 ret+=_loc.capacity();
270 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
274 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception)
280 int nbOfEnt=mst->getNumberOfNodes();
282 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
283 _items[0].checkInRange(nbOfEnt,1,globs);
288 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
289 (*it).checkWithMeshStructForCells(mst,globs);
294 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
295 (*it).checkWithMeshStructForGaussNE(mst,globs);
300 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
301 (*it).checkWithMeshStructForGaussPT(mst,globs);
305 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
309 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception)
311 if(_type!=other._type)
313 if(_items.size()!=other._items.size())
315 for(std::size_t i=0;i<_items.size();i++)
316 if(!(_items[i]==other._items[i]))
321 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) 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].isCellSupportEqual(other._items[i],globs)))
333 bool MEDFileField1TSStructItem::isNodeSupportEqual(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].isNodeSupportEqual(other._items[i],globs)))
345 bool MEDFileField1TSStructItem::isEntityCell() const
356 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
357 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
359 INTERP_KERNEL::NormalizedCellType _geo_type;
362 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobs *globs) const throw(INTERP_KERNEL::Exception)
365 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
366 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
368 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
370 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
372 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
374 (*it0).second.push_back(i);
376 if(m.size()==_items.size())
378 MEDFileField1TSStructItem ret(*this);
382 std::size_t sz(m.size());
383 std::vector< MEDFileField1TSStructItem2 > items(sz);
386 const std::vector<std::size_t>& ids=m[i].second;
387 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
388 for(std::size_t j=0;j<ids.size();j++)
389 objs[j]=&_items[ids[j]];
390 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
392 MEDFileField1TSStructItem ret(ON_CELLS,items);
398 * \a this is expected to be ON_CELLS and simplified.
400 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobs *globs) const throw(INTERP_KERNEL::Exception)
402 if(other._type!=ON_NODES)
403 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
404 if(other._items.size()!=1)
405 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
407 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
408 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
409 if(otherNodeIt.getPflName().empty())
413 return theFirstLevFull==0;
417 const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
418 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
420 int nbOfNodes(meshSt->getNumberOfNodes());
421 if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
422 {//on all nodes also !
425 return theFirstLevFull==0;
427 std::vector<bool> nodesFetched(nbOfNodes,false);
428 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
429 return cpyPfl->isFittingWith(nodesFetched);
433 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const throw(INTERP_KERNEL::Exception)
436 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
438 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
439 int nbOfLevs(meshSt->getNumberOfLevs());
441 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
442 std::vector<int> levs(nbOfLevs);
445 std::set<INTERP_KERNEL::NormalizedCellType> gts;
446 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
448 if(!(*it).getPflName().empty())
450 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
451 if(gts.find(gt)!=gts.end())
452 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
454 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
457 for(int i=0;i<nbOfLevs;i++)
458 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
459 { theFirstLevFull=-i; return true; }
463 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const throw(INTERP_KERNEL::Exception)
465 if(i<0 || i>=_items.size())
466 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
470 std::size_t MEDFileField1TSStructItem::getHeapMemorySize() const
473 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
474 ret+=(*it).getHeapMemorySize();
475 ret+=_items.size()*sizeof(MEDFileField1TSStructItem2);
479 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
481 std::vector<INTERP_KERNEL::NormalizedCellType> a0;
482 std::vector<const DataArrayInt *> a1;
485 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
487 a0[i]=(*it).getGeo();
488 a1[i]=(*it).getPfl(globs);
489 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
491 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
496 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst) throw(INTERP_KERNEL::Exception)
498 return new MEDFileField1TSStruct(ref,mst);
501 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
503 _already_checked.push_back(BuildItemFrom(ref,mst));
506 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobs *globs) throw(INTERP_KERNEL::Exception)
508 if(_already_checked.empty())
509 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
510 _already_checked.back().checkWithMeshStruct(mst,globs);
513 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const throw(INTERP_KERNEL::Exception)
515 MEDFileField1TSStructItem b(BuildItemFrom(other,mst));
516 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
525 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
527 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception)
529 if(_already_checked.empty())
530 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
531 MEDFileField1TSStructItem b(BuildItemFrom(other,meshSt));
532 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
533 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
534 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other->contentNotNull()));
536 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
537 if((*it).isComputed())
542 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other->contentNotNull()));
543 ret=this1.isCellSupportEqual(other1,other);
545 _already_checked.push_back(this1);
548 ret=_already_checked[found].isCellSupportEqual(other1,other);
550 _already_checked.push_back(b);
554 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception)
556 if(_already_checked.empty())
557 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
558 if(!_already_checked[0].isEntityCell())
559 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : only available on cell entities !");
560 MEDFileField1TSStructItem other1(BuildItemFrom(other,meshSt));
563 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
564 if((*it).isComputed())
569 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other->contentNotNull()));
570 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other->contentNotNull());
572 _already_checked.push_back(this1);
575 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other->contentNotNull());
577 _already_checked.push_back(other1);
581 std::size_t MEDFileField1TSStruct::getHeapMemorySize() const
584 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
585 ret+=(*it).getHeapMemorySize();
586 ret+=_already_checked.capacity()*sizeof(MEDFileField1TSStructItem);
590 MEDFileField1TSStructItem MEDFileField1TSStruct::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
593 std::vector< MEDFileField1TSStructItem2 > anItems;
595 std::vector< std::vector<std::string> > pfls,locs;
596 std::vector< std::vector<TypeOfField> > typesF;
597 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
598 std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(0,geoTypes,typesF,pfls,locs);
599 std::size_t nbOfGeoTypes(geoTypes.size());
601 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
603 for(std::size_t i=0;i<nbOfGeoTypes;i++)
605 std::size_t sz=typesF[i].size();
606 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
607 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
613 for(std::size_t j=0;j<sz;j++)
615 if(atype==typesF[i][j])
616 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
618 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
621 MEDFileField1TSStructItem ret(atype,anItems);
622 ret.checkWithMeshStruct(meshSt,ref->contentNotNull());
626 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
628 if(_already_checked.empty())
629 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
630 int pos0(-1),pos1(-1);
631 if(presenceOfCellDiscr(pos0))
633 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
634 if(presenceOfPartialNodeDiscr(pos1))
635 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
640 if(!presenceOfPartialNodeDiscr(pos1))
641 {//we have only all nodes, no cell definition info -> level 0;
642 std::vector<int> levs(1,0);
643 return MEDMeshMultiLev::New(mst->getTheMesh(),levs);
648 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
651 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
653 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
657 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
660 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
666 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
667 * 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.
669 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const throw(INTERP_KERNEL::Exception)
671 std::size_t refSz(std::numeric_limits<std::size_t>::max());
674 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
676 if((*it).getType()!=ON_NODES)
679 std::size_t sz((*it).getNumberOfItems());
685 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
690 * Returns true if presence in \a this of discretization ON_NODES.
691 * If true is returned the pos of the first element containing the single subpart.
693 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const throw(INTERP_KERNEL::Exception)
696 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
698 if((*it).getType()==ON_NODES)
700 std::size_t sz((*it).getNumberOfItems());
703 if(!(*it)[0].getPflName().empty())
704 { pos=i; return true; }
707 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
715 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception)
717 return new MEDFileFastCellSupportComparator(m,ref);
720 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
723 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
724 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
725 int nbPts=ref->getNumberOfTS();
726 _f1ts_cmps.resize(nbPts);
727 for(int i=0;i<nbPts;i++)
729 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
730 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
731 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt->contentNotNull());
735 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySize() const
738 const MEDFileMeshStruct *mst(_mesh_comp);
740 ret+=mst->getHeapMemorySize();
741 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
743 const MEDFileField1TSStruct *cur(*it);
745 ret+=cur->getHeapMemorySize()+sizeof(MEDFileField1TSStruct);
747 ret+=_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>);
751 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception)
753 int nbPts=other->getNumberOfTS();
754 if(nbPts!=(int)_f1ts_cmps.size())
756 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
757 throw INTERP_KERNEL::Exception(oss.str().c_str());
759 for(int i=0;i<nbPts;i++)
761 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
762 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
763 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
769 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other) throw(INTERP_KERNEL::Exception)
771 int nbPts=other->getNumberOfTS();
772 if(nbPts!=(int)_f1ts_cmps.size())
774 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
775 throw INTERP_KERNEL::Exception(oss.str().c_str());
777 for(int i=0;i<nbPts;i++)
779 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
780 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
786 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
788 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
790 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
791 throw INTERP_KERNEL::Exception(oss.str().c_str());
793 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
796 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
797 throw INTERP_KERNEL::Exception(oss.str().c_str());
799 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
802 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception)
804 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
806 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
807 throw INTERP_KERNEL::Exception(oss.str().c_str());
809 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
810 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
811 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
816 std::size_t MEDMeshMultiLev::getHeapMemorySize() const
821 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
824 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
825 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
827 return MEDUMeshMultiLev::New(um,levs);
828 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
830 return MEDCMeshMultiLev::New(cm,levs);
831 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
833 return MEDCurveLinearMeshMultiLev::New(clm,levs);
834 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
837 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)
840 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
841 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
843 return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
844 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
846 return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
847 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
849 return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
850 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
853 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
857 _node_reduction=const_cast<DataArrayInt*>(nr);
860 MEDMeshMultiLev::MEDMeshMultiLev()
864 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)
866 std::size_t sz(_geo_types.size());
867 if(sz!=pfls.size() || sz!=nbEntities.size())
868 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
870 for(std::size_t i=0;i<sz;i++)
874 _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
878 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
880 return new MEDUMeshMultiLev(m,levs);
883 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs)
886 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
887 std::vector<MEDCoupling1GTUMesh *> v;
888 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
890 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
891 v.insert(v.end(),vTmp.begin(),vTmp.end());
893 std::size_t sz(v.size());
896 _geo_types.resize(sz);
897 for(std::size_t i=0;i<sz;i++)
899 MEDCoupling1GTUMesh *obj(v[i]);
903 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
905 _geo_types[i]=obj->getCellModelEnum();
909 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)
911 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
914 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)
916 std::size_t sz(gts.size());
918 for(std::size_t i=0;i<sz;i++)
920 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
927 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
929 return new MEDCMeshMultiLev(m,levs);
932 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)
934 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
937 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs)
940 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
941 if(levs.size()!=1 || levs[0]!=0)
942 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
943 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
944 _coords.resize(mdim);
945 for(int i=0;i<mdim;i++)
947 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
949 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
954 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
957 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
958 if(gts.size()!=1 || pfls.size()!=1)
959 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
960 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
962 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
963 _coords.resize(mdim);
964 for(int i=0;i<mdim;i++)
966 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
968 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
973 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs) throw(INTERP_KERNEL::Exception)
975 return new MEDCurveLinearMeshMultiLev(m,levs);
978 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)
980 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
983 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
986 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
987 if(levs.size()!=1 || levs[0]!=0)
988 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
989 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
991 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
994 _structure=m->getMesh()->getNodeGridStructure();
997 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities):MEDMeshMultiLev(gts,pfls,nbEntities)
1000 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1001 if(gts.size()!=1 || pfls.size()!=1)
1002 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1003 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1005 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1006 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1008 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1011 _structure=m->getMesh()->getNodeGridStructure();