From: Anthony Geay Date: Wed, 5 Oct 2016 15:07:09 +0000 (+0200) Subject: Some useful tools for MEDCouplingMappedExtrudedMesh users that needs to store it... X-Git-Tag: V8_2_0a1~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8ac81021d486fcbc0c8edb860afaeada13e67141;p=tools%2Fmedcoupling.git Some useful tools for MEDCouplingMappedExtrudedMesh users that needs to store it in .med files --- diff --git a/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.cxx index d11c1fa3b..43acb2ab2 100644 --- a/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.cxx @@ -440,6 +440,10 @@ void MEDCouplingMappedExtrudedMesh::renumberCells(const int *old2NewBg, bool che throw INTERP_KERNEL::Exception("Functionnality of renumbering cells unavailable for ExtrudedMesh"); } +/*! + * \b WARNING in case of modif think to update MEDFileUMesh::New implementation ! + * \sa MEDFileUMesh::New + */ MEDCouplingUMesh *MEDCouplingMappedExtrudedMesh::build3DUnstructuredMesh() const { MCAuto mesh2DZC(_mesh2D->deepCopyConnectivityOnly()); @@ -451,6 +455,10 @@ MEDCouplingUMesh *MEDCouplingMappedExtrudedMesh::build3DUnstructuredMesh() const return ret.retn(); } +/*! + * \b WARNING in case of modif think to update MEDFileUMesh::New implementation ! + * \sa MEDFileUMesh::New + */ MEDCouplingUMesh *MEDCouplingMappedExtrudedMesh::buildUnstructured() const { return build3DUnstructuredMesh(); diff --git a/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.hxx index 54dc24048..6cc714c5b 100644 --- a/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.hxx @@ -107,6 +107,7 @@ namespace MEDCoupling const std::vector& littleStrings); MEDCOUPLING_EXPORT void reprQuickOverview(std::ostream& stream) const; MEDCOUPLING_EXPORT std::string getVTKFileExtension() const; + MEDCOUPLING_EXPORT int get2DCellIdForExtrusion() const { return _cell_2D_id; } private: MEDCouplingMappedExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId); MEDCouplingMappedExtrudedMesh(const MEDCouplingCMesh *mesh3D); diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 0ebb72521..df9bd0ef2 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -2827,6 +2827,7 @@ namespace MEDCoupling static MEDCouplingMappedExtrudedMesh *New(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception); static MEDCouplingMappedExtrudedMesh *New(const MEDCouplingCMesh *mesh3D) throw(INTERP_KERNEL::Exception); MEDCouplingUMesh *build3DUnstructuredMesh() const throw(INTERP_KERNEL::Exception); + int get2DCellIdForExtrusion() const; %extend { MEDCouplingMappedExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception) { diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 0332e42d6..e71326cea 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -27,6 +27,7 @@ #include "MEDLoaderBase.hxx" #include "MEDCouplingUMesh.hxx" +#include "MEDCouplingMappedExtrudedMesh.hxx" #include "InterpKernelAutoPtr.hxx" @@ -39,6 +40,8 @@ using namespace MEDCoupling; const char MEDFileMesh::DFT_FAM_NAME[]="FAMILLE_ZERO"; +const char MEDFileUMesh::SPE_FAM_STR_EXTRUDED_MESH[]="HIDDEN_FAM_EXT_MESH@"; + MEDFileMesh::MEDFileMesh():_order(-1),_iteration(-1),_time(0.),_univ_wr_status(true),_axis_type(AX_CART) { } @@ -2273,6 +2276,25 @@ MEDFileUMesh *MEDFileUMesh::New(const std::string& fileName, MEDFileMeshReadSele return new MEDFileUMesh(fid,ms.front(),dt,it,mrs); } +/*! + * \b WARNING this implementation is dependant from MEDCouplingMappedExtrudedMesh::buildUnstructured ! + * \sa MEDCouplingMappedExtrudedMesh::buildUnstructured , MEDCouplingMappedExtrudedMesh::build3DUnstructuredMesh + */ +MEDFileUMesh *MEDFileUMesh::New(const MEDCouplingMappedExtrudedMesh *mem) +{ + if(!mem) + throw INTERP_KERNEL::Exception("MEDFileUMesh::New : null input vector !"); + MCAuto ret(MEDFileUMesh::New()); + MCAuto m3D(mem->buildUnstructured()); + MCAuto m2D(mem->getMesh2D()->deepCopy()); + m2D->zipCoords(); + m2D->setCoords(m3D->getCoords()); + ret->setMeshAtLevel(0,m3D); + ret->setMeshAtLevel(-1,m2D); + ret->setFamilyId(GetSpeStr4ExtMesh(),mem->get2DCellIdForExtrusion()); + return ret.retn(); +} + /*! * Returns an empty instance of MEDFileUMesh. * \return MEDFileUMesh * - a new instance of MEDFileUMesh. The caller is to delete this @@ -4624,6 +4646,18 @@ MCAuto MEDFileUMesh::Aggregate(const std::vector m3D(getMeshAtLevel(0)),m2D(getMeshAtLevel(-1)); + if(m3D.isNull() || m2D.isNull()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::convertToExtrudedMesh : this must be defined both at level 0 and level -1 !"); + int zeId(getFamilyId(GetSpeStr4ExtMesh())); + MCAuto ret(MEDCouplingMappedExtrudedMesh::New(m3D,m2D,zeId)); + return ret.retn(); +} + void MEDFileUMesh::serialize(std::vector& tinyDouble, std::vector& tinyInt, std::vector& tinyStr, std::vector< MCAuto >& bigArraysI, MCAuto& bigArrayD) { clearNonDiscrAttributes(); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 1e0f48bb2..ac0b6fd3e 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -240,15 +240,19 @@ namespace MEDCoupling MEDLOADER_EXPORT static const char DFT_FAM_NAME[]; }; + class MEDCouplingMappedExtrudedMesh; + class MEDFileUMesh : public MEDFileMesh { friend class MEDFileMesh; public: MEDLOADER_EXPORT static MEDFileUMesh *New(const std::string& fileName, const std::string& mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0); MEDLOADER_EXPORT static MEDFileUMesh *New(const std::string& fileName, MEDFileMeshReadSelector *mrs=0); + MEDLOADER_EXPORT static MEDFileUMesh *New(const MEDCouplingMappedExtrudedMesh *mem); MEDLOADER_EXPORT static MEDFileUMesh *New(); MEDLOADER_EXPORT static MEDFileUMesh *LoadPartOf(const std::string& fileName, const std::string& mName, const std::vector& types, const std::vector& slicPerTyp, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0); MEDLOADER_EXPORT static MEDFileUMesh *LoadPartOf(med_idt fid, const std::string& mName, const std::vector& types, const std::vector& slicPerTyp, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0); + MEDLOADER_EXPORT static const char *GetSpeStr4ExtMesh() { return SPE_FAM_STR_EXTRUDED_MESH; } MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; MEDLOADER_EXPORT std::vector getDirectChildrenWithNull() const; MEDLOADER_EXPORT MEDFileMesh *createNewEmpty() const; @@ -338,6 +342,7 @@ namespace MEDCoupling MEDLOADER_EXPORT MEDFileUMesh *quadraticToLinear(double eps=1e-12) const; MEDLOADER_EXPORT MCAuto symmetry3DPlane(const double point[3], const double normalVector[3]) const; MEDLOADER_EXPORT static MCAuto Aggregate(const std::vector& meshes); + MEDLOADER_EXPORT MEDCouplingMappedExtrudedMesh *convertToExtrudedMesh() const; // serialization MEDLOADER_EXPORT void serialize(std::vector& tinyDouble, std::vector& tinyInt, std::vector& tinyStr, std::vector< MCAuto >& bigArraysI, MCAuto& bigArrayD); @@ -360,6 +365,8 @@ namespace MEDCoupling void changeFamilyIdArr(int oldId, int newId); std::list< MCAuto > getAllNonNullFamilyIds() const; MCAuto& checkAndGiveEntryInSplitL1(int meshDimRelToMax, MEDCouplingPointSet *m); + private: + static const char SPE_FAM_STR_EXTRUDED_MESH[]; private: std::vector< MCAuto > _ms; MCAuto _coords; diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 3a348ebde..788d419ec 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -127,6 +127,7 @@ using namespace MEDCoupling; %newobject MEDCoupling::MEDFileUMesh::quadraticToLinear; %newobject MEDCoupling::MEDFileUMesh::symmetry3DPlane; %newobject MEDCoupling::MEDFileUMesh::Aggregate; +%newobject MEDCoupling::MEDFileUMesh::convertToExtrudedMesh; %newobject MEDCoupling::MEDFileCMesh::New; %newobject MEDCoupling::MEDFileCurveLinearMesh::New; %newobject MEDCoupling::MEDFileMeshMultiTS::New; @@ -1223,7 +1224,9 @@ namespace MEDCoupling public: static MEDFileUMesh *New(const std::string& fileName, const std::string& mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception); static MEDFileUMesh *New(const std::string& fileName, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception); + static MEDFileUMesh *New(const MEDCouplingMappedExtrudedMesh *mem) throw(INTERP_KERNEL::Exception); static MEDFileUMesh *New(); + static const char *GetSpeStr4ExtMesh(); ~MEDFileUMesh(); int getSpaceDimension() const throw(INTERP_KERNEL::Exception); int getRelativeLevOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception); @@ -1256,6 +1259,7 @@ namespace MEDCoupling MEDFileUMesh *buildExtrudedMesh(const MEDCouplingUMesh *m1D, int policy) const throw(INTERP_KERNEL::Exception); MEDFileUMesh *linearToQuadratic(int conversionType=0, double eps=1e-12) const throw(INTERP_KERNEL::Exception); MEDFileUMesh *quadraticToLinear(double eps=1e-12) const throw(INTERP_KERNEL::Exception); + MEDCouplingMappedExtrudedMesh *convertToExtrudedMesh() const throw(INTERP_KERNEL::Exception); %extend { MEDFileUMesh(const std::string& fileName, const std::string& mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception) @@ -1268,6 +1272,11 @@ namespace MEDCoupling return MEDFileUMesh::New(fileName,mrs); } + MEDFileUMesh(const MEDCouplingMappedExtrudedMesh *mem) throw(INTERP_KERNEL::Exception) + { + return MEDFileUMesh::New(mem); + } + MEDFileUMesh() { return MEDFileUMesh::New(); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index cc6b9e8a4..028e17be9 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -5743,6 +5743,16 @@ class MEDLoaderTest3(unittest.TestCase): mfd=MEDFileData.Aggregate([MEDFileData(fname1),MEDFileData(fname2)]) CheckMFD(self,mfd) pass + + def testExtrudedMesh1(self): + fname1="Pyfile107.med" + arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5]) + mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ) + ex=MEDCouplingMappedExtrudedMesh(mesh3D) + mm=MEDFileUMesh(ex) + ex2=mm.convertToExtrudedMesh() + self.assertTrue(ex.isEqual(ex2,1e-12)) + pass pass