From: Anthony Geay Date: Tue, 23 Aug 2016 11:59:40 +0000 (+0200) Subject: A test X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0d2498e0060943003c04bfe81bd5194963f59f7d;p=tools%2Fmedcoupling.git A test --- diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 69b96d107..0471aa4b0 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -5126,7 +5126,305 @@ class MEDLoaderTest3(unittest.TestCase): self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr)) pass + def testMEDFileFieldEasyField1(self): + """Check for all spatial discretization of field (cells,nodes,elno,gauss) for double field that all is OK. Here no profile and only top level is considered.""" + ## Basic test on cells on top level + fname="Pyfile101.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[0]=m + mm.write(fname,2) + arr0=DataArrayDouble([10,11,12,13,100,101]) + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m) + f.setName(fieldName) ; f.setTime(2.,6,7) + f0=f.deepCopy() + ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f) + ff.write(fname,0) + arr2=arr0+1000 ; f.setArray(arr2) + f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f) + ff.write(fname,0) + f1=f.deepCopy() + ## + mm=MEDFileMesh.New(fname) + f1ts=MEDFileField1TS(fname,fieldName,6,7) + ftst0=f1ts.field(mm) + self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12)) + f1ts=MEDFileField1TS(fname,fieldName,8,9) + ftst1=f1ts.field(mm) + self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12)) + fmts=MEDFileFieldMultiTS(fname,fieldName) + self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12)) + ## Basic test on nodes on top level + f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24) + f2.setName(fieldName) + mm.write(fname,2) + ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileField1TS(fname,fieldName,23,24) + self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12)) + fmts=MEDFileFieldMultiTS(fname,fieldName) + self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12)) + ## Node on elements + f3=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3) + f3.setName(fieldName) ; f3.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileField1TS(fname,fieldName,2,3) + self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12)) + ## Gauss + f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName) + f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,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.1,0.05,0.35]) + f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5) + arr4=DataArrayDouble([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4) + f4.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileField1TS(fname,fieldName,4,5) + self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + + def testMEDFileFieldEasyField2(self): + """Same thantestMEDFileFieldEasyField1 except that here intfields are considered. + Check for all spatial discretization of field (cells,nodes,elno,gauss) for int field that all is OK. Here no profile and only top level is considered.""" + ## Basic test on cells on top level + fname="Pyfile102.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[0]=m + mm.write(fname,2) + arr0=DataArrayInt([10,11,12,13,100,101]) + f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m) + f.setName(fieldName) ; f.setTime(2.,6,7) + f0=f.deepCopy() + ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f) + ff.write(fname,0) + arr2=arr0+1000 ; f.setArray(arr2) + f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f) + ff.write(fname,0) + f1=f.deepCopy() + ## + mm=MEDFileMesh.New(fname) + f1ts=MEDFileIntField1TS(fname,fieldName,6,7) + ftst0=f1ts.field(mm) + self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12)) + f1ts=MEDFileIntField1TS(fname,fieldName,8,9) + ftst1=f1ts.field(mm) + self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12)) + fmts=MEDFileIntFieldMultiTS(fname,fieldName) + self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12)) + ## Basic test on nodes on top level + f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24) + f2.setName(fieldName) + mm.write(fname,2) + ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileIntField1TS(fname,fieldName,23,24) + self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12)) + fmts=MEDFileIntFieldMultiTS(fname,fieldName) + self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12)) + ## Node on elements + f3=MEDCouplingFieldInt(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3) + f3.setName(fieldName) ; f3.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileIntField1TS(fname,fieldName,2,3) + self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12)) + ## Gauss + f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName) + f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,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.1,0.05,0.35]) + f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5) + arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4) + f4.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) + f1ts=MEDFileIntField1TS(fname,fieldName,4,5) + self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + + def testMEDFileFieldEasyField3(self): + """Here a multi level mesh. And field on cells lying on different level of this mesh. Show how "field" method deal with that. Here on field double are considered.""" + fname="Pyfile103.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[-1]=m + m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo) + m0.allocateCells() + m0.insertNextCell(NORM_TETRA4,[3,2,5,0]) + m0.insertNextCell(NORM_TETRA4,[7,6,3,2]) + mm[0]=m0 + mm.write(fname,2) + # start slowly + f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2) + f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2) + self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12)) + # here f1 lying on level -1 not 0 check if "field" method detect it ! + f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)])) + f1.setMesh(mm[-1]) # -1 is very important + f1.setTime(16.,3,4) + f1.checkConsistencyLight() + mm.write(fname,2) + f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4) + self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12)) + # nodes on elements + f3=MEDCouplingFieldDouble(ON_GAUSS_NE) + f3.setMesh(mm[-1]) # this line is important + arr3=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3) + f3.setName(fieldName) ; f3.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3) + self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12)) + # gauss + f4=MEDCouplingFieldDouble(ON_GAUSS_PT) + f4.setMesh(mm[-1]) # this line is important + f4.setName(fieldName) + f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,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.1,0.05,0.35]) + f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5) + arr4=DataArrayDouble([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4) + f4.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0) + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5) + self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + + def testMEDFileFieldEasyField4(self): + """ Same than testMEDFileFieldEasyField3 but with integers""" + fname="Pyfile104.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[-1]=m + m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo) + m0.allocateCells() + m0.insertNextCell(NORM_TETRA4,[3,2,5,0]) + m0.insertNextCell(NORM_TETRA4,[7,6,3,2]) + mm[0]=m0 + mm.write(fname,2) + # start slowly + f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2) + f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2) + self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12)) + # here f1 lying on level -1 not 0 check if "field" method detect it ! + f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)])) + f1.setMesh(mm[-1]) # -1 is very important + f1.setTime(16.,3,4) + f1.checkConsistencyLight() + mm.write(fname,2) + f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4) + self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12)) + # nodes on elements + f3=MEDCouplingFieldInt(ON_GAUSS_NE) + f3.setMesh(mm[-1]) # this line is important + arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3) + f3.setName(fieldName) ; f3.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3) + self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12)) + # gauss + f4=MEDCouplingFieldInt(ON_GAUSS_PT) + f4.setMesh(mm[-1]) # this line is important + f4.setName(fieldName) + f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,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.1,0.05,0.35]) + f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5) + arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4) + f4.checkConsistencyLight() + mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0) + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5) + self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + + def testMEDFileFieldEasyField5(self): + """More and more difficult now look at how profiles are managed by "field" method.""" + fname="Pyfile105.med" + fieldName="field1" + mm=MEDFileUMesh() + coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)]) + m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo) + m.allocateCells() + m.insertNextCell(NORM_TRI3,[0,1,2]) + m.insertNextCell(NORM_TRI3,[3,4,5]) + m.insertNextCell(NORM_TRI3,[6,7,8]) + m.insertNextCell(NORM_TRI3,[9,10,11]) + m.insertNextCell(NORM_QUAD4,[100,101,102,103]) + m.insertNextCell(NORM_QUAD4,[104,105,106,107]) + mm[0]=m + mm.write(fname,2) + pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl") + m2=m.deepCopy()[pfl] ; m2.setName(m.getName()) + # + arr0=DataArrayDouble([10,11,12,13]) + f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2) + f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight() + ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile + ff.write(fname,0) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7) + self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12)) + # more complicated -> multi level + m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo) + m0.allocateCells() + m0.insertNextCell(NORM_TETRA4,[3,2,5,0]) + m0.insertNextCell(NORM_TETRA4,[7,6,3,2]) + mm2=MEDFileUMesh() + mm2[0]=m0 ; mm2[-1]=m + # + ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl) + # + mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7) + self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12)) + pass + pass if __name__ == "__main__": - unittest.main() + unittest.main()