#include "CellModel.hxx"
#include <algorithm>
+#include <iterator>
extern med_geometry_type typmai[MED_N_CELL_FIXED_GEO];
extern INTERP_KERNEL::NormalizedCellType typmai2[MED_N_CELL_FIXED_GEO];
_locs[i]->writeLL(fid);
}
+void MEDFieldFieldGlobs::appendGlobs(const MEDFieldFieldGlobs& other, double eps) throw(INTERP_KERNEL::Exception)
+{
+ std::vector<std::string> pfls=getPfls();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> >::const_iterator it=other._pfls.begin();it!=other._pfls.end();it++)
+ {
+ std::vector<std::string>::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<std::string> locs=getLocs();
+ for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldLoc> >::const_iterator it=_locs.begin();it!=_locs.end();it++)
+ {
+ std::vector<std::string>::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<std::string> profiles=real.getPflsReallyUsed();
_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);
int i=0;
med_access_mode medmod=MEDFileUtilities::TraduceWriteMode(mode);
MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,medmod);
+ writeGlobals(fid,*this);
for(std::vector< MEDCouplingAutoRefCountObjectPtr<MEDFileFieldMultiTSWithoutDAS> >::const_iterator it=_fields.begin();it!=_fields.end();it++,i++)
{
const MEDFileFieldMultiTSWithoutDAS *elt=*it;
_fields.resize(i+1);
field->incrRef();
_fields[i]=field;
+ appendGlobs(*field,1e-12);
}
void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception)
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);
MEDFieldFieldGlobsReal(const char *fname);
MEDFieldFieldGlobsReal();
void shallowCpyGlobs(const MEDFieldFieldGlobsReal& other);
+ void appendGlobs(const MEDFieldFieldGlobsReal& other, double eps) throw(INTERP_KERNEL::Exception);
virtual std::vector<std::string> getPflsReallyUsed() const = 0;
virtual std::vector<std::string> getLocsReallyUsed() const = 0;
//
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()