]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Useful MEDCouplingUMesh.Build1DMeshFromCoords method
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 17 Feb 2017 08:54:42 +0000 (09:54 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 17 Feb 2017 08:54:42 +0000 (09:54 +0100)
src/MEDCoupling/MEDCouplingUMesh.cxx
src/MEDCoupling/MEDCouplingUMesh.hxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest5.py
src/MEDCoupling_Swig/MEDCouplingCommon.i

index 39bf67ac565405d821fb4e09e7328e1ed2d3c369..cbff1a12d8e367ac92ef1a366caef97877316b10 100644 (file)
@@ -19,6 +19,7 @@
 // Author : Anthony Geay (CEA/DEN)
 
 #include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingCMesh.hxx"
 #include "MEDCoupling1GTUMesh.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingSkyLineArray.hxx"
@@ -8037,15 +8038,16 @@ MEDCouplingUMesh *MEDCouplingUMesh::Build0DMeshFromCoords(DataArrayDouble *da)
   if(!da)
     throw INTERP_KERNEL::Exception("MEDCouplingUMesh::Build0DMeshFromCoords : instance of DataArrayDouble must be not null !");
   da->checkAllocated();
-  MCAuto<MEDCouplingUMesh> ret=MEDCouplingUMesh::New(da->getName(),0);
+  std::string name(da->getName());
+  MCAuto<MEDCouplingUMesh> ret(MEDCouplingUMesh::New(name,0));
+  if(name.empty())
+    ret->setName("Mesh");
   ret->setCoords(da);
-  int nbOfTuples=da->getNumberOfTuples();
-  MCAuto<DataArrayInt> c=DataArrayInt::New();
-  MCAuto<DataArrayInt> cI=DataArrayInt::New();
+  int nbOfTuples(da->getNumberOfTuples());
+  MCAuto<DataArrayInt> c(DataArrayInt::New()),cI(DataArrayInt::New());
   c->alloc(2*nbOfTuples,1);
   cI->alloc(nbOfTuples+1,1);
-  int *cp=c->getPointer();
-  int *cip=cI->getPointer();
+  int *cp(c->getPointer()),*cip(cI->getPointer());
   *cip++=0;
   for(int i=0;i<nbOfTuples;i++)
     {
@@ -8056,6 +8058,29 @@ MEDCouplingUMesh *MEDCouplingUMesh::Build0DMeshFromCoords(DataArrayDouble *da)
   ret->setConnectivity(c,cI,true);
   return ret.retn();
 }
+
+MCAuto<MEDCouplingUMesh> MEDCouplingUMesh::Build1DMeshFromCoords(DataArrayDouble *da)
+{
+  if(!da)
+    throw INTERP_KERNEL::Exception("MEDCouplingUMesh::Build01MeshFromCoords : instance of DataArrayDouble must be not null !");
+  da->checkAllocated();
+  std::string name(da->getName());
+  MCAuto<MEDCouplingUMesh> ret;
+  {
+    MCAuto<MEDCouplingCMesh> tmp(MEDCouplingCMesh::New());
+    MCAuto<DataArrayDouble> arr(DataArrayDouble::New());
+    arr->alloc(da->getNumberOfTuples());
+    tmp->setCoordsAt(0,arr);
+    ret=tmp->buildUnstructured();
+  }
+  ret->setCoords(da);
+  if(name.empty())
+    ret->setName("Mesh");
+  else
+    ret->setName(name);
+  return ret;
+}
+
 /*!
  * Creates a new MEDCouplingUMesh by concatenating two given meshes of the same dimension.
  * Cells and nodes of
index 2241c267e5b7a26c8c3280d08123cf6143adebd8..ab2f47650fb37bb960c25051cf69b9ee4d62ef8d 100644 (file)
@@ -233,6 +233,7 @@ namespace MEDCoupling
     MEDCOUPLING_EXPORT DataArrayInt *colinearize2D(double eps);
     MEDCOUPLING_EXPORT int split2DCells(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *subNodesInSeg, const DataArrayInt *subNodesInSegI, const DataArrayInt *midOpt=0, const DataArrayInt *midOptI=0);
     MEDCOUPLING_EXPORT static MEDCouplingUMesh *Build0DMeshFromCoords(DataArrayDouble *da);
+    MEDCOUPLING_EXPORT static MCAuto<MEDCouplingUMesh> Build1DMeshFromCoords(DataArrayDouble *da);
     MEDCOUPLING_EXPORT static MEDCouplingUMesh *MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2);
     MEDCOUPLING_EXPORT static MEDCouplingUMesh *MergeUMeshes(const std::vector<const MEDCouplingUMesh *>& a);
     MEDCOUPLING_EXPORT static MEDCouplingUMesh *MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2);
index 6e9febf06ef3ef0c3d3b4aae0e41f6565b29c77f..4bbfe6087cfcffdcd744320336f6fc8b98f75a75 100644 (file)
@@ -4852,6 +4852,28 @@ class MEDCouplingBasicsTest5(unittest.TestCase):
         self.assertEqual(f2.getArray().getHiddenCppPointer(),f3.getArray().getHiddenCppPointer())
         self.assertEqual(f3.getTime(),[0.5,2,3])
         pass
+
+    def testBuild1DMeshFromCoords1(self):
+        da=DataArrayDouble([(3,4),(5,6),(7,8)])
+        da.setName("ZeArr")
+        da0=da.deepCopy()
+        m=MEDCouplingUMesh.Build1DMeshFromCoords(da0)
+        m.checkConsistencyLight()
+        self.assertEqual(da0.getHiddenCppPointer(),m.getCoords().getHiddenCppPointer())
+        self.assertTrue(da.isEqual(da0,1e-12))
+        self.assertEqual(m.getName(),da.getName())
+        self.assertEqual(m.getMeshDimension(),1)
+        self.assertTrue(isinstance(m,MEDCouplingUMesh))
+        m1=MEDCoupling1SGTUMesh(m)
+        m1.checkConsistencyLight()
+        self.assertTrue(m1.getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2])))
+        #
+        da0.setName("")
+        m2=MEDCouplingUMesh.Build1DMeshFromCoords(da0)
+        m2.checkConsistencyLight()
+        self.assertEqual(da0.getHiddenCppPointer(),m2.getCoords().getHiddenCppPointer())
+        self.assertEqual(m2.getName(),"Mesh")
+        pass
     
     pass
 
index 99bfc86c7187acfea66b0b58de1aa04d612308db..a8036fbba97366da860c0e68de2665d20ff41435 100644 (file)
@@ -315,6 +315,7 @@ using namespace INTERP_KERNEL;
 %newobject MEDCoupling::MEDCouplingUMesh::buildPartOrthogonalField;
 %newobject MEDCoupling::MEDCouplingUMesh::keepCellIdsByType;
 %newobject MEDCoupling::MEDCouplingUMesh::Build0DMeshFromCoords;
+%newobject MEDCoupling::MEDCouplingUMesh::Build1DMeshFromCoords;
 %newobject MEDCoupling::MEDCouplingUMesh::findAndCorrectBadOriented3DExtrudedCells;
 %newobject MEDCoupling::MEDCouplingUMesh::findAndCorrectBadOriented3DCells;
 %newobject MEDCoupling::MEDCouplingUMesh::convertIntoSingleGeoTypeMesh;
@@ -1896,6 +1897,12 @@ namespace MEDCoupling
         return self->cellIterator();
       }
 
+      static MEDCouplingUMesh *Build1DMeshFromCoords(DataArrayDouble *da) throw(INTERP_KERNEL::Exception)
+      {
+        MCAuto<MEDCouplingUMesh> ret(MEDCouplingUMesh::Build1DMeshFromCoords(da));
+        return ret.retn();
+      }
+      
       PyObject *getAllGeoTypesSorted() const throw(INTERP_KERNEL::Exception)
       {
         std::vector<INTERP_KERNEL::NormalizedCellType> result=self->getAllGeoTypesSorted();