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>& pfl) { return _pfl==pfl->getName(); }
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);
399 * The returned value is never null.
401 const DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName) const
403 std::string pflNameCpp(pflName);
404 std::vector< MCAuto<DataArrayInt> >::const_iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
407 std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
408 for(it=_pfls.begin();it!=_pfls.end();it++)
409 oss << "\"" << (*it)->getName() << "\", ";
410 throw INTERP_KERNEL::Exception(oss.str());
415 const DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId) const
417 if(pflId<0 || pflId>=(int)_pfls.size())
418 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
422 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalizationFromId(int locId)
424 if(locId<0 || locId>=(int)_locs.size())
425 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getLocalizationFromId : Invalid localization id !");
426 return *_locs[locId];
429 MEDFileFieldLoc& MEDFileFieldGlobs::getLocalization(const std::string& locName)
431 return getLocalizationFromId(getLocalizationId(locName));
435 * The returned value is never null.
437 DataArrayInt *MEDFileFieldGlobs::getProfile(const std::string& pflName)
439 std::string pflNameCpp(pflName);
440 std::vector< MCAuto<DataArrayInt> >::iterator it=std::find_if(_pfls.begin(),_pfls.end(),MEDCouplingImpl::PflFinder(pflNameCpp));
443 std::ostringstream oss; oss << "MEDFileFieldGlobs::getProfile: no such profile name : \"" << pflNameCpp << "\" Possible profiles are : ";
444 for(it=_pfls.begin();it!=_pfls.end();it++)
445 oss << "\"" << (*it)->getName() << "\", ";
446 throw INTERP_KERNEL::Exception(oss.str());
451 DataArrayInt *MEDFileFieldGlobs::getProfileFromId(int pflId)
453 if(pflId<0 || pflId>=(int)_pfls.size())
454 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::getProfileFromId : Invalid profile id !");
458 void MEDFileFieldGlobs::killProfileIds(const std::vector<int>& pflIds)
460 std::vector< MCAuto<DataArrayInt> > newPfls;
462 for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
464 if(std::find(pflIds.begin(),pflIds.end(),i)==pflIds.end())
465 newPfls.push_back(*it);
470 void MEDFileFieldGlobs::killLocalizationIds(const std::vector<int>& locIds)
472 std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
474 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++,i++)
476 if(std::find(locIds.begin(),locIds.end(),i)==locIds.end())
477 newLocs.push_back(*it);
482 void MEDFileFieldGlobs::killStructureElementsInGlobs()
484 std::vector< MCAuto<MEDFileFieldLoc> > newLocs;
485 for(std::vector< MCAuto<MEDFileFieldLoc> >::iterator it=_locs.begin();it!=_locs.end();it++)
489 if(!(*it)->isOnStructureElement())
490 newLocs.push_back(*it);
495 std::vector<std::string> MEDFileFieldGlobs::getPfls() const
498 std::vector<std::string> ret(sz);
499 for(int i=0;i<sz;i++)
500 ret[i]=_pfls[i]->getName();
504 std::vector<std::string> MEDFileFieldGlobs::getLocs() const
507 std::vector<std::string> ret(sz);
508 for(int i=0;i<sz;i++)
509 ret[i]=_locs[i]->getName();
513 bool MEDFileFieldGlobs::existsPfl(const std::string& pflName) const
515 std::vector<std::string> v=getPfls();
516 std::string s(pflName);
517 return std::find(v.begin(),v.end(),s)!=v.end();
520 bool MEDFileFieldGlobs::existsLoc(const std::string& locName) const
522 std::vector<std::string> v=getLocs();
523 std::string s(locName);
524 return std::find(v.begin(),v.end(),s)!=v.end();
527 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualProfiles() const
529 std::map<int,std::vector<int> > m;
531 for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++,i++)
533 const DataArrayInt *tmp=(*it);
536 m[tmp->getHashCode()].push_back(i);
539 std::vector< std::vector<int> > ret;
540 for(std::map<int,std::vector<int> >::const_iterator it2=m.begin();it2!=m.end();it2++)
542 if((*it2).second.size()>1)
544 std::vector<int> ret0;
545 bool equalityOrNot=false;
546 for(std::vector<int>::const_iterator it3=(*it2).second.begin();it3!=(*it2).second.end();it3++)
548 std::vector<int>::const_iterator it4=it3; it4++;
549 for(;it4!=(*it2).second.end();it4++)
551 if(_pfls[*it3]->isEqualWithoutConsideringStr(*_pfls[*it4]))
554 ret0.push_back(*it3);
555 ret0.push_back(*it4);
567 std::vector< std::vector<int> > MEDFileFieldGlobs::whichAreEqualLocs(double eps) const
569 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::whichAreEqualLocs : no implemented yet ! Sorry !");
572 void MEDFileFieldGlobs::appendProfile(DataArrayInt *pfl)
574 std::string name(pfl->getName());
576 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendProfile : unsupported profiles with no name !");
577 for(std::vector< MCAuto<DataArrayInt> >::const_iterator it=_pfls.begin();it!=_pfls.end();it++)
578 if(name==(*it)->getName())
580 if(!pfl->isEqual(*(*it)))
582 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendProfile : profile \"" << name << "\" already exists and is different from existing !";
583 throw INTERP_KERNEL::Exception(oss.str());
587 _pfls.push_back(pfl);
590 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)
592 std::string name(locName);
594 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::appendLoc : unsupported localizations with no name !");
595 MCAuto<MEDFileFieldLoc> obj=MEDFileFieldLoc::New(locName,geoType,refCoo,gsCoo,w);
596 for(std::vector< MCAuto<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
597 if((*it)->isName(locName))
599 if(!(*it)->isEqual(*obj,1e-12))
601 std::ostringstream oss; oss << "MEDFileFieldGlobs::appendLoc : localization \"" << name << "\" already exists and is different from existing !";
602 throw INTERP_KERNEL::Exception(oss.str());
605 _locs.push_back(obj);
608 std::string MEDFileFieldGlobs::createNewNameOfPfl() const
610 std::vector<std::string> names=getPfls();
611 return CreateNewNameNotIn("NewPfl_",names);
614 std::string MEDFileFieldGlobs::createNewNameOfLoc() const
616 std::vector<std::string> names=getLocs();
617 return CreateNewNameNotIn("NewLoc_",names);
620 std::string MEDFileFieldGlobs::CreateNewNameNotIn(const std::string& prefix, const std::vector<std::string>& namesToAvoid)
622 for(std::size_t sz=0;sz<100000;sz++)
624 std::ostringstream tryName;
625 tryName << prefix << sz;
626 if(std::find(namesToAvoid.begin(),namesToAvoid.end(),tryName.str())==namesToAvoid.end())
627 return tryName.str();
629 throw INTERP_KERNEL::Exception("MEDFileFieldGlobs::CreateNewNameNotIn : impossible to create an additional profile limit of 100000 profiles reached !");
633 * Creates a MEDFileFieldGlobsReal on a given file name. Nothing is read here.
634 * \param [in] fname - the file name.
636 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal(med_idt fid):_globals(MEDFileFieldGlobs::New(fid))
641 * Creates an empty MEDFileFieldGlobsReal.
643 MEDFileFieldGlobsReal::MEDFileFieldGlobsReal():_globals(MEDFileFieldGlobs::New())
647 std::size_t MEDFileFieldGlobsReal::getHeapMemorySizeWithoutChildren() const
652 std::vector<const BigMemoryObject *> MEDFileFieldGlobsReal::getDirectChildrenWithNull() const
654 std::vector<const BigMemoryObject *> ret;
655 ret.push_back((const MEDFileFieldGlobs *)_globals);
660 * Returns a string describing profiles and Gauss points held in \a this.
661 * \return std::string - the description string.
663 void MEDFileFieldGlobsReal::simpleReprGlobs(std::ostream& oss) const
665 const MEDFileFieldGlobs *glob=_globals;
666 std::ostringstream oss2; oss2 << glob;
667 std::string stars(oss2.str().length(),'*');
668 oss << "Globals information on fields (at " << oss2.str() << "):" << "\n************************************" << stars << "\n\n";
670 glob->simpleRepr(oss);
672 oss << "NO GLOBAL INFORMATION !\n";
675 void MEDFileFieldGlobsReal::resetContent()
677 _globals=MEDFileFieldGlobs::New();
680 void MEDFileFieldGlobsReal::killStructureElementsInGlobs()
682 contentNotNull()->killStructureElementsInGlobs();
685 MEDFileFieldGlobsReal::~MEDFileFieldGlobsReal()
690 * Copies references to profiles and Gauss points from another MEDFileFieldGlobsReal.
691 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
693 void MEDFileFieldGlobsReal::shallowCpyGlobs(const MEDFileFieldGlobsReal& other)
695 _globals=other._globals;
699 * Copies references to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
700 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
702 void MEDFileFieldGlobsReal::shallowCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
704 const MEDFileFieldGlobs *otherg(other._globals);
707 _globals=otherg->shallowCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
711 * Copies deeply to ** only used ** by \a this, profiles and Gauss points from another MEDFileFieldGlobsReal.
712 * \param [in] other - the other MEDFileFieldGlobsReal to copy data from.
714 void MEDFileFieldGlobsReal::deepCpyOnlyUsedGlobs(const MEDFileFieldGlobsReal& other)
716 const MEDFileFieldGlobs *otherg(other._globals);
719 _globals=otherg->deepCpyPart(getPflsReallyUsed(),getLocsReallyUsed());
722 void MEDFileFieldGlobsReal::deepCpyGlobs(const MEDFileFieldGlobsReal& other)
724 _globals=other._globals;
725 if((const MEDFileFieldGlobs *)_globals)
726 _globals=other._globals->deepCopy();
730 * Adds profiles and Gauss points held by another MEDFileFieldGlobsReal to \a this one.
731 * \param [in] other - the MEDFileFieldGlobsReal to copy data from.
732 * \param [in] eps - a precision used to compare Gauss points with same name held by
733 * \a this and \a other MEDFileFieldGlobsReal.
734 * \throw If \a this and \a other hold profiles with equal names but different ids.
735 * \throw If \a this and \a other hold different Gauss points with equal names.
737 void MEDFileFieldGlobsReal::appendGlobs(const MEDFileFieldGlobsReal& other, double eps)
739 const MEDFileFieldGlobs *thisGlobals(_globals),*otherGlobals(other._globals);
740 if(thisGlobals==otherGlobals)
744 _globals=other._globals;
747 _globals->appendGlobs(*other._globals,eps);
750 void MEDFileFieldGlobsReal::checkGlobsCoherency() const
752 checkGlobsPflsPartCoherency();
753 checkGlobsLocsPartCoherency();
756 void MEDFileFieldGlobsReal::checkGlobsPflsPartCoherency() const
758 contentNotNull()->checkGlobsPflsPartCoherency(getPflsReallyUsed());
761 void MEDFileFieldGlobsReal::checkGlobsLocsPartCoherency() const
763 contentNotNull()->checkGlobsLocsPartCoherency(getLocsReallyUsed());
766 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const std::string& pflName)
768 contentNotNull()->loadProfileInFile(fid,id,pflName);
771 void MEDFileFieldGlobsReal::loadProfileInFile(med_idt fid, int id)
773 contentNotNull()->loadProfileInFile(fid,id);
776 void MEDFileFieldGlobsReal::loadGlobals(med_idt fid)
778 contentNotNull()->loadGlobals(fid,*this);
781 void MEDFileFieldGlobsReal::loadAllGlobals(med_idt fid, const MEDFileEntities *entities)
783 contentNotNull()->loadAllGlobals(fid,entities);
786 void MEDFileFieldGlobsReal::writeGlobals(med_idt fid, const MEDFileWritable& opt) const
788 contentNotNull()->writeGlobals(fid,opt);
792 * Returns names of all profiles. To get only used profiles call getPflsReallyUsed()
793 * or getPflsReallyUsedMulti().
794 * \return std::vector<std::string> - a sequence of names of all profiles.
796 std::vector<std::string> MEDFileFieldGlobsReal::getPfls() const
798 return contentNotNull()->getPfls();
802 * Returns names of all localizations. To get only used localizations call getLocsReallyUsed()
803 * or getLocsReallyUsedMulti().
804 * \return std::vector<std::string> - a sequence of names of all localizations.
806 std::vector<std::string> MEDFileFieldGlobsReal::getLocs() const
808 return contentNotNull()->getLocs();
812 * Checks if the profile with a given name exists.
813 * \param [in] pflName - the profile name of interest.
814 * \return bool - \c true if the profile named \a pflName exists.
816 bool MEDFileFieldGlobsReal::existsPfl(const std::string& pflName) const
818 return contentNotNull()->existsPfl(pflName);
822 * Checks if the localization with a given name exists.
823 * \param [in] locName - the localization name of interest.
824 * \return bool - \c true if the localization named \a locName exists.
826 bool MEDFileFieldGlobsReal::existsLoc(const std::string& locName) const
828 return contentNotNull()->existsLoc(locName);
831 std::string MEDFileFieldGlobsReal::createNewNameOfPfl() const
833 return contentNotNull()->createNewNameOfPfl();
836 std::string MEDFileFieldGlobsReal::createNewNameOfLoc() const
838 return contentNotNull()->createNewNameOfLoc();
842 * Sets the name of a MED file.
843 * \param [inout] fileName - the file name.
845 void MEDFileFieldGlobsReal::setFileName(const std::string& fileName)
847 contentNotNull()->setFileName(fileName);
851 * Finds equal profiles. Two profiles are considered equal if they contain the same ids
853 * \return std::vector< std::vector<int> > - a sequence of groups of equal profiles.
854 * Each item of this sequence is a vector containing ids of equal profiles.
856 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualProfiles() const
858 return contentNotNull()->whichAreEqualProfiles();
862 * Finds equal localizations.
863 * \param [in] eps - a precision used to compare real values of the localizations.
864 * \return std::vector< std::vector<int> > - a sequence of groups of equal localizations.
865 * Each item of this sequence is a vector containing ids of equal localizations.
867 std::vector< std::vector<int> > MEDFileFieldGlobsReal::whichAreEqualLocs(double eps) const
869 return contentNotNull()->whichAreEqualLocs(eps);
873 * Renames the profiles. References to profiles (a reference is a profile name) are not changed.
874 * \param [in] mapOfModif - a sequence describing required renaming. Each element of
875 * this sequence is a pair whose
876 * - the first item is a vector of profile names to replace by the second item,
877 * - the second item is a profile name to replace every profile name of the first item.
879 void MEDFileFieldGlobsReal::changePflsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
881 contentNotNull()->changePflsNamesInStruct(mapOfModif);
885 * Renames the localizations. References to localizations (a reference is a localization name) are not changed.
886 * \param [in] mapOfModif - a sequence describing required renaming. Each element of
887 * this sequence is a pair whose
888 * - the first item is a vector of localization names to replace by the second item,
889 * - the second item is a localization name to replace every localization name of the first item.
891 void MEDFileFieldGlobsReal::changeLocsNamesInStruct(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
893 contentNotNull()->changeLocsNamesInStruct(mapOfModif);
897 * Replaces references to some profiles (a reference is a profile name) by references
898 * to other profiles and, contrary to changePflsRefsNamesGen(), renames the profiles
899 * them-selves accordingly. <br>
900 * This method is a generalization of changePflName().
901 * \param [in] mapOfModif - a sequence describing required replacements. Each element of
902 * this sequence is a pair whose
903 * - the first item is a vector of profile names to replace by the second item,
904 * - the second item is a profile name to replace every profile of the first item.
905 * \sa changePflsRefsNamesGen()
906 * \sa changePflName()
908 void MEDFileFieldGlobsReal::changePflsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
910 changePflsRefsNamesGen(mapOfModif);
911 changePflsNamesInStruct(mapOfModif);
915 * Replaces references to some localizations (a reference is a localization name) by references
916 * to other localizations and, contrary to changeLocsRefsNamesGen(), renames the localizations
917 * them-selves accordingly. <br>
918 * This method is a generalization of changeLocName().
919 * \param [in] mapOfModif - a sequence describing required replacements. Each element of
920 * this sequence is a pair whose
921 * - the first item is a vector of localization names to replace by the second item,
922 * - the second item is a localization name to replace every localization of the first item.
923 * \sa changeLocsRefsNamesGen()
924 * \sa changeLocName()
926 void MEDFileFieldGlobsReal::changeLocsNames(const std::vector< std::pair<std::vector<std::string>, std::string > >& mapOfModif)
928 changeLocsRefsNamesGen(mapOfModif);
929 changeLocsNamesInStruct(mapOfModif);
933 * Renames the profile having a given name and updates references to this profile.
934 * \param [in] oldName - the name of the profile to rename.
935 * \param [in] newName - a new name of the profile.
936 * \sa changePflsNames().
938 void MEDFileFieldGlobsReal::changePflName(const std::string& oldName, const std::string& newName)
940 std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
941 std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
943 changePflsNames(mapOfModif);
947 * Renames the localization having a given name and updates references to this localization.
948 * \param [in] oldName - the name of the localization to rename.
949 * \param [in] newName - a new name of the localization.
950 * \sa changeLocsNames().
952 void MEDFileFieldGlobsReal::changeLocName(const std::string& oldName, const std::string& newName)
954 std::vector< std::pair<std::vector<std::string>, std::string > > mapOfModif(1);
955 std::pair<std::vector<std::string>, std::string > p(std::vector<std::string>(1,std::string(oldName)),std::string(newName));
957 changeLocsNames(mapOfModif);
961 * Removes duplicated profiles. Returns a map used to update references to removed
962 * profiles via changePflsRefsNamesGen().
963 * Equal profiles are found using whichAreEqualProfiles().
964 * \return std::vector< std::pair<std::vector<std::string>, std::string > > -
965 * a sequence describing the performed replacements of profiles. Each element of
966 * this sequence is a pair whose
967 * - the first item is a vector of profile names replaced by the second item,
968 * - the second item is a profile name replacing every profile of the first item.
970 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipPflsNames()
972 std::vector< std::vector<int> > pseudoRet=whichAreEqualProfiles();
973 std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
975 for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
977 std::vector< std::string > tmp((*it).size());
979 for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
980 tmp[j]=std::string(getProfileFromId(*it2)->getName());
981 std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
983 std::vector<int> tmp2((*it).begin()+1,(*it).end());
984 killProfileIds(tmp2);
986 changePflsRefsNamesGen(ret);
991 * Removes duplicated localizations. Returns a map used to update references to removed
992 * localizations via changeLocsRefsNamesGen().
993 * Equal localizations are found using whichAreEqualLocs().
994 * \param [in] eps - a precision used to compare real values of the localizations.
995 * \return std::vector< std::pair<std::vector<std::string>, std::string > > -
996 * a sequence describing the performed replacements of localizations. Each element of
997 * this sequence is a pair whose
998 * - the first item is a vector of localization names replaced by the second item,
999 * - the second item is a localization name replacing every localization of the first item.
1001 std::vector< std::pair<std::vector<std::string>, std::string > > MEDFileFieldGlobsReal::zipLocsNames(double eps)
1003 std::vector< std::vector<int> > pseudoRet=whichAreEqualLocs(eps);
1004 std::vector< std::pair<std::vector<std::string>, std::string > > ret(pseudoRet.size());
1006 for(std::vector< std::vector<int> >::const_iterator it=pseudoRet.begin();it!=pseudoRet.end();it++,i++)
1008 std::vector< std::string > tmp((*it).size());
1010 for(std::vector<int>::const_iterator it2=(*it).begin();it2!=(*it).end();it2++,j++)
1011 tmp[j]=std::string(getLocalizationFromId(*it2).getName());
1012 std::pair<std::vector<std::string>, std::string > p(tmp,tmp.front());
1014 std::vector<int> tmp2((*it).begin()+1,(*it).end());
1015 killLocalizationIds(tmp2);
1017 changeLocsRefsNamesGen(ret);
1022 * Returns number of Gauss points per cell in a given localization.
1023 * \param [in] locId - an id of the localization of interest.
1024 * \return int - the number of the Gauss points per cell.
1026 int MEDFileFieldGlobsReal::getNbOfGaussPtPerCell(int locId) const
1028 return contentNotNull()->getNbOfGaussPtPerCell(locId);
1032 * Returns an id of a localization by its name.
1033 * \param [in] loc - the localization name of interest.
1034 * \return int - the id of the localization.
1035 * \throw If there is no a localization named \a loc.
1037 int MEDFileFieldGlobsReal::getLocalizationId(const std::string& loc) const
1039 return contentNotNull()->getLocalizationId(loc);
1043 * Returns the name of the MED file.
1044 * \return const std::string& - the MED file name.
1046 std::string MEDFileFieldGlobsReal::getFileName() const
1048 return contentNotNull()->getFileName();
1052 * Returns a localization object by its name.
1053 * \param [in] locName - the name of the localization of interest.
1054 * \return const MEDFileFieldLoc& - the localization object having the name \a locName.
1055 * \throw If there is no a localization named \a locName.
1057 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName) const
1059 return contentNotNull()->getLocalization(locName);
1063 * Returns a localization object by its id.
1064 * \param [in] locId - the id of the localization of interest.
1065 * \return const MEDFileFieldLoc& - the localization object having the id \a locId.
1066 * \throw If there is no a localization with id \a locId.
1068 const MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId) const
1070 return contentNotNull()->getLocalizationFromId(locId);
1074 * Returns a profile array by its name.
1075 * \param [in] pflName - the name of the profile of interest.
1076 * \return const DataArrayInt * - the profile array having the name \a pflName.
1077 * \throw If there is no a profile named \a pflName.
1079 const DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName) const
1081 return contentNotNull()->getProfile(pflName);
1085 * Returns a profile array by its id.
1086 * \param [in] pflId - the id of the profile of interest.
1087 * \return const DataArrayInt * - the profile array having the id \a pflId.
1088 * \throw If there is no a profile with id \a pflId.
1090 const DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId) const
1092 return contentNotNull()->getProfileFromId(pflId);
1096 * Returns a localization object, apt for modification, by its id.
1097 * \param [in] locId - the id of the localization of interest.
1098 * \return MEDFileFieldLoc& - a non-const reference to the localization object
1099 * having the id \a locId.
1100 * \throw If there is no a localization with id \a locId.
1102 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalizationFromId(int locId)
1104 return contentNotNull()->getLocalizationFromId(locId);
1108 * Returns a localization object, apt for modification, by its name.
1109 * \param [in] locName - the name of the localization of interest.
1110 * \return MEDFileFieldLoc& - a non-const reference to the localization object
1111 * having the name \a locName.
1112 * \throw If there is no a localization named \a locName.
1114 MEDFileFieldLoc& MEDFileFieldGlobsReal::getLocalization(const std::string& locName)
1116 return contentNotNull()->getLocalization(locName);
1120 * Returns a profile array, apt for modification, by its name.
1121 * \param [in] pflName - the name of the profile of interest.
1122 * \return DataArrayInt * - a non-const pointer to the profile array having the name \a pflName.
1123 * \throw If there is no a profile named \a pflName.
1125 DataArrayInt *MEDFileFieldGlobsReal::getProfile(const std::string& pflName)
1127 return contentNotNull()->getProfile(pflName);
1131 * Returns a profile array, apt for modification, by its id.
1132 * \param [in] pflId - the id of the profile of interest.
1133 * \return DataArrayInt * - a non-const pointer to the profile array having the id \a pflId.
1134 * \throw If there is no a profile with id \a pflId.
1136 DataArrayInt *MEDFileFieldGlobsReal::getProfileFromId(int pflId)
1138 return contentNotNull()->getProfileFromId(pflId);
1142 * Removes profiles given by their ids. No data is updated to track this removal.
1143 * \param [in] pflIds - a sequence of ids of the profiles to remove.
1145 void MEDFileFieldGlobsReal::killProfileIds(const std::vector<int>& pflIds)
1147 contentNotNull()->killProfileIds(pflIds);
1151 * Removes localizations given by their ids. No data is updated to track this removal.
1152 * \param [in] locIds - a sequence of ids of the localizations to remove.
1154 void MEDFileFieldGlobsReal::killLocalizationIds(const std::vector<int>& locIds)
1156 contentNotNull()->killLocalizationIds(locIds);
1160 * Stores a profile array.
1161 * \param [in] pfl - the profile array to store.
1162 * \throw If the name of \a pfl is empty.
1163 * \throw If a profile with the same name as that of \a pfl already exists but contains
1166 void MEDFileFieldGlobsReal::appendProfile(DataArrayInt *pfl)
1168 contentNotNull()->appendProfile(pfl);
1172 * Adds a new localization of Gauss points.
1173 * \param [in] locName - the name of the new localization.
1174 * \param [in] geoType - a geometrical type of the reference cell.
1175 * \param [in] refCoo - coordinates of points of the reference cell. Size of this vector
1176 * must be \c nbOfNodesPerCell * \c dimOfType.
1177 * \param [in] gsCoo - coordinates of Gauss points on the reference cell. Size of this vector
1178 * must be _wg_.size() * \c dimOfType.
1179 * \param [in] w - the weights of Gauss points.
1180 * \throw If \a locName is empty.
1181 * \throw If a localization with the name \a locName already exists but is
1182 * different form the new one.
1184 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)
1186 contentNotNull()->appendLoc(locName,geoType,refCoo,gsCoo,w);
1189 MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull()
1191 MEDFileFieldGlobs *g(_globals);
1193 throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in not const !");
1197 const MEDFileFieldGlobs *MEDFileFieldGlobsReal::contentNotNull() const
1199 const MEDFileFieldGlobs *g(_globals);
1201 throw INTERP_KERNEL::Exception("MEDFileFieldGlobsReal::contentNotNull : no content in const !");
1205 //= MEDFileFieldNameScope
1207 MEDFileFieldNameScope::MEDFileFieldNameScope()
1211 MEDFileFieldNameScope::MEDFileFieldNameScope(const std::string& fieldName, const std::string& meshName):_name(fieldName),_mesh_name(meshName)
1216 * Returns the name of \a this field.
1217 * \return std::string - a string containing the field name.
1219 std::string MEDFileFieldNameScope::getName() const
1225 * Sets name of \a this field
1226 * \param [in] name - the new field name.
1228 void MEDFileFieldNameScope::setName(const std::string& fieldName)
1233 std::string MEDFileFieldNameScope::getDtUnit() const
1238 void MEDFileFieldNameScope::setDtUnit(const std::string& dtUnit)
1243 void MEDFileFieldNameScope::copyNameScope(const MEDFileFieldNameScope& other)
1246 _mesh_name=other._mesh_name;
1247 _dt_unit=other._dt_unit;
1251 * Returns the mesh name.
1252 * \return std::string - a string holding the mesh name.
1253 * \throw If \c _field_per_mesh.empty()
1255 std::string MEDFileFieldNameScope::getMeshName() const
1260 void MEDFileFieldNameScope::setMeshName(const std::string& meshName)
1262 _mesh_name=meshName;