From 78f1227e26a33f389bb8a65759c6b499a3dad876 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 24 Jan 2020 18:04:41 +0100 Subject: [PATCH] [EDF20418] : Fix regression in computation of Voronoi 2D cells (linked to change of behavior of MEDCouplingUMesh.Intersect2DMeshes) --- src/MEDCoupling/MEDCouplingVoronoi.cxx | 19 +++++++++++++- .../MEDCouplingBasicsTest7.py | 25 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/MEDCoupling/MEDCouplingVoronoi.cxx b/src/MEDCoupling/MEDCouplingVoronoi.cxx index 80e1b0e3d..16dbe2e58 100755 --- a/src/MEDCoupling/MEDCouplingVoronoi.cxx +++ b/src/MEDCoupling/MEDCouplingVoronoi.cxx @@ -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 ComputeBigCellFrom(const double pt1[2], const double pt throw INTERP_KERNEL::Exception("ComputeBigCellFrom : expected single element !"); MCAuto ret(sp2->buildPartOfMySelfSlice(ccp[0],ccp[0]+1,1,true)); ret->zipCoords(); + { + MCAuto tmp(ret->getMeasureField(false)); + if(tmp->getArray()->getIJ(0,0)<0) + ret->invertOrientationOfAllCells(); + } return ret; } @@ -424,6 +430,11 @@ MCAuto MEDCoupling::Voronizer2D::doIt(const MEDCouplingUMesh * newVorCell->zipCoords(); MCAuto modifiedCell(a->buildPartOfMySelf(part->begin(),part->end())); modifiedCell->zipCoords(); + { + MCAuto tmp(modifiedCell->getMeasureField(false)); + if(tmp->getArray()->getIJ(0,0)<0) + modifiedCell->invertOrientationOfAllCells(); + } l0[poly]=modifiedCell; // MCAuto ids; @@ -455,7 +466,13 @@ MCAuto MEDCoupling::Voronizer2D::doIt(const MEDCouplingUMesh * } newVorCells.push_back(newVorCell); } - l0.push_back(MergeVorCells(newVorCells,eps)); + MCAuto mergedVorCell(MergeVorCells(newVorCells,eps)); + { + MCAuto 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 ret(MEDCouplingUMesh::MergeUMeshes(l0Bis)); diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index 23277fdf5..f6a764675 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -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__': -- 2.39.2