1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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 "MEDCouplingFieldDiscretization.hxx"
26 #include "CellModel.hxx"
28 using namespace MEDCoupling;
30 const unsigned char *MEDMeshMultiLev::PARAMEDMEM_2_VTKTYPE=MEDCOUPLING2VTKTYPETRADUCER;
32 const unsigned char MEDMeshMultiLev::HEXA27_PERM_ARRAY[27]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,24,22,21,23,20,25,26};
34 const char MEDFileField1TSStructItem2::NEWLY_CREATED_PFL_NAME[]="???";
36 MEDFileMeshStruct *MEDFileMeshStruct::New(const MEDFileMesh *mesh)
38 return new MEDFileMeshStruct(mesh);
41 std::size_t MEDFileMeshStruct::getHeapMemorySizeWithoutChildren() const
44 for(std::vector< std::vector<mcIdType> >::const_iterator it0=_geo_types_distrib.begin();it0!=_geo_types_distrib.end();it0++)
45 ret+=(*it0).capacity()*sizeof(int);
46 ret+=_geo_types_distrib.capacity()*sizeof(std::vector<mcIdType>);
50 std::vector<const BigMemoryObject *> MEDFileMeshStruct::getDirectChildrenWithNull() const
52 return std::vector<const BigMemoryObject *>();
55 MEDFileMeshStruct::MEDFileMeshStruct(const MEDFileMesh *mesh):_mesh(mesh)
57 std::vector<int> levs(mesh->getNonEmptyLevels());
58 _name=mesh->getName();
59 _nb_nodes=mesh->getNumberOfNodes();
62 _geo_types_distrib.resize(-(*std::min_element(levs.begin(),levs.end()))+1);
63 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
64 _geo_types_distrib[-(*lev)]=mesh->getDistributionOfTypes(*lev);
68 int MEDFileMeshStruct::getLevelOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
71 for(std::vector< std::vector<mcIdType> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++,j--)
73 std::size_t sz=(*it1).size();
75 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : internal error in code !");
76 std::size_t nbGeo=sz/3;
77 for(std::size_t i=0;i<nbGeo;i++)
78 if((*it1)[3*i]==(int)t)
81 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getLevelOfGeoType : The specified geometric type is not present in the mesh structure !");
85 * \sa MEDFileMeshStruct::doesManageGeoType
87 mcIdType MEDFileMeshStruct::getNumberOfElemsOfGeoType(INTERP_KERNEL::NormalizedCellType t) const
89 for(std::vector< std::vector<mcIdType> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
91 std::size_t sz=(*it1).size();
93 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfElemsOfGeoType : internal error in code !");
94 std::size_t nbGeo=sz/3;
95 for(std::size_t i=0;i<nbGeo;i++)
96 if((*it1)[3*i]==(int)t)
99 throw INTERP_KERNEL::Exception("The specified geometric type is not present in the mesh structure !");
103 * \sa MEDFileMeshStruct::getNumberOfElemsOfGeoType
105 bool MEDFileMeshStruct::doesManageGeoType(INTERP_KERNEL::NormalizedCellType t) const
107 for(std::vector< std::vector<mcIdType> >::const_iterator it1=_geo_types_distrib.begin();it1!=_geo_types_distrib.end();it1++)
109 std::size_t sz=(*it1).size();
111 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::doesManageGeoType : internal error in code !");
112 std::size_t nbGeo=sz/3;
113 for(std::size_t i=0;i<nbGeo;i++)
114 if((*it1)[3*i]==(int)t)
120 void MEDFileMeshStruct::appendIfImplicitType(INTERP_KERNEL::NormalizedCellType t)
122 if(!_mesh->hasImplicitPart())
123 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::appendIfImplicitType : by default no implicit geo type can be appended !");
124 static const char MSG[]="MEDFileMeshStruct::appendIfImplicitType : the distribution does not looks like structured standard !";
125 if(_geo_types_distrib.size()!=1)
126 throw INTERP_KERNEL::Exception(MSG);
127 std::size_t sz(_geo_types_distrib[0].size());
129 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::appendIfImplicitType : internal error in code !");
130 std::size_t nbGeo(sz/3);
132 throw INTERP_KERNEL::Exception(MSG);
133 std::vector<mcIdType> arr(3); arr[0]=(mcIdType)t; arr[1]=_mesh->buildImplicitPartIfAny(t); arr[2]=-1;
134 _geo_types_distrib.push_back(arr);
138 int MEDFileMeshStruct::getNumberOfLevs() const
140 return (int)_geo_types_distrib.size();
143 int MEDFileMeshStruct::getNumberOfGeoTypesInLev(int relativeLev) const
145 int pos(-relativeLev);
146 if(pos<0 || pos>=(int)_geo_types_distrib.size())
147 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : invalid level specified !");
148 std::size_t sz=_geo_types_distrib[pos].size();
150 throw INTERP_KERNEL::Exception("MEDFileMeshStruct::getNumberOfGeoTypesInLev : internal error in code !");
156 std::size_t MEDMeshMultiLev::getHeapMemorySizeWithoutChildren() const
161 std::vector<const BigMemoryObject *> MEDMeshMultiLev::getDirectChildrenWithNull() const
163 return std::vector<const BigMemoryObject *>();
166 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<int>& levs)
169 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : null input pointer !");
170 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
172 return MEDUMeshMultiLev::New(um,levs);
173 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
175 return MEDCMeshMultiLev::New(cm,levs);
176 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
178 return MEDCurveLinearMeshMultiLev::New(clm,levs);
179 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
182 MEDMeshMultiLev *MEDMeshMultiLev::New(const MEDFileMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities)
185 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : null input pointer !");
186 const MEDFileUMesh *um(dynamic_cast<const MEDFileUMesh *>(m));
188 return MEDUMeshMultiLev::New(um,gts,pfls,nbEntities);
189 const MEDFileCMesh *cm(dynamic_cast<const MEDFileCMesh *>(m));
191 return MEDCMeshMultiLev::New(cm,gts,pfls,nbEntities);
192 const MEDFileCurveLinearMesh *clm(dynamic_cast<const MEDFileCurveLinearMesh *>(m));
194 return MEDCurveLinearMeshMultiLev::New(clm,gts,pfls,nbEntities);
195 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::New 2 : unrecognized type of mesh ! Must be in [MEDFileUMesh,MEDFileCMesh,MEDFileCurveLinearMesh] !");
198 MEDMeshMultiLev *MEDMeshMultiLev::NewOnlyOnNode(const MEDFileMesh *m, const DataArrayIdType *pflOnNode)
200 MCAuto<MEDMeshMultiLev> ret(MEDMeshMultiLev::New(m,m->getNonEmptyLevels()));
201 ret->selectPartOfNodes(pflOnNode);
205 void MEDMeshMultiLev::setNodeReduction(const DataArrayIdType *nr)
209 _node_reduction=const_cast<DataArrayIdType*>(nr);
212 void MEDMeshMultiLev::setCellReduction(const DataArrayIdType *cr)
215 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::setCellReduction : can be used only for single geo type mesh !");
216 _pfls[0]=const_cast<DataArrayIdType*>(cr);
221 bool MEDMeshMultiLev::isFastlyTheSameStruct(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs) const
223 if(fst.getType()==ON_NODES)
225 if(fst.getNumberOfItems()!=1)
226 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::isFastlyTheSameStruct : unexpected situation for nodes !");
227 const MEDFileField1TSStructItem2& p(fst[0]);
228 std::string pflName(p.getPflName());
229 const DataArrayIdType *nr(_node_reduction);
230 if(pflName.empty() && !nr)
232 if(!pflName.empty() && !nr)
234 if(pflName==nr->getName())
240 std::size_t sz(fst.getNumberOfItems());
241 if(sz!=_geo_types.size())
244 for(unsigned int i=0;i<sz;i++)
246 const MEDFileField1TSStructItem2& p(fst[i]);
247 if(!p.isFastlyEqual(strt,_geo_types[i],getPflNameOfId(i).c_str()))
254 DataArray *MEDMeshMultiLev::buildDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
256 MCAuto<DataArray> ret(const_cast<DataArray *>(vals)); ret->incrRef();
257 if(isFastlyTheSameStruct(fst,globs))
260 return constructDataArray(fst,globs,vals);
264 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
265 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
267 void MEDMeshMultiLev::retrieveFamilyIdsOnCells(DataArrayIdType *& famIds, bool& isWithoutCopy) const
269 const DataArrayIdType *fids(_cell_fam_ids);
271 { famIds=0; isWithoutCopy=true; return ; }
272 std::size_t sz(_geo_types.size());
273 bool presenceOfPfls(false);
274 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
276 const DataArrayIdType *pfl(_pfls[i]);
281 { famIds=const_cast<DataArrayIdType *>(fids); famIds->incrRef(); isWithoutCopy=_mesh->isObjectInTheProgeny(famIds); return ; }
282 //bad luck the slowest part
284 std::vector< MCAuto<DataArrayIdType> > retSafe(sz);
285 std::vector< const DataArrayIdType *> ret(sz);
287 for(std::size_t i=0;i<sz;i++)
289 const DataArrayIdType *pfl(_pfls[i]);
290 mcIdType lgth(_nb_entities[i]);
293 MCAuto<DataArrayIdType> tmp(fids->selectByTupleIdSafeSlice(start,start+lgth,1));
294 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
298 retSafe[i]=fids->selectByTupleIdSafeSlice(start,start+lgth,1);
303 famIds=DataArrayIdType::Aggregate(ret);
307 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
308 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
310 void MEDMeshMultiLev::retrieveNumberIdsOnCells(DataArrayIdType *& numIds, bool& isWithoutCopy) const
312 const DataArrayIdType *nids(_cell_num_ids);
314 { numIds=0; isWithoutCopy=true; return ; }
315 std::size_t sz(_geo_types.size());
316 bool presenceOfPfls(false);
317 for(std::size_t i=0;i<sz && !presenceOfPfls;i++)
319 const DataArrayIdType *pfl(_pfls[i]);
324 { numIds=const_cast<DataArrayIdType *>(nids); numIds->incrRef(); isWithoutCopy=_mesh->isObjectInTheProgeny(numIds); return ; }
325 //bad luck the slowest part
327 std::vector< MCAuto<DataArrayIdType> > retSafe(sz);
328 std::vector< const DataArrayIdType *> ret(sz);
330 for(std::size_t i=0;i<sz;i++)
332 const DataArrayIdType *pfl(_pfls[i]);
333 mcIdType lgth(_nb_entities[i]);
336 MCAuto<DataArrayIdType> tmp(nids->selectByTupleIdSafeSlice(start,start+lgth,1));
337 retSafe[i]=tmp->selectByTupleIdSafe(pfl->begin(),pfl->end());
341 retSafe[i]=nids->selectByTupleIdSafeSlice(start,start+lgth,1);
346 numIds=DataArrayIdType::Aggregate(ret);
350 * \param [out] famIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
351 * \param [out] isWithoutCopy - When true the returned instance \a famIds if not null is directly those in the data structure.
353 void MEDMeshMultiLev::retrieveFamilyIdsOnNodes(DataArrayIdType *& famIds, bool& isWithoutCopy) const
355 const DataArrayIdType *fids(_node_fam_ids);
357 { famIds=0; isWithoutCopy=true; return ; }
358 const DataArrayIdType *nr(_node_reduction);
362 famIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
366 famIds=const_cast<DataArrayIdType *>(fids); famIds->incrRef();
367 isWithoutCopy=_mesh->isObjectInTheProgeny(famIds);
372 * \param [out] numIds - Can be null. If not null the instance has to be dealt by the caller (decrRef).
373 * \param [out] isWithoutCopy - When true the returned instance \a numIds if not null is directly those in the data structure.
375 void MEDMeshMultiLev::retrieveNumberIdsOnNodes(DataArrayIdType *& numIds, bool& isWithoutCopy) const
377 const DataArrayIdType *fids(_node_num_ids);
379 { numIds=0; isWithoutCopy=true; return ; }
380 const DataArrayIdType *nr(_node_reduction);
384 numIds=fids->selectByTupleIdSafe(nr->begin(),nr->end());
388 numIds=const_cast<DataArrayIdType *>(fids); numIds->incrRef();
389 isWithoutCopy=_mesh->isObjectInTheProgeny(numIds);
394 * This method returns, if any, a new object containing the global node ids **BUT CONTRARY TO OTHER RETRIEVE METHODS** the returned object is always a NON AGGREGATED object. So the returned object if not null
395 * can be used as this safely.
397 DataArrayIdType *MEDMeshMultiLev::retrieveGlobalNodeIdsIfAny() const
399 const MEDFileUMesh *umesh(dynamic_cast<const MEDFileUMesh *>(_mesh));
402 const PartDefinition *pd(umesh->getPartDefAtLevel(1));
405 MCAuto<DataArrayIdType> tmp(pd->toDAI());
406 const DataArrayIdType *tmpCpp(tmp);
410 const DataArrayIdType *nr(_node_reduction);
412 return tmp->selectByTupleIdSafe(nr->begin(),nr->end());
414 return tmp->deepCopy();// Yes a deep copy is needed because this method has to return a non aggregated object !
417 std::vector< INTERP_KERNEL::NormalizedCellType > MEDMeshMultiLev::getGeoTypes() const
422 void MEDMeshMultiLev::setFamilyIdsOnCells(DataArrayIdType *famIds)
424 _cell_fam_ids=famIds;
429 void MEDMeshMultiLev::setNumberIdsOnCells(DataArrayIdType *numIds)
431 _cell_num_ids=numIds;
436 void MEDMeshMultiLev::setFamilyIdsOnNodes(DataArrayIdType *famIds)
438 _node_fam_ids=famIds;
443 void MEDMeshMultiLev::setNumberIdsOnNodes(DataArrayIdType *numIds)
445 _node_num_ids=numIds;
450 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
452 std::size_t sz(_pfls.size());
453 if(id<0 || id>=(int)sz)
454 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
455 const DataArrayIdType *pfl(_pfls[id]);
457 return std::string("");
458 return pfl->getName();
462 * Returns the number of cells having geometric type \a t.
463 * The profiles are **NOT** taken into account here.
465 mcIdType MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
467 std::size_t sz(_nb_entities.size());
468 for(std::size_t i=0;i<sz;i++)
470 return _nb_entities[i];
471 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
474 mcIdType MEDMeshMultiLev::getNumberOfNodes() const
479 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
481 if(fst.getType()==ON_NODES)
483 if(fst.getNumberOfItems()!=1)
484 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
485 const MEDFileField1TSStructItem2& p(fst[0]);
486 std::string pflName(p.getPflName());
487 const DataArrayIdType *nr(_node_reduction);
488 if(pflName.empty() && !nr)
489 return vals->deepCopy();
490 if(pflName.empty() && nr)
491 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
492 if(!pflName.empty() && nr)
494 MCAuto<DataArrayIdType> p1(globs->getProfile(pflName.c_str())->deepCopy());
495 MCAuto<DataArrayIdType> p2(nr->deepCopy());
496 p1->sort(true); p2->sort(true);
497 if(!p1->isEqualWithoutConsideringStr(*p2))
498 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : it appears that a profile on nodes does not cover the cells correctly !");
499 p1=DataArrayIdType::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
500 MCAuto<DataArray> ret(vals->deepCopy());
501 ret->renumberInPlace(p1->begin());
504 if(!pflName.empty() && !nr)
506 MCAuto<DataArrayIdType> p1(globs->getProfile(pflName.c_str())->deepCopy());
508 if(!p1->isIota(getNumberOfNodes()))
509 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
510 MCAuto<DataArray> ret(vals->deepCopy());
511 ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
514 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
518 std::size_t sz(fst.getNumberOfItems());
519 std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
520 if(s.size()!=_geo_types.size())
521 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
522 std::vector< const DataArray *> arr(s.size());
523 std::vector< MCAuto<DataArray> > arrSafe(s.size());
525 mcIdType nc(ToIdType(vals->getNumberOfComponents()));
526 std::vector<std::string> compInfo(vals->getInfoOnComponents());
527 for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
529 const DataArrayIdType *thisP(_pfls[iii]);
530 std::vector<const MEDFileField1TSStructItem2 *> ps;
531 for(std::size_t i=0;i<sz;i++)
533 const MEDFileField1TSStructItem2& p(fst[i]);
538 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
541 int nbi(ps[0]->getNbOfIntegrationPts(globs));
542 const DataArrayIdType *otherP(ps[0]->getPfl(globs));
543 const std::pair<int,int>& strtStop(ps[0]->getStartStop());
544 MCAuto<DataArray> ret(vals->selectByTupleIdSafeSlice(strtStop.first,strtStop.second,1));
545 if(!thisP && !otherP)
547 arrSafe[iii]=ret; arr[iii]=ret;
552 MCAuto<DataArrayIdType> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
553 MCAuto<DataArrayIdType> p2(thisP->deepCopy());
554 p2->transformWithIndArr(p1->begin(),p1->end());
555 //p1=p2->findIdsNotEqual(-1);
556 //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
557 ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
558 arrSafe[iii]=ret; arr[iii]=ret;
563 MCAuto<DataArrayIdType> p1(otherP->deepCopy());
565 p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
566 p1=DataArrayIdType::FindPermutationFromFirstToSecond(otherP,p1);
567 ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
568 arrSafe[iii]=ret; arr[iii]=ret;
571 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
575 std::vector< const DataArrayIdType * >otherPS(ps.size());
576 std::vector< const DataArray * > arr2(ps.size());
577 std::vector< MCAuto<DataArray> > arr2Safe(ps.size());
578 std::vector< const DataArrayIdType * > nbis(ps.size());
579 std::vector< MCAuto<DataArrayIdType> > nbisSafe(ps.size());
581 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
583 int nbi((*it2)->getNbOfIntegrationPts(globs));
584 const DataArrayIdType *otherPfl((*it2)->getPfl(globs));
585 const std::pair<int,int>& strtStop((*it2)->getStartStop());
586 MCAuto<DataArray> ret2(vals->selectByTupleIdSafeSlice(strtStop.first,strtStop.second,1));
588 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
589 arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
590 nbisSafe[jj]=DataArrayIdType::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
591 nbis[jj]=nbisSafe[jj];
593 MCAuto<DataArray> arr3(DataArray::Aggregate(arr2));
594 MCAuto<DataArrayIdType> otherP(DataArrayIdType::Aggregate(otherPS));
595 MCAuto<DataArrayIdType> zenbis(DataArrayIdType::Aggregate(nbis));
596 MCAuto<DataArrayIdType> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
597 MCAuto<DataArrayIdType> p1;
599 p1=DataArrayIdType::FindPermutationFromFirstToSecond(otherP,thisP);
601 p1=otherP->deepCopy();
602 MCAuto<DataArrayIdType> zenbisN(zenbis->renumber(p1->begin()));
603 zenbisN->computeOffsetsFull();
605 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
607 //int nbi((*it2)->getNbOfIntegrationPts(globs));
608 const DataArrayIdType *otherPfl((*it2)->getPfl(globs));
609 const std::pair<int,int>& strtStop((*it2)->getStartStop());
610 MCAuto<DataArray> ret2(vals->selectByTupleIdSafeSlice(strtStop.first,strtStop.second,1));
612 MCAuto<DataArrayIdType> p2(otherPfl->deepCopy());
613 p2->transformWithIndArr(otherPN->begin(),otherPN->end());
614 p2->transformWithIndArr(p1->begin(),p1->end());
615 MCAuto<DataArrayIdType> idsN(p2->buildExplicitArrByRanges(zenbisN));
616 arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
618 arrSafe[iii]=arr3; arr[iii]=arr3;
622 return DataArray::Aggregate(arr);
627 * This method is called to add NORM_POINT1 cells in \a this so that orphan nodes in \a verticesToAdd will be fetched.
629 void MEDMeshMultiLev::appendVertices(const DataArrayIdType *verticesToAdd, DataArrayIdType *nr)
631 mcIdType nbOfVertices(verticesToAdd->getNumberOfTuples());
632 std::size_t sz(_pfls.size());
634 _geo_types.resize(sz+1,INTERP_KERNEL::NORM_POINT1);
635 _nb_entities.resize(sz+1,nbOfVertices);
636 _node_reduction=nr; nr->incrRef();
637 _nb_nodes+=nbOfVertices;
638 const DataArrayIdType *cf(_cell_fam_ids),*cn(_cell_num_ids),*nf(_node_fam_ids),*nn(_node_num_ids);
641 MCAuto<DataArrayIdType> tmp;
642 std::vector<const DataArrayIdType *> a(2);
645 tmp=nf->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
648 tmp=DataArrayIdType::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
651 _cell_fam_ids=DataArrayIdType::Aggregate(a);
655 MCAuto<DataArrayIdType> tmp;
656 std::vector<const DataArrayIdType *> a(2);
659 tmp=nn->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
662 tmp=DataArrayIdType::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
665 _cell_num_ids=DataArrayIdType::Aggregate(a);
669 MEDMeshMultiLev::MEDMeshMultiLev(const MEDFileMesh *mesh):_mesh(mesh),_nb_nodes(0)
673 MEDMeshMultiLev::MEDMeshMultiLev(const MEDFileMesh *mesh, mcIdType nbNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities):_mesh(mesh),_geo_types(gts),_nb_entities(nbEntities),_nb_nodes(nbNodes)
675 std::size_t sz(_geo_types.size());
676 if(sz!=pfls.size() || sz!=nbEntities.size())
677 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
679 for(std::size_t i=0;i<sz;i++)
683 _pfls[i]=const_cast<DataArrayIdType *>(pfls[i]);
687 MEDMeshMultiLev::MEDMeshMultiLev(const MEDMeshMultiLev& other):RefCountObject(other),_mesh(other._mesh),_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_num_ids(other._cell_num_ids),_node_fam_ids(other._node_fam_ids),_node_num_ids(other._node_num_ids)
693 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
695 return new MEDUMeshMultiLev(m,levs);
698 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs):MEDMeshMultiLev(m)
701 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
702 std::vector<MEDCoupling1GTUMesh *> v;
703 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
705 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
706 v.insert(v.end(),vTmp.begin(),vTmp.end());
708 std::size_t sz(v.size());
711 _coords=m->getCoords(); _coords->incrRef();
715 _geo_types.resize(sz);
716 _nb_entities.resize(sz);
717 for(std::size_t i=0;i<sz;i++)
719 MEDCoupling1GTUMesh *obj(v[i]);
723 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
725 _geo_types[i]=obj->getCellModelEnum();
726 _nb_entities[i]=obj->getNumberOfCells();
728 // ids fields management
729 bool cellFamIdsNoCpy(levs.size()==1);
732 const DataArrayIdType *tmp(m->getFamilyFieldAtLevel(levs[0]));
736 _cell_fam_ids=(const_cast<DataArrayIdType *>(tmp));
741 std::vector<const DataArrayIdType *> tmps(levs.size());
743 for(std::size_t i=0;i<levs.size();i++)
745 tmps[i]=m->getFamilyFieldAtLevel(levs[i]);
749 if(f && !tmps.empty())
750 _cell_fam_ids=DataArrayIdType::Aggregate(tmps);
752 bool cellNumIdsNoCpy(levs.size()==1);
755 const DataArrayIdType *tmp(m->getNumberFieldAtLevel(levs[0]));
759 _cell_num_ids=(const_cast<DataArrayIdType *>(tmp));
764 std::vector<const DataArrayIdType *> tmps(levs.size());
766 for(std::size_t i=0;i<levs.size();i++)
768 tmps[i]=m->getNumberFieldAtLevel(levs[i]);
772 if(n && !tmps.empty())
773 _cell_num_ids=DataArrayIdType::Aggregate(tmps);
777 const DataArrayIdType *tmp(m->getFamilyFieldAtLevel(1));
781 _node_fam_ids=(const_cast<DataArrayIdType *>(tmp));
785 const DataArrayIdType *tmp(m->getNumberFieldAtLevel(1));
789 _node_num_ids=(const_cast<DataArrayIdType *>(tmp));
794 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities)
796 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
799 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities):MEDMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
801 std::size_t sz(gts.size());
803 throw INTERP_KERNEL::Exception("constructor of MEDUMeshMultiLev : number of different geo type must be >= 1 !");
804 unsigned dim(INTERP_KERNEL::CellModel::GetCellModel(gts[0]).getDimension());
806 bool isSameDim(true),isNoPfl(true);
807 for(std::size_t i=0;i<sz;i++)
809 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
810 if(INTERP_KERNEL::CellModel::GetCellModel(gts[i]).getDimension()!=dim)
818 // ids fields management
819 int lev((int)dim-m->getMeshDimension());
820 if(isSameDim && isNoPfl && m->getGeoTypesAtLevel(lev)==gts)//optimized part
822 const DataArrayIdType *famIds(m->getFamilyFieldAtLevel(lev));
824 { _cell_fam_ids=const_cast<DataArrayIdType*>(famIds); famIds->incrRef(); }
825 const DataArrayIdType *numIds(m->getNumberFieldAtLevel(lev));
827 { _cell_num_ids=const_cast<DataArrayIdType*>(numIds); numIds->incrRef(); }
828 famIds=m->getFamilyFieldAtLevel(1);
830 { _node_fam_ids=const_cast<DataArrayIdType*>(famIds); famIds->incrRef(); }
831 numIds=m->getNumberFieldAtLevel(1);
833 { _node_num_ids=const_cast<DataArrayIdType*>(numIds); numIds->incrRef(); }
837 std::vector< MCAuto<DataArrayIdType> > famIdsSafe(sz);
838 std::vector<const DataArrayIdType *> famIds(sz);
840 for(std::size_t i=0;i<sz;i++)
842 famIdsSafe[i]=m->extractFamilyFieldOnGeoType(gts[i]);
843 famIds[i]=famIdsSafe[i];
848 _cell_fam_ids=DataArrayIdType::Aggregate(famIds);
849 std::vector< MCAuto<DataArrayIdType> > numIdsSafe(sz);
850 std::vector<const DataArrayIdType *> numIds(sz);
852 for(std::size_t i=0;i<sz;i++)
854 numIdsSafe[i]=m->extractNumberFieldOnGeoType(gts[i]);
855 numIds[i]=numIdsSafe[i];
860 _cell_num_ids=DataArrayIdType::Aggregate(numIds);
861 // node ids management
862 const DataArrayIdType *nodeFamIds(m->getFamilyFieldAtLevel(1));
864 { _node_fam_ids=const_cast<DataArrayIdType*>(nodeFamIds); nodeFamIds->incrRef(); }
865 const DataArrayIdType *nodeNumIds(m->getNumberFieldAtLevel(1));
867 { _node_num_ids=const_cast<DataArrayIdType*>(nodeNumIds); nodeNumIds->incrRef(); }
870 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayIdType *pflNodes)
872 if(!pflNodes || !pflNodes->isAllocated())
874 std::size_t sz(_parts.size());
875 std::vector< MCAuto<DataArrayIdType> > a(sz);
876 std::vector< const DataArrayIdType *> aa(sz);
877 for(std::size_t i=0;i<sz;i++)
879 const DataArrayIdType *pfl(_pfls[i]);
880 MCAuto<MEDCoupling1GTUMesh> m(_parts[i]);
882 m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
883 DataArrayIdType *cellIds=0;
884 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
885 MCAuto<DataArrayIdType> cellIdsSafe(cellIds);
886 MCAuto<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
888 MCAuto<DataArrayIdType> o2n(m2->getNodeIdsInUse(tmp));
889 a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
891 _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
893 _pfls[i]=cellIdsSafe;
896 _node_reduction=DataArrayIdType::Aggregate(aa);//general case
898 _node_reduction=pflNodes->deepCopy();//case where no cells in read mesh.
899 _node_reduction->sort(true);
900 _node_reduction=_node_reduction->buildUnique();
901 if(_node_reduction->getNumberOfTuples()==pflNodes->getNumberOfTuples())
902 return ;//This is the classical case where the input node profile corresponds perfectly to a subset of cells in _parts
903 if(_node_reduction->getNumberOfTuples()>pflNodes->getNumberOfTuples())
904 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::selectPartOfNodes : internal error in MEDCoupling during cell select from a list of nodes !");
905 // Here the cells available in _parts is not enough to cover all the nodes in pflNodes. So adding vertices cells in _parts...
906 MCAuto<DataArrayIdType> pflNodes2(pflNodes->deepCopy());
907 pflNodes2->sort(true);
908 MCAuto<DataArrayIdType> diff(pflNodes2->buildSubstractionOptimized(_node_reduction));
909 appendVertices(diff,pflNodes2);
912 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
914 return new MEDUMeshMultiLev(*this);
917 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts),_coords(other._coords)
921 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MCAuto<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
925 _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
926 _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
927 _pfls.resize(1); _pfls[0]=0;
931 * To be called only once ! Because due to some optimizations (sometimes aggressive) the internal state can be changed...
932 * 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.
933 * 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.
935 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayIdType *&cellLocations, DataArrayIdType *& cells, DataArrayIdType *&faceLocations, DataArrayIdType *&faces) const
937 const DataArrayDouble *tmp(0);
941 tmp=_parts[0]->getCoords();
943 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
944 MCAuto<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
945 mcIdType szBCE(0),szD(0),szF(0);
948 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
950 const MEDCoupling1GTUMesh *cur(*it);
952 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
954 const DataArrayIdType *pfl(_pfls[iii]);
955 MCAuto<MEDCoupling1GTUMesh> cur2;
957 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
959 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
961 mcIdType curNbCells(cur->getNumberOfCells());
963 if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
964 szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
968 MCAuto<DataArrayIdType> tmp2(cur->computeEffectiveNbOfNodesPerCell());
969 szD+=tmp2->accumulate((std::size_t)0)+curNbCells;
970 szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
973 MCAuto<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
974 MCAuto<DataArrayIdType> c(DataArrayIdType::New()); c->alloc(szBCE,1); mcIdType *cPtr(c->getPointer());
975 MCAuto<DataArrayIdType> d(DataArrayIdType::New()); d->alloc(szD,1); mcIdType *dPtr(d->getPointer());
976 MCAuto<DataArrayIdType> e(DataArrayIdType::New()),f(DataArrayIdType::New()); mcIdType *ePtr(0),*fPtr(0);
978 { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
981 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
983 const MEDCoupling1GTUMesh *cur(*it);
985 const DataArrayIdType *pfl(_pfls[iii]);
986 MCAuto<MEDCoupling1GTUMesh> cur2;
988 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
990 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
992 mcIdType curNbCells(cur->getNumberOfCells());
993 int gt((int)cur->getCellModelEnum());
994 if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
995 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
996 unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
998 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
999 std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
1000 const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
1001 const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
1002 const mcIdType *connPtr(cur->getNodalConnectivity()->begin());
1004 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
1007 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA27)
1009 mcIdType nnpc(scur->getNumberOfNodesPerCell());
1010 for(mcIdType i=0;i<curNbCells;i++,connPtr+=nnpc)
1013 dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
1014 *cPtr++=k; k+=nnpc+1;
1019 for(mcIdType i=0;i<curNbCells;i++,connPtr+=27)
1022 for(int j=0;j<27;j++,dPtr++)
1023 *dPtr=connPtr[HEXA27_PERM_ARRAY[j]];
1028 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1032 const mcIdType *connIPtr(dcur->getNodalConnectivityIndex()->begin());
1033 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1035 for(int i=0;i<curNbCells;i++,connIPtr++)
1037 *dPtr++=connIPtr[1]-connIPtr[0];
1038 dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
1039 *cPtr++=k; k+=connIPtr[1]-connIPtr[0]+1;
1044 for(mcIdType i=0;i<curNbCells;i++,connIPtr++)
1046 std::set<mcIdType> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
1047 *dPtr++=(mcIdType)s.size();
1048 dPtr=std::copy(s.begin(),s.end(),dPtr);
1049 *cPtr++=k; k+=(mcIdType)s.size()+1;
1054 connIPtr=dcur->getNodalConnectivityIndex()->begin();
1055 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1056 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1060 for(int i=0;i<curNbCells;i++,connIPtr++)
1062 mcIdType nbFace(ToIdType(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1));
1064 const mcIdType *work(connPtr+connIPtr[0]);
1065 for(int j=0;j<nbFace;j++)
1067 const mcIdType *work2=std::find(work,connPtr+connIPtr[1],-1);
1068 *fPtr++=ToIdType(std::distance(work,work2));
1069 fPtr=std::copy(work,work2,fPtr);
1072 *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
1079 reorderNodesIfNecessary(a,d,0);
1081 reorderNodesIfNecessary(a,d,f);
1082 if(a->getNumberOfComponents()!=3)
1083 a=a->changeNbOfComponents(3,0.);
1084 coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
1086 { faceLocations=0; faces=0; }
1088 { faceLocations=e.retn(); faces=f.retn(); }
1089 return _mesh->isObjectInTheProgeny(coords);
1092 void MEDUMeshMultiLev::reorderNodesIfNecessary(MCAuto<DataArrayDouble>& coords, DataArrayIdType *nodalConnVTK, DataArrayIdType *polyhedNodalConnVTK) const
1094 const DataArrayIdType *nr(_node_reduction);
1097 if(nodalConnVTK->empty() && !polyhedNodalConnVTK)
1099 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1102 mcIdType sz(coords->getNumberOfTuples());
1103 std::vector<bool> b(sz,false);
1104 const mcIdType *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
1107 mcIdType nb(*work++);
1108 for(mcIdType i=0;i<nb && work!=endW;i++,work++)
1110 if(*work>=0 && *work<sz)
1113 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
1116 if(polyhedNodalConnVTK)
1118 work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
1121 mcIdType nb(*work++);
1122 for(mcIdType i=0;i<nb && work!=endW;i++)
1124 mcIdType nb2(*work++);
1125 for(mcIdType j=0;j<nb2 && work!=endW;j++,work++)
1127 if(*work>=0 && *work<sz)
1130 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
1135 std::size_t szExp(std::count(b.begin(),b.end(),true));
1136 if(ToIdType(szExp)!=nr->getNumberOfTuples())
1137 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
1139 MCAuto<DataArrayIdType> o2n(DataArrayIdType::New()); o2n->alloc(sz,1);
1140 mcIdType *o2nPtr(o2n->getPointer());
1142 for(int i=0;i<sz;i++,o2nPtr++)
1143 if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
1144 const mcIdType *o2nPtrc(o2n->begin());
1145 MCAuto<DataArrayIdType> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
1146 MCAuto<DataArrayIdType> perm(DataArrayIdType::FindPermutationFromFirstToSecond(n2o,nr));
1147 const mcIdType *permPtr(perm->begin());
1148 mcIdType *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
1151 mcIdType nb(*work2++);
1152 for(mcIdType i=0;i<nb && work2!=endW2;i++,work2++)
1153 *work2=permPtr[o2nPtrc[*work2]];
1155 if(polyhedNodalConnVTK)
1157 work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
1160 mcIdType nb(*work2++);
1161 for(mcIdType i=0;i<nb && work2!=endW2;i++)
1163 mcIdType nb2(*work2++);
1164 for(mcIdType j=0;j<nb2 && work2!=endW2;j++,work2++)
1165 *work2=permPtr[o2nPtrc[*work2]];
1169 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1173 void MEDUMeshMultiLev::appendVertices(const DataArrayIdType *verticesToAdd, DataArrayIdType *nr)
1175 mcIdType nbOfCells(verticesToAdd->getNumberOfTuples());//it is not a bug cells are NORM_POINT1
1176 MEDMeshMultiLev::appendVertices(verticesToAdd,nr);
1177 MCAuto<MEDCoupling1SGTUMesh> elt(MEDCoupling1SGTUMesh::New("",INTERP_KERNEL::NORM_POINT1));
1178 elt->allocateCells(nbOfCells);
1179 for(mcIdType i=0;i<nbOfCells;i++)
1181 mcIdType pt(verticesToAdd->getIJ(i,0));
1182 elt->insertNextCell(&pt,&pt+1);
1185 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::appendVertices : parts are empty !");
1186 elt->setCoords(_parts[0]->getCoords());
1187 MCAuto<MEDCoupling1GTUMesh> elt2((MEDCoupling1SGTUMesh *)elt); elt2->incrRef();
1188 _parts.push_back(elt2);
1193 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector<int>& lev):MEDMeshMultiLev(m),_is_internal(true)
1195 initStdFieldOfIntegers(m);
1198 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, mcIdType nbOfNodes, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities):MEDMeshMultiLev(m,nbOfNodes,gts,pfls,nbEntities),_is_internal(true)
1200 initStdFieldOfIntegers(m);
1203 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other),_is_internal(true),_face_fam_ids(other._face_fam_ids),_face_num_ids(other._face_num_ids)
1207 void MEDStructuredMeshMultiLev::initStdFieldOfIntegers(const MEDFileStructuredMesh *m)
1209 // ids fields management
1210 const DataArrayIdType *tmp(0);
1211 tmp=m->getFamilyFieldAtLevel(0);
1215 _cell_fam_ids=const_cast<DataArrayIdType *>(tmp);
1217 tmp=m->getNumberFieldAtLevel(0);
1221 _cell_num_ids=const_cast<DataArrayIdType *>(tmp);
1225 tmp=m->getFamilyFieldAtLevel(1);
1229 _node_fam_ids=const_cast<DataArrayIdType *>(tmp);
1231 tmp=m->getNumberFieldAtLevel(1);
1235 _node_num_ids=const_cast<DataArrayIdType *>(tmp);
1238 tmp=m->getFamilyFieldAtLevel(-1);
1242 _face_fam_ids=const_cast<DataArrayIdType *>(tmp);
1244 tmp=m->getNumberFieldAtLevel(-1);
1248 _face_num_ids=const_cast<DataArrayIdType *>(tmp);
1252 void MEDStructuredMeshMultiLev::moveFaceToCell() const
1254 const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_fam_ids=_face_fam_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_fam_ids=0;
1255 const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_num_ids=_face_num_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_num_ids=0;
1258 bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const
1261 if(_geo_types.empty())
1263 if(_geo_types.size()!=1)
1264 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase only one geo types supported at most supported for the moment !");
1265 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(_mesh->getMeshDimension()));
1266 if(_geo_types[0]==gt)
1268 MEDCoupling1GTUMesh *facesIfPresent((static_cast<const MEDFileStructuredMesh *>(_mesh))->getImplicitFaceMesh());
1271 const DataArrayIdType *pfl(0),*nr(_node_reduction);
1274 MCAuto<MEDCoupling1GTUMesh> facesIfPresent2(facesIfPresent); facesIfPresent->incrRef();
1276 MCAuto<MEDUMeshMultiLev> ret2(new MEDUMeshMultiLev(*this,facesIfPresent2));
1278 ret2->setCellReduction(pfl);
1280 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for node reduction on implicit unstructured mesh.");
1285 void MEDStructuredMeshMultiLev::dealWithImplicitUnstructuredMesh(const MEDFileMesh *m)
1287 const DataArrayIdType *tmp(0);
1288 tmp=m->getFamilyFieldAtLevel(-1);
1292 _cell_fam_ids=const_cast<DataArrayIdType *>(tmp);
1294 tmp=m->getNumberFieldAtLevel(-1);
1298 _cell_num_ids=const_cast<DataArrayIdType *>(tmp);
1302 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayIdType *pflNodes)
1304 if(!pflNodes || !pflNodes->isAllocated())
1306 std::vector<mcIdType> ngs(getNodeGridStructure());
1307 MCAuto<DataArrayIdType> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1308 MCAuto<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension((int)ngs.size())));
1309 m->setNodalConnectivity(conn);
1310 const DataArrayIdType *pfl(_pfls[0]);
1313 m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1315 DataArrayIdType *cellIds=0;
1316 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1317 MCAuto<DataArrayIdType> cellIdsSafe(cellIds);
1318 MCAuto<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1320 _node_reduction=m2->getNodeIdsInUse(tmp);
1322 _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1324 _pfls[0]=cellIdsSafe;
1329 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
1331 return new MEDCMeshMultiLev(m,levs);
1334 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities)
1336 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
1339 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1342 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
1343 if(levs.size()!=1 || levs[0]!=0)
1344 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
1345 int sdim(m->getSpaceDimension());
1346 _coords.resize(sdim);
1347 for(int i=0;i<sdim;i++)
1349 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1351 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1357 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities):MEDStructuredMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
1360 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
1361 if(gts.size()!=1 || pfls.size()!=1)
1362 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengths of gts and pfls must be equal to one !");
1363 int mdim(m->getMeshDimension());
1364 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
1367 _coords.resize(mdim);
1368 for(int i=0;i<mdim;i++)
1370 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1372 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1373 _coords[i]=elt; _coords[i]->incrRef();
1377 dealWithImplicitUnstructuredMesh(m);
1380 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1384 std::vector<mcIdType> MEDCMeshMultiLev::getNodeGridStructure() const
1386 std::vector<mcIdType> ret(_coords.size());
1387 for(std::size_t i=0;i<_coords.size();i++)
1388 ret[i]=_coords[i]->getNumberOfTuples();
1392 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1394 MEDMeshMultiLev *retSpecific(0);
1395 if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1397 const DataArrayIdType *pfl(0),*nr(_node_reduction);
1400 MCAuto<DataArrayIdType> nnr;
1401 std::vector<mcIdType> cgs,ngs(getNodeGridStructure());
1402 cgs.resize(ngs.size());
1403 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<mcIdType>(),-1));
1406 std::vector< std::pair<mcIdType,mcIdType> > cellParts;
1407 MCAuto<MEDMeshMultiLev> ret2;
1408 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1410 MCAuto<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1411 ret->_is_internal=false;
1413 { nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1414 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1416 std::vector< MCAuto<DataArrayDouble> > coords(_coords.size());
1417 for(std::size_t i=0;i<_coords.size();i++)
1418 coords[i]=_coords[i]->selectByTupleIdSafeSlice(cellParts[i].first,cellParts[i].second+1,1);
1419 ret->_coords=coords;
1420 ret2=(MEDCMeshMultiLev *)ret; ret2->incrRef();
1424 MCAuto<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1425 for(unsigned int i=0;i<ngs.size();i++)
1426 m->setCoordsAt(i,_coords[i]);
1427 MCAuto<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1428 MCAuto<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1429 MCAuto<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1431 { m3->zipCoords(); nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1432 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1434 const DataArrayIdType *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1437 MCAuto<DataArrayIdType> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1438 ret2->setFamilyIdsOnCells(tmp);
1442 MCAuto<DataArrayIdType> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1443 ret2->setNumberIdsOnCells(tmp);
1450 MCAuto<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1452 { nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1458 * \a param [out] isInternal if true the returned pointers are those in main data structure. If false those pointers have been built especially for that method.
1460 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays(bool& isInternal) const
1462 isInternal=_is_internal;
1463 std::size_t sz(_coords.size());
1464 std::vector< DataArrayDouble * > ret(sz);
1465 for(std::size_t i=0;i<sz;i++)
1467 ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1475 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1477 return new MEDCurveLinearMeshMultiLev(m,levs);
1480 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities)
1482 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1485 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1488 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1489 if(levs.size()!=1 || levs[0]!=0)
1490 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1491 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1493 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1496 _structure=m->getMesh()->getNodeGridStructure();
1499 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities):MEDStructuredMeshMultiLev(m,m->getNumberOfNodes(),gts,pfls,nbEntities)
1502 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1503 if(gts.size()!=1 || pfls.size()!=1)
1504 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengths of gts and pfls must be equal to one !");
1505 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1508 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1510 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1513 _structure=m->getMesh()->getNodeGridStructure();
1516 dealWithImplicitUnstructuredMesh(m);
1519 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1523 std::vector<mcIdType> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1528 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1530 MEDMeshMultiLev *retSpecific(0);
1531 if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1533 const DataArrayIdType *pfl(0),*nr(_node_reduction);
1536 MCAuto<DataArrayIdType> nnr;
1537 std::vector<mcIdType> cgs,ngs(getNodeGridStructure());
1538 cgs.resize(ngs.size());
1539 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind2nd(std::plus<mcIdType>(),-1));
1542 std::vector< std::pair<mcIdType,mcIdType> > cellParts,nodeParts;
1543 MCAuto<MEDMeshMultiLev> ret2;
1544 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1546 nodeParts=cellParts;
1547 std::vector<mcIdType> st(ngs.size());
1548 for(std::size_t i=0;i<ngs.size();i++)
1550 nodeParts[i].second++;
1551 st[i]=nodeParts[i].second-nodeParts[i].first;
1553 MCAuto<DataArrayIdType> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1554 MCAuto<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1555 ret->_is_internal=false;
1557 { nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1558 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1560 ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1562 ret2=(MEDCurveLinearMeshMultiLev *)ret; ret2->incrRef();
1566 MCAuto<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1567 m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1568 MCAuto<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1569 MCAuto<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1570 MCAuto<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1572 { m3->zipCoords(); nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1573 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1575 const DataArrayIdType *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1578 MCAuto<DataArrayIdType> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1579 ret2->setFamilyIdsOnCells(tmp);
1583 MCAuto<DataArrayIdType> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1584 ret2->setNumberIdsOnCells(tmp);
1590 MCAuto<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1592 { nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1597 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<mcIdType>& nodeStrct, bool& isInternal) const
1599 isInternal=_is_internal;
1600 nodeStrct=_structure;
1601 const DataArrayDouble *coo(_coords);
1603 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1604 coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1609 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1613 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2(INTERP_KERNEL::NormalizedCellType a, const std::pair<mcIdType,mcIdType>& b, const std::string& c, const std::string& d):_geo_type(a),_start_end(b),_pfl(DataArrayIdType::New()),_loc(d),_nb_of_entity(-1)
1615 _pfl->setName(c.c_str());
1618 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1620 if(!mst->doesManageGeoType(_geo_type))
1622 MEDFileMeshStruct *mstUnConstCasted(const_cast<MEDFileMeshStruct *>(mst));
1623 mstUnConstCasted->appendIfImplicitType(_geo_type);
1625 mcIdType nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1626 checkInRange(nbOfEnt,1,globs);
1629 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1631 mcIdType nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1632 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1633 checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1636 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1639 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1641 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1642 const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1643 mcIdType nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1644 checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1647 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1651 if(getPflName().empty())
1652 return (int)((_start_end.second-_start_end.first)/_nb_of_entity);
1654 return (int)((_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples());
1658 const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1659 return loc.getNumberOfGaussPoints();
1663 std::string MEDFileField1TSStructItem2::getPflName() const
1665 return _pfl->getName();
1668 const DataArrayIdType *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1670 if(!_pfl->isAllocated())
1672 if(_pfl->getName().empty())
1675 return globs->getProfile(_pfl->getName().c_str());
1682 * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possibility.
1683 * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1685 void MEDFileField1TSStructItem2::checkInRange(mcIdType nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1687 _nb_of_entity=nbOfEntity;
1688 if(_pfl->getName().empty())
1690 if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1691 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of field !");
1697 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1698 const DataArrayIdType *pfl=globs->getProfile(_pfl->getName().c_str());
1700 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1701 pfl->checkAllIdsInRange(0,nbOfEntity);
1705 bool MEDFileField1TSStructItem2::isFastlyEqual(mcIdType& startExp, INTERP_KERNEL::NormalizedCellType gt, const std::string& pflName) const
1707 if(startExp!=_start_end.first)
1711 if(getPflName()!=pflName)
1713 startExp=_start_end.second;
1717 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const
1719 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1720 //idem for _loc. It is not an effective attribute for support comparison.
1721 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1724 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1726 if(_geo_type!=other._geo_type)
1728 if(_nb_of_entity!=other._nb_of_entity)
1730 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1732 if(_pfl->getName().empty() && other._pfl->getName().empty())
1734 const DataArrayIdType *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1735 return pfl1->isEqualWithoutConsideringStr(*pfl2);
1738 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1740 return isCellSupportEqual(other,globs);
1744 * \a objs must be non empty. \a objs should contain items having same geometric type.
1746 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1749 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1751 return MEDFileField1TSStructItem2(*objs[0]);
1752 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1753 mcIdType nbEntityRef(objs[0]->_nb_of_entity);
1754 std::size_t sz(objs.size());
1755 std::vector<const DataArrayIdType *> arrs(sz);
1756 for(std::size_t i=0;i<sz;i++)
1758 const MEDFileField1TSStructItem2 *obj(objs[i]);
1759 if(gt!=obj->_geo_type)
1760 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1761 if(nbEntityRef!=obj->_nb_of_entity)
1762 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1763 if(obj->_pfl->getName().empty())
1764 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1765 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1767 MCAuto<DataArrayIdType> arr(DataArrayIdType::Aggregate(arrs));
1769 mcIdType oldNbTuples(arr->getNumberOfTuples());
1770 arr=arr->buildUnique();
1771 if(oldNbTuples!=arr->getNumberOfTuples())
1772 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1773 if(arr->isIota(nbEntityRef))
1775 std::pair<mcIdType,mcIdType> p(0,nbEntityRef);
1777 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1778 ret._nb_of_entity=nbEntityRef;
1783 arr->setName(NEWLY_CREATED_PFL_NAME);
1784 std::pair<mcIdType,mcIdType> p(0,oldNbTuples);
1786 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1787 ret._nb_of_entity=nbEntityRef;
1793 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1795 std::size_t ret(_loc.capacity());
1799 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildrenWithNull() const
1801 std::vector<const BigMemoryObject *> ret;
1802 ret.push_back((const DataArrayIdType *)_pfl);
1808 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1812 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1818 mcIdType nbOfEnt=mst->getNumberOfNodes();
1819 if(_items.size()!=1)
1820 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1821 _items[0].checkInRange(nbOfEnt,1,globs);
1826 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1827 (*it).checkWithMeshStructForCells(mst,globs);
1832 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1833 (*it).checkWithMeshStructForGaussNE(mst,globs);
1838 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1839 (*it).checkWithMeshStructForGaussPT(mst,globs);
1843 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1847 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const
1849 if(_type!=other._type)
1851 if(_items.size()!=other._items.size())
1853 for(std::size_t i=0;i<_items.size();i++)
1854 if(!(_items[i]==other._items[i]))
1859 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1861 if(_type!=other._type)
1863 if(_items.size()!=other._items.size())
1865 for(std::size_t i=0;i<_items.size();i++)
1866 if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1871 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1873 if(_type!=other._type)
1875 if(_items.size()!=other._items.size())
1877 for(std::size_t i=0;i<_items.size();i++)
1878 if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1883 bool MEDFileField1TSStructItem::isEntityCell() const
1894 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1895 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1897 INTERP_KERNEL::NormalizedCellType _geo_type;
1900 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1903 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1904 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1906 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1908 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1910 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1912 (*it0).second.push_back(i);
1914 if(m.size()==_items.size())
1916 MEDFileField1TSStructItem ret(*this);
1920 std::size_t sz(m.size());
1921 std::vector< MEDFileField1TSStructItem2 > items(sz);
1924 const std::vector<std::size_t>& ids=m[i].second;
1925 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1926 for(std::size_t j=0;j<ids.size();j++)
1927 objs[j]=&_items[ids[j]];
1928 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1930 MEDFileField1TSStructItem ret(ON_CELLS,items);
1936 * \a this is expected to be ON_CELLS and simplified.
1938 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1940 if(other._type!=ON_NODES)
1941 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1942 if(other._items.size()!=1)
1943 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1944 int theFirstLevFull;
1945 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1946 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1947 mcIdType nbOfNodes(meshSt->getNumberOfNodes());
1948 if(otherNodeIt.getPflName().empty())
1952 std::vector<bool> nodesFetched(nbOfNodes,false);
1953 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1954 if(std::find(nodesFetched.begin(),nodesFetched.end(),false)==nodesFetched.end())
1955 return theFirstLevFull==0;
1961 const DataArrayIdType *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1962 MCAuto<DataArrayIdType> cpyPfl(pfl->deepCopy());
1964 if(cpyPfl->isIota(nbOfNodes))
1965 {//on all nodes also !
1968 return theFirstLevFull==0;
1970 std::vector<bool> nodesFetched(nbOfNodes,false);
1971 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1972 return cpyPfl->isFittingWith(nodesFetched);
1976 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1979 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1981 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1982 int nbOfLevs(meshSt->getNumberOfLevs());
1984 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1985 std::vector<int> levs(nbOfLevs);
1987 std::set<INTERP_KERNEL::NormalizedCellType> gts;
1988 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1990 if(!(*it).getPflName().empty())
1992 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1993 if(gts.find(gt)!=gts.end())
1994 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
1996 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
1999 for(int i=0;i<nbOfLevs;i++)
2000 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
2001 { theFirstLevFull=-i; return true; }
2005 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const
2007 if(i>=_items.size())
2008 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
2012 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
2014 std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
2018 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildrenWithNull() const
2020 std::vector<const BigMemoryObject *> ret;
2021 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2022 ret.push_back(&(*it));
2026 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2028 std::size_t sz(_items.size());
2029 std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
2030 std::vector<const DataArrayIdType *> a1(sz);
2031 std::vector<mcIdType> a2(sz);
2033 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
2035 a0[i]=(*it).getGeo();
2036 a1[i]=(*it).getPfl(globs);
2037 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
2039 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
2042 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStructItem::getGeoTypes(const MEDFileMesh *m) const
2044 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2047 if(!_items.empty() && _items[0].getPflName().empty())
2050 return m->getAllGeoTypes();
2057 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2059 INTERP_KERNEL::NormalizedCellType elt((*it).getGeo());
2060 std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it2(std::find(ret.begin(),ret.end(),elt));
2067 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
2069 std::vector< MEDFileField1TSStructItem2 > anItems;
2071 std::vector< std::vector<std::string> > pfls,locs;
2072 std::vector< std::vector<TypeOfField> > typesF;
2073 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2074 std::vector< std::vector<std::pair<mcIdType,mcIdType> > > strtEnds=ref->getFieldSplitedByType(std::string(),geoTypes,typesF,pfls,locs);
2075 std::size_t nbOfGeoTypes(geoTypes.size());
2077 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
2078 if(typesF[0].empty())
2079 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 bis !");
2080 TypeOfField atype(typesF[0][0]);
2081 for(std::size_t i=0;i<nbOfGeoTypes;i++)
2083 std::size_t sz=typesF[i].size();
2084 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
2085 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
2087 for(std::size_t j=0;j<sz;j++)
2089 if(atype==typesF[i][j])
2090 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
2092 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
2095 MEDFileField1TSStructItem ret(atype,anItems);
2098 ret.checkWithMeshStruct(meshSt,ref);
2100 catch(INTERP_KERNEL::Exception& e)
2102 std::ostringstream oss; oss << e.what() << " (" << MEDCouplingFieldDiscretization::GetTypeOfFieldRepr(ret.getType()) << ")";
2103 throw INTERP_KERNEL::Exception(oss.str().c_str());
2110 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2112 return new MEDFileField1TSStruct(ref,mst);
2115 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2117 _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
2120 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
2122 if(_already_checked.empty())
2123 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
2124 _already_checked.back().checkWithMeshStruct(mst,globs);
2127 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
2129 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
2130 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2139 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
2141 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2143 if(_already_checked.empty())
2144 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
2145 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2146 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
2147 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
2148 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
2150 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2151 if((*it).isComputed())
2156 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2157 ret=this1.isCellSupportEqual(other1,other);
2159 _already_checked.push_back(this1);
2162 ret=_already_checked[found].isCellSupportEqual(other1,other);
2164 _already_checked.push_back(b);
2169 * \param [in] other - a field with only one spatial discretization : ON_NODES.
2171 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2173 if(_already_checked.empty())
2174 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
2175 MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2176 if(_already_checked[0].isEntityCell())
2179 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2180 if((*it).isComputed())
2185 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2186 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
2188 _already_checked.push_back(this1);
2191 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
2193 _already_checked.push_back(other1);
2197 return _already_checked[0].isNodeSupportEqual(other1,other);
2200 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
2202 std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
2206 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildrenWithNull() const
2208 std::vector<const BigMemoryObject *> ret;
2209 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2210 ret.push_back(&(*it));
2214 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2216 if(_already_checked.empty())
2217 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
2218 int pos0(-1),pos1(-1);
2219 if(presenceOfCellDiscr(pos0))
2221 MCAuto<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
2222 if(presenceOfPartialNodeDiscr(pos1))
2223 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
2228 if(!presenceOfPartialNodeDiscr(pos1))
2229 {//we have only all nodes, no cell definition info -> all existing levels !;
2230 return MEDMeshMultiLev::New(mst->getTheMesh(),mst->getTheMesh()->getNonEmptyLevels());
2233 return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
2237 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
2240 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
2242 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
2243 if(a0!=c0 || a1!=c1)
2246 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
2249 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
2254 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStruct::getGeoTypes(const MEDFileMesh *m) const
2256 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2257 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2259 std::vector<INTERP_KERNEL::NormalizedCellType> ret2((*it).getGeoTypes(m));
2260 for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator it2=ret2.begin();it2!=ret2.end();it2++)
2262 if(*it2==INTERP_KERNEL::NORM_ERROR)
2264 std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it3(std::find(ret.begin(),ret.end(),*it2));
2266 ret.push_back(*it2);
2273 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
2274 * If true is returned the pos of the easiest is returned. The easiest is the first element in \a this having the less split subparts.
2276 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
2278 std::size_t refSz(std::numeric_limits<std::size_t>::max());
2281 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2283 if((*it).getType()!=ON_NODES)
2286 std::size_t sz((*it).getNumberOfItems());
2288 { pos=i; refSz=sz; }
2292 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
2297 * Returns true if presence in \a this of discretization ON_NODES.
2298 * If true is returned the pos of the first element containing the single subpart.
2300 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
2303 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2305 if((*it).getType()==ON_NODES)
2307 std::size_t sz((*it).getNumberOfItems());
2310 if(!(*it)[0].getPflName().empty())
2311 { pos=i; return true; }
2314 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
2322 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2324 return new MEDFileFastCellSupportComparator(m,ref);
2327 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2330 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
2331 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
2332 int nbPts=ref->getNumberOfTS();
2333 _f1ts_cmps.resize(nbPts);
2334 for(int i=0;i<nbPts;i++)
2336 MCAuto<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
2339 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
2340 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
2342 catch(INTERP_KERNEL::Exception& e)
2344 std::ostringstream oss; oss << "Problem in field with name \"" << ref->getName() << "\"" << std::endl;
2345 oss << "More Details : " << e.what();
2346 throw INTERP_KERNEL::Exception(oss.str().c_str());
2351 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
2353 std::size_t ret(_f1ts_cmps.capacity()*sizeof(MCAuto<MEDFileField1TSStruct>));
2357 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildrenWithNull() const
2359 std::vector<const BigMemoryObject *> ret;
2360 const MEDFileMeshStruct *mst(_mesh_comp);
2363 for(std::vector< MCAuto<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
2364 ret.push_back((const MEDFileField1TSStruct *)*it);
2368 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
2370 int nbPts=other->getNumberOfTS();
2371 if(nbPts!=(int)_f1ts_cmps.size())
2373 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2374 throw INTERP_KERNEL::Exception(oss.str().c_str());
2376 for(int i=0;i<nbPts;i++)
2378 MCAuto<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2379 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
2380 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
2386 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
2388 int nbPts=other->getNumberOfTS();
2389 if(nbPts!=(int)_f1ts_cmps.size())
2391 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2392 throw INTERP_KERNEL::Exception(oss.str().c_str());
2394 for(int i=0;i<nbPts;i++)
2396 MCAuto<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2397 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
2403 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2405 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2407 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2408 throw INTERP_KERNEL::Exception(oss.str().c_str());
2410 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2413 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
2414 throw INTERP_KERNEL::Exception(oss.str().c_str());
2416 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
2419 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2421 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
2423 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
2424 throw INTERP_KERNEL::Exception(oss.str().c_str());
2426 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2427 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
2428 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
2431 int MEDFileFastCellSupportComparator::getNumberOfTS() const
2433 return (int)_f1ts_cmps.size();
2436 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileFastCellSupportComparator::getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const
2438 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2440 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2441 throw INTERP_KERNEL::Exception(oss.str().c_str());
2443 const MEDFileField1TSStruct *elt(_f1ts_cmps[timeStepId]);
2446 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " points to a NULL pointer !";
2447 throw INTERP_KERNEL::Exception(oss.str().c_str());
2449 return elt->getGeoTypes(m);