1 // Copyright (C) 2007-2015 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"
27 #include "MEDCouplingUMesh.hxx"
29 #include "InterpKernelAutoPtr.hxx"
30 #include "CellModel.hxx"
35 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
36 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
37 extern med_geometry_type typmainoeud[1];
39 using namespace MEDCoupling;
41 const char MEDFileMeshL2::ZE_SEP_FOR_FAMILY_KILLERS[]="!/__\\!";//important start by - because ord('!')==33 the smallest (!=' ') to preserve orders at most.
43 int MEDFileMeshL2::ZE_SEP2_FOR_FAMILY_KILLERS=4;
45 MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
49 std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const
54 std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull() const
56 return std::vector<const BigMemoryObject *>();
59 int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& dt, int& it, std::string& dtunit1)
61 med_mesh_type type_maillage;
62 char maillage_description[MED_COMMENT_SIZE+1];
63 char dtunit[MED_LNAME_SIZE+1];
65 char nommaa[MED_NAME_SIZE+1];
66 med_int n=MEDnMesh(fid);
69 med_sorting_type stype;
70 std::vector<std::string> ms;
72 med_axis_type axistype;
73 for(int i=0;i<n && !found;i++)
75 int naxis(MEDmeshnAxis(fid,i+1));
76 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
77 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
78 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
79 dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
80 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
90 std::ostringstream oss;
91 oss << "No such meshname (" << mname << ") in file ! Must be in : ";
92 std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
93 throw INTERP_KERNEL::Exception(oss.str().c_str());
95 axType=TraduceAxisType(axistype);
98 case MED_UNSTRUCTURED_MESH:
99 meshType=UNSTRUCTURED;
101 case MED_STRUCTURED_MESH:
104 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mname.c_str(),>));
107 case MED_CARTESIAN_GRID:
110 case MED_CURVILINEAR_GRID:
111 meshType=CURVE_LINEAR;
113 case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
117 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
122 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
126 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mname.c_str(),1,&numdt,&numit,&dtt));
131 double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it)
136 std::vector< std::pair<int,int> > p(nstep);
137 for(int i=0;i<nstep;i++)
139 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),i+1,&numdt,&numit,&dtt));
140 p[i]=std::make_pair(numdt,numit);
141 found=(numdt==dt) && (numit==numit);
145 std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! ";
146 oss << "Possibilities are : ";
147 for(int i=0;i<nstep;i++)
148 oss << "(" << p[i].first << "," << p[i].second << "), ";
149 throw INTERP_KERNEL::Exception(oss.str().c_str());
155 * non static and non const method because _description, _dt_unit... are set in this method.
157 std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, MEDCoupling::MEDCouplingMeshType& meshType, MEDCoupling::MEDCouplingAxisType& axType, int& nstep, int& Mdim)
159 med_mesh_type type_maillage;
161 med_sorting_type stype;
162 med_axis_type axistype;
163 int naxis(MEDmeshnAxis(fid,mId));
164 INTERP_KERNEL::AutoPtr<char> nameTmp=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
165 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
166 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
167 INTERP_KERNEL::AutoPtr<char> univTmp=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
168 if(MEDmeshInfo(fid,mId,nameTmp,&spaceDim,&Mdim,&type_maillage,_description.getPointer(),_dt_unit.getPointer(),
169 &stype,&nstep,&axistype,axisname,axisunit)!=0)
170 throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
171 MEDmeshUniversalNameRd(fid,nameTmp,_univ_name.getPointer());// do not protect MEDFILESAFECALLERRD0 call : Thanks to fra.med.
172 axType=TraduceAxisType(axistype);
173 switch(type_maillage)
175 case MED_UNSTRUCTURED_MESH:
176 meshType=UNSTRUCTURED;
178 case MED_STRUCTURED_MESH:
181 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>));
184 case MED_CARTESIAN_GRID:
187 case MED_CURVILINEAR_GRID:
188 meshType=CURVE_LINEAR;
190 case MED_POLAR_GRID:// this is not a bug. A MED file POLAR_GRID is deal by CARTESIAN MEDLoader
194 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
199 throw INTERP_KERNEL::Exception("MEDFileMeshL2::getMeshIdFromName : unrecognized mesh type !");
202 std::vector<std::string> infosOnComp(naxis);
203 for(int i=0;i<naxis;i++)
205 std::string info=MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
211 void MEDFileMeshL2::ReadFamiliesAndGrps(med_idt fid, const std::string& meshName, std::map<std::string,int>& fams, std::map<std::string, std::vector<std::string> >& grps, MEDFileMeshReadSelector *mrs)
213 if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading()))
215 char nomfam[MED_NAME_SIZE+1];
217 int nfam=MEDnFamily(fid,meshName.c_str());
218 std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > > crudeFams(nfam);
219 for(int i=0;i<nfam;i++)
221 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
222 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
223 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
224 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
225 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
226 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
227 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
228 std::string famName(MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE));
229 std::vector<std::string> grps(ngro);
230 for(int j=0;j<ngro;j++)
231 grps[j]=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
232 crudeFams[i]=std::pair<std::string,std::pair<int,std::vector<std::string> > >(famName,std::pair<int,std::vector<std::string> >(numfam,grps));
234 RenameFamiliesFromFileToMemInternal(crudeFams);
235 for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it0=crudeFams.begin();it0!=crudeFams.end();it0++)
237 fams[(*it0).first]=(*it0).second.first;
238 for(std::vector<std::string>::const_iterator it1=(*it0).second.second.begin();it1!=(*it0).second.second.end();it1++)
239 grps[*it1].push_back((*it0).first);
243 void MEDFileMeshL2::WriteFamiliesAndGrps(med_idt fid, const std::string& mname, const std::map<std::string,int>& fams, const std::map<std::string, std::vector<std::string> >& grps, int tooLongStrPol)
245 std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > > crudeFams(fams.size());
247 for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++,ii++)
249 std::vector<std::string> grpsOfFam;
250 for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
252 if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
253 grpsOfFam.push_back((*it1).first);
255 crudeFams[ii]=std::pair<std::string,std::pair<int,std::vector<std::string> > >((*it).first,std::pair<int,std::vector<std::string> >((*it).second,grpsOfFam));
257 RenameFamiliesFromMemToFileInternal(crudeFams);
258 for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++)
260 int ngro((*it).second.second.size());
261 INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
263 for(std::vector<std::string>::const_iterator it2=(*it).second.second.begin();it2!=(*it).second.second.end();it2++,i++)
264 MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol);
265 INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
266 MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
267 int ret=MEDfamilyCr(fid,mname.c_str(),famName,(*it).second.first,ngro,groName);
272 void MEDFileMeshL2::RenameFamiliesPatternInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams, RenameFamiliesPatternFunc func)
275 std::vector<std::string> fams(crudeFams.size());
276 for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::const_iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
277 fams[ii]=(*it).first;
281 for(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >::iterator it=crudeFams.begin();it!=crudeFams.end();it++,ii++)
282 (*it).first=fams[ii];
286 * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
287 * So this method renames families (if needed generaly not !) in order to have a discriminant name for families.
289 void MEDFileMeshL2::RenameFamiliesFromFileToMemInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams)
291 RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromFileToMem);
294 bool MEDFileMeshL2::RenameFamiliesFromFileToMem(std::vector< std::string >& famNames)
296 std::map<std::string,int> m;
297 std::set<std::string> s;
298 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
300 if(s.find(*it)!=s.end())
305 return false;// the general case !
306 for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
308 std::map<std::string,int>::iterator it2(m.find(*it));
311 std::ostringstream oss; oss << *it << ZE_SEP_FOR_FAMILY_KILLERS << std::setfill('0') << std::setw(ZE_SEP2_FOR_FAMILY_KILLERS) << (*it2).second++;
319 * This method is dedicated to the killers that use a same family name to store different family ids. MED file API authorizes it.
320 * So this method renames families (if needed generaly not !) in order to have a discriminant name for families.
322 void MEDFileMeshL2::RenameFamiliesFromMemToFileInternal(std::vector< std::pair<std::string,std::pair<int,std::vector<std::string> > > >& crudeFams)
324 RenameFamiliesPatternInternal(crudeFams,RenameFamiliesFromMemToFile);
327 bool MEDFileMeshL2::RenameFamiliesFromMemToFile(std::vector< std::string >& famNames)
329 bool isSmthingStrange(false);
330 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
332 std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
333 if(found!=std::string::npos)
334 isSmthingStrange=true;
336 if(!isSmthingStrange)
339 std::map< std::string, std::vector<std::string> > m;
340 for(std::vector< std::string >::const_iterator it=famNames.begin();it!=famNames.end();it++)
342 std::size_t found((*it).find(ZE_SEP_FOR_FAMILY_KILLERS));
343 if(found!=std::string::npos && found>=1)
345 std::string s1((*it).substr(found+sizeof(ZE_SEP_FOR_FAMILY_KILLERS)-1));
346 if(s1.size()!=ZE_SEP2_FOR_FAMILY_KILLERS)
349 std::istringstream iss(s1);
351 bool isOK((iss.rdstate() & ( std::istream::failbit | std::istream::eofbit)) == std::istream::eofbit);
354 std::string s0((*it).substr(0,found));
355 m[s0].push_back(*it);
362 std::map<std::string,std::string> zeMap;
363 for(std::map< std::string, std::vector<std::string> >::const_iterator it=m.begin();it!=m.end();it++)
365 if((*it).second.size()==1)
367 for(std::vector<std::string>::const_iterator it1=(*it).second.begin();it1!=(*it).second.end();it1++)
368 zeMap[*it1]=(*it).first;
373 for(std::vector< std::string >::iterator it=famNames.begin();it!=famNames.end();it++)
375 std::map<std::string,std::string>::iterator it1(zeMap.find(*it));
382 MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisType(med_axis_type at)
388 case MED_CYLINDRICAL:
392 case MED_UNDEF_AXIS_TYPE:
395 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisType : unrecognized axis type !");
399 MEDCoupling::MEDCouplingAxisType MEDFileMeshL2::TraduceAxisTypeStruct(med_grid_type gt)
403 case MED_CARTESIAN_GRID:
408 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeStruct : only Cartesian and Cylindrical supported by MED file !");
412 med_axis_type MEDFileMeshL2::TraduceAxisTypeRev(MEDCoupling::MEDCouplingAxisType at)
417 return MED_CARTESIAN;
419 return MED_CYLINDRICAL;
421 return MED_SPHERICAL;
423 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRev : unrecognized axis type !");
427 med_grid_type MEDFileMeshL2::TraduceAxisTypeRevStruct(MEDCoupling::MEDCouplingAxisType at)
432 return MED_CARTESIAN_GRID;
434 return MED_POLAR_GRID;
436 return MED_POLAR_GRID;
438 throw INTERP_KERNEL::Exception("MEDFileMeshL2::TraduceAxisTypeRevStruct : unrecognized axis type !");
442 MEDFileUMeshL2::MEDFileUMeshL2()
446 std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim)
449 _name.set(mName.c_str());
451 MEDCoupling::MEDCouplingMeshType meshType;
452 MEDCoupling::MEDCouplingAxisType dummy3;
453 std::vector<std::string> ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim));
457 return std::vector<std::string>();
459 if(meshType!=UNSTRUCTURED)
460 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
461 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
467 void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
470 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
473 loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency
474 loadCoords(fid,mId,infosOnComp,mName,dt,it);
477 void MEDFileUMeshL2::loadPart(med_idt fid, int mId, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
480 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
483 loadPartOfConnectivity(fid,Mdim,mName,types,slicPerTyp,dt,it,mrs);
484 med_bool changement,transformation;
485 int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
486 std::vector<bool> fetchedNodeIds(nCoords,false);
487 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
488 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
489 (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds);
490 int nMin(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true)));
491 int nMax(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true)));
493 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
494 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
495 (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin);
496 loadPartCoords(fid,mId,infosOnComp,mName,dt,it,nMin,nMax);
499 void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
501 _per_type_mesh.resize(1);
502 _per_type_mesh[0].clear();
503 for(int j=0;j<MED_N_CELL_FIXED_GEO;j++)
505 MEDFileUMeshPerType *tmp(MEDFileUMeshPerType::New(fid,mName.c_str(),dt,it,mdim,typmai[j],typmai2[j],mrs));
507 _per_type_mesh[0].push_back(tmp);
512 void MEDFileUMeshL2::loadPartOfConnectivity(med_idt fid, int mdim, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
514 std::size_t nbOfTypes(types.size());
515 if(slicPerTyp.size()!=3*nbOfTypes)
516 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : The size of slicPerTyp array is expected to be equal to 3 times size of array types !");
517 std::set<INTERP_KERNEL::NormalizedCellType> types2(types.begin(),types.end());
518 if(types2.size()!=nbOfTypes)
519 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : the geometric types in types array must appear once !");
520 _per_type_mesh.resize(1);
521 _per_type_mesh[0].clear();
522 for(std::size_t ii=0;ii<nbOfTypes;ii++)
524 int strt(slicPerTyp[3*ii+0]),stp(slicPerTyp[3*ii+1]),step(slicPerTyp[3*ii+2]);
525 MCAuto<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs));
526 _per_type_mesh[0].push_back(tmp);
531 void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it)
533 int spaceDim((int)infosOnComp.size());
534 med_bool changement,transformation;
535 int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
536 _coords=DataArrayDouble::New();
537 _coords->alloc(nCoords,spaceDim);
538 double *coordsPtr(_coords->getPointer());
540 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,coordsPtr));
541 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
543 _fam_coords=DataArrayInt::New();
544 _fam_coords->alloc(nCoords,1);
545 MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()));
549 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
551 _num_coords=DataArrayInt::New();
552 _num_coords->alloc(nCoords,1);
553 MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()));
557 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
559 _name_coords=DataArrayAsciiChar::New();
560 _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
561 MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
562 _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
566 for(int i=0;i<spaceDim;i++)
567 _coords->setInfoOnComponent(i,infosOnComp[i]);
570 void MEDFileUMeshL2::loadPartCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it, int nMin, int nMax)
572 med_bool changement,transformation;
573 int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
574 _coords=DataArrayDouble::New();
575 int nbNodesToLoad(nMax-nMin);
576 _coords->alloc(nbNodesToLoad,spaceDim);
577 med_filter filter=MED_FILTER_INIT,filter2=MED_FILTER_INIT;
578 MEDfilterBlockOfEntityCr(fid,/*nentity*/nCoords,/*nvaluesperentity*/1,/*nconstituentpervalue*/spaceDim,
579 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
580 /*start*/nMin+1,/*stride*/1,/*count*/1,/*blocksize*/nbNodesToLoad,
581 /*lastblocksize=useless because count=1*/0,&filter);
582 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateAdvancedRd,(fid,mName.c_str(),dt,it,&filter,_coords->getPointer()));
583 _part_coords=PartDefinition::New(nMin,nMax,1);
584 MEDfilterClose(&filter);
585 MEDfilterBlockOfEntityCr(fid,nCoords,1,1,MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,
586 MED_NO_PROFILE,nMin+1,1,1,nbNodesToLoad,0,&filter2);
587 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
589 _fam_coords=DataArrayInt::New();
590 _fam_coords->alloc(nbNodesToLoad,1);
591 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_fam_coords->getPointer()));
595 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
597 _num_coords=DataArrayInt::New();
598 _num_coords->alloc(nbNodesToLoad,1);
599 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_num_coords->getPointer()));
603 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
605 _name_coords=DataArrayAsciiChar::New();
606 _name_coords->alloc(nbNodesToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
607 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NAME,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_name_coords->getPointer()));
608 _name_coords->reAlloc(nbNodesToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
612 MEDfilterClose(&filter2);
613 _coords->setInfoOnComponents(infosOnComp);
616 void MEDFileUMeshL2::sortTypes()
619 std::vector< MCAuto<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
620 _per_type_mesh.clear();
621 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
622 mdims.insert((*it)->getDim());
625 int mdim=*mdims.rbegin();
626 _per_type_mesh.resize(mdim+1);
627 for(int dim=mdim+1;dim!=0;dim--)
629 std::vector< MCAuto<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
630 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
631 if((*it)->getDim()==dim-1)
634 // suppression of contiguous empty levels at the end of _per_type_mesh.
635 int nbOfUselessLev=0;
637 for(std::vector< std::vector< MCAuto<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
639 if((*it2).empty() && isFirst)
646 _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
649 void MEDFileUMeshL2::WriteCoords(med_idt fid, const std::string& mname, int dt, int it, double time, const DataArrayDouble *coords, const DataArrayInt *famCoords, const DataArrayInt *numCoords, const DataArrayAsciiChar *nameCoords)
653 MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer()));
655 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer()));
657 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer()));
660 if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
662 std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
663 oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
664 throw INTERP_KERNEL::Exception(oss.str().c_str());
666 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer()));
670 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
672 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
673 if((*it)->getFam()==0)
678 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
680 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
681 if((*it)->getNum()==0)
686 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
688 for(std::vector< MCAuto<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
689 if((*it)->getNames()==0)
694 MEDFileCMeshL2::MEDFileCMeshL2():_ax_type(AX_CART)
698 void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
700 _name.set(mName.c_str());
703 MEDCoupling::MEDCouplingMeshType meshType;
704 MEDCoupling::MEDCouplingAxisType dummy3;
705 std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,dummy3,nstep,Mdim);
706 if(meshType!=CARTESIAN)
707 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
708 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
712 med_grid_type gridtype;
713 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype));
714 if(gridtype!=MED_CARTESIAN_GRID && gridtype!=MED_POLAR_GRID)
715 throw INTERP_KERNEL::Exception("Invalid rectilinear mesh ! Only cartesian and polar are supported !");
716 _ax_type=TraduceAxisTypeStruct(gridtype);
717 _cmesh=MEDCouplingCMesh::New();
718 for(int i=0;i<Mdim;i++)
720 med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
721 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
722 int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf));
723 MCAuto<DataArrayDouble> da=DataArrayDouble::New();
724 da->alloc(nbOfElt,1);
725 da->setInfoOnComponent(0,infosOnComp[i]);
726 MEDFILESAFECALLERRD0(MEDmeshGridIndexCoordinateRd,(fid,mName.c_str(),dt,it,i+1,da->getPointer()));
727 _cmesh->setCoordsAt(i,da);
731 med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id)
736 return MED_COORDINATE_AXIS1;
738 return MED_COORDINATE_AXIS2;
740 return MED_COORDINATE_AXIS3;
742 throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
746 MEDFileCLMeshL2::MEDFileCLMeshL2()
750 void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
752 _name.set(mName.c_str());
755 MEDCoupling::MEDCouplingMeshType meshType;
756 MEDCoupling::MEDCouplingAxisType dummy3;
757 std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,dummy3,nstep,Mdim);
758 if(meshType!=CURVE_LINEAR)
759 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
760 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
764 _clmesh=MEDCouplingCurveLinearMesh::New();
765 INTERP_KERNEL::AutoPtr<int> stGrid=new int[Mdim];
766 MEDFILESAFECALLERRD0(MEDmeshGridStructRd,(fid,mName.c_str(),dt,it,stGrid));
767 _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim);
768 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
769 int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf));
770 MCAuto<DataArrayDouble> da=DataArrayDouble::New();
771 da->alloc(nbNodes,infosOnComp.size());
772 da->setInfoOnComponents(infosOnComp);
773 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer()));
774 _clmesh->setCoords(da);
777 MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
782 * Warning it returns an instance to deallocate !!!!
784 MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
786 _st->_num->updateTime();
787 if((MEDCouplingUMesh *)_m==0)
790 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
791 _m->renumberCells(_st->_num->getConstPointer(),true);
796 if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
801 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCopy());
802 _m->renumberCells(_st->_num->getConstPointer(),true);
808 void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
813 void MEDFileUMeshPermCompute::updateTime() const
815 _mpt_time=_st->_m_by_types.getTimeOfThis();
816 _num_time=_st->_num->getTimeOfThis();
819 std::vector<const BigMemoryObject *> MEDFileUMeshPermCompute::getDirectChildrenWithNull() const
821 std::vector<const BigMemoryObject *> ret;
822 ret.push_back((const MEDCouplingUMesh *)_m);
826 std::size_t MEDFileUMeshPermCompute::getHeapMemorySizeWithoutChildren() const
828 return sizeof(MEDFileUMeshPermCompute);
831 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)
835 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this)
837 const std::vector< MCAuto<MEDFileUMeshPerType> >& v=l2.getLev(id);
841 std::vector<const MEDCoupling1GTUMesh *> ms(sz);
842 std::vector<const DataArrayInt *> fams(sz),nums(sz);
843 std::vector<const DataArrayChar *> names(sz);
844 std::vector<const PartDefinition *> pds(sz);
845 for(int i=0;i<sz;i++)
847 MEDCoupling1GTUMesh *elt(v[i]->getMesh());
848 MCAuto<DataArrayDouble> tmp2=l2.getCoords();
849 elt->setCoords(tmp2);
851 pds[i]=v[i]->getPartDef();
853 _m_by_types.assignParts(ms);
854 _m_by_types.assignDefParts(pds);
855 if(l2.isFamDefinedOnLev(id))
857 for(int i=0;i<sz;i++)
858 fams[i]=v[i]->getFam();
860 _fam=DataArrayInt::Aggregate(fams);
864 _fam=const_cast<DataArrayInt *>(fams[0]);
867 if(l2.isNumDefinedOnLev(id))
869 for(int i=0;i<sz;i++)
870 nums[i]=v[i]->getNum();
872 _num=DataArrayInt::Aggregate(nums);
876 _num=const_cast<DataArrayInt *>(nums[0]);
880 if(l2.isNamesDefinedOnLev(id))
882 for(int i=0;i<sz;i++)
883 names[i]=v[i]->getNames();
884 _names=dynamic_cast<DataArrayAsciiChar *>(DataArrayChar::Aggregate(names));
888 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m):_m(this)
890 std::vector< const MEDCoupling1GTUMesh * > v(1);
895 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
900 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
902 assignMesh(m,newOrOld);
905 void MEDFileUMeshSplitL1::setName(const std::string& name)
907 _m_by_types.setName(name);
910 std::size_t MEDFileUMeshSplitL1::getHeapMemorySizeWithoutChildren() const
915 std::vector<const BigMemoryObject *> MEDFileUMeshSplitL1::getDirectChildrenWithNull() const
917 std::vector<const BigMemoryObject *> ret;
918 ret.push_back(&_m_by_types);
920 ret.push_back((const DataArrayInt*)_fam);
921 ret.push_back((const DataArrayInt*)_num);
922 ret.push_back((const DataArrayInt*)_rev_num);
923 ret.push_back((const DataArrayAsciiChar*)_names);
927 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::shallowCpyUsingCoords(DataArrayDouble *coords) const
929 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
930 ret->_m_by_types.shallowCpyMeshes();
931 ret->_m_by_types.setCoords(coords);
935 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCopy(DataArrayDouble *coords) const
937 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1(*this));
938 ret->_m_by_types=_m_by_types.deepCopy(coords);
939 if((const DataArrayInt *)_fam)
940 ret->_fam=_fam->deepCopy();
941 if((const DataArrayInt *)_num)
942 ret->_num=_num->deepCopy();
943 if((const DataArrayInt *)_rev_num)
944 ret->_rev_num=_rev_num->deepCopy();
945 if((const DataArrayAsciiChar *)_names)
946 ret->_names=_names->deepCopy();
950 void MEDFileUMeshSplitL1::checkConsistency() const
952 if (!_fam || _fam->getNumberOfTuples() != getSize())
953 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): internal family array has an invalid size!");
954 int nbCells = getSize();
957 _num->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array!");
959 int maxValue=_num->getMaxValue(pos);
960 if (!_rev_num || _rev_num->getNumberOfTuples() != (maxValue+1))
961 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal revert node numbering array!");
963 if ((_num && !_rev_num) || (!_num && _rev_num))
964 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal numbering arrays (one is null)!");
965 if (_num && !_num->hasUniqueValues())
966 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::checkConsistency(): inconsistent internal node numbering array: duplicates found!");
968 _names->checkNbOfTuplesAndComp(nbCells,1,"MEDFileUMeshSplitL1::checkConsistency(): internal cell naming array has an invalid size!");
970 _m_by_types.checkConsistency();
973 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
975 if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
977 const DataArrayInt *d1=_fam;
978 const DataArrayInt *d2=other->_fam;
979 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
981 what="Presence of family arr in one sublevel and not in other!";
985 if(!d1->isEqual(*d2))
987 what="family arr at a sublevel are not deeply equal !";
992 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
994 what="Presence of cell numbering arr in one sublevel and not in other!";
998 if(!d1->isEqual(*d2))
1000 what="Numbering cell arr at a sublevel are not deeply equal !";
1003 const DataArrayAsciiChar *e1=_names;
1004 const DataArrayAsciiChar *e2=other->_names;
1005 if((e1==0 && e2!=0) || (e1!=0 && e2==0))
1007 what="Presence of cell names arr in one sublevel and not in other!";
1011 if(!e1->isEqual(*e2))
1013 what="Name cell arr at a sublevel are not deeply equal !";
1019 void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
1021 _m_by_types.synchronizeTinyInfo(master);
1024 void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
1026 _m_by_types.clearNonDiscrAttributes();
1029 void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
1033 (const_cast<MEDCouplingMesh *>(tmp))->setName("");
1034 (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
1035 (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
1036 (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
1039 void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords)
1041 _m_by_types.setCoords(coords);
1044 void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
1050 _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCopy()));
1051 MCAuto<DataArrayInt> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
1052 if(!da->isIota(m->getNumberOfCells()))
1054 _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
1057 _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false);
1062 if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
1063 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh(): the mesh does not follow the MED file numbering convention! Invoke sortCellsInMEDFileFrmt() first!");
1065 _m_by_types.assignUMesh(m);
1070 void MEDFileUMeshSplitL1::forceComputationOfParts() const
1072 _m_by_types.forceComputationOfPartsFromUMesh();
1075 void MEDFileUMeshSplitL1::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1077 _m_by_types.assignParts(mParts);
1081 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this)
1085 void MEDFileUMeshSplitL1::assignCommonPart()
1087 _fam=DataArrayInt::New();
1088 _fam->alloc(_m_by_types.getSize(),1);
1089 _fam->fillWithValue(0);
1092 bool MEDFileUMeshSplitL1::empty() const
1094 return _m_by_types.empty();
1097 bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector<int>& ids) const
1099 const DataArrayInt *fam=_fam;
1102 return fam->presenceOfValue(ids);
1105 int MEDFileUMeshSplitL1::getMeshDimension() const
1107 return _m_by_types.getMeshDimension();
1110 void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const
1112 std::vector<int> code=_m_by_types.getDistributionOfTypes();
1113 int nbOfTypes=code.size()/3;
1114 for(int i=0;i<nbOfTypes;i++)
1116 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType) code[3*i];
1117 oss << " - Number of cells with type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr() << " : " << code[3*i+1] << std::endl;
1121 int MEDFileUMeshSplitL1::getSize() const
1123 return _m_by_types.getSize();
1126 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
1128 MCAuto<DataArrayInt> eltsToKeep=_fam->findIdsEqualList(idsBg,idsEnd);
1129 MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
1131 return renumIfNeeded(m,eltsToKeep->getConstPointer());
1135 DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const
1137 MCAuto<DataArrayInt> da=_fam->findIdsEqualList(idsBg,idsEnd);
1139 return renumIfNeededArr(da);
1143 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes() const
1145 return _m_by_types.getGeoTypes();
1148 int MEDFileUMeshSplitL1::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1150 return _m_by_types.getNumberOfCellsWithType(ct);
1153 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
1155 MCAuto<MEDCouplingUMesh> tmp;
1156 if(renum && ((const DataArrayInt *)_num))
1159 { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
1163 int MEDFileUMeshSplitL1::getNumberOfCells() const
1165 return _m_by_types.getNumberOfCells();
1168 DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
1170 const DataArrayInt *fam(_fam);
1173 int start(0),stop(0);
1174 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
1175 return fam->selectByTupleIdSafeSlice(start,stop,1);
1178 DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
1180 const DataArrayInt *num(_num);
1183 int start(0),stop(0);
1184 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
1185 return num->selectByTupleIdSafeSlice(start,stop,1);
1188 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
1190 if((DataArrayInt *)_fam)
1192 int nbOfTuples=_m_by_types.getSize();
1193 _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
1197 const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
1202 const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const
1207 const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const
1212 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
1217 const PartDefinition *MEDFileUMeshSplitL1::getPartDef(INTERP_KERNEL::NormalizedCellType gt) const
1219 return _m_by_types.getPartDefOfWithoutComputation(gt);
1222 void MEDFileUMeshSplitL1::eraseFamilyField()
1224 _fam->fillWithZero();
1228 * This method ignores _m and _m_by_types.
1230 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
1231 std::map<std::string, std::vector<std::string> >& groups)
1233 std::vector< DataArrayInt * > corr;
1234 _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
1235 std::vector< MCAuto<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
1236 std::vector< std::vector<int> > fidsOfGroups;
1237 std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
1238 _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
1239 int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
1240 std::map<int,std::string> newfams;
1241 std::map<int,int> famIdTrad;
1242 TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
1243 int *w=_fam->getPointer();
1244 for(int i=0;i<nbOfCells;i++,w++)
1248 void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const
1250 std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1252 for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
1254 int nbCells=(*it)->getNumberOfCells();
1255 int end=start+nbCells;
1256 MCAuto<DataArrayInt> fam,num;
1257 MCAuto<DataArrayAsciiChar> names;
1258 if((const DataArrayInt *)_fam)
1259 fam=_fam->subArray(start,end);
1260 if((const DataArrayInt *)_num)
1261 num=_num->subArray(start,end);
1262 if((const DataArrayAsciiChar *)_names)
1263 names=static_cast<DataArrayAsciiChar *>(_names->subArray(start,end));
1264 MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
1269 void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N)
1271 _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
1274 void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const
1276 bigArraysI.push_back(_fam);
1277 bigArraysI.push_back(_num);
1278 _m_by_types.serialize(tinyInt,bigArraysI);
1281 void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
1283 _fam=bigArraysI.back(); bigArraysI.pop_back();
1284 _num=bigArraysI.back(); bigArraysI.pop_back();
1285 _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
1288 void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId)
1290 DataArrayInt *arr=_fam;
1292 arr->changeValue(oldId,newId);
1295 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr)
1302 int sz(_m_by_types.getSize());
1303 famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
1308 DataArrayInt *MEDFileUMeshSplitL1::getFamilyField()
1313 void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr)
1321 int sz(_m_by_types.getSize());
1322 renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
1323 renumArr->incrRef();
1328 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
1335 int sz(_m_by_types.getSize());
1336 nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
1341 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds)
1346 m->renumberCells(renum->getConstPointer(),true);
1349 MCAuto<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
1350 m->renumberCells(locnum->getConstPointer(),true);
1355 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
1357 MCAuto<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
1358 ret->unserialize(name,coo,tinyInt,bigArraysI);
1362 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
1364 return Renumber2(_num,m,cellIds);
1367 DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da)
1369 if((const DataArrayInt *)renum==0)
1372 return const_cast<DataArrayInt *>(da);
1374 return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
1377 DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
1379 return Renumber(_num,da);
1382 std::vector<int> MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
1385 for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
1386 id=std::max(id,(*it).second);
1389 std::vector<int> ret(nb);
1390 for(int i=1;i<=nb;i++)
1395 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
1396 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
1398 std::set<int> allfids;
1402 void MEDFileUMeshSplitL1::computeRevNum() const
1405 int maxValue=_num->getMaxValue(pos);
1406 _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
1411 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
1415 void MEDFileUMeshAggregateCompute::setName(const std::string& name)
1417 if(_m_time>=_mp_time)
1419 MEDCouplingUMesh *um(_m);
1423 if(_mp_time>=_m_time)
1425 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1427 MEDCoupling1GTUMesh *tmp(*it);
1434 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1436 std::size_t sz(mParts.size());
1437 std::vector< MCAuto<MEDCoupling1GTUMesh> > ret(sz);
1438 for(std::size_t i=0;i<sz;i++)
1440 const MEDCoupling1GTUMesh *elt(mParts[i]);
1442 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
1443 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
1446 _part_def.clear(); _part_def.resize(sz);
1447 _mp_time=std::max(_mp_time,_m_time)+1;
1451 void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector<const PartDefinition *>& partDefs)
1453 if(_mp_time<_m_time)
1454 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !");
1455 std::size_t sz(partDefs.size());
1456 if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size())
1457 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !");
1458 for(std::size_t i=0;i<sz;i++)
1460 const PartDefinition *elt(partDefs[i]);
1463 _part_def[i]=const_cast<PartDefinition*>(elt);
1467 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
1471 _m_time=std::max(_mp_time,_m_time)+1;
1474 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
1476 if(_mp_time<=_m_time)
1478 std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
1479 std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
1480 _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
1481 _m_parts.clear();//to avoid memory peak !
1482 _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
1486 int MEDFileUMeshAggregateCompute::getNumberOfCells() const
1488 if(_mp_time<=_m_time)
1489 return _m->getNumberOfCells();
1491 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1492 ret+=(*it)->getNumberOfCells();
1496 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
1498 if(_mp_time>=_m_time)
1500 std::size_t sz(_m_parts.size());
1501 std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
1502 for(std::size_t i=0;i<sz;i++)
1503 ret[i]=_m_parts[i]->getCellModelEnum();
1507 return _m->getAllGeoTypesSorted();
1510 int MEDFileUMeshAggregateCompute::getNumberOfCellsWithType(INTERP_KERNEL::NormalizedCellType ct) const
1512 if(_mp_time>=_m_time)
1514 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1516 const MEDCoupling1GTUMesh *elt(*it);
1517 if(elt && elt->getCellModelEnum()==ct)
1518 return elt->getNumberOfCells();
1523 return _m->getNumberOfCellsWithType(ct);
1526 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
1528 if(_mp_time<_m_time)
1529 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
1531 std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
1533 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
1535 const MEDCoupling1GTUMesh *elt(*it);
1536 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
1541 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
1543 if(_mp_time<_m_time)
1544 forceComputationOfPartsFromUMesh();
1545 return retrievePartsWithoutComputation();
1548 MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1550 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1551 std::size_t sz(v.size());
1552 for(std::size_t i=0;i<sz;i++)
1555 if(v[i]->getCellModelEnum()==gt)
1558 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
1561 void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const
1564 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1565 std::size_t sz(v.size());
1566 for(std::size_t i=0;i<sz;i++)
1570 if(v[i]->getCellModelEnum()==gt)
1572 stop=start+v[i]->getNumberOfCells();
1576 start+=v[i]->getNumberOfCells();
1579 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
1582 void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N)
1584 if(_mp_time>_m_time)
1586 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1588 MEDCoupling1GTUMesh *m(*it);
1590 m->renumberNodesInConn(newNodeNumbersO2N);
1595 MEDCouplingUMesh *m(getUmesh());
1598 m->renumberNodesInConn(newNodeNumbersO2N);
1602 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1604 const MEDCouplingUMesh *m(_m);
1607 if(_m_parts.empty())
1608 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1610 return ;// no needs to compte parts they are already here !
1612 std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1613 std::vector< MCAuto<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1614 std::size_t sz(msMSafe.size());
1615 _m_parts.resize(sz);
1616 for(std::size_t i=0;i<sz;i++)
1617 _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1619 _part_def.resize(_m_parts.size());
1620 _mp_time=std::max(_mp_time,_m_time);
1623 const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1625 if(_mp_time<_m_time)
1626 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : the parts require a computation !");
1627 if(_m_parts.size()!=_part_def.size())
1628 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : size of arrays are expected to be the same !");
1629 std::size_t sz(_m_parts.size());
1630 for(std::size_t i=0;i<sz;i++)
1632 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1634 if(mesh->getCellModelEnum()==gt)
1635 return _part_def[i];
1637 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
1640 void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI) const
1642 if(_mp_time<_m_time)
1643 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
1644 std::size_t sz(_m_parts.size());
1645 tinyInt.push_back((int)sz);
1646 for(std::size_t i=0;i<sz;i++)
1648 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1650 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
1651 tinyInt.push_back(mesh->getCellModelEnum());
1652 const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
1653 const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
1656 DataArrayInt *elt(mesh1->getNodalConnectivity());
1659 MCAuto<DataArrayInt> elt1(elt);
1660 bigArraysI.push_back(elt1);
1664 DataArrayInt *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
1669 MCAuto<DataArrayInt> elt11(elt1),elt22(elt2);
1670 bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
1673 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
1674 const PartDefinition *pd(_part_def[i]);
1676 tinyInt.push_back(-1);
1679 std::vector<int> tinyTmp;
1680 pd->serialize(tinyTmp,bigArraysI);
1681 tinyInt.push_back((int)tinyTmp.size());
1682 tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
1687 void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MCAuto<DataArrayInt> >& bigArraysI)
1689 int nbParts(tinyInt.back()); tinyInt.pop_back();
1690 _part_def.clear(); _part_def.resize(nbParts);
1691 _m_parts.clear(); _m_parts.resize(nbParts);
1692 for(int i=0;i<nbParts;i++)
1694 INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
1695 MCAuto<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
1696 mesh->setCoords(coo);
1697 MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1698 MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1701 mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
1705 MCAuto<DataArrayInt> elt0,elt1;
1706 elt0=bigArraysI.back(); bigArraysI.pop_back();
1707 elt1=bigArraysI.back(); bigArraysI.pop_back();
1708 mesh2->setNodalConnectivity(elt0,elt1);
1711 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
1713 int pdid(tinyInt.back()); tinyInt.pop_back();
1715 _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
1716 _mp_time=std::max(_mp_time,_m_time)+1;
1721 * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
1723 bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const
1725 return _mp_time>=_m_time;
1728 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
1730 if(_mp_time>_m_time)
1731 return getTimeOfParts();
1732 if(_m_time>_mp_time)
1733 return getTimeOfUMesh();
1734 return std::max(getTimeOfParts(),getTimeOfUMesh());
1737 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
1740 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1742 const MEDCoupling1GTUMesh *elt(*it);
1744 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
1745 ret=std::max(ret,elt->getTimeOfThis());
1748 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
1752 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
1754 const MEDCouplingUMesh *m(_m);
1756 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
1757 return m->getTimeOfThis();
1760 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
1762 std::size_t ret(_m_parts.size()*sizeof(MCAuto<MEDCoupling1GTUMesh>));
1766 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
1768 std::vector<const BigMemoryObject *> ret;
1769 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1770 ret.push_back((const MEDCoupling1GTUMesh *)*it);
1771 ret.push_back((const MEDCouplingUMesh *)_m);
1775 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCopy(DataArrayDouble *coords) const
1777 MEDFileUMeshAggregateCompute ret;
1778 ret._m_parts.resize(_m_parts.size());
1779 for(std::size_t i=0;i<_m_parts.size();i++)
1781 const MEDCoupling1GTUMesh *elt(_m_parts[i]);
1784 ret._m_parts[i]=static_cast<MEDCoupling::MEDCoupling1GTUMesh*>(elt->deepCopy());
1785 ret._m_parts[i]->setCoords(coords);
1788 ret._mp_time=_mp_time; ret._m_time=_m_time;
1789 if((const MEDCouplingUMesh *)_m)
1791 ret._m=static_cast<MEDCoupling::MEDCouplingUMesh*>(_m->deepCopy());
1792 ret._m->setCoords(coords);
1794 std::size_t sz(_part_def.size());
1795 ret._part_def.clear(); ret._part_def.resize(sz);
1796 for(std::size_t i=0;i<sz;i++)
1798 const PartDefinition *elt(_part_def[i]);
1800 ret._part_def[i]=elt->deepCopy();
1805 void MEDFileUMeshAggregateCompute::shallowCpyMeshes()
1807 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1809 const MEDCoupling1GTUMesh *elt(*it);
1812 MCAuto<MEDCouplingMesh> elt2(elt->clone(false));
1813 *it=DynamicCastSafe<MEDCouplingMesh,MEDCoupling1GTUMesh>(elt2);
1816 const MEDCouplingUMesh *m(_m);
1821 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
1823 const MEDCouplingUMesh *m1(getUmesh());
1824 const MEDCouplingUMesh *m2(other.getUmesh());
1825 if((m1==0 && m2!=0) || (m1!=0 && m2==0))
1827 what="Presence of mesh in one sublevel and not in other!";
1833 if(!m1->isEqualIfNotWhy(m2,eps,what2))
1835 what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
1839 std::size_t sz(_part_def.size());
1840 if(sz!=other._part_def.size())
1842 what=std::string("number of subdivision per geo type for part definition is not the same !");
1845 for(std::size_t i=0;i<sz;i++)
1847 const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
1850 if((!pd0 && pd1) || (pd0 && !pd1))
1852 what=std::string("a cell part def is defined only for one among this or other !");
1855 bool ret(pd0->isEqual(pd1,what));
1862 void MEDFileUMeshAggregateCompute::checkConsistency() const
1864 if(_mp_time >= _m_time)
1865 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();
1866 it!=_m_parts.end(); it++)
1867 (*it)->checkConsistency();
1869 _m->checkConsistency();
1872 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
1874 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1875 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
1876 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
1879 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
1881 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1883 const MEDCoupling1GTUMesh *tmp(*it);
1886 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
1887 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
1888 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1889 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
1892 const MEDCouplingUMesh *m(_m);
1895 (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
1896 (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
1897 (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1898 (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
1902 bool MEDFileUMeshAggregateCompute::empty() const
1904 if(_mp_time<_m_time)
1905 return ((const MEDCouplingUMesh *)_m)==0;
1906 //else _mp_time>=_m_time)
1907 return _m_parts.empty();
1910 int MEDFileUMeshAggregateCompute::getMeshDimension() const
1912 if(_mp_time<_m_time)
1914 const MEDCouplingUMesh *m(_m);
1916 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
1917 return m->getMeshDimension();
1921 if(_m_parts.empty())
1922 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
1923 const MEDCoupling1GTUMesh *m(_m_parts[0]);
1925 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
1926 return m->getMeshDimension();
1930 std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
1932 if(_mp_time<_m_time)
1934 const MEDCouplingUMesh *m(_m);
1936 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
1937 return m->getDistributionOfTypes();
1941 std::vector<int> ret;
1942 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1944 const MEDCoupling1GTUMesh *tmp(*it);
1946 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
1947 std::vector<int> ret0(tmp->getDistributionOfTypes());
1948 ret.insert(ret.end(),ret0.begin(),ret0.end());
1954 int MEDFileUMeshAggregateCompute::getSize() const
1956 if(_mp_time<_m_time)
1958 const MEDCouplingUMesh *m(_m);
1960 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
1961 return m->getNumberOfCells();
1966 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1968 const MEDCoupling1GTUMesh *m(*it);
1970 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
1971 ret+=m->getNumberOfCells();
1977 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
1979 for(std::vector< MCAuto<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1981 MEDCoupling1GTUMesh *tmp(*it);
1983 (*it)->setCoords(coords);
1985 MEDCouplingUMesh *m(_m);
1987 m->setCoords(coords);