From c5e3e8ce08e90aad8952542d5715ae8ca32371f6 Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 29 Jul 2013 09:21:16 +0000 Subject: [PATCH] MEDReader ready -> debug is in progress. --- src/MEDLoader/MEDFileField.cxx | 7 + src/MEDLoader/MEDFileFieldOverView.cxx | 37 ++-- src/MEDLoader/Swig/MEDLoaderTest4.py | 243 ++++++++++++++++++++++++- 3 files changed, 270 insertions(+), 17 deletions(-) diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 57afa853e..1b69de2ea 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -8297,6 +8297,13 @@ std::vector< std::vector > MEDFileAnyTypeFieldMult for(std::vector::const_iterator it2=vectFMTSNodes.begin();it2!=vectFMTSNodes.end();it2++) { i=0; + if(retCell.empty()) + { + std::vector tmp(1,*it2); + MEDCouplingAutoRefCountObjectPtr tmp2(MEDFileMeshStruct::New(mesh)); + ret.push_back(tmp); retCell.push_back(tmp); cmps.push_back(MEDFileFastCellSupportComparator::New(tmp2,*it2)); + continue; + } for(std::vector< std::vector >::const_iterator it0=retCell.begin();it0!=retCell.end();it0++,i++) { if((*it0).empty()) diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index e0c38c899..a6a56595b 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -1402,31 +1402,36 @@ bool MEDFileField1TSStruct::isSupportSameAs(const MEDFileAnyTypeField1TS *other, return ret; } +/*! + * \param [in] other - a field with only one spatial discretization : ON_NODES. + */ bool MEDFileField1TSStruct::isCompatibleWithNodesDiscr(const MEDFileAnyTypeField1TS *other, const MEDFileMeshStruct *meshSt) throw(INTERP_KERNEL::Exception) { if(_already_checked.empty()) throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : no ref !"); - if(!_already_checked[0].isEntityCell()) - throw INTERP_KERNEL::Exception("MEDFileField1TSStruct::isCompatibleWithNodesDiscr : only available on cell entities !"); MEDFileField1TSStructItem other1(MEDFileField1TSStructItem::BuildItemFrom(other,meshSt)); - // - int found=-1,i=0; - for(std::vector::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++) - if((*it).isComputed()) - { found=i; break; } - bool ret(false); - if(found==-1) + if(_already_checked[0].isEntityCell()) { - MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other)); - ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other); + int found=-1,i=0; + for(std::vector::const_iterator it=_already_checked.begin();it!=_already_checked.end();it++,i++) + if((*it).isComputed()) + { found=i; break; } + bool ret(false); + if(found==-1) + { + MEDFileField1TSStructItem this1(_already_checked[0].simplifyMeOnCellEntity(other)); + ret=this1.isCompatibleWithNodesDiscr(other1,meshSt,other); + if(ret) + _already_checked.push_back(this1); + } + else + ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other); if(ret) - _already_checked.push_back(this1); + _already_checked.push_back(other1); + return ret; } else - ret=_already_checked[found].isCompatibleWithNodesDiscr(other1,meshSt,other); - if(ret) - _already_checked.push_back(other1); - return ret; + return _already_checked[0].isNodeSupportEqual(other1,other); } std::size_t MEDFileField1TSStruct::getHeapMemorySize() const diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index 97e9ba071..6bf34b3c1 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -582,7 +582,248 @@ class MEDLoaderTest4(unittest.TestCase): pass pass - + def test4(self): + """ This test defines 3 fields on nodes on the same mesh. All of these fields have no profile. + """ + fname="ForMEDReader4.med" + # building a mesh containing 4 tri3 + 5 quad4 + tri=MEDCouplingUMesh("tri",2) + tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2]) + tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)])) + tris=[tri.deepCpy() for i in xrange(4)] + for i,elt in enumerate(tris): elt.translate([i,0]) + tris=MEDCouplingUMesh.MergeUMeshes(tris) + quad=MEDCouplingUMesh("quad",2) + quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3]) + quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)])) + quads=[quad.deepCpy() for i in xrange(5)] + for i,elt in enumerate(quads): elt.translate([5+i,0]) + quads=MEDCouplingUMesh.MergeUMeshes(quads) + m=MEDCouplingUMesh.MergeUMeshes(tris,quads) + m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"]) + mm=MEDFileUMesh() ; mm.setMeshes([m]) + # + fieldName1="zeField1" + fieldName2="zeField2" + fieldName3="zeField3" + fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS() + ##### Time step 0 + i=0 + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName1) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; 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) + fs1.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName2) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs2.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName3) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs3.pushBackTimeStep(f) + ##### Time step 1 + i=1 + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName1) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; 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) + fs1.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName2) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs2.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName3) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs3.pushBackTimeStep(f) + ##### Time step 2 + i=2 + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName1) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; 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) + fs1.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName2) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs2.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName3) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs3.pushBackTimeStep(f) + ##### Time step 3 + i=3 + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName1) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; 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) + fs1.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName2) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs2.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName3) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs3.pushBackTimeStep(f) + ##### Time step 4 + i=4 + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName1) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; 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) + fs1.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName2) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs2.pushBackTimeStep(f) + # + f=MEDFileField1TS() + fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0) + fNode.setName(fieldName3) ; fNode.setMesh(m) + arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2) + fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) + fNode.checkCoherency() + f.setFieldNoProfileSBT(fNode) + fs3.pushBackTimeStep(f) + # + mm.write(fname,2) + 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]),3) + allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[])) + self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 3 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]),3) + # + mst=MEDFileMeshStruct.New(ms[0]) + fcscp=MEDFileFastCellSupportComparator.New(mst,allFMTSLeavesPerCommonSupport[0][0]) + self.assertEqual(len(allFMTSLeavesPerCommonSupport),1) + self.assertEqual(len(allFMTSLeavesPerCommonSupport[0]),3) + fcscp=MEDFileFastCellSupportComparator.New(mst,allFMTSLeavesPerCommonSupport[0][0]) + mml=fcscp.buildFromScratchDataSetSupport(0,fields) + self.assertTrue(isinstance(mml,MEDUMeshMultiLev)) + for i in xrange(1,5): + self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)) + pass + a0,a1,a2,a3,a4,a5=mml.buildVTUArrays() + self.assertTrue(a0.isEqual(a0Exp,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(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) + # test all the time steps of the 1/1 time step serie, on field 1 + for i in xrange(5): + f=allFMTSLeavesPerCommonSupport[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.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,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.,52.,53.,54.,55.,56.,57.,58.,59.,60.,61.,62.,63.],32,2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]']) ; vExp+=i*1000 + self.assertTrue(v.isEqual(vExp,1e-12)) + pass + # test all the time steps of the 1/1 time step serie, on field 2 + for i in xrange(5): + f=allFMTSLeavesPerCommonSupport[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([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,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.,52.,53.,54.,55.,56.,57.,58.,59.,60.,61.,62.,63.],32,2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]']) ; vExp+=i*1000+100 + self.assertTrue(v.isEqual(vExp,1e-12)) + pass + # test all the time steps of the 1/1 time step serie, on field 3 + for i in xrange(5): + f=allFMTSLeavesPerCommonSupport[0][2][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([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,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.,52.,53.,54.,55.,56.,57.,58.,59.,60.,61.,62.,63.],32,2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]']) ; vExp+=i*1000+200 + self.assertTrue(v.isEqual(vExp,1e-12)) + pass + pass pass -- 2.39.2