+
+ def testMEDFileFieldConvertTo1(self):
+ fname="Pyfile68.med"
+ # building a mesh containing 4 tri3 + 5 quad4
+ tri=MEDCouplingUMesh("tri",2)
+ tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
+ tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
+ tris=[tri.deepCpy() for i in xrange(4)]
+ for i,elt in enumerate(tris): elt.translate([i,0])
+ tris=MEDCouplingUMesh.MergeUMeshes(tris)
+ quad=MEDCouplingUMesh("quad",2)
+ quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
+ quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
+ quads=[quad.deepCpy() for i in xrange(5)]
+ for i,elt in enumerate(quads): elt.translate([5+i,0])
+ quads=MEDCouplingUMesh.MergeUMeshes(quads)
+ m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
+ m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
+ mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
+ #
+ ff0=MEDFileField1TS()
+ f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCell")
+ f0.checkCoherency()
+ ff0.setFieldNoProfileSBT(f0)
+ #
+ fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
+ self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
+ #
+ ff0i=ff0.convertToInt()
+ self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
+ self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
+ #
+ ff1=ff0i.convertToDouble()
+ self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
+ self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
+ # With profiles
+ del arr,f0,ff0,ff1,ff0i,fspExp
+ ff0=MEDFileField1TS()
+ f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["XX [pm]","YYY [hm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellPfl")
+ f0.checkCoherency()
+ pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
+ ff0.setFieldProfile(f0,mm,0,pfl)
+ fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
+ self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
+ #
+ ff0i=ff0.convertToInt()
+ self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
+ self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
+ self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
+ #
+ ff1=ff0i.convertToDouble()
+ self.assertTrue(isinstance(ff1,MEDFileField1TS))
+ self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
+ self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
+ ## MultiTimeSteps
+ ff0=MEDFileFieldMultiTS()
+ f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(0.1,0,10)
+ f0.checkCoherency()
+ ff0.appendFieldProfile(f0,mm,0,pfl)
+ f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota(100) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(1.1,1,11)
+ f0.checkCoherency()
+ ff0.appendFieldProfile(f0,mm,0,pfl)
+ f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota(200) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(2.1,2,12)
+ f0.checkCoherency()
+ ff0.appendFieldProfile(f0,mm,0,pfl)
+ ff1=ff0.convertToInt()
+ self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
+ self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
+ for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
+ self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
+ arr=ff1.getUndergroundDataArray(dt,it)
+ arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
+ pass
+ self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
+ #
+ mm.write(fname,2)
+ ff1.write(fname,0)
+ #
+ ff1=ff1.convertToDouble()
+ self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
+ self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
+ for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
+ self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
+ arr=ff1.getUndergroundDataArray(dt,it)
+ arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
+ pass
+ self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
+ #
+ ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
+ self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
+ self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
+ for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
+ self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
+ arr=ff1.getUndergroundDataArray(dt,it)
+ arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
+ pass
+ self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
+ pass
+
+ def testMEDFileFieldPartialLoading(self):
+ fname="Pyfile69.med"
+ #
+ a=DataArrayInt() ; aa=a.getHeapMemorySize()
+ a.alloc(0,1)
+ strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
+ # building a mesh containing 30 tri3 + 40 quad4
+ tri=MEDCouplingUMesh("tri",2)
+ tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
+ tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
+ tris=[tri.deepCpy() for i in xrange(30)]
+ for i,elt in enumerate(tris): elt.translate([i,0])
+ tris=MEDCouplingUMesh.MergeUMeshes(tris)
+ quad=MEDCouplingUMesh("quad",2)
+ quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
+ quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
+ quads=[quad.deepCpy() for i in xrange(40)]
+ for i,elt in enumerate(quads): elt.translate([40+i,0])
+ quads=MEDCouplingUMesh.MergeUMeshes(quads)
+ m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
+ m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
+ mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
+ #
+ ff0=MEDFileField1TS()
+ f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCell")
+ f0.checkCoherency()
+ ff0.setFieldNoProfileSBT(f0)
+ ff0.write(fname,0)
+ #
+ fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
+ self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
+ # With profiles
+ ff0=MEDFileField1TS()
+ f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:50]) ; arr=DataArrayDouble(50*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["XX [pm]","YYY [hm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellPfl")
+ f0.checkCoherency()
+ pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
+ ff0.setFieldProfile(f0,mm,0,pfl)
+ fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
+ self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
+ ff0.write(fname,0)
+ #
+ ff0=MEDFileField1TS(fname,False)
+ self.assertEqual(ff0.getName(),"FieldCell")
+ self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
+ self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
+ heap_memory_ref=ff0.getHeapMemorySize()
+ self.assertIn(heap_memory_ref,xrange(182,298+2*strMulFac))
+ ff0.loadArrays() ##
+ arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
+ self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
+ self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
+ #
+ ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
+ self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
+ heap_memory_ref=ff0.getHeapMemorySize()
+ self.assertIn(heap_memory_ref,xrange(350,415+6*strMulFac))
+ ff0.loadArrays() ##
+ arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
+ self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
+ self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
+ ff0.loadArrays() ##
+ self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
+ self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
+ ff0.getUndergroundDataArray().setIJ(30,1,5.5)
+ self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
+ ff0.loadArrays() ##
+ self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
+ ff0.getUndergroundDataArray().setIJ(30,1,5.5)
+ self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
+ ff0.loadArraysIfNecessary() ##
+ self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
+ self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
+ heap_memory_ref=ff0.getHeapMemorySize()
+ self.assertIn(heap_memory_ref,xrange(1100,1215+2*strMulFac))
+ ff0.unloadArrays()
+ hmd=ff0.getHeapMemorySize()-heap_memory_ref
+ self.assertEqual(hmd,-800) # -50*8*2
+ ff0.loadArrays() ##
+ self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
+ #
+ ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
+ heap_memory_ref=ff0.getHeapMemorySize()
+ self.assertIn(heap_memory_ref,xrange(299,415+6*strMulFac))
+ ff0.loadArrays() ##
+ self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
+ self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
+ #
+ fieldName="FieldCellMultiTS"
+ ff0=MEDFileFieldMultiTS()
+ for t in xrange(20):
+ f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota(float(t+1000)) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName(fieldName)
+ f0.setTime(float(t)+0.1,t,100+t)
+ f0.checkCoherency()
+ ff0.appendFieldNoProfileSBT(f0)
+ pass
+ ff0.write(fname,0)
+ #
+ ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
+ heap_memory_ref=ff0.getHeapMemorySize()
+ self.assertIn(heap_memory_ref,xrange(5536,5956+(80+26)*strMulFac))
+ ff0.loadArrays()
+ self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
+ del ff0
+ #
+ ffs=MEDFileFields(fname,False)
+ heap_memory_ref=ffs.getHeapMemorySize()
+ self.assertIn(heap_memory_ref,xrange(5335,6687+(80+50)*strMulFac))
+ ffs.loadArrays()
+ self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
+ pass
+
+ def testMEDFileMeshReadSelector1(self):
+ mrs=MEDFileMeshReadSelector()
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs.__str__() ; mrs.__repr__()
+ #
+ mrs=MEDFileMeshReadSelector(0)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(1)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(2)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(3)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(4)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(5)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(6)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(7)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(8)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(9)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(10)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(11)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(12)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(13)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(14)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(15)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(16)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(17)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(18)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(19)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(20)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(21)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(22)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(23)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(24)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(25)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(26)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(27)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(28)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(29)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(30)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(31)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(32)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(33)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(34)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(35)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(36)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(37)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(38)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(39)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(40)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(41)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(42)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(43)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(44)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(45)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(46)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(47)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(48)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(49)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(50)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(51)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(52)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(53)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(54)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(55)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(56)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(57)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(58)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(59)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(60)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(61)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(62)
+ self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ mrs=MEDFileMeshReadSelector(63)
+ self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
+ #
+ mrs=MEDFileMeshReadSelector(63)
+ mrs.setCellFamilyFieldReading(False)
+ self.assertEqual(mrs.getCode(),62)
+ mrs.setCellFamilyFieldReading(True)
+ self.assertEqual(mrs.getCode(),63)
+ mrs.setNodeFamilyFieldReading(False)
+ self.assertEqual(mrs.getCode(),61)
+ mrs.setNodeFamilyFieldReading(True)
+ self.assertEqual(mrs.getCode(),63)
+ mrs.setCellNameFieldReading(False)
+ self.assertEqual(mrs.getCode(),59)
+ mrs.setCellNameFieldReading(True)
+ self.assertEqual(mrs.getCode(),63)
+ mrs.setNodeNameFieldReading(False)
+ self.assertEqual(mrs.getCode(),55)
+ mrs.setNodeNameFieldReading(True)
+ self.assertEqual(mrs.getCode(),63)
+ mrs.setCellNumFieldReading(False)
+ self.assertEqual(mrs.getCode(),47)
+ mrs.setCellNumFieldReading(True)
+ self.assertEqual(mrs.getCode(),63)
+ mrs.setNodeNumFieldReading(False)
+ self.assertEqual(mrs.getCode(),31)
+ mrs.setNodeNumFieldReading(True)
+ self.assertEqual(mrs.getCode(),63)
+ pass
+
+ def testPartialReadOfMeshes(self):
+ fname="Pyfile70.med"
+ # building a mesh containing 4 tri3 + 5 quad4
+ tri=MEDCouplingUMesh("tri",2)
+ tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
+ tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
+ tris=[tri.deepCpy() for i in xrange(4)]
+ for i,elt in enumerate(tris): elt.translate([i,0])
+ tris=MEDCouplingUMesh.MergeUMeshes(tris)
+ quad=MEDCouplingUMesh("quad",2)
+ quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
+ quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
+ quads=[quad.deepCpy() for i in xrange(5)]
+ for i,elt in enumerate(quads): elt.translate([5+i,0])
+ quads=MEDCouplingUMesh.MergeUMeshes(quads)
+ m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
+ m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
+ m1=m.buildDescendingConnectivity()[0]
+ mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
+ #
+ grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
+ grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
+ mm.setGroupsAtLevel(0,[grp0,grp1])
+ grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
+ grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
+ mm.setGroupsAtLevel(-1,[grp2,grp3])
+ grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
+ grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
+ mm.setGroupsAtLevel(1,[grp4,grp5])
+ mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
+ mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
+ mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
+ #
+ mm.write(fname,2)
+ ##
+ mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
+ b4_ref_heap_mem=mm.getHeapMemorySize()
+ mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
+ mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
+ ref_heap_mem=mm.getHeapMemorySize()
+ # check the gain of memory using 1GTUMesh instead of UMesh
+ self.assertTrue(ref_heap_mem-b4_ref_heap_mem>=(32+9)*4*2-32)# 32+9=nbCells 4=sizeof(int) 2=the types+index -32=loss linked to vector
+ #
+ mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
+ self.assertEqual(len(mm.getGroupsNames()),0)
+ self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
+ self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
+ self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
+ self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
+ self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
+ self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
+ delta1=ref_heap_mem-mm.getHeapMemorySize()
+ self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
+ #
+ mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
+ self.assertEqual(len(mm.getGroupsNames()),6)
+ self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
+ self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
+ self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
+ self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
+ self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
+ self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
+ delta2=ref_heap_mem-mm.getHeapMemorySize()
+ self.assertTrue(delta2<delta1)
+ self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
+ #
+ mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
+ self.assertEqual(len(mm.getGroupsNames()),6)
+ self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
+ self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
+ self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
+ self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
+ self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
+ self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
+ delta3=ref_heap_mem-mm.getHeapMemorySize()
+ self.assertTrue(delta3<delta2)
+ self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
+ #
+ mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
+ self.assertEqual(len(mm.getGroupsNames()),6)
+ self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
+ self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
+ self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
+ self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
+ self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
+ self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
+ delta4=ref_heap_mem-mm.getHeapMemorySize()
+ self.assertTrue(delta4<delta3)
+ self.assertTrue(delta4>=32*4*2)
+ #
+ mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
+ self.assertEqual(len(mm.getGroupsNames()),6)
+ self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
+ self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
+ self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
+ self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
+ self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
+ self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
+ delta5=ref_heap_mem-mm.getHeapMemorySize()
+ self.assertTrue(delta5<delta4)
+ self.assertEqual(delta5,0)
+ pass
+
+ # this test checks that setFieldProfile perform a check of the array length
+ # compared to the profile length. This test also checks that mesh attribute of field
+ # is not used by setFieldProfile (because across this test mesh is equal to None)
+ def testCheckCompatibilityPfl1(self):
+ # building a mesh containing 4 tri3 + 5 quad4
+ tri=MEDCouplingUMesh("tri",2)
+ tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
+ tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
+ tris=[tri.deepCpy() for i in xrange(4)]
+ for i,elt in enumerate(tris): elt.translate([i,0])
+ tris=MEDCouplingUMesh.MergeUMeshes(tris)
+ quad=MEDCouplingUMesh("quad",2)
+ quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
+ quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
+ quads=[quad.deepCpy() for i in xrange(5)]
+ for i,elt in enumerate(quads): elt.translate([5+i,0])
+ quads=MEDCouplingUMesh.MergeUMeshes(quads)
+ m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
+ m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
+ m1=m.buildDescendingConnectivity()[0]
+ mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
+ #
+ f1ts=MEDFileField1TS()
+ f=MEDCouplingFieldDouble(ON_NODES)
+ vals=DataArrayDouble(7) ; vals.iota(1000)
+ f.setArray(vals)
+ f.setName("anonymous") # f has no mesh it is not a bug
+ pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
+ f1ts.setFieldProfile(f,mm,0,pfl)
+ #
+ f1ts=MEDFileField1TS()
+ f=MEDCouplingFieldDouble(ON_NODES)
+ vals=DataArrayDouble(8) ; vals.iota(1000)
+ f.setArray(vals)
+ f.setName("anonymous") # f has no mesh it is not a bug
+ pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
+ self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
+ #
+ f1ts=MEDFileField1TS()
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ vals=DataArrayDouble(7) ; vals.iota(1000)
+ f.setArray(vals)
+ f.setName("anonymous") # f has no mesh it is not a bug
+ pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
+ f1ts.setFieldProfile(f,mm,0,pfl)
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
+ #
+ f1ts=MEDFileField1TS()
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT)
+ vals=DataArrayDouble(27) ; vals.iota(1000)
+ f.setArray(vals)
+ f.setName("anonymous") # f has no mesh it is not a bug
+ pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
+ f.setMesh(m[pfl])
+ f.setGaussLocalizationOnCells([0,1],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.1,0.1],[0.3,0.6,0.1])
+ f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
+ f.setGaussLocalizationOnCells([3,4,5,6],[0.,0.,1.,0.,1.,1.,0.,1.],[0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.5,0.5],[0.2,0.3,0.4,0.07,0.03])
+ f.setMesh(None)
+ f1ts.setFieldProfile(f,mm,0,pfl)
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
+ vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
+ self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
+ vals=DataArrayDouble(27) ; vals.iota(1000)
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
+ #
+ f1ts=MEDFileField1TS()
+ f=MEDCouplingFieldDouble(ON_GAUSS_NE)
+ vals=DataArrayDouble(25) ; vals.iota(1000)
+ f.setArray(vals)
+ f.setName("anonymous") # f has no mesh it is not a bug
+ pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
+ f1ts.setFieldProfile(f,mm,0,pfl)
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
+ vals2=DataArrayDouble(26) ; vals2.iota(1050)
+ f.setArray(vals2)
+ self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
+ #
+ f1ts=MEDFileField1TS()
+ self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
+ self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
+ f.setArray(vals)
+ f1ts.setFieldProfile(f,mm,0,pfl)
+ pass
+
+ def testWRMeshWithNoCells(self):
+ fname="Pyfile71.med"
+ a=DataArrayDouble(4) ; a.iota()
+ c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
+ m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
+ m=MEDFileUMesh()
+ m.setMeshAtLevel(0,m00)
+ m.setRenumFieldArr(1,DataArrayInt(range(10,26)))
+ m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
+ m.write(fname,2)
+ del m,a,c,m0,m00
+ #
+ m=MEDFileMesh.New(fname)
+ self.assertEqual((),m.getNonEmptyLevels())
+ self.assertTrue(m.getCoords().isEqual(DataArrayDouble([(0,0),(1,0),(2,0),(3,0),(0,1),(1,1),(2,1),(3,1),(0,2),(1,2),(2,2),(3,2),(0,3),(1,3),(2,3),(3,3)]),1e-12))
+ self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(range(10,26))))
+ self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
+ pass
+
+ #@unittest.skipUnless(False,"requires Vadim's green light")
+ def testWRQPolyg1(self):
+ fname="Pyfile72.med"
+ m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
+ m.insertNextCell([0,2,1,3])
+ m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
+ #
+ ms=[m.deepCpy() for i in xrange(4)]
+ for i,elt in enumerate(ms):
+ elt.translate([float(i)*1.5,0.])
+ pass
+ m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
+ m0.convertAllToPoly()
+ #
+ ms=[m.deepCpy() for i in xrange(5)]
+ for i,elt in enumerate(ms):
+ elt.translate([float(i)*1.5,1.5])
+ pass
+ m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
+ m1.convertAllToPoly()
+ m1.convertLinearCellsToQuadratic()
+ #
+ m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
+ ##
+ mm=MEDFileUMesh()
+ mm.setMeshAtLevel(0,m)
+ grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
+ grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
+ grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
+ mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
+ ##
+ mm.write(fname,2)
+ del mm
+ #
+ mm_read=MEDFileUMesh(fname)
+ self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
+ self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
+ self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
+ ##
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
+ f.setMesh(m)
+ arr0=DataArrayDouble(9) ; arr0.iota()
+ arr1=DataArrayDouble(9) ; arr1.iota(100)
+ arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
+ f.setArray(arr) ; f.checkCoherency()
+ f.setTime(5.6,1,2)
+ ff=MEDFileField1TS()
+ ff.setFieldNoProfileSBT(f)
+ ff.write(fname,0)
+ ##
+ ff_read=MEDFileField1TS(fname)
+ f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
+ self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
+ pass
+
+ def testLoadIfNecessaryOnFromScratchFields0(self):
+ """
+ This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
+ """
+ fname="Pyfile77.med"
+ coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
+ m.allocateCells()
+ m.insertNextCell(NORM_QUAD4,[0,5,3,2])
+ m.insertNextCell(NORM_QUAD4,[4,2,3,1])
+ m.finishInsertingCells()
+ #
+ mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
+ ms=MEDFileMeshes() ; ms.pushMesh(mm)
+ fs=MEDFileFields()
+ arrs=4*[None]
+ #
+ ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
+ f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
+ f0.setTime(1.1,1,1)
+ f0.setName("myELNOField")
+ arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
+ f0.setArray(arrs[0])
+ ff0.appendFieldNoProfileSBT(f0)
+ #
+ f0.setTime(2.2,2,1)
+ arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
+ f0.setArray(arrs[1])
+ ff0.appendFieldNoProfileSBT(f0)
+ #
+ f0.setTime(3.3,3,1)
+ arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
+ f0.setArray(arrs[2])
+ ff0.appendFieldNoProfileSBT(f0)
+ #
+ f0.setTime(4.4,4,1)
+ arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
+ f0.setArray(arrs[3])
+ ff0.appendFieldNoProfileSBT(f0)
+ #
+ for i,arr in enumerate(arrs):
+ self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
+ fs[0][i].loadArraysIfNecessary()
+ self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
+ pass
+ fs.loadArraysIfNecessary()
+ for i,arr in enumerate(arrs):
+ self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
+ pass
+ fs[0].loadArraysIfNecessary()
+ for i,arr in enumerate(arrs):
+ self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
+ pass
+ pass
+
+ def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
+ """ This test is very important, because the same mechanism is used by the MEDReader to generate a field on all the mesh without any processing and memory.
+ """
+ fname="Pyfile78.med"
+ coords=DataArrayDouble([-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ],9,3)
+ targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
+ m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
+ m0.allocateCells()
+ for elt in [[0,1,2,3],[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7],[5,6,7,8]]:#6
+ m0.insertNextCell(NORM_TETRA4,elt)
+ pass
+ for elt in [[0,1,2,3,4],[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8]]:#5
+ m0.insertNextCell(NORM_PYRA5,elt)
+ pass
+ for elt in [[0,1,2,3,4,5],[1,2,3,4,5,6],[2,3,4,5,6,7],[3,4,5,6,7,8]]:#4
+ m0.insertNextCell(NORM_PENTA6,elt)
+ pass
+ m0.checkCoherency2()
+ m1=MEDCouplingUMesh(); m1.setName("mesh")
+ m1.setMeshDimension(2);
+ m1.allocateCells(5);
+ m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
+ m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
+ m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
+ m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
+ m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
+ m1.setCoords(coords);
+ m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
+ m3.allocateCells()
+ m3.insertNextCell(NORM_POINT1,[2])
+ m3.insertNextCell(NORM_POINT1,[3])
+ m3.insertNextCell(NORM_POINT1,[4])
+ m3.insertNextCell(NORM_POINT1,[5])
+ #
+ mm=MEDFileUMesh()
+ mm.setMeshAtLevel(0,m0)
+ mm.setMeshAtLevel(-1,m1)
+ mm.setMeshAtLevel(-3,m3)
+ mm.write(fname,2)
+ #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
+ mm=MEDFileMesh.New(fname)
+ fs=MEDFileFields()
+ fmts=MEDFileFieldMultiTS()
+ f1ts=MEDFileField1TS()
+ for lev in mm.getNonEmptyLevels():
+ for gt in mm.getGeoTypesAtLevel(lev):
+ p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
+ arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
+ f.setArray(arr) ; f.setName("f0")
+ f1ts.setFieldNoProfileSBT(f)
+ pass
+ pass
+ self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
+ for lev in [0,-1,-3]:
+ mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
+ pass
+ fmts.pushBackTimeStep(f1ts)
+ fs.pushField(fmts)
+ fs.write(fname,0)
+ del fs,fmts,f1ts
+ #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
+ fs=MEDFileFields(fname)
+ self.assertEqual(len(fs),1)
+ self.assertEqual(len(fs[0]),1)
+ f1ts=fs[0][0]
+ self.assertEqual(f1ts.getFieldSplitedByType(),[(0,[(0,(0,4),'','')]),(3,[(0,(4,6),'','')]),(4,[(0,(6,9),'','')]),(14,[(0,(9,15),'','')]),(15,[(0,(15,20),'','')]),(16,[(0,(20,24),'','')])])
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0,1,2,3,0,1,0,1,2,0,1,2,3,4,5,0,1,2,3,4,0,1,2,3]),1e-12))
+ pass
+
+ def testMEDFileUMeshSetName(self):
+ """ This test is a small but important one for MEDReader in sauv mode. When .sauv file is loaded the convertion is performed in memory and a preparation is done then.
+ This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
+ """
+ fname="Pyfile79.med"
+ targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
+ mm=MEDFileUMesh()
+ m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
+ coords=DataArrayDouble([-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ],9,3)
+ m0.allocateCells(5);
+ m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
+ m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
+ m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
+ m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
+ m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
+ m0.setCoords(coords);
+ mm.setMeshAtLevel(0,m0)
+ m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
+ m2.allocateCells()
+ m2.insertNextCell(NORM_POINT1,[2])
+ m2.insertNextCell(NORM_POINT1,[3])
+ m2.insertNextCell(NORM_POINT1,[4])
+ m2.insertNextCell(NORM_POINT1,[5])
+ mm.setMeshAtLevel(-2,m2)
+ self.assertEqual(mm.getName(),"")
+ self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
+ mm.forceComputationOfParts()
+ self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
+ mm.setName("abc")
+ self.assertEqual(mm.getName(),"abc")
+ self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
+ self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
+ self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
+ self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
+ pass
+
+ def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
+ fileName="Pyfile80.med"
+ m=MEDCouplingCMesh() ; m.setName("cmesh")
+ arr=DataArrayDouble(6) ; arr.iota()
+ m.setCoords(arr,arr)
+ nbCells=m.getNumberOfCells()
+ self.assertEqual(25,nbCells)
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setName("FieldOnCell") ; f.setMesh(m)
+ arr=DataArrayDouble(nbCells) ; arr.iota()
+ mm=MEDFileCMesh()
+ mm.setMesh(m)
+ #
+ fmts=MEDFileFieldMultiTS()
+ #
+ for i in xrange(nbCells):
+ t=(float(i)+0.1,i+1,-i-2)
+ f.setTime(*t)
+ arr2=DataArrayDouble(nbCells)
+ perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
+ arr2[perm]=arr
+ f.setArray(arr2)
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f)
+ fmts.pushBackTimeStep(f1ts)
+ pass
+ fmts.unloadArraysWithoutDataLoss()
+ self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ fs=MEDFileFields() ; fs.pushField(fmts)
+ self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ fs.unloadArraysWithoutDataLoss()
+ self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ f1ts=fs[0][0]
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ f1ts.unloadArraysWithoutDataLoss()
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ mm.write(fileName,2)
+ fs.write(fileName,0)
+ del m,fmts,mm,f,f1ts
+ ##
+ mm=MEDFileMesh.New(fileName)
+ fmts=MEDFileFieldMultiTS(fileName)
+ self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ fmts.unloadArraysWithoutDataLoss()
+ self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
+ fmts.loadArraysIfNecessary()
+ self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ del mm,fmts
+ fs=MEDFileFields(fileName)
+ self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ fs.unloadArraysWithoutDataLoss()
+ self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
+ fs.loadArraysIfNecessary()
+ self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ del fs
+ f1ts=MEDFileField1TS(fileName)
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ f1ts.unloadArraysWithoutDataLoss()
+ self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
+ f1ts.loadArraysIfNecessary()
+ self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([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.]),1e-12))
+ pass
+
+ def testMEDFileUMeshLoadPart1(self):
+ """ This method tests MEDFileUMesh.LoadPart that loads only a part of a specified mesh in a MED file. The part is specfied using a slice of cell ids. Only nodes on which cells lies are loaded to reduce at most the amount of
+ memory of the returned instance.
+ """
+ fileName="Pyfile81.med"
+ arr=DataArrayDouble(6) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ m.setName("Mesh")
+ m.changeSpaceDimension(3,0.)
+ infos=["aa [b]","cc [de]","gg [klm]"]
+ m.getCoords().setInfoOnComponents(infos)
+ m.checkCoherency2()
+ mm=MEDFileUMesh()
+ mm.setMeshAtLevel(0,m)
+ m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh")
+ m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
+ mm.setMeshAtLevel(-1,m1)
+ renum0=DataArrayInt([3,6,7,10,11,0,2,1,9,8,5,4,12,13,14,24,23,22,21,20,19,18,17,16,15])
+ famField0=DataArrayInt([-3,-6,-7,-10,-11,0,-2,-1,-9,-8,-5,-4,-12,-13,-14,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15])
+ namesCellL0=DataArrayAsciiChar(25,16)
+ namesCellL0[:]=["Cell#%.3d "%(i) for i in xrange(25)]
+ renumM1=DataArrayInt([3,4,0,2,1])
+ famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
+ mm.setRenumFieldArr(0,renum0)
+ mm.setFamilyFieldArr(0,famField0)
+ mm.setNameFieldAtLevel(0,namesCellL0)
+ mm.setRenumFieldArr(-1,renumM1)
+ mm.setFamilyFieldArr(-1,famFieldM1)
+ renum1=DataArrayInt([13,16,17,20,21,10,12,11,19,18,15,14,22,23,24,34,33,32,31,30,29,28,27,26,25,45,44,43,42,41,40,39,38,37,36,35])
+ famField1=DataArrayInt([-13,-16,-17,-20,-21,-10,-12,-11,-19,-18,-15,-14,-22,-23,-24,-34,-33,-32,-31,-30,-29,-28,-27,-26,-25,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35])
+ namesNodes=DataArrayAsciiChar(36,16)
+ namesNodes[:]=["Node#%.3d "%(i) for i in xrange(36)]
+ mm.setRenumFieldArr(1,renum1)
+ mm.setFamilyFieldArr(1,famField1)
+ mm.setNameFieldAtLevel(1,namesNodes)
+ mm.setFamilyId("Fam7",77)
+ mm.setFamilyId("Fam8",88)
+ mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
+ mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
+ mm.write(fileName,2)
+ #
+ mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
+ self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
+ self.assertTrue(mm0.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,11,10,16,17])))
+ coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),(5,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(4,1,0),(5,1,0),(0,2,0),(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0)]) ; coo.setInfoOnComponents(infos)
+ self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
+ self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
+ self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
+ self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
+ self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
+ self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
+ self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
+ #
+ mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
+ self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
+ self.assertTrue(mm1.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,6,5,11,12,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,12,11,17,18,13,12,18,19,14,13,19,20,15,14,20,21,16,15,21,22])))
+ coo=DataArrayDouble([(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0),(0,3,0),(1,3,0),(2,3,0),(3,3,0),(4,3,0),(5,3,0),(0,4,0),(1,4,0),(2,4,0),(3,4,0),(4,4,0),(5,4,0),(0,5,0),(1,5,0),(2,5,0),(3,5,0),(4,5,0),(5,5,0)]) ; coo.setInfoOnComponents(infos)
+ self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
+ self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
+ self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
+ self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
+ self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
+ self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
+ self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
+ #
+ mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
+ self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
+ self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
+ self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
+ self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
+ self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
+ self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
+ self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
+ self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,11,10,16,17])))
+ self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
+ coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),(5,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(4,1,0),(5,1,0),(0,2,0),(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0)]) ; coo.setInfoOnComponents(infos)
+ self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
+ self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
+ self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
+ self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
+ pass
+
+ def testMEDFileFieldsLoadPart1(self):
+ """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
+ """
+ fileName="Pyfile82.med"
+ meshName="Mesh"
+ compos=["aa [kg]","bbb [m/s]"]
+ arr=DataArrayDouble(6) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ m.setName(meshName)
+ m.changeSpaceDimension(3,0.)
+ infos=["aa [b]","cc [de]","gg [klm]"]
+ m.getCoords().setInfoOnComponents(infos)
+ m.checkCoherency2()
+ f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
+ f.setName("Field")
+ arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
+ arr[:,0]=range(25)
+ arr[:,1]=range(100,125)
+ f.setArray(arr)
+ MEDLoader.WriteField(fileName,f,2)
+ f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
+ f.setName("FieldNode")
+ arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
+ arr[:,0]=range(200,236)
+ arr[:,1]=range(300,336)
+ f.setArray(arr)
+ f.checkCoherency()
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f)
+ #
+ ms=MEDFileMeshes()
+ mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
+ ms.pushMesh(mm)
+ fs=MEDFileFields.LoadPartOf(fileName,False,ms)
+ self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
+ #
+ ms=MEDFileMeshes()
+ mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
+ ms.pushMesh(mm)
+ fs=MEDFileFields.LoadPartOf(fileName,False,ms)
+ fs=fs.deepCpy()
+ fs[0][0].loadArrays()
+ arr=DataArrayDouble(12,2) ; arr[:,0]=range(3,15) ; arr[:,1]=range(103,115)
+ arr.setInfoOnComponents(compos)
+ self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
+ fs[1][0].loadArrays()
+ arr=DataArrayDouble(21,2) ; arr[:,0]=range(203,224) ; arr[:,1]=range(303,324)
+ arr.setInfoOnComponents(compos)
+ self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
+ pass
+
+ def testMEDFileWithoutCells1(self):
+ fileName="Pyfile83.med"
+ coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
+ coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
+ mm=MEDFileUMesh()
+ mm.setCoords(coo)
+ mm.setName("mesh")
+ mm.write(fileName,2)
+ #
+ mm=MEDFileMesh.New(fileName)
+ self.assertEqual(mm.getName(),"mesh")
+ self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
+ pass
+
+ def testZipCoordsWithLoadPart1(self):
+ """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
+ """
+ fileName="Pyfile84.med"
+ meshName="Mesh"
+ compos=["aa [kg]","bbb [m/s]"]
+ arr=DataArrayDouble(6) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ m.setName(meshName)
+ m.changeSpaceDimension(3,0.)
+ infos=["aa [b]","cc [de]","gg [klm]"]
+ m.getCoords().setInfoOnComponents(infos)
+ m.checkCoherency2()
+ f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
+ f.setName("Field")
+ arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
+ arr[:,0]=range(25)
+ arr[:,1]=range(100,125)
+ f.setArray(arr)
+ MEDLoader.WriteField(fileName,f,2)
+ f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
+ f.setName("FieldNode")
+ arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
+ arr[:,0]=range(200,236)
+ arr[:,1]=range(300,336)
+ f.setArray(arr)
+ f.checkCoherency()
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f)
+ #
+ ms=MEDFileMeshes()
+ mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
+ ms.pushMesh(mm)
+ spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
+ self.assertEqual(spd.getSlice(),slice(4,6,1))
+ spd=mm.getPartDefAtLevel(1)
+ self.assertEqual(spd.getSlice(),slice(4,14,1))
+ self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
+ mm.zipCoords() # <- The important line is here !
+ spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
+ self.assertEqual(spd.getSlice(),slice(4,6,1))
+ spd=mm.getPartDefAtLevel(1)
+ self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
+ self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
+ fs=MEDFileFields.LoadPartOf(fileName,False,ms)
+ fs[0][0].loadArrays()
+ arr=DataArrayDouble([(4,104),(5,105)])
+ arr.setInfoOnComponents(compos)
+ self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
+ fs[1][0].loadArrays()
+ arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
+ arr.setInfoOnComponents(compos)
+ self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
+ pass
+
+ def testMEDFileCMeshSetGroupsAtLevel(self):
+ """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
+ """
+ m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
+ m.setName("Mesh")
+ mm=MEDFileCMesh() ; mm.setMesh(m)
+ grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
+ mm.setGroupsAtLevel(0,[grp])
+ self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
+ pass
+
+ def testMEDFileUMeshBuildExtrudedMesh1(self):
+ """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
+ fileName="Pyfile85.med"
+ meshName2D="Mesh"
+ meshName1D="Mesh1D"
+ meshName3DOut="Mesh3D"
+ #
+ d1=DataArrayInt([0,4,20,24])
+ d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
+ #
+ a=DataArrayDouble(6) ; a.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(a,a)
+ m=m.buildUnstructured()
+ d1c=d1.buildComplement(m.getNumberOfCells())
+ m=m[d1c] ; m.zipCoords()
+ m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
+ m0.simplexize(0)
+ m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
+ m.setName(meshName2D)
+ mMinus1,a,b,c,d=m.buildDescendingConnectivity()
+ e=d.deltaShiftIndex().getIdsEqual(1)
+ #
+ mm=MEDFileUMesh()
+ mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
+ grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
+ mm.setGroupsAtLevel(0,[grp0])
+ grp1=e ; grp1.setName("grp1")
+ mm.setGroupsAtLevel(-1,[grp1])
+ mm.write(fileName,2)
+ #
+ a=DataArrayDouble(3) ; a.iota()
+ tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
+ tmp.setName(meshName1D)
+ tmp.changeSpaceDimension(3)
+ tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
+ mm1D=MEDFileUMesh()
+ mm1D.setMeshAtLevel(0,tmp)
+ mm1D.write(fileName,0)
+ # test is here !
+ mm2D=MEDFileMesh.New(fileName,meshName2D)
+ mm1D=MEDFileMesh.New(fileName,meshName1D)
+ m1D=mm1D.getMeshAtLevel(0)
+ mm3D=mm2D.buildExtrudedMesh(m1D,0)
+ #
+ self.assertEqual(mm3D.getName(),mm2D.getName())
+ self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
+ self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
+ self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
+ self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
+ self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
+ self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
+ self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
+ self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
+ self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
+ d=DataArrayDouble([(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(4.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(4.,1.,0.),(5.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(4.,2.,0.),(5.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.),(4.,3.,0.),(5.,3.,0.),(0.,4.,0.),(1.,4.,0.),(2.,4.,0.),(3.,4.,0.),(4.,4.,0.),(5.,4.,0.),(1.,5.,0.),(2.,5.,0.),(3.,5.,0.),(4.,5.,0.),(1.,0.,1.),(2.,0.,1.),(3.,0.,1.),(4.,0.,1.),(0.,1.,1.),(1.,1.,1.),(2.,1.,1.),(3.,1.,1.),(4.,1.,1.),(5.,1.,1.),(0.,2.,1.),(1.,2.,1.),(2.,2.,1.),(3.,2.,1.),(4.,2.,1.),(5.,2.,1.),(0.,3.,1.),(1.,3.,1.),(2.,3.,1.),(3.,3.,1.),(4.,3.,1.),(5.,3.,1.),(0.,4.,1.),(1.,4.,1.),(2.,4.,1.),(3.,4.,1.),(4.,4.,1.),(5.,4.,1.),(1.,5.,1.),(2.,5.,1.),(3.,5.,1.),(4.,5.,1.),(1.,0.,2.),(2.,0.,2.),(3.,0.,2.),(4.,0.,2.),(0.,1.,2.),(1.,1.,2.),(2.,1.,2.),(3.,1.,2.),(4.,1.,2.),(5.,1.,2.),(0.,2.,2.),(1.,2.,2.),(2.,2.,2.),(3.,2.,2.),(4.,2.,2.),(5.,2.,2.),(0.,3.,2.),(1.,3.,2.),(2.,3.,2.),(3.,3.,2.),(4.,3.,2.),(5.,3.,2.),(0.,4.,2.),(1.,4.,2.),(2.,4.,2.),(3.,4.,2.),(4.,4.,2.),(5.,4.,2.),(1.,5.,2.),(2.,5.,2.),(3.,5.,2.),(4.,5.,2.)])
+ self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
+ d=DataArrayInt([16,1,0,5,33,32,37,16,1,5,6,33,37,38,16,2,1,6,34,33,38,16,2,6,7,34,38,39,16,3,2,7,35,34,39,16,3,7,8,35,39,40,16,5,4,10,37,36,42,16,5,10,11,37,42,43,16,9,8,14,41,40,46,16,9,14,15,41,46,47,16,11,10,16,43,42,48,16,11,16,17,43,48,49,16,15,14,20,47,46,52,16,15,20,21,47,52,53,16,17,16,22,49,48,54,16,17,22,23,49,54,55,16,21,20,26,53,52,58,16,21,26,27,53,58,59,16,24,23,28,56,55,60,16,24,28,29,56,60,61,16,25,24,29,57,56,61,16,25,29,30,57,61,62,16,26,25,30,58,57,62,16,26,30,31,58,62,63,16,33,32,37,65,64,69,16,33,37,38,65,69,70,16,34,33,38,66,65,70,16,34,38,39,66,70,71,16,35,34,39,67,66,71,16,35,39,40,67,71,72,16,37,36,42,69,68,74,16,37,42,43,69,74,75,16,41,40,46,73,72,78,16,41,46,47,73,78,79,16,43,42,48,75,74,80,16,43,48,49,75,80,81,16,47,46,52,79,78,84,16,47,52,53,79,84,85,16,49,48,54,81,80,86,16,49,54,55,81,86,87,16,53,52,58,85,84,90,16,53,58,59,85,90,91,16,56,55,60,88,87,92,16,56,60,61,88,92,93,16,57,56,61,89,88,93,16,57,61,62,89,93,94,16,58,57,62,90,89,94,16,58,62,63,90,94,95,18,6,5,11,12,38,37,43,44,18,7,6,12,13,39,38,44,45,18,8,7,13,14,40,39,45,46,18,12,11,17,18,44,43,49,50,18,13,12,18,19,45,44,50,51,18,14,13,19,20,46,45,51,52,18,18,17,23,24,50,49,55,56,18,19,18,24,25,51,50,56,57,18,20,19,25,26,52,51,57,58,18,38,37,43,44,70,69,75,76,18,39,38,44,45,71,70,76,77,18,40,39,45,46,72,71,77,78,18,44,43,49,50,76,75,81,82,18,45,44,50,51,77,76,82,83,18,46,45,51,52,78,77,83,84,18,50,49,55,56,82,81,87,88,18,51,50,56,57,83,82,88,89,18,52,51,57,58,84,83,89,90])
+ self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
+ d=DataArrayInt([0,7,14,21,28,35,42,49,56,63,70,77,84,91,98,105,112,119,126,133,140,147,154,161,168,175,182,189,196,203,210,217,224,231,238,245,252,259,266,273,280,287,294,301,308,315,322,329,336,345,354,363,372,381,390,399,408,417,426,435,444,453,462,471,480,489,498])
+ self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
+ d=DataArrayInt([3,1,0,5,3,1,5,6,3,2,1,6,3,2,6,7,3,3,2,7,3,3,7,8,3,5,4,10,3,5,10,11,3,9,8,14,3,9,14,15,3,11,10,16,3,11,16,17,3,15,14,20,3,15,20,21,3,17,16,22,3,17,22,23,3,21,20,26,3,21,26,27,3,24,23,28,3,24,28,29,3,25,24,29,3,25,29,30,3,26,25,30,3,26,30,31,3,65,64,69,3,65,69,70,3,66,65,70,3,66,70,71,3,67,66,71,3,67,71,72,3,69,68,74,3,69,74,75,3,73,72,78,3,73,78,79,3,75,74,80,3,75,80,81,3,79,78,84,3,79,84,85,3,81,80,86,3,81,86,87,3,85,84,90,3,85,90,91,3,88,87,92,3,88,92,93,3,89,88,93,3,89,93,94,3,90,89,94,3,90,94,95,4,1,0,32,33,4,0,5,37,32,4,5,1,33,37,4,5,6,38,37,4,6,1,33,38,4,2,1,33,34,4,6,2,34,38,4,6,7,39,38,4,7,2,34,39,4,3,2,34,35,4,7,3,35,39,4,7,8,40,39,4,8,3,35,40,4,5,4,36,37,4,4,10,42,36,4,10,5,37,42,4,10,11,43,42,4,11,5,37,43,4,9,8,40,41,4,8,14,46,40,4,14,9,41,46,4,14,15,47,46,4,15,9,41,47,4,10,16,48,42,4,16,11,43,48,4,16,17,49,48,4,17,11,43,49,4,14,20,52,46,4,20,15,47,52,4,20,21,53,52,4,21,15,47,53,4,16,22,54,48,4,22,17,49,54,4,22,23,55,54,4,23,17,49,55,4,20,26,58,52,4,26,21,53,58,4,26,27,59,58,4,27,21,53,59,4,24,23,55,56,4,23,28,60,55,4,28,24,56,60,4,28,29,61,60,4,29,24,56,61,4,25,24,56,57,4,29,25,57,61,4,29,30,62,61,4,30,25,57,62,4,26,25,57,58,4,30,26,58,62,4,30,31,63,62,4,31,26,58,63,4,11,12,44,43,4,12,6,38,44,4,12,13,45,44,4,13,7,39,45,4,13,14,46,45,4,17,18,50,49,4,18,12,44,50,4,18,19,51,50,4,19,13,45,51,4,19,20,52,51,4,24,18,50,56,4,25,19,51,57,4,33,32,64,65,4,32,37,69,64,4,37,33,65,69,4,37,38,70,69,4,38,33,65,70,4,34,33,65,66,4,38,34,66,70,4,38,39,71,70,4,39,34,66,71,4,35,34,66,67,4,39,35,67,71,4,39,40,72,71,4,40,35,67,72,4,37,36,68,69,4,36,42,74,68,4,42,37,69,74,4,42,43,75,74,4,43,37,69,75,4,41,40,72,73,4,40,46,78,72,4,46,41,73,78,4,46,47,79,78,4,47,41,73,79,4,42,48,80,74,4,48,43,75,80,4,48,49,81,80,4,49,43,75,81,4,46,52,84,78,4,52,47,79,84,4,52,53,85,84,4,53,47,79,85,4,48,54,86,80,4,54,49,81,86,4,54,55,87,86,4,55,49,81,87,4,52,58,90,84,4,58,53,85,90,4,58,59,91,90,4,59,53,85,91,4,56,55,87,88,4,55,60,92,87,4,60,56,88,92,4,60,61,93,92,4,61,56,88,93,4,57,56,88,89,4,61,57,89,93,4,61,62,94,93,4,62,57,89,94,4,58,57,89,90,4,62,58,90,94,4,62,63,95,94,4,63,58,90,95,4,43,44,76,75,4,44,38,70,76,4,44,45,77,76,4,45,39,71,77,4,45,46,78,77,4,49,50,82,81,4,50,44,76,82,4,50,51,83,82,4,51,45,77,83,4,51,52,84,83,4,56,50,82,88,4,57,51,83,89,4,6,5,11,12,4,7,6,12,13,4,8,7,13,14,4,12,11,17,18,4,13,12,18,19,4,14,13,19,20,4,18,17,23,24,4,19,18,24,25,4,20,19,25,26,4,70,69,75,76,4,71,70,76,77,4,72,71,77,78,4,76,75,81,82,4,77,76,82,83,4,78,77,83,84,4,82,81,87,88,4,83,82,88,89,4,84,83,89,90])
+ self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
+ d=DataArrayInt([0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,197,202,207,212,217,222,227,232,237,242,247,252,257,262,267,272,277,282,287,292,297,302,307,312,317,322,327,332,337,342,347,352,357,362,367,372,377,382,387,392,397,402,407,412,417,422,427,432,437,442,447,452,457,462,467,472,477,482,487,492,497,502,507,512,517,522,527,532,537,542,547,552,557,562,567,572,577,582,587,592,597,602,607,612,617,622,627,632,637,642,647,652,657,662,667,672,677,682,687,692,697,702,707,712,717,722,727,732,737,742,747,752,757,762,767,772,777,782,787,792,797,802,807,812,817,822,827,832,837,842,847,852,857,862,867,872,877,882,887,892,897,902,907,912,917,922])
+ self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
+ d=DataArrayInt([1,1,0,1,0,5,1,5,1,1,5,6,1,6,1,1,2,1,1,6,2,1,6,7,1,7,2,1,3,2,1,7,3,1,7,8,1,8,3,1,5,4,1,4,10,1,10,5,1,10,11,1,11,5,1,9,8,1,8,14,1,14,9,1,14,15,1,15,9,1,10,16,1,16,11,1,16,17,1,17,11,1,14,20,1,20,15,1,20,21,1,21,15,1,16,22,1,22,17,1,22,23,1,23,17,1,20,26,1,26,21,1,26,27,1,27,21,1,24,23,1,23,28,1,28,24,1,28,29,1,29,24,1,25,24,1,29,25,1,29,30,1,30,25,1,26,25,1,30,26,1,30,31,1,31,26,1,11,12,1,12,6,1,12,13,1,13,7,1,13,14,1,17,18,1,18,12,1,18,19,1,19,13,1,19,20,1,24,18,1,25,19,1,65,64,1,64,69,1,69,65,1,69,70,1,70,65,1,66,65,1,70,66,1,70,71,1,71,66,1,67,66,1,71,67,1,71,72,1,72,67,1,69,68,1,68,74,1,74,69,1,74,75,1,75,69,1,73,72,1,72,78,1,78,73,1,78,79,1,79,73,1,74,80,1,80,75,1,80,81,1,81,75,1,78,84,1,84,79,1,84,85,1,85,79,1,80,86,1,86,81,1,86,87,1,87,81,1,84,90,1,90,85,1,90,91,1,91,85,1,88,87,1,87,92,1,92,88,1,92,93,1,93,88,1,89,88,1,93,89,1,93,94,1,94,89,1,90,89,1,94,90,1,94,95,1,95,90,1,75,76,1,76,70,1,76,77,1,77,71,1,77,78,1,81,82,1,82,76,1,82,83,1,83,77,1,83,84,1,88,82,1,89,83])
+ self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
+ d=DataArrayInt(129) ; d.iota() ; d*=3
+ self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
+ #
+ self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
+ self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
+ self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
+ self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
+ self.assertTrue(mm3D.getGroupArr(-2,"grp1").isEqualWithoutConsideringStr(DataArrayInt([0,1,5,9,12,13,14,18,22,23,30,31,33,37,38,40,42,46,50,51])))
+ self.assertTrue(mm3D.getGroupArr(-2,"grp1_top").isEqualWithoutConsideringStr(DataArrayInt([64,65,69,73,76,77,78,82,86,87,94,95,97,101,102,104,106,110,114,115])))
+ self.assertTrue(mm3D.getGroupArr(0,"grp0_extruded").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,24,25,26,27,28,29,48,49,50,57,58,59])))
+ self.assertTrue(mm3D.getGroupArr(-1,"grp1_extruded").isEqualWithoutConsideringStr(DataArrayInt([48,49,53,57,60,61,62,66,70,71,78,79,81,85,86,88,90,94,98,99,112,113,117,121,124,125,126,130,134,135,142,143,145,149,150,152,154,158,162,163])))
+ mm3D.setName("MeshExtruded")
+ mm3D.write(fileName,0)
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def testMEDFileUMeshPickeling1(self):
+ import cPickle
+ outFileName="Pyfile86.med"
+ c=DataArrayDouble([-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ],9,2)
+ c.setInfoOnComponents(["aa","bbb"])
+ targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
+ m=MEDCouplingUMesh();
+ m.setMeshDimension(2);
+ m.allocateCells(5);
+ m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
+ m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
+ m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
+ m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
+ m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
+ m.finishInsertingCells();
+ m.setCoords(c)
+ m.checkCoherency()
+ m1=MEDCouplingUMesh.New();
+ m1.setMeshDimension(1);
+ m1.allocateCells(3);
+ m1.insertNextCell(NORM_SEG2,2,[1,4])
+ m1.insertNextCell(NORM_SEG2,2,[3,6])
+ m1.insertNextCell(NORM_SEG3,3,[2,8,5])
+ m1.finishInsertingCells();
+ m1.setCoords(c)
+ m1.checkCoherency()
+ m2=MEDCouplingUMesh.New();
+ m2.setMeshDimension(0);
+ m2.allocateCells(4);
+ m2.insertNextCell(NORM_POINT1,1,[1])
+ m2.insertNextCell(NORM_POINT1,1,[3])
+ m2.insertNextCell(NORM_POINT1,1,[2])
+ m2.insertNextCell(NORM_POINT1,1,[6])
+ m2.finishInsertingCells();
+ m2.setCoords(c)
+ m2.checkCoherency()
+ #
+ mm=MEDFileUMesh.New()
+ self.assertTrue(mm.getUnivNameWrStatus())
+ mm.setName("MyFirstMEDCouplingMEDmesh")
+ mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
+ mm.setCoords(c)
+ mm.setMeshAtLevel(-1,m1);
+ mm.setMeshAtLevel(0,m);
+ mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
+ mm.setMeshAtLevel(-2,m2);
+ mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
+ # playing with groups
+ g1_2=DataArrayInt.New()
+ g1_2.setValues([1,3],2,1)
+ g1_2.setName("G1")
+ g2_2=DataArrayInt.New()
+ g2_2.setValues([1,2,3],3,1)
+ g2_2.setName("G2")
+ mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
+ g1_1=DataArrayInt.New()
+ g1_1.setValues([0,1,2],3,1)
+ g1_1.setName("G1")
+ g2_1=DataArrayInt.New()
+ g2_1.setValues([0,2],2,1)
+ g2_1.setName("G2")
+ mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
+ g1_N=DataArrayInt.New()
+ g1_N.setValues(range(8),8,1)
+ g1_N.setName("G1")
+ g2_N=DataArrayInt.New()
+ g2_N.setValues(range(9),9,1)
+ g2_N.setName("G2")
+ mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
+ mm.createGroupOnAll(0,"GrpOnAllCell")
+ # check content of mm
+ t=mm.getGroupArr(0,"G1",False)
+ self.assertTrue(g1_2.isEqual(t));
+ t=mm.getGroupArr(0,"G2",False)
+ self.assertTrue(g2_2.isEqual(t));
+ t=mm.getGroupArr(-1,"G1",False)
+ self.assertTrue(g1_1.isEqual(t));
+ t=mm.getGroupArr(-1,"G2",False)
+ self.assertTrue(g2_1.isEqual(t));
+ t=mm.getGroupArr(1,"G1",False)
+ self.assertTrue(g1_N.isEqual(t));
+ t=mm.getGroupArr(1,"G2",False)
+ self.assertTrue(g2_N.isEqual(t));
+ self.assertTrue(mm.existsGroup("GrpOnAllCell"));
+ t=mm.getGroupArr(0,"GrpOnAllCell")
+ #
+ st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
+ mm2=cPickle.loads(st)
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ pass