From: geay Date: Wed, 14 May 2014 15:45:49 +0000 (+0200) Subject: Addition of MEDCoupling1SGTUMesh::structurizeMe X-Git-Tag: V7_4_0rc1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f22f39ceb4d6d148aa02c03f0fe80cec7e14e66e;p=modules%2Fmed.git Addition of MEDCoupling1SGTUMesh::structurizeMe --- diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx index 0724620a5..971e31781 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.cxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.cxx @@ -21,6 +21,7 @@ #include "MEDCoupling1GTUMesh.hxx" #include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingCMesh.hxx" #include "SplitterTetra.hxx" @@ -527,6 +528,9 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::New(const MEDCouplingUMesh *m) } } ret->setNodalConnectivity(conn); + try + { ret->copyTinyInfoFrom(m); } + catch(INTERP_KERNEL::Exception&) { } return ret.retn(); } @@ -964,6 +968,9 @@ MEDCouplingUMesh *MEDCoupling1SGTUMesh::buildUnstructured() const } MEDCouplingAutoRefCountObjectPtr cI=DataArrayInt::Range(0,(nbCells+1)*(nbNodesPerCell+1),nbNodesPerCell+1); ret->setConnectivity(c,cI,true); + try + { ret->copyTinyInfoFrom(this); } + catch(INTERP_KERNEL::Exception&) { } return ret.retn(); } @@ -1661,6 +1668,41 @@ MEDCoupling1SGTUMesh *MEDCoupling1SGTUMesh::explodeEachHexa8To6Quad4() const return ret.retn(); } +/*! + * This method starts from an unstructured mesh that hides in reality a cartesian mesh. + * If it is not the case, an exception will be thrown. + * This method returns three objects : The cartesian mesh geometrically equivalent to \a this (within a precision of \a eps) and a permutation of cells + * and a permutation of nodes. + * + * \param [out] cellPerm the permutation array of size \c this->getNumberOfCells() + * \param [out] nodePerm the permutation array of size \c this->getNumberOfNodes() + * \return MEDCouplingCMesh * - a newly allocated mesh that is the result of the structurization of \a this. + */ +MEDCouplingCMesh *MEDCoupling1SGTUMesh::structurizeMe(DataArrayInt *& cellPerm, DataArrayInt *& nodePerm, double eps) const +{ + checkCoherency(); + int spaceDim(getSpaceDimension()),meshDim(getMeshDimension()),nbNodes(getNumberOfNodes()); + if(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(meshDim)!=getCellModelEnum()) + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::structurizeMe : the unique geo type in this is not compatible with the geometric type regarding mesh dimension !"); + MEDCouplingAutoRefCountObjectPtr cm(MEDCouplingCMesh::New()); + for(int i=0;i tmp(1,i); + MEDCouplingAutoRefCountObjectPtr elt(static_cast(getCoords()->keepSelectedComponents(tmp))); + elt=elt->getDifferentValues(eps); + elt->sort(true); + cm->setCoordsAt(i,elt); + } + if(nbNodes!=cm->getNumberOfNodes()) + throw INTERP_KERNEL::Exception("MEDCoupling1SGTUMesh::structurizeMe : considering the number of nodes after split per components in space this can't be a cartesian mesh ! Maybe your epsilon parameter is invalid ?"); + try + { cm->copyTinyInfoFrom(this); } + catch(INTERP_KERNEL::Exception&) { } + MEDCouplingAutoRefCountObjectPtr um(cm->buildUnstructured()),self(buildUnstructured()); + self->checkGeoEquivalWith(um,12,eps,cellPerm,nodePerm); + return cm.retn(); +} + /// @cond INTERNAL bool UpdateHexa8Cell(int validAxis, int neighId, const int *validConnQuad4NeighSide, int *allFacesNodalConn, int *myNeighbours) @@ -2649,6 +2691,9 @@ MEDCouplingUMesh *MEDCoupling1DGTUMesh::buildUnstructured() const } } ret->setConnectivity(c,cI,true); + try + { ret->copyTinyInfoFrom(this); } + catch(INTERP_KERNEL::Exception&) { } return ret.retn(); } diff --git a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx index 6c4411121..55c85d39a 100644 --- a/src/MEDCoupling/MEDCoupling1GTUMesh.hxx +++ b/src/MEDCoupling/MEDCoupling1GTUMesh.hxx @@ -81,6 +81,7 @@ namespace ParaMEDMEM }; class MEDCoupling1DGTUMesh; + class MEDCouplingCMesh; class MEDCoupling1SGTUMesh : public MEDCoupling1GTUMesh { @@ -146,6 +147,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT MEDCoupling1GTUMesh *computeDualMesh() const; MEDCOUPLING_EXPORT DataArrayInt *sortHexa8EachOther(); MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *explodeEachHexa8To6Quad4() const; + MEDCOUPLING_EXPORT MEDCouplingCMesh *structurizeMe(DataArrayInt *& cellPerm, DataArrayInt *& nodePerm, double eps=1e-12) const; public://serialization MEDCOUPLING_EXPORT void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const; MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const; diff --git a/src/MEDCoupling/MEDCouplingPointSet.cxx b/src/MEDCoupling/MEDCouplingPointSet.cxx index a2654034d..72cb033ee 100644 --- a/src/MEDCoupling/MEDCouplingPointSet.cxx +++ b/src/MEDCoupling/MEDCouplingPointSet.cxx @@ -124,10 +124,10 @@ DataArrayDouble *MEDCouplingPointSet::getCoordinatesAndOwner() const */ void MEDCouplingPointSet::copyTinyStringsFrom(const MEDCouplingMesh *other) { + MEDCouplingMesh::copyTinyStringsFrom(other); const MEDCouplingPointSet *otherC=dynamic_cast(other); if(!otherC) throw INTERP_KERNEL::Exception("MEDCouplingPointSet::copyTinyStringsFrom : meshes have not same type !"); - MEDCouplingMesh::copyTinyStringsFrom(other); if(_coords && otherC->_coords) _coords->copyStringInfoFrom(*otherC->_coords); } diff --git a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx index e737159ea..c43a49a79 100644 --- a/src/MEDCoupling/MEDCouplingStructuredMesh.cxx +++ b/src/MEDCoupling/MEDCouplingStructuredMesh.cxx @@ -352,6 +352,9 @@ MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const MEDCouplingAutoRefCountObjectPtr conn(Build1GTNodalConnectivity(ns,ns+spaceDim)); MEDCouplingAutoRefCountObjectPtr ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim))); ret->setNodalConnectivity(conn); ret->setCoords(coords); + try + { ret->copyTinyInfoFrom(this); } + catch(INTERP_KERNEL::Exception&) { } return ret.retn(); } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 20b8b5848..a7fbdca6b 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -14995,7 +14995,26 @@ class MEDCouplingBasicsTest(unittest.TestCase): #f.applyLin(2.,0.) #self.assertTrue(f.getArray().isEqual(DataArrayDouble([243.,211.,211.,179.,211.,179.,179.,127.]),1e-12)) pass - + + def testSwig2StructurizeMe1(self): + arrx=DataArrayDouble(3) ; arrx.iota() ; arrx*=2. + arry=DataArrayDouble(4) ; arry.iota() ; arry+=3. + arrz=DataArrayDouble(5) ; arrz.iota() ; arrz*=0.5 ; arrz+=2. + c=MEDCouplingCMesh() ; c.setCoords(arrx,arry,arrz) + c.setName("mesh") ; c.setDescription("mesh descr") ; c.setTimeUnit("us") ; c.setTime(1.2,3,4) + u=c.buildUnstructured() + cp=DataArrayInt([3,5,6,1,0,9,8,7,12,11,16,10,17,23,22,21,19,20,18,14,13,2,4,15]) + np=DataArrayInt([3,33,5,35,6,36,1,31,0,30,9,39,8,38,7,37,12,42,11,41,16,46,10,40,17,47,23,53,22,52,21,51,19,49,20,50,18,48,14,44,13,43,2,32,4,34,15,45,29,59,28,58,27,57,26,56,25,55,24,54]) + u.renumberCells(cp) + u.renumberNodes(np,len(np)) + u=MEDCoupling1SGTUMesh(u) + # + e,d,f=u.structurizeMe() + self.assertTrue(c.isEqual(e,1e-12)) + self.assertTrue(d.isEqual(cp)) + self.assertTrue(f.isEqual(np)) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 92cd4bbd2..e5add4eaa 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -2648,6 +2648,17 @@ namespace ParaMEDMEM return oss.str(); } + PyObject *structurizeMe(double eps=1e-12) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *cellPerm(0),*nodePerm(0); + MEDCouplingCMesh *retCpp(self->structurizeMe(cellPerm,nodePerm,eps)); + PyObject *ret(PyTuple_New(3)); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(retCpp),SWIGTYPE_p_ParaMEDMEM__MEDCouplingCMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(cellPerm),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(nodePerm),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + static MEDCoupling1SGTUMesh *Merge1SGTUMeshes(PyObject *li) throw(INTERP_KERNEL::Exception) { std::vector tmp;