Salome HOME
Addition of MEDCoupling1SGTUMesh::structurizeMe
authorgeay <anthony.geay@cea.fr>
Wed, 14 May 2014 15:45:49 +0000 (17:45 +0200)
committergeay <anthony.geay@cea.fr>
Wed, 14 May 2014 15:45:49 +0000 (17:45 +0200)
src/MEDCoupling/MEDCoupling1GTUMesh.cxx
src/MEDCoupling/MEDCoupling1GTUMesh.hxx
src/MEDCoupling/MEDCouplingPointSet.cxx
src/MEDCoupling/MEDCouplingStructuredMesh.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 0724620a53155ffd4880dfcd4301b4d3e9260ab6..971e31781f6f25a08eb25725f590318b0a4814e5 100644 (file)
@@ -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<DataArrayInt> 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<MEDCouplingCMesh> cm(MEDCouplingCMesh::New());
+  for(int i=0;i<spaceDim;i++)
+    {
+      std::vector<int> tmp(1,i);
+      MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> elt(static_cast<DataArrayDouble*>(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<MEDCouplingUMesh> 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();
 }
 
index 6c4411121cf2eb6d6694c0be7a4f5072342646bb..55c85d39a20716ca44a1681f6a9fc90332c8348b 100644 (file)
@@ -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<double>& tinyInfoD, std::vector<int>& tinyInfo, std::vector<std::string>& littleStrings) const;
     MEDCOUPLING_EXPORT void resizeForUnserialization(const std::vector<int>& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector<std::string>& littleStrings) const;
index a2654034dd0e9cca65bbcb19380e844cb28b4e1e..72cb033ee60d50394eec3492b89b00a184d357f3 100644 (file)
@@ -124,10 +124,10 @@ DataArrayDouble *MEDCouplingPointSet::getCoordinatesAndOwner() const
  */
 void MEDCouplingPointSet::copyTinyStringsFrom(const MEDCouplingMesh *other)
 {
+  MEDCouplingMesh::copyTinyStringsFrom(other);
   const MEDCouplingPointSet *otherC=dynamic_cast<const MEDCouplingPointSet *>(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);
 }
index e737159ea3d3a800979363d645c84559ad0186ec..c43a49a7973a7c979103c4ae217be1f5a1c1fa7d 100644 (file)
@@ -352,6 +352,9 @@ MEDCoupling1SGTUMesh *MEDCouplingStructuredMesh::build1SGTUnstructured() const
   MEDCouplingAutoRefCountObjectPtr<DataArrayInt> conn(Build1GTNodalConnectivity(ns,ns+spaceDim));
   MEDCouplingAutoRefCountObjectPtr<MEDCoupling1SGTUMesh> ret(MEDCoupling1SGTUMesh::New(getName(),GetGeoTypeGivenMeshDimension(meshDim)));
   ret->setNodalConnectivity(conn); ret->setCoords(coords);
+  try
+    { ret->copyTinyInfoFrom(this); }
+  catch(INTERP_KERNEL::Exception&) { }
   return ret.retn();
 }
 
index 20b8b5848003d9941aa8d1c73af9063a14f75537..a7fbdca6b88c2ca6c18d5de31335683fc2d9fd27 100644 (file)
@@ -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
index 92cd4bbd2b7bfc0be1466963a026130eba996d86..e5add4eaa9e1a707391ba765841998c48f5014d1 100644 (file)
@@ -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<const ParaMEDMEM::MEDCoupling1SGTUMesh *> tmp;