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 "MEDFileMeshReadSelector.hxx"
26 #include "MEDCouplingUMesh.hxx"
28 #include "InterpKernelAutoPtr.hxx"
29 #include "CellModel.hxx"
33 extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
34 extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
35 extern med_geometry_type typmainoeud[1];
37 using namespace ParaMEDMEM;
39 MEDFileMeshL2::MEDFileMeshL2():_name(MED_NAME_SIZE),_description(MED_COMMENT_SIZE),_univ_name(MED_LNAME_SIZE),_dt_unit(MED_LNAME_SIZE)
43 std::size_t MEDFileMeshL2::getHeapMemorySizeWithoutChildren() const
48 std::vector<const BigMemoryObject *> MEDFileMeshL2::getDirectChildrenWithNull() const
50 return std::vector<const BigMemoryObject *>();
53 int MEDFileMeshL2::GetMeshIdFromName(med_idt fid, const std::string& mname, ParaMEDMEM::MEDCouplingMeshType& meshType, int& dt, int& it, std::string& dtunit1)
55 med_mesh_type type_maillage;
56 char maillage_description[MED_COMMENT_SIZE+1];
57 char dtunit[MED_LNAME_SIZE+1];
59 char nommaa[MED_NAME_SIZE+1];
60 med_int n=MEDnMesh(fid);
63 med_sorting_type stype;
64 std::vector<std::string> ms;
66 med_axis_type axistype;
67 for(int i=0;i<n && !found;i++)
69 int naxis=MEDmeshnAxis(fid,i+1);
70 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
71 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
72 MEDmeshInfo(fid,i+1,nommaa,&spaceDim,&dim,&type_maillage,maillage_description,dtunit,&stype,&nstep,&axistype,axisname,axisunit);
73 dtunit1=MEDLoaderBase::buildStringFromFortran(dtunit,sizeof(dtunit));
74 std::string cur=MEDLoaderBase::buildStringFromFortran(nommaa,sizeof(nommaa));
84 std::ostringstream oss;
85 oss << "No such meshname (" << mname << ") in file ! Must be in : ";
86 std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss,", "));
87 throw INTERP_KERNEL::Exception(oss.str().c_str());
91 case MED_UNSTRUCTURED_MESH:
92 meshType=UNSTRUCTURED;
94 case MED_STRUCTURED_MESH:
97 MEDmeshGridTypeRd(fid,mname.c_str(),>);
100 case MED_CARTESIAN_GRID:
103 case MED_CURVILINEAR_GRID:
104 meshType=CURVE_LINEAR;
107 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
112 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
116 MEDmeshComputationStepInfo(fid,mname.c_str(),1,&numdt,&numit,&dtt);
121 double MEDFileMeshL2::CheckMeshTimeStep(med_idt fid, const std::string& mName, int nstep, int dt, int it)
126 std::vector< std::pair<int,int> > p(nstep);
127 for(int i=0;i<nstep;i++)
129 MEDmeshComputationStepInfo(fid,mName.c_str(),i+1,&numdt,&numit,&dtt);
130 p[i]=std::make_pair<int,int>(numdt,numit);
131 found=(numdt==dt) && (numit==numit);
135 std::ostringstream oss; oss << "No such iteration=" << dt << ",order=" << it << " numbers found for mesh '" << mName << "' ! ";
136 oss << "Possibilities are : ";
137 for(int i=0;i<nstep;i++)
138 oss << "(" << p[i].first << "," << p[i].second << "), ";
139 throw INTERP_KERNEL::Exception(oss.str().c_str());
144 std::vector<std::string> MEDFileMeshL2::getAxisInfoOnMesh(med_idt fid, int mId, const std::string& mName, ParaMEDMEM::MEDCouplingMeshType& meshType, int& nstep, int& Mdim)
146 med_mesh_type type_maillage;
148 med_sorting_type stype;
149 med_axis_type axistype;
150 int naxis=MEDmeshnAxis(fid,mId);
151 INTERP_KERNEL::AutoPtr<char> nameTmp=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
152 INTERP_KERNEL::AutoPtr<char> axisname=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
153 INTERP_KERNEL::AutoPtr<char> axisunit=MEDLoaderBase::buildEmptyString(naxis*MED_SNAME_SIZE);
154 INTERP_KERNEL::AutoPtr<char> univTmp=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
155 if(MEDmeshInfo(fid,mId,nameTmp,&spaceDim,&Mdim,&type_maillage,_description.getPointer(),_dt_unit.getPointer(),
156 &stype,&nstep,&axistype,axisname,axisunit)!=0)
157 throw INTERP_KERNEL::Exception("A problem has been detected when trying to get info on mesh !");
158 MEDmeshUniversalNameRd(fid,nameTmp,_univ_name.getPointer());
159 switch(type_maillage)
161 case MED_UNSTRUCTURED_MESH:
162 meshType=UNSTRUCTURED;
164 case MED_STRUCTURED_MESH:
167 MEDmeshGridTypeRd(fid,mName.c_str(),>);
170 case MED_CARTESIAN_GRID:
173 case MED_CURVILINEAR_GRID:
174 meshType=CURVE_LINEAR;
177 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getAxisInfoOnMesh : unrecognized structured mesh type ! Supported are :\n - cartesian\n - curve linear\n");
182 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::getMeshIdFromName : unrecognized mesh type !");
185 std::vector<std::string> infosOnComp(naxis);
186 for(int i=0;i<naxis;i++)
188 std::string info=MEDLoaderBase::buildUnionUnit(((char *)axisname)+i*MED_SNAME_SIZE,MED_SNAME_SIZE,((char *)axisunit)+i*MED_SNAME_SIZE,MED_SNAME_SIZE);
194 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)
196 if(mrs && !(mrs->isCellFamilyFieldReading() || mrs->isNodeFamilyFieldReading()))
198 char nomfam[MED_NAME_SIZE+1];
200 int nfam=MEDnFamily(fid,meshName.c_str());
201 for(int i=0;i<nfam;i++)
203 int ngro=MEDnFamilyGroup(fid,meshName.c_str(),i+1);
204 med_int natt=MEDnFamily23Attribute(fid,meshName.c_str(),i+1);
205 INTERP_KERNEL::AutoPtr<med_int> attide=new med_int[natt];
206 INTERP_KERNEL::AutoPtr<med_int> attval=new med_int[natt];
207 INTERP_KERNEL::AutoPtr<char> attdes=new char[MED_COMMENT_SIZE*natt+1];
208 INTERP_KERNEL::AutoPtr<char> gro=new char[MED_LNAME_SIZE*ngro+1];
209 MEDfamily23Info(fid,meshName.c_str(),i+1,nomfam,attide,attval,attdes,&numfam,gro);
210 std::string famName=MEDLoaderBase::buildStringFromFortran(nomfam,MED_NAME_SIZE);
211 fams[famName]=numfam;
212 for(int j=0;j<ngro;j++)
214 std::string groupname=MEDLoaderBase::buildStringFromFortran(gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
215 grps[groupname].push_back(famName);
220 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)
222 for(std::map<std::string,int>::const_iterator it=fams.begin();it!=fams.end();it++)
224 std::vector<std::string> grpsOfFam;
225 for(std::map<std::string, std::vector<std::string> >::const_iterator it1=grps.begin();it1!=grps.end();it1++)
227 if(std::find((*it1).second.begin(),(*it1).second.end(),(*it).first)!=(*it1).second.end())
228 grpsOfFam.push_back((*it1).first);
230 int ngro=grpsOfFam.size();
231 INTERP_KERNEL::AutoPtr<char> groName=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE*ngro);
233 for(std::vector<std::string>::const_iterator it2=grpsOfFam.begin();it2!=grpsOfFam.end();it2++,i++)
234 MEDLoaderBase::safeStrCpy2((*it2).c_str(),MED_LNAME_SIZE-1,groName+i*MED_LNAME_SIZE,tooLongStrPol);
235 INTERP_KERNEL::AutoPtr<char> famName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
236 MEDLoaderBase::safeStrCpy((*it).first.c_str(),MED_NAME_SIZE,famName,tooLongStrPol);
237 int ret=MEDfamilyCr(fid,mname.c_str(),famName,(*it).second,ngro,groName);
242 MEDFileUMeshL2::MEDFileUMeshL2()
246 std::vector<std::string> MEDFileUMeshL2::loadCommonPart(med_idt fid, int mId, const std::string& mName, int dt, int it, int& Mdim)
249 _name.set(mName.c_str());
251 ParaMEDMEM::MEDCouplingMeshType meshType;
252 std::vector<std::string> ret(getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim));
256 return std::vector<std::string>();
258 if(meshType!=UNSTRUCTURED)
259 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected an unstructured one whereas in file it is not an unstructured !");
260 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
266 void MEDFileUMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
269 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
272 loadConnectivity(fid,Mdim,mName,dt,it,mrs);//to improve check (dt,it) coherency
273 loadCoords(fid,mId,infosOnComp,mName,dt,it);
276 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)
279 std::vector<std::string> infosOnComp(loadCommonPart(fid,mId,mName,dt,it,Mdim));
282 loadPartOfConnectivity(fid,Mdim,mName,types,slicPerTyp,dt,it,mrs);
283 med_bool changement,transformation;
284 int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
285 std::vector<bool> fetchedNodeIds(nCoords,false);
286 for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
287 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
288 (*it1)->getMesh()->computeNodeIdsAlg(fetchedNodeIds);
289 int nMin(std::distance(fetchedNodeIds.begin(),std::find(fetchedNodeIds.begin(),fetchedNodeIds.end(),true)));
290 int nMax(std::distance(fetchedNodeIds.rbegin(),std::find(fetchedNodeIds.rbegin(),fetchedNodeIds.rend(),true)));
292 for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::const_iterator it0=_per_type_mesh.begin();it0!=_per_type_mesh.end();it0++)
293 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
294 (*it1)->getMesh()->renumberNodesWithOffsetInConn(-nMin);
295 loadPartCoords(fid,mId,infosOnComp,mName,dt,it,nMin,nMax);
298 void MEDFileUMeshL2::loadConnectivity(med_idt fid, int mdim, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
300 _per_type_mesh.resize(1);
301 _per_type_mesh[0].clear();
302 for(int j=0;j<MED_N_CELL_FIXED_GEO;j++)
304 MEDFileUMeshPerType *tmp(MEDFileUMeshPerType::New(fid,mName.c_str(),dt,it,mdim,typmai[j],typmai2[j],mrs));
306 _per_type_mesh[0].push_back(tmp);
311 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)
313 std::size_t nbOfTypes(types.size());
314 if(slicPerTyp.size()!=3*nbOfTypes)
315 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : The size of slicPerTyp array is expected to be equal to 3 times size of array types !");
316 std::set<INTERP_KERNEL::NormalizedCellType> types2(types.begin(),types.end());
317 if(types2.size()!=nbOfTypes)
318 throw INTERP_KERNEL::Exception("MEDFileUMeshL2::loadPartOfConnectivity : the geometric types in types array must appear once !");
319 _per_type_mesh.resize(1);
320 _per_type_mesh[0].clear();
321 for(std::size_t ii=0;ii<nbOfTypes;ii++)
323 int strt(slicPerTyp[3*ii+0]),stp(slicPerTyp[3*ii+1]),step(slicPerTyp[3*ii+2]);
324 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> tmp(MEDFileUMeshPerType::NewPart(fid,mName.c_str(),dt,it,mdim,types[ii],strt,stp,step,mrs));
325 _per_type_mesh[0].push_back(tmp);
330 void MEDFileUMeshL2::loadCoords(med_idt fid, int mId, const std::vector<std::string>& infosOnComp, const std::string& mName, int dt, int it)
332 int spaceDim((int)infosOnComp.size());
333 med_bool changement,transformation;
334 int nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
335 _coords=DataArrayDouble::New();
336 _coords->alloc(nCoords,spaceDim);
337 double *coordsPtr(_coords->getPointer());
338 MEDmeshNodeCoordinateRd(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,coordsPtr);
339 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
341 _fam_coords=DataArrayInt::New();
342 _fam_coords->alloc(nCoords,1);
343 MEDmeshEntityFamilyNumberRd(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_fam_coords->getPointer());
347 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
349 _num_coords=DataArrayInt::New();
350 _num_coords->alloc(nCoords,1);
351 MEDmeshEntityNumberRd(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_num_coords->getPointer());
355 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
357 _name_coords=DataArrayAsciiChar::New();
358 _name_coords->alloc(nCoords+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
359 MEDmeshEntityNameRd(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,_name_coords->getPointer());
360 _name_coords->reAlloc(nCoords);//not a bug to avoid the memory corruption due to last \0 at the end
364 for(int i=0;i<spaceDim;i++)
365 _coords->setInfoOnComponent(i,infosOnComp[i]);
368 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)
370 med_bool changement,transformation;
371 int spaceDim((int)infosOnComp.size()),nCoords(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&changement,&transformation));
372 _coords=DataArrayDouble::New();
373 int nbNodesToLoad(nMax-nMin);
374 _coords->alloc(nbNodesToLoad,spaceDim);
375 med_filter filter=MED_FILTER_INIT,filter2=MED_FILTER_INIT;
376 MEDfilterBlockOfEntityCr(fid,/*nentity*/nCoords,/*nvaluesperentity*/1,/*nconstituentpervalue*/spaceDim,
377 MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,MED_NO_PROFILE,
378 /*start*/nMin+1,/*stride*/1,/*count*/1,/*blocksize*/nbNodesToLoad,
379 /*lastblocksize=useless because count=1*/0,&filter);
380 MEDmeshNodeCoordinateAdvancedRd(fid,mName.c_str(),dt,it,&filter,_coords->getPointer());
381 _part_coords=PartDefinition::New(nMin,nMax,1);
382 MEDfilterClose(&filter);
383 MEDfilterBlockOfEntityCr(fid,nCoords,1,1,MED_ALL_CONSTITUENT,MED_FULL_INTERLACE,MED_COMPACT_STMODE,
384 MED_NO_PROFILE,nMin+1,1,1,nbNodesToLoad,0,&filter2);
385 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_FAMILY_NUMBER,MED_NODAL,&changement,&transformation)>0)
387 _fam_coords=DataArrayInt::New();
388 _fam_coords->alloc(nbNodesToLoad,1);
389 MEDmeshEntityAttributeAdvancedRd(fid,mName.c_str(),MED_FAMILY_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_fam_coords->getPointer());
393 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NUMBER,MED_NODAL,&changement,&transformation)>0)
395 _num_coords=DataArrayInt::New();
396 _num_coords->alloc(nbNodesToLoad,1);
397 MEDmeshEntityAttributeAdvancedRd(fid,mName.c_str(),MED_NUMBER,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_num_coords->getPointer());
401 if(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,MED_NAME,MED_NODAL,&changement,&transformation)>0)
403 _name_coords=DataArrayAsciiChar::New();
404 _name_coords->alloc(nbNodesToLoad+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
405 MEDmeshEntityAttributeAdvancedRd(fid,mName.c_str(),MED_NAME,dt,it,MED_NODE,MED_NO_GEOTYPE,&filter2,_name_coords->getPointer());
406 _name_coords->reAlloc(nbNodesToLoad);//not a bug to avoid the memory corruption due to last \0 at the end
410 MEDfilterClose(&filter2);
411 _coords->setInfoOnComponents(infosOnComp);
414 void MEDFileUMeshL2::sortTypes()
417 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > tmp(_per_type_mesh[0]);
418 _per_type_mesh.clear();
419 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
420 mdims.insert((*it)->getDim());
423 int mdim=*mdims.rbegin();
424 _per_type_mesh.resize(mdim+1);
425 for(int dim=mdim+1;dim!=0;dim--)
427 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& elt=_per_type_mesh[mdim+1-dim];
428 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=tmp.begin();it!=tmp.end();it++)
429 if((*it)->getDim()==dim-1)
432 // suppression of contiguous empty levels at the end of _per_type_mesh.
433 int nbOfUselessLev=0;
435 for(std::vector< std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> > >::reverse_iterator it2=_per_type_mesh.rbegin();it2!=_per_type_mesh.rend();it2++)
437 if((*it2).empty() && isFirst)
444 _per_type_mesh.resize(_per_type_mesh.size()-nbOfUselessLev);
447 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)
451 MEDmeshNodeCoordinateWr(fid,mname.c_str(),dt,it,time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->getConstPointer());
453 MEDmeshEntityFamilyNumberWr(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,famCoords->getNumberOfTuples(),famCoords->getConstPointer());
455 MEDmeshEntityNumberWr(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,numCoords->getNumberOfTuples(),numCoords->getConstPointer());
458 if(nameCoords->getNumberOfComponents()!=MED_SNAME_SIZE)
460 std::ostringstream oss; oss << " MEDFileUMeshL2::WriteCoords : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
461 oss << " ! The array has " << nameCoords->getNumberOfComponents() << " components !";
462 throw INTERP_KERNEL::Exception(oss.str().c_str());
464 MEDmeshEntityNameWr(fid,mname.c_str(),dt,it,MED_NODE,MED_NO_GEOTYPE,nameCoords->getNumberOfTuples(),nameCoords->getConstPointer());
468 bool MEDFileUMeshL2::isFamDefinedOnLev(int levId) const
470 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
471 if((*it)->getFam()==0)
476 bool MEDFileUMeshL2::isNumDefinedOnLev(int levId) const
478 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
479 if((*it)->getNum()==0)
484 bool MEDFileUMeshL2::isNamesDefinedOnLev(int levId) const
486 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >::const_iterator it=_per_type_mesh[levId].begin();it!=_per_type_mesh[levId].end();it++)
487 if((*it)->getNames()==0)
492 MEDFileCMeshL2::MEDFileCMeshL2()
496 void MEDFileCMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
498 _name.set(mName.c_str());
501 ParaMEDMEM::MEDCouplingMeshType meshType;
502 std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName.c_str(),meshType,nstep,Mdim);
503 if(meshType!=CARTESIAN)
504 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
505 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
509 med_grid_type gridtype;
510 MEDmeshGridTypeRd(fid,mName.c_str(),&gridtype);
511 if(gridtype!=MED_CARTESIAN_GRID)
512 throw INTERP_KERNEL::Exception("Invalid structured mesh ! Expected cartesian mesh type !");
513 _cmesh=MEDCouplingCMesh::New();
514 for(int i=0;i<Mdim;i++)
516 med_data_type dataTypeReq=GetDataTypeCorrespondingToSpaceId(i);
517 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
518 int nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,dataTypeReq,MED_NO_CMODE,&chgt,&trsf);
519 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
520 da->alloc(nbOfElt,1);
521 da->setInfoOnComponent(0,infosOnComp[i]);
522 MEDmeshGridIndexCoordinateRd(fid,mName.c_str(),dt,it,i+1,da->getPointer());
523 _cmesh->setCoordsAt(i,da);
527 med_data_type MEDFileCMeshL2::GetDataTypeCorrespondingToSpaceId(int id)
532 return MED_COORDINATE_AXIS1;
534 return MED_COORDINATE_AXIS2;
536 return MED_COORDINATE_AXIS3;
538 throw INTERP_KERNEL::Exception("Invalid meshdim detected in Cartesian Grid !");
542 MEDFileCLMeshL2::MEDFileCLMeshL2()
546 void MEDFileCLMeshL2::loadAll(med_idt fid, int mId, const std::string& mName, int dt, int it)
548 _name.set(mName.c_str());
551 ParaMEDMEM::MEDCouplingMeshType meshType;
552 std::vector<std::string> infosOnComp=getAxisInfoOnMesh(fid,mId,mName,meshType,nstep,Mdim);
553 if(meshType!=CURVE_LINEAR)
554 throw INTERP_KERNEL::Exception("Invalid mesh type ! You are expected a structured one whereas in file it is not a structured !");
555 _time=CheckMeshTimeStep(fid,mName,nstep,dt,it);
559 _clmesh=MEDCouplingCurveLinearMesh::New();
560 INTERP_KERNEL::AutoPtr<int> stGrid=new int[Mdim];
561 MEDmeshGridStructRd(fid,mName.c_str(),dt,it,stGrid);
562 _clmesh->setNodeGridStructure(stGrid,((int *)stGrid)+Mdim);
563 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
564 int nbNodes=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE,&chgt,&trsf);
565 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> da=DataArrayDouble::New();
566 da->alloc(nbNodes,infosOnComp.size());
567 da->setInfoOnComponents(infosOnComp);
568 MEDmeshNodeCoordinateRd(fid,mName.c_str(),dt,it,MED_FULL_INTERLACE,da->getPointer());
569 _clmesh->setCoords(da);
572 MEDFileUMeshPermCompute::MEDFileUMeshPermCompute(const MEDFileUMeshSplitL1* st):_st(st),_mpt_time(0),_num_time(0)
577 * Warning it returns an instance to deallocate !!!!
579 MEDFileUMeshPermCompute::operator MEDCouplingUMesh *() const
581 _st->_num->updateTime();
582 if((MEDCouplingUMesh *)_m==0)
585 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
586 _m->renumberCells(_st->_num->getConstPointer(),true);
591 if(_mpt_time==_st->_m_by_types.getTimeOfThis() && _num_time==_st->_num->getTimeOfThis())
596 _m=static_cast<MEDCouplingUMesh *>(_st->_m_by_types.getUmesh()->deepCpy());
597 _m->renumberCells(_st->_num->getConstPointer(),true);
603 void MEDFileUMeshPermCompute::operator=(MEDCouplingUMesh *m)
608 void MEDFileUMeshPermCompute::updateTime() const
610 _mpt_time=_st->_m_by_types.getTimeOfThis();
611 _num_time=_st->_num->getTimeOfThis();
614 std::vector<const BigMemoryObject *> MEDFileUMeshPermCompute::getDirectChildrenWithNull() const
616 std::vector<const BigMemoryObject *> ret;
617 ret.push_back((const MEDCouplingUMesh *)_m);
621 std::size_t MEDFileUMeshPermCompute::getHeapMemorySizeWithoutChildren() const
623 return sizeof(MEDFileUMeshPermCompute);
626 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)
630 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(const MEDFileUMeshL2& l2, const std::string& mName, int id):_m(this)
632 const std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshPerType> >& v=l2.getLev(id);
636 std::vector<const MEDCoupling1GTUMesh *> ms(sz);
637 std::vector<const DataArrayInt *> fams(sz),nums(sz);
638 std::vector<const DataArrayChar *> names(sz);
639 std::vector<const PartDefinition *> pds(sz);
640 for(int i=0;i<sz;i++)
642 MEDCoupling1GTUMesh *elt(v[i]->getMesh());
643 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp2=l2.getCoords();
644 elt->setCoords(tmp2);
646 pds[i]=v[i]->getPartDef();
648 _m_by_types.assignParts(ms);
649 _m_by_types.assignDefParts(pds);
650 if(l2.isFamDefinedOnLev(id))
652 for(int i=0;i<sz;i++)
653 fams[i]=v[i]->getFam();
655 _fam=DataArrayInt::Aggregate(fams);
659 _fam=const_cast<DataArrayInt *>(fams[0]);
662 if(l2.isNumDefinedOnLev(id))
664 for(int i=0;i<sz;i++)
665 nums[i]=v[i]->getNum();
667 _num=DataArrayInt::Aggregate(nums);
671 _num=const_cast<DataArrayInt *>(nums[0]);
675 if(l2.isNamesDefinedOnLev(id))
677 for(int i=0;i<sz;i++)
678 names[i]=v[i]->getNames();
679 _names=dynamic_cast<DataArrayAsciiChar *>(DataArrayChar::Aggregate(names));
683 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCoupling1GTUMesh *m):_m(this)
685 std::vector< const MEDCoupling1GTUMesh * > v(1);
690 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m):_m(this)
695 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1(MEDCouplingUMesh *m, bool newOrOld):_m(this)
697 assignMesh(m,newOrOld);
700 void MEDFileUMeshSplitL1::setName(const std::string& name)
702 _m_by_types.setName(name);
705 std::size_t MEDFileUMeshSplitL1::getHeapMemorySizeWithoutChildren() const
710 std::vector<const BigMemoryObject *> MEDFileUMeshSplitL1::getDirectChildrenWithNull() const
712 std::vector<const BigMemoryObject *> ret;
713 ret.push_back(&_m_by_types);
715 ret.push_back((const DataArrayInt*)_fam);
716 ret.push_back((const DataArrayInt*)_num);
717 ret.push_back((const DataArrayInt*)_rev_num);
718 ret.push_back((const DataArrayAsciiChar*)_names);
722 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::deepCpy(DataArrayDouble *coords) const
724 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret=new MEDFileUMeshSplitL1(*this);
725 ret->_m_by_types=_m_by_types.deepCpy(coords);
726 if((const DataArrayInt *)_fam)
727 ret->_fam=_fam->deepCpy();
728 if((const DataArrayInt *)_num)
729 ret->_num=_num->deepCpy();
730 if((const DataArrayInt *)_rev_num)
731 ret->_rev_num=_rev_num->deepCpy();
732 if((const DataArrayAsciiChar *)_names)
733 ret->_names=_names->deepCpy();
737 bool MEDFileUMeshSplitL1::isEqual(const MEDFileUMeshSplitL1 *other, double eps, std::string& what) const
739 if(!_m_by_types.isEqual(other->_m_by_types,eps,what))
741 const DataArrayInt *d1=_fam;
742 const DataArrayInt *d2=other->_fam;
743 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
745 what="Presence of family arr in one sublevel and not in other!";
749 if(!d1->isEqual(*d2))
751 what="family arr at a sublevel are not deeply equal !";
756 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
758 what="Presence of cell numbering arr in one sublevel and not in other!";
762 if(!d1->isEqual(*d2))
764 what="Numbering cell arr at a sublevel are not deeply equal !";
767 const DataArrayAsciiChar *e1=_names;
768 const DataArrayAsciiChar *e2=other->_names;
769 if((e1==0 && e2!=0) || (e1!=0 && e2==0))
771 what="Presence of cell names arr in one sublevel and not in other!";
775 if(!e1->isEqual(*e2))
777 what="Name cell arr at a sublevel are not deeply equal !";
783 void MEDFileUMeshSplitL1::synchronizeTinyInfo(const MEDFileMesh& master) const
785 _m_by_types.synchronizeTinyInfo(master);
788 void MEDFileUMeshSplitL1::clearNonDiscrAttributes() const
790 _m_by_types.clearNonDiscrAttributes();
793 void MEDFileUMeshSplitL1::ClearNonDiscrAttributes(const MEDCouplingMesh *tmp)
797 (const_cast<MEDCouplingMesh *>(tmp))->setName("");
798 (const_cast<MEDCouplingMesh *>(tmp))->setDescription("");
799 (const_cast<MEDCouplingMesh *>(tmp))->setTime(0.,-1,-1);
800 (const_cast<MEDCouplingMesh *>(tmp))->setTimeUnit("");
803 void MEDFileUMeshSplitL1::setCoords(DataArrayDouble *coords)
805 _m_by_types.setCoords(coords);
808 void MEDFileUMeshSplitL1::assignMesh(MEDCouplingUMesh *m, bool newOrOld)
814 _m_by_types.assignUMesh(dynamic_cast<MEDCouplingUMesh *>(m->deepCpy()));
815 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_m_by_types.getUmesh()->getRenumArrForConsecutiveCellTypesSpec(typmai2,typmai2+MED_N_CELL_FIXED_GEO);
816 if(!da->isIdentity())
818 _num=da->invertArrayO2N2N2O(m->getNumberOfCells());
821 _m_by_types.getUmesh()->renumberCells(da->getConstPointer(),false);
826 if(!m->checkConsecutiveCellTypesAndOrder(typmai2,typmai2+MED_N_CELL_FIXED_GEO))
827 throw INTERP_KERNEL::Exception("MEDFileUMeshSplitL1::assignMesh : the mode of mesh setting expects to follow the MED file numbering convention ! it is not the case !");
829 _m_by_types.assignUMesh(m);
834 void MEDFileUMeshSplitL1::forceComputationOfParts() const
836 _m_by_types.forceComputationOfPartsFromUMesh();
839 void MEDFileUMeshSplitL1::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
841 _m_by_types.assignParts(mParts);
845 MEDFileUMeshSplitL1::MEDFileUMeshSplitL1():_m(this)
849 void MEDFileUMeshSplitL1::assignCommonPart()
851 _fam=DataArrayInt::New();
852 _fam->alloc(_m_by_types.getSize(),1);
853 _fam->fillWithValue(0);
856 bool MEDFileUMeshSplitL1::empty() const
858 return _m_by_types.empty();
861 bool MEDFileUMeshSplitL1::presenceOfOneFams(const std::vector<int>& ids) const
863 const DataArrayInt *fam=_fam;
866 return fam->presenceOfValue(ids);
869 int MEDFileUMeshSplitL1::getMeshDimension() const
871 return _m_by_types.getMeshDimension();
874 void MEDFileUMeshSplitL1::simpleRepr(std::ostream& oss) const
876 std::vector<int> code=_m_by_types.getDistributionOfTypes();
877 int nbOfTypes=code.size()/3;
878 for(int i=0;i<nbOfTypes;i++)
880 INTERP_KERNEL::NormalizedCellType typ=(INTERP_KERNEL::NormalizedCellType) code[3*i];
881 oss << " - Number of cells with type " << INTERP_KERNEL::CellModel::GetCellModel(typ).getRepr() << " : " << code[3*i+1] << std::endl;
885 int MEDFileUMeshSplitL1::getSize() const
887 return _m_by_types.getSize();
890 MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const
892 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> eltsToKeep=_fam->getIdsEqualList(idsBg,idsEnd);
893 MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types.getUmesh()->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true);
895 return renumIfNeeded(m,eltsToKeep->getConstPointer());
899 DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const
901 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da=_fam->getIdsEqualList(idsBg,idsEnd);
903 return renumIfNeededArr(da);
907 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshSplitL1::getGeoTypes() const
909 return _m_by_types.getGeoTypes();
912 MEDCouplingUMesh *MEDFileUMeshSplitL1::getWholeMesh(bool renum) const
914 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp;
915 if(renum && ((const DataArrayInt *)_num))
918 { tmp=_m_by_types.getUmesh(); if(tmp) tmp->incrRef(); }
922 int MEDFileUMeshSplitL1::getNumberOfCells() const
924 return _m_by_types.getNumberOfCells();
927 DataArrayInt *MEDFileUMeshSplitL1::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
929 const DataArrayInt *fam(_fam);
932 int start(0),stop(0);
933 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
934 return fam->selectByTupleId2(start,stop,1);
937 DataArrayInt *MEDFileUMeshSplitL1::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
939 const DataArrayInt *num(_num);
942 int start(0),stop(0);
943 _m_by_types.getStartStopOfGeoTypeWithoutComputation(gt,start,stop);
944 return num->selectByTupleId2(start,stop,1);
947 DataArrayInt *MEDFileUMeshSplitL1::getOrCreateAndGetFamilyField()
949 if((DataArrayInt *)_fam)
951 int nbOfTuples=_m_by_types.getSize();
952 _fam=DataArrayInt::New(); _fam->alloc(nbOfTuples,1); _fam->fillWithZero();
956 const DataArrayInt *MEDFileUMeshSplitL1::getFamilyField() const
961 const DataArrayInt *MEDFileUMeshSplitL1::getNumberField() const
966 const DataArrayInt *MEDFileUMeshSplitL1::getRevNumberField() const
971 const DataArrayAsciiChar *MEDFileUMeshSplitL1::getNameField() const
976 const PartDefinition *MEDFileUMeshSplitL1::getPartDef(INTERP_KERNEL::NormalizedCellType gt) const
978 return _m_by_types.getPartDefOfWithoutComputation(gt);
981 void MEDFileUMeshSplitL1::eraseFamilyField()
983 _fam->fillWithZero();
987 * This method ignores _m and _m_by_types.
989 void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector<const MEDCouplingUMesh *>& ms, std::map<std::string,int>& familyIds,
990 std::map<std::string, std::vector<std::string> >& groups)
992 std::vector< DataArrayInt * > corr;
993 _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr);
994 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corrMSafe(corr.begin(),corr.end());
995 std::vector< std::vector<int> > fidsOfGroups;
996 std::vector< const DataArrayInt * > corr2(corr.begin(),corr.end());
997 _fam=DataArrayInt::MakePartition(corr2,((MEDCouplingUMesh *)_m)->getNumberOfCells(),fidsOfGroups);
998 int nbOfCells=((MEDCouplingUMesh *)_m)->getNumberOfCells();
999 std::map<int,std::string> newfams;
1000 std::map<int,int> famIdTrad;
1001 TraduceFamilyNumber(fidsOfGroups,familyIds,famIdTrad,newfams);
1002 int *w=_fam->getPointer();
1003 for(int i=0;i<nbOfCells;i++,w++)
1007 void MEDFileUMeshSplitL1::write(med_idt fid, const std::string& mName, int mdim) const
1009 std::vector<MEDCoupling1GTUMesh *> ms(_m_by_types.getParts());
1011 for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
1013 int nbCells=(*it)->getNumberOfCells();
1014 int end=start+nbCells;
1015 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam,num;
1016 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> names;
1017 if((const DataArrayInt *)_fam)
1018 fam=_fam->substr(start,end);
1019 if((const DataArrayInt *)_num)
1020 num=_num->substr(start,end);
1021 if((const DataArrayAsciiChar *)_names)
1022 names=static_cast<DataArrayAsciiChar *>(_names->substr(start,end));
1023 MEDFileUMeshPerType::Write(fid,mName,mdim,(*it),fam,num,names);
1028 void MEDFileUMeshSplitL1::renumberNodesInConn(const int *newNodeNumbersO2N)
1030 _m_by_types.renumberNodesInConnWithoutComputation(newNodeNumbersO2N);
1033 void MEDFileUMeshSplitL1::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
1035 bigArraysI.push_back(_fam);
1036 bigArraysI.push_back(_num);
1037 _m_by_types.serialize(tinyInt,bigArraysI);
1040 void MEDFileUMeshSplitL1::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1042 _fam=bigArraysI.back(); bigArraysI.pop_back();
1043 _num=bigArraysI.back(); bigArraysI.pop_back();
1044 _m_by_types.unserialize(name,coo,tinyInt,bigArraysI);
1047 void MEDFileUMeshSplitL1::changeFamilyIdArr(int oldId, int newId)
1049 DataArrayInt *arr=_fam;
1051 arr->changeValue(oldId,newId);
1054 void MEDFileUMeshSplitL1::setFamilyArr(DataArrayInt *famArr)
1061 int sz(_m_by_types.getSize());
1062 famArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setFamilyArr : Problem in size of Family arr ! ");
1067 void MEDFileUMeshSplitL1::setRenumArr(DataArrayInt *renumArr)
1075 int sz(_m_by_types.getSize());
1076 renumArr->checkNbOfTuplesAndComp(sz,1,"MEDFileUMeshSplitL1::setRenumArr : Problem in size of numbering arr ! ");
1077 renumArr->incrRef();
1082 void MEDFileUMeshSplitL1::setNameArr(DataArrayAsciiChar *nameArr)
1089 int sz(_m_by_types.getSize());
1090 nameArr->checkNbOfTuplesAndComp(sz,MED_SNAME_SIZE,"MEDFileUMeshSplitL1::setNameArr : Problem in size of name arr ! ");
1095 MEDCouplingUMesh *MEDFileUMeshSplitL1::Renumber2(const DataArrayInt *renum, MEDCouplingUMesh *m, const int *cellIds)
1100 m->renumberCells(renum->getConstPointer(),true);
1103 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> locnum=renum->selectByTupleId(cellIds,cellIds+m->getNumberOfCells());
1104 m->renumberCells(locnum->getConstPointer(),true);
1109 MEDFileUMeshSplitL1 *MEDFileUMeshSplitL1::Unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1111 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> ret(new MEDFileUMeshSplitL1);
1112 ret->unserialize(name,coo,tinyInt,bigArraysI);
1116 MEDCouplingUMesh *MEDFileUMeshSplitL1::renumIfNeeded(MEDCouplingUMesh *m, const int *cellIds) const
1118 return Renumber2(_num,m,cellIds);
1121 DataArrayInt *MEDFileUMeshSplitL1::Renumber(const DataArrayInt *renum, const DataArrayInt *da)
1123 if((const DataArrayInt *)renum==0)
1126 return const_cast<DataArrayInt *>(da);
1128 return renum->selectByTupleId(da->getConstPointer(),da->getConstPointer()+da->getNumberOfTuples());
1131 DataArrayInt *MEDFileUMeshSplitL1::renumIfNeededArr(const DataArrayInt *da) const
1133 return Renumber(_num,da);
1136 std::vector<int> MEDFileUMeshSplitL1::GetNewFamiliesNumber(int nb, const std::map<std::string,int>& families)
1139 for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++)
1140 id=std::max(id,(*it).second);
1143 std::vector<int> ret(nb);
1144 for(int i=1;i<=nb;i++)
1149 void MEDFileUMeshSplitL1::TraduceFamilyNumber(const std::vector< std::vector<int> >& fidsGrps, std::map<std::string,int>& familyIds,
1150 std::map<int,int>& famIdTrad, std::map<int,std::string>& newfams)
1152 std::set<int> allfids;
1156 void MEDFileUMeshSplitL1::computeRevNum() const
1159 int maxValue=_num->getMaxValue(pos);
1160 _rev_num=_num->invertArrayN2O2O2N(maxValue+1);
1165 MEDFileUMeshAggregateCompute::MEDFileUMeshAggregateCompute():_mp_time(0),_m_time(0)
1169 void MEDFileUMeshAggregateCompute::setName(const std::string& name)
1171 if(_m_time>=_mp_time)
1173 MEDCouplingUMesh *um(_m);
1177 if(_mp_time>=_m_time)
1179 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1181 MEDCoupling1GTUMesh *tmp(*it);
1188 void MEDFileUMeshAggregateCompute::assignParts(const std::vector< const MEDCoupling1GTUMesh * >& mParts)
1190 std::size_t sz(mParts.size());
1191 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> > ret(sz);
1192 for(std::size_t i=0;i<sz;i++)
1194 const MEDCoupling1GTUMesh *elt(mParts[i]);
1196 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignParts : presence of null pointer !");
1197 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt); elt->incrRef();
1200 _part_def.clear(); _part_def.resize(sz);
1201 _mp_time=std::max(_mp_time,_m_time)+1;
1205 void MEDFileUMeshAggregateCompute::assignDefParts(const std::vector<const PartDefinition *>& partDefs)
1207 if(_mp_time<_m_time)
1208 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : the parts require a computation !");
1209 std::size_t sz(partDefs.size());
1210 if(_part_def.size()!=partDefs.size() || _part_def.size()!=_m_parts.size())
1211 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::assignDefParts : sizes of vectors of part definition mismatch !");
1212 for(std::size_t i=0;i<sz;i++)
1214 const PartDefinition *elt(partDefs[i]);
1217 _part_def[i]=const_cast<PartDefinition*>(elt);
1221 void MEDFileUMeshAggregateCompute::assignUMesh(MEDCouplingUMesh *m)
1225 _m_time=std::max(_mp_time,_m_time)+1;
1228 MEDCouplingUMesh *MEDFileUMeshAggregateCompute::getUmesh() const
1230 if(_mp_time<=_m_time)
1232 std::vector< const MEDCoupling1GTUMesh *> mp(_m_parts.size());
1233 std::copy(_m_parts.begin(),_m_parts.end(),mp.begin());
1234 _m=MEDCoupling1GTUMesh::AggregateOnSameCoordsToUMesh(mp);
1235 _m_parts.clear();//to avoid memory peak !
1236 _m_time=_mp_time+1;//+1 is important ! That is to say that only _m is OK not _m_parts because cleared !
1240 int MEDFileUMeshAggregateCompute::getNumberOfCells() const
1242 if(_mp_time<=_m_time)
1243 return _m->getNumberOfCells();
1245 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1246 ret+=(*it)->getNumberOfCells();
1250 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMeshAggregateCompute::getGeoTypes() const
1252 if(_mp_time>=_m_time)
1254 std::size_t sz(_m_parts.size());
1255 std::vector<INTERP_KERNEL::NormalizedCellType> ret(sz);
1256 for(std::size_t i=0;i<sz;i++)
1257 ret[i]=_m_parts[i]->getCellModelEnum();
1261 return _m->getAllGeoTypesSorted();
1264 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::retrievePartsWithoutComputation() const
1266 if(_mp_time<_m_time)
1267 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartsWithoutComputation : the parts require a computation !");
1269 std::vector<MEDCoupling1GTUMesh *> ret(_m_parts.size());
1271 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++,i++)
1273 const MEDCoupling1GTUMesh *elt(*it);
1274 ret[i]=const_cast<MEDCoupling1GTUMesh *>(elt);
1279 std::vector<MEDCoupling1GTUMesh *> MEDFileUMeshAggregateCompute::getParts() const
1281 if(_mp_time<_m_time)
1282 forceComputationOfPartsFromUMesh();
1283 return retrievePartsWithoutComputation();
1286 MEDCoupling1GTUMesh *MEDFileUMeshAggregateCompute::retrievePartWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1288 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1289 std::size_t sz(v.size());
1290 for(std::size_t i=0;i<sz;i++)
1293 if(v[i]->getCellModelEnum()==gt)
1296 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartWithoutComputation : the geometric type is not existing !");
1299 void MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation(INTERP_KERNEL::NormalizedCellType gt, int& start, int& stop) const
1302 std::vector<MEDCoupling1GTUMesh *> v(retrievePartsWithoutComputation());
1303 std::size_t sz(v.size());
1304 for(std::size_t i=0;i<sz;i++)
1308 if(v[i]->getCellModelEnum()==gt)
1310 stop=start+v[i]->getNumberOfCells();
1314 start+=v[i]->getNumberOfCells();
1317 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getStartStopOfGeoTypeWithoutComputation : the geometric type is not existing !");
1320 void MEDFileUMeshAggregateCompute::renumberNodesInConnWithoutComputation(const int *newNodeNumbersO2N)
1322 if(_mp_time>_m_time)
1324 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1326 MEDCoupling1GTUMesh *m(*it);
1328 m->renumberNodesInConn(newNodeNumbersO2N);
1333 MEDCouplingUMesh *m(getUmesh());
1336 m->renumberNodesInConn(newNodeNumbersO2N);
1340 void MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh() const
1342 const MEDCouplingUMesh *m(_m);
1344 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::forceComputationOfPartsFromUMesh : null UMesh !");
1345 std::vector<MEDCouplingUMesh *> ms(m->splitByType());
1346 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > msMSafe(ms.begin(),ms.end());
1347 std::size_t sz(msMSafe.size());
1348 _m_parts.resize(sz);
1349 for(std::size_t i=0;i<sz;i++)
1350 _m_parts[i]=MEDCoupling1GTUMesh::New(ms[i]);
1352 _part_def.resize(_m_parts.size());
1353 _mp_time=std::max(_mp_time,_m_time);
1356 const PartDefinition *MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation(INTERP_KERNEL::NormalizedCellType gt) const
1358 if(_mp_time<_m_time)
1359 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : the parts require a computation !");
1360 if(_m_parts.size()!=_part_def.size())
1361 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : size of arrays are expected to be the same !");
1362 std::size_t sz(_m_parts.size());
1363 for(std::size_t i=0;i<sz;i++)
1365 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1367 if(mesh->getCellModelEnum()==gt)
1368 return _part_def[i];
1370 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getPartDefOfWithoutComputation : The input geo type is not existing in this !");
1373 void MEDFileUMeshAggregateCompute::serialize(std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI) const
1375 if(_mp_time<_m_time)
1376 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : the parts require a computation !");
1377 std::size_t sz(_m_parts.size());
1378 tinyInt.push_back((int)sz);
1379 for(std::size_t i=0;i<sz;i++)
1381 const MEDCoupling1GTUMesh *mesh(_m_parts[i]);
1383 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : one part is empty !");
1384 tinyInt.push_back(mesh->getCellModelEnum());
1385 const MEDCoupling1SGTUMesh *mesh1(dynamic_cast<const MEDCoupling1SGTUMesh *>(mesh));
1386 const MEDCoupling1DGTUMesh *mesh2(dynamic_cast<const MEDCoupling1DGTUMesh *>(mesh));
1389 DataArrayInt *elt(mesh1->getNodalConnectivity());
1392 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt1(elt);
1393 bigArraysI.push_back(elt1);
1397 DataArrayInt *elt1(mesh2->getNodalConnectivity()),*elt2(mesh2->getNodalConnectivityIndex());
1402 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt11(elt1),elt22(elt2);
1403 bigArraysI.push_back(elt11); bigArraysI.push_back(elt22);
1406 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::serialize : unrecognized single geo type mesh !");
1407 const PartDefinition *pd(_part_def[i]);
1409 tinyInt.push_back(-1);
1412 std::vector<int> tinyTmp;
1413 pd->serialize(tinyTmp,bigArraysI);
1414 tinyInt.push_back((int)tinyTmp.size());
1415 tinyInt.insert(tinyInt.end(),tinyTmp.begin(),tinyTmp.end());
1420 void MEDFileUMeshAggregateCompute::unserialize(const std::string& name, DataArrayDouble *coo, std::vector<int>& tinyInt, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI)
1422 int nbParts(tinyInt.back()); tinyInt.pop_back();
1423 _part_def.clear(); _part_def.resize(nbParts);
1424 _m_parts.clear(); _m_parts.resize(nbParts);
1425 for(int i=0;i<nbParts;i++)
1427 INTERP_KERNEL::NormalizedCellType tp((INTERP_KERNEL::NormalizedCellType) tinyInt.back()); tinyInt.pop_back();
1428 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> mesh(MEDCoupling1GTUMesh::New(name,tp));
1429 mesh->setCoords(coo);
1430 MEDCoupling1SGTUMesh *mesh1(dynamic_cast<MEDCoupling1SGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1431 MEDCoupling1DGTUMesh *mesh2(dynamic_cast<MEDCoupling1DGTUMesh *>((MEDCoupling1GTUMesh *) mesh));
1434 mesh1->setNodalConnectivity(bigArraysI.back()); bigArraysI.pop_back();
1438 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> elt0,elt1;
1439 elt0=bigArraysI.back(); bigArraysI.pop_back();
1440 elt1=bigArraysI.back(); bigArraysI.pop_back();
1441 mesh2->setNodalConnectivity(elt0,elt1);
1444 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::unserialize : unrecognized single geo type mesh !");
1446 int pdid(tinyInt.back()); tinyInt.pop_back();
1448 _part_def[i]=PartDefinition::Unserialize(tinyInt,bigArraysI);
1449 _mp_time=std::max(_mp_time,_m_time)+1;
1454 * This method returns true if \a this is stored split by type false if stored in a merged unstructured mesh.
1456 bool MEDFileUMeshAggregateCompute::isStoredSplitByType() const
1458 return _mp_time>=_m_time;
1461 std::size_t MEDFileUMeshAggregateCompute::getTimeOfThis() const
1463 if(_mp_time>_m_time)
1464 return getTimeOfParts();
1465 if(_m_time>_mp_time)
1466 return getTimeOfUMesh();
1467 return std::max(getTimeOfParts(),getTimeOfUMesh());
1470 std::size_t MEDFileUMeshAggregateCompute::getTimeOfParts() const
1473 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1475 const MEDCoupling1GTUMesh *elt(*it);
1477 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : null obj in parts !");
1478 ret=std::max(ret,elt->getTimeOfThis());
1481 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfParts : parts is empty !");
1485 std::size_t MEDFileUMeshAggregateCompute::getTimeOfUMesh() const
1487 const MEDCouplingUMesh *m(_m);
1489 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getTimeOfUMesh : unmesh is null !");
1490 return m->getTimeOfThis();
1493 std::size_t MEDFileUMeshAggregateCompute::getHeapMemorySizeWithoutChildren() const
1495 std::size_t ret(_m_parts.size()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh>));
1499 std::vector<const BigMemoryObject *> MEDFileUMeshAggregateCompute::getDirectChildrenWithNull() const
1501 std::vector<const BigMemoryObject *> ret;
1502 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1503 ret.push_back((const MEDCoupling1GTUMesh *)*it);
1504 ret.push_back((const MEDCouplingUMesh *)_m);
1508 MEDFileUMeshAggregateCompute MEDFileUMeshAggregateCompute::deepCpy(DataArrayDouble *coords) const
1510 MEDFileUMeshAggregateCompute ret;
1511 ret._m_parts.resize(_m_parts.size());
1512 for(std::size_t i=0;i<_m_parts.size();i++)
1514 const MEDCoupling1GTUMesh *elt(_m_parts[i]);
1517 ret._m_parts[i]=static_cast<ParaMEDMEM::MEDCoupling1GTUMesh*>(elt->deepCpy());
1518 ret._m_parts[i]->setCoords(coords);
1521 ret._mp_time=_mp_time; ret._m_time=_m_time;
1522 if((const MEDCouplingUMesh *)_m)
1524 ret._m=static_cast<ParaMEDMEM::MEDCouplingUMesh*>(_m->deepCpy());
1525 ret._m->setCoords(coords);
1527 std::size_t sz(_part_def.size());
1528 ret._part_def.clear(); ret._part_def.resize(sz);
1529 for(std::size_t i=0;i<sz;i++)
1531 const PartDefinition *elt(_part_def[i]);
1533 ret._part_def[i]=elt->deepCpy();
1538 bool MEDFileUMeshAggregateCompute::isEqual(const MEDFileUMeshAggregateCompute& other, double eps, std::string& what) const
1540 const MEDCouplingUMesh *m1(getUmesh());
1541 const MEDCouplingUMesh *m2(other.getUmesh());
1542 if((m1==0 && m2!=0) || (m1!=0 && m2==0))
1544 what="Presence of mesh in one sublevel and not in other!";
1550 if(!m1->isEqualIfNotWhy(m2,eps,what2))
1552 what=std::string("meshes at a sublevel are not deeply equal (")+what2+std::string(")!");
1556 std::size_t sz(_part_def.size());
1557 if(sz!=other._part_def.size())
1559 what=std::string("number of subdivision per geo type for part definition is not the same !");
1562 for(std::size_t i=0;i<sz;i++)
1564 const PartDefinition *pd0(_part_def[i]),*pd1(other._part_def[i]);
1567 if((!pd0 && pd1) || (pd0 && !pd1))
1569 what=std::string("a cell part def is defined only for one among this or other !");
1572 bool ret(pd0->isEqual(pd1,what));
1579 void MEDFileUMeshAggregateCompute::clearNonDiscrAttributes() const
1581 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1582 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(*it);
1583 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_m);
1586 void MEDFileUMeshAggregateCompute::synchronizeTinyInfo(const MEDFileMesh& master) const
1588 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1590 const MEDCoupling1GTUMesh *tmp(*it);
1593 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setName(master.getName().c_str());
1594 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setDescription(master.getDescription().c_str());
1595 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1596 (const_cast<MEDCoupling1GTUMesh *>(tmp))->setTimeUnit(master.getTimeUnit());
1599 const MEDCouplingUMesh *m(_m);
1602 (const_cast<MEDCouplingUMesh *>(m))->setName(master.getName().c_str());
1603 (const_cast<MEDCouplingUMesh *>(m))->setDescription(master.getDescription().c_str());
1604 (const_cast<MEDCouplingUMesh *>(m))->setTime(master.getTimeValue(),master.getIteration(),master.getOrder());
1605 (const_cast<MEDCouplingUMesh *>(m))->setTimeUnit(master.getTimeUnit());
1609 bool MEDFileUMeshAggregateCompute::empty() const
1611 if(_mp_time<_m_time)
1612 return ((const MEDCouplingUMesh *)_m)==0;
1613 //else _mp_time>=_m_time)
1614 return _m_parts.empty();
1617 int MEDFileUMeshAggregateCompute::getMeshDimension() const
1619 if(_mp_time<_m_time)
1621 const MEDCouplingUMesh *m(_m);
1623 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : no umesh in this !");
1624 return m->getMeshDimension();
1628 if(_m_parts.empty())
1629 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh is empty !");
1630 const MEDCoupling1GTUMesh *m(_m_parts[0]);
1632 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getMeshDimension : part mesh contains null instance !");
1633 return m->getMeshDimension();
1637 std::vector<int> MEDFileUMeshAggregateCompute::getDistributionOfTypes() const
1639 if(_mp_time<_m_time)
1641 const MEDCouplingUMesh *m(_m);
1643 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : no umesh in this !");
1644 return m->getDistributionOfTypes();
1648 std::vector<int> ret;
1649 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1651 const MEDCoupling1GTUMesh *tmp(*it);
1653 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getDistributionOfTypes : part mesh contains null instance !");
1654 std::vector<int> ret0(tmp->getDistributionOfTypes());
1655 ret.insert(ret.end(),ret0.begin(),ret0.end());
1661 int MEDFileUMeshAggregateCompute::getSize() const
1663 if(_mp_time<_m_time)
1665 const MEDCouplingUMesh *m(_m);
1667 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : no umesh in this !");
1668 return m->getNumberOfCells();
1673 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::const_iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1675 const MEDCoupling1GTUMesh *m(*it);
1677 throw INTERP_KERNEL::Exception("MEDFileUMeshAggregateCompute::getSize : part mesh contains null instance !");
1678 ret+=m->getNumberOfCells();
1684 void MEDFileUMeshAggregateCompute::setCoords(DataArrayDouble *coords)
1686 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> >::iterator it=_m_parts.begin();it!=_m_parts.end();it++)
1688 MEDCoupling1GTUMesh *tmp(*it);
1690 (*it)->setCoords(coords);
1692 MEDCouplingUMesh *m(_m);
1694 m->setCoords(coords);