X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDCoupling_Swig%2FMEDCouplingBasicsTest7.py;h=c45f74141b3e8a558b556b8bfa4ea15a985a826d;hb=662a2a2393a25baef77e42f74204b11b70a9646c;hp=3a5cacd9f0488651cdf05a65934a554c76665c10;hpb=fd8dbd347649185790f62a4382b21c7ab8271a76;p=tools%2Fmedcoupling.git diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py index 3a5cacd9f..c45f74141 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest7.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2007-2022 CEA/DEN, EDF R&D +# Copyright (C) 2007-2023 CEA, EDF # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,10 +20,7 @@ import sys -if sys.platform == "win32": - from MEDCouplingCompat import * -else: - from medcoupling import * +from medcoupling import * import unittest from math import pi,e,sqrt,cos,sin from datetime import datetime @@ -452,9 +449,9 @@ class MEDCouplingBasicsTest7(unittest.TestCase): # non regression test in python wrapping rg=DataArrayInt64([0,10,29,56,75,102,121,148,167,194,213,240,259,286,305,332,351,378,397,424,443,470,489,516]) a,b,c=DataArrayInt64([75]).splitByValueRange(rg) - assert(a.isEqual(DataArrayInt64([4]))) - assert(b.isEqual(DataArrayInt64([0]))) - assert(c.isEqual(DataArrayInt64([4]))) + self.assertTrue(a.isEqual(DataArrayInt64([4]))) + self.assertTrue(b.isEqual(DataArrayInt64([0]))) + self.assertTrue(c.isEqual(DataArrayInt64([4]))) pass def testDAIBuildExplicitArrByRanges1(self): @@ -1177,7 +1174,7 @@ class MEDCouplingBasicsTest7(unittest.TestCase): # 1D cells vec = [0.64] - for gt in [NORM_SEG2,NORM_SEG3]: + for gt in [NORM_SEG2,NORM_SEG3,NORM_SEG4]: ref_coord = [list(elt) for elt in MEDCouplingGaussLocalization.GetDefaultReferenceCoordinatesOf(gt).getValuesAsTuple()] der_computed = GetDerivative(ref_coord,vec) @@ -1250,6 +1247,90 @@ class MEDCouplingBasicsTest7(unittest.TestCase): self.assertTrue( disc.getMeasureField(tri,True).getArray().isEqual( tri.getMeasureField(True).getArray(), 1e-10) ) pass + def testUMeshExplodeMeshTo(self): + """ + [EDF27988] : implementation of reduceToCells implies implementation of MEDCouplingUMesh.explodeMeshTo + """ + arr = DataArrayDouble(5) ; arr.iota() + m = MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) + m = m.buildUnstructured() + m1 = m[::2] ; m2 = m[1::2] + m1.simplexize(PLANAR_FACE_5) + m = MEDCouplingUMesh.MergeUMeshesOnSameCoords([m1,m2]) + mE1 = m.explodeMeshTo(-1) + ref1 = m.buildDescendingConnectivity() + mE2 = m.explodeMeshTo(-2) + ref2 = m.explode3DMeshTo1D() + mE3 = m.explodeMeshTo(-3) + self.assertTrue( len(mE1) ==5 ) + self.assertTrue( mE1[0].getNodalConnectivity().isEqual(ref1[0].getNodalConnectivity()) ) + self.assertTrue( mE1[0].getNodalConnectivityIndex().isEqual(ref1[0].getNodalConnectivityIndex()) ) + self.assertTrue( mE1[0].getCoords().getHiddenCppPointer() == m.getCoords().getHiddenCppPointer() ) + for i in range(1,5): + self.assertTrue( mE1[i].isEqual(ref1[i]) ) + # + self.assertTrue( len(mE2) ==5 ) + self.assertTrue( mE2[0].getNodalConnectivity().isEqual(ref2[0].getNodalConnectivity()) ) + self.assertTrue( mE2[0].getNodalConnectivityIndex().isEqual(ref2[0].getNodalConnectivityIndex()) ) + self.assertTrue( mE2[0].getCoords().getHiddenCppPointer() == m.getCoords().getHiddenCppPointer() ) + for i in range(1,5): + self.assertTrue( mE2[i].isEqual(ref2[i]) ) + # + self.assertTrue( mE3[0].getMeshDimension() == 0 ) + self.assertTrue( mE3[0].getNumberOfCells() == mE3[0].getNumberOfNodes() ) + a,b = m.getReverseNodalConnectivity() + self.assertTrue( mE3[3].isEqual(a) and mE3[4].isEqual(b) ) + ref3_2 = (m.getNodalConnectivityIndex().deltaShiftIndex()-1) ; ref3_2.computeOffsetsFull() + self.assertTrue( ref3_2.isEqual(mE3[2]) ) + tmp = m.getNodalConnectivityIndex().deepCopy() ; tmp.popBackSilent() ; tmp = tmp.buildComplement( len(m.getNodalConnectivity()) ) ; ref3_1 = m.getNodalConnectivity()[tmp] + self.assertTrue( ref3_1.isEqual(mE3[1]) ) + # + cellsInPolyh = [37,160] + polyh = m[cellsInPolyh] + polyh.convertAllToPoly() + m[cellsInPolyh] = polyh + pE3 = m.explodeMeshTo(-3) + self.assertTrue( pE3[0].getMeshDimension() == 0 ) + self.assertTrue( pE3[0].getNumberOfCells() == pE3[0].getNumberOfNodes() ) + a,b = m.getReverseNodalConnectivity() + self.assertTrue( pE3[3].isEqual(a) and pE3[4].isEqual(b) ) + self.assertTrue( pE3[2].isEqual(mE3[2]) ) # indexed arrays are the same + + ref_a,ref_b = DataArrayInt.ExtractFromIndexedArrays( DataArrayInt(cellsInPolyh).buildComplement(m.getNumberOfCells()), mE3[1], mE3[2] ) + a,b = DataArrayInt.ExtractFromIndexedArrays( DataArrayInt(cellsInPolyh).buildComplement(m.getNumberOfCells()), pE3[1], pE3[2] ) + self.assertTrue( ref_a.isEqual(a) ) + self.assertTrue( ref_b.isEqual(b) ) + for cell in cellsInPolyh: + ref_c,ref_d = DataArrayInt.ExtractFromIndexedArrays( cell, mE3[1], mE3[2] ) ; ref_c.sort() + c,d = DataArrayInt.ExtractFromIndexedArrays( cell, pE3[1], pE3[2] ) + self.assertTrue( ref_c.isEqual(c) ) + self.assertTrue( ref_d.isEqual(d) ) + + def testGetCellContainingPointRelativeEps(self): + """ + See EDF27860 : This test checks that detection of point inside a cell works by normalizing cell around origin with factor equal to the max delta of bbox along axis X, Y or Z. + """ + # in this test cell is vuluntary far from origin {15260.775604514516, 11197.646906189217, 14187.820484060947} + # and caracteritic size is ~ 1500 + coo = DataArrayDouble( [(14724.199858870656, 11928.888084722483, 14442.32726944039), (14788.407409534622, 11992.60694822231, 14453.86181555231), (15572.175148726046, 10798.586790270576, 14471.54225356788), (15643.898717334796, 10853.094666047728, 14477.233802854305), (15005.31495255754, 11573.261110174888, 13933.313698681504), (15070.29423166349, 11636.377758513776, 13946.650959030132), (15797.351350158377, 10466.40572765595, 13965.524190108257), (15869.808770928525, 10519.99285973948, 13972.419352086607), (15273.866774426142, 11216.458197414971, 13433.169979717744), (15340.421031616577, 11277.882145177837, 13446.53598386297), (16013.382514001762, 10132.795887638129, 13465.184281842226), (16086.979064572806, 10184.802292369684, 13472.147425473782)] ) + m = MEDCouplingUMesh("",3) + m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TETRA4,[0,5,4,6]) + m.insertNextCell(NORM_TETRA4,[4,5,9,7]) + + ##### See EDF2760 pt is outside cell 0 (6e-4) and 1 (8e-4) + pt = DataArrayDouble([(15263.41200205526, 11314.957094727113, 13950.0)]) + a,b = m.getCellsContainingPoints(pt,1e-3) + self.assertTrue(a.isEqual(DataArrayInt([0,1]))) + self.assertTrue(b.isEqual(DataArrayInt([0,2]))) + + # by shifting pt by 10 along Z pt in only inside cell # 0 + pt += [0,0,10] + a1,b1 = m.getCellsContainingPoints(pt,1e-3) + self.assertTrue(a1.isEqual(DataArrayInt([0]))) + self.assertTrue(b1.isEqual(DataArrayInt([0,1]))) + pass if __name__ == '__main__':