+ def testSwig2IsPartStructured1(self):
+ #dim 1
+ d10=DataArrayInt([2,3,4,5,6,7,8,9,10,11])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d10,[13])
+ self.assertTrue(a) ; self.assertEqual(b,[(2,12)])
+ d11=DataArrayInt([2,3,4,5,6,7,8,10,9,11])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d11,[13])
+ self.assertTrue(not a)
+ self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d10,[11])
+ #dim 2
+ st=[10,4]
+ d20=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+ self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,3)])
+ d20=DataArrayInt([1,2,3,4,12,11,13,14,21,22,23,24])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+ self.assertTrue(not a)
+ d20=DataArrayInt([1,2,3,4,11,12,13,15,21,22,23,24])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d20,st)
+ self.assertTrue(not a)
+ d21=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d21,st)
+ self.assertTrue(a) ; self.assertEqual(b,[(0,10),(0,4)])
+ d22=DataArrayInt([1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44])
+ self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d22,st)
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d22,[10,5])
+ self.assertTrue(a) ; self.assertEqual(b,[(1,5),(0,5)])
+ #dim 3
+ d30=DataArrayInt([11,12,13,14,21,22,23,24,51,52,53,54,61,62,63,64])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d30,[10,4,2])
+ self.assertTrue(a) ; self.assertEqual(b,[(1,5),(1,3),(0,2)])
+ d31=DataArrayInt([11,12,13,14,21,22,24,23,51,52,53,54,61,62,63,64])
+ a,b=MEDCouplingStructuredMesh.IsPartStructured(d31,[10,4,2])
+ self.assertTrue(not a)
+ self.assertRaises(InterpKernelException,MEDCouplingStructuredMesh.IsPartStructured,d30,[10,4,1])
+ pass
+
+ def testSwig2PartStructured1(self):
+ c=MEDCouplingCMesh() ; c.setName("toto")
+ arr0=DataArrayDouble(10); arr0.iota()
+ arr1=DataArrayDouble(4) ; arr1.iota(3)
+ c.setCoords(arr0,arr1)
+ self.assertEqual(c.getNodeGridStructure(),(10,4))
+ self.assertEqual(c.getCellGridStructure(),(9,3))
+ d20=DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])
+ self.assertEqual(27,c.getNumberOfCells())
+ self.assertEqual(40,c.getNumberOfNodes())
+ self.assertEqual(2,c.getMeshDimension())
+ c.checkCoherency()
+ #
+ arr2=MEDCouplingStructuredMesh.BuildExplicitIdsFrom([9,3],[(1,5),(0,3)])
+ self.assertTrue(arr2.isEqual(DataArrayInt([1,2,3,4,10,11,12,13,19,20,21,22])))
+ # CMesh
+ c2=c.buildStructuredSubPart([(1,5),(0,3)])
+ c2.checkCoherency()
+ self.assertTrue(isinstance(c2,MEDCouplingCMesh))
+ self.assertEqual(12,c2.getNumberOfCells())
+ self.assertEqual(20,c2.getNumberOfNodes())
+ self.assertEqual(2,c2.getMeshDimension())
+ self.assertEqual("toto",c2.getName())
+ self.assertTrue(c2.getCoordsAt(0).isEqual(DataArrayDouble([1.,2.,3.,4.,5.]),1e-12))
+ self.assertTrue(c2.getCoordsAt(1).isEqual(DataArrayDouble([3.,4.,5.,6.]),1e-12))
+ #
+ a,b=c.buildPartAndReduceNodes(d20)
+ a.checkCoherency()
+ exp2=DataArrayInt([-1,0,1,2,3,4,-1,-1,-1,-1,-1,5,6,7,8,9,-1,-1,-1,-1,-1,10,11,12,13,14,-1,-1,-1,-1,-1,15,16,17,18,19,-1,-1,-1,-1])
+ self.assertTrue(exp2.isEqual(b))
+ self.assertTrue(isinstance(a,MEDCouplingCMesh))
+ self.assertTrue(a.buildUnstructured().isEqual(c.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
+ # CurveLinearMesh
+ c2=MEDCouplingCurveLinearMesh() ; c2.setName("toto")
+ c2.setCoords(c.buildUnstructured().getCoords())
+ c2.setNodeGridStructure([10,4])
+ c2.checkCoherency()
+ a,b=c2.buildPartAndReduceNodes(d20)
+ a.checkCoherency()
+ self.assertTrue(exp2.isEqual(b))
+ self.assertTrue(isinstance(a,MEDCouplingCurveLinearMesh))
+ self.assertTrue(a.buildUnstructured().isEqual(c2.buildUnstructured().buildPartAndReduceNodes(d20)[0],1e-12))
+ pass
+
+ def testSwig2FindPermutationFromFirstToSecond1(self):
+ ids1=DataArrayInt([3,1,103,4,6,10,-7,205])
+ ids2=DataArrayInt([-7,1,205,10,6,3,103,4])
+ ids3=DataArrayInt.FindPermutationFromFirstToSecond(ids1,ids2)
+ self.assertTrue(ids3.isEqual(DataArrayInt([5,1,6,7,4,3,0,2])))
+ ids2ToTest=ids1.renumber(ids3)
+ self.assertTrue(ids2ToTest.isEqual(ids2))
+ self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103]))
+ self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103,2]))
+ self.assertRaises(InterpKernelException,DataArrayInt.FindPermutationFromFirstToSecond,DataArrayInt([3,1,103]),DataArrayInt([1,103,1]))
+ self.assertTrue(DataArrayInt.FindPermutationFromFirstToSecond(DataArrayInt([]),DataArrayInt([])).empty())
+ pass
+
+ def testSwig2BugStructuredMeshGetNodeIdsOfCell1(self):
+ m=MEDCouplingCMesh("mesh")
+ coordsX=DataArrayDouble([0,1.1,2.2,3.3,4.4]) ; coordsX.setInfoOnComponents(["XX [m]"])
+ coordsY=DataArrayDouble([0,1.7,3.4]) ; coordsY.setInfoOnComponents(["YYY [km]"])
+ m.setCoords(coordsX,coordsY)
+ self.assertEqual([2,3,8,7],m.getNodeIdsOfCell(2))
+ self.assertEqual([3,4,9,8],m.getNodeIdsOfCell(3))
+ self.assertEqual([7,8,13,12],m.getNodeIdsOfCell(6))
+ self.assertEqual([8,9,14,13],m.getNodeIdsOfCell(7))
+ pass
+
+ def testSwig2ThrowOnDAIInvertN2O2ON2(self):
+ p1=DataArrayInt([3,5,8])
+ p2=DataArrayInt([0,3,4,5,6,7,8,9,10])
+ p1.transformWithIndArr(p2.invertArrayN2O2O2N(11))
+ self.assertTrue(p1.isEqual(DataArrayInt([1,3,6])))
+ self.assertTrue(p2.invertArrayN2O2O2N(11).isEqual(DataArrayInt([0,-1,-1,1,2,3,4,5,6,7,8])))
+ self.assertRaises(InterpKernelException,p2.invertArrayN2O2O2N,10)
+ pass
+
+ def testSwig2ComputeEffectiveNbOfNodesPerCell1(self):
+ coords=DataArrayDouble([ 0.241310763507 , 0.0504777305619 , 0.0682283524903 , 0.252501053866 , -0.0625176732937 , 0.137272639894 ,
+ 0.152262663601 , 0.241816569527 , 0.133812556197 , 0.18047750211 , -0.0789949051358 , 0.339098173401 ,
+ 0.151741971857 , 0.238885278571 , 0.137715037333 , 0.242532155481 , -0.0928169086456 , 0.0678043417367 ,
+ 0.240941965335 , -0.015461491464 , 0.0617186345825 , 0.24127650112 , 0.0499427876717 , 0.0679634099148 ,
+ -0.145828917428 , 0.206291632565 , 0.0310071927543 , 0.0125651775307 , 0.266262085828 , 0.105228430543 ,
+ -0.0994066533286 , 0.233224271238 , 0.0572213839567 , -0.0951345338317 , 0.234819509426 , 0.0592126284538 ,
+ 0.136580574205 , -0.205486212579 , 0.0572866072014 , 0.0637270784978 , -0.168886355238 , 0.446614057077 ,
+ 0.041337157151 , -0.213402568198 , 0.372407095999 , 0.0411601970268 , -0.202387875756 , 0.411334979491 ,
+ -0.108355701857 , 0.193636239335 , 0.204886756738 , 0.00639779029829 , 0.155296981517 , 0.252585892979 ,
+ 0.0262473111702 , -0.112919732543 , 0.424286639249 ,-0.224103052733 , -0.139430015438 , -0.0122352295701 ,
+ -0.0312760589481 , -0.274272003594 , 0.0323959636568 , -0.166663422532 , -0.217754445175 , 0.00392109070364 ,
+ -0.30586619777 , -0.0475168041091 , -0.0144585228182 , -0.280881480586 , 0.135571293538 , 0.00623923647986 ,
+ -0.25548538234 , 0.156819217766 , 0.0645277879769 , -0.131567009284 , 0.184133752309 , 0.206021802753 ,
+ -0.196204010965 , 0.151602971681 , 0.212974777736 , -0.183713879463 , 0.0802946639531 , 0.260115662599 ,
+ -0.244241178767 , -0.0738873389604 , 0.144590565817 , -0.155804057829 , -0.164892720025 , 0.210613950558 ,
+ -0.170950800428 , -0.215099334026 , 0.00610122860092 , -0.30552634869 , -0.0490020791904 , -0.0132786533145 ,
+ 0.271831011884 , 0.15105657296 , 0.0230534827908 , 0.281919192283 , 0.0898544306288 , -0.0625201489143 ,
+ 0.260240727276 , -0.0120688706637 , -0.0532316588626 , 0.244947737722 , 0.0197984684293 , 0.0309341209233 ,
+ 0.23439631578 , 0.229825279875 , 0.0508520585381 , 0.160921316875 , 0.265078502128 , 0.121716560626 ,
+ -0.315088694175 , 0.0747700471918 , -0.245836615071 , -0.327728781776 , 0.0857114674649 , -0.239431905957 ,
+ -0.308385460634 , 0.145142997084 , -0.149886828433 , 0.0488236045164 , 0.309462801914 , 0.0849169148265 ,
+ -0.0244964803395 , 0.33145611751 , -0.0476415818061 , 0.0060567994229 , 0.32418412014 , 0.0367779543812 ,
+ -0.0950221448063 , 0.236675326003 , 0.0572594453983 , 0.248723023186 , 0.0886648784791 , -0.176629430538 ,
+ 0.116796984 , 0.256596599567 , -0.292863523603 , 0.118024552914 , 0.229154257843 , -0.34233232501 ,
+ 0.217507892549 , -0.0417822335742 , -0.176771782888 , -0.224429321304 , 0.0125595300114 , -0.362064725588 ,
+ 0.0937301100955 , -0.0500824832657 , -0.299713548444 , -0.244162220397 , 0.0383853931293 , -0.389856984411 ,
+ -0.0281989366102 , 0.097392811563 , -0.458244577284 , -0.385010847162 , 0.10122766194 , -0.140052859922 ,
+ -0.377936358012 , 0.110875172128 , -0.176207095463 , 0.244483045556 , -0.0991073977045 , 0.0575134372934 ,
+ 0.262605120167 , -0.100243191645 , -0.0495620806935 , 0.240306880972 , -0.136153701579 , -0.114745281696 ,
+ 0.215763176129 , -0.0836766059189 , -0.183249640616 , 0.237870396603 , -0.132449578286 , -0.121598854639 ,
+ -0.0637683083097 , -0.27921020214 , -0.149112321992 , -0.0856211014977 , -0.2973233473 , -0.0446878139589 ,
+ 0.104675342288 , -0.0625908305324 , -0.290346256534 , 0.0248264249186 , -0.247797708548 , -0.165830884019 ,
+ 0.0719302438309 , -0.178468260473 , -0.211432157345 , 0.142871843159 , -0.208769948542 , 0.0454101128246 ,
+ 0.167803379307 , -0.207851396623 , -0.088802726124 , 0.12868717152 , -0.230920439715 , 0.00760508389036 ,
+ -0.0372812069535 , -0.286740286332 , 0.00963701291166 ], 69, 3)
+ connN = [ #polyhedron 0
+ 0 , 1 , 3 , 4 , 2 , -1 , 1 , 5 , 6 , 7 , 0 , -1 , 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 1 , 5 , 12 , 14 , 15 , 13 , 3 , -1 , 16 , 9 , 2 , 4 , 17 , -1
+ , 4 , 3 , 13 , 18 , 17 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1 , 6 , 7 , 8 , 23 , 22 , 19 , -1 , 23 , 24 , 10 , 8 , -1 , 25 , 11 , 9 , 16 , -1
+ , 24 , 26 , 25 , 11 , 10 , -1 , 12 , 14 , 20 , -1 , 27 , 28 , 29 , 15 , 13 , 18 , -1 , 14 , 15 , 29 , 30 , 21 , 20 , -1 , 26 , 27 , 18 , 17 , 16 , 25 , -1
+ , 22 , 19 , 21 , 30 , 31 , -1 , 22 , 31 , 28 , 27 , 26 , 24 , 23 , -1 , 31 , 30 , 29 , 28,
+ # polyhedron 1
+ 0 , 7 , 8 , 10 , 11 , 9 , 2 , -1 , 32 , 0 , 7 , 35 , 34 , 33 , -1 , 32 , 0 , 2 , 37 , 36 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1
+ , 2 , 37 , 41 , 9 , -1 , 40 , 8 , 10 , 44 , 43 , 42 , -1 , 41 , 9 , 11 , 44 , 43 , -1 , 44 , 11 , 10 , -1 , 32 , 33 , 45 , 47 , 46 , 36 , -1
+ , 33 , 34 , 48 , 45 , -1 , 35 , 34 , 48 , 50 , 49 , 38 , -1 , 41 , 43 , 42 , 46 , 36 , 37 , -1 , 38 , 39 , 51 , 49 , -1
+ , 39 , 40 , 42 , 46 , 47 , 52 , 51 , -1 , 45 , 47 , 52 , 50 , 48 , -1 , 52 , 51 , 49 , 50,
+ # polyhedron 2
+ 6 , 7 , 8 , 23 , 22 , 19 , -1 , 6 , 35 , 7 , -1 , 6 , 35 , 38 , 19 , -1 , 35 , 7 , 8 , 40 , 39 , 38 , -1 , 53 , 22 , 19 , 38 , 39 , 54 , -1
+ , 23 , 53 , 54 , 40 , 8 , -1 , 53 , 22 , 23 , -1 , 39 , 54 , 40,
+ # polyhedron 3
+ 35 , 34 , 48 , 50 , 49 , 38 , -1 , 6 , 35 , 34 , 56 , 55 , 5 , -1 , 6 , 35 , 38 , 19 , -1 , 34 , 56 , 57 , 59 , 58 , 48 , -1
+ , 60 , 61 , 21 , 19 , 38 , 49 , -1 , 62 , 50 , 48 , 58 , -1 , 60 , 63 , 64 , 62 , 50 , 49 , -1 , 5 , 6 , 19 , 21 , 20 , 12 , -1
+ , 55 , 5 , 12 , 65 , -1 , 66 , 67 , 65 , 55 , 56 , 57 , -1 , 63 , 66 , 57 , 59 , 64 , -1 , 64 , 62 , 58 , 59 , -1
+ , 60 , 63 , 66 , 67 , 68 , 61 , -1 , 61 , 68 , 20 , 21 , -1 , 67 , 68 , 20 , 12 , 65]
+ meshN=MEDCouplingUMesh.New()
+ meshN.setName("ForBary")
+ meshN.setMeshDimension(3) ; meshN.setCoords(coords)
+ meshN.allocateCells(4)
+ meshN.insertNextCell(NORM_POLYHED,113,connN);
+ meshN.insertNextCell(NORM_POLYHED,99,connN[113:])
+ meshN.insertNextCell(NORM_POLYHED,43,connN[212:])
+ meshN.insertNextCell(NORM_POLYHED,92,connN[255:])
+ d=meshN.computeEffectiveNbOfNodesPerCell()
+ e=meshN.computeNbOfNodesPerCell()
+ self.assertTrue(d.isEqual(DataArrayInt([32,28,12,26])))
+ self.assertTrue(e.isEqual(DataArrayInt([96,84,36,78])))
+ m0=MEDCoupling1DGTUMesh(meshN)
+ c=MEDCouplingCMesh()
+ arr=DataArrayDouble(3) ; arr.iota(10)
+ c.setCoords(arr,arr,arr)
+ m10=c.buildUnstructured()
+ m11=c.build1SGTUnstructured()
+ m12=MEDCoupling1SGTUMesh.New(m10)
+ self.assertTrue(m12.isEqual(m11,1e-12))
+ m12.setCoords(m0.getCoords()) # m12 is not OK geometrically but the aim of the test is only connectivity values
+ m3=MEDCoupling1GTUMesh.AggregateOnSameCoordsToUMesh([m12,m0])
+ m3.checkCoherency()
+ self.assertEqual(m3.getCoords().getHiddenCppPointer(),m12.getCoords().getHiddenCppPointer())
+ self.assertTrue(m3.getNodalConnectivity().isEqual(DataArrayInt([18,1,0,3,4,10,9,12,13,18,2,1,4,5,11,10,13,14,18,4,3,6,7,13,12,15,16,18,5,4,7,8,14,13,16,17,18,10,9,12,13,19,18,21,22,18,11,10,13,14,20,19,22,23,18,13,12,15,16,22,21,24,25,18,14,13,16,17,23,22,25,26,31,0,1,3,4,2,-1,1,5,6,7,0,-1,0,7,8,10,11,9,2,-1,1,5,12,14,15,13,3,-1,16,9,2,4,17,-1,4,3,13,18,17,-1,5,6,19,21,20,12,-1,6,7,8,23,22,19,-1,23,24,10,8,-1,25,11,9,16,-1,24,26,25,11,10,-1,12,14,20,-1,27,28,29,15,13,18,-1,14,15,29,30,21,20,-1,26,27,18,17,16,25,-1,22,19,21,30,31,-1,22,31,28,27,26,24,23,-1,31,30,29,28,31,0,7,8,10,11,9,2,-1,32,0,7,35,34,33,-1,32,0,2,37,36,-1,35,7,8,40,39,38,-1,2,37,41,9,-1,40,8,10,44,43,42,-1,41,9,11,44,43,-1,44,11,10,-1,32,33,45,47,46,36,-1,33,34,48,45,-1,35,34,48,50,49,38,-1,41,43,42,46,36,37,-1,38,39,51,49,-1,39,40,42,46,47,52,51,-1,45,47,52,50,48,-1,52,51,49,50,31,6,7,8,23,22,19,-1,6,35,7,-1,6,35,38,19,-1,35,7,8,40,39,38,-1,53,22,19,38,39,54,-1,23,53,54,40,8,-1,53,22,23,-1,39,54,40,31,35,34,48,50,49,38,-1,6,35,34,56,55,5,-1,6,35,38,19,-1,34,56,57,59,58,48,-1,60,61,21,19,38,49,-1,62,50,48,58,-1,60,63,64,62,50,49,-1,5,6,19,21,20,12,-1,55,5,12,65,-1,66,67,65,55,56,57,-1,63,66,57,59,64,-1,64,62,58,59,-1,60,63,66,67,68,61,-1,61,68,20,21,-1,67,68,20,12,65])))
+ self.assertTrue(m3.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,18,27,36,45,54,63,72,186,286,330,423])))
+ pass
+
+ def testSwig2Tetrahedrize1(self):
+ d=DataArrayInt([0,3,6,10,14,20])
+ d2=d.buildExplicitArrOfSliceOnScaledArr(slice(0,5,2))
+ self.assertTrue(d2.isEqual(DataArrayInt([0,0,0, 2,2,2,2, 4,4,4,4,4,4])))
+ m=MEDCouplingUMesh("Penta6",3)
+ m.setCoords(DataArrayDouble([0,0,0,0,1,0,1,0,0,0,0,2,0,1,2,1,0,2],6,3)) ; m.getCoords().setInfoOnComponents(["X","YY","ZZZ"])
+ m.allocateCells()
+ m.insertNextCell(NORM_PENTA6,[1,2,0,4,5,3])
+ st=m.getCoords().getHiddenCppPointer()
+ c,a,b=m.tetrahedrize(PLANAR_FACE_5)
+ c.checkCoherency2()
+ self.assertTrue(a.isEqual(DataArrayInt([0,0,0])))
+ self.assertEqual(0,b)
+ self.assertEqual(m.getCoords().getHiddenCppPointer(),c.getCoords().getHiddenCppPointer())
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([1,2,0,4,4,3,5,0,5,0,2,4])))
+ del m,c
+ #
+ m2=MEDCouplingUMesh("octa12",3)
+ coords=DataArrayDouble([1.,0.,0.,0.5,0.8660254037844386,0.,-0.5,0.8660254037844387,0.,-1.,1.2246467991473532e-16,0.,-0.5,-0.8660254037844384,0.,0.5,-0.866025403784439,0.,1.,0.,2.,0.5,0.8660254037844386,2.,-0.5,0.8660254037844387,2.,-1.,1.2246467991473532e-16,2.,-0.5,-0.8660254037844384,2.,0.5,-0.866025403784439,2.0],12,3)
+ m2.setCoords(coords)
+ m2.allocateCells()
+ m2.insertNextCell(NORM_HEXGP12,[3,2,1,0,5,4,9,8,7,6,11,10])
+ c,a,b=m2.tetrahedrize(PLANAR_FACE_5)
+ c.checkCoherency2()
+ self.assertTrue(a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0])))
+ self.assertEqual(0,b)
+ self.assertEqual(c.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,4,9,9,10,8,4,8,4,2,9,2,5,4,8,8,10,11,4,11,4,5,8,2,1,5,8,8,11,7,5,7,5,1,8,1,0,5,7,7,11,6,5,6,5,0,7])))
+ del m2,coords,c
+ #
+ coords=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.],8,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
+ m3=MEDCouplingUMesh("hexa8",3)
+ m3.setCoords(coords)
+ m3.allocateCells(0)
+ m3.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
+ st=m3.getCoords().getHiddenCppPointer()
+ c,a,b=m3.tetrahedrize(PLANAR_FACE_5)
+ c.checkCoherency2()
+ a.isEqual(DataArrayInt([0,0,0,0,0]))
+ self.assertEqual(0,b)
+ self.assertEqual(m3.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,6,2,1,3,7,6,4,3,0,4,1,6,4,5,1,3,6,1,4])))
+ #
+ m4=MEDCouplingUMesh("hexa8",3)
+ m4.setCoords(coords)
+ m4.allocateCells(0)
+ m4.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
+ c,a,b=m4.tetrahedrize(PLANAR_FACE_6)
+ c.checkCoherency2()
+ a.isEqual(DataArrayInt([0,0,0,0,0,0]))
+ self.assertEqual(0,b)
+ self.assertEqual(c.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,6,2,5,3,2,1,5,3,7,6,5,3,4,7,5,3,1,0,5,3,0,4,5])))
+ #
+ m4=MEDCouplingUMesh("hexa8",3)
+ m4.setCoords(coords)
+ m4.allocateCells(0)
+ m4.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
+ st=m4.getCoords().getHiddenCppPointer()
+ c,a,b=m4.tetrahedrize(GENERAL_24)
+ c.checkCoherency2()
+ a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
+ self.assertEqual(7,b)
+ self.assertTrue(c.getCoords().getHiddenCppPointer()!=coords.getHiddenCppPointer())
+ self.assertTrue(c.getCoords()[:8].isEqual(coords,0))
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,7,8,14,7,6,8,14,6,2,8,14,2,3,8,14,3,2,9,14,2,1,9,14,1,0,9,14,0,3,9,14,3,0,10,14,0,4,10,14,4,7,10,14,7,3,10,14,2,6,11,14,6,5,11,14,5,1,11,14,1,2,11,14,7,4,12,14,4,5,12,14,5,6,12,14,6,7,12,14,1,5,13,14,5,4,13,14,4,0,13,14,0,1,13,14])))
+ m4CoordsExp=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.,0.5,1.,1.,0.5,0.5,0.,0.,0.5,1.,1.,0.5,1.,0.5,0.5,2.,0.5,0.,1.,0.5,0.5,1.],15,3)
+ m4CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
+ self.assertTrue(c.getCoords().isEqual(m4CoordsExp,1e-12))
+ self.assertAlmostEqual(2.,c.getMeasureField(False).accumulate()[0],12)
+ #
+ m6=MEDCouplingUMesh("hexa8",3)
+ m6.setCoords(coords)
+ m6.allocateCells(0)
+ m6.insertNextCell(NORM_HEXA8,[3,2,1,0,7,6,5,4])
+ st=m6.getCoords().getHiddenCppPointer()
+ c,a,b=m6.tetrahedrize(GENERAL_48)
+ c.checkCoherency2()
+ a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
+ self.assertEqual(19,b)
+ self.assertTrue(c.getCoords().getHiddenCppPointer()!=coords.getHiddenCppPointer())
+ self.assertTrue(c.getCoords()[:8].isEqual(coords,0))
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,20,8,26,3,8,21,26,3,9,20,26,3,22,9,26,3,21,12,26,3,12,22,26,8,10,2,23,8,2,13,23,8,20,10,23,8,26,20,23,8,13,21,23,8,21,26,23,12,26,21,25,12,21,16,25,12,22,26,25,12,17,22,25,12,16,0,25,12,0,17,25,21,23,13,18,21,13,1,18,21,26,23,18,21,25,26,18,21,1,16,18,21,16,25,18,9,11,20,24,9,20,26,24,9,7,11,24,9,14,7,24,9,26,22,24,9,22,14,24,20,6,10,15,20,10,23,15,20,11,6,15,20,24,11,15,20,23,26,15,20,26,24,15,22,24,26,19,22,26,25,19,22,14,24,19,22,4,14,19,22,25,17,19,22,17,4,19,26,15,23,5,26,23,18,5,26,24,15,5,26,19,24,5,26,18,25,5,26,25,19,5])))
+ m6CoordsExp=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.,0.5,1.,0.,0.,1.,1.,1.,1.,1.,0.5,1.,2.,0.,0.5,0.,1.,0.5,0.,0.,0.5,2.,1.,0.5,2.,0.5,0.,0.,0.,0.,1.,1.,0.,1.,0.5,0.,2.,0.5,1.,1.,0.5,0.5,0.,0.,0.5,1.,1.,0.5,1.,0.5,0.5,2.,0.5,0.,1.,0.5,0.5,1.],27,3)
+ m6CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
+ self.assertTrue(c.getCoords().isEqual(m6CoordsExp,1e-12))
+ self.assertAlmostEqual(2.,c.getMeasureField(False).accumulate()[0],12)
+ #
+ m7=MEDCouplingUMesh("polyhed",3)
+ coords=DataArrayDouble([1.,0.,0.,0.5,0.8660254037844386,0.,-0.5,0.8660254037844387,0.,-1.,0.,0.,-0.5,-0.8660254037844384,0.,0.5,-0.866025403784439,0.,1.,0.,2.,0.5,0.8660254037844386,2.,-0.5,0.8660254037844387,2.,-1.,0.,2.,-0.5,-0.8660254037844384,2.,0.5,-0.866025403784439,2.0],12,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
+ m7.setCoords(coords)
+ m7.allocateCells()
+ m7.insertNextCell(NORM_POLYHED,[3,2,1,0,5,4,-1,9,10,11,6,7,8,-1,3,9,8,2,-1,2,8,7,1,-1,1,7,6,0,-1,0,6,11,5,-1,5,11,10,4,-1,4,10,9,3])
+ c,a,b=m7.tetrahedrize(PLANAR_FACE_5)
+ c.checkCoherency2()
+ self.assertTrue(a.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])))
+ self.assertEqual(9,b)
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,12,20,2,1,12,20,1,0,12,20,0,5,12,20,5,4,12,20,4,3,12,20,9,10,13,20,10,11,13,20,11,6,13,20,6,7,13,20,7,8,13,20,8,9,13,20,3,9,14,20,9,8,14,20,8,2,14,20,2,3,14,20,2,8,15,20,8,7,15,20,7,1,15,20,1,2,15,20,1,7,16,20,7,6,16,20,6,0,16,20,0,1,16,20,0,6,17,20,6,11,17,20,11,5,17,20,5,0,17,20,5,11,18,20,11,10,18,20,10,4,18,20,4,5,18,20,4,10,19,20,10,9,19,20,9,3,19,20,3,4,19,20])))
+ self.assertAlmostEqual(5.196152422706635,c.getMeasureField(False).accumulate()[0],12)
+ m7CoordsExp=DataArrayDouble([1.0,0.0,0.0,0.5,0.8660254037844386,0.0,-0.5,0.8660254037844387,0.0,-1.0,0.,0.0,-0.5,-0.8660254037844384,0.0,0.5,-0.866025403784439,0.0,1.0,0.0,2.0,0.5,0.8660254037844386,2.0,-0.5,0.8660254037844387,2.0,-1.0,0.,2.0,-0.5,-0.8660254037844384,2.0,0.5,-0.866025403784439,2.0,0.0,0.0,0.0,0.0,0.,2.0,-0.75,0.4330127018922194,1.0,0.0,0.8660254037844386,1.0,0.75,0.4330127018922193,1.0,0.75,-0.4330127018922195,1.0,0.0,-0.8660254037844387,1.0,-0.75,-0.4330127018922191,1.0,0.0,0.,1.0],21,3)
+ m7CoordsExp.setInfoOnComponents(["X","YY","ZZZ"])
+ self.assertTrue(c.getCoords().isEqual(m7CoordsExp,1e-12))
+ del m7,coords,c
+ #
+ coords=DataArrayDouble([0.,0.,0.,1.,0.,0.,1.,1.,0.,0.,1.,0.,0.,0.,2.,1.,0.,2.,1.,1.,2.,0.,1.,2.],8,3) ; coords.setInfoOnComponents(["X","YY","ZZZ"])
+ m8=MEDCouplingUMesh("pyra5",3)
+ m8.setCoords(coords)
+ m8.allocateCells(0)
+ m8.insertNextCell(NORM_PYRA5,[3,2,1,0,7])
+ st=m8.getCoords().getHiddenCppPointer()
+ c,a,b=m8.tetrahedrize(PLANAR_FACE_5)
+ self.assertEqual(m8.getCoords().getHiddenCppPointer(),coords.getHiddenCppPointer())
+ c.checkCoherency2()
+ self.assertTrue(a.isEqual(DataArrayInt([0,0])))
+ self.assertEqual(0,b)
+ self.assertTrue(c.getNodalConnectivity().isEqual(DataArrayInt([3,2,1,7,3,1,0,7])))
+ self.assertAlmostEqual(0.6666666666666667,c.getMeasureField(False).accumulate()[0],12)
+ pass
+
+ def testDualMesh3D1(self):
+ arr=DataArrayDouble(2) ; arr.iota()
+ c=MEDCouplingCMesh() ; c.setCoords(arr,arr,arr)
+ m=c.buildUnstructured()
+ t=m.tetrahedrize(PLANAR_FACE_5)[0]
+ d=t.computeDualMesh()
+ self.assertTrue(d.getNodalConnectivityIndex().isEqual(DataArrayInt([0,29,118,207,236,325,354,383,472])))
+ self.assertTrue(d.getNodalConnectivity().isEqual(DataArrayInt([26,11,42,8,-1,25,8,42,10,-1,29,10,42,11,-1,0,26,8,25,-1,0,25,10,29,-1,0,29,11,26,24,9,42,8,-1,26,8,42,11,-1,27,11,42,9,-1,1,24,8,26,-1,1,26,11,27,-1,30,13,43,12,-1,24,12,43,15,-1,32,15,43,13,-1,1,30,12,24,-1,1,32,13,30,-1,35,17,44,16,-1,32,16,44,19,-1,27,19,44,17,-1,1,35,16,32,-1,1,27,17,35,-1,24,15,46,9,-1,27,9,46,19,-1,32,19,46,15,27,9,42,11,-1,29,11,42,10,-1,28,10,42,9,-1,2,29,10,28,-1,2,27,11,29,-1,27,17,44,19,-1,38,19,44,18,-1,37,18,44,17,-1,2,37,17,27,-1,2,38,18,37,-1,28,21,45,23,-1,41,23,45,22,-1,38,22,45,21,-1,2,41,22,38,-1,2,28,23,41,-1,27,19,46,9,-1,28,9,46,21,-1,38,21,46,19,35,16,44,17,-1,36,18,44,16,-1,37,17,44,18,-1,3,36,16,35,-1,3,35,17,37,-1,3,37,18,36,24,8,42,9,-1,25,10,42,8,-1,28,9,42,10,-1,4,25,8,24,-1,4,28,10,25,-1,24,15,43,12,-1,31,12,43,14,-1,34,14,43,15,-1,4,24,12,31,-1,4,31,14,34,-1,34,21,45,20,-1,40,20,45,23,-1,28,23,45,21,-1,4,34,20,40,-1,4,40,23,28,-1,24,9,46,15,-1,28,21,46,9,-1,34,15,46,21,30,12,43,13,-1,31,14,43,12,-1,33,13,43,14,-1,5,31,12,30,-1,5,30,13,33,-1,5,33,14,31,40,23,45,20,-1,39,20,45,22,-1,41,22,45,23,-1,6,40,20,39,-1,6,39,22,41,-1,6,41,23,40,32,13,43,15,-1,34,15,43,14,-1,33,14,43,13,-1,7,33,13,32,-1,7,34,14,33,-1,32,19,44,16,-1,36,16,44,18,-1,38,18,44,19,-1,7,32,16,36,-1,7,36,18,38,-1,34,20,45,21,-1,39,22,45,20,-1,38,21,45,22,-1,7,39,20,34,-1,7,38,22,39,-1,32,15,46,19,-1,38,19,46,21,-1,34,21,46,15])))
+ self.assertTrue(d.getCoords().isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.,1.,1.,0.,0.,0.,1.,1.,0.,1.,0.,1.,1.,1.,1.,1.,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.3333333333333333,0.,0.6666666666666666,0.,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,1.,0.6666666666666666,0.3333333333333333,0.6666666666666666,1.,0.6666666666666666,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,0.3333333333333333,0.6666666666666666,1.,0.3333333333333333,0.6666666666666666,0.6666666666666666,0.3333333333333333,1.,0.6666666666666666,0.,0.6666666666666666,0.6666666666666666,0.5,0.,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.5,0.,0.,0.5,0.5,0.,0.5,0.,1.,0.,0.5,0.5,0.,1.,1.,0.5,0.5,1.,0.5,1.,0.5,0.5,1.,1.,0.5,0.,1.,1.,0.5,0.5,1.,0.,0.5,1.,0.5,0.5,1.,1.,0.,0.5,1.,0.,1.,0.5,0.25,0.25,0.25,0.75,0.25,0.75,0.75,0.75,0.25,0.25,0.75,0.75,0.5,0.5,0.5],47,3),1e-12))
+ self.assertAlmostEqual(1.,d.getMeasureField(False).accumulate()[0],1e-13)
+ pass
+
+ def testDualMesh2D1(self):
+ arr=DataArrayDouble(5) ; arr.iota()
+ c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
+ m=c.buildUnstructured()
+ m.simplexize(0)
+ t=MEDCoupling1SGTUMesh(m)
+ d=t.computeDualMesh()
+ self.assertTrue(d.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,12,20,28,34,42,54,66,78,86,94,106,118,130,138,146,158,170,182,190,196,204,212,220,224])))
+ self.assertTrue(d.getNodalConnectivity().isEqual(DataArrayInt([26,81,25,0,25,81,27,82,29,83,30,1,30,83,31,84,33,85,34,2,34,85,35,86,37,87,38,3,38,87,39,88,41,4,27,81,26,5,42,89,28,82,29,82,28,89,43,90,45,91,32,84,31,83,33,84,32,91,46,92,48,93,36,86,35,85,37,86,36,93,49,94,51,95,40,88,39,87,41,88,40,95,52,96,54,9,43,89,42,10,55,97,44,90,45,90,44,97,56,98,58,99,47,92,46,91,48,92,47,99,59,100,61,101,50,94,49,93,51,94,50,101,62,102,64,103,53,96,52,95,54,96,53,103,65,104,67,14,56,97,55,15,68,105,57,98,58,98,57,105,69,106,71,107,60,100,59,99,61,100,60,107,72,108,74,109,63,102,62,101,64,102,63,109,75,110,77,111,66,104,65,103,67,104,66,111,78,112,80,19,69,105,68,20,70,106,71,106,70,21,73,108,72,107,74,108,73,22,76,110,75,109,77,110,76,23,79,112,78,111,80,112,79,24])))
+ self.assertTrue(d.getCoords().isEqual(DataArrayDouble([0.,0.,1.,0.,2.,0.,3.,0.,4.,0.,0.,1.,1.,1.,2.,1.,3.,1.,4.,1.,0.,2.,1.,2.,2.,2.,3.,2.,4.,2.,0.,3.,1.,3.,2.,3.,3.,3.,4.,3.,0.,4.,1.,4.,2.,4.,3.,4.,4.,4.,0.5,0.,0.,0.5,0.5,0.5,0.5,1.,1.,0.5,1.5,0.,1.5,0.5,1.5,1.,2.,0.5,2.5,0.,2.5,0.5,2.5,1.,3.,0.5,3.5,0.,3.5,0.5,3.5,1.,4.,0.5,0.,1.5,0.5,1.5,0.5,2.,1.,1.5,1.5,1.5,1.5,2.,2.,1.5,2.5,1.5,2.5,2.,3.,1.5,3.5,1.5,3.5,2.,4.,1.5,0.,2.5,0.5,2.5,0.5,3.,1.,2.5,1.5,2.5,1.5,3.,2.,2.5,2.5,2.5,2.5,3.,3.,2.5,3.5,2.5,3.5,3.,4.,2.5,0.,3.5,0.5,3.5,0.5,4.,1.,3.5,1.5,3.5,1.5,4.,2.,3.5,2.5,3.5,2.5,4.,3.,3.5,3.5,3.5,3.5,4.,4.,3.5,0.3333333333333333,0.3333333333333333,0.6666666666666666,0.6666666666666666,1.3333333333333333,0.3333333333333333,1.6666666666666665,0.6666666666666666,2.333333333333333,0.3333333333333333,2.6666666666666665,0.6666666666666666,3.333333333333333,0.3333333333333333,3.6666666666666665,0.6666666666666666,0.3333333333333333,1.3333333333333333,0.6666666666666666,1.6666666666666665,1.3333333333333333,1.3333333333333333,1.6666666666666665,1.6666666666666665,2.333333333333333,1.3333333333333333,2.6666666666666665,1.6666666666666665,3.333333333333333,1.3333333333333333,3.6666666666666665,1.6666666666666665,0.3333333333333333,2.333333333333333,0.6666666666666666,2.6666666666666665,1.3333333333333333,2.333333333333333,1.6666666666666665,2.6666666666666665,2.333333333333333,2.333333333333333,2.6666666666666665,2.6666666666666665,3.333333333333333,2.333333333333333,3.6666666666666665,2.6666666666666665,0.3333333333333333,3.333333333333333,0.6666666666666666,3.6666666666666665,1.3333333333333333,3.333333333333333,1.6666666666666665,3.6666666666666665,2.333333333333333,3.333333333333333,2.6666666666666665,3.6666666666666665,3.333333333333333,3.333333333333333,3.6666666666666665,3.6666666666666665],113,2),1e-12))
+ self.assertAlmostEqual(16.,d.getMeasureField(False).accumulate()[0],1e-13)
+ pass
+
+ def testSwig2LoadBalanceBBox1(self):
+ arr=DataArrayDouble(5) ; arr.iota()
+ t=MEDCouplingCMesh() ; t.setCoords(arr,arr)
+ arr=DataArrayDouble(16) ; arr.iota() ; arr*=2./15
+ s=MEDCouplingCMesh() ; s.setCoords(arr,arr[:]) ; s.translate([2.,1.])
+ #
+ s1=s.build1SGTUnstructured()
+ t1=t.build1SGTUnstructured()
+ w=MEDCouplingPointSet.ComputeNbOfInteractionsWithSrcCells(s1,t1,1e-12)
+ wExp=DataArrayInt([0,0,0,0,0,0,64,64,0,0,64,64,0,0,0,0])
+ self.assertTrue(w.isEqual(wExp))
+ slcs=w.splitInBalancedSlices(4)
+ self.assertEqual(len(slcs),4)
+ self.assertEqual(slcs,[slice(0,7,1),slice(7,8,1),slice(8,11,1),slice(11,16,1)])
+ bbs=s1.getBoundingBoxForBBTree()
+ bbt=t1.getBoundingBoxForBBTree()
+ self.assertTrue(bbt.computeNbOfInteractionsWith(bbs,1e-12).isEqual(wExp))
+ pass
+
+ def testKrSpatialDiscretization2(self):
+ srcPointCoordsXY=DataArrayDouble([0.8401877171547095,0.39438292681909304,0.7830992237586059,0.7984400334760733,0.9116473579367843,0.19755136929338396,0.335222755714889,0.768229594811904,0.2777747108031878,0.5539699557954305,0.47739705186216025,0.6288709247619244,0.36478447279184334,0.5134009101956155,0.9522297251747128,0.9161950680037007,0.6357117279599009,0.7172969294326831,0.14160255535580338,0.6069688762570586,0.01630057162432958,0.24288677062973696,0.13723157678601872,0.8041767542269904,0.15667908925408455,0.4009443942461835,0.12979044678145574,0.10880880202576929,0.998924518003559,0.21825690531090688,0.5129323944043984,0.8391122346926072,0.6126398325956612,0.29603161769734304,0.6375522677030192,0.5242871900667843,0.493582986990727,0.9727750238835695,0.29251678441302703,0.7713576977939148,0.5267449792133388,0.7699138362751873,0.4002286220901779,0.8915294520051822,0.2833147460051415,0.3524583472648907,0.8077245200088827,0.9190264739650424,0.06975527623191256,0.9493270753646861,0.5259953502221011,0.08605584785624214,0.19221384599442307,0.6632269270081198,0.8902326025488938,0.3488929352485076,0.06417132078864207,0.02002304886468828,0.4577017372742769,0.06309583832653977,0.23827995417559517,0.9706341316786754,0.9022080734848082,0.8509197867712563,0.2666657493760184,0.5397603407221662,0.3752069763723793,0.7602487363667454,0.5125353641400744,0.6677237607854063,0.5316064341606602,0.039280343353413204,0.4376375965949323,0.9318350562508382,0.9308097953585953,0.7209523430657351,0.28429340305006756,0.7385343149018168,0.6399788165651163,0.3540486797476414,0.687861390266503,0.16597416632155615,0.4401045276038835,0.880075236260926,0.829201093329676,0.3303371296871161,0.22896817104377232,0.8933724145839793,0.35036017855180435,0.6866699083180492,0.9564682529105192,0.5886401331930609,0.6573040395310633,0.8586763259296661,0.4395599194986559,0.9239697889070817,0.39843666665183225,0.8147668963366965,0.6842185252738271,0.9109720307919067,0.4824906566564416,0.21582495896882609,0.9502523741453198,0.9201282537170352,0.14766001475400292,0.8810621695039152,0.641080596317109,0.43195341826973177,0.6195964839400707,0.281059412416564,0.7860020980173732,0.3074578737409124,0.44703357920378145,0.22610662515559543,0.18753310953617705,0.27623467206779617,0.5564437553083728,0.4165012805799494,0.16960708618611428,0.9068039338601771,0.10317118843233734,0.1260753390966334,0.49544406658757667,0.7604752284290619,0.9847516650262995,0.9350039865518939,0.6844450168704823,0.3831883312124705,0.7497708824229291,0.36866354167864823,0.2941603620043771,0.2322615386137094,0.5844885006474743,0.24441273568403568,0.15238979186508328,0.7321485158671385,0.12547490472228962,0.7934703881821923,0.164101933671209,0.7450713891280216,0.07452980059875632,0.9501040316885822,0.05252926240327268,0.5215633798025378,0.1762106563785163,0.24006237240511102,0.797798051870334,0.732654411686889,0.6565636529850605,0.9674051385221095,0.6394583455470663,0.7597348418830591,0.09348047715308166,0.13490241166898162,0.5202100698464597,0.07823214171371988,0.06990639775521419,0.2046550862512808,0.4614204733918516,0.8196772801781433,0.5733186283955903,0.7555808353962288,0.05193881879185271,0.1578071285774033,0.9999935710802644,0.204328610656936,0.8899556444445419,0.12546847580255405,0.9977989993047895,0.054057577650089554,0.8705398649305757,0.07232879943788462,0.004161608873010431,0.9230691273338484,0.5938921792404224,0.180372265717188,0.16313149927329806,0.3916902306450951,0.9130266774040771,0.8196951527240198,0.35909536870154335,0.552485022485482,0.5794299941414176,0.452575845854625,0.687387434620125,0.09964006352221597,0.5308079880340062,0.7572938323753392,0.30429514977349675,0.9922284614258579,0.5769711125534824,0.877613778169087,0.7478092963564253,0.6289099313453351,0.03542090674649035,0.7478028669710285,0.8332385420022712,0.9253765511910322,0.8732713427735824,0.8310375408413995],100,2)
+ srcFieldValsOnPoints=DataArrayDouble([0.7643742528498438,-0.023507696856211995,1.1082895131907775,0.6299357452572031,0.8892623544912389,0.72212114810697,0.9196401044320336,-0.759961711221917,0.40801932617748826,0.8441134300809151,0.982483804252809,0.6752368914020778,0.9924403977479798,1.1063334970204484,0.9403055261137516,0.3624481886322733,1.1344772505996308,0.7522965618948239,0.17077741651388564,0.6504551671311436,0.45843479588425423,0.41098905950326753,1.0681420394050904,-0.3483587903820091,0.5620151050607809,1.384969776596035,0.7948875141132845,0.7931192000237167,1.062498042490183,1.3709072529577366,0.44929346605311893,-0.4469683401788374,0.9035857424514101,0.6137249300593463,0.6355610879026966,1.4318174829507697,0.3097567072129551,-0.20515052260807165,0.6922559820922779,1.0341638749443423,1.3072652153341024,0.38511367353000436,0.9160514929274943,0.54513408530581,0.722252267913328,0.06684522818576251,0.10571899758067793,0.3193844999960903,0.5213532270828706,-0.04834998649603944,1.2408805068350615,-0.7632951295676795,0.5980054665011202,0.9064738717547436,1.1541070755096696,1.008234260272265,1.2225806960553827,1.0788560195121106,0.9818990282104452,0.5621951325841853,1.0796757508374188,0.5082872315589883,-0.9153702001062469,0.9560418838920791,0.9251098559152824,1.1603063610984021,1.2122303611181837,0.7379539363312343,0.6877611899207183,0.723966552446608,0.5596025827162566,0.8849725005989729,1.0908363665075547,0.08956512916455672,-0.10247645571248344,0.3236718069555875,1.069478546398975,1.3900071080692746,1.0322398863403262,0.45315515354558034,0.4249870238786733,1.030226761858634,0.974024629584669,1.2838885424020365,1.3451943506525155,1.4029933267831995,0.6025539675442462,1.2947650597767038,1.0006061239483002,-0.4017336259949164,0.8771165113201297,0.9158909024218246,1.403798605551443,0.4742904006425974,0.3671787905896653,0.20646491720419674,0.40739337434288925,0.7341932402033597,-0.4295893651836911,-0.3187777570661546],100,1)
+ targetPointCoordsXY=DataArrayDouble([-0.5,-0.5,-0.5,-0.35,-0.5,-0.2,-0.5,-0.05,-0.5,0.1,-0.5,0.25,-0.5,0.4,-0.5,0.55,-0.5,0.7,-0.5,0.85,-0.5,1.0,-0.5,1.15,-0.5,1.3,-0.5,1.45,-0.35,-0.5,-0.35,-0.35,-0.35,-0.2,-0.35,-0.05,-0.35,0.1,-0.35,0.25,-0.35,0.4,-0.35,0.55,-0.35,0.7,-0.35,0.85,-0.35,1.0,-0.35,1.15,-0.35,1.3,-0.35,1.45,-0.2,-0.5,-0.2,-0.35,-0.2,-0.2,-0.2,-0.05,-0.2,0.1,-0.2,0.25,-0.2,0.4,-0.2,0.55,-0.2,0.7,-0.2,0.85,-0.2,1.0,-0.2,1.15,-0.2,1.3,-0.2,1.45,-0.05,-0.5,-0.05,-0.35,-0.05,-0.2,-0.05,-0.05,-0.05,0.1,-0.05,0.25,-0.05,0.4,-0.05,0.55,-0.05,0.7,-0.05,0.85,-0.05,1.0,-0.05,1.15,-0.05,1.3,-0.05,1.45,0.1,-0.5,0.1,-0.35,0.1,-0.2,0.1,-0.05,0.1,0.1,0.1,0.25,0.1,0.4,0.1,0.55,0.1,0.7,0.1,0.85,0.1,1.0,0.1,1.15,0.1,1.3,0.1,1.45,0.25,-0.5,0.25,-0.35,0.25,-0.2,0.25,-0.05,0.25,0.1,0.25,0.25,0.25,0.4,0.25,0.55,0.25,0.7,0.25,0.85,0.25,1.0,0.25,1.15,0.25,1.3,0.25,1.45,0.4,-0.5,0.4,-0.35,0.4,-0.2,0.4,-0.05,0.4,0.1,0.4,0.25,0.4,0.4,0.4,0.55,0.4,0.7,0.4,0.85,0.4,1.0,0.4,1.15,0.4,1.3,0.4,1.45,0.55,-0.5,0.55,-0.35,0.55,-0.2,0.55,-0.05,0.55,0.1,0.55,0.25,0.55,0.4,0.55,0.55,0.55,0.7,0.55,0.85,0.55,1.0,0.55,1.15,0.55,1.3,0.55,1.45,0.7,-0.5,0.7,-0.35,0.7,-0.2,0.7,-0.05,0.7,0.1,0.7,0.25,0.7,0.4,0.7,0.55,0.7,0.7,0.7,0.85,0.7,1.0,0.7,1.15,0.7,1.3,0.7,1.45,0.85,-0.5,0.85,-0.35,0.85,-0.2,0.85,-0.05,0.85,0.1,0.85,0.25,0.85,0.4,0.85,0.55,0.85,0.7,0.85,0.85,0.85,1.0,0.85,1.15,0.85,1.3,0.85,1.45,1.0,-0.5,1.0,-0.35,1.0,-0.2,1.0,-0.05,1.0,0.1,1.0,0.25,1.0,0.4,1.0,0.55,1.0,0.7,1.0,0.85,1.0,1.0,1.0,1.15,1.0,1.3,1.0,1.45,1.15,-0.5,1.15,-0.35,1.15,-0.2,1.15,-0.05,1.15,0.1,1.15,0.25,1.15,0.4,1.15,0.55,1.15,0.7,1.15,0.85,1.15,1.0,1.15,1.15,1.15,1.3,1.15,1.45,1.3,-0.5,1.3,-0.35,1.3,-0.2,1.3,-0.05,1.3,0.1,1.3,0.25,1.3,0.4,1.3,0.55,1.3,0.7,1.3,0.85,1.3,1.0,1.3,1.15,1.3,1.3,1.3,1.45,1.45,-0.5,1.45,-0.35,1.45,-0.2,1.45,-0.05,1.45,0.1,1.45,0.25,1.45,0.4,1.45,0.55,1.45,0.7,1.45,0.85,1.45,1.0,1.45,1.15,1.45,1.3,1.45,1.45],196,2)
+ targetFieldValsExpected=DataArrayDouble([1.645976003316459, 1.454458180060204, 1.286087532859835, 1.147305389930914, 1.040143042030752, 0.9592075185603157, 0.8932542207607532, 0.8296417057622609, 0.7572539678257579, 0.6669048311361028, 0.551329882743212, 0.4064445075734602, 0.2323703965460786, 0.03253142054561309, 1.615321686989539, 1.414941300553572, 1.238383118538708, 1.096701655702075, 0.9955792747382535, 0.9271194507282707, 0.8741000712825546, 0.8201879508155141, 0.7537335933761495, 0.6656210809234322, 0.5470285414729397, 0.3927301586610237, 0.2044036897887453, -0.01181672742825013, 1.609602552867195, 1.400625195269133, 1.213287847440801, 1.065318574929208, 0.9717609562002842, 0.9182626517777217, 0.8760698972315855, 0.8258196104516153, 0.7586487405165288, 0.6686168424854784, 0.5434121624038266, 0.3741815029337978, 0.1661376046619205, -0.0704038088420833, 1.635421686625182, 1.422642113482769, 1.225977424080963, 1.066864693789366, 0.9864801043792362, 0.9486639217909161, 0.9075176697327381, 0.8471248730261529, 0.7660983406349626, 0.6675300501188994, 0.5320013361909732, 0.3404583135353376, 0.1074346390951333, -0.1520751802856468, 1.695346918429566, 1.489526279573347, 1.297678617961701, 1.139921240332637, 1.080508463804929, 1.036847769764088, 0.9687840669352359, 0.8790397822170175, 0.76938768351059, 0.6441978169925557, 0.4915328571013788, 0.2742929463574293, 0.0148214290833748, -0.2671755287427691, 1.782761788232491, 1.59423004798623, 1.422317125787222, 1.286999529473285, 1.20500638941831, 1.127058114031519, 1.022332539190471, 0.8945753999401338, 0.7469190939381181, 0.582396906110898, 0.4015920181411496, 0.1584700483835366, -0.1251860255418387, -0.4254052799545267, 1.881794862747652, 1.712890309994015, 1.557517508390291, 1.422727414977963, 1.308048056353061, 1.187569766723152, 1.03942150436647, 0.8677583087532357, 0.6766652050643343, 0.4703897480238999, 0.2497994532908829, -0.02005989176786582, -0.3224387891441491, -0.6331519303649853, 1.973114284621266, 1.820187301531605, 1.673403730111759, 1.528504440482262, 1.379693463484634, 1.207642134784147, 1.008217764780293, 0.7863328498822348, 0.5465383049529959, 0.2944879513187435, 0.03250657765404452, -0.2670900851421072, -0.5806516907976924, -0.8911331026431459, 2.038729888975378, 1.895652364645637, 1.751759791756183, 1.594035761810714, 1.403016809171641, 1.171403152610878, 0.913267035125007, 0.6343281031932027, 0.3434843176189371, 0.04195410032095204, -0.2645533663891493, -0.58577400250975, -0.8958218846257981, -1.192230697656513, 2.064018033720731, 1.922048791644444, 1.773847180028208, 1.600340336378483, 1.361620036333164, 1.060873411411508, 0.7373484802125152, 0.3868966266761109, 0.04316272760227413, -0.3009370030949727, -0.6505233805563486, -0.9669887470696283, -1.250005719852354, -1.519122595631787, 2.039938287785342, 1.887400820799651, 1.722008733683987, 1.523879290022419, 1.23834392230135, 0.8606985727866472, 0.4844892131548788, 0.08077959236877175, -0.3195742594962179, -0.726291368696764, -1.094357645641832, -1.359078900303776, -1.604725656501341, -1.845297168323687, 1.965762248218393, 1.791665198563286, 1.595056719739704, 1.353692777435502, 1.033006623003495, 0.6416349531117889, 0.2290046916364761, -0.1993180965088852, -0.6311618804827295, -1.051489875129883, -1.409404344854132, -1.681249363331096, -1.917859637689007, -2.145034400762945, 1.849053542205925, 1.648479366622312, 1.418493963148431, 1.141939527533839, 0.8042385795619003, 0.4127534639189761, -0.008572116677791453, -0.4428317297963555, -0.8745477268718713, -1.281769237471681, -1.635421857742795, -1.926210204560556, -2.175577364628722, -2.405762639746138, 1.701519686999922, 1.475879908746998, 1.219065416294153, 0.9203732349759972, 0.5740137315474942, 0.1856460506119944, -0.2298288912529738, -0.6558565521653752, -1.075391078040103, -1.469402631469075, -1.820558929095151, -2.123592211415966, -2.388177455227765, -2.628832075944413])
+ coeffsExpected=DataArrayDouble([0.3953237723894342,-0.17220705170185724,0.620727139132215,-0.01938292763088709,-0.007524685306185282,0.0016277944443884584,-0.0005209587893117361,-1.8992696595839718,-0.13154330748345855,0.11248800965389728,-0.47310750305033406,0.03685741122098605,0.21362468750754374,0.8082608687799991,-0.6775548200221704,-0.027683208482275873,-0.007806877014495724,-0.013539239795959668,0.3478535665778018,0.005145793726360813,0.03708618549628136,-0.18235332489209385,-0.04517273339177797,-0.081755114492025,0.12791746560435255,0.09659355695676189,-0.024809653129318366,0.08327587452569823,-1.790380673650165,-0.10622983512164165,0.14989029282340274,0.05949513762355707,0.004548072841131278,0.011252095917834793,-0.004848057194721367,-0.2658537133108412,0.016651579133606154,-0.021640915366981317,0.008975511042160175,-0.021052213988815974,-0.09347841701844657,0.03533229488135717,-0.014556185287109863,-0.27228591670520086,0.002989987191209683,-0.5489428537951813,-0.02134456783001304,-0.22462281620064825,0.005230853443767429,-0.1894678262257301,0.0033140729457334884,5.295483062326795,-0.2724500716060311,0.026433905662192683,0.01368706308878908,-0.03014264855048227,0.053679001877659956,0.08109477254132096,-0.005004603067203444,0.016907143132293558,0.2105509502082437,0.003657404455024417,-4.904755847017426,0.01634808163992959,-0.008325515865305198,0.062188432751569676,-0.013114633511406406,0.11020519384963083,-0.008599402366091309,-0.012125149710784723,0.31723729052927313,-0.10298398036815914,-0.07250078775612204,0.39976713701763433,0.45897498107347223,0.01018626210400031,0.20163425809089347,0.19729093298588943,0.42863333455911523,0.015595097081693168,0.06060353651437489,-0.16379444813161725,-0.43290344196574165,-0.5931022701412187,1.1906610004748832,0.44418106894148945,0.06536220001548931,0.010261694323554562,-0.05943099382075491,-0.04939614579484797,0.002234505477641322,-0.011262130967449935,0.09644905007708474,-0.029518792883267808,0.41564004027396634,-0.18459770295961597,0.3100981306103734,-0.2509873737065425,0.5434321443668653,0.3009912967350914,1.9560655796099518,-0.7143435150084513,-1.5123449469879784])
+ #
+ nbOfInputPoints=100;
+ f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME);
+ mesh=MEDCoupling1SGTUMesh.New("aMesh",NORM_POINT1);
+ mesh.setCoords(srcPointCoordsXY);
+ f.setMesh(mesh);
+ f.setArray(srcFieldValsOnPoints);
+ f.checkCoherency();
+ #
+ res0=f.getValueOn([-0.5,-0.5]);
+ self.assertAlmostEqual(targetFieldValsExpected.getIJ(0,0),res0[0],10)
+ #
+ valuesToTest=f.getValueOnMulti(targetPointCoordsXY);
+ self.assertEqual(196,valuesToTest.getNumberOfTuples());
+ self.assertEqual(1,valuesToTest.getNumberOfComponents());
+ for i in xrange(40):
+ self.assertAlmostEqual(targetFieldValsExpected[i],valuesToTest.getIJ(i,0),10)
+ pass
+ fd=f.getDiscretization()
+ del f
+ self.assertTrue(isinstance(fd,MEDCouplingFieldDiscretizationKriging))
+ coeffs,isDrift=fd.computeVectorOfCoefficients(mesh,srcFieldValsOnPoints)
+ self.assertEqual(3,isDrift)
+ self.assertTrue(coeffsExpected.isEqual(coeffs,1e-8))
+ # testing matrix
+ pts3=[-0.5,-0.5,-0.5,-0.35,-0.35,-0.2]
+ mesh.setCoords(srcPointCoordsXY[:4])
+ m,nbCols=fd.computeEvaluationMatrixOnGivenPts(mesh,pts3)
+ self.assertTrue(m.isEqual(DataArrayDouble([0.05768877688524917,-4.438982030395039,1.9495386255911573,3.431754627918642,0.11803848510231275,-4.138339658420563,1.6630742187104417,3.357226954607818,0.14630203028580618,-3.5156045565871734,1.414680070737206,2.954622455564169]),1e-12))
+ if MEDCouplingHasNumPyBindings():
+ import numpy as np
+ m0=m.toNumPyArray() ; m0=m0.reshape(3,nbCols) ; m0=np.matrix(m0)
+ srcFieldValsOnPoints2=DataArrayDouble(4,2) ; srcFieldValsOnPoints2[:,0]=srcFieldValsOnPoints[:4] ; srcFieldValsOnPoints2[:,1]=2*srcFieldValsOnPoints[:4]
+ n0=srcFieldValsOnPoints2.toNumPyArray() ; n0=n0.reshape(4,2) ; n0=np.matrix(n0)
+ #
+ f=MEDCouplingFieldDouble.New(ON_NODES_KR,ONE_TIME) ; f.setMesh(mesh) ; f.setArray(srcFieldValsOnPoints2) ; f.checkCoherency()
+ self.assertTrue(DataArrayDouble(np.array((m0*n0))).isEqual(f.getValueOnMulti(pts3),1e-14))
+ pass
+ #
+ pass
+
+ # test the when input slice is all the same object is return by MEDCouplingMesh.buildPartRange
+ def testSwig2MeshPartSlice1(self):
+ a=DataArrayDouble(4) ; a.iota()
+ c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m=c.buildUnstructured()
+ fc0=c.getMeasureField(False) ; fc1=fc0[:] ; fc2=fc0*fc1 ; fc2.setName(fc0.getName())
+ self.assertEqual(fc0.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer())
+ self.assertEqual(fc2.getMesh().getHiddenCppPointer(),fc1.getMesh().getHiddenCppPointer())
+ self.assertTrue(fc2.isEqual(fc1,1e-12,1e-12))
+ #
+ fm0=m.getMeasureField(False) ; fm1=fm0[:] ; fm2=fm0*fm1 ; fm2.setName(fm0.getName())
+ self.assertEqual(fm0.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer())
+ self.assertEqual(fm2.getMesh().getHiddenCppPointer(),fm1.getMesh().getHiddenCppPointer())
+ self.assertTrue(fm2.isEqual(fm1,1e-12,1e-12))
+ pass
+
+ # test the correct behaviour when attempting to aggregate two fields whose mesh is null
+ def testSwig2MergeFieldsOnFieldsHavingNoMesh(self):
+ a=DataArrayDouble(4) ; a.iota() ; a*=1.5
+ c=MEDCouplingCMesh() ; c.setCoords(a,a) ; f1=c.getMeasureField(False)
+ f1.setMesh(None) ; f2=f1.deepCpy() ; f2*=2
+ f3=MEDCouplingFieldDouble.MergeFields(f1,f2)
+ daExp=DataArrayDouble([2.25,2.25,2.25,2.25,2.25,2.25,2.25,2.25,2.25,4.5,4.5,4.5,4.5,4.5,4.5,4.5,4.5,4.5])
+ self.assertTrue(f3.getArray().isEqual(daExp,1e-12))
+ self.assertEqual(f3.getTypeOfField(),ON_CELLS)
+ self.assertEqual(f3.getMesh(),None)
+ f4=MEDCouplingFieldDouble.MergeFields([f1,f2])
+ self.assertTrue(f4.getArray().isEqual(daExp,1e-12))
+ self.assertEqual(f4.getTypeOfField(),ON_CELLS)
+ self.assertEqual(f4.getMesh(),None)
+ pass
+
+ # test a simple node to cell convertion of a field
+ def testSwig2NodeToCellDiscretization1(self):
+ f=MEDCouplingFieldDouble(ON_NODES) ; f.setTime(1.1,2,3)
+ a1=DataArrayDouble(4) ; a1.iota()
+ a2=DataArrayDouble(3) ; a2.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(a1,a2)
+ f.setMesh(m)
+ arr=DataArrayDouble([21.,121.,20.,120.,19.,119.,18.,118.,17.,117.,16.,116.,15.,115.,14.,114.,13.,113.,12.,112.,11.,111.,10.,110.],12,2) ; arr.setInfoOnComponents(["aa [km]","bbb [kJ]"])
+ f.setArray(arr) ; f.setName("toto")
+ #
+ f2=f.nodeToCellDiscretization()
+ self.assertEqual(ON_CELLS,f2.getTypeOfField())
+ self.assertEqual("toto",f2.getName())
+ self.assertEqual([1.1,2,3],f2.getTime())
+ self.assertEqual(["aa [km]","bbb [kJ]"],f2.getArray().getInfoOnComponents())
+ self.assertEqual(6,f2.getArray().getNumberOfTuples())
+ self.assertEqual(f.getMesh().getHiddenCppPointer(),f2.getMesh().getHiddenCppPointer())
+ exp=DataArrayDouble([18.5,118.5,17.5,117.5,16.5,116.5,14.5,114.5,13.5,113.5,12.5,112.5],6,2) ; exp.setInfoOnComponents(["aa [km]","bbb [kJ]"])
+ self.assertTrue(f2.getArray().isEqual(exp,1e-13))
+ pass
+
+ def testSwig2NonRegressionBugIntersectMeshes1(self):
+ src=MEDCouplingUMesh("src",2)
+ src.setCoords(DataArrayDouble([-2.5,-3,-2.5,3,2.5,3],3,2))
+ src.allocateCells()
+ src.insertNextCell(NORM_TRI3,[0,1,2])
+ #
+ trg=MEDCouplingUMesh("trg",2)
+ trg.setCoords(DataArrayDouble([-2.5,-3.,0.,-3.,0.,-2.,-2.,0.,-2.25,0.,-2.5,0.,-2.5,-1.5,0.,-2.5,-1.25,-3.,-1.414213562373095,-1.414213562373095],10,2))
+ trg.allocateCells()
+ trg.insertNextCell(NORM_QPOLYG,[2,1,0,5,3,7,8,6,4,9])
+ #
+ a,b,c=MEDCouplingUMesh.Intersect2DMeshes(src,trg,1.0e-8)
+ a.mergeNodes(1e-8)
+ self.assertTrue(a.getCoords().isEqual(DataArrayDouble([-2.5,-3.,-2.5,3.,2.5,3.,0.,-3.,0.,-2.,-2.,0.,-2.25,0.,-2.5,0.,-2.5,-1.5,0.,-2.5,-1.25,-3.,-1.414213562373095,-1.414213562373095,-1.2803687993289596,-1.5364425591947515,-1.8901843996644798,-2.2682212795973755,-1.81117884244736,-0.8483107924994473,-2.5,1.5,0.,3.,0.6098156003355202,0.7317787204026243],18,2),1e-12))
+ self.assertTrue(a.getNodalConnectivity().isEqual(DataArrayInt([32,12,0,7,5,13,8,6,14,32,7,1,2,12,5,15,16,17,14,6])))
+ self.assertTrue(a.getNodalConnectivityIndex().isEqual(DataArrayInt([0,9,20])))
+ self.assertTrue(b.isEqual(DataArrayInt([0,0])))
+ self.assertTrue(c.isEqual(DataArrayInt([0,-1])))
+ pass
+
+ def testSwig2MeshOrientCorrectly2DCells1(self):
+ m=MEDCouplingUMesh("mesh",2)
+ coo=DataArrayDouble([1.,0.,0.5,-0.1,0.,1.,0.,0.,0.07,0.5,0.59,0.5],6,2)
+ m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI6,[3,0,2,1,5,4])
+ m.insertNextCell(NORM_QPOLYG,[3,0,2,1,5,4])
+ self.assertTrue(DataArrayDouble([-0.58093333350930543,-0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
+ m.changeSpaceDimension(3)
+ m.orientCorrectly2DCells([0.,0.,-1.],False)
+ #
+ m.checkCoherency()
+ self.assertTrue(m.getNodalConnectivity().isEqual(DataArrayInt([6,3,2,0,4,5,1, 32,3,2,0,4,5,1])))
+ self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,7,14])))
+ m.changeSpaceDimension(2)
+ self.assertTrue(DataArrayDouble([0.58093333350930543,0.58093333350930543]).isEqual(m.getMeasureField(False).getArray(),1e-12))
+ pass
+
+ def testSwig2Hexa8HavingFacesWarped1(self):
+ """ This test is bases on a "error" of interpolation detected. After investigation cell #3 of src is warped that leads to the fact that when trg is
+ intersected with src the sum of intersection volume is greater than the volume of the trg cell.
+ A test that can be done is to split the cell #3 of src into tetrohedrons and by summing all the volumes it does not fit the volume computed of cell#3 unsplitted (expect for
+ GENERAL_24).
+ """
+ srcCoo=DataArrayDouble([0.15694071546650565,0.09383333333333337,6.920842121738133,0.15774332475430292,0.185486666666667,6.920682472824616,0.1585459340420992,0.27713999999999994,6.9205228239111,0.07427195882345167,0.05782666666666668,6.937285959830335,0.06343673343819695,0.11347333333333297,6.939441220162809,0.05260150805294228,0.16911999999999996,6.941596480495282,0.014076262238703396,0.04800666666666667,6.949259628344076,0.014076262238703396,0.07092000000000007,6.949259628344076,0.15407499632681992,0.09383333333333338,6.897607484780063,0.15489234394181514,0.18548666666666702,6.897567331066572,0.15570969155680933,0.27714,6.897527177353081,0.06988819198237989,0.05782666666666669,6.901743317269663,0.05885399917995321,0.11347333333333298,6.9022853924017955,0.047819806377526586,0.16912,6.902827467533927,0.0085871208577874,0.048006666666666684,6.9047548457815076,0.0085871208577874,0.07092000000000008,6.9047548457815076,0.153883333333333,0.09383333333333338,6.820902,0.154701666666667,0.18548666666666702,6.820902,0.15551999999999996,0.27714,6.820902,0.06959499999999999,0.05782666666666669,6.820902,0.058547499999999975,0.11347333333333298,6.820902,0.04749999999999999,0.16912,6.820902],22,3)
+ src=MEDCouplingUMesh("TBmesh3D",3) ; src.setCoords(srcCoo)
+ src.allocateCells()
+ src.insertNextCell(NORM_HEXA8,[0,1,4,3,8,9,12,11])
+ src.insertNextCell(NORM_HEXA8,[1,2,5,4,9,10,13,12])
+ src.insertNextCell(NORM_HEXA8,[4,5,7,6,12,13,15,14])
+ src.insertNextCell(NORM_HEXA8,[8,9,12,11,16,17,20,19])
+ src.insertNextCell(NORM_HEXA8,[9,10,13,12,17,18,21,20])
+ src.checkCoherency2()
+ # trg is useless here but I keep it in case of MEDCouplingRemapper were expected to do something about warped NORM_HEXA8
+ trgCoo=DataArrayDouble([0.0960891897852753,0.105088620541845,6.8598,0.0599574480546212,0.118434267436059,6.8598,0.113514510609589,0.14874473653263,6.8598,0.0831322609794463,0.167319109733883,6.8598,0.0960891897852753,0.105088620541845,6.92146666666667,0.0599574480546212,0.118434267436059,6.92146666666667,0.113514510609589,0.14874473653263,6.92146666666667,0.0831322609794463,0.167319109733883,6.92146666666667],8,3)
+ trg=MEDCouplingUMesh("MESH",3) ; trg.setCoords(trgCoo)
+ trg.allocateCells()
+ trg.insertNextCell(NORM_HEXA8,[0,1,3,2,4,5,7,6])
+ #
+ srcFace=src.buildDescendingConnectivity()[0]
+ conn=MEDCoupling1SGTUMesh(srcFace).getNodalConnectivity() ; conn.rearrange(4)
+ eqFaces=srcFace.computePlaneEquationOf3DFaces()
+ nodeIdInCell=3
+ e=(srcFace.getCoords()[conn[:,nodeIdInCell]]*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# e represent the error between the expected 'a*X+b*Y+c*Z+d' in eqFaces and 0. Closer e to 0. is closer the 4th point is to the plane built with the 3 first points
+ lambd=-e/(eqFaces[:,:3]**2).sumPerTuple()
+ pts=lambd*eqFaces[:,:-1]+srcFace.getCoords()[conn[:,nodeIdInCell]]#pts represent the projection of the last points of each NORM_QUAD4 to the plane defined by the 3 first points of the NORM_QUAD4 cell
+ shouldBeZero=(pts*eqFaces[:,:-1]).sumPerTuple()+eqFaces[:,3]# this line is useless only to be sure that pts are on the plane.
+ check=(pts-srcFace.getCoords()[conn[:,nodeIdInCell]]).magnitude() # check contains the distance of the last point to its plane
+ idsToTest=check.getIdsNotInRange(0.,1e-10)
+ self.assertTrue(idsToTest.isEqual(DataArrayInt([17,18,19,20,22,23,24])))
+ idsToTest2=idsToTest.getIdsNotInRange(18,22)
+ self.assertTrue(idsToTest2.isEqual(DataArrayInt([0,4,5,6])))
+ idsToTest2.rearrange(2)
+ self.assertTrue(idsToTest2.sumPerTuple().isEqual(DataArrayInt([4,11])))
+ pass
+
+ def testSwig2SortHexa8EachOther1(self):
+ """
+ testing MEDCoupling1SGTUMesh.sortHexa8EachOther method
+ """
+ coords1=DataArrayDouble([(-0.5,0.5,-0.5),(0.5,-0.5,-0.5),(-0.5,-0.5,0.5),(-0.5,-0.5,-0.5),(0.5,-0.5,0.5),(-0.5,0.5,0.5),(0.5,0.5,0.5),(0.5,0.5,-0.5)])
+ m1=MEDCouplingUMesh("m1",3) ; m1.setCoords(coords1)
+ m1.allocateCells() ; m1.insertNextCell(NORM_HEXA8,[7,1,3,0,6,4,2,5])
+ m1.checkCoherency()
+ #
+ m2=m1.deepCpy() ; m2.setName("m2")
+ #
+ trs=[[0.,0.,-1.],[0.,0.,1.],[1.,0.,0.],[0.,-1.,0.],[-1.,0.,0.],[0.,1.,0.]]
+ for i,t in enumerate(trs):
+ for j in xrange(64):
+ j2=(j//16) ; j1=((j%16)//4) ; j0=(j%4)
+ m11=m1.deepCpy()
+ m11.rotate([0.,0.,0.],[0.,0.,1.],float(j0)*pi/2)
+ m11.rotate([0.,0.,0.],[0.,1.,0.],float(j1)*pi/2)
+ m11.rotate([0.,0.,0.],[1.,0.,0.],float(j2)*pi/2)
+ m11.translate(t)
+ #
+ m=MEDCouplingUMesh.MergeUMeshes(m2,m11)
+ m.mergeNodes(1e-12)
+ self.assertEqual(12,m.getNumberOfNodes())
+ m=MEDCoupling1SGTUMesh(m)
+ m.sortHexa8EachOther()
+ tmp0=m.buildUnstructured().tetrahedrize(PLANAR_FACE_6)[0].buildUnstructured()
+ self.assertEqual(20,tmp0.computeSkin().getNumberOfCells())
+ pass
+ pass
+ pass
+
+ def testSwig2normMinComputeAbs1(self):
+ d=DataArrayDouble([4,-5,2,6.1,-7.33,1,-1,3e2,0.07,-0.009,-6,-1e30],4,3)
+ d.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
+ d0=d.computeAbs()
+ dExp=d.deepCpy() ; dExp.abs()
+ self.assertTrue(dExp.isEqual(d0,1e-12))
+ e=d0-DataArrayDouble([4,5,2,6.1,7.33,1,1,3e2,0.07,0.009,6,1e30],4,3)
+ self.assertAlmostEqual(0.,e.normMin(),13)
+ self.assertAlmostEqual(0.009,d.normMin(),13)
+ #
+ di=DataArrayInt([3,-12,5,6,14,16,-23,100,23,-1,0,-6],4,3)
+ di.setInfoOnComponents(["XX [m]","YYY [km]","ABSJJ [MW]"])
+ d0i=di.computeAbs()
+ diExp=di.deepCpy() ; diExp.abs()
+ self.assertTrue(diExp.isEqual(d0i))
+ self.assertEqual([3,12,5,6,14,16,23,100,23,1,0,6],d0i.getValues())
+ pass
+
+ def testSwig2GetCellsContainingPointsForNonConvexPolygon1(self):
+ coo=DataArrayDouble([-0.5,-0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,0.,-0.5,0.,0.,0.5,0.,],7,2)
+ m=MEDCouplingUMesh("Intersect2D",2) ; m.setCoords(coo) ; m.allocateCells()
+ m.insertNextCell(NORM_POLYGON,[6,3,4,5])
+ m.insertNextCell(NORM_POLYGON,[4,0,1,2,6,5])
+ m.checkCoherency2()
+ #
+ self.assertTrue(m.getCellsContainingPoint((0.4,-0.4),1e-12).isEqual(DataArrayInt([0])))
+ self.assertTrue(m.getCellsContainingPoint((-0.4,-0.4),1e-12).isEqual(DataArrayInt([1])))
+ self.assertTrue(m.getCellsContainingPoint((0.,-0.4),1e-12).isEqual(DataArrayInt([0,1])))
+ pass
+
+ def testSwig2GetCellsContainingPointsForNonConvexPolygon2(self):
+ coo=DataArrayDouble([-0.5,-0.5,-0.5,0.5,0.5,0.5,0.5,-0.5,-2.0816681711721685e-17,-2.0816681711721685e-17,-0.17677669529663687,0.1767766952966369,0.,0.5,0.5,0.,0.17677669529663684,-0.17677669529663692,0.17677669529663692,0.17677669529663684,-0.17677669529663692,-0.17677669529663687,0.,-0.5,-0.5,0.,0.33838834764831843,-0.3383883476483185,-0.33838834764831843,0.33838834764831843,-0.21213203435596423,0.21213203435596426,0.2121320343559642,-0.2121320343559643,0.21213203435596426,0.2121320343559642,-0.21213203435596423,-0.21213203435596428,0.3560660171779821,-0.35606601717798214,-0.35606601717798214,0.35606601717798214,0.19445436482630052,-0.19445436482630063,-0.19445436482630055,0.19445436482630057,0.,0.27],24,2)
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) ; m.allocateCells()
+ m.insertNextCell(NORM_QPOLYG,[8,5,4,9])
+ m.insertNextCell(NORM_QPOLYG,[5,8,4,10])
+ m.insertNextCell(NORM_QPOLYG,[16,8,5,15,21,9,22,17])
+ m.insertNextCell(NORM_QPOLYG,[15,1,2,3,16,20,6,7,19,17])
+ m.insertNextCell(NORM_QPOLYG,[15,5,8,16,22,10,21,18])
+ m.insertNextCell(NORM_QPOLYG,[16,3,0,1,15,19,11,12,20,18])
+ m.checkCoherency2()
+ self.assertTrue(m.getCellsContainingPoint([0.,0.27],1e-12).isEqual(DataArrayInt([2])))
+ pass
+
+ def testSwig2DAIGetIdsEqualTuple1(self):
+ da=DataArrayInt([0,7,1,2,4,1,2,1,1,2,0,1,2,1,5,1,1,2],9,2)
+ self.assertTrue(da.getIdsEqualTuple([1,2]).isEqual(DataArrayInt([1,4,8])))
+ self.assertTrue(da.getIdsEqualTuple((1,2)).isEqual(DataArrayInt([1,4,8])))
+ self.assertTrue(da.getIdsEqualTuple(DataArrayInt([1,2])).isEqual(DataArrayInt([1,4,8])))
+ da.rearrange(3)
+ self.assertRaises(InterpKernelException,da.getIdsEqualTuple,[1,2])# mismatch nb of compo (3) and nb of elts in input tuple (2)
+ self.assertTrue(da.getIdsEqualTuple([2,0,1]).isEqual(DataArrayInt([3])))
+ self.assertTrue(da.getIdsEqualTuple([2,0,7]).isEqual(DataArrayInt([])))
+ da.rearrange(1)
+ self.assertTrue(da.getIdsEqualTuple(2).isEqual(DataArrayInt([3,6,9,12,17])))
+ self.assertTrue(da.getIdsEqualTuple(2).isEqual(da.getIdsEqual(2)))
+ pass
+
+ def testSwig2GaussNEStaticInfo1(self):
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetWeightArrayFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.16666666666666666]),1e-12))
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetRefCoordsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.,0.,1.,0.,0.,1.]),1e-12))
+ self.assertTrue(DataArrayDouble(MEDCouplingFieldDiscretizationGaussNE.GetLocsFromGeometricType(NORM_TRI3)).isEqual(DataArrayDouble([0.16666666666666666,0.16666666666666666,0.6666666666666667,0.16666666666666666,0.16666666666666666,0.6666666666666667]),1e-12))
+ pass
+
+ def testSwigReverseNodalConnOnStructuredMesh(self):
+ # 1D - standard
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 1D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(1) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 1D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(0) ; arr.iota()
+ c.setCoordsAt(0,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn.isEqual(DataArrayInt([]))
+ rni.isEqual(DataArrayInt([0]))
+ # 2D - standard
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota() ; arr2=DataArrayDouble(4) ; arr.iota()
+ c.setCoords(arr,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,8,4,5,8,9,5,6,9,10,6,7,10,11,7,11,8,8,9,9,10,10,11,11])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,26,30,34,38,40,41,43,45,47,48])))
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ # 2D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
+ c.setCoords(arr,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ # 2D - limit
+ c=MEDCouplingCMesh() ; arr=DataArrayDouble(10) ; arr.iota() ; arr2=DataArrayDouble(1) ; arr.iota()
+ c.setCoords(arr2,arr)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,9,11,13,15,17,18])))
+ # 3D - standard
+ c=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(3) ; arr1.iota() ; arr2=DataArrayDouble(4) ; arr2.iota()
+ c.setCoords(arr0,arr1,arr2)
+ rn,rni=c.getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(DataArrayInt([0,0,1,1,2,2,3,3,0,4,0,1,4,5,1,2,5,6,2,3,6,7,3,7,4,4,5,5,6,6,7,7,0,8,0,1,8,9,1,2,9,10,2,3,10,11,3,11,0,4,8,12,0,1,4,5,8,9,12,13,1,2,5,6,9,10,13,14,2,3,6,7,10,11,14,15,3,7,11,15,4,12,4,5,12,13,5,6,13,14,6,7,14,15,7,15,8,16,8,9,16,17,9,10,17,18,10,11,18,19,11,19,8,12,16,20,8,9,12,13,16,17,20,21,9,10,13,14,17,18,21,22,10,11,14,15,18,19,22,23,11,15,19,23,12,20,12,13,20,21,13,14,21,22,14,15,22,23,15,23,16,16,17,17,18,18,19,19,16,20,16,17,20,21,17,18,21,22,18,19,22,23,19,23,20,20,21,21,22,22,23,23])))
+ self.assertTrue(rni.isEqual(DataArrayInt([0,1,3,5,7,8,10,14,18,22,24,25,27,29,31,32,34,38,42,46,48,52,60,68,76,80,82,86,90,94,96,98,102,106,110,112,116,124,132,140,144,146,150,154,158,160,161,163,165,167,168,170,174,178,182,184,185,187,189,191,192])))
+ rn2,rni2=c.buildUnstructured().getReverseNodalConnectivity()
+ self.assertTrue(rn.isEqual(rn2)) ; self.assertTrue(rni.isEqual(rni2))
+ pass
+
+ def testSwig2CellToNodeDiscretization1(self):
+ m=MEDCouplingCMesh() ; arr0=DataArrayDouble(5) ; arr0.iota() ; arr1=DataArrayDouble(4) ; arr1.iota() ; m.setCoords(arr0,arr1)
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setTime(1.1,5,6)
+ arr=DataArrayDouble(12) ; arr.iota()
+ arr=DataArrayDouble.Meld(arr,arr+100.) ; arr.setInfoOnComponents(["aaa","bbb"])
+ f.setArray(arr)
+ f.checkCoherency()
+ #
+ ref=DataArrayDouble([0.,0.5,1.5,2.5,3.,2.,2.5,3.5,4.5,5.,6.,6.5,7.5,8.5,9.,8.,8.5,9.5,10.5,11.])
+ ref=DataArrayDouble.Meld(ref,ref+100.) ; ref.setInfoOnComponents(["aaa","bbb"])
+ f2=f.cellToNodeDiscretization()
+ f2.checkCoherency()
+ self.assertEqual(f2.getTime()[1:],[5,6])
+ self.assertAlmostEqual(f2.getTime()[0],1.1,15)
+ self.assertEqual(f2.getMesh().getHiddenCppPointer(),m.getHiddenCppPointer())
+ self.assertTrue(f2.getArray().isEqual(ref,1e-12))
+ rn,rni=m.getReverseNodalConnectivity()
+ rni2=(rni.deltaShiftIndex()).convertToDblArr()
+ arr2=(f.getArray()[rn]).accumulatePerChunck(rni)/rni2
+ self.assertTrue(f2.getArray().isEqual(arr2,1e-12))
+ del f2
+ #
+ u=m.buildUnstructured() ; f.setMesh(u) ; del m
+ f3=f.cellToNodeDiscretization()
+ f3.checkCoherency()
+ self.assertEqual(f3.getTime()[1:],[5,6])
+ self.assertAlmostEqual(f3.getTime()[0],1.1,15)
+ self.assertEqual(f3.getMesh().getHiddenCppPointer(),u.getHiddenCppPointer())
+ self.assertTrue(f3.getArray().isEqual(ref,1e-12))
+ pass
+
+ def testSwig2GetMeshSpaceDimensionCMesh1(self):
+ c=MEDCouplingCMesh()
+ arr0=DataArrayDouble([0,1,2])
+ arr1=DataArrayDouble([0])
+ c.setCoords(arr0,arr0,arr0)
+ self.assertEqual(c.getMeshDimension(),3)
+ self.assertEqual(c.getSpaceDimension(),3)
+ #
+ c.setCoords(arr0,arr0,arr1)
+ self.assertEqual(c.getMeshDimension(),2)
+ self.assertEqual(c.getSpaceDimension(),3)
+ #
+ c.setCoords(arr0,arr0)
+ self.assertEqual(c.getMeshDimension(),2)
+ self.assertEqual(c.getSpaceDimension(),2)
+ #
+ c.setCoords(arr0,arr1)
+ self.assertEqual(c.getMeshDimension(),1)
+ self.assertEqual(c.getSpaceDimension(),2)
+ #
+ c.setCoords(arr0)
+ self.assertEqual(c.getMeshDimension(),1)
+ self.assertEqual(c.getSpaceDimension(),1)
+ #
+ c.setCoords(arr1)
+ self.assertEqual(c.getMeshDimension(),0)
+ self.assertEqual(c.getSpaceDimension(),1)
+ pass
+