1 // Copyright (C) 2007-2021 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 "MEDCouplingMemArray.txx"
32 #include "MEDCouplingFieldDiscretization.hxx"
35 #include "InterpKernelAutoPtr.hxx"
36 #include "CellModel.hxx"
41 using namespace MEDCoupling;
43 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
45 if(id>=(int)_pfls.size())
47 MCAuto<DataArrayMedInt> miPfl=DataArrayMedInt::New();
48 med_int lgth(MEDprofileSizeByName(fid,pflName.c_str()));
49 miPfl->setName(pflName);
51 MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName.c_str(),miPfl->getPointer()));
52 _pfls[id]=FromMedIntArray<mcIdType>(miPfl);
53 _pfls[id]->applyLin(1,-1,0);//Converting into C format
56 void MEDFileFieldGlobs::loadProfileInFile(med_idt fid, int i)
58 INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
60 MEDFILESAFECALLERRD0(MEDprofileInfo,(fid,i+1,pflName,&sz));
61 std::string pflCpp=MEDLoaderBase::buildStringFromFortran(pflName,MED_NAME_SIZE);
62 if(i>=(int)_pfls.size())
64 MCAuto<DataArrayMedInt> miPfl=DataArrayMedInt::New();
66 miPfl->setName(pflCpp.c_str());
67 MEDFILESAFECALLERRD0(MEDprofileRd,(fid,pflName,miPfl->getPointer()));
68 _pfls[i]=FromMedIntArray<mcIdType>(miPfl);
69 _pfls[i]->applyLin(1,-1,0);//Converting into C format
72 void MEDFileFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
74 std::size_t nbOfPfls=_pfls.size();
75 for(std::size_t i=0;i<nbOfPfls;i++)
77 MCAuto<DataArrayMedInt> cpy=DataArrayMedInt::Copy((const DataArrayIdType*)_pfls[i]);
79 INTERP_KERNEL::AutoPtr<char> pflName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE);
80 MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy());
81 MEDFILESAFECALLERWR0(MEDprofileWr,(fid,pflName,ToMedInt(_pfls[i]->getNumberOfTuples()),cpy->getConstPointer()));
84 std::size_t nbOfLocs=_locs.size();
85 for(std::size_t i=0;i<nbOfLocs;i++)
86 _locs[i]->writeLL(fid);
89 void MEDFileFieldGlobs::appendGlobs(const MEDFileFieldGlobs& other, double eps)
91 std::vector<std::string> pfls=getPfls();
92 for(std::vector< MCAuto<DataArrayIdType> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
94 std::vector<std::string>::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName());
101 std::size_t id=std::distance(pfls.begin(),it2);
102 if(!(*it)->isEqual(*_pfls[id]))
104 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
105 throw INTERP_KERNEL::Exception(oss.str());
109 std::vector<std::string> locs=getLocs();
110 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=other._locs.begin();it!=other._locs.end();it++)
112 std::vector<std::string>::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName());
115 _locs.push_back(*it);
119 std::size_t id=std::distance(locs.begin(),it2);
120 if(!(*it)->isEqual(*_locs[id],eps))
122 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !";
123 throw INTERP_KERNEL::Exception(oss.str());
129 void MEDFileFieldGlobs::checkGlobsPflsPartCoherency(const std::vector<std::string>& pflsUsed) const
131 for(std::vector<std::string>::const_iterator it=pflsUsed.begin();it!=pflsUsed.end();it++)
132 getProfile((*it).c_str());
135 void MEDFileFieldGlobs::checkGlobsLocsPartCoherency(const std::vector<std::string>& locsUsed) const
137 for(std::vector<std::string>::const_iterator it=locsUsed.begin();it!=locsUsed.end();it++)
138 getLocalization((*it).c_str());
141 void MEDFileFieldGlobs::loadGlobals(med_idt fid, const MEDFileFieldGlobsReal& real)
143 std::vector<std::string> profiles=real.getPflsReallyUsed();
144 std::size_t sz=profiles.size();
146 for(unsigned int i=0;i<sz;i++)
147 loadProfileInFile(fid,i,profiles[i].c_str());
149 std::vector<std::string> locs=real.getLocsReallyUsed();
152 for(std::size_t i=0;i<sz;i++)
153 _locs[i]=MEDFileFieldLoc::New(fid,locs[i].c_str());
156 void MEDFileFieldGlobs::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
158 med_int nProfil=MEDnProfile(fid);
159 for(int i=0;i<nProfil;i++)
160 loadProfileInFile(fid,i);
161 med_int sz=MEDnLocalization(fid);
163 for(int i=0;i<sz;i++)
165 _locs[i]=MEDFileFieldLoc::New(fid,i,entities);
169 MEDFileFieldGlobs *MEDFileFieldGlobs::New(med_idt fid)
171 return new MEDFileFieldGlobs(fid);
174 MEDFileFieldGlobs *MEDFileFieldGlobs::New()
176 return new MEDFileFieldGlobs;
179 std::size_t MEDFileFieldGlobs::getHeapMemorySizeWithoutChildren() const
181 return _file_name.capacity()+_pfls.capacity()*sizeof(MCAuto<DataArrayInt>)+_locs.capacity()*sizeof(MCAuto<MEDFileFieldLoc>);
184 std::vector<const BigMemoryObject *> MEDFileFieldGlobs::getDirectChildrenWithNull() const
186 std::vector<const BigMemoryObject *> ret;
187 for(std::vector< MCAuto< DataArrayIdType > >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
188 ret.push_back((const DataArrayIdType *)*it);
189 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
190 ret.push_back((const MEDFileFieldLoc *)*it);
194 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCopy() const
196 MCAuto<MEDFileFieldGlobs> ret=new MEDFileFieldGlobs(*this);
198 for(std::vector< MCAuto<DataArrayIdType> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
200 if((const DataArrayIdType *)*it)
201 ret->_pfls[i]=(*it)->deepCopy();
204 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
206 if((const MEDFileFieldLoc*)*it)
207 ret->_locs[i]=(*it)->deepCopy();
213 * \throw if a profile in \a pfls in not in \a this.
214 * \throw if a localization in \a locs in not in \a this.
215 * \sa MEDFileFieldGlobs::deepCpyPart
217 MEDFileFieldGlobs *MEDFileFieldGlobs::shallowCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
219 MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
220 for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
222 DataArrayIdType *pfl=const_cast<DataArrayIdType *>(getProfile((*it1).c_str()));
224 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! pfl null !");
226 MCAuto<DataArrayIdType> pfl2(pfl);
227 ret->_pfls.push_back(pfl2);
229 for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
231 MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
233 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::shallowCpyPart : internal error ! loc null !");
235 MCAuto<MEDFileFieldLoc> loc2(loc);
236 ret->_locs.push_back(loc2);
238 ret->setFileName(getFileName());
243 * \throw if a profile in \a pfls in not in \a this.
244 * \throw if a localization in \a locs in not in \a this.
245 * \sa MEDFileFieldGlobs::shallowCpyPart
247 MEDFileFieldGlobs *MEDFileFieldGlobs::deepCpyPart(const std::vector<std::string>& pfls, const std::vector<std::string>& locs) const
249 MCAuto<MEDFileFieldGlobs> ret=MEDFileFieldGlobs::New();
250 for(std::vector<std::string>::const_iterator it1=pfls.begin();it1!=pfls.end();it1++)
252 DataArrayIdType *pfl=const_cast<DataArrayIdType *>(getProfile((*it1).c_str()));
254 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! pfl null !");
255 ret->_pfls.push_back(pfl->deepCopy());
257 for(std::vector<std::string>::const_iterator it2=locs.begin();it2!=locs.end();it2++)
259 MEDFileFieldLoc *loc=const_cast<MEDFileFieldLoc *>(&getLocalization((*it2).c_str()));
261 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::deepCpyPart : internal error ! loc null !");
262 ret->_locs.push_back(loc->deepCopy());
264 ret->setFileName(getFileName());
268 MEDFileFieldGlobs::MEDFileFieldGlobs(med_idt fid):_file_name(MEDFileWritable::FileNameFromFID(fid))
272 MEDFileFieldGlobs::MEDFileFieldGlobs()
276 MEDFileFieldGlobs::~MEDFileFieldGlobs()
280 void MEDFileFieldGlobs::simpleRepr(std::ostream& oss) const
282 oss << "Profiles :\n";
283 std::size_t n=_pfls.size();
284 for(std::size_t i=0;i<n;i++)
286 oss << " - #" << i << " ";
287 const DataArrayIdType *pfl=_pfls[i];
289 oss << "\"" << pfl->getName() << "\"\n";
294 oss << "Localizations :\n";
295 for(std::size_t i=0;i<n;i++)
297 oss << " - #" << i << " ";
298 const MEDFileFieldLoc *loc=_locs[i];
300 loc->simpleRepr(oss);
306 void MEDFileFieldGlobs::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
308 for(std::vector< MCAuto<DataArrayIdType> >::iterator it=_pfls.begin();it!=_pfls.end();it++)
310 DataArrayIdType *elt(*it);
313 std::string name(elt->getName());
314 for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
316 if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
318 elt->setName((*it2).second.c_str());
326 void MEDFileFieldGlobs::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
328 for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
330 MEDFileFieldLoc *elt(*it);
333 std::string name(elt->getName());
334 for(std::vector< std::pair<std::vector<std::string>, std::string > >::const_iterator it2=mapOfModif.begin();it2!=mapOfModif.end();it2++)
336 if(std::find((*it2).first.begin(),(*it2).first.end(),name)!=(*it2).first.end())
338 elt->setName((*it2).second.c_str());
346 int MEDFileFieldGlobs::getNbOfGaussPtPerCell(int locId) const
348 if(locId<0 || locId>=(int)_locs.size())
349 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getNbOfGaussPtPerCell : Invalid localization id !");
350 return _locs[locId]->getNbOfGaussPtPerCell();
353 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName) const
355 return getLocalizationFromId(getLocalizationId(locName));
358 const MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId) const
360 if(locId<0 || locId>=(int)_locs.size())
361 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
362 return *_locs[locId];
366 namespace MEDCouplingImpl
371 LocFinder(const std::string& loc):_loc(loc) { }
372 bool operator() (const MCAuto<MEDFileFieldLoc>& loc) { return loc->isName(_loc); }
374 const std::string &_loc;
380 PflFinder(const std::string& pfl):_pfl(pfl) { }
381 bool operator() (const MCAuto<DataArrayIdType>& loc) { return loc->getName()==_pfl; }
383 const std::string _pfl;
388 int MEDFileFieldGlobs::getLocalizationId(const std::string& loc) const
390 std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=std::find_if(_locs.begin(),_locs.end(),MEDCouplingImpl::LocFinder(loc));
393 std::ostringstream oss; oss << "MEDFileFieldGlobs::getLocalisationId : no such localisation name : \"" << loc << "\" Possible localizations are : ";
394 for(it=_locs.begin();it!=_locs.end();it++)
395 oss << "\"" << (*it)->getName() << "\", ";
396 throw INTERP_KERNEL::Exception(oss.str());
398 return (int)std::distance(_locs.begin(),it);
401 int MEDFileFieldGlobs::getProfileId(const std::string& pfl) const
403 std::vector< MCAuto<DataArrayIdType> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pfl));
406 std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfileId : no such profile name : \"" << pfl << "\" Possible localizations are : ";
407 for(it=_pfls.begin();it!=_pfls.end();it++)
408 oss << "\"" << (*it)->getName() << "\", ";
409 throw INTERP_KERNEL::Exception(oss.str());
411 return (int)std::distance(_pfls.begin(),it);
415 * The returned value is never null.
417 const DataArrayIdType *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
419 return getProfileFromId(getProfileId(pflName));
422 const DataArrayIdType *MEDFileFieldGlobs::getProfileFromId(int pflId) const
424 if(pflId<0 || pflId>=(int)_pfls.size())
425 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
429 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
431 if(locId<0 || locId>=(int)_locs.size())
432 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
433 return *_locs[locId];
436 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
438 return getLocalizationFromId(getLocalizationId(locName));
442 * The returned value is never null. Borrowed reference returned.
444 DataArrayIdType *MEDFileFieldGlobs::getProfile(const std::string& pflName)
446 std::string pflNameCpp(pflName);
447 std::vector< MCAuto<DataArrayIdType> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
450 std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
451 for(it=_pfls.begin();it!=_pfls.end();it++)
452 oss << "\"" << (*it)->getName() << "\", ";
453 throw INTERP_KERNEL::Exception(oss.str());
458 DataArrayIdType *MEDFileFieldGlobs::getProfileFromId(int pflId)
460 if(pflId<0 || pflId>=(int)_pfls.size())
461 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
465 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
467 std::vector< MCAuto<DataArrayIdType> > newPfls;
469 for(std::vector< MCAuto<DataArrayIdType> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
471 if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
472 newPfls.push_back(*it);
477 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
479 std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
481 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
483 if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
484 newLocs.push_back(*it);
489 void MEDFileFieldGlobs::killStructureElementsInGlobs()
491 std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
492 for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
496 if(!(*it)->isOnStructureElement())
497 newLocs.push_back(*it);
502 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
504 std::size_t sz=_pfls.size();
505 std::vector<std::string> ret(sz);
506 for(std::size_t i=0;i<sz;i++)
507 ret[i]=_pfls[i]->getName();
511 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
513 std::size_t sz=_locs.size();
514 std::vector<std::string> ret(sz);
515 for(std::size_t i=0;i<sz;i++)
516 ret[i]=_locs[i]->getName();
520 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
522 std::vector<std::string> v=getPfls();
523 std::string s(pflName);
524 return std::find(v.begin(),v.end(),s)!=v.end();
527 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
529 std::vector<std::string> v=getLocs();
530 std::string s(locName);
531 return std::find(v.begin(),v.end(),s)!=v.end();
534 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
536 std::map<mcIdType,std::vector<int> > m;
538 for(std::vector< MCAuto<DataArrayIdType> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
540 const DataArrayIdType *tmp=(*it);
543 m[tmp->getHashCode()].push_back(i);
546 std::vector< std::vector<int> > ret;
547 for(std::map<mcIdType,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
549 if((*it2).second.size()>1)
551 std::vector<int> ret0;
552 bool equalityOrNot=false;
553 for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
555 std::vector<int>::const_iterator it4=it3; it4++;
556 for(;it4!=(*it2).second.end();it4++)
558 if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
561 ret0.push_back(*it3);
562 ret0.push_back(*it4);
574 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
576 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
579 void MEDFileFieldGlobs::appendProfile(DataArrayIdType *pfl)
581 std::string name(pfl->getName());
583 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
584 for(std::vector< MCAuto<DataArrayIdType> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
585 if(name==(*it)->getName())
587 if(!pfl->isEqual(*(*it)))
589 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
590 throw INTERP_KERNEL::Exception(oss.str());
594 _pfls.push_back(pfl);
597 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)
599 std::string name(locName);
601 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
602 MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
603 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
604 if((*it)->isName(locName))
606 if(!(*it)->isEqual(*obj,1e-12))
608 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
609 throw INTERP_KERNEL::Exception(oss.str());
612 _locs.push_back(obj);
615 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
617 std::vector<std::string> names=getPfls();
618 return CreateNewNameNotIn("NewPfl_",names);
621 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
623 std::vector<std::string> names=getLocs();
624 return CreateNewNameNotIn("NewLoc_",names);
627 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
629 for(std::size_t sz=0;sz<100000;sz++)
631 std::ostringstream tryName;
632 tryName << prefix << sz;
633 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
634 return tryName.str();
636 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
640 * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
641 * \param [in] fid - the MED file handler.
643 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
648 * Creates an empty MEDFileFieldGlobsReal.
650 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
654 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
659 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
661 std::vector<const BigMemoryObject *> ret;
662 ret.push_back((const MEDFileFieldGlobs *)_globals);
667 * Returns a string describing profiles and Gauss points held in \a this.
668 * \param[out] oss - the description string (in a std::ostream).
670 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
672 const MEDFileFieldGlobs *glob=_globals;
673 std::ostringstream oss2; oss2 << glob;
674 std::string stars(oss2.str().length(),'*');
675 oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars << "\n\n";
677 glob->simpleRepr(oss);
679 oss << "NO GLOBAL INFORMATION !\n";
682 void MEDFileFieldGlobsReal::resetContent()
684 _globals=MEDFileFieldGlobs::New();
687 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
689 contentNotNull()->killStructureElementsInGlobs();
692 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
697 * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
698 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
700 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
702 _globals=other._globals;
706 * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
707 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
709 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
711 const MEDFileFieldGlobs *otherg(other._globals);
714 _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
718 * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
719 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
721 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
723 const MEDFileFieldGlobs *otherg(other._globals);
726 _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
729 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
731 _globals=other._globals;
732 if((const MEDFileFieldGlobs *)_globals)
733 _globals=other._globals->deepCopy();
737 * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
738 * \param [in] other - the MEDFileFieldGlobsReal to copy data from.
739 * \param [in] eps - a precision used to compare Gauss points with same name held by
740 * \a this and \a other MEDFileFieldGlobsReal.
741 * \throw If \a this and \a other hold profiles with equal names but different ids.
742 * \throw If \a this and \a other hold different Gauss points with equal names.
744 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
746 const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
747 if(thisGlobals==otherGlobals)
751 _globals=other._globals;
754 _globals->appendGlobs(*other._globals,eps);
757 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
759 checkGlobsPflsPartCoherency();
760 checkGlobsLocsPartCoherency();
763 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
765 contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
768 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
770 contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
773 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
775 contentNotNull()->loadProfileInFile(fid,id,pflName);
778 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
780 contentNotNull()->loadProfileInFile(fid,id);
783 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
785 contentNotNull()->loadGlobals(fid,*this);
788 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
790 contentNotNull()->loadAllGlobals(fid,entities);
793 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
795 contentNotNull()->writeGlobals(fid,opt);
799 * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
800 * or getPflsReallyUsedMulti().
801 * \return std::vector<std::string> - a sequence of names of all profiles.
803 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
805 return contentNotNull()->getPfls();
809 * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
810 * or getLocsReallyUsedMulti().
811 * \return std::vector<std::string> - a sequence of names of all localizations.
813 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
815 return contentNotNull()->getLocs();
819 * Checks if the profile with a given name exists.
820 * \param [in] pflName - the profile name of interest.
821 * \return bool - \c true if the profile named \a pflName exists.
823 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
825 return contentNotNull()->existsPfl(pflName);
829 * Checks if the localization with a given name exists.
830 * \param [in] locName - the localization name of interest.
831 * \return bool - \c true if the localization named \a locName exists.
833 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
835 return contentNotNull()->existsLoc(locName);
838 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
840 return contentNotNull()->createNewNameOfPfl();
843 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
845 return contentNotNull()->createNewNameOfLoc();
849 * Sets the name of a MED file.
850 * \param [in,out] fileName - the file name.
852 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
854 contentNotNull()->setFileName(fileName);
858 * Finds equal profiles. Two profiles are considered equal if they contain the same ids
860 * \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
861 * Each item of this sequence is a vector containing ids of equal profiles.
863 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
865 return contentNotNull()->whichAreEqualProfiles();
869 * Finds equal localizations.
870 * \param [in] eps - a precision used to compare real values of the localizations.
871 * \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
872 * Each item of this sequence is a vector containing ids of equal localizations.
874 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
876 return contentNotNull()->whichAreEqualLocs(eps);
880 * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
881 * \param [in] mapOfModif - a sequence describing required renaming. Each element of
882 * this sequence is a pair whose
883 * - the first item is a vector of profile names to replace by the second item,
884 * - the second item is a profile name to replace every profile name of the first item.
886 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
888 contentNotNull()->changePflsNamesInStruct(mapOfModif);
892 * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
893 * \param [in] mapOfModif - a sequence describing required renaming. Each element of
894 * this sequence is a pair whose
895 * - the first item is a vector of localization names to replace by the second item,
896 * - the second item is a localization name to replace every localization name of the first item.
898 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
900 contentNotNull()->changeLocsNamesInStruct(mapOfModif);
904 * Replaces references to some profiles (a reference is a profile name) by references
905 * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
906 * them-selves accordingly. <br>
907 * This method is a generalization of changePflName().
908 * \param [in] mapOfModif - a sequence describing required replacements. Each element of
909 * this sequence is a pair whose
910 * - the first item is a vector of profile names to replace by the second item,
911 * - the second item is a profile name to replace every profile of the first item.
912 * \sa changePflsRefsNamesGen()
913 * \sa changePflName()
915 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
917 changePflsRefsNamesGen(mapOfModif);
918 changePflsNamesInStruct(mapOfModif);
922 * Replaces references to some localizations (a reference is a localization name) by references
923 * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
924 * them-selves accordingly. <br>
925 * This method is a generalization of changeLocName().
926 * \param [in] mapOfModif - a sequence describing required replacements. Each element of
927 * this sequence is a pair whose
928 * - the first item is a vector of localization names to replace by the second item,
929 * - the second item is a localization name to replace every localization of the first item.
930 * \sa changeLocsRefsNamesGen()
931 * \sa changeLocName()
933 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
935 changeLocsRefsNamesGen(mapOfModif);
936 changeLocsNamesInStruct(mapOfModif);
940 * Renames the profile having a given name and updates references to this profile.
941 * \param [in] oldName - the name of the profile to rename.
942 * \param [in] newName - a new name of the profile.
943 * \sa changePflsNames().
945 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
947 std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
948 std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
950 changePflsNames(mapOfModif);
954 * Renames the localization having a given name and updates references to this localization.
955 * \param [in] oldName - the name of the localization to rename.
956 * \param [in] newName - a new name of the localization.
957 * \sa changeLocsNames().
959 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
961 std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
962 std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
964 changeLocsNames(mapOfModif);
968 * Removes duplicated profiles. Returns a map used to update references to removed
969 * profiles via changePflsRefsNamesGen().
970 * Equal profiles are found using whichAreEqualProfiles().
971 * \return std::vector< std::pair<std::vector<std::string>, std::string > > -
972 * a sequence describing the performed replacements of profiles. Each element of
973 * this sequence is a pair whose
974 * - the first item is a vector of profile names replaced by the second item,
975 * - the second item is a profile name replacing every profile of the first item.
977 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
979 std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
980 std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
982 for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
984 std::vector< std::string > tmp((*it).size());
986 for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
987 tmp[j]=std::string(getProfileFromId(*it2)->getName());
988 std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
990 std::vector<int> tmp2((*it).begin()+1,(*it).end());
991 killProfileIds(tmp2);
993 changePflsRefsNamesGen(ret);
998 * Removes duplicated localizations. Returns a map used to update references to removed
999 * localizations via changeLocsRefsNamesGen().
1000 * Equal localizations are found using whichAreEqualLocs().
1001 * \param [in] eps - a precision used to compare real values of the localizations.
1002 * \return std::vector< std::pair<std::vector<std::string>, std::string > > -
1003 * a sequence describing the performed replacements of localizations. Each element of
1004 * this sequence is a pair whose
1005 * - the first item is a vector of localization names replaced by the second item,
1006 * - the second item is a localization name replacing every localization of the first item.
1008 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
1010 std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
1011 std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
1013 for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
1015 std::vector< std::string > tmp((*it).size());
1017 for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
1018 tmp[j]=std::string(getLocalizationFromId(*it2).getName());
1019 std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
1021 std::vector<int> tmp2((*it).begin()+1,(*it).end());
1022 killLocalizationIds(tmp2);
1024 changeLocsRefsNamesGen(ret);
1029 * Returns number of Gauss points per cell in a given localization.
1030 * \param [in] locId - an id of the localization of interest.
1031 * \return int - the number of the Gauss points per cell.
1033 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
1035 return contentNotNull()->getNbOfGaussPtPerCell(locId);
1039 * Returns an id of a localization by its name.
1040 * \param [in] loc - the localization name of interest.
1041 * \return int - the id of the localization.
1042 * \throw If there is no a localization named \a loc.
1044 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
1046 return contentNotNull()->getLocalizationId(loc);
1050 * Returns an id of a profile by its name.
1051 * \param [in] pfl - the profile name of interest.
1052 * \return int - the id of the profile.
1053 * \throw If there is no a profile named \a loc.
1055 int MEDFileFieldGlobsReal::getProfileId(const std::string& pfl) const
1057 return contentNotNull()->getProfileId(pfl);
1061 * Returns the name of the MED file.
1062 * \return const std::string& - the MED file name.
1064 std::string MEDFileFieldGlobsReal::getFileName() const
1066 return contentNotNull()->getFileName();
1070 * Returns a localization object by its name.
1071 * \param [in] locName - the name of the localization of interest.
1072 * \return const MEDFileFieldLoc& - the localization object having the name \a locName.
1073 * \throw If there is no a localization named \a locName.
1075 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
1077 return contentNotNull()->getLocalization(locName);
1081 * Returns a localization object by its id.
1082 * \param [in] locId - the id of the localization of interest.
1083 * \return const MEDFileFieldLoc& - the localization object having the id \a locId.
1084 * \throw If there is no a localization with id \a locId.
1086 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
1088 return contentNotNull()->getLocalizationFromId(locId);
1092 * Returns a profile array by its name.
1093 * \param [in] pflName - the name of the profile of interest.
1094 * \return const DataArrayIdType * - the profile array having the name \a pflName.
1095 * \throw If there is no a profile named \a pflName.
1097 const DataArrayIdType *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
1099 return contentNotNull()->getProfile(pflName);
1103 * Returns a profile array by its id.
1104 * \param [in] pflId - the id of the profile of interest.
1105 * \return const DataArrayIdType * - the profile array having the id \a pflId.
1106 * \throw If there is no a profile with id \a pflId.
1108 const DataArrayIdType *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
1110 return contentNotNull()->getProfileFromId(pflId);
1114 * Returns a localization object, apt for modification, by its id.
1115 * \param [in] locId - the id of the localization of interest.
1116 * \return MEDFileFieldLoc& - a non-const reference to the localization object
1117 * having the id \a locId.
1118 * \throw If there is no a localization with id \a locId.
1120 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
1122 return contentNotNull()->getLocalizationFromId(locId);
1126 * Returns a localization object, apt for modification, by its name.
1127 * \param [in] locName - the name of the localization of interest.
1128 * \return MEDFileFieldLoc& - a non-const reference to the localization object
1129 * having the name \a locName.
1130 * \throw If there is no a localization named \a locName.
1132 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
1134 return contentNotNull()->getLocalization(locName);
1138 * Returns a profile array, apt for modification, by its name.
1139 * \param [in] pflName - the name of the profile of interest.
1140 * \return DataArrayIdType * - Borrowed reference - a non-const pointer to the profile array having the name \a pflName.
1141 * \throw If there is no a profile named \a pflName.
1143 DataArrayIdType *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
1145 return contentNotNull()->getProfile(pflName);
1149 * Returns a profile array, apt for modification, by its id.
1150 * \param [in] pflId - the id of the profile of interest.
1151 * \return DataArrayIdType * - Borrowed reference - a non-const pointer to the profile array having the id \a pflId.
1152 * \throw If there is no a profile with id \a pflId.
1154 DataArrayIdType *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
1156 return contentNotNull()->getProfileFromId(pflId);
1160 * Removes profiles given by their ids. No data is updated to track this removal.
1161 * \param [in] pflIds - a sequence of ids of the profiles to remove.
1163 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
1165 contentNotNull()->killProfileIds(pflIds);
1169 * Removes localizations given by their ids. No data is updated to track this removal.
1170 * \param [in] locIds - a sequence of ids of the localizations to remove.
1172 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
1174 contentNotNull()->killLocalizationIds(locIds);
1178 * Stores a profile array.
1179 * \param [in] pfl - the profile array to store.
1180 * \throw If the name of \a pfl is empty.
1181 * \throw If a profile with the same name as that of \a pfl already exists but contains
1184 void MEDFileFieldGlobsReal::appendProfile(DataArrayIdType *pfl)
1186 contentNotNull()->appendProfile(pfl);
1190 * Adds a new localization of Gauss points.
1191 * \param [in] locName - the name of the new localization.
1192 * \param [in] geoType - a geometrical type of the reference cell.
1193 * \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
1194 * must be \c nbOfNodesPerCell * \c dimOfType.
1195 * \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
1196 * must be _wg_.size() * \c dimOfType.
1197 * \param [in] w - the weights of Gauss points.
1198 * \throw If \a locName is empty.
1199 * \throw If a localization with the name \a locName already exists but is
1200 * different form the new one.
1202 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)
1204 contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
1207 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
1209 MEDFileFieldGlobs *g(_globals);
1211 throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
1215 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
1217 const MEDFileFieldGlobs *g(_globals);
1219 throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
1223 //= MEDFileFieldNameScope
1225 MEDFileFieldNameScope::MEDFileFieldNameScope()
1229 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
1234 * Returns the name of \a this field.
1235 * \return std::string - a string containing the field name.
1237 std::string MEDFileFieldNameScope::getName() const
1243 * Sets name of \a this field
1244 * \param [in] fieldName - the new field name.
1246 void MEDFileFieldNameScope::setName(const std::string& fieldName)
1251 std::string MEDFileFieldNameScope::getDtUnit() const
1256 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
1261 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
1264 _mesh_name=other._mesh_name;
1265 _dt_unit=other._dt_unit;
1269 * Returns the mesh name.
1270 * \return std::string - a string holding the mesh name.
1271 * \throw If \c _field_per_mesh.empty()
1273 std::string MEDFileFieldNameScope::getMeshName() const
1278 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
1280 _mesh_name=meshName;