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);
209 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
211 std::size_t sz(_pfls.size());
212 if(id<0 || id>=(int)sz)
213 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
214 const DataArrayInt *pfl(_pfls[id]);
216 return std::string("");
217 return pfl->getName();
221 * Returns the number of cells having geometric type \a t.
222 * The profiles are **NOT** taken into account here.
224 int MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
226 std::size_t sz(_nb_entities.size());
227 for(std::size_t i=0;i<sz;i++)
229 return _nb_entities[i];
230 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
233 int MEDMeshMultiLev::getNumberOfNodes() const
238 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
240 if(fst.getType()==ON_NODES)
242 if(fst.getNumberOfItems()!=1)
243 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
244 const MEDFileField1TSStructItem2& p(fst[0]);
245 std::string pflName(p.getPflName());
246 const DataArrayInt *nr(_node_reduction);
247 if(pflName.empty() && !nr)
248 return vals->deepCpy();
249 if(pflName.empty() && nr)
250 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
251 if(!pflName.empty() && nr)
253 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
254 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(nr->deepCpy());
255 p1->sort(true); p2->sort(true);
256 if(!p1->isEqualWithoutConsideringStr(*p2))
257 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 3 !");
258 p1=DataArrayInt::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
259 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
260 ret->renumberInPlace(p1->begin());
263 if(!pflName.empty() && !nr)
265 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(globs->getProfile(pflName.c_str())->deepCpy());
267 if(!p1->isIdentity() || p1->getNumberOfTuples()!=getNumberOfNodes())
268 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
269 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->deepCpy());
270 ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
273 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
277 std::size_t sz(fst.getNumberOfItems());
278 std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
279 if(s.size()!=_geo_types.size())
280 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
281 std::vector< const DataArray *> arr(s.size());
282 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arrSafe(s.size());
284 int nc(vals->getNumberOfComponents());
285 std::vector<std::string> compInfo(vals->getInfoOnComponents());
286 for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
288 const DataArrayInt *thisP(_pfls[iii]);
289 std::vector<const MEDFileField1TSStructItem2 *> ps;
290 for(std::size_t i=0;i<sz;i++)
292 const MEDFileField1TSStructItem2& p(fst[i]);
297 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
300 int nbi(ps[0]->getNbOfIntegrationPts(globs));
301 const DataArrayInt *otherP(ps[0]->getPfl(globs));
302 const std::pair<int,int>& strtStop(ps[0]->getStartStop());
303 MEDCouplingAutoRefCountObjectPtr<DataArray> ret(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
304 if(!thisP && !otherP)
306 arrSafe[iii]=ret; arr[iii]=ret;
311 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
312 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(thisP->deepCpy());
313 p2->transformWithIndArr(p1->begin(),p1->end());
314 //p1=p2->getIdsNotEqual(-1);
315 //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
316 ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
317 arrSafe[iii]=ret; arr[iii]=ret;
322 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1(otherP->deepCpy());
324 p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
325 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,p1);
326 ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
327 arrSafe[iii]=ret; arr[iii]=ret;
330 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
334 std::vector< const DataArrayInt * >otherPS(ps.size());
335 std::vector< const DataArray * > arr2(ps.size());
336 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArray> > arr2Safe(ps.size());
337 std::vector< const DataArrayInt * > nbis(ps.size());
338 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > nbisSafe(ps.size());
340 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
342 int nbi((*it2)->getNbOfIntegrationPts(globs));
343 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
344 const std::pair<int,int>& strtStop((*it2)->getStartStop());
345 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
347 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
348 arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
349 nbisSafe[jj]=DataArrayInt::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
350 nbis[jj]=nbisSafe[jj];
352 MEDCouplingAutoRefCountObjectPtr<DataArray> arr3(DataArray::Aggregate(arr2));
353 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherP(DataArrayInt::Aggregate(otherPS));
354 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbis(DataArrayInt::Aggregate(nbis));
355 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
356 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p1;
358 p1=DataArrayInt::FindPermutationFromFirstToSecond(otherP,thisP);
360 p1=otherP->deepCpy();
361 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> zenbisN(zenbis->renumber(p1->begin()));
362 zenbisN->computeOffsets2();
364 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
366 //int nbi((*it2)->getNbOfIntegrationPts(globs));
367 const DataArrayInt *otherPfl((*it2)->getPfl(globs));
368 const std::pair<int,int>& strtStop((*it2)->getStartStop());
369 MEDCouplingAutoRefCountObjectPtr<DataArray> ret2(vals->selectByTupleId2(strtStop.first,strtStop.second,1));
371 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p2(otherPfl->deepCpy());
372 p2->transformWithIndArr(otherPN->begin(),otherPN->end());
373 p2->transformWithIndArr(p1->begin(),p1->end());
374 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idsN(p2->buildExplicitArrByRanges(zenbisN));
375 arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
377 arrSafe[iii]=arr3; arr[iii]=arr3;
381 return DataArray::Aggregate(arr);
385 MEDMeshMultiLev::MEDMeshMultiLev()
389 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)
391 std::size_t sz(_geo_types.size());
392 if(sz!=pfls.size() || sz!=nbEntities.size())
393 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
395 for(std::size_t i=0;i<sz;i++)
399 _pfls[i]=const_cast<DataArrayInt *>(pfls[i]);
403 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)
409 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
411 return new MEDUMeshMultiLev(m,levs);
414 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs)
417 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
418 std::vector<MEDCoupling1GTUMesh *> v;
419 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
421 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
422 v.insert(v.end(),vTmp.begin(),vTmp.end());
424 std::size_t sz(v.size());
427 _geo_types.resize(sz);
428 for(std::size_t i=0;i<sz;i++)
430 MEDCoupling1GTUMesh *obj(v[i]);
434 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
436 _geo_types[i]=obj->getCellModelEnum();
440 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
442 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
445 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)
447 std::size_t sz(gts.size());
449 for(std::size_t i=0;i<sz;i++)
451 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
458 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
460 if(!pflNodes || !pflNodes->isAllocated())
462 std::size_t sz(_parts.size());
463 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a(sz);
464 std::vector< const DataArrayInt *> aa(sz);
465 for(std::size_t i=0;i<sz;i++)
468 const DataArrayInt *pfl(_pfls[i]);
469 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m(_parts[i]);
471 m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
472 DataArrayInt *cellIds=0;
473 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
474 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
475 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
477 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(m2->getNodeIdsInUse(tmp));
478 a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
480 _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
482 _pfls[i]=cellIdsSafe;
484 _node_reduction=DataArrayInt::Aggregate(aa);
485 _node_reduction->sort(true);
486 _node_reduction=_node_reduction->buildUnique();
489 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
491 return new MEDUMeshMultiLev(*this);
494 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts)
498 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
502 _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
503 _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
504 _pfls.resize(1); _pfls[0]=0;
508 * 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.
509 * 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.
511 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayInt *&cellLocations, DataArrayInt *& cells, DataArrayInt *&faceLocations, DataArrayInt *&faces) const
514 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : empty array !");
515 if(!(const MEDCoupling1GTUMesh *)_parts[0])
516 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : first part is null !");
517 const DataArrayDouble *tmp(_parts[0]->getCoords());
519 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
520 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
521 int szBCE(0),szD(0),szF(0);
524 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
526 const MEDCoupling1GTUMesh *cur(*it);
528 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
530 const DataArrayInt *pfl(_pfls[iii]);
531 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
533 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
535 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
537 int curNbCells(cur->getNumberOfCells());
539 if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
540 szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
544 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp2(cur->computeEffectiveNbOfNodesPerCell());
545 szD+=tmp2->accumulate(0)+curNbCells;
546 szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
549 MEDCouplingAutoRefCountObjectPtr<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
550 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> c(DataArrayInt::New()); c->alloc(szBCE,1); int *cPtr(c->getPointer());
551 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> d(DataArrayInt::New()); d->alloc(szD,1); int *dPtr(d->getPointer());
552 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> e(DataArrayInt::New()),f(DataArrayInt::New()); int *ePtr(0),*fPtr(0);
554 { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
557 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
559 const MEDCoupling1GTUMesh *cur(*it);
561 const DataArrayInt *pfl(_pfls[iii]);
562 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> cur2;
564 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
566 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
568 int curNbCells(cur->getNumberOfCells());
569 int gt((int)cur->getCellModelEnum());
570 if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
571 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
572 unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
574 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
575 std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
576 const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
577 const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
578 const int *connPtr(cur->getNodalConnectivity()->begin());
580 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
583 int nnpc(scur->getNumberOfNodesPerCell());
584 for(int i=0;i<curNbCells;i++,connPtr+=nnpc)
587 dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
588 *cPtr=k+nnpc; k=*cPtr++;
591 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
595 const int *connIPtr(dcur->getNodalConnectivityIndex()->begin());
596 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
598 for(int i=0;i<curNbCells;i++,connIPtr++)
600 *dPtr++=connIPtr[1]-connIPtr[0];
601 dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
602 *cPtr=k+connIPtr[1]-connIPtr[0]; k=*cPtr++;
607 for(int i=0;i<curNbCells;i++,connIPtr++)
609 std::set<int> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
610 *dPtr++=(int)s.size();
611 dPtr=std::copy(s.begin(),s.end(),dPtr);
612 *cPtr=k+(int)s.size(); k=*cPtr++;
617 connIPtr=dcur->getNodalConnectivityIndex()->begin();
618 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
619 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
623 for(int i=0;i<curNbCells;i++,connIPtr++)
625 int nbFace(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1);
627 const int *work(connPtr+connIPtr[0]);
628 for(int j=0;j<nbFace;j++)
630 const int *work2=std::find(work,connPtr+connIPtr[1],-1);
631 *fPtr++=std::distance(work,work2);
632 fPtr=std::copy(work,work2,fPtr);
635 *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
642 reorderNodesIfNecessary(a,d,0);
644 reorderNodesIfNecessary(a,d,f);
645 if(a->getNumberOfComponents()!=3)
646 a=a->changeNbOfComponents(3,0.);
647 coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
649 { faceLocations=0; faces=0; }
651 { faceLocations=e.retn(); faces=f.retn(); }
652 return tmp==((DataArrayDouble *)a);
655 void MEDUMeshMultiLev::reorderNodesIfNecessary(MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& coords, DataArrayInt *nodalConnVTK, DataArrayInt *polyhedNodalConnVTK) const
657 const DataArrayInt *nr(_node_reduction);
660 int sz(coords->getNumberOfTuples());
661 std::vector<bool> b(sz,false);
662 const int *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
666 for(int i=0;i<nb && work!=endW;i++,work++)
668 if(*work>=0 && *work<sz)
671 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
674 if(polyhedNodalConnVTK)
676 work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
680 for(int i=0;i<nb && work!=endW;i++)
683 for(int j=0;j<nb2 && work!=endW;j++,work++)
685 if(*work>=0 && *work<sz)
688 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
693 int szExp(std::count(b.begin(),b.end(),true));
694 if(szExp!=nr->getNumberOfTuples())
695 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
697 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n(DataArrayInt::New()); o2n->alloc(sz,1);
698 int *o2nPtr(o2n->getPointer());
700 for(int i=0;i<sz;i++,o2nPtr++)
701 if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
702 const int *o2nPtrc(o2n->begin());
703 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
704 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> perm(DataArrayInt::FindPermutationFromFirstToSecond(n2o,nr));
705 const int *permPtr(perm->begin());
706 int *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
710 for(int i=0;i<nb && work2!=endW2;i++,work2++)
711 *work2=permPtr[o2nPtrc[*work2]];
713 if(polyhedNodalConnVTK)
715 work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
719 for(int i=0;i<nb && work2!=endW2;i++)
722 for(int j=0;j<nb2 && work2!=endW2;j++,work2++)
723 *work2=permPtr[o2nPtrc[*work2]];
727 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
732 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev()
736 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)
740 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayInt *pflNodes)
742 if(!pflNodes || !pflNodes->isAllocated())
744 std::vector<int> ngs(getNodeGridStructure());
745 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
746 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(ngs.size())));
747 m->setNodalConnectivity(conn);
748 const DataArrayInt *pfl(_pfls[0]);
751 m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
753 DataArrayInt *cellIds=0;
754 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
755 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellIdsSafe(cellIds);
756 MEDCouplingAutoRefCountObjectPtr<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
758 _node_reduction=m2->getNodeIdsInUse(tmp);
760 _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
762 _pfls[0]=cellIdsSafe;
765 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other)
771 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
773 return new MEDCMeshMultiLev(m,levs);
776 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
778 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
781 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs)
784 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
785 if(levs.size()!=1 || levs[0]!=0)
786 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
787 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
788 _coords.resize(mdim);
789 for(int i=0;i<mdim;i++)
791 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
793 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
798 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)
801 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
802 if(gts.size()!=1 || pfls.size()!=1)
803 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
804 int mdim(m->getMeshDimension());
805 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
807 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
808 _coords.resize(mdim);
809 for(int i=0;i<mdim;i++)
811 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
813 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
814 _coords[i]=elt; _coords[i]->incrRef();
818 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
822 std::vector<int> MEDCMeshMultiLev::getNodeGridStructure() const
824 std::vector<int> ret(_coords.size());
825 for(std::size_t i=0;i<_coords.size();i++)
826 ret[i]=_coords[i]->getNumberOfTuples();
830 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
832 const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
833 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
834 std::vector<int> cgs,ngs(getNodeGridStructure());
835 cgs.resize(ngs.size());
836 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
839 std::vector< std::pair<int,int> > cellParts;
840 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
842 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
844 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
845 ret->_nb_entities[0]=pfl->getNumberOfTuples();
847 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> > coords(_coords.size());
848 for(std::size_t i=0;i<_coords.size();i++)
849 coords[i]=_coords[i]->selectByTupleId2(cellParts[i].first,cellParts[i].second+1,1);
855 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
856 for(std::size_t i=0;i<ngs.size();i++)
857 m->setCoordsAt(i,_coords[i]);
858 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
859 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
860 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
862 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
868 MEDCouplingAutoRefCountObjectPtr<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
870 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
875 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays() const
877 std::size_t sz(_coords.size());
878 std::vector< DataArrayDouble * > ret(sz);
879 for(std::size_t i=0;i<sz;i++)
881 ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
889 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
891 return new MEDCurveLinearMeshMultiLev(m,levs);
894 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayInt *>& pfls, const std::vector<int>& nbEntities)
896 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
899 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
902 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
903 if(levs.size()!=1 || levs[0]!=0)
904 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
905 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
907 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
910 _structure=m->getMesh()->getNodeGridStructure();
913 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)
916 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
917 if(gts.size()!=1 || pfls.size()!=1)
918 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengthes of gts and pfls must be equal to one !");
919 int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
921 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : the unique geo type is invalid regarding meshdim !");
922 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
924 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
927 _structure=m->getMesh()->getNodeGridStructure();
930 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
934 std::vector<int> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
939 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
941 const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction);
942 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nnr;
943 std::vector<int> cgs,ngs(getNodeGridStructure());
944 cgs.resize(ngs.size());
945 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<int>(),-1));
948 std::vector< std::pair<int,int> > cellParts,nodeParts;
949 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
952 std::vector<int> st(ngs.size());
953 for(std::size_t i=0;i<ngs.size();i++)
955 nodeParts[i].second++;
956 st[i]=nodeParts[i].second-nodeParts[i].first;
958 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
959 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
961 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
962 ret->_nb_entities[0]=pfl->getNumberOfTuples();
964 ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
970 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
971 m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
972 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
973 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
974 MEDCouplingAutoRefCountObjectPtr<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
976 { m3->zipCoords(); nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
982 MEDCouplingAutoRefCountObjectPtr<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
984 { nnr=nr->deepCpy(); nnr->sort(true); ret->setNodeReduction(nnr); }
989 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<int>& nodeStrct) const
991 nodeStrct=_structure;
992 const DataArrayDouble *coo(_coords);
994 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
995 coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1000 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1004 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)
1006 _pfl->setName(c.c_str());
1009 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1011 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1012 checkInRange(nbOfEnt,1,globs);
1015 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1017 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1018 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1019 checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1022 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1025 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1027 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1028 const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1029 int nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1030 checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1033 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1037 if(getPflName().empty())
1038 return (_start_end.second-_start_end.first)/_nb_of_entity;
1040 return (_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples();
1044 const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1045 return loc.getNumberOfGaussPoints();
1049 std::string MEDFileField1TSStructItem2::getPflName() const
1051 return _pfl->getName();
1054 const DataArrayInt *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1056 if(!_pfl->isAllocated())
1058 if(_pfl->getName().empty())
1061 return globs->getProfile(_pfl->getName().c_str());
1068 * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possiblity.
1069 * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1071 void MEDFileField1TSStructItem2::checkInRange(int nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1073 _nb_of_entity=nbOfEntity;
1074 if(_pfl->getName().empty())
1076 if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1077 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of node field !");
1083 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1084 const DataArrayInt *pfl=globs->getProfile(_pfl->getName().c_str());
1086 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1087 pfl->checkAllIdsInRange(0,nbOfEntity);
1091 bool MEDFileField1TSStructItem2::isFastlyEqual(int& startExp, INTERP_KERNEL::NormalizedCellType gt, const char *pflName) const
1093 if(startExp!=_start_end.first)
1097 if(getPflName()!=pflName)
1099 startExp=_start_end.second;
1103 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const throw(INTERP_KERNEL::Exception)
1105 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1106 //idem for _loc. It is not an effective attribute for support comparison.
1107 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1110 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1112 if(_geo_type!=other._geo_type)
1114 if(_nb_of_entity!=other._nb_of_entity)
1116 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1118 if(_pfl->getName().empty() && other._pfl->getName().empty())
1120 const DataArrayInt *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1121 return pfl1->isEqualWithoutConsideringStr(*pfl2);
1124 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1126 return isCellSupportEqual(other,globs);
1130 * \a objs must be non empty. \a objs should contain items having same geometric type.
1132 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1135 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1137 return MEDFileField1TSStructItem2(*objs[0]);
1138 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1139 int nbEntityRef(objs[0]->_nb_of_entity);
1140 std::size_t sz(objs.size());
1141 std::vector<const DataArrayInt *> arrs(sz);
1142 for(std::size_t i=0;i<sz;i++)
1144 const MEDFileField1TSStructItem2 *obj(objs[i]);
1145 if(gt!=obj->_geo_type)
1146 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1147 if(nbEntityRef!=obj->_nb_of_entity)
1148 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1149 if(obj->_pfl->getName().empty())
1150 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1151 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1153 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::Aggregate(arrs));
1155 int oldNbTuples(arr->getNumberOfTuples());
1156 arr=arr->buildUnique();
1157 if(oldNbTuples!=arr->getNumberOfTuples())
1158 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1159 if(arr->isIdentity() && oldNbTuples==nbEntityRef)
1161 std::pair<int,int> p(0,nbEntityRef);
1163 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1164 ret._nb_of_entity=nbEntityRef;
1169 arr->setName(NEWLY_CREATED_PFL_NAME);
1170 std::pair<int,int> p(0,oldNbTuples);
1172 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1173 ret._nb_of_entity=nbEntityRef;
1179 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1181 std::size_t ret(_loc.capacity());
1185 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildren() const
1187 std::vector<const BigMemoryObject *> ret;
1188 const DataArrayInt *pfl(_pfl);
1196 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1200 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1206 int nbOfEnt=mst->getNumberOfNodes();
1207 if(_items.size()!=1)
1208 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1209 _items[0].checkInRange(nbOfEnt,1,globs);
1214 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1215 (*it).checkWithMeshStructForCells(mst,globs);
1220 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1221 (*it).checkWithMeshStructForGaussNE(mst,globs);
1226 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1227 (*it).checkWithMeshStructForGaussPT(mst,globs);
1231 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1235 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const throw(INTERP_KERNEL::Exception)
1237 if(_type!=other._type)
1239 if(_items.size()!=other._items.size())
1241 for(std::size_t i=0;i<_items.size();i++)
1242 if(!(_items[i]==other._items[i]))
1247 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1249 if(_type!=other._type)
1251 if(_items.size()!=other._items.size())
1253 for(std::size_t i=0;i<_items.size();i++)
1254 if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1259 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1261 if(_type!=other._type)
1263 if(_items.size()!=other._items.size())
1265 for(std::size_t i=0;i<_items.size();i++)
1266 if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1271 bool MEDFileField1TSStructItem::isEntityCell() const
1282 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1283 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1285 INTERP_KERNEL::NormalizedCellType _geo_type;
1288 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1291 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1292 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1294 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1296 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1298 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1300 (*it0).second.push_back(i);
1302 if(m.size()==_items.size())
1304 MEDFileField1TSStructItem ret(*this);
1308 std::size_t sz(m.size());
1309 std::vector< MEDFileField1TSStructItem2 > items(sz);
1312 const std::vector<std::size_t>& ids=m[i].second;
1313 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1314 for(std::size_t j=0;j<ids.size();j++)
1315 objs[j]=&_items[ids[j]];
1316 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1318 MEDFileField1TSStructItem ret(ON_CELLS,items);
1324 * \a this is expected to be ON_CELLS and simplified.
1326 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1328 if(other._type!=ON_NODES)
1329 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1330 if(other._items.size()!=1)
1331 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1332 int theFirstLevFull;
1333 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1334 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1335 if(otherNodeIt.getPflName().empty())
1339 return theFirstLevFull==0;
1343 const DataArrayInt *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1344 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cpyPfl(pfl->deepCpy());
1346 int nbOfNodes(meshSt->getNumberOfNodes());
1347 if(cpyPfl->isIdentity() && cpyPfl->getNumberOfTuples()==nbOfNodes)
1348 {//on all nodes also !
1351 return theFirstLevFull==0;
1353 std::vector<bool> nodesFetched(nbOfNodes,false);
1354 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1355 return cpyPfl->isFittingWith(nodesFetched);
1359 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1362 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1364 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1365 int nbOfLevs(meshSt->getNumberOfLevs());
1367 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1368 std::vector<int> levs(nbOfLevs);
1370 std::set<INTERP_KERNEL::NormalizedCellType> gts;
1371 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1373 if(!(*it).getPflName().empty())
1375 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1376 if(gts.find(gt)!=gts.end())
1377 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1379 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1382 for(int i=0;i<nbOfLevs;i++)
1383 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
1384 { theFirstLevFull=-i; return true; }
1388 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const throw(INTERP_KERNEL::Exception)
1390 if(i>=_items.size())
1391 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
1395 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
1397 std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
1401 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildren() const
1403 std::vector<const BigMemoryObject *> ret;
1404 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1405 ret.push_back(&(*it));
1409 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
1411 std::size_t sz(_items.size());
1412 std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
1413 std::vector<const DataArrayInt *> a1(sz);
1414 std::vector<int> a2(sz);
1416 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1418 a0[i]=(*it).getGeo();
1419 a1[i]=(*it).getPfl(globs);
1420 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
1422 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
1425 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
1428 std::vector< MEDFileField1TSStructItem2 > anItems;
1430 std::vector< std::vector<std::string> > pfls,locs;
1431 std::vector< std::vector<TypeOfField> > typesF;
1432 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
1433 std::vector< std::vector<std::pair<int,int> > > strtEnds=ref->getFieldSplitedByType(0,geoTypes,typesF,pfls,locs);
1434 std::size_t nbOfGeoTypes(geoTypes.size());
1436 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
1438 for(std::size_t i=0;i<nbOfGeoTypes;i++)
1440 std::size_t sz=typesF[i].size();
1441 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
1442 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
1448 for(std::size_t j=0;j<sz;j++)
1450 if(atype==typesF[i][j])
1451 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
1453 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
1456 MEDFileField1TSStructItem ret(atype,anItems);
1457 ret.checkWithMeshStruct(meshSt,ref);
1463 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
1465 return new MEDFileField1TSStruct(ref,mst);
1468 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
1470 _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
1473 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1475 if(_already_checked.empty())
1476 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
1477 _already_checked.back().checkWithMeshStruct(mst,globs);
1480 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
1482 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
1483 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
1492 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
1494 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
1496 if(_already_checked.empty())
1497 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
1498 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
1499 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
1500 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
1501 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
1503 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1504 if((*it).isComputed())
1509 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
1510 ret=this1.isCellSupportEqual(other1,other);
1512 _already_checked.push_back(this1);
1515 ret=_already_checked[found].isCellSupportEqual(other1,other);
1517 _already_checked.push_back(b);
1522 * \param [in] other - a field with only one spatial discretization : ON_NODES.
1524 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
1526 if(_already_checked.empty())
1527 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
1528 MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
1529 if(_already_checked[0].isEntityCell())
1532 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1533 if((*it).isComputed())
1538 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
1539 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
1541 _already_checked.push_back(this1);
1544 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
1546 _already_checked.push_back(other1);
1550 return _already_checked[0].isNodeSupportEqual(other1,other);
1553 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
1555 std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
1559 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildren() const
1561 std::vector<const BigMemoryObject *> ret;
1562 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
1563 ret.push_back(&(*it));
1567 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
1569 if(_already_checked.empty())
1570 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
1571 int pos0(-1),pos1(-1);
1572 if(presenceOfCellDiscr(pos0))
1574 MEDCouplingAutoRefCountObjectPtr<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
1575 if(presenceOfPartialNodeDiscr(pos1))
1576 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
1581 if(!presenceOfPartialNodeDiscr(pos1))
1582 {//we have only all nodes, no cell definition info -> level 0;
1583 std::vector<int> levs(1,0);
1584 return MEDMeshMultiLev::New(mst->getTheMesh(),levs);
1587 return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
1591 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
1594 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
1596 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
1597 if(a0!=c0 || a1!=c1)
1600 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
1603 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
1609 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
1610 * 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.
1612 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
1614 std::size_t refSz(std::numeric_limits<std::size_t>::max());
1617 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1619 if((*it).getType()!=ON_NODES)
1622 std::size_t sz((*it).getNumberOfItems());
1624 { pos=i; refSz=sz; }
1628 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
1633 * Returns true if presence in \a this of discretization ON_NODES.
1634 * If true is returned the pos of the first element containing the single subpart.
1636 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
1639 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
1641 if((*it).getType()==ON_NODES)
1643 std::size_t sz((*it).getNumberOfItems());
1646 if(!(*it)[0].getPflName().empty())
1647 { pos=i; return true; }
1650 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
1658 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
1660 return new MEDFileFastCellSupportComparator(m,ref);
1663 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
1666 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
1667 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
1668 int nbPts=ref->getNumberOfTS();
1669 _f1ts_cmps.resize(nbPts);
1670 for(int i=0;i<nbPts;i++)
1672 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
1673 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
1674 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
1678 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
1680 std::size_t ret(_f1ts_cmps.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct>));
1684 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildren() const
1686 std::vector<const BigMemoryObject *> ret;
1687 const MEDFileMeshStruct *mst(_mesh_comp);
1690 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
1692 const MEDFileField1TSStruct *cur(*it);
1699 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
1701 int nbPts=other->getNumberOfTS();
1702 if(nbPts!=(int)_f1ts_cmps.size())
1704 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
1705 throw INTERP_KERNEL::Exception(oss.str().c_str());
1707 for(int i=0;i<nbPts;i++)
1709 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
1710 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
1711 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
1717 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
1719 int nbPts=other->getNumberOfTS();
1720 if(nbPts!=(int)_f1ts_cmps.size())
1722 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
1723 throw INTERP_KERNEL::Exception(oss.str().c_str());
1725 for(int i=0;i<nbPts;i++)
1727 MEDCouplingAutoRefCountObjectPtr<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
1728 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
1734 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
1736 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
1738 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
1739 throw INTERP_KERNEL::Exception(oss.str().c_str());
1741 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
1744 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
1745 throw INTERP_KERNEL::Exception(oss.str().c_str());
1747 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
1750 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
1752 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
1754 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
1755 throw INTERP_KERNEL::Exception(oss.str().c_str());
1757 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
1758 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
1759 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);