From f9d8b9f75a942ad6fa450137b09f4224c3515dbd Mon Sep 17 00:00:00 2001 From: ageay Date: Tue, 30 Jul 2013 13:44:13 +0000 Subject: [PATCH] MEDReader -> debugging session --- src/MEDLoader/Swig/MEDLoaderCommon.i | 2 +- src/MEDLoader/Swig/MEDLoaderTest4.py | 175 +++++++++++++++++++++++++++ 2 files changed, 176 insertions(+), 1 deletion(-) diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 9465715e9..54d6c9fea 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -2874,7 +2874,7 @@ namespace ParaMEDMEM public: %extend { - PyObject *buildVTUArrays(DataArrayDouble *&coords, std::vector& nodeStrct) const throw(INTERP_KERNEL::Exception) + PyObject *buildVTUArrays() const throw(INTERP_KERNEL::Exception) { DataArrayDouble *ret0(0); std::vector ret1; diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index a65f9bb4a..7bcb7570c 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -1133,6 +1133,181 @@ class MEDLoaderTest4(unittest.TestCase): self.assertTrue(v.isEqual(vExp,1e-12)) pass pass + + def test7(self): + """ This test plays with curvilinear mesh and profiles. When a sub curvilinear mesh can also be considered as a cartesian mesh it is done. + This test is very similar to the test6. + """ + fname="ForMEDReader7.med" + m=MEDCouplingCurveLinearMesh("mesh") ; m.setNodeGridStructure([5,3]) + 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]"]) + m.setCoords(a0Exp) + mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) + # + fieldName0="zeField0" ; # on cells + fieldName1="zeField1" ; pfl1=DataArrayInt([2,3,6,7]) ; pfl1.setName("pfl1") # on cells + fieldName2="zeField2" ; pfl2=DataArrayInt([2,3,4,7,8,9,12,13,14]) ; pfl2.setName("pfl2") # on nodes + fieldName3="zeField3" ; pfl3=DataArrayInt([2,3,5,7]) ; pfl3.setName("pfl3") # on cells but different support + fieldName4="zeField4" ;# on nodes + fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS() ; fs4=MEDFileFieldMultiTS() + # + for i in xrange(5): + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName0) ; fNode.setMesh(m) + arr=DataArrayDouble(2*8) ; arr.iota(0+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs0.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName1) + arr=DataArrayDouble(2*4) ; 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) + self.assertEqual(pfl1.getName(),"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,pfl2) + self.assertEqual(pfl2.getName(),"pfl2") + fs2.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName3) + arr=DataArrayDouble(2*4) ; arr.iota(300+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_3 [m]","Com2_3 [s^2]"]) + f.setFieldProfile(fNode,mm,0,pfl3) + self.assertEqual(pfl3.getName(),"pfl3") + fs3.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName4) ; fNode.setMesh(m) + arr=DataArrayDouble(2*15) ; arr.iota(400+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_4 [m]","Com2_4 [s^2]"]) ; fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs4.pushBackTimeStep(f) + pass + mm.write(fname,2) + fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0) ; fs4.write(fname,0) + 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]),5) + allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[])) + self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 5 fields are defined on the same time steps + self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),5) + allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]]) + self.assertEqual(len(allFMTSLeavesPerCommonSupport),3) + self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2) + self.assertEqual(len(allFMTSLeavesPerCommonSupport[1][0]),2) + self.assertEqual(len(allFMTSLeavesPerCommonSupport[2][0]),1) + # + mst=MEDFileMeshStruct.New(ms[0]) + # + fcscp=allFMTSLeavesPerCommonSupport[0][1] + mml=fcscp.buildFromScratchDataSetSupport(0,fields) + mml2=mml.prepare() + self.assertTrue(isinstance(mml2,MEDCurveLinearMeshMultiLev)) + a,b=mml2.buildVTUArrays() + self.assertTrue(a.isEqual(a0Exp,1e-12)) + self.assertEqual(b,[5,3]) + 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(8*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(),fieldName4) + self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) + vExp=DataArrayDouble(15*2) ; vExp.iota(400+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_4 [m]','Com2_4 [s^2]']) + self.assertTrue(v.isEqual(vExp,1e-12)) + pass + + fcscp=allFMTSLeavesPerCommonSupport[1][1] + mml=fcscp.buildFromScratchDataSetSupport(0,fields) + mml2=mml.prepare() + self.assertTrue(isinstance(mml2,MEDCurveLinearMeshMultiLev)) # here the 2nd support is a part of CMesh that is also a CMesh -> CMesh not a UMesh + a,b=mml2.buildVTUArrays() + self.assertTrue(a.isEqual(a0Exp[pfl2],1e-12)) + self.assertEqual(b,[3,3]) + for i in xrange(1,5): + self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))) + pass + for i in xrange(5): + f=allFMTSLeavesPerCommonSupport[1][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(4*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[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(9*2) ; vExp.iota(200+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]']) + self.assertTrue(v.isEqual(vExp,1e-12)) + pass + # + fcscp=allFMTSLeavesPerCommonSupport[2][1] + 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() + 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,1e-12)) + self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9]))) + self.assertTrue(a2.isEqual(DataArrayInt([4,8,12,16]))) + 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) + for i in xrange(5): + f=allFMTSLeavesPerCommonSupport[2][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(4*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_3 [m]','Com2_3 [s^2]']) + self.assertTrue(v.isEqual(vExp,1e-12)) + pass + pass pass unittest.main() -- 2.39.2