From e8d23862df98c569db3f255e0fce1dcb6d832f53 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 24 Jan 2017 12:10:22 +0100 Subject: [PATCH] Step 8 : meshes have been managed, fields still remaining. --- src/MEDLoader/MEDFileBlowStrEltUp.cxx | 181 ++++++++++++++++++++++++++ src/MEDLoader/MEDFileBlowStrEltUp.hxx | 12 +- src/MEDLoader/MEDFileField.cxx | 17 +++ src/MEDLoader/MEDFileField.hxx | 1 + src/MEDLoader/MEDFileMesh.hxx | 1 + src/MEDLoader/MEDFileMeshElt.hxx | 6 +- src/MEDLoader/MEDFileMeshLL.hxx | 4 + src/MEDLoader/Swig/MEDLoaderCommon.i | 1 + 8 files changed, 219 insertions(+), 4 deletions(-) diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.cxx b/src/MEDLoader/MEDFileBlowStrEltUp.cxx index 9d10247df..0ee8ec16f 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.cxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.cxx @@ -19,9 +19,12 @@ // Author : Anthony Geay (EDF R&D) #include "MEDFileBlowStrEltUp.hxx" +#include "MEDCouplingFieldDouble.hxx" using namespace MEDCoupling; +const char MEDFileBlowStrEltUp::MED_BALL_STR[]="MED_BALL"; + MEDFileBlowStrEltUp::MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses) { if(!fsOnlyOnSE || !ms || !ses) @@ -37,4 +40,182 @@ MEDFileBlowStrEltUp::MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MCAuto f(fsOnlyOnSE->partOfThisLyingOnSpecifiedMeshSEName(p.first,p.second)); _elts[i]=f; } + for(std::size_t i=0;i& p(ps[i]); + MEDFileMesh *mesh(_ms->getMeshWithName(p.first)); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp : NULL mesh !"); + MEDFileUMesh *umesh(dynamic_cast(mesh)); + if(!umesh) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp : Blow up of Stru Elt not managed yet for unstructured meshes !"); + } +} + +/*! + * \param [in] mesh - The mesh containing structure element called \a seName. After the call of this method the Structure elements parts will be removed. + * \param [out] mOut - the physical mesh of the structure element \a seName in mesh \a mesh + * \param [out] fsOut - the list of var attribute of structure element \a seName - \b WARNING no time steps here + */ +MCAuto MEDFileBlowStrEltUp::dealWithSEInMesh(const std::string& seName, MEDFileUMesh *mesh, MCAuto& mOut, MCAuto& fsOut) const +{ + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInMesh : null pointer !"); + if(seName==MED_BALL_STR) + { + MCAuto ret(dealWithMEDBALLInMesh(mesh,mOut,fsOut)); + mesh->killStructureElements(); + return ret; + } + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInMesh : only MED_BALL is managed for the moment, but if you are interested please send spec to anthony.geay@edf.fr !"); +} + +MCAuto MEDFileBlowStrEltUp::dealWithMEDBALLInMesh(const MEDFileUMesh *mesh, MCAuto& mOut, MCAuto& fsOut) const +{ + mOut=MEDFileUMesh::New(); fsOut=MEDFileFields::New(); + const std::vector< MCAuto >& strs(mesh->getAccessOfUndergroundEltStrs()); + MCAuto zeStr; + for(std::vector< MCAuto >::const_iterator it=strs.begin();it!=strs.end();it++) + { + if((*it)->getGeoTypeName()==MED_BALL_STR) + { + zeStr=*it; + break; + } + } + if(zeStr.isNull()) + { + std::ostringstream oss; oss << "MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : no geo type with name " << MED_BALL_STR << " in " << mesh->getName() << " !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + const DataArrayDouble *coo(mesh->getCoords()); + if(!coo) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : null coords !"); + MCAuto conn(zeStr->getConn()); + if(conn.isNull()) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : null connectivity !"); + conn->checkAllocated(); + if(conn->getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithMEDBALLInMesh : excepted to be single compo !"); + int nbCells(conn->getNumberOfTuples()); + MCAuto connOut(coo->selectByTupleIdSafe(conn->begin(),conn->end())); + MCAuto mcOut(MEDCouplingUMesh::Build0DMeshFromCoords(connOut)); + mcOut->setName(BuildNewMeshName(mesh->getName(),MED_BALL_STR)); + mOut->setMeshAtLevel(0,mcOut); + const DataArrayInt *ff1(mesh->getFamilyFieldAtLevel(1)); + if(ff1) + { + MCAuto ff1o(ff1->selectByTupleIdSafe(conn->begin(),conn->end())); + mOut->setFamilyFieldArr(1,ff1o); + } + const DataArrayInt *nf1(mesh->getNumberFieldAtLevel(1)); + if(nf1) + { + MCAuto nf1o(nf1->selectByTupleIdSafe(conn->begin(),conn->end())); + mOut->setRenumFieldArr(1,nf1o); + } + MCAuto md(zeStr->getMeshDef()); + const DataArrayInt *ff0(md->getFam()); + if(ff0) + { + MCAuto ff0o(ff0->duplicateEachTupleNTimes(nbCells)); + mOut->setFamilyFieldArr(0,ff0o); + } + const DataArrayInt *nf0(md->getNum()); + if(nf0) + { + MCAuto nf0o(ff0->duplicateEachTupleNTimes(nbCells)); + mOut->setRenumFieldArr(0,nf0o); + } + mOut->copyFamGrpMapsFrom(*mesh); + const std::vector< MCAuto >& vars(zeStr->getVars()); + for(std::vector< MCAuto >::const_iterator it=vars.begin();it!=vars.end();it++) + { + const DataArray *elt(*it); + if(!elt) + continue; + { + const DataArrayDouble *eltC(dynamic_cast(elt)); + if(eltC) + { + MCAuto fmts(MEDFileFieldMultiTS::New()); + MCAuto f1ts(MEDFileField1TS::New()); + MCAuto f(MEDCouplingFieldDouble::New(ON_NODES)); + f->setMesh(mcOut); + f->setArray(const_cast(eltC)); + f->setName(eltC->getName()); + f1ts->setFieldNoProfileSBT(f); + fmts->pushBackTimeStep(f1ts); + fsOut->pushField(fmts); + } + } + } + return zeStr; +} + +/*! + * \param [in] fs - fields lying all on same mesh and on same structure element + * \param [in] zeStr - ze structure of current structure element + * \param [in] varAtt - fields containing var att of current structure element. WARNING at this stage the number of iteration are equal to one for each field in \a varAtt + * \param [out] zeOutputs - ze fields that are the concatenation of fields in \a fs transformed and those in \a varAtt normalized in time space + */ +void MEDFileBlowStrEltUp::dealWithSEInFields(const std::string& seName, const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MCAuto& zeOutputs) const +{ + if(!fs) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInFields : null pointer !"); + if(seName==MED_BALL_STR) + { + dealWithMEDBALLSInFields(fs,zeStr,varAtt,zeOutputs); + return ; + } + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::dealWithSEInFields : only MED_BALL is managed for the moment, but if you are interested please send spec to anthony.geay@edf.fr !"); +} + +void MEDFileBlowStrEltUp::dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MCAuto& zeOutputs) const +{ + +} + +void MEDFileBlowStrEltUp::generate(MCAuto& msOut, MCAuto& allZeOutFields) +{ + msOut=MEDFileMeshes::New(); + allZeOutFields=MEDFileFields::New(); + for(std::vector< MCAuto >::iterator elt=_elts.begin();elt!=_elts.end();elt++) + { + std::vector< std::pair > ps; + (*elt)->getMeshSENames(ps); + if(ps.size()!=1) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : internal error !"); + MEDFileMesh *mesh(_ms->getMeshWithName(ps[0].first)); + if(!mesh) + throw INTERP_KERNEL::Exception("MEDFileBlowStrEltUp::generateMeshes : NULL mesh !"); + 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(umesh); + MCAuto fsOut2; + dealWithSEInFields(ps[0].second,*elt,zeStr,fsOut1,fsOut2); + allZeOutFields->aggregate(*fsOut2); + } +} + +std::string MEDFileBlowStrEltUp::BuildNewMeshName(const std::string& meshName, const std::string& seName) +{ + std::ostringstream mNameOut; + mNameOut << meshName << "_" << seName; + return mNameOut.str(); +} + +void MEDFileBlowStrEltUp::DealWithSE(MEDFileFields *fs, const MEDFileMeshes *ms, const MEDFileStructureElements *ses, MCAuto& fsOut, MCAuto& msOut) +{ + MCAuto fsSEOnly(fs->partOfThisOnStructureElements()); + fs->killStructureElements(); + MEDFileBlowStrEltUp bu(fsSEOnly,ms,ses); + MCAuto msOut1; + MCAuto allZeOutFields1; + bu.generate(msOut1,allZeOutFields1); + } diff --git a/src/MEDLoader/MEDFileBlowStrEltUp.hxx b/src/MEDLoader/MEDFileBlowStrEltUp.hxx index 6930f352c..49743a1d7 100644 --- a/src/MEDLoader/MEDFileBlowStrEltUp.hxx +++ b/src/MEDLoader/MEDFileBlowStrEltUp.hxx @@ -35,8 +35,18 @@ namespace MEDCoupling { public: MEDFileBlowStrEltUp(const MEDFileFields *fsOnlyOnSE, const MEDFileMeshes *ms, const MEDFileStructureElements *ses); + static void DealWithSE(MEDFileFields *fs, const MEDFileMeshes *ms, const MEDFileStructureElements *ses, MCAuto& fsOut, MCAuto& msOut); private: - std::vector< MCAuto > _elts; + void generate(MCAuto& msOut, MCAuto& allZeOutFields); + 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, MCAuto& zeOutputs) const; + void dealWithMEDBALLSInFields(const MEDFileFields *fs, const MEDFileEltStruct4Mesh *zeStr, const MEDFileFields *varAtt, MCAuto& zeOutputs) const; + static std::string BuildNewMeshName(const std::string& meshName, const std::string& seName); + public: + static const char MED_BALL_STR[]; + private: + std::vector< MCAuto > _elts;// split by pair(meshName,SEName) MCConstAuto _ms; MCConstAuto _ses; }; diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index c6c13a44b..ded7e99dd 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -11223,6 +11223,23 @@ MCAuto MEDFileFields::partOfThisLyingOnSpecifiedMeshSEName(const return ret; } +void MEDFileFields::aggregate(const MEDFileFields& other) +{ + int nbFieldsToAdd(other.getNumberOfFields()); + std::vector fsn(getFieldsNames()); + for(int i=0;i elt(other.getFieldAtPos(i)); + std::string name(elt->getName()); + if(std::find(fsn.begin(),fsn.end(),name)!=fsn.end()) + { + std::ostringstream oss; oss << "MEDFileFields::aggregate : name \"" << name << "\" already appears !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + pushField(elt); + } +} + MEDFileFieldsIterator *MEDFileFields::iterator() { return new MEDFileFieldsIterator(this); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index 1be649510..8b49d1dac 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -1260,6 +1260,7 @@ namespace MEDCoupling MEDLOADER_EXPORT void getMeshSENames(std::vector< std::pair >& ps) const; MEDLOADER_EXPORT MCAuto partOfThisOnStructureElements() const; MEDLOADER_EXPORT MCAuto partOfThisLyingOnSpecifiedMeshSEName(const std::string& meshName, const std::string& seName) const; + MEDLOADER_EXPORT void aggregate(const MEDFileFields& other); MEDLOADER_EXPORT MEDFileFieldsIterator *iterator(); MEDLOADER_EXPORT void destroyFieldAtPos(int i); MEDLOADER_EXPORT void destroyFieldsAtPos(const int *startIds, const int *endIds); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 5cca36ee7..ba5c8fe40 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -274,6 +274,7 @@ namespace MEDCoupling MEDLOADER_EXPORT void clearNodeAndCellNumbers(); MEDLOADER_EXPORT void clearNonDiscrAttributes() const; MEDLOADER_EXPORT void setName(const std::string& name); + MEDLOADER_EXPORT const std::vector< MCAuto >& getAccessOfUndergroundEltStrs() const { return _elt_str; } // MEDLOADER_EXPORT int getMaxAbsFamilyIdInArrays() const; MEDLOADER_EXPORT int getMaxFamilyIdInArrays() const; diff --git a/src/MEDLoader/MEDFileMeshElt.hxx b/src/MEDLoader/MEDFileMeshElt.hxx index a093fb69d..57e50f558 100644 --- a/src/MEDLoader/MEDFileMeshElt.hxx +++ b/src/MEDLoader/MEDFileMeshElt.hxx @@ -43,6 +43,9 @@ namespace MEDCoupling med_entity_type entity, MEDFileMeshReadSelector *mrs); std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; + const DataArrayInt *getFam() const { return _fam; } + const DataArrayInt *getNum() const { return _num; } + const DataArrayAsciiChar *getNames() const { return _names; } protected: MCAuto _num; MCAuto _fam; @@ -59,9 +62,6 @@ namespace MEDCoupling std::vector getDirectChildrenWithNull() const; int getDim() const; MEDCoupling1GTUMesh *getMesh() const { return const_cast((const MEDCoupling1GTUMesh *)_m); } - const DataArrayInt *getFam() const { return _fam; } - const DataArrayInt *getNum() const { return _num; } - const DataArrayAsciiChar *getNames() const { return _names; } const PartDefinition *getPartDef() const { return _pd; } static void Write(med_idt fid, const std::string& mname, int mdim, const MEDCoupling1GTUMesh *m, const DataArrayInt *fam, const DataArrayInt *num, const DataArrayAsciiChar *names); private: diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 8a8d31b85..0113a22bf 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -326,6 +326,10 @@ namespace MEDCoupling { public: static MEDFileEltStruct4Mesh *New(med_idt fid, const std::string& mName, int dt, int it, int iterOnStEltOfMesh, MEDFileMeshReadSelector *mrs); + std::string getGeoTypeName() const { return _geo_type_name; } + MCAuto getConn() const { return _conn; } + MCAuto getMeshDef() const { return _common; } + const std::vector< MCAuto >& getVars() const { return _vars; } private: std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index abd8b7b33..63061304c 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -3022,6 +3022,7 @@ namespace MEDCoupling MEDFileAnyTypeFieldMultiTS *getFieldWithName(const std::string& fieldName) const throw(INTERP_KERNEL::Exception); MEDFileFields *partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const throw(INTERP_KERNEL::Exception); bool presenceOfStructureElements() const throw(INTERP_KERNEL::Exception); + void aggregate(const MEDFileFields& other) throw(INTERP_KERNEL::Exception); void killStructureElements() throw(INTERP_KERNEL::Exception); void keepOnlyStructureElements() throw(INTERP_KERNEL::Exception); void keepOnlyOnMeshSE(const std::string& meshName, const std::string& seName) throw(INTERP_KERNEL::Exception); -- 2.39.2