From: ageay Date: Mon, 5 Nov 2012 10:01:02 +0000 (+0000) Subject: Testing all CU, CC, UC configuration to improve coverage. X-Git-Tag: V6_6_0b1~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e74359811d8f29f03231fd3450115fc1586bb965;p=tools%2Fmedcoupling.git Testing all CU, CC, UC configuration to improve coverage. --- diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py index 97a63091d..5c8042f5e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py @@ -169,19 +169,121 @@ class MEDCouplingBasicsTest(unittest.TestCase): fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.]) fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) rem=MEDCouplingRemapper() - #rem.prepare(src,trg,"P0P0") - #print rem.getCrudeMatrix() - #src.writeVTK("src.vtu") - #trg2=trg.buildUnstructured() - #trg2.writeVTK("trg.vtu") - #trgField=rem.transferField(fieldSrc,-7.) - #print trgField.getArray().getValues() - #expected3=[-7.,-7.,7.35,0.15,-7.,-7.,2.8,14.85,5.25,-7.,-7.,2.,2.5,-7.,-7.,-7.,1.2,3.,0.9,-7.,-7.,-7.,-7.,-7.,-7.] - #self.assertEqual(100,trgField.getArray().getNumberOfTuples()) - #self.assertEqual(100,len(expected3)) - #for i,val in enumerate(expected3): - # self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12); - # pass + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected3=[-7.,-7.,2.925,0.015,-7.,-7.,0.9392,8.595,2.265,-7.,-7.,1.1008,1.1192,-7.,-7.,-7.,0.6392,1.6408,0.2808,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,0.81,-7.,-7.,-7.,0.1208,11.55,0.96,-7.,-7.,1.1752,0.6592,-7.,-7.,-7.,0.8512,1.7744,0.0192,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,1.92,-7.,-7.,-7.,0.12578571428571422,0.007314285714285673,-7.,-7.,-7.,0.3189253968253971,0.1879746031746033,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.] + self.assertEqual(100,trgField.getArray().getNumberOfTuples()) + self.assertEqual(100,len(expected3)) + for i,val in enumerate(expected3): + self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12); + pass + pass + + def testPrepareCU(self): + # 1D + coords=DataArrayDouble([0.,0.5,0.7]) + trg=MEDCouplingUMesh("",1) ; trg.setCoords(coords) + trg.allocateCells(2) ; trg.insertNextCell(NORM_SEG2,[0,1]) ; trg.insertNextCell(NORM_SEG2,[1,2]) ; trg.finishInsertingCells() + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrTrg=DataArrayDouble([10.,30.,40.,70.,80.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrTrg) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected1=[44.,16.] + self.assertEqual(2.,trgField.getArray().getNumberOfTuples()) + self.assertEqual(2,len(expected1)) + for i,val in enumerate(expected1): + self.assertAlmostEqual(expected1[i],trgField.getArray().getIJ(i,0),12); + pass + # 2D + coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.5,-0.2],5,2) + trg=MEDCouplingUMesh("",2) ; trg.setCoords(coords) + trg.allocateCells(2) ; trg.insertNextCell(NORM_TRI3,[0,1,2]) ; trg.insertNextCell(NORM_TRI3,[3,4,0]) ; trg.finishInsertingCells() + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.,40.,70.,80.,110.,130.,140.,170.,180.,210.,230.,240.,270.,280.,310.,330.,340.,370.,380.,410.,430.,440.,470.,480.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected2=[441.3050624589086,68.69529914529915] + self.assertEqual(2,trgField.getArray().getNumberOfTuples()) + self.assertEqual(2,len(expected2)) + for i,val in enumerate(expected2): + self.assertAlmostEqual(expected2[i],trgField.getArray().getIJ(i,0),12); + pass + # 3D + coords=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.5,-0.2,0.,0.1,0.8,1.,0.5,0.,1.],7,3) + trg=MEDCouplingUMesh("",3) ; trg.setCoords(coords) + trg.allocateCells(2) ; trg.insertNextCell(NORM_TETRA4,[0,1,2,5]) ; trg.insertNextCell(NORM_TETRA4,[3,4,0,6]) ; trg.finishInsertingCells() + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) ; arr2=DataArrayDouble([-0.7,0.2,0.6,1.2,2.]) + src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) ; src.setCoordsAt(2,arr2) + trg.checkCoherency2(1e-10) + src.checkCoherency() + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble(100) ; arrSrc.iota(7.7) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected3=[39.635196634558845,12.13422356758468] + self.assertEqual(2,trgField.getArray().getNumberOfTuples()) + self.assertEqual(2,len(expected3)) + for i,val in enumerate(expected3): + self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12); + pass + pass + + def testPrepareCC(self): + # 1D + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15]) + trg.setCoordsAt(0,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrTrg=DataArrayDouble([10.,30.,40.,70.,80.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrTrg) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected1=[10.,25.] + self.assertEqual(2.,trgField.getArray().getNumberOfTuples()) + self.assertEqual(2,len(expected1)) + for i,val in enumerate(expected1): + self.assertAlmostEqual(expected1[i],trgField.getArray().getIJ(i,0),12); + pass + # 2D + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15]) + trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.,40.,70.,80.,110.,130.,140.,170.,180.,210.,230.,240.,270.,280.,310.,330.,340.,370.,380.,410.,430.,440.,470.,480.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected2=[10.,25.,91.66666666666666,90.27777777777777] + self.assertEqual(4,trgField.getArray().getNumberOfTuples()) + self.assertEqual(4,len(expected2)) + for i,val in enumerate(expected2): + self.assertAlmostEqual(expected2[i],trgField.getArray().getIJ(i,0),12); + pass + # 3D + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) ; src.setCoordsAt(2,arr) + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15]) + trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr) ; trg.setCoordsAt(2,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble(125) ; arrSrc.iota(7.7) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) ; fieldSrc.checkCoherency() + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected3=[7.7, 7.249999999999999, 10.583333333333332, 9.513888888888886, 27.25, 23.40277777777777, 26.180555555555546, 22.39583333333333] + self.assertEqual(8,trgField.getArray().getNumberOfTuples()) + self.assertEqual(8,len(expected3)) + for i,val in enumerate(expected3): + self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12); + pass pass def build2DSourceMesh_1(self):