From 3b2e9e7942cdf5228a43282b3f642dc82ffd9068 Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 19 Apr 2011 08:01:33 +0000 Subject: [PATCH] MEDFileField Gauss Points. --- src/MEDLoader/MEDFileField.cxx | 202 +++++++++++++++++---------- src/MEDLoader/MEDFileField.hxx | 24 +++- src/MEDLoader/Swig/MEDLoader.i | 4 +- src/MEDLoader/Swig/MEDLoaderTest3.py | 8 ++ 4 files changed, 160 insertions(+), 78 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 50dd6d061..69d20fe6c 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -23,6 +23,7 @@ #include "MEDFileUtilities.hxx" #include "InterpKernelAutoPtr.hxx" +#include "CellModel.hxx" #include @@ -33,6 +34,33 @@ extern med_geometry_type typmai3[32]; using namespace ParaMEDMEM; +MEDFileFieldLoc *MEDFileFieldLoc::New(med_idt fid, const char *locName) +{ + return new MEDFileFieldLoc(fid,locName); +} + +MEDFileFieldLoc::MEDFileFieldLoc(med_idt fid, const char *locName):_name(locName) +{ + med_geometry_type geotype; + med_geometry_type sectiongeotype; + int nsectionmeshcell; + INTERP_KERNEL::AutoPtr geointerpname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr sectionmeshname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + MEDlocalizationInfoByName(fid,locName,&geotype,&_dim,&_nb_gauss_pt,geointerpname,sectionmeshname,&nsectionmeshcell,§iongeotype); + _geo_type=(INTERP_KERNEL::NormalizedCellType)(std::distance(typmai3,std::find(typmai3,typmai3+32,geotype))); + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::getCellModel(_geo_type); + _nb_node_per_cell=cm.getNumberOfNodes(); + _ref_coo.resize(_dim*_nb_node_per_cell); + _gs_coo.resize(_dim*_nb_gauss_pt); + _w.resize(_nb_gauss_pt); + MEDlocalizationRd(fid,locName,MED_FULL_INTERLACE,&_ref_coo[0],&_gs_coo[0],&_w[0]); +} + +void MEDFileFieldLoc::writeLL(med_idt fid) const +{ + MEDlocalizationWr(fid,_name.c_str(),typmai3[(int)_geo_type],_dim,&_ref_coo[0],MED_FULL_INTERLACE,_nb_gauss_pt,&_gs_coo[0],&_w[0],MED_NO_INTERPOLATION,MED_NO_MESH_SUPPORT); +} + MEDFileFieldPerMeshPerTypePerDisc *MEDFileFieldPerMeshPerTypePerDisc::New(MEDFileFieldPerMeshPerType *fath, med_idt fid, int profileIt) throw(INTERP_KERNEL::Exception) { return new MEDFileFieldPerMeshPerTypePerDisc(fath,fid,profileIt); @@ -51,10 +79,10 @@ try:_father(fath),_profile_it(profileIt) TypeOfField type=getType(); INTERP_KERNEL::NormalizedCellType geoType=getGeoType(); int profilesize,nbi; - int nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,type==ON_CELLS?MED_CELL:MED_NODE,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,profileIt,MED_COMPACT_PFLMODE, - pflname,&profilesize,locname,&nbi); + _nval=MEDfieldnValueWithProfile(fid,fieldName.c_str(),iteration,order,type==ON_CELLS?MED_CELL:MED_NODE,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,profileIt,MED_COMPACT_PFLMODE, + pflname,&profilesize,locname,&nbi); _arr=DataArrayDouble::New(); - _arr->alloc(nval,infos.size()); + _arr->alloc(_nval*nbi,infos.size()); MEDfieldValueWithProfileRd(fid,fieldName.c_str(),iteration,order,type==ON_CELLS?MED_CELL:MED_NODE,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE,MED_COMPACT_PFLMODE, pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,reinterpret_cast(_arr->getPointer())); _profile=MEDLoaderBase::buildStringFromFortran(pflname,MED_NAME_SIZE); @@ -135,7 +163,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::writeLL(med_idt fid) const throw(INTERP_ TypeOfField type=getType(); INTERP_KERNEL::NormalizedCellType geoType=getGeoType(); MEDfieldValueWithProfileWr(fid,getName().c_str(),getIteration(),getOrder(),getTime(),type==ON_CELLS?MED_CELL:MED_NODE,type==ON_CELLS?typmai3[(int)geoType]:MED_NONE, - MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_arr->getNumberOfTuples(), + MED_COMPACT_PFLMODE,_profile.c_str(),_localization.c_str(),MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,_nval, reinterpret_cast(_arr->getConstPointer())); } @@ -459,6 +487,25 @@ void MEDFieldFieldGlobs::writeGlobals(med_idt fid, const MEDFileWritable& opt) c MEDLoaderBase::safeStrCpy(_pfls[i]->getName().c_str(),MED_NAME_SIZE,pflName,opt.getTooLongStrPolicy()); MEDprofileWr(fid,pflName,_pfls[i]->getNumberOfTuples(),cpy->getConstPointer()); } + // + int nbOfLocs=_locs.size(); + for(int i=0;iwriteLL(fid); +} + +void MEDFieldFieldGlobs::loadGlobals(med_idt fid) throw(INTERP_KERNEL::Exception) +{ + std::vector profiles=getPflsReallyUsed(); + int sz=profiles.size(); + _pfls.resize(sz); + for(int i=0;i locs=getLocsReallyUsed(); + sz=locs.size(); + _locs.resize(sz); + for(int i=0;ifinishLoading(fid); } -void MEDFileField1TSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) -{ - if(_field_per_mesh.empty()) - throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::writeLL : empty field !"); - if(_field_per_mesh.size()>1) - throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !"); - _field_per_mesh[0]->writeLL(fid); -} - -MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) -{ - //MEDCouplingAutoRefCountObjectPtr mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),_mesh_iteration,_mesh_order); - //MEDCouplingAutoRefCountObjectPtr m=mm->getGenMeshAtLevel(meshDimRelToMaxExt); - return 0;//_field_per_mesh[0]->getFieldOnMeshAtLevel(meshDimRelToMaxExt,glob,m); -} - -MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) -{ - return _field_per_mesh[0]->getFieldOnMeshAtLevel(meshDimRelToMaxExt,glob,mesh); -} - -std::vector MEDFileField1TSWithoutDAS::getPflsReallyUsed() const +std::vector MEDFileField1TSWithoutDAS::getPflsReallyUsed2() const { std::vector ret; std::set ret2; @@ -564,7 +590,7 @@ std::vector MEDFileField1TSWithoutDAS::getPflsReallyUsed() const return ret; } -std::vector MEDFileField1TSWithoutDAS::getLocsReallyUsed() const +std::vector MEDFileField1TSWithoutDAS::getLocsReallyUsed2() const { std::vector ret; std::set ret2; @@ -581,6 +607,27 @@ std::vector MEDFileField1TSWithoutDAS::getLocsReallyUsed() const return ret; } +void MEDFileField1TSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception) +{ + if(_field_per_mesh.empty()) + throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::writeLL : empty field !"); + if(_field_per_mesh.size()>1) + throw INTERP_KERNEL::Exception("MEDFileField1TSWithoutDAS::writeLL : In MED3.0 mode in writting mode only ONE underlying mesh supported !"); + _field_per_mesh[0]->writeLL(fid); +} + +MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception) +{ + //MEDCouplingAutoRefCountObjectPtr mm=MEDFileMesh::New(glob->getFileName(),getMeshName().c_str(),_mesh_iteration,_mesh_order); + //MEDCouplingAutoRefCountObjectPtr m=mm->getGenMeshAtLevel(meshDimRelToMaxExt); + return 0;//_field_per_mesh[0]->getFieldOnMeshAtLevel(meshDimRelToMaxExt,glob,m); +} + +MEDCouplingFieldDouble *MEDFileField1TSWithoutDAS::getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception) +{ + return _field_per_mesh[0]->getFieldOnMeshAtLevel(meshDimRelToMaxExt,glob,mesh); +} + MEDFileField1TSWithoutDAS::MEDFileField1TSWithoutDAS(const char *fieldName, int csit, int iteration, int order, const std::vector& infos):_name(fieldName),_infos(infos),_csit(csit),_iteration(iteration),_order(order) { @@ -674,17 +721,23 @@ try:MEDFileField1TSWithoutDAS(fieldName,-1,iteration,order,std::vector profiles=getPflsReallyUsed(); - int sz=profiles.size(); - _pfls.resize(sz); - for(int i=0;i MEDFileField1TS::getPflsReallyUsed() const +{ + return getPflsReallyUsed2(); +} + +std::vector MEDFileField1TS::getLocsReallyUsed() const +{ + return getLocsReallyUsed2(); +} + MEDCouplingFieldDouble *MEDFileField1TS::getFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { return MEDFileField1TSWithoutDAS::getFieldAtLevel(meshDimRelToMaxExt,this); @@ -775,40 +828,6 @@ void MEDFileFieldMultiTSWithoutDAS::writeLL(med_idt fid) const throw(INTERP_KERN } } -std::vector MEDFileFieldMultiTSWithoutDAS::getPflsReallyUsed() const -{ - std::vector ret; - std::set ret2; - for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutDAS > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) - { - std::vector tmp=(*it)->getPflsReallyUsed(); - for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) - if(ret2.find(*it2)==ret2.end()) - { - ret.push_back(*it2); - ret2.insert(*it2); - } - } - return ret; -} - -std::vector MEDFileFieldMultiTSWithoutDAS::getLocsReallyUsed() const -{ - std::vector ret; - std::set ret2; - for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutDAS > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) - { - std::vector tmp=(*it)->getLocsReallyUsed(); - for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) - if(ret2.find(*it2)==ret2.end()) - { - ret.push_back(*it2); - ret2.insert(*it2); - } - } - return ret; -} - int MEDFileFieldMultiTSWithoutDAS::getNumberOfTS() const { return _time_steps.size(); @@ -866,17 +885,47 @@ try:MEDFileFieldMultiTSWithoutDAS(fieldName),MEDFieldFieldGlobs(fileName) throw INTERP_KERNEL::Exception(oss.str().c_str()); } finishLoading(fid,nbstep2); - std::vector profiles=getPflsReallyUsed(); - int sz=profiles.size(); - _pfls.resize(sz); - for(int i=0;i MEDFileFieldMultiTS::getPflsReallyUsed() const +{ + std::vector ret; + std::set ret2; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutDAS > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + { + std::vector tmp=(*it)->getPflsReallyUsed2(); + for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) + if(ret2.find(*it2)==ret2.end()) + { + ret.push_back(*it2); + ret2.insert(*it2); + } + } + return ret; +} + +std::vector MEDFileFieldMultiTS::getLocsReallyUsed() const +{ + std::vector ret; + std::set ret2; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileField1TSWithoutDAS > >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++) + { + std::vector tmp=(*it)->getLocsReallyUsed2(); + for(std::vector::const_iterator it2=tmp.begin();it2!=tmp.end();it2++) + if(ret2.find(*it2)==ret2.end()) + { + ret.push_back(*it2); + ret2.insert(*it2); + } + } + return ret; +} + MEDFileFields *MEDFileFields::New(const char *fileName) throw(INTERP_KERNEL::Exception) { return new MEDFileFields(fileName); @@ -920,3 +969,14 @@ catch(INTERP_KERNEL::Exception& e) { throw e; } + +std::vector MEDFileFields::getPflsReallyUsed() const +{ + return std::vector();//tony +} + +std::vector MEDFileFields::getLocsReallyUsed() const +{ + return std::vector();//tony +} + diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 2319b1dc8..b42ae5cff 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -46,7 +46,11 @@ namespace ParaMEDMEM class MEDFileFieldLoc : public RefCountObject { public: - const std::string& getName() const { return _name; } + const std::string& getName() const { return _name; } + static MEDFileFieldLoc *New(med_idt fid, const char *locName); + void writeLL(med_idt fid) const; + private: + MEDFileFieldLoc(med_idt fid, const char *locName); private: int _dim; int _nb_gauss_pt; @@ -86,6 +90,7 @@ namespace ParaMEDMEM private: MEDFileFieldPerMeshPerType *_father; MEDCouplingAutoRefCountObjectPtr< DataArrayDouble > _arr; + int _nval; int _profile_it; std::string _profile; std::string _localization; @@ -158,11 +163,14 @@ namespace ParaMEDMEM MEDFieldFieldGlobs(const char *fname); 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) throw(INTERP_KERNEL::Exception); void writeGlobals(med_idt fid, const MEDFileWritable& opt) const throw(INTERP_KERNEL::Exception); std::vector getPfls() const; std::vector getLocs() const; void setFileName(const char *fileName); const char *getFileName() const { return _file_name.c_str(); } + virtual std::vector getPflsReallyUsed() const = 0; + virtual std::vector getLocsReallyUsed() const = 0; protected: std::vector< MEDCouplingAutoRefCountObjectPtr > _pfls; std::vector< MEDCouplingAutoRefCountObjectPtr > _locs; @@ -180,13 +188,13 @@ namespace ParaMEDMEM std::string getMeshName() const throw(INTERP_KERNEL::Exception); int getNumberOfComponents() const { return _infos.size(); } const std::vector& getInfo() const { return _infos; } - std::vector getPflsReallyUsed() const; - std::vector getLocsReallyUsed() const; // static MEDFileField1TSWithoutDAS *New(const char *fieldName, int csit, int iteration, int order, const std::vector& infos); void pushBack(TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType, double time) const; void finishLoading(med_idt fid) throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); + std::vector getPflsReallyUsed2() const; + std::vector getLocsReallyUsed2() const; protected: MEDCouplingFieldDouble *getFieldAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDFieldFieldGlobs *glob, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); @@ -219,6 +227,8 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(int meshDimRelToMaxExt, const MEDCouplingMesh *mesh) const throw(INTERP_KERNEL::Exception); private: + std::vector getPflsReallyUsed() const; + std::vector getLocsReallyUsed() const; MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception); }; @@ -234,8 +244,6 @@ namespace ParaMEDMEM MEDFileFieldMultiTSWithoutDAS(const char *fieldName); MEDFileFieldMultiTSWithoutDAS(med_idt fid, const char *fieldName, int id, const std::vector& infos, int nbOfStep) throw(INTERP_KERNEL::Exception); void finishLoading(med_idt fid, int nbPdt) throw(INTERP_KERNEL::Exception); - std::vector getPflsReallyUsed() const; - std::vector getLocsReallyUsed() const; void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); protected: std::string _name; @@ -251,6 +259,9 @@ namespace ParaMEDMEM public: static MEDFileFieldMultiTS *New(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); + private: + std::vector getPflsReallyUsed() const; + std::vector getLocsReallyUsed() const; private: MEDFileFieldMultiTS(const char *fileName, const char *fieldName) throw(INTERP_KERNEL::Exception); }; @@ -263,6 +274,9 @@ namespace ParaMEDMEM public: static MEDFileFields *New(const char *fileName) throw(INTERP_KERNEL::Exception); int getNumberOfFields() const; + private: + std::vector getPflsReallyUsed() const; + std::vector getLocsReallyUsed() const; private: MEDFileFields(const char *fileName) throw(INTERP_KERNEL::Exception); private: diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 229b02ea1..57131a316 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -441,6 +441,8 @@ namespace ParaMEDMEM public: std::vector getPfls() const; std::vector getLocs() const; + virtual std::vector getPflsReallyUsed() const = 0; + virtual std::vector getLocsReallyUsed() const = 0; }; class MEDFileField1TSWithoutDAS : public RefCountObject @@ -452,8 +454,6 @@ namespace ParaMEDMEM std::string getMeshName(); int getNumberOfComponents() const; const std::vector& getInfo() const; - std::vector getPflsReallyUsed() const; - std::vector getLocsReallyUsed() const; }; class MEDFileField1TS : public MEDFileField1TSWithoutDAS, public MEDFieldFieldGlobs, public MEDFileWritable diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 12734f47f..3e06f2914 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -347,6 +347,14 @@ class MEDLoaderTest(unittest.TestCase): ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes") ff.write("Pyfile19_bis.med",0) pass + + def testMEDField3(self): + mm=MEDFileMesh.New("Pyfile13.med") + mm.write("Pyfile13_bis.med",2) + ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint") + ff.write("Pyfile13_bis.med",0) + pass + pass unittest.main() -- 2.39.2