]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
[EDF20418] : Fix regression in computation of Voronoi 2D cells (linked to change...
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 24 Jan 2020 17:04:41 +0000 (18:04 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 27 Jan 2020 07:12:21 +0000 (08:12 +0100)
src/MEDCoupling/MEDCouplingVoronoi.cxx
src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py

index 80e1b0e3da473fe92967d8c81a3a5ad38aeffe1f..16dbe2e587f52c6ab53ceb13fd49335cb64c1075 100755 (executable)
@@ -21,6 +21,7 @@
 #include "MEDCouplingVoronoi.hxx"
 #include "MEDCoupling1GTUMesh.hxx"
 #include "MEDCouplingCMesh.hxx"
+#include "MEDCouplingFieldDouble.hxx"
 #include "MCAuto.txx"
 
 #include "MEDCouplingNormalizedUnstructuredMesh.txx"
@@ -90,6 +91,11 @@ MCAuto<MEDCouplingUMesh> ComputeBigCellFrom(const double pt1[2], const double pt
     throw INTERP_KERNEL::Exception("ComputeBigCellFrom : expected single element !");
   MCAuto<MEDCouplingUMesh> ret(sp2->buildPartOfMySelfSlice(ccp[0],ccp[0]+1,1,true));
   ret->zipCoords();
+  {
+    MCAuto<MEDCouplingFieldDouble> tmp(ret->getMeasureField(false));
+    if(tmp->getArray()->getIJ(0,0)<0)
+      ret->invertOrientationOfAllCells();
+  }
   return ret;
 }
 
@@ -424,6 +430,11 @@ MCAuto<MEDCouplingUMesh> MEDCoupling::Voronizer2D::doIt(const MEDCouplingUMesh *
           newVorCell->zipCoords();
           MCAuto<MEDCouplingUMesh> modifiedCell(a->buildPartOfMySelf(part->begin(),part->end()));
           modifiedCell->zipCoords();
+          {
+            MCAuto<MEDCouplingFieldDouble> tmp(modifiedCell->getMeasureField(false));
+            if(tmp->getArray()->getIJ(0,0)<0)
+              modifiedCell->invertOrientationOfAllCells();
+          }
           l0[poly]=modifiedCell;
           //
           MCAuto<DataArrayIdType> ids;
@@ -455,7 +466,13 @@ MCAuto<MEDCouplingUMesh> MEDCoupling::Voronizer2D::doIt(const MEDCouplingUMesh *
             }
           newVorCells.push_back(newVorCell);
         }
-      l0.push_back(MergeVorCells(newVorCells,eps));
+      MCAuto<MEDCouplingUMesh> mergedVorCell(MergeVorCells(newVorCells,eps));
+      {
+        MCAuto<MEDCouplingFieldDouble> tmp(mergedVorCell->getMeasureField(false));
+        if(tmp->getArray()->getIJ(0,0)<0)
+          mergedVorCell->invertOrientationOfAllCells();
+      }
+      l0.push_back(mergedVorCell);
     }
   std::vector< const MEDCouplingUMesh * > l0Bis(VecAutoToVecOfCstPt(l0));
   MCAuto<MEDCouplingUMesh> ret(MEDCouplingUMesh::MergeUMeshes(l0Bis));
index 23277fdf574f85a72f98dad5c47946374a9cf012..f6a7646751f92ca8d0a0a824e0ef60c3600b63e3 100644 (file)
@@ -730,6 +730,31 @@ class MEDCouplingBasicsTest7(unittest.TestCase):
             self.assertNotEqual(MEDCouplingUMesh.GetDimensionOfGeometricType(elt),-1)
         pass
 
+    def testVoronoi2D_3(self):
+        """
+        Non regression test for EDF20418 : After 8.5.0 MEDCouplingUMesh.Interset2DMeshes method (called by voronoize) is sensible to cell orientation of 2 input meshes. This test check correct behavior in
+        case of non standard orientation input cell.
+        """
+        coo = DataArrayDouble([0.018036113896685007,0.030867224641316506,0.019000000000000003,0.030833333333333407,0.018518056948342503,0.030850278987324904,0.018773068345659904,0.031180320157635305,0.018546136691319805,0.031527306981937307,0.018291125294002404,0.031197265811626906],6,2)
+        m = MEDCouplingUMesh("mesh",2)
+        m.setCoords(coo)
+        m.allocateCells()
+        m.insertNextCell(NORM_TRI3,[0,1,4])
+        f=MEDCouplingFieldDouble(ON_GAUSS_PT)
+        f.setMesh(m)
+        f.setArray(DataArrayDouble([12613576.708019681, 18945164.734307285, 22385248.637775388, 17074219.938821714, 19361929.467164982, 19258841.562907547]))
+        f.setGaussLocalizationOnType(NORM_TRI3,[0, 0, 1, 0, 0, 1],[0.0915762, 0.0915762, 0.816848, 0.0915762, 0.0915762, 0.816848, 0.445948, 0.108103, 0.445948, 0.445948, 0.108103, 0.445948],[0.0549759, 0.0549759, 0.0549759, 0.111691, 0.111691, 0.111691])
+        f.setName("field")
+        f_voro = f.voronoize(1e-13)
+        ref_area = DataArrayDouble([4.6679303278867127, 4.2514546761810138, 4.2514546761809337, 6.6206415950989804, 6.2643538685231039, 6.6206415950989884])
+        area = f_voro.buildMeasureField(True).getArray()*1e8
+        self.assertTrue(ref_area.isEqual(area,1e-6))
+        ref_bary = DataArrayDouble([(0.018231625096313969, 0.030950287685553721), (0.018826045778781105, 0.030916927013719033), (0.018533397739746087, 0.031364396601025746), (0.018541498169815956, 0.030944333493252929), (0.018660195622447071, 0.031132366117047686), (0.018400646702087166, 0.031159700554391174)])
+        bary = f_voro.getMesh().computeCellCenterOfMass()
+        self.assertTrue(ref_bary.isEqual(bary,1e-8))
+        self.assertTrue(f_voro.getArray().isEqual(f.getArray(),1e-8))
+        pass
+
     pass
 
 if __name__ == '__main__':