pass
#
pass
+
+ def test9(self):
+ """ This test plays with with gauss fields with profiles.
+ """
+ fname="ForMEDReader9.med"
+ # building a mesh containing 6 tri3 + 5 quad4
+ m=MEDCouplingUMesh("mesh",2)
+ coords=DataArrayDouble([(0,0),(1,0),(2,0),(3,0),(4,0),(0,1),(1,1),(2,1),(3,1),(4,1),(0,2),(1,2),(2,2),(3,2),(4,2)]) ; coords.setInfoOnComponents(["XX [m]","YYY [km]"])
+ m.setCoords(coords)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI3,[2,7,3]) ; m.insertNextCell(NORM_TRI3,[7,8,3]) ; m.insertNextCell(NORM_TRI3,[3,8,4]) ; m.insertNextCell(NORM_TRI3,[8,9,4])
+ m.insertNextCell(NORM_TRI3,[13,9,8]) ; m.insertNextCell(NORM_TRI3,[13,14,9])
+ m.insertNextCell(NORM_QUAD4,[0,5,6,1]) ; m.insertNextCell(NORM_QUAD4,[1,6,7,2]) ; m.insertNextCell(NORM_QUAD4,[5,10,11,6]) ; m.insertNextCell(NORM_QUAD4,[6,11,12,7])
+ m.insertNextCell(NORM_QUAD4,[12,13,8,7])
+ mm=MEDFileUMesh() ; mm.setMeshes([m])
+ #
+ fieldName0="zeField0"
+ fieldName1="zeField1"
+ fieldName2="zeField2"
+ fieldName3="zeField3"
+ pfl1=DataArrayInt([0,1,7,9,10]) ; pfl1.setName("pfl1") # on cells
+ pfl2=DataArrayInt([1,2,3,6,7,8,11,12,13]) ; pfl2.setName("pfl2") # on nodes
+ fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
+ for i in xrange(5):
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_GAUSS_NE) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName0)
+ arr=DataArrayDouble(2*18) ; arr.iota(0+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl1)
+ fs0.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName1)
+ arr=DataArrayDouble(2*5) ; arr.iota(100+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl1)
+ fs1.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName2) ; fNode.setMesh(m[pfl1])
+ fNode.setGaussLocalizationOnCells([0],[0.,0.,1.,0.,0.,1.],[0.5,0.5,0.7,0.7],[0.8,0.2])
+ fNode.setGaussLocalizationOnCells([1],[0.,0.,1.,0.,0.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3],[0.8,0.05,0.1,0.04,0.01])
+ fNode.setGaussLocalizationOnCells([2,3],[0.,0.,1.,0.,1.,1.,0.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2],[0.8,0.05,0.1,0.04])
+ fNode.setGaussLocalizationOnCells([4],[0.,0.,1.,0.,1.,1.,0.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.8,0.8],[0.8,0.05,0.1,0.01,0.02,0.005,0.005])
+ arr=DataArrayDouble(2*(2*1+5*1+4*2+7*1)) ; arr.iota(300+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) ; fNode.checkCoherency()
+ f.setFieldProfile(fNode,mm,0,pfl1)
+ fs2.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName3)
+ arr=DataArrayDouble(2*9) ; arr.iota(400+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_3 [m]","Com2_3 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl2)
+ fs3.pushBackTimeStep(f)
+ #
+ pass
+ #
+ mm.write(fname,2)
+ fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0)
+ a0Exp=mm.getCoords().deepCpy()
+ del m,mm,fs1,fs2,fs3,f,fNode
+ ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
+ ms=MEDFileMeshes(fname)
+ fields=MEDFileFields(fname,False)
+ fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
+ allFMTSLeavesToDisplay=[]
+ for fields in fields_per_mesh:
+ allFMTSLeavesToDisplay2=[]
+ for fmts in fields:
+ allFMTSLeavesToDisplay2+=fmts.splitDiscretizations()
+ pass
+ allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
+ pass
+ self.assertEqual(len(allFMTSLeavesToDisplay),1)
+ self.assertEqual(len(allFMTSLeavesToDisplay[0]),4)
+ allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 4 fields are defined on the same time steps
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
+ allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),4)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(a0.isEqual(a0Exp[pfl2],1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([5,5,9,9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([3,6,10,14,18])))
+ self.assertTrue(a3.isEqual(DataArrayInt([3,1,4,2,3,4,5,2,4,0,3,4,1,4,3,6,7,4,4,7,8,5,4])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ for i in xrange(1,5):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ for i in xrange(5):
+ f=allFMTSLeavesPerCommonSupport[0][0][0][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName0)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(18*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport[0][0][1][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName1)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(5*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport[0][0][2][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName2)
+ #self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) # not a bug
+ vExp=DataArrayDouble(22*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport[0][0][3][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName3)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(9*2) ; vExp.iota(400+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_3 [m]','Com2_3 [s^2]'])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ pass
+ pass
+
+ def test10(self):
+ """ This test plays with fields only on nodes containing profiles.
+ """
+ fname="ForMEDReader9.med"
+ # building a mesh containing 6 tri3 + 5 quad4
+ m=MEDCouplingUMesh("mesh",2)
+ coords=DataArrayDouble([(0,0),(1,0),(2,0),(3,0),(4,0),(0,1),(1,1),(2,1),(3,1),(4,1),(0,2),(1,2),(2,2),(3,2),(4,2)]) ; coords.setInfoOnComponents(["XX [m]","YYY [km]"])
+ m.setCoords(coords)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI3,[2,7,3]) ; m.insertNextCell(NORM_TRI3,[7,8,3]) ; m.insertNextCell(NORM_TRI3,[3,8,4]) ; m.insertNextCell(NORM_TRI3,[8,9,4])
+ m.insertNextCell(NORM_TRI3,[13,9,8]) ; m.insertNextCell(NORM_TRI3,[13,14,9])
+ m.insertNextCell(NORM_QUAD4,[0,5,6,1]) ; m.insertNextCell(NORM_QUAD4,[1,6,7,2]) ; m.insertNextCell(NORM_QUAD4,[5,10,11,6]) ; m.insertNextCell(NORM_QUAD4,[6,11,12,7])
+ m.insertNextCell(NORM_QUAD4,[12,13,8,7])
+ mm=MEDFileUMesh() ; mm.setMeshes([m])
+ #
+ fieldName0="zeField0"
+ fieldName1="zeField1"
+ fieldName2="zeField2"
+ pfl1=DataArrayInt([1,2,3,6,7,8,11,12,13]) ; pfl1.setName("pfl1") # on nodes
+ fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS()
+ for i in xrange(5):
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName0)
+ arr=DataArrayDouble(2*9) ; arr.iota(0+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl1)
+ fs0.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName1)
+ arr=DataArrayDouble(2*9) ; arr.iota(100+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl1)
+ fs1.pushBackTimeStep(f)
+ #
+ f=MEDFileField1TS()
+ fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
+ fNode.setName(fieldName2)
+ arr=DataArrayDouble(2*9) ; arr.iota(200+1000*i) ; arr.rearrange(2)
+ fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
+ f.setFieldProfile(fNode,mm,0,pfl1)
+ fs2.pushBackTimeStep(f)
+ #
+ pass
+ #
+ mm.write(fname,2)
+ fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0)
+ a0Exp=mm.getCoords().deepCpy()
+ del m,mm,fs1,fs2,f,fNode
+ ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
+ ms=MEDFileMeshes(fname)
+ fields=MEDFileFields(fname,False)
+ fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
+ allFMTSLeavesToDisplay=[]
+ for fields in fields_per_mesh:
+ allFMTSLeavesToDisplay2=[]
+ for fmts in fields:
+ allFMTSLeavesToDisplay2+=fmts.splitDiscretizations()
+ pass
+ allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
+ pass
+ self.assertEqual(len(allFMTSLeavesToDisplay),1)
+ self.assertEqual(len(allFMTSLeavesToDisplay[0]),3)
+ allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 4 fields are defined on the same time steps
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
+ allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),3)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(a0.isEqual(a0Exp[pfl1],1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([5,5,9,9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([3,6,10,14,18])))
+ self.assertTrue(a3.isEqual(DataArrayInt([3,1,4,2,3,4,5,2,4,0,3,4,1,4,3,6,7,4,4,7,8,5,4])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ for i in xrange(1,5):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ pass
+
pass
unittest.main()