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,255,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 std::vector<int> levs(1,0);
157 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,levs));
158 ret->selectPartOfNodes(pflOnNode);
162 void MEDMeshMultiLev::setNodeReduction(const DataArrayInt *nr)
166 _node_reduction=const_cast<DataArrayInt*>(nr);
169 bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const
171 if(fst.getType()==ON_NODES)
173 if(fst.getNumberOfItems()!=1)
174 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::isFastlyTheSameStruct : unexpected situation for nodes !");
175 const MEDFileField1TSStructItem2& p(fst[0]);
176 std::string pflName(p.getPflName());
177 const DataArrayInt *nr(_node_reduction);
178 if(pflName.empty() && !nr)
180 if(pflName==nr->getName())
186 std::size_t sz(fst.getNumberOfItems());
187 if(sz!=_geo_types.size())
190 for(std::size_t i=0;i<sz;i++)
192 const MEDFileField1TSStructItem2& p(fst[i]);
193 if(!p.isFastlyEqual(strt,_geo_types[i],getPflNameOfId(i).c_str()))
200 DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
202 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(const_cast<DataArray *>(vals)); ret->incrRef();
203 if(isFastlyTheSameStruct(fst,globs))
206 return constructDataArray(fst,globs,vals);
210 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
211 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
213 void MEDMeshMultiLev::retrieveFamilyIdsOnCells(DataArrayInt *& famIds, bool& isWithoutCopy) const
215 const DataArrayInt *fids(_cell_fam_ids);
217 { famIds=0; isWithoutCopy=true; return ; }
218 std::size_t sz(_geo_types.size());
219 bool presenceOfPfls(false);
220 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
222 const DataArrayInt *pfl(_pfls[i]);
227 { famIds=const_cast<DataArrayInt *>(fids); famIds->incrRef(); isWithoutCopy=_cell_fam_ids_nocpy; return ; }
228 //bad luck the slowest part
230 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
231 std::vector< const DataArrayInt *> ret(sz);
233 for(std::size_t i=0;i<sz;i++)
235 const DataArrayInt *pfl(_pfls[i]);
236 int lgth(_nb_entities[i]);
239 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(fids->selectByTupleId2(start,start+lgth,1));
240 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
244 retSafe[i]=fids->selectByTupleId2(start,start+lgth,1);
249 famIds=DataArrayInt::Aggregate(ret);
253 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
254 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
256 void MEDMeshMultiLev::retrieveNumberIdsOnCells(DataArrayInt *& numIds, bool& isWithoutCopy) const
258 const DataArrayInt *nids(_cell_num_ids);
260 { numIds=0; isWithoutCopy=true; return ; }
261 std::size_t sz(_geo_types.size());
262 bool presenceOfPfls(false);
263 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
265 const DataArrayInt *pfl(_pfls[i]);
270 { numIds=const_cast<DataArrayInt *>(nids); numIds->incrRef(); isWithoutCopy=_cell_num_ids_nocpy; return ; }
271 //bad luck the slowest part
273 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > retSafe(sz);
274 std::vector< const DataArrayInt *> ret(sz);
276 for(std::size_t i=0;i<sz;i++)
278 const DataArrayInt *pfl(_pfls[i]);
279 int lgth(_nb_entities[i]);
282 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(nids->selectByTupleId2(start,start+lgth,1));
283 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
287 retSafe[i]=nids->selectByTupleId2(start,start+lgth,1);
292 numIds=DataArrayInt::Aggregate(ret);
295 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
297 std::size_t sz(_pfls.size());
298 if(id<0 || id>=(int)sz)
299 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
300 const DataArrayInt *pfl(_pfls[id]);
302 return std::string("");
303 return pfl->getName();
307 * Returns the number of cells having geometric type \a t.
308 * The profiles are **NOT** taken into account here.
310 int MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
312 std::size_t sz(_nb_entities.size());
313 for(std::size_t i=0;i<sz;i++)
315 return _nb_entities[i];
316 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
319 int MEDMeshMultiLev::getNumberOfNodes() const
324 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
326 if(fst.getType()==ON_NODES)
328 if(fst.getNumberOfItems()!=1)
329 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
330 const MEDFileField1TSStructItem2& p(fst[0]);
331 std::string pflName(p.getPflName());
332 const DataArrayInt *nr(_node_reduction);
333 if(pflName.empty() && !nr)
334 return vals->deepCpy();
335 if(pflName.empty() && nr)
336 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
337 if(!pflName.empty() && nr)
339 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
340 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(nr->deepCpy());
341 p1->sort(true); p2->sort(true);
342 if(!p1->isEqualWithoutConsideringStr(*p2))
343 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 3 !");
344 p1=DataArrayInt::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
345 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
346 ret->renumberInPlace(p1->begin());
349 if(!pflName.empty() && !nr)
351 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
353 if(!p1->isIdentity() || p1->getNumberOfTuples()!=getNumberOfNodes())
354 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
355 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
356 ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
359 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
363 std::size_t sz(fst.getNumberOfItems());
364 std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
365 if(s.size()!=_geo_types.size())
366 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
367 std::vector< const DataArray *> arr(s.size());
368 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arrSafe(s.size());
370 int nc(vals->getNumberOfComponents());
371 std::vector<std::string> compInfo(vals->getInfoOnComponents());
372 for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
374 const DataArrayInt *thisP(_pfls[iii]);
375 std::vector<const MEDFileField1TSStructItem2 *> ps;
376 for(std::size_t i=0;i<sz;i++)
378 const MEDFileField1TSStructItem2& p(fst[i]);
383 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
386 int nbi(ps[0]->getNbOfIntegrationPts(globs));
387 const DataArrayInt *otherP(ps[0]->getPfl(globs));
388 const std::pair<int,int>& strtStop(ps[0]->getStartStop());
389 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
390 if(!thisP && !otherP)
392 arrSafe[iii]=ret; arr[iii]=ret;
397 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
398 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(thisP->deepCpy());
399 p2->transformWithIndArr(p1->begin(),p1->end());
400 //p1=p2->getIdsNotEqual(-1);
401 //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
402 ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
403 arrSafe[iii]=ret; arr[iii]=ret;
408 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->deepCpy());
410 p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
411 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,p1);
412 ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
413 arrSafe[iii]=ret; arr[iii]=ret;
416 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
420 std::vector< const DataArrayInt * >otherPS(ps.size());
421 std::vector< const DataArray * > arr2(ps.size());
422 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arr2Safe(ps.size());
423 std::vector< const DataArrayInt * > nbis(ps.size());
424 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > nbisSafe(ps.size());
426 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
428 int nbi((*it2)->getNbOfIntegrationPts(globs));
429 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
430 const std::pair<int,int>& strtStop((*it2)->getStartStop());
431 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
433 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
434 arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
435 nbisSafe[jj]=DataArrayInt::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
436 nbis[jj]=nbisSafe[jj];
438 MEDCouplingAutoRefCountObjectPtr<DataArray> arr3(DataArray::Aggregate(arr2));
439 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherP(DataArrayInt::Aggregate(otherPS));
440 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbis(DataArrayInt::Aggregate(nbis));
441 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
442 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1;
444 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,thisP);
446 p1=otherP->deepCpy();
447 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbisN(zenbis->renumber(p1->begin()));
448 zenbisN->computeOffsets2();
450 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
452 //int nbi((*it2)->getNbOfIntegrationPts(globs));
453 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
454 const std::pair<int,int>& strtStop((*it2)->getStartStop());
455 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
457 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(otherPfl->deepCpy());
458 p2->transformWithIndArr(otherPN->begin(),otherPN->end());
459 p2->transformWithIndArr(p1->begin(),p1->end());
460 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsN(p2->buildExplicitArrByRanges(zenbisN));
461 arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
463 arrSafe[iii]=arr3; arr[iii]=arr3;
467 return DataArray::Aggregate(arr);
471 MEDMeshMultiLev::MEDMeshMultiLev():_nb_nodes(0),_cell_fam_ids_nocpy(false)
475 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)
477 std::size_t sz(_geo_types.size());
478 if(sz!=pfls.size() || sz!=nbEntities.size())
479 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
481 for(std::size_t i=0;i<sz;i++)
485 _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
489 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)
495 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
497 return new MEDUMeshMultiLev(m,levs);
500 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs)
503 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
504 std::vector<MEDCoupling1GTUMesh *> v;
505 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
507 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
508 v.insert(v.end(),vTmp.begin(),vTmp.end());
510 std::size_t sz(v.size());
513 _geo_types.resize(sz);
514 _nb_entities.resize(sz);
515 for(std::size_t i=0;i<sz;i++)
517 MEDCoupling1GTUMesh *obj(v[i]);
521 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
523 _geo_types[i]=obj->getCellModelEnum();
524 _nb_entities[i]=obj->getNumberOfCells();
526 // ids fields management
527 _cell_fam_ids_nocpy=(levs.size()==1);
528 if(_cell_fam_ids_nocpy)
530 const DataArrayInt *tmp(m->getFamilyFieldAtLevel(levs[0]));
534 _cell_fam_ids=(const_cast<DataArrayInt *>(tmp));
539 std::vector<const DataArrayInt *> tmps(levs.size());
541 for(std::size_t i=0;i<levs.size();i++)
543 tmps[i]=m->getFamilyFieldAtLevel(levs[i]);
548 _cell_fam_ids=DataArrayInt::Aggregate(tmps);
550 _cell_num_ids_nocpy=(levs.size()==1);
551 if(_cell_num_ids_nocpy)
553 const DataArrayInt *tmp(m->getNumberFieldAtLevel(levs[0]));
557 _cell_num_ids=(const_cast<DataArrayInt *>(tmp));
562 std::vector<const DataArrayInt *> tmps(levs.size());
564 for(std::size_t i=0;i<levs.size();i++)
566 tmps[i]=m->getNumberFieldAtLevel(levs[i]);
571 _cell_num_ids=DataArrayInt::Aggregate(tmps);
575 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
577 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
580 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)
582 std::size_t sz(gts.size());
584 for(std::size_t i=0;i<sz;i++)
586 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
591 // ids fields management
592 _cell_fam_ids_nocpy=false;
593 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > famIdsSafe(sz);
594 std::vector<const DataArrayInt *> famIds(sz);
596 for(std::size_t i=0;i<sz;i++)
598 famIdsSafe[i]=m->extractFamilyFieldOnGeoType(gts[i]);
599 famIds[i]=famIdsSafe[i];
604 _cell_fam_ids=DataArrayInt::Aggregate(famIds);
607 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
609 if(!pflNodes || !pflNodes->isAllocated())
611 std::size_t sz(_parts.size());
612 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
613 std::vector< const DataArrayInt *> aa(sz);
614 for(std::size_t i=0;i<sz;i++)
617 const DataArrayInt *pfl(_pfls[i]);
618 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
620 m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
621 DataArrayInt *cellIds=0;
622 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
623 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
624 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
626 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m2->getNodeIdsInUse(tmp));
627 a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
629 _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
631 _pfls[i]=cellIdsSafe;
633 _node_reduction=DataArrayInt::Aggregate(aa);
634 _node_reduction->sort(true);
635 _node_reduction=_node_reduction->buildUnique();
638 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
640 return new MEDUMeshMultiLev(*this);
643 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts)
647 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
651 _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
652 _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
653 _pfls.resize(1); _pfls[0]=0;
657 * 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.
658 * 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.
660 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const
663 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : empty array !");
664 if(!(const MEDCoupling1GTUMesh *)_parts[0])
665 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : first part is null !");
666 const DataArrayDouble *tmp(_parts[0]->getCoords());
668 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
669 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
670 int szBCE(0),szD(0),szF(0);
673 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
675 const MEDCoupling1GTUMesh *cur(*it);
677 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
679 const DataArrayInt *pfl(_pfls[iii]);
680 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
682 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
684 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
686 int curNbCells(cur->getNumberOfCells());
688 if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
689 szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
693 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(cur->computeEffectiveNbOfNodesPerCell());
694 szD+=tmp2->accumulate(0)+curNbCells;
695 szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
698 MEDCouplingAutoRefCountObjectPtr<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
699 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()); c->alloc(szBCE,1); int *cPtr(c->getPointer());
700 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d(DataArrayInt::New()); d->alloc(szD,1); int *dPtr(d->getPointer());
701 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> e(DataArrayInt::New()),f(DataArrayInt::New()); int *ePtr(0),*fPtr(0);
703 { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
706 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
708 const MEDCoupling1GTUMesh *cur(*it);
710 const DataArrayInt *pfl(_pfls[iii]);
711 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
713 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
715 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
717 int curNbCells(cur->getNumberOfCells());
718 int gt((int)cur->getCellModelEnum());
719 if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
720 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
721 unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
723 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
724 std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
725 const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
726 const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
727 const int *connPtr(cur->getNodalConnectivity()->begin());
729 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
732 int nnpc(scur->getNumberOfNodesPerCell());
733 for(int i=0;i<curNbCells;i++,connPtr+=nnpc)
736 dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
737 *cPtr=k+nnpc; k=*cPtr++;
740 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
744 const int *connIPtr(dcur->getNodalConnectivityIndex()->begin());
745 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
747 for(int i=0;i<curNbCells;i++,connIPtr++)
749 *dPtr++=connIPtr[1]-connIPtr[0];
750 dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
751 *cPtr=k+connIPtr[1]-connIPtr[0]; k=*cPtr++;
756 for(int i=0;i<curNbCells;i++,connIPtr++)
758 std::set<int> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
759 *dPtr++=(int)s.size();
760 dPtr=std::copy(s.begin(),s.end(),dPtr);
761 *cPtr=k+(int)s.size(); k=*cPtr++;
766 connIPtr=dcur->getNodalConnectivityIndex()->begin();
767 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
768 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
772 for(int i=0;i<curNbCells;i++,connIPtr++)
774 int nbFace(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1);
776 const int *work(connPtr+connIPtr[0]);
777 for(int j=0;j<nbFace;j++)
779 const int *work2=std::find(work,connPtr+connIPtr[1],-1);
780 *fPtr++=std::distance(work,work2);
781 fPtr=std::copy(work,work2,fPtr);
784 *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
791 reorderNodesIfNecessary(a,d,0);
793 reorderNodesIfNecessary(a,d,f);
794 if(a->getNumberOfComponents()!=3)
795 a=a->changeNbOfComponents(3,0.);
796 coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
798 { faceLocations=0; faces=0; }
800 { faceLocations=e.retn(); faces=f.retn(); }
801 return tmp==((DataArrayDouble *)a);
804 void MEDUMeshMultiLev::reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const
806 const DataArrayInt *nr(_node_reduction);
809 int sz(coords->getNumberOfTuples());
810 std::vector<bool> b(sz,false);
811 const int *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
815 for(int i=0;i<nb && work!=endW;i++,work++)
817 if(*work>=0 && *work<sz)
820 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
823 if(polyhedNodalConnVTK)
825 work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
829 for(int i=0;i<nb && work!=endW;i++)
832 for(int j=0;j<nb2 && work!=endW;j++,work++)
834 if(*work>=0 && *work<sz)
837 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
842 int szExp(std::count(b.begin(),b.end(),true));
843 if(szExp!=nr->getNumberOfTuples())
844 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
846 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(DataArrayInt::New()); o2n->alloc(sz,1);
847 int *o2nPtr(o2n->getPointer());
849 for(int i=0;i<sz;i++,o2nPtr++)
850 if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
851 const int *o2nPtrc(o2n->begin());
852 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
853 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> perm(DataArrayInt::FindPermutationFromFirstToSecond(n2o,nr));
854 const int *permPtr(perm->begin());
855 int *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
859 for(int i=0;i<nb && work2!=endW2;i++,work2++)
860 *work2=permPtr[o2nPtrc[*work2]];
862 if(polyhedNodalConnVTK)
864 work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
868 for(int i=0;i<nb && work2!=endW2;i++)
871 for(int j=0;j<nb2 && work2!=endW2;j++,work2++)
872 *work2=permPtr[o2nPtrc[*work2]];
876 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
881 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev()
885 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(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)
889 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
891 if(!pflNodes || !pflNodes->isAllocated())
893 std::vector<int> ngs(getNodeGridStructure());
894 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
895 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
896 m->setNodalConnectivity(conn);
897 const DataArrayInt *pfl(_pfls[0]);
900 m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
902 DataArrayInt *cellIds=0;
903 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
904 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
905 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
907 _node_reduction=m2->getNodeIdsInUse(tmp);
909 _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
911 _pfls[0]=cellIdsSafe;
914 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other)
920 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
922 return new MEDCMeshMultiLev(m,levs);
925 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
927 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
930 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs)
933 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
934 if(levs.size()!=1 || levs[0]!=0)
935 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
936 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
937 _coords.resize(mdim);
938 for(int i=0;i<mdim;i++)
940 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
942 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
945 // ids fields management
946 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
947 const DataArrayInt *tmp(0);
948 tmp=m->getFamilyFieldAtLevel(0);
952 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
954 tmp=m->getNumberFieldAtLevel(0);
958 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
962 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->getNumberOfNodes(),gts,pfls,nbEntities)
965 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
966 if(gts.size()!=1 || pfls.size()!=1)
967 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
968 int mdim(m->getMeshDimension());
969 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
971 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
972 _coords.resize(mdim);
973 for(int i=0;i<mdim;i++)
975 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
977 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
978 _coords[i]=elt; _coords[i]->incrRef();
980 // ids fields management
981 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
982 const DataArrayInt *tmp(0);
983 tmp=m->getFamilyFieldAtLevel(0);
987 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
989 tmp=m->getNumberFieldAtLevel(0);
993 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
997 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1001 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const
1003 std::vector<int> ret(_coords.size());
1004 for(std::size_t i=0;i<_coords.size();i++)
1005 ret[i]=_coords[i]->getNumberOfTuples();
1009 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1011 const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
1012 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1013 std::vector<int> cgs,ngs(getNodeGridStructure());
1014 cgs.resize(ngs.size());
1015 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1018 std::vector< std::pair<int,int> > cellParts;
1019 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1021 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1023 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1024 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1026 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
1027 for(std::size_t i=0;i<_coords.size();i++)
1028 coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
1029 ret->_coords=coords;
1034 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1035 for(std::size_t i=0;i<ngs.size();i++)
1036 m->setCoordsAt(i,_coords[i]);
1037 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1038 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1039 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1041 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1047 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1049 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1054 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays() const
1056 std::size_t sz(_coords.size());
1057 std::vector< DataArrayDouble * > ret(sz);
1058 for(std::size_t i=0;i<sz;i++)
1060 ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1068 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1070 return new MEDCurveLinearMeshMultiLev(m,levs);
1073 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
1075 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1078 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1081 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1082 if(levs.size()!=1 || levs[0]!=0)
1083 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1084 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1086 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1089 _structure=m->getMesh()->getNodeGridStructure();
1090 // ids fields management
1091 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1092 const DataArrayInt *tmp(0);
1093 tmp=m->getFamilyFieldAtLevel(0);
1097 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1099 tmp=m->getNumberFieldAtLevel(0);
1103 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1107 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->getNumberOfNodes(),gts,pfls,nbEntities)
1110 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1111 if(gts.size()!=1 || pfls.size()!=1)
1112 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
1113 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1115 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
1116 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1118 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1121 _structure=m->getMesh()->getNodeGridStructure();
1122 // ids fields management
1123 _cell_fam_ids_nocpy=true; _cell_num_ids_nocpy=true;
1124 const DataArrayInt *tmp(0);
1125 tmp=m->getFamilyFieldAtLevel(0);
1129 _cell_fam_ids=const_cast<DataArrayInt *>(tmp);
1131 tmp=m->getNumberFieldAtLevel(0);
1135 _cell_num_ids=const_cast<DataArrayInt *>(tmp);
1139 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1143 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1148 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1150 const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
1151 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
1152 std::vector<int> cgs,ngs(getNodeGridStructure());
1153 cgs.resize(ngs.size());
1154 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
1157 std::vector< std::pair<int,int> > cellParts,nodeParts;
1158 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1160 nodeParts=cellParts;
1161 std::vector<int> st(ngs.size());
1162 for(std::size_t i=0;i<ngs.size();i++)
1164 nodeParts[i].second++;
1165 st[i]=nodeParts[i].second-nodeParts[i].first;
1167 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1168 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1170 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1171 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1173 ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1179 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1180 m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1181 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1182 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1183 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1185 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1191 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1193 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1198 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct) const
1200 nodeStrct=_structure;
1201 const DataArrayDouble *coo(_coords);
1203 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1204 coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1209 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1213 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)
1215 _pfl->setName(c.c_str());
1218 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1220 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1221 checkInRange(nbOfEnt,1,globs);
1224 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1226 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1227 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1228 checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1231 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1234 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1236 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1237 const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1238 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1239 checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1242 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1246 if(getPflName().empty())
1247 return (_start_end.second-_start_end.first)/_nb_of_entity;
1249 return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples();
1253 const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1254 return loc.getNumberOfGaussPoints();
1258 std::string MEDFileField1TSStructItem2::getPflName() const
1260 return _pfl->getName();
1263 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1265 if(!_pfl->isAllocated())
1267 if(_pfl->getName().empty())
1270 return globs->getProfile(_pfl->getName().c_str());
1277 * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
1278 * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1280 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1282 _nb_of_entity=nbOfEntity;
1283 if(_pfl->getName().empty())
1285 if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1286 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !");
1292 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1293 const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
1295 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1296 pfl->checkAllIdsInRange(0,nbOfEntity);
1300 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const char *pflName) const
1302 if(startExp!=_start_end.first)
1306 if(getPflName()!=pflName)
1308 startExp=_start_end.second;
1312 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception)
1314 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1315 //idem for _loc. It is not an effective attribute for support comparison.
1316 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1319 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1321 if(_geo_type!=other._geo_type)
1323 if(_nb_of_entity!=other._nb_of_entity)
1325 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1327 if(_pfl->getName().empty() && other._pfl->getName().empty())
1329 const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1330 return pfl1->isEqualWithoutConsideringStr(*pfl2);
1333 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1335 return isCellSupportEqual(other,globs);
1339 * \a objs must be non empty. \a objs should contain items having same geometric type.
1341 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1344 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1346 return MEDFileField1TSStructItem2(*objs[0]);
1347 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1348 int nbEntityRef(objs[0]->_nb_of_entity);
1349 std::size_t sz(objs.size());
1350 std::vector<const DataArrayInt *> arrs(sz);
1351 for(std::size_t i=0;i<sz;i++)
1353 const MEDFileField1TSStructItem2 *obj(objs[i]);
1354 if(gt!=obj->_geo_type)
1355 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1356 if(nbEntityRef!=obj->_nb_of_entity)
1357 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1358 if(obj->_pfl->getName().empty())
1359 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1360 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1362 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
1364 int oldNbTuples(arr->getNumberOfTuples());
1365 arr=arr->buildUnique();
1366 if(oldNbTuples!=arr->getNumberOfTuples())
1367 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1368 if(arr->isIdentity() && oldNbTuples==nbEntityRef)
1370 std::pair<int,int> p(0,nbEntityRef);
1372 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1373 ret._nb_of_entity=nbEntityRef;
1378 arr->setName(NEWLY_CREATED_PFL_NAME);
1379 std::pair<int,int> p(0,oldNbTuples);
1381 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1382 ret._nb_of_entity=nbEntityRef;
1388 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1390 std::size_t ret(_loc.capacity());
1394 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildren() const
1396 std::vector<const BigMemoryObject *> ret;
1397 const DataArrayInt *pfl(_pfl);
1405 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1409 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1415 int nbOfEnt=mst->getNumberOfNodes();
1416 if(_items.size()!=1)
1417 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1418 _items[0].checkInRange(nbOfEnt,1,globs);
1423 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1424 (*it).checkWithMeshStructForCells(mst,globs);
1429 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1430 (*it).checkWithMeshStructForGaussNE(mst,globs);
1435 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1436 (*it).checkWithMeshStructForGaussPT(mst,globs);
1440 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1444 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception)
1446 if(_type!=other._type)
1448 if(_items.size()!=other._items.size())
1450 for(std::size_t i=0;i<_items.size();i++)
1451 if(!(_items[i]==other._items[i]))
1456 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1458 if(_type!=other._type)
1460 if(_items.size()!=other._items.size())
1462 for(std::size_t i=0;i<_items.size();i++)
1463 if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1468 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1470 if(_type!=other._type)
1472 if(_items.size()!=other._items.size())
1474 for(std::size_t i=0;i<_items.size();i++)
1475 if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1480 bool MEDFileField1TSStructItem::isEntityCell() const
1491 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1492 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1494 INTERP_KERNEL::NormalizedCellType _geo_type;
1497 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1500 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1501 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1503 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1505 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1507 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1509 (*it0).second.push_back(i);
1511 if(m.size()==_items.size())
1513 MEDFileField1TSStructItem ret(*this);
1517 std::size_t sz(m.size());
1518 std::vector< MEDFileField1TSStructItem2 > items(sz);
1521 const std::vector<std::size_t>& ids=m[i].second;
1522 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1523 for(std::size_t j=0;j<ids.size();j++)
1524 objs[j]=&_items[ids[j]];
1525 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1527 MEDFileField1TSStructItem ret(ON_CELLS,items);
1533 * \a this is expected to be ON_CELLS and simplified.
1535 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1537 if(other._type!=ON_NODES)
1538 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1539 if(other._items.size()!=1)
1540 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1541 int theFirstLevFull;
1542 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1543 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1544 if(otherNodeIt.getPflName().empty())
1548 return theFirstLevFull==0;
1552 const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1553 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
1555 int nbOfNodes(meshSt->getNumberOfNodes());
1556 if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
1557 {//on all nodes also !
1560 return theFirstLevFull==0;
1562 std::vector<bool> nodesFetched(nbOfNodes,false);
1563 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1564 return cpyPfl->isFittingWith(nodesFetched);
1568 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1571 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1573 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1574 int nbOfLevs(meshSt->getNumberOfLevs());
1576 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1577 std::vector<int> levs(nbOfLevs);
1579 std::set<INTERP_KERNEL::NormalizedCellType> gts;
1580 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1582 if(!(*it).getPflName().empty())
1584 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1585 if(gts.find(gt)!=gts.end())
1586 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1588 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1591 for(int i=0;i<nbOfLevs;i++)
1592 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
1593 { theFirstLevFull=-i; return true; }
1597 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const throw(INTERP_KERNEL::Exception)
1599 if(i>=_items.size())
1600 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
1604 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
1606 std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
1610 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildren() const
1612 std::vector<const BigMemoryObject *> ret;
1613 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1614 ret.push_back(&(*it));
1618 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
1620 std::size_t sz(_items.size());
1621 std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
1622 std::vector<const DataArrayInt *> a1(sz);
1623 std::vector<int> a2(sz);
1625 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1627 a0[i]=(*it).getGeo();
1628 a1[i]=(*it).getPfl(globs);
1629 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
1631 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
1634 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
1637 std::vector< MEDFileField1TSStructItem2 > anItems;
1639 std::vector< std::vector<std::string> > pfls,locs;
1640 std::vector< std::vector<TypeOfField> > typesF;
1641 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1642 std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(0,geoTypes,typesF,pfls,locs);
1643 std::size_t nbOfGeoTypes(geoTypes.size());
1645 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
1647 for(std::size_t i=0;i<nbOfGeoTypes;i++)
1649 std::size_t sz=typesF[i].size();
1650 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
1651 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
1657 for(std::size_t j=0;j<sz;j++)
1659 if(atype==typesF[i][j])
1660 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
1662 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
1665 MEDFileField1TSStructItem ret(atype,anItems);
1666 ret.checkWithMeshStruct(meshSt,ref);
1672 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
1674 return new MEDFileField1TSStruct(ref,mst);
1677 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
1679 _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
1682 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1684 if(_already_checked.empty())
1685 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
1686 _already_checked.back().checkWithMeshStruct(mst,globs);
1689 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
1691 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
1692 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
1701 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
1703 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
1705 if(_already_checked.empty())
1706 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
1707 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
1708 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
1709 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
1710 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
1712 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1713 if((*it).isComputed())
1718 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
1719 ret=this1.isCellSupportEqual(other1,other);
1721 _already_checked.push_back(this1);
1724 ret=_already_checked[found].isCellSupportEqual(other1,other);
1726 _already_checked.push_back(b);
1731 * \param [in] other - a field with only one spatial discretization : ON_NODES.
1733 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
1735 if(_already_checked.empty())
1736 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
1737 MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
1738 if(_already_checked[0].isEntityCell())
1741 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1742 if((*it).isComputed())
1747 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
1748 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
1750 _already_checked.push_back(this1);
1753 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
1755 _already_checked.push_back(other1);
1759 return _already_checked[0].isNodeSupportEqual(other1,other);
1762 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
1764 std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
1768 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildren() const
1770 std::vector<const BigMemoryObject *> ret;
1771 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
1772 ret.push_back(&(*it));
1776 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
1778 if(_already_checked.empty())
1779 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
1780 int pos0(-1),pos1(-1);
1781 if(presenceOfCellDiscr(pos0))
1783 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
1784 if(presenceOfPartialNodeDiscr(pos1))
1785 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
1790 if(!presenceOfPartialNodeDiscr(pos1))
1791 {//we have only all nodes, no cell definition info -> level 0;
1792 std::vector<int> levs(1,0);
1793 return MEDMeshMultiLev::New(mst->getTheMesh(),levs);
1796 return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
1800 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
1803 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
1805 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
1806 if(a0!=c0 || a1!=c1)
1809 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
1812 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
1818 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
1819 * 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.
1821 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
1823 std::size_t refSz(std::numeric_limits<std::size_t>::max());
1826 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1828 if((*it).getType()!=ON_NODES)
1831 std::size_t sz((*it).getNumberOfItems());
1833 { pos=i; refSz=sz; }
1837 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
1842 * Returns true if presence in \a this of discretization ON_NODES.
1843 * If true is returned the pos of the first element containing the single subpart.
1845 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
1848 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1850 if((*it).getType()==ON_NODES)
1852 std::size_t sz((*it).getNumberOfItems());
1855 if(!(*it)[0].getPflName().empty())
1856 { pos=i; return true; }
1859 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
1867 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
1869 return new MEDFileFastCellSupportComparator(m,ref);
1872 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
1875 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
1876 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
1877 int nbPts=ref->getNumberOfTS();
1878 _f1ts_cmps.resize(nbPts);
1879 for(int i=0;i<nbPts;i++)
1881 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
1882 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
1883 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
1887 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
1889 std::size_t ret(_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>));
1893 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildren() const
1895 std::vector<const BigMemoryObject *> ret;
1896 const MEDFileMeshStruct *mst(_mesh_comp);
1899 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
1901 const MEDFileField1TSStruct *cur(*it);
1908 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
1910 int nbPts=other->getNumberOfTS();
1911 if(nbPts!=(int)_f1ts_cmps.size())
1913 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
1914 throw INTERP_KERNEL::Exception(oss.str().c_str());
1916 for(int i=0;i<nbPts;i++)
1918 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
1919 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
1920 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
1926 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
1928 int nbPts=other->getNumberOfTS();
1929 if(nbPts!=(int)_f1ts_cmps.size())
1931 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
1932 throw INTERP_KERNEL::Exception(oss.str().c_str());
1934 for(int i=0;i<nbPts;i++)
1936 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
1937 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
1943 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
1945 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
1947 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
1948 throw INTERP_KERNEL::Exception(oss.str().c_str());
1950 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
1953 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
1954 throw INTERP_KERNEL::Exception(oss.str().c_str());
1956 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
1959 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
1961 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
1963 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
1964 throw INTERP_KERNEL::Exception(oss.str().c_str());
1966 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
1967 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
1968 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);