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());
339 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,coordsPtr));
340 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
342 _fam_coords=DataArrayInt::New();
343 _fam_coords->alloc(nCoords,1);
344 MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer()));
348 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
350 _num_coords=DataArrayInt::New();
351 _num_coords->alloc(nCoords,1);
352 MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer()));
356 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
358 _name_coords=DataArrayAsciiChar::New();
359 _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
360 MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer()));
361 _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
365 for(int i=0;i<spaceDim;i++)
366 _coords->setInfoOnComponent(i,infosOnComp[i]);
369 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)
371 med_bool changement,transformation;
372 int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
373 _coords=DataArrayDouble::New();
374 int nbNodesToLoad(nMax-nMin);
375 _coords->alloc(nbNodesToLoad,spaceDim);
376 med_filter filter=MED_FILTER_INIT,filter2=MED_FILTER_INIT;
377 MEDfilterBlockOfEntityCr(fid,/*nentity*/nCoords,/*nvaluesperentity*/1,/*nconstituentpervalue*/spaceDim,
378 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
379 /*start*/nMin+1,/*stride*/1,/*count*/1,/*blocksize*/nbNodesToLoad,
380 /*lastblocksize=useless because count=1*/0,&filter);
381 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateAdvancedRd,(fid,mName.c_str(),dt,it,&filter,_coords->getPointer()));
382 _part_coords=PartDefinition::New(nMin,nMax,1);
383 MEDfilterClose(&filter);
384 MEDfilterBlockOfEntityCr(fid,nCoords,1,1,MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,
385 MED_NO_PROFILE,nMin+1,1,1,nbNodesToLoad,0,&filter2);
386 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
388 _fam_coords=DataArrayInt::New();
389 _fam_coords->alloc(nbNodesToLoad,1);
390 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_fam_coords->getPointer()));
394 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
396 _num_coords=DataArrayInt::New();
397 _num_coords->alloc(nbNodesToLoad,1);
398 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_num_coords->getPointer()));
402 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
404 _name_coords=DataArrayAsciiChar::New();
405 _name_coords->alloc(nbNodesToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
406 MEDFILESAFECALLERRD0(MEDmeshEntityAttributeAdvancedRd,(fid,mName.c_str(),MED_NAME,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_name_coords->getPointer()));
407 _name_coords->reAlloc(nbNodesToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
411 MEDfilterClose(&filter2);
412 _coords->setInfoOnComponents(infosOnComp);
415 void MEDFileUMeshL2::sortTypes()
418 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
419 _per_type_mesh.clear();
420 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
421 mdims.insert((*it)->getDim());
424 int mdim=*mdims.rbegin();
425 _per_type_mesh.resize(mdim+1);
426 for(int dim=mdim+1;dim!=0;dim--)
428 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
429 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
430 if((*it)->getDim()==dim-1)
433 // suppression of contiguous empty levels at the end of _per_type_mesh.
434 int nbOfUselessLev=0;
436 for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
438 if((*it2).empty() && isFirst)
445 _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
448 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)
452 MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer()));
454 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer()));
456 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer()));
459 if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
461 std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
462 oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
463 throw INTERP_KERNEL::Exception(oss.str().c_str());
465 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer()));
469 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
471 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
472 if((*it)->getFam()==0)
477 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
479 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
480 if((*it)->getNum()==0)
485 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
487 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
488 if((*it)->getNames()==0)
493 MEDFileCMeshL2::MEDFileCMeshL2()
497 void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
499 _name.set(mName.c_str());
502 ParaMEDMEM::MEDCouplingMeshType meshType;
503 std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim);
504 if(meshType!=CARTESIAN)
505 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
506 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
510 med_grid_type gridtype;
511 MEDFILESAFECALLERRD0(MEDmeshGridTypeRd,(fid,mName.c_str(),&gridtype));
512 if(gridtype!=MED_CARTESIAN_GRID)
513 throw INTERP_KERNEL::Exception("Invalid structured mesh ! Expected cartesian mesh type !");
514 _cmesh=MEDCouplingCMesh::New();
515 for(int i=0;i<Mdim;i++)
517 med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
518 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
519 int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf));
520 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
521 da->alloc(nbOfElt,1);
522 da->setInfoOnComponent(0,infosOnComp[i]);
523 MEDFILESAFECALLERRD0(MEDmeshGridIndexCoordinateRd,(fid,mName.c_str(),dt,it,i+1,da->getPointer()));
524 _cmesh->setCoordsAt(i,da);
528 med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id)
533 return MED_COORDINATE_AXIS1;
535 return MED_COORDINATE_AXIS2;
537 return MED_COORDINATE_AXIS3;
539 throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
543 MEDFileCLMeshL2::MEDFileCLMeshL2()
547 void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
549 _name.set(mName.c_str());
552 ParaMEDMEM::MEDCouplingMeshType meshType;
553 std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
554 if(meshType!=CURVE_LINEAR)
555 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
556 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
560 _clmesh=MEDCouplingCurveLinearMesh::New();
561 INTERP_KERNEL::AutoPtr<int> stGrid=new int[Mdim];
562 MEDFILESAFECALLERRD0(MEDmeshGridStructRd,(fid,mName.c_str(),dt,it,stGrid));
563 _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim);
564 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
565 int nbNodes(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf));
566 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
567 da->alloc(nbNodes,infosOnComp.size());
568 da->setInfoOnComponents(infosOnComp);
569 MEDFILESAFECALLERRD0(MEDmeshNodeCoordinateRd,(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer()));
570 _clmesh->setCoords(da);
573 MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
578 * Warning it returns an instance to deallocate !!!!
580 MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
582 _st->_num->updateTime();
583 if((MEDCouplingUMesh *)_m==0)
586 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
587 _m->renumberCells(_st->_num->getConstPointer(),true);
592 if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
597 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
598 _m->renumberCells(_st->_num->getConstPointer(),true);
604 void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
609 void MEDFileUMeshPermCompute::updateTime() const
611 _mpt_time=_st->_m_by_types.getTimeOfThis();
612 _num_time=_st->_num->getTimeOfThis();
615 std::vector<const BigMemoryObject *> MEDFileUMeshPermCompute::getDirectChildrenWithNull() const
617 std::vector<const BigMemoryObject *> ret;
618 ret.push_back((const MEDCouplingUMesh *)_m);
622 std::size_t MEDFileUMeshPermCompute::getHeapMemorySizeWithoutChildren() const
624 return sizeof(MEDFileUMeshPermCompute);
627 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)
631 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this)
633 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& v=l2.getLev(id);
637 std::vector<const MEDCoupling1GTUMesh *> ms(sz);
638 std::vector<const DataArrayInt *> fams(sz),nums(sz);
639 std::vector<const DataArrayChar *> names(sz);
640 std::vector<const PartDefinition *> pds(sz);
641 for(int i=0;i<sz;i++)
643 MEDCoupling1GTUMesh *elt(v[i]->getMesh());
644 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp2=l2.getCoords();
645 elt->setCoords(tmp2);
647 pds[i]=v[i]->getPartDef();
649 _m_by_types.assignParts(ms);
650 _m_by_types.assignDefParts(pds);
651 if(l2.isFamDefinedOnLev(id))
653 for(int i=0;i<sz;i++)
654 fams[i]=v[i]->getFam();
656 _fam=DataArrayInt::Aggregate(fams);
660 _fam=const_cast<DataArrayInt *>(fams[0]);
663 if(l2.isNumDefinedOnLev(id))
665 for(int i=0;i<sz;i++)
666 nums[i]=v[i]->getNum();
668 _num=DataArrayInt::Aggregate(nums);
672 _num=const_cast<DataArrayInt *>(nums[0]);
676 if(l2.isNamesDefinedOnLev(id))
678 for(int i=0;i<sz;i++)
679 names[i]=v[i]->getNames();
680 _names=dynamic_cast<DataArrayAsciiChar *>(DataArrayChar::Aggregate(names));
684 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m):_m(this)
686 std::vector< const MEDCoupling1GTUMesh * > v(1);
691 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
696 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
698 assignMesh(m,newOrOld);
701 void MEDFileUMeshSplitL1::setName(const std::string& name)
703 _m_by_types.setName(name);
706 std::size_t MEDFileUMeshSplitL1::getHeapMemorySizeWithoutChildren() const
711 std::vector<const BigMemoryObject *> MEDFileUMeshSplitL1::getDirectChildrenWithNull() const
713 std::vector<const BigMemoryObject *> ret;
714 ret.push_back(&_m_by_types);
716 ret.push_back((const DataArrayInt*)_fam);
717 ret.push_back((const DataArrayInt*)_num);
718 ret.push_back((const DataArrayInt*)_rev_num);
719 ret.push_back((const DataArrayAsciiChar*)_names);
723 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy(DataArrayDouble *coords) const
725 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret=new MEDFileUMeshSplitL1(*this);
726 ret->_m_by_types=_m_by_types.deepCpy(coords);
727 if((const DataArrayInt *)_fam)
728 ret->_fam=_fam->deepCpy();
729 if((const DataArrayInt *)_num)
730 ret->_num=_num->deepCpy();
731 if((const DataArrayInt *)_rev_num)
732 ret->_rev_num=_rev_num->deepCpy();
733 if((const DataArrayAsciiChar *)_names)
734 ret->_names=_names->deepCpy();
738 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
740 if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
742 const DataArrayInt *d1=_fam;
743 const DataArrayInt *d2=other->_fam;
744 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
746 what="Presence of family arr in one sublevel and not in other!";
750 if(!d1->isEqual(*d2))
752 what="family arr at a sublevel are not deeply equal !";
757 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
759 what="Presence of cell numbering arr in one sublevel and not in other!";
763 if(!d1->isEqual(*d2))
765 what="Numbering cell arr at a sublevel are not deeply equal !";
768 const DataArrayAsciiChar *e1=_names;
769 const DataArrayAsciiChar *e2=other->_names;
770 if((e1==0 && e2!=0) || (e1!=0 && e2==0))
772 what="Presence of cell names arr in one sublevel and not in other!";
776 if(!e1->isEqual(*e2))
778 what="Name cell arr at a sublevel are not deeply equal !";
784 void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
786 _m_by_types.synchronizeTinyInfo(master);
789 void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
791 _m_by_types.clearNonDiscrAttributes();
794 void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
798 (const_cast<MEDCouplingMesh *>(tmp))->setName("");
799 (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
800 (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
801 (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
804 void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords)
806 _m_by_types.setCoords(coords);
809 void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
815 _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCpy()));
816 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
817 if(!da->isIdentity())
819 _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
822 _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false);
827 if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
828 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !");
830 _m_by_types.assignUMesh(m);
835 void MEDFileUMeshSplitL1::forceComputationOfParts() const
837 _m_by_types.forceComputationOfPartsFromUMesh();
840 void MEDFileUMeshSplitL1::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
842 _m_by_types.assignParts(mParts);
846 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this)
850 void MEDFileUMeshSplitL1::assignCommonPart()
852 _fam=DataArrayInt::New();
853 _fam->alloc(_m_by_types.getSize(),1);
854 _fam->fillWithValue(0);
857 bool MEDFileUMeshSplitL1::empty() const
859 return _m_by_types.empty();
862 bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector<int>& ids) const
864 const DataArrayInt *fam=_fam;
867 return fam->presenceOfValue(ids);
870 int MEDFileUMeshSplitL1::getMeshDimension() const
872 return _m_by_types.getMeshDimension();
875 void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const
877 std::vector<int> code=_m_by_types.getDistributionOfTypes();
878 int nbOfTypes=code.size()/3;
879 for(int i=0;i<nbOfTypes;i++)
881 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType) code[3*i];
882 oss << " - Number of cells with type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr() << " : " << code[3*i+1] << std::endl;
886 int MEDFileUMeshSplitL1::getSize() const
888 return _m_by_types.getSize();
891 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
893 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> eltsToKeep=_fam->getIdsEqualList(idsBg,idsEnd);
894 MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
896 return renumIfNeeded(m,eltsToKeep->getConstPointer());
900 DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const
902 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam->getIdsEqualList(idsBg,idsEnd);
904 return renumIfNeededArr(da);
908 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes() const
910 return _m_by_types.getGeoTypes();
913 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
915 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp;
916 if(renum && ((const DataArrayInt *)_num))
919 { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
923 int MEDFileUMeshSplitL1::getNumberOfCells() const
925 return _m_by_types.getNumberOfCells();
928 DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
930 const DataArrayInt *fam(_fam);
933 int start(0),stop(0);
934 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
935 return fam->selectByTupleId2(start,stop,1);
938 DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
940 const DataArrayInt *num(_num);
943 int start(0),stop(0);
944 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
945 return num->selectByTupleId2(start,stop,1);
948 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
950 if((DataArrayInt *)_fam)
952 int nbOfTuples=_m_by_types.getSize();
953 _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
957 const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
962 const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const
967 const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const
972 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
977 const PartDefinition *MEDFileUMeshSplitL1::getPartDef(INTERP_KERNEL::NormalizedCellType gt) const
979 return _m_by_types.getPartDefOfWithoutComputation(gt);
982 void MEDFileUMeshSplitL1::eraseFamilyField()
984 _fam->fillWithZero();
988 * This method ignores _m and _m_by_types.
990 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
991 std::map<std::string, std::vector<std::string> >& groups)
993 std::vector< DataArrayInt * > corr;
994 _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
995 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
996 std::vector< std::vector<int> > fidsOfGroups;
997 std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
998 _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
999 int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
1000 std::map<int,std::string> newfams;
1001 std::map<int,int> famIdTrad;
1002 TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
1003 int *w=_fam->getPointer();
1004 for(int i=0;i<nbOfCells;i++,w++)
1008 void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const
1010 std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1012 for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
1014 int nbCells=(*it)->getNumberOfCells();
1015 int end=start+nbCells;
1016 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam,num;
1017 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> names;
1018 if((const DataArrayInt *)_fam)
1019 fam=_fam->substr(start,end);
1020 if((const DataArrayInt *)_num)
1021 num=_num->substr(start,end);
1022 if((const DataArrayAsciiChar *)_names)
1023 names=static_cast<DataArrayAsciiChar *>(_names->substr(start,end));
1024 MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
1029 void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N)
1031 _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
1034 void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
1036 bigArraysI.push_back(_fam);
1037 bigArraysI.push_back(_num);
1038 _m_by_types.serialize(tinyInt,bigArraysI);
1041 void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1043 _fam=bigArraysI.back(); bigArraysI.pop_back();
1044 _num=bigArraysI.back(); bigArraysI.pop_back();
1045 _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
1048 void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId)
1050 DataArrayInt *arr=_fam;
1052 arr->changeValue(oldId,newId);
1055 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr)
1062 int sz(_m_by_types.getSize());
1063 famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
1068 DataArrayInt *MEDFileUMeshSplitL1::getFamilyField()
1073 void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr)
1081 int sz(_m_by_types.getSize());
1082 renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
1083 renumArr->incrRef();
1088 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
1095 int sz(_m_by_types.getSize());
1096 nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
1101 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds)
1106 m->renumberCells(renum->getConstPointer(),true);
1109 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
1110 m->renumberCells(locnum->getConstPointer(),true);
1115 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1117 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
1118 ret->unserialize(name,coo,tinyInt,bigArraysI);
1122 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
1124 return Renumber2(_num,m,cellIds);
1127 DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da)
1129 if((const DataArrayInt *)renum==0)
1132 return const_cast<DataArrayInt *>(da);
1134 return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
1137 DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
1139 return Renumber(_num,da);
1142 std::vector<int> MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
1145 for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
1146 id=std::max(id,(*it).second);
1149 std::vector<int> ret(nb);
1150 for(int i=1;i<=nb;i++)
1155 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
1156 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
1158 std::set<int> allfids;
1162 void MEDFileUMeshSplitL1::computeRevNum() const
1165 int maxValue=_num->getMaxValue(pos);
1166 _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
1171 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
1175 void MEDFileUMeshAggregateCompute::setName(const std::string& name)
1177 if(_m_time>=_mp_time)
1179 MEDCouplingUMesh *um(_m);
1183 if(_mp_time>=_m_time)
1185 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1187 MEDCoupling1GTUMesh *tmp(*it);
1194 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1196 std::size_t sz(mParts.size());
1197 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > ret(sz);
1198 for(std::size_t i=0;i<sz;i++)
1200 const MEDCoupling1GTUMesh *elt(mParts[i]);
1202 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
1203 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
1206 _part_def.clear(); _part_def.resize(sz);
1207 _mp_time=std::max(_mp_time,_m_time)+1;
1211 void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector<const PartDefinition *>& partDefs)
1213 if(_mp_time<_m_time)
1214 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !");
1215 std::size_t sz(partDefs.size());
1216 if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size())
1217 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !");
1218 for(std::size_t i=0;i<sz;i++)
1220 const PartDefinition *elt(partDefs[i]);
1223 _part_def[i]=const_cast<PartDefinition*>(elt);
1227 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
1231 _m_time=std::max(_mp_time,_m_time)+1;
1234 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
1236 if(_mp_time<=_m_time)
1238 std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
1239 std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
1240 _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
1241 _m_parts.clear();//to avoid memory peak !
1242 _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
1246 int MEDFileUMeshAggregateCompute::getNumberOfCells() const
1248 if(_mp_time<=_m_time)
1249 return _m->getNumberOfCells();
1251 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1252 ret+=(*it)->getNumberOfCells();
1256 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
1258 if(_mp_time>=_m_time)
1260 std::size_t sz(_m_parts.size());
1261 std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
1262 for(std::size_t i=0;i<sz;i++)
1263 ret[i]=_m_parts[i]->getCellModelEnum();
1267 return _m->getAllGeoTypesSorted();
1270 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
1272 if(_mp_time<_m_time)
1273 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
1275 std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
1277 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
1279 const MEDCoupling1GTUMesh *elt(*it);
1280 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
1285 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
1287 if(_mp_time<_m_time)
1288 forceComputationOfPartsFromUMesh();
1289 return retrievePartsWithoutComputation();
1292 MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1294 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1295 std::size_t sz(v.size());
1296 for(std::size_t i=0;i<sz;i++)
1299 if(v[i]->getCellModelEnum()==gt)
1302 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
1305 void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const
1308 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1309 std::size_t sz(v.size());
1310 for(std::size_t i=0;i<sz;i++)
1314 if(v[i]->getCellModelEnum()==gt)
1316 stop=start+v[i]->getNumberOfCells();
1320 start+=v[i]->getNumberOfCells();
1323 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
1326 void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N)
1328 if(_mp_time>_m_time)
1330 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1332 MEDCoupling1GTUMesh *m(*it);
1334 m->renumberNodesInConn(newNodeNumbersO2N);
1339 MEDCouplingUMesh *m(getUmesh());
1342 m->renumberNodesInConn(newNodeNumbersO2N);
1346 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1348 const MEDCouplingUMesh *m(_m);
1350 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1351 std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1352 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1353 std::size_t sz(msMSafe.size());
1354 _m_parts.resize(sz);
1355 for(std::size_t i=0;i<sz;i++)
1356 _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1358 _part_def.resize(_m_parts.size());
1359 _mp_time=std::max(_mp_time,_m_time);
1362 const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1364 if(_mp_time<_m_time)
1365 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : the parts require a computation !");
1366 if(_m_parts.size()!=_part_def.size())
1367 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : size of arrays are expected to be the same !");
1368 std::size_t sz(_m_parts.size());
1369 for(std::size_t i=0;i<sz;i++)
1371 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1373 if(mesh->getCellModelEnum()==gt)
1374 return _part_def[i];
1376 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
1379 void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
1381 if(_mp_time<_m_time)
1382 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
1383 std::size_t sz(_m_parts.size());
1384 tinyInt.push_back((int)sz);
1385 for(std::size_t i=0;i<sz;i++)
1387 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1389 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
1390 tinyInt.push_back(mesh->getCellModelEnum());
1391 const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
1392 const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
1395 DataArrayInt *elt(mesh1->getNodalConnectivity());
1398 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt1(elt);
1399 bigArraysI.push_back(elt1);
1403 DataArrayInt *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
1408 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt11(elt1),elt22(elt2);
1409 bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
1412 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
1413 const PartDefinition *pd(_part_def[i]);
1415 tinyInt.push_back(-1);
1418 std::vector<int> tinyTmp;
1419 pd->serialize(tinyTmp,bigArraysI);
1420 tinyInt.push_back((int)tinyTmp.size());
1421 tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
1426 void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1428 int nbParts(tinyInt.back()); tinyInt.pop_back();
1429 _part_def.clear(); _part_def.resize(nbParts);
1430 _m_parts.clear(); _m_parts.resize(nbParts);
1431 for(int i=0;i<nbParts;i++)
1433 INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
1434 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
1435 mesh->setCoords(coo);
1436 MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1437 MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1440 mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
1444 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt0,elt1;
1445 elt0=bigArraysI.back(); bigArraysI.pop_back();
1446 elt1=bigArraysI.back(); bigArraysI.pop_back();
1447 mesh2->setNodalConnectivity(elt0,elt1);
1450 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
1452 int pdid(tinyInt.back()); tinyInt.pop_back();
1454 _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
1455 _mp_time=std::max(_mp_time,_m_time)+1;
1460 * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
1462 bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const
1464 return _mp_time>=_m_time;
1467 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
1469 if(_mp_time>_m_time)
1470 return getTimeOfParts();
1471 if(_m_time>_mp_time)
1472 return getTimeOfUMesh();
1473 return std::max(getTimeOfParts(),getTimeOfUMesh());
1476 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
1479 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1481 const MEDCoupling1GTUMesh *elt(*it);
1483 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
1484 ret=std::max(ret,elt->getTimeOfThis());
1487 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
1491 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
1493 const MEDCouplingUMesh *m(_m);
1495 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
1496 return m->getTimeOfThis();
1499 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
1501 std::size_t ret(_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>));
1505 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
1507 std::vector<const BigMemoryObject *> ret;
1508 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1509 ret.push_back((const MEDCoupling1GTUMesh *)*it);
1510 ret.push_back((const MEDCouplingUMesh *)_m);
1514 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const
1516 MEDFileUMeshAggregateCompute ret;
1517 ret._m_parts.resize(_m_parts.size());
1518 for(std::size_t i=0;i<_m_parts.size();i++)
1520 const MEDCoupling1GTUMesh *elt(_m_parts[i]);
1523 ret._m_parts[i]=static_cast<ParaMEDMEM::MEDCoupling1GTUMesh*>(elt->deepCpy());
1524 ret._m_parts[i]->setCoords(coords);
1527 ret._mp_time=_mp_time; ret._m_time=_m_time;
1528 if((const MEDCouplingUMesh *)_m)
1530 ret._m=static_cast<ParaMEDMEM::MEDCouplingUMesh*>(_m->deepCpy());
1531 ret._m->setCoords(coords);
1533 std::size_t sz(_part_def.size());
1534 ret._part_def.clear(); ret._part_def.resize(sz);
1535 for(std::size_t i=0;i<sz;i++)
1537 const PartDefinition *elt(_part_def[i]);
1539 ret._part_def[i]=elt->deepCpy();
1544 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
1546 const MEDCouplingUMesh *m1(getUmesh());
1547 const MEDCouplingUMesh *m2(other.getUmesh());
1548 if((m1==0 && m2!=0) || (m1!=0 && m2==0))
1550 what="Presence of mesh in one sublevel and not in other!";
1556 if(!m1->isEqualIfNotWhy(m2,eps,what2))
1558 what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
1562 std::size_t sz(_part_def.size());
1563 if(sz!=other._part_def.size())
1565 what=std::string("number of subdivision per geo type for part definition is not the same !");
1568 for(std::size_t i=0;i<sz;i++)
1570 const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
1573 if((!pd0 && pd1) || (pd0 && !pd1))
1575 what=std::string("a cell part def is defined only for one among this or other !");
1578 bool ret(pd0->isEqual(pd1,what));
1585 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
1587 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1588 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
1589 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
1592 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
1594 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1596 const MEDCoupling1GTUMesh *tmp(*it);
1599 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
1600 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
1601 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1602 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
1605 const MEDCouplingUMesh *m(_m);
1608 (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
1609 (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
1610 (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1611 (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
1615 bool MEDFileUMeshAggregateCompute::empty() const
1617 if(_mp_time<_m_time)
1618 return ((const MEDCouplingUMesh *)_m)==0;
1619 //else _mp_time>=_m_time)
1620 return _m_parts.empty();
1623 int MEDFileUMeshAggregateCompute::getMeshDimension() const
1625 if(_mp_time<_m_time)
1627 const MEDCouplingUMesh *m(_m);
1629 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
1630 return m->getMeshDimension();
1634 if(_m_parts.empty())
1635 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
1636 const MEDCoupling1GTUMesh *m(_m_parts[0]);
1638 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
1639 return m->getMeshDimension();
1643 std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
1645 if(_mp_time<_m_time)
1647 const MEDCouplingUMesh *m(_m);
1649 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
1650 return m->getDistributionOfTypes();
1654 std::vector<int> ret;
1655 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1657 const MEDCoupling1GTUMesh *tmp(*it);
1659 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
1660 std::vector<int> ret0(tmp->getDistributionOfTypes());
1661 ret.insert(ret.end(),ret0.begin(),ret0.end());
1667 int MEDFileUMeshAggregateCompute::getSize() const
1669 if(_mp_time<_m_time)
1671 const MEDCouplingUMesh *m(_m);
1673 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
1674 return m->getNumberOfCells();
1679 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1681 const MEDCoupling1GTUMesh *m(*it);
1683 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
1684 ret+=m->getNumberOfCells();
1690 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
1692 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1694 MEDCoupling1GTUMesh *tmp(*it);
1696 (*it)->setCoords(coords);
1698 MEDCouplingUMesh *m(_m);
1700 m->setCoords(coords);