From: Anthony Geay Date: Wed, 3 Jan 2018 15:36:55 +0000 (+0100) Subject: Go on to MEDFileFields::linearToQuadratic X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6d1667ad0eabbf4bbbd0e4c7875dc135a00b4e49;p=tools%2Fmedcoupling.git Go on to MEDFileFields::linearToQuadratic --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index f4c906f8b..811d33316 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -607,6 +607,103 @@ void MEDFileFields::accept(MEDFileFieldVisitor& visitor) const } } +class MEDFileFieldLin2QuadVisitor : public MEDFileFieldVisitor +{ +public: + MEDFileFieldLin2QuadVisitor(const MEDFileUMesh *lin, const MEDFileUMesh *quad, const MEDFileFieldGlobsReal *linGlobs, MEDFileFields* outFs):_lin(lin),_quad(quad),_lin_globs(linGlobs),_out_fs(outFs),_gt(INTERP_KERNEL::NORM_ERROR) { } + void newFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field) { if(field->getMeshName()!=_lin->getName()) return; _cur_fmts=MEDFileFieldMultiTS::New(); } + void endFieldEntry(const MEDFileAnyTypeFieldMultiTSWithoutSDA *field) { if(_cur_fmts.isNotNull()) { if(_cur_fmts->getNumberOfTS()>0) _out_fs->pushField(_cur_fmts); } } + // + void newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts); + void endTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts) { if(_cur_f1ts.isNotNull() && _cur_fmts.isNotNull()) { _cur_fmts->pushBackTimeStep(_cur_f1ts); } } + // + 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 MEDFileUMesh *_lin; + const MEDFileUMesh *_quad; + const MEDFileFieldGlobsReal *_lin_globs; + MEDFileFields *_out_fs; + MCAuto _cur_fmts; + MCAuto _cur_f1ts; + INTERP_KERNEL::NormalizedCellType _gt; +}; + +void MEDFileFieldLin2QuadVisitor::newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd) +{ + if(_cur_f1ts.isNull()) + return; + if(pmptpd->getType()!=ON_NODES) + return;// Only node-fields need care + MEDFileAnyTypeField1TSWithoutSDA *ct(_cur_f1ts->contentNotNullBase()); + MEDFileFieldPerMeshPerTypePerDisc *pmtd(ct->getLeafGivenMeshAndTypeAndLocId(_lin->getName(),_gt,pmptpd->getLocId())); +} + +void MEDFileFieldLin2QuadVisitor::newPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt) +{ + const MEDFileFieldPerMeshPerType *pmpt2(dynamic_cast(pmpt)); + if(!pmpt2) + throw INTERP_KERNEL::Exception("MEDFileFieldLin2QuadVisitor::newPerMeshPerTypeEntry : not managed for structure elements !"); + if(pmpt2->getNumberOfLoc()!=1) + throw INTERP_KERNEL::Exception("MEDFileFieldLin2QuadVisitor::newPerMeshPerTypeEntry : not managed for multi discr per timestep !"); + _gt=pmpt->getGeoType(); +} + +void MEDFileFieldLin2QuadVisitor::newMeshEntry(const MEDFileFieldPerMesh *fpm) +{ + if(fpm->getMeshName()!=_lin->getName()) + throw INTERP_KERNEL::Exception("MEDFileFieldLin2QuadVisitor::newMeshEntry : mismatch into meshName !"); +} + +void MEDFileFieldLin2QuadVisitor::newTimeStepEntry(const MEDFileAnyTypeField1TSWithoutSDA *ts) +{ + if(!ts) + return ; + const MEDFileField1TSWithoutSDA *tsd(dynamic_cast(ts)); + if(!tsd) + return ; + MCAuto contentCpy(ts->deepCopy()); + MCAuto contentCpy2(DynamicCastSafe(contentCpy)); + if(contentCpy2.isNotNull()) + return; + _cur_f1ts=MEDFileField1TS::New(*contentCpy2,true); + _cur_f1ts->shallowCpyGlobs(*_lin_globs); +} + +/*! + * \a newQuad is expected to be the result of MEDFileUMesh::linearToQuadratic of \a oldLin + */ +MCAuto MEDFileFields::linearToQuadratic(const MEDFileMeshes *oldLin, const MEDFileMeshes *newQuad) const +{ + if(!oldLin || !newQuad) + throw INTERP_KERNEL::Exception("MEDFileFields::linearToQuadratic : input meshes must be non NULL !"); + MCAuto ret(MEDFileFields::New()); + for(int i=0;igetNumberOfMeshes();i++) + { + MEDFileMesh *mm(oldLin->getMeshAtPos(i)); + if(!mm) + continue; + MEDFileUMesh *mmu(dynamic_cast(mm)); + if(!mmu) + continue; + MEDFileMesh *mmq(newQuad->getMeshWithName(mmu->getName())); + MEDFileUMesh *mmqu(dynamic_cast(mmq)); + if(!mmqu) + { + std::ostringstream oss; oss << "MEDFileFields::linearToQuadratic : mismatch of name between input meshes for name \"" << mmu->getName() << "\""; + throw INTERP_KERNEL::Exception(oss.str()); + } + MEDFileFieldLin2QuadVisitor vis(mmu,mmqu,this,ret); + accept(vis); + } + return ret; +} + MEDFileAnyTypeFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const { if(i<0 || i>=(int)_fields.size()) diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 724a53321..f173681e8 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -123,6 +123,7 @@ namespace MEDCoupling MEDLOADER_EXPORT bool changeMeshNames(const std::vector< std::pair >& modifTab); MEDLOADER_EXPORT bool renumberEntitiesLyingOnMesh(const std::string& meshName, const std::vector& oldCode, const std::vector& newCode, const DataArrayInt *renumO2N); MEDLOADER_EXPORT void accept(MEDFileFieldVisitor& visitor) const; + MEDLOADER_EXPORT MCAuto linearToQuadratic(const MEDFileMeshes *oldLin, const MEDFileMeshes *newQuad) const; public: MEDLOADER_EXPORT MEDFileFields *extractPart(const std::map >& extractDef, MEDFileMesh *mm) const; public: diff --git a/src/MEDLoader/MEDFileFieldVisitor.hxx b/src/MEDLoader/MEDFileFieldVisitor.hxx index 9ad13e9f6..47269e3a9 100644 --- a/src/MEDLoader/MEDFileFieldVisitor.hxx +++ b/src/MEDLoader/MEDFileFieldVisitor.hxx @@ -48,6 +48,7 @@ namespace MEDCoupling virtual void endPerMeshPerTypeEntry(const MEDFileFieldPerMeshPerTypeCommon *pmpt) = 0; // virtual void newPerMeshPerTypePerDisc(const MEDFileFieldPerMeshPerTypePerDisc *pmptpd) = 0; + virtual ~MEDFileFieldVisitor() { } }; }