From: Anthony Geay Date: Wed, 5 Oct 2016 14:03:29 +0000 (+0200) Subject: New constructor for ExtrudedMeshes taking 3D MEDCouplingCMesh instance X-Git-Tag: V8_2_0a1~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=caf364883bab2fd09c362a5423a9593df9377be1;p=tools%2Fmedcoupling.git New constructor for ExtrudedMeshes taking 3D MEDCouplingCMesh instance --- diff --git a/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.cxx b/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.cxx index 351daf58c..d11c1fa3b 100644 --- a/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.cxx @@ -20,6 +20,7 @@ #include "MEDCouplingMappedExtrudedMesh.hxx" #include "MEDCouplingUMesh.hxx" +#include "MEDCouplingCMesh.hxx" #include "MEDCouplingMemArray.hxx" #include "MEDCouplingFieldDouble.hxx" #include "MCAuto.hxx" @@ -50,6 +51,11 @@ MEDCouplingMappedExtrudedMesh *MEDCouplingMappedExtrudedMesh::New(const MEDCoupl return new MEDCouplingMappedExtrudedMesh(mesh3D,mesh2D,cell2DId); } +MEDCouplingMappedExtrudedMesh *MEDCouplingMappedExtrudedMesh::New(const MEDCouplingCMesh *mesh3D) +{ + return new MEDCouplingMappedExtrudedMesh(mesh3D); +} + /*! * This constructor is here only for unserialisation process. * This constructor is normally completely useless for end user. @@ -95,22 +101,31 @@ void MEDCouplingMappedExtrudedMesh::copyTinyStringsFrom(const MEDCouplingMesh *o MEDCouplingMappedExtrudedMesh::MEDCouplingMappedExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId) try:_mesh2D(const_cast(mesh2D)),_mesh1D(MEDCouplingUMesh::New()),_mesh3D_ids(0),_cell_2D_id(cell2DId) { - if(_mesh2D!=0) + if(_mesh2D.isNotNull()) _mesh2D->incrRef(); computeExtrusion(mesh3D); - setName(mesh3D->getName()); + setName(mesh3D->getName()); setDescription(mesh3D->getDescription()); } catch(INTERP_KERNEL::Exception& e) { - if(_mesh2D) - _mesh2D->decrRef(); - if(_mesh1D) - _mesh1D->decrRef(); - if(_mesh3D_ids) - _mesh3D_ids->decrRef(); throw e; } +MEDCouplingMappedExtrudedMesh::MEDCouplingMappedExtrudedMesh(const MEDCouplingCMesh *mesh3D):_mesh1D(MEDCouplingUMesh::New()),_mesh3D_ids(0),_cell_2D_id(0) +{ + if(!mesh3D) + throw INTERP_KERNEL::Exception("MEDCouplingMappedExtrudedMesh contrct : null input pointer !"); + if(mesh3D->getMeshDimension()!=3) + throw INTERP_KERNEL::Exception("MEDCouplingMappedExtrudedMesh contrct : input cart mesh must have dimension equal to 3 !"); + MCAuto umesh3D(mesh3D->buildUnstructured()); + MCAuto cmesh2D(MEDCouplingCMesh::New()); cmesh2D->setName(mesh3D->getName()); + cmesh2D->setCoords(mesh3D->getCoordsAt(0),mesh3D->getCoordsAt(1)); + _mesh2D=cmesh2D->buildUnstructured(); + _mesh2D->setCoords(umesh3D->getCoords()); + computeExtrusion(umesh3D); + setName(mesh3D->getName()); setDescription(mesh3D->getDescription()); +} + MEDCouplingMappedExtrudedMesh::MEDCouplingMappedExtrudedMesh():_mesh2D(0),_mesh1D(0),_mesh3D_ids(0),_cell_2D_id(-1) { } @@ -126,14 +141,8 @@ MEDCouplingMappedExtrudedMesh::MEDCouplingMappedExtrudedMesh(const MEDCouplingMa else { _mesh2D=other._mesh2D; - if(_mesh2D) - _mesh2D->incrRef(); _mesh1D=other._mesh1D; - if(_mesh1D) - _mesh1D->incrRef(); _mesh3D_ids=other._mesh3D_ids; - if(_mesh3D_ids) - _mesh3D_ids->incrRef(); } } @@ -752,7 +761,7 @@ void MEDCouplingMappedExtrudedMesh::getReverseNodalConnectivity(DataArrayInt *re void MEDCouplingMappedExtrudedMesh::computeExtrusionAlg(const MEDCouplingUMesh *mesh3D) { _mesh3D_ids->alloc(mesh3D->getNumberOfCells(),1); - int nbOf1DLev=mesh3D->getNumberOfCells()/_mesh2D->getNumberOfCells(); + int nbOf1DLev(mesh3D->getNumberOfCells()/_mesh2D->getNumberOfCells()); _mesh1D->setMeshDimension(1); _mesh1D->allocateCells(nbOf1DLev); int tmpConn[2]; diff --git a/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.hxx b/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.hxx index c1ea9f579..54dc24048 100644 --- a/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMappedExtrudedMesh.hxx @@ -31,12 +31,14 @@ namespace MEDCoupling class DataArrayInt; class DataArrayDouble; class MEDCouplingUMesh; + class MEDCouplingCMesh; class MEDCouplingFieldDouble; class MEDCouplingMappedExtrudedMesh : public MEDCouplingMesh { public: MEDCOUPLING_EXPORT static MEDCouplingMappedExtrudedMesh *New(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId); + MEDCOUPLING_EXPORT static MEDCouplingMappedExtrudedMesh *New(const MEDCouplingCMesh *mesh3D); MEDCOUPLING_EXPORT static MEDCouplingMappedExtrudedMesh *New(); MEDCOUPLING_EXPORT MEDCouplingMeshType getType() const; MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const; @@ -107,6 +109,7 @@ namespace MEDCoupling MEDCOUPLING_EXPORT std::string getVTKFileExtension() const; private: MEDCouplingMappedExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId); + MEDCouplingMappedExtrudedMesh(const MEDCouplingCMesh *mesh3D); MEDCouplingMappedExtrudedMesh(const MEDCouplingMappedExtrudedMesh& other, bool deepCopy); MEDCouplingMappedExtrudedMesh(); void computeExtrusion(const MEDCouplingUMesh *mesh3D); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py index f8eb9c254..ea5851ffe 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py @@ -4424,7 +4424,13 @@ class MEDCouplingBasicsTest5(unittest.TestCase): self.assertTrue(em.buildUnstructured().isEqual(m,1e-12)) # the bug was here ... buildUnstructured used to modify em ... self.assertTrue(em.buildUnstructured().isEqual(m,1e-12)) # the bug was here ... buildUnstructured used to modify em ... pass - + + def testExtrudedMeshFromCMesh1(self): + 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) + self.assertTrue(ex.buildUnstructured().isEqual(mesh3D.buildUnstructured(),1e-12)) + pass pass if __name__ == '__main__': diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index cb145e880..0ebb72521 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -522,6 +522,7 @@ namespace MEDCoupling class DataArrayInt; class DataArrayDouble; class MEDCouplingUMesh; + class MEDCouplingCMesh; class MEDCouplingFieldDouble; %extend RefCountObject @@ -2824,6 +2825,7 @@ namespace MEDCoupling { public: 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); %extend { MEDCouplingMappedExtrudedMesh(const MEDCouplingUMesh *mesh3D, const MEDCouplingUMesh *mesh2D, int cell2DId) throw(INTERP_KERNEL::Exception) @@ -2831,6 +2833,11 @@ namespace MEDCoupling return MEDCouplingMappedExtrudedMesh::New(mesh3D,mesh2D,cell2DId); } + MEDCouplingMappedExtrudedMesh(const MEDCouplingCMesh *mesh3D) throw(INTERP_KERNEL::Exception) + { + return MEDCouplingMappedExtrudedMesh::New(mesh3D); + } + MEDCouplingMappedExtrudedMesh() { return MEDCouplingMappedExtrudedMesh::New();