1 // Copyright (C) 2007-2023 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 "MEDFileMeshLL.hxx"
22 #include "MEDFileMesh.hxx"
23 #include "MEDLoaderBase.hxx"
24 #include "MEDFileSafeCaller.txx"
25 #include "MEDFileMeshReadSelector.hxx"
26 #include "MEDFileStructureElement.hxx"
27 #include "MEDFileMeshSupport.hxx"
29 #include "MEDCouplingUMesh.hxx"
31 #include "InterpKernelAutoPtr.hxx"
32 #include "CellModel.hxx"
34 #include "MEDFilterEntity.hxx"
38 // From MEDLOader.cxx TU
39 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
40 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
41 extern med_geometry_type typmainoeud[1];
43 using namespace MEDCoupling;
45 const char MEDFileMeshL2::ZE_SEP_FOR_FAMILY_KILLERS[]="!/__\\!";//important start by - because ord('!')==33 the smallest (!=' ') to preserve orders at most.
47 int MEDFileMeshL2::ZE_SEP2_FOR_FAMILY_KILLERS=4;
49 std::vector<std::string> MeshCls::getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const
51 med_mesh_type type_maillage;
52 med_int spaceDim, meshDim, nbSteps;
53 med_sorting_type stype;
54 med_axis_type axistype;
55 med_int naxis(MEDmeshnAxis(fid,getID()));
56 INTERP_KERNEL::AutoPtr<char> nameTmp(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
57 INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
58 INTERP_KERNEL::AutoPtr<char> axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
59 INTERP_KERNEL::AutoPtr<char> univTmp(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
60 if(MEDmeshInfo(fid,getID(),nameTmp,&spaceDim,&meshDim,&type_maillage,description.getPointer(),dtunit.getPointer(),
61 &stype,&nbSteps,&axistype,axisname,axisunit)!=0)
62 throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
63 Mdim=FromMedInt<int>(meshDim);
64 nstep=FromMedInt<int>(nbSteps);
65 MEDmeshUniversalNameRd(fid,nameTmp,univName.getPointer());// do not protect MEDFILESAFECALLERRD0 call : Thanks to fra.med.
66 axType=MEDFileMeshL2::TraduceAxisType(axistype);
69 case MED_UNSTRUCTURED_MESH:
70 meshType=UNSTRUCTURED;
72 case MED_STRUCTURED_MESH:
75 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>));
78 case MED_CARTESIAN_GRID:
81 case MED_CURVILINEAR_GRID:
82 meshType=CURVE_LINEAR;
84 case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
88 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
93 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
96 std::vector<std::string> infosOnComp(naxis);
97 for(int i=0;i<naxis;i++)
99 std::string info(MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE));
105 double MeshCls::checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const
110 std::vector< std::pair<int,int> > p(nstep);
111 for(int i=0;i<nstep;i++)
113 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),i+1,&numdt,&numit,&dtt));
114 p[i]=std::make_pair((int)numdt,(int)numit);
115 found=(numdt==dt) && (numit==it);
120 std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! ";
121 oss << "Possibilities are : ";
122 for(int i=0;i<nstep;i++)
123 oss << "(" << p[i].first << "," << p[i].second << "), ";
124 throw INTERP_KERNEL::Exception(oss.str().c_str());
129 std::vector<std::string> StructMeshCls::getAxisInfoOnMesh(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim, MEDFileString& description, MEDFileString& dtunit, MEDFileString& univName) const
131 INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
132 INTERP_KERNEL::AutoPtr<char> zeDescription(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
133 med_axis_type medAxType;
134 med_int nAxis(MEDsupportMeshnAxis(fid,getID()));
135 INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
136 med_int spaceDim(0),meshDim(0);
137 MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,getID(),msn,&spaceDim,&meshDim,zeDescription,&medAxType,axisName,axisUnit));
138 std::string descriptionCpp(MEDLoaderBase::buildStringFromFortran(zeDescription,MED_COMMENT_SIZE));
139 description.set(descriptionCpp.c_str());
140 dtunit.clear(); univName.clear(); meshType=UNSTRUCTURED; nstep=1;
141 axType=MEDFileMeshL2::TraduceAxisType(medAxType);
143 //med_bool chgt=MED_FALSE,trsf=MED_FALSE;
144 //nmodels=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
145 std::vector<std::string> ret;
146 for(int i=0;i<nAxis;i++)
148 std::string info(DataArray::BuildInfoFromVarAndUnit(MEDLoaderBase::buildStringFromFortran(axisName+i*MED_SNAME_SIZE,MED_SNAME_SIZE),
149 MEDLoaderBase::buildStringFromFortran(axisUnit+i*MED_SNAME_SIZE,MED_SNAME_SIZE)));
155 double StructMeshCls::checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const
160 MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
164 std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const
169 std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull() const
171 return std::vector<const BigMemoryObject *>();
174 INTERP_KERNEL::AutoCppPtr<MeshOrStructMeshCls> MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1)
176 med_mesh_type type_maillage=MED_UNDEF_MESH_TYPE;
177 char maillage_description[MED_COMMENT_SIZE+1];
178 char dtunit[MED_LNAME_SIZE+1];
179 med_int spaceDim,dim;
180 char nommaa[MED_NAME_SIZE+1];
181 med_int n=MEDnMesh(fid);
184 med_sorting_type stype;
185 std::vector<std::string> ms;
187 med_axis_type axistype=MED_UNDEF_AXIS_TYPE;
188 for(int i=0;i<n && found==0;i++)
190 med_int naxis(MEDmeshnAxis(fid,i+1));
191 INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
192 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
193 dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
194 std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)));
203 {//last chance ! Is it a support mesh ?
204 med_int nbSM(MEDnSupportMesh(fid));
205 for(int i=0;i<nbSM && found==0;i++)
207 med_int naxis(MEDsupportMeshnAxis(fid,i+1));
208 INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
209 MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,maillage_description,&axistype,axisname,axisunit));
210 std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)));
219 ////////////////////////
224 axType=TraduceAxisType(axistype);
225 switch(type_maillage)
227 case MED_UNSTRUCTURED_MESH:
228 meshType=UNSTRUCTURED;
230 case MED_STRUCTURED_MESH:
233 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>));
236 case MED_CARTESIAN_GRID:
239 case MED_CURVILINEAR_GRID:
240 meshType=CURVE_LINEAR;
242 case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
246 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
251 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
255 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),1,&numdt,&numit,&dtt));
256 dt=FromMedInt<int>(numdt); it=FromMedInt<int>(numit);
257 return new MeshCls(ret);
261 meshType=UNSTRUCTURED;
262 dt=MED_NO_DT; it=MED_NO_IT; dtunit1.clear();
263 axType=TraduceAxisType(axistype);
264 return new StructMeshCls(ret);
268 std::ostringstream oss;
269 oss << "No such meshname (" << mName << ") in file ! Must be in : ";
270 std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
271 throw INTERP_KERNEL::Exception(oss.str().c_str());
278 * non static and non const method because _description, _dt_unit... are set in this method.
280 std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim)
282 return mId->getAxisInfoOnMesh(fid,mName,meshType,axType,nstep,Mdim,_description,_dt_unit,_univ_name);
285 void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const std::string& meshName, std::map<std::string,mcIdType>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs)
287 if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading()))
289 char nomfam[MED_NAME_SIZE+1];
291 med_int nfam=MEDnFamily(fid,meshName.c_str());
292 std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > > crudeFams(nfam);
293 for(int i=0;i<nfam;i++)
295 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
296 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
297 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
298 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
299 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
300 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
301 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
302 std::string famName(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
303 std::vector<std::string> grps2(ngro);
304 for(int j=0;j<ngro;j++)
305 grps2[j]=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
306 crudeFams[i]=std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > >(famName,std::pair<mcIdType,std::vector<std::string> >(numfam,grps2));
308 RenameFamiliesFromFileToMemInternal(crudeFams);
309 for(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >::const_iterator it0=crudeFams.begin();it0!=crudeFams.end();it0++)
311 fams[(*it0).first]=(*it0).second.first;
312 for(std::vector<std::string>::const_iterator it1=(*it0).second.second.begin();it1!=(*it0).second.second.end();it1++)
313 grps[*it1].push_back((*it0).first);
317 void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map<std::string,mcIdType>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol)
319 std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > > crudeFams(fams.size());
321 for(std::map<std::string,mcIdType>::const_iterator it=fams.begin();it!=fams.end();it++,ii++)
323 std::vector<std::string> grpsOfFam;
324 for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
326 if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
327 grpsOfFam.push_back((*it1).first);
329 crudeFams[ii]=std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > >((*it).first,std::pair<mcIdType,std::vector<std::string> >((*it).second,grpsOfFam));
331 RenameFamiliesFromMemToFileInternal(crudeFams);
332 for(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++)
334 std::size_t ngro((*it).second.second.size());
335 INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
337 for(std::vector<std::string>::const_iterator it2=(*it).second.second.begin();it2!=(*it).second.second.end();it2++,i++)
338 MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE,groName+i*MED_LNAME_SIZE,tooLongStrPol);
339 INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
340 MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
341 med_int ret=MEDfamilyCr(fid,mname.c_str(),famName,ToMedInt((*it).second.first),ToMedInt(ngro),groName);
346 void MEDFileMeshL2::RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func)
349 std::vector<std::string> fams(crudeFams.size());
350 for(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
351 fams[ii]=(*it).first;
355 for(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >::iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
356 (*it).first=fams[ii];
360 * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
361 * So this method renames families (if needed generally not !) in order to have a discriminant name for families.
363 void MEDFileMeshL2::RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams)
365 RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromFileToMem);
368 bool MEDFileMeshL2::RenameFamiliesFromFileToMem(std::vector< std::string >& famNames)
370 std::map<std::string,mcIdType> m;
371 std::set<std::string> s;
372 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
374 if(s.find(*it)!=s.end())
379 return false;// the general case !
380 for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
382 std::map<std::string,mcIdType>::iterator it2(m.find(*it));
385 std::ostringstream oss; oss << *it << ZE_SEP_FOR_FAMILY_KILLERS << std::setfill('0') << std::setw(ZE_SEP2_FOR_FAMILY_KILLERS) << (*it2).second++;
393 * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
394 * So this method renames families (if needed generally not !) in order to have a discriminant name for families.
396 void MEDFileMeshL2::RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams)
398 RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromMemToFile);
401 bool MEDFileMeshL2::RenameFamiliesFromMemToFile(std::vector< std::string >& famNames)
403 bool isSmthingStrange(false);
404 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
406 std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
407 if(found!=std::string::npos)
408 isSmthingStrange=true;
410 if(!isSmthingStrange)
413 std::map< std::string, std::vector<std::string> > m;
414 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
416 std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
417 if(found!=std::string::npos && found>=1)
419 std::string s1((*it).substr(found+sizeof(ZE_SEP_FOR_FAMILY_KILLERS)-1));
420 if((int)s1.size()!=ZE_SEP2_FOR_FAMILY_KILLERS)
423 std::istringstream iss(s1);
425 bool isOK((iss.rdstate() & ( std::istream::failbit | std::istream::eofbit)) == std::istream::eofbit);
428 std::string s0((*it).substr(0,found));
429 m[s0].push_back(*it);
436 std::map<std::string,std::string> zeMap;
437 for(std::map< std::string, std::vector<std::string> >::const_iterator it=m.begin();it!=m.end();it++)
439 if((*it).second.size()==1)
441 for(std::vector<std::string>::const_iterator it1=(*it).second.begin();it1!=(*it).second.end();it1++)
442 zeMap[*it1]=(*it).first;
447 for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
449 std::map<std::string,std::string>::iterator it1(zeMap.find(*it));
456 MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisType(med_axis_type at)
462 case MED_CYLINDRICAL:
466 case MED_UNDEF_AXIS_TYPE:
469 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisType : unrecognized axis type !");
473 MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisTypeStruct(med_grid_type gt)
477 case MED_CARTESIAN_GRID:
482 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeStruct : only Cartesian and Cylindrical supported by MED file !");
486 med_axis_type MEDFileMeshL2::TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at)
491 return MED_CARTESIAN;
493 return MED_CYLINDRICAL;
495 return MED_SPHERICAL;
497 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRev : unrecognized axis type !");
501 med_grid_type MEDFileMeshL2::TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at)
506 return MED_CARTESIAN_GRID;
508 return MED_POLAR_GRID;
510 return MED_POLAR_GRID;
512 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRevStruct : unrecognized axis type !");
516 MEDFileUMeshL2::MEDFileUMeshL2()
520 std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, int& Mdim)
523 _name.set(mName.c_str());
525 MEDCoupling::MEDCouplingMeshType meshType;
526 MEDCoupling::MEDCouplingAxisType dummy3;
527 std::vector<std::string> ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
531 return std::vector<std::string>();
533 if(meshType!=UNSTRUCTURED)
534 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
535 _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
541 void MEDFileUMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
544 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
547 loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency
548 loadCoords(fid,infosOnComp,mName,dt,it);
552 * This method is expected to be invoked after the load of connectivity.
553 * This method is in charge of :
554 * - dealing with optimized load of coordinates (loading only points fetched by the already loaded cells)
555 * - update the connectivity in \a this to fit the coordinates loaded just above
557 void MEDFileUMeshL2::dealWithCoordsInLoadPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<std::string>& infosOnComp, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<mcIdType>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
559 med_bool changement,transformation;
560 mcIdType nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
561 std::vector<bool> fetchedNodeIds(nCoords,false);
562 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
563 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
564 (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds);
565 if(!mrs || mrs->getNumberOfCoordsLoadSessions()==1)
567 mcIdType nMin(ToIdType(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true))));
568 mcIdType nMax(ToIdType(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true))));
570 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
571 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
572 (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin);
573 this->loadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax);
577 mcIdType nbOfCooLS(mrs->getNumberOfCoordsLoadSessions());
578 MCAuto<DataArrayIdType> fni(DataArrayIdType::BuildListOfSwitchedOn(fetchedNodeIds));
579 MCAuto< MapKeyVal<mcIdType, mcIdType> > o2n(fni->invertArrayN2O2O2NOptimized());
580 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
581 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
582 (*it1)->getMesh()->renumberNodesInConn(o2n->data());
583 this->loadPartCoordsSlice(fid,infosOnComp,mName,dt,it,fni,nbOfCooLS);
587 std::vector<std::string> MEDFileUMeshL2::loadPartConnectivityOnly(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<mcIdType>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs, int& Mdim)
589 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
592 loadPartOfConnectivity(fid,Mdim,mName,types,slicPerTyp,dt,it,mrs);
596 void MEDFileUMeshL2::loadPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<mcIdType>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
599 std::vector<std::string> infosOnComp(loadPartConnectivityOnly(fid,mId,mName,types,slicPerTyp,dt,it,mrs,Mdim));
602 loadPartOfConnectivity(fid,Mdim,mName,types,slicPerTyp,dt,it,mrs);
603 dealWithCoordsInLoadPart(fid,mId,mName,infosOnComp,types,slicPerTyp,dt,it,mrs);
607 * This method loads from file \a fid a part of the mesh (made of same geometrical type cells \a type) called \a mName. The loading is done in 2 steps:
608 * First, we load the connectivity of nodes.
609 * Second, we load coordinates of nodes lying in the specified cells (same as MEDFileUMeshL2::dealWithCoordsInLoadPart, except in this case, we're not limited to slice of nodes)
610 * \throw exception if multiple load sessions are requested
612 void MEDFileUMeshL2::loadPartFromUserDistrib(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, const std::map<INTERP_KERNEL::NormalizedCellType,std::vector<mcIdType>>& distrib, int dt, int it, MEDFileMeshReadSelector *mrs)
615 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
619 /* First step : loading connectivity of nodes, ie building a new mesh of one geometrical type with only the specified cells in distrib */
620 loadPartOfConnectivityFromUserDistrib(fid,Mdim,mName,distrib,dt,it,mrs);
622 /* Second step : loading nodes */
623 med_bool changement,transformation;
624 mcIdType nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
625 std::vector<bool> fetchedNodeIds(nCoords,false);
626 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
627 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
628 (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds); // for each node in the original mesh, which ones are laying on the current single geometrical type partial mesh
630 if(!mrs || mrs->getNumberOfCoordsLoadSessions()==1)
632 // renumbering nodes inside the connectivity of the partial mesh:
633 // until now, the numbering used in the connectivity of the cells was that of the integral mesh,
634 // so it might be sparsed as some original nodes are missing in the partial mesh,
635 // thus we want each node to be renumbered so that the sequence of their numbers form a range
636 MCAuto<DataArrayIdType> fni(DataArrayIdType::BuildListOfSwitchedOn(fetchedNodeIds));
637 MCAuto< MapKeyVal<mcIdType, mcIdType> > o2n(fni->invertArrayN2O2O2NOptimized());
638 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
639 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
640 (*it1)->getMesh()->renumberNodesInConn(o2n->data());
642 // loading coordinates of fetched nodes
643 std::vector<mcIdType> distribNodes;
644 for(std::map<mcIdType,mcIdType>::const_iterator mapIter = o2n->data().begin(); mapIter != o2n->data().end(); ++mapIter)
645 distribNodes.push_back(mapIter->first);
646 this->loadPartCoords(fid,infosOnComp,mName,dt,it,distribNodes);
649 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartFromUserDistrib: multiple load sessions not handled!");
652 void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
654 _per_type_mesh.resize(1);
655 _per_type_mesh[0].clear();
656 for(int j=0;j<MED_N_CELL_FIXED_GEO;j++)
658 MEDFileUMeshPerType *tmp(MEDFileUMeshPerType::New(fid,mName.c_str(),dt,it,mdim,typmai[j],typmai2[j],mrs));
660 _per_type_mesh[0].push_back(tmp);
665 void MEDFileUMeshL2::loadPartOfConnectivity(med_idt fid, int mdim, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<mcIdType>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
667 std::size_t nbOfTypes(types.size());
668 if(slicPerTyp.size()!=3*nbOfTypes)
669 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : The size of slicPerTyp array is expected to be equal to 3 times size of array types !");
670 std::set<INTERP_KERNEL::NormalizedCellType> types2(types.begin(),types.end());
671 if(types2.size()!=nbOfTypes)
672 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : the geometric types in types array must appear once !");
673 _per_type_mesh.resize(1);
674 _per_type_mesh[0].clear();
675 for(std::size_t ii=0;ii<nbOfTypes;ii++)
677 mcIdType strt(slicPerTyp[3*ii+0]),stp(slicPerTyp[3*ii+1]),step(slicPerTyp[3*ii+2]);
678 MCAuto<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs));
679 _per_type_mesh[0].push_back(tmp);
685 * This method builds a new mesh of single geometrical type based on the partition of cells \a distrib, from mesh \a mName in file \a fid.
686 * This distribution is not necessarily a slice.
688 void MEDFileUMeshL2::loadPartOfConnectivityFromUserDistrib(med_idt fid, int mdim, const std::string& mName, const std::map<INTERP_KERNEL::NormalizedCellType,std::vector<mcIdType>>& distrib, int dt, int it, MEDFileMeshReadSelector *mrs)
690 _per_type_mesh.resize(1);
691 _per_type_mesh[0].clear();
692 std::map<INTERP_KERNEL::NormalizedCellType,std::vector<mcIdType>>::const_iterator iter;
693 for (iter = distrib.begin(); iter != distrib.end(); iter++)
695 MCAuto<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,iter->first/*type*/,iter->second/*distrib over the current type*/,mrs));
696 _per_type_mesh[0].push_back(tmp);
701 void MEDFileUMeshL2::loadCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it)
703 int spaceDim((int)infosOnComp.size());
704 med_bool changement,transformation;
705 med_int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
706 _coords=DataArrayDouble::New();
707 _coords->alloc(nCoords,spaceDim);
708 double *coordsPtr(_coords->getPointer());
710 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,coordsPtr));
711 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
713 MCAuto<DataArrayMedInt> miFamCoord=DataArrayMedInt::New();
714 miFamCoord->alloc(nCoords,1);
715 MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miFamCoord->getPointer()));
716 _fam_coords=FromMedIntArray<mcIdType>(miFamCoord);
720 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
722 MCAuto<DataArrayMedInt> miNumCoord=DataArrayMedInt::New();
723 miNumCoord->alloc(nCoords,1);
724 MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miNumCoord->getPointer()));
725 _num_coords=FromMedIntArray<mcIdType>(miNumCoord);
729 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
731 _name_coords=DataArrayAsciiChar::New();
732 _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
733 MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
734 _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
738 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_GLOBAL_NUMBER,MED_NODAL,&changement,&transformation)>0)
740 MCAuto<DataArrayMedInt> miNumCoord=DataArrayMedInt::New();
741 miNumCoord->alloc(nCoords,1);
742 MEDFILESAFECALLERRD0(MEDmeshGlobalNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miNumCoord->getPointer()));
743 _global_num_coords=FromMedIntArray<mcIdType>(miNumCoord);
745 for(int i=0;i<spaceDim;i++)
746 _coords->setInfoOnComponent(i,infosOnComp[i]);
750 void MEDFileUMeshL2::LoadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, const std::vector<mcIdType>& distribNodes,
751 MCAuto<DataArrayDouble>& _coords, MCAuto<PartDefinition>& _part_coords, MCAuto<DataArrayIdType>& _fam_coords, MCAuto<DataArrayIdType>& _num_coords, MCAuto<DataArrayAsciiChar>& _name_coords)
753 med_int spaceDim((int)infosOnComp.size());
754 allocCoordsPartCoords(spaceDim,distribNodes,_coords,_part_coords);
755 _coords->setInfoOnComponents(infosOnComp);
756 fillPartCoords(fid,spaceDim,mName,dt,it,_part_coords,_coords,_fam_coords,_num_coords,_name_coords);
759 void MEDFileUMeshL2::LoadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, mcIdType nMin, mcIdType nMax,
760 MCAuto<DataArrayDouble>& _coords, MCAuto<PartDefinition>& _part_coords, MCAuto<DataArrayIdType>& _fam_coords, MCAuto<DataArrayIdType>& _num_coords, MCAuto<DataArrayAsciiChar>& _name_coords)
762 med_int spaceDim((int)infosOnComp.size());
763 allocCoordsPartCoords(spaceDim,nMin,nMax,_coords,_part_coords);
764 _coords->setInfoOnComponents(infosOnComp);
765 fillPartCoords(fid,spaceDim,mName,dt,it,_part_coords,_coords,_fam_coords,_num_coords,_name_coords);
769 * This method allocates the space needed to load coordinates of nodes specified in the vector \a nodeIds and creates a PartDefinition object to store the ids in \a nodeIds
771 void MEDFileUMeshL2::allocCoordsPartCoords(mcIdType spaceDim, const std::vector<mcIdType>& nodeIds, MCAuto<DataArrayDouble>& _coords, MCAuto<PartDefinition>& _part_coords)
773 mcIdType nbNodesToLoad(nodeIds.size());
774 _coords=DataArrayDouble::New();
775 _coords->alloc(nbNodesToLoad,spaceDim);
777 MCAuto<DataArrayIdType> nodeIdsArray=DataArrayIdType::New();
778 nodeIdsArray->useArray(nodeIds.data(),false,DeallocType::C_DEALLOC,nbNodesToLoad,1);
779 _part_coords=PartDefinition::New(nodeIdsArray);
783 * This method allocates the space needed to load coordinates of all nodes between \a nMin and \a nMax and creates a PartDefinition object to store them
785 void MEDFileUMeshL2::allocCoordsPartCoords(mcIdType spaceDim, mcIdType nMin, mcIdType nMax, MCAuto<DataArrayDouble>& _coords, MCAuto<PartDefinition>& _part_coords)
787 _coords=DataArrayDouble::New();
788 mcIdType nbNodesToLoad(nMax-nMin);
789 _coords->alloc(nbNodesToLoad,spaceDim);
791 _part_coords=PartDefinition::New(nMin,nMax,1);
795 * This method loads coordinates of every node in \a partCoords and additionnal low-level information
797 void MEDFileUMeshL2::fillPartCoords(med_idt fid, mcIdType spaceDim, const std::string& mName, int dt, int it, const PartDefinition *partCoords,
798 MCAuto<DataArrayDouble>& _coords, MCAuto<DataArrayIdType>& _fam_coords, MCAuto<DataArrayIdType>& _num_coords, MCAuto<DataArrayAsciiChar>& _name_coords)
800 med_bool changement,transformation;
801 med_int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
802 mcIdType nbNodesToLoad = partCoords->getNumberOfElems();
804 // Based on the ids in \a partCoords, defining the appropriate med_filter (filter of block if the ids form a slice, a generic filter otherwise)
806 MEDFilterEntity filter1;
807 filter1.fill(fid,/*nentity*/nCoords,/*nvaluesperentity*/1,/*nconstituentpervalue*/spaceDim,
808 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
810 // With the filter defined above, retrieve coordinates of nodes
811 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateAdvancedRd,(fid,mName.c_str(),dt,it,filter1.getPtr(),_coords->getPointer()));
815 MEDFilterEntity filter2;
816 filter2.fill(fid,nCoords,1,1,
817 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE, partCoords);
819 // Retrieve additional information regarding nodes
820 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
822 MCAuto<DataArrayMedInt> miFamCoord=DataArrayMedInt::New();
823 miFamCoord->alloc(nbNodesToLoad,1);
824 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,filter2.getPtr(),miFamCoord->getPointer()));
825 _fam_coords=FromMedIntArray<mcIdType>(miFamCoord);
829 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
831 MCAuto<DataArrayMedInt> miNumCoord=DataArrayMedInt::New();
832 miNumCoord->alloc(nbNodesToLoad,1);
833 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,filter2.getPtr(),miNumCoord->getPointer()));
834 _num_coords=FromMedIntArray<mcIdType>(miNumCoord);
838 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
840 _name_coords=DataArrayAsciiChar::New();
841 _name_coords->alloc(nbNodesToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
842 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NAME,dt,it,MED_NODE,MED_NO_GEOTYPE,filter2.getPtr(),_name_coords->getPointer()));
843 _name_coords->reAlloc(nbNodesToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
846 _name_coords=nullptr;
852 * For performance reasons LoadPartCoordsArray method calls LoadPartCoords
854 void MEDFileUMeshL2::LoadPartCoordsArray(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, const DataArrayIdType *nodeIds,
855 MCAuto<DataArrayDouble>& _coords, MCAuto<DataArrayIdType>& _fam_coords, MCAuto<DataArrayIdType>& _num_coords, MCAuto<DataArrayAsciiChar>& _name_coords)
857 MCAuto<PartDefinition> useless;
858 nodeIds->checkAllocated();
859 nodeIds->checkNbOfComps(1,"loadPartCoordsSlice : Only one component expected !");
860 mcIdType nMin(0),nMax(0);
861 if(!nodeIds->empty())
862 { nMin = nodeIds->front(); nMax = nodeIds->back()+1; }
863 LoadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax,_coords,useless,_fam_coords,_num_coords,_name_coords);
866 MCAuto<DataArrayIdType> nodeIds2(nodeIds->deepCopy());
867 nodeIds2->applyLin(1,-nMin);
868 _coords = _coords->selectByTupleIdSafe(nodeIds2->begin(),nodeIds2->end());
869 if(_fam_coords.isNotNull())
870 _fam_coords = _fam_coords->selectByTupleIdSafe(nodeIds2->begin(),nodeIds2->end());
871 if(_num_coords.isNotNull())
872 _num_coords = _num_coords->selectByTupleIdSafe(nodeIds2->begin(),nodeIds2->end());
873 if(_name_coords.isNotNull())
875 MCAuto<DataArrayChar> tmp(_name_coords->selectByTupleIdSafe(nodeIds2->begin(),nodeIds2->end()));
876 _name_coords = DynamicCastSafe<DataArrayChar,DataArrayAsciiChar>( tmp );
880 void MEDFileUMeshL2::loadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, mcIdType nMin, mcIdType nMax)
882 LoadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax,_coords,_part_coords,_fam_coords,_num_coords,_name_coords);
885 void MEDFileUMeshL2::loadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, const std::vector<mcIdType>& distribNodes)
887 LoadPartCoords(fid,infosOnComp,mName,dt,it,distribNodes,_coords,_part_coords,_fam_coords,_num_coords,_name_coords);
891 void MEDFileUMeshL2::loadPartCoordsSlice(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, const DataArrayIdType *nodeIds, mcIdType nbOfCoordLS)
893 nodeIds->checkAllocated();
894 nodeIds->checkNbOfComps(1,"loadPartCoordsSlice : Only one component expected !");
898 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartCoordsSlice : nb of coords load session must be >=1 !");
899 mcIdType nMin(nodeIds->front()),nMax(nodeIds->back()+1);
900 std::vector< MCAuto<DataArrayDouble> > coords(nbOfCoordLS);
901 std::vector< MCAuto<DataArrayIdType> > famCoords(nbOfCoordLS);
902 std::vector< MCAuto<DataArrayIdType> > numCoords(nbOfCoordLS);
903 std::vector< MCAuto<DataArrayAsciiChar> > nameCoords(nbOfCoordLS);
904 for(mcIdType ipart = 0 ; ipart < nbOfCoordLS ; ++ipart)
906 mcIdType partStart,partStop;
907 DataArray::GetSlice(nMin,nMax,1,ipart,nbOfCoordLS,partStart,partStop);
908 MCAuto<DataArrayIdType> idsNodeIdsToKeep(nodeIds->findIdsInRange(partStart,partStop));
909 MCAuto<DataArrayIdType> nodeIdsToKeep( nodeIds->selectByTupleIdSafe(idsNodeIdsToKeep->begin(),idsNodeIdsToKeep->end()) );
910 LoadPartCoordsArray(fid,infosOnComp,mName,dt,it,nodeIdsToKeep,coords[ipart],famCoords[ipart],numCoords[ipart],nameCoords[ipart]);
912 _coords = DataArrayDouble::Aggregate(ToConstVect<DataArrayDouble>(coords));
913 if(famCoords[0].isNotNull())
914 _fam_coords = DataArrayIdType::Aggregate(ToConstVect<DataArrayIdType>(famCoords));
915 if(numCoords[0].isNotNull())
916 _num_coords = DataArrayIdType::Aggregate(ToConstVect<DataArrayIdType>(numCoords));
917 if(nameCoords[0].isNotNull())
919 std::vector< MCAuto<DataArrayChar> > nameCoords2(nameCoords.begin(),nameCoords.end());
920 std::for_each(nameCoords2.begin(),nameCoords2.end(),[](MCAuto<DataArrayChar>& elt){ elt->incrRef(); });
921 MCAuto<DataArrayChar> tmp( DataArrayChar::Aggregate(ToConstVect<DataArrayChar>(nameCoords2)) );
922 _name_coords = DynamicCastSafe<DataArrayChar,DataArrayAsciiChar>( tmp );
924 _part_coords = DataArrayPartDefinition::New( const_cast<DataArrayIdType *>(nodeIds) );
927 void MEDFileUMeshL2::sortTypes()
930 std::vector< MCAuto<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
931 _per_type_mesh.clear();
932 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
933 mdims.insert((*it)->getDim());
936 int mdim=*mdims.rbegin();
937 _per_type_mesh.resize(mdim+1);
938 for(int dim=mdim+1;dim!=0;dim--)
940 std::vector< MCAuto<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
941 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
942 if((*it)->getDim()==dim-1)
945 // suppression of contiguous empty levels at the end of _per_type_mesh.
946 int nbOfUselessLev=0;
948 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
950 if((*it2).empty() && isFirst)
957 _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
960 void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayIdType *famCoords, const DataArrayIdType *numCoords, const DataArrayAsciiChar *nameCoords, const DataArrayIdType *globalNumCoords)
964 MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,ToMedInt(coords->getNumberOfTuples()),coords->begin()));
966 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(famCoords->getNumberOfTuples()),ToMedIntArray<mcIdType>(famCoords)->begin()));
968 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(numCoords->getNumberOfTuples()),ToMedIntArray<mcIdType>(numCoords)->begin()));
971 if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
973 std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
974 oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
975 throw INTERP_KERNEL::Exception(oss.str().c_str());
977 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(nameCoords->getNumberOfTuples()),nameCoords->begin()));
980 MEDFILESAFECALLERWR0(MEDmeshGlobalNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NONE,ToMedInt(globalNumCoords->getNumberOfTuples()),ToMedIntArray<mcIdType>(globalNumCoords)->begin()));
983 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
985 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
986 if((*it)->getFam()==0)
991 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
993 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
994 if((*it)->getNum()==0)
999 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
1001 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
1002 if((*it)->getNames()==0)
1007 MEDFileCMeshL2::MEDFileCMeshL2():_ax_type(AX_CART)
1011 void MEDFileCMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it)
1013 _name.set(mName.c_str());
1016 MEDCoupling::MEDCouplingMeshType meshType;
1017 MEDCoupling::MEDCouplingAxisType dummy3;
1018 std::vector<std::string> infosOnComp(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
1019 if(meshType!=CARTESIAN)
1020 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
1021 _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
1025 med_grid_type gridtype;
1026 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype));
1027 if(gridtype!=MED_CARTESIAN_GRID && gridtype!=MED_POLAR_GRID)
1028 throw INTERP_KERNEL::Exception("Invalid rectilinear mesh ! Only cartesian and polar are supported !");
1029 _ax_type=TraduceAxisTypeStruct(gridtype);
1030 _cmesh=MEDCouplingCMesh::New();
1031 for(int i=0;i<Mdim;i++)
1033 med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
1034 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
1035 med_int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf));
1036 MCAuto<DataArrayDouble> da=DataArrayDouble::New();
1037 da->alloc(nbOfElt,1);
1038 da->setInfoOnComponent(0,infosOnComp[i]);
1039 MEDFILESAFECALLERRD0(MEDmeshGridIndexCoordinateRd,(fid,mName.c_str(),dt,it,i+1,da->getPointer()));
1040 _cmesh->setCoordsAt(i,da);
1044 med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id)
1049 return MED_COORDINATE_AXIS1;
1051 return MED_COORDINATE_AXIS2;
1053 return MED_COORDINATE_AXIS3;
1055 throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
1059 MEDFileCLMeshL2::MEDFileCLMeshL2()
1063 void MEDFileCLMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it)
1065 _name.set(mName.c_str());
1068 MEDCoupling::MEDCouplingMeshType meshType;
1069 MEDCoupling::MEDCouplingAxisType dummy3;
1070 std::vector<std::string> infosOnComp(getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim));
1071 if(meshType!=CURVE_LINEAR)
1072 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
1073 _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
1077 _clmesh=MEDCouplingCurveLinearMesh::New();
1078 MCAuto<DataArrayMedInt> miStGrid=DataArrayMedInt::New();
1079 miStGrid->alloc(Mdim,1);
1080 MEDFILESAFECALLERRD0(MEDmeshGridStructRd,(fid,mName.c_str(),dt,it,miStGrid->getPointer()));
1081 MCAuto<DataArrayIdType> stGrid=FromMedIntArray<mcIdType>(miStGrid);
1082 _clmesh->setNodeGridStructure(stGrid->begin(),stGrid->end());
1083 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
1084 med_int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf));
1085 MCAuto<DataArrayDouble> da=DataArrayDouble::New();
1086 da->alloc(nbNodes,infosOnComp.size());
1087 da->setInfoOnComponents(infosOnComp);
1088 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer()));
1089 _clmesh->setCoords(da);
1092 MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
1097 * Warning it returns an instance to deallocate !!!!
1099 MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
1101 _st->_num->updateTime();
1102 if((MEDCouplingUMesh *)_m==0)
1105 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
1106 _m->renumberCells(_st->_num->begin(),true);
1111 if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
1116 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
1117 _m->renumberCells(_st->_num->begin(),true);
1123 void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
1128 void MEDFileUMeshPermCompute::updateTime() const
1130 _mpt_time=_st->_m_by_types.getTimeOfThis();
1131 _num_time=_st->_num->getTimeOfThis();
1134 std::vector<const BigMemoryObject *> MEDFileUMeshPermCompute::getDirectChildrenWithNull() const
1136 std::vector<const BigMemoryObject *> ret;
1137 ret.push_back((const MEDCouplingUMesh *)_m);
1141 std::size_t MEDFileUMeshPermCompute::getHeapMemorySizeWithoutChildren() const
1143 return sizeof(MEDFileUMeshPermCompute);
1146 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshSplitL1& other):RefCountObject(other),_m_by_types(other._m_by_types),_fam(other._fam),_num(other._num),_names(other._names),_rev_num(other._rev_num),_m(this)
1150 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this)
1152 const std::vector< MCAuto<MEDFileUMeshPerType> >& v=l2.getLev(id);
1155 std::size_t sz=v.size();
1156 std::vector<const MEDCoupling1GTUMesh *> ms(sz);
1157 std::vector<const DataArrayIdType *> fams(sz),nums(sz);
1158 std::vector<const DataArrayChar *> names(sz);
1159 std::vector<const PartDefinition *> pds(sz);
1160 for(std::size_t i=0;i<sz;i++)
1162 MEDCoupling1GTUMesh *elt(v[i]->getMesh());
1163 MCAuto<DataArrayDouble> tmp2=l2.getCoords();
1164 elt->setCoords(tmp2);
1166 pds[i]=v[i]->getPartDef();
1168 _m_by_types.assignParts(ms);
1169 _m_by_types.assignDefParts(pds);
1170 if(l2.isFamDefinedOnLev(id))
1172 for(std::size_t i=0;i<sz;i++)
1173 fams[i]=v[i]->getFam();
1175 _fam=DataArrayIdType::Aggregate(fams);
1179 _fam=const_cast<DataArrayIdType *>(fams[0]);
1182 if(l2.isNumDefinedOnLev(id))
1184 for(std::size_t i=0;i<sz;i++)
1185 nums[i]=v[i]->getNum();
1187 _num=DataArrayIdType::Aggregate(nums);
1191 _num=const_cast<DataArrayIdType *>(nums[0]);
1195 if(l2.isNamesDefinedOnLev(id))
1197 for(std::size_t i=0;i<sz;i++)
1198 names[i]=v[i]->getNames();
1199 _names=dynamic_cast<DataArrayAsciiChar *>(DataArrayChar::Aggregate(names));
1203 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m):_m(this)
1205 std::vector< const MEDCoupling1GTUMesh * > v(1);
1210 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
1215 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
1217 assignMesh(m,newOrOld);
1220 void MEDFileUMeshSplitL1::setName(const std::string& name)
1222 _m_by_types.setName(name);
1225 std::size_t MEDFileUMeshSplitL1::getHeapMemorySizeWithoutChildren() const
1230 std::vector<const BigMemoryObject *> MEDFileUMeshSplitL1::getDirectChildrenWithNull() const
1232 std::vector<const BigMemoryObject *> ret;
1233 ret.push_back(&_m_by_types);
1235 ret.push_back((const DataArrayIdType*)_fam);
1236 ret.push_back((const DataArrayIdType*)_num);
1237 ret.push_back((const DataArrayIdType*)_rev_num);
1238 ret.push_back((const DataArrayAsciiChar*)_names);
1242 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::shallowCpyUsingCoords(DataArrayDouble *coords) const
1244 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
1245 ret->_m_by_types.shallowCpyMeshes();
1246 ret->_m_by_types.setCoords(coords);
1250 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCopy(DataArrayDouble *coords) const
1252 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
1253 ret->_m_by_types=_m_by_types.deepCopy(coords);
1254 if((const DataArrayIdType *)_fam)
1255 ret->_fam=_fam->deepCopy();
1256 if((const DataArrayIdType *)_num)
1257 ret->_num=_num->deepCopy();
1258 if((const DataArrayIdType *)_rev_num)
1259 ret->_rev_num=_rev_num->deepCopy();
1260 if((const DataArrayAsciiChar *)_names)
1261 ret->_names=_names->deepCopy();
1265 void MEDFileUMeshSplitL1::checkConsistency() const
1267 if (!_fam || _fam->getNumberOfTuples() != getSize())
1268 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): internal family array has an invalid size!");
1269 mcIdType nbCells = getSize();
1272 _num->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array!");
1274 mcIdType maxValue=_num->getMaxValue(pos);
1275 if (!_rev_num || _rev_num->getNumberOfTuples() != (maxValue+1))
1276 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal revert node numbering array!");
1278 if ((_num && !_rev_num) || (!_num && _rev_num))
1279 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal numbering arrays (one is null)!");
1280 if (_num && !_num->hasUniqueValues())
1281 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array: duplicates found!");
1283 _names->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): internal cell naming array has an invalid size!");
1285 _m_by_types.checkConsistency();
1288 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
1290 if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
1292 const DataArrayIdType *d1=_fam;
1293 const DataArrayIdType *d2=other->_fam;
1294 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
1296 what="Presence of family arr in one sublevel and not in other!";
1300 if(!d1->isEqual(*d2))
1302 what="family arr at a sublevel are not deeply equal !";
1307 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
1309 what="Presence of cell numbering arr in one sublevel and not in other!";
1313 if(!d1->isEqual(*d2))
1315 what="Numbering cell arr at a sublevel are not deeply equal !";
1318 const DataArrayAsciiChar *e1=_names;
1319 const DataArrayAsciiChar *e2=other->_names;
1320 if((e1==0 && e2!=0) || (e1!=0 && e2==0))
1322 what="Presence of cell names arr in one sublevel and not in other!";
1326 if(!e1->isEqual(*e2))
1328 what="Name cell arr at a sublevel are not deeply equal !";
1334 void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
1336 _m_by_types.synchronizeTinyInfo(master);
1339 void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
1341 _m_by_types.clearNonDiscrAttributes();
1344 void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
1348 (const_cast<MEDCouplingMesh *>(tmp))->setName("");
1349 (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
1350 (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
1351 (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
1354 void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords)
1356 _m_by_types.setCoords(coords);
1359 void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
1365 _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCopy()));
1366 MCAuto<DataArrayIdType> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
1367 if(!da->isIota(m->getNumberOfCells()))
1369 _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
1372 _m_by_types.getUmesh()->renumberCells(da->begin(),false);
1377 if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
1378 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh(): the mesh does not follow the MED file numbering convention! Invoke sortCellsInMEDFileFrmt() first!");
1380 _m_by_types.assignUMesh(m);
1385 void MEDFileUMeshSplitL1::forceComputationOfParts() const
1387 _m_by_types.forceComputationOfPartsFromUMesh();
1390 void MEDFileUMeshSplitL1::declarePartsUpdated() const
1392 _m_by_types.declarePartsUpdated();
1395 void MEDFileUMeshSplitL1::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1397 _m_by_types.assignParts(mParts);
1401 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this)
1405 void MEDFileUMeshSplitL1::assignCommonPart()
1407 _fam=DataArrayIdType::New();
1408 _fam->alloc(_m_by_types.getSize(),1);
1409 _fam->fillWithValue(0);
1412 bool MEDFileUMeshSplitL1::empty() const
1414 return _m_by_types.empty();
1417 bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector<mcIdType>& ids) const
1419 const DataArrayIdType *fam=_fam;
1422 return fam->presenceOfValue(ids);
1425 int MEDFileUMeshSplitL1::getMeshDimension() const
1427 return _m_by_types.getMeshDimension();
1430 void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const
1432 std::vector<mcIdType> code=_m_by_types.getDistributionOfTypes();
1433 std::size_t nbOfTypes=code.size()/3;
1434 for(std::size_t i=0;i<nbOfTypes;i++)
1436 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType) code[3*i];
1437 oss << " - Number of cells with type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr() << " : " << code[3*i+1] << std::endl;
1441 mcIdType MEDFileUMeshSplitL1::getSize() const
1443 return _m_by_types.getSize();
1446 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const mcIdType *idsBg, const mcIdType *idsEnd, bool renum) const
1448 MCAuto<DataArrayIdType> eltsToKeep=_fam->findIdsEqualList(idsBg,idsEnd);
1449 MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->begin(),eltsToKeep->end(),true);
1451 return renumIfNeeded(m,eltsToKeep->begin());
1455 DataArrayIdType *MEDFileUMeshSplitL1::getFamilyPartArr(const mcIdType *idsBg, const mcIdType *idsEnd, bool renum) const
1457 MCAuto<DataArrayIdType> da=_fam->findIdsEqualList(idsBg,idsEnd);
1459 return renumIfNeededArr(da);
1463 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes() const
1465 return _m_by_types.getGeoTypes();
1468 mcIdType MEDFileUMeshSplitL1::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1470 return _m_by_types.getNumberOfCellsWithType(ct);
1473 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
1475 MCAuto<MEDCouplingUMesh> tmp;
1476 if(renum && ((const DataArrayIdType *)_num))
1479 { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
1483 mcIdType MEDFileUMeshSplitL1::getNumberOfCells() const
1485 return _m_by_types.getNumberOfCells();
1488 DataArrayIdType *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
1490 const DataArrayIdType *fam(_fam);
1493 mcIdType start(0),stop(0);
1494 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
1495 return fam->selectByTupleIdSafeSlice(start,stop,1);
1498 DataArrayIdType *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
1500 const DataArrayIdType *num(_num);
1503 mcIdType start(0),stop(0);
1504 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
1505 return num->selectByTupleIdSafeSlice(start,stop,1);
1508 DataArrayIdType *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
1510 if((DataArrayIdType *)_fam)
1512 mcIdType nbOfTuples=_m_by_types.getSize();
1513 _fam=DataArrayIdType::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
1517 const DataArrayIdType *MEDFileUMeshSplitL1::getFamilyField() const
1522 const DataArrayIdType *MEDFileUMeshSplitL1::getNumberField() const
1527 const DataArrayIdType *MEDFileUMeshSplitL1::getRevNumberField() const
1532 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
1537 const PartDefinition *MEDFileUMeshSplitL1::getPartDef(INTERP_KERNEL::NormalizedCellType gt) const
1539 return _m_by_types.getPartDefOfWithoutComputation(gt);
1542 void MEDFileUMeshSplitL1::eraseFamilyField()
1544 _fam->fillWithZero();
1548 * This method ignores _m and _m_by_types.
1550 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,mcIdType>& familyIds,
1551 std::map<std::string, std::vector<std::string> >& groups)
1553 std::vector< DataArrayIdType * > corr;
1554 _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
1555 std::vector< MCAuto<DataArrayIdType> > corrMSafe(corr.begin(),corr.end());
1556 std::vector< std::vector<mcIdType> > fidsOfGroups;
1557 std::vector< const DataArrayIdType * > corr2(corr.begin(),corr.end());
1558 _fam=DataArrayIdType::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
1559 mcIdType nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
1560 std::map<mcIdType,std::string> newfams;
1561 std::map<mcIdType,mcIdType> famIdTrad;
1562 TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
1563 mcIdType *w=_fam->getPointer();
1564 for(mcIdType i=0;i<nbOfCells;i++,w++)
1568 void MEDFileUMeshSplitL1::checkCoordsConsistency(const DataArrayDouble *coords) const
1570 std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1574 if(mesh->getCoords() != coords)
1575 mesh->getCoords()->checkNbOfTuplesAndComp(*coords,"MEDFileUMeshSplitL1::checkCoordsConsistency : mismatch between coordinates instance in MEDFileUMesh and instance in subparts");
1579 void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const
1581 std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1583 for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
1585 mcIdType nbCells=(*it)->getNumberOfCells();
1586 mcIdType end=start+nbCells;
1587 MCAuto<DataArrayIdType> fam,num;
1588 MCAuto<DataArrayAsciiChar> names;
1589 if((const DataArrayIdType *)_fam)
1590 fam=_fam->subArray(start,end);
1591 if((const DataArrayIdType *)_num)
1592 num=_num->subArray(start,end);
1593 if((const DataArrayAsciiChar *)_names)
1594 names=static_cast<DataArrayAsciiChar *>(_names->subArray(start,end));
1595 MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
1600 void MEDFileUMeshSplitL1::renumberNodesInConn(const mcIdType *newNodeNumbersO2N)
1602 _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
1605 void MEDFileUMeshSplitL1::serialize(std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI) const
1607 bigArraysI.push_back(_fam);
1608 bigArraysI.push_back(_num);
1609 _m_by_types.serialize(tinyInt,bigArraysI);
1612 void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI)
1614 _fam=bigArraysI.back(); bigArraysI.pop_back();
1615 _num=bigArraysI.back(); bigArraysI.pop_back();
1616 _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
1619 void MEDFileUMeshSplitL1::changeFamilyIdArr(mcIdType oldId, mcIdType newId)
1621 DataArrayIdType *arr=_fam;
1623 arr->changeValue(oldId,newId);
1626 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayIdType *famArr)
1633 mcIdType sz(_m_by_types.getSize());
1634 famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
1639 DataArrayIdType *MEDFileUMeshSplitL1::getFamilyField()
1644 void MEDFileUMeshSplitL1::setRenumArr(DataArrayIdType *renumArr)
1652 mcIdType sz(_m_by_types.getSize());
1653 renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
1654 renumArr->incrRef();
1659 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
1666 mcIdType sz(_m_by_types.getSize());
1667 nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
1672 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayIdType *renum, MEDCouplingUMesh *m, const mcIdType *cellIds)
1677 m->renumberCells(renum->begin(),true);
1680 MCAuto<DataArrayIdType> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
1681 m->renumberCells(locnum->begin(),true);
1686 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI)
1688 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
1689 ret->unserialize(name,coo,tinyInt,bigArraysI);
1693 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const mcIdType *cellIds) const
1695 return Renumber2(_num,m,cellIds);
1698 DataArrayIdType *MEDFileUMeshSplitL1::Renumber(const DataArrayIdType *renum, const DataArrayIdType *da)
1700 if((const DataArrayIdType *)renum==0)
1703 return const_cast<DataArrayIdType *>(da);
1705 return renum->selectByTupleId(da->begin(),da->end());
1708 DataArrayIdType *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayIdType *da) const
1710 return Renumber(_num,da);
1713 std::vector<mcIdType> MEDFileUMeshSplitL1::GetNewFamiliesNumber(mcIdType nb, const std::map<std::string,mcIdType>& families)
1716 for(std::map<std::string,mcIdType>::const_iterator it=families.begin();it!=families.end();it++)
1717 id=std::max(id,(*it).second);
1720 std::vector<mcIdType> ret(nb);
1721 for(mcIdType i=1;i<=nb;i++)
1726 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<mcIdType> >& fidsGrps, std::map<std::string,mcIdType>& familyIds,
1727 std::map<mcIdType,mcIdType>& famIdTrad, std::map<mcIdType,std::string>& newfams)
1729 std::set<mcIdType> allfids;
1733 void MEDFileUMeshSplitL1::computeRevNum() const
1738 mcIdType maxValue=_num->getMaxValue(pos);
1739 _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
1743 _rev_num = DataArrayIdType::New();
1744 _rev_num->alloc(0,1);
1751 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
1755 void MEDFileUMeshAggregateCompute::setName(const std::string& name)
1757 if(_m_time>=_mp_time)
1759 MEDCouplingUMesh *um(_m);
1763 if(_mp_time>=_m_time)
1765 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1767 MEDCoupling1GTUMesh *tmp(*it);
1774 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1776 std::size_t sz(mParts.size());
1777 std::vector< MCAuto<MEDCoupling1GTUMesh> > ret(sz);
1778 for(std::size_t i=0;i<sz;i++)
1780 const MEDCoupling1GTUMesh *elt(mParts[i]);
1782 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
1783 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
1786 _part_def.clear(); _part_def.resize(sz);
1787 _mp_time=std::max(_mp_time,_m_time)+1;
1791 void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector<const PartDefinition *>& partDefs)
1793 if(_mp_time<_m_time)
1794 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !");
1795 std::size_t sz(partDefs.size());
1796 if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size())
1797 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !");
1798 for(std::size_t i=0;i<sz;i++)
1800 const PartDefinition *elt(partDefs[i]);
1803 _part_def[i]=const_cast<PartDefinition*>(elt);
1807 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
1811 _m_time=std::max(_mp_time,_m_time)+1;
1814 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
1816 if(_mp_time<=_m_time)
1818 std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
1819 std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
1820 _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
1821 _m_parts.clear();//to avoid memory peak !
1822 _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
1826 mcIdType MEDFileUMeshAggregateCompute::getNumberOfCells() const
1828 if(_mp_time<=_m_time)
1829 return _m->getNumberOfCells();
1831 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1832 ret+=(*it)->getNumberOfCells();
1836 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
1838 if(_mp_time>=_m_time)
1840 std::size_t sz(_m_parts.size());
1841 std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
1842 for(std::size_t i=0;i<sz;i++)
1843 ret[i]=_m_parts[i]->getCellModelEnum();
1847 return _m->getAllGeoTypesSorted();
1850 mcIdType MEDFileUMeshAggregateCompute::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1852 if(_mp_time>=_m_time)
1854 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1856 const MEDCoupling1GTUMesh *elt(*it);
1857 if(elt && elt->getCellModelEnum()==ct)
1858 return elt->getNumberOfCells();
1863 return _m->getNumberOfCellsWithType(ct);
1866 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
1868 if(_mp_time<_m_time)
1869 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
1871 std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
1873 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
1875 const MEDCoupling1GTUMesh *elt(*it);
1876 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
1881 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
1883 if(_mp_time<_m_time)
1884 forceComputationOfPartsFromUMesh();
1885 return retrievePartsWithoutComputation();
1888 void MEDFileUMeshAggregateCompute::highlightUsedNodes(std::vector<bool>& nodesToBeHighlighted) const
1890 if(_mp_time<_m_time)
1891 forceComputationOfPartsFromUMesh();
1892 for(auto part : this->_m_parts)
1894 part->computeNodeIdsAlg(nodesToBeHighlighted);
1898 MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1900 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1901 std::size_t sz(v.size());
1902 for(std::size_t i=0;i<sz;i++)
1905 if(v[i]->getCellModelEnum()==gt)
1908 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
1911 void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, mcIdType& start, mcIdType& stop) const
1914 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1915 std::size_t sz(v.size());
1916 for(std::size_t i=0;i<sz;i++)
1920 if(v[i]->getCellModelEnum()==gt)
1922 stop=start+v[i]->getNumberOfCells();
1926 start+=v[i]->getNumberOfCells();
1929 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
1932 void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const mcIdType *newNodeNumbersO2N)
1934 if(_mp_time>_m_time)
1936 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1938 MEDCoupling1GTUMesh *m(*it);
1940 m->renumberNodesInConn(newNodeNumbersO2N);
1945 MEDCouplingUMesh *m(getUmesh());
1948 m->renumberNodesInConn(newNodeNumbersO2N);
1949 // if _mp_time == _m_time notify for future clients that _m_parts is obsolete
1951 _m_time = std::max(_m_time,_mp_time+1);
1955 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1957 const MEDCouplingUMesh *m(_m);
1960 if(_m_parts.empty())
1961 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1963 return ;// no needs to compte parts they are already here !
1965 std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1966 std::vector< MCAuto<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1967 std::size_t sz(msMSafe.size());
1968 _m_parts.resize(sz);
1969 for(std::size_t i=0;i<sz;i++)
1970 _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1972 _part_def.resize(_m_parts.size());
1973 _mp_time=std::max(_mp_time,_m_time);
1976 void MEDFileUMeshAggregateCompute::declarePartsUpdated() const
1978 _mp_time=std::max(_mp_time,_m_time) + 1;
1982 const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1984 if(_mp_time<_m_time)
1985 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : the parts require a computation !");
1986 if(_m_parts.size()!=_part_def.size())
1987 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : size of arrays are expected to be the same !");
1988 std::size_t sz(_m_parts.size());
1989 for(std::size_t i=0;i<sz;i++)
1991 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1993 if(mesh->getCellModelEnum()==gt)
1994 return _part_def[i];
1996 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
1999 void MEDFileUMeshAggregateCompute::serialize(std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI) const
2001 if(_mp_time<_m_time)
2002 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
2003 std::size_t sz(_m_parts.size());
2004 tinyInt.push_back((mcIdType)sz);
2005 for(std::size_t i=0;i<sz;i++)
2007 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
2009 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
2010 tinyInt.push_back(mesh->getCellModelEnum());
2011 const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
2012 const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
2015 DataArrayIdType *elt(mesh1->getNodalConnectivity());
2018 MCAuto<DataArrayIdType> elt1(elt);
2019 bigArraysI.push_back(elt1);
2023 DataArrayIdType *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
2028 MCAuto<DataArrayIdType> elt11(elt1),elt22(elt2);
2029 bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
2032 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
2033 const PartDefinition *pd(_part_def[i]);
2035 tinyInt.push_back(-1);
2038 std::vector<mcIdType> tinyTmp;
2039 pd->serialize(tinyTmp,bigArraysI);
2040 tinyInt.push_back((mcIdType)tinyTmp.size());
2041 tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
2046 void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI)
2048 mcIdType nbParts(tinyInt.back()); tinyInt.pop_back();
2049 _part_def.clear(); _part_def.resize(nbParts);
2050 _m_parts.clear(); _m_parts.resize(nbParts);
2051 for(mcIdType i=0;i<nbParts;i++)
2053 INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
2054 MCAuto<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
2055 mesh->setCoords(coo);
2056 MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
2057 MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
2060 mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
2064 MCAuto<DataArrayIdType> elt0,elt1;
2065 elt0=bigArraysI.back(); bigArraysI.pop_back();
2066 elt1=bigArraysI.back(); bigArraysI.pop_back();
2067 mesh2->setNodalConnectivity(elt0,elt1);
2070 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
2072 mcIdType pdid(tinyInt.back()); tinyInt.pop_back();
2074 _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
2075 _mp_time=std::max(_mp_time,_m_time)+1;
2080 * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
2082 bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const
2084 return _mp_time>=_m_time;
2087 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
2089 if(_mp_time>_m_time)
2090 return getTimeOfParts();
2091 if(_m_time>_mp_time)
2092 return getTimeOfUMesh();
2093 return std::max(getTimeOfParts(),getTimeOfUMesh());
2096 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
2099 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2101 const MEDCoupling1GTUMesh *elt(*it);
2103 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
2104 ret=std::max(ret,elt->getTimeOfThis());
2107 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
2111 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
2113 const MEDCouplingUMesh *m(_m);
2115 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
2116 return m->getTimeOfThis();
2119 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
2121 std::size_t ret(_m_parts.size()*sizeof(MCAuto<MEDCoupling1GTUMesh>));
2125 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
2127 std::vector<const BigMemoryObject *> ret;
2128 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2129 ret.push_back((const MEDCoupling1GTUMesh *)*it);
2130 ret.push_back((const MEDCouplingUMesh *)_m);
2134 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCopy(DataArrayDouble *coords) const
2136 MEDFileUMeshAggregateCompute ret;
2137 ret._m_parts.resize(_m_parts.size());
2138 for(std::size_t i=0;i<_m_parts.size();i++)
2140 const MEDCoupling1GTUMesh *elt(_m_parts[i]);
2143 ret._m_parts[i]=static_cast<MEDCoupling::MEDCoupling1GTUMesh*>(elt->deepCopy());
2144 ret._m_parts[i]->setCoords(coords);
2147 ret._mp_time=_mp_time; ret._m_time=_m_time;
2148 if((const MEDCouplingUMesh *)_m)
2150 ret._m=static_cast<MEDCoupling::MEDCouplingUMesh*>(_m->deepCopy());
2151 ret._m->setCoords(coords);
2153 std::size_t sz(_part_def.size());
2154 ret._part_def.clear(); ret._part_def.resize(sz);
2155 for(std::size_t i=0;i<sz;i++)
2157 const PartDefinition *elt(_part_def[i]);
2159 ret._part_def[i]=elt->deepCopy();
2164 void MEDFileUMeshAggregateCompute::shallowCpyMeshes()
2166 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2168 const MEDCoupling1GTUMesh *elt(*it);
2171 MCAuto<MEDCouplingMesh> elt2(elt->clone(false));
2172 *it=DynamicCastSafe<MEDCouplingMesh,MEDCoupling1GTUMesh>(elt2);
2175 const MEDCouplingUMesh *m(_m);
2180 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
2182 const MEDCouplingUMesh *m1(getUmesh());
2183 const MEDCouplingUMesh *m2(other.getUmesh());
2184 if((m1==0 && m2!=0) || (m1!=0 && m2==0))
2186 what="Presence of mesh in one sublevel and not in other!";
2192 if(!m1->isEqualIfNotWhy(m2,eps,what2))
2194 what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
2198 std::size_t sz(_part_def.size());
2199 if(sz!=other._part_def.size())
2201 what=std::string("number of subdivision per geo type for part definition is not the same !");
2204 for(std::size_t i=0;i<sz;i++)
2206 const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
2209 if((!pd0 && pd1) || (pd0 && !pd1))
2211 what=std::string("a cell part def is defined only for one among this or other !");
2214 bool ret(pd0->isEqual(pd1,what));
2221 void MEDFileUMeshAggregateCompute::checkConsistency() const
2223 if(_mp_time >= _m_time)
2224 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();
2225 it!=_m_parts.end(); it++)
2226 (*it)->checkConsistency();
2228 _m->checkConsistency();
2231 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
2233 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2234 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
2235 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
2238 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
2240 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2242 const MEDCoupling1GTUMesh *tmp(*it);
2245 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
2246 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
2247 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
2248 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
2251 const MEDCouplingUMesh *m(_m);
2254 (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
2255 (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
2256 (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
2257 (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
2261 bool MEDFileUMeshAggregateCompute::empty() const
2263 if(_mp_time<_m_time)
2264 return ((const MEDCouplingUMesh *)_m)==0;
2265 //else _mp_time>=_m_time)
2266 return _m_parts.empty();
2269 int MEDFileUMeshAggregateCompute::getMeshDimension() const
2271 if(_mp_time<_m_time)
2273 const MEDCouplingUMesh *m(_m);
2275 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
2276 return m->getMeshDimension();
2280 if(_m_parts.empty())
2281 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
2282 const MEDCoupling1GTUMesh *m(_m_parts[0]);
2284 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
2285 return m->getMeshDimension();
2289 std::vector<mcIdType> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
2291 if(_mp_time<_m_time)
2293 const MEDCouplingUMesh *m(_m);
2295 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
2296 return m->getDistributionOfTypes();
2300 std::vector<mcIdType> ret;
2301 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2303 const MEDCoupling1GTUMesh *tmp(*it);
2305 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
2306 std::vector<mcIdType> ret0(tmp->getDistributionOfTypes());
2307 ret.insert(ret.end(),ret0.begin(),ret0.end());
2313 mcIdType MEDFileUMeshAggregateCompute::getSize() const
2315 if(_mp_time<_m_time)
2317 const MEDCouplingUMesh *m(_m);
2319 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
2320 return m->getNumberOfCells();
2325 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2327 const MEDCoupling1GTUMesh *m(*it);
2329 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
2330 ret+=m->getNumberOfCells();
2336 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
2338 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2340 MEDCoupling1GTUMesh *tmp(*it);
2342 (*it)->setCoords(coords);
2344 MEDCouplingUMesh *m(_m);
2346 m->setCoords(coords);
2349 MEDFileEltStruct4Mesh *MEDFileEltStruct4Mesh::New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs)
2351 return new MEDFileEltStruct4Mesh(fid,mName,dt,it,iterOnStEltOfMesh,mrs);
2354 std::size_t MEDFileEltStruct4Mesh::getHeapMemorySizeWithoutChildren() const
2356 return _geo_type_name.capacity()+_vars.capacity()*sizeof(MCAuto<DataArray>);
2359 std::vector<const MEDCoupling::BigMemoryObject*> MEDFileEltStruct4Mesh::getDirectChildrenWithNull() const
2361 std::vector<const MEDCoupling::BigMemoryObject*> ret;
2362 ret.push_back(_conn);
2363 ret.push_back(_common);
2364 for(std::vector< MCAuto<DataArray> >::const_iterator it=_vars.begin();it!=_vars.end();it++)
2369 MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs)
2371 med_geometry_type geoType;
2372 INTERP_KERNEL::AutoPtr<char> geoTypeName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2373 MEDFILESAFECALLERRD0(MEDmeshEntityInfo,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,iterOnStEltOfMesh+1,geoTypeName,&geoType));
2375 _geo_type_name=MEDLoaderBase::buildStringFromFortran(geoTypeName,MED_NAME_SIZE);
2378 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
2379 nCells=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,geoType,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
2381 MCAuto<MEDFileMeshSupports> mss(MEDFileMeshSupports::New(fid));
2382 MCAuto<MEDFileStructureElements> mse(MEDFileStructureElements::New(fid,mss));
2383 mcIdType nbEntities(mse->getNumberOfNodesPerSE(_geo_type_name));
2384 MCAuto<DataArrayMedInt> miConn=DataArrayMedInt::New(); miConn->alloc(nCells*nbEntities);
2385 MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,_geo_type,MED_NODAL,MED_FULL_INTERLACE,miConn->getPointer()));
2386 _conn=FromMedIntArray<mcIdType>(miConn);
2387 _conn->applyLin(1,-1);
2388 _conn->rearrange(nbEntities);
2389 _common=MEDFileUMeshPerTypeCommon::New();
2390 _common->loadCommonPart(fid,mName.c_str(),dt,it,nCells,geoType,MED_STRUCT_ELEMENT,mrs);
2391 std::vector<std::string> vns(mse->getVarAttsOf(_geo_type_name));
2392 std::size_t sz(vns.size());
2394 for(std::size_t i=0;i<sz;i++)
2396 const MEDFileSEVarAtt *var(mse->getVarAttOf(_geo_type_name,vns[i]));
2397 MCAuto<DataArray> gen(var->getGenerator());
2398 MCAuto<DataArray> arr(gen->buildNewEmptyInstance());
2399 arr->alloc(nCells,var->getNbOfComponents());
2400 arr->setName(vns[i]);
2401 MEDFILESAFECALLERRD0(MEDmeshStructElementVarAttRd,(fid,mName.c_str(),dt,it,_geo_type,vns[i].c_str(),arr->getVoidStarPointer()));