1 // Copyright (C) 2007-2012 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
20 #include "MEDFileMesh.hxx"
21 #include "MEDFileUtilities.hxx"
22 #include "MEDLoader.hxx"
23 #include "MEDLoaderBase.hxx"
25 #include "MEDCouplingUMesh.hxx"
27 #include "InterpKernelAutoPtr.hxx"
32 using namespace ParaMEDMEM;
34 const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO";
36 MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.)
40 MEDFileMesh *MEDFileMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
42 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
45 std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << fileName << "\" !";
46 throw INTERP_KERNEL::Exception(oss.str().c_str());
48 MEDFileUtilities::CheckFileForRead(fileName);
49 ParaMEDMEM::MEDCouplingMeshType meshType;
50 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
53 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
58 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
59 ret->loadUMeshFromFile(fid,ms.front().c_str(),dt,it);
61 return (MEDFileUMesh *)ret;
65 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
66 ret->loadCMeshFromFile(fid,ms.front().c_str(),dt,it);
68 return (MEDFileCMesh *)ret;
72 std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << ms.front() << "' exists but unsupported type yet !";
73 throw INTERP_KERNEL::Exception(oss.str().c_str());
78 MEDFileMesh *MEDFileMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
80 MEDFileUtilities::CheckFileForRead(fileName);
81 ParaMEDMEM::MEDCouplingMeshType meshType;
82 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
85 MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
90 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
91 ret->loadUMeshFromFile(fid,mName,dt,it);
93 return (MEDFileUMesh *)ret;
97 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
98 ret->loadCMeshFromFile(fid,mName,dt,it);
100 return (MEDFileCMesh *)ret;
104 std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << mName << "' exists but unsupported type yet !";
105 throw INTERP_KERNEL::Exception(oss.str().c_str());
110 void MEDFileMesh::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
113 const_cast<MEDFileMesh *>(this)->addFamily(DFT_FAM_NAME,0);
115 throw INTERP_KERNEL::Exception("MEDFileMesh : name is empty. MED file ask for a NON EMPTY name !");
119 void MEDFileMesh::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
121 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
122 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
123 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
124 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
128 bool MEDFileMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
130 if(_order!=other->_order)
132 what="Orders differ !";
135 if(_iteration!=other->_iteration)
137 what="Iterations differ !";
140 if(fabs(_time-other->_time)>eps)
142 what="Time values differ !";
145 if(_dt_unit!=other->_dt_unit)
147 what="Time units differ !";
150 if(_name!=other->_name)
152 what="Names differ !";
155 if(_univ_name!=other->_univ_name)
157 what="Univ names differ !";
160 if(_desc_name!=other->_desc_name)
162 what="Description names differ !";
165 if(!areGrpsEqual(other,what))
167 if(!areFamsEqual(other,what))
172 void MEDFileMesh::clearNonDiscrAttributes() const
177 bool MEDFileMesh::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
179 for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
181 if((*it).first==_name)
190 void MEDFileMesh::copyFamGrpMapsFrom(const MEDFileMesh& other)
192 _groups=other._groups;
193 _families=other._families;
196 std::vector<std::string> MEDFileMesh::getFamiliesOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
198 std::string oname(name);
199 std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
200 std::vector<std::string> grps=getGroupsNames();
201 if(it==_groups.end())
203 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
204 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
205 throw INTERP_KERNEL::Exception(oss.str().c_str());
210 std::vector<std::string> MEDFileMesh::getFamiliesOnGroups(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
212 std::set<std::string> fams;
213 for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
215 std::map<std::string, std::vector<std::string> >::const_iterator it2=_groups.find(*it);
216 if(it2==_groups.end())
218 std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it;
219 std::vector<std::string> grps=getGroupsNames(); oss << "\" !\nAvailable groups are :";
220 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
221 throw INTERP_KERNEL::Exception(oss.str().c_str());
223 fams.insert((*it2).second.begin(),(*it2).second.end());
225 std::vector<std::string> fams2(fams.begin(),fams.end());
229 std::vector<int> MEDFileMesh::getFamiliesIdsOnGroup(const char *name) const throw(INTERP_KERNEL::Exception)
231 std::string oname(name);
232 std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
233 std::vector<std::string> grps=getGroupsNames();
234 if(it==_groups.end())
236 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
237 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
238 throw INTERP_KERNEL::Exception(oss.str().c_str());
240 return getFamiliesIds((*it).second);
244 * This method sets families at a corresponding groups existing or not. If it existed, it is replaced by new 'fams'.
245 * Each entry in 'fams' is checked if it is not still existing default id 0 is set.
247 void MEDFileMesh::setFamiliesOnGroup(const char *name, const std::vector<std::string>& fams) throw(INTERP_KERNEL::Exception)
249 std::string oname(name);
251 for(std::vector<std::string>::const_iterator it1=fams.begin();it1!=fams.end();it1++)
253 std::map<std::string,int>::iterator it2=_families.find(*it1);
254 if(it2==_families.end())
260 * Behaves as MEDFileMesh::setFamiliesOnGroup, except that if there is presence of a family id in 'famIds' not existing an exception is thrown.
261 * If several families have same id the first one in lexical order is taken into account.
263 void MEDFileMesh::setFamiliesIdsOnGroup(const char *name, const std::vector<int>& famIds) throw(INTERP_KERNEL::Exception)
265 std::string oname(name);
266 std::vector<std::string> fams(famIds.size());
268 for(std::vector<int>::const_iterator it1=famIds.begin();it1!=famIds.end();it1++,i++)
270 std::string name2=getFamilyNameGivenId(*it1);
276 std::vector<std::string> MEDFileMesh::getGroupsOnFamily(const char *name) const throw(INTERP_KERNEL::Exception)
278 std::vector<std::string> ret;
279 for(std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();it1!=_groups.end();it1++)
281 for(std::vector<std::string>::const_iterator it2=(*it1).second.begin();it2!=(*it1).second.end();it2++)
284 ret.push_back((*it1).first);
292 * This method expects that family 'famName' is already existing. If not an exception will be thrown.
294 void MEDFileMesh::setGroupsOnFamily(const char *famName, const std::vector<std::string>& grps) throw(INTERP_KERNEL::Exception)
296 std::string fName(famName);
297 const std::map<std::string,int>::const_iterator it=_families.find(fName);
298 if(it==_families.end())
300 std::vector<std::string> fams=getFamiliesNames();
301 std::ostringstream oss; oss << "No such familyname \"" << fName << "\" !\nAvailable families are :";
302 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
303 throw INTERP_KERNEL::Exception(oss.str().c_str());
305 for(std::vector<std::string>::const_iterator it3=grps.begin();it3!=grps.end();it3++)
307 std::map< std::string, std::vector<std::string> >::iterator it2=_groups.find(*it3);
308 if(it2!=_groups.end())
309 (*it2).second.push_back(fName);
312 std::vector<std::string> grps2(1,fName);
318 std::vector<std::string> MEDFileMesh::getGroupsNames() const
320 std::vector<std::string> ret(_groups.size());
322 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++,i++)
327 std::vector<std::string> MEDFileMesh::getFamiliesNames() const
329 std::vector<std::string> ret(_families.size());
331 for(std::map<std::string, int >::const_iterator it=_families.begin();it!=_families.end();it++,i++)
337 * This method scans every families and for each families shared by only one group, the corresponding family takes the same name than the group.
339 void MEDFileMesh::assignFamilyNameWithGroupName() throw(INTERP_KERNEL::Exception)
341 std::map<std::string, std::vector<std::string> > groups(_groups);
342 std::map<std::string,int> newFams;
343 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
345 std::vector<std::string> grps=getGroupsOnFamily((*it).first.c_str());
346 if(grps.size()==1 && groups[grps[0]].size()==1)
348 if(newFams.find(grps[0])!=newFams.end())
350 std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << grps[0] << "\" already exists !";
351 throw INTERP_KERNEL::Exception(oss.str().c_str());
353 newFams[grps[0]]=(*it).second;
354 std::vector<std::string>& grps2=groups[grps[0]];
355 std::size_t pos=std::distance(grps2.begin(),std::find(grps2.begin(),grps2.end(),(*it).first));
360 if(newFams.find((*it).first)!=newFams.end())
362 std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << (*it).first << "\" already exists !";
363 throw INTERP_KERNEL::Exception(oss.str().c_str());
365 newFams[(*it).first]=(*it).second;
372 void MEDFileMesh::removeGroup(const char *name) throw(INTERP_KERNEL::Exception)
374 std::string oname(name);
375 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
376 std::vector<std::string> grps=getGroupsNames();
377 if(it==_groups.end())
379 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
380 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
381 throw INTERP_KERNEL::Exception(oss.str().c_str());
386 void MEDFileMesh::removeFamily(const char *name) throw(INTERP_KERNEL::Exception)
388 std::string oname(name);
389 std::map<std::string, int >::iterator it=_families.find(oname);
390 std::vector<std::string> fams=getFamiliesNames();
391 if(it==_families.end())
393 std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
394 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
395 throw INTERP_KERNEL::Exception(oss.str().c_str());
398 for(std::map<std::string, std::vector<std::string> >::iterator it3=_groups.begin();it3!=_groups.end();it3++)
400 std::vector<std::string>& v=(*it3).second;
401 std::vector<std::string>::iterator it4=std::find(v.begin(),v.end(),oname);
407 void MEDFileMesh::changeGroupName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
409 std::string oname(oldName);
410 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
411 std::vector<std::string> grps=getGroupsNames();
412 if(it==_groups.end())
414 std::ostringstream oss; oss << "No such groupname \"" << oldName << "\" !\nAvailable groups are :";
415 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
416 throw INTERP_KERNEL::Exception(oss.str().c_str());
418 std::string nname(newName);
419 it=_groups.find(nname);
420 if(it!=_groups.end())
422 std::ostringstream oss; oss << "Such groupname \"" << newName << "\" already exists ! Kill it before !";
423 throw INTERP_KERNEL::Exception(oss.str().c_str());
425 std::vector<std::string> cpy=(*it).second;
427 _groups[newName]=cpy;
431 * This method changes the family ids in 'this'. It leads to a modification into '_families' attributes \b and in
432 * ids stored in arrays. This method calls MEDFileMesh::changeFamilyIdArr method.
434 void MEDFileMesh::changeFamilyId(int oldId, int newId) throw(INTERP_KERNEL::Exception)
436 changeFamilyIdArr(oldId,newId);
437 std::map<std::string,int> fam2;
438 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
440 if((*it).second==oldId)
441 fam2[(*it).first]=newId;
443 fam2[(*it).first]=(*it).second;
448 void MEDFileMesh::changeFamilyName(const char *oldName, const char *newName) throw(INTERP_KERNEL::Exception)
450 std::string oname(oldName);
451 std::map<std::string, int >::iterator it=_families.find(oname);
452 std::vector<std::string> fams=getFamiliesNames();
453 if(it==_families.end())
455 std::ostringstream oss; oss << "No such familyname \"" << oldName << "\" !\nAvailable families are :";
456 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
457 throw INTERP_KERNEL::Exception(oss.str().c_str());
459 std::string nname(newName);
460 std::map<std::string, int >::iterator it2=_families.find(nname);
461 if(it2!=_families.end())
463 std::ostringstream oss; oss << "Such familyname \"" << newName << " already exists ! Kill it before !";
464 throw INTERP_KERNEL::Exception(oss.str().c_str());
466 int cpy=(*it).second;
468 _families[newName]=cpy;
469 for(std::map<std::string, std::vector<std::string> >::iterator it3=_groups.begin();it3!=_groups.end();it3++)
471 std::vector<std::string>& v=(*it3).second;
472 std::vector<std::string>::iterator it4=std::find(v.begin(),v.end(),oname);
478 bool MEDFileMesh::areFamsEqual(const MEDFileMesh *other, std::string& what) const
480 if(_families==other->_families)
482 std::map<std::string,int> fam0;
483 std::map<std::string,int> fam1;
484 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
486 fam0[(*it).first]=(*it).second;
487 for(std::map<std::string,int>::const_iterator it=other->_families.begin();it!=other->_families.end();it++)
489 fam1[(*it).first]=(*it).second;
493 bool MEDFileMesh::areGrpsEqual(const MEDFileMesh *other, std::string& what) const
495 if(_groups==other->_groups)
498 std::size_t sz=_groups.size();
499 if(sz!=other->_groups.size())
501 what="Groups differ because not same number !\n";
506 std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();
507 for(std::size_t i=0;i<sz && ret;i++,it1++)
509 std::map<std::string, std::vector<std::string> >::const_iterator it2=other->_groups.find((*it1).first);
510 if(it2!=other->_groups.end())
512 std::set<std::string> s1((*it1).second.begin(),(*it1).second.end());
513 std::set<std::string> s2((*it2).second.begin(),(*it2).second.end());
519 what="A group in first mesh exists not in other !\n";
525 std::ostringstream oss; oss << "Groups description differs :\n";
526 oss << "First group description :\n";
527 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
529 oss << " Group \"" << (*it).first << "\" on following families :\n";
530 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
531 oss << " \"" << *it2 << "\n";
533 oss << "Second group description :\n";
534 for(std::map<std::string, std::vector<std::string> >::const_iterator it=other->_groups.begin();it!=other->_groups.end();it++)
536 oss << " Group \"" << (*it).first << "\" on following families :\n";
537 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
538 oss << " \"" << *it2 << "\n";
545 bool MEDFileMesh::existsGroup(const char *groupName) const
547 std::string grpName(groupName);
548 return _groups.find(grpName)!=_groups.end();
551 bool MEDFileMesh::existsFamily(int famId) const
553 for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
554 if((*it2).second==famId)
559 bool MEDFileMesh::existsFamily(const char *familyName) const
561 std::string fname(familyName);
562 return _families.find(fname)!=_families.end();
565 void MEDFileMesh::setFamilyId(const char *familyName, int id)
567 std::string fname(familyName);
571 void MEDFileMesh::setFamilyIdUnique(const char *familyName, int id) throw(INTERP_KERNEL::Exception)
573 std::string fname(familyName);
574 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
577 if((*it).first!=familyName)
579 std::ostringstream oss; oss << "MEDFileMesh::setFamilyIdUnique : Family id #" << id << " is already belonging to family with name \"" << (*it).first << "\" !";
580 throw INTERP_KERNEL::Exception(oss.str().c_str());
587 * This method appends a new entry in _families attribute. An exception is thrown if either the famId is already
588 * kept by an another familyName. An exception is thrown if name 'familyName' is alreadyset with a different 'famId'.
590 void MEDFileMesh::addFamily(const char *familyName, int famId) throw(INTERP_KERNEL::Exception)
592 std::string fname(familyName);
593 std::map<std::string,int>::const_iterator it=_families.find(fname);
594 if(it==_families.end())
596 for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
597 if((*it2).second==famId)
599 std::ostringstream oss;
600 oss << "MEDFileMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !";
601 throw INTERP_KERNEL::Exception(oss.str().c_str());
603 _families[fname]=famId;
607 if((*it).second!=famId)
609 std::ostringstream oss;
610 oss << "MEDFileMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !";
611 throw INTERP_KERNEL::Exception(oss.str().c_str());
617 * 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.
618 * If the 'meshDimRelToMaxExt' is not existing an INTERP_KERNEL::Exception will be thrown too.
619 * \b WARNING : This method does \b not garantee that 'groupName' lies only on a single level specified by 'meshDimRelToMaxExt'.
620 * in the case of a presence of one or more family id in family field at 'meshDimRelToMaxExt' level that appears in another level.
621 * If there is a risk of such case call MEDFileMesh::keepFamIdsOnlyOnLevs method \b before calling this method.
622 * (call to MEDFileMesh::keepFamIdsOnlyOnLevs should be done with MEDFileMesh::getFamiliesIdsOnGroup('groupName' as first input ).
624 void MEDFileMesh::createGroupOnAll(int meshDimRelToMaxExt, const char *groupName) throw(INTERP_KERNEL::Exception)
626 std::string grpName(groupName);
627 std::vector<int> levs=getNonEmptyLevelsExt();
628 if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)==levs.end())
630 std::ostringstream oss; oss << "MEDFileMesh::createGroupOnAll : The relative ext dimension " << meshDimRelToMaxExt << " is not available !" << std::endl;
631 oss << "Available relative ext levels are : ";
632 std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," "));
633 throw INTERP_KERNEL::Exception(oss.str().c_str());
635 if(existsGroup(groupName))
637 std::ostringstream oss; oss << "MEDFileMesh::createGroupOnAll : The groups \"" << grpName << "\" already exists in this !" << std::endl;
638 oss << "Already existing groups are : ";
639 std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," "));
640 oss << std::endl << "Please choose an another group name or call removeGroup(\"" << grpName << "\") method !";
641 throw INTERP_KERNEL::Exception(oss.str().c_str());
643 const DataArrayInt *fieldFamIds=getFamilyFieldAtLevel(meshDimRelToMaxExt);
645 throw INTERP_KERNEL::Exception("MEDFileMesh::createGroupOnAll : Family field arr ids is not defined for this level !");
646 std::set<int> famIds=fieldFamIds->getDifferentValues();
647 std::vector<std::string> familiesOnWholeGroup;
648 for(std::set<int>::const_iterator it=famIds.begin();it!=famIds.end();it++)
651 familiesOnWholeGroup.push_back(findOrCreateAndGiveFamilyWithId(*it,tmp));
653 _groups[grpName]=familiesOnWholeGroup;
657 * This method checks that family Ids in 'famIds' are not present in levels \b not in 'vMeshDimRelToMaxExt'.
658 * If it is the case true is returned and 'this' is not modified.
659 * If there is some levels not in 'vMeshDimRelToMaxExt' where one or more family ids in 'famIds' appear
660 * new families are created and groups are updated in consequence.
662 bool MEDFileMesh::keepFamIdsOnlyOnLevs(const std::vector<int>& famIds, const std::vector<int>& vMeshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
664 std::set<int> levsInput(vMeshDimRelToMaxExt.begin(),vMeshDimRelToMaxExt.end());
665 std::vector<int> levs=getNonEmptyLevelsExt();
666 std::set<int> levs2(levs.begin(),levs.end());
667 std::vector<int> levsToTest;
668 std::set_difference(levs2.begin(),levs2.end(),levsInput.begin(),levsInput.end(),std::back_insert_iterator< std::vector<int> >(levsToTest));
669 std::set<int> famIds2(famIds.begin(),famIds.end());
672 if(!_families.empty())
673 maxFamId=getMaxFamilyId()+1;
674 std::vector<std::string> allFams=getFamiliesNames();
675 for(std::vector<int>::const_iterator it=levsToTest.begin();it!=levsToTest.end();it++)
677 const DataArrayInt *fieldFamIds=getFamilyFieldAtLevel(*it);
680 std::set<int> famIds3=fieldFamIds->getDifferentValues();
681 std::vector<int> tmp;
682 std::set_intersection(famIds3.begin(),famIds3.end(),famIds2.begin(),famIds2.end(),std::back_insert_iterator< std::vector<int> >(tmp));
683 for(std::vector<int>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
686 std::string famName=getFamilyNameGivenId(*it2);
687 std::ostringstream oss; oss << "Family_" << maxFamId;
688 std::string zeName=CreateNameNotIn(oss.str(),allFams);
689 addFamilyOnAllGroupsHaving(famName.c_str(),zeName.c_str());
690 _families[zeName]=maxFamId;
691 (const_cast<DataArrayInt *>(fieldFamIds))->changeValue(*it2,maxFamId);
700 * This method add into the family list of a group 'grpName' the family with name 'famName'.
701 * If the group 'grpName' does not exist it is created and 'famName' is added to the list.
702 * If the group 'grpName' already exists, 'famName' will be added into family list of the existing group.
703 * This method throws an INTERP_KERNEL::Exception if 'famName' does not exit.
705 void MEDFileMesh::addFamilyOnGrp(const char *grpName, const char *famName) throw(INTERP_KERNEL::Exception)
707 std::string grpn(grpName);
708 std::string famn(famName);
709 if(grpn.empty() || famn.empty())
710 throw INTERP_KERNEL::Exception("MEDFileMesh::addFamilyOnGrp : input strings must be non null !");
711 std::vector<std::string> fams=getFamiliesNames();
712 if(std::find(fams.begin(),fams.end(),famn)==fams.end())
714 std::ostringstream oss; oss << "MEDFileMesh::addFamilyOnGrp : Family \"" << famn << "\" does not exist !" << std::endl;
715 oss << "Create this family or choose an existing one ! Existing fams are : ";
716 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," ")); oss << ".";
717 throw INTERP_KERNEL::Exception(oss.str().c_str());
719 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(grpn);
720 if(it==_groups.end())
722 _groups[grpn].push_back(famn);
726 std::vector<std::string>::iterator it2=std::find((*it).second.begin(),(*it).second.end(),famn);
727 if(it2==(*it).second.end())
728 (*it).second.push_back(famn);
733 * This method adds to all groups lying on family with name 'famName' the other family name 'otherFamName'.
734 * This method is quite underground because it can lead to unconsistency because family 'otherFamName' is \b not added into _families.
735 * This method is used by MEDFileMesh::keepFamIdsOnlyOnLevs method.
737 void MEDFileMesh::addFamilyOnAllGroupsHaving(const char *famName, const char *otherFamName) throw(INTERP_KERNEL::Exception)
739 std::string famNameCpp(famName);
740 std::string otherCpp(otherFamName);
741 for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
743 std::vector<std::string>& v=(*it).second;
744 if(std::find(v.begin(),v.end(),famNameCpp)!=v.end())
746 v.push_back(otherCpp);
752 * If it exists a family whose family id is equal to 'id' this method behaves as MEDFileMesh::getFamilyNameGivenId.
753 * In this case, 'this' internal states remains unchanged and 'created' out parameter will be set to false.
754 * If there is no family whose family id is equal to 'id' a family is created with a name different from those
755 * already existing. In this case 'created' will be returned with a value set to true, and internal state
757 * This method will throws an exception if it is not possible to create a unique family name.
759 std::string MEDFileMesh::findOrCreateAndGiveFamilyWithId(int id, bool& created) throw(INTERP_KERNEL::Exception)
761 std::vector<std::string> famAlreadyExisting(_families.size());
763 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++,ii++)
767 famAlreadyExisting[ii]=(*it).first;
776 std::ostringstream oss; oss << "Family_" << id;
777 std::string ret=CreateNameNotIn(oss.str(),famAlreadyExisting);
782 void MEDFileMesh::setFamilyInfo(const std::map<std::string,int>& info)
787 void MEDFileMesh::setGroupInfo(const std::map<std::string, std::vector<std::string> >&info)
792 int MEDFileMesh::getFamilyId(const char *name) const throw(INTERP_KERNEL::Exception)
794 std::string oname(name);
795 std::map<std::string, int>::const_iterator it=_families.find(oname);
796 std::vector<std::string> fams=getFamiliesNames();
797 if(it==_families.end())
799 std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
800 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
801 throw INTERP_KERNEL::Exception(oss.str().c_str());
806 std::vector<int> MEDFileMesh::getFamiliesIds(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
808 std::vector<int> ret(fams.size());
810 for(std::vector<std::string>::const_iterator it=fams.begin();it!=fams.end();it++,i++)
812 std::map<std::string, int>::const_iterator it2=_families.find(*it);
813 if(it2==_families.end())
815 std::vector<std::string> fams2=getFamiliesNames();
816 std::ostringstream oss; oss << "No such familyname \"" << *it << "\" in input list !\nAvailable families are :";
817 std::copy(fams2.begin(),fams2.end(),std::ostream_iterator<std::string>(oss," "));
818 throw INTERP_KERNEL::Exception(oss.str().c_str());
820 ret[i]=(*it2).second;
825 int MEDFileMesh::getMaxFamilyId() const throw(INTERP_KERNEL::Exception)
827 if(_families.empty())
828 throw INTERP_KERNEL::Exception("MEDFileUMesh::getMaxFamilyId : no families set !");
829 int ret=-std::numeric_limits<int>::max();
830 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
832 ret=std::max((*it).second,ret);
837 int MEDFileMesh::getMinFamilyId() const throw(INTERP_KERNEL::Exception)
839 if(_families.empty())
840 throw INTERP_KERNEL::Exception("MEDFileUMesh::getMinFamilyId : no families set !");
841 int ret=std::numeric_limits<int>::max();
842 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
844 ret=std::min((*it).second,ret);
849 DataArrayInt *MEDFileMesh::getAllFamiliesIdsReferenced() const throw(INTERP_KERNEL::Exception)
851 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
853 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
854 v.insert((*it).second);
855 ret->alloc((int)v.size(),1);
856 std::copy(v.begin(),v.end(),ret->getPointer());
857 ret->incrRef(); return ret;
861 * true is returned if no modification has been needed. false if family
862 * renumbering has been needed.
864 bool MEDFileMesh::ensureDifferentFamIdsPerLevel() throw(INTERP_KERNEL::Exception)
866 std::vector<int> levs=getNonEmptyLevelsExt();
867 std::set<int> allFamIds;
868 int maxId=getMaxFamilyId()+1;
869 std::map<int,std::vector<int> > famIdsToRenum;
870 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
872 const DataArrayInt *fam=getFamilyFieldAtLevel(*it);
875 std::set<int> tmp=fam->getDifferentValues();
877 std::set_intersection(tmp.begin(),tmp.end(),allFamIds.begin(),allFamIds.end(),std::inserter(r2,r2.end()));
879 famIdsToRenum[*it].insert(famIdsToRenum[*it].end(),r2.begin(),r2.end());
881 std::set_union(tmp.begin(),tmp.end(),allFamIds.begin(),allFamIds.end(),std::inserter(r3,r3.end()));
884 if(famIdsToRenum.empty())
886 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
887 for(std::map<int,std::vector<int> >::const_iterator it2=famIdsToRenum.begin();it2!=famIdsToRenum.end();it2++)
889 DataArrayInt *fam=const_cast<DataArrayInt *>(getFamilyFieldAtLevel((*it2).first));
890 int *famIdsToChange=fam->getPointer();
891 std::map<int,int> ren;
892 for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++,maxId++)
894 if(allIds->presenceOfValue(*it3))
896 std::string famName=getFamilyNameGivenId(*it3);
897 std::vector<std::string> grps=getGroupsOnFamily(famName.c_str());
900 std::string newFam=findOrCreateAndGiveFamilyWithId(maxId,dummy);
901 for(std::vector<std::string>::const_iterator it4=grps.begin();it4!=grps.end();it4++)
902 addFamilyOnGrp((*it4).c_str(),newFam.c_str());
905 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=fam->getIdsEqualList(&(*it2).second[0],&(*it2).second[0]+(*it2).second.size());
906 for(const int *id=ids->begin();id!=ids->end();id++)
907 famIdsToChange[*id]=ren[famIdsToChange[*id]];
913 * This method normalizes fam id with the policy explained underneath. This policy is close to those implemented in SMESH.
914 * Level #0 famids > 0, Level #-1 famids < 0, Level #-2 famids=0, Level #1 famids=0
915 * This policy is those used by SMESH and Trio and that is the opposite of those in MED file.
916 * This method will throw an exception if a same family id is detected in different level.
917 * \warning This policy is the opposite of those in MED file documentation ...
919 void MEDFileMesh::normalizeFamIdsTrio() throw(INTERP_KERNEL::Exception)
921 ensureDifferentFamIdsPerLevel();
922 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
923 std::vector<int> levs=getNonEmptyLevelsExt();
924 std::set<int> levsS(levs.begin(),levs.end());
925 std::set<std::string> famsFetched;
926 std::map<std::string,int> families;
927 if(std::find(levs.begin(),levs.end(),0)!=levs.end())
930 const DataArrayInt *fam=getFamilyFieldAtLevel(0);
934 std::set<int> tmp=fam->getDifferentValues();
935 std::map<int,int> ren;
936 for(std::set<int>::const_iterator it=tmp.begin();it!=tmp.end();it++,refId++)
938 int nbOfTuples=fam->getNumberOfTuples();
939 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
940 for(int *w=start;w!=start+nbOfTuples;w++)
942 for(std::set<int>::const_iterator it=tmp.begin();it!=tmp.end();it++)
944 if(allIds->presenceOfValue(*it))
946 std::string famName=getFamilyNameGivenId(*it);
947 families[famName]=ren[*it];
948 famsFetched.insert(famName);
953 if(std::find(levs.begin(),levs.end(),-1)!=levs.end())
956 const DataArrayInt *fam=getFamilyFieldAtLevel(-1);
960 std::set<int> tmp=fam->getDifferentValues();
961 std::map<int,int> ren;
962 for(std::set<int>::const_iterator it=tmp.begin();it!=tmp.end();it++,refId--)
964 int nbOfTuples=fam->getNumberOfTuples();
965 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
966 for(int *w=start;w!=start+nbOfTuples;w++)
968 for(std::set<int>::const_iterator it=tmp.begin();it!=tmp.end();it++)
970 if(allIds->presenceOfValue(*it))
972 std::string famName=getFamilyNameGivenId(*it);
973 families[famName]=ren[*it];
974 famsFetched.insert(famName);
979 for(std::set<int>::const_iterator it2=levsS.begin();it2!=levsS.end();it2++)
981 DataArrayInt *fam=const_cast<DataArrayInt*>(getFamilyFieldAtLevel(*it2));
984 std::set<int> tmp=fam->getDifferentValues();
986 for(std::set<int>::const_iterator it3=tmp.begin();it3!=tmp.end();it3++)
987 if(allIds->presenceOfValue(*it3))
989 std::string famName=getFamilyNameGivenId(*it3);
991 famsFetched.insert(famName);
996 std::vector<std::string> allFams=getFamiliesNames();
997 std::set<std::string> allFamsS(allFams.begin(),allFams.end());
998 std::set<std::string> unFetchedIds;
999 std::set_difference(allFamsS.begin(),allFamsS.end(),famsFetched.begin(),famsFetched.end(),std::inserter(unFetchedIds,unFetchedIds.end()));
1000 for(std::set<std::string>::const_iterator it4=unFetchedIds.begin();it4!=unFetchedIds.end();it4++)
1001 families[*it4]=_families[*it4];
1006 * This method normalizes fam id with the following policy.
1007 * Level #0 famids < 0, Level #-1 famids < 0 and for Level #1 famids >= 0
1008 * This policy is those used by SMESH and Trio and that is the opposite of those in MED file.
1009 * This method will throw an exception if a same family id is detected in different level.
1011 void MEDFileMesh::normalizeFamIdsMEDFile() throw(INTERP_KERNEL::Exception)
1013 ensureDifferentFamIdsPerLevel();
1014 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
1015 std::vector<int> levs=getNonEmptyLevelsExt();
1016 std::set<int> levsS(levs.begin(),levs.end());
1017 std::set<std::string> famsFetched;
1018 std::map<std::string,int> families;
1020 if(std::find(levs.begin(),levs.end(),1)!=levs.end())
1023 const DataArrayInt *fam=getFamilyFieldAtLevel(1);
1026 std::set<int> tmp=fam->getDifferentValues();
1027 std::map<int,int> ren;
1028 for(std::set<int>::const_iterator it=tmp.begin();it!=tmp.end();it++,refId++)
1030 int nbOfTuples=fam->getNumberOfTuples();
1031 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1032 for(int *w=start;w!=start+nbOfTuples;w++)
1034 for(std::set<int>::const_iterator it=tmp.begin();it!=tmp.end();it++)
1036 if(allIds->presenceOfValue(*it))
1038 std::string famName=getFamilyNameGivenId(*it);
1039 families[famName]=ren[*it];
1040 famsFetched.insert(famName);
1046 for(std::set<int>::const_reverse_iterator it2=levsS.rbegin();it2!=levsS.rend();it2++)
1048 const DataArrayInt *fam=getFamilyFieldAtLevel(1);
1051 std::set<int> tmp=fam->getDifferentValues();
1052 std::map<int,int> ren;
1053 for(std::set<int>::const_iterator it=tmp.begin();it!=tmp.end();it++,refId--)
1055 int nbOfTuples=fam->getNumberOfTuples();
1056 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1057 for(int *w=start;w!=start+nbOfTuples;w++)
1059 for(std::set<int>::const_iterator it=tmp.begin();it!=tmp.end();it++)
1061 if(allIds->presenceOfValue(*it))
1063 std::string famName=getFamilyNameGivenId(*it);
1064 families[famName]=ren[*it];
1065 famsFetched.insert(famName);
1071 std::vector<std::string> allFams=getFamiliesNames();
1072 std::set<std::string> allFamsS(allFams.begin(),allFams.end());
1073 std::set<std::string> unFetchedIds;
1074 std::set_difference(allFamsS.begin(),allFamsS.end(),famsFetched.begin(),famsFetched.end(),std::inserter(unFetchedIds,unFetchedIds.end()));
1075 for(std::set<std::string>::const_iterator it4=unFetchedIds.begin();it4!=unFetchedIds.end();it4++)
1076 families[*it4]=_families[*it4];
1081 * Returns the first (in lexical order) family name having family id equal to 'id'.
1083 std::string MEDFileMesh::getFamilyNameGivenId(int id) const throw(INTERP_KERNEL::Exception)
1085 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1086 if((*it).second==id)
1088 std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id;
1089 throw INTERP_KERNEL::Exception(oss.str().c_str());
1092 std::string MEDFileMesh::simpleRepr() const
1094 std::ostringstream oss;
1095 oss << "(*************************************)\n(* GENERAL INFORMATION ON THE MESH : *)\n(*************************************)\n";
1096 oss << "- Name of the mesh : <<" << getName() << ">>\n";
1097 oss << "- Description associated to the mesh : " << getDescription() << std::endl;
1101 DataArrayInt *MEDFileMesh::getGroupArr(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
1103 std::vector<std::string> tmp(1);
1105 DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum);
1110 DataArrayInt *MEDFileMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
1112 std::vector<std::string> fams2=getFamiliesOnGroups(grps);
1113 return getFamiliesArr(meshDimRelToMaxExt,fams2,renum);
1116 DataArrayInt *MEDFileMesh::getFamilyArr(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
1118 std::vector<std::string> tmp(1);
1120 DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum);
1125 DataArrayInt *MEDFileMesh::getNodeGroupArr(const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
1127 std::vector<std::string> tmp(1);
1129 DataArrayInt *ret=getNodeGroupsArr(tmp,renum);
1134 DataArrayInt *MEDFileMesh::getNodeGroupsArr(const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
1136 return getGroupsArr(1,grps,renum);
1139 DataArrayInt *MEDFileMesh::getNodeFamilyArr(const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
1141 std::vector<std::string> tmp(1);
1143 DataArrayInt *ret=getNodeFamiliesArr(tmp,renum);
1148 DataArrayInt *MEDFileMesh::getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
1150 return getFamiliesArr(1,fams,renum);
1153 void MEDFileMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum) throw(INTERP_KERNEL::Exception)
1157 std::set<std::string> grpsName;
1158 std::vector<std::string> grpsName2(grps.size());
1161 for(std::vector<const DataArrayInt *>::const_iterator it=grps.begin();it!=grps.end();it++,i++)
1163 grpsName.insert((*it)->getName());
1164 grpsName2[i]=(*it)->getName();
1166 if(grpsName.size()!=grps.size())
1167 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !");
1168 if(grpsName.find(std::string(""))!=grpsName.end())
1169 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !");
1170 int sz=getSizeAtLevel(meshDimRelToMaxExt);
1171 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam;
1172 std::vector< std::vector<int> > fidsOfGroups;
1175 fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups);
1179 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grps2(grps.size());
1180 for(unsigned int ii=0;ii<grps.size();ii++)
1182 grps2[ii]=MEDFileUMeshSplitL1::Renumber(getRevNumberFieldAtLevel(meshDimRelToMaxExt),grps[ii]);
1183 grps2[ii]->setName(grps[ii]->getName().c_str());
1185 std::vector<const DataArrayInt *> grps3(grps2.begin(),grps2.end());
1186 fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups);
1189 if(!_families.empty())
1190 offset=getMaxFamilyId()+1;
1191 TranslateFamilyIds(offset,fam,fidsOfGroups);
1192 std::set<int> ids=fam->getDifferentValues();
1193 appendFamilyEntries(ids,fidsOfGroups,grpsName2);
1194 setFamilyFieldArr(meshDimRelToMaxExt,fam);
1198 * This method append into '_families' attribute the families whose ids are in 'famIds'. Warning 'famIds' are expected to be ids
1199 * not in '_families'. Groups information are given in parameters in order to give to families representative names.
1200 * For the moment, the two last input parameters are not taken into account.
1202 void MEDFileMesh::appendFamilyEntries(const std::set<int>& famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames)
1204 std::map<int,std::string> famInv;
1205 for(std::set<int>::const_iterator it=famIds.begin();it!=famIds.end();it++)
1207 std::ostringstream oss;
1208 oss << "Family_" << (*it);
1209 _families[oss.str()]=(*it);
1210 famInv[*it]=oss.str();
1213 for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++)
1215 for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
1217 _groups[grpNames[i]].push_back(famInv[*it2]);
1222 void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp)
1224 famArr->applyLin(1,offset,0);
1225 for(std::vector< std::vector<int> >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++)
1226 std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<int>(),offset));
1230 * Warning no check is done on 'nameTry' in parameter. It should be non empty.
1231 * This method returns a name close to 'nameTry' so that it is not already into 'namesToAvoid'.
1232 * If this method fails to find such a name it will throw an exception.
1234 std::string MEDFileMesh::CreateNameNotIn(const std::string& nameTry, const std::vector<std::string>& namesToAvoid) throw(INTERP_KERNEL::Exception)
1237 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),nameTry)==namesToAvoid.end())
1240 std::size_t len=nameTry.length();
1241 for(std::size_t ii=1;ii<len;ii++)
1243 std::string tmp=nameTry.substr(ii,len-ii);
1244 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp)==namesToAvoid.end())
1250 for(std::size_t i=1;i<30;i++)
1252 std::string tmp1(nameTry.at(0),i);
1254 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp1)==namesToAvoid.end())
1260 for(std::vector<std::string>::const_iterator it2=namesToAvoid.begin();it2!=namesToAvoid.end();it2++)
1262 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp2)==namesToAvoid.end())
1264 throw INTERP_KERNEL::Exception("MEDFileMesh::CreateNameNotIn : impossible to find a not already used name !");
1267 int MEDFileMesh::PutInThirdComponentOfCodeOffset(std::vector<int>& code, int strt) throw(INTERP_KERNEL::Exception)
1269 std::size_t nbOfChunks=code.size()/3;
1270 if(code.size()%3!=0)
1271 throw INTERP_KERNEL::Exception("MEDFileMesh::PutInThirdComponentOfCodeOffset : code has invalid size : should be of size 3*x !");
1273 for(std::size_t i=0;i<nbOfChunks;i++)
1282 * This method should be called by any set* method of subclasses to deal automatically with _name attribute.
1283 * If _name attribute is empty the name of 'm' if taken as _name attribute.
1284 * If _name is not empty and that 'm' has the same name nothing is done.
1285 * If _name is not emplt and that 'm' has \b NOT the same name an exception is thrown.
1287 void MEDFileMesh::dealWithTinyInfo(const MEDCouplingMesh *m) throw(INTERP_KERNEL::Exception)
1293 std::string name(m->getName());
1298 std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : name of current MEDfile mesh is '" << _name << "' whereas name of input mesh is : '";
1299 oss << name << "' ! Names must match !";
1300 throw INTERP_KERNEL::Exception(oss.str().c_str());
1306 void MEDFileMesh::getFamilyRepr(std::ostream& oss) const
1308 oss << "(**************************)\n(* FAMILIES OF THE MESH : *)\n(**************************)\n";
1309 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1311 oss << "- Family with name \"" << (*it).first << "\" with number " << (*it).second << std::endl;
1312 oss << " - Groups lying on this family : ";
1313 std::vector<std::string> grps=getGroupsOnFamily((*it).first.c_str());
1314 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
1315 oss << std::endl << std::endl;
1319 MEDFileUMesh *MEDFileUMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
1321 MEDFileUtilities::CheckFileForRead(fileName);
1322 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1323 return new MEDFileUMesh(fid,mName,dt,it);
1326 MEDFileUMesh *MEDFileUMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
1328 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
1331 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
1332 throw INTERP_KERNEL::Exception(oss.str().c_str());
1334 MEDFileUtilities::CheckFileForRead(fileName);
1335 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
1337 ParaMEDMEM::MEDCouplingMeshType meshType;
1339 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
1340 return new MEDFileUMesh(fid,ms.front().c_str(),dt,it);
1343 MEDFileUMesh *MEDFileUMesh::New()
1345 return new MEDFileUMesh;
1348 bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
1350 if(!MEDFileMesh::isEqual(other,eps,what))
1352 const MEDFileUMesh *otherC=dynamic_cast<const MEDFileUMesh *>(other);
1355 what="Mesh types differ ! This is unstructured and other is NOT !";
1358 clearNonDiscrAttributes();
1359 otherC->clearNonDiscrAttributes();
1360 const DataArrayDouble *coo1=_coords;
1361 const DataArrayDouble *coo2=otherC->_coords;
1362 if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
1364 what="Mismatch of coordinates ! One is defined and not other !";
1369 bool ret=coo1->isEqual(*coo2,eps);
1372 what="Coords differ !";
1376 const DataArrayInt *famc1=_fam_coords;
1377 const DataArrayInt *famc2=otherC->_fam_coords;
1378 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
1380 what="Mismatch of families arr on nodes ! One is defined and not other !";
1385 bool ret=famc1->isEqual(*famc2);
1388 what="Families arr on node differ !";
1392 const DataArrayInt *numc1=_num_coords;
1393 const DataArrayInt *numc2=otherC->_num_coords;
1394 if((numc1==0 && numc2!=0) || (numc1!=0 && numc2==0))
1396 what="Mismatch of numbering arr on nodes ! One is defined and not other !";
1401 bool ret=numc1->isEqual(*numc2);
1404 what="Numbering arr on node differ !";
1408 if(_ms.size()!=otherC->_ms.size())
1410 what="Number of levels differs !";
1413 std::size_t sz=_ms.size();
1414 for(std::size_t i=0;i<sz;i++)
1416 const MEDFileUMeshSplitL1 *s1=_ms[i];
1417 const MEDFileUMeshSplitL1 *s2=otherC->_ms[i];
1418 if((s1==0 && s2!=0) || (s1!=0 && s2==0))
1420 what="Mismatch of presence of sub levels !";
1425 bool ret=s1->isEqual(s2,eps,what);
1430 //std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> > _ms;
1434 void MEDFileUMesh::clearNonDiscrAttributes() const
1436 MEDFileMesh::clearNonDiscrAttributes();
1437 const DataArrayDouble *coo1=_coords;
1439 (const_cast<DataArrayDouble *>(coo1))->setName("");//This parameter is not discriminant for comparison
1440 const DataArrayInt *famc1=_fam_coords;
1442 (const_cast<DataArrayInt *>(famc1))->setName("");//This parameter is not discriminant for comparison
1443 const DataArrayInt *numc1=_num_coords;
1445 (const_cast<DataArrayInt *>(numc1))->setName("");//This parameter is not discriminant for comparison
1446 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
1448 const MEDFileUMeshSplitL1 *tmp=(*it);
1450 tmp->clearNonDiscrAttributes();
1454 MEDFileUMesh::MEDFileUMesh()
1458 MEDFileUMesh::MEDFileUMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
1461 loadUMeshFromFile(fid,mName,dt,it);
1463 catch(INTERP_KERNEL::Exception& e)
1468 void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
1470 MEDFileUMeshL2 loaderl2;
1471 ParaMEDMEM::MEDCouplingMeshType meshType;
1474 int mid=MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
1475 if(meshType!=UNSTRUCTURED)
1477 std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !";
1478 throw INTERP_KERNEL::Exception(oss.str().c_str());
1480 loaderl2.loadAll(fid,mid,mName,dt,it);
1481 int lev=loaderl2.getNumberOfLevels();
1483 for(int i=0;i<lev;i++)
1485 if(!loaderl2.emptyLev(i))
1486 _ms[i]=new MEDFileUMeshSplitL1(loaderl2,mName,i);
1490 MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups);
1492 setName(loaderl2.getName());
1493 setDescription(loaderl2.getDescription());
1494 setIteration(loaderl2.getIteration());
1495 setOrder(loaderl2.getOrder());
1496 setTimeValue(loaderl2.getTime());
1497 setTimeUnit(loaderl2.getTimeUnit());
1498 _coords=loaderl2.getCoords();
1499 _fam_coords=loaderl2.getCoordsFamily();
1500 _num_coords=loaderl2.getCoordsNum();
1504 MEDFileUMesh::~MEDFileUMesh()
1508 void MEDFileUMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
1510 const DataArrayDouble *coo=_coords;
1511 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
1512 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
1513 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
1514 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
1515 int spaceDim=coo?coo->getNumberOfComponents():0;
1516 int mdim=getMeshDimension();
1517 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
1518 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
1519 for(int i=0;i<spaceDim;i++)
1521 std::string info=coo->getInfoOnComponent(i);
1523 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
1524 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
1525 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
1527 MEDmeshCr(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
1528 MEDFileUMeshL2::WriteCoords(fid,maa,_iteration,_order,_time,_coords,_fam_coords,_num_coords);
1529 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
1530 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
1531 (*it)->write(fid,maa,mdim);
1532 MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
1535 std::vector<int> MEDFileUMesh::getNonEmptyLevels() const
1537 std::vector<int> ret;
1539 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
1540 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
1546 std::vector<int> MEDFileUMesh::getNonEmptyLevelsExt() const
1548 std::vector<int> ret0=getNonEmptyLevels();
1549 if((const DataArrayDouble *) _coords)
1551 std::vector<int> ret(ret0.size()+1);
1553 std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
1560 * This methods returns all relative mesh levels where group 'grp' is defined \b excluded \b nodes.
1561 * To include nodes call MEDFileUMesh::getGrpNonEmptyLevelsExt method.
1563 std::vector<int> MEDFileUMesh::getGrpNonEmptyLevels(const char *grp) const throw(INTERP_KERNEL::Exception)
1565 std::vector<std::string> fams=getFamiliesOnGroup(grp);
1566 return getFamsNonEmptyLevels(fams);
1570 * 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.
1572 std::vector<int> MEDFileUMesh::getGrpNonEmptyLevelsExt(const char *grp) const throw(INTERP_KERNEL::Exception)
1574 std::vector<std::string> fams=getFamiliesOnGroup(grp);
1575 return getFamsNonEmptyLevelsExt(fams);
1579 * This methods returns all relative mesh levels where family 'fam' is defined \b excluded \b nodes.
1580 * To include nodes call MEDFileUMesh::getFamNonEmptyLevelsExt method.
1582 std::vector<int> MEDFileUMesh::getFamNonEmptyLevels(const char *fam) const throw(INTERP_KERNEL::Exception)
1584 std::vector<std::string> fams(1,std::string(fam));
1585 return getFamsNonEmptyLevels(fams);
1589 * 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.
1591 std::vector<int> MEDFileUMesh::getFamNonEmptyLevelsExt(const char *fam) const throw(INTERP_KERNEL::Exception)
1593 std::vector<std::string> fams(1,std::string(fam));
1594 return getFamsNonEmptyLevelsExt(fams);
1598 * This methods returns all relative mesh levels where groups 'grps' are defined \b excluded \b nodes.
1599 * To include nodes call MEDFileUMesh::getGrpsNonEmptyLevelsExt method.
1601 std::vector<int> MEDFileUMesh::getGrpsNonEmptyLevels(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
1603 std::vector<std::string> fams=getFamiliesOnGroups(grps);
1604 return getFamsNonEmptyLevels(fams);
1608 * 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.
1610 std::vector<int> MEDFileUMesh::getGrpsNonEmptyLevelsExt(const std::vector<std::string>& grps) const throw(INTERP_KERNEL::Exception)
1612 std::vector<std::string> fams=getFamiliesOnGroups(grps);
1613 return getFamsNonEmptyLevelsExt(fams);
1617 * This methods returns all relative mesh levels where families 'fams' are defined \b excluded \b nodes.
1618 * To include nodes call MEDFileUMesh::getFamsNonEmptyLevelsExt method.
1620 std::vector<int> MEDFileUMesh::getFamsNonEmptyLevels(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
1622 std::vector<int> ret;
1623 std::vector<int> levs=getNonEmptyLevels();
1624 std::vector<int> famIds=getFamiliesIds(fams);
1625 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
1626 if(_ms[-(*it)]->presenceOfOneFams(famIds))
1632 * 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.
1634 std::vector<int> MEDFileUMesh::getFamsNonEmptyLevelsExt(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception)
1636 std::vector<int> ret0=getFamsNonEmptyLevels(fams);
1637 const DataArrayInt *famCoords=_fam_coords;
1640 std::vector<int> famIds=getFamiliesIds(fams);
1641 if(famCoords->presenceOfValue(famIds))
1643 std::vector<int> ret(ret0.size()+1);
1645 std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
1653 * This method retrives all groups that partly or fully appear on the level 'meshDimRelToMaxExt'.
1655 std::vector<std::string> MEDFileUMesh::getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1657 std::vector<std::string> ret;
1658 std::vector<std::string> allGrps=getGroupsNames();
1659 for(std::vector<std::string>::const_iterator it=allGrps.begin();it!=allGrps.end();it++)
1661 std::vector<int> levs=getGrpNonEmptyLevelsExt((*it).c_str());
1662 if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)!=levs.end())
1668 int MEDFileUMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception)
1671 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++)
1672 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
1673 return (*it)->getMeshDimension()+lev;
1674 throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !");
1677 int MEDFileUMesh::getSpaceDimension() const throw(INTERP_KERNEL::Exception)
1679 const DataArrayDouble *coo=_coords;
1681 throw INTERP_KERNEL::Exception(" MEDFileUMesh::getSpaceDimension : no coords set !");
1682 return coo->getNumberOfComponents();
1685 std::string MEDFileUMesh::simpleRepr() const
1687 std::ostringstream oss;
1688 oss << MEDFileMesh::simpleRepr();
1689 const DataArrayDouble *coo=_coords;
1690 oss << "- The dimension of the space is ";
1691 static const char MSG1[]= "*** NO COORDS SET ***";
1692 static const char MSG2[]= "*** NO CONNECTIVITY SET FOR THIS LEVEL***";
1694 oss << _coords->getNumberOfComponents() << std::endl;
1696 oss << MSG1 << std::endl;
1697 oss << "- Type of the mesh : UNSTRUCTURED\n";
1698 oss << "- Number of nodes : ";
1700 oss << _coords->getNumberOfTuples() << std::endl;
1702 oss << MSG1 << std::endl;
1703 std::size_t nbOfLev=_ms.size();
1704 oss << "- Number of levels allocated : " << nbOfLev << std::endl;
1705 for(std::size_t i=0;i<nbOfLev;i++)
1707 const MEDFileUMeshSplitL1 *lev=_ms[i];
1708 oss << " - Level #" << -((int) i) << " has dimension : ";
1711 oss << lev->getMeshDimension() << std::endl;
1712 lev->simpleRepr(oss);
1715 oss << MSG2 << std::endl;
1717 oss << "- Number of families : " << _families.size() << std::endl << std::endl;
1720 oss << "(***********************)\n(* NODES OF THE MESH : *)\n(***********************)\n";
1721 oss << "- Names of coordinates :" << std::endl;
1722 std::vector<std::string> vars=coo->getVarsOnComponent();
1723 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
1724 oss << std::endl << "- Units of coordinates : " << std::endl;
1725 std::vector<std::string> units=coo->getUnitsOnComponent();
1726 std::copy(units.begin(),units.end(),std::ostream_iterator<std::string>(oss," "));
1728 oss << std::endl << std::endl;
1733 std::string MEDFileUMesh::advancedRepr() const
1735 return simpleRepr();
1738 int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1740 if(meshDimRelToMaxExt==1)
1742 if(!((const DataArrayDouble *)_coords))
1743 throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !");
1744 return _coords->getNumberOfTuples();
1746 return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize();
1749 const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1751 if(meshDimRelToMaxExt==1)
1753 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1754 return l1->getFamilyField();
1757 const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1759 if(meshDimRelToMaxExt==1)
1761 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1762 return l1->getNumberField();
1765 int MEDFileUMesh::getNumberOfNodes() const throw(INTERP_KERNEL::Exception)
1767 const DataArrayDouble *coo=_coords;
1769 throw INTERP_KERNEL::Exception(" MEDFileUMesh::getNumberOfNodes : no coords set !");
1770 return coo->getNumberOfTuples();
1773 const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1775 if(meshDimRelToMaxExt==1)
1777 if(!((const DataArrayInt *)_num_coords))
1778 throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !");
1779 return _rev_num_coords;
1781 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1782 return l1->getRevNumberField();
1786 * This method returns coordinates in 'this'. The returned array reference counter is \b not incremented by this method (as MEDCouplingPointSet::getCoords does).
1788 DataArrayDouble *MEDFileUMesh::getCoords() const
1790 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(_coords);
1791 if((DataArrayDouble *)tmp)
1798 MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const char *grp, bool renum) const throw(INTERP_KERNEL::Exception)
1800 synchronizeTinyInfoOnLeaves();
1801 std::vector<std::string> tmp(1);
1803 MEDCouplingUMesh *ret=getGroups(meshDimRelToMaxExt,tmp,renum);
1808 MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const throw(INTERP_KERNEL::Exception)
1810 synchronizeTinyInfoOnLeaves();
1811 std::vector<std::string> fams2=getFamiliesOnGroups(grps);
1812 return getFamilies(meshDimRelToMaxExt,fams2,renum);
1815 MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const char *fam, bool renum) const throw(INTERP_KERNEL::Exception)
1817 synchronizeTinyInfoOnLeaves();
1818 std::vector<std::string> tmp(1);
1820 MEDCouplingUMesh *ret=getFamilies(meshDimRelToMaxExt,tmp,renum);
1825 MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
1827 synchronizeTinyInfoOnLeaves();
1828 if(meshDimRelToMaxExt==1)
1830 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=getFamiliesArr(1,fams,renum);
1831 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
1832 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems());
1837 std::vector<int> famIds=getFamiliesIds(fams);
1838 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1840 return l1->getFamilyPart(&famIds[0],&famIds[0]+famIds.size(),renum);
1842 return l1->getFamilyPart(0,0,renum);
1845 DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
1847 std::vector<int> famIds=getFamiliesIds(fams);
1848 if(meshDimRelToMaxExt==1)
1850 if((const DataArrayInt *)_fam_coords)
1852 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
1854 da=_fam_coords->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
1856 da=_fam_coords->getIdsEqualList(0,0);
1858 return MEDFileUMeshSplitL1::Renumber(_num_coords,da);
1866 throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamiliesArr : no family array specified on nodes !");
1868 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1870 return l1->getFamilyPartArr(&famIds[0],&famIds[0]+famIds.size(),renum);
1872 return l1->getFamilyPartArr(0,0,renum);
1875 MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception)
1877 synchronizeTinyInfoOnLeaves();
1878 if(meshDimRelToMaxExt==1)
1882 MEDCouplingUMesh *umesh=MEDCouplingUMesh::New();
1883 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> cc=_coords->deepCpy();
1884 umesh->setCoords(cc);
1885 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(umesh);
1886 umesh->setName(getName());
1890 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1891 return l1->getWholeMesh(renum);
1894 MEDCouplingMesh *MEDFileUMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception)
1896 return getMeshAtLevel(meshDimRelToMax,renum);
1899 MEDCouplingUMesh *MEDFileUMesh::getLevel0Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
1901 return getMeshAtLevel(0,renum);
1904 MEDCouplingUMesh *MEDFileUMesh::getLevelM1Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
1906 return getMeshAtLevel(-1,renum);
1909 MEDCouplingUMesh *MEDFileUMesh::getLevelM2Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
1911 return getMeshAtLevel(-2,renum);
1914 MEDCouplingUMesh *MEDFileUMesh::getLevelM3Mesh(bool renum) const throw(INTERP_KERNEL::Exception)
1916 return getMeshAtLevel(-3,renum);
1919 const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
1921 if(meshDimRelToMaxExt==1)
1922 throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
1923 if(meshDimRelToMaxExt>1)
1924 throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
1925 int tracucedRk=-meshDimRelToMaxExt;
1926 if(tracucedRk>=(int)_ms.size())
1927 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
1928 if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
1929 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
1930 return _ms[tracucedRk];
1933 MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
1935 if(meshDimRelToMaxExt==1)
1936 throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
1937 if(meshDimRelToMaxExt>1)
1938 throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
1939 int tracucedRk=-meshDimRelToMaxExt;
1940 if(tracucedRk>=(int)_ms.size())
1941 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
1942 if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
1943 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
1944 return _ms[tracucedRk];
1947 void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
1949 if(-meshDimRelToMax>=(int)_ms.size())
1950 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : The meshdim of mesh is not managed by 'this' !");
1952 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++)
1954 if(((const MEDFileUMeshSplitL1*) (*it))!=0)
1956 int ref=(*it)->getMeshDimension();
1957 if(ref+i!=meshDim-meshDimRelToMax)
1958 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : no coherency between levels !");
1963 void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception)
1966 throw INTERP_KERNEL::Exception("MEDFileUMesh::setCoords : null pointer in input !");
1967 coords->checkAllocated();
1968 int nbOfTuples=coords->getNumberOfTuples();
1971 _fam_coords=DataArrayInt::New();
1972 _fam_coords->alloc(nbOfTuples,1);
1973 _fam_coords->fillWithZero();
1976 void MEDFileUMesh::eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception)
1978 if(meshDimRelToMaxExt==1)
1980 if((DataArrayInt *)_fam_coords)
1981 _fam_coords->fillWithZero();
1984 MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
1985 l1->eraseFamilyField();
1989 void MEDFileUMesh::optimizeFamilies() throw(INTERP_KERNEL::Exception)
1991 std::vector<int> levs=getNonEmptyLevelsExt();
1992 std::set<int> allFamsIds;
1993 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
1995 const DataArrayInt *ffield=getFamilyFieldAtLevel(*it);
1996 std::set<int> ids=ffield->getDifferentValues();
1998 std::set_union(ids.begin(),ids.end(),allFamsIds.begin(),allFamsIds.end(),std::inserter(res,res.begin()));
2001 std::set<std::string> famNamesToKill;
2002 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
2004 if(allFamsIds.find((*it).second)!=allFamsIds.end())
2005 famNamesToKill.insert((*it).first);
2007 for(std::set<std::string>::const_iterator it=famNamesToKill.begin();it!=famNamesToKill.end();it++)
2008 _families.erase(*it);
2009 std::vector<std::string> grpNamesToKill;
2010 for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
2012 std::vector<std::string> tmp;
2013 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
2015 if(famNamesToKill.find(*it2)==famNamesToKill.end())
2016 tmp.push_back(*it2);
2021 tmp.push_back((*it).first);
2023 for(std::vector<std::string>::const_iterator it=grpNamesToKill.begin();it!=grpNamesToKill.end();it++)
2027 void MEDFileUMesh::duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified, DataArrayInt *&cellsNotModified) throw(INTERP_KERNEL::Exception)
2029 std::vector<int> levs=getNonEmptyLevels();
2030 if(std::find(levs.begin(),levs.end(),0)==levs.end() || std::find(levs.begin(),levs.end(),-1)==levs.end())
2031 throw INTERP_KERNEL::Exception("MEDFileUMesh::duplicateNodesOnM1Group : This method works only for mesh definied on level 0 and -1 !");
2032 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0=getMeshAtLevel(0);
2033 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1=getMeshAtLevel(-1);
2034 int nbNodes=m0->getNumberOfNodes();
2035 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m11=getGroup(-1,grpNameM1);
2036 DataArrayInt *tmp00=0,*tmp11=0,*tmp22=0;
2037 m0->findNodesToDuplicate(*m11,tmp00,tmp11,tmp22);
2038 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeIdsToDuplicate(tmp00);
2039 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn0(tmp11);
2040 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn1(tmp22);
2041 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp0=static_cast<MEDCouplingUMesh *>(m0->buildPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),true));
2042 // node renumbering of cells in m1 impacted by duplication of node but not in group 'grpNameM1' on level -1
2043 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> descTmp0=DataArrayInt::New(),descITmp0=DataArrayInt::New(),revDescTmp0=DataArrayInt::New(),revDescITmp0=DataArrayInt::New();
2044 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp0Desc=tmp0->buildDescendingConnectivity(descTmp0,descITmp0,revDescTmp0,revDescITmp0);
2045 descTmp0=0; descITmp0=0; revDescTmp0=0; revDescITmp0=0;
2046 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW2=tmp0Desc->getCellIdsLyingOnNodes(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),false);
2047 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> cellsInM1ToRenumW3=static_cast<MEDCouplingUMesh *>(tmp0Desc->buildPartOfMySelf(cellsInM1ToRenumW2->begin(),cellsInM1ToRenumW2->end(),true));
2048 DataArrayInt *cellsInM1ToRenumW4Tmp=0;
2049 m1->areCellsIncludedIn(cellsInM1ToRenumW3,2,cellsInM1ToRenumW4Tmp);
2050 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW4(cellsInM1ToRenumW4Tmp);
2051 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW5=cellsInM1ToRenumW4->getIdsInRange(0,m1->getNumberOfCells());
2052 cellsInM1ToRenumW5->transformWithIndArr(cellsInM1ToRenumW4->begin(),cellsInM1ToRenumW4->end());
2053 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpIds=getGroupArr(-1,grpNameM1);
2054 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenum=cellsInM1ToRenumW5->buildSubstraction(grpIds);
2055 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1Part=static_cast<MEDCouplingUMesh *>(m1->buildPartOfMySelf(cellsInM1ToRenum->begin(),cellsInM1ToRenum->end(),true));
2056 m1Part->duplicateNodesInConn(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),nbNodes);
2057 m1->setPartOfMySelf(cellsInM1ToRenum->begin(),cellsInM1ToRenum->end(),*m1Part);
2058 // end of node renumbering of cells in m1 impacted by duplication of node but not in group of level -1 'grpNameM1'
2059 tmp0->duplicateNodes(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end());
2060 m0->setCoords(tmp0->getCoords());
2061 m0->setPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),*tmp0);
2062 m1->setCoords(m0->getCoords());
2063 _coords=m0->getCoords(); _coords->incrRef();
2064 // duplication of cells in group 'grpNameM1' on level -1
2065 m11->duplicateNodesInConn(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),nbNodes); m11->setCoords(m0->getCoords());
2066 std::vector<const MEDCouplingUMesh *> v(2); v[0]=m1; v[1]=m11;
2067 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> newm1=MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(v,tmp00,tmp11);
2068 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> szOfCellGrpOfSameType(tmp00);
2069 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idInMsOfCellGrpOfSameType(tmp11);
2071 newm1->setName(getName());
2072 const DataArrayInt *fam=getFamilyFieldAtLevel(-1);
2074 throw INTERP_KERNEL::Exception("MEDFileUMesh::duplicateNodesOnM1Group : internal problem !");
2075 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFam=DataArrayInt::New();
2076 newFam->alloc(newm1->getNumberOfCells(),1);
2077 int idd=getMaxFamilyId()+1;
2078 int globStart=0,start=0,end,globEnd;
2079 int nbOfChunks=szOfCellGrpOfSameType->getNumberOfTuples();
2080 for(int i=0;i<nbOfChunks;i++)
2082 globEnd=globStart+szOfCellGrpOfSameType->getIJ(i,0);
2083 if(idInMsOfCellGrpOfSameType->getIJ(i,0)==0)
2085 end=start+szOfCellGrpOfSameType->getIJ(i,0);
2086 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> part=fam->selectByTupleId2(start,end,1);
2087 newFam->setPartOfValues1(part,globStart,globEnd,1,0,1,1,true);
2092 newFam->setPartOfValuesSimple1(idd,globStart,globEnd,1,0,1,1);
2096 newm1->setCoords(getCoords());
2097 setMeshAtLevel(-1,newm1);
2098 setFamilyFieldArr(-1,newFam);
2099 std::string grpName2(grpNameM1); grpName2+="_dup";
2100 addFamily(grpName2.c_str(),idd);
2101 addFamilyOnGrp(grpName2.c_str(),grpName2.c_str());
2106 int newNbOfNodes=getCoords()->getNumberOfTuples();
2107 newFam=DataArrayInt::New(); newFam->alloc(newNbOfNodes,1);
2108 newFam->setPartOfValues1(fam,0,nbNodes,1,0,1,1,true);
2109 newFam->setPartOfValuesSimple1(0,nbNodes,newNbOfNodes,1,0,1,1);
2112 nodesDuplicated=nodeIdsToDuplicate; nodeIdsToDuplicate->incrRef();
2113 cellsModified=cellsToModifyConn0; cellsToModifyConn0->incrRef();
2114 cellsNotModified=cellsToModifyConn1; cellsToModifyConn1->incrRef();
2118 * \param [out] oldCode retrieves the distribution of types before the call if true is returned
2119 * \param [out] newCode etrieves the distribution of types after the call if true is returned
2120 * \param [out] o2nRenumCell tells for **all levels** the old 2 new renumbering of cells.
2122 * \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.
2123 * 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.
2125 bool MEDFileUMesh::unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception)
2127 o2nRenumCell=0; oldCode.clear(); newCode.clear();
2128 std::vector<int> levs=getNonEmptyLevels();
2130 std::vector< const DataArrayInt* > renumCellsSplited;//same than memorySaverIfThrow
2131 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > memorySaverIfThrow;//same than renumCellsSplited only in case of throw
2134 for(std::vector<int>::const_reverse_iterator it=levs.rbegin();it!=levs.rend();it++)
2136 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=getMeshAtLevel(*it);
2137 std::vector<int> code1=m->getDistributionOfTypes();
2138 end=PutInThirdComponentOfCodeOffset(code1,start);
2139 oldCode.insert(oldCode.end(),code1.begin(),code1.end());
2140 bool hasChanged=m->unPolyze();
2141 DataArrayInt *fake=0;
2142 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nCellsPart=m->getLevArrPerCellTypes(MEDCouplingUMesh::MEDMEM_ORDER,
2143 MEDCouplingUMesh::MEDMEM_ORDER+MEDCouplingUMesh::N_MEDMEM_ORDER,fake);
2145 renumCellsSplited.push_back(o2nCellsPart); memorySaverIfThrow.push_back(o2nCellsPart);
2148 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nCellsPart2=o2nCellsPart->buildPermArrPerLevel();
2149 m->renumberCells(o2nCellsPart2->getConstPointer(),false);
2151 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famField2,numField2;
2152 const DataArrayInt *famField=getFamilyFieldAtLevel(*it); if(famField) { famField->incrRef(); famField2=const_cast<DataArrayInt *>(famField); }
2153 const DataArrayInt *numField=getNumberFieldAtLevel(*it); if(numField) { numField->incrRef(); numField2=const_cast<DataArrayInt *>(numField); }
2154 setMeshAtLevel(*it,m);
2155 std::vector<int> code2=m->getDistributionOfTypes();
2156 end=PutInThirdComponentOfCodeOffset(code2,start);
2157 newCode.insert(newCode.end(),code2.begin(),code2.end());
2159 if(o2nCellsPart2->isIdentity())
2163 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFamField=famField->renumber(o2nCellsPart2->getConstPointer());
2164 setFamilyFieldArr(*it,newFamField);
2168 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newNumField=numField->renumber(o2nCellsPart2->getConstPointer());
2169 setRenumFieldArr(*it,newNumField);
2174 newCode.insert(newCode.end(),code1.begin(),code1.end());
2180 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumCells=DataArrayInt::Aggregate(renumCellsSplited);
2181 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nRenumCellRet=renumCells->buildPermArrPerLevel();
2182 o2nRenumCell=o2nRenumCellRet; o2nRenumCellRet->incrRef();
2187 void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector<int>& ids) throw(INTERP_KERNEL::Exception)
2189 const DataArrayDouble *coords=_coords;
2191 throw INTERP_KERNEL::Exception("addNodeGroup : no coords set !");
2192 DataArrayInt *sub=_fam_coords->selectByTupleIdSafe(&ids[0],&ids[0]+ids.size());
2193 std::set<int> ssub(sub->getConstPointer(),sub->getConstPointer()+sub->getNumberOfTuples());
2197 void MEDFileUMesh::setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception)
2199 std::string oldName=getFamilyNameGivenId(id);
2200 _families.erase(oldName);
2201 _families[newFamName]=id;
2204 void MEDFileUMesh::removeMeshAtLevel(int meshDimRelToMax) throw(INTERP_KERNEL::Exception)
2206 std::vector<int> levSet=getNonEmptyLevels();
2207 std::vector<int>::const_iterator it=std::find(levSet.begin(),levSet.end(),meshDimRelToMax);
2208 if(it==levSet.end())
2209 throw INTERP_KERNEL::Exception("MEDFileUMesh::removeMeshAtLevel : the requested level is not existing !");
2210 int pos=(-meshDimRelToMax);
2214 void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
2216 setMeshAtLevelGen(meshDimRelToMax,m,newOrOld);
2219 void MEDFileUMesh::setMeshAtLevelGen(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld) throw(INTERP_KERNEL::Exception)
2221 dealWithTinyInfo(m);
2222 std::vector<int> levSet=getNonEmptyLevels();
2223 if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end())
2225 if((DataArrayDouble *)_coords==0)
2227 DataArrayDouble *c=m->getCoords();
2232 if(m->getCoords()!=_coords)
2233 throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtLevel : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !");
2234 int sz=(-meshDimRelToMax)+1;
2235 if(sz>=(int)_ms.size())
2237 checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax);
2238 _ms[sz-1]=new MEDFileUMeshSplitL1(m,newOrOld);
2241 _ms[-meshDimRelToMax]=new MEDFileUMeshSplitL1(m,newOrOld);
2244 void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms) throw(INTERP_KERNEL::Exception)
2247 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !");
2248 int sz=(-meshDimRelToMax)+1;
2249 if(sz>=(int)_ms.size())
2251 checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
2252 DataArrayDouble *coo=checkMultiMesh(ms);
2253 if((DataArrayDouble *)_coords==0)
2259 if((DataArrayDouble *)_coords!=coo)
2260 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : coordinates mismatches !");
2261 std::vector<DataArrayInt *> corr;
2262 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,_zipconn_pol,corr);
2263 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr3(corr.begin(),corr.end());
2264 setMeshAtLevel(meshDimRelToMax,m);
2265 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2266 setGroupsAtLevel(meshDimRelToMax,corr2,true);
2269 void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum) throw(INTERP_KERNEL::Exception)
2272 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !");
2273 int sz=(-meshDimRelToMax)+1;
2274 if(sz>=(int)_ms.size())
2276 checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
2277 DataArrayDouble *coo=checkMultiMesh(ms);
2278 if((DataArrayDouble *)_coords==0)
2284 if((DataArrayDouble *)_coords!=coo)
2285 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : coordinates mismatches !");
2286 MEDCouplingUMesh *m=getMeshAtLevel(meshDimRelToMax,renum);
2287 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr(ms.size());
2289 for(std::vector<const MEDCouplingUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
2291 DataArrayInt *arr=0;
2292 bool test=m->areCellsIncludedIn(*it,_zipconn_pol,arr);
2296 std::ostringstream oss; oss << "MEDFileUMesh::setGroupsOnSetMesh : mesh #" << i << " is not part of whole mesh !";
2297 throw INTERP_KERNEL::Exception(oss.str().c_str());
2300 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
2301 setGroupsAtLevel(meshDimRelToMax,corr2,renum);
2304 DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const throw(INTERP_KERNEL::Exception)
2306 const DataArrayDouble *ret=ms[0]->getCoords();
2307 int mdim=ms[0]->getMeshDimension();
2308 for(unsigned int i=1;i<ms.size();i++)
2310 ms[i]->checkCoherency();
2311 if(ms[i]->getCoords()!=ret)
2312 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes must share the same coords !");
2313 if(ms[i]->getMeshDimension()!=mdim)
2314 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes have not same mesh dimension !");
2316 return const_cast<DataArrayDouble *>(ret);
2319 void MEDFileUMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
2321 if(meshDimRelToMaxExt==1)
2328 DataArrayDouble *coo(_coords);
2330 throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : the coordinates have not been set !");
2331 famArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),1,"MEDFileUMesh::setFamilyFieldArr : Problem in size of node family arr ! ");
2336 if(meshDimRelToMaxExt>1)
2337 throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : Dimension request is invalid (>1) !");
2338 int traducedRk=-meshDimRelToMaxExt;
2339 if(traducedRk>=(int)_ms.size())
2340 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
2341 if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
2342 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
2343 return _ms[traducedRk]->setFamilyArr(famArr);
2346 void MEDFileUMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception)
2348 if(meshDimRelToMaxExt==1)
2356 DataArrayDouble *coo(_coords);
2358 throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumFieldArr : the coordinates have not been set !");
2359 renumArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),1,"MEDFileUMesh::setRenumArr : Problem in size of node numbering arr ! ");
2360 renumArr->incrRef();
2361 _num_coords=renumArr;
2365 if(meshDimRelToMaxExt>1)
2366 throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumArr : Dimension request is invalid (>1) !");
2367 int traducedRk=-meshDimRelToMaxExt;
2368 if(traducedRk>=(int)_ms.size())
2369 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! To low !");
2370 if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
2371 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
2372 return _ms[traducedRk]->setRenumArr(renumArr);
2375 void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const
2377 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2378 if((const MEDFileUMeshSplitL1 *)(*it))
2379 (*it)->synchronizeTinyInfo(*this);
2383 * This method is called by MEDFileMesh::changeFamilyId. It performs only one part of the family id modification.
2385 void MEDFileUMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception)
2387 DataArrayInt *arr=_fam_coords;
2389 arr->changeValue(oldId,newId);
2390 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
2392 MEDFileUMeshSplitL1 *sp=(*it);
2395 sp->changeFamilyIdArr(oldId,newId);
2400 void MEDFileUMesh::computeRevNum() const
2402 if((const DataArrayInt *)_num_coords)
2405 int maxValue=_num_coords->getMaxValue(pos);
2406 _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1);
2410 MEDFileCMesh *MEDFileCMesh::New()
2412 return new MEDFileCMesh;
2415 MEDFileCMesh *MEDFileCMesh::New(const char *fileName) throw(INTERP_KERNEL::Exception)
2417 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
2420 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
2421 throw INTERP_KERNEL::Exception(oss.str().c_str());
2423 MEDFileUtilities::CheckFileForRead(fileName);
2424 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
2426 ParaMEDMEM::MEDCouplingMeshType meshType;
2428 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
2429 return new MEDFileCMesh(fid,ms.front().c_str(),dt,it);
2432 MEDFileCMesh *MEDFileCMesh::New(const char *fileName, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
2434 MEDFileUtilities::CheckFileForRead(fileName);
2435 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
2436 return new MEDFileCMesh(fid,mName,dt,it);
2439 int MEDFileCMesh::getMeshDimension() const throw(INTERP_KERNEL::Exception)
2441 if(!((const MEDCouplingCMesh*)_cmesh))
2442 throw INTERP_KERNEL::Exception("MEDFileCMesh::getMeshDimension : unable to get meshdimension because no mesh set !");
2443 return _cmesh->getMeshDimension();
2446 std::string MEDFileCMesh::simpleRepr() const
2448 return MEDFileMesh::simpleRepr();
2451 std::string MEDFileCMesh::advancedRepr() const
2453 return simpleRepr();
2456 bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
2458 if(!MEDFileMesh::isEqual(other,eps,what))
2460 const MEDFileCMesh *otherC=dynamic_cast<const MEDFileCMesh *>(other);
2463 what="Mesh types differ ! This is cartesian and other is NOT !";
2466 clearNonDiscrAttributes();
2467 otherC->clearNonDiscrAttributes();
2468 const MEDCouplingCMesh *coo1=_cmesh;
2469 const MEDCouplingCMesh *coo2=otherC->_cmesh;
2470 if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
2472 what="Mismatch of cartesian meshes ! One is defined and not other !";
2477 bool ret=coo1->isEqual(coo2,eps);
2480 what="cartesian meshes differ !";
2484 const DataArrayInt *famc1=_fam_nodes;
2485 const DataArrayInt *famc2=otherC->_fam_nodes;
2486 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2488 what="Mismatch of families arr on nodes ! One is defined and not other !";
2493 bool ret=famc1->isEqual(*famc2);
2496 what="Families arr on nodes differ !";
2501 famc2=otherC->_fam_cells;
2502 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2504 what="Mismatch of families arr on cells ! One is defined and not other !";
2509 bool ret=famc1->isEqual(*famc2);
2512 what="Families arr on cells differ !";
2517 famc2=otherC->_num_nodes;
2518 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2520 what="Mismatch of numbering arr on nodes ! One is defined and not other !";
2525 bool ret=famc1->isEqual(*famc2);
2528 what="Numbering arr on nodes differ !";
2533 famc2=otherC->_num_cells;
2534 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2536 what="Mismatch of numbering arr on cells ! One is defined and not other !";
2541 bool ret=famc1->isEqual(*famc2);
2544 what="Numbering arr on cells differ !";
2551 void MEDFileCMesh::clearNonDiscrAttributes() const
2553 MEDFileMesh::clearNonDiscrAttributes();
2554 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_cmesh);
2555 const DataArrayInt *tmp=_fam_nodes;
2557 (const_cast<DataArrayInt *>(tmp))->setName("");
2560 (const_cast<DataArrayInt *>(tmp))->setName("");
2563 (const_cast<DataArrayInt *>(tmp))->setName("");
2566 (const_cast<DataArrayInt *>(tmp))->setName("");
2569 MEDFileCMesh::MEDFileCMesh()
2573 MEDFileCMesh::MEDFileCMesh(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
2576 loadCMeshFromFile(fid,mName,dt,it);
2578 catch(INTERP_KERNEL::Exception& e)
2583 void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const char *mName, int dt, int it) throw(INTERP_KERNEL::Exception)
2585 MEDFileCMeshL2 loaderl2;
2586 ParaMEDMEM::MEDCouplingMeshType meshType;
2589 int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
2590 if(meshType!=CARTESIAN)
2592 std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !";
2593 throw INTERP_KERNEL::Exception(oss.str().c_str());
2595 loaderl2.loadAll(fid,mid,mName,dt,it);
2596 MEDCouplingCMesh *mesh=loaderl2.getMesh();
2599 setName(loaderl2.getName());
2600 setDescription(loaderl2.getDescription());
2601 setIteration(loaderl2.getIteration());
2602 setOrder(loaderl2.getOrder());
2603 setTimeValue(loaderl2.getTime());
2604 setTimeUnit(loaderl2.getTimeUnit());
2605 MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups);
2606 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
2607 int nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
2610 _fam_nodes=DataArrayInt::New();
2611 _fam_nodes->alloc(nbOfElt,1);
2612 MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer());
2614 nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf);
2617 _num_nodes=DataArrayInt::New();
2618 _num_nodes->alloc(nbOfElt,1);
2619 MEDmeshEntityNumberRd(fid,mName,dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer());
2621 int spaceDim=mesh->getSpaceDimension();
2622 med_geometry_type geoTypeReq=MED_NONE;
2626 geoTypeReq=MED_HEXA8;
2629 geoTypeReq=MED_QUAD4;
2632 geoTypeReq=MED_SEG2;
2635 geoTypeReq=MED_POINT1;
2638 throw INTERP_KERNEL::Exception("Invalid spacedim detected for cartesian mesh ! Must be in (1,2,3) !");
2640 nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
2643 _fam_cells=DataArrayInt::New();
2644 _fam_cells->alloc(nbOfElt,1);
2645 MEDmeshEntityFamilyNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_fam_cells->getPointer());
2647 nbOfElt=MEDmeshnEntity(fid,mName,dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf);
2650 _num_cells=DataArrayInt::New();
2651 _num_cells->alloc(nbOfElt,1);
2652 MEDmeshEntityNumberRd(fid,mName,dt,it,MED_CELL,geoTypeReq,_num_cells->getPointer());
2656 void MEDFileCMesh::changeFamilyIdArr(int oldId, int newId) throw(INTERP_KERNEL::Exception)
2658 DataArrayInt *arr=_fam_nodes;
2660 arr->changeValue(oldId,newId);
2663 arr->changeValue(oldId,newId);
2666 const MEDCouplingCMesh *MEDFileCMesh::getMesh() const
2668 synchronizeTinyInfoOnLeaves();
2672 MEDCouplingMesh *MEDFileCMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const throw(INTERP_KERNEL::Exception)
2675 throw INTERP_KERNEL::Exception("MEDFileCMesh does not support renumbering ! To do it perform request of renum array directly !");
2676 if(meshDimRelToMax!=0)
2677 throw INTERP_KERNEL::Exception("MEDFileCMesh does not support multi level for mesh 0 expected as input !");
2678 const MEDCouplingCMesh *m=getMesh();
2681 return const_cast<MEDCouplingCMesh *>(m);
2684 void MEDFileCMesh::setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception)
2686 dealWithTinyInfo(m);
2692 void MEDFileCMesh::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception)
2694 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2695 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
2696 INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
2697 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
2698 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
2699 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str);
2700 int spaceDim=_cmesh->getSpaceDimension();
2701 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
2702 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
2703 for(int i=0;i<spaceDim;i++)
2705 std::string info(_cmesh->getCoordsAt(i)->getInfoOnComponent(0));
2707 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
2708 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
2709 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
2711 MEDmeshCr(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit);
2712 MEDmeshGridTypeWr(fid,maa,MED_CARTESIAN_GRID);
2713 for(int i=0;i<spaceDim;i++)
2715 const DataArrayDouble *da=_cmesh->getCoordsAt(i);
2716 MEDmeshGridIndexCoordinateWr(fid,maa,_iteration,_order,_time,i+1,da->getNumberOfTuples(),da->getConstPointer());
2719 med_geometry_type geoTypeReq=MED_NONE;
2723 geoTypeReq=MED_HEXA8;
2726 geoTypeReq=MED_QUAD4;
2729 geoTypeReq=MED_SEG2;
2732 geoTypeReq=MED_POINT1;
2735 throw INTERP_KERNEL::Exception("Invalid spacedim detected for cartesian mesh ! Must be in (1,2,3) !");
2738 if((const DataArrayInt *)_fam_cells)
2739 MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_CELL,geoTypeReq,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer());
2740 if((const DataArrayInt *)_fam_nodes)
2741 MEDmeshEntityFamilyNumberWr(fid,maa,_iteration,_order,MED_NODE,MED_NONE,_fam_nodes->getNumberOfTuples(),_fam_nodes->getConstPointer());
2743 MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa,_families,_groups,_too_long_str);
2746 int MEDFileCMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
2748 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
2749 throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : Only available for levels 0 or 1 !");
2750 if(!((const MEDCouplingCMesh *)_cmesh))
2751 throw INTERP_KERNEL::Exception("MEDFileCMesh::getSizeAtLevel : No cartesian mesh set !");
2752 if(meshDimRelToMaxExt==0)
2753 return _cmesh->getNumberOfCells();
2755 return _cmesh->getNumberOfNodes();
2758 void MEDFileCMesh::synchronizeTinyInfoOnLeaves() const
2760 const MEDCouplingCMesh *cmesh=_cmesh;
2761 (const_cast<MEDCouplingCMesh *>(cmesh))->setName(_name.c_str());
2762 (const_cast<MEDCouplingCMesh *>(cmesh))->setDescription(_desc_name.c_str());
2763 (const_cast<MEDCouplingCMesh *>(cmesh))->setTime(_time,_iteration,_order);
2764 (const_cast<MEDCouplingCMesh *>(cmesh))->setTimeUnit(_dt_unit.c_str());
2767 int MEDFileCMesh::getNumberOfNodes() const throw(INTERP_KERNEL::Exception)
2769 const MEDCouplingCMesh *cmesh(_cmesh);
2771 throw INTERP_KERNEL::Exception("MEDFileCMesh::getNumberOfNodes : no cartesian mesh set !");
2772 return cmesh->getNumberOfNodes();
2775 std::vector<int> MEDFileCMesh::getNonEmptyLevels() const
2777 std::vector<int> ret(1);
2781 std::vector<int> MEDFileCMesh::getNonEmptyLevelsExt() const
2783 std::vector<int> ret(2);
2788 DataArrayInt *MEDFileCMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const throw(INTERP_KERNEL::Exception)
2790 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
2791 throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : Only available for levels 0 or 1 !");
2792 std::vector<int> famIds=getFamiliesIds(fams);
2793 if(meshDimRelToMaxExt==1)
2795 if((const DataArrayInt *)_fam_nodes)
2797 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
2799 da=_fam_nodes->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
2801 da=_fam_nodes->getIdsEqualList(0,0);
2803 return MEDFileUMeshSplitL1::Renumber(_num_nodes,da);
2811 throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on nodes !");
2815 if((const DataArrayInt *)_fam_cells)
2817 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
2819 da=_fam_cells->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
2821 da=_fam_cells->getIdsEqualList(0,0);
2823 return MEDFileUMeshSplitL1::Renumber(_num_cells,da);
2831 throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamiliesArr : no family array specified on cells !");
2835 void MEDFileCMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr) throw(INTERP_KERNEL::Exception)
2837 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
2838 throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !");
2841 if(meshDimRelToMaxExt==0)
2847 void MEDFileCMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr) throw(INTERP_KERNEL::Exception)
2849 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
2850 throw INTERP_KERNEL::Exception("MEDFileCMesh::setRenumFieldArr : Only available for levels 0 or 1 !");
2852 renumArr->incrRef();
2853 if(meshDimRelToMaxExt==0)
2854 _num_cells=renumArr;
2856 _num_nodes=renumArr;
2859 const DataArrayInt *MEDFileCMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
2861 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
2862 throw INTERP_KERNEL::Exception("MEDFileCMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 !");
2863 if(meshDimRelToMaxExt==0)
2869 const DataArrayInt *MEDFileCMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
2871 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
2872 throw INTERP_KERNEL::Exception("MEDFileCMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 !");
2873 if(meshDimRelToMaxExt==0)
2879 const DataArrayInt *MEDFileCMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
2881 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
2882 throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : Only available for levels 0 or 1 !");
2883 if(meshDimRelToMaxExt==0)
2885 if((const DataArrayInt *)_num_cells)
2888 int maxValue=_num_cells->getMaxValue(pos);
2889 _rev_num_cells=_num_cells->invertArrayN2O2O2N(maxValue+1);
2890 return _rev_num_cells;
2893 throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no cell renumbering for a request on reverse numbering !");
2897 if((const DataArrayInt *)_num_nodes)
2900 int maxValue=_num_nodes->getMaxValue(pos);
2901 _rev_num_nodes=_num_nodes->invertArrayN2O2O2N(maxValue+1);
2902 return _rev_num_nodes;
2905 throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !");
2910 * no implementation here, it is not a bug, but intresically no polyhedra in \a this.
2912 bool MEDFileCMesh::unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell) throw(INTERP_KERNEL::Exception)
2914 oldCode.clear(); newCode.clear(); o2nRenumCell=0;
2918 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New()
2920 return new MEDFileMeshMultiTS;
2923 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName) throw(INTERP_KERNEL::Exception)
2925 return new MEDFileMeshMultiTS(fileName);
2928 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
2930 return new MEDFileMeshMultiTS(fileName,mName);
2933 const char *MEDFileMeshMultiTS::getName() const throw(INTERP_KERNEL::Exception)
2935 if(_mesh_one_ts.empty())
2936 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getName : no time steps set !");
2937 return _mesh_one_ts[0]->getName();
2940 void MEDFileMeshMultiTS::setName(const char *newMeshName) throw(INTERP_KERNEL::Exception)
2942 std::string oldName(getName());
2943 std::vector< std::pair<std::string,std::string> > v(1);
2944 v[0].first=oldName; v[0].second=newMeshName;
2948 bool MEDFileMeshMultiTS::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
2951 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
2953 MEDFileMesh *cur(*it);
2955 ret=cur->changeNames(modifTab) || ret;
2960 MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const throw(INTERP_KERNEL::Exception)
2962 if(_mesh_one_ts.empty())
2963 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getOneTimeStep : empty time step set !");
2964 return const_cast<MEDFileMesh *>(static_cast<const MEDFileMesh *>(_mesh_one_ts[0]));
2967 void MEDFileMeshMultiTS::setOneTimeStep(MEDFileMesh *mesh1TimeStep) throw(INTERP_KERNEL::Exception)
2970 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::setOneTimeStep : input pointer should be different from 0 !");
2971 _mesh_one_ts.resize(1);
2972 mesh1TimeStep->incrRef();
2973 //MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> toto=mesh1TimeStep;
2974 _mesh_one_ts[0]=mesh1TimeStep;
2977 void MEDFileMeshMultiTS::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
2979 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
2981 (*it)->copyOptionsFrom(*this);
2986 void MEDFileMeshMultiTS::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
2988 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
2989 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
2990 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
2991 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
2995 void MEDFileMeshMultiTS::loadFromFile(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
2996 {//for the moment to be improved
2997 _mesh_one_ts.resize(1);
2998 _mesh_one_ts[0]=MEDFileMesh::New(fileName,mName,-1,-1);
3001 MEDFileMeshMultiTS::MEDFileMeshMultiTS()
3005 MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName) throw(INTERP_KERNEL::Exception)
3008 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
3011 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
3012 throw INTERP_KERNEL::Exception(oss.str().c_str());
3014 MEDFileUtilities::CheckFileForRead(fileName);
3015 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY);
3017 ParaMEDMEM::MEDCouplingMeshType meshType;
3019 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front().c_str(),meshType,dt,it,dummy2);
3020 loadFromFile(fileName,ms.front().c_str());
3022 catch(INTERP_KERNEL::Exception& e)
3027 MEDFileMeshMultiTS::MEDFileMeshMultiTS(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception)
3030 loadFromFile(fileName,mName);
3032 catch(INTERP_KERNEL::Exception& e)
3037 MEDFileMeshes *MEDFileMeshes::New()
3039 return new MEDFileMeshes;
3042 MEDFileMeshes *MEDFileMeshes::New(const char *fileName) throw(INTERP_KERNEL::Exception)
3044 return new MEDFileMeshes(fileName);
3047 void MEDFileMeshes::write(med_idt fid) const throw(INTERP_KERNEL::Exception)
3050 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
3052 (*it)->copyOptionsFrom(*this);
3057 void MEDFileMeshes::write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception)
3059 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
3060 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
3061 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
3062 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str().c_str());
3067 int MEDFileMeshes::getNumberOfMeshes() const throw(INTERP_KERNEL::Exception)
3069 return _meshes.size();
3072 MEDFileMeshesIterator *MEDFileMeshes::iterator() throw(INTERP_KERNEL::Exception)
3074 return new MEDFileMeshesIterator(this);
3077 MEDFileMesh *MEDFileMeshes::getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception)
3079 if(i<0 || i>=(int)_meshes.size())
3081 std::ostringstream oss; oss << "MEDFileMeshes::getMeshAtPos : invalid mesh id given in parameter ! Should be in [0;" << _meshes.size() << ") !";
3082 throw INTERP_KERNEL::Exception(oss.str().c_str());
3084 return _meshes[i]->getOneTimeStep();
3087 MEDFileMesh *MEDFileMeshes::getMeshWithName(const char *mname) const throw(INTERP_KERNEL::Exception)
3089 std::vector<std::string> ms=getMeshesNames();
3090 std::vector<std::string>::iterator it=std::find(ms.begin(),ms.end(),mname);
3093 std::ostringstream oss; oss << "MEDFileMeshes::getMeshWithName : Mesh \"" << mname << "\" does not exist in this ! Existing are : ";
3094 std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss," "));
3095 throw INTERP_KERNEL::Exception(oss.str().c_str());
3097 return getMeshAtPos((int)std::distance(ms.begin(),it));
3100 std::vector<std::string> MEDFileMeshes::getMeshesNames() const throw(INTERP_KERNEL::Exception)
3102 std::vector<std::string> ret(_meshes.size());
3104 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
3106 const MEDFileMeshMultiTS *f=(*it);
3109 ret[i]=f->getName();
3113 std::ostringstream oss; oss << "MEDFileMeshes::getMeshesNames : At rank #" << i << " mesh is not defined !";
3114 throw INTERP_KERNEL::Exception(oss.str().c_str());
3120 bool MEDFileMeshes::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab) throw(INTERP_KERNEL::Exception)
3123 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::iterator it=_meshes.begin();it!=_meshes.end();it++)
3125 MEDFileMeshMultiTS *cur(*it);
3127 ret=cur->changeNames(modifTab) || ret;
3132 void MEDFileMeshes::resize(int newSize) throw(INTERP_KERNEL::Exception)
3134 _meshes.resize(newSize);
3137 void MEDFileMeshes::pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
3140 throw INTERP_KERNEL::Exception("MEDFileMeshes::pushMesh : invalid input pointer ! should be different from 0 !");
3141 MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
3142 elt->setOneTimeStep(mesh);
3143 _meshes.push_back(elt);
3146 void MEDFileMeshes::setMeshAtPos(int i, MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception)
3149 throw INTERP_KERNEL::Exception("MEDFileMeshes::setMeshAtPos : invalid input pointer ! should be different from 0 !");
3150 if(i>=(int)_meshes.size())
3151 _meshes.resize(i+1);
3152 MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
3153 elt->setOneTimeStep(mesh);
3157 void MEDFileMeshes::destroyMeshAtPos(int i) throw(INTERP_KERNEL::Exception)
3159 if(i<0 || i>=(int)_meshes.size())
3161 std::ostringstream oss; oss << "MEDFileMeshes::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _meshes.size() << ") !";
3162 throw INTERP_KERNEL::Exception(oss.str().c_str());
3164 _meshes.erase(_meshes.begin()+i);
3167 void MEDFileMeshes::loadFromFile(const char *fileName) throw(INTERP_KERNEL::Exception)
3169 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
3171 _meshes.resize(ms.size());
3172 for(std::vector<std::string>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
3173 _meshes[i]=MEDFileMeshMultiTS::New(fileName,(*it).c_str());
3176 MEDFileMeshes::MEDFileMeshes()
3180 MEDFileMeshes::MEDFileMeshes(const char *fileName) throw(INTERP_KERNEL::Exception)
3183 loadFromFile(fileName);
3185 catch(INTERP_KERNEL::Exception& e)
3189 std::string MEDFileMeshes::simpleRepr() const
3191 std::ostringstream oss;
3192 oss << "(*****************)\n(* MEDFileMeshes *)\n(*****************)\n\n";
3193 simpleReprWithoutHeader(oss);
3197 void MEDFileMeshes::simpleReprWithoutHeader(std::ostream& oss) const
3199 int nbOfMeshes=getNumberOfMeshes();
3200 oss << "There are " << nbOfMeshes << " meshes with the following names : \n";
3201 std::vector<std::string> mns=getMeshesNames();
3202 for(int i=0;i<nbOfMeshes;i++)
3203 oss << " - #" << i << " \"" << mns[i] << "\"\n";
3206 void MEDFileMeshes::checkCoherency() const throw(INTERP_KERNEL::Exception)
3208 static const char MSG[]="MEDFileMeshes::checkCoherency : mesh at rank ";
3210 std::set<std::string> s;
3211 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
3213 const MEDFileMeshMultiTS *elt=(*it);
3216 std::ostringstream oss; oss << MSG << i << "/" << _meshes.size() << " is empty !";
3217 throw INTERP_KERNEL::Exception(oss.str().c_str());
3219 std::size_t sz=s.size();
3220 s.insert(std::string((*it)->getName()));
3223 std::ostringstream oss; oss << MSG << i << " has a name (\"" << (*it)->getName() << "\") already used by an another mesh in list !";
3224 throw INTERP_KERNEL::Exception(oss.str().c_str());
3229 MEDFileMeshesIterator::MEDFileMeshesIterator(MEDFileMeshes *ms):_ms(ms),_iter_id(0),_nb_iter(0)
3234 _nb_iter=ms->getNumberOfMeshes();
3238 MEDFileMeshesIterator::~MEDFileMeshesIterator()
3242 MEDFileMesh *MEDFileMeshesIterator::nextt()
3244 if(_iter_id<_nb_iter)
3246 MEDFileMeshes *ms(_ms);
3248 return ms->getMeshAtPos(_iter_id++);