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"
34 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
35 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
36 extern med_geometry_type typmainoeud[1];
38 using namespace ParaMEDMEM;
40 MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
44 std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const
49 std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull() const
51 return std::vector<const BigMemoryObject *>();
54 int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1)
56 med_mesh_type type_maillage;
57 char maillage_description[MED_COMMENT_SIZE+1];
58 char dtunit[MED_LNAME_SIZE+1];
60 char nommaa[MED_NAME_SIZE+1];
61 med_int n=MEDnMesh(fid);
64 med_sorting_type stype;
65 std::vector<std::string> ms;
67 med_axis_type axistype;
68 for(int i=0;i<n && !found;i++)
70 int naxis(MEDmeshnAxis(fid,i+1));
71 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
72 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
73 MEDFILESAFECALLERRD0(MEDmeshInfo,(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit));
74 dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
75 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
85 std::ostringstream oss;
86 oss << "No such meshname (" << mname << ") in file ! Must be in : ";
87 std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
88 throw INTERP_KERNEL::Exception(oss.str().c_str());
92 case MED_UNSTRUCTURED_MESH:
93 meshType=UNSTRUCTURED;
95 case MED_STRUCTURED_MESH:
98 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mname.c_str(),>));
101 case MED_CARTESIAN_GRID:
104 case MED_CURVILINEAR_GRID:
105 meshType=CURVE_LINEAR;
108 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
113 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
117 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mname.c_str(),1,&numdt,&numit,&dtt));
122 double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it)
127 std::vector< std::pair<int,int> > p(nstep);
128 for(int i=0;i<nstep;i++)
130 MEDFILESAFECALLERRD0(MEDmeshComputationStepInfo,(fid,mName.c_str(),i+1,&numdt,&numit,&dtt));
131 p[i]=std::make_pair<int,int>(numdt,numit);
132 found=(numdt==dt) && (numit==numit);
136 std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! ";
137 oss << "Possibilities are : ";
138 for(int i=0;i<nstep;i++)
139 oss << "(" << p[i].first << "," << p[i].second << "), ";
140 throw INTERP_KERNEL::Exception(oss.str().c_str());
145 std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim)
147 med_mesh_type type_maillage;
149 med_sorting_type stype;
150 med_axis_type axistype;
151 int naxis(MEDmeshnAxis(fid,mId));
152 INTERP_KERNEL::AutoPtr<char> nameTmp=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
153 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
154 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
155 INTERP_KERNEL::AutoPtr<char> univTmp=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
156 if(MEDmeshInfo(fid,mId,nameTmp,&spaceDim,&Mdim,&type_maillage,_description.getPointer(),_dt_unit.getPointer(),
157 &stype,&nstep,&axistype,axisname,axisunit)!=0)
158 throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
159 MEDmeshUniversalNameRd(fid,nameTmp,_univ_name.getPointer());// do not protect MEDFILESAFECALLERRD0 call : Thanks to fra.med.
160 switch(type_maillage)
162 case MED_UNSTRUCTURED_MESH:
163 meshType=UNSTRUCTURED;
165 case MED_STRUCTURED_MESH:
168 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),>));
171 case MED_CARTESIAN_GRID:
174 case MED_CURVILINEAR_GRID:
175 meshType=CURVE_LINEAR;
178 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
183 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
186 std::vector<std::string> infosOnComp(naxis);
187 for(int i=0;i<naxis;i++)
189 std::string info=MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
195 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)
197 if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading()))
199 char nomfam[MED_NAME_SIZE+1];
201 int nfam=MEDnFamily(fid,meshName.c_str());
202 for(int i=0;i<nfam;i++)
204 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
205 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
206 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
207 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
208 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
209 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
210 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
211 std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE);
212 fams[famName]=numfam;
213 for(int j=0;j<ngro;j++)
215 std::string groupname=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
216 grps[groupname].push_back(famName);
221 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)
223 for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++)
225 std::vector<std::string> grpsOfFam;
226 for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
228 if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
229 grpsOfFam.push_back((*it1).first);
231 int ngro=grpsOfFam.size();
232 INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
234 for(std::vector<std::string>::const_iterator it2=grpsOfFam.begin();it2!=grpsOfFam.end();it2++,i++)
235 MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol);
236 INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
237 MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
238 int ret=MEDfamilyCr(fid,mname.c_str(),famName,(*it).second,ngro,groName);
243 MEDFileUMeshL2::MEDFileUMeshL2()
247 std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim)
250 _name.set(mName.c_str());
252 ParaMEDMEM::MEDCouplingMeshType meshType;
253 std::vector<std::string> ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim));
257 return std::vector<std::string>();
259 if(meshType!=UNSTRUCTURED)
260 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
261 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
267 void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
270 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
273 loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency
274 loadCoords(fid,mId,infosOnComp,mName,dt,it);
277 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)
280 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
283 loadPartOfConnectivity(fid,Mdim,mName,types,slicPerTyp,dt,it,mrs);
284 med_bool changement,transformation;
285 int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
286 std::vector<bool> fetchedNodeIds(nCoords,false);
287 for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
288 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
289 (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds);
290 int nMin(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true)));
291 int nMax(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true)));
293 for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
294 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
295 (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin);
296 loadPartCoords(fid,mId,infosOnComp,mName,dt,it,nMin,nMax);
299 void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
301 _per_type_mesh.resize(1);
302 _per_type_mesh[0].clear();
303 for(int j=0;j<MED_N_CELL_FIXED_GEO;j++)
305 MEDFileUMeshPerType *tmp(MEDFileUMeshPerType::New(fid,mName.c_str(),dt,it,mdim,typmai[j],typmai2[j],mrs));
307 _per_type_mesh[0].push_back(tmp);
312 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)
314 std::size_t nbOfTypes(types.size());
315 if(slicPerTyp.size()!=3*nbOfTypes)
316 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : The size of slicPerTyp array is expected to be equal to 3 times size of array types !");
317 std::set<INTERP_KERNEL::NormalizedCellType> types2(types.begin(),types.end());
318 if(types2.size()!=nbOfTypes)
319 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : the geometric types in types array must appear once !");
320 _per_type_mesh.resize(1);
321 _per_type_mesh[0].clear();
322 for(std::size_t ii=0;ii<nbOfTypes;ii++)
324 int strt(slicPerTyp[3*ii+0]),stp(slicPerTyp[3*ii+1]),step(slicPerTyp[3*ii+2]);
325 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs));
326 _per_type_mesh[0].push_back(tmp);
331 void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it)
333 int spaceDim((int)infosOnComp.size());
334 med_bool changement,transformation;
335 int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
336 _coords=DataArrayDouble::New();
337 _coords->alloc(nCoords,spaceDim);
338 double *coordsPtr(_coords->getPointer());
340 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,coordsPtr));
341 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
343 _fam_coords=DataArrayInt::New();
344 _fam_coords->alloc(nCoords,1);
345 MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()));
349 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
351 _num_coords=DataArrayInt::New();
352 _num_coords->alloc(nCoords,1);
353 MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()));
357 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
359 _name_coords=DataArrayAsciiChar::New();
360 _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
361 MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
362 _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
366 for(int i=0;i<spaceDim;i++)
367 _coords->setInfoOnComponent(i,infosOnComp[i]);
370 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)
372 med_bool changement,transformation;
373 int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
374 _coords=DataArrayDouble::New();
375 int nbNodesToLoad(nMax-nMin);
376 _coords->alloc(nbNodesToLoad,spaceDim);
377 med_filter filter=MED_FILTER_INIT,filter2=MED_FILTER_INIT;
378 MEDfilterBlockOfEntityCr(fid,/*nentity*/nCoords,/*nvaluesperentity*/1,/*nconstituentpervalue*/spaceDim,
379 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
380 /*start*/nMin+1,/*stride*/1,/*count*/1,/*blocksize*/nbNodesToLoad,
381 /*lastblocksize=useless because count=1*/0,&filter);
382 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateAdvancedRd,(fid,mName.c_str(),dt,it,&filter,_coords->getPointer()));
383 _part_coords=PartDefinition::New(nMin,nMax,1);
384 MEDfilterClose(&filter);
385 MEDfilterBlockOfEntityCr(fid,nCoords,1,1,MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,
386 MED_NO_PROFILE,nMin+1,1,1,nbNodesToLoad,0,&filter2);
387 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
389 _fam_coords=DataArrayInt::New();
390 _fam_coords->alloc(nbNodesToLoad,1);
391 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_fam_coords->getPointer()));
395 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
397 _num_coords=DataArrayInt::New();
398 _num_coords->alloc(nbNodesToLoad,1);
399 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_num_coords->getPointer()));
403 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
405 _name_coords=DataArrayAsciiChar::New();
406 _name_coords->alloc(nbNodesToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
407 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NAME,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_name_coords->getPointer()));
408 _name_coords->reAlloc(nbNodesToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
412 MEDfilterClose(&filter2);
413 _coords->setInfoOnComponents(infosOnComp);
416 void MEDFileUMeshL2::sortTypes()
419 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
420 _per_type_mesh.clear();
421 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
422 mdims.insert((*it)->getDim());
425 int mdim=*mdims.rbegin();
426 _per_type_mesh.resize(mdim+1);
427 for(int dim=mdim+1;dim!=0;dim--)
429 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
430 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
431 if((*it)->getDim()==dim-1)
434 // suppression of contiguous empty levels at the end of _per_type_mesh.
435 int nbOfUselessLev=0;
437 for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
439 if((*it2).empty() && isFirst)
446 _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
449 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)
453 MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer()));
455 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer()));
457 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer()));
460 if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
462 std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
463 oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
464 throw INTERP_KERNEL::Exception(oss.str().c_str());
466 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer()));
470 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
472 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
473 if((*it)->getFam()==0)
478 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
480 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
481 if((*it)->getNum()==0)
486 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
488 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
489 if((*it)->getNames()==0)
494 MEDFileCMeshL2::MEDFileCMeshL2()
498 void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
500 _name.set(mName.c_str());
503 ParaMEDMEM::MEDCouplingMeshType meshType;
504 std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim);
505 if(meshType!=CARTESIAN)
506 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
507 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
511 med_grid_type gridtype;
512 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype));
513 if(gridtype!=MED_CARTESIAN_GRID)
514 throw INTERP_KERNEL::Exception("Invalid structured mesh ! Expected cartesian mesh type !");
515 _cmesh=MEDCouplingCMesh::New();
516 for(int i=0;i<Mdim;i++)
518 med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
519 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
520 int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf));
521 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
522 da->alloc(nbOfElt,1);
523 da->setInfoOnComponent(0,infosOnComp[i]);
524 MEDFILESAFECALLERRD0(MEDmeshGridIndexCoordinateRd,(fid,mName.c_str(),dt,it,i+1,da->getPointer()));
525 _cmesh->setCoordsAt(i,da);
529 med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id)
534 return MED_COORDINATE_AXIS1;
536 return MED_COORDINATE_AXIS2;
538 return MED_COORDINATE_AXIS3;
540 throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
544 MEDFileCLMeshL2::MEDFileCLMeshL2()
548 void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
550 _name.set(mName.c_str());
553 ParaMEDMEM::MEDCouplingMeshType meshType;
554 std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
555 if(meshType!=CURVE_LINEAR)
556 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
557 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
561 _clmesh=MEDCouplingCurveLinearMesh::New();
562 INTERP_KERNEL::AutoPtr<int> stGrid=new int[Mdim];
563 MEDFILESAFECALLERRD0(MEDmeshGridStructRd,(fid,mName.c_str(),dt,it,stGrid));
564 _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim);
565 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
566 int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf));
567 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
568 da->alloc(nbNodes,infosOnComp.size());
569 da->setInfoOnComponents(infosOnComp);
570 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer()));
571 _clmesh->setCoords(da);
574 MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
579 * Warning it returns an instance to deallocate !!!!
581 MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
583 _st->_num->updateTime();
584 if((MEDCouplingUMesh *)_m==0)
587 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
588 _m->renumberCells(_st->_num->getConstPointer(),true);
593 if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
598 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
599 _m->renumberCells(_st->_num->getConstPointer(),true);
605 void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
610 void MEDFileUMeshPermCompute::updateTime() const
612 _mpt_time=_st->_m_by_types.getTimeOfThis();
613 _num_time=_st->_num->getTimeOfThis();
616 std::vector<const BigMemoryObject *> MEDFileUMeshPermCompute::getDirectChildrenWithNull() const
618 std::vector<const BigMemoryObject *> ret;
619 ret.push_back((const MEDCouplingUMesh *)_m);
623 std::size_t MEDFileUMeshPermCompute::getHeapMemorySizeWithoutChildren() const
625 return sizeof(MEDFileUMeshPermCompute);
628 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)
632 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this)
634 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& v=l2.getLev(id);
638 std::vector<const MEDCoupling1GTUMesh *> ms(sz);
639 std::vector<const DataArrayInt *> fams(sz),nums(sz);
640 std::vector<const DataArrayChar *> names(sz);
641 std::vector<const PartDefinition *> pds(sz);
642 for(int i=0;i<sz;i++)
644 MEDCoupling1GTUMesh *elt(v[i]->getMesh());
645 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp2=l2.getCoords();
646 elt->setCoords(tmp2);
648 pds[i]=v[i]->getPartDef();
650 _m_by_types.assignParts(ms);
651 _m_by_types.assignDefParts(pds);
652 if(l2.isFamDefinedOnLev(id))
654 for(int i=0;i<sz;i++)
655 fams[i]=v[i]->getFam();
657 _fam=DataArrayInt::Aggregate(fams);
661 _fam=const_cast<DataArrayInt *>(fams[0]);
664 if(l2.isNumDefinedOnLev(id))
666 for(int i=0;i<sz;i++)
667 nums[i]=v[i]->getNum();
669 _num=DataArrayInt::Aggregate(nums);
673 _num=const_cast<DataArrayInt *>(nums[0]);
677 if(l2.isNamesDefinedOnLev(id))
679 for(int i=0;i<sz;i++)
680 names[i]=v[i]->getNames();
681 _names=dynamic_cast<DataArrayAsciiChar *>(DataArrayChar::Aggregate(names));
685 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m):_m(this)
687 std::vector< const MEDCoupling1GTUMesh * > v(1);
692 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
697 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
699 assignMesh(m,newOrOld);
702 void MEDFileUMeshSplitL1::setName(const std::string& name)
704 _m_by_types.setName(name);
707 std::size_t MEDFileUMeshSplitL1::getHeapMemorySizeWithoutChildren() const
712 std::vector<const BigMemoryObject *> MEDFileUMeshSplitL1::getDirectChildrenWithNull() const
714 std::vector<const BigMemoryObject *> ret;
715 ret.push_back(&_m_by_types);
717 ret.push_back((const DataArrayInt*)_fam);
718 ret.push_back((const DataArrayInt*)_num);
719 ret.push_back((const DataArrayInt*)_rev_num);
720 ret.push_back((const DataArrayAsciiChar*)_names);
724 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy(DataArrayDouble *coords) const
726 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret=new MEDFileUMeshSplitL1(*this);
727 ret->_m_by_types=_m_by_types.deepCpy(coords);
728 if((const DataArrayInt *)_fam)
729 ret->_fam=_fam->deepCpy();
730 if((const DataArrayInt *)_num)
731 ret->_num=_num->deepCpy();
732 if((const DataArrayInt *)_rev_num)
733 ret->_rev_num=_rev_num->deepCpy();
734 if((const DataArrayAsciiChar *)_names)
735 ret->_names=_names->deepCpy();
739 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
741 if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
743 const DataArrayInt *d1=_fam;
744 const DataArrayInt *d2=other->_fam;
745 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
747 what="Presence of family arr in one sublevel and not in other!";
751 if(!d1->isEqual(*d2))
753 what="family arr at a sublevel are not deeply equal !";
758 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
760 what="Presence of cell numbering arr in one sublevel and not in other!";
764 if(!d1->isEqual(*d2))
766 what="Numbering cell arr at a sublevel are not deeply equal !";
769 const DataArrayAsciiChar *e1=_names;
770 const DataArrayAsciiChar *e2=other->_names;
771 if((e1==0 && e2!=0) || (e1!=0 && e2==0))
773 what="Presence of cell names arr in one sublevel and not in other!";
777 if(!e1->isEqual(*e2))
779 what="Name cell arr at a sublevel are not deeply equal !";
785 void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
787 _m_by_types.synchronizeTinyInfo(master);
790 void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
792 _m_by_types.clearNonDiscrAttributes();
795 void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
799 (const_cast<MEDCouplingMesh *>(tmp))->setName("");
800 (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
801 (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
802 (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
805 void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords)
807 _m_by_types.setCoords(coords);
810 void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
816 _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCpy()));
817 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
818 if(!da->isIdentity())
820 _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
823 _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false);
828 if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
829 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !");
831 _m_by_types.assignUMesh(m);
836 void MEDFileUMeshSplitL1::forceComputationOfParts() const
838 _m_by_types.forceComputationOfPartsFromUMesh();
841 void MEDFileUMeshSplitL1::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
843 _m_by_types.assignParts(mParts);
847 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this)
851 void MEDFileUMeshSplitL1::assignCommonPart()
853 _fam=DataArrayInt::New();
854 _fam->alloc(_m_by_types.getSize(),1);
855 _fam->fillWithValue(0);
858 bool MEDFileUMeshSplitL1::empty() const
860 return _m_by_types.empty();
863 bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector<int>& ids) const
865 const DataArrayInt *fam=_fam;
868 return fam->presenceOfValue(ids);
871 int MEDFileUMeshSplitL1::getMeshDimension() const
873 return _m_by_types.getMeshDimension();
876 void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const
878 std::vector<int> code=_m_by_types.getDistributionOfTypes();
879 int nbOfTypes=code.size()/3;
880 for(int i=0;i<nbOfTypes;i++)
882 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType) code[3*i];
883 oss << " - Number of cells with type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr() << " : " << code[3*i+1] << std::endl;
887 int MEDFileUMeshSplitL1::getSize() const
889 return _m_by_types.getSize();
892 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
894 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> eltsToKeep=_fam->getIdsEqualList(idsBg,idsEnd);
895 MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
897 return renumIfNeeded(m,eltsToKeep->getConstPointer());
901 DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const
903 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam->getIdsEqualList(idsBg,idsEnd);
905 return renumIfNeededArr(da);
909 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes() const
911 return _m_by_types.getGeoTypes();
914 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
916 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp;
917 if(renum && ((const DataArrayInt *)_num))
920 { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
924 int MEDFileUMeshSplitL1::getNumberOfCells() const
926 return _m_by_types.getNumberOfCells();
929 DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
931 const DataArrayInt *fam(_fam);
934 int start(0),stop(0);
935 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
936 return fam->selectByTupleId2(start,stop,1);
939 DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
941 const DataArrayInt *num(_num);
944 int start(0),stop(0);
945 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
946 return num->selectByTupleId2(start,stop,1);
949 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
951 if((DataArrayInt *)_fam)
953 int nbOfTuples=_m_by_types.getSize();
954 _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
958 const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
963 const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const
968 const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const
973 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
978 const PartDefinition *MEDFileUMeshSplitL1::getPartDef(INTERP_KERNEL::NormalizedCellType gt) const
980 return _m_by_types.getPartDefOfWithoutComputation(gt);
983 void MEDFileUMeshSplitL1::eraseFamilyField()
985 _fam->fillWithZero();
989 * This method ignores _m and _m_by_types.
991 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
992 std::map<std::string, std::vector<std::string> >& groups)
994 std::vector< DataArrayInt * > corr;
995 _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
996 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
997 std::vector< std::vector<int> > fidsOfGroups;
998 std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
999 _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
1000 int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
1001 std::map<int,std::string> newfams;
1002 std::map<int,int> famIdTrad;
1003 TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
1004 int *w=_fam->getPointer();
1005 for(int i=0;i<nbOfCells;i++,w++)
1009 void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const
1011 std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1013 for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
1015 int nbCells=(*it)->getNumberOfCells();
1016 int end=start+nbCells;
1017 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam,num;
1018 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> names;
1019 if((const DataArrayInt *)_fam)
1020 fam=_fam->substr(start,end);
1021 if((const DataArrayInt *)_num)
1022 num=_num->substr(start,end);
1023 if((const DataArrayAsciiChar *)_names)
1024 names=static_cast<DataArrayAsciiChar *>(_names->substr(start,end));
1025 MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
1030 void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N)
1032 _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
1035 void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
1037 bigArraysI.push_back(_fam);
1038 bigArraysI.push_back(_num);
1039 _m_by_types.serialize(tinyInt,bigArraysI);
1042 void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1044 _fam=bigArraysI.back(); bigArraysI.pop_back();
1045 _num=bigArraysI.back(); bigArraysI.pop_back();
1046 _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
1049 void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId)
1051 DataArrayInt *arr=_fam;
1053 arr->changeValue(oldId,newId);
1056 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr)
1063 int sz(_m_by_types.getSize());
1064 famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
1069 DataArrayInt *MEDFileUMeshSplitL1::getFamilyField()
1074 void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr)
1082 int sz(_m_by_types.getSize());
1083 renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
1084 renumArr->incrRef();
1089 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
1096 int sz(_m_by_types.getSize());
1097 nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
1102 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds)
1107 m->renumberCells(renum->getConstPointer(),true);
1110 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
1111 m->renumberCells(locnum->getConstPointer(),true);
1116 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1118 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
1119 ret->unserialize(name,coo,tinyInt,bigArraysI);
1123 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
1125 return Renumber2(_num,m,cellIds);
1128 DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da)
1130 if((const DataArrayInt *)renum==0)
1133 return const_cast<DataArrayInt *>(da);
1135 return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
1138 DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
1140 return Renumber(_num,da);
1143 std::vector<int> MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
1146 for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
1147 id=std::max(id,(*it).second);
1150 std::vector<int> ret(nb);
1151 for(int i=1;i<=nb;i++)
1156 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
1157 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
1159 std::set<int> allfids;
1163 void MEDFileUMeshSplitL1::computeRevNum() const
1166 int maxValue=_num->getMaxValue(pos);
1167 _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
1172 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
1176 void MEDFileUMeshAggregateCompute::setName(const std::string& name)
1178 if(_m_time>=_mp_time)
1180 MEDCouplingUMesh *um(_m);
1184 if(_mp_time>=_m_time)
1186 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1188 MEDCoupling1GTUMesh *tmp(*it);
1195 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1197 std::size_t sz(mParts.size());
1198 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > ret(sz);
1199 for(std::size_t i=0;i<sz;i++)
1201 const MEDCoupling1GTUMesh *elt(mParts[i]);
1203 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
1204 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
1207 _part_def.clear(); _part_def.resize(sz);
1208 _mp_time=std::max(_mp_time,_m_time)+1;
1212 void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector<const PartDefinition *>& partDefs)
1214 if(_mp_time<_m_time)
1215 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !");
1216 std::size_t sz(partDefs.size());
1217 if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size())
1218 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !");
1219 for(std::size_t i=0;i<sz;i++)
1221 const PartDefinition *elt(partDefs[i]);
1224 _part_def[i]=const_cast<PartDefinition*>(elt);
1228 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
1232 _m_time=std::max(_mp_time,_m_time)+1;
1235 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
1237 if(_mp_time<=_m_time)
1239 std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
1240 std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
1241 _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
1242 _m_parts.clear();//to avoid memory peak !
1243 _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
1247 int MEDFileUMeshAggregateCompute::getNumberOfCells() const
1249 if(_mp_time<=_m_time)
1250 return _m->getNumberOfCells();
1252 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1253 ret+=(*it)->getNumberOfCells();
1257 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
1259 if(_mp_time>=_m_time)
1261 std::size_t sz(_m_parts.size());
1262 std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
1263 for(std::size_t i=0;i<sz;i++)
1264 ret[i]=_m_parts[i]->getCellModelEnum();
1268 return _m->getAllGeoTypesSorted();
1271 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
1273 if(_mp_time<_m_time)
1274 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
1276 std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
1278 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
1280 const MEDCoupling1GTUMesh *elt(*it);
1281 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
1286 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
1288 if(_mp_time<_m_time)
1289 forceComputationOfPartsFromUMesh();
1290 return retrievePartsWithoutComputation();
1293 MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1295 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1296 std::size_t sz(v.size());
1297 for(std::size_t i=0;i<sz;i++)
1300 if(v[i]->getCellModelEnum()==gt)
1303 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
1306 void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const
1309 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1310 std::size_t sz(v.size());
1311 for(std::size_t i=0;i<sz;i++)
1315 if(v[i]->getCellModelEnum()==gt)
1317 stop=start+v[i]->getNumberOfCells();
1321 start+=v[i]->getNumberOfCells();
1324 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
1327 void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N)
1329 if(_mp_time>_m_time)
1331 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1333 MEDCoupling1GTUMesh *m(*it);
1335 m->renumberNodesInConn(newNodeNumbersO2N);
1340 MEDCouplingUMesh *m(getUmesh());
1343 m->renumberNodesInConn(newNodeNumbersO2N);
1347 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1349 const MEDCouplingUMesh *m(_m);
1351 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1352 std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1353 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1354 std::size_t sz(msMSafe.size());
1355 _m_parts.resize(sz);
1356 for(std::size_t i=0;i<sz;i++)
1357 _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1359 _part_def.resize(_m_parts.size());
1360 _mp_time=std::max(_mp_time,_m_time);
1363 const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1365 if(_mp_time<_m_time)
1366 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : the parts require a computation !");
1367 if(_m_parts.size()!=_part_def.size())
1368 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : size of arrays are expected to be the same !");
1369 std::size_t sz(_m_parts.size());
1370 for(std::size_t i=0;i<sz;i++)
1372 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1374 if(mesh->getCellModelEnum()==gt)
1375 return _part_def[i];
1377 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
1380 void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
1382 if(_mp_time<_m_time)
1383 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
1384 std::size_t sz(_m_parts.size());
1385 tinyInt.push_back((int)sz);
1386 for(std::size_t i=0;i<sz;i++)
1388 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1390 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
1391 tinyInt.push_back(mesh->getCellModelEnum());
1392 const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
1393 const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
1396 DataArrayInt *elt(mesh1->getNodalConnectivity());
1399 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt1(elt);
1400 bigArraysI.push_back(elt1);
1404 DataArrayInt *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
1409 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt11(elt1),elt22(elt2);
1410 bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
1413 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
1414 const PartDefinition *pd(_part_def[i]);
1416 tinyInt.push_back(-1);
1419 std::vector<int> tinyTmp;
1420 pd->serialize(tinyTmp,bigArraysI);
1421 tinyInt.push_back((int)tinyTmp.size());
1422 tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
1427 void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1429 int nbParts(tinyInt.back()); tinyInt.pop_back();
1430 _part_def.clear(); _part_def.resize(nbParts);
1431 _m_parts.clear(); _m_parts.resize(nbParts);
1432 for(int i=0;i<nbParts;i++)
1434 INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
1435 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
1436 mesh->setCoords(coo);
1437 MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1438 MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1441 mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
1445 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt0,elt1;
1446 elt0=bigArraysI.back(); bigArraysI.pop_back();
1447 elt1=bigArraysI.back(); bigArraysI.pop_back();
1448 mesh2->setNodalConnectivity(elt0,elt1);
1451 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
1453 int pdid(tinyInt.back()); tinyInt.pop_back();
1455 _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
1456 _mp_time=std::max(_mp_time,_m_time)+1;
1461 * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
1463 bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const
1465 return _mp_time>=_m_time;
1468 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
1470 if(_mp_time>_m_time)
1471 return getTimeOfParts();
1472 if(_m_time>_mp_time)
1473 return getTimeOfUMesh();
1474 return std::max(getTimeOfParts(),getTimeOfUMesh());
1477 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
1480 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1482 const MEDCoupling1GTUMesh *elt(*it);
1484 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
1485 ret=std::max(ret,elt->getTimeOfThis());
1488 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
1492 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
1494 const MEDCouplingUMesh *m(_m);
1496 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
1497 return m->getTimeOfThis();
1500 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
1502 std::size_t ret(_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>));
1506 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
1508 std::vector<const BigMemoryObject *> ret;
1509 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1510 ret.push_back((const MEDCoupling1GTUMesh *)*it);
1511 ret.push_back((const MEDCouplingUMesh *)_m);
1515 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const
1517 MEDFileUMeshAggregateCompute ret;
1518 ret._m_parts.resize(_m_parts.size());
1519 for(std::size_t i=0;i<_m_parts.size();i++)
1521 const MEDCoupling1GTUMesh *elt(_m_parts[i]);
1524 ret._m_parts[i]=static_cast<ParaMEDMEM::MEDCoupling1GTUMesh*>(elt->deepCpy());
1525 ret._m_parts[i]->setCoords(coords);
1528 ret._mp_time=_mp_time; ret._m_time=_m_time;
1529 if((const MEDCouplingUMesh *)_m)
1531 ret._m=static_cast<ParaMEDMEM::MEDCouplingUMesh*>(_m->deepCpy());
1532 ret._m->setCoords(coords);
1534 std::size_t sz(_part_def.size());
1535 ret._part_def.clear(); ret._part_def.resize(sz);
1536 for(std::size_t i=0;i<sz;i++)
1538 const PartDefinition *elt(_part_def[i]);
1540 ret._part_def[i]=elt->deepCpy();
1545 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
1547 const MEDCouplingUMesh *m1(getUmesh());
1548 const MEDCouplingUMesh *m2(other.getUmesh());
1549 if((m1==0 && m2!=0) || (m1!=0 && m2==0))
1551 what="Presence of mesh in one sublevel and not in other!";
1557 if(!m1->isEqualIfNotWhy(m2,eps,what2))
1559 what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
1563 std::size_t sz(_part_def.size());
1564 if(sz!=other._part_def.size())
1566 what=std::string("number of subdivision per geo type for part definition is not the same !");
1569 for(std::size_t i=0;i<sz;i++)
1571 const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
1574 if((!pd0 && pd1) || (pd0 && !pd1))
1576 what=std::string("a cell part def is defined only for one among this or other !");
1579 bool ret(pd0->isEqual(pd1,what));
1586 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
1588 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1589 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
1590 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
1593 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
1595 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1597 const MEDCoupling1GTUMesh *tmp(*it);
1600 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
1601 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
1602 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1603 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
1606 const MEDCouplingUMesh *m(_m);
1609 (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
1610 (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
1611 (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1612 (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
1616 bool MEDFileUMeshAggregateCompute::empty() const
1618 if(_mp_time<_m_time)
1619 return ((const MEDCouplingUMesh *)_m)==0;
1620 //else _mp_time>=_m_time)
1621 return _m_parts.empty();
1624 int MEDFileUMeshAggregateCompute::getMeshDimension() const
1626 if(_mp_time<_m_time)
1628 const MEDCouplingUMesh *m(_m);
1630 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
1631 return m->getMeshDimension();
1635 if(_m_parts.empty())
1636 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
1637 const MEDCoupling1GTUMesh *m(_m_parts[0]);
1639 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
1640 return m->getMeshDimension();
1644 std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
1646 if(_mp_time<_m_time)
1648 const MEDCouplingUMesh *m(_m);
1650 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
1651 return m->getDistributionOfTypes();
1655 std::vector<int> ret;
1656 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1658 const MEDCoupling1GTUMesh *tmp(*it);
1660 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
1661 std::vector<int> ret0(tmp->getDistributionOfTypes());
1662 ret.insert(ret.end(),ret0.begin(),ret0.end());
1668 int MEDFileUMeshAggregateCompute::getSize() const
1670 if(_mp_time<_m_time)
1672 const MEDCouplingUMesh *m(_m);
1674 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
1675 return m->getNumberOfCells();
1680 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1682 const MEDCoupling1GTUMesh *m(*it);
1684 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
1685 ret+=m->getNumberOfCells();
1691 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
1693 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1695 MEDCoupling1GTUMesh *tmp(*it);
1697 (*it)->setCoords(coords);
1699 MEDCouplingUMesh *m(_m);
1701 m->setCoords(coords);