m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
m1=m.buildDescendingConnectivity()[0]
mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
+ fam=DataArrayInt(9) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam)
+ fam=DataArrayInt(32) ; fam.iota(20) ; mm.setFamilyFieldArr(-1,fam) ; del fam
+ num=DataArrayInt(9) ; num.iota(100) ; mm.setRenumFieldArr(0,num)
+ num=DataArrayInt(32) ; num.iota(120) ; mm.setRenumFieldArr(-1,num) ; del num
#
fieldName="zeField"
fs=MEDFileFieldMultiTS()
for i in xrange(1,5):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,5,5,5,5,9,9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,67,70,73,76,80,84,88,92,96])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,100,104,108,112,117,122,127,132])))
self.assertTrue(a3.isEqual(DataArrayInt([2,0,1,2,1,2,2,2,0,2,3,4,2,4,5,2,5,3,2,6,7,2,7,8,2,8,6,2,9,10,2,10,11,2,11,9,2,12,13,2,13,14,2,14,15,2,15,12,2,16,17,2,17,18,2,18,19,2,19,16,2,20,21,2,21,22,2,22,23,2,23,20,2,24,25,2,25,26,2,26,27,2,27,24,2,28,29,2,29,30,2,30,31,2,31,28,3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,0,1,2,3,4,5,6,7,8])))
+ self.assertTrue(not a7)
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,100,101,102,103,104,105,106,107,108])))
+ self.assertTrue(not a9)
for i in xrange(5):
fsst=MEDFileField1TSStructItem.BuildItemFrom(fields[0][i],mst)
fields[0][i].loadArraysIfNecessary()
for i in xrange(1,5):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,5,5,5,5,9,9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,67,70,73,76,80,84,88,92,96])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,100,104,108,112,117,122,127,132])))
self.assertTrue(a3.isEqual(DataArrayInt([2,0,1,2,1,2,2,2,0,2,3,4,2,4,5,2,5,3,2,6,7,2,7,8,2,8,6,2,9,10,2,10,11,2,11,9,2,12,13,2,13,14,2,14,15,2,15,12,2,16,17,2,17,18,2,18,19,2,19,16,2,20,21,2,21,22,2,22,23,2,23,20,2,24,25,2,25,26,2,26,27,2,27,24,2,28,29,2,29,30,2,30,31,2,31,28,3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
for i in xrange(1,3):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,5,5,5,5,9,9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,67,70,73,76,80,84,88,92,96])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,100,104,108,112,117,122,127,132])))
self.assertTrue(a3.isEqual(DataArrayInt([2,0,1,2,1,2,2,2,0,2,3,4,2,4,5,2,5,3,2,6,7,2,7,8,2,8,6,2,9,10,2,10,11,2,11,9,2,12,13,2,13,14,2,14,15,2,15,12,2,16,17,2,17,18,2,18,19,2,19,16,2,20,21,2,21,22,2,22,23,2,23,20,2,24,25,2,25,26,2,26,27,2,27,24,2,28,29,2,29,30,2,30,31,2,31,28,3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
assert a4 is None
assert a5 is None
for i in xrange(1,2):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,9,9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([3,6,9,12,16,20,24,28,32])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,21,26,31,36])))
self.assertTrue(a3.isEqual(DataArrayInt([3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
for i in xrange(1,5):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,9,9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([3,6,9,12,16,20,24,28,32])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,21,26,31,36])))
self.assertTrue(a3.isEqual(DataArrayInt([3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
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])
+ fam=DataArrayInt(11) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam) ; del fam
+ num=DataArrayInt(11) ; num.iota(100) ; mm.setRenumFieldArr(0,num) ; del num
#
fieldName1="zeField1" ; pfl1=DataArrayInt([0,1,2,3,4,5]) ; pfl1.setName("pfl1") # on cells
fieldName2="zeField2" ; pfl2=DataArrayInt([2,3,4,7,8,9,13,14]) ; pfl2.setName("pfl2") # on nodes
for i in xrange(1,5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp[pfl2].changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,5,5])))
- self.assertTrue(a2.isEqual(DataArrayInt([3,6,9,12,15,18])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,20])))
self.assertTrue(a3.isEqual(DataArrayInt([3,0,3,1,3,3,4,1,3,1,4,2,3,4,5,2,3,6,5,4,3,6,7,5])))
assert a4 is None
assert a5 is None
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5])))
+ self.assertTrue(not a7)
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105])))
+ self.assertTrue(not a9)
for i in xrange(5):
nbOfT=[6,8]
fieldNames=[fieldName1,fieldName2]
for i in xrange(1,5):
self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
pass
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,5,5,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([3,6,9,12,15,18,22,26])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,20,24,29])))
self.assertTrue(a3.isEqual(DataArrayInt([3,2,7,3,3,7,8,3,3,3,8,4,3,8,9,4,3,13,9,8,3,13,14,9,4,6,11,12,7,4,12,13,8,7])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5,9,10])))
+ self.assertTrue(not a7)
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,109,110])))
+ self.assertTrue(not a9)
for i in xrange(5):
f=allFMTSLeavesPerCommonSupport[1][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
coordsY=DataArrayDouble([0,1.7,3.4]) ; coordsY.setInfoOnComponents(["YYY [km]"])
m.setCoords(coordsX,coordsY)
mm=MEDFileCMesh() ; mm.setMesh(m)
+ fam=DataArrayInt(8) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam) ; del fam
+ num=DataArrayInt(8) ; num.iota(100) ; mm.setRenumFieldArr(0,num) ; del num
+ num=DataArrayInt(15) ; num.iota(200) ; mm.setRenumFieldArr(1,num) ; del num
#
fieldName0="zeField0" ; # on cells
fieldName1="zeField1" ; pfl1=DataArrayInt([2,3,6,7]) ; pfl1.setName("pfl1") # on cells
for i in xrange(1,5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5,6,7])))
+ self.assertTrue(a7) # True because no copy
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,106,107])))
+ self.assertTrue(a9) # True because no copy
+ a10,a11=mml2.retrieveNumberIdsOnNodes()
+ self.assertTrue(a10.isEqual(DataArrayInt([200,201,202,203,204,205,206,207,208,209,210,211,212,213,214])))
+ self.assertTrue(a11) # True because no copy
for i in xrange(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
a,b=mml2.buildVTUArrays()
self.assertTrue(a.isEqual(coordsX[[2,3,4]],1e-12))
self.assertTrue(b.isEqual(coordsY,1e-12))
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([2,3,6,7])))
+ self.assertTrue(not a7) # False because copy
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([102,103,106,107])))
+ self.assertTrue(not a9) # False because copy
+ a10,a11=mml2.retrieveNumberIdsOnNodes()
+ self.assertTrue(a10.isEqual(DataArrayInt([202,203,204,207,208,209,212,213,214])))
+ self.assertTrue(not a11) # False because copy
for i in xrange(1,5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) # here the 3rd support is a part of CMesh but impossible to simplify more than a UMesh
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
a0Exp=DataArrayDouble([0.,0.,1.1,0.,2.2,0.,3.3,0.,4.4,0.,0.,1.7,1.1,1.7,2.2,1.7,3.3,1.7,4.4,1.7,0.,3.4,1.1,3.4,2.2,3.4,3.3,3.4,4.4,3.4],15,2)
a0Exp.setInfoOnComponents(["XX [m]","YYY [km]"])
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([4,8,12,16])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15])))
self.assertTrue(a3.isEqual(DataArrayInt([4,3,2,7,8,4,4,3,8,9,4,7,6,11,12,4,9,8,13,14])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([2,3,5,7])))
+ self.assertTrue(not a7) # False because copy
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([102,103,105,107])))
+ self.assertTrue(not a9) # False because copy
for i in xrange(5):
f=allFMTSLeavesPerCommonSupport[2][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
a0Exp.setInfoOnComponents(["XX [m]","YYY [km]"])
m.setCoords(a0Exp)
mm=MEDFileCurveLinearMesh() ; mm.setMesh(m)
+ fam=DataArrayInt(8) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam) ; del fam
+ num=DataArrayInt(8) ; num.iota(100) ; mm.setRenumFieldArr(0,num) ; del num
#
fieldName0="zeField0" ; # on cells
fieldName1="zeField1" ; pfl1=DataArrayInt([2,3,6,7]) ; pfl1.setName("pfl1") # on cells
a,b=mml2.buildVTUArrays()
self.assertTrue(a.isEqual(a0Exp,1e-12))
self.assertEqual(b,[5,3])
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5,6,7])))
+ self.assertTrue(a7) # True because no copy
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,106,107])))
+ self.assertTrue(a9) # True because no copy
for i in xrange(1,5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
a,b=mml2.buildVTUArrays()
self.assertTrue(a.isEqual(a0Exp[pfl2],1e-12))
self.assertEqual(b,[3,3])
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([2,3,6,7])))
+ self.assertTrue(not a7) # False because copy
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([102,103,106,107])))
+ self.assertTrue(not a9) # False because copy
for i in xrange(1,5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) # here the 3rd support is a part of CMesh but impossible to simplify more than a UMesh
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
a0Exp=DataArrayDouble([0.,0.,1.1,0.,2.2,0.,3.3,0.,4.4,0.,0.,1.7,1.1,1.7,2.2,1.7,3.3,1.7,4.4,1.7,0.,3.4,1.1,3.4,2.2,3.4,3.3,3.4,4.4,3.4],15,2)
a0Exp.setInfoOnComponents(["XX [m]","YYY [km]"])
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([4,8,12,16])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15])))
self.assertTrue(a3.isEqual(DataArrayInt([4,3,2,7,8,4,4,3,8,9,4,7,6,11,12,4,9,8,13,14])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([2,3,5,7])))
+ self.assertTrue(not a7) # False because copy
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([102,103,105,107])))
+ self.assertTrue(not a9) # False because copy
for i in xrange(5):
f=allFMTSLeavesPerCommonSupport[2][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,5,5,9,9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([3,6,9,12,15,18,22,26,30,34,38])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,20,24,29,34,39,44])))
self.assertTrue(a3.isEqual(DataArrayInt([3,2,7,3,3,7,8,3,3,3,8,4,3,8,9,4,3,13,9,8,3,13,14,9,4,0,5,6,1,4,1,6,7,2,4,5,10,11,6,4,6,11,12,7,4,12,13,8,7])))
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp[pfl2].changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([5,5,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([3,6,10,14,18])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,13,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)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp[pfl1].changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([5,5,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([3,6,10,14,18])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,13,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)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75])))
self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,5,6,4,3,2,7,8,4,4,3,8,9,4,6,5,10,11,4,9,8,13,14,4,19,18,23,24,4,2,1,6,7,4,7,6,11,12,4,11,10,15,16,4,12,11,16,17,4,8,7,12,13,4,13,12,17,18,4,17,16,21,22,4,14,13,18,19,4,16,15,20,21,4,18,17,22,23]))) # <- here the mesh is renumbered : the mesh is equal to m[[0,2,3,4,7,15, 1,5,8,9, 6,10,13, 11,12,14]]
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
- self.assertTrue(a2.isEqual(DataArrayInt([4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75])))
self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,5,6,4,2,1,6,7,4,3,2,7,8,4,4,3,8,9,4,6,5,10,11,4,7,6,11,12,4,8,7,12,13,4,9,8,13,14,4,11,10,15,16,4,12,11,16,17,4,13,12,17,18,4,14,13,18,19,4,16,15,20,21,4,17,16,21,22,4,18,17,22,23,4,19,18,23,24]))) # <- here the mesh is NOT renumbered : the mesh is equal to m
self.assertTrue(a4 is None)
self.assertTrue(a5 is None)
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(ncc)
self.assertTrue(a0.isEqual(a0Exp,1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([12,12,42,42,42])))
- self.assertTrue(a2.isEqual(DataArrayInt([8,16,24,32,40])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,9,18,27,36])))
self.assertTrue(a3.isEqual(DataArrayInt([8,1,0,6,7,13,12,18,19,8,2,1,7,8,14,13,19,20,8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22,8,4,5,10,11,16,17,22,23])))
self.assertTrue(a4.isEqual(DataArrayInt([-1,-1,0,31,62])))
self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(ncc)
self.assertTrue(a0.isEqual(a0Exp,1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([42,42])))
- self.assertTrue(a2.isEqual(DataArrayInt([8,16])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,9])))
self.assertTrue(a3.isEqual(DataArrayInt([8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22])))
self.assertTrue(a4.isEqual(DataArrayInt([0,31])))
self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4])))
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(ncc)
self.assertTrue(a0.isEqual(a0Exp,1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([42,42,42])))
- self.assertTrue(a2.isEqual(DataArrayInt([8,16,24])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,9,18])))
self.assertTrue(a3.isEqual(DataArrayInt([8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22,8,4,5,10,11,16,17,22,23])))
self.assertTrue(a4.isEqual(DataArrayInt([0,31,62])))
self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
mml=fcscp.buildFromScratchDataSetSupport(0,fields)
mml2=mml.prepare()
self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
- a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(ncc)
self.assertTrue(a0.isEqual(a0Exp,1e-12))
self.assertTrue(a1.isEqual(DataArrayByte([42,42,42])))
- self.assertTrue(a2.isEqual(DataArrayInt([8,16,24])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,9,18])))
self.assertTrue(a3.isEqual(DataArrayInt([8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22,8,4,5,10,11,16,17,22,23])))
self.assertTrue(a4.isEqual(DataArrayInt([0,31,62])))
self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
for i in xrange(1,5):
self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
pass
- pass
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,0,0])))
+ self.assertTrue(a7)
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8 is None)
+ self.assertTrue(a9)
for i in xrange(5):
f=allFMTSLeavesPerCommonSupport[0][0][0][i]
fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
"""
fname="ForMEDReader15.med"
m0=MEDCouplingCMesh()
- arr=DataArrayDouble(5) ; arr.iota(0)
+ arr=DataArrayDouble(3) ; arr.iota(0)
m0.setCoords(arr,arr,arr)
m0.setName("mesh")
m0=m0.buildUnstructured()
#
mm=MEDFileUMesh()
mm.setMeshAtLevel(0,m0)
+ fam=DataArrayInt(8) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam) ; del fam
+ num=DataArrayInt(8) ; num.iota(100) ; mm.setRenumFieldArr(0,num) ; del num
#
ffs=MEDFileFieldMultiTS()
# TimeStep 0
mm.write(fname,2)
ffs.write(fname,0)
########## 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]),2)
+ allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
+ allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(ncc)
+ self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,2.,2.,0.,0.,0.,1.,1.,0.,1.,2.,0.,1.,0.,1.,1.,1.,1.,1.,2.,1.,1.,0.,2.,1.,1.,2.,1.,2.,2.,1.,0.,0.,2.,1.,0.,2.,2.,0.,2.,0.,1.,2.,1.,1.,2.,2.,1.,2.,0.,2.,2.,1.,2.,2.,2.,2.,2.0],27,3),1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([12,12,12,12,12,12,12,12])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,9,18,27,36,45,54,63])))
+ self.assertTrue(a3.isEqual(DataArrayInt([8,1,0,3,4,10,9,12,13,8,2,1,4,5,11,10,13,14,8,4,3,6,7,13,12,15,16,8,5,4,7,8,14,13,16,17,8,10,9,12,13,19,18,21,22,8,11,10,13,14,20,19,22,23,8,13,12,15,16,22,21,24,25,8,14,13,16,17,23,22,25,26])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5,6,7])))
+ self.assertTrue(a7) # no copy here
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,106,107])))
+ self.assertTrue(a9) # no copy here
pass
+ def test16(self):
+ """ Here 2 meshes "mesh1" and "mesh2" and 4 fields (no profiles here) :
+ - "zeField1_0" (CELLS) and "zeField2_0" (NODES) on "mesh1"
+ - "zeField3_1" (CELLS) and "zeField4_1" (NODES) on "mesh2"
+ time steps series are the same for the whole 4 fields
+ """
+ fname="ForMEDReader16.med"
+ m0=MEDCouplingCMesh()
+ arr=DataArrayDouble(3) ; arr.iota(0)
+ m0.setCoords(arr,arr,arr)
+ m0.setName("mesh1")
+ m0=m0.buildUnstructured()
+ #
+ fCell1=MEDCouplingFieldDouble(ON_CELLS)
+ fCell1.setName("zeField1_0")
+ fCell1.setMesh(m0)
+ #
+ fNode1=MEDCouplingFieldDouble(ON_NODES)
+ fNode1.setName("zeField2_0")
+ fNode1.setMesh(m0)
+ #
+ mms=MEDFileMeshes()
+ mm1=MEDFileUMesh()
+ mm1.setMeshAtLevel(0,m0)
+ fam=DataArrayInt([0,1,0,1,2,3,2,3]); mm1.setFamilyFieldArr(0,fam) ; del fam
+ num=DataArrayInt(8) ; num.iota(100) ; mm1.setRenumFieldArr(0,num) ; del num
+ mm1.setFamilyId("FAMILLE_ZERO",0) ; mm1.setFamilyId("Family1_1",1) ; mm1.setFamilyId("Family1_2",2) ; mm1.setFamilyId("Family1_3",3) ; mm1.setFamilyId("Family1_4",4)
+ mm1.setFamiliesIdsOnGroup("Grp1_1",[0,1]) ; mm1.setFamiliesIdsOnGroup("Grp1_2",[2,3])
+ mms.pushMesh(mm1) ; del mm1
+ #
+ m1=m0.deepCpy() ; m1.translate([2.5,0.,0.]) ; m1.setName("mesh2")
+ #
+ fCell2=MEDCouplingFieldDouble(ON_CELLS)
+ fCell2.setName("zeField3_1")
+ fCell2.setMesh(m1)
+ #
+ fNode2=MEDCouplingFieldDouble(ON_NODES)
+ fNode2.setName("zeField4_1")
+ fNode2.setMesh(m1)
+ #
+ mm2=MEDFileUMesh()
+ mm2.setMeshAtLevel(0,m1)
+ fam=DataArrayInt([0,1,0,1,2,3,2,3]); mm2.setFamilyFieldArr(0,fam) ; del fam
+ num=DataArrayInt(8) ; num.iota(200) ; mm2.setRenumFieldArr(0,num) ; del num
+ mm2.setFamilyId("FAMILLE_ZERO",0) ; mm2.setFamilyId("Family2_1",1) ; mm2.setFamilyId("Family2_2",2) ; mm2.setFamilyId("Family2_3",3) ; mm2.setFamilyId("Family2_4",4)
+ mm2.setFamiliesIdsOnGroup("Grp2_1",[0,1]) ; mm2.setFamiliesIdsOnGroup("Grp2_2",[2,3]) ; mm2.setFamiliesIdsOnGroup("Grp2_3",[1,2,3])
+ mms.pushMesh(mm2) ; del mm2
+ ffs1_1=MEDFileFieldMultiTS()
+ ffs1_2=MEDFileFieldMultiTS()
+ ffs2_1=MEDFileFieldMultiTS()
+ ffs2_2=MEDFileFieldMultiTS()
+ mts=MEDFileFields()
+ for elt in ffs1_1,ffs1_2,ffs2_1,ffs2_2:
+ mts.pushField(elt)
+ pass
+ # TimeStep 0
+ t=(1.,0,0) ; off=0.
+ f1ts1=MEDFileField1TS()
+ f1ts2=MEDFileField1TS()
+ a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
+ fCell1.setArray(a)
+ fCell1.setTime(*t)
+ fCell1.checkCoherency()
+ a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
+ a=a.negate()
+ fNode1.setArray(a)
+ fNode1.setTime(*t)
+ fNode1.checkCoherency()
+ f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
+ f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
+ #
+ f1ts1=MEDFileField1TS()
+ f1ts2=MEDFileField1TS()
+ a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
+ fCell2.setArray(a)
+ fCell2.setTime(*t)
+ fCell2.checkCoherency()
+ a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
+ a=a.negate()
+ fNode2.setArray(a)
+ fNode2.setTime(*t)
+ fNode2.checkCoherency()
+ f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
+ f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
+ # TimeStep 1
+ t=(2.1,1,0) ; off=100.
+ f1ts1=MEDFileField1TS()
+ f1ts2=MEDFileField1TS()
+ a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
+ fCell1.setArray(a)
+ fCell1.setTime(*t)
+ fCell1.checkCoherency()
+ a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
+ a=a.negate()
+ fNode1.setArray(a)
+ fNode1.setTime(*t)
+ fNode1.checkCoherency()
+ f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
+ f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
+ #
+ f1ts1=MEDFileField1TS()
+ f1ts2=MEDFileField1TS()
+ a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
+ fCell2.setArray(a)
+ fCell2.setTime(*t)
+ fCell2.checkCoherency()
+ a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
+ a=a.negate()
+ fNode2.setArray(a)
+ fNode2.setTime(*t)
+ fNode2.checkCoherency()
+ f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
+ f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
+ # TimeStep 2
+ t=(3.1,2,0) ; off=200.
+ f1ts1=MEDFileField1TS()
+ f1ts2=MEDFileField1TS()
+ a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
+ fCell1.setArray(a)
+ fCell1.setTime(*t)
+ fCell1.checkCoherency()
+ a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
+ a=a.negate()
+ fNode1.setArray(a)
+ fNode1.setTime(*t)
+ fNode1.checkCoherency()
+ f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
+ f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
+ #
+ f1ts1=MEDFileField1TS()
+ f1ts2=MEDFileField1TS()
+ a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
+ fCell2.setArray(a)
+ fCell2.setTime(*t)
+ fCell2.checkCoherency()
+ a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
+ a=a.negate()
+ fNode2.setArray(a)
+ fNode2.setTime(*t)
+ fNode2.checkCoherency()
+ f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
+ f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
+ #
+ mms.write(fname,2) ; mts.write(fname,0)
+ ########## 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),2)
+ self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
+ self.assertEqual(len(allFMTSLeavesToDisplay[1]),2)
+ allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
+ allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),2)
+ allFMTSLeavesPerCommonSupport2=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport2),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport2[0][0]),2)
+ pass
+
+ def test17(self):
+ """ First test on GAUSS_NE (Elno). Here no Profiles.
+ 2 times steps.
+ """
+ fname="ForMEDReader17.med"
+ fieldName1="MyFirstElno"
+ fieldName2="ACellField"
+ fieldName3="ANodeField"
+ coo=DataArrayDouble([0.,0.,1.,0.,2.,0.,0.,1.,1.,1.,2.,1.],6,2)
+ m=MEDCouplingUMesh("mesh",2)
+ m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_QUAD4,[0,3,4,1])
+ m.insertNextCell(NORM_QUAD4,[1,4,5,2])
+ m.checkCoherency2()
+ #
+ t=(1.1,0,-1)
+ f=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f.setTime(*t) ; f.setMesh(m)
+ f.setArray(DataArrayDouble([3.,5.,7.,6.,2.,3.,11.,8.]))
+ f.setName(fieldName1)
+ f.checkCoherency()
+ MEDLoader.WriteField(fname,f,True)
+ f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(*t) ; f2.setMesh(m)
+ f2.setArray(DataArrayDouble([7.,11.],2,1))
+ f2.setName(fieldName2)
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
+ f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setTime(*t) ; f3.setMesh(m)
+ f3.setArray(DataArrayDouble([1.,2.,4.,1.,2.,4.],6,1))
+ f3.setName(fieldName3)
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
+ #
+ t=(2.1,1,-1)
+ f=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f.setTime(*t) ; f.setMesh(m)
+ f.setArray(DataArrayDouble([7.,6.,3.,5.,11.,8.,2.,3.]))
+ f.setName(fieldName1)
+ f.checkCoherency()
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f)
+ f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(*t) ; f2.setMesh(m)
+ f2.setArray(DataArrayDouble([11.,7.],2,1))
+ f2.setName(fieldName2)
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
+ f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setTime(*t) ; f3.setMesh(m)
+ f3.setArray(DataArrayDouble([4.,2.,1.,4.,2.,1.],6,1))
+ f3.setName(fieldName3)
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
+ ########## 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)
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
+ allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),3)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport1[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc) # spaceDim 2 -> VTK wants 3D
+ self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.],6,3),1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5])))
+ self.assertTrue(a3.isEqual(DataArrayInt([4,0,3,4,1,4,1,4,5,2])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,0])))
+ self.assertTrue(a7) # no copy here
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
+ self.assertTrue(a9) # no copy here
+ for i in xrange(1,2):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
+ vExp1=[DataArrayDouble([3.,5.,7.,6.,2.,3.,11.,8.]),DataArrayDouble([7.,6.,3.,5.,11.,8.,2.,3.])]
+ for i in xrange(2):
+ f=allFMTSLeavesPerCommonSupport1[0][0][0][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())
+ self.assertTrue(v.isEqual(vExp0[i],1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport1[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())
+ self.assertTrue(v.isEqual(vExp1[i],1e-12))
+ pass
+ pass
+
+ def test18(self):
+ """ First test on GAUSS_PT. Here no Profiles. 2 times steps.
+ """
+ fname="ForMEDReader18.med"
+ fieldName1="MyFirstGauss"
+ fieldName2="ACellField"
+ fieldName3="ANodeField"
+ coo=DataArrayDouble([0.,0.,1.,0.,2.,0.,0.,1.,1.,1.,2.,1.],6,2)
+ m=MEDCouplingUMesh("mesh",2)
+ m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_QUAD4,[0,3,4,1])
+ m.insertNextCell(NORM_QUAD4,[1,4,5,2])
+ m.checkCoherency2()
+ #
+ t=(1.1,0,-1)
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f.setTime(*t) ; f.setMesh(m)
+ f.setGaussLocalizationOnType(NORM_QUAD4,[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.2,0.2,0.8,0.8],[0.7,0.3])
+ f.setArray(DataArrayDouble([3.,5.,4.,6.])) ; f.getArray().setInfoOnComponents(["Smth"])
+ f.setName(fieldName1)
+ f.checkCoherency()
+ MEDLoader.WriteField(fname,f,True)
+ f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(*t) ; f2.setMesh(m)
+ f2.setArray(DataArrayDouble([7.,11.],2,1))
+ f2.setName(fieldName2)
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
+ f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setTime(*t) ; f3.setMesh(m)
+ f3.setArray(DataArrayDouble([1.,2.,4.,1.,2.,4.],6,1))
+ f3.setName(fieldName3)
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
+ #
+ t=(2.1,1,-1)
+ f=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f.setTime(*t) ; f.setMesh(m)
+ f.setGaussLocalizationOnType(NORM_QUAD4,[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.2,0.2,0.8,0.8],[0.7,0.3])
+ f.setArray(DataArrayDouble([5.,3.,6.,4.])) ; f.getArray().setInfoOnComponents(["Smth"])
+ f.setName(fieldName1)
+ f.checkCoherency()
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f)
+ f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(*t) ; f2.setMesh(m)
+ f2.setArray(DataArrayDouble([11.,7.],2,1))
+ f2.setName(fieldName2)
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
+ f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setTime(*t) ; f3.setMesh(m)
+ f3.setArray(DataArrayDouble([4.,2.,1.,4.,2.,1.],6,1))
+ f3.setName(fieldName3)
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
+ ########## 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)
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
+ allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),3)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport1[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc) # spaceDim 2 -> VTK wants 3D
+ self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.],6,3),1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5])))
+ self.assertTrue(a3.isEqual(DataArrayInt([4,0,3,4,1,4,1,4,5,2])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,0])))
+ self.assertTrue(a7) # no copy here
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
+ self.assertTrue(a9) # no copy here
+ for i in xrange(1,2):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
+ vExp1=[DataArrayDouble([3.,5.,4.,6.]),DataArrayDouble([5.,3.,6.,4.])]
+ for i in xrange(2):
+ f=allFMTSLeavesPerCommonSupport1[0][0][0][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())
+ self.assertTrue(v.isEqual(vExp0[i],1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport1[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())
+ vExp1[i].setInfoOnComponents(["Smth"])
+ self.assertTrue(v.isEqual(vExp1[i],1e-12))
+ pass
+ ## Now same exercise but with a different load strategy. All is load directly.
+ ms=MEDFileMeshes(fname)
+ fields=MEDFileFields(fname) # here all is read, the SauvReader (or other Reader) is emulated
+ 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)
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
+ allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),3)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport1[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc) # spaceDim 2 -> VTK wants 3D
+ self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.],6,3),1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5])))
+ self.assertTrue(a3.isEqual(DataArrayInt([4,0,3,4,1,4,1,4,5,2])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,0])))
+ self.assertTrue(a7) # no copy here
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
+ self.assertTrue(a9) # no copy here
+ for i in xrange(1,2):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
+ vExp1=[DataArrayDouble([3.,5.,4.,6.]),DataArrayDouble([5.,3.,6.,4.])]
+ for i in xrange(2):
+ f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst) # no load needed here
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName2)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ self.assertTrue(v.isEqual(vExp0[i],1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport1[0][0][1][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst) # no load needed here
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName1)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp1[i].setInfoOnComponents(["Smth"])
+ self.assertTrue(v.isEqual(vExp1[i],1e-12))
+ pass
+ pass
+
+ def test19(self):
+ """
+ This test is a simple non profile CELL field but lying on cells of dimension -1 (not 0 as "usual").
+ """
+ fname="ForMEDReader19.med"
+ fieldName="ACellFieldOnDimM1"
+ coo=DataArrayDouble(3) ; coo.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(coo,coo,coo) ; m.setName("mesh")
+ m0=m.buildUnstructured() ; del m
+ m1=m0.computeSkin()
+ #
+ mm=MEDFileUMesh()
+ mm.setMeshAtLevel(0,m0)
+ mm.setMeshAtLevel(-1,m1)
+ ff=MEDFileFieldMultiTS()
+ # time 0
+ t=(1.1,1,-1)
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setTime(*t) ; f.setMesh(m1)
+ f.setName(fieldName)
+ arr=DataArrayDouble(24) ; arr.iota() ; arr.setInfoOnComponents(["AStr"])
+ f.setArray(arr)
+ f.checkCoherency()
+ f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f)
+ ff.pushBackTimeStep(f1ts)
+ # time 1
+ t=(2.1,2,-2)
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setTime(*t) ; f.setMesh(m1)
+ f.setName(fieldName)
+ arr=DataArrayDouble(24) ; arr.iota() ; arr.reverse() ; arr.setInfoOnComponents(["AStr"])
+ f.setArray(arr)
+ f.checkCoherency()
+ f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f)
+ ff.pushBackTimeStep(f1ts)
+ #
+ mm.write(fname,2)
+ ff.write(fname,0)
+ ########## 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]),1)
+ allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
+ allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport1[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(ncc)
+ self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,2.,2.,0.,0.,0.,1.,1.,0.,1.,2.,0.,1.,0.,1.,1.,1.,1.,1.,2.,1.,1.,0.,2.,1.,1.,2.,1.,2.,2.,1.,0.,0.,2.,1.,0.,2.,2.,0.,2.,0.,1.,2.,1.,1.,2.,2.,1.,2.,0.,2.,2.,1.,2.,2.,2.,2.,2.],27,3),1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115])))
+ self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,3,4,4,1,10,9,0,4,0,9,12,3,4,2,1,4,5,4,2,11,10,1,4,5,14,11,2,4,4,3,6,7,4,3,12,15,6,4,6,15,16,7,4,5,4,7,8,4,7,16,17,8,4,8,17,14,5,4,19,22,21,18,4,10,19,18,9,4,9,18,21,12,4,20,23,22,19,4,11,20,19,10,4,14,23,20,11,4,22,25,24,21,4,12,21,24,15,4,15,24,25,16,4,23,26,25,22,4,16,25,26,17,4,17,26,23,14])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])))
+ self.assertTrue(a7) # no copy here
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8 is None)
+ self.assertTrue(a9) # no copy here
+ a10,a11=mml2.retrieveFamilyIdsOnNodes()
+ self.assertTrue(not a10)
+ self.assertTrue(a11) # no copy here
+ a12,a13=mml2.retrieveNumberIdsOnNodes()
+ self.assertTrue(not a12)
+ self.assertTrue(a13) # no copy here
+ for i in xrange(1,2):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ for i in xrange(2):
+ f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
+ fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
+ f.loadArraysIfNecessary()
+ v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
+ self.assertEqual(f.getName(),fieldName)
+ self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
+ vExp=DataArrayDouble(24) ; vExp.iota()
+ if i==1: vExp.reverse()
+ vExp.setInfoOnComponents(["AStr"])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ pass
+ pass
+
+ def test20(self):
+ """ This test works with groups/families on cells AND on nodes. Here 4 fields each on same time steps (2).
+ 1 field on CELLS without profile, 1 field on CELLS with profile, 1 field on NODES without profile, 1 field on NODES with profile.
+ All of these 4 fields lies on a single mesh "mesh". The 2 fields on profile lies on a same support.
+ One drawback of this test : no multi geom type. Coming soon !
+ """
+ fname="ForMEDReader20.med"
+ fieldName0="ANodeField"
+ fieldName1="ACellField"
+ fieldName2="ANodeFieldPfl"
+ fieldName3="ACellFieldPfl"
+ pfl2=DataArrayInt([5,6,7,10,11,12,15,16,17,20,21,22]) ; pfl2.setName("pfl2")
+ pfl3=DataArrayInt([4,5,8,9,12,13]) ; pfl3.setName("pfl3")
+ #
+ arr=DataArrayDouble(5) ; arr.iota()
+ m=MEDCouplingCMesh("mesh") ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ mm=MEDFileUMesh()
+ mm.setMeshAtLevel(0,m)
+ fs=MEDFileFields()
+ fmts0=MEDFileFieldMultiTS() ; fs.pushField(fmts0)
+ fmts0.setDtUnit("s")
+ fmts1=MEDFileFieldMultiTS() ; fs.pushField(fmts1)
+ fmts1.setDtUnit("s")
+ fmts2=MEDFileFieldMultiTS() ; fs.pushField(fmts2)
+ fmts2.setDtUnit("s")
+ fmts3=MEDFileFieldMultiTS() ; fs.pushField(fmts3)
+ fmts3.setDtUnit("s")
+ ####
+ t=(1.1,0,-2)
+ f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m)
+ f0.setName(fieldName0) ; f0.setTime(*t)
+ da=m.getCoords().magnitude() ; da.setInfoOnComponents(["zeInfo"])
+ f0.setArray(da)
+ f0.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f0)
+ fmts0.pushBackTimeStep(f1ts)
+ #
+ f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setMesh(m)
+ f1.setName(fieldName1) ; f1.setTime(*t)
+ da=m.getBarycenterAndOwner().magnitude() ; da.setInfoOnComponents(["zeInfoCell"])
+ f1.setArray(da)
+ f1.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f1)
+ fmts1.pushBackTimeStep(f1ts)
+ #
+ f2=MEDCouplingFieldDouble(ON_NODES) ; mTmp=m[pfl3] ; mTmp.zipCoords() ; mTmp.setName(m.getName()) ; f2.setMesh(mTmp)
+ f2.setName(fieldName2) ; f2.setTime(*t)
+ da=m.getCoords().magnitude()[pfl2] ; da.setInfoOnComponents(["zzzz"])
+ f2.setArray(da)
+ f2.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldProfile(f2,mm,0,pfl2)
+ fmts2.pushBackTimeStep(f1ts)
+ #
+ f3=MEDCouplingFieldDouble(ON_CELLS) ; mTmp=m[pfl3] ; mTmp.setName(m.getName()) ; f3.setMesh(mTmp)
+ f3.setName(fieldName3) ; f3.setTime(*t)
+ da=mTmp.getBarycenterAndOwner().magnitude() ; da.setInfoOnComponents(["abcdefg"])
+ f3.setArray(da)
+ f3.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldProfile(f3,mm,0,pfl3)
+ fmts3.pushBackTimeStep(f1ts)
+ ####
+ t=(2.1,1,-3)
+ f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m)
+ f0.setName(fieldName0) ; f0.setTime(*t)
+ da=m.getCoords().magnitude() ; da.reverse() ; da.setInfoOnComponents(["zeInfo"])
+ f0.setArray(da)
+ f0.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f0)
+ fmts0.pushBackTimeStep(f1ts)
+ #
+ f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setMesh(m)
+ f1.setName(fieldName1) ; f1.setTime(*t)
+ da=m.getBarycenterAndOwner().magnitude() ; da.reverse() ; da.setInfoOnComponents(["zeInfoCell"])
+ f1.setArray(da)
+ f1.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f1)
+ fmts1.pushBackTimeStep(f1ts)
+ #
+ f2=MEDCouplingFieldDouble(ON_NODES) ; mTmp=m[pfl3] ; mTmp.zipCoords() ; mTmp.setName(m.getName()) ; f2.setMesh(mTmp)
+ f2.setName(fieldName2) ; f2.setTime(*t)
+ da=m.getCoords().magnitude()[pfl2] ; da.reverse() ; da.setInfoOnComponents(["zzzz"])
+ f2.setArray(da)
+ f2.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldProfile(f2,mm,0,pfl2)
+ fmts2.pushBackTimeStep(f1ts)
+ #
+ f3=MEDCouplingFieldDouble(ON_CELLS) ; mTmp=m[pfl3] ; mTmp.setName(m.getName()) ; f3.setMesh(mTmp)
+ f3.setName(fieldName3) ; f3.setTime(*t)
+ da=mTmp.getBarycenterAndOwner().magnitude() ; da.reverse() ; da.setInfoOnComponents(["abcdefg"])
+ f3.setArray(da)
+ f3.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldProfile(f3,mm,0,pfl3)
+ fmts3.pushBackTimeStep(f1ts)
+ ####
+ grp1=DataArrayInt([6,7,8,11,12,13,16,17,18]) ; grp1.setName("grp1")
+ grp2=DataArrayInt([10,11,15,16,20,21]) ; grp2.setName("grp2")
+ mm.setGroupsAtLevel(1,[grp1,grp2])
+ grp3=DataArrayInt([4,5,6]) ; grp3.setName("grp3")
+ grp4=DataArrayInt([8,9,10]) ; grp4.setName("grp4")
+ mm.setGroupsAtLevel(0,[grp3,grp4])
+ d=DataArrayInt(25) ; d.iota() ; d*=10 ; mm.setRenumFieldArr(1,d)
+ d=DataArrayInt(16) ; d.iota() ; d*=11 ; mm.setRenumFieldArr(0,d)
+ mm.write(fname,2)
+ fs.appendGlobs(fmts2,1e-12)
+ fs.appendGlobs(fmts3,1e-12)
+ fs.write(fname,0)
+ ########## 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)
+ self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
+ allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1),2)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),2)
+ self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),2)
+ #
+ mst=MEDFileMeshStruct.New(ms[0])
+ #
+ fcscp=allFMTSLeavesPerCommonSupport1[0][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
+ self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,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.,0.,2.,0.,1.,2.,0.,2.,2.,0.,3.,2.,0.,4.,2.,0.,0.,3.,0.,1.,3.,0.,2.,3.,0.,3.,3.,0.,4.,3.,0.,0.,4.,0.,1.,4.,0.,2.,4.,0.,3.,4.,0.,4.,4.,0.],25,3),1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75])))
+ self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,5,6,4,2,1,6,7,4,3,2,7,8,4,4,3,8,9,4,6,5,10,11,4,7,6,11,12,4,8,7,12,13,4,9,8,13,14,4,11,10,15,16,4,12,11,16,17,4,13,12,17,18,4,14,13,18,19,4,16,15,20,21,4,17,16,21,22,4,18,17,22,23,4,19,18,23,24])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([-5,-5,-5,-5,-6,-6,-6,-5,-7,-7,-7,-5,-5,-5,-5,-5])))
+ self.assertTrue(a7) # no copy here
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([0,11,22,33,44,55,66,77,88,99,110,121,132,143,154,165])))
+ self.assertTrue(a9) # no copy here
+ a10,a11=mml2.retrieveFamilyIdsOnNodes()
+ self.assertTrue(a10.isEqual(DataArrayInt([1,1,1,1,1,1,2,2,2,1,3,4,2,2,1,3,4,2,2,1,3,3,1,1,1])))
+ self.assertTrue(a11) # no copy here
+ a12,a13=mml2.retrieveNumberIdsOnNodes()
+ self.assertTrue(a12.isEqual(DataArrayInt([0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240])))
+ self.assertTrue(a13) # no copy here
+ for i in xrange(1,2):
+ self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
+ pass
+ for i in xrange(2):
+ f=allFMTSLeavesPerCommonSupport1[0][0][0][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([0.7071067811865476,1.5811388300841898,2.5495097567963922,3.5355339059327378,1.5811388300841898,2.1213203435596424,2.9154759474226504,3.8078865529319543,2.5495097567963922,2.9154759474226504,3.5355339059327378,4.301162633521313,3.5355339059327378,3.8078865529319543,4.301162633521313,4.949747468305833])
+ if i==1: vExp.reverse()
+ vExp.setInfoOnComponents(["zeInfoCell"])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport1[0][0][1][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([0.,1.,2.,3.,4.,1.,1.4142135623730951,2.23606797749979,3.1622776601683795,4.123105625617661,2.,2.23606797749979,2.8284271247461903,3.605551275463989,4.47213595499958,3.,3.1622776601683795,3.605551275463989,4.242640687119285,5.,4.,4.123105625617661,4.47213595499958,5.,5.656854249492381])
+ if i==1: vExp.reverse()
+ vExp.setInfoOnComponents(["zeInfo"])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ pass
+ ### Testing the 2nd support
+ fcscp=allFMTSLeavesPerCommonSupport1[1][1]
+ mml=fcscp.buildFromScratchDataSetSupport(0,fields)
+ mml2=mml.prepare()
+ self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
+ ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
+ self.assertTrue(not ncc)
+ self.assertTrue(not ncc)
+ self.assertTrue(a0.isEqual(DataArrayDouble([0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,2.,2.,0.,0.,3.,0.,1.,3.,0.,2.,3.,0.,0.,4.,0.,1.,4.,0.,2.,4.,0.],12,3),1e-12))
+ self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9])))
+ self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25])))
+ self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,3,4,4,2,1,4,5,4,4,3,6,7,4,5,4,7,8,4,7,6,9,10,4,8,7,10,11])))
+ self.assertTrue(a4 is None)
+ self.assertTrue(a5 is None)
+ a6,a7=mml2.retrieveFamilyIdsOnCells()
+ self.assertTrue(a6.isEqual(DataArrayInt([-6,-6,-7,-7,-5,-5])))
+ self.assertTrue(not a7) # copy here
+ a8,a9=mml2.retrieveNumberIdsOnCells()
+ self.assertTrue(a8.isEqual(DataArrayInt([44,55,88,99,132,143])))
+ self.assertTrue(not a9) # copy here
+ a10,a11=mml2.retrieveFamilyIdsOnNodes()
+ self.assertTrue(a10.isEqual(DataArrayInt([1,2,2,3,4,2,3,4,2,3,3,1])))
+ self.assertTrue(not a11) # copy here
+ a12,a13=mml2.retrieveNumberIdsOnNodes()
+ self.assertTrue(a12.isEqual(DataArrayInt([50,60,70,100,110,120,150,160,170,200,210,220])))
+ self.assertTrue(not a13) # copy here
+ for i in xrange(2):
+ f=allFMTSLeavesPerCommonSupport1[1][0][0][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([1.5811388300842,2.1213203435596,2.5495097567964,2.9154759474227,3.5355339059327,3.807886552932])
+ if i==1: vExp.reverse()
+ vExp.setInfoOnComponents(["abcdefg"])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ #
+ f=allFMTSLeavesPerCommonSupport1[1][0][1][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())
+ vExp=DataArrayDouble([1.,1.4142135623731,2.2360679774998,2.,2.2360679774998,2.8284271247462,3.,3.1622776601684,3.605551275464,4.,4.1231056256177,4.4721359549996])
+ if i==1: vExp.reverse()
+ vExp.setInfoOnComponents(["zzzz"])
+ self.assertTrue(v.isEqual(vExp,1e-12))
+ pass
+ pass
pass
unittest.main()