1 // Copyright (C) 2007-2024 CEA, EDF
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> gni = umesh->getGlobalNumFieldAtLevel(1);
408 return gni->deepCopy();
410 MCAuto<DataArrayIdType> tmp(pd->toDAI());
411 const DataArrayIdType *tmpCpp(tmp);
415 const DataArrayIdType *nr(_node_reduction);
417 return tmp->selectByTupleIdSafe(nr->begin(),nr->end());
419 return tmp->deepCopy();// Yes a deep copy is needed because this method has to return a non aggregated object !
422 std::vector< INTERP_KERNEL::NormalizedCellType > MEDMeshMultiLev::getGeoTypes() const
427 void MEDMeshMultiLev::setFamilyIdsOnCells(DataArrayIdType *famIds)
429 _cell_fam_ids=famIds;
434 void MEDMeshMultiLev::setNumberIdsOnCells(DataArrayIdType *numIds)
436 _cell_num_ids=numIds;
441 void MEDMeshMultiLev::setFamilyIdsOnNodes(DataArrayIdType *famIds)
443 _node_fam_ids=famIds;
448 void MEDMeshMultiLev::setNumberIdsOnNodes(DataArrayIdType *numIds)
450 _node_num_ids=numIds;
455 std::string MEDMeshMultiLev::getPflNameOfId(int id) const
457 std::size_t sz(_pfls.size());
458 if(id<0 || id>=(int)sz)
459 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getPflNameOfId : invalid input id !");
460 const DataArrayIdType *pfl(_pfls[id]);
462 return std::string("");
463 return pfl->getName();
467 * Returns the number of cells having geometric type \a t.
468 * The profiles are **NOT** taken into account here.
470 mcIdType MEDMeshMultiLev::getNumberOfCells(INTERP_KERNEL::NormalizedCellType t) const
472 std::size_t sz(_nb_entities.size());
473 for(std::size_t i=0;i<sz;i++)
475 return _nb_entities[i];
476 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::getNumberOfCells : not existing geometric type in this !");
479 mcIdType MEDMeshMultiLev::getNumberOfNodes() const
484 DataArray *MEDMeshMultiLev::constructDataArray(const MEDFileField1TSStructItem& fst, const MEDFileFieldGlobsReal *globs, const DataArray *vals) const
486 if(fst.getType()==ON_NODES)
488 if(fst.getNumberOfItems()!=1)
489 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes !");
490 const MEDFileField1TSStructItem2& p(fst[0]);
491 std::string pflName(p.getPflName());
492 const DataArrayIdType *nr(_node_reduction);
493 if(pflName.empty() && !nr)
494 return vals->deepCopy();
495 if(pflName.empty() && nr)
496 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 2 !");
497 if(!pflName.empty() && nr)
499 MCAuto<DataArrayIdType> p1(globs->getProfile(pflName.c_str())->deepCopy());
500 MCAuto<DataArrayIdType> p2(nr->deepCopy());
501 p1->sort(true); p2->sort(true);
502 if(!p1->isEqualWithoutConsideringStr(*p2))
503 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : it appears that a profile on nodes does not cover the cells correctly !");
504 p1=DataArrayIdType::FindPermutationFromFirstToSecond(globs->getProfile(pflName.c_str()),nr);
505 MCAuto<DataArray> ret(vals->deepCopy());
506 ret->renumberInPlace(p1->begin());
509 if(!pflName.empty() && !nr)
511 MCAuto<DataArrayIdType> p1(globs->getProfile(pflName.c_str())->deepCopy());
513 if(!p1->isIota(getNumberOfNodes()))
514 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 4 !");
515 MCAuto<DataArray> ret(vals->deepCopy());
516 ret->renumberInPlace(globs->getProfile(pflName.c_str())->begin());
519 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for nodes 5 !");
523 std::size_t sz(fst.getNumberOfItems());
524 std::set<INTERP_KERNEL::NormalizedCellType> s(_geo_types.begin(),_geo_types.end());
525 if(s.size()!=_geo_types.size())
526 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 2 !");
527 std::vector< const DataArray *> arr(s.size());
528 std::vector< MCAuto<DataArray> > arrSafe(s.size());
530 mcIdType nc(ToIdType(vals->getNumberOfComponents()));
531 std::vector<std::string> compInfo(vals->getInfoOnComponents());
532 for(std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator it=_geo_types.begin();it!=_geo_types.end();it++,iii++)
534 const DataArrayIdType *thisP(_pfls[iii]);
535 std::vector<const MEDFileField1TSStructItem2 *> ps;
536 for(std::size_t i=0;i<sz;i++)
538 const MEDFileField1TSStructItem2& p(fst[i]);
543 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 1 !");
546 int nbi(ps[0]->getNbOfIntegrationPts(globs));
547 const DataArrayIdType *otherP(ps[0]->getPfl(globs));
548 const std::pair<int,int>& strtStop(ps[0]->getStartStop());
549 MCAuto<DataArray> ret(vals->selectByTupleIdSafeSlice(strtStop.first,strtStop.second,1));
550 if(!thisP && !otherP)
552 arrSafe[iii]=ret; arr[iii]=ret;
557 MCAuto<DataArrayIdType> p1(otherP->invertArrayN2O2O2N(getNumberOfCells(ps[0]->getGeo())));
558 MCAuto<DataArrayIdType> p2(thisP->deepCopy());
559 p2->transformWithIndArr(p1->begin(),p1->end());
560 //p1=p2->findIdsNotEqual(-1);
561 //p1=p2->selectByTupleIdSafe(p1->begin(),p1->end());
562 ret->rearrange(nbi*nc); ret=ret->selectByTupleIdSafe(p2->begin(),p2->end()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
563 arrSafe[iii]=ret; arr[iii]=ret;
568 MCAuto<DataArrayIdType> p1(otherP->deepCopy());
570 p1->checkAllIdsInRange(0,getNumberOfCells(ps[0]->getGeo()));
571 p1=DataArrayIdType::FindPermutationFromFirstToSecond(otherP,p1);
572 ret->rearrange(nbi*nc); ret->renumberInPlace(p1->begin()); ret->rearrange(nc); ret->setInfoOnComponents(compInfo);
573 arrSafe[iii]=ret; arr[iii]=ret;
576 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 3 !");
580 std::vector< const DataArrayIdType * >otherPS(ps.size());
581 std::vector< const DataArray * > arr2(ps.size());
582 std::vector< MCAuto<DataArray> > arr2Safe(ps.size());
583 std::vector< const DataArrayIdType * > nbis(ps.size());
584 std::vector< MCAuto<DataArrayIdType> > nbisSafe(ps.size());
586 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
588 int nbi((*it2)->getNbOfIntegrationPts(globs));
589 const DataArrayIdType *otherPfl((*it2)->getPfl(globs));
590 const std::pair<int,int>& strtStop((*it2)->getStartStop());
591 MCAuto<DataArray> ret2(vals->selectByTupleIdSafeSlice(strtStop.first,strtStop.second,1));
593 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::constructDataArray : unexpected situation for cells 4 !");
594 arr2[jj]=ret2; arr2Safe[jj]=ret2; otherPS[jj]=otherPfl;
595 nbisSafe[jj]=DataArrayIdType::New(); nbisSafe[jj]->alloc(otherPfl->getNumberOfTuples(),1); nbisSafe[jj]->fillWithValue(nbi);
596 nbis[jj]=nbisSafe[jj];
598 MCAuto<DataArray> arr3(DataArray::Aggregate(arr2));
599 MCAuto<DataArrayIdType> otherP(DataArrayIdType::Aggregate(otherPS));
600 MCAuto<DataArrayIdType> zenbis(DataArrayIdType::Aggregate(nbis));
601 MCAuto<DataArrayIdType> otherPN(otherP->invertArrayN2O2O2N(getNumberOfCells(*it)));
602 MCAuto<DataArrayIdType> p1;
604 p1=DataArrayIdType::FindPermutationFromFirstToSecond(otherP,thisP);
606 p1=otherP->deepCopy();
607 MCAuto<DataArrayIdType> zenbisN(zenbis->renumber(p1->begin()));
608 zenbisN->computeOffsetsFull();
610 for(std::vector<const MEDFileField1TSStructItem2 *>::const_iterator it2=ps.begin();it2!=ps.end();it2++,jj++)
612 //int nbi((*it2)->getNbOfIntegrationPts(globs));
613 const DataArrayIdType *otherPfl((*it2)->getPfl(globs));
614 const std::pair<int,int>& strtStop((*it2)->getStartStop());
615 MCAuto<DataArray> ret2(vals->selectByTupleIdSafeSlice(strtStop.first,strtStop.second,1));
617 MCAuto<DataArrayIdType> p2(otherPfl->deepCopy());
618 p2->transformWithIndArr(otherPN->begin(),otherPN->end());
619 p2->transformWithIndArr(p1->begin(),p1->end());
620 MCAuto<DataArrayIdType> idsN(p2->buildExplicitArrByRanges(zenbisN));
621 arr3->setPartOfValuesBase3(ret2,idsN->begin(),idsN->end(),0,nc,1);
623 arrSafe[iii]=arr3; arr[iii]=arr3;
627 return DataArray::Aggregate(arr);
632 * This method is called to add NORM_POINT1 cells in \a this so that orphan nodes in \a verticesToAdd will be fetched.
634 void MEDMeshMultiLev::appendVertices(const DataArrayIdType *verticesToAdd, DataArrayIdType *nr)
636 mcIdType nbOfVertices(verticesToAdd->getNumberOfTuples());
637 std::size_t sz(_pfls.size());
639 _geo_types.resize(sz+1,INTERP_KERNEL::NORM_POINT1);
640 _nb_entities.resize(sz+1,nbOfVertices);
641 _node_reduction=nr; nr->incrRef();
642 _nb_nodes+=nbOfVertices;
643 const DataArrayIdType *cf(_cell_fam_ids),*cn(_cell_num_ids),*nf(_node_fam_ids),*nn(_node_num_ids);
646 MCAuto<DataArrayIdType> tmp;
647 std::vector<const DataArrayIdType *> a(2);
650 tmp=nf->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
653 tmp=DataArrayIdType::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
656 _cell_fam_ids=DataArrayIdType::Aggregate(a);
660 MCAuto<DataArrayIdType> tmp;
661 std::vector<const DataArrayIdType *> a(2);
664 tmp=nn->selectByTupleIdSafe(verticesToAdd->begin(),verticesToAdd->end());
667 tmp=DataArrayIdType::New(); tmp->alloc(nbOfVertices,1); tmp->fillWithZero();
670 _cell_num_ids=DataArrayIdType::Aggregate(a);
674 MEDMeshMultiLev::MEDMeshMultiLev(const MEDFileMesh *mesh):_mesh(mesh),_nb_nodes(0)
678 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)
680 std::size_t sz(_geo_types.size());
681 if(sz!=pfls.size() || sz!=nbEntities.size())
682 throw INTERP_KERNEL::Exception("MEDMeshMultiLev::MEDMeshMultiLev : input vector must have the same size !");
684 for(std::size_t i=0;i<sz;i++)
688 _pfls[i]=const_cast<DataArrayIdType *>(pfls[i]);
692 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)
698 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<int>& levs)
700 return new MEDUMeshMultiLev(m,levs);
703 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDFileUMesh *m, const std::vector<int>& levs):MEDMeshMultiLev(m)
706 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : null input pointer !");
707 std::vector<MEDCoupling1GTUMesh *> v;
708 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
710 std::vector<MEDCoupling1GTUMesh *> vTmp(m->getDirectUndergroundSingleGeoTypeMeshes(*it));
711 v.insert(v.end(),vTmp.begin(),vTmp.end());
713 std::size_t sz(v.size());
716 _coords=m->getCoords(); _coords->incrRef();
720 _geo_types.resize(sz);
721 _nb_entities.resize(sz);
722 for(std::size_t i=0;i<sz;i++)
724 MEDCoupling1GTUMesh *obj(v[i]);
728 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev constructor : presence of a null pointer !");
730 _geo_types[i]=obj->getCellModelEnum();
731 _nb_entities[i]=obj->getNumberOfCells();
733 // ids fields management
734 bool cellFamIdsNoCpy(levs.size()==1);
737 const DataArrayIdType *tmp(m->getFamilyFieldAtLevel(levs[0]));
741 _cell_fam_ids=(const_cast<DataArrayIdType *>(tmp));
746 std::vector<const DataArrayIdType *> tmps(levs.size());
748 for(std::size_t i=0;i<levs.size();i++)
750 tmps[i]=m->getFamilyFieldAtLevel(levs[i]);
754 if(f && !tmps.empty())
755 _cell_fam_ids=DataArrayIdType::Aggregate(tmps);
757 bool cellNumIdsNoCpy(levs.size()==1);
760 const DataArrayIdType *tmp(m->getNumberFieldAtLevel(levs[0]));
764 _cell_num_ids=(const_cast<DataArrayIdType *>(tmp));
769 std::vector<const DataArrayIdType *> tmps(levs.size());
771 for(std::size_t i=0;i<levs.size();i++)
773 tmps[i]=m->getNumberFieldAtLevel(levs[i]);
777 if(n && !tmps.empty())
778 _cell_num_ids=DataArrayIdType::Aggregate(tmps);
782 const DataArrayIdType *tmp(m->getFamilyFieldAtLevel(1));
786 _node_fam_ids=(const_cast<DataArrayIdType *>(tmp));
790 const DataArrayIdType *tmp(m->getNumberFieldAtLevel(1));
794 _node_num_ids=(const_cast<DataArrayIdType *>(tmp));
799 MEDUMeshMultiLev *MEDUMeshMultiLev::New(const MEDFileUMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities)
801 return new MEDUMeshMultiLev(m,gts,pfls,nbEntities);
804 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)
806 std::size_t sz(gts.size());
808 throw INTERP_KERNEL::Exception("constructor of MEDUMeshMultiLev : number of different geo type must be >= 1 !");
809 unsigned dim(INTERP_KERNEL::CellModel::GetCellModel(gts[0]).getDimension());
811 bool isSameDim(true),isNoPfl(true);
812 for(std::size_t i=0;i<sz;i++)
814 MEDCoupling1GTUMesh *elt(m->getDirectUndergroundSingleGeoTypeMesh(gts[i]));
815 if(INTERP_KERNEL::CellModel::GetCellModel(gts[i]).getDimension()!=dim)
823 // ids fields management
824 int lev((int)dim-m->getMeshDimension());
825 if(isSameDim && isNoPfl && m->getGeoTypesAtLevel(lev)==gts)//optimized part
827 const DataArrayIdType *famIds(m->getFamilyFieldAtLevel(lev));
829 { _cell_fam_ids=const_cast<DataArrayIdType*>(famIds); famIds->incrRef(); }
830 const DataArrayIdType *numIds(m->getNumberFieldAtLevel(lev));
832 { _cell_num_ids=const_cast<DataArrayIdType*>(numIds); numIds->incrRef(); }
833 famIds=m->getFamilyFieldAtLevel(1);
835 { _node_fam_ids=const_cast<DataArrayIdType*>(famIds); famIds->incrRef(); }
836 numIds=m->getNumberFieldAtLevel(1);
838 { _node_num_ids=const_cast<DataArrayIdType*>(numIds); numIds->incrRef(); }
842 std::vector< MCAuto<DataArrayIdType> > famIdsSafe(sz);
843 std::vector<const DataArrayIdType *> famIds(sz);
845 for(std::size_t i=0;i<sz;i++)
847 famIdsSafe[i]=m->extractFamilyFieldOnGeoType(gts[i]);
848 famIds[i]=famIdsSafe[i];
853 _cell_fam_ids=DataArrayIdType::Aggregate(famIds);
854 std::vector< MCAuto<DataArrayIdType> > numIdsSafe(sz);
855 std::vector<const DataArrayIdType *> numIds(sz);
857 for(std::size_t i=0;i<sz;i++)
859 numIdsSafe[i]=m->extractNumberFieldOnGeoType(gts[i]);
860 numIds[i]=numIdsSafe[i];
865 _cell_num_ids=DataArrayIdType::Aggregate(numIds);
866 // node ids management
867 const DataArrayIdType *nodeFamIds(m->getFamilyFieldAtLevel(1));
869 { _node_fam_ids=const_cast<DataArrayIdType*>(nodeFamIds); nodeFamIds->incrRef(); }
870 const DataArrayIdType *nodeNumIds(m->getNumberFieldAtLevel(1));
872 { _node_num_ids=const_cast<DataArrayIdType*>(nodeNumIds); nodeNumIds->incrRef(); }
875 void MEDUMeshMultiLev::selectPartOfNodes(const DataArrayIdType *pflNodes)
877 if(!pflNodes || !pflNodes->isAllocated())
879 std::size_t sz(_parts.size());
880 std::vector< MCAuto<DataArrayIdType> > a(sz);
881 std::vector< const DataArrayIdType *> aa(sz);
882 for(std::size_t i=0;i<sz;i++)
884 const DataArrayIdType *pfl(_pfls[i]);
885 MCAuto<MEDCoupling1GTUMesh> m(_parts[i]);
887 m=dynamic_cast<MEDCoupling1GTUMesh *>(_parts[i]->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
888 DataArrayIdType *cellIds=0;
889 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
890 MCAuto<DataArrayIdType> cellIdsSafe(cellIds);
891 MCAuto<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
893 MCAuto<DataArrayIdType> o2n(m2->getNodeIdsInUse(tmp));
894 a[i]=o2n->invertArrayO2N2N2O(tmp); aa[i]=a[i];
896 _pfls[i]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
898 _pfls[i]=cellIdsSafe;
901 _node_reduction=DataArrayIdType::Aggregate(aa);//general case
903 _node_reduction=pflNodes->deepCopy();//case where no cells in read mesh.
904 _node_reduction->sort(true);
905 _node_reduction=_node_reduction->buildUnique();
906 if(_node_reduction->getNumberOfTuples()==pflNodes->getNumberOfTuples())
907 return ;//This is the classical case where the input node profile corresponds perfectly to a subset of cells in _parts
908 if(_node_reduction->getNumberOfTuples()>pflNodes->getNumberOfTuples())
909 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::selectPartOfNodes : internal error in MEDCoupling during cell select from a list of nodes !");
910 // Here the cells available in _parts is not enough to cover all the nodes in pflNodes. So adding vertices cells in _parts...
911 MCAuto<DataArrayIdType> pflNodes2(pflNodes->deepCopy());
912 pflNodes2->sort(true);
913 MCAuto<DataArrayIdType> diff(pflNodes2->buildSubstractionOptimized(_node_reduction));
914 appendVertices(diff,pflNodes2);
917 MEDMeshMultiLev *MEDUMeshMultiLev::prepare() const
919 return new MEDUMeshMultiLev(*this);
922 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDUMeshMultiLev& other):MEDMeshMultiLev(other),_parts(other._parts),_coords(other._coords)
926 MEDUMeshMultiLev::MEDUMeshMultiLev(const MEDStructuredMeshMultiLev& other, const MCAuto<MEDCoupling1GTUMesh>& part):MEDMeshMultiLev(other)
930 _geo_types.resize(1); _geo_types[0]=part->getCellModelEnum();
931 _nb_entities.resize(1); _nb_entities[0]=part->getNumberOfCells();
932 _pfls.resize(1); _pfls[0]=0;
936 * To be called only once ! Because due to some optimizations (sometimes aggressive) the internal state can be changed...
937 * 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.
938 * 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.
940 bool MEDUMeshMultiLev::buildVTUArrays(DataArrayDouble *& coords, DataArrayByte *&types, DataArrayIdType *&cellLocations, DataArrayIdType *& cells, DataArrayIdType *&faceLocations, DataArrayIdType *&faces) const
942 const DataArrayDouble *tmp(0);
946 tmp=_parts[0]->getCoords();
948 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : the coordinates are null !");
949 MCAuto<DataArrayDouble> a(const_cast<DataArrayDouble *>(tmp)); tmp->incrRef();
950 mcIdType szBCE(0),szD(0),szF(0);
953 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
955 const MEDCoupling1GTUMesh *cur(*it);
957 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : a part is null !");
959 const DataArrayIdType *pfl(_pfls[iii]);
960 MCAuto<MEDCoupling1GTUMesh> cur2;
962 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
964 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
966 mcIdType curNbCells(cur->getNumberOfCells());
968 if((*it)->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
969 szD+=cur->getNodalConnectivity()->getNumberOfTuples()+curNbCells;
973 MCAuto<DataArrayIdType> tmp2(cur->computeEffectiveNbOfNodesPerCell());
974 szD+=tmp2->accumulate((std::size_t)0)+curNbCells;
975 szF+=2*curNbCells+cur->getNodalConnectivity()->getNumberOfTuples();
978 MCAuto<DataArrayByte> b(DataArrayByte::New()); b->alloc(szBCE,1); char *bPtr(b->getPointer());
979 MCAuto<DataArrayIdType> c(DataArrayIdType::New()); c->alloc(szBCE,1); mcIdType *cPtr(c->getPointer());
980 MCAuto<DataArrayIdType> d(DataArrayIdType::New()); d->alloc(szD,1); mcIdType *dPtr(d->getPointer());
981 MCAuto<DataArrayIdType> e(DataArrayIdType::New()),f(DataArrayIdType::New()); mcIdType *ePtr(0),*fPtr(0);
983 { e->alloc(szBCE,1); ePtr=e->getPointer(); f->alloc(szF,1); fPtr=f->getPointer(); }
986 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_parts.begin();it!=_parts.end();it++,iii++)
988 const MEDCoupling1GTUMesh *cur(*it);
990 const DataArrayIdType *pfl(_pfls[iii]);
991 MCAuto<MEDCoupling1GTUMesh> cur2;
993 { cur2=const_cast<MEDCoupling1GTUMesh *>(cur); cur2->incrRef(); }
995 { cur2=dynamic_cast<MEDCoupling1GTUMesh *>(cur->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end())); cur=cur2; }
997 mcIdType curNbCells(cur->getNumberOfCells());
998 int gt((int)cur->getCellModelEnum());
999 if(gt<0 || gt>=PARAMEDMEM_2_VTKTYPE_LGTH)
1000 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : invalid geometric type !");
1001 unsigned char gtvtk(PARAMEDMEM_2_VTKTYPE[gt]);
1003 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : no VTK type for the requested INTERP_KERNEL geometric type !");
1004 std::fill(bPtr,bPtr+curNbCells,gtvtk); bPtr+=curNbCells;
1005 const MEDCoupling1SGTUMesh *scur(dynamic_cast<const MEDCoupling1SGTUMesh *>(cur));
1006 const MEDCoupling1DGTUMesh *dcur(dynamic_cast<const MEDCoupling1DGTUMesh *>(cur));
1007 const mcIdType *connPtr(cur->getNodalConnectivity()->begin());
1009 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::getVTUArrays : internal error !");
1012 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_HEXA27)
1014 mcIdType nnpc(scur->getNumberOfNodesPerCell());
1015 for(mcIdType i=0;i<curNbCells;i++,connPtr+=nnpc)
1018 dPtr=std::copy(connPtr,connPtr+nnpc,dPtr);
1019 *cPtr++=k; k+=nnpc+1;
1024 for(mcIdType i=0;i<curNbCells;i++,connPtr+=27)
1027 for(int j=0;j<27;j++,dPtr++)
1028 *dPtr=connPtr[HEXA27_PERM_ARRAY[j]];
1033 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1037 const mcIdType *connIPtr(dcur->getNodalConnectivityIndex()->begin());
1038 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1040 for(int i=0;i<curNbCells;i++,connIPtr++)
1042 *dPtr++=connIPtr[1]-connIPtr[0];
1043 dPtr=std::copy(connPtr+connIPtr[0],connPtr+connIPtr[1],dPtr);
1044 *cPtr++=k; k+=connIPtr[1]-connIPtr[0]+1;
1049 for(mcIdType i=0;i<curNbCells;i++,connIPtr++)
1051 std::set<mcIdType> s(connPtr+connIPtr[0],connPtr+connIPtr[1]); s.erase(-1);
1052 *dPtr++=(mcIdType)s.size();
1053 dPtr=std::copy(s.begin(),s.end(),dPtr);
1054 *cPtr++=k; k+=(mcIdType)s.size()+1;
1059 connIPtr=dcur->getNodalConnectivityIndex()->begin();
1060 if(cur->getCellModelEnum()!=INTERP_KERNEL::NORM_POLYHED)
1061 { std::fill(ePtr,ePtr+curNbCells,-1); ePtr+=curNbCells; }
1065 for(int i=0;i<curNbCells;i++,connIPtr++)
1067 mcIdType nbFace(ToIdType(std::count(connPtr+connIPtr[0],connPtr+connIPtr[1],-1)+1));
1069 const mcIdType *work(connPtr+connIPtr[0]);
1070 for(int j=0;j<nbFace;j++)
1072 const mcIdType *work2=std::find(work,connPtr+connIPtr[1],-1);
1073 *fPtr++=ToIdType(std::distance(work,work2));
1074 fPtr=std::copy(work,work2,fPtr);
1077 *ePtr++=kk; kk+=connIPtr[1]-connIPtr[0]+2;
1084 reorderNodesIfNecessary(a,d,0);
1086 reorderNodesIfNecessary(a,d,f);
1087 if(a->getNumberOfComponents()!=3)
1088 a=a->changeNbOfComponents(3,0.);
1089 coords=a.retn(); types=b.retn(); cellLocations=c.retn(); cells=d.retn();
1091 { faceLocations=0; faces=0; }
1093 { faceLocations=e.retn(); faces=f.retn(); }
1094 return _mesh->isObjectInTheProgeny(coords);
1097 void MEDUMeshMultiLev::reorderNodesIfNecessary(MCAuto<DataArrayDouble>& coords, DataArrayIdType *nodalConnVTK, DataArrayIdType *polyhedNodalConnVTK) const
1099 const DataArrayIdType *nr(_node_reduction);
1102 if(nodalConnVTK->empty() && !polyhedNodalConnVTK)
1104 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1107 mcIdType sz(coords->getNumberOfTuples());
1108 std::vector<bool> b(sz,false);
1109 const mcIdType *work(nodalConnVTK->begin()),*endW(nodalConnVTK->end());
1112 mcIdType nb(*work++);
1113 for(mcIdType i=0;i<nb && work!=endW;i++,work++)
1115 if(*work>=0 && *work<sz)
1118 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error !");
1121 if(polyhedNodalConnVTK)
1123 work=polyhedNodalConnVTK->begin(); endW=polyhedNodalConnVTK->end();
1126 mcIdType nb(*work++);
1127 for(mcIdType i=0;i<nb && work!=endW;i++)
1129 mcIdType nb2(*work++);
1130 for(mcIdType j=0;j<nb2 && work!=endW;j++,work++)
1132 if(*work>=0 && *work<sz)
1135 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #2 !");
1140 std::size_t szExp(std::count(b.begin(),b.end(),true));
1141 if(ToIdType(szExp)!=nr->getNumberOfTuples())
1142 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::reorderNodesIfNecessary : internal error #3 !");
1144 MCAuto<DataArrayIdType> o2n(DataArrayIdType::New()); o2n->alloc(sz,1);
1145 mcIdType *o2nPtr(o2n->getPointer());
1147 for(int i=0;i<sz;i++,o2nPtr++)
1148 if(b[i]) *o2nPtr=newId++; else *o2nPtr=-1;
1149 const mcIdType *o2nPtrc(o2n->begin());
1150 MCAuto<DataArrayIdType> n2o(o2n->invertArrayO2N2N2O(nr->getNumberOfTuples()));
1151 MCAuto<DataArrayIdType> perm(DataArrayIdType::FindPermutationFromFirstToSecond(n2o,nr));
1152 const mcIdType *permPtr(perm->begin());
1153 mcIdType *work2(nodalConnVTK->getPointer()),*endW2(nodalConnVTK->getPointer()+nodalConnVTK->getNumberOfTuples());
1156 mcIdType nb(*work2++);
1157 for(mcIdType i=0;i<nb && work2!=endW2;i++,work2++)
1158 *work2=permPtr[o2nPtrc[*work2]];
1160 if(polyhedNodalConnVTK)
1162 work2=polyhedNodalConnVTK->getPointer(); endW2=polyhedNodalConnVTK->getPointer()+polyhedNodalConnVTK->getNumberOfTuples();
1165 mcIdType nb(*work2++);
1166 for(mcIdType i=0;i<nb && work2!=endW2;i++)
1168 mcIdType nb2(*work2++);
1169 for(mcIdType j=0;j<nb2 && work2!=endW2;j++,work2++)
1170 *work2=permPtr[o2nPtrc[*work2]];
1174 coords=(coords->selectByTupleIdSafe(nr->begin(),nr->end()));
1178 void MEDUMeshMultiLev::appendVertices(const DataArrayIdType *verticesToAdd, DataArrayIdType *nr)
1180 mcIdType nbOfCells(verticesToAdd->getNumberOfTuples());//it is not a bug cells are NORM_POINT1
1181 MEDMeshMultiLev::appendVertices(verticesToAdd,nr);
1182 MCAuto<MEDCoupling1SGTUMesh> elt(MEDCoupling1SGTUMesh::New("",INTERP_KERNEL::NORM_POINT1));
1183 elt->allocateCells(nbOfCells);
1184 for(mcIdType i=0;i<nbOfCells;i++)
1186 mcIdType pt(verticesToAdd->getIJ(i,0));
1187 elt->insertNextCell(&pt,&pt+1);
1190 throw INTERP_KERNEL::Exception("MEDUMeshMultiLev::appendVertices : parts are empty !");
1191 elt->setCoords(_parts[0]->getCoords());
1192 MCAuto<MEDCoupling1GTUMesh> elt2((MEDCoupling1SGTUMesh *)elt); elt2->incrRef();
1193 _parts.push_back(elt2);
1198 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDFileStructuredMesh *m, const std::vector<int>& lev):MEDMeshMultiLev(m),_is_internal(true)
1200 initStdFieldOfIntegers(m);
1203 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)
1205 initStdFieldOfIntegers(m);
1208 MEDStructuredMeshMultiLev::MEDStructuredMeshMultiLev(const MEDStructuredMeshMultiLev& other):MEDMeshMultiLev(other),_is_internal(true),_face_fam_ids(other._face_fam_ids),_face_num_ids(other._face_num_ids)
1212 void MEDStructuredMeshMultiLev::initStdFieldOfIntegers(const MEDFileStructuredMesh *m)
1214 // ids fields management
1215 const DataArrayIdType *tmp(0);
1216 tmp=m->getFamilyFieldAtLevel(0);
1220 _cell_fam_ids=const_cast<DataArrayIdType *>(tmp);
1222 tmp=m->getNumberFieldAtLevel(0);
1226 _cell_num_ids=const_cast<DataArrayIdType *>(tmp);
1230 tmp=m->getFamilyFieldAtLevel(1);
1234 _node_fam_ids=const_cast<DataArrayIdType *>(tmp);
1236 tmp=m->getNumberFieldAtLevel(1);
1240 _node_num_ids=const_cast<DataArrayIdType *>(tmp);
1243 tmp=m->getFamilyFieldAtLevel(-1);
1247 _face_fam_ids=const_cast<DataArrayIdType *>(tmp);
1249 tmp=m->getNumberFieldAtLevel(-1);
1253 _face_num_ids=const_cast<DataArrayIdType *>(tmp);
1257 void MEDStructuredMeshMultiLev::moveFaceToCell() const
1259 const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_fam_ids=_face_fam_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_fam_ids=0;
1260 const_cast<MEDStructuredMeshMultiLev *>(this)->_cell_num_ids=_face_num_ids; const_cast<MEDStructuredMeshMultiLev *>(this)->_face_num_ids=0;
1263 bool MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase(MEDMeshMultiLev *&ret) const
1266 if(_geo_types.empty())
1268 if(_geo_types.size()!=1)
1269 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase only one geo types supported at most supported for the moment !");
1270 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(_mesh->getMeshDimension()));
1271 if(_geo_types[0]==gt)
1273 MEDCoupling1GTUMesh *facesIfPresent((static_cast<const MEDFileStructuredMesh *>(_mesh))->getImplicitFaceMesh());
1276 const DataArrayIdType *pfl(0),*nr(_node_reduction);
1279 MCAuto<MEDCoupling1GTUMesh> facesIfPresent2(facesIfPresent); facesIfPresent->incrRef();
1281 MCAuto<MEDUMeshMultiLev> ret2(new MEDUMeshMultiLev(*this,facesIfPresent2));
1283 ret2->setCellReduction(pfl);
1285 throw INTERP_KERNEL::Exception("MEDStructuredMeshMultiLev::prepareForImplicitUnstructuredMeshCase : case is not treated yet for node reduction on implicit unstructured mesh.");
1290 void MEDStructuredMeshMultiLev::dealWithImplicitUnstructuredMesh(const MEDFileMesh *m)
1292 const DataArrayIdType *tmp(0);
1293 tmp=m->getFamilyFieldAtLevel(-1);
1297 _cell_fam_ids=const_cast<DataArrayIdType *>(tmp);
1299 tmp=m->getNumberFieldAtLevel(-1);
1303 _cell_num_ids=const_cast<DataArrayIdType *>(tmp);
1307 void MEDStructuredMeshMultiLev::selectPartOfNodes(const DataArrayIdType *pflNodes)
1309 if(!pflNodes || !pflNodes->isAllocated())
1311 std::vector<mcIdType> ngs(getNodeGridStructure());
1312 MCAuto<DataArrayIdType> conn(MEDCouplingStructuredMesh::Build1GTNodalConnectivity(&ngs[0],&ngs[0]+ngs.size()));
1313 MCAuto<MEDCoupling1SGTUMesh> m(MEDCoupling1SGTUMesh::New("",MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension((int)ngs.size())));
1314 m->setNodalConnectivity(conn);
1315 const DataArrayIdType *pfl(_pfls[0]);
1318 m=dynamic_cast<MEDCoupling1SGTUMesh *>(m->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1320 DataArrayIdType *cellIds=0;
1321 m->fillCellIdsToKeepFromNodeIds(pflNodes->begin(),pflNodes->end(),true,cellIds);
1322 MCAuto<DataArrayIdType> cellIdsSafe(cellIds);
1323 MCAuto<MEDCouplingPointSet> m2(m->buildPartOfMySelfKeepCoords(cellIds->begin(),cellIds->end()));
1325 _node_reduction=m2->getNodeIdsInUse(tmp);
1327 _pfls[0]=pfl->selectByTupleIdSafe(cellIds->begin(),cellIds->end());
1329 _pfls[0]=cellIdsSafe;
1334 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<int>& levs)
1336 return new MEDCMeshMultiLev(m,levs);
1339 MEDCMeshMultiLev *MEDCMeshMultiLev::New(const MEDFileCMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities)
1341 return new MEDCMeshMultiLev(m,gts,pfls,nbEntities);
1344 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1347 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !");
1348 if(levs.size()!=1 || levs[0]!=0)
1349 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !");
1350 int sdim(m->getSpaceDimension());
1351 _coords.resize(sdim);
1352 for(int i=0;i<sdim;i++)
1354 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1356 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1362 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)
1365 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : null input pointer !");
1366 if(gts.size()!=1 || pfls.size()!=1)
1367 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : lengths of gts and pfls must be equal to one !");
1368 int mdim(m->getMeshDimension());
1369 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim));
1372 _coords.resize(mdim);
1373 for(int i=0;i<mdim;i++)
1375 DataArrayDouble *elt(const_cast<DataArrayDouble *>(m->getMesh()->getCoordsAt(i)));
1377 throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !");
1378 _coords[i]=elt; _coords[i]->incrRef();
1382 dealWithImplicitUnstructuredMesh(m);
1385 MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDCMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords)
1389 std::vector<mcIdType> MEDCMeshMultiLev::getNodeGridStructure() const
1391 std::vector<mcIdType> ret(_coords.size());
1392 for(std::size_t i=0;i<_coords.size();i++)
1393 ret[i]=_coords[i]->getNumberOfTuples();
1397 MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const
1399 MEDMeshMultiLev *retSpecific(0);
1400 if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1402 const DataArrayIdType *pfl(0),*nr(_node_reduction);
1405 MCAuto<DataArrayIdType> nnr;
1406 std::vector<mcIdType> cgs,ngs(getNodeGridStructure());
1407 cgs.resize(ngs.size());
1408 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind(std::plus<mcIdType>(),std::placeholders::_1,-1));
1411 std::vector< std::pair<mcIdType,mcIdType> > cellParts;
1412 MCAuto<MEDMeshMultiLev> ret2;
1413 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1415 MCAuto<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1416 ret->_is_internal=false;
1418 { nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1419 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1421 std::vector< MCAuto<DataArrayDouble> > coords(_coords.size());
1422 for(std::size_t i=0;i<_coords.size();i++)
1423 coords[i]=_coords[i]->selectByTupleIdSafeSlice(cellParts[i].first,cellParts[i].second+1,1);
1424 ret->_coords=coords;
1425 ret2=(MEDCMeshMultiLev *)ret; ret2->incrRef();
1429 MCAuto<MEDCouplingCMesh> m(MEDCouplingCMesh::New());
1430 for(unsigned int i=0;i<ngs.size();i++)
1431 m->setCoordsAt(i,_coords[i]);
1432 MCAuto<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1433 MCAuto<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1434 MCAuto<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1436 { m3->zipCoords(); nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1437 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1439 const DataArrayIdType *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1442 MCAuto<DataArrayIdType> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1443 ret2->setFamilyIdsOnCells(tmp);
1447 MCAuto<DataArrayIdType> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1448 ret2->setNumberIdsOnCells(tmp);
1455 MCAuto<MEDCMeshMultiLev> ret(new MEDCMeshMultiLev(*this));
1457 { nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1463 * \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.
1465 std::vector< DataArrayDouble * > MEDCMeshMultiLev::buildVTUArrays(bool& isInternal) const
1467 isInternal=_is_internal;
1468 std::size_t sz(_coords.size());
1469 std::vector< DataArrayDouble * > ret(sz);
1470 for(std::size_t i=0;i<sz;i++)
1472 ret[i]=const_cast<DataArrayDouble *>((const DataArrayDouble *)_coords[i]);
1480 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs)
1482 return new MEDCurveLinearMeshMultiLev(m,levs);
1485 MEDCurveLinearMeshMultiLev *MEDCurveLinearMeshMultiLev::New(const MEDFileCurveLinearMesh *m, const std::vector<INTERP_KERNEL::NormalizedCellType>& gts, const std::vector<const DataArrayIdType *>& pfls, const std::vector<mcIdType>& nbEntities)
1487 return new MEDCurveLinearMeshMultiLev(m,gts,pfls,nbEntities);
1490 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDFileCurveLinearMesh *m, const std::vector<int>& levs):MEDStructuredMeshMultiLev(m,levs)
1493 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : null input pointer !");
1494 if(levs.size()!=1 || levs[0]!=0)
1495 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor : levels supported is 0 only !");
1496 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1498 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1501 _structure=m->getMesh()->getNodeGridStructure();
1504 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)
1507 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : null input pointer !");
1508 if(gts.size()!=1 || pfls.size()!=1)
1509 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : lengths of gts and pfls must be equal to one !");
1510 INTERP_KERNEL::NormalizedCellType gt(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension()));
1513 DataArrayDouble *coords(const_cast<DataArrayDouble *>(m->getMesh()->getCoords()));
1515 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev constructor 2 : no coords set !");
1518 _structure=m->getMesh()->getNodeGridStructure();
1521 dealWithImplicitUnstructuredMesh(m);
1524 MEDCurveLinearMeshMultiLev::MEDCurveLinearMeshMultiLev(const MEDCurveLinearMeshMultiLev& other):MEDStructuredMeshMultiLev(other),_coords(other._coords),_structure(other._structure)
1528 std::vector<mcIdType> MEDCurveLinearMeshMultiLev::getNodeGridStructure() const
1533 MEDMeshMultiLev *MEDCurveLinearMeshMultiLev::prepare() const
1535 MEDMeshMultiLev *retSpecific(0);
1536 if(prepareForImplicitUnstructuredMeshCase(retSpecific))
1538 const DataArrayIdType *pfl(0),*nr(_node_reduction);
1541 MCAuto<DataArrayIdType> nnr;
1542 std::vector<mcIdType> cgs,ngs(getNodeGridStructure());
1543 cgs.resize(ngs.size());
1544 std::transform(ngs.begin(),ngs.end(),cgs.begin(),std::bind(std::plus<mcIdType>(),std::placeholders::_1,-1));
1547 std::vector< std::pair<mcIdType,mcIdType> > cellParts,nodeParts;
1548 MCAuto<MEDMeshMultiLev> ret2;
1549 if(MEDCouplingStructuredMesh::IsPartStructured(pfl->begin(),pfl->end(),cgs,cellParts))
1551 nodeParts=cellParts;
1552 std::vector<mcIdType> st(ngs.size());
1553 for(std::size_t i=0;i<ngs.size();i++)
1555 nodeParts[i].second++;
1556 st[i]=nodeParts[i].second-nodeParts[i].first;
1558 MCAuto<DataArrayIdType> p(MEDCouplingStructuredMesh::BuildExplicitIdsFrom(ngs,nodeParts));
1559 MCAuto<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1560 ret->_is_internal=false;
1562 { nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1563 ret->_nb_entities[0]=pfl->getNumberOfTuples();
1565 ret->_coords=_coords->selectByTupleIdSafe(p->begin(),p->end());
1567 ret2=(MEDCurveLinearMeshMultiLev *)ret; ret2->incrRef();
1571 MCAuto<MEDCouplingCurveLinearMesh> m(MEDCouplingCurveLinearMesh::New());
1572 m->setCoords(_coords); m->setNodeGridStructure(&_structure[0],&_structure[0]+_structure.size());
1573 MCAuto<MEDCoupling1SGTUMesh> m2(m->build1SGTUnstructured());
1574 MCAuto<MEDCoupling1GTUMesh> m3=dynamic_cast<MEDCoupling1GTUMesh *>(m2->buildPartOfMySelfKeepCoords(pfl->begin(),pfl->end()));
1575 MCAuto<MEDUMeshMultiLev> ret(new MEDUMeshMultiLev(*this,m3));
1577 { m3->zipCoords(); nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1578 ret2=(MEDUMeshMultiLev *)ret; ret2->incrRef();
1580 const DataArrayIdType *famIds(_cell_fam_ids),*numIds(_cell_num_ids);
1583 MCAuto<DataArrayIdType> tmp(famIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1584 ret2->setFamilyIdsOnCells(tmp);
1588 MCAuto<DataArrayIdType> tmp(numIds->selectByTupleIdSafe(pfl->begin(),pfl->end()));
1589 ret2->setNumberIdsOnCells(tmp);
1595 MCAuto<MEDCurveLinearMeshMultiLev> ret(new MEDCurveLinearMeshMultiLev(*this));
1597 { nnr=nr->deepCopy(); nnr->sort(true); ret->setNodeReduction(nnr); }
1602 void MEDCurveLinearMeshMultiLev::buildVTUArrays(DataArrayDouble *&coords, std::vector<mcIdType>& nodeStrct, bool& isInternal) const
1604 isInternal=_is_internal;
1605 nodeStrct=_structure;
1606 const DataArrayDouble *coo(_coords);
1608 throw INTERP_KERNEL::Exception("MEDCurveLinearMeshMultiLev::buildVTUArrays : null pointer on coordinates !");
1609 coords=const_cast<DataArrayDouble *>(coo); coords->incrRef();
1614 MEDFileField1TSStructItem2::MEDFileField1TSStructItem2()
1618 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)
1620 _pfl->setName(c.c_str());
1623 void MEDFileField1TSStructItem2::checkWithMeshStructForCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1625 if(!mst->doesManageGeoType(_geo_type))
1627 MEDFileMeshStruct *mstUnConstCasted(const_cast<MEDFileMeshStruct *>(mst));
1628 mstUnConstCasted->appendIfImplicitType(_geo_type);
1630 mcIdType nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1631 checkInRange(nbOfEnt,1,globs);
1634 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussNE(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1636 mcIdType nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1637 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type);
1638 checkInRange(nbOfEnt,(int)cm.getNumberOfNodes(),globs);
1641 void MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1644 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no globals specified !");
1646 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkWithMeshStructForGaussPT : no localization specified !");
1647 const MEDFileFieldLoc& loc=globs->getLocalization(_loc.c_str());
1648 mcIdType nbOfEnt=mst->getNumberOfElemsOfGeoType(_geo_type);
1649 checkInRange(nbOfEnt,loc.getNumberOfGaussPoints(),globs);
1652 int MEDFileField1TSStructItem2::getNbOfIntegrationPts(const MEDFileFieldGlobsReal *globs) const
1656 if(getPflName().empty())
1657 return (int)((_start_end.second-_start_end.first)/_nb_of_entity);
1659 return (int)((_start_end.second-_start_end.first)/getPfl(globs)->getNumberOfTuples());
1663 const MEDFileFieldLoc& loc(globs->getLocalization(_loc.c_str()));
1664 return loc.getNumberOfGaussPoints();
1668 std::string MEDFileField1TSStructItem2::getPflName() const
1670 return _pfl->getName();
1673 const DataArrayIdType *MEDFileField1TSStructItem2::getPfl(const MEDFileFieldGlobsReal *globs) const
1675 if(!_pfl->isAllocated())
1677 if(_pfl->getName().empty())
1680 return globs->getProfile(_pfl->getName().c_str());
1687 * \param [in] nbOfEntity - number of entity that can be either cells or nodes. Not other possibility.
1688 * \param [in] nip - number of integration points. 1 for ON_CELLS and NO_NODES
1690 void MEDFileField1TSStructItem2::checkInRange(mcIdType nbOfEntity, int nip, const MEDFileFieldGlobsReal *globs)
1692 _nb_of_entity=nbOfEntity;
1693 if(_pfl->getName().empty())
1695 if(nbOfEntity!=(_start_end.second-_start_end.first)/nip)
1696 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Mismatch between number of entities and size of field !");
1702 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no globals found in file !");
1703 const DataArrayIdType *pfl=globs->getProfile(_pfl->getName().c_str());
1705 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::checkInRange : Presence of a profile on field whereas no such profile found in file !");
1706 pfl->checkAllIdsInRange(0,nbOfEntity);
1710 bool MEDFileField1TSStructItem2::isFastlyEqual(mcIdType& startExp, INTERP_KERNEL::NormalizedCellType gt, const std::string& pflName) const
1712 if(startExp!=_start_end.first)
1716 if(getPflName()!=pflName)
1718 startExp=_start_end.second;
1722 bool MEDFileField1TSStructItem2::operator==(const MEDFileField1TSStructItem2& other) const
1724 //_nb_of_entity is not taken into account here. It is not a bug, because no mesh consideration needed here to perform fast compare.
1725 //idem for _loc. It is not an effective attribute for support comparison.
1726 return _geo_type==other._geo_type && _start_end==other._start_end && _pfl->getName()==other._pfl->getName();
1729 bool MEDFileField1TSStructItem2::isCellSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1731 if(_geo_type!=other._geo_type)
1733 if(_nb_of_entity!=other._nb_of_entity)
1735 if((_pfl->getName().empty() && !other._pfl->getName().empty()) || (!_pfl->getName().empty() && other._pfl->getName().empty()))
1737 if(_pfl->getName().empty() && other._pfl->getName().empty())
1739 const DataArrayIdType *pfl1(getPfl(globs)),*pfl2(other.getPfl(globs));
1740 return pfl1->isEqualWithoutConsideringStr(*pfl2);
1743 bool MEDFileField1TSStructItem2::isNodeSupportEqual(const MEDFileField1TSStructItem2& other, const MEDFileFieldGlobsReal *globs) const
1745 return isCellSupportEqual(other,globs);
1749 * \a objs must be non empty. \a objs should contain items having same geometric type.
1751 MEDFileField1TSStructItem2 MEDFileField1TSStructItem2::BuildAggregationOf(const std::vector<const MEDFileField1TSStructItem2 *>& objs, const MEDFileFieldGlobsReal *globs)
1754 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : empty input !");
1756 return MEDFileField1TSStructItem2(*objs[0]);
1757 INTERP_KERNEL::NormalizedCellType gt(objs[0]->_geo_type);
1758 mcIdType nbEntityRef(objs[0]->_nb_of_entity);
1759 std::size_t sz(objs.size());
1760 std::vector<const DataArrayIdType *> arrs(sz);
1761 for(std::size_t i=0;i<sz;i++)
1763 const MEDFileField1TSStructItem2 *obj(objs[i]);
1764 if(gt!=obj->_geo_type)
1765 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the same geo type !");
1766 if(nbEntityRef!=obj->_nb_of_entity)
1767 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! All input must have the global nb of entity !");
1768 if(obj->_pfl->getName().empty())
1769 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : invalid situation ! Several same geo type chunk must all lie on profiles !");
1770 arrs[i]=globs->getProfile(obj->_pfl->getName().c_str());
1772 MCAuto<DataArrayIdType> arr(DataArrayIdType::Aggregate(arrs));
1774 mcIdType oldNbTuples(arr->getNumberOfTuples());
1775 arr=arr->buildUnique();
1776 if(oldNbTuples!=arr->getNumberOfTuples())
1777 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem2::BuildAggregationOf : some entities are present several times !");
1778 if(arr->isIota(nbEntityRef))
1780 std::pair<mcIdType,mcIdType> p(0,nbEntityRef);
1782 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1783 ret._nb_of_entity=nbEntityRef;
1788 arr->setName(NEWLY_CREATED_PFL_NAME);
1789 std::pair<mcIdType,mcIdType> p(0,oldNbTuples);
1791 MEDFileField1TSStructItem2 ret(gt,p,a,b);
1792 ret._nb_of_entity=nbEntityRef;
1798 std::size_t MEDFileField1TSStructItem2::getHeapMemorySizeWithoutChildren() const
1800 std::size_t ret(_loc.capacity());
1804 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem2::getDirectChildrenWithNull() const
1806 std::vector<const BigMemoryObject *> ret;
1807 ret.push_back((const DataArrayIdType *)_pfl);
1813 MEDFileField1TSStructItem::MEDFileField1TSStructItem(TypeOfField a, const std::vector< MEDFileField1TSStructItem2 >& b):_computed(false),_type(a),_items(b)
1817 void MEDFileField1TSStructItem::checkWithMeshStruct(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
1823 mcIdType nbOfEnt=mst->getNumberOfNodes();
1824 if(_items.size()!=1)
1825 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : for nodes field only one subdivision supported !");
1826 _items[0].checkInRange(nbOfEnt,1,globs);
1831 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1832 (*it).checkWithMeshStructForCells(mst,globs);
1837 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1838 (*it).checkWithMeshStructForGaussNE(mst,globs);
1843 for(std::vector< MEDFileField1TSStructItem2 >::iterator it=_items.begin();it!=_items.end();it++)
1844 (*it).checkWithMeshStructForGaussPT(mst,globs);
1848 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::checkWithMeshStruct : not managed field type !");
1852 bool MEDFileField1TSStructItem::operator==(const MEDFileField1TSStructItem& other) const
1854 if(_type!=other._type)
1856 if(_items.size()!=other._items.size())
1858 for(std::size_t i=0;i<_items.size();i++)
1859 if(!(_items[i]==other._items[i]))
1864 bool MEDFileField1TSStructItem::isCellSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1866 if(_type!=other._type)
1868 if(_items.size()!=other._items.size())
1870 for(std::size_t i=0;i<_items.size();i++)
1871 if(!(_items[i].isCellSupportEqual(other._items[i],globs)))
1876 bool MEDFileField1TSStructItem::isNodeSupportEqual(const MEDFileField1TSStructItem& other, const MEDFileFieldGlobsReal *globs) const
1878 if(_type!=other._type)
1880 if(_items.size()!=other._items.size())
1882 for(std::size_t i=0;i<_items.size();i++)
1883 if(!(_items[i].isNodeSupportEqual(other._items[i],globs)))
1888 bool MEDFileField1TSStructItem::isEntityCell() const
1899 CmpGeo(INTERP_KERNEL::NormalizedCellType geoTyp):_geo_type(geoTyp) { }
1900 bool operator()(const std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > & v) const { return _geo_type==v.first; }
1902 INTERP_KERNEL::NormalizedCellType _geo_type;
1905 MEDFileField1TSStructItem MEDFileField1TSStructItem::simplifyMeOnCellEntity(const MEDFileFieldGlobsReal *globs) const
1908 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::simplifyMeOnCellEntity : must be on ON_CELLS, ON_GAUSS_NE or ON_GAUSS_PT !");
1909 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > > m;
1911 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
1913 std::vector< std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> > >::iterator it0(std::find_if(m.begin(),m.end(),CmpGeo((*it).getGeo())));
1915 m.push_back(std::pair< INTERP_KERNEL::NormalizedCellType, std::vector<std::size_t> >((*it).getGeo(),std::vector<std::size_t>(1,i)));
1917 (*it0).second.push_back(i);
1919 if(m.size()==_items.size())
1921 MEDFileField1TSStructItem ret(*this);
1925 std::size_t sz(m.size());
1926 std::vector< MEDFileField1TSStructItem2 > items(sz);
1929 const std::vector<std::size_t>& ids=m[i].second;
1930 std::vector<const MEDFileField1TSStructItem2 *>objs(ids.size());
1931 for(std::size_t j=0;j<ids.size();j++)
1932 objs[j]=&_items[ids[j]];
1933 items[i]=MEDFileField1TSStructItem2::BuildAggregationOf(objs,globs);
1935 MEDFileField1TSStructItem ret(ON_CELLS,items);
1941 * \a this is expected to be ON_CELLS and simplified.
1943 bool MEDFileField1TSStructItem::isCompatibleWithNodesDiscr(const MEDFileField1TSStructItem& other, const MEDFileMeshStruct *meshSt, const MEDFileFieldGlobsReal *globs) const
1945 if(other._type!=ON_NODES)
1946 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other must be on nodes !");
1947 if(other._items.size()!=1)
1948 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isCompatibleWithNodesDiscr : other is on nodes but number of subparts !");
1949 int theFirstLevFull;
1950 bool ret0=isFullyOnOneLev(meshSt,theFirstLevFull);
1951 const MEDFileField1TSStructItem2& otherNodeIt(other._items[0]);
1952 mcIdType nbOfNodes(meshSt->getNumberOfNodes());
1953 if(otherNodeIt.getPflName().empty())
1957 std::vector<bool> nodesFetched(nbOfNodes,false);
1958 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1959 if(std::find(nodesFetched.begin(),nodesFetched.end(),false)==nodesFetched.end())
1960 return theFirstLevFull==0;
1966 const DataArrayIdType *pfl=globs->getProfile(otherNodeIt.getPflName().c_str());
1967 MCAuto<DataArrayIdType> cpyPfl(pfl->deepCopy());
1969 if(cpyPfl->isIota(nbOfNodes))
1970 {//on all nodes also !
1973 return theFirstLevFull==0;
1975 std::vector<bool> nodesFetched(nbOfNodes,false);
1976 meshSt->getTheMesh()->whichAreNodesFetched(*this,globs,nodesFetched);
1977 return cpyPfl->isFittingWith(nodesFetched);
1981 bool MEDFileField1TSStructItem::isFullyOnOneLev(const MEDFileMeshStruct *meshSt, int& theFirstLevFull) const
1984 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : works only for ON_CELLS discretization !");
1986 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : items vector is empty !");
1987 int nbOfLevs(meshSt->getNumberOfLevs());
1989 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : no levels in input mesh structure !");
1990 std::vector<int> levs(nbOfLevs);
1992 std::set<INTERP_KERNEL::NormalizedCellType> gts;
1993 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
1995 if(!(*it).getPflName().empty())
1997 INTERP_KERNEL::NormalizedCellType gt((*it).getGeo());
1998 if(gts.find(gt)!=gts.end())
1999 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::isFullyOnOneLev : internal error !");
2001 int pos(meshSt->getLevelOfGeoType((*it).getGeo()));
2004 for(int i=0;i<nbOfLevs;i++)
2005 if(meshSt->getNumberOfGeoTypesInLev(-i)==levs[i])
2006 { theFirstLevFull=-i; return true; }
2010 const MEDFileField1TSStructItem2& MEDFileField1TSStructItem::operator[](std::size_t i) const
2012 if(i>=_items.size())
2013 throw INTERP_KERNEL::Exception("MEDFileField1TSStructItem::operator[] : input is not in valid range !");
2017 std::size_t MEDFileField1TSStructItem::getHeapMemorySizeWithoutChildren() const
2019 std::size_t ret(_items.size()*sizeof(MEDFileField1TSStructItem2));
2023 std::vector<const BigMemoryObject *> MEDFileField1TSStructItem::getDirectChildrenWithNull() const
2025 std::vector<const BigMemoryObject *> ret;
2026 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2027 ret.push_back(&(*it));
2031 MEDMeshMultiLev *MEDFileField1TSStructItem::buildFromScratchDataSetSupportOnCells(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2033 std::size_t sz(_items.size());
2034 std::vector<INTERP_KERNEL::NormalizedCellType> a0(sz);
2035 std::vector<const DataArrayIdType *> a1(sz);
2036 std::vector<mcIdType> a2(sz);
2038 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++,i++)
2040 a0[i]=(*it).getGeo();
2041 a1[i]=(*it).getPfl(globs);
2042 a2[i]=mst->getNumberOfElemsOfGeoType((*it).getGeo());
2044 return MEDMeshMultiLev::New(mst->getTheMesh(),a0,a1,a2);
2047 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStructItem::getGeoTypes(const MEDFileMesh *m) const
2049 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2052 if(!_items.empty() && _items[0].getPflName().empty())
2055 return m->getAllGeoTypes();
2062 for(std::vector< MEDFileField1TSStructItem2 >::const_iterator it=_items.begin();it!=_items.end();it++)
2064 INTERP_KERNEL::NormalizedCellType elt((*it).getGeo());
2065 std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it2(std::find(ret.begin(),ret.end(),elt));
2072 MEDFileField1TSStructItem MEDFileField1TSStructItem::BuildItemFrom(const MEDFileAnyTypeField1TS *ref, const MEDFileMeshStruct *meshSt)
2074 std::vector< MEDFileField1TSStructItem2 > anItems;
2076 std::vector< std::vector<std::string> > pfls,locs;
2077 std::vector< std::vector<TypeOfField> > typesF;
2078 std::vector<INTERP_KERNEL::NormalizedCellType> geoTypes;
2079 std::vector< std::vector<std::pair<mcIdType,mcIdType> > > strtEnds=ref->getFieldSplitedByType(std::string(),geoTypes,typesF,pfls,locs);
2080 std::size_t nbOfGeoTypes(geoTypes.size());
2082 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : not null by empty ref !");
2083 if(typesF[0].empty())
2084 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 bis !");
2085 TypeOfField atype(typesF[0][0]);
2086 for(std::size_t i=0;i<nbOfGeoTypes;i++)
2088 std::size_t sz=typesF[i].size();
2089 if(strtEnds[i].size()<1 || sz<1 || pfls[i].size()<1)
2090 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : internal error #1 !");
2092 for(std::size_t j=0;j<sz;j++)
2094 if(atype==typesF[i][j])
2095 anItems.push_back(MEDFileField1TSStructItem2(geoTypes[i],strtEnds[i][j],pfls[i][j],locs[i][j]));
2097 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct : can be applied only on single spatial discretization fields ! Call SplitPerDiscretization method !");
2100 MEDFileField1TSStructItem ret(atype,anItems);
2103 ret.checkWithMeshStruct(meshSt,ref);
2105 catch(INTERP_KERNEL::Exception& e)
2107 std::ostringstream oss; oss << e.what() << " (" << MEDCouplingFieldDiscretization::GetTypeOfFieldRepr(ret.getType()) << ")";
2108 throw INTERP_KERNEL::Exception(oss.str().c_str());
2115 MEDFileField1TSStruct *MEDFileField1TSStruct::New(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2117 return new MEDFileField1TSStruct(ref,mst);
2120 MEDFileField1TSStruct::MEDFileField1TSStruct(const MEDFileAnyTypeField1TS *ref, MEDFileMeshStruct *mst)
2122 _already_checked.push_back(MEDFileField1TSStructItem::BuildItemFrom(ref,mst));
2125 void MEDFileField1TSStruct::checkWithMeshStruct(MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs)
2127 if(_already_checked.empty())
2128 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::checkWithMeshStruct : not correctly initialized !");
2129 _already_checked.back().checkWithMeshStruct(mst,globs);
2132 bool MEDFileField1TSStruct::isEqualConsideringThePast(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *mst) const
2134 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,mst));
2135 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2144 * Not const because \a other structure will be added to the \c _already_checked attribute in case of success.
2146 bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2148 if(_already_checked.empty())
2149 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : no ref !");
2150 MEDFileField1TSStructItem b(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2151 if(!_already_checked[0].isEntityCell() || !b.isEntityCell())
2152 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isSupportSameAs : only available on cell entities !");
2153 MEDFileField1TSStructItem other1(b.simplifyMeOnCellEntity(other));
2155 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2156 if((*it).isComputed())
2161 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2162 ret=this1.isCellSupportEqual(other1,other);
2164 _already_checked.push_back(this1);
2167 ret=_already_checked[found].isCellSupportEqual(other1,other);
2169 _already_checked.push_back(b);
2174 * \param [in] other - a field with only one spatial discretization : ON_NODES.
2176 bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt)
2178 if(_already_checked.empty())
2179 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !");
2180 MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt));
2181 if(_already_checked[0].isEntityCell())
2184 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2185 if((*it).isComputed())
2190 MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other));
2191 ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other);
2193 _already_checked.push_back(this1);
2196 ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other);
2198 _already_checked.push_back(other1);
2202 return _already_checked[0].isNodeSupportEqual(other1,other);
2205 std::size_t MEDFileField1TSStruct::getHeapMemorySizeWithoutChildren() const
2207 std::size_t ret(_already_checked.capacity()*sizeof(MEDFileField1TSStructItem));
2211 std::vector<const BigMemoryObject *> MEDFileField1TSStruct::getDirectChildrenWithNull() const
2213 std::vector<const BigMemoryObject *> ret;
2214 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2215 ret.push_back(&(*it));
2219 MEDMeshMultiLev *MEDFileField1TSStruct::buildFromScratchDataSetSupport(const MEDFileMeshStruct *mst, const MEDFileFieldGlobsReal *globs) const
2221 if(_already_checked.empty())
2222 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::buildFromScratchDataSetSupport : No outline structure in this !");
2223 int pos0(-1),pos1(-1);
2224 if(presenceOfCellDiscr(pos0))
2226 MCAuto<MEDMeshMultiLev> ret(_already_checked[pos0].buildFromScratchDataSetSupportOnCells(mst,globs));
2227 if(presenceOfPartialNodeDiscr(pos1))
2228 ret->setNodeReduction(_already_checked[pos1][0].getPfl(globs));
2233 if(!presenceOfPartialNodeDiscr(pos1))
2234 {//we have only all nodes, no cell definition info -> all existing levels !;
2235 return MEDMeshMultiLev::New(mst->getTheMesh(),mst->getTheMesh()->getNonEmptyLevels());
2238 return MEDMeshMultiLev::NewOnlyOnNode(mst->getTheMesh(),_already_checked[pos1][0].getPfl(globs));
2242 bool MEDFileField1TSStruct::isDataSetSupportFastlyEqualTo(const MEDFileField1TSStruct& other, const MEDFileFieldGlobsReal *globs) const
2245 bool a0(presenceOfCellDiscr(b0)),a1(presenceOfPartialNodeDiscr(b1));
2247 bool c0(other.presenceOfCellDiscr(d0)),c1(other.presenceOfPartialNodeDiscr(d1));
2248 if(a0!=c0 || a1!=c1)
2251 if(!_already_checked[b0].isCellSupportEqual(other._already_checked[d0],globs))
2254 if(!_already_checked[b1].isNodeSupportEqual(other._already_checked[d1],globs))
2259 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileField1TSStruct::getGeoTypes(const MEDFileMesh *m) const
2261 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
2262 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++)
2264 std::vector<INTERP_KERNEL::NormalizedCellType> ret2((*it).getGeoTypes(m));
2265 for(std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator it2=ret2.begin();it2!=ret2.end();it2++)
2267 if(*it2==INTERP_KERNEL::NORM_ERROR)
2269 std::vector<INTERP_KERNEL::NormalizedCellType>::iterator it3(std::find(ret.begin(),ret.end(),*it2));
2271 ret.push_back(*it2);
2278 * Returns true if presence in \a this of discretization ON_CELLS, ON_GAUSS_PT, ON_GAUSS_NE.
2279 * 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.
2281 bool MEDFileField1TSStruct::presenceOfCellDiscr(int& pos) const
2283 std::size_t refSz(std::numeric_limits<std::size_t>::max());
2286 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2288 if((*it).getType()!=ON_NODES)
2291 std::size_t sz((*it).getNumberOfItems());
2293 { pos=i; refSz=sz; }
2297 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfCellDiscr : an element in this on entity CELL is empty !");
2302 * Returns true if presence in \a this of discretization ON_NODES.
2303 * If true is returned the pos of the first element containing the single subpart.
2305 bool MEDFileField1TSStruct::presenceOfPartialNodeDiscr(int& pos) const
2308 for(std::vector<MEDFileField1TSStructItem>::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++)
2310 if((*it).getType()==ON_NODES)
2312 std::size_t sz((*it).getNumberOfItems());
2315 if(!(*it)[0].getPflName().empty())
2316 { pos=i; return true; }
2319 throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::presenceOfPartialNodeDiscr : an element in this on entity NODE is split into several parts !");
2327 MEDFileFastCellSupportComparator *MEDFileFastCellSupportComparator::New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2329 return new MEDFileFastCellSupportComparator(m,ref);
2332 MEDFileFastCellSupportComparator::MEDFileFastCellSupportComparator(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref)
2335 throw INTERP_KERNEL::Exception("MEDFileFastCellSupportComparator constructor : null input mesh struct !");
2336 _mesh_comp=const_cast<MEDFileMeshStruct *>(m); _mesh_comp->incrRef();
2337 int nbPts=ref->getNumberOfTS();
2338 _f1ts_cmps.resize(nbPts);
2339 for(int i=0;i<nbPts;i++)
2341 MCAuto<MEDFileAnyTypeField1TS> elt=ref->getTimeStepAtPos(i);
2344 _f1ts_cmps[i]=MEDFileField1TSStruct::New(elt,_mesh_comp);
2345 _f1ts_cmps[i]->checkWithMeshStruct(_mesh_comp,elt);
2347 catch(INTERP_KERNEL::Exception& e)
2349 std::ostringstream oss; oss << "Problem in field with name \"" << ref->getName() << "\"" << std::endl;
2350 oss << "More Details : " << e.what();
2351 throw INTERP_KERNEL::Exception(oss.str().c_str());
2356 std::size_t MEDFileFastCellSupportComparator::getHeapMemorySizeWithoutChildren() const
2358 std::size_t ret(_f1ts_cmps.capacity()*sizeof(MCAuto<MEDFileField1TSStruct>));
2362 std::vector<const BigMemoryObject *> MEDFileFastCellSupportComparator::getDirectChildrenWithNull() const
2364 std::vector<const BigMemoryObject *> ret;
2365 const MEDFileMeshStruct *mst(_mesh_comp);
2368 for(std::vector< MCAuto<MEDFileField1TSStruct> >::const_iterator it=_f1ts_cmps.begin();it!=_f1ts_cmps.end();it++)
2369 ret.push_back((const MEDFileField1TSStruct *)*it);
2373 bool MEDFileFastCellSupportComparator::isEqual(const MEDFileAnyTypeFieldMultiTS *other)
2375 int nbPts=other->getNumberOfTS();
2376 if(nbPts!=(int)_f1ts_cmps.size())
2378 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isEqual : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2379 throw INTERP_KERNEL::Exception(oss.str().c_str());
2381 for(int i=0;i<nbPts;i++)
2383 MCAuto<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2384 if(!_f1ts_cmps[i]->isEqualConsideringThePast(elt,_mesh_comp))
2385 if(!_f1ts_cmps[i]->isSupportSameAs(elt,_mesh_comp))
2391 bool MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr(const MEDFileAnyTypeFieldMultiTS *other)
2393 int nbPts=other->getNumberOfTS();
2394 if(nbPts!=(int)_f1ts_cmps.size())
2396 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isCompatibleWithNodesDiscr : unexpected nb of time steps in input ! Should be " << _f1ts_cmps.size() << " it is in reality " << nbPts << " !";
2397 throw INTERP_KERNEL::Exception(oss.str().c_str());
2399 for(int i=0;i<nbPts;i++)
2401 MCAuto<MEDFileAnyTypeField1TS> elt=other->getTimeStepAtPos(i);
2402 if(!_f1ts_cmps[i]->isCompatibleWithNodesDiscr(elt,_mesh_comp))
2408 MEDMeshMultiLev *MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2410 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2412 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2413 throw INTERP_KERNEL::Exception(oss.str().c_str());
2415 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2418 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::buildFromScratchDataSetSupport : at time step id #" << timeStepId << " no field structure overview defined !";
2419 throw INTERP_KERNEL::Exception(oss.str().c_str());
2421 return obj->buildFromScratchDataSetSupport(_mesh_comp,globs);
2424 bool MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const
2426 if(timeStepId<=0 || timeStepId>=(int)_f1ts_cmps.size())
2428 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::isDataSetSupportEqualToThePreviousOne : requested time step id #" << timeStepId << " is not in [1," << _f1ts_cmps.size() << ") !";
2429 throw INTERP_KERNEL::Exception(oss.str().c_str());
2431 const MEDFileField1TSStruct *obj(_f1ts_cmps[timeStepId]);
2432 const MEDFileField1TSStruct *objRef(_f1ts_cmps[timeStepId-1]);
2433 return objRef->isDataSetSupportFastlyEqualTo(*obj,globs);
2436 int MEDFileFastCellSupportComparator::getNumberOfTS() const
2438 return (int)_f1ts_cmps.size();
2441 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileFastCellSupportComparator::getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const
2443 if(timeStepId<0 || timeStepId>=(int)_f1ts_cmps.size())
2445 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " is not in [0," << _f1ts_cmps.size() << ") !";
2446 throw INTERP_KERNEL::Exception(oss.str().c_str());
2448 const MEDFileField1TSStruct *elt(_f1ts_cmps[timeStepId]);
2451 std::ostringstream oss; oss << "MEDFileFastCellSupportComparator::getGeoTypesAt : requested time step id #" << timeStepId << " points to a NULL pointer !";
2452 throw INTERP_KERNEL::Exception(oss.str().c_str());
2454 return elt->getGeoTypes(m);