1 // Copyright (C) 2007-2016 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 (EDF R&D)
21 #include "MEDFileFieldGlobs.hxx"
22 #include "MEDFileField.txx"
23 #include "MEDFileMesh.hxx"
24 #include "MEDLoaderBase.hxx"
25 #include "MEDLoaderTraits.hxx"
26 #include "MEDFileSafeCaller.txx"
27 #include "MEDFileFieldOverView.hxx"
28 #include "MEDFileBlowStrEltUp.hxx"
29 #include "MEDFileFieldVisitor.hxx"
31 #include "MEDCouplingFieldDiscretization.hxx"
34 #include "InterpKernelAutoPtr.hxx"
35 #include "CellModel.hxx"
40 using namespace MEDCoupling;
42 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
44 if(id>=(int)_pfls.size())
46 _pfls[id]=DataArrayInt::New();
47 int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
48 _pfls[id]->setName(pflName);
49 _pfls[id]->alloc(lgth,1);
50 MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),_pfls[id]->getPointer()));
51 _pfls[id]->applyLin(1,-1,0);//Converting into C format
54 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
56 INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
58 MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
59 std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
60 if(i>=(int)_pfls.size())
62 _pfls[i]=DataArrayInt::New();
63 _pfls[i]->alloc(sz,1);
64 _pfls[i]->setName(pflCpp.c_str());
65 MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,_pfls[i]->getPointer()));
66 _pfls[i]->applyLin(1,-1,0);//Converting into C format
69 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
71 int nbOfPfls=_pfls.size();
72 for(int i=0;i<nbOfPfls;i++)
74 MCAuto<DataArrayInt> cpy=_pfls[i]->deepCopy();
76 INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
77 MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
78 MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()));
81 int nbOfLocs=_locs.size();
82 for(int i=0;i<nbOfLocs;i++)
83 _locs[i]->writeLL(fid);
86 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
88 std::vector<std::string> pfls=getPfls();
89 for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
91 std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
98 int id=std::distance(pfls.begin(),it2);
99 if(!(*it)->isEqual(*_pfls[id]))
101 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
102 throw INTERP_KERNEL::Exception(oss.str());
106 std::vector<std::string> locs=getLocs();
107 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
109 std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
112 _locs.push_back(*it);
116 int id=std::distance(locs.begin(),it2);
117 if(!(*it)->isEqual(*_locs[id],eps))
119 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
120 throw INTERP_KERNEL::Exception(oss.str());
126 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
128 for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
129 getProfile((*it).c_str());
132 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
134 for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
135 getLocalization((*it).c_str());
138 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
140 std::vector<std::string> profiles=real.getPflsReallyUsed();
141 int sz=profiles.size();
143 for(int i=0;i<sz;i++)
144 loadProfileInFile(fid,i,profiles[i].c_str());
146 std::vector<std::string> locs=real.getLocsReallyUsed();
149 for(int i=0;i<sz;i++)
150 _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
153 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
155 int nProfil=MEDnProfile(fid);
156 for(int i=0;i<nProfil;i++)
157 loadProfileInFile(fid,i);
158 int sz=MEDnLocalization(fid);
160 for(int i=0;i<sz;i++)
162 _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
166 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
168 return new MEDFileFieldGlobs(fid);
171 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
173 return new MEDFileFieldGlobs;
176 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
178 return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
181 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
183 std::vector<const BigMemoryObject *> ret;
184 for(std::vector< MCAuto< DataArrayInt > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
185 ret.push_back((const DataArrayInt *)*it);
186 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
187 ret.push_back((const MEDFileFieldLoc *)*it);
191 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
193 MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
195 for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
197 if((const DataArrayInt *)*it)
198 ret->_pfls[i]=(*it)->deepCopy();
201 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
203 if((const MEDFileFieldLoc*)*it)
204 ret->_locs[i]=(*it)->deepCopy();
210 * \throw if a profile in \a pfls in not in \a this.
211 * \throw if a localization in \a locs in not in \a this.
212 * \sa MEDFileFieldGlobs::deepCpyPart
214 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
216 MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
217 for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
219 DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
221 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
223 MCAuto<DataArrayInt> pfl2(pfl);
224 ret->_pfls.push_back(pfl2);
226 for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
228 MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
230 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
232 MCAuto<MEDFileFieldLoc> loc2(loc);
233 ret->_locs.push_back(loc2);
235 ret->setFileName(getFileName());
240 * \throw if a profile in \a pfls in not in \a this.
241 * \throw if a localization in \a locs in not in \a this.
242 * \sa MEDFileFieldGlobs::shallowCpyPart
244 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
246 MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
247 for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
249 DataArrayInt *pfl=const_cast<DataArrayInt *>(getProfile((*it1).c_str()));
251 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
252 ret->_pfls.push_back(pfl->deepCopy());
254 for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
256 MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
258 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
259 ret->_locs.push_back(loc->deepCopy());
261 ret->setFileName(getFileName());
265 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
269 MEDFileFieldGlobs::MEDFileFieldGlobs()
273 MEDFileFieldGlobs::~MEDFileFieldGlobs()
277 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
279 oss << "Profiles :\n";
280 std::size_t n=_pfls.size();
281 for(std::size_t i=0;i<n;i++)
283 oss << " - #" << i << " ";
284 const DataArrayInt *pfl=_pfls[i];
286 oss << "\"" << pfl->getName() << "\"\n";
291 oss << "Localizations :\n";
292 for(std::size_t i=0;i<n;i++)
294 oss << " - #" << i << " ";
295 const MEDFileFieldLoc *loc=_locs[i];
297 loc->simpleRepr(oss);
303 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
305 for(std::vector< MCAuto<DataArrayInt> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
307 DataArrayInt *elt(*it);
310 std::string name(elt->getName());
311 for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
313 if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
315 elt->setName((*it2).second.c_str());
323 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
325 for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
327 MEDFileFieldLoc *elt(*it);
330 std::string name(elt->getName());
331 for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
333 if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
335 elt->setName((*it2).second.c_str());
343 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
345 if(locId<0 || locId>=(int)_locs.size())
346 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
347 return _locs[locId]->getNbOfGaussPtPerCell();
350 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
352 return getLocalizationFromId(getLocalizationId(locName));
355 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
357 if(locId<0 || locId>=(int)_locs.size())
358 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
359 return *_locs[locId];
363 namespace MEDCouplingImpl
368 LocFinder(const std::string& loc):_loc(loc) { }
369 bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
371 const std::string &_loc;
377 PflFinder(const std::string& pfl):_pfl(pfl) { }
378 bool operator() (const MCAuto<DataArrayInt>& loc) { return loc->getName()==_pfl; }
380 const std::string _pfl;
385 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
387 std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
390 std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
391 for(it=_locs.begin();it!=_locs.end();it++)
392 oss << "\"" << (*it)->getName() << "\", ";
393 throw INTERP_KERNEL::Exception(oss.str());
395 return std::distance(_locs.begin(),it);
398 int MEDFileFieldGlobs::getProfileId(const std::string& pfl) const
400 std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pfl));
403 std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfileId : no such profile name : \"" << pfl << "\" Possible localizations are : ";
404 for(it=_pfls.begin();it!=_pfls.end();it++)
405 oss << "\"" << (*it)->getName() << "\", ";
406 throw INTERP_KERNEL::Exception(oss.str());
408 return std::distance(_pfls.begin(),it);
412 * The returned value is never null.
414 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
416 return getProfileFromId(getProfileId(pflName));
419 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
421 if(pflId<0 || pflId>=(int)_pfls.size())
422 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
426 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
428 if(locId<0 || locId>=(int)_locs.size())
429 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
430 return *_locs[locId];
433 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
435 return getLocalizationFromId(getLocalizationId(locName));
439 * The returned value is never null. Borrowed reference returned.
441 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
443 std::string pflNameCpp(pflName);
444 std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
447 std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
448 for(it=_pfls.begin();it!=_pfls.end();it++)
449 oss << "\"" << (*it)->getName() << "\", ";
450 throw INTERP_KERNEL::Exception(oss.str());
455 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
457 if(pflId<0 || pflId>=(int)_pfls.size())
458 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
462 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
464 std::vector< MCAuto<DataArrayInt> > newPfls;
466 for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
468 if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
469 newPfls.push_back(*it);
474 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
476 std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
478 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
480 if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
481 newLocs.push_back(*it);
486 void MEDFileFieldGlobs::killStructureElementsInGlobs()
488 std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
489 for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
493 if(!(*it)->isOnStructureElement())
494 newLocs.push_back(*it);
499 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
502 std::vector<std::string> ret(sz);
503 for(int i=0;i<sz;i++)
504 ret[i]=_pfls[i]->getName();
508 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
511 std::vector<std::string> ret(sz);
512 for(int i=0;i<sz;i++)
513 ret[i]=_locs[i]->getName();
517 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
519 std::vector<std::string> v=getPfls();
520 std::string s(pflName);
521 return std::find(v.begin(),v.end(),s)!=v.end();
524 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
526 std::vector<std::string> v=getLocs();
527 std::string s(locName);
528 return std::find(v.begin(),v.end(),s)!=v.end();
531 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
533 std::map<int,std::vector<int> > m;
535 for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
537 const DataArrayInt *tmp=(*it);
540 m[tmp->getHashCode()].push_back(i);
543 std::vector< std::vector<int> > ret;
544 for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
546 if((*it2).second.size()>1)
548 std::vector<int> ret0;
549 bool equalityOrNot=false;
550 for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
552 std::vector<int>::const_iterator it4=it3; it4++;
553 for(;it4!=(*it2).second.end();it4++)
555 if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
558 ret0.push_back(*it3);
559 ret0.push_back(*it4);
571 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
573 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
576 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
578 std::string name(pfl->getName());
580 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
581 for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
582 if(name==(*it)->getName())
584 if(!pfl->isEqual(*(*it)))
586 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
587 throw INTERP_KERNEL::Exception(oss.str());
591 _pfls.push_back(pfl);
594 void MEDFileFieldGlobs::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
596 std::string name(locName);
598 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
599 MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
600 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
601 if((*it)->isName(locName))
603 if(!(*it)->isEqual(*obj,1e-12))
605 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
606 throw INTERP_KERNEL::Exception(oss.str());
609 _locs.push_back(obj);
612 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
614 std::vector<std::string> names=getPfls();
615 return CreateNewNameNotIn("NewPfl_",names);
618 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
620 std::vector<std::string> names=getLocs();
621 return CreateNewNameNotIn("NewLoc_",names);
624 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
626 for(std::size_t sz=0;sz<100000;sz++)
628 std::ostringstream tryName;
629 tryName << prefix << sz;
630 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
631 return tryName.str();
633 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
637 * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
638 * \param [in] fname - the file name.
640 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
645 * Creates an empty MEDFileFieldGlobsReal.
647 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
651 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
656 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
658 std::vector<const BigMemoryObject *> ret;
659 ret.push_back((const MEDFileFieldGlobs *)_globals);
664 * Returns a string describing profiles and Gauss points held in \a this.
665 * \return std::string - the description string.
667 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
669 const MEDFileFieldGlobs *glob=_globals;
670 std::ostringstream oss2; oss2 << glob;
671 std::string stars(oss2.str().length(),'*');
672 oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars << "\n\n";
674 glob->simpleRepr(oss);
676 oss << "NO GLOBAL INFORMATION !\n";
679 void MEDFileFieldGlobsReal::resetContent()
681 _globals=MEDFileFieldGlobs::New();
684 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
686 contentNotNull()->killStructureElementsInGlobs();
689 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
694 * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
695 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
697 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
699 _globals=other._globals;
703 * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
704 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
706 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
708 const MEDFileFieldGlobs *otherg(other._globals);
711 _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
715 * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
716 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
718 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
720 const MEDFileFieldGlobs *otherg(other._globals);
723 _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
726 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
728 _globals=other._globals;
729 if((const MEDFileFieldGlobs *)_globals)
730 _globals=other._globals->deepCopy();
734 * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
735 * \param [in] other - the MEDFileFieldGlobsReal to copy data from.
736 * \param [in] eps - a precision used to compare Gauss points with same name held by
737 * \a this and \a other MEDFileFieldGlobsReal.
738 * \throw If \a this and \a other hold profiles with equal names but different ids.
739 * \throw If \a this and \a other hold different Gauss points with equal names.
741 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
743 const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
744 if(thisGlobals==otherGlobals)
748 _globals=other._globals;
751 _globals->appendGlobs(*other._globals,eps);
754 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
756 checkGlobsPflsPartCoherency();
757 checkGlobsLocsPartCoherency();
760 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
762 contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
765 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
767 contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
770 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
772 contentNotNull()->loadProfileInFile(fid,id,pflName);
775 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
777 contentNotNull()->loadProfileInFile(fid,id);
780 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
782 contentNotNull()->loadGlobals(fid,*this);
785 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
787 contentNotNull()->loadAllGlobals(fid,entities);
790 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
792 contentNotNull()->writeGlobals(fid,opt);
796 * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
797 * or getPflsReallyUsedMulti().
798 * \return std::vector<std::string> - a sequence of names of all profiles.
800 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
802 return contentNotNull()->getPfls();
806 * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
807 * or getLocsReallyUsedMulti().
808 * \return std::vector<std::string> - a sequence of names of all localizations.
810 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
812 return contentNotNull()->getLocs();
816 * Checks if the profile with a given name exists.
817 * \param [in] pflName - the profile name of interest.
818 * \return bool - \c true if the profile named \a pflName exists.
820 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
822 return contentNotNull()->existsPfl(pflName);
826 * Checks if the localization with a given name exists.
827 * \param [in] locName - the localization name of interest.
828 * \return bool - \c true if the localization named \a locName exists.
830 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
832 return contentNotNull()->existsLoc(locName);
835 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
837 return contentNotNull()->createNewNameOfPfl();
840 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
842 return contentNotNull()->createNewNameOfLoc();
846 * Sets the name of a MED file.
847 * \param [inout] fileName - the file name.
849 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
851 contentNotNull()->setFileName(fileName);
855 * Finds equal profiles. Two profiles are considered equal if they contain the same ids
857 * \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
858 * Each item of this sequence is a vector containing ids of equal profiles.
860 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
862 return contentNotNull()->whichAreEqualProfiles();
866 * Finds equal localizations.
867 * \param [in] eps - a precision used to compare real values of the localizations.
868 * \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
869 * Each item of this sequence is a vector containing ids of equal localizations.
871 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
873 return contentNotNull()->whichAreEqualLocs(eps);
877 * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
878 * \param [in] mapOfModif - a sequence describing required renaming. Each element of
879 * this sequence is a pair whose
880 * - the first item is a vector of profile names to replace by the second item,
881 * - the second item is a profile name to replace every profile name of the first item.
883 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
885 contentNotNull()->changePflsNamesInStruct(mapOfModif);
889 * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
890 * \param [in] mapOfModif - a sequence describing required renaming. Each element of
891 * this sequence is a pair whose
892 * - the first item is a vector of localization names to replace by the second item,
893 * - the second item is a localization name to replace every localization name of the first item.
895 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
897 contentNotNull()->changeLocsNamesInStruct(mapOfModif);
901 * Replaces references to some profiles (a reference is a profile name) by references
902 * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
903 * them-selves accordingly. <br>
904 * This method is a generalization of changePflName().
905 * \param [in] mapOfModif - a sequence describing required replacements. Each element of
906 * this sequence is a pair whose
907 * - the first item is a vector of profile names to replace by the second item,
908 * - the second item is a profile name to replace every profile of the first item.
909 * \sa changePflsRefsNamesGen()
910 * \sa changePflName()
912 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
914 changePflsRefsNamesGen(mapOfModif);
915 changePflsNamesInStruct(mapOfModif);
919 * Replaces references to some localizations (a reference is a localization name) by references
920 * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
921 * them-selves accordingly. <br>
922 * This method is a generalization of changeLocName().
923 * \param [in] mapOfModif - a sequence describing required replacements. Each element of
924 * this sequence is a pair whose
925 * - the first item is a vector of localization names to replace by the second item,
926 * - the second item is a localization name to replace every localization of the first item.
927 * \sa changeLocsRefsNamesGen()
928 * \sa changeLocName()
930 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
932 changeLocsRefsNamesGen(mapOfModif);
933 changeLocsNamesInStruct(mapOfModif);
937 * Renames the profile having a given name and updates references to this profile.
938 * \param [in] oldName - the name of the profile to rename.
939 * \param [in] newName - a new name of the profile.
940 * \sa changePflsNames().
942 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
944 std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
945 std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
947 changePflsNames(mapOfModif);
951 * Renames the localization having a given name and updates references to this localization.
952 * \param [in] oldName - the name of the localization to rename.
953 * \param [in] newName - a new name of the localization.
954 * \sa changeLocsNames().
956 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
958 std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
959 std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
961 changeLocsNames(mapOfModif);
965 * Removes duplicated profiles. Returns a map used to update references to removed
966 * profiles via changePflsRefsNamesGen().
967 * Equal profiles are found using whichAreEqualProfiles().
968 * \return std::vector< std::pair<std::vector<std::string>, std::string > > -
969 * a sequence describing the performed replacements of profiles. Each element of
970 * this sequence is a pair whose
971 * - the first item is a vector of profile names replaced by the second item,
972 * - the second item is a profile name replacing every profile of the first item.
974 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
976 std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
977 std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
979 for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
981 std::vector< std::string > tmp((*it).size());
983 for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
984 tmp[j]=std::string(getProfileFromId(*it2)->getName());
985 std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
987 std::vector<int> tmp2((*it).begin()+1,(*it).end());
988 killProfileIds(tmp2);
990 changePflsRefsNamesGen(ret);
995 * Removes duplicated localizations. Returns a map used to update references to removed
996 * localizations via changeLocsRefsNamesGen().
997 * Equal localizations are found using whichAreEqualLocs().
998 * \param [in] eps - a precision used to compare real values of the localizations.
999 * \return std::vector< std::pair<std::vector<std::string>, std::string > > -
1000 * a sequence describing the performed replacements of localizations. Each element of
1001 * this sequence is a pair whose
1002 * - the first item is a vector of localization names replaced by the second item,
1003 * - the second item is a localization name replacing every localization of the first item.
1005 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
1007 std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
1008 std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
1010 for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
1012 std::vector< std::string > tmp((*it).size());
1014 for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
1015 tmp[j]=std::string(getLocalizationFromId(*it2).getName());
1016 std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
1018 std::vector<int> tmp2((*it).begin()+1,(*it).end());
1019 killLocalizationIds(tmp2);
1021 changeLocsRefsNamesGen(ret);
1026 * Returns number of Gauss points per cell in a given localization.
1027 * \param [in] locId - an id of the localization of interest.
1028 * \return int - the number of the Gauss points per cell.
1030 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
1032 return contentNotNull()->getNbOfGaussPtPerCell(locId);
1036 * Returns an id of a localization by its name.
1037 * \param [in] loc - the localization name of interest.
1038 * \return int - the id of the localization.
1039 * \throw If there is no a localization named \a loc.
1041 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
1043 return contentNotNull()->getLocalizationId(loc);
1047 * Returns an id of a profile by its name.
1048 * \param [in] loc - the profile name of interest.
1049 * \return int - the id of the profile.
1050 * \throw If there is no a profile named \a loc.
1052 int MEDFileFieldGlobsReal::getProfileId(const std::string& pfl) const
1054 return contentNotNull()->getProfileId(pfl);
1058 * Returns the name of the MED file.
1059 * \return const std::string& - the MED file name.
1061 std::string MEDFileFieldGlobsReal::getFileName() const
1063 return contentNotNull()->getFileName();
1067 * Returns a localization object by its name.
1068 * \param [in] locName - the name of the localization of interest.
1069 * \return const MEDFileFieldLoc& - the localization object having the name \a locName.
1070 * \throw If there is no a localization named \a locName.
1072 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
1074 return contentNotNull()->getLocalization(locName);
1078 * Returns a localization object by its id.
1079 * \param [in] locId - the id of the localization of interest.
1080 * \return const MEDFileFieldLoc& - the localization object having the id \a locId.
1081 * \throw If there is no a localization with id \a locId.
1083 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
1085 return contentNotNull()->getLocalizationFromId(locId);
1089 * Returns a profile array by its name.
1090 * \param [in] pflName - the name of the profile of interest.
1091 * \return const DataArrayInt * - the profile array having the name \a pflName.
1092 * \throw If there is no a profile named \a pflName.
1094 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
1096 return contentNotNull()->getProfile(pflName);
1100 * Returns a profile array by its id.
1101 * \param [in] pflId - the id of the profile of interest.
1102 * \return const DataArrayInt * - the profile array having the id \a pflId.
1103 * \throw If there is no a profile with id \a pflId.
1105 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
1107 return contentNotNull()->getProfileFromId(pflId);
1111 * Returns a localization object, apt for modification, by its id.
1112 * \param [in] locId - the id of the localization of interest.
1113 * \return MEDFileFieldLoc& - a non-const reference to the localization object
1114 * having the id \a locId.
1115 * \throw If there is no a localization with id \a locId.
1117 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
1119 return contentNotNull()->getLocalizationFromId(locId);
1123 * Returns a localization object, apt for modification, by its name.
1124 * \param [in] locName - the name of the localization of interest.
1125 * \return MEDFileFieldLoc& - a non-const reference to the localization object
1126 * having the name \a locName.
1127 * \throw If there is no a localization named \a locName.
1129 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
1131 return contentNotNull()->getLocalization(locName);
1135 * Returns a profile array, apt for modification, by its name.
1136 * \param [in] pflName - the name of the profile of interest.
1137 * \return DataArrayInt * - Borrowed reference - a non-const pointer to the profile array having the name \a pflName.
1138 * \throw If there is no a profile named \a pflName.
1140 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
1142 return contentNotNull()->getProfile(pflName);
1146 * Returns a profile array, apt for modification, by its id.
1147 * \param [in] pflId - the id of the profile of interest.
1148 * \return DataArrayInt * - Borrowed reference - a non-const pointer to the profile array having the id \a pflId.
1149 * \throw If there is no a profile with id \a pflId.
1151 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
1153 return contentNotNull()->getProfileFromId(pflId);
1157 * Removes profiles given by their ids. No data is updated to track this removal.
1158 * \param [in] pflIds - a sequence of ids of the profiles to remove.
1160 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
1162 contentNotNull()->killProfileIds(pflIds);
1166 * Removes localizations given by their ids. No data is updated to track this removal.
1167 * \param [in] locIds - a sequence of ids of the localizations to remove.
1169 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
1171 contentNotNull()->killLocalizationIds(locIds);
1175 * Stores a profile array.
1176 * \param [in] pfl - the profile array to store.
1177 * \throw If the name of \a pfl is empty.
1178 * \throw If a profile with the same name as that of \a pfl already exists but contains
1181 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
1183 contentNotNull()->appendProfile(pfl);
1187 * Adds a new localization of Gauss points.
1188 * \param [in] locName - the name of the new localization.
1189 * \param [in] geoType - a geometrical type of the reference cell.
1190 * \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
1191 * must be \c nbOfNodesPerCell * \c dimOfType.
1192 * \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
1193 * must be _wg_.size() * \c dimOfType.
1194 * \param [in] w - the weights of Gauss points.
1195 * \throw If \a locName is empty.
1196 * \throw If a localization with the name \a locName already exists but is
1197 * different form the new one.
1199 void MEDFileFieldGlobsReal::appendLoc(const std::string& locName, INTERP_KERNEL::NormalizedCellType geoType, const std::vector<double>& refCoo, const std::vector<double>& gsCoo, const std::vector<double>& w)
1201 contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
1204 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
1206 MEDFileFieldGlobs *g(_globals);
1208 throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
1212 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
1214 const MEDFileFieldGlobs *g(_globals);
1216 throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
1220 //= MEDFileFieldNameScope
1222 MEDFileFieldNameScope::MEDFileFieldNameScope()
1226 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
1231 * Returns the name of \a this field.
1232 * \return std::string - a string containing the field name.
1234 std::string MEDFileFieldNameScope::getName() const
1240 * Sets name of \a this field
1241 * \param [in] name - the new field name.
1243 void MEDFileFieldNameScope::setName(const std::string& fieldName)
1248 std::string MEDFileFieldNameScope::getDtUnit() const
1253 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
1258 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
1261 _mesh_name=other._mesh_name;
1262 _dt_unit=other._dt_unit;
1266 * Returns the mesh name.
1267 * \return std::string - a string holding the mesh name.
1268 * \throw If \c _field_per_mesh.empty()
1270 std::string MEDFileFieldNameScope::getMeshName() const
1275 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
1277 _mesh_name=meshName;