1 // Copyright (C) 2007-2013 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.
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 "MEDFileMesh.hxx"
22 #include "MEDFileUtilities.hxx"
23 #include "MEDLoader.hxx"
24 #include "MEDLoaderBase.hxx"
26 #include "MEDCouplingUMesh.hxx"
28 #include "InterpKernelAutoPtr.hxx"
33 using namespace ParaMEDMEM;
35 const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO";
37 MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.)
41 std::size_t MEDFileMesh::getHeapMemorySize() const
43 std::size_t ret=_dt_unit.capacity()+_name.capacity()+_univ_name.capacity()+_desc_name.capacity();
44 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
46 ret+=(*it).first.capacity()+(*it).second.capacity()*sizeof(std::string);
47 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
48 ret+=(*it2).capacity();
50 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
51 ret+=(*it).first.capacity()+sizeof(int);
55 MEDFileMesh *MEDFileMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
57 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
60 std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << fileName << "\" !";
61 throw INTERP_KERNEL::Exception(oss.str().c_str());
63 MEDFileUtilities::CheckFileForRead(fileName);
64 ParaMEDMEM::MEDCouplingMeshType meshType;
65 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
68 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
73 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
74 ret->loadUMeshFromFile(fid,ms.front().c_str(),dt,it);
75 return (MEDFileUMesh *)ret.retn();
79 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
80 ret->loadCMeshFromFile(fid,ms.front().c_str(),dt,it);
81 return (MEDFileCMesh *)ret.retn();
85 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=MEDFileCurveLinearMesh::New();
86 ret->loadCLMeshFromFile(fid,ms.front().c_str(),dt,it);
87 return (MEDFileCMesh *)ret.retn();
91 std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << ms.front() << "' exists but unsupported type yet !";
92 throw INTERP_KERNEL::Exception(oss.str().c_str());
97 MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
99 MEDFileUtilities::CheckFileForRead(fileName);
100 ParaMEDMEM::MEDCouplingMeshType meshType;
101 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
104 MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
109 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
110 ret->loadUMeshFromFile(fid,mName,dt,it);
111 return (MEDFileUMesh *)ret.retn();
115 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
116 ret->loadCMeshFromFile(fid,mName,dt,it);
117 return (MEDFileCMesh *)ret.retn();
121 std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << mName << "' exists but unsupported type yet !";
122 throw INTERP_KERNEL::Exception(oss.str().c_str());
127 void MEDFileMesh::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
130 const_cast<MEDFileMesh *>(this)->addFamily(DFT_FAM_NAME,0);
132 throw INTERP_KERNEL::Exception("MEDFileMesh : name is empty. MED file ask for a NON EMPTY name !");
136 void MEDFileMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
138 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
139 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
140 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
141 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
145 bool MEDFileMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
147 if(_order!=other->_order)
149 what="Orders differ !";
152 if(_iteration!=other->_iteration)
154 what="Iterations differ !";
157 if(fabs(_time-other->_time)>eps)
159 what="Time values differ !";
162 if(_dt_unit!=other->_dt_unit)
164 what="Time units differ !";
167 if(_name!=other->_name)
169 what="Names differ !";
172 if(_univ_name!=other->_univ_name)
174 what="Univ names differ !";
177 if(_desc_name!=other->_desc_name)
179 what="Description names differ !";
182 if(!areGrpsEqual(other,what))
184 if(!areFamsEqual(other,what))
189 void MEDFileMesh::clearNonDiscrAttributes() const
194 bool MEDFileMesh::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
196 for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
198 if((*it).first==_name)
207 void MEDFileMesh::copyFamGrpMapsFrom(const MEDFileMesh& other)
209 _groups=other._groups;
210 _families=other._families;
213 std::vector<std::string> MEDFileMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
215 std::string oname(name);
216 std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
217 std::vector<std::string> grps=getGroupsNames();
218 if(it==_groups.end())
220 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
221 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
222 throw INTERP_KERNEL::Exception(oss.str().c_str());
227 std::vector<std::string> MEDFileMesh::getFamiliesOnGroups(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
229 std::set<std::string> fams;
230 for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
232 std::map<std::string, std::vector<std::string> >::const_iterator it2=_groups.find(*it);
233 if(it2==_groups.end())
235 std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it;
236 std::vector<std::string> grps2=getGroupsNames(); oss << "\" !\nAvailable groups are :";
237 std::copy(grps2.begin(),grps2.end(),std::ostream_iterator<std::string>(oss," "));
238 throw INTERP_KERNEL::Exception(oss.str().c_str());
240 fams.insert((*it2).second.begin(),(*it2).second.end());
242 std::vector<std::string> fams2(fams.begin(),fams.end());
246 std::vector<int> MEDFileMesh::getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
248 std::string oname(name);
249 std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
250 std::vector<std::string> grps=getGroupsNames();
251 if(it==_groups.end())
253 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
254 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
255 throw INTERP_KERNEL::Exception(oss.str().c_str());
257 return getFamiliesIds((*it).second);
261 * This method sets families at a corresponding groups existing or not. If it existed, it is replaced by new 'fams'.
262 * Each entry in 'fams' is checked if it is not still existing default id 0 is set.
264 void MEDFileMesh::setFamiliesOnGroup(const char *name, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
266 std::string oname(name);
268 for(std::vector<std::string>::const_iterator it1=fams.begin();it1!=fams.end();it1++)
270 std::map<std::string,int>::iterator it2=_families.find(*it1);
271 if(it2==_families.end())
277 * Behaves as MEDFileMesh::setFamiliesOnGroup, except that if there is presence of a family id in 'famIds' not existing an exception is thrown.
278 * If several families have same id the first one in lexical order is taken into account.
280 void MEDFileMesh::setFamiliesIdsOnGroup(const char *name, const std::vector<int>& famIds) throw(INTERP_KERNEL::Exception)
282 std::string oname(name);
283 std::vector<std::string> fams(famIds.size());
285 for(std::vector<int>::const_iterator it1=famIds.begin();it1!=famIds.end();it1++,i++)
287 std::string name2=getFamilyNameGivenId(*it1);
293 std::vector<std::string> MEDFileMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception)
295 std::vector<std::string> ret;
296 for(std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();it1!=_groups.end();it1++)
298 for(std::vector<std::string>::const_iterator it2=(*it1).second.begin();it2!=(*it1).second.end();it2++)
301 ret.push_back((*it1).first);
309 * This method expects that family 'famName' is already existing. If not an exception will be thrown.
311 void MEDFileMesh::setGroupsOnFamily(const char *famName, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception)
313 std::string fName(famName);
314 const std::map<std::string,int>::const_iterator it=_families.find(fName);
315 if(it==_families.end())
317 std::vector<std::string> fams=getFamiliesNames();
318 std::ostringstream oss; oss << "No such familyname \"" << fName << "\" !\nAvailable families are :";
319 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
320 throw INTERP_KERNEL::Exception(oss.str().c_str());
322 for(std::vector<std::string>::const_iterator it3=grps.begin();it3!=grps.end();it3++)
324 std::map< std::string, std::vector<std::string> >::iterator it2=_groups.find(*it3);
325 if(it2!=_groups.end())
326 (*it2).second.push_back(fName);
329 std::vector<std::string> grps2(1,fName);
335 std::vector<std::string> MEDFileMesh::getGroupsNames() const
337 std::vector<std::string> ret(_groups.size());
339 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++,i++)
344 std::vector<std::string> MEDFileMesh::getFamiliesNames() const
346 std::vector<std::string> ret(_families.size());
348 for(std::map<std::string, int >::const_iterator it=_families.begin();it!=_families.end();it++,i++)
354 * This method scans every families and for each families shared by only one group, the corresponding family takes the same name than the group.
356 void MEDFileMesh::assignFamilyNameWithGroupName() throw(INTERP_KERNEL::Exception)
358 std::map<std::string, std::vector<std::string> > groups(_groups);
359 std::map<std::string,int> newFams;
360 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
362 std::vector<std::string> grps=getGroupsOnFamily((*it).first.c_str());
363 if(grps.size()==1 && groups[grps[0]].size()==1)
365 if(newFams.find(grps[0])!=newFams.end())
367 std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << grps[0] << "\" already exists !";
368 throw INTERP_KERNEL::Exception(oss.str().c_str());
370 newFams[grps[0]]=(*it).second;
371 std::vector<std::string>& grps2=groups[grps[0]];
372 std::size_t pos=std::distance(grps2.begin(),std::find(grps2.begin(),grps2.end(),(*it).first));
377 if(newFams.find((*it).first)!=newFams.end())
379 std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << (*it).first << "\" already exists !";
380 throw INTERP_KERNEL::Exception(oss.str().c_str());
382 newFams[(*it).first]=(*it).second;
389 void MEDFileMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception)
391 std::string oname(name);
392 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
393 std::vector<std::string> grps=getGroupsNames();
394 if(it==_groups.end())
396 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
397 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
398 throw INTERP_KERNEL::Exception(oss.str().c_str());
403 void MEDFileMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception)
405 std::string oname(name);
406 std::map<std::string, int >::iterator it=_families.find(oname);
407 std::vector<std::string> fams=getFamiliesNames();
408 if(it==_families.end())
410 std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
411 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
412 throw INTERP_KERNEL::Exception(oss.str().c_str());
415 for(std::map<std::string, std::vector<std::string> >::iterator it3=_groups.begin();it3!=_groups.end();it3++)
417 std::vector<std::string>& v=(*it3).second;
418 std::vector<std::string>::iterator it4=std::find(v.begin(),v.end(),oname);
424 void MEDFileMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
426 std::string oname(oldName);
427 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
428 std::vector<std::string> grps=getGroupsNames();
429 if(it==_groups.end())
431 std::ostringstream oss; oss << "No such groupname \"" << oldName << "\" !\nAvailable groups are :";
432 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
433 throw INTERP_KERNEL::Exception(oss.str().c_str());
435 std::string nname(newName);
436 it=_groups.find(nname);
437 if(it!=_groups.end())
439 std::ostringstream oss; oss << "Such groupname \"" << newName << "\" already exists ! Kill it before !";
440 throw INTERP_KERNEL::Exception(oss.str().c_str());
442 std::vector<std::string> cpy=(*it).second;
444 _groups[newName]=cpy;
448 * This method changes the family ids in 'this'. It leads to a modification into '_families' attributes \b and in
449 * ids stored in arrays. This method calls MEDFileMesh::changeFamilyIdArr method.
451 void MEDFileMesh::changeFamilyId(int oldId, int newId) throw(INTERP_KERNEL::Exception)
453 changeFamilyIdArr(oldId,newId);
454 std::map<std::string,int> fam2;
455 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
457 if((*it).second==oldId)
458 fam2[(*it).first]=newId;
460 fam2[(*it).first]=(*it).second;
465 void MEDFileMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
467 std::string oname(oldName);
468 std::map<std::string, int >::iterator it=_families.find(oname);
469 std::vector<std::string> fams=getFamiliesNames();
470 if(it==_families.end())
472 std::ostringstream oss; oss << "No such familyname \"" << oldName << "\" !\nAvailable families are :";
473 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
474 throw INTERP_KERNEL::Exception(oss.str().c_str());
476 std::string nname(newName);
477 std::map<std::string, int >::iterator it2=_families.find(nname);
478 if(it2!=_families.end())
480 std::ostringstream oss; oss << "Such familyname \"" << newName << " already exists ! Kill it before !";
481 throw INTERP_KERNEL::Exception(oss.str().c_str());
483 int cpy=(*it).second;
485 _families[newName]=cpy;
486 for(std::map<std::string, std::vector<std::string> >::iterator it3=_groups.begin();it3!=_groups.end();it3++)
488 std::vector<std::string>& v=(*it3).second;
489 std::vector<std::string>::iterator it4=std::find(v.begin(),v.end(),oname);
495 bool MEDFileMesh::areFamsEqual(const MEDFileMesh *other, std::string& what) const
497 if(_families==other->_families)
499 std::map<std::string,int> fam0;
500 std::map<std::string,int> fam1;
501 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
503 fam0[(*it).first]=(*it).second;
504 for(std::map<std::string,int>::const_iterator it=other->_families.begin();it!=other->_families.end();it++)
506 fam1[(*it).first]=(*it).second;
510 bool MEDFileMesh::areGrpsEqual(const MEDFileMesh *other, std::string& what) const
512 if(_groups==other->_groups)
515 std::size_t sz=_groups.size();
516 if(sz!=other->_groups.size())
518 what="Groups differ because not same number !\n";
523 std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();
524 for(std::size_t i=0;i<sz && ret;i++,it1++)
526 std::map<std::string, std::vector<std::string> >::const_iterator it2=other->_groups.find((*it1).first);
527 if(it2!=other->_groups.end())
529 std::set<std::string> s1((*it1).second.begin(),(*it1).second.end());
530 std::set<std::string> s2((*it2).second.begin(),(*it2).second.end());
536 what="A group in first mesh exists not in other !\n";
542 std::ostringstream oss; oss << "Groups description differs :\n";
543 oss << "First group description :\n";
544 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
546 oss << " Group \"" << (*it).first << "\" on following families :\n";
547 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
548 oss << " \"" << *it2 << "\n";
550 oss << "Second group description :\n";
551 for(std::map<std::string, std::vector<std::string> >::const_iterator it=other->_groups.begin();it!=other->_groups.end();it++)
553 oss << " Group \"" << (*it).first << "\" on following families :\n";
554 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
555 oss << " \"" << *it2 << "\n";
562 bool MEDFileMesh::existsGroup(const char *groupName) const
564 std::string grpName(groupName);
565 return _groups.find(grpName)!=_groups.end();
568 bool MEDFileMesh::existsFamily(int famId) const
570 for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
571 if((*it2).second==famId)
576 bool MEDFileMesh::existsFamily(const char *familyName) const
578 std::string fname(familyName);
579 return _families.find(fname)!=_families.end();
582 void MEDFileMesh::setFamilyId(const char *familyName, int id)
584 std::string fname(familyName);
588 void MEDFileMesh::setFamilyIdUnique(const char *familyName, int id) throw(INTERP_KERNEL::Exception)
590 std::string fname(familyName);
591 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
594 if((*it).first!=familyName)
596 std::ostringstream oss; oss << "MEDFileMesh::setFamilyIdUnique : Family id #" << id << " is already belonging to family with name \"" << (*it).first << "\" !";
597 throw INTERP_KERNEL::Exception(oss.str().c_str());
604 * This method appends a new entry in _families attribute. An exception is thrown if either the famId is already
605 * kept by an another familyName. An exception is thrown if name 'familyName' is alreadyset with a different 'famId'.
607 void MEDFileMesh::addFamily(const char *familyName, int famId) throw(INTERP_KERNEL::Exception)
609 std::string fname(familyName);
610 std::map<std::string,int>::const_iterator it=_families.find(fname);
611 if(it==_families.end())
613 for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
614 if((*it2).second==famId)
616 std::ostringstream oss;
617 oss << "MEDFileMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !";
618 throw INTERP_KERNEL::Exception(oss.str().c_str());
620 _families[fname]=famId;
624 if((*it).second!=famId)
626 std::ostringstream oss;
627 oss << "MEDFileMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !";
628 throw INTERP_KERNEL::Exception(oss.str().c_str());
634 * This method creates a new group called 'groupName' in 'this'. If it exists a group with the same name an INTERP_KERNEL::Exception will be thrown.
635 * If the 'meshDimRelToMaxExt' is not existing an INTERP_KERNEL::Exception will be thrown too.
636 * \b WARNING : This method does \b not garantee that 'groupName' lies only on a single level specified by 'meshDimRelToMaxExt'.
637 * in the case of a presence of one or more family id in family field at 'meshDimRelToMaxExt' level that appears in another level.
638 * If there is a risk of such case call MEDFileMesh::keepFamIdsOnlyOnLevs method \b before calling this method.
639 * (call to MEDFileMesh::keepFamIdsOnlyOnLevs should be done with MEDFileMesh::getFamiliesIdsOnGroup('groupName' as first input ).
641 void MEDFileMesh::createGroupOnAll(int meshDimRelToMaxExt, const char *groupName) throw(INTERP_KERNEL::Exception)
643 std::string grpName(groupName);
644 std::vector<int> levs=getNonEmptyLevelsExt();
645 if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)==levs.end())
647 std::ostringstream oss; oss << "MEDFileMesh::createGroupOnAll : The relative ext dimension " << meshDimRelToMaxExt << " is not available !" << std::endl;
648 oss << "Available relative ext levels are : ";
649 std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," "));
650 throw INTERP_KERNEL::Exception(oss.str().c_str());
652 if(existsGroup(groupName))
654 std::ostringstream oss; oss << "MEDFileMesh::createGroupOnAll : The groups \"" << grpName << "\" already exists in this !" << std::endl;
655 oss << "Already existing groups are : ";
656 std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," "));
657 oss << std::endl << "Please choose an another group name or call removeGroup(\"" << grpName << "\") method !";
658 throw INTERP_KERNEL::Exception(oss.str().c_str());
660 const DataArrayInt *fieldFamIds=getFamilyFieldAtLevel(meshDimRelToMaxExt);
662 throw INTERP_KERNEL::Exception("MEDFileMesh::createGroupOnAll : Family field arr ids is not defined for this level !");
663 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famIds=fieldFamIds->getDifferentValues();
664 std::vector<std::string> familiesOnWholeGroup;
665 for(const int *it=famIds->begin();it!=famIds->end();it++)
668 familiesOnWholeGroup.push_back(findOrCreateAndGiveFamilyWithId(*it,tmp));
670 _groups[grpName]=familiesOnWholeGroup;
674 * This method checks that family Ids in 'famIds' are not present in levels \b not in 'vMeshDimRelToMaxExt'.
675 * If it is the case true is returned and 'this' is not modified.
676 * If there is some levels not in 'vMeshDimRelToMaxExt' where one or more family ids in 'famIds' appear
677 * new families are created and groups are updated in consequence.
679 bool MEDFileMesh::keepFamIdsOnlyOnLevs(const std::vector<int>& famIds, const std::vector<int>& vMeshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
681 std::set<int> levsInput(vMeshDimRelToMaxExt.begin(),vMeshDimRelToMaxExt.end());
682 std::vector<int> levs=getNonEmptyLevelsExt();
683 std::set<int> levs2(levs.begin(),levs.end());
684 std::vector<int> levsToTest;
685 std::set_difference(levs2.begin(),levs2.end(),levsInput.begin(),levsInput.end(),std::back_insert_iterator< std::vector<int> >(levsToTest));
686 std::set<int> famIds2(famIds.begin(),famIds.end());
689 if(!_families.empty())
690 maxFamId=getMaxFamilyId()+1;
691 std::vector<std::string> allFams=getFamiliesNames();
692 for(std::vector<int>::const_iterator it=levsToTest.begin();it!=levsToTest.end();it++)
694 const DataArrayInt *fieldFamIds=getFamilyFieldAtLevel(*it);
697 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famIds3=fieldFamIds->getDifferentValues();
698 std::vector<int> tmp;
699 std::set_intersection(famIds3->begin(),famIds3->end(),famIds2.begin(),famIds2.end(),std::back_insert_iterator< std::vector<int> >(tmp));
700 for(std::vector<int>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
703 std::string famName=getFamilyNameGivenId(*it2);
704 std::ostringstream oss; oss << "Family_" << maxFamId;
705 std::string zeName=CreateNameNotIn(oss.str(),allFams);
706 addFamilyOnAllGroupsHaving(famName.c_str(),zeName.c_str());
707 _families[zeName]=maxFamId;
708 (const_cast<DataArrayInt *>(fieldFamIds))->changeValue(*it2,maxFamId);
717 * This method add into the family list of a group 'grpName' the family with name 'famName'.
718 * If the group 'grpName' does not exist it is created and 'famName' is added to the list.
719 * If the group 'grpName' already exists, 'famName' will be added into family list of the existing group.
720 * This method throws an INTERP_KERNEL::Exception if 'famName' does not exit.
722 void MEDFileMesh::addFamilyOnGrp(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception)
724 std::string grpn(grpName);
725 std::string famn(famName);
726 if(grpn.empty() || famn.empty())
727 throw INTERP_KERNEL::Exception("MEDFileMesh::addFamilyOnGrp : input strings must be non null !");
728 std::vector<std::string> fams=getFamiliesNames();
729 if(std::find(fams.begin(),fams.end(),famn)==fams.end())
731 std::ostringstream oss; oss << "MEDFileMesh::addFamilyOnGrp : Family \"" << famn << "\" does not exist !" << std::endl;
732 oss << "Create this family or choose an existing one ! Existing fams are : ";
733 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," ")); oss << ".";
734 throw INTERP_KERNEL::Exception(oss.str().c_str());
736 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(grpn);
737 if(it==_groups.end())
739 _groups[grpn].push_back(famn);
743 std::vector<std::string>::iterator it2=std::find((*it).second.begin(),(*it).second.end(),famn);
744 if(it2==(*it).second.end())
745 (*it).second.push_back(famn);
750 * This method adds to all groups lying on family with name 'famName' the other family name 'otherFamName'.
751 * This method is quite underground because it can lead to unconsistency because family 'otherFamName' is \b not added into _families.
752 * This method is used by MEDFileMesh::keepFamIdsOnlyOnLevs method.
754 void MEDFileMesh::addFamilyOnAllGroupsHaving(const char *famName, const char *otherFamName) throw(INTERP_KERNEL::Exception)
756 std::string famNameCpp(famName);
757 std::string otherCpp(otherFamName);
758 for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
760 std::vector<std::string>& v=(*it).second;
761 if(std::find(v.begin(),v.end(),famNameCpp)!=v.end())
763 v.push_back(otherCpp);
768 void MEDFileMesh::changeAllGroupsContainingFamily(const char *familyNameToChange, const std::vector<std::string>& newFamiliesNames) throw(INTERP_KERNEL::Exception)
770 ChangeAllGroupsContainingFamily(_groups,familyNameToChange,newFamiliesNames);
773 void MEDFileMesh::ChangeAllGroupsContainingFamily(std::map<std::string, std::vector<std::string> >& groups, const char *familyNameToChange, const std::vector<std::string>& newFamiliesNames) throw(INTERP_KERNEL::Exception)
775 std::string fam(familyNameToChange);
776 for(std::map<std::string, std::vector<std::string> >::iterator it=groups.begin();it!=groups.end();it++)
778 std::vector<std::string>& fams((*it).second);
779 std::vector<std::string>::iterator it2=std::find(fams.begin(),fams.end(),fam);
783 fams.insert(fams.end(),newFamiliesNames.begin(),newFamiliesNames.end());
789 * If it exists a family whose family id is equal to 'id' this method behaves as MEDFileMesh::getFamilyNameGivenId.
790 * In this case, 'this' internal states remains unchanged and 'created' out parameter will be set to false.
791 * If there is no family whose family id is equal to 'id' a family is created with a name different from those
792 * already existing. In this case 'created' will be returned with a value set to true, and internal state
794 * This method will throws an exception if it is not possible to create a unique family name.
796 std::string MEDFileMesh::findOrCreateAndGiveFamilyWithId(int id, bool& created) throw(INTERP_KERNEL::Exception)
798 return FindOrCreateAndGiveFamilyWithId(_families,id,created);
802 * If it exists a family whose family id is equal to 'id' this method behaves as MEDFileMesh::getFamilyNameGivenId.
803 * In this case, 'this' internal states remains unchanged and 'created' out parameter will be set to false.
804 * If there is no family whose family id is equal to 'id' a family is created with a name different from those
805 * already existing. In this case 'created' will be returned with a value set to true, and internal state
807 * This method will throws an exception if it is not possible to create a unique family name.
809 std::string MEDFileMesh::FindOrCreateAndGiveFamilyWithId(std::map<std::string,int>& families, int id, bool& created) throw(INTERP_KERNEL::Exception)
811 std::vector<std::string> famAlreadyExisting(families.size());
813 for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++,ii++)
817 famAlreadyExisting[ii]=(*it).first;
826 std::ostringstream oss; oss << "Family_" << id;
827 std::string ret=CreateNameNotIn(oss.str(),famAlreadyExisting);
832 void MEDFileMesh::setFamilyInfo(const std::map<std::string,int>& info)
837 void MEDFileMesh::setGroupInfo(const std::map<std::string, std::vector<std::string> >&info)
842 int MEDFileMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception)
844 std::string oname(name);
845 std::map<std::string, int>::const_iterator it=_families.find(oname);
846 std::vector<std::string> fams=getFamiliesNames();
847 if(it==_families.end())
849 std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
850 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
851 throw INTERP_KERNEL::Exception(oss.str().c_str());
856 std::vector<int> MEDFileMesh::getFamiliesIds(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
858 std::vector<int> ret(fams.size());
860 for(std::vector<std::string>::const_iterator it=fams.begin();it!=fams.end();it++,i++)
862 std::map<std::string, int>::const_iterator it2=_families.find(*it);
863 if(it2==_families.end())
865 std::vector<std::string> fams2=getFamiliesNames();
866 std::ostringstream oss; oss << "No such familyname \"" << *it << "\" in input list !\nAvailable families are :";
867 std::copy(fams2.begin(),fams2.end(),std::ostream_iterator<std::string>(oss," "));
868 throw INTERP_KERNEL::Exception(oss.str().c_str());
870 ret[i]=(*it2).second;
875 int MEDFileMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception)
877 if(_families.empty())
878 throw INTERP_KERNEL::Exception("MEDFileUMesh::getMaxFamilyId : no families set !");
879 int ret=-std::numeric_limits<int>::max();
880 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
882 ret=std::max((*it).second,ret);
887 int MEDFileMesh::getMinFamilyId() const throw(INTERP_KERNEL::Exception)
889 if(_families.empty())
890 throw INTERP_KERNEL::Exception("MEDFileUMesh::getMinFamilyId : no families set !");
891 int ret=std::numeric_limits<int>::max();
892 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
894 ret=std::min((*it).second,ret);
899 int MEDFileMesh::getTheMaxFamilyId() const throw(INTERP_KERNEL::Exception)
901 int m1=-std::numeric_limits<int>::max();
902 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
903 m1=std::max((*it).second,m1);
904 int m2=getMaxFamilyIdInArrays();
905 return std::max(m1,m2);
908 int MEDFileMesh::getTheMinFamilyId() const throw(INTERP_KERNEL::Exception)
910 int m1=std::numeric_limits<int>::max();
911 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
912 m1=std::min((*it).second,m1);
913 int m2=getMinFamilyIdInArrays();
914 return std::min(m1,m2);
917 DataArrayInt *MEDFileMesh::getAllFamiliesIdsReferenced() const throw(INTERP_KERNEL::Exception)
919 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
921 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
922 v.insert((*it).second);
923 ret->alloc((int)v.size(),1);
924 std::copy(v.begin(),v.end(),ret->getPointer());
929 * true is returned if no modification has been needed. false if family
930 * renumbering has been needed.
932 bool MEDFileMesh::ensureDifferentFamIdsPerLevel() throw(INTERP_KERNEL::Exception)
934 std::vector<int> levs=getNonEmptyLevelsExt();
935 std::set<int> allFamIds;
936 int maxId=getMaxFamilyId()+1;
937 std::map<int,std::vector<int> > famIdsToRenum;
938 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
940 const DataArrayInt *fam=getFamilyFieldAtLevel(*it);
943 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
945 std::set_intersection(tmp->begin(),tmp->end(),allFamIds.begin(),allFamIds.end(),std::inserter(r2,r2.end()));
947 famIdsToRenum[*it].insert(famIdsToRenum[*it].end(),r2.begin(),r2.end());
949 std::set_union(tmp->begin(),tmp->end(),allFamIds.begin(),allFamIds.end(),std::inserter(r3,r3.end()));
952 if(famIdsToRenum.empty())
954 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
955 for(std::map<int,std::vector<int> >::const_iterator it2=famIdsToRenum.begin();it2!=famIdsToRenum.end();it2++)
957 DataArrayInt *fam=const_cast<DataArrayInt *>(getFamilyFieldAtLevel((*it2).first));
958 int *famIdsToChange=fam->getPointer();
959 std::map<int,int> ren;
960 for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++,maxId++)
962 if(allIds->presenceOfValue(*it3))
964 std::string famName=getFamilyNameGivenId(*it3);
965 std::vector<std::string> grps=getGroupsOnFamily(famName.c_str());
968 std::string newFam=findOrCreateAndGiveFamilyWithId(maxId,dummy);
969 for(std::vector<std::string>::const_iterator it4=grps.begin();it4!=grps.end();it4++)
970 addFamilyOnGrp((*it4).c_str(),newFam.c_str());
973 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=fam->getIdsEqualList(&(*it2).second[0],&(*it2).second[0]+(*it2).second.size());
974 for(const int *id=ids->begin();id!=ids->end();id++)
975 famIdsToChange[*id]=ren[famIdsToChange[*id]];
981 * This method normalizes fam id with the policy explained underneath. This policy is close to those implemented in SMESH.
982 * Level #0 famids > 0, Level #-1 famids < 0, Level #-2 famids=0, Level #1 famids=0
983 * This policy is those used by SMESH and Trio and that is the opposite of those in MED file.
984 * This method will throw an exception if a same family id is detected in different level.
985 * \warning This policy is the opposite of those in MED file documentation ...
987 void MEDFileMesh::normalizeFamIdsTrio() throw(INTERP_KERNEL::Exception)
989 ensureDifferentFamIdsPerLevel();
990 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
991 std::vector<int> levs=getNonEmptyLevelsExt();
992 std::set<int> levsS(levs.begin(),levs.end());
993 std::set<std::string> famsFetched;
994 std::map<std::string,int> families;
995 if(std::find(levs.begin(),levs.end(),0)!=levs.end())
998 const DataArrayInt *fam=getFamilyFieldAtLevel(0);
1002 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1003 std::map<int,int> ren;
1004 for(const int *it=tmp->begin();it!=tmp->end();it++,refId++)
1006 int nbOfTuples=fam->getNumberOfTuples();
1007 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1008 for(int *w=start;w!=start+nbOfTuples;w++)
1010 for(const int *it=tmp->begin();it!=tmp->end();it++)
1012 if(allIds->presenceOfValue(*it))
1014 std::string famName=getFamilyNameGivenId(*it);
1015 families[famName]=ren[*it];
1016 famsFetched.insert(famName);
1021 if(std::find(levs.begin(),levs.end(),-1)!=levs.end())
1024 const DataArrayInt *fam=getFamilyFieldAtLevel(-1);
1028 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1029 std::map<int,int> ren;
1030 for(const int *it=tmp->begin();it!=tmp->end();it++,refId--)
1032 int nbOfTuples=fam->getNumberOfTuples();
1033 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1034 for(int *w=start;w!=start+nbOfTuples;w++)
1036 for(const int *it=tmp->begin();it!=tmp->end();it++)
1038 if(allIds->presenceOfValue(*it))
1040 std::string famName=getFamilyNameGivenId(*it);
1041 families[famName]=ren[*it];
1042 famsFetched.insert(famName);
1047 for(std::set<int>::const_iterator it2=levsS.begin();it2!=levsS.end();it2++)
1049 DataArrayInt *fam=const_cast<DataArrayInt*>(getFamilyFieldAtLevel(*it2));
1052 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1053 fam->fillWithZero();
1054 for(const int *it3=tmp->begin();it3!=tmp->end();it3++)
1055 if(allIds->presenceOfValue(*it3))
1057 std::string famName=getFamilyNameGivenId(*it3);
1058 families[famName]=0;
1059 famsFetched.insert(famName);
1064 std::vector<std::string> allFams=getFamiliesNames();
1065 std::set<std::string> allFamsS(allFams.begin(),allFams.end());
1066 std::set<std::string> unFetchedIds;
1067 std::set_difference(allFamsS.begin(),allFamsS.end(),famsFetched.begin(),famsFetched.end(),std::inserter(unFetchedIds,unFetchedIds.end()));
1068 for(std::set<std::string>::const_iterator it4=unFetchedIds.begin();it4!=unFetchedIds.end();it4++)
1069 families[*it4]=_families[*it4];
1074 * This method normalizes fam id with the following policy.
1075 * Level #0 famids < 0, Level #-1 famids < 0 and for Level #1 famids >= 0
1076 * This policy is those defined in the MED file format but is the opposite of those implemented in SMESH and Trio.
1077 * This method will throw an exception if a same family id is detected in different level.
1079 void MEDFileMesh::normalizeFamIdsMEDFile() throw(INTERP_KERNEL::Exception)
1081 ensureDifferentFamIdsPerLevel();
1082 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
1083 std::vector<int> levs=getNonEmptyLevelsExt();
1084 std::set<int> levsS(levs.begin(),levs.end());
1085 std::set<std::string> famsFetched;
1086 std::map<std::string,int> families;
1088 if(std::find(levs.begin(),levs.end(),1)!=levs.end())
1091 const DataArrayInt *fam=getFamilyFieldAtLevel(1);
1094 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1095 std::map<int,int> ren;
1096 for(const int *it=tmp->begin();it!=tmp->end();it++,refId++)
1098 int nbOfTuples=fam->getNumberOfTuples();
1099 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1100 for(int *w=start;w!=start+nbOfTuples;w++)
1102 for(const int *it=tmp->begin();it!=tmp->end();it++)
1104 if(allIds->presenceOfValue(*it))
1106 std::string famName=getFamilyNameGivenId(*it);
1107 families[famName]=ren[*it];
1108 famsFetched.insert(famName);
1114 for(std::set<int>::const_reverse_iterator it2=levsS.rbegin();it2!=levsS.rend();it2++)
1116 const DataArrayInt *fam=getFamilyFieldAtLevel(1);
1119 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1120 std::map<int,int> ren;
1121 for(const int *it=tmp->begin();it!=tmp->end();it++,refId--)
1123 int nbOfTuples=fam->getNumberOfTuples();
1124 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1125 for(int *w=start;w!=start+nbOfTuples;w++)
1127 for(const int *it=tmp->begin();it!=tmp->end();it++)
1129 if(allIds->presenceOfValue(*it))
1131 std::string famName=getFamilyNameGivenId(*it);
1132 families[famName]=ren[*it];
1133 famsFetched.insert(famName);
1139 std::vector<std::string> allFams=getFamiliesNames();
1140 std::set<std::string> allFamsS(allFams.begin(),allFams.end());
1141 std::set<std::string> unFetchedIds;
1142 std::set_difference(allFamsS.begin(),allFamsS.end(),famsFetched.begin(),famsFetched.end(),std::inserter(unFetchedIds,unFetchedIds.end()));
1143 for(std::set<std::string>::const_iterator it4=unFetchedIds.begin();it4!=unFetchedIds.end();it4++)
1144 families[*it4]=_families[*it4];
1149 * Returns the first (in lexical order) family name having family id equal to 'id'.
1151 std::string MEDFileMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception)
1153 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1154 if((*it).second==id)
1156 std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id;
1157 throw INTERP_KERNEL::Exception(oss.str().c_str());
1160 std::string MEDFileMesh::simpleRepr() const
1162 std::ostringstream oss;
1163 oss << "(*************************************)\n(* GENERAL INFORMATION ON THE MESH : *)\n(*************************************)\n";
1164 oss << "- Name of the mesh : <<" << getName() << ">>\n";
1165 oss << "- Description associated to the mesh : " << getDescription() << std::endl;
1169 DataArrayInt *MEDFileMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
1171 std::vector<std::string> tmp(1);
1173 DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum);
1178 DataArrayInt *MEDFileMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
1180 std::vector<std::string> fams2=getFamiliesOnGroups(grps);
1181 return getFamiliesArr(meshDimRelToMaxExt,fams2,renum);
1184 DataArrayInt *MEDFileMesh::getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
1186 std::vector<std::string> tmp(1);
1188 DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum);
1193 DataArrayInt *MEDFileMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
1195 std::vector<std::string> tmp(1);
1197 DataArrayInt *ret=getNodeGroupsArr(tmp,renum);
1202 DataArrayInt *MEDFileMesh::getNodeGroupsArr(const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
1204 return getGroupsArr(1,grps,renum);
1207 DataArrayInt *MEDFileMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
1209 std::vector<std::string> tmp(1);
1211 DataArrayInt *ret=getNodeFamiliesArr(tmp,renum);
1216 DataArrayInt *MEDFileMesh::getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
1218 return getFamiliesArr(1,fams,renum);
1221 void MEDFileMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum) throw(INTERP_KERNEL::Exception)
1225 std::set<std::string> grpsName;
1226 std::vector<std::string> grpsName2(grps.size());
1229 for(std::vector<const DataArrayInt *>::const_iterator it=grps.begin();it!=grps.end();it++,i++)
1231 grpsName.insert((*it)->getName());
1232 grpsName2[i]=(*it)->getName();
1234 if(grpsName.size()!=grps.size())
1235 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !");
1236 if(grpsName.find(std::string(""))!=grpsName.end())
1237 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !");
1238 int sz=getSizeAtLevel(meshDimRelToMaxExt);
1239 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam;
1240 std::vector< std::vector<int> > fidsOfGroups;
1243 fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups);
1247 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grps2(grps.size());
1248 for(unsigned int ii=0;ii<grps.size();ii++)
1250 grps2[ii]=MEDFileUMeshSplitL1::Renumber(getRevNumberFieldAtLevel(meshDimRelToMaxExt),grps[ii]);
1251 grps2[ii]->setName(grps[ii]->getName().c_str());
1253 std::vector<const DataArrayInt *> grps3(grps2.begin(),grps2.end());
1254 fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups);
1257 if(!_families.empty())
1258 offset=getMaxFamilyId()+1;
1259 TranslateFamilyIds(offset,fam,fidsOfGroups);
1260 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=fam->getDifferentValues();
1261 appendFamilyEntries(ids,fidsOfGroups,grpsName2);
1262 setFamilyFieldArr(meshDimRelToMaxExt,fam);
1266 * This method append into '_families' attribute the families whose ids are in 'famIds'. Warning 'famIds' are expected to be ids
1267 * not in '_families'. Groups information are given in parameters in order to give to families representative names.
1268 * For the moment, the two last input parameters are not taken into account.
1270 void MEDFileMesh::appendFamilyEntries(const DataArrayInt *famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames)
1272 std::map<int,std::string> famInv;
1273 for(const int *it=famIds->begin();it!=famIds->end();it++)
1275 std::ostringstream oss;
1276 oss << "Family_" << (*it);
1277 _families[oss.str()]=(*it);
1278 famInv[*it]=oss.str();
1281 for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++)
1283 for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
1285 _groups[grpNames[i]].push_back(famInv[*it2]);
1290 void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp)
1292 famArr->applyLin(1,offset,0);
1293 for(std::vector< std::vector<int> >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++)
1294 std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<int>(),offset));
1298 * Warning no check is done on 'nameTry' in parameter. It should be non empty.
1299 * This method returns a name close to 'nameTry' so that it is not already into 'namesToAvoid'.
1300 * If this method fails to find such a name it will throw an exception.
1302 std::string MEDFileMesh::CreateNameNotIn(const std::string& nameTry, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
1305 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),nameTry)==namesToAvoid.end())
1308 std::size_t len=nameTry.length();
1309 for(std::size_t ii=1;ii<len;ii++)
1311 std::string tmp=nameTry.substr(ii,len-ii);
1312 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp)==namesToAvoid.end())
1318 for(std::size_t i=1;i<30;i++)
1320 std::string tmp1(nameTry.at(0),i);
1322 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp1)==namesToAvoid.end())
1328 for(std::vector<std::string>::const_iterator it2=namesToAvoid.begin();it2!=namesToAvoid.end();it2++)
1330 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp2)==namesToAvoid.end())
1332 throw INTERP_KERNEL::Exception("MEDFileMesh::CreateNameNotIn : impossible to find a not already used name !");
1335 int MEDFileMesh::PutInThirdComponentOfCodeOffset(std::vector<int>& code, int strt) throw(INTERP_KERNEL::Exception)
1337 std::size_t nbOfChunks=code.size()/3;
1338 if(code.size()%3!=0)
1339 throw INTERP_KERNEL::Exception("MEDFileMesh::PutInThirdComponentOfCodeOffset : code has invalid size : should be of size 3*x !");
1341 for(std::size_t i=0;i<nbOfChunks;i++)
1350 * This method should be called by any set* method of subclasses to deal automatically with _name attribute.
1351 * If _name attribute is empty the name of 'm' if taken as _name attribute.
1352 * If _name is not empty and that 'm' has the same name nothing is done.
1353 * If _name is not emplt and that 'm' has \b NOT the same name an exception is thrown.
1355 void MEDFileMesh::dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception)
1361 std::string name(m->getName());
1366 std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : name of current MEDfile mesh is '" << _name << "' whereas name of input mesh is : '";
1367 oss << name << "' ! Names must match !";
1368 throw INTERP_KERNEL::Exception(oss.str().c_str());
1372 if(_desc_name.empty())
1373 _desc_name=m->getDescription();
1376 std::string name(m->getDescription());
1379 if(_desc_name!=name)
1381 std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : description of current MEDfile mesh is '" << _desc_name << "' whereas name of input mesh is : '";
1382 oss << name << "' ! Names must match !";
1383 throw INTERP_KERNEL::Exception(oss.str().c_str());
1389 void MEDFileMesh::getFamilyRepr(std::ostream& oss) const
1391 oss << "(**************************)\n(* FAMILIES OF THE MESH : *)\n(**************************)\n";
1392 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1394 oss << "- Family with name \"" << (*it).first << "\" with number " << (*it).second << std::endl;
1395 oss << " - Groups lying on this family : ";
1396 std::vector<std::string> grps=getGroupsOnFamily((*it).first.c_str());
1397 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
1398 oss << std::endl << std::endl;
1402 MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
1404 MEDFileUtilities::CheckFileForRead(fileName);
1405 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1406 return new MEDFileUMesh(fid,mName,dt,it);
1409 MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
1411 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
1414 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
1415 throw INTERP_KERNEL::Exception(oss.str().c_str());
1417 MEDFileUtilities::CheckFileForRead(fileName);
1418 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1420 ParaMEDMEM::MEDCouplingMeshType meshType;
1422 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
1423 return new MEDFileUMesh(fid,ms.front().c_str(),dt,it);
1426 MEDFileUMesh *MEDFileUMesh::New()
1428 return new MEDFileUMesh;
1431 std::size_t MEDFileUMesh::getHeapMemorySize() const
1433 std::size_t ret=MEDFileMesh::getHeapMemorySize();
1434 if((const DataArrayDouble*)_coords)
1435 ret+=_coords->getHeapMemorySize();
1436 if((const DataArrayInt *)_fam_coords)
1437 ret+=_fam_coords->getHeapMemorySize();
1438 if((const DataArrayInt *)_num_coords)
1439 ret+=_num_coords->getHeapMemorySize();
1440 if((const DataArrayInt *)_rev_num_coords)
1441 ret+=_rev_num_coords->getHeapMemorySize();
1442 if((const DataArrayAsciiChar *)_name_coords)
1443 ret+=_name_coords->getHeapMemorySize();
1444 ret+=_ms.capacity()*(sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1>));
1445 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
1446 if((const MEDFileUMeshSplitL1*) *it)
1447 ret+=(*it)->getHeapMemorySize();
1451 MEDFileMesh *MEDFileUMesh::shallowCpy() const throw(INTERP_KERNEL::Exception)
1453 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=new MEDFileUMesh(*this);
1457 MEDFileMesh *MEDFileUMesh::deepCpy() const throw(INTERP_KERNEL::Exception)
1459 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=new MEDFileUMesh(*this);
1460 if((const DataArrayDouble*)_coords)
1461 ret->_coords=_coords->deepCpy();
1462 if((const DataArrayInt*)_fam_coords)
1463 ret->_fam_coords=_fam_coords->deepCpy();
1464 if((const DataArrayInt*)_num_coords)
1465 ret->_num_coords=_num_coords->deepCpy();
1466 if((const DataArrayInt*)_rev_num_coords)
1467 ret->_rev_num_coords=_rev_num_coords->deepCpy();
1468 if((const DataArrayAsciiChar*)_name_coords)
1469 ret->_name_coords=_name_coords->deepCpy();
1471 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++)
1473 if((const MEDFileUMeshSplitL1 *)(*it))
1474 ret->_ms[i]=(*it)->deepCpy();
1479 bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
1481 if(!MEDFileMesh::isEqual(other,eps,what))
1483 const MEDFileUMesh *otherC=dynamic_cast<const MEDFileUMesh *>(other);
1486 what="Mesh types differ ! This is unstructured and other is NOT !";
1489 clearNonDiscrAttributes();
1490 otherC->clearNonDiscrAttributes();
1491 const DataArrayDouble *coo1=_coords;
1492 const DataArrayDouble *coo2=otherC->_coords;
1493 if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
1495 what="Mismatch of coordinates ! One is defined and not other !";
1500 bool ret=coo1->isEqual(*coo2,eps);
1503 what="Coords differ !";
1507 const DataArrayInt *famc1=_fam_coords;
1508 const DataArrayInt *famc2=otherC->_fam_coords;
1509 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
1511 what="Mismatch of families arr on nodes ! One is defined and not other !";
1516 bool ret=famc1->isEqual(*famc2);
1519 what="Families arr on node differ !";
1523 const DataArrayInt *numc1=_num_coords;
1524 const DataArrayInt *numc2=otherC->_num_coords;
1525 if((numc1==0 && numc2!=0) || (numc1!=0 && numc2==0))
1527 what="Mismatch of numbering arr on nodes ! One is defined and not other !";
1532 bool ret=numc1->isEqual(*numc2);
1535 what="Numbering arr on node differ !";
1539 const DataArrayAsciiChar *namec1=_name_coords;
1540 const DataArrayAsciiChar *namec2=otherC->_name_coords;
1541 if((namec1==0 && namec2!=0) || (namec1!=0 && namec2==0))
1543 what="Mismatch of naming arr on nodes ! One is defined and not other !";
1548 bool ret=namec1->isEqual(*namec2);
1551 what="Names arr on node differ !";
1555 if(_ms.size()!=otherC->_ms.size())
1557 what="Number of levels differs !";
1560 std::size_t sz=_ms.size();
1561 for(std::size_t i=0;i<sz;i++)
1563 const MEDFileUMeshSplitL1 *s1=_ms[i];
1564 const MEDFileUMeshSplitL1 *s2=otherC->_ms[i];
1565 if((s1==0 && s2!=0) || (s1!=0 && s2==0))
1567 what="Mismatch of presence of sub levels !";
1572 bool ret=s1->isEqual(s2,eps,what);
1580 void MEDFileUMesh::clearNonDiscrAttributes() const
1582 MEDFileMesh::clearNonDiscrAttributes();
1583 const DataArrayDouble *coo1=_coords;
1585 (const_cast<DataArrayDouble *>(coo1))->setName("");//This parameter is not discriminant for comparison
1586 const DataArrayInt *famc1=_fam_coords;
1588 (const_cast<DataArrayInt *>(famc1))->setName("");//This parameter is not discriminant for comparison
1589 const DataArrayInt *numc1=_num_coords;
1591 (const_cast<DataArrayInt *>(numc1))->setName("");//This parameter is not discriminant for comparison
1592 const DataArrayAsciiChar *namc1=_name_coords;
1594 (const_cast<DataArrayAsciiChar *>(namc1))->setName("");//This parameter is not discriminant for comparison
1595 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
1597 const MEDFileUMeshSplitL1 *tmp=(*it);
1599 tmp->clearNonDiscrAttributes();
1603 MEDFileUMesh::MEDFileUMesh()
1607 MEDFileUMesh::MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
1610 loadUMeshFromFile(fid,mName,dt,it);
1612 catch(INTERP_KERNEL::Exception& e)
1617 void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
1619 MEDFileUMeshL2 loaderl2;
1620 ParaMEDMEM::MEDCouplingMeshType meshType;
1623 int mid=MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
1624 if(meshType!=UNSTRUCTURED)
1626 std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !";
1627 throw INTERP_KERNEL::Exception(oss.str().c_str());
1629 loaderl2.loadAll(fid,mid,mName,dt,it);
1630 int lev=loaderl2.getNumberOfLevels();
1632 for(int i=0;i<lev;i++)
1634 if(!loaderl2.emptyLev(i))
1635 _ms[i]=new MEDFileUMeshSplitL1(loaderl2,mName,i);
1639 MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups);
1641 setName(loaderl2.getName());
1642 setDescription(loaderl2.getDescription());
1643 setIteration(loaderl2.getIteration());
1644 setOrder(loaderl2.getOrder());
1645 setTimeValue(loaderl2.getTime());
1646 setTimeUnit(loaderl2.getTimeUnit());
1647 _coords=loaderl2.getCoords();
1648 _fam_coords=loaderl2.getCoordsFamily();
1649 _num_coords=loaderl2.getCoordsNum();
1650 _name_coords=loaderl2.getCoordsName();
1654 MEDFileUMesh::~MEDFileUMesh()
1658 void MEDFileUMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
1660 const DataArrayDouble *coo=_coords;
1661 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1662 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
1663 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
1664 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
1665 int spaceDim=coo?coo->getNumberOfComponents():0;
1666 int mdim=getMeshDimension();
1667 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
1668 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
1669 for(int i=0;i<spaceDim;i++)
1671 std::string info=coo->getInfoOnComponent(i);
1673 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
1674 MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
1675 MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
1677 MEDmeshCr(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
1678 MEDFileUMeshL2::WriteCoords(fid,maa,_iteration,_order,_time,_coords,_fam_coords,_num_coords,_name_coords);
1679 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
1680 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
1681 (*it)->write(fid,maa,mdim);
1682 MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
1685 std::vector<int> MEDFileUMesh::getNonEmptyLevels() const
1687 std::vector<int> ret;
1689 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
1690 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
1696 std::vector<int> MEDFileUMesh::getNonEmptyLevelsExt() const
1698 std::vector<int> ret0=getNonEmptyLevels();
1699 if((const DataArrayDouble *) _coords)
1701 std::vector<int> ret(ret0.size()+1);
1703 std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
1710 * This methods returns all relative mesh levels where group 'grp' is defined \b excluded \b nodes.
1711 * To include nodes call MEDFileUMesh::getGrpNonEmptyLevelsExt method.
1713 std::vector<int> MEDFileUMesh::getGrpNonEmptyLevels(const char *grp) const throw(INTERP_KERNEL::Exception)
1715 std::vector<std::string> fams=getFamiliesOnGroup(grp);
1716 return getFamsNonEmptyLevels(fams);
1720 * This method is a generalization of MEDFileUMesh::getGrpNonEmptyLevelsExt. It looks at the node level to state if the group 'grp' has a part lying on node.
1722 std::vector<int> MEDFileUMesh::getGrpNonEmptyLevelsExt(const char *grp) const throw(INTERP_KERNEL::Exception)
1724 std::vector<std::string> fams=getFamiliesOnGroup(grp);
1725 return getFamsNonEmptyLevelsExt(fams);
1729 * This methods returns all relative mesh levels where family 'fam' is defined \b excluded \b nodes.
1730 * To include nodes call MEDFileUMesh::getFamNonEmptyLevelsExt method.
1732 std::vector<int> MEDFileUMesh::getFamNonEmptyLevels(const char *fam) const throw(INTERP_KERNEL::Exception)
1734 std::vector<std::string> fams(1,std::string(fam));
1735 return getFamsNonEmptyLevels(fams);
1739 * This method is a generalization of MEDFileUMesh::getFamNonEmptyLevels. It looks at the node level to state if the family 'fam' has a part lying on node.
1741 std::vector<int> MEDFileUMesh::getFamNonEmptyLevelsExt(const char *fam) const throw(INTERP_KERNEL::Exception)
1743 std::vector<std::string> fams(1,std::string(fam));
1744 return getFamsNonEmptyLevelsExt(fams);
1748 * This methods returns all relative mesh levels where groups 'grps' are defined \b excluded \b nodes.
1749 * To include nodes call MEDFileUMesh::getGrpsNonEmptyLevelsExt method.
1751 std::vector<int> MEDFileUMesh::getGrpsNonEmptyLevels(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
1753 std::vector<std::string> fams=getFamiliesOnGroups(grps);
1754 return getFamsNonEmptyLevels(fams);
1758 * This method is a generalization of MEDFileUMesh::getGrpsNonEmptyLevels. It looks at the node level to state if the families 'fams' has a part lying on node.
1760 std::vector<int> MEDFileUMesh::getGrpsNonEmptyLevelsExt(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
1762 std::vector<std::string> fams=getFamiliesOnGroups(grps);
1763 return getFamsNonEmptyLevelsExt(fams);
1767 * This methods returns all relative mesh levels where families 'fams' are defined \b excluded \b nodes.
1768 * To include nodes call MEDFileUMesh::getFamsNonEmptyLevelsExt method.
1770 std::vector<int> MEDFileUMesh::getFamsNonEmptyLevels(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
1772 std::vector<int> ret;
1773 std::vector<int> levs=getNonEmptyLevels();
1774 std::vector<int> famIds=getFamiliesIds(fams);
1775 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
1776 if(_ms[-(*it)]->presenceOfOneFams(famIds))
1782 * This method is a generalization of MEDFileUMesh::getFamsNonEmptyLevels. It looks at the node level to state if the families 'fams' has a part lying on node.
1784 std::vector<int> MEDFileUMesh::getFamsNonEmptyLevelsExt(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
1786 std::vector<int> ret0=getFamsNonEmptyLevels(fams);
1787 const DataArrayInt *famCoords=_fam_coords;
1790 std::vector<int> famIds=getFamiliesIds(fams);
1791 if(famCoords->presenceOfValue(famIds))
1793 std::vector<int> ret(ret0.size()+1);
1795 std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
1803 * This method retrives all groups that partly or fully appear on the level 'meshDimRelToMaxExt'.
1805 std::vector<std::string> MEDFileUMesh::getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1807 std::vector<std::string> ret;
1808 std::vector<std::string> allGrps=getGroupsNames();
1809 for(std::vector<std::string>::const_iterator it=allGrps.begin();it!=allGrps.end();it++)
1811 std::vector<int> levs=getGrpNonEmptyLevelsExt((*it).c_str());
1812 if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)!=levs.end())
1818 int MEDFileUMesh::getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception)
1820 int ret=-std::numeric_limits<int>::max(),tmp=-1;
1821 if((const DataArrayInt *)_fam_coords)
1823 int val=_fam_coords->getMaxValue(tmp);
1824 ret=std::max(ret,val);
1826 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
1828 if((const MEDFileUMeshSplitL1 *)(*it))
1830 const DataArrayInt *da=(*it)->getFamilyField();
1833 int val=_fam_coords->getMaxValue(tmp);
1834 ret=std::max(ret,val);
1841 int MEDFileUMesh::getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception)
1843 int ret=std::numeric_limits<int>::max(),tmp=-1;
1844 if((const DataArrayInt *)_fam_coords)
1846 int val=_fam_coords->getMinValue(tmp);
1847 ret=std::min(ret,val);
1849 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
1851 if((const MEDFileUMeshSplitL1 *)(*it))
1853 const DataArrayInt *da=(*it)->getFamilyField();
1856 int val=_fam_coords->getMinValue(tmp);
1857 ret=std::min(ret,val);
1864 int MEDFileUMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception)
1867 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++)
1868 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
1869 return (*it)->getMeshDimension()+lev;
1870 throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !");
1873 int MEDFileUMesh::getSpaceDimension() const throw(INTERP_KERNEL::Exception)
1875 const DataArrayDouble *coo=_coords;
1877 throw INTERP_KERNEL::Exception(" MEDFileUMesh::getSpaceDimension : no coords set !");
1878 return coo->getNumberOfComponents();
1881 std::string MEDFileUMesh::simpleRepr() const
1883 std::ostringstream oss;
1884 oss << MEDFileMesh::simpleRepr();
1885 const DataArrayDouble *coo=_coords;
1886 oss << "- The dimension of the space is ";
1887 static const char MSG1[]= "*** NO COORDS SET ***";
1888 static const char MSG2[]= "*** NO CONNECTIVITY SET FOR THIS LEVEL***";
1890 oss << _coords->getNumberOfComponents() << std::endl;
1892 oss << MSG1 << std::endl;
1893 oss << "- Type of the mesh : UNSTRUCTURED\n";
1894 oss << "- Number of nodes : ";
1896 oss << _coords->getNumberOfTuples() << std::endl;
1898 oss << MSG1 << std::endl;
1899 std::size_t nbOfLev=_ms.size();
1900 oss << "- Number of levels allocated : " << nbOfLev << std::endl;
1901 for(std::size_t i=0;i<nbOfLev;i++)
1903 const MEDFileUMeshSplitL1 *lev=_ms[i];
1904 oss << " - Level #" << -((int) i) << " has dimension : ";
1907 oss << lev->getMeshDimension() << std::endl;
1908 lev->simpleRepr(oss);
1911 oss << MSG2 << std::endl;
1913 oss << "- Number of families : " << _families.size() << std::endl << std::endl;
1916 oss << "(***********************)\n(* NODES OF THE MESH : *)\n(***********************)\n";
1917 oss << "- Names of coordinates :" << std::endl;
1918 std::vector<std::string> vars=coo->getVarsOnComponent();
1919 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
1920 oss << std::endl << "- Units of coordinates : " << std::endl;
1921 std::vector<std::string> units=coo->getUnitsOnComponent();
1922 std::copy(units.begin(),units.end(),std::ostream_iterator<std::string>(oss," "));
1924 oss << std::endl << std::endl;
1929 std::string MEDFileUMesh::advancedRepr() const
1931 return simpleRepr();
1934 int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1936 if(meshDimRelToMaxExt==1)
1938 if(!((const DataArrayDouble *)_coords))
1939 throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !");
1940 return _coords->getNumberOfTuples();
1942 return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize();
1945 const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1947 if(meshDimRelToMaxExt==1)
1949 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1950 return l1->getFamilyField();
1953 const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1955 if(meshDimRelToMaxExt==1)
1957 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1958 return l1->getNumberField();
1961 const DataArrayAsciiChar *MEDFileUMesh::getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1963 if(meshDimRelToMaxExt==1)
1964 return _name_coords;
1965 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1966 return l1->getNameField();
1969 int MEDFileUMesh::getNumberOfNodes() const throw(INTERP_KERNEL::Exception)
1971 const DataArrayDouble *coo=_coords;
1973 throw INTERP_KERNEL::Exception(" MEDFileUMesh::getNumberOfNodes : no coords set !");
1974 return coo->getNumberOfTuples();
1977 const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1979 if(meshDimRelToMaxExt==1)
1981 if(!((const DataArrayInt *)_num_coords))
1982 throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !");
1983 return _rev_num_coords;
1985 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1986 return l1->getRevNumberField();
1990 * This method returns coordinates in 'this'. The returned array reference counter is \b not incremented by this method (as MEDCouplingPointSet::getCoords does).
1992 DataArrayDouble *MEDFileUMesh::getCoords() const
1994 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(_coords);
1995 if((DataArrayDouble *)tmp)
2002 MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
2004 synchronizeTinyInfoOnLeaves();
2005 std::vector<std::string> tmp(1);
2007 MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum);
2012 MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
2014 synchronizeTinyInfoOnLeaves();
2015 std::vector<std::string> fams2=getFamiliesOnGroups(grps);
2016 return getFamilies(meshDimRelToMaxExt,fams2,renum);
2019 MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
2021 synchronizeTinyInfoOnLeaves();
2022 std::vector<std::string> tmp(1);
2024 MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum);
2029 MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
2031 synchronizeTinyInfoOnLeaves();
2032 if(meshDimRelToMaxExt==1)
2034 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=getFamiliesArr(1,fams,renum);
2035 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
2036 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems());
2040 std::vector<int> famIds=getFamiliesIds(fams);
2041 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
2043 return l1->getFamilyPart(&famIds[0],&famIds[0]+famIds.size(),renum);
2045 return l1->getFamilyPart(0,0,renum);
2048 DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
2050 std::vector<int> famIds=getFamiliesIds(fams);
2051 if(meshDimRelToMaxExt==1)
2053 if((const DataArrayInt *)_fam_coords)
2055 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
2057 da=_fam_coords->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
2059 da=_fam_coords->getIdsEqualList(0,0);
2061 return MEDFileUMeshSplitL1::Renumber(_num_coords,da);
2066 throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamiliesArr : no family array specified on nodes !");
2068 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
2070 return l1->getFamilyPartArr(&famIds[0],&famIds[0]+famIds.size(),renum);
2072 return l1->getFamilyPartArr(0,0,renum);
2076 * Returns a pointer to mesh at the specified level.
2078 * \return a pointer to unstructured mesh that need to be managed by the caller.
2079 * \warning the returned pointer has to be managed by the caller.
2080 * \sa MEDFileUMesh::getGenMeshAtLevel
2082 MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception)
2084 synchronizeTinyInfoOnLeaves();
2085 if(meshDimRelToMaxExt==1)
2089 MEDCouplingUMesh *umesh=MEDCouplingUMesh::New();
2090 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> cc=_coords->deepCpy();
2091 umesh->setCoords(cc);
2092 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(umesh);
2093 umesh->setName(getName());
2097 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
2098 return l1->getWholeMesh(renum);
2102 * Returns a pointer to mesh at the specified level.
2104 * \return a pointer to unstructured mesh that need to be managed by the caller.
2105 * \warning the returned pointer has to be managed by the caller.
2106 * \sa MEDFileUMesh::getMeshAtLevel
2108 MEDCouplingMesh *MEDFileUMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception)
2110 return getMeshAtLevel(meshDimRelToMax,renum);
2113 MEDCouplingUMesh *MEDFileUMesh::getLevel0Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
2115 return getMeshAtLevel(0,renum);
2118 MEDCouplingUMesh *MEDFileUMesh::getLevelM1Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
2120 return getMeshAtLevel(-1,renum);
2123 MEDCouplingUMesh *MEDFileUMesh::getLevelM2Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
2125 return getMeshAtLevel(-2,renum);
2128 MEDCouplingUMesh *MEDFileUMesh::getLevelM3Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
2130 return getMeshAtLevel(-3,renum);
2133 const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
2135 if(meshDimRelToMaxExt==1)
2136 throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
2137 if(meshDimRelToMaxExt>1)
2138 throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
2139 int tracucedRk=-meshDimRelToMaxExt;
2140 if(tracucedRk>=(int)_ms.size())
2141 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
2142 if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
2143 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
2144 return _ms[tracucedRk];
2147 MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
2149 if(meshDimRelToMaxExt==1)
2150 throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
2151 if(meshDimRelToMaxExt>1)
2152 throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
2153 int tracucedRk=-meshDimRelToMaxExt;
2154 if(tracucedRk>=(int)_ms.size())
2155 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
2156 if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
2157 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
2158 return _ms[tracucedRk];
2161 void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
2163 if(-meshDimRelToMax>=(int)_ms.size())
2164 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : The meshdim of mesh is not managed by 'this' !");
2166 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++)
2168 if(((const MEDFileUMeshSplitL1*) (*it))!=0)
2170 int ref=(*it)->getMeshDimension();
2171 if(ref+i!=meshDim-meshDimRelToMax)
2172 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : no coherency between levels !");
2177 void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception)
2180 throw INTERP_KERNEL::Exception("MEDFileUMesh::setCoords : null pointer in input !");
2181 coords->checkAllocated();
2182 int nbOfTuples=coords->getNumberOfTuples();
2185 _fam_coords=DataArrayInt::New();
2186 _fam_coords->alloc(nbOfTuples,1);
2187 _fam_coords->fillWithZero();
2190 void MEDFileUMesh::eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
2192 if(meshDimRelToMaxExt==1)
2194 if((DataArrayInt *)_fam_coords)
2195 _fam_coords->fillWithZero();
2198 MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
2199 l1->eraseFamilyField();
2203 void MEDFileUMesh::optimizeFamilies() throw(INTERP_KERNEL::Exception)
2205 std::vector<int> levs=getNonEmptyLevelsExt();
2206 std::set<int> allFamsIds;
2207 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
2209 const DataArrayInt *ffield=getFamilyFieldAtLevel(*it);
2210 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=ffield->getDifferentValues();
2212 std::set_union(ids->begin(),ids->end(),allFamsIds.begin(),allFamsIds.end(),std::inserter(res,res.begin()));
2215 std::set<std::string> famNamesToKill;
2216 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
2218 if(allFamsIds.find((*it).second)!=allFamsIds.end())
2219 famNamesToKill.insert((*it).first);
2221 for(std::set<std::string>::const_iterator it=famNamesToKill.begin();it!=famNamesToKill.end();it++)
2222 _families.erase(*it);
2223 std::vector<std::string> grpNamesToKill;
2224 for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
2226 std::vector<std::string> tmp;
2227 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
2229 if(famNamesToKill.find(*it2)==famNamesToKill.end())
2230 tmp.push_back(*it2);
2235 tmp.push_back((*it).first);
2237 for(std::vector<std::string>::const_iterator it=grpNamesToKill.begin();it!=grpNamesToKill.end();it++)
2241 void MEDFileUMesh::duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified, DataArrayInt *&cellsNotModified) throw(INTERP_KERNEL::Exception)
2243 std::vector<int> levs=getNonEmptyLevels();
2244 if(std::find(levs.begin(),levs.end(),0)==levs.end() || std::find(levs.begin(),levs.end(),-1)==levs.end())
2245 throw INTERP_KERNEL::Exception("MEDFileUMesh::duplicateNodesOnM1Group : This method works only for mesh definied on level 0 and -1 !");
2246 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0=getMeshAtLevel(0);
2247 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1=getMeshAtLevel(-1);
2248 int nbNodes=m0->getNumberOfNodes();
2249 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m11=getGroup(-1,grpNameM1);
2250 DataArrayInt *tmp00=0,*tmp11=0,*tmp22=0;
2251 m0->findNodesToDuplicate(*m11,tmp00,tmp11,tmp22);
2252 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeIdsToDuplicate(tmp00);
2253 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn0(tmp11);
2254 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn1(tmp22);
2255 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp0=static_cast<MEDCouplingUMesh *>(m0->buildPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),true));
2256 // node renumbering of cells in m1 impacted by duplication of node but not in group 'grpNameM1' on level -1
2257 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> descTmp0=DataArrayInt::New(),descITmp0=DataArrayInt::New(),revDescTmp0=DataArrayInt::New(),revDescITmp0=DataArrayInt::New();
2258 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp0Desc=tmp0->buildDescendingConnectivity(descTmp0,descITmp0,revDescTmp0,revDescITmp0);
2259 descTmp0=0; descITmp0=0; revDescTmp0=0; revDescITmp0=0;
2260 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW2=tmp0Desc->getCellIdsLyingOnNodes(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),false);
2261 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> cellsInM1ToRenumW3=static_cast<MEDCouplingUMesh *>(tmp0Desc->buildPartOfMySelf(cellsInM1ToRenumW2->begin(),cellsInM1ToRenumW2->end(),true));
2262 DataArrayInt *cellsInM1ToRenumW4Tmp=0;
2263 m1->areCellsIncludedIn(cellsInM1ToRenumW3,2,cellsInM1ToRenumW4Tmp);
2264 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW4(cellsInM1ToRenumW4Tmp);
2265 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW5=cellsInM1ToRenumW4->getIdsInRange(0,m1->getNumberOfCells());
2266 cellsInM1ToRenumW5->transformWithIndArr(cellsInM1ToRenumW4->begin(),cellsInM1ToRenumW4->end());
2267 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpIds=getGroupArr(-1,grpNameM1);
2268 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenum=cellsInM1ToRenumW5->buildSubstraction(grpIds);
2269 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1Part=static_cast<MEDCouplingUMesh *>(m1->buildPartOfMySelf(cellsInM1ToRenum->begin(),cellsInM1ToRenum->end(),true));
2270 m1Part->duplicateNodesInConn(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),nbNodes);
2271 m1->setPartOfMySelf(cellsInM1ToRenum->begin(),cellsInM1ToRenum->end(),*m1Part);
2272 // end of node renumbering of cells in m1 impacted by duplication of node but not in group of level -1 'grpNameM1'
2273 tmp0->duplicateNodes(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end());
2274 m0->setCoords(tmp0->getCoords());
2275 m0->setPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),*tmp0);
2276 m1->setCoords(m0->getCoords());
2277 _coords=m0->getCoords(); _coords->incrRef();
2278 // duplication of cells in group 'grpNameM1' on level -1
2279 m11->duplicateNodesInConn(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),nbNodes); m11->setCoords(m0->getCoords());
2280 std::vector<const MEDCouplingUMesh *> v(2); v[0]=m1; v[1]=m11;
2281 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> newm1=MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(v,tmp00,tmp11);
2282 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> szOfCellGrpOfSameType(tmp00);
2283 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idInMsOfCellGrpOfSameType(tmp11);
2285 newm1->setName(getName());
2286 const DataArrayInt *fam=getFamilyFieldAtLevel(-1);
2288 throw INTERP_KERNEL::Exception("MEDFileUMesh::duplicateNodesOnM1Group : internal problem !");
2289 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFam=DataArrayInt::New();
2290 newFam->alloc(newm1->getNumberOfCells(),1);
2291 int idd=getMaxFamilyId()+1;
2292 int globStart=0,start=0,end,globEnd;
2293 int nbOfChunks=szOfCellGrpOfSameType->getNumberOfTuples();
2294 for(int i=0;i<nbOfChunks;i++)
2296 globEnd=globStart+szOfCellGrpOfSameType->getIJ(i,0);
2297 if(idInMsOfCellGrpOfSameType->getIJ(i,0)==0)
2299 end=start+szOfCellGrpOfSameType->getIJ(i,0);
2300 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> part=fam->selectByTupleId2(start,end,1);
2301 newFam->setPartOfValues1(part,globStart,globEnd,1,0,1,1,true);
2306 newFam->setPartOfValuesSimple1(idd,globStart,globEnd,1,0,1,1);
2310 newm1->setCoords(getCoords());
2311 setMeshAtLevel(-1,newm1);
2312 setFamilyFieldArr(-1,newFam);
2313 std::string grpName2(grpNameM1); grpName2+="_dup";
2314 addFamily(grpName2.c_str(),idd);
2315 addFamilyOnGrp(grpName2.c_str(),grpName2.c_str());
2320 int newNbOfNodes=getCoords()->getNumberOfTuples();
2321 newFam=DataArrayInt::New(); newFam->alloc(newNbOfNodes,1);
2322 newFam->setPartOfValues1(fam,0,nbNodes,1,0,1,1,true);
2323 newFam->setPartOfValuesSimple1(0,nbNodes,newNbOfNodes,1,0,1,1);
2326 nodesDuplicated=nodeIdsToDuplicate.retn();
2327 cellsModified=cellsToModifyConn0.retn();
2328 cellsNotModified=cellsToModifyConn1.retn();
2332 * \param [out] oldCode retrieves the distribution of types before the call if true is returned
2333 * \param [out] newCode etrieves the distribution of types after the call if true is returned
2334 * \param [out] o2nRenumCell tells for **all levels** the old 2 new renumbering of cells.
2336 * \return false if no modification has been performed linked to the unpolyzation. Neither cell type, not cell numbers. When false is returned no need of field on cells or on gauss renumbering.
2337 * Inversely, if true is returned, it means that distribution of cell by geometric type has changed and field on cell and field on gauss point must be renumbered.
2339 bool MEDFileUMesh::unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception)
2341 o2nRenumCell=0; oldCode.clear(); newCode.clear();
2342 std::vector<int> levs=getNonEmptyLevels();
2344 std::vector< const DataArrayInt* > renumCellsSplited;//same than memorySaverIfThrow
2345 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > memorySaverIfThrow;//same than renumCellsSplited only in case of throw
2348 for(std::vector<int>::reverse_iterator it=levs.rbegin();it!=levs.rend();it++)
2350 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=getMeshAtLevel(*it);
2351 std::vector<int> code1=m->getDistributionOfTypes();
2352 end=PutInThirdComponentOfCodeOffset(code1,start);
2353 oldCode.insert(oldCode.end(),code1.begin(),code1.end());
2354 bool hasChanged=m->unPolyze();
2355 DataArrayInt *fake=0;
2356 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nCellsPart=m->getLevArrPerCellTypes(MEDCouplingUMesh::MEDMEM_ORDER,
2357 MEDCouplingUMesh::MEDMEM_ORDER+MEDCouplingUMesh::N_MEDMEM_ORDER,fake);
2359 renumCellsSplited.push_back(o2nCellsPart); memorySaverIfThrow.push_back(o2nCellsPart);
2362 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nCellsPart2=o2nCellsPart->buildPermArrPerLevel();
2363 m->renumberCells(o2nCellsPart2->getConstPointer(),false);
2365 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famField2,numField2;
2366 const DataArrayInt *famField=getFamilyFieldAtLevel(*it); if(famField) { famField->incrRef(); famField2=const_cast<DataArrayInt *>(famField); }
2367 const DataArrayInt *numField=getNumberFieldAtLevel(*it); if(numField) { numField->incrRef(); numField2=const_cast<DataArrayInt *>(numField); }
2368 setMeshAtLevel(*it,m);
2369 std::vector<int> code2=m->getDistributionOfTypes();
2370 end=PutInThirdComponentOfCodeOffset(code2,start);
2371 newCode.insert(newCode.end(),code2.begin(),code2.end());
2373 if(o2nCellsPart2->isIdentity())
2377 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFamField=famField->renumber(o2nCellsPart2->getConstPointer());
2378 setFamilyFieldArr(*it,newFamField);
2382 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newNumField=numField->renumber(o2nCellsPart2->getConstPointer());
2383 setRenumFieldArr(*it,newNumField);
2388 newCode.insert(newCode.end(),code1.begin(),code1.end());
2394 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumCells=DataArrayInt::Aggregate(renumCellsSplited);
2395 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nRenumCellRet=renumCells->buildPermArrPerLevel();
2396 o2nRenumCell=o2nRenumCellRet.retn();
2401 struct MEDLoaderAccVisit1
2403 MEDLoaderAccVisit1():_new_nb_of_nodes(0) { }
2404 int operator()(bool val) { return val?_new_nb_of_nodes++:-1; }
2405 int _new_nb_of_nodes;
2409 * Array returned is the correspondance in \b old \b to \b new format. The returned array is newly created and should be dealt by the caller.
2410 * The maximum value stored in returned array is the number of nodes of \a this minus 1 after call of this method.
2411 * The size of returned array is the number of nodes of the old (previous to the call of this method) number of nodes.
2412 * -1 values in returned array means that the corresponding old node is no more used.
2414 * \return newly allocated array containing correspondance in \b old \b to \b new format. If all nodes in \a this are fetched NULL pointer is returned and nothing
2415 * is modified in \a this.
2416 * \throw If no coordinates are set in \a this or if there is in any available mesh in \a this a cell having a nodal connectivity containing a node id not in the range of
2419 DataArrayInt *MEDFileUMesh::zipCoords() throw(INTERP_KERNEL::Exception)
2421 const DataArrayDouble *coo=getCoords();
2423 throw INTERP_KERNEL::Exception("MEDFileUMesh::zipCoords : no coordinates set in this !");
2424 int nbOfNodes=coo->getNumberOfTuples();
2425 std::vector<bool> nodeIdsInUse(nbOfNodes,false);
2426 std::vector<int> neLevs=getNonEmptyLevels();
2427 for(std::vector<int>::const_iterator lev=neLevs.begin();lev!=neLevs.end();lev++)
2429 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=getMeshAtLevel(*lev);
2430 m->computeNodeIdsAlg(nodeIdsInUse);
2432 int nbrOfNodesInUse=(int)std::count(nodeIdsInUse.begin(),nodeIdsInUse.end(),true);
2433 if(nbrOfNodesInUse==nbOfNodes)
2435 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New(); ret->alloc(nbOfNodes,1);
2436 std::transform(nodeIdsInUse.begin(),nodeIdsInUse.end(),ret->getPointer(),MEDLoaderAccVisit1());
2437 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2=ret->invertArrayO2N2N2OBis(nbrOfNodesInUse);
2438 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> newCoords=coo->selectByTupleIdSafe(ret2->begin(),ret2->end());
2439 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFamCoords;
2440 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> newNameCoords;
2441 if((const DataArrayInt *)_fam_coords)
2442 newFamCoords=_fam_coords->selectByTupleIdSafe(ret2->begin(),ret2->end());
2443 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newNumCoords;
2444 if((const DataArrayInt *)_num_coords)
2445 newNumCoords=_num_coords->selectByTupleIdSafe(ret2->begin(),ret2->end());
2446 if((const DataArrayAsciiChar *)_name_coords)
2447 newNameCoords=static_cast<DataArrayAsciiChar *>(_name_coords->selectByTupleIdSafe(ret2->begin(),ret2->end()));
2448 _coords=newCoords; _fam_coords=newFamCoords; _num_coords=newNumCoords; _name_coords=newNameCoords; _rev_num_coords=0;
2449 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
2451 if((MEDFileUMeshSplitL1*)*it)
2452 (*it)->renumberNodesInConn(ret->begin());
2458 * This method is here only to add a group on node.
2459 * MEDFileUMesh::setGroupsAtLevel with 1 in the first parameter.
2461 * \param [in] ids node ids and group name of the new group to add. The ids should be sorted and different each other (MED file norm).
2463 void MEDFileUMesh::addNodeGroup(const DataArrayInt *ids) throw(INTERP_KERNEL::Exception)
2465 const DataArrayDouble *coords=_coords;
2467 throw INTERP_KERNEL::Exception("MEDFileUMesh::addNodeGroup : no coords set !");
2468 int nbOfNodes=coords->getNumberOfTuples();
2469 if(!((DataArrayInt *)_fam_coords))
2470 { _fam_coords=DataArrayInt::New(); _fam_coords->alloc(nbOfNodes,1); _fam_coords->fillWithZero(); }
2472 addGroupUnderground(ids,_fam_coords);
2475 void MEDFileUMesh::addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids) throw(INTERP_KERNEL::Exception)
2477 std::vector<int> levs=getNonEmptyLevelsExt();
2478 if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)==levs.end())
2480 std::ostringstream oss; oss << "MEDFileUMesh::addGroup : level " << meshDimRelToMaxExt << " not available ! Should be in ";
2481 std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," ")); oss << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str());
2483 if(meshDimRelToMaxExt==1)
2484 { addNodeGroup(ids); return ; }
2485 MEDFileUMeshSplitL1 *lev=getMeshAtLevSafe(meshDimRelToMaxExt);
2486 DataArrayInt *fam=lev->getOrCreateAndGetFamilyField();
2487 addGroupUnderground(ids,fam);
2491 * \param [in] ids ids and group name of the new group to add. The ids should be sorted and different each other (MED file norm).
2492 * \parma [in,out] famArr family array on level of interest to be renumbered. The input pointer should be not NULL (no check of that will be performed)
2494 void MEDFileUMesh::addGroupUnderground(const DataArrayInt *ids, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
2497 throw INTERP_KERNEL::Exception("MEDFileUMesh::addGroup : NULL pointer in input !");
2498 std::string grpName(ids->getName());
2500 throw INTERP_KERNEL::Exception("MEDFileUMesh::addGroup : empty group name ! MED file format do not accept empty group name !");
2501 ids->checkStrictlyMonotonic(true);
2502 famArr->incrRef(); MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famArrTmp(famArr);
2503 std::vector<std::string> grpsNames=getGroupsNames();
2504 if(std::find(grpsNames.begin(),grpsNames.end(),grpName)!=grpsNames.end())
2506 std::ostringstream oss; oss << "MEDFileUMesh::addGroup : Group with name \"" << grpName << "\" already exists ! Destroy it before calling this method !";
2507 throw INTERP_KERNEL::Exception(oss.str().c_str());
2509 std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > allFamIds=getAllNonNullFamilyIds();
2510 allFamIds.erase(std::find(allFamIds.begin(),allFamIds.end(),famArrTmp));
2511 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famIds=famArr->selectByTupleIdSafe(ids->begin(),ids->end());
2512 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffFamIds=famIds->getDifferentValues();
2513 std::vector<int> familyIds;
2514 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerfamiliyIds;
2515 int maxVal=getTheMaxFamilyId()+1;
2516 std::map<std::string,int> families(_families);
2517 std::map<std::string, std::vector<std::string> > groups(_groups);
2518 std::vector<std::string> fams;
2519 bool created(false);
2520 for(const int *famId=diffFamIds->begin();famId!=diffFamIds->end();famId++)
2522 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2Tmp=famIds->getIdsEqual(*famId);
2523 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2=ids->selectByTupleId(ids2Tmp->begin(),ids2Tmp->end());
2524 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids1=famArr->getIdsEqual(*famId);
2525 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret0(ids1->buildSubstractionOptimized(ids2));
2528 bool isFamPresent=false;
2529 for(std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator itl=allFamIds.begin();itl!=allFamIds.end() && !isFamPresent;itl++)
2530 isFamPresent=(*itl)->presenceOfValue(*famId);
2532 { familyIds.push_back(*famId); idsPerfamiliyIds.push_back(ret0); fams.push_back(FindOrCreateAndGiveFamilyWithId(families,*famId,created)); } // adding *famId in grp
2535 familyIds.push_back(maxVal); idsPerfamiliyIds.push_back(ids2); std::string locFamName=FindOrCreateAndGiveFamilyWithId(families,maxVal,created);
2536 fams.push_back(locFamName);
2537 if(existsFamily(*famId))
2539 std::string locFamName2=getFamilyNameGivenId(*famId); std::vector<std::string> v(2); v[0]=locFamName2; v[1]=locFamName;
2540 ChangeAllGroupsContainingFamily(groups,getFamilyNameGivenId(*famId).c_str(),v);
2543 } // modifying all other groups on *famId to lie on maxVal and lie the grp on maxVal
2547 familyIds.push_back(maxVal); idsPerfamiliyIds.push_back(ret0); // modifying all other groups on *famId to lie on maxVal and on maxVal+1
2548 familyIds.push_back(maxVal+1); idsPerfamiliyIds.push_back(ids2);//grp lie only on maxVal+1
2549 std::string n2(FindOrCreateAndGiveFamilyWithId(families,maxVal+1,created)); fams.push_back(n2);
2550 if(existsFamily(*famId))
2552 std::string n1(FindOrCreateAndGiveFamilyWithId(families,maxVal,created)); std::vector<std::string> v(2); v[0]=n1; v[1]=n2;
2553 ChangeAllGroupsContainingFamily(groups,getFamilyNameGivenId(*famId).c_str(),v);
2558 for(std::size_t i=0;i<familyIds.size();i++)
2560 DataArrayInt *da=idsPerfamiliyIds[i];
2561 famArr->setPartOfValuesSimple3(familyIds[i],da->begin(),da->end(),0,1,1);
2565 _groups[grpName]=fams;
2568 void MEDFileUMesh::setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception)
2570 std::string oldName=getFamilyNameGivenId(id);
2571 _families.erase(oldName);
2572 _families[newFamName]=id;
2575 void MEDFileUMesh::removeMeshAtLevel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
2577 std::vector<int> levSet=getNonEmptyLevels();
2578 std::vector<int>::const_iterator it=std::find(levSet.begin(),levSet.end(),meshDimRelToMax);
2579 if(it==levSet.end())
2580 throw INTERP_KERNEL::Exception("MEDFileUMesh::removeMeshAtLevel : the requested level is not existing !");
2581 int pos=(-meshDimRelToMax);
2585 void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
2587 setMeshAtLevelGen(meshDimRelToMax,m,newOrOld);
2590 void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
2592 dealWithTinyInfo(m);
2593 std::vector<int> levSet=getNonEmptyLevels();
2594 if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end())
2596 if((DataArrayDouble *)_coords==0)
2598 DataArrayDouble *c=m->getCoords();
2603 if(m->getCoords()!=_coords)
2604 throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtLevel : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !");
2605 int sz=(-meshDimRelToMax)+1;
2606 if(sz>=(int)_ms.size())
2608 checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax);
2609 _ms[sz-1]=new MEDFileUMeshSplitL1(m,newOrOld);
2612 _ms[-meshDimRelToMax]=new MEDFileUMeshSplitL1(m,newOrOld);
2615 void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception)
2618 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !");
2619 int sz=(-meshDimRelToMax)+1;
2620 if(sz>=(int)_ms.size())
2622 checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
2623 DataArrayDouble *coo=checkMultiMesh(ms);
2624 if((DataArrayDouble *)_coords==0)
2630 if((DataArrayDouble *)_coords!=coo)
2631 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : coordinates mismatches !");
2632 std::vector<DataArrayInt *> corr;
2633 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,_zipconn_pol,corr);
2634 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr3(corr.begin(),corr.end());
2635 setMeshAtLevel(meshDimRelToMax,m);
2636 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2637 setGroupsAtLevel(meshDimRelToMax,corr2,true);
2640 void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception)
2643 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !");
2644 int sz=(-meshDimRelToMax)+1;
2645 if(sz>=(int)_ms.size())
2647 checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
2648 DataArrayDouble *coo=checkMultiMesh(ms);
2649 if((DataArrayDouble *)_coords==0)
2655 if((DataArrayDouble *)_coords!=coo)
2656 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : coordinates mismatches !");
2657 MEDCouplingUMesh *m=getMeshAtLevel(meshDimRelToMax,renum);
2658 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr(ms.size());
2660 for(std::vector<const MEDCouplingUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
2662 DataArrayInt *arr=0;
2663 bool test=m->areCellsIncludedIn(*it,_zipconn_pol,arr);
2667 std::ostringstream oss; oss << "MEDFileUMesh::setGroupsOnSetMesh : mesh #" << i << " is not part of whole mesh !";
2668 throw INTERP_KERNEL::Exception(oss.str().c_str());
2671 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2672 setGroupsAtLevel(meshDimRelToMax,corr2,renum);
2675 DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception)
2677 const DataArrayDouble *ret=ms[0]->getCoords();
2678 int mdim=ms[0]->getMeshDimension();
2679 for(unsigned int i=1;i<ms.size();i++)
2681 ms[i]->checkCoherency();
2682 if(ms[i]->getCoords()!=ret)
2683 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes must share the same coords !");
2684 if(ms[i]->getMeshDimension()!=mdim)
2685 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes have not same mesh dimension !");
2687 return const_cast<DataArrayDouble *>(ret);
2690 void MEDFileUMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
2692 if(meshDimRelToMaxExt==1)
2699 DataArrayDouble *coo(_coords);
2701 throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : the coordinates have not been set !");
2702 famArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),1,"MEDFileUMesh::setFamilyFieldArr : Problem in size of node family arr ! ");
2707 if(meshDimRelToMaxExt>1)
2708 throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : Dimension request is invalid (>1) !");
2709 int traducedRk=-meshDimRelToMaxExt;
2710 if(traducedRk>=(int)_ms.size())
2711 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
2712 if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
2713 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
2714 return _ms[traducedRk]->setFamilyArr(famArr);
2717 void MEDFileUMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception)
2719 if(meshDimRelToMaxExt==1)
2727 DataArrayDouble *coo(_coords);
2729 throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumFieldArr : the coordinates have not been set !");
2730 renumArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),1,"MEDFileUMesh::setRenumArr : Problem in size of node numbering arr ! ");
2731 renumArr->incrRef();
2732 _num_coords=renumArr;
2736 if(meshDimRelToMaxExt>1)
2737 throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumArr : Dimension request is invalid (>1) !");
2738 int traducedRk=-meshDimRelToMaxExt;
2739 if(traducedRk>=(int)_ms.size())
2740 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
2741 if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
2742 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
2743 return _ms[traducedRk]->setRenumArr(renumArr);
2746 void MEDFileUMesh::setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception)
2748 if(meshDimRelToMaxExt==1)
2755 DataArrayDouble *coo(_coords);
2757 throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumFieldArr : the coordinates have not been set !");
2758 nameArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),MED_SNAME_SIZE,"MEDFileUMesh::setRenumArr : Problem in size of node numbering arr ! ");
2760 _name_coords=nameArr;
2763 if(meshDimRelToMaxExt>1)
2764 throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumArr : Dimension request is invalid (>1) !");
2765 int traducedRk=-meshDimRelToMaxExt;
2766 if(traducedRk>=(int)_ms.size())
2767 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
2768 if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
2769 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
2770 return _ms[traducedRk]->setNameArr(nameArr);
2773 void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const
2775 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2776 if((const MEDFileUMeshSplitL1 *)(*it))
2777 (*it)->synchronizeTinyInfo(*this);
2781 * This method is called by MEDFileMesh::changeFamilyId. It performs only one part of the family id modification.
2783 void MEDFileUMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception)
2785 DataArrayInt *arr=_fam_coords;
2787 arr->changeValue(oldId,newId);
2788 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
2790 MEDFileUMeshSplitL1 *sp=(*it);
2793 sp->changeFamilyIdArr(oldId,newId);
2798 std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > MEDFileUMesh::getAllNonNullFamilyIds() const
2800 std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > ret;
2801 const DataArrayInt *da(_fam_coords);
2803 { da->incrRef(); ret.push_back(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>(const_cast<DataArrayInt *>(da))); }
2804 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2806 const MEDFileUMeshSplitL1 *elt(*it);
2809 da=elt->getFamilyField();
2811 { da->incrRef(); ret.push_back(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>(const_cast<DataArrayInt *>(da))); }
2817 void MEDFileUMesh::computeRevNum() const
2819 if((const DataArrayInt *)_num_coords)
2822 int maxValue=_num_coords->getMaxValue(pos);
2823 _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1);
2827 std::size_t MEDFileStructuredMesh::getHeapMemorySize() const
2829 std::size_t ret=MEDFileMesh::getHeapMemorySize();
2830 if((const DataArrayInt*)_fam_nodes)
2831 ret+=_fam_nodes->getHeapMemorySize();
2832 if((const DataArrayInt*)_num_nodes)
2833 ret+=_num_nodes->getHeapMemorySize();
2834 if((const DataArrayInt*)_fam_cells)
2835 ret+=_fam_cells->getHeapMemorySize();
2836 if((const DataArrayInt*)_num_cells)
2837 ret+=_num_cells->getHeapMemorySize();
2838 if((const DataArrayInt*)_rev_num_nodes)
2839 ret+=_rev_num_nodes->getHeapMemorySize();
2840 if((const DataArrayInt*)_rev_num_cells)
2841 ret+=_rev_num_cells->getHeapMemorySize();
2845 int MEDFileStructuredMesh::getMaxFamilyIdInArrays() const throw(INTERP_KERNEL::Exception)
2847 int ret=-std::numeric_limits<int>::max(),tmp=-1;
2848 if((const DataArrayInt *)_fam_nodes)
2850 int val=_fam_nodes->getMaxValue(tmp);
2851 ret=std::max(ret,val);
2853 if((const DataArrayInt *)_fam_cells)
2855 int val=_fam_cells->getMaxValue(tmp);
2856 ret=std::max(ret,val);
2861 int MEDFileStructuredMesh::getMinFamilyIdInArrays() const throw(INTERP_KERNEL::Exception)
2863 int ret=std::numeric_limits<int>::max(),tmp=-1;
2864 if((const DataArrayInt *)_fam_nodes)
2866 int val=_fam_nodes->getMinValue(tmp);
2867 ret=std::min(ret,val);
2869 if((const DataArrayInt *)_fam_cells)
2871 int val=_fam_cells->getMinValue(tmp);
2872 ret=std::min(ret,val);
2877 bool MEDFileStructuredMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
2879 if(!MEDFileMesh::isEqual(other,eps,what))
2881 const MEDFileStructuredMesh *otherC=dynamic_cast<const MEDFileStructuredMesh *>(other);
2884 what="Mesh types differ ! This is structured and other is NOT !";
2887 const DataArrayInt *famc1=_fam_nodes;
2888 const DataArrayInt *famc2=otherC->_fam_nodes;
2889 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2891 what="Mismatch of families arr on nodes ! One is defined and not other !";
2896 bool ret=famc1->isEqual(*famc2);
2899 what="Families arr on nodes differ !";
2904 famc2=otherC->_fam_cells;
2905 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2907 what="Mismatch of families arr on cells ! One is defined and not other !";
2912 bool ret=famc1->isEqual(*famc2);
2915 what="Families arr on cells differ !";
2920 famc2=otherC->_num_nodes;
2921 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2923 what="Mismatch of numbering arr on nodes ! One is defined and not other !";
2928 bool ret=famc1->isEqual(*famc2);
2931 what="Numbering arr on nodes differ !";
2936 famc2=otherC->_num_cells;
2937 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2939 what="Mismatch of numbering arr on cells ! One is defined and not other !";
2944 bool ret=famc1->isEqual(*famc2);
2947 what="Numbering arr on cells differ !";
2951 const DataArrayAsciiChar *d1=_names_cells;
2952 const DataArrayAsciiChar *d2=otherC->_names_cells;
2953 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
2955 what="Mismatch of naming arr on cells ! One is defined and not other !";
2960 bool ret=d1->isEqual(*d2);
2963 what="Naming arr on cells differ !";
2968 d2=otherC->_names_nodes;
2969 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
2971 what="Mismatch of naming arr on nodes ! One is defined and not other !";
2976 bool ret=d1->isEqual(*d2);
2979 what="Naming arr on nodes differ !";
2986 void MEDFileStructuredMesh::clearNonDiscrAttributes() const
2988 MEDFileMesh::clearNonDiscrAttributes();
2989 const DataArrayInt *tmp=_fam_nodes;
2991 (const_cast<DataArrayInt *>(tmp))->setName("");
2994 (const_cast<DataArrayInt *>(tmp))->setName("");
2997 (const_cast<DataArrayInt *>(tmp))->setName("");
3000 (const_cast<DataArrayInt *>(tmp))->setName("");
3003 DataArrayInt *MEDFileStructuredMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
3005 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3006 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : Only available for levels 0 or 1 !");
3007 std::vector<int> famIds=getFamiliesIds(fams);
3008 if(meshDimRelToMaxExt==1)
3010 if((const DataArrayInt *)_fam_nodes)
3012 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
3014 da=_fam_nodes->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
3016 da=_fam_nodes->getIdsEqualList(0,0);
3018 return MEDFileUMeshSplitL1::Renumber(_num_nodes,da);
3023 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : no family array specified on nodes !");
3027 if((const DataArrayInt *)_fam_cells)
3029 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
3031 da=_fam_cells->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
3033 da=_fam_cells->getIdsEqualList(0,0);
3035 return MEDFileUMeshSplitL1::Renumber(_num_cells,da);
3040 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : no family array specified on cells !");
3044 void MEDFileStructuredMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
3046 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3047 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : Only available for levels 0 or 1 !");
3048 const MEDCouplingStructuredMesh *mesh=getStructuredMesh();
3050 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setFamilyFieldArr : no structured mesh specified ! Impossible to set family array !");
3051 if(meshDimRelToMaxExt==0)
3053 int nbCells=mesh->getNumberOfCells();
3054 famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !");
3059 int nbNodes=mesh->getNumberOfNodes();
3060 famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !");
3067 void MEDFileStructuredMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception)
3069 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3070 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : Only available for levels 0 or 1 !");
3071 const MEDCouplingStructuredMesh *mesh=getStructuredMesh();
3073 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : no structured mesh specified ! Impossible to set number array !");
3074 if(meshDimRelToMaxExt==0)
3076 int nbCells=mesh->getNumberOfCells();
3077 renumArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setRenumFieldArr : Problem in size of Renum arr ! Mismatch with number of cells of mesh !");
3078 _num_cells=renumArr;
3082 int nbNodes=mesh->getNumberOfNodes();
3083 renumArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setRenumFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !");
3084 _num_nodes=renumArr;
3087 renumArr->incrRef();
3090 void MEDFileStructuredMesh::setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr) throw(INTERP_KERNEL::Exception)
3092 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3093 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setNameFieldAtLevel : Only available for levels 0 or 1 !");
3094 const MEDCouplingStructuredMesh *mesh=getStructuredMesh();
3096 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setNameFieldAtLevel : no structured mesh specified ! Impossible to set names array !");
3097 if(meshDimRelToMaxExt==0)
3099 int nbCells=mesh->getNumberOfCells();
3100 nameArr->checkNbOfTuplesAndComp(nbCells,MED_SNAME_SIZE,"MEDFileStructuredMesh::setNameFieldAtLevel : Problem in size of names arr ! Mismatch with number of cells of mesh !");
3101 _names_cells=nameArr;
3105 int nbNodes=mesh->getNumberOfNodes();
3106 nameArr->checkNbOfTuplesAndComp(nbNodes,MED_SNAME_SIZE,"MEDFileStructuredMesh::setNameFieldAtLevel : Problem in size of names arr ! Mismatch with number of nodes of mesh !");
3107 _names_nodes=nameArr;
3113 const DataArrayInt *MEDFileStructuredMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
3115 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3116 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 !");
3117 if(meshDimRelToMaxExt==0)
3123 const DataArrayInt *MEDFileStructuredMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
3125 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3126 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 !");
3127 if(meshDimRelToMaxExt==0)
3133 const DataArrayInt *MEDFileStructuredMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
3135 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3136 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getRevNumberFieldAtLevel : Only available for levels 0 or 1 !");
3137 if(meshDimRelToMaxExt==0)
3139 if((const DataArrayInt *)_num_cells)
3142 int maxValue=_num_cells->getMaxValue(pos);
3143 _rev_num_cells=_num_cells->invertArrayN2O2O2N(maxValue+1);
3144 return _rev_num_cells;
3147 throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no cell renumbering for a request on reverse numbering !");
3151 if((const DataArrayInt *)_num_nodes)
3154 int maxValue=_num_nodes->getMaxValue(pos);
3155 _rev_num_nodes=_num_nodes->invertArrayN2O2O2N(maxValue+1);
3156 return _rev_num_nodes;
3159 throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !");
3163 const DataArrayAsciiChar *MEDFileStructuredMesh::getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
3165 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3166 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNameFieldAtLevel : Only available for levels 0 or 1 !");
3167 if(meshDimRelToMaxExt==0)
3168 return _names_cells;
3170 return _names_nodes;
3173 std::vector<int> MEDFileStructuredMesh::getNonEmptyLevels() const
3175 std::vector<int> ret(1);
3179 std::vector<int> MEDFileStructuredMesh::getNonEmptyLevelsExt() const
3181 std::vector<int> ret(2);
3187 * no implementation here, it is not a bug, but intresically no polyhedra in \a this.
3189 bool MEDFileStructuredMesh::unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception)
3191 oldCode.clear(); newCode.clear(); o2nRenumCell=0;
3195 void MEDFileStructuredMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception)
3197 DataArrayInt *arr=_fam_nodes;
3199 arr->changeValue(oldId,newId);
3202 arr->changeValue(oldId,newId);
3205 void MEDFileStructuredMesh::deepCpyAttributes() throw(INTERP_KERNEL::Exception)
3207 if((const DataArrayInt*)_fam_nodes)
3208 _fam_nodes=_fam_nodes->deepCpy();
3209 if((const DataArrayInt*)_num_nodes)
3210 _num_nodes=_num_nodes->deepCpy();
3211 if((const DataArrayInt*)_fam_cells)
3212 _fam_cells=_fam_cells->deepCpy();
3213 if((const DataArrayInt*)_num_cells)
3214 _num_cells=_num_cells->deepCpy();
3215 if((const DataArrayInt*)_rev_num_nodes)
3216 _rev_num_nodes=_rev_num_nodes->deepCpy();
3217 if((const DataArrayInt*)_rev_num_cells)
3218 _rev_num_cells=_rev_num_cells->deepCpy();
3222 * Returns a pointer to mesh at the specified level (here 0 is compulsary for cartesian mesh).
3224 * \return a pointer to cartesian mesh that need to be managed by the caller.
3225 * \warning the returned pointer has to be managed by the caller.
3227 MEDCouplingMesh *MEDFileStructuredMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception)
3230 throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support renumbering ! To do it perform request of renum array directly !");
3231 if(meshDimRelToMax!=0)
3232 throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support multi level for mesh 0 expected as input !");
3233 const MEDCouplingStructuredMesh *m=getStructuredMesh();
3236 return const_cast<MEDCouplingStructuredMesh *>(m);
3239 int MEDFileStructuredMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
3241 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
3242 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getSizeAtLevel : Only available for levels 0 or 1 !");
3243 const MEDCouplingStructuredMesh *cmesh=getStructuredMesh();
3245 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getSizeAtLevel : No structured mesh set !");
3246 if(meshDimRelToMaxExt==0)
3247 return cmesh->getNumberOfCells();
3249 return cmesh->getNumberOfNodes();
3252 int MEDFileStructuredMesh::getNumberOfNodes() const throw(INTERP_KERNEL::Exception)
3254 const MEDCouplingStructuredMesh *cmesh=getStructuredMesh();
3256 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberOfNodes : no cartesian mesh set !");
3257 return cmesh->getNumberOfNodes();
3260 med_geometry_type MEDFileStructuredMesh::GetGeoTypeFromMeshDim(int meshDim) throw(INTERP_KERNEL::Exception)
3262 med_geometry_type geoTypeReq=MED_NONE;
3266 geoTypeReq=MED_HEXA8;
3269 geoTypeReq=MED_QUAD4;
3272 geoTypeReq=MED_SEG2;
3275 geoTypeReq=MED_POINT1;
3278 throw INTERP_KERNEL::Exception("Invalid meshdim detected for structured mesh ! Must be in (1,2,3) !");
3283 void MEDFileStructuredMesh::loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
3285 setName(strm->getName());
3286 setDescription(strm->getDescription());
3287 setIteration(strm->getIteration());
3288 setOrder(strm->getOrder());
3289 setTimeValue(strm->getTime());
3290 setTimeUnit(strm->getTimeUnit());
3291 MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups);
3292 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
3293 int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
3296 _fam_nodes=DataArrayInt::New();
3297 _fam_nodes->alloc(nbOfElt,1);
3298 MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer());
3300 nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf);
3303 _num_nodes=DataArrayInt::New();
3304 _num_nodes->alloc(nbOfElt,1);
3305 MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer());
3307 int meshDim=getStructuredMesh()->getMeshDimension();
3308 med_geometry_type geoTypeReq=GetGeoTypeFromMeshDim(meshDim);
3309 nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
3312 _fam_cells=DataArrayInt::New();
3313 _fam_cells->alloc(nbOfElt,1);
3314 MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer());
3316 nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf);
3319 _num_cells=DataArrayInt::New();
3320 _num_cells->alloc(nbOfElt,1);
3321 MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer());
3323 nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NAME,MED_NODAL,&chgt,&trsf);
3326 _names_cells=DataArrayAsciiChar::New();
3327 _names_cells->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
3328 MEDmeshEntityNameRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_names_cells->getPointer());
3329 _names_cells->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end
3331 nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NAME,MED_NODAL,&chgt,&trsf);
3334 _names_nodes=DataArrayAsciiChar::New();
3335 _names_nodes->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
3336 MEDmeshEntityNameRd(fid,mName,dt,it,MED_NODE,MED_NONE,_names_nodes->getPointer());
3337 _names_nodes->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end
3341 void MEDFileStructuredMesh::writeStructuredLL(med_idt fid, const char *maa) const throw(INTERP_KERNEL::Exception)
3343 int meshDim=getStructuredMesh()->getMeshDimension();
3344 med_geometry_type geoTypeReq=GetGeoTypeFromMeshDim(meshDim);
3346 if((const DataArrayInt *)_fam_cells)
3347 MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer());
3348 if((const DataArrayInt *)_fam_nodes)
3349 MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_fam_nodes->getNumberOfTuples(),_fam_nodes->getConstPointer());
3350 if((const DataArrayInt *)_num_cells)
3351 MEDmeshEntityNumberWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_num_cells->getNumberOfTuples(),_num_cells->getConstPointer());
3352 if((const DataArrayInt *)_num_nodes)
3353 MEDmeshEntityNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_num_nodes->getNumberOfTuples(),_num_nodes->getConstPointer());
3354 if((const DataArrayAsciiChar *)_names_cells)
3356 if(_names_cells->getNumberOfComponents()!=MED_SNAME_SIZE)
3358 std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on cells with number of components set to " << MED_SNAME_SIZE;
3359 oss << " ! The array has " << _names_cells->getNumberOfComponents() << " components !";
3360 throw INTERP_KERNEL::Exception(oss.str().c_str());
3362 MEDmeshEntityNameWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_names_cells->getNumberOfTuples(),_names_cells->getConstPointer());
3364 if((const DataArrayAsciiChar *)_names_nodes)
3366 if(_names_nodes->getNumberOfComponents()!=MED_SNAME_SIZE)
3368 std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
3369 oss << " ! The array has " << _names_cells->getNumberOfComponents() << " components !";
3370 throw INTERP_KERNEL::Exception(oss.str().c_str());
3372 MEDmeshEntityNameWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_names_nodes->getNumberOfTuples(),_names_nodes->getConstPointer());
3375 MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
3378 MEDFileCMesh *MEDFileCMesh::New()
3380 return new MEDFileCMesh;
3383 MEDFileCMesh *MEDFileCMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
3385 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
3388 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
3389 throw INTERP_KERNEL::Exception(oss.str().c_str());
3391 MEDFileUtilities::CheckFileForRead(fileName);
3392 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3394 ParaMEDMEM::MEDCouplingMeshType meshType;
3396 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
3397 return new MEDFileCMesh(fid,ms.front().c_str(),dt,it);
3400 MEDFileCMesh *MEDFileCMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
3402 MEDFileUtilities::CheckFileForRead(fileName);
3403 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3404 return new MEDFileCMesh(fid,mName,dt,it);
3407 std::size_t MEDFileCMesh::getHeapMemorySize() const
3409 std::size_t ret=MEDFileStructuredMesh::getHeapMemorySize();
3410 if((const MEDCouplingCMesh *)_cmesh)
3411 ret+=_cmesh->getHeapMemorySize();
3415 int MEDFileCMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception)
3417 if(!((const MEDCouplingCMesh*)_cmesh))
3418 throw INTERP_KERNEL::Exception("MEDFileCMesh::getMeshDimension : unable to get meshdimension because no mesh set !");
3419 return _cmesh->getMeshDimension();
3422 std::string MEDFileCMesh::simpleRepr() const
3424 return MEDFileStructuredMesh::simpleRepr();
3427 std::string MEDFileCMesh::advancedRepr() const
3429 return simpleRepr();
3432 MEDFileMesh *MEDFileCMesh::shallowCpy() const throw(INTERP_KERNEL::Exception)
3434 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=new MEDFileCMesh(*this);
3438 MEDFileMesh *MEDFileCMesh::deepCpy() const throw(INTERP_KERNEL::Exception)
3440 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=new MEDFileCMesh(*this);
3441 if((const MEDCouplingCMesh*)_cmesh)
3442 ret->_cmesh=static_cast<MEDCouplingCMesh*>(_cmesh->deepCpy());
3443 ret->deepCpyAttributes();
3447 bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
3449 if(!MEDFileStructuredMesh::isEqual(other,eps,what))
3451 const MEDFileCMesh *otherC=dynamic_cast<const MEDFileCMesh *>(other);
3454 what="Mesh types differ ! This is cartesian and other is NOT !";
3457 clearNonDiscrAttributes();
3458 otherC->clearNonDiscrAttributes();
3459 const MEDCouplingCMesh *coo1=_cmesh;
3460 const MEDCouplingCMesh *coo2=otherC->_cmesh;
3461 if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
3463 what="Mismatch of cartesian meshes ! One is defined and not other !";
3468 bool ret=coo1->isEqual(coo2,eps);
3471 what="cartesian meshes differ !";
3478 void MEDFileCMesh::clearNonDiscrAttributes() const
3480 MEDFileStructuredMesh::clearNonDiscrAttributes();
3481 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_cmesh);//to it is not a bug umeshsplit have already the method implemented
3484 MEDFileCMesh::MEDFileCMesh()
3488 MEDFileCMesh::MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
3491 loadCMeshFromFile(fid,mName,dt,it);
3493 catch(INTERP_KERNEL::Exception& e)
3498 void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
3500 ParaMEDMEM::MEDCouplingMeshType meshType;
3503 int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
3504 if(meshType!=CARTESIAN)
3506 std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !";
3507 throw INTERP_KERNEL::Exception(oss.str().c_str());
3509 MEDFileCMeshL2 loaderl2;
3510 loaderl2.loadAll(fid,mid,mName,dt,it);
3511 MEDCouplingCMesh *mesh=loaderl2.getMesh();
3514 loadStrMeshFromFile(&loaderl2,fid,mName,dt,it);
3517 const MEDCouplingCMesh *MEDFileCMesh::getMesh() const
3519 synchronizeTinyInfoOnLeaves();
3523 const MEDCouplingStructuredMesh *MEDFileCMesh::getStructuredMesh() const
3525 synchronizeTinyInfoOnLeaves();
3529 void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception)
3531 dealWithTinyInfo(m);
3537 void MEDFileCMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
3539 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3540 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
3541 INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
3542 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
3543 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
3544 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str);
3545 int spaceDim=_cmesh->getSpaceDimension();
3546 int meshDim=_cmesh->getMeshDimension();
3547 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
3548 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
3549 for(int i=0;i<spaceDim;i++)
3551 std::string info(_cmesh->getCoordsAt(i)->getInfoOnComponent(0));
3553 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
3554 MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
3555 MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
3557 MEDmeshCr(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
3558 MEDmeshGridTypeWr(fid,maa,MED_CARTESIAN_GRID);
3559 for(int i=0;i<spaceDim;i++)
3561 const DataArrayDouble *da=_cmesh->getCoordsAt(i);
3562 MEDmeshGridIndexCoordinateWr(fid,maa,_iteration,_order,_time,i+1,da->getNumberOfTuples(),da->getConstPointer());
3565 MEDFileStructuredMesh::writeStructuredLL(fid,maa);
3568 void MEDFileCMesh::synchronizeTinyInfoOnLeaves() const
3570 const MEDCouplingCMesh *cmesh=_cmesh;
3573 (const_cast<MEDCouplingCMesh *>(cmesh))->setName(_name.c_str());
3574 (const_cast<MEDCouplingCMesh *>(cmesh))->setDescription(_desc_name.c_str());
3575 (const_cast<MEDCouplingCMesh *>(cmesh))->setTime(_time,_iteration,_order);
3576 (const_cast<MEDCouplingCMesh *>(cmesh))->setTimeUnit(_dt_unit.c_str());
3579 MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New()
3581 return new MEDFileCurveLinearMesh;
3584 MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
3586 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
3589 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
3590 throw INTERP_KERNEL::Exception(oss.str().c_str());
3592 MEDFileUtilities::CheckFileForRead(fileName);
3593 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3595 ParaMEDMEM::MEDCouplingMeshType meshType;
3597 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
3598 return new MEDFileCurveLinearMesh(fid,ms.front().c_str(),dt,it);
3601 MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
3603 MEDFileUtilities::CheckFileForRead(fileName);
3604 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3605 return new MEDFileCurveLinearMesh(fid,mName,dt,it);
3608 std::size_t MEDFileCurveLinearMesh::getHeapMemorySize() const
3610 std::size_t ret=MEDFileStructuredMesh::getHeapMemorySize();
3611 if((const MEDCouplingCurveLinearMesh *)_clmesh)
3612 ret+=_clmesh->getHeapMemorySize();
3616 MEDFileMesh *MEDFileCurveLinearMesh::shallowCpy() const throw(INTERP_KERNEL::Exception)
3618 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=new MEDFileCurveLinearMesh(*this);
3622 MEDFileMesh *MEDFileCurveLinearMesh::deepCpy() const throw(INTERP_KERNEL::Exception)
3624 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=new MEDFileCurveLinearMesh(*this);
3625 if((const MEDCouplingCurveLinearMesh*)_clmesh)
3626 ret->_clmesh=static_cast<MEDCouplingCurveLinearMesh*>(_clmesh->deepCpy());
3627 ret->deepCpyAttributes();
3631 int MEDFileCurveLinearMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception)
3633 if(!((const MEDCouplingCurveLinearMesh*)_clmesh))
3634 throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::getMeshDimension : unable to get meshdimension because no mesh set !");
3635 return _clmesh->getMeshDimension();
3638 std::string MEDFileCurveLinearMesh::simpleRepr() const
3640 return MEDFileStructuredMesh::simpleRepr();
3643 std::string MEDFileCurveLinearMesh::advancedRepr() const
3645 return simpleRepr();
3648 bool MEDFileCurveLinearMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
3650 if(!MEDFileStructuredMesh::isEqual(other,eps,what))
3652 const MEDFileCurveLinearMesh *otherC=dynamic_cast<const MEDFileCurveLinearMesh *>(other);
3655 what="Mesh types differ ! This is curve linear and other is NOT !";
3658 clearNonDiscrAttributes();
3659 otherC->clearNonDiscrAttributes();
3660 const MEDCouplingCurveLinearMesh *coo1=_clmesh;
3661 const MEDCouplingCurveLinearMesh *coo2=otherC->_clmesh;
3662 if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
3664 what="Mismatch of curve linear meshes ! One is defined and not other !";
3669 bool ret=coo1->isEqual(coo2,eps);
3672 what="curve linear meshes differ !";
3679 void MEDFileCurveLinearMesh::clearNonDiscrAttributes() const
3681 MEDFileStructuredMesh::clearNonDiscrAttributes();
3682 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_clmesh);//to it is not a bug umeshsplit have already the method implemented
3685 void MEDFileCurveLinearMesh::synchronizeTinyInfoOnLeaves() const
3687 const MEDCouplingCurveLinearMesh *clmesh=_clmesh;
3690 (const_cast<MEDCouplingCurveLinearMesh *>(clmesh))->setName(_name.c_str());
3691 (const_cast<MEDCouplingCurveLinearMesh *>(clmesh))->setDescription(_desc_name.c_str());
3692 (const_cast<MEDCouplingCurveLinearMesh *>(clmesh))->setTime(_time,_iteration,_order);
3693 (const_cast<MEDCouplingCurveLinearMesh *>(clmesh))->setTimeUnit(_dt_unit.c_str());
3696 const MEDCouplingCurveLinearMesh *MEDFileCurveLinearMesh::getMesh() const
3698 synchronizeTinyInfoOnLeaves();
3702 void MEDFileCurveLinearMesh::setMesh(MEDCouplingCurveLinearMesh *m) throw(INTERP_KERNEL::Exception)
3704 dealWithTinyInfo(m);
3710 const MEDCouplingStructuredMesh *MEDFileCurveLinearMesh::getStructuredMesh() const
3712 synchronizeTinyInfoOnLeaves();
3716 MEDFileCurveLinearMesh::MEDFileCurveLinearMesh()
3720 MEDFileCurveLinearMesh::MEDFileCurveLinearMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
3723 loadCLMeshFromFile(fid,mName,dt,it);
3725 catch(INTERP_KERNEL::Exception& e)
3730 void MEDFileCurveLinearMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
3732 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
3733 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
3734 INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
3735 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
3736 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
3737 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str);
3738 int spaceDim=_clmesh->getSpaceDimension();
3739 int meshDim=_clmesh->getMeshDimension();
3740 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
3741 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
3742 const DataArrayDouble *coords=_clmesh->getCoords();
3744 throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::writeLL : no coordinates set !");
3745 for(int i=0;i<spaceDim;i++)
3747 std::string info(_clmesh->getCoords()->getInfoOnComponent(i));
3749 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
3750 MEDLoaderBase::safeStrCpy2(c.c_str(),MED_SNAME_SIZE-1,comp+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
3751 MEDLoaderBase::safeStrCpy2(u.c_str(),MED_SNAME_SIZE-1,unit+i*MED_SNAME_SIZE,_too_long_str);//MED_TAILLE_PNOM-1 to avoid to write '\0' on next compo
3753 MEDmeshCr(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
3754 MEDmeshGridTypeWr(fid,maa,MED_CURVILINEAR_GRID);
3755 std::vector<int> nodeGridSt=_clmesh->getNodeGridStructure();
3756 MEDmeshGridStructWr(fid,maa,_iteration,_order,_time,&nodeGridSt[0]);
3758 MEDmeshNodeCoordinateWr(fid,maa,_iteration,_order,_time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->begin());
3760 MEDFileStructuredMesh::writeStructuredLL(fid,maa);
3763 void MEDFileCurveLinearMesh::loadCLMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
3765 ParaMEDMEM::MEDCouplingMeshType meshType;
3768 int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
3769 if(meshType!=CURVE_LINEAR)
3771 std::ostringstream oss; oss << "Trying to load as curve linear an existing mesh with name '" << mName << "' that is NOT curve linear !";
3772 throw INTERP_KERNEL::Exception(oss.str().c_str());
3774 MEDFileCLMeshL2 loaderl2;
3775 loaderl2.loadAll(fid,mid,mName,dt,it);
3776 MEDCouplingCurveLinearMesh *mesh=loaderl2.getMesh();
3779 loadStrMeshFromFile(&loaderl2,fid,mName,dt,it);
3782 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New()
3784 return new MEDFileMeshMultiTS;
3787 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
3789 return new MEDFileMeshMultiTS(fileName);
3792 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
3794 return new MEDFileMeshMultiTS(fileName,mName);
3797 MEDFileMeshMultiTS *MEDFileMeshMultiTS::deepCpy() const throw(INTERP_KERNEL::Exception)
3799 MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> ret=MEDFileMeshMultiTS::New();
3800 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> > meshOneTs(_mesh_one_ts.size());
3802 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++,i++)
3803 if((const MEDFileMesh *)*it)
3804 meshOneTs[i]=(*it)->deepCpy();
3805 ret->_mesh_one_ts=meshOneTs;
3809 std::size_t MEDFileMeshMultiTS::getHeapMemorySize() const
3811 std::size_t ret=_mesh_one_ts.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileMesh>);
3812 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
3813 ret+=(*it)->getHeapMemorySize();
3817 const char *MEDFileMeshMultiTS::getName() const throw(INTERP_KERNEL::Exception)
3819 if(_mesh_one_ts.empty())
3820 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getName : no time steps set !");
3821 return _mesh_one_ts[0]->getName();
3824 void MEDFileMeshMultiTS::setName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
3826 std::string oldName(getName());
3827 std::vector< std::pair<std::string,std::string> > v(1);
3828 v[0].first=oldName; v[0].second=newMeshName;
3832 bool MEDFileMeshMultiTS::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3835 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
3837 MEDFileMesh *cur(*it);
3839 ret=cur->changeNames(modifTab) || ret;
3844 MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const throw(INTERP_KERNEL::Exception)
3846 if(_mesh_one_ts.empty())
3847 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getOneTimeStep : empty time step set !");
3848 return const_cast<MEDFileMesh *>(static_cast<const MEDFileMesh *>(_mesh_one_ts[0]));
3851 void MEDFileMeshMultiTS::setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception)
3854 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::setOneTimeStep : input pointer should be different from 0 !");
3855 _mesh_one_ts.resize(1);
3856 mesh1TimeStep->incrRef();
3857 //MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> toto=mesh1TimeStep;
3858 _mesh_one_ts[0]=mesh1TimeStep;
3861 void MEDFileMeshMultiTS::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
3863 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
3865 (*it)->copyOptionsFrom(*this);
3870 void MEDFileMeshMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
3872 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
3873 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
3874 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
3875 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
3879 void MEDFileMeshMultiTS::loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
3880 {//for the moment to be improved
3881 _mesh_one_ts.resize(1);
3882 _mesh_one_ts[0]=MEDFileMesh::New(fileName,mName,-1,-1);
3885 MEDFileMeshMultiTS::MEDFileMeshMultiTS()
3889 MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
3892 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
3895 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
3896 throw INTERP_KERNEL::Exception(oss.str().c_str());
3898 MEDFileUtilities::CheckFileForRead(fileName);
3899 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3901 ParaMEDMEM::MEDCouplingMeshType meshType;
3903 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
3904 loadFromFile(fileName,ms.front().c_str());
3906 catch(INTERP_KERNEL::Exception& e)
3911 MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
3914 loadFromFile(fileName,mName);
3916 catch(INTERP_KERNEL::Exception& e)
3921 MEDFileMeshes *MEDFileMeshes::New()
3923 return new MEDFileMeshes;
3926 MEDFileMeshes *MEDFileMeshes::New(const char *fileName) throw(INTERP_KERNEL::Exception)
3928 return new MEDFileMeshes(fileName);
3931 void MEDFileMeshes::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
3934 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
3936 (*it)->copyOptionsFrom(*this);
3941 void MEDFileMeshes::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
3943 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
3944 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
3945 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
3946 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
3951 int MEDFileMeshes::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
3953 return _meshes.size();
3956 MEDFileMeshesIterator *MEDFileMeshes::iterator() throw(INTERP_KERNEL::Exception)
3958 return new MEDFileMeshesIterator(this);
3961 MEDFileMesh *MEDFileMeshes::getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception)
3963 if(i<0 || i>=(int)_meshes.size())
3965 std::ostringstream oss; oss << "MEDFileMeshes::getMeshAtPos : invalid mesh id given in parameter ! Should be in [0;" << _meshes.size() << ") !";
3966 throw INTERP_KERNEL::Exception(oss.str().c_str());
3968 return _meshes[i]->getOneTimeStep();
3971 MEDFileMesh *MEDFileMeshes::getMeshWithName(const char *mname) const throw(INTERP_KERNEL::Exception)
3973 std::vector<std::string> ms=getMeshesNames();
3974 std::vector<std::string>::iterator it=std::find(ms.begin(),ms.end(),mname);
3977 std::ostringstream oss; oss << "MEDFileMeshes::getMeshWithName : Mesh \"" << mname << "\" does not exist in this ! Existing are : ";
3978 std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss," "));
3979 throw INTERP_KERNEL::Exception(oss.str().c_str());
3981 return getMeshAtPos((int)std::distance(ms.begin(),it));
3984 std::vector<std::string> MEDFileMeshes::getMeshesNames() const throw(INTERP_KERNEL::Exception)
3986 std::vector<std::string> ret(_meshes.size());
3988 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
3990 const MEDFileMeshMultiTS *f=(*it);
3993 ret[i]=f->getName();
3997 std::ostringstream oss; oss << "MEDFileMeshes::getMeshesNames : At rank #" << i << " mesh is not defined !";
3998 throw INTERP_KERNEL::Exception(oss.str().c_str());
4004 bool MEDFileMeshes::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
4007 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::iterator it=_meshes.begin();it!=_meshes.end();it++)
4009 MEDFileMeshMultiTS *cur(*it);
4011 ret=cur->changeNames(modifTab) || ret;
4016 void MEDFileMeshes::resize(int newSize) throw(INTERP_KERNEL::Exception)
4018 _meshes.resize(newSize);
4021 void MEDFileMeshes::pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
4024 throw INTERP_KERNEL::Exception("MEDFileMeshes::pushMesh : invalid input pointer ! should be different from 0 !");
4025 MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
4026 elt->setOneTimeStep(mesh);
4027 _meshes.push_back(elt);
4030 void MEDFileMeshes::setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
4033 throw INTERP_KERNEL::Exception("MEDFileMeshes::setMeshAtPos : invalid input pointer ! should be different from 0 !");
4034 if(i>=(int)_meshes.size())
4035 _meshes.resize(i+1);
4036 MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
4037 elt->setOneTimeStep(mesh);
4041 void MEDFileMeshes::destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception)
4043 if(i<0 || i>=(int)_meshes.size())
4045 std::ostringstream oss; oss << "MEDFileMeshes::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _meshes.size() << ") !";
4046 throw INTERP_KERNEL::Exception(oss.str().c_str());
4048 _meshes.erase(_meshes.begin()+i);
4051 void MEDFileMeshes::loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception)
4053 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
4055 _meshes.resize(ms.size());
4056 for(std::vector<std::string>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
4057 _meshes[i]=MEDFileMeshMultiTS::New(fileName,(*it).c_str());
4060 MEDFileMeshes::MEDFileMeshes()
4064 MEDFileMeshes::MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception)
4067 loadFromFile(fileName);
4069 catch(INTERP_KERNEL::Exception& e)
4073 MEDFileMeshes *MEDFileMeshes::deepCpy() const throw(INTERP_KERNEL::Exception)
4075 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> > meshes(_meshes.size());
4077 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
4078 if((const MEDFileMeshMultiTS *)*it)
4079 meshes[i]=(*it)->deepCpy();
4080 MEDCouplingAutoRefCountObjectPtr<MEDFileMeshes> ret=MEDFileMeshes::New();
4081 ret->_meshes=meshes;
4085 std::size_t MEDFileMeshes::getHeapMemorySize() const
4087 std::size_t ret=_meshes.capacity()*(sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS>));
4088 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
4089 if((const MEDFileMeshMultiTS*)*it)
4090 ret+=(*it)->getHeapMemorySize();
4094 std::string MEDFileMeshes::simpleRepr() const
4096 std::ostringstream oss;
4097 oss << "(*****************)\n(* MEDFileMeshes *)\n(*****************)\n\n";
4098 simpleReprWithoutHeader(oss);
4102 void MEDFileMeshes::simpleReprWithoutHeader(std::ostream& oss) const
4104 int nbOfMeshes=getNumberOfMeshes();
4105 oss << "There are " << nbOfMeshes << " meshes with the following names : \n";
4106 std::vector<std::string> mns=getMeshesNames();
4107 for(int i=0;i<nbOfMeshes;i++)
4108 oss << " - #" << i << " \"" << mns[i] << "\"\n";
4111 void MEDFileMeshes::checkCoherency() const throw(INTERP_KERNEL::Exception)
4113 static const char MSG[]="MEDFileMeshes::checkCoherency : mesh at rank ";
4115 std::set<std::string> s;
4116 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
4118 const MEDFileMeshMultiTS *elt=(*it);
4121 std::ostringstream oss; oss << MSG << i << "/" << _meshes.size() << " is empty !";
4122 throw INTERP_KERNEL::Exception(oss.str().c_str());
4124 std::size_t sz=s.size();
4125 s.insert(std::string((*it)->getName()));
4128 std::ostringstream oss; oss << MSG << i << " has a name (\"" << (*it)->getName() << "\") already used by an another mesh in list !";
4129 throw INTERP_KERNEL::Exception(oss.str().c_str());
4134 MEDFileMeshesIterator::MEDFileMeshesIterator(MEDFileMeshes *ms):_ms(ms),_iter_id(0),_nb_iter(0)
4139 _nb_iter=ms->getNumberOfMeshes();
4143 MEDFileMeshesIterator::~MEDFileMeshesIterator()
4147 MEDFileMesh *MEDFileMeshesIterator::nextt()
4149 if(_iter_id<_nb_iter)
4151 MEDFileMeshes *ms(_ms);
4153 return ms->getMeshAtPos(_iter_id++);