1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "MEDFileMesh.hxx"
22 #include "MEDFileUtilities.hxx"
23 #include "MEDFileFieldOverView.hxx"
24 #include "MEDFileField.hxx"
25 #include "MEDLoader.hxx"
26 #include "MEDFileSafeCaller.txx"
27 #include "MEDLoaderBase.hxx"
29 #include "MEDCouplingUMesh.hxx"
31 #include "InterpKernelAutoPtr.hxx"
36 extern med_geometry_type typmai3[34];
38 using namespace ParaMEDMEM;
40 const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO";
42 MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_univ_wr_status(true)
46 std::size_t MEDFileMesh::getHeapMemorySizeWithoutChildren() const
48 std::size_t ret(_dt_unit.capacity()+_name.capacity()+_univ_name.capacity()+_desc_name.capacity());
49 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
51 ret+=(*it).first.capacity()+(*it).second.capacity()*sizeof(std::string);
52 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
53 ret+=(*it2).capacity();
55 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
56 ret+=(*it).first.capacity()+sizeof(int);
60 std::vector<const BigMemoryObject *> MEDFileMesh::getDirectChildrenWithNull() const
62 return std::vector<const BigMemoryObject *>();
66 * Returns a new MEDFileMesh holding the mesh data that has been read from a given MED
67 * file. The first mesh in the file is loaded.
68 * \param [in] fileName - the name of MED file to read.
69 * \return MEDFileMesh * - a new instance of MEDFileMesh. The caller is to delete this
70 * mesh using decrRef() as it is no more needed.
71 * \throw If the file is not readable.
72 * \throw If there is no meshes in the file.
73 * \throw If the mesh in the file is of a not supported type.
75 MEDFileMesh *MEDFileMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
77 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
80 std::ostringstream oss; oss << "MEDFileMesh::New : no meshes in file \"" << fileName << "\" !";
81 throw INTERP_KERNEL::Exception(oss.str().c_str());
83 MEDFileUtilities::CheckFileForRead(fileName);
84 ParaMEDMEM::MEDCouplingMeshType meshType;
85 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
88 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
93 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
94 ret->loadUMeshFromFile(fid,ms.front(),dt,it,mrs);
95 ret->loadJointsFromFile(fid);
96 return (MEDFileUMesh *)ret.retn();
100 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
101 ret->loadCMeshFromFile(fid,ms.front(),dt,it,mrs);
102 ret->loadJointsFromFile(fid);
103 return (MEDFileCMesh *)ret.retn();
107 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=MEDFileCurveLinearMesh::New();
108 ret->loadCLMeshFromFile(fid,ms.front(),dt,it,mrs);
109 ret->loadJointsFromFile(fid);
110 return (MEDFileCurveLinearMesh *)ret.retn();
114 std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << ms.front() << "' exists but unsupported type yet !";
115 throw INTERP_KERNEL::Exception(oss.str().c_str());
121 * Returns a new MEDFileMesh holding the mesh data that has been read from a given MED
122 * file. The mesh to load is specified by its name and numbers of a time step and an
124 * \param [in] fileName - the name of MED file to read.
125 * \param [in] mName - the name of the mesh to read.
126 * \param [in] dt - the number of a time step.
127 * \param [in] it - the number of an iteration.
128 * \param [in] joints - the sub-domain joints to use instead of those that can be read
129 * from the MED file. Usually this joints are those just read by another iteration
130 * of mName mesh, when this method is called by MEDFileMeshMultiTS::New()
131 * \return MEDFileMesh * - a new instance of MEDFileMesh. The caller is to delete this
132 * mesh using decrRef() as it is no more needed.
133 * \throw If the file is not readable.
134 * \throw If there is no mesh with given attributes in the file.
135 * \throw If the mesh in the file is of a not supported type.
137 MEDFileMesh *MEDFileMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs, MEDFileJoints* joints)
139 MEDFileUtilities::CheckFileForRead(fileName);
140 ParaMEDMEM::MEDCouplingMeshType meshType;
141 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
144 MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2);
149 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=MEDFileUMesh::New();
150 ret->loadUMeshFromFile(fid,mName,dt,it,mrs);
151 ret->loadJointsFromFile(fid,joints);
152 return (MEDFileUMesh *)ret.retn();
156 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=MEDFileCMesh::New();
157 ret->loadCMeshFromFile(fid,mName,dt,it,mrs);
158 ret->loadJointsFromFile(fid,joints);
159 return (MEDFileCMesh *)ret.retn();
163 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=MEDFileCurveLinearMesh::New();
164 ret->loadCLMeshFromFile(fid,mName,dt,it,mrs);
165 ret->loadJointsFromFile(fid,joints);
166 return (MEDFileCurveLinearMesh *)ret.retn();
170 std::ostringstream oss; oss << "MEDFileMesh::New : MED file exists and has mesh '" << mName << "' exists but unsupported type yet !";
171 throw INTERP_KERNEL::Exception(oss.str().c_str());
177 * Writes \a this mesh into an open MED file specified by its descriptor.
178 * \param [in] fid - the MED file descriptor.
179 * \throw If the mesh name is not set.
180 * \throw If the file is open for reading only.
181 * \throw If the writing mode == 1 and the same data is present in an existing file.
183 void MEDFileMesh::write(med_idt fid) const
186 const_cast<MEDFileMesh *>(this)->addFamily(DFT_FAM_NAME,0);
188 throw INTERP_KERNEL::Exception("MEDFileMesh : name is empty. MED file ask for a NON EMPTY name !");
193 * Writes \a this mesh into a MED file specified by its name.
194 * \param [in] fileName - the MED file name.
195 * \param [in] mode - the writing mode. For more on \a mode, see \ref AdvMEDLoaderBasics.
196 * - 2 - erase; an existing file is removed.
197 * - 1 - append; same data should not be present in an existing file.
198 * - 0 - overwrite; same data present in an existing file is overwritten.
199 * \throw If the mesh name is not set.
200 * \throw If \a mode == 1 and the same data is present in an existing file.
202 void MEDFileMesh::write(const std::string& fileName, int mode) const
204 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
205 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
206 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
207 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
212 * Checks if \a this and another mesh are equal.
213 * \param [in] other - the mesh to compare with.
214 * \param [in] eps - a precision used to compare real values.
215 * \param [in,out] what - the string returning description of unequal data.
216 * \return bool - \c true if the meshes are equal, \c false, else.
218 bool MEDFileMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
220 if(_order!=other->_order)
222 what="Orders differ !";
225 if(_iteration!=other->_iteration)
227 what="Iterations differ !";
230 if(fabs(_time-other->_time)>eps)
232 what="Time values differ !";
235 if(_dt_unit!=other->_dt_unit)
237 what="Time units differ !";
240 if(_name!=other->_name)
242 what="Names differ !";
245 //univ_name has been ignored -> not a bug because it is a mutable attribute
246 if(_desc_name!=other->_desc_name)
248 what="Description names differ !";
251 if(!areGrpsEqual(other,what))
253 if(!areFamsEqual(other,what))
258 void MEDFileMesh::setName(const std::string& name)
264 * Clears redundant attributes of incorporated data arrays.
266 void MEDFileMesh::clearNonDiscrAttributes() const
271 bool MEDFileMesh::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
273 for(std::vector< std::pair<std::string,std::string> >::const_iterator it=modifTab.begin();it!=modifTab.end();it++)
275 if((*it).first==_name)
285 * Copies data on groups and families from another mesh.
286 * \param [in] other - the mesh to copy the data from.
288 void MEDFileMesh::copyFamGrpMapsFrom(const MEDFileMesh& other)
290 _groups=other._groups;
291 _families=other._families;
296 * This method clear all the groups in the map.
297 * So this method does not operate at all on arrays.
298 * So this method can lead to orphan families.
300 * \sa MEDFileMesh::clearFamMap, MEDFileMesh::clearFamGrpMaps
302 void MEDFileMesh::clearGrpMap()
308 * This method clear all the families in the map.
309 * So this method does not operate at all on arrays.
310 * WARNING ! if there are some groups lying on cleared families, those groups will be impacted !
312 * \sa MEDFileMesh::clearFamMap, MEDFileMesh::clearFamGrpMaps
314 void MEDFileMesh::clearFamMap()
320 * This method clear all the families and groups in the map.
321 * So this method does not operate at all on arrays.
322 * As all groups and families entry will be removed after
323 * the call of MEDFileMesh::setFamilyFieldArr method with 0 or None (python) in the 2nd parameter can be useful to reduce the size of the object.
325 * \sa MEDFileMesh::clearFamMap, MEDFileMesh::clearFamMap
327 void MEDFileMesh::clearFamGrpMaps()
334 * Returns names of families constituting a group.
335 * \param [in] name - the name of the group of interest.
336 * \return std::vector<std::string> - a sequence of names of the families.
337 * \throw If the name of a nonexistent group is specified.
339 std::vector<std::string> MEDFileMesh::getFamiliesOnGroup(const std::string& name) const
341 std::string oname(name);
342 std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
343 if(it==_groups.end())
345 std::vector<std::string> grps=getGroupsNames();
346 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
347 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
348 throw INTERP_KERNEL::Exception(oss.str().c_str());
354 * Returns names of families constituting some groups.
355 * \param [in] grps - a sequence of names of groups of interest.
356 * \return std::vector<std::string> - a sequence of names of the families.
357 * \throw If a name of a nonexistent group is present in \a grps.
359 std::vector<std::string> MEDFileMesh::getFamiliesOnGroups(const std::vector<std::string>& grps) const
361 std::set<std::string> fams;
362 for(std::vector<std::string>::const_iterator it=grps.begin();it!=grps.end();it++)
364 std::map<std::string, std::vector<std::string> >::const_iterator it2=_groups.find(*it);
365 if(it2==_groups.end())
367 std::ostringstream oss; oss << "No such group in mesh \"" << _name << "\" : " << *it;
368 std::vector<std::string> grps2=getGroupsNames(); oss << "\" !\nAvailable groups are :";
369 std::copy(grps2.begin(),grps2.end(),std::ostream_iterator<std::string>(oss," "));
370 throw INTERP_KERNEL::Exception(oss.str().c_str());
372 fams.insert((*it2).second.begin(),(*it2).second.end());
374 std::vector<std::string> fams2(fams.begin(),fams.end());
379 * Returns ids of families constituting a group.
380 * \param [in] name - the name of the group of interest.
381 * \return std::vector<int> - sequence of ids of the families.
382 * \throw If the name of a nonexistent group is specified.
384 std::vector<int> MEDFileMesh::getFamiliesIdsOnGroup(const std::string& name) const
386 std::string oname(name);
387 std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.find(oname);
388 std::vector<std::string> grps=getGroupsNames();
389 if(it==_groups.end())
391 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
392 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
393 throw INTERP_KERNEL::Exception(oss.str().c_str());
395 return getFamiliesIds((*it).second);
399 * Sets names of families constituting a group. If data on families of this group is
400 * already present, it is overwritten. Every family in \a fams is checked, and if a
401 family is not yet in \a this mesh, the default group id \c 0 is assigned to it.
402 * \param [in] name - the name of the group of interest.
403 * \param [in] fams - a sequence of names of families constituting the group.
405 void MEDFileMesh::setFamiliesOnGroup(const std::string& name, const std::vector<std::string>& fams)
407 std::string oname(name);
409 for(std::vector<std::string>::const_iterator it1=fams.begin();it1!=fams.end();it1++)
411 std::map<std::string,int>::iterator it2=_families.find(*it1);
412 if(it2==_families.end())
418 * Sets families constituting a group. The families are specified by their ids.
419 * If a family name is not found by its id, an exception is thrown.
420 * If several families have same id, the first one in lexical order is taken.
421 * \param [in] name - the name of the group of interest.
422 * \param [in] famIds - a sequence of ids of families constituting the group.
423 * \throw If a family name is not found by its id.
425 void MEDFileMesh::setFamiliesIdsOnGroup(const std::string& name, const std::vector<int>& famIds)
427 std::string oname(name);
428 std::vector<std::string> fams(famIds.size());
430 for(std::vector<int>::const_iterator it1=famIds.begin();it1!=famIds.end();it1++,i++)
432 std::string name2=getFamilyNameGivenId(*it1);
439 * Returns names of groups including a given family.
440 * \param [in] name - the name of the family of interest.
441 * \return std::vector<std::string> - a sequence of names of groups including the family.
443 std::vector<std::string> MEDFileMesh::getGroupsOnFamily(const std::string& name) const
445 std::vector<std::string> ret;
446 for(std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();it1!=_groups.end();it1++)
448 for(std::vector<std::string>::const_iterator it2=(*it1).second.begin();it2!=(*it1).second.end();it2++)
451 ret.push_back((*it1).first);
459 * Adds an existing family to groups.
460 * \param [in] famName - a name of family to add to \a grps.
461 * \param [in] grps - a sequence of group names to add the family in.
462 * \throw If a family named \a famName not yet exists.
464 void MEDFileMesh::setGroupsOnFamily(const std::string& famName, const std::vector<std::string>& grps)
466 std::string fName(famName);
467 const std::map<std::string,int>::const_iterator it=_families.find(fName);
468 if(it==_families.end())
470 std::vector<std::string> fams=getFamiliesNames();
471 std::ostringstream oss; oss << "No such familyname \"" << fName << "\" !\nAvailable families are :";
472 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
473 throw INTERP_KERNEL::Exception(oss.str().c_str());
475 for(std::vector<std::string>::const_iterator it3=grps.begin();it3!=grps.end();it3++)
477 std::map< std::string, std::vector<std::string> >::iterator it2=_groups.find(*it3);
478 if(it2!=_groups.end())
479 (*it2).second.push_back(fName);
482 std::vector<std::string> grps2(1,fName);
489 * Returns names of all groups of \a this mesh.
490 * \return std::vector<std::string> - a sequence of group names.
492 std::vector<std::string> MEDFileMesh::getGroupsNames() const
494 std::vector<std::string> ret(_groups.size());
496 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++,i++)
502 * Returns names of all families of \a this mesh.
503 * \return std::vector<std::string> - a sequence of family names.
505 std::vector<std::string> MEDFileMesh::getFamiliesNames() const
507 std::vector<std::string> ret(_families.size());
509 for(std::map<std::string, int >::const_iterator it=_families.begin();it!=_families.end();it++,i++)
515 * Changes a name of every family, included in one group only, to be same as the group name.
516 * \throw If there are families with equal names in \a this mesh.
518 void MEDFileMesh::assignFamilyNameWithGroupName()
520 std::map<std::string, std::vector<std::string> > groups(_groups);
521 std::map<std::string,int> newFams;
522 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
524 std::vector<std::string> grps=getGroupsOnFamily((*it).first);
525 if(grps.size()==1 && groups[grps[0]].size()==1)
527 if(newFams.find(grps[0])!=newFams.end())
529 std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << grps[0] << "\" already exists !";
530 throw INTERP_KERNEL::Exception(oss.str().c_str());
532 newFams[grps[0]]=(*it).second;
533 std::vector<std::string>& grps2=groups[grps[0]];
534 std::size_t pos=std::distance(grps2.begin(),std::find(grps2.begin(),grps2.end(),(*it).first));
539 if(newFams.find((*it).first)!=newFams.end())
541 std::ostringstream oss; oss << "MEDFileMesh::assignFamilyNameWithGroupName : Family \"" << (*it).first << "\" already exists !";
542 throw INTERP_KERNEL::Exception(oss.str().c_str());
544 newFams[(*it).first]=(*it).second;
552 * Removes all groups lying on no family. If there is no empty groups, \a this is let untouched.
554 * \return the removed groups.
556 std::vector<std::string> MEDFileMesh::removeEmptyGroups()
558 std::vector<std::string> ret;
559 std::map<std::string, std::vector<std::string> > newGrps;
560 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
562 if((*it).second.empty())
563 ret.push_back((*it).first);
565 newGrps[(*it).first]=(*it).second;
573 * Removes a group from \a this mesh.
574 * \param [in] name - the name of the group to remove.
575 * \throw If no group with such a \a name exists.
577 void MEDFileMesh::removeGroup(const std::string& name)
579 std::string oname(name);
580 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
581 std::vector<std::string> grps=getGroupsNames();
582 if(it==_groups.end())
584 std::ostringstream oss; oss << "No such groupname \"" << name << "\" !\nAvailable groups are :";
585 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
586 throw INTERP_KERNEL::Exception(oss.str().c_str());
592 * Removes a family from \a this mesh.
593 * \param [in] name - the name of the family to remove.
594 * \throw If no family with such a \a name exists.
596 void MEDFileMesh::removeFamily(const std::string& name)
598 std::string oname(name);
599 std::map<std::string, int >::iterator it=_families.find(oname);
600 std::vector<std::string> fams=getFamiliesNames();
601 if(it==_families.end())
603 std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
604 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
605 throw INTERP_KERNEL::Exception(oss.str().c_str());
608 for(std::map<std::string, std::vector<std::string> >::iterator it3=_groups.begin();it3!=_groups.end();it3++)
610 std::vector<std::string>& v=(*it3).second;
611 std::vector<std::string>::iterator it4=std::find(v.begin(),v.end(),oname);
618 * Removes all groups in \a this that are orphan. A group is orphan if this group lies on
619 * a set of families, themselves orphan. A family is said orphan if its id appears nowhere in
620 * family field whatever its level. This method also suppresses the orphan families.
622 * \return - The list of removed groups names.
624 * \sa MEDFileMesh::removeOrphanFamilies.
626 std::vector<std::string> MEDFileMesh::removeOrphanGroups()
628 removeOrphanFamilies();
629 return removeEmptyGroups();
633 * Removes all families in \a this that are orphan. A family is said orphan if its id appears nowhere in
634 * family field whatever its level. Groups are updated in consequence, that is to say all groups lying on orphan family, will see their families list modified.
636 * \return - The list of removed families names.
637 * \sa MEDFileMesh::removeOrphanGroups.
639 std::vector<std::string> MEDFileMesh::removeOrphanFamilies()
641 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allFamIdsInUse=computeAllFamilyIdsInUse();
642 std::vector<std::string> ret;
643 if(!((DataArrayInt*)allFamIdsInUse))
645 ret=getFamiliesNames();
646 _families.clear(); _groups.clear();
649 std::map<std::string,int> famMap;
650 std::map<std::string, std::vector<std::string> > grps(_groups);
651 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
653 if(allFamIdsInUse->presenceOfValue((*it).second))
654 famMap[(*it).first]=(*it).second;
657 ret.push_back((*it).first);
658 std::vector<std::string> grpsOnEraseFam=getGroupsOnFamily((*it).first);
659 for(std::vector<std::string>::const_iterator it2=grpsOnEraseFam.begin();it2!=grpsOnEraseFam.end();it2++)
661 std::map<std::string, std::vector<std::string> >::iterator it3=grps.find(*it2);//it3!=grps.empty() thanks to copy
662 std::vector<std::string>& famv=(*it3).second;
663 std::vector<std::string>::iterator it4=std::find(famv.begin(),famv.end(),(*it).first);//it4!=famv.end() thanks to copy
669 { _families=famMap; _groups=grps; }
674 * This method operates only on maps in \a this. The arrays are not considered here. So this method will remove a family (except "FAMILLE_ZERO" family) if no group lies on it whatever
675 * this family is orphan or not.
677 * \warning this method is different from removeOrphanFamilies that scans family field array to find orphan families.
679 void MEDFileMesh::removeFamiliesReferedByNoGroups()
681 std::map<std::string,int> fams;
682 std::set<std::string> sfams;
683 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
684 sfams.insert((*it).first);
685 for(std::map<std::string, std::vector<std::string> >::const_iterator it0=_groups.begin();it0!=_groups.end();it0++)
686 for(std::vector<std::string>::const_iterator it1=(*it0).second.begin();it1!=(*it0).second.end();it1++)
688 for(std::set<std::string>::const_iterator it=sfams.begin();it!=sfams.end();it++)
689 if(*it!=DFT_FAM_NAME)
690 _families.erase(*it);
694 * This method has no impact on groups. This method only works on families. This method firstly removes families not refered by any groups in \a this, then all unused entities
695 * are put as belonging to family 0 ("FAMILLE_ZERO"). Finally, all orphanFamilies are killed.
696 * This method raises an exception if "FAMILLE_ZERO" is already belonging to a group.
698 * \sa MEDFileMesh::removeOrphanFamilies
700 void MEDFileMesh::rearrangeFamilies()
702 checkOrphanFamilyZero();
703 removeFamiliesReferedByNoGroups();
705 std::vector<int> levels(getNonEmptyLevelsExt());
706 std::set<int> idsRefed;
707 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
708 idsRefed.insert((*it).second);
709 for(std::vector<int>::const_iterator it=levels.begin();it!=levels.end();it++)
711 const DataArrayInt *fams(0);
714 fams=getFamilyFieldAtLevel(*it);
716 catch(INTERP_KERNEL::Exception& e) { }
719 std::vector<bool> v(fams->getNumberOfTuples(),false);
720 for(std::set<int>::const_iterator pt=idsRefed.begin();pt!=idsRefed.end();pt++)
721 fams->switchOnTupleEqualTo(*pt,v);
722 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> unfetchedIds(DataArrayInt::BuildListOfSwitchedOff(v));
723 if(!unfetchedIds->empty())
725 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFams(fams->deepCpy());
726 newFams->setPartOfValuesSimple3(0,unfetchedIds->begin(),unfetchedIds->end(),0,1,1);
727 setFamilyFieldArr(*it,newFams);
730 removeOrphanFamilies();
734 * This method only checks that "FAMILLE_ZERO" is orphan (not belonging to a group).
736 void MEDFileMesh::checkOrphanFamilyZero() const
738 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
740 if(std::find((*it).second.begin(),(*it).second.end(),DFT_FAM_NAME)!=(*it).second.end())
742 std::ostringstream oss; oss << "MEDFileMesh::rearrangeFamilies : Groups \"" << (*it).first << "\" is lying on family \"" << DFT_FAM_NAME << "\" !";
743 throw INTERP_KERNEL::Exception(oss.str().c_str());
749 * Renames a group in \a this mesh.
750 * \param [in] oldName - a current name of the group to rename.
751 * \param [in] newName - a new group name.
752 * \throw If no group named \a oldName exists in \a this mesh.
753 * \throw If a group named \a newName already exists.
755 void MEDFileMesh::changeGroupName(const std::string& oldName, const std::string& newName)
757 std::string oname(oldName);
758 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(oname);
759 std::vector<std::string> grps=getGroupsNames();
760 if(it==_groups.end())
762 std::ostringstream oss; oss << "No such groupname \"" << oldName << "\" !\nAvailable groups are :";
763 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
764 throw INTERP_KERNEL::Exception(oss.str().c_str());
766 std::string nname(newName);
767 std::map<std::string, std::vector<std::string> >::iterator it2=_groups.find(nname);
768 if(it2!=_groups.end())
770 std::ostringstream oss; oss << "Such groupname \"" << newName << "\" already exists ! Kill it before !";
771 throw INTERP_KERNEL::Exception(oss.str().c_str());
773 std::vector<std::string> cpy=(*it).second;
775 _groups[newName]=cpy;
779 * Changes an id of a family in \a this mesh.
780 * This method calls changeFamilyIdArr().
781 * \param [in] oldId - a current id of the family.
782 * \param [in] newId - a new family id.
784 void MEDFileMesh::changeFamilyId(int oldId, int newId)
786 changeFamilyIdArr(oldId,newId);
787 std::map<std::string,int> fam2;
788 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
790 if((*it).second==oldId)
791 fam2[(*it).first]=newId;
793 fam2[(*it).first]=(*it).second;
799 * Renames a family in \a this mesh.
800 * \param [in] oldName - a current name of the family to rename.
801 * \param [in] newName - a new family name.
802 * \throw If no family named \a oldName exists in \a this mesh.
803 * \throw If a family named \a newName already exists.
805 void MEDFileMesh::changeFamilyName(const std::string& oldName, const std::string& newName)
807 std::string oname(oldName);
808 std::map<std::string, int >::iterator it=_families.find(oname);
809 std::vector<std::string> fams=getFamiliesNames();
810 if(it==_families.end())
812 std::ostringstream oss; oss << "No such familyname \"" << oldName << "\" !\nAvailable families are :";
813 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
814 throw INTERP_KERNEL::Exception(oss.str().c_str());
816 std::string nname(newName);
817 std::map<std::string, int >::iterator it2=_families.find(nname);
818 if(it2!=_families.end())
820 std::ostringstream oss; oss << "Such familyname \"" << newName << " already exists ! Kill it before !";
821 throw INTERP_KERNEL::Exception(oss.str().c_str());
823 int cpy=(*it).second;
825 _families[newName]=cpy;
826 for(std::map<std::string, std::vector<std::string> >::iterator it3=_groups.begin();it3!=_groups.end();it3++)
828 std::vector<std::string>& v=(*it3).second;
829 std::vector<std::string>::iterator it4=std::find(v.begin(),v.end(),oname);
836 * Checks if \a this and another mesh contains the same families.
837 * \param [in] other - the mesh to compare with \a this one.
838 * \param [in,out] what - an unused parameter.
839 * \return bool - \c true if number of families and their ids are the same in the two
840 * meshes. Families with the id == \c 0 are not considered.
842 bool MEDFileMesh::areFamsEqual(const MEDFileMesh *other, std::string& what) const
844 if(_families==other->_families)
846 std::map<std::string,int> fam0;
847 std::map<std::string,int> fam1;
848 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
850 fam0[(*it).first]=(*it).second;
851 for(std::map<std::string,int>::const_iterator it=other->_families.begin();it!=other->_families.end();it++)
853 fam1[(*it).first]=(*it).second;
858 * Checks if \a this and another mesh contains the same groups.
859 * \param [in] other - the mesh to compare with \a this one.
860 * \param [in,out] what - a string describing a difference of groups of the two meshes
861 * in case if this method returns \c false.
862 * \return bool - \c true if number of groups and families constituting them are the
863 * same in the two meshes.
865 bool MEDFileMesh::areGrpsEqual(const MEDFileMesh *other, std::string& what) const
867 if(_groups==other->_groups)
870 std::size_t sz=_groups.size();
871 if(sz!=other->_groups.size())
873 what="Groups differ because not same number !\n";
878 std::map<std::string, std::vector<std::string> >::const_iterator it1=_groups.begin();
879 for(std::size_t i=0;i<sz && ret;i++,it1++)
881 std::map<std::string, std::vector<std::string> >::const_iterator it2=other->_groups.find((*it1).first);
882 if(it2!=other->_groups.end())
884 std::set<std::string> s1((*it1).second.begin(),(*it1).second.end());
885 std::set<std::string> s2((*it2).second.begin(),(*it2).second.end());
891 what="A group in first mesh exists not in other !\n";
897 std::ostringstream oss; oss << "Groups description differs :\n";
898 oss << "First group description :\n";
899 for(std::map<std::string, std::vector<std::string> >::const_iterator it=_groups.begin();it!=_groups.end();it++)
901 oss << " Group \"" << (*it).first << "\" on following families :\n";
902 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
903 oss << " \"" << *it2 << "\n";
905 oss << "Second group description :\n";
906 for(std::map<std::string, std::vector<std::string> >::const_iterator it=other->_groups.begin();it!=other->_groups.end();it++)
908 oss << " Group \"" << (*it).first << "\" on following families :\n";
909 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
910 oss << " \"" << *it2 << "\n";
918 * Checks if a group with a given name exists in \a this mesh.
919 * \param [in] groupName - the group name.
920 * \return bool - \c true the group \a groupName exists in \a this mesh.
922 bool MEDFileMesh::existsGroup(const std::string& groupName) const
924 std::string grpName(groupName);
925 return _groups.find(grpName)!=_groups.end();
929 * Checks if a family with a given id exists in \a this mesh.
930 * \param [in] famId - the family id.
931 * \return bool - \c true the family with the id \a famId exists in \a this mesh.
933 bool MEDFileMesh::existsFamily(int famId) const
935 for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
936 if((*it2).second==famId)
942 * Checks if a family with a given name exists in \a this mesh.
943 * \param [in] familyName - the family name.
944 * \return bool - \c true the family \a familyName exists in \a this mesh.
946 bool MEDFileMesh::existsFamily(const std::string& familyName) const
948 std::string fname(familyName);
949 return _families.find(fname)!=_families.end();
953 * Sets an id of a family.
954 * \param [in] familyName - the family name.
955 * \param [in] id - a new id of the family.
957 void MEDFileMesh::setFamilyId(const std::string& familyName, int id)
959 std::string fname(familyName);
963 void MEDFileMesh::setFamilyIdUnique(const std::string& familyName, int id)
965 std::string fname(familyName);
966 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
969 if((*it).first!=familyName)
971 std::ostringstream oss; oss << "MEDFileMesh::setFamilyIdUnique : Family id #" << id << " is already belonging to family with name \"" << (*it).first << "\" !";
972 throw INTERP_KERNEL::Exception(oss.str().c_str());
979 * Adds a family to \a this mesh.
980 * \param [in] familyName - a name of the family.
981 * \param [in] famId - an id of the family.
982 * \throw If a family with the same name or id already exists in \a this mesh.
984 void MEDFileMesh::addFamily(const std::string& familyName, int famId)
986 std::string fname(familyName);
987 std::map<std::string,int>::const_iterator it=_families.find(fname);
988 if(it==_families.end())
990 for(std::map<std::string,int>::const_iterator it2=_families.begin();it2!=_families.end();it2++)
991 if((*it2).second==famId)
993 std::ostringstream oss;
994 oss << "MEDFileMesh::addFamily : Family \"" << (*it2).first << "\" already exists with specified id : " << famId << " !";
995 throw INTERP_KERNEL::Exception(oss.str().c_str());
997 _families[fname]=famId;
1001 if((*it).second!=famId)
1003 std::ostringstream oss;
1004 oss << "MEDFileMesh::addFamily : Family \"" << fname << "\" already exists but has id set to " << (*it).second << " different from asked famId " << famId << " !";
1005 throw INTERP_KERNEL::Exception(oss.str().c_str());
1011 * Creates a group including all mesh entities of given dimension.
1012 * \warning This method does \b not guarantee that the created group includes mesh
1013 * entities of only \a meshDimRelToMaxExt dimension in the case if some family id is
1014 * present in family fields of different dimensions. To assure this, call
1015 * ensureDifferentFamIdsPerLevel() \b before calling this method.
1016 * \param [in] meshDimRelToMaxExt - a relative dimension of mesh entities to include to
1018 * \param [in] groupName - a name of the new group.
1019 * \throw If a group named \a groupName already exists.
1020 * \throw If no mesh entities of dimension \a meshDimRelToMaxExt exist in \a this mesh.
1021 * \throw If no family field of dimension \a meshDimRelToMaxExt is present in \a this mesh.
1023 void MEDFileMesh::createGroupOnAll(int meshDimRelToMaxExt, const std::string& groupName)
1025 std::string grpName(groupName);
1026 std::vector<int> levs=getNonEmptyLevelsExt();
1027 if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)==levs.end())
1029 std::ostringstream oss; oss << "MEDFileMesh::createGroupOnAll : The relative ext dimension " << meshDimRelToMaxExt << " is not available !" << std::endl;
1030 oss << "Available relative ext levels are : ";
1031 std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," "));
1032 throw INTERP_KERNEL::Exception(oss.str().c_str());
1034 if(existsGroup(groupName))
1036 std::ostringstream oss; oss << "MEDFileMesh::createGroupOnAll : The groups \"" << grpName << "\" already exists in this !" << std::endl;
1037 oss << "Already existing groups are : ";
1038 std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," "));
1039 oss << std::endl << "Please choose an another group name or call removeGroup(\"" << grpName << "\") method !";
1040 throw INTERP_KERNEL::Exception(oss.str().c_str());
1042 const DataArrayInt *fieldFamIds=getFamilyFieldAtLevel(meshDimRelToMaxExt);
1044 throw INTERP_KERNEL::Exception("MEDFileMesh::createGroupOnAll : Family field arr ids is not defined for this level !");
1045 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famIds=fieldFamIds->getDifferentValues();
1046 std::vector<std::string> familiesOnWholeGroup;
1047 for(const int *it=famIds->begin();it!=famIds->end();it++)
1050 familiesOnWholeGroup.push_back(findOrCreateAndGiveFamilyWithId(*it,tmp));
1052 _groups[grpName]=familiesOnWholeGroup;
1056 * Ensures that given family ids do not present in family fields of dimensions different
1057 * than given ones. If a family id is present in the family fields of dimensions different
1058 * than the given ones, a new family is created and the whole data is updated accordingly.
1059 * \param [in] famIds - a sequence of family ids to check.
1060 * \param [in] vMeshDimRelToMaxExt - a sequence of relative dimensions to which the \a
1061 * famIds should exclusively belong.
1062 * \return bool - \c true if no modification is done in \a this mesh by this method.
1064 bool MEDFileMesh::keepFamIdsOnlyOnLevs(const std::vector<int>& famIds, const std::vector<int>& vMeshDimRelToMaxExt)
1066 std::set<int> levsInput(vMeshDimRelToMaxExt.begin(),vMeshDimRelToMaxExt.end());
1067 std::vector<int> levs=getNonEmptyLevelsExt();
1068 std::set<int> levs2(levs.begin(),levs.end());
1069 std::vector<int> levsToTest;
1070 std::set_difference(levs2.begin(),levs2.end(),levsInput.begin(),levsInput.end(),std::back_insert_iterator< std::vector<int> >(levsToTest));
1071 std::set<int> famIds2(famIds.begin(),famIds.end());
1074 if(!_families.empty())
1075 maxFamId=getMaxFamilyId()+1;
1076 std::vector<std::string> allFams=getFamiliesNames();
1077 for(std::vector<int>::const_iterator it=levsToTest.begin();it!=levsToTest.end();it++)
1079 const DataArrayInt *fieldFamIds=getFamilyFieldAtLevel(*it);
1082 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famIds3=fieldFamIds->getDifferentValues();
1083 std::vector<int> tmp;
1084 std::set_intersection(famIds3->begin(),famIds3->end(),famIds2.begin(),famIds2.end(),std::back_insert_iterator< std::vector<int> >(tmp));
1085 for(std::vector<int>::const_iterator it2=tmp.begin();it2!=tmp.end();it2++)
1088 std::string famName=getFamilyNameGivenId(*it2);
1089 std::ostringstream oss; oss << "Family_" << maxFamId;
1090 std::string zeName=CreateNameNotIn(oss.str(),allFams);
1091 addFamilyOnAllGroupsHaving(famName,zeName);
1092 _families[zeName]=maxFamId;
1093 (const_cast<DataArrayInt *>(fieldFamIds))->changeValue(*it2,maxFamId);
1102 * Adds a family to a given group in \a this mesh. If the group with a given name does
1103 * not exist, it is created.
1104 * \param [in] grpName - the name of the group to add the family in.
1105 * \param [in] famName - the name of the family to add to the group named \a grpName.
1106 * \throw If \a grpName or \a famName is an empty string.
1107 * \throw If no family named \a famName is present in \a this mesh.
1109 void MEDFileMesh::addFamilyOnGrp(const std::string& grpName, const std::string& famName)
1111 std::string grpn(grpName);
1112 std::string famn(famName);
1113 if(grpn.empty() || famn.empty())
1114 throw INTERP_KERNEL::Exception("MEDFileMesh::addFamilyOnGrp : input strings must be non null !");
1115 std::vector<std::string> fams=getFamiliesNames();
1116 if(std::find(fams.begin(),fams.end(),famn)==fams.end())
1118 std::ostringstream oss; oss << "MEDFileMesh::addFamilyOnGrp : Family \"" << famn << "\" does not exist !" << std::endl;
1119 oss << "Create this family or choose an existing one ! Existing fams are : ";
1120 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," ")); oss << ".";
1121 throw INTERP_KERNEL::Exception(oss.str().c_str());
1123 std::map<std::string, std::vector<std::string> >::iterator it=_groups.find(grpn);
1124 if(it==_groups.end())
1126 _groups[grpn].push_back(famn);
1130 std::vector<std::string>::iterator it2=std::find((*it).second.begin(),(*it).second.end(),famn);
1131 if(it2==(*it).second.end())
1132 (*it).second.push_back(famn);
1137 * This method adds to all groups lying on family with name 'famName' the other family name 'otherFamName'.
1138 * This method is quite underground because it can lead to unconsistency because family 'otherFamName' is \b not added into _families.
1139 * This method is used by MEDFileMesh::keepFamIdsOnlyOnLevs method.
1141 void MEDFileMesh::addFamilyOnAllGroupsHaving(const std::string& famName, const std::string& otherFamName)
1143 std::string famNameCpp(famName);
1144 std::string otherCpp(otherFamName);
1145 for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
1147 std::vector<std::string>& v=(*it).second;
1148 if(std::find(v.begin(),v.end(),famNameCpp)!=v.end())
1150 v.push_back(otherCpp);
1156 * \param [in] ids ids and group name of the new group to add. The ids should be sorted and different each other (MED file norm).
1157 * \parma [in,out] famArr family array on level of interest to be renumbered. The input pointer should be not \c NULL (no check of that will be performed)
1159 void MEDFileMesh::addGroupUnderground(bool isNodeGroup, const DataArrayInt *ids, DataArrayInt *famArr)
1162 throw INTERP_KERNEL::Exception("MEDFileUMesh::addGroup : NULL pointer in input !");
1163 std::string grpName(ids->getName());
1165 throw INTERP_KERNEL::Exception("MEDFileUMesh::addGroup : empty group name ! MED file format do not accept empty group name !");
1166 ids->checkStrictlyMonotonic(true);
1167 famArr->incrRef(); MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famArrTmp(famArr);
1168 std::vector<std::string> grpsNames=getGroupsNames();
1169 if(std::find(grpsNames.begin(),grpsNames.end(),grpName)!=grpsNames.end())
1171 std::ostringstream oss; oss << "MEDFileUMesh::addGroup : Group with name \"" << grpName << "\" already exists ! Destroy it before calling this method !";
1172 throw INTERP_KERNEL::Exception(oss.str().c_str());
1174 std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > allFamIds(getAllNonNullFamilyIds());
1175 allFamIds.erase(std::find(allFamIds.begin(),allFamIds.end(),famArrTmp));
1176 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famIds=famArr->selectByTupleIdSafe(ids->begin(),ids->end());
1177 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> diffFamIds=famIds->getDifferentValues();
1178 std::vector<int> familyIds;
1179 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > idsPerfamiliyIds;
1180 int maxVal=getTheMaxAbsFamilyId()+1;
1181 std::map<std::string,int> families(_families);
1182 std::map<std::string, std::vector<std::string> > groups(_groups);
1183 std::vector<std::string> fams;
1184 bool created(false);
1185 for(const int *famId=diffFamIds->begin();famId!=diffFamIds->end();famId++)
1187 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2Tmp=famIds->getIdsEqual(*famId);
1188 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids2=ids->selectByTupleId(ids2Tmp->begin(),ids2Tmp->end());
1189 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids1=famArr->getIdsEqual(*famId);
1190 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret0(ids1->buildSubstractionOptimized(ids2));
1193 bool isFamPresent=false;
1194 for(std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator itl=allFamIds.begin();itl!=allFamIds.end() && !isFamPresent;itl++)
1195 isFamPresent=(*itl)->presenceOfValue(*famId);
1197 { familyIds.push_back(*famId); idsPerfamiliyIds.push_back(ret0); fams.push_back(FindOrCreateAndGiveFamilyWithId(families,*famId,created)); } // adding *famId in grp
1200 familyIds.push_back(isNodeGroup?maxVal:-maxVal); idsPerfamiliyIds.push_back(ids2);
1201 std::string locFamName=FindOrCreateAndGiveFamilyWithId(families,isNodeGroup?maxVal:-maxVal,created);
1202 fams.push_back(locFamName);
1203 if(existsFamily(*famId))
1205 std::string locFamName2=getFamilyNameGivenId(*famId); std::vector<std::string> v(2); v[0]=locFamName2; v[1]=locFamName;
1206 ChangeAllGroupsContainingFamily(groups,getFamilyNameGivenId(*famId),v);
1209 } // modifying all other groups on *famId to lie on maxVal and lie the grp on maxVal
1213 familyIds.push_back(isNodeGroup?maxVal:-maxVal); idsPerfamiliyIds.push_back(ret0); // modifying all other groups on *famId to lie on maxVal and on maxVal+1
1214 familyIds.push_back(isNodeGroup?maxVal+1:-maxVal-1); idsPerfamiliyIds.push_back(ids2);//grp lie only on maxVal+1
1215 std::string n2(FindOrCreateAndGiveFamilyWithId(families,isNodeGroup?maxVal+1:-maxVal-1,created)); fams.push_back(n2);
1216 if(existsFamily(*famId))
1218 std::string n1(FindOrCreateAndGiveFamilyWithId(families,isNodeGroup?maxVal:-maxVal,created)); std::vector<std::string> v(2); v[0]=n1; v[1]=n2;
1219 ChangeAllGroupsContainingFamily(groups,getFamilyNameGivenId(*famId),v);
1224 for(std::size_t i=0;i<familyIds.size();i++)
1226 DataArrayInt *da=idsPerfamiliyIds[i];
1227 famArr->setPartOfValuesSimple3(familyIds[i],da->begin(),da->end(),0,1,1);
1231 _groups[grpName]=fams;
1234 void MEDFileMesh::changeAllGroupsContainingFamily(const std::string& familyNameToChange, const std::vector<std::string>& newFamiliesNames)
1236 ChangeAllGroupsContainingFamily(_groups,familyNameToChange,newFamiliesNames);
1239 void MEDFileMesh::ChangeAllGroupsContainingFamily(std::map<std::string, std::vector<std::string> >& groups, const std::string& familyNameToChange, const std::vector<std::string>& newFamiliesNames)
1241 std::string fam(familyNameToChange);
1242 for(std::map<std::string, std::vector<std::string> >::iterator it=groups.begin();it!=groups.end();it++)
1244 std::vector<std::string>& fams((*it).second);
1245 std::vector<std::string>::iterator it2=std::find(fams.begin(),fams.end(),fam);
1249 fams.insert(fams.end(),newFamiliesNames.begin(),newFamiliesNames.end());
1255 * Returns a name of the family having a given id or, if no such a family exists, creates
1256 * a new uniquely named family and returns its name.
1257 * \param [in] id - the id of the family whose name is required.
1258 * \param [out] created - returns \c true if the new family has been created, \c false, else.
1259 * \return std::string - the name of the existing or the created family.
1260 * \throw If it is not possible to create a unique family name.
1262 std::string MEDFileMesh::findOrCreateAndGiveFamilyWithId(int id, bool& created)
1264 return FindOrCreateAndGiveFamilyWithId(_families,id,created);
1268 * If it exists a family whose family id is equal to 'id' this method behaves as MEDFileMesh::getFamilyNameGivenId.
1269 * In this case, 'this' internal states remains unchanged and 'created' out parameter will be set to false.
1270 * If there is no family whose family id is equal to 'id' a family is created with a name different from those
1271 * already existing. In this case 'created' will be returned with a value set to true, and internal state
1273 * This method will throws an exception if it is not possible to create a unique family name.
1275 std::string MEDFileMesh::FindOrCreateAndGiveFamilyWithId(std::map<std::string,int>& families, int id, bool& created)
1277 std::vector<std::string> famAlreadyExisting(families.size());
1279 for(std::map<std::string,int>::const_iterator it=families.begin();it!=families.end();it++,ii++)
1281 if((*it).second!=id)
1283 famAlreadyExisting[ii]=(*it).first;
1292 std::ostringstream oss; oss << "Family_" << id;
1293 std::string ret=CreateNameNotIn(oss.str(),famAlreadyExisting);
1299 * Sets names and ids of all families in \a this mesh.
1300 * \param [in] info - a map of a family name to a family id.
1302 void MEDFileMesh::setFamilyInfo(const std::map<std::string,int>& info)
1308 * Sets names of all groups and families constituting them in \a this mesh.
1309 * \param [in] info - a map of a group name to a vector of names of families
1310 * constituting the group.
1312 void MEDFileMesh::setGroupInfo(const std::map<std::string, std::vector<std::string> >&info)
1318 * Returns an id of the family having a given name.
1319 * \param [in] name - the name of the family of interest.
1320 * \return int - the id of the family of interest.
1321 * \throw If no family with such a \a name exists.
1323 int MEDFileMesh::getFamilyId(const std::string& name) const
1325 std::string oname(name);
1326 std::map<std::string, int>::const_iterator it=_families.find(oname);
1327 std::vector<std::string> fams=getFamiliesNames();
1328 if(it==_families.end())
1330 std::ostringstream oss; oss << "No such familyname \"" << name << "\" !\nAvailable families are :";
1331 std::copy(fams.begin(),fams.end(),std::ostream_iterator<std::string>(oss," "));
1332 throw INTERP_KERNEL::Exception(oss.str().c_str());
1334 return (*it).second;
1338 * Returns ids of the families having given names.
1339 * \param [in] fams - a sequence of the names of families of interest.
1340 * \return std::vector<int> - a sequence of the ids of families of interest.
1341 * \throw If \a fams contains a name of an inexistent family.
1343 std::vector<int> MEDFileMesh::getFamiliesIds(const std::vector<std::string>& fams) const
1345 std::vector<int> ret(fams.size());
1347 for(std::vector<std::string>::const_iterator it=fams.begin();it!=fams.end();it++,i++)
1349 std::map<std::string, int>::const_iterator it2=_families.find(*it);
1350 if(it2==_families.end())
1352 std::vector<std::string> fams2=getFamiliesNames();
1353 std::ostringstream oss; oss << "No such familyname \"" << *it << "\" in input list !\nAvailable families are :";
1354 std::copy(fams2.begin(),fams2.end(),std::ostream_iterator<std::string>(oss," "));
1355 throw INTERP_KERNEL::Exception(oss.str().c_str());
1357 ret[i]=(*it2).second;
1363 * Returns a maximal abs(id) of families in \a this mesh.
1364 * \return int - the maximal norm of family id.
1365 * \throw If there are no families in \a this mesh.
1367 int MEDFileMesh::getMaxAbsFamilyId() const
1369 if(_families.empty())
1370 throw INTERP_KERNEL::Exception("MEDFileMesh::getMaxFamilyId : no families set !");
1371 int ret=-std::numeric_limits<int>::max();
1372 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1374 ret=std::max(std::abs((*it).second),ret);
1380 * Returns a maximal id of families in \a this mesh.
1381 * \return int - the maximal family id.
1382 * \throw If there are no families in \a this mesh.
1384 int MEDFileMesh::getMaxFamilyId() const
1386 if(_families.empty())
1387 throw INTERP_KERNEL::Exception("MEDFileMesh::getMaxFamilyId : no families set !");
1388 int ret=-std::numeric_limits<int>::max();
1389 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1391 ret=std::max((*it).second,ret);
1397 * Returns a minimal id of families in \a this mesh.
1398 * \return int - the minimal family id.
1399 * \throw If there are no families in \a this mesh.
1401 int MEDFileMesh::getMinFamilyId() const
1403 if(_families.empty())
1404 throw INTERP_KERNEL::Exception("MEDFileMesh::getMinFamilyId : no families set !");
1405 int ret=std::numeric_limits<int>::max();
1406 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1408 ret=std::min((*it).second,ret);
1414 * Returns a maximal id of families in \a this mesh. Not only named families are
1415 * considered but all family fields as well.
1416 * \return int - the maximal family id.
1418 int MEDFileMesh::getTheMaxAbsFamilyId() const
1420 int m1=-std::numeric_limits<int>::max();
1421 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1422 m1=std::max(std::abs((*it).second),m1);
1423 int m2=getMaxAbsFamilyIdInArrays();
1424 return std::max(m1,m2);
1428 * Returns a maximal id of families in \a this mesh. Not only named families are
1429 * considered but all family fields as well.
1430 * \return int - the maximal family id.
1432 int MEDFileMesh::getTheMaxFamilyId() const
1434 int m1=-std::numeric_limits<int>::max();
1435 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1436 m1=std::max((*it).second,m1);
1437 int m2=getMaxFamilyIdInArrays();
1438 return std::max(m1,m2);
1442 * Returns a minimal id of families in \a this mesh. Not only named families are
1443 * considered but all family fields as well.
1444 * \return int - the minimal family id.
1446 int MEDFileMesh::getTheMinFamilyId() const
1448 int m1=std::numeric_limits<int>::max();
1449 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1450 m1=std::min((*it).second,m1);
1451 int m2=getMinFamilyIdInArrays();
1452 return std::min(m1,m2);
1456 * This method only considers the maps. The contain of family array is ignored here.
1458 * \sa MEDFileMesh::computeAllFamilyIdsInUse
1460 DataArrayInt *MEDFileMesh::getAllFamiliesIdsReferenced() const
1462 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret=DataArrayInt::New();
1464 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1465 v.insert((*it).second);
1466 ret->alloc((int)v.size(),1);
1467 std::copy(v.begin(),v.end(),ret->getPointer());
1472 * This method does not consider map of family name, family id. Only family field array on different levels is considered.
1474 * \sa MEDFileMesh::getAllFamiliesIdsReferenced
1476 DataArrayInt *MEDFileMesh::computeAllFamilyIdsInUse() const
1478 std::vector<int> famLevs=getFamArrNonEmptyLevelsExt();
1479 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret;
1480 for(std::vector<int>::const_iterator it=famLevs.begin();it!=famLevs.end();it++)
1482 const DataArrayInt *arr=getFamilyFieldAtLevel(*it);//arr not null due to spec of getFamArrNonEmptyLevelsExt
1483 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> dv=arr->getDifferentValues();
1484 if((DataArrayInt *) ret)
1485 ret=dv->buildUnion(ret);
1493 * true is returned if no modification has been needed. false if family
1494 * renumbering has been needed.
1496 bool MEDFileMesh::ensureDifferentFamIdsPerLevel()
1498 std::vector<int> levs=getNonEmptyLevelsExt();
1499 std::set<int> allFamIds;
1500 int maxId=getMaxFamilyId()+1;
1501 std::map<int,std::vector<int> > famIdsToRenum;
1502 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
1504 const DataArrayInt *fam=getFamilyFieldAtLevel(*it);
1507 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1509 std::set_intersection(tmp->begin(),tmp->end(),allFamIds.begin(),allFamIds.end(),std::inserter(r2,r2.end()));
1511 famIdsToRenum[*it].insert(famIdsToRenum[*it].end(),r2.begin(),r2.end());
1513 std::set_union(tmp->begin(),tmp->end(),allFamIds.begin(),allFamIds.end(),std::inserter(r3,r3.end()));
1516 if(famIdsToRenum.empty())
1518 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
1519 for(std::map<int,std::vector<int> >::const_iterator it2=famIdsToRenum.begin();it2!=famIdsToRenum.end();it2++)
1521 DataArrayInt *fam=const_cast<DataArrayInt *>(getFamilyFieldAtLevel((*it2).first));
1522 int *famIdsToChange=fam->getPointer();
1523 std::map<int,int> ren;
1524 for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++,maxId++)
1526 if(allIds->presenceOfValue(*it3))
1528 std::string famName=getFamilyNameGivenId(*it3);
1529 std::vector<std::string> grps=getGroupsOnFamily(famName);
1532 std::string newFam=findOrCreateAndGiveFamilyWithId(maxId,dummy);
1533 for(std::vector<std::string>::const_iterator it4=grps.begin();it4!=grps.end();it4++)
1534 addFamilyOnGrp((*it4),newFam);
1537 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=fam->getIdsEqualList(&(*it2).second[0],&(*it2).second[0]+(*it2).second.size());
1538 for(const int *id=ids->begin();id!=ids->end();id++)
1539 famIdsToChange[*id]=ren[famIdsToChange[*id]];
1545 * This method normalizes fam id with the policy explained underneath. This policy is close to those implemented in SMESH.
1546 * Level #0 famids > 0, Level #-1 famids < 0, Level #-2 famids=0, Level #1 famids=0
1547 * This policy is those used by SMESH and Trio and that is the opposite of those in MED file.
1548 * This method will throw an exception if a same family id is detected in different level.
1549 * \warning This policy is the opposite of those in MED file documentation ...
1551 void MEDFileMesh::normalizeFamIdsTrio()
1553 ensureDifferentFamIdsPerLevel();
1554 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
1555 std::vector<int> levs=getNonEmptyLevelsExt();
1556 std::set<int> levsS(levs.begin(),levs.end());
1557 std::set<std::string> famsFetched;
1558 std::map<std::string,int> families;
1559 if(std::find(levs.begin(),levs.end(),0)!=levs.end())
1562 const DataArrayInt *fam=getFamilyFieldAtLevel(0);
1566 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1567 std::map<int,int> ren;
1568 for(const int *it=tmp->begin();it!=tmp->end();it++,refId++)
1570 int nbOfTuples=fam->getNumberOfTuples();
1571 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1572 for(int *w=start;w!=start+nbOfTuples;w++)
1574 for(const int *it=tmp->begin();it!=tmp->end();it++)
1576 if(allIds->presenceOfValue(*it))
1578 std::string famName=getFamilyNameGivenId(*it);
1579 families[famName]=ren[*it];
1580 famsFetched.insert(famName);
1585 if(std::find(levs.begin(),levs.end(),-1)!=levs.end())
1588 const DataArrayInt *fam=getFamilyFieldAtLevel(-1);
1592 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1593 std::map<int,int> ren;
1594 for(const int *it=tmp->begin();it!=tmp->end();it++,refId--)
1596 int nbOfTuples=fam->getNumberOfTuples();
1597 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1598 for(int *w=start;w!=start+nbOfTuples;w++)
1600 for(const int *it=tmp->begin();it!=tmp->end();it++)
1602 if(allIds->presenceOfValue(*it))
1604 std::string famName=getFamilyNameGivenId(*it);
1605 families[famName]=ren[*it];
1606 famsFetched.insert(famName);
1611 for(std::set<int>::const_iterator it2=levsS.begin();it2!=levsS.end();it2++)
1613 DataArrayInt *fam=const_cast<DataArrayInt*>(getFamilyFieldAtLevel(*it2));
1616 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1617 fam->fillWithZero();
1618 for(const int *it3=tmp->begin();it3!=tmp->end();it3++)
1619 if(allIds->presenceOfValue(*it3))
1621 std::string famName=getFamilyNameGivenId(*it3);
1622 families[famName]=0;
1623 famsFetched.insert(famName);
1628 std::vector<std::string> allFams=getFamiliesNames();
1629 std::set<std::string> allFamsS(allFams.begin(),allFams.end());
1630 std::set<std::string> unFetchedIds;
1631 std::set_difference(allFamsS.begin(),allFamsS.end(),famsFetched.begin(),famsFetched.end(),std::inserter(unFetchedIds,unFetchedIds.end()));
1632 for(std::set<std::string>::const_iterator it4=unFetchedIds.begin();it4!=unFetchedIds.end();it4++)
1633 families[*it4]=_families[*it4];
1638 * This method normalizes fam id with the following policy.
1639 * Level #0 famids < 0, Level #-1 famids < 0 and for Level #1 famids >= 0
1640 * This policy is those defined in the MED file format but is the opposite of those implemented in SMESH and Trio.
1641 * This method will throw an exception if a same family id is detected in different level.
1643 void MEDFileMesh::normalizeFamIdsMEDFile()
1645 ensureDifferentFamIdsPerLevel();
1646 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> allIds=getAllFamiliesIdsReferenced();
1647 std::vector<int> levs=getNonEmptyLevelsExt();
1648 std::set<int> levsS(levs.begin(),levs.end());
1649 std::set<std::string> famsFetched;
1650 std::map<std::string,int> families;
1652 if(std::find(levs.begin(),levs.end(),1)!=levs.end())
1655 const DataArrayInt *fam=getFamilyFieldAtLevel(1);
1658 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1659 std::map<int,int> ren;
1660 for(const int *it=tmp->begin();it!=tmp->end();it++,refId++)
1662 int nbOfTuples=fam->getNumberOfTuples();
1663 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1664 for(int *w=start;w!=start+nbOfTuples;w++)
1666 for(const int *it=tmp->begin();it!=tmp->end();it++)
1668 if(allIds->presenceOfValue(*it))
1670 std::string famName=getFamilyNameGivenId(*it);
1671 families[famName]=ren[*it];
1672 famsFetched.insert(famName);
1678 for(std::set<int>::const_reverse_iterator it2=levsS.rbegin();it2!=levsS.rend();it2++)
1680 const DataArrayInt *fam=getFamilyFieldAtLevel(*it2);
1683 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp=fam->getDifferentValues();
1684 std::map<int,int> ren;
1685 for(const int *it=tmp->begin();it!=tmp->end();it++,refId--)
1687 int nbOfTuples=fam->getNumberOfTuples();
1688 int *start=const_cast<DataArrayInt *>(fam)->getPointer();
1689 for(int *w=start;w!=start+nbOfTuples;w++)
1691 for(const int *it=tmp->begin();it!=tmp->end();it++)
1693 if(allIds->presenceOfValue(*it))
1695 std::string famName=getFamilyNameGivenId(*it);
1696 families[famName]=ren[*it];
1697 famsFetched.insert(famName);
1703 std::vector<std::string> allFams=getFamiliesNames();
1704 std::set<std::string> allFamsS(allFams.begin(),allFams.end());
1705 std::set<std::string> unFetchedIds;
1706 std::set_difference(allFamsS.begin(),allFamsS.end(),famsFetched.begin(),famsFetched.end(),std::inserter(unFetchedIds,unFetchedIds.end()));
1707 for(std::set<std::string>::const_iterator it4=unFetchedIds.begin();it4!=unFetchedIds.end();it4++)
1708 families[*it4]=_families[*it4];
1713 * Returns a name of the family by its id. If there are several families having the given
1714 * id, the name first in lexical order is returned.
1715 * \param [in] id - the id of the family whose name is required.
1716 * \return std::string - the name of the found family.
1717 * \throw If no family with the given \a id exists.
1719 std::string MEDFileMesh::getFamilyNameGivenId(int id) const
1721 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
1722 if((*it).second==id)
1724 std::ostringstream oss; oss << "MEDFileUMesh::getFamilyNameGivenId : no such family id : " << id;
1725 throw INTERP_KERNEL::Exception(oss.str().c_str());
1729 * Returns a string describing \a this mesh. This description includes the mesh name and
1730 * the mesh description string.
1731 * \return std::string - the mesh information string.
1733 std::string MEDFileMesh::simpleRepr() const
1735 std::ostringstream oss;
1736 oss << "(*************************************)\n(* GENERAL INFORMATION ON THE MESH : *)\n(*************************************)\n";
1737 oss << "- Name of the mesh : <<" << getName() << ">>\n";
1738 oss << "- Description associated to the mesh : " << getDescription() << std::endl;
1743 * This method is nearly like getFamilyFieldAtLevel method. Except that if the array does not exist at the specified level \a meshDimRelToMaxExt
1744 * an empty one is created.
1746 DataArrayInt *MEDFileMesh::getOrCreateAndGetFamilyFieldAtLevel(int meshDimRelToMaxExt)
1748 DataArrayInt *ret(getFamilyFieldAtLevel(meshDimRelToMaxExt));
1751 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr(DataArrayInt::New());
1752 arr->alloc(getSizeAtLevel(meshDimRelToMaxExt),1);
1753 arr->fillWithZero();
1754 setFamilyFieldArr(meshDimRelToMaxExt,arr);
1755 return getFamilyFieldAtLevel(meshDimRelToMaxExt);
1759 * Returns ids of mesh entities contained in a given group of a given dimension.
1760 * \param [in] meshDimRelToMaxExt - a relative dimension of the mesh entities whose ids
1762 * \param [in] grp - the name of the group of interest.
1763 * \param [in] renum - if \c true, the optional numbers of entities, if available, are
1764 * returned instead of ids.
1765 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
1766 * numbers, if available and required, of mesh entities of the group. The caller
1767 * is to delete this array using decrRef() as it is no more needed.
1768 * \throw If the name of a nonexistent group is specified.
1769 * \throw If the family field is missing for \a meshDimRelToMaxExt.
1771 DataArrayInt *MEDFileMesh::getGroupArr(int meshDimRelToMaxExt, const std::string& grp, bool renum) const
1773 std::vector<std::string> tmp(1);
1775 DataArrayInt *ret=getGroupsArr(meshDimRelToMaxExt,tmp,renum);
1781 * Returns ids of mesh entities contained in given groups of a given dimension.
1782 * \param [in] meshDimRelToMaxExt - a relative dimension of the mesh entities whose ids
1784 * \param [in] grps - the names of the groups of interest.
1785 * \param [in] renum - if \c true, the optional numbers of entities, if available, are
1786 * returned instead of ids.
1787 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
1788 * numbers, if available and required, of mesh entities of the groups. The caller
1789 * is to delete this array using decrRef() as it is no more needed.
1790 * \throw If the name of a nonexistent group is present in \a grps.
1791 * \throw If the family field is missing for \a meshDimRelToMaxExt.
1793 DataArrayInt *MEDFileMesh::getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const
1795 std::vector<std::string> fams2=getFamiliesOnGroups(grps);
1796 return getFamiliesArr(meshDimRelToMaxExt,fams2,renum);
1800 * Returns ids of mesh entities contained in a given family of a given dimension.
1801 * \param [in] meshDimRelToMaxExt - a relative dimension of the mesh entities whose ids
1803 * \param [in] fam - the name of the family of interest.
1804 * \param [in] renum - if \c true, the optional numbers of entities, if available, are
1805 * returned instead of ids.
1806 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
1807 * numbers, if available and required, of mesh entities of the family. The caller
1808 * is to delete this array using decrRef() as it is no more needed.
1809 * \throw If the family field is missing for \a meshDimRelToMaxExt.
1811 DataArrayInt *MEDFileMesh::getFamilyArr(int meshDimRelToMaxExt, const std::string& fam, bool renum) const
1813 std::vector<std::string> tmp(1);
1815 DataArrayInt *ret=getFamiliesArr(meshDimRelToMaxExt,tmp,renum);
1821 * Returns ids of nodes contained in a given group.
1822 * \param [in] grp - the name of the group of interest.
1823 * \param [in] renum - if \c true, the optional numbers of nodes, if available, are
1824 * returned instead of ids.
1825 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
1826 * numbers, if available and required, of nodes of the group. The caller
1827 * is to delete this array using decrRef() as it is no more needed.
1828 * \throw If the name of a nonexistent group is specified.
1829 * \throw If the family field is missing for nodes.
1831 DataArrayInt *MEDFileMesh::getNodeGroupArr(const std::string& grp, bool renum) const
1833 std::vector<std::string> tmp(1);
1835 DataArrayInt *ret=getNodeGroupsArr(tmp,renum);
1841 * Returns ids of nodes contained in given groups.
1842 * \param [in] grps - the names of the groups of interest.
1843 * \param [in] renum - if \c true, the optional numbers of nodes, if available, are
1844 * returned instead of ids.
1845 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
1846 * numbers, if available and required, of nodes of the groups. The caller
1847 * is to delete this array using decrRef() as it is no more needed.
1848 * \throw If the name of a nonexistent group is present in \a grps.
1849 * \throw If the family field is missing for nodes.
1851 DataArrayInt *MEDFileMesh::getNodeGroupsArr(const std::vector<std::string>& grps, bool renum) const
1853 return getGroupsArr(1,grps,renum);
1857 * Returns ids of nodes contained in a given group.
1858 * \param [in] grp - the name of the group of interest.
1859 * \param [in] renum - if \c true, the optional numbers of nodes, if available, are
1860 * returned instead of ids.
1861 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
1862 * numbers, if available and required, of nodes of the group. The caller
1863 * is to delete this array using decrRef() as it is no more needed.
1864 * \throw If the name of a nonexistent group is specified.
1865 * \throw If the family field is missing for nodes.
1867 DataArrayInt *MEDFileMesh::getNodeFamilyArr(const std::string& fam, bool renum) const
1869 std::vector<std::string> tmp(1);
1871 DataArrayInt *ret=getNodeFamiliesArr(tmp,renum);
1877 * Returns ids of nodes contained in given families.
1878 * \param [in] fams - the names of the families of interest.
1879 * \param [in] renum - if \c true, the optional numbers of nodes, if available, are
1880 * returned instead of ids.
1881 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
1882 * numbers, if available and required, of nodes of the families. The caller
1883 * is to delete this array using decrRef() as it is no more needed.
1884 * \throw If the family field is missing for nodes.
1886 DataArrayInt *MEDFileMesh::getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum) const
1888 return getFamiliesArr(1,fams,renum);
1892 * Adds groups of given dimension and creates corresponding families and family fields
1893 * given ids of mesh entities of each group.
1894 * \param [in] meshDimRelToMaxExt - the relative mesh dimension of given mesh entities.
1895 * \param [in] grps - a sequence of arrays of ids each describing a group.
1896 * \param [in] renum - \c true means that \a grps contains not ids but optional numbers
1898 * \throw If names of some groups in \a grps are equal.
1899 * \throw If \a grps includes a group with an empty name.
1900 * \throw If \a grps includes invalid ids (or numbers if \a renum == \c true ).
1901 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
1903 void MEDFileMesh::setGroupsAtLevel(int meshDimRelToMaxExt, const std::vector<const DataArrayInt *>& grps, bool renum)
1907 std::set<std::string> grpsName;
1908 std::vector<std::string> grpsName2(grps.size());
1911 for(std::vector<const DataArrayInt *>::const_iterator it=grps.begin();it!=grps.end();it++,i++)
1913 grpsName.insert((*it)->getName());
1914 grpsName2[i]=(*it)->getName();
1916 if(grpsName.size()!=grps.size())
1917 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different each other !");
1918 if(grpsName.find(std::string(""))!=grpsName.end())
1919 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsAtLevel : groups name must be different empty string !");
1920 int sz=getSizeAtLevel(meshDimRelToMaxExt);
1921 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam;
1922 std::vector< std::vector<int> > fidsOfGroups;
1925 fam=DataArrayInt::MakePartition(grps,sz,fidsOfGroups);
1929 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grps2(grps.size());
1930 for(unsigned int ii=0;ii<grps.size();ii++)
1932 grps2[ii]=MEDFileUMeshSplitL1::Renumber(getRevNumberFieldAtLevel(meshDimRelToMaxExt),grps[ii]);
1933 grps2[ii]->setName(grps[ii]->getName());
1935 std::vector<const DataArrayInt *> grps3(grps2.begin(),grps2.end());
1936 fam=DataArrayInt::MakePartition(grps3,sz,fidsOfGroups);
1939 if(!_families.empty())
1940 offset=getMaxAbsFamilyId()+1;
1941 TranslateFamilyIds(meshDimRelToMaxExt==1?offset:-offset,fam,fidsOfGroups);
1942 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=fam->getDifferentValues();
1943 appendFamilyEntries(ids,fidsOfGroups,grpsName2);
1944 setFamilyFieldArr(meshDimRelToMaxExt,fam);
1948 * This method append into '_families' attribute the families whose ids are in 'famIds'. Warning 'famIds' are expected to be ids
1949 * not in '_families'. Groups information are given in parameters in order to give to families representative names.
1950 * For the moment, the two last input parameters are not taken into account.
1952 void MEDFileMesh::appendFamilyEntries(const DataArrayInt *famIds, const std::vector< std::vector<int> >& fidsOfGrps, const std::vector<std::string>& grpNames)
1954 std::map<int,std::string> famInv;
1955 for(const int *it=famIds->begin();it!=famIds->end();it++)
1957 std::ostringstream oss;
1958 oss << "Family_" << (*it);
1959 _families[oss.str()]=(*it);
1960 famInv[*it]=oss.str();
1963 for(std::vector< std::vector<int> >::const_iterator it1=fidsOfGrps.begin();it1!=fidsOfGrps.end();it1++,i++)
1965 for(std::vector<int>::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
1967 _groups[grpNames[i]].push_back(famInv[*it2]);
1972 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileMesh::getAllGeoTypes() const
1974 std::vector<int> levs(getNonEmptyLevels());
1975 std::vector<INTERP_KERNEL::NormalizedCellType> ret;
1976 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
1978 std::vector<INTERP_KERNEL::NormalizedCellType> elts(getGeoTypesAtLevel(*it));
1979 ret.insert(ret.end(),elts.begin(),elts.end());
1984 std::vector<int> MEDFileMesh::getDistributionOfTypes(int meshDimRelToMax) const
1986 MEDCouplingAutoRefCountObjectPtr<MEDCouplingMesh> mLev(getGenMeshAtLevel(meshDimRelToMax));
1987 return mLev->getDistributionOfTypes();
1990 void MEDFileMesh::TranslateFamilyIds(int offset, DataArrayInt *famArr, std::vector< std::vector<int> >& famIdsPerGrp)
1992 famArr->applyLin(offset>0?1:-1,offset,0);
1993 for(std::vector< std::vector<int> >::iterator it1=famIdsPerGrp.begin();it1!=famIdsPerGrp.end();it1++)
1996 std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::negate<int>());
1997 std::transform((*it1).begin(),(*it1).end(),(*it1).begin(),std::bind2nd(std::plus<int>(),offset));
2002 * Warning no check is done on 'nameTry' in parameter. It should be non empty.
2003 * This method returns a name close to 'nameTry' so that it is not already into 'namesToAvoid'.
2004 * If this method fails to find such a name it will throw an exception.
2006 std::string MEDFileMesh::CreateNameNotIn(const std::string& nameTry, const std::vector<std::string>& namesToAvoid)
2009 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),nameTry)==namesToAvoid.end())
2012 std::size_t len=nameTry.length();
2013 for(std::size_t ii=1;ii<len;ii++)
2015 std::string tmp=nameTry.substr(ii,len-ii);
2016 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp)==namesToAvoid.end())
2022 for(std::size_t i=1;i<30;i++)
2024 std::string tmp1(nameTry.at(0),i);
2026 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp1)==namesToAvoid.end())
2032 for(std::vector<std::string>::const_iterator it2=namesToAvoid.begin();it2!=namesToAvoid.end();it2++)
2034 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tmp2)==namesToAvoid.end())
2036 throw INTERP_KERNEL::Exception("MEDFileMesh::CreateNameNotIn : impossible to find a not already used name !");
2039 int MEDFileMesh::PutInThirdComponentOfCodeOffset(std::vector<int>& code, int strt)
2041 std::size_t nbOfChunks=code.size()/3;
2042 if(code.size()%3!=0)
2043 throw INTERP_KERNEL::Exception("MEDFileMesh::PutInThirdComponentOfCodeOffset : code has invalid size : should be of size 3*x !");
2045 for(std::size_t i=0;i<nbOfChunks;i++)
2054 * This method should be called by any set* method of subclasses to deal automatically with _name attribute.
2055 * If _name attribute is empty the name of 'm' if taken as _name attribute.
2056 * If _name is not empty and that 'm' has the same name nothing is done.
2057 * If _name is not emplt and that 'm' has \b NOT the same name an exception is thrown.
2059 void MEDFileMesh::dealWithTinyInfo(const MEDCouplingMesh *m)
2062 throw INTERP_KERNEL::Exception("MEDFileMesh::dealWithTinyInfo : input mesh in NULL !");
2067 std::string name(m->getName());
2072 std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : name of current MEDfile mesh is '" << _name << "' whereas name of input mesh is : '";
2073 oss << name << "' ! Names must match !";
2074 throw INTERP_KERNEL::Exception(oss.str().c_str());
2078 if(_desc_name.empty())
2079 _desc_name=m->getDescription();
2082 std::string name(m->getDescription());
2085 if(_desc_name!=name)
2087 std::ostringstream oss; oss << "MEDFileMesh::dealWithTinyInfo : description of current MEDfile mesh is '" << _desc_name << "' whereas name of input mesh is : '";
2088 oss << name << "' ! Names must match !";
2089 throw INTERP_KERNEL::Exception(oss.str().c_str());
2095 void MEDFileMesh::getFamilyRepr(std::ostream& oss) const
2097 oss << "(**************************)\n(* FAMILIES OF THE MESH : *)\n(**************************)\n";
2098 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
2100 oss << "- Family with name \"" << (*it).first << "\" with number " << (*it).second << std::endl;
2101 oss << " - Groups lying on this family : ";
2102 std::vector<std::string> grps=getGroupsOnFamily((*it).first);
2103 std::copy(grps.begin(),grps.end(),std::ostream_iterator<std::string>(oss," "));
2104 oss << std::endl << std::endl;
2109 * Returns a new MEDFileUMesh holding the mesh data that has been read from a given MED
2110 * file. The mesh to load is specified by its name and numbers of a time step and an
2112 * \param [in] fileName - the name of MED file to read.
2113 * \param [in] mName - the name of the mesh to read.
2114 * \param [in] dt - the number of a time step.
2115 * \param [in] it - the number of an iteration.
2116 * \return MEDFileUMesh * - a new instance of MEDFileUMesh. The caller is to delete this
2117 * mesh using decrRef() as it is no more needed.
2118 * \throw If the file is not readable.
2119 * \throw If there is no mesh with given attributes in the file.
2120 * \throw If the mesh in the file is not an unstructured one.
2122 MEDFileUMesh *MEDFileUMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
2124 MEDFileUtilities::CheckFileForRead(fileName);
2125 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
2126 return new MEDFileUMesh(fid,mName,dt,it,mrs);
2130 * Returns a new MEDFileUMesh holding the mesh data that has been read from a given MED
2131 * file. The first mesh in the file is loaded.
2132 * \param [in] fileName - the name of MED file to read.
2133 * \return MEDFileUMesh * - a new instance of MEDFileUMesh. The caller is to delete this
2134 * mesh using decrRef() as it is no more needed.
2135 * \throw If the file is not readable.
2136 * \throw If there is no meshes in the file.
2137 * \throw If the mesh in the file is not an unstructured one.
2139 MEDFileUMesh *MEDFileUMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
2141 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
2144 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
2145 throw INTERP_KERNEL::Exception(oss.str().c_str());
2147 MEDFileUtilities::CheckFileForRead(fileName);
2148 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
2150 ParaMEDMEM::MEDCouplingMeshType meshType;
2152 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
2153 return new MEDFileUMesh(fid,ms.front(),dt,it,mrs);
2157 * Returns an empty instance of MEDFileUMesh.
2158 * \return MEDFileUMesh * - a new instance of MEDFileUMesh. The caller is to delete this
2159 * mesh using decrRef() as it is no more needed.
2161 MEDFileUMesh *MEDFileUMesh::New()
2163 return new MEDFileUMesh;
2167 * This method loads from file with name \a fileName the mesh called \a mName as New does. The difference is that
2168 * here only a part of cells contained in the file will be loaded. The selection of cell is specified using the two consecutive parameters
2169 * \a types and \a slicPerTyp. This method allows to load from a mesh (typically huge) in a MED file a part of cells of that mesh.
2170 * The part of cells is specified using triplet (start,stop,step) for each geometric type. Only nodes lying on selected cells will be loaded to reduce
2171 * at most the memory consumtion.
2173 * \param [in] fileName - the name of the file.
2174 * \param [in] mName - the name of the mesh to be read.
2175 * \param [in] types - the list of the geo types of which some part will be taken. A geometric type in \a types must appear only once at most.
2176 * \param [in] slicPerType - an array of size 3 times larger than \a types that specifies for each type in \a types (in the same order) resp the start, the stop and the step.
2177 * \param [in] dt - the iteration, that is to say the first element of the pair that locates the asked time step.
2178 * \param [in] it - the order, that is to say the second element of the pair that locates the asked time step.
2179 * \param [in] mrs - the request for what to be loaded.
2180 * \return MEDFileUMesh * - a new instance of MEDFileUMesh. The caller is to delete this mesh using decrRef() as it is no more needed.
2182 MEDFileUMesh *MEDFileUMesh::LoadPartOf(const std::string& fileName, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
2184 MEDFileUtilities::CheckFileForRead(fileName);
2185 MEDFileUtilities::AutoFid fid(MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY));
2186 return MEDFileUMesh::LoadPartOf(fid,mName,types,slicPerTyp,dt,it,mrs);
2190 * Please refer to the other MEDFileUMesh::LoadPartOf method that has the same semantic and the same parameter (excepted the first).
2191 * This method is \b NOT wrapped into python.
2193 MEDFileUMesh *MEDFileUMesh::LoadPartOf(med_idt fid, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
2195 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(MEDFileUMesh::New());
2196 ret->loadPartUMeshFromFile(fid,mName,types,slicPerTyp,dt,it,mrs);
2200 std::size_t MEDFileUMesh::getHeapMemorySizeWithoutChildren() const
2202 std::size_t ret(MEDFileMesh::getHeapMemorySizeWithoutChildren());
2203 ret+=_ms.capacity()*(sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1>));
2207 std::vector<const BigMemoryObject *> MEDFileUMesh::getDirectChildrenWithNull() const
2209 std::vector<const BigMemoryObject *> ret(MEDFileMesh::getDirectChildrenWithNull());
2210 ret.push_back((const DataArrayDouble*)_coords);
2211 ret.push_back((const DataArrayInt *)_fam_coords);
2212 ret.push_back((const DataArrayInt *)_num_coords);
2213 ret.push_back((const DataArrayInt *)_rev_num_coords);
2214 ret.push_back((const DataArrayAsciiChar *)_name_coords);
2215 ret.push_back((const PartDefinition *)_part_coords);
2216 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2217 ret.push_back((const MEDFileUMeshSplitL1*) *it);
2221 MEDFileMesh *MEDFileUMesh::shallowCpy() const
2223 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=new MEDFileUMesh(*this);
2227 MEDFileMesh *MEDFileUMesh::createNewEmpty() const
2229 return new MEDFileUMesh;
2232 MEDFileMesh *MEDFileUMesh::deepCpy() const
2234 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret=new MEDFileUMesh(*this);
2235 if((const DataArrayDouble*)_coords)
2236 ret->_coords=_coords->deepCpy();
2237 if((const DataArrayInt*)_fam_coords)
2238 ret->_fam_coords=_fam_coords->deepCpy();
2239 if((const DataArrayInt*)_num_coords)
2240 ret->_num_coords=_num_coords->deepCpy();
2241 if((const DataArrayInt*)_rev_num_coords)
2242 ret->_rev_num_coords=_rev_num_coords->deepCpy();
2243 if((const DataArrayAsciiChar*)_name_coords)
2244 ret->_name_coords=_name_coords->deepCpy();
2246 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++)
2248 if((const MEDFileUMeshSplitL1 *)(*it))
2249 ret->_ms[i]=(*it)->deepCpy(ret->_coords);
2251 if((const PartDefinition*)_part_coords)
2252 ret->_part_coords=_part_coords->deepCpy();
2257 * Checks if \a this and another mesh are equal.
2258 * \param [in] other - the mesh to compare with.
2259 * \param [in] eps - a precision used to compare real values.
2260 * \param [in,out] what - the string returning description of unequal data.
2261 * \return bool - \c true if the meshes are equal, \c false, else.
2263 bool MEDFileUMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
2265 if(!MEDFileMesh::isEqual(other,eps,what))
2267 const MEDFileUMesh *otherC=dynamic_cast<const MEDFileUMesh *>(other);
2270 what="Mesh types differ ! This is unstructured and other is NOT !";
2273 clearNonDiscrAttributes();
2274 otherC->clearNonDiscrAttributes();
2275 const DataArrayDouble *coo1=_coords;
2276 const DataArrayDouble *coo2=otherC->_coords;
2277 if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
2279 what="Mismatch of coordinates ! One is defined and not other !";
2284 bool ret=coo1->isEqual(*coo2,eps);
2287 what="Coords differ !";
2291 const DataArrayInt *famc1=_fam_coords;
2292 const DataArrayInt *famc2=otherC->_fam_coords;
2293 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
2295 what="Mismatch of families arr on nodes ! One is defined and not other !";
2300 bool ret=famc1->isEqual(*famc2);
2303 what="Families arr on node differ !";
2307 const DataArrayInt *numc1=_num_coords;
2308 const DataArrayInt *numc2=otherC->_num_coords;
2309 if((numc1==0 && numc2!=0) || (numc1!=0 && numc2==0))
2311 what="Mismatch of numbering arr on nodes ! One is defined and not other !";
2316 bool ret=numc1->isEqual(*numc2);
2319 what="Numbering arr on node differ !";
2323 const DataArrayAsciiChar *namec1=_name_coords;
2324 const DataArrayAsciiChar *namec2=otherC->_name_coords;
2325 if((namec1==0 && namec2!=0) || (namec1!=0 && namec2==0))
2327 what="Mismatch of naming arr on nodes ! One is defined and not other !";
2332 bool ret=namec1->isEqual(*namec2);
2335 what="Names arr on node differ !";
2339 if(_ms.size()!=otherC->_ms.size())
2341 what="Number of levels differs !";
2344 std::size_t sz=_ms.size();
2345 for(std::size_t i=0;i<sz;i++)
2347 const MEDFileUMeshSplitL1 *s1=_ms[i];
2348 const MEDFileUMeshSplitL1 *s2=otherC->_ms[i];
2349 if((s1==0 && s2!=0) || (s1!=0 && s2==0))
2351 what="Mismatch of presence of sub levels !";
2356 bool ret=s1->isEqual(s2,eps,what);
2361 const PartDefinition *pd0(_part_coords),*pd1(otherC->_part_coords);
2364 if((!pd0 && pd1) || (pd0 && !pd1))
2366 what=std::string("node part def is defined only for one among this or other !");
2369 return pd0->isEqual(pd1,what);
2373 * Clears redundant attributes of incorporated data arrays.
2375 void MEDFileUMesh::clearNonDiscrAttributes() const
2377 MEDFileMesh::clearNonDiscrAttributes();
2378 const DataArrayDouble *coo1=_coords;
2380 (const_cast<DataArrayDouble *>(coo1))->setName("");//This parameter is not discriminant for comparison
2381 const DataArrayInt *famc1=_fam_coords;
2383 (const_cast<DataArrayInt *>(famc1))->setName("");//This parameter is not discriminant for comparison
2384 const DataArrayInt *numc1=_num_coords;
2386 (const_cast<DataArrayInt *>(numc1))->setName("");//This parameter is not discriminant for comparison
2387 const DataArrayAsciiChar *namc1=_name_coords;
2389 (const_cast<DataArrayAsciiChar *>(namc1))->setName("");//This parameter is not discriminant for comparison
2390 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2392 const MEDFileUMeshSplitL1 *tmp=(*it);
2394 tmp->clearNonDiscrAttributes();
2398 void MEDFileUMesh::setName(const std::string& name)
2400 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
2401 if((MEDFileUMeshSplitL1 *)(*it)!=0)
2402 (*it)->setName(name);
2403 MEDFileMesh::setName(name);
2406 MEDFileUMesh::MEDFileUMesh()
2410 MEDFileUMesh::MEDFileUMesh(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
2413 loadUMeshFromFile(fid,mName,dt,it,mrs);
2414 loadJointsFromFile(fid);
2416 catch(INTERP_KERNEL::Exception& e)
2422 * This method loads only a part of specified cells (given by range of cell ID per geometric type)
2423 * See MEDFileUMesh::LoadPartOf for detailed description.
2425 * \sa loadUMeshFromFile
2427 void MEDFileUMesh::loadPartUMeshFromFile(med_idt fid, const std::string& mName, const std::vector<INTERP_KERNEL::NormalizedCellType>& types, const std::vector<int>& slicPerTyp, int dt, int it, MEDFileMeshReadSelector *mrs)
2429 MEDFileUMeshL2 loaderl2;
2430 ParaMEDMEM::MEDCouplingMeshType meshType;
2433 int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2));
2434 if(meshType!=UNSTRUCTURED)
2436 std::ostringstream oss; oss << "loadPartUMeshFromFile : Trying to load as unstructured an existing mesh with name '" << mName << "' !";
2437 throw INTERP_KERNEL::Exception(oss.str().c_str());
2439 loaderl2.loadPart(fid,mid,mName,types,slicPerTyp,dt,it,mrs);
2440 dispatchLoadedPart(fid,loaderl2,mName,mrs);
2444 * \brief Write joints in a file
2446 void MEDFileMesh::writeJoints(med_idt fid) const
2448 if ( (const MEDFileJoints*) _joints )
2449 _joints->write(fid);
2453 * \brief Load joints in a file or use provided ones
2455 //================================================================================
2457 * \brief Load joints in a file or use provided ones
2458 * \param [in] fid - MED file descriptor
2459 * \param [in] toUseInstedOfReading - optional joints to use instead of reading,
2460 * Usually this joints are those just read by another iteration
2461 * of namesake mesh, when this method is called by MEDFileMeshMultiTS::New()
2463 //================================================================================
2465 void MEDFileMesh::loadJointsFromFile(med_idt fid, MEDFileJoints* toUseInstedOfReading)
2467 if ( toUseInstedOfReading )
2468 setJoints( toUseInstedOfReading );
2470 _joints = MEDFileJoints::New( fid, _name );
2474 * \brief Return number of joints, which is equal to number of adjacent mesh domains
2476 int MEDFileMesh::getNumberOfJoints()
2478 return ( (MEDFileJoints*) _joints ) ? _joints->getNumberOfJoints() : 0;
2482 * \brief Return joints with all adjacent mesh domains
2484 MEDFileJoints * MEDFileMesh::getJoints() const
2486 return const_cast<MEDFileJoints*>(& (*_joints));
2489 void MEDFileMesh::setJoints( MEDFileJoints* joints )
2491 if ( joints != _joints )
2500 * This method loads \b all \b the \b mesh \a mName in the file with \a fid descriptor.
2502 * \sa loadPartUMeshFromFile
2504 void MEDFileUMesh::loadUMeshFromFile(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
2506 MEDFileUMeshL2 loaderl2;
2507 ParaMEDMEM::MEDCouplingMeshType meshType;
2510 int mid(MEDFileUMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dummy2));
2511 if(meshType!=UNSTRUCTURED)
2513 std::ostringstream oss; oss << "Trying to load as unstructured an existing mesh with name '" << mName << "' !";
2514 throw INTERP_KERNEL::Exception(oss.str().c_str());
2516 loaderl2.loadAll(fid,mid,mName,dt,it,mrs);
2517 dispatchLoadedPart(fid,loaderl2,mName,mrs);
2520 void MEDFileUMesh::dispatchLoadedPart(med_idt fid, const MEDFileUMeshL2& loaderl2, const std::string& mName, MEDFileMeshReadSelector *mrs)
2522 int lev=loaderl2.getNumberOfLevels();
2524 for(int i=0;i<lev;i++)
2526 if(!loaderl2.emptyLev(i))
2527 _ms[i]=new MEDFileUMeshSplitL1(loaderl2,mName,i);
2531 MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups,mrs);
2533 setName(loaderl2.getName());
2534 setDescription(loaderl2.getDescription());
2535 setUnivName(loaderl2.getUnivName());
2536 setIteration(loaderl2.getIteration());
2537 setOrder(loaderl2.getOrder());
2538 setTimeValue(loaderl2.getTime());
2539 setTimeUnit(loaderl2.getTimeUnit());
2540 _coords=loaderl2.getCoords();
2541 if(!mrs || mrs->isNodeFamilyFieldReading())
2542 _fam_coords=loaderl2.getCoordsFamily();
2543 if(!mrs || mrs->isNodeNumFieldReading())
2544 _num_coords=loaderl2.getCoordsNum();
2545 if(!mrs || mrs->isNodeNameFieldReading())
2546 _name_coords=loaderl2.getCoordsName();
2547 _part_coords=loaderl2.getPartDefOfCoo();
2551 MEDFileUMesh::~MEDFileUMesh()
2555 void MEDFileUMesh::writeLL(med_idt fid) const
2557 const DataArrayDouble *coo=_coords;
2558 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
2559 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
2560 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
2561 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
2562 int spaceDim=coo?coo->getNumberOfComponents():0;
2565 mdim=getMeshDimension();
2566 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
2567 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
2568 for(int i=0;i<spaceDim;i++)
2570 std::string info=coo->getInfoOnComponent(i);
2572 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
2573 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
2574 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
2576 MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,mdim,MED_UNSTRUCTURED_MESH,desc,"",MED_SORT_DTIT,MED_CARTESIAN,comp,unit));
2577 MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa));
2578 std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE));
2579 MEDFileUMeshL2::WriteCoords(fid,meshName,_iteration,_order,_time,_coords,_fam_coords,_num_coords,_name_coords);
2580 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2581 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
2582 (*it)->write(fid,meshName,mdim);
2583 MEDFileUMeshL2::WriteFamiliesAndGrps(fid,meshName,_families,_groups,_too_long_str);
2589 * Returns relative dimensions of mesh entities (excluding nodes) present in \a this mesh.
2590 * \return std::vector<int> - a sequence of the relative dimensions.
2592 std::vector<int> MEDFileUMesh::getNonEmptyLevels() const
2594 std::vector<int> ret;
2596 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
2597 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
2604 * Returns relative dimensions of mesh entities (including nodes) present in \a this mesh.
2605 * \return std::vector<int> - a sequence of the relative dimensions.
2607 std::vector<int> MEDFileUMesh::getNonEmptyLevelsExt() const
2609 std::vector<int> ret0=getNonEmptyLevels();
2610 if((const DataArrayDouble *) _coords)
2612 std::vector<int> ret(ret0.size()+1);
2614 std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
2620 std::vector<int> MEDFileUMesh::getFamArrNonEmptyLevelsExt() const
2622 std::vector<int> ret;
2623 const DataArrayInt *famCoo(_fam_coords);
2627 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
2629 const MEDFileUMeshSplitL1 *cur(*it);
2631 if(cur->getFamilyField())
2637 std::vector<int> MEDFileUMesh::getNumArrNonEmptyLevelsExt() const
2639 std::vector<int> ret;
2640 const DataArrayInt *numCoo(_num_coords);
2644 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
2646 const MEDFileUMeshSplitL1 *cur(*it);
2648 if(cur->getNumberField())
2654 std::vector<int> MEDFileUMesh::getNameArrNonEmptyLevelsExt() const
2656 std::vector<int> ret;
2657 const DataArrayAsciiChar *nameCoo(_name_coords);
2661 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev--)
2663 const MEDFileUMeshSplitL1 *cur(*it);
2665 if(cur->getNameField())
2672 * Returns all relative mesh levels (**excluding nodes**) where a given group is defined.
2673 * To include nodes, call getGrpNonEmptyLevelsExt() method.
2674 * \param [in] grp - the name of the group of interest.
2675 * \return std::vector<int> - a sequence of the relative dimensions.
2677 std::vector<int> MEDFileUMesh::getGrpNonEmptyLevels(const std::string& grp) const
2679 std::vector<std::string> fams=getFamiliesOnGroup(grp);
2680 return getFamsNonEmptyLevels(fams);
2684 * Returns all relative mesh levels (including nodes) where a given group is defined.
2685 * \param [in] grp - the name of the group of interest.
2686 * \return std::vector<int> - a sequence of the relative dimensions.
2688 std::vector<int> MEDFileUMesh::getGrpNonEmptyLevelsExt(const std::string& grp) const
2690 std::vector<std::string> fams=getFamiliesOnGroup(grp);
2691 return getFamsNonEmptyLevelsExt(fams);
2695 * Returns all relative mesh levels (**excluding nodes**) where a given family is defined.
2696 * To include nodes, call getFamNonEmptyLevelsExt() method.
2697 * \param [in] fam - the name of the family of interest.
2698 * \return std::vector<int> - a sequence of the relative dimensions.
2700 std::vector<int> MEDFileUMesh::getFamNonEmptyLevels(const std::string& fam) const
2702 std::vector<std::string> fams(1,std::string(fam));
2703 return getFamsNonEmptyLevels(fams);
2707 * Returns all relative mesh levels (including nodes) where a given family is defined.
2708 * \param [in] fam - the name of the family of interest.
2709 * \return std::vector<int> - a sequence of the relative dimensions.
2711 std::vector<int> MEDFileUMesh::getFamNonEmptyLevelsExt(const std::string& fam) const
2713 std::vector<std::string> fams(1,std::string(fam));
2714 return getFamsNonEmptyLevelsExt(fams);
2718 * Returns all relative mesh levels (**excluding nodes**) where given groups are defined.
2719 * To include nodes, call getGrpsNonEmptyLevelsExt() method.
2720 * \param [in] grps - a sequence of names of the groups of interest.
2721 * \return std::vector<int> - a sequence of the relative dimensions.
2723 std::vector<int> MEDFileUMesh::getGrpsNonEmptyLevels(const std::vector<std::string>& grps) const
2725 std::vector<std::string> fams=getFamiliesOnGroups(grps);
2726 return getFamsNonEmptyLevels(fams);
2730 * Returns all relative mesh levels (including nodes) where given groups are defined.
2731 * \param [in] grps - a sequence of names of the groups of interest.
2732 * \return std::vector<int> - a sequence of the relative dimensions.
2734 std::vector<int> MEDFileUMesh::getGrpsNonEmptyLevelsExt(const std::vector<std::string>& grps) const
2736 std::vector<std::string> fams=getFamiliesOnGroups(grps);
2737 return getFamsNonEmptyLevelsExt(fams);
2741 * Returns all relative mesh levels (**excluding nodes**) where given families are defined.
2742 * To include nodes, call getFamsNonEmptyLevelsExt() method.
2743 * \param [in] fams - the name of the family of interest.
2744 * \return std::vector<int> - a sequence of the relative dimensions.
2746 std::vector<int> MEDFileUMesh::getFamsNonEmptyLevels(const std::vector<std::string>& fams) const
2748 std::vector<int> ret;
2749 std::vector<int> levs=getNonEmptyLevels();
2750 std::vector<int> famIds=getFamiliesIds(fams);
2751 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
2752 if(_ms[-(*it)]->presenceOfOneFams(famIds))
2758 * Returns all relative mesh levels (including nodes) where given families are defined.
2759 * \param [in] fams - the names of the families of interest.
2760 * \return std::vector<int> - a sequence of the relative dimensions.
2762 std::vector<int> MEDFileUMesh::getFamsNonEmptyLevelsExt(const std::vector<std::string>& fams) const
2764 std::vector<int> ret0=getFamsNonEmptyLevels(fams);
2765 const DataArrayInt *famCoords=_fam_coords;
2768 std::vector<int> famIds=getFamiliesIds(fams);
2769 if(famCoords->presenceOfValue(famIds))
2771 std::vector<int> ret(ret0.size()+1);
2773 std::copy(ret0.begin(),ret0.end(),ret.begin()+1);
2781 * Returns names of groups that partly or fully appear on the level \a meshDimRelToMaxExt.
2782 * \param [in] meshDimRelToMaxExt - a relative dimension of interest.
2783 * \return std::vector<std::string> - a sequence of group names at \a meshDimRelToMaxExt
2786 std::vector<std::string> MEDFileUMesh::getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) const
2788 std::vector<std::string> ret;
2789 std::vector<std::string> allGrps=getGroupsNames();
2790 for(std::vector<std::string>::const_iterator it=allGrps.begin();it!=allGrps.end();it++)
2792 std::vector<int> levs=getGrpNonEmptyLevelsExt((*it));
2793 if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)!=levs.end())
2799 int MEDFileUMesh::getMaxAbsFamilyIdInArrays() const
2801 int ret=-std::numeric_limits<int>::max(),tmp=-1;
2802 if((const DataArrayInt *)_fam_coords)
2804 int val=_fam_coords->getMaxValue(tmp);
2805 ret=std::max(ret,std::abs(val));
2807 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2809 if((const MEDFileUMeshSplitL1 *)(*it))
2811 const DataArrayInt *da=(*it)->getFamilyField();
2814 int val=da->getMaxValue(tmp);
2815 ret=std::max(ret,std::abs(val));
2822 int MEDFileUMesh::getMaxFamilyIdInArrays() const
2824 int ret=-std::numeric_limits<int>::max(),tmp=-1;
2825 if((const DataArrayInt *)_fam_coords)
2827 int val=_fam_coords->getMaxValue(tmp);
2828 ret=std::max(ret,val);
2830 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2832 if((const MEDFileUMeshSplitL1 *)(*it))
2834 const DataArrayInt *da=(*it)->getFamilyField();
2837 int val=da->getMaxValue(tmp);
2838 ret=std::max(ret,val);
2845 int MEDFileUMesh::getMinFamilyIdInArrays() const
2847 int ret=std::numeric_limits<int>::max(),tmp=-1;
2848 if((const DataArrayInt *)_fam_coords)
2850 int val=_fam_coords->getMinValue(tmp);
2851 ret=std::min(ret,val);
2853 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
2855 if((const MEDFileUMeshSplitL1 *)(*it))
2857 const DataArrayInt *da=(*it)->getFamilyField();
2860 int val=da->getMinValue(tmp);
2861 ret=std::min(ret,val);
2869 * Returns the dimension on cells in \a this mesh.
2870 * \return int - the mesh dimension.
2871 * \throw If there are no cells in this mesh.
2873 int MEDFileUMesh::getMeshDimension() const
2876 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,lev++)
2877 if((const MEDFileUMeshSplitL1 *)(*it)!=0)
2878 return (*it)->getMeshDimension()+lev;
2879 throw INTERP_KERNEL::Exception("MEDFileUMesh::getMeshDimension : impossible to find a mesh dimension !");
2883 * Returns the space dimension of \a this mesh that is equal to number of components in
2884 * the node coordinates array.
2885 * \return int - the space dimension of \a this mesh.
2886 * \throw If the node coordinates array is not available.
2888 int MEDFileUMesh::getSpaceDimension() const
2890 const DataArrayDouble *coo=_coords;
2892 throw INTERP_KERNEL::Exception(" MEDFileUMesh::getSpaceDimension : no coords set !");
2893 return coo->getNumberOfComponents();
2897 * Returns a string describing \a this mesh.
2898 * \return std::string - the mesh information string.
2900 std::string MEDFileUMesh::simpleRepr() const
2902 std::ostringstream oss;
2903 oss << MEDFileMesh::simpleRepr();
2904 const DataArrayDouble *coo=_coords;
2905 oss << "- The dimension of the space is ";
2906 static const char MSG1[]= "*** NO COORDS SET ***";
2907 static const char MSG2[]= "*** NO CONNECTIVITY SET FOR THIS LEVEL***";
2909 oss << _coords->getNumberOfComponents() << std::endl;
2911 oss << MSG1 << std::endl;
2912 oss << "- Type of the mesh : UNSTRUCTURED\n";
2913 oss << "- Number of nodes : ";
2915 oss << _coords->getNumberOfTuples() << std::endl;
2917 oss << MSG1 << std::endl;
2918 std::size_t nbOfLev=_ms.size();
2919 oss << "- Number of levels allocated : " << nbOfLev << std::endl;
2920 for(std::size_t i=0;i<nbOfLev;i++)
2922 const MEDFileUMeshSplitL1 *lev=_ms[i];
2923 oss << " - Level #" << -((int) i) << " has dimension : ";
2926 oss << lev->getMeshDimension() << std::endl;
2927 lev->simpleRepr(oss);
2930 oss << MSG2 << std::endl;
2932 oss << "- Number of families : " << _families.size() << std::endl << std::endl;
2935 oss << "(***********************)\n(* NODES OF THE MESH : *)\n(***********************)\n";
2936 oss << "- Names of coordinates :" << std::endl;
2937 std::vector<std::string> vars=coo->getVarsOnComponent();
2938 std::copy(vars.begin(),vars.end(),std::ostream_iterator<std::string>(oss," "));
2939 oss << std::endl << "- Units of coordinates : " << std::endl;
2940 std::vector<std::string> units=coo->getUnitsOnComponent();
2941 std::copy(units.begin(),units.end(),std::ostream_iterator<std::string>(oss," "));
2943 oss << std::endl << std::endl;
2949 * Returns a full textual description of \a this mesh.
2950 * \return std::string - the string holding the mesh description.
2952 std::string MEDFileUMesh::advancedRepr() const
2954 return simpleRepr();
2958 * Returns number of mesh entities of a given relative dimension in \a this mesh.
2959 * \param [in] meshDimRelToMaxExt - the relative dimension of interest.
2960 * \return int - the number of entities.
2961 * \throw If no mesh entities of dimension \a meshDimRelToMaxExt are available in \a this mesh.
2963 int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const
2965 if(meshDimRelToMaxExt==1)
2967 if(!((const DataArrayDouble *)_coords))
2968 throw INTERP_KERNEL::Exception("MEDFileUMesh::getSizeAtLevel : no coordinates specified !");
2969 return _coords->getNumberOfTuples();
2971 return getMeshAtLevSafe(meshDimRelToMaxExt)->getSize();
2975 * Returns the family field for mesh entities of a given dimension.
2976 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
2977 * \return const DataArrayInt * - the family field. It is an array of ids of families
2978 * each mesh entity belongs to. It can be \c NULL.
2980 const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const
2982 if(meshDimRelToMaxExt==1)
2984 const MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMaxExt));
2985 return l1->getFamilyField();
2988 DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt)
2990 if(meshDimRelToMaxExt==1)
2992 MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMaxExt));
2993 return l1->getFamilyField();
2997 * Returns the optional numbers of mesh entities of a given dimension.
2998 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
2999 * \return const DataArrayInt * - the array of the entity numbers.
3000 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
3002 const DataArrayInt *MEDFileUMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const
3004 if(meshDimRelToMaxExt==1)
3006 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
3007 return l1->getNumberField();
3010 const DataArrayAsciiChar *MEDFileUMesh::getNameFieldAtLevel(int meshDimRelToMaxExt) const
3012 if(meshDimRelToMaxExt==1)
3013 return _name_coords;
3014 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
3015 return l1->getNameField();
3019 * This method returns for a specified relative level \a meshDimRelToMaxExt the part effectively read (if the instance is the result of the read of a file).
3021 * \param [in] meshDimRelToMaxExt - the extended relative level for which the part definition is requested.
3022 * \param [in] gt - The input geometric type for which the part definition is requested.
3023 * \return the part definition owned by \a this. So no need to deallocate the returned instance.
3025 const PartDefinition *MEDFileUMesh::getPartDefAtLevel(int meshDimRelToMaxExt, INTERP_KERNEL::NormalizedCellType gt) const
3027 if(meshDimRelToMaxExt==1)
3028 return _part_coords;
3029 const MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMaxExt));
3030 return l1->getPartDef(gt);
3033 int MEDFileUMesh::getNumberOfNodes() const
3035 const DataArrayDouble *coo(_coords);
3037 throw INTERP_KERNEL::Exception(" MEDFileUMesh::getNumberOfNodes : no coords set !");
3038 return coo->getNumberOfTuples();
3041 int MEDFileUMesh::getNumberOfCellsAtLevel(int meshDimRelToMaxExt) const
3043 const MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMaxExt));
3044 return l1->getNumberOfCells();
3047 bool MEDFileUMesh::hasImplicitPart() const
3052 int MEDFileUMesh::buildImplicitPartIfAny(INTERP_KERNEL::NormalizedCellType gt) const
3054 throw INTERP_KERNEL::Exception("MEDFileUMesh::buildImplicitPartIfAny : unstructured meshes do not have implicit part !");
3057 void MEDFileUMesh::releaseImplicitPartIfAny() const
3061 void MEDFileUMesh::whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector<bool>& nodesFetched) const
3063 std::size_t sz(st.getNumberOfItems());
3064 for(std::size_t i=0;i<sz;i++)
3066 INTERP_KERNEL::NormalizedCellType curGt(st[i].getGeo());
3067 const MEDCoupling1GTUMesh *m(getDirectUndergroundSingleGeoTypeMesh(curGt));
3068 if(st[i].getPflName().empty())
3069 m->computeNodeIdsAlg(nodesFetched);
3072 const DataArrayInt *arr(globs->getProfile(st[i].getPflName()));
3073 MEDCouplingAutoRefCountObjectPtr<MEDCoupling1GTUMesh> m2(dynamic_cast<MEDCoupling1GTUMesh *>(m->buildPartOfMySelf(arr->begin(),arr->end(),true)));
3074 m2->computeNodeIdsAlg(nodesFetched);
3080 * Returns the optional numbers of mesh entities of a given dimension transformed using
3081 * DataArrayInt::invertArrayN2O2O2N().
3082 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
3083 * \return const DataArrayInt * - the array of the entity numbers transformed using
3084 * DataArrayInt::invertArrayN2O2O2N().
3085 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
3087 const DataArrayInt *MEDFileUMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const
3089 if(meshDimRelToMaxExt==1)
3091 if(!((const DataArrayInt *)_num_coords))
3092 throw INTERP_KERNEL::Exception("MEDFileUMesh::getRevNumberFieldAtLevel : no coordinates renum specified !");
3093 return _rev_num_coords;
3095 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
3096 return l1->getRevNumberField();
3100 * Returns a pointer to the node coordinates array of \a this mesh \b without
3101 * incrementing its reference counter, thus there is no need to decrRef() it by the caller.
3103 DataArrayDouble *MEDFileUMesh::getCoords() const
3105 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> tmp(_coords);
3106 if((DataArrayDouble *)tmp)
3114 * Returns a new MEDCouplingUMesh corresponding to mesh entities included in a given
3115 * group of \a this mesh. Only mesh entities of a given dimension are included in the
3117 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities of interest.
3118 * \param [in] grp - the name of the group whose mesh entities are included in the
3120 * \param [in] renum - if \c true, cells and nodes of the result mesh are permuted
3121 * according to the optional numbers of entities, if available.
3122 * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
3123 * delete this mesh using decrRef() as it is no more needed.
3124 * \throw If the name of a nonexistent group is specified.
3125 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
3127 MEDCouplingUMesh *MEDFileUMesh::getGroup(int meshDimRelToMaxExt, const std::string& grp, bool renum) const
3129 synchronizeTinyInfoOnLeaves();
3130 std::vector<std::string> tmp(1);
3132 return getGroups(meshDimRelToMaxExt,tmp,renum);
3136 * Returns a new MEDCouplingUMesh corresponding to mesh entities included in given
3137 * groups of \a this mesh. Only mesh entities of a given dimension are included in the
3139 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities of interest.
3140 * \param [in] grps - a sequence of group names whose mesh entities are included in the
3142 * \param [in] renum - if \c true, cells and nodes of the result mesh are permuted
3143 * according to the optional numbers of entities, if available.
3144 * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
3145 * delete this mesh using decrRef() as it is no more needed.
3146 * \throw If a name of a nonexistent group is present in \a grps.
3147 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
3149 MEDCouplingUMesh *MEDFileUMesh::getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum) const
3151 synchronizeTinyInfoOnLeaves();
3152 std::vector<std::string> fams2=getFamiliesOnGroups(grps);
3153 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> zeRet=getFamilies(meshDimRelToMaxExt,fams2,renum);
3154 if(grps.size()==1 && ((MEDCouplingUMesh *)zeRet))
3155 zeRet->setName(grps[0]);
3156 return zeRet.retn();
3160 * Returns a new MEDCouplingUMesh corresponding to mesh entities included in a given
3161 * family of \a this mesh. Only mesh entities of a given dimension are included in the
3163 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities of interest.
3164 * \param [in] fam - the name of the family whose mesh entities are included in the
3166 * \param [in] renum - if \c true, cells and nodes of the result mesh are permuted
3167 * according to the optional numbers of entities, if available.
3168 * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
3169 * delete this mesh using decrRef() as it is no more needed.
3170 * \throw If a name of a nonexistent family is present in \a grps.
3171 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
3173 MEDCouplingUMesh *MEDFileUMesh::getFamily(int meshDimRelToMaxExt, const std::string& fam, bool renum) const
3175 synchronizeTinyInfoOnLeaves();
3176 std::vector<std::string> tmp(1);
3178 return getFamilies(meshDimRelToMaxExt,tmp,renum);
3182 * Returns a new MEDCouplingUMesh corresponding to mesh entities included in given
3183 * families of \a this mesh. Only mesh entities of a given dimension are included in the
3185 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities of interest.
3186 * \param [in] fams - a sequence of family names whose mesh entities are included in the
3188 * \param [in] renum - if \c true, cells and nodes of the result mesh are permuted
3189 * according to the optional numbers of entities, if available.
3190 * \return MEDCouplingUMesh * - a new instance of MEDCouplingUMesh. The caller is to
3191 * delete this mesh using decrRef() as it is no more needed.
3192 * \throw If a name of a nonexistent family is present in \a fams.
3193 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
3195 MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const
3197 synchronizeTinyInfoOnLeaves();
3198 if(meshDimRelToMaxExt==1)
3200 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> arr=getFamiliesArr(1,fams,renum);
3201 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> ret=MEDCouplingUMesh::New();
3202 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> c=_coords->selectByTupleId(arr->getConstPointer(),arr->getConstPointer()+arr->getNbOfElems());
3206 std::vector<int> famIds=getFamiliesIds(fams);
3207 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
3208 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> zeRet;
3210 zeRet=l1->getFamilyPart(&famIds[0],&famIds[0]+famIds.size(),renum);
3212 zeRet=l1->getFamilyPart(0,0,renum);
3213 if(fams.size()==1 && ((MEDCouplingUMesh *)zeRet))
3214 zeRet->setName(fams[0]);
3215 return zeRet.retn();
3219 * Returns ids of mesh entities contained in given families of a given dimension.
3220 * \param [in] meshDimRelToMaxExt - a relative dimension of the mesh entities whose ids
3222 * \param [in] fams - the names of the families of interest.
3223 * \param [in] renum - if \c true, the optional numbers of entities, if available, are
3224 * returned instead of ids.
3225 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
3226 * numbers, if available and required, of mesh entities of the families. The caller
3227 * is to delete this array using decrRef() as it is no more needed.
3228 * \throw If the family field is missing for \a meshDimRelToMaxExt.
3230 DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const
3232 std::vector<int> famIds=getFamiliesIds(fams);
3233 if(meshDimRelToMaxExt==1)
3235 if((const DataArrayInt *)_fam_coords)
3237 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
3239 da=_fam_coords->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
3241 da=_fam_coords->getIdsEqualList(0,0);
3243 return MEDFileUMeshSplitL1::Renumber(_num_coords,da);
3248 throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamiliesArr : no family array specified on nodes !");
3250 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
3252 return l1->getFamilyPartArr(&famIds[0],&famIds[0]+famIds.size(),renum);
3254 return l1->getFamilyPartArr(0,0,renum);
3258 * Returns a MEDCouplingUMesh of a given relative dimension.
3259 * \warning If \a meshDimRelToMaxExt == 1 (which means nodes), the returned mesh **is not
3260 * valid**. This is a feature, because MEDLoader does not create cells that do not exist!
3261 * To build a valid MEDCouplingUMesh from the returned one in this case,
3262 * call MEDCouplingUMesh::Build0DMeshFromCoords().
3263 * \param [in] meshDimRelToMax - the relative dimension of interest.
3264 * \param [in] renum - if \c true, the returned mesh is permuted according to the
3265 * optional numbers of mesh entities.
3266 * \return MEDCouplingUMesh * - a pointer to MEDCouplingUMesh that the caller is to
3267 * delete using decrRef() as it is no more needed.
3268 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
3269 * \sa getGenMeshAtLevel()
3271 MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const
3273 synchronizeTinyInfoOnLeaves();
3274 if(meshDimRelToMaxExt==1)
3278 MEDCouplingUMesh *umesh=MEDCouplingUMesh::New();
3279 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> cc=_coords->deepCpy();
3280 umesh->setCoords(cc);
3281 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(umesh);
3282 umesh->setName(getName());
3286 const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
3287 return l1->getWholeMesh(renum);
3291 * Returns a MEDCouplingUMesh of a given relative dimension.
3292 * \warning If \a meshDimRelToMaxExt == 1 (which means nodes), the returned mesh **is not
3293 * valid**. This is a feature, because MEDLoader does not create cells that do not exist!
3294 * To build a valid MEDCouplingUMesh from the returned one in this case,
3295 * call MEDCouplingUMesh::Build0DMeshFromCoords().
3296 * \param [in] meshDimRelToMax - the relative dimension of interest.
3297 * \param [in] renum - if \c true, the returned mesh is permuted according to the
3298 * optional numbers of mesh entities.
3299 * \return MEDCouplingMesh * - a pointer to MEDCouplingUMesh that the caller is to
3300 * delete using decrRef() as it is no more needed.
3301 * \throw If there are no mesh entities of \a meshDimRelToMax dimension in \a this mesh.
3302 * \sa getMeshAtLevel()
3304 MEDCouplingMesh *MEDFileUMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const
3306 return getMeshAtLevel(meshDimRelToMax,renum);
3309 std::vector<int> MEDFileUMesh::getDistributionOfTypes(int meshDimRelToMax) const
3311 const MEDFileUMeshSplitL1 *l1(getMeshAtLevSafe(meshDimRelToMax));
3312 return l1->getDistributionOfTypes();
3316 * Returns a MEDCouplingUMesh of a relative dimension == 0.
3317 * \param [in] renum - if \c true, the returned mesh is permuted according to the
3318 * optional numbers of mesh entities.
3319 * \return MEDCouplingUMesh * - a pointer to MEDCouplingUMesh that the caller is to
3320 * delete using decrRef() as it is no more needed.
3321 * \throw If there are no mesh entities of the relative dimension == 0 in \a this mesh.
3323 MEDCouplingUMesh *MEDFileUMesh::getLevel0Mesh(bool renum) const
3325 return getMeshAtLevel(0,renum);
3329 * Returns a MEDCouplingUMesh of a relative dimension == -1.
3330 * \param [in] renum - if \c true, the returned mesh is permuted according to the
3331 * optional numbers of mesh entities.
3332 * \return MEDCouplingUMesh * - a pointer to MEDCouplingUMesh that the caller is to
3333 * delete using decrRef() as it is no more needed.
3334 * \throw If there are no mesh entities of the relative dimension == -1 in \a this mesh.
3336 MEDCouplingUMesh *MEDFileUMesh::getLevelM1Mesh(bool renum) const
3338 return getMeshAtLevel(-1,renum);
3342 * Returns a MEDCouplingUMesh of a relative dimension == -2.
3343 * \param [in] renum - if \c true, the returned mesh is permuted according to the
3344 * optional numbers of mesh entities.
3345 * \return MEDCouplingUMesh * - a pointer to MEDCouplingUMesh that the caller is to
3346 * delete using decrRef() as it is no more needed.
3347 * \throw If there are no mesh entities of the relative dimension == -2 in \a this mesh.
3349 MEDCouplingUMesh *MEDFileUMesh::getLevelM2Mesh(bool renum) const
3351 return getMeshAtLevel(-2,renum);
3355 * Returns a MEDCouplingUMesh of a relative dimension == -3.
3356 * \param [in] renum - if \c true, the returned mesh is permuted according to the
3357 * optional numbers of mesh entities.
3358 * \return MEDCouplingUMesh * - a pointer to MEDCouplingUMesh that the caller is to
3359 * delete using decrRef() as it is no more needed.
3360 * \throw If there are no mesh entities of the relative dimension == -3 in \a this mesh.
3362 MEDCouplingUMesh *MEDFileUMesh::getLevelM3Mesh(bool renum) const
3364 return getMeshAtLevel(-3,renum);
3368 * This method is for advanced users. There is two storing strategy of mesh in \a this.
3369 * Either MEDCouplingUMesh, or vector of MEDCoupling1GTUMesh instances.
3370 * When assignement is done the first one is done, which is not optimal in write mode for MED file.
3371 * This method allows to switch from MEDCouplingUMesh mode to MEDCoupling1GTUMesh mode.
3373 void MEDFileUMesh::forceComputationOfParts() const
3375 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
3377 const MEDFileUMeshSplitL1 *elt(*it);
3379 elt->forceComputationOfParts();
3384 * This method returns a vector of mesh parts containing each exactly one geometric type.
3385 * This method will never launch an automatic computation of split by type (an INTERP_KERNEL::Exception will be then thrown).
3386 * This method is only for memory aware users.
3387 * The returned pointers are **NOT** new object pointer. No need to mange them.
3389 std::vector<MEDCoupling1GTUMesh *> MEDFileUMesh::getDirectUndergroundSingleGeoTypeMeshes(int meshDimRelToMax) const
3391 const MEDFileUMeshSplitL1 *sp(getMeshAtLevSafe(meshDimRelToMax));
3392 return sp->getDirectUndergroundSingleGeoTypeMeshes();
3396 * This method returns the part of \a this having the geometric type \a gt.
3397 * If such part is not existing an exception will be thrown.
3398 * The returned pointer is **NOT** new object pointer. No need to mange it.
3400 MEDCoupling1GTUMesh *MEDFileUMesh::getDirectUndergroundSingleGeoTypeMesh(INTERP_KERNEL::NormalizedCellType gt) const
3402 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(gt);
3403 int lev=(int)cm.getDimension()-getMeshDimension();
3404 const MEDFileUMeshSplitL1 *sp(getMeshAtLevSafe(lev));
3405 return sp->getDirectUndergroundSingleGeoTypeMesh(gt);
3409 * Given a relative level \a meshDimRelToMax it returns the sorted vector of geometric types present in \a this.
3410 * \throw if the reqsuested \a meshDimRelToMax does not exist.
3412 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileUMesh::getGeoTypesAtLevel(int meshDimRelToMax) const
3414 const MEDFileUMeshSplitL1 *sp(getMeshAtLevSafe(meshDimRelToMax));
3415 return sp->getGeoTypes();
3419 * This method extracts from whole family field ids the part relative to the input parameter \a gt.
3420 * \param [in] gt - the geometric type for which the family field is asked.
3421 * \return DataArrayInt * - a pointer to DataArrayInt that the caller is to
3422 * delete using decrRef() as it is no more needed.
3423 * \sa MEDFileUMesh::extractNumberFieldOnGeoType
3425 DataArrayInt *MEDFileUMesh::extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
3427 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(gt);
3428 int lev=(int)cm.getDimension()-getMeshDimension();
3429 const MEDFileUMeshSplitL1 *sp(getMeshAtLevSafe(lev));
3430 return sp->extractFamilyFieldOnGeoType(gt);
3434 * This method extracts from whole number field ids the part relative to the input parameter \a gt.
3435 * \param [in] gt - the geometric type for which the number field is asked.
3436 * \return DataArrayInt * - a pointer to DataArrayInt that the caller is to
3437 * delete using decrRef() as it is no more needed.
3438 * \sa MEDFileUMesh::extractFamilyFieldOnGeoType
3440 DataArrayInt *MEDFileUMesh::extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
3442 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(gt);
3443 int lev=(int)cm.getDimension()-getMeshDimension();
3444 const MEDFileUMeshSplitL1 *sp(getMeshAtLevSafe(lev));
3445 return sp->extractNumberFieldOnGeoType(gt);
3449 * This method returns for specified geometric type \a gt the relative level to \a this.
3450 * If the relative level is empty an exception will be thrown.
3452 int MEDFileUMesh::getRelativeLevOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const
3454 const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(gt);
3455 int ret((int)cm.getDimension()-getMeshDimension());
3456 getMeshAtLevSafe(ret);//To test that returned value corresponds to a valid level.
3460 const MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt) const
3462 if(meshDimRelToMaxExt==1)
3463 throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
3464 if(meshDimRelToMaxExt>1)
3465 throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
3466 int tracucedRk=-meshDimRelToMaxExt;
3467 if(tracucedRk>=(int)_ms.size())
3468 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! Too low !");
3469 if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
3470 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
3471 return _ms[tracucedRk];
3474 MEDFileUMeshSplitL1 *MEDFileUMesh::getMeshAtLevSafe(int meshDimRelToMaxExt)
3476 if(meshDimRelToMaxExt==1)
3477 throw INTERP_KERNEL::Exception("Dimension request is invalid : asking for node level (1) !");
3478 if(meshDimRelToMaxExt>1)
3479 throw INTERP_KERNEL::Exception("Dimension request is invalid (>1) !");
3480 int tracucedRk=-meshDimRelToMaxExt;
3481 if(tracucedRk>=(int)_ms.size())
3482 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! Too low !");
3483 if((const MEDFileUMeshSplitL1 *)_ms[tracucedRk]==0)
3484 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
3485 return _ms[tracucedRk];
3488 void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const
3490 if(-meshDimRelToMax>=(int)_ms.size())
3491 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : The meshdim of mesh is not managed by 'this' !");
3493 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++,i++)
3495 if(((const MEDFileUMeshSplitL1*) (*it))!=0)
3497 int ref=(*it)->getMeshDimension();
3498 if(ref+i!=meshDim-meshDimRelToMax)
3499 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMeshDimCoherency : no coherency between levels !");
3505 * Sets the node coordinates array of \a this mesh.
3506 * \param [in] coords - the new node coordinates array.
3507 * \throw If \a coords == \c NULL.
3509 void MEDFileUMesh::setCoords(DataArrayDouble *coords)
3512 throw INTERP_KERNEL::Exception("MEDFileUMesh::setCoords : null pointer in input !");
3513 coords->checkAllocated();
3514 int nbOfTuples=coords->getNumberOfTuples();
3517 _fam_coords=DataArrayInt::New();
3518 _fam_coords->alloc(nbOfTuples,1);
3519 _fam_coords->fillWithZero();
3520 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
3521 if((MEDFileUMeshSplitL1 *)(*it))
3522 (*it)->setCoords(coords);
3526 * Removes all groups of a given dimension in \a this mesh.
3527 * \param [in] meshDimRelToMaxExt - the relative dimension of interest.
3528 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
3530 void MEDFileUMesh::eraseGroupsAtLevel(int meshDimRelToMaxExt)
3532 if(meshDimRelToMaxExt==1)
3534 if((DataArrayInt *)_fam_coords)
3535 _fam_coords->fillWithZero();
3538 MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt);
3539 l1->eraseFamilyField();
3544 * Removes all families with ids not present in the family fields of \a this mesh.
3546 void MEDFileUMesh::optimizeFamilies()
3548 std::vector<int> levs=getNonEmptyLevelsExt();
3549 std::set<int> allFamsIds;
3550 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
3552 const DataArrayInt *ffield=getFamilyFieldAtLevel(*it);
3553 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ids=ffield->getDifferentValues();
3555 std::set_union(ids->begin(),ids->end(),allFamsIds.begin(),allFamsIds.end(),std::inserter(res,res.begin()));
3558 std::set<std::string> famNamesToKill;
3559 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
3561 if(allFamsIds.find((*it).second)!=allFamsIds.end())
3562 famNamesToKill.insert((*it).first);
3564 for(std::set<std::string>::const_iterator it=famNamesToKill.begin();it!=famNamesToKill.end();it++)
3565 _families.erase(*it);
3566 std::vector<std::string> grpNamesToKill;
3567 for(std::map<std::string, std::vector<std::string> >::iterator it=_groups.begin();it!=_groups.end();it++)
3569 std::vector<std::string> tmp;
3570 for(std::vector<std::string>::const_iterator it2=(*it).second.begin();it2!=(*it).second.end();it2++)
3572 if(famNamesToKill.find(*it2)==famNamesToKill.end())
3573 tmp.push_back(*it2);
3578 tmp.push_back((*it).first);
3580 for(std::vector<std::string>::const_iterator it=grpNamesToKill.begin();it!=grpNamesToKill.end();it++)
3585 * \b this must be filled at level 0 and -1, typically the -1 level being (part of) the descending connectivity
3586 * of the top level. This method build a "crack" in \b this along the group of level -1 named grpNameM1.
3587 * The "crack" is built according to the following method:
3588 * - all nodes along the crack which are not lying on an internal extremity of the crack are duplicated (so the
3589 * coordinates array is extended). The
3590 * - new (-1)-level cells are built lying on those new nodes. So the edges/faces along the crack are duplicated.
3591 * After this operation a top-level cell bordering the crack will loose some neighbor (typically the cell which is on the
3592 * other side of the crack is no more a neighbor)
3593 * - finally, the connectivity of (part of) the top level-cells bordering the crack is also modified so that some cells
3594 * bordering the crack use the newly computed nodes.
3596 * \param[in] grpNameM1 name of the (-1)-level group defining the crack
3597 * \param[out] nodesDuplicated ids of the initial nodes which have been duplicated (and whose copy is put at the end of
3599 * \param[out] cellsModified ids of the cells whose connectivity has been modified (to use the newly created nodes)
3600 * \param[out] cellsNotModified ids of the rest of cells bordering the crack whose connectivity remains unchanged.
3602 void MEDFileUMesh::duplicateNodesOnM1Group(const std::string& grpNameM1, DataArrayInt *&nodesDuplicated,
3603 DataArrayInt *&cellsModified, DataArrayInt *&cellsNotModified)
3605 std::vector<int> levs=getNonEmptyLevels();
3606 if(std::find(levs.begin(),levs.end(),0)==levs.end() || std::find(levs.begin(),levs.end(),-1)==levs.end())
3607 throw INTERP_KERNEL::Exception("MEDFileUMesh::duplicateNodesOnM1Group : This method works only for mesh definied on level 0 and -1 !");
3608 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0=getMeshAtLevel(0);
3609 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1=getMeshAtLevel(-1);
3610 int nbNodes=m0->getNumberOfNodes();
3611 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m11=getGroup(-1,grpNameM1);
3612 DataArrayInt *tmp00=0,*tmp11=0,*tmp22=0;
3613 m0->findNodesToDuplicate(*m11,tmp00,tmp11,tmp22);
3614 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> nodeIdsToDuplicate(tmp00);
3615 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn0(tmp11);
3616 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsToModifyConn1(tmp22);
3617 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp0=static_cast<MEDCouplingUMesh *>(m0->buildPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),true));
3618 // node renumbering of cells in m1 impacted by duplication of node but not in group 'grpNameM1' on level -1
3619 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> descTmp0=DataArrayInt::New(),descITmp0=DataArrayInt::New(),revDescTmp0=DataArrayInt::New(),revDescITmp0=DataArrayInt::New();
3620 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp0Desc=tmp0->buildDescendingConnectivity(descTmp0,descITmp0,revDescTmp0,revDescITmp0);
3621 descTmp0=0; descITmp0=0; revDescTmp0=0; revDescITmp0=0;
3622 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW2=tmp0Desc->getCellIdsLyingOnNodes(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),false);
3623 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> cellsInM1ToRenumW3=static_cast<MEDCouplingUMesh *>(tmp0Desc->buildPartOfMySelf(cellsInM1ToRenumW2->begin(),cellsInM1ToRenumW2->end(),true));
3624 DataArrayInt *cellsInM1ToRenumW4Tmp=0;
3625 m1->areCellsIncludedIn(cellsInM1ToRenumW3,2,cellsInM1ToRenumW4Tmp);
3626 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW4(cellsInM1ToRenumW4Tmp);
3627 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenumW5=cellsInM1ToRenumW4->getIdsInRange(0,m1->getNumberOfCells());
3628 cellsInM1ToRenumW5->transformWithIndArr(cellsInM1ToRenumW4->begin(),cellsInM1ToRenumW4->end());
3629 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpIds=getGroupArr(-1,grpNameM1);
3630 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> cellsInM1ToRenum=cellsInM1ToRenumW5->buildSubstraction(grpIds);
3631 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1Part=static_cast<MEDCouplingUMesh *>(m1->buildPartOfMySelf(cellsInM1ToRenum->begin(),cellsInM1ToRenum->end(),true));
3632 m1Part->duplicateNodesInConn(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),nbNodes);
3633 m1->setPartOfMySelf(cellsInM1ToRenum->begin(),cellsInM1ToRenum->end(),*m1Part);
3634 // end of node renumbering of cells in m1 impacted by duplication of node but not in group of level -1 'grpNameM1'
3635 tmp0->duplicateNodes(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end());
3636 m0->setCoords(tmp0->getCoords());
3637 m0->setPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),*tmp0);
3638 m1->setCoords(m0->getCoords());
3639 _coords=m0->getCoords(); _coords->incrRef();
3640 // duplication of cells in group 'grpNameM1' on level -1
3641 m11->duplicateNodesInConn(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),nbNodes); m11->setCoords(m0->getCoords());
3642 std::vector<const MEDCouplingUMesh *> v(2); v[0]=m1; v[1]=m11;
3643 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> newm1=MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(v,tmp00,tmp11);
3644 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> szOfCellGrpOfSameType(tmp00);
3645 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> idInMsOfCellGrpOfSameType(tmp11);
3647 newm1->setName(getName());
3648 const DataArrayInt *fam=getFamilyFieldAtLevel(-1);
3650 throw INTERP_KERNEL::Exception("MEDFileUMesh::duplicateNodesOnM1Group : internal problem !");
3651 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFam=DataArrayInt::New();
3652 newFam->alloc(newm1->getNumberOfCells(),1);
3653 int idd=getMaxFamilyId()+1;
3654 int globStart=0,start=0,end,globEnd;
3655 int nbOfChunks=szOfCellGrpOfSameType->getNumberOfTuples();
3656 for(int i=0;i<nbOfChunks;i++)
3658 globEnd=globStart+szOfCellGrpOfSameType->getIJ(i,0);
3659 if(idInMsOfCellGrpOfSameType->getIJ(i,0)==0)
3661 end=start+szOfCellGrpOfSameType->getIJ(i,0);
3662 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> part=fam->selectByTupleId2(start,end,1);
3663 newFam->setPartOfValues1(part,globStart,globEnd,1,0,1,1,true);
3668 newFam->setPartOfValuesSimple1(idd,globStart,globEnd,1,0,1,1);
3672 newm1->setCoords(getCoords());
3673 setMeshAtLevel(-1,newm1);
3674 setFamilyFieldArr(-1,newFam);
3675 std::string grpName2(grpNameM1); grpName2+="_dup";
3676 addFamily(grpName2,idd);
3677 addFamilyOnGrp(grpName2,grpName2);
3682 int newNbOfNodes=getCoords()->getNumberOfTuples();
3683 newFam=DataArrayInt::New(); newFam->alloc(newNbOfNodes,1);
3684 newFam->setPartOfValues1(fam,0,nbNodes,1,0,1,1,true);
3685 newFam->setPartOfValuesSimple1(0,nbNodes,newNbOfNodes,1,0,1,1);
3688 nodesDuplicated=nodeIdsToDuplicate.retn();
3689 cellsModified=cellsToModifyConn0.retn();
3690 cellsNotModified=cellsToModifyConn1.retn();
3694 * \param [out] oldCode retrieves the distribution of types before the call if true is returned
3695 * \param [out] newCode etrieves the distribution of types after the call if true is returned
3696 * \param [out] o2nRenumCell tells for **all levels** the old 2 new renumbering of cells.
3698 * \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.
3699 * 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.
3701 bool MEDFileUMesh::unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell)
3703 o2nRenumCell=0; oldCode.clear(); newCode.clear();
3704 std::vector<int> levs=getNonEmptyLevels();
3706 std::vector< const DataArrayInt* > renumCellsSplited;//same than memorySaverIfThrow
3707 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > memorySaverIfThrow;//same than renumCellsSplited only in case of throw
3710 for(std::vector<int>::reverse_iterator it=levs.rbegin();it!=levs.rend();it++)
3712 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=getMeshAtLevel(*it);
3713 std::vector<int> code1=m->getDistributionOfTypes();
3714 end=PutInThirdComponentOfCodeOffset(code1,start);
3715 oldCode.insert(oldCode.end(),code1.begin(),code1.end());
3716 bool hasChanged=m->unPolyze();
3717 DataArrayInt *fake=0;
3718 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nCellsPart=m->getLevArrPerCellTypes(MEDCouplingUMesh::MEDMEM_ORDER,
3719 MEDCouplingUMesh::MEDMEM_ORDER+MEDCouplingUMesh::N_MEDMEM_ORDER,fake);
3721 renumCellsSplited.push_back(o2nCellsPart); memorySaverIfThrow.push_back(o2nCellsPart);
3724 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nCellsPart2=o2nCellsPart->buildPermArrPerLevel();
3725 m->renumberCells(o2nCellsPart2->getConstPointer(),false);
3727 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famField2,numField2;
3728 const DataArrayInt *famField=getFamilyFieldAtLevel(*it); if(famField) { famField->incrRef(); famField2=const_cast<DataArrayInt *>(famField); }
3729 const DataArrayInt *numField=getNumberFieldAtLevel(*it); if(numField) { numField->incrRef(); numField2=const_cast<DataArrayInt *>(numField); }
3730 setMeshAtLevel(*it,m);
3731 std::vector<int> code2=m->getDistributionOfTypes();
3732 end=PutInThirdComponentOfCodeOffset(code2,start);
3733 newCode.insert(newCode.end(),code2.begin(),code2.end());
3735 if(o2nCellsPart2->isIdentity())
3739 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFamField=famField->renumber(o2nCellsPart2->getConstPointer());
3740 setFamilyFieldArr(*it,newFamField);
3744 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newNumField=numField->renumber(o2nCellsPart2->getConstPointer());
3745 setRenumFieldArr(*it,newNumField);
3750 newCode.insert(newCode.end(),code1.begin(),code1.end());
3756 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renumCells=DataArrayInt::Aggregate(renumCellsSplited);
3757 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2nRenumCellRet=renumCells->buildPermArrPerLevel();
3758 o2nRenumCell=o2nRenumCellRet.retn();
3763 struct MEDLoaderAccVisit1
3765 MEDLoaderAccVisit1():_new_nb_of_nodes(0) { }
3766 int operator()(bool val) { return val?_new_nb_of_nodes++:-1; }
3767 int _new_nb_of_nodes;
3771 * Array returned is the correspondance in \b old \b to \b new format. The returned array is newly created and should be dealt by the caller.
3772 * The maximum value stored in returned array is the number of nodes of \a this minus 1 after call of this method.
3773 * The size of returned array is the number of nodes of the old (previous to the call of this method) number of nodes.
3774 * -1 values in returned array means that the corresponding old node is no more used.
3776 * \return newly allocated array containing correspondance in \b old \b to \b new format. If all nodes in \a this are fetched \c NULL pointer is returned and nothing
3777 * is modified in \a this.
3778 * \throw If no coordinates are set in \a this or if there is in any available mesh in \a this a cell having a nodal connectivity containing a node id not in the range of
3781 DataArrayInt *MEDFileUMesh::zipCoords()
3783 const DataArrayDouble *coo(getCoords());
3785 throw INTERP_KERNEL::Exception("MEDFileUMesh::zipCoords : no coordinates set in this !");
3786 int nbOfNodes(coo->getNumberOfTuples());
3787 std::vector<bool> nodeIdsInUse(nbOfNodes,false);
3788 std::vector<int> neLevs(getNonEmptyLevels());
3789 for(std::vector<int>::const_iterator lev=neLevs.begin();lev!=neLevs.end();lev++)
3791 const MEDFileUMeshSplitL1 *zeLev(getMeshAtLevSafe(*lev));
3792 if(zeLev->isMeshStoredSplitByType())
3794 std::vector<MEDCoupling1GTUMesh *> ms(zeLev->getDirectUndergroundSingleGeoTypeMeshes());
3795 for(std::vector<MEDCoupling1GTUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
3797 (*it)->computeNodeIdsAlg(nodeIdsInUse);
3801 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> mesh(zeLev->getWholeMesh(false));
3802 mesh->computeNodeIdsAlg(nodeIdsInUse);
3805 int nbrOfNodesInUse((int)std::count(nodeIdsInUse.begin(),nodeIdsInUse.end(),true));
3806 if(nbrOfNodesInUse==nbOfNodes)
3807 return 0;//no need to update _part_coords
3808 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New()); ret->alloc(nbOfNodes,1);
3809 std::transform(nodeIdsInUse.begin(),nodeIdsInUse.end(),ret->getPointer(),MEDLoaderAccVisit1());
3810 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret2(ret->invertArrayO2N2N2OBis(nbrOfNodesInUse));
3811 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> newCoords(coo->selectByTupleIdSafe(ret2->begin(),ret2->end()));
3812 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newFamCoords;
3813 MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar> newNameCoords;
3814 if((const DataArrayInt *)_fam_coords)
3815 newFamCoords=_fam_coords->selectByTupleIdSafe(ret2->begin(),ret2->end());
3816 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> newNumCoords;
3817 if((const DataArrayInt *)_num_coords)
3818 newNumCoords=_num_coords->selectByTupleIdSafe(ret2->begin(),ret2->end());
3819 if((const DataArrayAsciiChar *)_name_coords)
3820 newNameCoords=static_cast<DataArrayAsciiChar *>(_name_coords->selectByTupleIdSafe(ret2->begin(),ret2->end()));
3821 _coords=newCoords; _fam_coords=newFamCoords; _num_coords=newNumCoords; _name_coords=newNameCoords; _rev_num_coords=0;
3822 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
3824 if((MEDFileUMeshSplitL1*)*it)
3826 (*it)->renumberNodesInConn(ret->begin());
3827 (*it)->setCoords(_coords);
3830 // updates _part_coords
3831 const PartDefinition *pc(_part_coords);
3834 MEDCouplingAutoRefCountObjectPtr<PartDefinition> tmpPD(DataArrayPartDefinition::New(ret2));
3835 _part_coords=tmpPD->composeWith(pc);
3841 * This method performs an extrusion along a path defined by \a m1D.
3842 * \a this is expected to be a mesh with max mesh dimension equal to 2.
3843 * \a m1D is expected to be a mesh with space dimesion equal to 3 and mesh dimension equal to 1.
3844 * Mesh dimensions of returned mesh is incremented by one compared to thoose in \a this.
3845 * This method scans all levels in \a this
3846 * and put them in the returned mesh. All groups in \a this are also put in the returned mesh.
3848 * \param [in] m1D - the mesh defining the extrusion path.
3849 * \param [in] policy - defines the policy of extrusion (see MEDCouplingUMesh::buildExtrudedMesh for more details)
3850 * \return - a new reference on mesh (you have to deal with using decrRef). The returned mesh will have the same name than \a this.
3852 * \sa MEDCouplingUMesh::buildExtrudedMesh
3854 MEDFileUMesh *MEDFileUMesh::buildExtrudedMesh(const MEDCouplingUMesh *m1D, int policy) const
3856 if(getMeshDimension()!=2)
3857 throw INTERP_KERNEL::Exception("MEDFileUMesh::buildExtrudedMesh : this is expected to be with mesh dimension equal to 2 !");
3858 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(MEDFileUMesh::New());
3859 m1D->checkCoherency();
3860 if(m1D->getMeshDimension()!=1)
3861 throw INTERP_KERNEL::Exception("MEDFileUMesh::buildExtrudedMesh : input mesh must have a mesh dimension equal to one !");
3862 int nbRep(m1D->getNumberOfCells());
3863 std::vector<int> levs(getNonEmptyLevels());
3864 std::vector<std::string> grps(getGroupsNames());
3865 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> > zeList;
3866 DataArrayDouble *coords(0);
3867 std::size_t nbOfLevsOut(levs.size()+1);
3868 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > o2ns(nbOfLevsOut);
3869 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
3871 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> item(getMeshAtLevel(*lev));
3872 item=item->clone(false);
3873 item->changeSpaceDimension(3+(*lev),0.);//no problem non const but change DataArrayDouble for coordinates do not alter data
3874 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> tmp(static_cast<MEDCouplingUMesh *>(m1D->deepCpy()));
3875 tmp->changeSpaceDimension(3+(*lev),0.);
3876 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> elt(item->buildExtrudedMesh(tmp,policy));
3877 zeList.push_back(elt);
3879 coords=elt->getCoords();
3882 throw INTERP_KERNEL::Exception("MEDFileUMesh::buildExtrudedMesh : internal error !");
3883 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> >::iterator it=zeList.begin();it!=zeList.end();it++)
3885 (*it)->setName(getName());
3886 (*it)->setCoords(coords);
3888 for(std::size_t ii=0;ii!=zeList.size();ii++)
3891 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> elt(zeList[ii]);
3894 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> elt1(getMeshAtLevel(lev+1));
3895 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> elt2(elt1->clone(false));
3896 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(elt2->getNodalConnectivity()->deepCpy());
3897 elt2->setConnectivity(tmp,elt2->getNodalConnectivityIndex());
3898 elt2->shiftNodeNumbersInConn(nbRep*elt1->getNumberOfNodes());
3899 elt1->setCoords(elt->getCoords()); elt2->setCoords(elt->getCoords());
3900 std::vector<const MEDCouplingUMesh *> elts(3);
3901 elts[0]=elt; elts[1]=elt1; elts[2]=elt2;
3902 elt=MEDCouplingUMesh::MergeUMeshesOnSameCoords(elts);
3903 elt->setName(getName());
3906 o2ns[ii]=elt->sortCellsInMEDFileFrmt();
3907 ret->setMeshAtLevel(lev,elt);
3909 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> endLev(getMeshAtLevel(levs.back())),endLev2;
3910 endLev=endLev->clone(false); endLev->setCoords(coords);
3911 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> tmp(endLev->getNodalConnectivity()->deepCpy());
3912 endLev2=endLev->clone(false); endLev2->setConnectivity(tmp,endLev->getNodalConnectivityIndex());
3913 endLev2->shiftNodeNumbersInConn(nbRep*getNumberOfNodes());
3914 endLev=MEDCouplingUMesh::MergeUMeshesOnSameCoords(endLev,endLev2);
3915 o2ns[levs.size()]=endLev->sortCellsInMEDFileFrmt();
3916 endLev->setName(getName());
3917 ret->setMeshAtLevel(levs.back()-1,endLev);
3919 for(std::size_t ii=0;ii!=zeList.size();ii++)
3922 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > outGrps;
3923 std::vector< const DataArrayInt * > outGrps2;
3926 for(std::vector<std::string>::const_iterator grp=grps.begin();grp!=grps.end();grp++)
3928 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr(getGroupArr(lev+1,*grp));
3929 if(!grpArr->empty())
3931 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr1(grpArr->deepCpy()),grpArr2(grpArr->deepCpy());
3932 int offset0(zeList[ii]->getNumberOfCells());
3933 int offset1(offset0+getNumberOfCellsAtLevel(lev+1));
3934 grpArr1->applyLin(1,offset0); grpArr2->applyLin(1,offset1);
3935 std::ostringstream oss; oss << grpArr2->getName() << "_top";
3936 grpArr2->setName(oss.str());
3937 grpArr1->transformWithIndArr(o2ns[ii]->begin(),o2ns[ii]->end());
3938 grpArr2->transformWithIndArr(o2ns[ii]->begin(),o2ns[ii]->end());
3939 outGrps.push_back(grpArr1); outGrps.push_back(grpArr2);
3940 outGrps2.push_back(grpArr1); outGrps2.push_back(grpArr2);
3945 for(std::vector<std::string>::const_iterator grp=grps.begin();grp!=grps.end();grp++)
3947 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr(getGroupArr(lev,*grp));
3948 if(!grpArr->empty())
3950 int nbCellsB4Extrusion(getNumberOfCellsAtLevel(lev));
3951 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > grpArrs(nbRep);
3952 std::vector< const DataArrayInt *> grpArrs2(nbRep);
3953 for(int iii=0;iii<nbRep;iii++)
3955 grpArrs[iii]=grpArr->deepCpy(); grpArrs[iii]->applyLin(1,iii*nbCellsB4Extrusion);
3956 grpArrs2[iii]=grpArrs[iii];
3958 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArrExt(DataArrayInt::Aggregate(grpArrs2));
3959 grpArrExt->transformWithIndArr(o2ns[ii]->begin(),o2ns[ii]->end());
3960 std::ostringstream grpName; grpName << *grp << "_extruded";
3961 grpArrExt->setName(grpName.str());
3962 outGrps.push_back(grpArrExt);
3963 outGrps2.push_back(grpArrExt);
3966 ret->setGroupsAtLevel(lev,outGrps2);
3968 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > outGrps;
3969 std::vector< const DataArrayInt * > outGrps2;
3970 for(std::vector<std::string>::const_iterator grp=grps.begin();grp!=grps.end();grp++)
3972 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr1(getGroupArr(levs.back(),*grp));
3973 if(grpArr1->empty())
3975 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> grpArr2(grpArr1->deepCpy());
3976 std::ostringstream grpName; grpName << *grp << "_top";
3977 grpArr2->setName(grpName.str());
3978 grpArr2->applyLin(1,getNumberOfCellsAtLevel(levs.back()));
3979 outGrps.push_back(grpArr1); outGrps.push_back(grpArr2);
3980 outGrps2.push_back(grpArr1); outGrps2.push_back(grpArr2);
3982 ret->setGroupsAtLevel(levs.back()-1,outGrps2);
3987 * This method converts all linear cells in \a this into quadratic cells (following the \a conversionType policy).
3988 * All the cells converted are put in the returned instance. This method applies all the groups and families in \a this to returned instance.
3989 * Groups on nodes and families on nodes are copied directly to the returned instance without transformation.
3991 * \param [in] conversionType - conversionType specifies the type of conversion expected. Only 0 (default) and 1 are supported presently. 0 those that creates the 'most' simple
3992 * corresponding quadratic cells. 1 is those creating the 'most' complex.
3993 * \param [in] eps - detection threshold for coordinates.
3994 * \return A new instance that is the result of the conversion. The caller has the ownership of this returned instance.
3996 * \sa MEDCouplingUMesh::convertLinearCellsToQuadratic , quadraticToLinear
3998 MEDFileUMesh *MEDFileUMesh::linearToQuadratic(int conversionType, double eps) const
4000 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(MEDFileUMesh::New());
4001 int initialNbNodes(getNumberOfNodes());
4002 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0Tmp(getMeshAtLevel(0));
4003 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0(dynamic_cast<MEDCouplingUMesh *>(m0Tmp->deepCpy()));
4005 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> notUsed(m0->convertLinearCellsToQuadratic(conversionType));
4007 DataArrayDouble *zeCoords(m0->getCoords());
4008 ret->setMeshAtLevel(0,m0);
4009 std::vector<int> levs(getNonEmptyLevels());
4010 const DataArrayInt *famField(getFamilyFieldAtLevel(0));
4013 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famFieldCpy(famField->deepCpy());
4014 ret->setFamilyFieldArr(0,famFieldCpy);
4016 famField=getFamilyFieldAtLevel(1);
4019 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam(DataArrayInt::New()); fam->alloc(zeCoords->getNumberOfTuples(),1);
4020 fam->fillWithZero();
4021 fam->setPartOfValues1(famField,0,initialNbNodes,1,0,1,1);
4022 ret->setFamilyFieldArr(1,fam);
4024 ret->copyFamGrpMapsFrom(*this);
4025 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> partZeCoords(zeCoords->selectByTupleId2(initialNbNodes,zeCoords->getNumberOfTuples(),1));
4026 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
4030 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1Tmp(getMeshAtLevel(*lev));
4031 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1(dynamic_cast<MEDCouplingUMesh *>(m1Tmp->deepCpy()));
4033 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> notUsed(m1->convertLinearCellsToQuadratic(conversionType));
4035 MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> m1Coords(m1->getCoords()->selectByTupleId2(initialNbNodes,m1->getNumberOfNodes(),1));
4037 bool a(partZeCoords->areIncludedInMe(m1Coords,eps,b));
4038 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> bSafe(b);
4041 std::ostringstream oss; oss << "MEDFileUMesh::linearCellsToQuadratic : for level " << *lev << " problem to identify nodes generated !";
4042 throw INTERP_KERNEL::Exception(oss.str().c_str());
4044 b->applyLin(1,initialNbNodes);
4045 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> l0(DataArrayInt::New()); l0->alloc(initialNbNodes,1); l0->iota();
4046 std::vector<const DataArrayInt *> v(2); v[0]=l0; v[1]=b;
4047 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> renum(DataArrayInt::Aggregate(v));
4048 m1->renumberNodesInConn(renum->begin());
4049 m1->setCoords(zeCoords);
4050 ret->setMeshAtLevel(*lev,m1);
4051 famField=getFamilyFieldAtLevel(*lev);
4054 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famFieldCpy(famField->deepCpy());
4055 ret->setFamilyFieldArr(*lev,famFieldCpy);
4062 * This method converts all quadratic cells in \a this into linear cells.
4063 * All the cells converted are put in the returned instance. This method applies all the groups and families in \a this to returned instance.
4064 * Groups on nodes and families on nodes are copied directly to the returned instance without transformation.
4066 * \param [in] eps - detection threshold for coordinates.
4067 * \return A new instance that is the result of the conversion. The caller has the ownership of this returned instance.
4069 * \sa MEDCouplingUMesh::convertLinearCellsToQuadratic , linearToQuadratic
4071 MEDFileUMesh *MEDFileUMesh::quadraticToLinear(double eps) const
4073 MEDCouplingAutoRefCountObjectPtr<MEDFileUMesh> ret(MEDFileUMesh::New());
4074 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0Tmp(getMeshAtLevel(0));
4075 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m0(dynamic_cast<MEDCouplingUMesh *>(m0Tmp->deepCpy()));
4076 m0->convertQuadraticCellsToLinear();
4078 DataArrayDouble *zeCoords(m0->getCoords());
4079 ret->setMeshAtLevel(0,m0);
4080 std::vector<int> levs(getNonEmptyLevels());
4081 const DataArrayInt *famField(getFamilyFieldAtLevel(0));
4084 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famFieldCpy(famField->deepCpy());
4085 ret->setFamilyFieldArr(0,famFieldCpy);
4087 famField=getFamilyFieldAtLevel(1);
4090 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> fam(famField->selectByTupleId2(0,zeCoords->getNumberOfTuples(),1));
4091 ret->setFamilyFieldArr(1,fam);
4093 ret->copyFamGrpMapsFrom(*this);
4094 for(std::vector<int>::const_iterator lev=levs.begin();lev!=levs.end();lev++)
4098 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1Tmp(getMeshAtLevel(*lev));
4099 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m1(dynamic_cast<MEDCouplingUMesh *>(m1Tmp->deepCpy()));
4100 m1->convertQuadraticCellsToLinear();
4103 bool a(zeCoords->areIncludedInMe(m1->getCoords(),eps,b));
4104 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> bSafe(b);
4107 std::ostringstream oss; oss << "MEDFileUMesh::quadraticToLinear : for level " << *lev << " problem to identify nodes generated !";
4108 throw INTERP_KERNEL::Exception(oss.str().c_str());
4110 m1->renumberNodesInConn(b->begin());
4111 m1->setCoords(zeCoords);
4112 ret->setMeshAtLevel(*lev,m1);
4113 famField=getFamilyFieldAtLevel(*lev);
4116 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famFieldCpy(famField->deepCpy());
4117 ret->setFamilyFieldArr(*lev,famFieldCpy);
4123 void MEDFileUMesh::serialize(std::vector<double>& tinyDouble, std::vector<int>& tinyInt, std::vector<std::string>& tinyStr, std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI, MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& bigArrayD)
4125 clearNonDiscrAttributes();
4126 forceComputationOfParts();
4127 tinyDouble.clear(); tinyInt.clear(); tinyStr.clear(); bigArraysI.clear(); bigArrayD=0;
4128 std::vector<int> layer0;
4129 layer0.push_back(_order); //0 i
4130 layer0.push_back(_iteration);//1 i
4131 layer0.push_back(getSpaceDimension());//2 i
4132 tinyDouble.push_back(_time);//0 d
4133 tinyStr.push_back(_name);//0 s
4134 tinyStr.push_back(_desc_name);//1 s
4135 for(int i=0;i<getSpaceDimension();i++)
4136 tinyStr.push_back(_coords->getInfoOnComponent(i));
4137 layer0.push_back((int)_families.size());//3 i <- key info aa layer#0
4138 for(std::map<std::string,int>::const_iterator it=_families.begin();it!=_families.end();it++)
4140 tinyStr.push_back((*it).first);
4141 layer0.push_back((*it).second);
4143 layer0.push_back((int)_groups.size());//3+aa i <- key info bb layer#0
4144 for(std::map<std::string, std::vector<std::string> >::const_iterator it0=_groups.begin();it0!=_groups.end();it0++)
4146 layer0.push_back((int)(*it0).second.size());
4147 tinyStr.push_back((*it0).first);
4148 for(std::vector<std::string>::const_iterator it1=((*it0).second).begin();it1!=((*it0).second).end();it1++)
4149 tinyStr.push_back(*it1);
4151 // sizeof(layer0)==3+aa+1+bb layer#0
4152 bigArrayD=_coords;// 0 bd
4153 bigArraysI.push_back(_fam_coords);// 0 bi
4154 bigArraysI.push_back(_num_coords);// 1 bi
4155 const PartDefinition *pd(_part_coords);
4157 layer0.push_back(-1);
4160 std::vector<int> tmp0;
4161 pd->serialize(tmp0,bigArraysI);
4162 tinyInt.push_back(tmp0.size());
4163 tinyInt.insert(tinyInt.end(),tmp0.begin(),tmp0.end());
4166 std::vector<int> layer1;
4167 std::vector<int> levs(getNonEmptyLevels());
4168 layer1.push_back((int)levs.size());// 0 i <- key
4169 layer1.insert(layer1.end(),levs.begin(),levs.end());
4170 for(std::vector<int>::const_iterator it=levs.begin();it!=levs.end();it++)
4172 const MEDFileUMeshSplitL1 *lev(getMeshAtLevSafe(*it));
4173 lev->serialize(layer1,bigArraysI);
4175 // put layers all together.
4176 tinyInt.push_back(layer0.size());
4177 tinyInt.insert(tinyInt.end(),layer0.begin(),layer0.end());
4178 tinyInt.push_back(layer1.size());
4179 tinyInt.insert(tinyInt.end(),layer1.begin(),layer1.end());
4182 void MEDFileUMesh::unserialize(std::vector<double>& tinyDouble, std::vector<int>& tinyInt, std::vector<std::string>& tinyStr,
4183 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >& bigArraysI, MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>& bigArrayD)
4185 int sz0(tinyInt[0]);
4186 std::vector<int> layer0(tinyInt.begin()+1,tinyInt.begin()+1+sz0);
4187 int sz1(tinyInt[sz0+1]);
4188 std::vector<int> layer1(tinyInt.begin()+2+sz0,tinyInt.begin()+2+sz0+sz1);
4190 std::reverse(layer0.begin(),layer0.end());
4191 std::reverse(layer1.begin(),layer1.end());
4192 std::reverse(tinyDouble.begin(),tinyDouble.end());
4193 std::reverse(tinyStr.begin(),tinyStr.end());
4194 std::reverse(bigArraysI.begin(),bigArraysI.end());
4196 _order=layer0.back(); layer0.pop_back();
4197 _iteration=layer0.back(); layer0.pop_back();
4198 int spaceDim(layer0.back()); layer0.pop_back();
4199 _time=tinyDouble.back(); tinyDouble.pop_back();
4200 _name=tinyStr.back(); tinyStr.pop_back();
4201 _desc_name=tinyStr.back(); tinyStr.pop_back();
4202 _coords=bigArrayD; _coords->rearrange(spaceDim);
4203 for(int i=0;i<spaceDim;i++)
4205 _coords->setInfoOnComponent(i,tinyStr.back());
4208 int nbOfFams(layer0.back()); layer0.pop_back();
4210 for(int i=0;i<nbOfFams;i++)
4212 _families[tinyStr.back()]=layer0.back();
4213 tinyStr.pop_back(); layer0.pop_back();
4215 int nbGroups(layer0.back()); layer0.pop_back();
4217 for(int i=0;i<nbGroups;i++)
4219 std::string grpName(tinyStr.back()); tinyStr.pop_back();
4220 int nbOfFamsOnGrp(layer0.back()); layer0.pop_back();
4221 std::vector<std::string> fams(nbOfFamsOnGrp);
4222 for(int j=0;j<nbOfFamsOnGrp;j++)
4224 fams[j]=tinyStr.back(); tinyStr.pop_back();
4226 _groups[grpName]=fams;
4228 _fam_coords=bigArraysI.back(); bigArraysI.pop_back();
4229 _num_coords=bigArraysI.back(); bigArraysI.pop_back();
4231 int isPd(layer0.back()); layer0.pop_back();
4234 std::vector<int> tmp0(layer0.begin(),layer0.begin()+isPd);
4235 layer0.erase(layer0.begin(),layer0.begin()+isPd);
4236 _part_coords=PartDefinition::Unserialize(tmp0,bigArraysI);
4239 throw INTERP_KERNEL::Exception("MEDFileUMesh::unserialize : something wrong during unserialization #1 !");
4241 int nbLevs(layer1.back()); layer1.pop_back();
4242 std::vector<int> levs(layer1.rbegin(),layer1.rbegin()+nbLevs); layer1.erase(layer1.end()-nbLevs,layer1.end());
4244 int maxLev(-(*std::min_element(levs.begin(),levs.end())));
4245 _ms.resize(maxLev+1);
4246 for(int i=0;i<nbLevs;i++)
4250 _ms[pos]=MEDFileUMeshSplitL1::Unserialize(_name,_coords,layer1,bigArraysI);
4255 * Adds a group of nodes to \a this mesh.
4256 * \param [in] ids - a DataArrayInt providing ids and a name of the group to add.
4257 * The ids should be sorted and different each other (MED file norm).
4259 * \warning this method can alter default "FAMILLE_ZERO" family.
4260 * For users sensitive to this a call to MEDFileMesh::rearrangeFamilies will be necessary after addGroup session.
4262 * \throw If the node coordinates array is not set.
4263 * \throw If \a ids == \c NULL.
4264 * \throw If \a ids->getName() == "".
4265 * \throw If \a ids does not respect the MED file norm.
4266 * \throw If a group with name \a ids->getName() already exists.
4268 void MEDFileUMesh::addNodeGroup(const DataArrayInt *ids)
4270 const DataArrayDouble *coords(_coords);
4272 throw INTERP_KERNEL::Exception("MEDFileUMesh::addNodeGroup : no coords set !");
4273 int nbOfNodes(coords->getNumberOfTuples());
4274 if(!((DataArrayInt *)_fam_coords))
4275 { _fam_coords=DataArrayInt::New(); _fam_coords->alloc(nbOfNodes,1); _fam_coords->fillWithZero(); }
4277 addGroupUnderground(true,ids,_fam_coords);
4281 * Adds a group of nodes/cells/faces/edges to \a this mesh.
4283 * \param [in] ids - a DataArrayInt providing ids and a name of the group to add.
4284 * The ids should be sorted and different each other (MED file norm).
4286 * \warning this method can alter default "FAMILLE_ZERO" family.
4287 * For users sensitive to this a call to MEDFileMesh::rearrangeFamilies will be necessary after addGroup session.
4289 * \throw If the node coordinates array is not set.
4290 * \throw If \a ids == \c NULL.
4291 * \throw If \a ids->getName() == "".
4292 * \throw If \a ids does not respect the MED file norm.
4293 * \throw If a group with name \a ids->getName() already exists.
4295 void MEDFileUMesh::addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids)
4297 std::vector<int> levs(getNonEmptyLevelsExt());
4298 if(std::find(levs.begin(),levs.end(),meshDimRelToMaxExt)==levs.end())
4300 std::ostringstream oss; oss << "MEDFileUMesh::addGroup : level " << meshDimRelToMaxExt << " not available ! Should be in ";
4301 std::copy(levs.begin(),levs.end(),std::ostream_iterator<int>(oss," ")); oss << " !"; throw INTERP_KERNEL::Exception(oss.str().c_str());
4303 if(meshDimRelToMaxExt==1)
4304 { addNodeGroup(ids); return ; }
4305 MEDFileUMeshSplitL1 *lev(getMeshAtLevSafe(meshDimRelToMaxExt));
4306 DataArrayInt *fam(lev->getOrCreateAndGetFamilyField());
4307 addGroupUnderground(false,ids,fam);
4311 * Changes a name of a family specified by its id.
4312 * \param [in] id - the id of the family of interest.
4313 * \param [in] newFamName - the new family name.
4314 * \throw If no family with the given \a id exists.
4316 void MEDFileUMesh::setFamilyNameAttachedOnId(int id, const std::string& newFamName)
4318 std::string oldName=getFamilyNameGivenId(id);
4319 _families.erase(oldName);
4320 _families[newFamName]=id;
4324 * Removes a mesh of a given dimension.
4325 * \param [in] meshDimRelToMax - the relative dimension of interest.
4326 * \throw If there is no mesh at level \a meshDimRelToMax in \a this mesh.
4328 void MEDFileUMesh::removeMeshAtLevel(int meshDimRelToMax)
4330 std::vector<int> levSet=getNonEmptyLevels();
4331 std::vector<int>::const_iterator it=std::find(levSet.begin(),levSet.end(),meshDimRelToMax);
4332 if(it==levSet.end())
4333 throw INTERP_KERNEL::Exception("MEDFileUMesh::removeMeshAtLevel : the requested level is not existing !");
4334 int pos=(-meshDimRelToMax);
4339 * Sets a new MEDCoupling1GTUMesh at a given level in \a this mesh.
4340 * \param [in] meshDimRelToMax - a relative level to set the mesh at.
4341 * \param [in] m - the new mesh to set.
4342 * \throw If the name or the description of \a this mesh and \a m are not empty and are
4344 * \throw If the node coordinates array is set \a this in mesh and \a m refers to
4345 * another node coordinates array.
4346 * \throw If the mesh dimension of \a m does not correspond to \a meshDimRelToMax or
4347 * to the existing meshes of other levels of \a this mesh.
4349 void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCoupling1GTUMesh *m)
4351 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> elt(new MEDFileUMeshSplitL1(m));
4352 checkAndGiveEntryInSplitL1(meshDimRelToMax,m)=elt;
4356 * Sets a new MEDCouplingUMesh at a given level in \a this mesh.
4357 * \param [in] meshDimRelToMax - a relative level to set the mesh at.
4358 * \param [in] m - the new mesh to set.
4359 * \param [in] newOrOld - if \c true, cells in \a m are sorted by type to be ready for
4360 * writing \a this mesh in a MED file.
4361 * \throw If the name or the description of \a this mesh and \a m are not empty and are
4363 * \throw If the node coordinates array is set \a this in mesh and \a m refers to
4364 * another node coordinates array.
4365 * \throw If the mesh dimension of \a m does not correspond to \a meshDimRelToMax or
4366 * to the existing meshes of other levels of \a this mesh.
4368 void MEDFileUMesh::setMeshAtLevel(int meshDimRelToMax, MEDCouplingUMesh *m, bool newOrOld)
4370 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> elt(new MEDFileUMeshSplitL1(m,newOrOld));
4371 checkAndGiveEntryInSplitL1(meshDimRelToMax,m)=elt;
4374 MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1>& MEDFileUMesh::checkAndGiveEntryInSplitL1(int meshDimRelToMax, MEDCouplingPointSet *m)
4376 dealWithTinyInfo(m);
4377 std::vector<int> levSet=getNonEmptyLevels();
4378 if(std::find(levSet.begin(),levSet.end(),meshDimRelToMax)==levSet.end())
4380 if((DataArrayDouble *)_coords==0)
4382 DataArrayDouble *c=m->getCoords();
4387 if(m->getCoords()!=_coords)
4388 throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshAtLevel : Invalid Given Mesh ! The coordinates are not the same ! try to use tryToShareSameCoords !");
4389 int sz=(-meshDimRelToMax)+1;
4390 if(sz>=(int)_ms.size())
4392 checkMeshDimCoherency(m->getMeshDimension(),meshDimRelToMax);
4396 return _ms[-meshDimRelToMax];
4400 * This method allows to set at once the content of different levels in \a this.
4401 * This method is equivalent to a series of call to MEDFileUMesh::setMeshAtLevel.
4403 * \param [in] ms - List of unstructured meshes lying on the same coordinates and having different mesh dimesnion.
4404 * \param [in] renum - the parameter (set to false by default) that tells the beheviour if there is a mesh on \a ms that is not geo type sorted.
4405 * If false, an exception ois thrown. If true the mesh is reordered automatically. It is highly recommanded to let this parameter to false.
4407 * \throw If \a there is a null pointer in \a ms.
4408 * \sa MEDFileUMesh::setMeshAtLevel
4410 void MEDFileUMesh::setMeshes(const std::vector<const MEDCouplingUMesh *>& ms, bool renum)
4414 const MEDCouplingUMesh *mRef=ms[0];
4416 throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshes : null instance in the first element of input meshes !");
4417 std::string name(mRef->getName());
4418 const DataArrayDouble *coo(mRef->getCoords());
4421 for(std::vector<const MEDCouplingUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
4423 const MEDCouplingUMesh *cur(*it);
4425 throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshes : null instance in input vector of meshes !");
4426 if(coo!=cur->getCoords())
4427 throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshes : The input meshes do not share the same coordinates !");
4428 int mdim=cur->getMeshDimension();
4429 zeDim=std::max(zeDim,mdim);
4430 if(s.find(mdim)!=s.end())
4431 throw INTERP_KERNEL::Exception("MEDFileUMesh::setMeshes : The input meshes must share the same coordinates pointer, and should have different mesh dimension each other !");
4433 for(std::vector<const MEDCouplingUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++)
4435 int mdim=(*it)->getMeshDimension();
4436 setName((*it)->getName());
4437 setMeshAtLevel(mdim-zeDim,const_cast<MEDCouplingUMesh *>(*it),renum);
4443 * Creates one MEDCouplingUMesh at a given level in \a this mesh from a sequence of
4444 * meshes each representing a group, and creates corresponding groups in \a this mesh.
4445 * The given meshes must share the same node coordinates array.
4446 * \param [in] meshDimRelToMax - the relative dimension to create the mesh and groups at.
4447 * \param [in] ms - the sequence of meshes. Each mesh in \a ms represents a group to
4448 * create in \a this mesh.
4449 * \throw If \a ms is empty.
4450 * \throw If dimension of meshes in \a ms does not correspond to \a meshDimRelToMax or
4451 * to the existing meshes of other levels of \a this mesh.
4452 * \throw If the meshes in \a ms do not share the same node coordinates array.
4453 * \throw If the node coordinates array of \a this mesh (if any) is not the same as that
4454 * of the given meshes.
4455 * \throw If \a ms[ i ] is not well defined (MEDCouplingUMesh::checkCoherency()).
4456 * \throw If names of some meshes in \a ms are equal.
4457 * \throw If \a ms includes a mesh with an empty name.
4459 void MEDFileUMesh::setGroupsFromScratch(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum)
4462 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : expecting a non empty vector !");
4463 int sz=(-meshDimRelToMax)+1;
4464 if(sz>=(int)_ms.size())
4466 checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
4467 DataArrayDouble *coo=checkMultiMesh(ms);
4468 if((DataArrayDouble *)_coords==0)
4474 if((DataArrayDouble *)_coords!=coo)
4475 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsFromScratch : coordinates mismatches !");
4476 std::vector<DataArrayInt *> corr;
4477 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,_zipconn_pol,corr);
4478 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr3(corr.begin(),corr.end());
4479 setMeshAtLevel(meshDimRelToMax,m,renum);
4480 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
4481 setGroupsAtLevel(meshDimRelToMax,corr2,true);
4485 * Creates groups at a given level in \a this mesh from a sequence of
4486 * meshes each representing a group.
4487 * The given meshes must share the same node coordinates array.
4488 * \param [in] meshDimRelToMax - the relative dimension to create the groups at.
4489 * \param [in] ms - the sequence of meshes. Each mesh in \a ms represents a group to
4490 * create in \a this mesh.
4491 * \param [in] renum - if \c true, then the optional numbers of entities are taken into
4493 * \throw If \a ms is empty.
4494 * \throw If dimension of meshes in \a ms does not correspond to \a meshDimRelToMax or
4495 * to the existing meshes of other levels of \a this mesh.
4496 * \throw If the meshes in \a ms do not share the same node coordinates array.
4497 * \throw If the node coordinates array of \a this mesh (if any) is not the same as that
4498 * of the given meshes.
4499 * \throw If \a ms[ i ] is not well defined (MEDCouplingUMesh::checkCoherency()).
4500 * \throw If names of some meshes in \a ms are equal.
4501 * \throw If \a ms includes a mesh with an empty name.
4503 void MEDFileUMesh::setGroupsOnSetMesh(int meshDimRelToMax, const std::vector<const MEDCouplingUMesh *>& ms, bool renum)
4506 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : expecting a non empty vector !");
4507 int sz=(-meshDimRelToMax)+1;
4508 if(sz>=(int)_ms.size())
4510 checkMeshDimCoherency(ms[0]->getMeshDimension(),meshDimRelToMax);
4511 DataArrayDouble *coo=checkMultiMesh(ms);
4512 if((DataArrayDouble *)_coords==0)
4518 if((DataArrayDouble *)_coords!=coo)
4519 throw INTERP_KERNEL::Exception("MEDFileUMesh::setGroupsOnSetMesh : coordinates mismatches !");
4520 MEDCouplingUMesh *m=getMeshAtLevel(meshDimRelToMax,renum);
4521 std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > corr(ms.size());
4523 for(std::vector<const MEDCouplingUMesh *>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
4525 DataArrayInt *arr=0;
4526 bool test=m->areCellsIncludedIn(*it,_zipconn_pol,arr);
4530 std::ostringstream oss; oss << "MEDFileUMesh::setGroupsOnSetMesh : mesh #" << i << " is not part of whole mesh !";
4531 throw INTERP_KERNEL::Exception(oss.str().c_str());
4534 std::vector<const DataArrayInt *> corr2(corr.begin(),corr.end());
4535 setGroupsAtLevel(meshDimRelToMax,corr2,renum);
4538 DataArrayDouble *MEDFileUMesh::checkMultiMesh(const std::vector<const MEDCouplingUMesh *>& ms) const
4540 const DataArrayDouble *ret=ms[0]->getCoords();
4541 int mdim=ms[0]->getMeshDimension();
4542 for(unsigned int i=1;i<ms.size();i++)
4544 ms[i]->checkCoherency();
4545 if(ms[i]->getCoords()!=ret)
4546 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes must share the same coords !");
4547 if(ms[i]->getMeshDimension()!=mdim)
4548 throw INTERP_KERNEL::Exception("MEDFileUMesh::checkMultiMesh : meshes have not same mesh dimension !");
4550 return const_cast<DataArrayDouble *>(ret);
4554 * Sets the family field of a given relative dimension.
4555 * \param [in] meshDimRelToMaxExt - the relative dimension of entities for which
4556 * the family field is set.
4557 * \param [in] famArr - the array of the family field.
4558 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
4559 * \throw If \a famArr has an invalid size.
4561 void MEDFileUMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr)
4563 if(meshDimRelToMaxExt==1)
4570 DataArrayDouble *coo(_coords);
4572 throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : the coordinates have not been set !");
4573 famArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),1,"MEDFileUMesh::setFamilyFieldArr : Problem in size of node family arr ! ");
4578 if(meshDimRelToMaxExt>1)
4579 throw INTERP_KERNEL::Exception("MEDFileUMesh::setFamilyFieldArr : Dimension request is invalid (>1) !");
4580 int traducedRk=-meshDimRelToMaxExt;
4581 if(traducedRk>=(int)_ms.size())
4582 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! Too low !");
4583 if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
4584 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
4585 return _ms[traducedRk]->setFamilyArr(famArr);
4589 * Sets the optional numbers of mesh entities of a given dimension.
4590 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
4591 * \param [in] renumArr - the array of the numbers.
4592 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
4593 * \throw If \a renumArr has an invalid size.
4595 void MEDFileUMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr)
4597 if(meshDimRelToMaxExt==1)
4605 DataArrayDouble *coo(_coords);
4607 throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumFieldArr : the coordinates have not been set !");
4608 renumArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),1,"MEDFileUMesh::setRenumArr : Problem in size of node numbering arr ! ");
4609 renumArr->incrRef();
4610 _num_coords=renumArr;
4614 if(meshDimRelToMaxExt>1)
4615 throw INTERP_KERNEL::Exception("MEDFileUMesh::setRenumArr : Dimension request is invalid (>1) !");
4616 int traducedRk=-meshDimRelToMaxExt;
4617 if(traducedRk>=(int)_ms.size())
4618 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! Too low !");
4619 if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
4620 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
4621 return _ms[traducedRk]->setRenumArr(renumArr);
4625 * Sets the optional names of mesh entities of a given dimension.
4626 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
4627 * \param [in] nameArr - the array of the names.
4628 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
4629 * \throw If \a nameArr has an invalid size.
4631 void MEDFileUMesh::setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr)
4633 if(meshDimRelToMaxExt==1)
4640 DataArrayDouble *coo(_coords);
4642 throw INTERP_KERNEL::Exception("MEDFileUMesh::setNameFieldAtLevel : the coordinates have not been set !");
4643 nameArr->checkNbOfTuplesAndComp(coo->getNumberOfTuples(),MED_SNAME_SIZE,"MEDFileUMesh::setNameFieldAtLevel : Problem in size of node numbering arr ! ");
4645 _name_coords=nameArr;
4648 if(meshDimRelToMaxExt>1)
4649 throw INTERP_KERNEL::Exception("MEDFileUMesh::setNameFieldAtLevel : Dimension request is invalid (>1) !");
4650 int traducedRk=-meshDimRelToMaxExt;
4651 if(traducedRk>=(int)_ms.size())
4652 throw INTERP_KERNEL::Exception("Invalid mesh dim relative to max given ! Too low !");
4653 if((MEDFileUMeshSplitL1 *)_ms[traducedRk]==0)
4654 throw INTERP_KERNEL::Exception("On specified lev (or entity) no cells exists !");
4655 return _ms[traducedRk]->setNameArr(nameArr);
4658 void MEDFileUMesh::synchronizeTinyInfoOnLeaves() const
4660 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
4661 if((const MEDFileUMeshSplitL1 *)(*it))
4662 (*it)->synchronizeTinyInfo(*this);
4666 * This method is called by MEDFileMesh::changeFamilyId. It performs only one part of the family id modification.
4668 void MEDFileUMesh::changeFamilyIdArr(int oldId, int newId)
4670 DataArrayInt *arr=_fam_coords;
4672 arr->changeValue(oldId,newId);
4673 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::iterator it=_ms.begin();it!=_ms.end();it++)
4675 MEDFileUMeshSplitL1 *sp=(*it);
4678 sp->changeFamilyIdArr(oldId,newId);
4683 std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > MEDFileUMesh::getAllNonNullFamilyIds() const
4685 std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > ret;
4686 const DataArrayInt *da(_fam_coords);
4688 { da->incrRef(); ret.push_back(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>(const_cast<DataArrayInt *>(da))); }
4689 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileUMeshSplitL1> >::const_iterator it=_ms.begin();it!=_ms.end();it++)
4691 const MEDFileUMeshSplitL1 *elt(*it);
4694 da=elt->getFamilyField();
4696 { da->incrRef(); ret.push_back(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>(const_cast<DataArrayInt *>(da))); }
4702 void MEDFileUMesh::computeRevNum() const
4704 if((const DataArrayInt *)_num_coords)
4707 int maxValue=_num_coords->getMaxValue(pos);
4708 _rev_num_coords=_num_coords->invertArrayN2O2O2N(maxValue+1);
4712 std::size_t MEDFileStructuredMesh::getHeapMemorySizeWithoutChildren() const
4714 return MEDFileMesh::getHeapMemorySizeWithoutChildren();
4717 std::vector<const BigMemoryObject *> MEDFileStructuredMesh::getDirectChildrenWithNull() const
4719 std::vector<const BigMemoryObject *> ret(MEDFileMesh::getDirectChildrenWithNull());
4720 ret.push_back((const DataArrayInt *)_fam_nodes);
4721 ret.push_back((const DataArrayInt *)_num_nodes);
4722 ret.push_back((const DataArrayAsciiChar *)_names_nodes);
4723 ret.push_back((const DataArrayInt *)_fam_cells);
4724 ret.push_back((const DataArrayInt *)_num_cells);
4725 ret.push_back((const DataArrayAsciiChar *)_names_cells);
4726 ret.push_back((const DataArrayInt *)_fam_faces);
4727 ret.push_back((const DataArrayInt *)_num_faces);
4728 ret.push_back((const DataArrayInt *)_rev_num_nodes);
4729 ret.push_back((const DataArrayAsciiChar *)_names_faces);
4730 ret.push_back((const DataArrayInt *)_rev_num_cells);
4731 ret.push_back((const MEDCoupling1SGTUMesh*)_faces_if_necessary);
4735 int MEDFileStructuredMesh::getMaxAbsFamilyIdInArrays() const
4737 int ret=-std::numeric_limits<int>::max(),tmp=-1;
4738 if((const DataArrayInt *)_fam_nodes)
4740 int val=_fam_nodes->getMaxValue(tmp);
4741 ret=std::max(ret,std::abs(val));
4743 if((const DataArrayInt *)_fam_cells)
4745 int val=_fam_cells->getMaxValue(tmp);
4746 ret=std::max(ret,std::abs(val));
4748 if((const DataArrayInt *)_fam_faces)
4750 int val=_fam_faces->getMaxValue(tmp);
4751 ret=std::max(ret,std::abs(val));
4756 int MEDFileStructuredMesh::getMaxFamilyIdInArrays() const
4758 int ret=-std::numeric_limits<int>::max(),tmp=-1;
4759 if((const DataArrayInt *)_fam_nodes)
4761 int val=_fam_nodes->getMaxValue(tmp);
4762 ret=std::max(ret,val);
4764 if((const DataArrayInt *)_fam_cells)
4766 int val=_fam_cells->getMaxValue(tmp);
4767 ret=std::max(ret,val);
4769 if((const DataArrayInt *)_fam_faces)
4771 int val=_fam_faces->getMaxValue(tmp);
4772 ret=std::max(ret,val);
4777 int MEDFileStructuredMesh::getMinFamilyIdInArrays() const
4779 int ret=std::numeric_limits<int>::max(),tmp=-1;
4780 if((const DataArrayInt *)_fam_nodes)
4782 int val=_fam_nodes->getMinValue(tmp);
4783 ret=std::min(ret,val);
4785 if((const DataArrayInt *)_fam_cells)
4787 int val=_fam_cells->getMinValue(tmp);
4788 ret=std::min(ret,val);
4790 if((const DataArrayInt *)_fam_faces)
4792 int val=_fam_faces->getMinValue(tmp);
4793 ret=std::min(ret,val);
4798 bool MEDFileStructuredMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
4800 if(!MEDFileMesh::isEqual(other,eps,what))
4802 const MEDFileStructuredMesh *otherC=dynamic_cast<const MEDFileStructuredMesh *>(other);
4805 what="Mesh types differ ! This is structured and other is NOT !";
4808 const DataArrayInt *famc1=_fam_nodes;
4809 const DataArrayInt *famc2=otherC->_fam_nodes;
4810 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
4812 what="Mismatch of families arr on nodes ! One is defined and not other !";
4817 bool ret=famc1->isEqual(*famc2);
4820 what="Families arr on nodes differ !";
4825 famc2=otherC->_fam_cells;
4826 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
4828 what="Mismatch of families arr on cells ! One is defined and not other !";
4833 bool ret=famc1->isEqual(*famc2);
4836 what="Families arr on cells differ !";
4841 famc2=otherC->_fam_faces;
4842 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
4844 what="Mismatch of families arr on faces ! One is defined and not other !";
4849 bool ret=famc1->isEqual(*famc2);
4852 what="Families arr on faces differ !";
4857 famc2=otherC->_num_nodes;
4858 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
4860 what="Mismatch of numbering arr on nodes ! One is defined and not other !";
4865 bool ret=famc1->isEqual(*famc2);
4868 what="Numbering arr on nodes differ !";
4873 famc2=otherC->_num_cells;
4874 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
4876 what="Mismatch of numbering arr on cells ! One is defined and not other !";
4881 bool ret=famc1->isEqual(*famc2);
4884 what="Numbering arr on cells differ !";
4889 famc2=otherC->_num_faces;
4890 if((famc1==0 && famc2!=0) || (famc1!=0 && famc2==0))
4892 what="Mismatch of numbering arr on faces ! One is defined and not other !";
4897 bool ret=famc1->isEqual(*famc2);
4900 what="Numbering arr on faces differ !";
4904 const DataArrayAsciiChar *d1=_names_cells;
4905 const DataArrayAsciiChar *d2=otherC->_names_cells;
4906 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
4908 what="Mismatch of naming arr on cells ! One is defined and not other !";
4913 bool ret=d1->isEqual(*d2);
4916 what="Naming arr on cells differ !";
4921 d2=otherC->_names_faces;
4922 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
4924 what="Mismatch of naming arr on faces ! One is defined and not other !";
4929 bool ret=d1->isEqual(*d2);
4932 what="Naming arr on faces differ !";
4937 d2=otherC->_names_nodes;
4938 if((d1==0 && d2!=0) || (d1!=0 && d2==0))
4940 what="Mismatch of naming arr on nodes ! One is defined and not other !";
4945 bool ret=d1->isEqual(*d2);
4948 what="Naming arr on nodes differ !";
4955 void MEDFileStructuredMesh::clearNonDiscrAttributes() const
4957 MEDFileMesh::clearNonDiscrAttributes();
4958 const DataArrayInt *tmp=_fam_nodes;
4960 (const_cast<DataArrayInt *>(tmp))->setName("");
4963 (const_cast<DataArrayInt *>(tmp))->setName("");
4966 (const_cast<DataArrayInt *>(tmp))->setName("");
4969 (const_cast<DataArrayInt *>(tmp))->setName("");
4972 (const_cast<DataArrayInt *>(tmp))->setName("");
4975 (const_cast<DataArrayInt *>(tmp))->setName("");
4979 * Returns ids of mesh entities contained in given families of a given dimension.
4980 * \param [in] meshDimRelToMaxExt - a relative dimension of the mesh entities whose ids
4982 * \param [in] fams - the names of the families of interest.
4983 * \param [in] renum - if \c true, the optional numbers of entities, if available, are
4984 * returned instead of ids.
4985 * \return DataArrayInt * - a new instance of DataArrayInt holding either ids or
4986 * numbers, if available and required, of mesh entities of the families. The caller
4987 * is to delete this array using decrRef() as it is no more needed.
4988 * \throw If the family field is missing for \a meshDimRelToMaxExt.
4990 DataArrayInt *MEDFileStructuredMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum) const
4992 std::vector<int> famIds(getFamiliesIds(fams));
4993 switch(meshDimRelToMaxExt)
4997 if((const DataArrayInt *)_fam_nodes)
4999 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
5001 da=_fam_nodes->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
5003 da=_fam_nodes->getIdsEqualList(0,0);
5005 return MEDFileUMeshSplitL1::Renumber(_num_nodes,da);
5010 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : no family array specified on nodes !");
5015 if((const DataArrayInt *)_fam_cells)
5017 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
5019 da=_fam_cells->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
5021 da=_fam_cells->getIdsEqualList(0,0);
5023 return MEDFileUMeshSplitL1::Renumber(_num_cells,da);
5028 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : no family array specified on cells !");
5033 if((const DataArrayInt *)_fam_faces)
5035 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> da;
5037 da=_fam_faces->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size());
5039 da=_fam_faces->getIdsEqualList(0,0);
5041 return MEDFileUMeshSplitL1::Renumber(_num_faces,da);
5046 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : no family array specified on faces !");
5050 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : input meshDimRelative must be in [0,1,-1] !");
5052 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamiliesArr : unmanaged case !");
5056 * Sets the family field of a given relative dimension.
5057 * \param [in] meshDimRelToMaxExt - the relative dimension of entities for which
5058 * the family field is set.
5059 * \param [in] famArr - the array of the family field.
5060 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
5061 * \throw If \a famArr has an invalid size.
5062 * \throw If \a meshDimRelToMaxExt != 0 and \a meshDimRelToMaxExt != 1 and \a meshDimRelToMaxExt != -1.
5064 void MEDFileStructuredMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayInt *famArr)
5066 const MEDCouplingStructuredMesh *mesh(getStructuredMesh());
5068 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setFamilyFieldArr : no structured mesh specified ! Impossible to set family array !");
5069 switch(meshDimRelToMaxExt)
5073 int nbCells=mesh->getNumberOfCells();
5074 famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !");
5080 int nbNodes=mesh->getNumberOfNodes();
5081 famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !");
5087 int nbCells=mesh->getNumberOfCellsOfSubLevelMesh();
5088 famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of faces of mesh !");
5093 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setFamilyFieldArr : Only available for levels 0 or 1 or -1 !");
5100 * Sets the optional numbers of mesh entities of a given dimension.
5101 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
5102 * \param [in] renumArr - the array of the numbers.
5103 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
5104 * \throw If \a renumArr has an invalid size.
5105 * \throw If \a meshDimRelToMaxExt != 0 and \a meshDimRelToMaxExt != 1.
5107 void MEDFileStructuredMesh::setRenumFieldArr(int meshDimRelToMaxExt, DataArrayInt *renumArr)
5109 const MEDCouplingStructuredMesh *mesh=getStructuredMesh();
5111 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : no structured mesh specified ! Impossible to set number array !");
5112 switch(meshDimRelToMaxExt)
5116 int nbCells=mesh->getNumberOfCells();
5117 renumArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setRenumFieldArr : Problem in size of Renum arr ! Mismatch with number of cells of mesh !");
5118 _num_cells=renumArr;
5123 int nbNodes=mesh->getNumberOfNodes();
5124 renumArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setRenumFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !");
5125 _num_nodes=renumArr;
5130 int nbCells=mesh->getNumberOfCellsOfSubLevelMesh();
5131 renumArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setRenumFieldArr : Problem in size of Renum arr ! Mismatch with number of faces of mesh !");
5132 _num_faces=renumArr;
5136 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setRenumFieldArr : Only available for levels 0 or 1 or -1 !");
5139 renumArr->incrRef();
5143 * Sets the optional names of mesh entities of a given dimension.
5144 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
5145 * \param [in] nameArr - the array of the names.
5146 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
5147 * \throw If \a nameArr has an invalid size.
5149 void MEDFileStructuredMesh::setNameFieldAtLevel(int meshDimRelToMaxExt, DataArrayAsciiChar *nameArr)
5151 const MEDCouplingStructuredMesh *mesh(getStructuredMesh());
5153 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setNameFieldAtLevel : no structured mesh specified ! Impossible to set names array !");
5154 switch(meshDimRelToMaxExt)
5158 int nbCells=mesh->getNumberOfCells();
5159 nameArr->checkNbOfTuplesAndComp(nbCells,MED_SNAME_SIZE,"MEDFileStructuredMesh::setNameFieldAtLevel : Problem in size of names arr ! Mismatch with number of cells of mesh !");
5160 _names_cells=nameArr;
5165 int nbNodes=mesh->getNumberOfNodes();
5166 nameArr->checkNbOfTuplesAndComp(nbNodes,MED_SNAME_SIZE,"MEDFileStructuredMesh::setNameFieldAtLevel : Problem in size of names arr ! Mismatch with number of nodes of mesh !");
5167 _names_nodes=nameArr;
5172 int nbCells=mesh->getNumberOfCellsOfSubLevelMesh();
5173 nameArr->checkNbOfTuplesAndComp(nbCells,MED_SNAME_SIZE,"MEDFileStructuredMesh::setNameFieldAtLevel : Problem in size of names arr ! Mismatch with number of faces of mesh !");
5174 _names_cells=nameArr;
5177 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::setNameFieldAtLevel : Only available for levels 0 or 1 or -1 !");
5184 * Adds a group of nodes to \a this mesh.
5185 * \param [in] ids - a DataArrayInt providing ids and a name of the group to add.
5186 * The ids should be sorted and different each other (MED file norm).
5188 * \warning this method can alter default "FAMILLE_ZERO" family.
5189 * For users sensitive to this a call to MEDFileMesh::rearrangeFamilies will be necessary after addGroup session.
5191 * \throw If the node coordinates array is not set.
5192 * \throw If \a ids == \c NULL.
5193 * \throw If \a ids->getName() == "".
5194 * \throw If \a ids does not respect the MED file norm.
5195 * \throw If a group with name \a ids->getName() already exists.
5197 void MEDFileStructuredMesh::addNodeGroup(const DataArrayInt *ids)
5203 * Adds a group of nodes/cells/faces/edges to \a this mesh.
5205 * \param [in] ids - a DataArrayInt providing ids and a name of the group to add.
5206 * The ids should be sorted and different each other (MED file norm).
5208 * \warning this method can alter default "FAMILLE_ZERO" family.
5209 * For users sensitive to this a call to MEDFileMesh::rearrangeFamilies will be necessary after addGroup session.
5211 * \throw If the node coordinates array is not set.
5212 * \throw If \a ids == \c NULL.
5213 * \throw If \a ids->getName() == "".
5214 * \throw If \a ids does not respect the MED file norm.
5215 * \throw If a group with name \a ids->getName() already exists.
5217 void MEDFileStructuredMesh::addGroup(int meshDimRelToMaxExt, const DataArrayInt *ids)
5219 DataArrayInt *fam(getOrCreateAndGetFamilyFieldAtLevel(meshDimRelToMaxExt));
5220 addGroupUnderground(false,ids,fam);
5225 * Returns the family field for mesh entities of a given dimension.
5226 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
5227 * \return const DataArrayInt * - the family field. It is an array of ids of families
5228 * each mesh entity belongs to. It can be \c NULL.
5229 * \throw If \a meshDimRelToMaxExt != 0 and \a meshDimRelToMaxExt != 1.
5231 const DataArrayInt *MEDFileStructuredMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const
5233 switch(meshDimRelToMaxExt)
5242 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 or -1 !");
5247 * Returns the family field for mesh entities of a given dimension.
5248 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
5249 * \return const DataArrayInt * - the family field. It is an array of ids of families
5250 * each mesh entity belongs to. It can be \c NULL.
5251 * \throw If \a meshDimRelToMaxExt != 0 and \a meshDimRelToMaxExt != 1.
5253 DataArrayInt *MEDFileStructuredMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt)
5255 switch(meshDimRelToMaxExt)
5264 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getFamilyFieldAtLevel : Only available for levels 0 or 1 or -1 !");
5269 * Returns the optional numbers of mesh entities of a given dimension.
5270 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
5271 * \return const DataArrayInt * - the array of the entity numbers.
5272 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
5273 * \throw If \a meshDimRelToMaxExt != 0 and \a meshDimRelToMaxExt != 1.
5275 const DataArrayInt *MEDFileStructuredMesh::getNumberFieldAtLevel(int meshDimRelToMaxExt) const
5277 switch(meshDimRelToMaxExt)
5286 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberFieldAtLevel : Only available for levels 0 or 1 or -1 !");
5291 * Returns the optional numbers of mesh entities of a given dimension transformed using
5292 * DataArrayInt::invertArrayN2O2O2N().
5293 * \param [in] meshDimRelToMaxExt - the relative dimension of mesh entities.
5294 * \return const DataArrayInt * - the array of the entity numbers transformed using
5295 * DataArrayInt::invertArrayN2O2O2N().
5296 * \throw If \a meshDimRelToMaxExt != 0 and \a meshDimRelToMaxExt != 1.
5297 * \throw If there are no mesh entities of \a meshDimRelToMaxExt dimension in \a this mesh.
5299 const DataArrayInt *MEDFileStructuredMesh::getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const
5301 if(meshDimRelToMaxExt!=0 && meshDimRelToMaxExt!=1)
5302 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getRevNumberFieldAtLevel : Only available for levels 0 or 1 !");
5303 if(meshDimRelToMaxExt==0)
5305 if((const DataArrayInt *)_num_cells)
5308 int maxValue=_num_cells->getMaxValue(pos);
5309 _rev_num_cells=_num_cells->invertArrayN2O2O2N(maxValue+1);
5310 return _rev_num_cells;
5313 throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no cell renumbering for a request on reverse numbering !");
5317 if((const DataArrayInt *)_num_nodes)
5320 int maxValue=_num_nodes->getMaxValue(pos);
5321 _rev_num_nodes=_num_nodes->invertArrayN2O2O2N(maxValue+1);
5322 return _rev_num_nodes;
5325 throw INTERP_KERNEL::Exception("MEDFileCMesh::getRevNumberFieldAtLevel : no node renumbering for a request on reverse numbering !");
5329 const DataArrayAsciiChar *MEDFileStructuredMesh::getNameFieldAtLevel(int meshDimRelToMaxExt) const
5331 switch(meshDimRelToMaxExt)
5334 return _names_cells;
5336 return _names_nodes;
5338 return _names_faces;
5340 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNameFieldAtLevel : Only available for levels 0 or 1 or -1 !");
5345 * Returns relative dimensions of mesh entities (excluding nodes) present in \a this mesh.
5346 * \return std::vector<int> - a sequence of the relative dimensions: [0].
5348 std::vector<int> MEDFileStructuredMesh::getNonEmptyLevels() const
5350 std::vector<int> ret(1);
5355 * Returns relative dimensions of mesh entities (including nodes) present in \a this mesh.
5356 * \return std::vector<int> - a sequence of the relative dimensions: [1,0].
5358 std::vector<int> MEDFileStructuredMesh::getNonEmptyLevelsExt() const
5360 std::vector<int> ret(2);
5366 * Returns the set of extensive levels (nodes included) where not NULL family arr are defined.
5368 std::vector<int> MEDFileStructuredMesh::getFamArrNonEmptyLevelsExt() const
5370 std::vector<int> ret;
5371 const DataArrayInt *famNodes(_fam_nodes),*famCells(_fam_cells),*famFaces(_fam_faces);
5382 * Returns the set of extensive levels (nodes included) where not NULL numbering arr are defined.
5384 std::vector<int> MEDFileStructuredMesh::getNumArrNonEmptyLevelsExt() const
5386 std::vector<int> ret;
5387 const DataArrayInt *numNodes(_num_nodes),*numCells(_num_cells),*numFaces(_num_faces);
5398 * Returns the set of extensive levels (nodes included) where not NULL naming arr are defined.
5400 std::vector<int> MEDFileStructuredMesh::getNameArrNonEmptyLevelsExt() const
5402 std::vector<int> ret;
5403 const DataArrayAsciiChar *namesNodes(_names_nodes),*namesCells(_names_cells),*namesFaces(_names_faces);
5414 * no implementation here, it is not a bug, but intresically no polyhedra in \a this.
5416 bool MEDFileStructuredMesh::unPolyze(std::vector<int>& oldCode, std::vector<int>& newCode, DataArrayInt *& o2nRenumCell)
5418 oldCode.clear(); newCode.clear(); o2nRenumCell=0;
5422 void MEDFileStructuredMesh::changeFamilyIdArr(int oldId, int newId)
5424 DataArrayInt *arr=_fam_nodes;
5426 arr->changeValue(oldId,newId);
5429 arr->changeValue(oldId,newId);
5432 arr->changeValue(oldId,newId);
5435 std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > MEDFileStructuredMesh::getAllNonNullFamilyIds() const
5437 std::list< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > ret;
5438 const DataArrayInt *da(_fam_nodes);
5440 { da->incrRef(); ret.push_back(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>(const_cast<DataArrayInt *>(da))); }
5443 { da->incrRef(); ret.push_back(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>(const_cast<DataArrayInt *>(da))); }
5446 { da->incrRef(); ret.push_back(MEDCouplingAutoRefCountObjectPtr<DataArrayInt>(const_cast<DataArrayInt *>(da))); }
5450 void MEDFileStructuredMesh::deepCpyAttributes()
5452 if((const DataArrayInt*)_fam_nodes)
5453 _fam_nodes=_fam_nodes->deepCpy();
5454 if((const DataArrayInt*)_num_nodes)
5455 _num_nodes=_num_nodes->deepCpy();
5456 if((const DataArrayAsciiChar*)_names_nodes)
5457 _names_nodes=_names_nodes->deepCpy();
5458 if((const DataArrayInt*)_fam_cells)
5459 _fam_cells=_fam_cells->deepCpy();
5460 if((const DataArrayInt*)_num_cells)
5461 _num_cells=_num_cells->deepCpy();
5462 if((const DataArrayAsciiChar*)_names_cells)
5463 _names_cells=_names_cells->deepCpy();
5464 if((const DataArrayInt*)_fam_faces)
5465 _fam_faces=_fam_faces->deepCpy();
5466 if((const DataArrayInt*)_num_faces)
5467 _num_faces=_num_faces->deepCpy();
5468 if((const DataArrayAsciiChar*)_names_faces)
5469 _names_faces=_names_faces->deepCpy();
5470 if((const DataArrayInt*)_rev_num_nodes)
5471 _rev_num_nodes=_rev_num_nodes->deepCpy();
5472 if((const DataArrayInt*)_rev_num_cells)
5473 _rev_num_cells=_rev_num_cells->deepCpy();
5477 * Returns a pointer to mesh at the specified level (here 0 is compulsary for cartesian mesh).
5479 * \return a pointer to cartesian mesh that need to be managed by the caller.
5480 * \warning the returned pointer has to be managed by the caller.
5484 * Returns a pointer to MEDCouplingStructuredMesh held by \a this.
5485 * \param [in] meshDimRelToMax - it must be \c 0 or \c -1.
5486 * \param [in] renum - it must be \c false.
5487 * \return MEDCouplingMesh * - a pointer to MEDCouplingMesh that the caller is to
5488 * delete using decrRef() as it is no more needed.
5490 MEDCouplingMesh *MEDFileStructuredMesh::getGenMeshAtLevel(int meshDimRelToMax, bool renum) const
5493 throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support renumbering ! To do it perform request of renum array directly !");
5494 const MEDCouplingStructuredMesh *m(getStructuredMesh());
5495 switch(meshDimRelToMax)
5501 return const_cast<MEDCouplingStructuredMesh *>(m);
5506 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGenMeshAtLevel : level -1 requested must be non empty to be able to compute unstructured sub mesh !");
5507 buildMinusOneImplicitPartIfNeeded();
5508 MEDCouplingMesh *ret(_faces_if_necessary);
5514 throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh does not support multi level for mesh 0 expected as input !");
5519 * Returns number of mesh entities of a given relative dimension in \a this mesh.
5520 * \param [in] meshDimRelToMaxExt - the relative dimension of interest.
5521 * \return int - the number of entities.
5522 * \throw If no mesh entities of dimension \a meshDimRelToMaxExt are available in \a this mesh.
5524 int MEDFileStructuredMesh::getSizeAtLevel(int meshDimRelToMaxExt) const
5526 const MEDCouplingStructuredMesh *cmesh(getStructuredMesh());
5528 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getSizeAtLevel : No structured mesh set !");
5529 switch(meshDimRelToMaxExt)
5532 return cmesh->getNumberOfCells();
5534 return cmesh->getNumberOfNodes();
5536 return cmesh->getNumberOfCellsOfSubLevelMesh();
5538 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getSizeAtLevel : Only available for levels 0 or 1 or -1 !");
5542 int MEDFileStructuredMesh::getNumberOfNodes() const
5544 const MEDCouplingStructuredMesh *cmesh(getStructuredMesh());
5546 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberOfNodes : no cartesian mesh set !");
5547 return cmesh->getNumberOfNodes();
5550 int MEDFileStructuredMesh::getNumberOfCellsAtLevel(int meshDimRelToMaxExt) const
5552 const MEDCouplingStructuredMesh *cmesh(getStructuredMesh());
5554 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberOfNodes : no cartesian mesh set !");
5555 switch(meshDimRelToMaxExt)
5558 return cmesh->getNumberOfCells();
5560 return cmesh->getNumberOfCellsOfSubLevelMesh();
5562 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getNumberOfNodes : only meshDimRelToMax=0 and meshDimRelToMax=-1 supported !");
5566 bool MEDFileStructuredMesh::hasImplicitPart() const
5572 * \sa MEDFileStructuredMesh::getImplicitFaceMesh
5574 int MEDFileStructuredMesh::buildImplicitPartIfAny(INTERP_KERNEL::NormalizedCellType gt) const
5576 static const char MSG[]="MEDFileStructuredMesh::buildImplicitPartIfAny : the given geo type is not manageable by a structured mesh !";
5577 const MEDCoupling1SGTUMesh *zeFaceMesh(_faces_if_necessary);
5580 const INTERP_KERNEL::CellModel& cm(INTERP_KERNEL::CellModel::GetCellModel(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(getMeshDimension())));
5581 if(cm.getReverseExtrudedType()!=gt)
5582 throw INTERP_KERNEL::Exception(MSG);
5583 buildImplicitPart();
5584 return getStructuredMesh()->getNumberOfCellsOfSubLevelMesh();
5588 if(gt!=zeFaceMesh->getCellModelEnum())
5589 throw INTERP_KERNEL::Exception(MSG);
5590 return zeFaceMesh->getNumberOfCells();
5594 void MEDFileStructuredMesh::buildMinusOneImplicitPartIfNeeded() const
5596 const MEDCoupling1SGTUMesh *zeFaceMesh(_faces_if_necessary);
5598 buildImplicitPart();
5601 void MEDFileStructuredMesh::buildImplicitPart() const
5603 const MEDCouplingStructuredMesh *mcmesh(getStructuredMesh());
5605 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::buildImplicitPart : Unable to build the implicit part of structured mesh because no structured mesh at level 0 defined !");
5606 _faces_if_necessary=mcmesh->build1SGTSubLevelMesh();
5609 void MEDFileStructuredMesh::releaseImplicitPartIfAny() const
5611 _faces_if_necessary=0;
5615 * Retrieves the internal pointer (no decrRef requested) of the implicit face mesh if any.
5616 * To force to build it you can invoke MEDFileStructuredMesh::buildImplicitPartIfAny method.
5618 * \sa MEDFileStructuredMesh::buildImplicitPartIfAny
5620 MEDCoupling1SGTUMesh *MEDFileStructuredMesh::getImplicitFaceMesh() const
5622 return _faces_if_necessary;
5625 std::vector<INTERP_KERNEL::NormalizedCellType> MEDFileStructuredMesh::getGeoTypesAtLevel(int meshDimRelToMax) const
5627 const MEDCouplingStructuredMesh *cmesh(getStructuredMesh());
5629 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGeoTypesAtLevel : No structured mesh set !");
5630 switch(meshDimRelToMax)
5634 std::vector<INTERP_KERNEL::NormalizedCellType> ret(1,cmesh->getTypeOfCell(0));
5639 int mdim(cmesh->getMeshDimension());
5641 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGeoTypesAtLevel : only one level available for structured meshes ! Input 0 is mandatory or 0D mesh !");
5642 std::vector<INTERP_KERNEL::NormalizedCellType> ret(1,MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(mdim-1));
5646 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::getGeoTypesAtLevel : only 2 levels available at most : 0 and -1 !");
5650 void MEDFileStructuredMesh::whichAreNodesFetched(const MEDFileField1TSStructItem& st, const MEDFileFieldGlobsReal *globs, std::vector<bool>& nodesFetched) const
5652 if(st.getNumberOfItems()!=1)
5653 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::whichAreNodesFetched : The sturture of field is not lying on single geo type ! it is not managed yet for structured mesh !");
5654 if(st[0].getGeo()!=MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(getMeshDimension()))
5655 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::whichAreNodesFetched : The sturture of field is not lying on expected geo type !");
5656 if(getNumberOfNodes()!=(int)nodesFetched.size())
5657 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::whichAreNodesFetched : invalid size of array !");
5658 if(st[0].getPflName().empty())
5660 std::fill(nodesFetched.begin(),nodesFetched.end(),true);
5663 const DataArrayInt *arr(globs->getProfile(st[0].getPflName()));
5664 const MEDCouplingStructuredMesh *cmesh=getStructuredMesh();//cmesh not null because getNumberOfNodes called before
5665 int sz(nodesFetched.size());
5666 for(const int *work=arr->begin();work!=arr->end();work++)
5668 std::vector<int> conn;
5669 cmesh->getNodeIdsOfCell(*work,conn);
5670 for(std::vector<int>::const_iterator it=conn.begin();it!=conn.end();it++)
5671 if(*it>=0 && *it<sz)
5672 nodesFetched[*it]=true;
5674 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::whichAreNodesFetched : internal error !");
5678 med_geometry_type MEDFileStructuredMesh::GetGeoTypeFromMeshDim(int meshDim)
5680 INTERP_KERNEL::NormalizedCellType ct(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(meshDim));
5684 void MEDFileStructuredMesh::LoadStrMeshDAFromFile(med_idt fid, int meshDim, int dt, int it, const std::string& mName, MEDFileMeshReadSelector *mrs,
5685 MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& famCells, MEDCouplingAutoRefCountObjectPtr<DataArrayInt>& numCells, MEDCouplingAutoRefCountObjectPtr<DataArrayAsciiChar>& namesCells)
5687 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
5688 med_geometry_type geoTypeReq=MEDFileStructuredMesh::GetGeoTypeFromMeshDim(meshDim);
5690 nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf);
5693 if(!mrs || mrs->isCellFamilyFieldReading())
5695 famCells=DataArrayInt::New();
5696 famCells->alloc(nbOfElt,1);
5697 MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,famCells->getPointer()));
5700 nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,MED_NUMBER,MED_NODAL,&chgt,&trsf);
5703 if(!mrs || mrs->isCellNumFieldReading())
5705 numCells=DataArrayInt::New();
5706 numCells->alloc(nbOfElt,1);
5707 MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,numCells->getPointer()));
5710 nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,MED_NAME,MED_NODAL,&chgt,&trsf);
5713 if(!mrs || mrs->isCellNameFieldReading())
5715 namesCells=DataArrayAsciiChar::New();
5716 namesCells->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
5717 MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,mName.c_str(),dt,it,MED_CELL,geoTypeReq,namesCells->getPointer()));
5718 namesCells->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end
5723 void MEDFileStructuredMesh::loadStrMeshFromFile(MEDFileStrMeshL2 *strm, med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
5725 setName(strm->getName());
5726 setDescription(strm->getDescription());
5727 setUnivName(strm->getUnivName());
5728 setIteration(strm->getIteration());
5729 setOrder(strm->getOrder());
5730 setTimeValue(strm->getTime());
5731 setTimeUnit(strm->getTimeUnit());
5732 MEDFileMeshL2::ReadFamiliesAndGrps(fid,mName,_families,_groups,mrs);
5733 med_bool chgt=MED_FALSE,trsf=MED_FALSE;
5734 int nbOfElt(MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_FAMILY_NUMBER,MED_NODAL,&chgt,&trsf));
5737 if(!mrs || mrs->isNodeFamilyFieldReading())
5739 int nbNodes(getNumberOfNodes());
5741 throw INTERP_KERNEL::Exception("MEDFileStructuredMesh::loadStrMeshFromFile : invalid size of family node array regarding number of nodes in this ! File seems to be corrupted !");
5742 _fam_nodes=DataArrayInt::New();
5743 _fam_nodes->alloc(nbNodes,1);//yes nbNodes and not nbOfElt see next line.
5744 if(nbNodes>nbOfElt)//yes it appends some times... It explains surely the mdump implementation. Bug revealed by PARAVIS EDF #2475 on structured.med file where only 12 first nodes are !=0 so nbOfElt=12 and nbOfNodes=378...
5745 _fam_nodes->fillWithZero();
5746 MEDFILESAFECALLERRD0(MEDmeshEntityFamilyNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,_fam_nodes->getPointer()));
5749 nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_NUMBER,MED_NODAL,&chgt,&trsf);
5752 if(!mrs || mrs->isNodeNumFieldReading())
5754 _num_nodes=DataArrayInt::New();
5755 _num_nodes->alloc(nbOfElt,1);
5756 MEDFILESAFECALLERRD0(MEDmeshEntityNumberRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,_num_nodes->getPointer()));
5759 nbOfElt=MEDmeshnEntity(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,MED_NAME,MED_NODAL,&chgt,&trsf);
5762 if(!mrs || mrs->isNodeNameFieldReading())
5764 _names_nodes=DataArrayAsciiChar::New();
5765 _names_nodes->alloc(nbOfElt+1,MED_SNAME_SIZE);//not a bug to avoid the memory corruption due to last \0 at the end
5766 MEDFILESAFECALLERRD0(MEDmeshEntityNameRd,(fid,mName.c_str(),dt,it,MED_NODE,MED_NONE,_names_nodes->getPointer()));
5767 _names_nodes->reAlloc(nbOfElt);//not a bug to avoid the memory corruption due to last \0 at the end
5770 int meshDim(getStructuredMesh()->getMeshDimension());
5771 LoadStrMeshDAFromFile(fid,meshDim,dt,it,mName,mrs,_fam_cells,_num_cells,_names_cells);
5773 LoadStrMeshDAFromFile(fid,meshDim-1,dt,it,mName,mrs,_fam_faces,_num_faces,_names_faces);
5776 void MEDFileStructuredMesh::writeStructuredLL(med_idt fid, const std::string& maa) const
5778 int meshDim(getStructuredMesh()->getMeshDimension());
5779 med_geometry_type geoTypeReq(GetGeoTypeFromMeshDim(meshDim)),geoTypeReq2(GetGeoTypeFromMeshDim(meshDim-1));
5781 if((const DataArrayInt *)_fam_cells)
5782 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq,_fam_cells->getNumberOfTuples(),_fam_cells->getConstPointer()));
5783 if((const DataArrayInt *)_fam_faces)
5784 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq2,_fam_faces->getNumberOfTuples(),_fam_faces->getConstPointer()));
5785 if((const DataArrayInt *)_fam_nodes)
5786 MEDFILESAFECALLERWR0(MEDmeshEntityFamilyNumberWr,(fid,maa.c_str(),_iteration,_order,MED_NODE,MED_NONE,_fam_nodes->getNumberOfTuples(),_fam_nodes->getConstPointer()));
5787 if((const DataArrayInt *)_num_cells)
5788 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq,_num_cells->getNumberOfTuples(),_num_cells->getConstPointer()));
5789 if((const DataArrayInt *)_num_faces)
5790 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq2,_num_faces->getNumberOfTuples(),_num_faces->getConstPointer()));
5791 if((const DataArrayInt *)_num_nodes)
5792 MEDFILESAFECALLERWR0(MEDmeshEntityNumberWr,(fid,maa.c_str(),_iteration,_order,MED_NODE,MED_NONE,_num_nodes->getNumberOfTuples(),_num_nodes->getConstPointer()));
5793 if((const DataArrayAsciiChar *)_names_cells)
5795 if(_names_cells->getNumberOfComponents()!=MED_SNAME_SIZE)
5797 std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on cells with number of components set to " << MED_SNAME_SIZE;
5798 oss << " ! The array has " << _names_cells->getNumberOfComponents() << " components !";
5799 throw INTERP_KERNEL::Exception(oss.str().c_str());
5801 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq,_names_cells->getNumberOfTuples(),_names_cells->getConstPointer()));
5803 if((const DataArrayAsciiChar *)_names_faces)
5805 if(_names_faces->getNumberOfComponents()!=MED_SNAME_SIZE)
5807 std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on faces with number of components set to " << MED_SNAME_SIZE;
5808 oss << " ! The array has " << _names_faces->getNumberOfComponents() << " components !";
5809 throw INTERP_KERNEL::Exception(oss.str().c_str());
5811 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,maa.c_str(),_iteration,_order,MED_CELL,geoTypeReq2,_names_faces->getNumberOfTuples(),_names_faces->getConstPointer()));
5813 if((const DataArrayAsciiChar *)_names_nodes)
5815 if(_names_nodes->getNumberOfComponents()!=MED_SNAME_SIZE)
5817 std::ostringstream oss; oss << "MEDFileStructuredMesh::writeStructuredLL : expected a name field on nodes with number of components set to " << MED_SNAME_SIZE;
5818 oss << " ! The array has " << _names_cells->getNumberOfComponents() << " components !";
5819 throw INTERP_KERNEL::Exception(oss.str().c_str());
5821 MEDFILESAFECALLERWR0(MEDmeshEntityNameWr,(fid,maa.c_str(),_iteration,_order,MED_NODE,MED_NONE,_names_nodes->getNumberOfTuples(),_names_nodes->getConstPointer()));
5824 MEDFileUMeshL2::WriteFamiliesAndGrps(fid,maa.c_str(),_families,_groups,_too_long_str);
5828 * Returns an empty instance of MEDFileCMesh.
5829 * \return MEDFileCMesh * - a new instance of MEDFileCMesh. The caller is to delete this
5830 * mesh using decrRef() as it is no more needed.
5832 MEDFileCMesh *MEDFileCMesh::New()
5834 return new MEDFileCMesh;
5838 * Returns a new MEDFileCMesh holding the mesh data that has been read from a given MED
5839 * file. The first mesh in the file is loaded.
5840 * \param [in] fileName - the name of MED file to read.
5841 * \return MEDFileCMesh * - a new instance of MEDFileCMesh. The caller is to delete this
5842 * mesh using decrRef() as it is no more needed.
5843 * \throw If the file is not readable.
5844 * \throw If there is no meshes in the file.
5845 * \throw If the mesh in the file is not a Cartesian one.
5847 MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
5849 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
5852 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
5853 throw INTERP_KERNEL::Exception(oss.str().c_str());
5855 MEDFileUtilities::CheckFileForRead(fileName);
5856 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5858 ParaMEDMEM::MEDCouplingMeshType meshType;
5860 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
5861 return new MEDFileCMesh(fid,ms.front(),dt,it,mrs);
5865 * Returns a new MEDFileCMesh holding the mesh data that has been read from a given MED
5866 * file. The mesh to load is specified by its name and numbers of a time step and an
5868 * \param [in] fileName - the name of MED file to read.
5869 * \param [in] mName - the name of the mesh to read.
5870 * \param [in] dt - the number of a time step.
5871 * \param [in] it - the number of an iteration.
5872 * \return MEDFileCMesh * - a new instance of MEDFileCMesh. The caller is to delete this
5873 * mesh using decrRef() as it is no more needed.
5874 * \throw If the file is not readable.
5875 * \throw If there is no mesh with given attributes in the file.
5876 * \throw If the mesh in the file is not a Cartesian one.
5878 MEDFileCMesh *MEDFileCMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
5880 MEDFileUtilities::CheckFileForRead(fileName);
5881 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
5882 return new MEDFileCMesh(fid,mName,dt,it,mrs);
5885 std::size_t MEDFileCMesh::getHeapMemorySizeWithoutChildren() const
5887 return MEDFileStructuredMesh::getHeapMemorySizeWithoutChildren();
5890 std::vector<const BigMemoryObject *> MEDFileCMesh::getDirectChildrenWithNull() const
5892 std::vector<const BigMemoryObject *> ret(MEDFileStructuredMesh::getDirectChildrenWithNull());
5893 ret.push_back((const MEDCouplingCMesh *)_cmesh);
5898 * Returns the dimension on cells in \a this mesh.
5899 * \return int - the mesh dimension.
5900 * \throw If there are no cells in this mesh.
5902 int MEDFileCMesh::getMeshDimension() const
5904 if(!((const MEDCouplingCMesh*)_cmesh))
5905 throw INTERP_KERNEL::Exception("MEDFileCMesh::getMeshDimension : unable to get meshdimension because no mesh set !");
5906 return _cmesh->getMeshDimension();
5910 * Returns the dimension on nodes in \a this mesh.
5911 * \return int - the space dimension.
5912 * \throw If there are no cells in this mesh.
5914 int MEDFileCMesh::getSpaceDimension() const
5916 if(!((const MEDCouplingCMesh*)_cmesh))
5917 throw INTERP_KERNEL::Exception("MEDFileCMesh::getSpaceDimension : unable to get spacedimension because no mesh set !");
5918 return _cmesh->getSpaceDimension();
5922 * Returns a string describing \a this mesh.
5923 * \return std::string - the mesh information string.
5925 std::string MEDFileCMesh::simpleRepr() const
5927 return MEDFileStructuredMesh::simpleRepr();
5931 * Returns a full textual description of \a this mesh.
5932 * \return std::string - the string holding the mesh description.
5934 std::string MEDFileCMesh::advancedRepr() const
5936 return simpleRepr();
5939 MEDFileMesh *MEDFileCMesh::shallowCpy() const
5941 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=new MEDFileCMesh(*this);
5945 MEDFileMesh *MEDFileCMesh::createNewEmpty() const
5947 return new MEDFileCMesh;
5950 MEDFileMesh *MEDFileCMesh::deepCpy() const
5952 MEDCouplingAutoRefCountObjectPtr<MEDFileCMesh> ret=new MEDFileCMesh(*this);
5953 if((const MEDCouplingCMesh*)_cmesh)
5954 ret->_cmesh=static_cast<MEDCouplingCMesh*>(_cmesh->deepCpy());
5955 ret->deepCpyAttributes();
5960 * Checks if \a this and another mesh are equal.
5961 * \param [in] other - the mesh to compare with.
5962 * \param [in] eps - a precision used to compare real values.
5963 * \param [in,out] what - the string returning description of unequal data.
5964 * \return bool - \c true if the meshes are equal, \c false, else.
5966 bool MEDFileCMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
5968 if(!MEDFileStructuredMesh::isEqual(other,eps,what))
5970 const MEDFileCMesh *otherC=dynamic_cast<const MEDFileCMesh *>(other);
5973 what="Mesh types differ ! This is cartesian and other is NOT !";
5976 clearNonDiscrAttributes();
5977 otherC->clearNonDiscrAttributes();
5978 const MEDCouplingCMesh *coo1=_cmesh;
5979 const MEDCouplingCMesh *coo2=otherC->_cmesh;
5980 if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
5982 what="Mismatch of cartesian meshes ! One is defined and not other !";
5987 bool ret=coo1->isEqual(coo2,eps);
5990 what="cartesian meshes differ !";
5998 * Clears redundant attributes of incorporated data arrays.
6000 void MEDFileCMesh::clearNonDiscrAttributes() const
6002 MEDFileStructuredMesh::clearNonDiscrAttributes();
6003 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_cmesh);//to it is not a bug umeshsplit have already the method implemented
6006 MEDFileCMesh::MEDFileCMesh()
6010 MEDFileCMesh::MEDFileCMesh(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
6013 loadCMeshFromFile(fid,mName,dt,it,mrs);
6014 loadJointsFromFile(fid);
6016 catch(INTERP_KERNEL::Exception& e)
6021 void MEDFileCMesh::loadCMeshFromFile(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
6023 ParaMEDMEM::MEDCouplingMeshType meshType;
6026 int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
6027 if(meshType!=CARTESIAN)
6029 std::ostringstream oss; oss << "Trying to load as cartesian an existing mesh with name '" << mName << "' that is NOT cartesian !";
6030 throw INTERP_KERNEL::Exception(oss.str().c_str());
6032 MEDFileCMeshL2 loaderl2;
6033 loaderl2.loadAll(fid,mid,mName,dt,it);
6034 MEDCouplingCMesh *mesh=loaderl2.getMesh();
6037 loadStrMeshFromFile(&loaderl2,fid,mName,dt,it,mrs);
6041 * Returns a const pointer to MEDCouplingCMesh held by \a this mesh.
6042 * \return const MEDCouplingCMesh * - a pointer to the held MEDCouplingCMesh.
6044 const MEDCouplingCMesh *MEDFileCMesh::getMesh() const
6046 synchronizeTinyInfoOnLeaves();
6050 const MEDCouplingStructuredMesh *MEDFileCMesh::getStructuredMesh() const
6052 synchronizeTinyInfoOnLeaves();
6057 * Sets the MEDCouplingCMesh holding the data of \a this mesh.
6058 * \param [in] m - the new MEDCouplingCMesh to refer to.
6059 * \throw If the name or the description of \a this mesh and \a m are not empty and are
6062 void MEDFileCMesh::setMesh(MEDCouplingCMesh *m)
6064 dealWithTinyInfo(m);
6070 void MEDFileCMesh::writeLL(med_idt fid) const
6072 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
6073 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
6074 INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
6075 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
6076 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
6077 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str);
6078 int spaceDim(_cmesh->getSpaceDimension());
6079 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
6080 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
6081 for(int i=0;i<spaceDim;i++)
6083 std::string info(_cmesh->getCoordsAt(i)->getInfoOnComponent(0));
6085 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6086 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
6087 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
6089 MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,spaceDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit));
6090 MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa));
6091 MEDFILESAFECALLERWR0(MEDmeshGridTypeWr,(fid,maa,MED_CARTESIAN_GRID));
6092 for(int i=0;i<spaceDim;i++)
6094 const DataArrayDouble *da=_cmesh->getCoordsAt(i);
6095 MEDFILESAFECALLERWR0(MEDmeshGridIndexCoordinateWr,(fid,maa,_iteration,_order,_time,i+1,da->getNumberOfTuples(),da->getConstPointer()));
6098 std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE));
6099 MEDFileStructuredMesh::writeStructuredLL(fid,meshName);
6104 void MEDFileCMesh::synchronizeTinyInfoOnLeaves() const
6106 const MEDCouplingCMesh *cmesh=_cmesh;
6109 (const_cast<MEDCouplingCMesh *>(cmesh))->setName(_name);
6110 (const_cast<MEDCouplingCMesh *>(cmesh))->setDescription(_desc_name);
6111 (const_cast<MEDCouplingCMesh *>(cmesh))->setTime(_time,_iteration,_order);
6112 (const_cast<MEDCouplingCMesh *>(cmesh))->setTimeUnit(_dt_unit);
6115 MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New()
6117 return new MEDFileCurveLinearMesh;
6120 MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const std::string& fileName, MEDFileMeshReadSelector *mrs)
6122 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
6125 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
6126 throw INTERP_KERNEL::Exception(oss.str().c_str());
6128 MEDFileUtilities::CheckFileForRead(fileName);
6129 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
6131 ParaMEDMEM::MEDCouplingMeshType meshType;
6133 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
6134 return new MEDFileCurveLinearMesh(fid,ms.front(),dt,it,mrs);
6137 MEDFileCurveLinearMesh *MEDFileCurveLinearMesh::New(const std::string& fileName, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
6139 MEDFileUtilities::CheckFileForRead(fileName);
6140 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
6141 return new MEDFileCurveLinearMesh(fid,mName,dt,it,mrs);
6144 std::size_t MEDFileCurveLinearMesh::getHeapMemorySizeWithoutChildren() const
6146 return MEDFileStructuredMesh::getHeapMemorySizeWithoutChildren();
6149 std::vector<const BigMemoryObject *> MEDFileCurveLinearMesh::getDirectChildrenWithNull() const
6151 std::vector<const BigMemoryObject *> ret(MEDFileStructuredMesh::getDirectChildrenWithNull());
6152 ret.push_back((const MEDCouplingCurveLinearMesh *)_clmesh);
6156 MEDFileMesh *MEDFileCurveLinearMesh::shallowCpy() const
6158 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=new MEDFileCurveLinearMesh(*this);
6162 MEDFileMesh *MEDFileCurveLinearMesh::createNewEmpty() const
6164 return new MEDFileCurveLinearMesh;
6167 MEDFileMesh *MEDFileCurveLinearMesh::deepCpy() const
6169 MEDCouplingAutoRefCountObjectPtr<MEDFileCurveLinearMesh> ret=new MEDFileCurveLinearMesh(*this);
6170 if((const MEDCouplingCurveLinearMesh*)_clmesh)
6171 ret->_clmesh=static_cast<MEDCouplingCurveLinearMesh*>(_clmesh->deepCpy());
6172 ret->deepCpyAttributes();
6176 int MEDFileCurveLinearMesh::getMeshDimension() const
6178 if(!((const MEDCouplingCurveLinearMesh*)_clmesh))
6179 throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::getMeshDimension : unable to get meshdimension because no mesh set !");
6180 return _clmesh->getMeshDimension();
6183 std::string MEDFileCurveLinearMesh::simpleRepr() const
6185 return MEDFileStructuredMesh::simpleRepr();
6188 std::string MEDFileCurveLinearMesh::advancedRepr() const
6190 return simpleRepr();
6193 bool MEDFileCurveLinearMesh::isEqual(const MEDFileMesh *other, double eps, std::string& what) const
6195 if(!MEDFileStructuredMesh::isEqual(other,eps,what))
6197 const MEDFileCurveLinearMesh *otherC=dynamic_cast<const MEDFileCurveLinearMesh *>(other);
6200 what="Mesh types differ ! This is curve linear and other is NOT !";
6203 clearNonDiscrAttributes();
6204 otherC->clearNonDiscrAttributes();
6205 const MEDCouplingCurveLinearMesh *coo1=_clmesh;
6206 const MEDCouplingCurveLinearMesh *coo2=otherC->_clmesh;
6207 if((coo1==0 && coo2!=0) || (coo1!=0 && coo2==0))
6209 what="Mismatch of curve linear meshes ! One is defined and not other !";
6214 bool ret=coo1->isEqual(coo2,eps);
6217 what="curve linear meshes differ !";
6224 void MEDFileCurveLinearMesh::clearNonDiscrAttributes() const
6226 MEDFileStructuredMesh::clearNonDiscrAttributes();
6227 MEDFileUMeshSplitL1::ClearNonDiscrAttributes(_clmesh);//to it is not a bug umeshsplit have already the method implemented
6230 void MEDFileCurveLinearMesh::synchronizeTinyInfoOnLeaves() const
6232 const MEDCouplingCurveLinearMesh *clmesh=_clmesh;
6235 (const_cast<MEDCouplingCurveLinearMesh *>(clmesh))->setName(_name);
6236 (const_cast<MEDCouplingCurveLinearMesh *>(clmesh))->setDescription(_desc_name);
6237 (const_cast<MEDCouplingCurveLinearMesh *>(clmesh))->setTime(_time,_iteration,_order);
6238 (const_cast<MEDCouplingCurveLinearMesh *>(clmesh))->setTimeUnit(_dt_unit);
6241 const MEDCouplingCurveLinearMesh *MEDFileCurveLinearMesh::getMesh() const
6243 synchronizeTinyInfoOnLeaves();
6247 void MEDFileCurveLinearMesh::setMesh(MEDCouplingCurveLinearMesh *m)
6249 dealWithTinyInfo(m);
6255 const MEDCouplingStructuredMesh *MEDFileCurveLinearMesh::getStructuredMesh() const
6257 synchronizeTinyInfoOnLeaves();
6261 MEDFileCurveLinearMesh::MEDFileCurveLinearMesh()
6265 MEDFileCurveLinearMesh::MEDFileCurveLinearMesh(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
6268 loadCLMeshFromFile(fid,mName,dt,it,mrs);
6269 loadJointsFromFile(fid);
6271 catch(INTERP_KERNEL::Exception& e)
6276 void MEDFileCurveLinearMesh::writeLL(med_idt fid) const
6278 INTERP_KERNEL::AutoPtr<char> maa=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
6279 INTERP_KERNEL::AutoPtr<char> desc=MEDLoaderBase::buildEmptyString(MED_COMMENT_SIZE);
6280 INTERP_KERNEL::AutoPtr<char> dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE);
6281 MEDLoaderBase::safeStrCpy(_name.c_str(),MED_NAME_SIZE,maa,_too_long_str);
6282 MEDLoaderBase::safeStrCpy(_desc_name.c_str(),MED_COMMENT_SIZE,desc,_too_long_str);
6283 MEDLoaderBase::safeStrCpy(_dt_unit.c_str(),MED_LNAME_SIZE,dtunit,_too_long_str);
6284 int spaceDim=_clmesh->getSpaceDimension();
6285 int meshDim=_clmesh->getMeshDimension();
6286 INTERP_KERNEL::AutoPtr<char> comp=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
6287 INTERP_KERNEL::AutoPtr<char> unit=MEDLoaderBase::buildEmptyString(spaceDim*MED_SNAME_SIZE);
6288 const DataArrayDouble *coords=_clmesh->getCoords();
6290 throw INTERP_KERNEL::Exception("MEDFileCurveLinearMesh::writeLL : no coordinates set !");
6291 for(int i=0;i<spaceDim;i++)
6293 std::string info(_clmesh->getCoords()->getInfoOnComponent(i));
6295 MEDLoaderBase::splitIntoNameAndUnit(info,c,u);
6296 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
6297 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
6299 MEDFILESAFECALLERWR0(MEDmeshCr,(fid,maa,spaceDim,meshDim,MED_STRUCTURED_MESH,desc,dtunit,MED_SORT_DTIT,MED_CARTESIAN,comp,unit));
6300 MEDFILESAFECALLERWR0(MEDmeshUniversalNameWr,(fid,maa));
6301 MEDFILESAFECALLERWR0(MEDmeshGridTypeWr,(fid,maa,MED_CURVILINEAR_GRID));
6302 std::vector<int> nodeGridSt=_clmesh->getNodeGridStructure();
6303 MEDFILESAFECALLERWR0(MEDmeshGridStructWr,(fid,maa,_iteration,_order,_time,&nodeGridSt[0]));
6305 MEDFILESAFECALLERWR0(MEDmeshNodeCoordinateWr,(fid,maa,_iteration,_order,_time,MED_FULL_INTERLACE,coords->getNumberOfTuples(),coords->begin()));
6307 std::string meshName(MEDLoaderBase::buildStringFromFortran(maa,MED_NAME_SIZE));
6308 MEDFileStructuredMesh::writeStructuredLL(fid,meshName);
6313 void MEDFileCurveLinearMesh::loadCLMeshFromFile(med_idt fid, const std::string& mName, int dt, int it, MEDFileMeshReadSelector *mrs)
6315 ParaMEDMEM::MEDCouplingMeshType meshType;
6318 int mid=MEDFileMeshL2::GetMeshIdFromName(fid,mName,meshType,dummy0,dummy1,dtunit);
6319 if(meshType!=CURVE_LINEAR)
6321 std::ostringstream oss; oss << "Trying to load as curve linear an existing mesh with name '" << mName << "' that is NOT curve linear !";
6322 throw INTERP_KERNEL::Exception(oss.str().c_str());
6324 MEDFileCLMeshL2 loaderl2;
6325 loaderl2.loadAll(fid,mid,mName,dt,it);
6326 MEDCouplingCurveLinearMesh *mesh=loaderl2.getMesh();
6329 loadStrMeshFromFile(&loaderl2,fid,mName,dt,it,mrs);
6332 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New()
6334 return new MEDFileMeshMultiTS;
6337 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const std::string& fileName)
6339 return new MEDFileMeshMultiTS(fileName);
6342 MEDFileMeshMultiTS *MEDFileMeshMultiTS::New(const std::string& fileName, const std::string& mName)
6344 return new MEDFileMeshMultiTS(fileName,mName);
6347 MEDFileMeshMultiTS *MEDFileMeshMultiTS::deepCpy() const
6349 MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> ret=MEDFileMeshMultiTS::New();
6350 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> > meshOneTs(_mesh_one_ts.size());
6352 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++,i++)
6353 if((const MEDFileMesh *)*it)
6354 meshOneTs[i]=(*it)->deepCpy();
6355 ret->_mesh_one_ts=meshOneTs;
6359 std::size_t MEDFileMeshMultiTS::getHeapMemorySizeWithoutChildren() const
6361 return _mesh_one_ts.capacity()*sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileMesh>);
6364 std::vector<const BigMemoryObject *> MEDFileMeshMultiTS::getDirectChildrenWithNull() const
6366 std::vector<const BigMemoryObject *> ret;
6367 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
6368 ret.push_back((const MEDFileMesh *)*it);
6372 std::string MEDFileMeshMultiTS::getName() const
6374 if(_mesh_one_ts.empty())
6375 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getName : no time steps set !");
6376 return _mesh_one_ts[0]->getName();
6379 void MEDFileMeshMultiTS::setName(const std::string& newMeshName)
6381 std::string oldName(getName());
6382 std::vector< std::pair<std::string,std::string> > v(1);
6383 v[0].first=oldName; v[0].second=newMeshName;
6387 bool MEDFileMeshMultiTS::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6390 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
6392 MEDFileMesh *cur(*it);
6394 ret=cur->changeNames(modifTab) || ret;
6399 MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const
6401 if(_mesh_one_ts.empty())
6402 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::getOneTimeStep : empty time step set !");
6403 return const_cast<MEDFileMesh *>(static_cast<const MEDFileMesh *>(_mesh_one_ts[0]));
6406 void MEDFileMeshMultiTS::setOneTimeStep(MEDFileMesh *mesh1TimeStep)
6409 throw INTERP_KERNEL::Exception("MEDFileMeshMultiTS::setOneTimeStep : input pointer should be different from 0 !");
6410 _mesh_one_ts.resize(1);
6411 mesh1TimeStep->incrRef();
6412 //MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> toto=mesh1TimeStep;
6413 _mesh_one_ts[0]=mesh1TimeStep;
6416 MEDFileJoints * MEDFileMeshMultiTS::getJoints() const
6418 if ( MEDFileMesh* m = getOneTimeStep() )
6419 return m->getJoints();
6424 * \brief Set Joints that are common to all time-stamps
6426 void MEDFileMeshMultiTS::setJoints( MEDFileJoints* joints )
6428 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
6430 (*it)->setJoints( joints );
6434 void MEDFileMeshMultiTS::write(med_idt fid) const
6436 MEDFileJoints *joints(getJoints());
6437 bool jointsWritten(false);
6439 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMesh> >::const_iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++)
6441 if ( jointsWritten )
6442 const_cast<MEDFileMesh&>(**it).setJoints( 0 );
6444 jointsWritten = true;
6446 (*it)->copyOptionsFrom(*this);
6450 (const_cast<MEDFileMeshMultiTS*>(this))->setJoints( joints ); // restore joints
6453 void MEDFileMeshMultiTS::write(const std::string& fileName, int mode) const
6455 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
6456 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
6457 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
6458 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
6462 void MEDFileMeshMultiTS::loadFromFile(const std::string& fileName, const std::string& mName)
6464 MEDFileJoints* joints = 0;
6465 if ( !_mesh_one_ts.empty() && getOneTimeStep() )
6467 // joints of mName already read, pass them to MEDFileMesh::New() to prevent repeated reading
6468 joints = getOneTimeStep()->getJoints();
6471 _mesh_one_ts.clear(); //for the moment to be improved
6472 _mesh_one_ts.push_back( MEDFileMesh::New(fileName,mName,-1,-1,0, joints ));
6475 MEDFileMeshMultiTS::MEDFileMeshMultiTS()
6479 MEDFileMeshMultiTS::MEDFileMeshMultiTS(const std::string& fileName)
6482 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
6485 std::ostringstream oss; oss << "MEDFileUMesh::New : no meshes in file \"" << fileName << "\" !";
6486 throw INTERP_KERNEL::Exception(oss.str().c_str());
6488 MEDFileUtilities::CheckFileForRead(fileName);
6489 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),MED_ACC_RDONLY);
6491 ParaMEDMEM::MEDCouplingMeshType meshType;
6493 MEDFileMeshL2::GetMeshIdFromName(fid,ms.front(),meshType,dt,it,dummy2);
6494 loadFromFile(fileName,ms.front());
6496 catch(INTERP_KERNEL::Exception& e)
6501 MEDFileMeshMultiTS::MEDFileMeshMultiTS(const std::string& fileName, const std::string& mName)
6504 loadFromFile(fileName,mName);
6506 catch(INTERP_KERNEL::Exception& e)
6511 MEDFileMeshes *MEDFileMeshes::New()
6513 return new MEDFileMeshes;
6516 MEDFileMeshes *MEDFileMeshes::New(const std::string& fileName)
6518 return new MEDFileMeshes(fileName);
6521 void MEDFileMeshes::write(med_idt fid) const
6524 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
6526 (*it)->copyOptionsFrom(*this);
6531 void MEDFileMeshes::write(const std::string& fileName, int mode) const
6533 med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
6534 MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName.c_str(),medmod);
6535 std::ostringstream oss; oss << "MEDFileMesh : error on attempt to write in file : \"" << fileName << "\"";
6536 MEDFileUtilities::CheckMEDCode(fid,fid,oss.str());
6541 int MEDFileMeshes::getNumberOfMeshes() const
6543 return _meshes.size();
6546 MEDFileMeshesIterator *MEDFileMeshes::iterator()
6548 return new MEDFileMeshesIterator(this);
6551 /** Return a borrowed reference (caller is not responsible) */
6552 MEDFileMesh *MEDFileMeshes::getMeshAtPos(int i) const
6554 if(i<0 || i>=(int)_meshes.size())
6556 std::ostringstream oss; oss << "MEDFileMeshes::getMeshAtPos : invalid mesh id given in parameter ! Should be in [0;" << _meshes.size() << ") !";
6557 throw INTERP_KERNEL::Exception(oss.str().c_str());
6559 return _meshes[i]->getOneTimeStep();
6562 /** Return a borrowed reference (caller is not responsible) */
6563 MEDFileMesh *MEDFileMeshes::getMeshWithName(const std::string& mname) const
6565 std::vector<std::string> ms=getMeshesNames();
6566 std::vector<std::string>::iterator it=std::find(ms.begin(),ms.end(),mname);
6569 std::ostringstream oss; oss << "MEDFileMeshes::getMeshWithName : Mesh \"" << mname << "\" does not exist in this ! Existing are : ";
6570 std::copy(ms.begin(),ms.end(),std::ostream_iterator<std::string>(oss," "));
6571 throw INTERP_KERNEL::Exception(oss.str().c_str());
6573 return getMeshAtPos((int)std::distance(ms.begin(),it));
6576 std::vector<std::string> MEDFileMeshes::getMeshesNames() const
6578 std::vector<std::string> ret(_meshes.size());
6580 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
6582 const MEDFileMeshMultiTS *f=(*it);
6585 ret[i]=f->getName();
6589 std::ostringstream oss; oss << "MEDFileMeshes::getMeshesNames : At rank #" << i << " mesh is not defined !";
6590 throw INTERP_KERNEL::Exception(oss.str().c_str());
6595 /*const MEDFileJoints* MEDFileMeshes::getJoints() const
6597 const MEDFileJoints *ret=_joints;
6600 std::ostringstream oss; oss << "MEDFileMeshes::getJoints : joints is not defined !";
6601 throw INTERP_KERNEL::Exception(oss.str().c_str());
6606 bool MEDFileMeshes::changeNames(const std::vector< std::pair<std::string,std::string> >& modifTab)
6609 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::iterator it=_meshes.begin();it!=_meshes.end();it++)
6611 MEDFileMeshMultiTS *cur(*it);
6613 ret=cur->changeNames(modifTab) || ret;
6618 void MEDFileMeshes::resize(int newSize)
6620 _meshes.resize(newSize);
6623 void MEDFileMeshes::pushMesh(MEDFileMesh *mesh)
6626 throw INTERP_KERNEL::Exception("MEDFileMeshes::pushMesh : invalid input pointer ! should be different from 0 !");
6627 MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
6628 elt->setOneTimeStep(mesh);
6629 _meshes.push_back(elt);
6632 void MEDFileMeshes::setMeshAtPos(int i, MEDFileMesh *mesh)
6635 throw INTERP_KERNEL::Exception("MEDFileMeshes::setMeshAtPos : invalid input pointer ! should be different from 0 !");
6636 if(i>=(int)_meshes.size())
6637 _meshes.resize(i+1);
6638 MEDFileMeshMultiTS *elt=MEDFileMeshMultiTS::New();
6639 elt->setOneTimeStep(mesh);
6643 void MEDFileMeshes::destroyMeshAtPos(int i)
6645 if(i<0 || i>=(int)_meshes.size())
6647 std::ostringstream oss; oss << "MEDFileMeshes::destroyMeshAtPos : Invalid given id in input (" << i << ") should be in [0," << _meshes.size() << ") !";
6648 throw INTERP_KERNEL::Exception(oss.str().c_str());
6650 _meshes.erase(_meshes.begin()+i);
6653 void MEDFileMeshes::loadFromFile(const std::string& fileName)
6655 std::vector<std::string> ms=MEDLoader::GetMeshNames(fileName);
6657 _meshes.resize(ms.size());
6658 for(std::vector<std::string>::const_iterator it=ms.begin();it!=ms.end();it++,i++)
6659 _meshes[i]=MEDFileMeshMultiTS::New(fileName,(*it));
6662 MEDFileMeshes::MEDFileMeshes()
6666 MEDFileMeshes::MEDFileMeshes(const std::string& fileName)
6669 loadFromFile(fileName);
6671 catch(INTERP_KERNEL::Exception& /*e*/)
6675 MEDFileMeshes *MEDFileMeshes::deepCpy() const
6677 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> > meshes(_meshes.size());
6679 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
6680 if((const MEDFileMeshMultiTS *)*it)
6681 meshes[i]=(*it)->deepCpy();
6682 MEDCouplingAutoRefCountObjectPtr<MEDFileMeshes> ret=MEDFileMeshes::New();
6683 ret->_meshes=meshes;
6687 std::size_t MEDFileMeshes::getHeapMemorySizeWithoutChildren() const
6689 return _meshes.capacity()*(sizeof(MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS>));
6692 std::vector<const BigMemoryObject *> MEDFileMeshes::getDirectChildrenWithNull() const
6694 std::vector<const BigMemoryObject *> ret;
6695 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++)
6696 ret.push_back((const MEDFileMeshMultiTS *)*it);
6700 std::string MEDFileMeshes::simpleRepr() const
6702 std::ostringstream oss;
6703 oss << "(*****************)\n(* MEDFileMeshes *)\n(*****************)\n\n";
6704 simpleReprWithoutHeader(oss);
6708 void MEDFileMeshes::simpleReprWithoutHeader(std::ostream& oss) const
6710 int nbOfMeshes=getNumberOfMeshes();
6711 oss << "There are " << nbOfMeshes << " meshes with the following names : \n";
6712 std::vector<std::string> mns=getMeshesNames();
6713 for(int i=0;i<nbOfMeshes;i++)
6714 oss << " - #" << i << " \"" << mns[i] << "\"\n";
6717 void MEDFileMeshes::checkCoherency() const
6719 static const char MSG[]="MEDFileMeshes::checkCoherency : mesh at rank ";
6721 std::set<std::string> s;
6722 for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileMeshMultiTS> >::const_iterator it=_meshes.begin();it!=_meshes.end();it++,i++)
6724 const MEDFileMeshMultiTS *elt=(*it);
6727 std::ostringstream oss; oss << MSG << i << "/" << _meshes.size() << " is empty !";
6728 throw INTERP_KERNEL::Exception(oss.str().c_str());
6730 std::size_t sz=s.size();
6731 s.insert(std::string((*it)->getName()));
6734 std::ostringstream oss; oss << MSG << i << " has a name (\"" << (*it)->getName() << "\") already used by an another mesh in list !";
6735 throw INTERP_KERNEL::Exception(oss.str().c_str());
6740 MEDFileMeshesIterator::MEDFileMeshesIterator(MEDFileMeshes *ms):_ms(ms),_iter_id(0),_nb_iter(0)
6745 _nb_iter=ms->getNumberOfMeshes();
6749 MEDFileMeshesIterator::~MEDFileMeshesIterator()
6753 MEDFileMesh *MEDFileMeshesIterator::nextt()
6755 if(_iter_id<_nb_iter)
6757 MEDFileMeshes *ms(_ms);
6759 return ms->getMeshAtPos(_iter_id++);