From: ageay Date: Wed, 24 Aug 2011 08:17:37 +0000 (+0000) Subject: Bug correction on globals in MEDFileFields. X-Git-Tag: V6_main_FINAL~981 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=727018251131ef99d76000a7736f9d067fd3ffc3;p=tools%2Fmedcoupling.git Bug correction on globals in MEDFileFields. --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 44ddac1e2..c3cdfb3ff 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -29,6 +29,7 @@ #include "CellModel.hxx" #include +#include extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO]; extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO]; @@ -1302,6 +1303,46 @@ void MEDFieldFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) c _locs[i]->writeLL(fid); } +void MEDFieldFieldGlobs::appendGlobs(const MEDFieldFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception) +{ + std::vector pfls=getPfls(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++) + { + std::vector::iterator it2=std::find(pfls.begin(),pfls.end(),(*it)->getName()); + if(it2==pfls.end()) + { + _pfls.push_back(*it); + } + else + { + int id=std::distance(pfls.begin(),it2); + if(!(*it)->isEqual(*_pfls[id])) + { + std::ostringstream oss; oss << "MEDFieldFieldGlobs::appendGlobs : Profile \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + std::vector locs=getLocs(); + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_locs.begin();it!=_locs.end();it++) + { + std::vector::iterator it2=std::find(locs.begin(),locs.end(),(*it)->getName()); + if(it2==locs.end()) + { + _locs.push_back(*it); + } + else + { + int id=std::distance(locs.begin(),it2); + if(!(*it)->isEqual(*_locs[id],eps)) + { + std::ostringstream oss; oss << "MEDFieldFieldGlobs::appendGlobs : Localization \"" << (*it)->getName() << "\" already exists and is different from those expecting to be append !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } +} + void MEDFieldFieldGlobs::loadGlobals(med_idt fid, const MEDFieldFieldGlobsReal& real) throw(INTERP_KERNEL::Exception) { std::vector profiles=real.getPflsReallyUsed(); @@ -1472,6 +1513,11 @@ void MEDFieldFieldGlobsReal::shallowCpyGlobs(const MEDFieldFieldGlobsReal& other _globals=other._globals; } +void MEDFieldFieldGlobsReal::appendGlobs(const MEDFieldFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception) +{ + _globals->appendGlobs(*other._globals,eps); +} + void MEDFieldFieldGlobsReal::loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception) { _globals->loadProfileInFile(fid,id,pflName); @@ -2596,6 +2642,7 @@ void MEDFileFields::write(const char *fileName, int mode) const throw(INTERP_KER int i=0; med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode); MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod); + writeGlobals(fid,*this); for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++) { const MEDFileFieldMultiTSWithoutDAS *elt=*it; @@ -2664,6 +2711,7 @@ void MEDFileFields::setFieldAtPos(int i, MEDFileFieldMultiTS *field) throw(INTER _fields.resize(i+1); field->incrRef(); _fields[i]=field; + appendGlobs(*field,1e-12); } void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception) diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index b65b02a95..d48bbeb0f 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -218,6 +218,7 @@ namespace ParaMEDMEM public: static MEDFieldFieldGlobs *New(const char *fname); static MEDFieldFieldGlobs *New(); + void appendGlobs(const MEDFieldFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception); void loadProfileInFile(med_idt fid, int id, const char *pflName) throw(INTERP_KERNEL::Exception); void loadProfileInFile(med_idt fid, int id); void loadGlobals(med_idt fid, const MEDFieldFieldGlobsReal& real) throw(INTERP_KERNEL::Exception); @@ -250,6 +251,7 @@ namespace ParaMEDMEM MEDFieldFieldGlobsReal(const char *fname); MEDFieldFieldGlobsReal(); void shallowCpyGlobs(const MEDFieldFieldGlobsReal& other); + void appendGlobs(const MEDFieldFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception); virtual std::vector getPflsReallyUsed() const = 0; virtual std::vector getLocsReallyUsed() const = 0; // diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 4a45dafc1..e69815b4d 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -792,6 +792,33 @@ class MEDLoaderTest(unittest.TestCase): f1bis=ff2.getFieldAtTopLevel(ON_CELLS) self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12)) pass + + # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos + def testMEDField17(self): + fname="Pyfile39.med" + m1=MEDLoaderDataForTest.build2DMesh_1() + m1.renumberCells([0,1,4,2,3,5],False) + mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName()) + mm1.write(fname,2) + ffs=MEDFileFields.New() + ff1=MEDFileFieldMultiTS.New() + f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2") + d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]") + f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that. + da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2") + # + ff1.appendFieldProfile(f1,mm1,0,da) + f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ; + ff1.appendFieldProfile(f1,mm1,0,da) + ffs.resize(1) + ffs.setFieldAtPos(0,ff1) + ffs.write(fname,0) + # + ffsr=MEDFileFields.New(fname) + ff3=ffsr.getFieldAtPos(0) + f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2) + self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12)) + pass pass unittest.main()