1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "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"
37 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
38 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
39 extern med_geometry_type typmainoeud[1];
41 using namespace MEDCoupling;
43 const char MEDFileMeshL2::ZE_SEP_FOR_FAMILY_KILLERS[]="!/__\\!";//important start by - because ord('!')==33 the smallest (!=' ') to preserve orders at most.
45 int MEDFileMeshL2::ZE_SEP2_FOR_FAMILY_KILLERS=4;
47 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
49 med_mesh_type type_maillage;
50 med_int spaceDim, meshDim, nbSteps;
51 med_sorting_type stype;
52 med_axis_type axistype;
53 med_int naxis(MEDmeshnAxis(fid,getID()));
54 INTERP_KERNEL::AutoPtr<char> nameTmp(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
55 INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
56 INTERP_KERNEL::AutoPtr<char> axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
57 INTERP_KERNEL::AutoPtr<char> univTmp(MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE));
58 if(MEDmeshInfo(fid,getID(),nameTmp,&spaceDim,&meshDim,&type_maillage,description.getPointer(),dtunit.getPointer(),
59 &stype,&nbSteps,&axistype,axisname,axisunit)!=0)
60 throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
61 Mdim=FromMedInt<int>(meshDim);
62 nstep=FromMedInt<int>(nbSteps);
63 MEDmeshUniversalNameRd(fid,nameTmp,univName.getPointer());// do not protect MEDFILESAFECALLERRD0 call : Thanks to fra.med.
64 axType=MEDFileMeshL2::TraduceAxisType(axistype);
67 case MED_UNSTRUCTURED_MESH:
68 meshType=UNSTRUCTURED;
70 case MED_STRUCTURED_MESH:
73 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>));
76 case MED_CARTESIAN_GRID:
79 case MED_CURVILINEAR_GRID:
80 meshType=CURVE_LINEAR;
82 case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
86 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
91 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
94 std::vector<std::string> infosOnComp(naxis);
95 for(int i=0;i<naxis;i++)
97 std::string info(MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE));
103 double MeshCls::checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const
108 std::vector< std::pair<int,int> > p(nstep);
109 for(int i=0;i<nstep;i++)
111 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),i+1,&numdt,&numit,&dtt));
112 p[i]=std::make_pair((int)numdt,(int)numit);
113 found=(numdt==dt) && (numit==it);
118 std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! ";
119 oss << "Possibilities are : ";
120 for(int i=0;i<nstep;i++)
121 oss << "(" << p[i].first << "," << p[i].second << "), ";
122 throw INTERP_KERNEL::Exception(oss.str().c_str());
127 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
129 INTERP_KERNEL::AutoPtr<char> msn(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
130 INTERP_KERNEL::AutoPtr<char> zeDescription(MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE));
131 med_axis_type medAxType;
132 med_int nAxis(MEDsupportMeshnAxis(fid,getID()));
133 INTERP_KERNEL::AutoPtr<char> axisName(new char[MED_SNAME_SIZE*nAxis+1]),axisUnit(new char[MED_SNAME_SIZE*nAxis+1]);
134 med_int spaceDim(0),meshDim(0);
135 MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,getID(),msn,&spaceDim,&meshDim,zeDescription,&medAxType,axisName,axisUnit));
136 std::string descriptionCpp(MEDLoaderBase::buildStringFromFortran(zeDescription,MED_COMMENT_SIZE));
137 description.set(descriptionCpp.c_str());
138 dtunit.clear(); univName.clear(); meshType=UNSTRUCTURED; nstep=1;
139 axType=MEDFileMeshL2::TraduceAxisType(medAxType);
141 //med_bool chgt=MED_FALSE,trsf=MED_FALSE;
142 //nmodels=MEDmeshnEntity(fid,_name.c_str(),MED_NO_DT,MED_NO_IT,MED_STRUCT_ELEMENT,MED_GEO_ALL,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
143 std::vector<std::string> ret;
144 for(int i=0;i<nAxis;i++)
146 std::string info(DataArray::BuildInfoFromVarAndUnit(MEDLoaderBase::buildStringFromFortran(axisName+i*MED_SNAME_SIZE,MED_SNAME_SIZE),
147 MEDLoaderBase::buildStringFromFortran(axisUnit+i*MED_SNAME_SIZE,MED_SNAME_SIZE)));
153 double StructMeshCls::checkMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it) const
158 MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
162 std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const
167 std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull() const
169 return std::vector<const BigMemoryObject *>();
172 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)
174 med_mesh_type type_maillage;
175 char maillage_description[MED_COMMENT_SIZE+1];
176 char dtunit[MED_LNAME_SIZE+1];
177 med_int spaceDim,dim;
178 char nommaa[MED_NAME_SIZE+1];
179 med_int n=MEDnMesh(fid);
182 med_sorting_type stype;
183 std::vector<std::string> ms;
185 med_axis_type axistype;
186 for(int i=0;i<n && found==0;i++)
188 med_int naxis(MEDmeshnAxis(fid,i+1));
189 INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
190 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
191 dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
192 std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)));
201 {//last chance ! Is it a support mesh ?
202 med_int nbSM(MEDnSupportMesh(fid));
203 for(int i=0;i<nbSM && found==0;i++)
205 med_int naxis(MEDsupportMeshnAxis(fid,i+1));
206 INTERP_KERNEL::AutoPtr<char> axisname(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE)),axisunit(MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE));
207 MEDFILESAFECALLERRD0(MEDsupportMeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,maillage_description,&axistype,axisname,axisunit));
208 std::string cur(MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa)));
217 ////////////////////////
222 axType=TraduceAxisType(axistype);
223 switch(type_maillage)
225 case MED_UNSTRUCTURED_MESH:
226 meshType=UNSTRUCTURED;
228 case MED_STRUCTURED_MESH:
231 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>));
234 case MED_CARTESIAN_GRID:
237 case MED_CURVILINEAR_GRID:
238 meshType=CURVE_LINEAR;
240 case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
244 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
249 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
253 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),1,&numdt,&numit,&dtt));
254 dt=FromMedInt<int>(numdt); it=FromMedInt<int>(numit);
255 return new MeshCls(ret);
259 meshType=UNSTRUCTURED;
260 dt=MED_NO_DT; it=MED_NO_IT; dtunit1.clear();
261 axType=TraduceAxisType(axistype);
262 return new StructMeshCls(ret);
266 std::ostringstream oss;
267 oss << "No such meshname (" << mName << ") in file ! Must be in : ";
268 std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
269 throw INTERP_KERNEL::Exception(oss.str().c_str());
276 * non static and non const method because _description, _dt_unit... are set in this method.
278 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)
280 return mId->getAxisInfoOnMesh(fid,mName,meshType,axType,nstep,Mdim,_description,_dt_unit,_univ_name);
283 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)
285 if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading()))
287 char nomfam[MED_NAME_SIZE+1];
289 med_int nfam=MEDnFamily(fid,meshName.c_str());
290 std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > > crudeFams(nfam);
291 for(int i=0;i<nfam;i++)
293 med_int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
294 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
295 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
296 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
297 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
298 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
299 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
300 std::string famName(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
301 std::vector<std::string> grps(ngro);
302 for(int j=0;j<ngro;j++)
303 grps[j]=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
304 crudeFams[i]=std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > >(famName,std::pair<mcIdType,std::vector<std::string> >(numfam,grps));
306 RenameFamiliesFromFileToMemInternal(crudeFams);
307 for(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >::const_iterator it0=crudeFams.begin();it0!=crudeFams.end();it0++)
309 fams[(*it0).first]=(*it0).second.first;
310 for(std::vector<std::string>::const_iterator it1=(*it0).second.second.begin();it1!=(*it0).second.second.end();it1++)
311 grps[*it1].push_back((*it0).first);
315 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)
317 std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > > crudeFams(fams.size());
319 for(std::map<std::string,mcIdType>::const_iterator it=fams.begin();it!=fams.end();it++,ii++)
321 std::vector<std::string> grpsOfFam;
322 for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
324 if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
325 grpsOfFam.push_back((*it1).first);
327 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));
329 RenameFamiliesFromMemToFileInternal(crudeFams);
330 for(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++)
332 std::size_t ngro((*it).second.second.size());
333 INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
335 for(std::vector<std::string>::const_iterator it2=(*it).second.second.begin();it2!=(*it).second.second.end();it2++,i++)
336 MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE,groName+i*MED_LNAME_SIZE,tooLongStrPol);
337 INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
338 MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
339 med_int ret=MEDfamilyCr(fid,mname.c_str(),famName,ToMedInt((*it).second.first),ToMedInt(ngro),groName);
344 void MEDFileMeshL2::RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func)
347 std::vector<std::string> fams(crudeFams.size());
348 for(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
349 fams[ii]=(*it).first;
353 for(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >::iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
354 (*it).first=fams[ii];
358 * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
359 * So this method renames families (if needed generally not !) in order to have a discriminant name for families.
361 void MEDFileMeshL2::RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams)
363 RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromFileToMem);
366 bool MEDFileMeshL2::RenameFamiliesFromFileToMem(std::vector< std::string >& famNames)
368 std::map<std::string,mcIdType> m;
369 std::set<std::string> s;
370 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
372 if(s.find(*it)!=s.end())
377 return false;// the general case !
378 for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
380 std::map<std::string,mcIdType>::iterator it2(m.find(*it));
383 std::ostringstream oss; oss << *it << ZE_SEP_FOR_FAMILY_KILLERS << std::setfill('0') << std::setw(ZE_SEP2_FOR_FAMILY_KILLERS) << (*it2).second++;
391 * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
392 * So this method renames families (if needed generally not !) in order to have a discriminant name for families.
394 void MEDFileMeshL2::RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<mcIdType,std::vector<std::string> > > >& crudeFams)
396 RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromMemToFile);
399 bool MEDFileMeshL2::RenameFamiliesFromMemToFile(std::vector< std::string >& famNames)
401 bool isSmthingStrange(false);
402 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
404 std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
405 if(found!=std::string::npos)
406 isSmthingStrange=true;
408 if(!isSmthingStrange)
411 std::map< std::string, std::vector<std::string> > m;
412 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
414 std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
415 if(found!=std::string::npos && found>=1)
417 std::string s1((*it).substr(found+sizeof(ZE_SEP_FOR_FAMILY_KILLERS)-1));
418 if((int)s1.size()!=ZE_SEP2_FOR_FAMILY_KILLERS)
421 std::istringstream iss(s1);
423 bool isOK((iss.rdstate() & ( std::istream::failbit | std::istream::eofbit)) == std::istream::eofbit);
426 std::string s0((*it).substr(0,found));
427 m[s0].push_back(*it);
434 std::map<std::string,std::string> zeMap;
435 for(std::map< std::string, std::vector<std::string> >::const_iterator it=m.begin();it!=m.end();it++)
437 if((*it).second.size()==1)
439 for(std::vector<std::string>::const_iterator it1=(*it).second.begin();it1!=(*it).second.end();it1++)
440 zeMap[*it1]=(*it).first;
445 for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
447 std::map<std::string,std::string>::iterator it1(zeMap.find(*it));
454 MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisType(med_axis_type at)
460 case MED_CYLINDRICAL:
464 case MED_UNDEF_AXIS_TYPE:
467 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisType : unrecognized axis type !");
471 MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisTypeStruct(med_grid_type gt)
475 case MED_CARTESIAN_GRID:
480 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeStruct : only Cartesian and Cylindrical supported by MED file !");
484 med_axis_type MEDFileMeshL2::TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at)
489 return MED_CARTESIAN;
491 return MED_CYLINDRICAL;
493 return MED_SPHERICAL;
495 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRev : unrecognized axis type !");
499 med_grid_type MEDFileMeshL2::TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at)
504 return MED_CARTESIAN_GRID;
506 return MED_POLAR_GRID;
508 return MED_POLAR_GRID;
510 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRevStruct : unrecognized axis type !");
514 MEDFileUMeshL2::MEDFileUMeshL2()
518 std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, int& Mdim)
521 _name.set(mName.c_str());
523 MEDCoupling::MEDCouplingMeshType meshType;
524 MEDCoupling::MEDCouplingAxisType dummy3;
525 std::vector<std::string> ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
529 return std::vector<std::string>();
531 if(meshType!=UNSTRUCTURED)
532 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
533 _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
539 void MEDFileUMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
542 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
545 loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency
546 loadCoords(fid,infosOnComp,mName,dt,it);
549 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)
552 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
555 loadPartOfConnectivity(fid,Mdim,mName,types,slicPerTyp,dt,it,mrs);
556 med_bool changement,transformation;
557 mcIdType nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
558 std::vector<bool> fetchedNodeIds(nCoords,false);
559 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
560 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
561 (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds);
562 mcIdType nMin(ToIdType(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true))));
563 mcIdType nMax(ToIdType(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true))));
565 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
566 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
567 (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin);
568 loadPartCoords(fid,infosOnComp,mName,dt,it,nMin,nMax);
571 void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
573 _per_type_mesh.resize(1);
574 _per_type_mesh[0].clear();
575 for(int j=0;j<MED_N_CELL_FIXED_GEO;j++)
577 MEDFileUMeshPerType *tmp(MEDFileUMeshPerType::New(fid,mName.c_str(),dt,it,mdim,typmai[j],typmai2[j],mrs));
579 _per_type_mesh[0].push_back(tmp);
584 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)
586 std::size_t nbOfTypes(types.size());
587 if(slicPerTyp.size()!=3*nbOfTypes)
588 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : The size of slicPerTyp array is expected to be equal to 3 times size of array types !");
589 std::set<INTERP_KERNEL::NormalizedCellType> types2(types.begin(),types.end());
590 if(types2.size()!=nbOfTypes)
591 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : the geometric types in types array must appear once !");
592 _per_type_mesh.resize(1);
593 _per_type_mesh[0].clear();
594 for(std::size_t ii=0;ii<nbOfTypes;ii++)
596 mcIdType strt(slicPerTyp[3*ii+0]),stp(slicPerTyp[3*ii+1]),step(slicPerTyp[3*ii+2]);
597 MCAuto<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs));
598 _per_type_mesh[0].push_back(tmp);
603 void MEDFileUMeshL2::loadCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it)
605 int spaceDim((int)infosOnComp.size());
606 med_bool changement,transformation;
607 med_int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
608 _coords=DataArrayDouble::New();
609 _coords->alloc(nCoords,spaceDim);
610 double *coordsPtr(_coords->getPointer());
612 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,coordsPtr));
613 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
615 MCAuto<DataArrayMedInt> miFamCoord=DataArrayMedInt::New();
616 miFamCoord->alloc(nCoords,1);
617 MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miFamCoord->getPointer()));
618 _fam_coords=FromMedIntArray<mcIdType>(miFamCoord);
622 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
624 MCAuto<DataArrayMedInt> miNumCoord=DataArrayMedInt::New();
625 miNumCoord->alloc(nCoords,1);
626 MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miNumCoord->getPointer()));
627 _num_coords=FromMedIntArray<mcIdType>(miNumCoord);
631 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
633 _name_coords=DataArrayAsciiChar::New();
634 _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
635 MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
636 _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
640 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_GLOBAL_NUMBER,MED_NODAL,&changement,&transformation)>0)
642 MCAuto<DataArrayMedInt> miNumCoord=DataArrayMedInt::New();
643 miNumCoord->alloc(nCoords,1);
644 MEDFILESAFECALLERRD0(MEDmeshGlobalNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,miNumCoord->getPointer()));
645 _global_num_coords=FromMedIntArray<mcIdType>(miNumCoord);
647 for(int i=0;i<spaceDim;i++)
648 _coords->setInfoOnComponent(i,infosOnComp[i]);
651 void MEDFileUMeshL2::loadPartCoords(med_idt fid, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, mcIdType nMin, mcIdType nMax)
653 med_bool changement,transformation;
654 med_int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
655 _coords=DataArrayDouble::New();
656 mcIdType nbNodesToLoad(nMax-nMin);
657 _coords->alloc(nbNodesToLoad,spaceDim);
658 med_filter filter=MED_FILTER_INIT,filter2=MED_FILTER_INIT;
659 MEDfilterBlockOfEntityCr(fid,/*nentity*/nCoords,/*nvaluesperentity*/1,/*nconstituentpervalue*/spaceDim,
660 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
661 /*start*/ToMedInt(nMin+1),/*stride*/1,/*count*/1,/*blocksize*/ToMedInt(nbNodesToLoad),
662 /*lastblocksize=useless because count=1*/0,&filter);
663 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateAdvancedRd,(fid,mName.c_str(),dt,it,&filter,_coords->getPointer()));
664 _part_coords=PartDefinition::New(nMin,nMax,1);
665 MEDfilterClose(&filter);
666 MEDfilterBlockOfEntityCr(fid,nCoords,1,1,MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,
667 MED_NO_PROFILE,ToMedInt(nMin+1),1,1,ToMedInt(nbNodesToLoad),0,&filter2);
668 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
670 MCAuto<DataArrayMedInt> miFamCoord=DataArrayMedInt::New();
671 miFamCoord->alloc(nbNodesToLoad,1);
672 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,miFamCoord->getPointer()));
673 _fam_coords=FromMedIntArray<mcIdType>(miFamCoord);
677 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
679 MCAuto<DataArrayMedInt> miNumCoord=DataArrayMedInt::New();
680 miNumCoord->alloc(nbNodesToLoad,1);
681 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,miNumCoord->getPointer()));
682 _num_coords=FromMedIntArray<mcIdType>(miNumCoord);
686 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
688 _name_coords=DataArrayAsciiChar::New();
689 _name_coords->alloc(nbNodesToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
690 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NAME,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_name_coords->getPointer()));
691 _name_coords->reAlloc(nbNodesToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
695 MEDfilterClose(&filter2);
696 _coords->setInfoOnComponents(infosOnComp);
699 void MEDFileUMeshL2::sortTypes()
702 std::vector< MCAuto<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
703 _per_type_mesh.clear();
704 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
705 mdims.insert((*it)->getDim());
708 int mdim=*mdims.rbegin();
709 _per_type_mesh.resize(mdim+1);
710 for(int dim=mdim+1;dim!=0;dim--)
712 std::vector< MCAuto<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
713 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
714 if((*it)->getDim()==dim-1)
717 // suppression of contiguous empty levels at the end of _per_type_mesh.
718 int nbOfUselessLev=0;
720 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
722 if((*it2).empty() && isFirst)
729 _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
732 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)
736 MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,ToMedInt(coords->getNumberOfTuples()),coords->begin()));
738 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(famCoords->getNumberOfTuples()),ToMedIntArray<mcIdType>(famCoords)->begin()));
740 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(numCoords->getNumberOfTuples()),ToMedIntArray<mcIdType>(numCoords)->begin()));
743 if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
745 std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
746 oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
747 throw INTERP_KERNEL::Exception(oss.str().c_str());
749 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,ToMedInt(nameCoords->getNumberOfTuples()),nameCoords->begin()));
752 MEDFILESAFECALLERWR0(MEDmeshGlobalNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NONE,ToMedInt(globalNumCoords->getNumberOfTuples()),ToMedIntArray<mcIdType>(globalNumCoords)->begin()));
755 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
757 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
758 if((*it)->getFam()==0)
763 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
765 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
766 if((*it)->getNum()==0)
771 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
773 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
774 if((*it)->getNames()==0)
779 MEDFileCMeshL2::MEDFileCMeshL2():_ax_type(AX_CART)
783 void MEDFileCMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it)
785 _name.set(mName.c_str());
788 MEDCoupling::MEDCouplingMeshType meshType;
789 MEDCoupling::MEDCouplingAxisType dummy3;
790 std::vector<std::string> infosOnComp(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
791 if(meshType!=CARTESIAN)
792 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
793 _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
797 med_grid_type gridtype;
798 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype));
799 if(gridtype!=MED_CARTESIAN_GRID && gridtype!=MED_POLAR_GRID)
800 throw INTERP_KERNEL::Exception("Invalid rectilinear mesh ! Only cartesian and polar are supported !");
801 _ax_type=TraduceAxisTypeStruct(gridtype);
802 _cmesh=MEDCouplingCMesh::New();
803 for(int i=0;i<Mdim;i++)
805 med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
806 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
807 med_int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf));
808 MCAuto<DataArrayDouble> da=DataArrayDouble::New();
809 da->alloc(nbOfElt,1);
810 da->setInfoOnComponent(0,infosOnComp[i]);
811 MEDFILESAFECALLERRD0(MEDmeshGridIndexCoordinateRd,(fid,mName.c_str(),dt,it,i+1,da->getPointer()));
812 _cmesh->setCoordsAt(i,da);
816 med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id)
821 return MED_COORDINATE_AXIS1;
823 return MED_COORDINATE_AXIS2;
825 return MED_COORDINATE_AXIS3;
827 throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
831 MEDFileCLMeshL2::MEDFileCLMeshL2()
835 void MEDFileCLMeshL2::loadAll(med_idt fid, const MeshOrStructMeshCls *mId, const std::string& mName, int dt, int it)
837 _name.set(mName.c_str());
840 MEDCoupling::MEDCouplingMeshType meshType;
841 MEDCoupling::MEDCouplingAxisType dummy3;
842 std::vector<std::string> infosOnComp(getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim));
843 if(meshType!=CURVE_LINEAR)
844 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
845 _time=mId->checkMeshTimeStep(fid,mName,nstep,dt,it);
849 _clmesh=MEDCouplingCurveLinearMesh::New();
850 MCAuto<DataArrayMedInt> miStGrid=DataArrayMedInt::New();
851 miStGrid->alloc(Mdim,1);
852 MEDFILESAFECALLERRD0(MEDmeshGridStructRd,(fid,mName.c_str(),dt,it,miStGrid->getPointer()));
853 MCAuto<DataArrayIdType> stGrid=FromMedIntArray<mcIdType>(miStGrid);
854 _clmesh->setNodeGridStructure(stGrid->begin(),stGrid->end());
855 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
856 med_int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf));
857 MCAuto<DataArrayDouble> da=DataArrayDouble::New();
858 da->alloc(nbNodes,infosOnComp.size());
859 da->setInfoOnComponents(infosOnComp);
860 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer()));
861 _clmesh->setCoords(da);
864 MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
869 * Warning it returns an instance to deallocate !!!!
871 MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
873 _st->_num->updateTime();
874 if((MEDCouplingUMesh *)_m==0)
877 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
878 _m->renumberCells(_st->_num->begin(),true);
883 if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
888 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
889 _m->renumberCells(_st->_num->begin(),true);
895 void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
900 void MEDFileUMeshPermCompute::updateTime() const
902 _mpt_time=_st->_m_by_types.getTimeOfThis();
903 _num_time=_st->_num->getTimeOfThis();
906 std::vector<const BigMemoryObject *> MEDFileUMeshPermCompute::getDirectChildrenWithNull() const
908 std::vector<const BigMemoryObject *> ret;
909 ret.push_back((const MEDCouplingUMesh *)_m);
913 std::size_t MEDFileUMeshPermCompute::getHeapMemorySizeWithoutChildren() const
915 return sizeof(MEDFileUMeshPermCompute);
918 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)
922 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this)
924 const std::vector< MCAuto<MEDFileUMeshPerType> >& v=l2.getLev(id);
927 std::size_t sz=v.size();
928 std::vector<const MEDCoupling1GTUMesh *> ms(sz);
929 std::vector<const DataArrayIdType *> fams(sz),nums(sz);
930 std::vector<const DataArrayChar *> names(sz);
931 std::vector<const PartDefinition *> pds(sz);
932 for(std::size_t i=0;i<sz;i++)
934 MEDCoupling1GTUMesh *elt(v[i]->getMesh());
935 MCAuto<DataArrayDouble> tmp2=l2.getCoords();
936 elt->setCoords(tmp2);
938 pds[i]=v[i]->getPartDef();
940 _m_by_types.assignParts(ms);
941 _m_by_types.assignDefParts(pds);
942 if(l2.isFamDefinedOnLev(id))
944 for(std::size_t i=0;i<sz;i++)
945 fams[i]=v[i]->getFam();
947 _fam=DataArrayIdType::Aggregate(fams);
951 _fam=const_cast<DataArrayIdType *>(fams[0]);
954 if(l2.isNumDefinedOnLev(id))
956 for(std::size_t i=0;i<sz;i++)
957 nums[i]=v[i]->getNum();
959 _num=DataArrayIdType::Aggregate(nums);
963 _num=const_cast<DataArrayIdType *>(nums[0]);
967 if(l2.isNamesDefinedOnLev(id))
969 for(std::size_t i=0;i<sz;i++)
970 names[i]=v[i]->getNames();
971 _names=dynamic_cast<DataArrayAsciiChar *>(DataArrayChar::Aggregate(names));
975 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m):_m(this)
977 std::vector< const MEDCoupling1GTUMesh * > v(1);
982 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
987 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
989 assignMesh(m,newOrOld);
992 void MEDFileUMeshSplitL1::setName(const std::string& name)
994 _m_by_types.setName(name);
997 std::size_t MEDFileUMeshSplitL1::getHeapMemorySizeWithoutChildren() const
1002 std::vector<const BigMemoryObject *> MEDFileUMeshSplitL1::getDirectChildrenWithNull() const
1004 std::vector<const BigMemoryObject *> ret;
1005 ret.push_back(&_m_by_types);
1007 ret.push_back((const DataArrayIdType*)_fam);
1008 ret.push_back((const DataArrayIdType*)_num);
1009 ret.push_back((const DataArrayIdType*)_rev_num);
1010 ret.push_back((const DataArrayAsciiChar*)_names);
1014 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::shallowCpyUsingCoords(DataArrayDouble *coords) const
1016 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
1017 ret->_m_by_types.shallowCpyMeshes();
1018 ret->_m_by_types.setCoords(coords);
1022 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCopy(DataArrayDouble *coords) const
1024 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
1025 ret->_m_by_types=_m_by_types.deepCopy(coords);
1026 if((const DataArrayIdType *)_fam)
1027 ret->_fam=_fam->deepCopy();
1028 if((const DataArrayIdType *)_num)
1029 ret->_num=_num->deepCopy();
1030 if((const DataArrayIdType *)_rev_num)
1031 ret->_rev_num=_rev_num->deepCopy();
1032 if((const DataArrayAsciiChar *)_names)
1033 ret->_names=_names->deepCopy();
1037 void MEDFileUMeshSplitL1::checkConsistency() const
1039 if (!_fam || _fam->getNumberOfTuples() != getSize())
1040 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): internal family array has an invalid size!");
1041 mcIdType nbCells = getSize();
1044 _num->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array!");
1046 mcIdType maxValue=_num->getMaxValue(pos);
1047 if (!_rev_num || _rev_num->getNumberOfTuples() != (maxValue+1))
1048 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal revert node numbering array!");
1050 if ((_num && !_rev_num) || (!_num && _rev_num))
1051 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal numbering arrays (one is null)!");
1052 if (_num && !_num->hasUniqueValues())
1053 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array: duplicates found!");
1055 _names->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): internal cell naming array has an invalid size!");
1057 _m_by_types.checkConsistency();
1060 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
1062 if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
1064 const DataArrayIdType *d1=_fam;
1065 const DataArrayIdType *d2=other->_fam;
1066 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
1068 what="Presence of family arr in one sublevel and not in other!";
1072 if(!d1->isEqual(*d2))
1074 what="family arr at a sublevel are not deeply equal !";
1079 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
1081 what="Presence of cell numbering arr in one sublevel and not in other!";
1085 if(!d1->isEqual(*d2))
1087 what="Numbering cell arr at a sublevel are not deeply equal !";
1090 const DataArrayAsciiChar *e1=_names;
1091 const DataArrayAsciiChar *e2=other->_names;
1092 if((e1==0 && e2!=0) || (e1!=0 && e2==0))
1094 what="Presence of cell names arr in one sublevel and not in other!";
1098 if(!e1->isEqual(*e2))
1100 what="Name cell arr at a sublevel are not deeply equal !";
1106 void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
1108 _m_by_types.synchronizeTinyInfo(master);
1111 void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
1113 _m_by_types.clearNonDiscrAttributes();
1116 void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
1120 (const_cast<MEDCouplingMesh *>(tmp))->setName("");
1121 (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
1122 (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
1123 (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
1126 void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords)
1128 _m_by_types.setCoords(coords);
1131 void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
1137 _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCopy()));
1138 MCAuto<DataArrayIdType> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
1139 if(!da->isIota(m->getNumberOfCells()))
1141 _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
1144 _m_by_types.getUmesh()->renumberCells(da->begin(),false);
1149 if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
1150 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh(): the mesh does not follow the MED file numbering convention! Invoke sortCellsInMEDFileFrmt() first!");
1152 _m_by_types.assignUMesh(m);
1157 void MEDFileUMeshSplitL1::forceComputationOfParts() const
1159 _m_by_types.forceComputationOfPartsFromUMesh();
1162 void MEDFileUMeshSplitL1::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1164 _m_by_types.assignParts(mParts);
1168 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this)
1172 void MEDFileUMeshSplitL1::assignCommonPart()
1174 _fam=DataArrayIdType::New();
1175 _fam->alloc(_m_by_types.getSize(),1);
1176 _fam->fillWithValue(0);
1179 bool MEDFileUMeshSplitL1::empty() const
1181 return _m_by_types.empty();
1184 bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector<mcIdType>& ids) const
1186 const DataArrayIdType *fam=_fam;
1189 return fam->presenceOfValue(ids);
1192 int MEDFileUMeshSplitL1::getMeshDimension() const
1194 return _m_by_types.getMeshDimension();
1197 void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const
1199 std::vector<mcIdType> code=_m_by_types.getDistributionOfTypes();
1200 std::size_t nbOfTypes=code.size()/3;
1201 for(std::size_t i=0;i<nbOfTypes;i++)
1203 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType) code[3*i];
1204 oss << " - Number of cells with type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr() << " : " << code[3*i+1] << std::endl;
1208 mcIdType MEDFileUMeshSplitL1::getSize() const
1210 return _m_by_types.getSize();
1213 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const mcIdType *idsBg, const mcIdType *idsEnd, bool renum) const
1215 MCAuto<DataArrayIdType> eltsToKeep=_fam->findIdsEqualList(idsBg,idsEnd);
1216 MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->begin(),eltsToKeep->end(),true);
1218 return renumIfNeeded(m,eltsToKeep->begin());
1222 DataArrayIdType *MEDFileUMeshSplitL1::getFamilyPartArr(const mcIdType *idsBg, const mcIdType *idsEnd, bool renum) const
1224 MCAuto<DataArrayIdType> da=_fam->findIdsEqualList(idsBg,idsEnd);
1226 return renumIfNeededArr(da);
1230 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes() const
1232 return _m_by_types.getGeoTypes();
1235 mcIdType MEDFileUMeshSplitL1::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1237 return _m_by_types.getNumberOfCellsWithType(ct);
1240 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
1242 MCAuto<MEDCouplingUMesh> tmp;
1243 if(renum && ((const DataArrayIdType *)_num))
1246 { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
1250 mcIdType MEDFileUMeshSplitL1::getNumberOfCells() const
1252 return _m_by_types.getNumberOfCells();
1255 DataArrayIdType *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
1257 const DataArrayIdType *fam(_fam);
1260 mcIdType start(0),stop(0);
1261 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
1262 return fam->selectByTupleIdSafeSlice(start,stop,1);
1265 DataArrayIdType *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
1267 const DataArrayIdType *num(_num);
1270 mcIdType start(0),stop(0);
1271 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
1272 return num->selectByTupleIdSafeSlice(start,stop,1);
1275 DataArrayIdType *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
1277 if((DataArrayIdType *)_fam)
1279 mcIdType nbOfTuples=_m_by_types.getSize();
1280 _fam=DataArrayIdType::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
1284 const DataArrayIdType *MEDFileUMeshSplitL1::getFamilyField() const
1289 const DataArrayIdType *MEDFileUMeshSplitL1::getNumberField() const
1294 const DataArrayIdType *MEDFileUMeshSplitL1::getRevNumberField() const
1299 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
1304 const PartDefinition *MEDFileUMeshSplitL1::getPartDef(INTERP_KERNEL::NormalizedCellType gt) const
1306 return _m_by_types.getPartDefOfWithoutComputation(gt);
1309 void MEDFileUMeshSplitL1::eraseFamilyField()
1311 _fam->fillWithZero();
1315 * This method ignores _m and _m_by_types.
1317 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,mcIdType>& familyIds,
1318 std::map<std::string, std::vector<std::string> >& groups)
1320 std::vector< DataArrayIdType * > corr;
1321 _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
1322 std::vector< MCAuto<DataArrayIdType> > corrMSafe(corr.begin(),corr.end());
1323 std::vector< std::vector<mcIdType> > fidsOfGroups;
1324 std::vector< const DataArrayIdType * > corr2(corr.begin(),corr.end());
1325 _fam=DataArrayIdType::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
1326 mcIdType nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
1327 std::map<mcIdType,std::string> newfams;
1328 std::map<mcIdType,mcIdType> famIdTrad;
1329 TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
1330 mcIdType *w=_fam->getPointer();
1331 for(mcIdType i=0;i<nbOfCells;i++,w++)
1335 void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const
1337 std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1339 for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
1341 mcIdType nbCells=(*it)->getNumberOfCells();
1342 mcIdType end=start+nbCells;
1343 MCAuto<DataArrayIdType> fam,num;
1344 MCAuto<DataArrayAsciiChar> names;
1345 if((const DataArrayIdType *)_fam)
1346 fam=_fam->subArray(start,end);
1347 if((const DataArrayIdType *)_num)
1348 num=_num->subArray(start,end);
1349 if((const DataArrayAsciiChar *)_names)
1350 names=static_cast<DataArrayAsciiChar *>(_names->subArray(start,end));
1351 MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
1356 void MEDFileUMeshSplitL1::renumberNodesInConn(const mcIdType *newNodeNumbersO2N)
1358 _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
1361 void MEDFileUMeshSplitL1::serialize(std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI) const
1363 bigArraysI.push_back(_fam);
1364 bigArraysI.push_back(_num);
1365 _m_by_types.serialize(tinyInt,bigArraysI);
1368 void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI)
1370 _fam=bigArraysI.back(); bigArraysI.pop_back();
1371 _num=bigArraysI.back(); bigArraysI.pop_back();
1372 _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
1375 void MEDFileUMeshSplitL1::changeFamilyIdArr(mcIdType oldId, mcIdType newId)
1377 DataArrayIdType *arr=_fam;
1379 arr->changeValue(oldId,newId);
1382 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayIdType *famArr)
1389 mcIdType sz(_m_by_types.getSize());
1390 famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
1395 DataArrayIdType *MEDFileUMeshSplitL1::getFamilyField()
1400 void MEDFileUMeshSplitL1::setRenumArr(DataArrayIdType *renumArr)
1408 mcIdType sz(_m_by_types.getSize());
1409 renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
1410 renumArr->incrRef();
1415 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
1422 mcIdType sz(_m_by_types.getSize());
1423 nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
1428 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayIdType *renum, MEDCouplingUMesh *m, const mcIdType *cellIds)
1433 m->renumberCells(renum->begin(),true);
1436 MCAuto<DataArrayIdType> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
1437 m->renumberCells(locnum->begin(),true);
1442 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI)
1444 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
1445 ret->unserialize(name,coo,tinyInt,bigArraysI);
1449 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const mcIdType *cellIds) const
1451 return Renumber2(_num,m,cellIds);
1454 DataArrayIdType *MEDFileUMeshSplitL1::Renumber(const DataArrayIdType *renum, const DataArrayIdType *da)
1456 if((const DataArrayIdType *)renum==0)
1459 return const_cast<DataArrayIdType *>(da);
1461 return renum->selectByTupleId(da->begin(),da->end());
1464 DataArrayIdType *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayIdType *da) const
1466 return Renumber(_num,da);
1469 std::vector<mcIdType> MEDFileUMeshSplitL1::GetNewFamiliesNumber(mcIdType nb, const std::map<std::string,mcIdType>& families)
1472 for(std::map<std::string,mcIdType>::const_iterator it=families.begin();it!=families.end();it++)
1473 id=std::max(id,(*it).second);
1476 std::vector<mcIdType> ret(nb);
1477 for(mcIdType i=1;i<=nb;i++)
1482 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<mcIdType> >& fidsGrps, std::map<std::string,mcIdType>& familyIds,
1483 std::map<mcIdType,mcIdType>& famIdTrad, std::map<mcIdType,std::string>& newfams)
1485 std::set<mcIdType> allfids;
1489 void MEDFileUMeshSplitL1::computeRevNum() const
1492 mcIdType maxValue=_num->getMaxValue(pos);
1493 _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
1498 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
1502 void MEDFileUMeshAggregateCompute::setName(const std::string& name)
1504 if(_m_time>=_mp_time)
1506 MEDCouplingUMesh *um(_m);
1510 if(_mp_time>=_m_time)
1512 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1514 MEDCoupling1GTUMesh *tmp(*it);
1521 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1523 std::size_t sz(mParts.size());
1524 std::vector< MCAuto<MEDCoupling1GTUMesh> > ret(sz);
1525 for(std::size_t i=0;i<sz;i++)
1527 const MEDCoupling1GTUMesh *elt(mParts[i]);
1529 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
1530 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
1533 _part_def.clear(); _part_def.resize(sz);
1534 _mp_time=std::max(_mp_time,_m_time)+1;
1538 void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector<const PartDefinition *>& partDefs)
1540 if(_mp_time<_m_time)
1541 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !");
1542 std::size_t sz(partDefs.size());
1543 if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size())
1544 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !");
1545 for(std::size_t i=0;i<sz;i++)
1547 const PartDefinition *elt(partDefs[i]);
1550 _part_def[i]=const_cast<PartDefinition*>(elt);
1554 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
1558 _m_time=std::max(_mp_time,_m_time)+1;
1561 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
1563 if(_mp_time<=_m_time)
1565 std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
1566 std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
1567 _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
1568 _m_parts.clear();//to avoid memory peak !
1569 _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
1573 mcIdType MEDFileUMeshAggregateCompute::getNumberOfCells() const
1575 if(_mp_time<=_m_time)
1576 return _m->getNumberOfCells();
1578 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1579 ret+=(*it)->getNumberOfCells();
1583 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
1585 if(_mp_time>=_m_time)
1587 std::size_t sz(_m_parts.size());
1588 std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
1589 for(std::size_t i=0;i<sz;i++)
1590 ret[i]=_m_parts[i]->getCellModelEnum();
1594 return _m->getAllGeoTypesSorted();
1597 mcIdType MEDFileUMeshAggregateCompute::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1599 if(_mp_time>=_m_time)
1601 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1603 const MEDCoupling1GTUMesh *elt(*it);
1604 if(elt && elt->getCellModelEnum()==ct)
1605 return elt->getNumberOfCells();
1610 return _m->getNumberOfCellsWithType(ct);
1613 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
1615 if(_mp_time<_m_time)
1616 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
1618 std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
1620 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
1622 const MEDCoupling1GTUMesh *elt(*it);
1623 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
1628 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
1630 if(_mp_time<_m_time)
1631 forceComputationOfPartsFromUMesh();
1632 return retrievePartsWithoutComputation();
1635 MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1637 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1638 std::size_t sz(v.size());
1639 for(std::size_t i=0;i<sz;i++)
1642 if(v[i]->getCellModelEnum()==gt)
1645 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
1648 void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, mcIdType& start, mcIdType& stop) const
1651 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1652 std::size_t sz(v.size());
1653 for(std::size_t i=0;i<sz;i++)
1657 if(v[i]->getCellModelEnum()==gt)
1659 stop=start+v[i]->getNumberOfCells();
1663 start+=v[i]->getNumberOfCells();
1666 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
1669 void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const mcIdType *newNodeNumbersO2N)
1671 if(_mp_time>_m_time)
1673 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1675 MEDCoupling1GTUMesh *m(*it);
1677 m->renumberNodesInConn(newNodeNumbersO2N);
1682 MEDCouplingUMesh *m(getUmesh());
1685 m->renumberNodesInConn(newNodeNumbersO2N);
1689 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1691 const MEDCouplingUMesh *m(_m);
1694 if(_m_parts.empty())
1695 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1697 return ;// no needs to compte parts they are already here !
1699 std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1700 std::vector< MCAuto<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1701 std::size_t sz(msMSafe.size());
1702 _m_parts.resize(sz);
1703 for(std::size_t i=0;i<sz;i++)
1704 _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1706 _part_def.resize(_m_parts.size());
1707 _mp_time=std::max(_mp_time,_m_time);
1710 const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1712 if(_mp_time<_m_time)
1713 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : the parts require a computation !");
1714 if(_m_parts.size()!=_part_def.size())
1715 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : size of arrays are expected to be the same !");
1716 std::size_t sz(_m_parts.size());
1717 for(std::size_t i=0;i<sz;i++)
1719 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1721 if(mesh->getCellModelEnum()==gt)
1722 return _part_def[i];
1724 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
1727 void MEDFileUMeshAggregateCompute::serialize(std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI) const
1729 if(_mp_time<_m_time)
1730 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
1731 std::size_t sz(_m_parts.size());
1732 tinyInt.push_back((mcIdType)sz);
1733 for(std::size_t i=0;i<sz;i++)
1735 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1737 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
1738 tinyInt.push_back(mesh->getCellModelEnum());
1739 const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
1740 const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
1743 DataArrayIdType *elt(mesh1->getNodalConnectivity());
1746 MCAuto<DataArrayIdType> elt1(elt);
1747 bigArraysI.push_back(elt1);
1751 DataArrayIdType *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
1756 MCAuto<DataArrayIdType> elt11(elt1),elt22(elt2);
1757 bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
1760 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
1761 const PartDefinition *pd(_part_def[i]);
1763 tinyInt.push_back(-1);
1766 std::vector<mcIdType> tinyTmp;
1767 pd->serialize(tinyTmp,bigArraysI);
1768 tinyInt.push_back((mcIdType)tinyTmp.size());
1769 tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
1774 void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<mcIdType>& tinyInt, std::vector< MCAuto<DataArrayIdType> >& bigArraysI)
1776 mcIdType nbParts(tinyInt.back()); tinyInt.pop_back();
1777 _part_def.clear(); _part_def.resize(nbParts);
1778 _m_parts.clear(); _m_parts.resize(nbParts);
1779 for(mcIdType i=0;i<nbParts;i++)
1781 INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
1782 MCAuto<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
1783 mesh->setCoords(coo);
1784 MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1785 MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1788 mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
1792 MCAuto<DataArrayIdType> elt0,elt1;
1793 elt0=bigArraysI.back(); bigArraysI.pop_back();
1794 elt1=bigArraysI.back(); bigArraysI.pop_back();
1795 mesh2->setNodalConnectivity(elt0,elt1);
1798 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
1800 mcIdType pdid(tinyInt.back()); tinyInt.pop_back();
1802 _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
1803 _mp_time=std::max(_mp_time,_m_time)+1;
1808 * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
1810 bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const
1812 return _mp_time>=_m_time;
1815 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
1817 if(_mp_time>_m_time)
1818 return getTimeOfParts();
1819 if(_m_time>_mp_time)
1820 return getTimeOfUMesh();
1821 return std::max(getTimeOfParts(),getTimeOfUMesh());
1824 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
1827 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1829 const MEDCoupling1GTUMesh *elt(*it);
1831 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
1832 ret=std::max(ret,elt->getTimeOfThis());
1835 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
1839 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
1841 const MEDCouplingUMesh *m(_m);
1843 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
1844 return m->getTimeOfThis();
1847 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
1849 std::size_t ret(_m_parts.size()*sizeof(MCAuto<MEDCoupling1GTUMesh>));
1853 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
1855 std::vector<const BigMemoryObject *> ret;
1856 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1857 ret.push_back((const MEDCoupling1GTUMesh *)*it);
1858 ret.push_back((const MEDCouplingUMesh *)_m);
1862 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCopy(DataArrayDouble *coords) const
1864 MEDFileUMeshAggregateCompute ret;
1865 ret._m_parts.resize(_m_parts.size());
1866 for(std::size_t i=0;i<_m_parts.size();i++)
1868 const MEDCoupling1GTUMesh *elt(_m_parts[i]);
1871 ret._m_parts[i]=static_cast<MEDCoupling::MEDCoupling1GTUMesh*>(elt->deepCopy());
1872 ret._m_parts[i]->setCoords(coords);
1875 ret._mp_time=_mp_time; ret._m_time=_m_time;
1876 if((const MEDCouplingUMesh *)_m)
1878 ret._m=static_cast<MEDCoupling::MEDCouplingUMesh*>(_m->deepCopy());
1879 ret._m->setCoords(coords);
1881 std::size_t sz(_part_def.size());
1882 ret._part_def.clear(); ret._part_def.resize(sz);
1883 for(std::size_t i=0;i<sz;i++)
1885 const PartDefinition *elt(_part_def[i]);
1887 ret._part_def[i]=elt->deepCopy();
1892 void MEDFileUMeshAggregateCompute::shallowCpyMeshes()
1894 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1896 const MEDCoupling1GTUMesh *elt(*it);
1899 MCAuto<MEDCouplingMesh> elt2(elt->clone(false));
1900 *it=DynamicCastSafe<MEDCouplingMesh,MEDCoupling1GTUMesh>(elt2);
1903 const MEDCouplingUMesh *m(_m);
1908 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
1910 const MEDCouplingUMesh *m1(getUmesh());
1911 const MEDCouplingUMesh *m2(other.getUmesh());
1912 if((m1==0 && m2!=0) || (m1!=0 && m2==0))
1914 what="Presence of mesh in one sublevel and not in other!";
1920 if(!m1->isEqualIfNotWhy(m2,eps,what2))
1922 what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
1926 std::size_t sz(_part_def.size());
1927 if(sz!=other._part_def.size())
1929 what=std::string("number of subdivision per geo type for part definition is not the same !");
1932 for(std::size_t i=0;i<sz;i++)
1934 const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
1937 if((!pd0 && pd1) || (pd0 && !pd1))
1939 what=std::string("a cell part def is defined only for one among this or other !");
1942 bool ret(pd0->isEqual(pd1,what));
1949 void MEDFileUMeshAggregateCompute::checkConsistency() const
1951 if(_mp_time >= _m_time)
1952 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();
1953 it!=_m_parts.end(); it++)
1954 (*it)->checkConsistency();
1956 _m->checkConsistency();
1959 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
1961 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1962 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
1963 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
1966 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
1968 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1970 const MEDCoupling1GTUMesh *tmp(*it);
1973 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
1974 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
1975 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1976 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
1979 const MEDCouplingUMesh *m(_m);
1982 (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
1983 (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
1984 (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1985 (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
1989 bool MEDFileUMeshAggregateCompute::empty() const
1991 if(_mp_time<_m_time)
1992 return ((const MEDCouplingUMesh *)_m)==0;
1993 //else _mp_time>=_m_time)
1994 return _m_parts.empty();
1997 int MEDFileUMeshAggregateCompute::getMeshDimension() const
1999 if(_mp_time<_m_time)
2001 const MEDCouplingUMesh *m(_m);
2003 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
2004 return m->getMeshDimension();
2008 if(_m_parts.empty())
2009 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
2010 const MEDCoupling1GTUMesh *m(_m_parts[0]);
2012 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
2013 return m->getMeshDimension();
2017 std::vector<mcIdType> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
2019 if(_mp_time<_m_time)
2021 const MEDCouplingUMesh *m(_m);
2023 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
2024 return m->getDistributionOfTypes();
2028 std::vector<mcIdType> ret;
2029 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2031 const MEDCoupling1GTUMesh *tmp(*it);
2033 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
2034 std::vector<mcIdType> ret0(tmp->getDistributionOfTypes());
2035 ret.insert(ret.end(),ret0.begin(),ret0.end());
2041 mcIdType MEDFileUMeshAggregateCompute::getSize() const
2043 if(_mp_time<_m_time)
2045 const MEDCouplingUMesh *m(_m);
2047 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
2048 return m->getNumberOfCells();
2053 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2055 const MEDCoupling1GTUMesh *m(*it);
2057 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
2058 ret+=m->getNumberOfCells();
2064 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
2066 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
2068 MEDCoupling1GTUMesh *tmp(*it);
2070 (*it)->setCoords(coords);
2072 MEDCouplingUMesh *m(_m);
2074 m->setCoords(coords);
2077 MEDFileEltStruct4Mesh *MEDFileEltStruct4Mesh::New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs)
2079 return new MEDFileEltStruct4Mesh(fid,mName,dt,it,iterOnStEltOfMesh,mrs);
2082 std::size_t MEDFileEltStruct4Mesh::getHeapMemorySizeWithoutChildren() const
2084 return _geo_type_name.capacity()+_vars.capacity()*sizeof(MCAuto<DataArray>);
2087 std::vector<const MEDCoupling::BigMemoryObject*> MEDFileEltStruct4Mesh::getDirectChildrenWithNull() const
2089 std::vector<const MEDCoupling::BigMemoryObject*> ret;
2090 ret.push_back(_conn);
2091 ret.push_back(_common);
2092 for(std::vector< MCAuto<DataArray> >::const_iterator it=_vars.begin();it!=_vars.end();it++)
2097 MEDFileEltStruct4Mesh::MEDFileEltStruct4Mesh(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs)
2099 med_geometry_type geoType;
2100 INTERP_KERNEL::AutoPtr<char> geoTypeName(MEDLoaderBase::buildEmptyString(MED_NAME_SIZE));
2101 MEDFILESAFECALLERRD0(MEDmeshEntityInfo,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,iterOnStEltOfMesh+1,geoTypeName,&geoType));
2103 _geo_type_name=MEDLoaderBase::buildStringFromFortran(geoTypeName,MED_NAME_SIZE);
2106 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
2107 nCells=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,geoType,MED_CONNECTIVITY,MED_NODAL,&chgt,&trsf);
2109 MCAuto<MEDFileMeshSupports> mss(MEDFileMeshSupports::New(fid));
2110 MCAuto<MEDFileStructureElements> mse(MEDFileStructureElements::New(fid,mss));
2111 mcIdType nbEntities(mse->getNumberOfNodesPerSE(_geo_type_name));
2112 MCAuto<DataArrayMedInt> miConn=DataArrayMedInt::New(); miConn->alloc(nCells*nbEntities);
2113 MEDFILESAFECALLERRD0(MEDmeshElementConnectivityRd,(fid,mName.c_str(),dt,it,MED_STRUCT_ELEMENT,_geo_type,MED_NODAL,MED_FULL_INTERLACE,miConn->getPointer()));
2114 _conn=FromMedIntArray<mcIdType>(miConn);
2115 _conn->applyLin(1,-1);
2116 _conn->rearrange(nbEntities);
2117 _common=MEDFileUMeshPerTypeCommon::New();
2118 _common->loadCommonPart(fid,mName.c_str(),dt,it,nCells,geoType,MED_STRUCT_ELEMENT,mrs);
2119 std::vector<std::string> vns(mse->getVarAttsOf(_geo_type_name));
2120 std::size_t sz(vns.size());
2122 for(std::size_t i=0;i<sz;i++)
2124 const MEDFileSEVarAtt *var(mse->getVarAttOf(_geo_type_name,vns[i]));
2125 MCAuto<DataArray> gen(var->getGenerator());
2126 MCAuto<DataArray> arr(gen->buildNewEmptyInstance());
2127 arr->alloc(nCells,var->getNbOfComponents());
2128 arr->setName(vns[i]);
2129 MEDFILESAFECALLERRD0(MEDmeshStructElementVarAttRd,(fid,mName.c_str(),dt,it,_geo_type,vns[i].c_str(),arr->getVoidStarPointer()));