+ 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])))
+
+ def testGetCellContainingPointOnPolyhedronWithPlanarFace(self):
+ """
+ See CEA spns #40783
+ In case of polyhedron with a face defined by several colinear points,
+ we must use other non colinear points to be able to define a face from these three points
+ to define the relative position of the test point to this face
+ """
+ eps = 1.0e-12
+ coo = DataArrayDouble( [ (0.176, 0.1125, 1.05),
+ (0.176, 0.120375, 1.05),
+ (0.176, 0.120375, 1.0),
+ (0.176, 0.1125, 1.0),
+ (0.176000000000000018, 0.12825, 1.05),
+ (0.176000000000000018, 0.12825, 1.0),
+ (0.207, 0.1125, 1.05),
+ (0.207, 0.1125, 1.0),
+ (0.207, 0.12825, 1.05),
+ (0.207, 0.12825, 1.0)] )
+
+ m = MEDCouplingUMesh("Mesh",3)
+ m.setCoords(coo)
+ m.allocateCells()
+ # put -1 to separate faces connectivity
+ # substract -1 from mdump table ids
+ m.insertNextCell(NORM_POLYHED,[0, 1, 2, 3, -1,
+ 1, 4, 5, 2, -1,
+ 6, 7, 9, 8, -1,
+ 3, 7, 6, 0, -1,
+ 9, 5, 4, 8, -1,
+ 3, 2, 5, 9, 7, -1, # PB in this order
+ #7, 3, 2, 5, 9, -1, # OK in this order
+ 1, 0, 6, 8, 4])
+
+ # test point inside the box
+ pt_above = (0.2, 0.12, 1.07)
+ pt_below = (0.2, 0.12, 0.9)
+ pt_inside = (0.2, 0.12, 1.025)
+ pts = DataArrayDouble([pt_above, pt_below, pt_inside])
+ a,b = m.getCellsContainingPoints(pts, eps)
+ self.assertTrue(a.isEqual(DataArrayInt([0])))
+ # only the third point is inside
+ self.assertTrue(b.isEqual(DataArrayInt([0,0,0,1])))
+
+ # rotate the mesh to see if getCellsContainingPoints works
+ # even if point is not inside bounding box
+ center=coo[0]
+ vector=[1.,0.,0.]
+ m.rotate(center,vector,-pi/4.);
+
+ # test 3 points: above, below and inside
+ pt_above = (0.19, 0.09, 1.04)
+ pt_below = (0.19, 0.11, 1.02)
+ pt_inside = (0.19, 0.10, 1.02)
+ pts_rotated = DataArrayDouble([pt_above, pt_below, pt_inside])
+
+ a,b = m.getCellsContainingPoints(pts_rotated, eps)
+ self.assertTrue(a.isEqual(DataArrayInt([0])))
+ # only the third point is inside
+ self.assertTrue(b.isEqual(DataArrayInt([0,0,0,1])))
+
+ def testGetCellContainingPointOnPolyhedronWithPlanarFaceWithManyNodes(self):
+ """
+ Similar test with many colinear nodes on the planar face
+ """
+ eps = 1.0e-12
+ coo = DataArrayDouble( [(0.176000000000000018, 0.120375, 1.0 ),
+ (0.176000000000000018, 0.128250, 1.0 ),
+ (0.176000000000000018, 0.136125, 1.0 ),
+ (0.176000000000000018, 0.144, 1.0 ),
+ (0.176000000000000018, 0.151875, 1.0 ),
+ (0.176000000000000018, 0.159750, 1.0 ),
+ (0.176000000000000018, 0.167625, 1.0 ),
+ (0.176000000000000018, 0.1755, 1.0 ),
+ (0.176000000000000018, 0.183375, 1.0 ),
+ (0.176000000000000018, 0.191250, 1.0 ),
+ (0.176000000000000018, 0.199125, 1.0 ),
+ (0.176, 0.207, 1.0 ),
+ (0.207, 0.207, 1.0 ),
+ (0.176, 0.1125, 1.0 ),
+ (0.207, 0.1125, 1.0 ),
+ (0.176, 0.120375, 1.05),
+ (0.176000000000000018, 0.128250, 1.05),
+ (0.176000000000000018, 0.136125, 1.05),
+ (0.176000000000000018, 0.144, 1.05),
+ (0.176000000000000018, 0.151875, 1.05),
+ (0.176000000000000018, 0.159750, 1.05),
+ (0.176000000000000018, 0.167625, 1.05),
+ (0.176000000000000018, 0.1755, 1.05),
+ (0.176000000000000018, 0.183375, 1.05),
+ (0.176000000000000018, 0.191250, 1.05),
+ (0.176000000000000018, 0.199125, 1.05),
+ (0.176, 0.207, 1.05),
+ (0.207, 0.207, 1.05),
+ (0.176, 0.1125, 1.05),
+ (0.207, 0.1125, 1.05)])
+
+ m = MEDCouplingUMesh("Mesh",3)
+ m.setCoords(coo)
+ m.allocateCells()
+ # put -1 to separate faces connectivity
+ # substract -1 from mdump table ids
+ m.insertNextCell(NORM_POLYHED,
+ [13, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, -1, #1
+ 29, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 28, -1, #2
+ 14, 29, 28, 13, -1, #3
+ 11, 26, 27, 12, -1, #4
+ 12, 27, 29, 14, -1, #5
+ 13, 28, 15, 0, -1, #6
+ 0, 15, 16, 1, -1, #7
+ 1, 16, 17, 2, -1, #8
+ 2, 17, 18, 3, -1, #9
+ 3, 18, 19, 4, -1, #10
+ 4, 19, 20, 5, -1, #11
+ 5, 20, 21, 6, -1, #12
+ 6, 21, 22, 7, -1, #13
+ 7, 22, 23, 8, -1, #14
+ 8, 23, 24, 9, -1, #15
+ 9, 24, 25, 10, -1, #16
+ 10, 25, 26, 11] )
+
+ ##### See CEA 40783: error with polyhedrons (box split by on edge on its face)
+ pt_above = (0.1915, 0.15975, 1.07)
+ pt_below = (0.1915, 0.15975, 0.9)
+ pt_inside = (0.1915, 0.15975, 1.025)
+ pts = DataArrayDouble([pt_above, pt_below, pt_inside])
+ a,b = m.getCellsContainingPoints(pts,eps)
+ self.assertTrue(a.isEqual(DataArrayInt([0])))
+ # only the third point is inside
+ self.assertTrue(b.isEqual(DataArrayInt([0,0,0,1])))
+