From 07d232b5a9831b3e8c832ec107b76a52af41fbaa Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 13 Feb 2017 15:51:50 +0100 Subject: [PATCH] On the road Jack --- .../Bases/InterpKernelAutoPtr.hxx | 6 + src/MEDLoader/MEDFileBlowStrEltUp.cxx | 298 +++++++++++++++++- src/MEDLoader/MEDFileBlowStrEltUp.hxx | 3 +- src/MEDLoader/MEDFileField.cxx | 5 +- 4 files changed, 302 insertions(+), 10 deletions(-) diff --git a/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx b/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx index 7dcec2b96..ea984a760 100644 --- a/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx +++ b/src/INTERP_KERNEL/Bases/InterpKernelAutoPtr.hxx @@ -29,6 +29,8 @@ namespace INTERP_KERNEL public: AutoPtr(T *ptr=0):_ptr(ptr) { } ~AutoPtr() { destroyPtr(); } + bool isNull() const { return _ptr==0; } + bool isNotNull() const { return !isNull(); } AutoPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } T *operator->() { return _ptr ; } const T *operator->() const { return _ptr; } @@ -48,6 +50,8 @@ namespace INTERP_KERNEL public: AutoCppPtr(T *ptr=0):_ptr(ptr) { } ~AutoCppPtr() { destroyPtr(); } + bool isNull() const { return _ptr==0; } + bool isNotNull() const { return !isNull(); } AutoCppPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } T *operator->() { return _ptr ; } const T *operator->() const { return _ptr; } @@ -67,6 +71,8 @@ namespace INTERP_KERNEL public: AutoCPtr(T *ptr=0):_ptr(ptr) { } ~AutoCPtr() { destroyPtr(); } + bool isNull() const { return _ptr==0; } + bool isNotNull() const { return !isNull(); } AutoCPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } T *operator->() { return _ptr ; } const T *operator->() const { return _ptr; } diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.cxx b/src/MEDLoader/MEDFileBlowStrEltUp.cxx index fcd9e51fa..28b7b0f6b 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.cxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.cxx @@ -20,6 +20,7 @@ #include "MEDFileBlowStrEltUp.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDFileFieldVisitor.hxx" using namespace MEDCoupling; @@ -264,11 +265,21 @@ void MEDFileBlowStrEltUp::generate(MEDFileMeshes *msOut, MEDFileFields *allZeOut MEDFileUMesh *umesh(dynamic_cast(mesh)); if(!umesh) throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : Blow up of Stru Elt not managed yet for unstructured meshes !"); - MCAuto mOut; - MCAuto fsOut1; - MCAuto zeStr(dealWithSEInMesh(ps[0].second,umesh,mOut,fsOut1)); - msOut->pushMesh(mOut); - dealWithSEInFields(ps[0].second,*elt,zeStr,fsOut1,allZeOutFields); + // + std::vector< MCAuto > elts2; + std::vector< MCAuto > elts3; + MCAuto classicalSEFields(splitFieldsPerLoc(*elt,elts2,elts3)); + if(classicalSEFields.isNotNull()) + { + MCAuto mOut; + MCAuto fsOut1; + MCAuto zeStr(dealWithSEInMesh(ps[0].second,umesh,mOut,fsOut1)); + msOut->pushMesh(mOut); + dealWithSEInFields(ps[0].second,classicalSEFields,zeStr,fsOut1,allZeOutFields); + } + /*for(std::vector< MCAuto >::iterator elt2=elts2.begin();elt2!=elts2.end();elt2++) + { + }*/ } } @@ -295,3 +306,280 @@ void MEDFileBlowStrEltUp::DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileBlowStrEltUp bu(fsSEOnly,ms,ses); bu.generate(ms,fs); } + +// + +class LocInfo +{ +public: + LocInfo() { } + bool operator==(const LocInfo& other) const { return _locs==other._locs && _pfl==other._pfl; } + void push(const std::string& loc, const std::string& pfl) { checkUniqueLoc(loc); _locs.push_back(loc); _pfl.push_back(pfl); } +private: + void checkUniqueLoc(const std::string& loc) const; +private: + std::vector _locs; + std::vector _pfl; +}; + +void LocInfo::checkUniqueLoc(const std::string& loc) const +{ + if(std::find(_locs.begin(),_locs.end(),loc)!=_locs.end()) + { + std::ostringstream oss; oss << "LocInfo::checkUniqueLoc : loc \"" << loc << "\" already exists !"; + throw INTERP_KERNEL::Exception(oss.str()); + } +} + +class FieldWalker2 +{ +public: + FieldWalker2(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd); + bool isClassic() const { return _is_classic; } + bool operator!=(const FieldWalker2& other) const; +private: + std::string _loc; + std::string _pfl; + bool _is_classic; +}; + +FieldWalker2::FieldWalker2(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd) +{ + _loc=pmptpd->getLocalization(); + _pfl=pmptpd->getProfile(); + _is_classic=pmptpd->getType()==ON_GAUSS_PT; +} + +bool FieldWalker2::operator!=(const FieldWalker2& other) const +{ + bool ret(_loc==other._loc && _pfl==other._pfl && _is_classic==other._is_classic); + return !ret; +} + +class FieldWalker1 +{ +public: + FieldWalker1(const MEDFileAnyTypeField1TSWithoutSDA *ts):_ts(ts),_pm_pt(0),_nb_mesh(0) { } + void newMeshEntry(const MEDFileFieldPerMesh *fpm); + void endMeshEntry(const MEDFileFieldPerMesh *fpm) { } + void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt); + void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt); + void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd); + void checkOK(const FieldWalker1& other) const; + bool isClassical() const; +private: + const MEDFileAnyTypeField1TSWithoutSDA *_ts; + const MEDFileFieldPerMeshPerTypeDyn *_pm_pt; + std::vector _fw; + int _nb_mesh; +}; + +void FieldWalker1::newMeshEntry(const MEDFileFieldPerMesh *fpm) +{ + if(_nb_mesh++==1) + throw INTERP_KERNEL::Exception("FieldWalker1::newMeshEntry : multi mesh not supported !"); +} + +void FieldWalker1::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt) +{ + if(_pm_pt) + throw INTERP_KERNEL::Exception("FieldWalker1::newPerMeshPerTypeEntry : multi SE loc not managed yet !"); + const MEDFileFieldPerMeshPerTypeDyn *pmpt2(dynamic_cast(pmpt)); + if(!pmpt2) + throw INTERP_KERNEL::Exception("newPerMeshPerTypeEntry : internal error !"); + _pm_pt=pmpt2; +} + +void FieldWalker1::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *) +{ + isClassical(); +} + +void FieldWalker1::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd) +{ + _fw.push_back(FieldWalker2(pmptpd)); +} + +void FieldWalker1::checkOK(const FieldWalker1& other) const +{ + std::size_t sz(_fw.size()); + if(other._fw.size()!=sz) + throw INTERP_KERNEL::Exception("checkOK : not OK because size are not the same !"); + for(std::size_t i=0;i::const_iterator it=_fw.begin();it!=_fw.end();it++) + { + if((*it).isClassic()) + ic++; + else + inc++; + } + if(ic!=0 && inc!=0) + throw INTERP_KERNEL::Exception("FieldWalker1::endPerMeshPerTypeEntry : mix is not allowed yet !"); + return inc==0; +} + +class FieldWalker +{ +public: + FieldWalker(const MEDFileAnyTypeFieldMultiTSWithoutSDA *f):_f(f) { } + void newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts); + void endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts); + void newMeshEntry(const MEDFileFieldPerMesh *fpm); + void endMeshEntry(const MEDFileFieldPerMesh *fpm); + void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt); + void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt); + void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd); +public: + bool isEmpty() const; + bool isClassical() const; +private: + const MEDFileAnyTypeFieldMultiTSWithoutSDA *_f; + mutable INTERP_KERNEL::AutoCppPtr _fw; + mutable INTERP_KERNEL::AutoCppPtr _fw_prev; +}; + +bool FieldWalker::isEmpty() const +{ + return _fw_prev.isNull(); +} + +bool FieldWalker::isClassical() const +{ + return _fw_prev->isClassical(); +} + +void FieldWalker::newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts) +{ + _fw=new FieldWalker1(ts); +} + +void FieldWalker::endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts) +{ + if(_fw_prev.isNull()) + _fw_prev=new FieldWalker1(*_fw); + else + _fw_prev->checkOK(*_fw); + _fw=0; +} + +void FieldWalker::newMeshEntry(const MEDFileFieldPerMesh *fpm) +{ + _fw->newMeshEntry(fpm); +} + +void FieldWalker::endMeshEntry(const MEDFileFieldPerMesh *fpm) +{ + _fw->endMeshEntry(fpm); +} + +void FieldWalker::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt) +{ + _fw->newPerMeshPerTypeEntry(pmpt); +} + +void FieldWalker::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt) +{ + _fw->endPerMeshPerTypeEntry(pmpt); +} + +void FieldWalker::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd) +{ + _fw->newPerMeshPerTypePerDisc(pmptpd); +} + +// this class splits fields into same +class LocSpliter : public MEDFileFieldVisitor +{ +public: + LocSpliter(const MEDFileFieldGlobsReal *globs):_globs(globs),_fw(0) { } +private: + void newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field); + void endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field); + // + void newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts); + void endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts); + // + void newMeshEntry(const MEDFileFieldPerMesh *fpm); + void endMeshEntry(const MEDFileFieldPerMesh *fpm); + // + void newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt); + void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt); + // + void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd); +private: + const MEDFileFieldGlobsReal *_globs; + std::vector< LocInfo > _locs; + std::vector< MCAuto > _fields_on_locs;//size of _locs== size of _fields_on_locs + MCAuto _classical; +private: + mutable INTERP_KERNEL::AutoCppPtr _fw; +}; + +void LocSpliter::newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field) +{ + _fw=new FieldWalker(field); +} + +void LocSpliter::endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field) +{ + if(_fw->isEmpty()) + return ; + if(_fw->isClassical()) + { + if(_classical.isNull()) + { + _classical=MEDFileFields::New(); + _classical->shallowCpyGlobs(*_globs); + } + } +} + +void LocSpliter::newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts) +{ + _fw->newTimeStepEntry(ts); +} + +void LocSpliter::endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts) +{ + _fw->endTimeStepEntry(ts); +} + +void LocSpliter::newMeshEntry(const MEDFileFieldPerMesh *fpm) +{ + _fw->newMeshEntry(fpm); +} + +void LocSpliter::endMeshEntry(const MEDFileFieldPerMesh *fpm) +{ + _fw->endMeshEntry(fpm); +} + +void LocSpliter::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt) +{ + _fw->newPerMeshPerTypeEntry(pmpt); +} + +void LocSpliter::endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt) +{ + _fw->endPerMeshPerTypeEntry(pmpt); +} + +void LocSpliter::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd) +{ + _fw->newPerMeshPerTypePerDisc(pmptpd); +} + +MCAuto MEDFileBlowStrEltUp::splitFieldsPerLoc(const MEDFileFields *fields, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes) +{ + LocSpliter ls(fields); + fields->accept(ls); +} diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.hxx b/src/MEDLoader/MEDFileBlowStrEltUp.hxx index 2f5743996..46b800eff 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.hxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.hxx @@ -35,9 +35,10 @@ namespace MEDCoupling { public: MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses); - static void DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileStructureElements *ses); void generate(MEDFileMeshes *msOut, MEDFileFields *allZeOutFields); + static void DealWithSE(MEDFileFields *fs, MEDFileMeshes *ms, const MEDFileStructureElements *ses); private: + MCAuto splitFieldsPerLoc(const MEDFileFields *fields, std::vector< MCAuto >& outFields, std::vector< MCAuto >& outMeshes); MCAuto dealWithSEInMesh(const std::string& seName, MEDFileUMesh *mesh, MCAuto& mOut, MCAuto& fsOut) const; MCAuto dealWithMEDBALLInMesh(const MEDFileUMesh *mesh, MCAuto& mOut, MCAuto& fsOut) const; void dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MEDFileFields *zeOutputs) const; diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 2677195fd..eedfeeaf4 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -11438,10 +11438,7 @@ void MEDFileFields::getMeshSENames(std::vector< std::pair fsSEOnly(partOfThisOnStructureElements()); - killStructureElements(); - MEDFileBlowStrEltUp bu(fsSEOnly,ms,ses); - bu.generate(ms,this); + MEDFileBlowStrEltUp::DealWithSE(this,ms,ses); } MCAuto MEDFileFields::partOfThisOnStructureElements() const -- 2.39.2