# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013 CEA/DEN, EDF R&D
+# Copyright (C) 2007-2014 CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
m2_1=MEDLoader.ReadUMeshFromFile(fileName,mname,-1)
self.assertTrue(m2_0.isEqual(m2_1,1e-12));
pass
+
def testMEDMesh2(self):
fileName="Pyfile10.med"
mname="3DToto"
g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]);
g1_1.setName(g1_0.getName())
self.assertTrue(g1_0.isEqual(g1_1,1e-12));
- g1_0=medmesh.getFamily(0,"Family_2",True)
- g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2"]);
+ g1_0=medmesh.getFamily(0,"Family_-3",True)
+ g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_-3"]);
self.assertTrue(g1_0.isEqual(g1_1,1e-12));
- g1_0=medmesh.getFamilies(0,["Family_2","Family_4"],True)
- g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2","Family_4"]);
+ g1_0=medmesh.getFamilies(0,["Family_-3","Family_-5"],True)
+ g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_-3","Family_-5"]);
g1_1.setName(g1_0.getName())
self.assertTrue(g1_0.isEqual(g1_1,1e-12));
self.assertTrue(g1_0.isEqual(g1_1,1e-12));
medmesh.write(outFileName,2);
- self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",True).getValues());
- self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",True).getValues());
- self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],True).getValues());
- self.assertEqual([19,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
+ self.assertEqual([1,2,4,13,15],medmesh.getGroupArr(0,"mesh2",True).getValues());
+ self.assertEqual([1,2,15],medmesh.getFamilyArr(0,"Family_-3",True).getValues());
+ self.assertEqual([1,2,4,13,15],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"],True).getValues());
+ self.assertEqual([18,1,2,3,4,13,14,15],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
famn=medmesh.getFamilyNameGivenId(0)
self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True);
#without renum
- self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",False).getValues());
- self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",False).getValues());
- self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],False).getValues());
+ self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues());
+ self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_-3").getValues());
+ self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"]).getValues());
self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False);
pass
mmCpy.write(outFileName,2);
#
mm=MEDFileMesh.New(outFileName)
+ #
+ self.assertEqual([NORM_TRI3,NORM_QUAD4,NORM_POLYGON],mm.getGeoTypesAtLevel(0))
+ self.assertEqual([NORM_SEG2,NORM_SEG3],mm.getGeoTypesAtLevel(-1))
+ self.assertEqual([NORM_POINT1],mm.getGeoTypesAtLevel(-2))
+ mm0=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POLYGON)
+ self.assertTrue(isinstance(mm0,MEDCoupling1DGTUMesh))
+ self.assertTrue(mm0.getNodalConnectivity().isEqual(DataArrayInt([6,7,4,3,7,8,5,4])))
+ self.assertTrue(mm0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8])))
+ lmm=mm.getDirectUndergroundSingleGeoTypeMeshes(0)
+ self.assertEqual(3,len(lmm))
+ self.assertTrue(isinstance(lmm[0],MEDCoupling1SGTUMesh))
+ self.assertTrue(isinstance(lmm[1],MEDCoupling1SGTUMesh))
+ self.assertTrue(isinstance(lmm[2],MEDCoupling1DGTUMesh))
+ #
self.assertTrue(mm.getUnivNameWrStatus())
self.assertTrue(isinstance(mm.getUnivName(),str))
self.assertTrue(len(mm.getUnivName())!=0)
self.assertTrue(m.getUnivNameWrStatus())
m.write(outFileName,2);
mm=MEDFileMesh.New(outFileName)
+ self.assertEqual([NORM_HEXA8],mm.getGeoTypesAtLevel(0))
self.assertTrue(isinstance(mm,MEDFileCMesh))
self.assertTrue(isinstance(mm.getUnivName(),str))
self.assertTrue(len(mm.getUnivName())!=0)
def testMEDFieldBug1(self):
fname="Pyfile13.med"
d=MEDFileData.New(fname)
- self.assertEqual(('GP_MyFirstFieldOnGaussPoint0', 'GP_MyFirstFieldOnGaussPoint1', 'GP_MyFirstFieldOnGaussPoint2'),d.getFields().getFieldAtPos(0).getLocs())
+ self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs())
pass
def testMEDMesh8(self):
def testBasicConstructors(self):
fname="Pyfile18.med"
- m=MEDFileMesh(fname)
- m=MEDFileMesh(fname,"ExampleOfMultiDimW",-1,-1)
- m=MEDFileMesh(fname)
+ m=MEDFileMesh.New(fname)
+ m=MEDFileMesh.New(fname,"ExampleOfMultiDimW",-1,-1)
+ m=MEDFileMesh.New(fname)
m=MEDFileUMesh(fname,"ExampleOfMultiDimW",-1,-1)
m=MEDFileUMesh(fname)
m=MEDFileUMesh()
pass
def testHeapMem1(self):
+ a=DataArrayInt() ; aa=a.getHeapMemorySize()
+ a.alloc(0,1)
+ strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
+ #
m=MEDCouplingCMesh()
arr=DataArrayDouble(10,1) ; arr.iota(0)
m.setCoords(arr,arr)
m=m.buildUnstructured()
m.setName("mm")
f=m.getMeasureField(ON_CELLS)
- self.assertIn(m.getHeapMemorySize(),xrange(3552-100,3552+100))
- self.assertIn(f.getHeapMemorySize(),xrange(4215-100,4215+100))
+ self.assertIn(m.getHeapMemorySize(),xrange(3552-100,3552+100+4*strMulFac))
+ self.assertIn(f.getHeapMemorySize(),xrange(4215-100,4215+100+8*strMulFac))
#
mm=MEDFileUMesh()
mm.setMeshAtLevel(0,m)
- self.assertIn(mm.getHeapMemorySize(),xrange(3889-100,3889+100))
+ self.assertIn(mm.getHeapMemorySize(),xrange(3889-100,3889+100+10*strMulFac))
ff=MEDFileField1TS()
ff.setFieldNoProfileSBT(f)
- self.assertIn(ff.getHeapMemorySize(),xrange(711-20,711+20))
+ self.assertIn(ff.getHeapMemorySize(),xrange(711-40,711+21+(4+1)*strMulFac))
#
fff=MEDFileFieldMultiTS()
fff.appendFieldNoProfileSBT(f)
- self.assertIn(fff.getHeapMemorySize(),xrange(743-30,743+30))
+ self.assertIn(fff.getHeapMemorySize(),xrange(743-50,743+30+(6+2)*strMulFac))
f.setTime(1.,0,-1)
fff.appendFieldNoProfileSBT(f)
- self.assertIn(fff.getHeapMemorySize(),xrange(1462-50,1462+50))
- self.assertIn(fff[0,-1].getHeapMemorySize(),xrange(711-20,711+20))
+ self.assertIn(fff.getHeapMemorySize(),xrange(1462-90,1462+50+(10+1)*strMulFac))
+ self.assertIn(fff[0,-1].getHeapMemorySize(),xrange(711-40,711+20+(4+1)*strMulFac))
f2=f[:50]
f2.setTime(2.,1,-1)
pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
fff.appendFieldProfile(f2,mm,0,pfl)
- self.assertIn(fff.getHeapMemorySize(),xrange(2178-100,2178+100))
- self.assertIn(fff.getProfile("pfl_NORM_QUAD4").getHeapMemorySize(),xrange(215-10,215+10))
- self.assertIn(fff[1,-1].getHeapMemorySize(),xrange(700-30,700+30))
+ self.assertIn(fff.getHeapMemorySize(),xrange(2178-130,2178+100+(10+2)*strMulFac))
+ self.assertIn(fff.getProfile("pfl_NORM_QUAD4").getHeapMemorySize(),xrange(215-10,215+10+2*strMulFac))
+ self.assertIn(fff[1,-1].getHeapMemorySize(),xrange(700-50,700+30+4*strMulFac))
pass
def testCurveLinearMesh1(self):
self.assertTrue(d.isEqual(f.getArray(),1e-13))
pass
pass
+
+ 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(100,210+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(150,260+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(1000,1120+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(150,260+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(2000,3000+(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(2400,3500+(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
+
pass
unittest.main()