From: ageay Date: Wed, 15 Jan 2014 15:47:46 +0000 (+0000) Subject: Correct bug on CMesh with no profiles ! X-Git-Tag: V7_3_1b1^2~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=df56135afe344c8bd375d36f3ffc7c05874ec36e;p=modules%2Fmed.git Correct bug on CMesh with no profiles ! --- diff --git a/src/MEDLoader/MEDFileFieldOverView.cxx b/src/MEDLoader/MEDFileFieldOverView.cxx index d8ed26f42..c7c3e5287 100644 --- a/src/MEDLoader/MEDFileFieldOverView.cxx +++ b/src/MEDLoader/MEDFileFieldOverView.cxx @@ -1143,13 +1143,14 @@ MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : null input pointer !"); if(levs.size()!=1 || levs[0]!=0) throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor : levels supported is 0 only !"); - int mdim(MEDCouplingStructuredMesh::GetGeoTypeGivenMeshDimension(m->getMeshDimension())); - _coords.resize(mdim); - for(int i=0;igetSpaceDimension()); + _coords.resize(sdim); + for(int i=0;i(m->getMesh()->getCoordsAt(i))); if(!elt) throw INTERP_KERNEL::Exception("MEDCMeshMultiLev constructor 2 : presence of null pointer for an vector of double along an axis !"); + elt->incrRef(); _coords[i]=elt; } } @@ -1188,7 +1189,9 @@ std::vector MEDCMeshMultiLev::getNodeGridStructure() const MEDMeshMultiLev *MEDCMeshMultiLev::prepare() const { - const DataArrayInt *pfl(_pfls[0]),*nr(_node_reduction); + const DataArrayInt *pfl(0),*nr(_node_reduction); + if(!_pfls.empty()) + pfl=_pfls[0]; MEDCouplingAutoRefCountObjectPtr nnr; std::vector cgs,ngs(getNodeGridStructure()); cgs.resize(ngs.size()); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 06607db5e..7c557c9ab 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -860,6 +860,7 @@ namespace ParaMEDMEM static MEDFileCMesh *New(const char *fileName, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception); static MEDFileCMesh *New(const char *fileName, const char *mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception); void setMesh(MEDCouplingCMesh *m) throw(INTERP_KERNEL::Exception); + int getSpaceDimension() const throw(INTERP_KERNEL::Exception); %extend { MEDFileCMesh() diff --git a/src/MEDLoader/Swig/MEDLoaderTest.py b/src/MEDLoader/Swig/MEDLoaderTest.py index 441ee6610..bfd1b3bbe 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest.py +++ b/src/MEDLoader/Swig/MEDLoaderTest.py @@ -710,6 +710,45 @@ class MEDLoaderTest(unittest.TestCase): MEDLoader.MEDLoader.WriteField(fname,f,True) pass + def testUsingAlreadyWrittenMesh2(self): + """ This test focuses on MEDLoader.WriteFieldUsingAlreadyWrittenMesh with mesh different from UMesh. + """ + fname="Pyfile76.med" + mesh=MEDLoader.MEDCouplingCMesh("mesh") + arrX=MEDLoader.DataArrayDouble([0,1,2,3]) + arrY=MEDLoader.DataArrayDouble([0,2,3,5,7]) + arrZ=MEDLoader.DataArrayDouble([7]) + mesh.setCoords(arrX,arrY,arrZ) + # + f1=MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_NODES) ; f1.setName("f1") + f1.setMesh(mesh) + arr=MEDLoader.DataArrayDouble(20) ; arr.iota() + f1.setArray(arr) + f1.checkCoherency() + # + f2=MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_NODES) ; f2.setName("f2") + f2.setMesh(mesh) + arr=MEDLoader.DataArrayDouble(20) ; arr.iota() ; arr*=3 + f2.setArray(arr) + f2.checkCoherency() + # + f11=f1.deepCpy() ; (f11.getArray())[:]*=4 ; f11.setTime(1.1,5,6) + # + MEDLoader.MEDLoader.WriteMesh(fname,f1.getMesh(),True) + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f1) + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2) + MEDLoader.MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f11) + ## + f1r=MEDLoader.MEDLoader.ReadFieldNode(fname,"mesh",0,"f1",-1,-1); + self.assertTrue(f1.isEqual(f1r,1e-12,1e-12)) + self.assertTrue(f1r.getArray().isEqual(MEDLoader.DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.]),1e-12)) + f2r=MEDLoader.MEDLoader.ReadFieldNode(fname,"mesh",0,"f2",-1,-1); + self.assertTrue(f2.isEqual(f2r,1e-12,1e-12)) + self.assertTrue(f2r.getArray().isEqual(MEDLoader.DataArrayDouble([0.,3.,6.,9.,12.,15.,18.,21.,24.,27.,30.,33.,36.,39.,42.,45.,48.,51.,54.,57.]),1e-12)) + f3r=MEDLoader.MEDLoader.ReadFieldNode(fname,"mesh",0,"f1",5,6); + self.assertTrue(f11.isEqual(f3r,1e-12,1e-12)) + self.assertTrue(f3r.getArray().isEqual(MEDLoader.DataArrayDouble([0.,4.,8.,12.,16.,20.,24.,28.,32.,36.,40.,44.,48.,52.,56.,60.,64.,68.,72.,76.]),1e-12)) + pass pass unittest.main() diff --git a/src/MEDLoader/Swig/MEDLoaderTest4.py b/src/MEDLoader/Swig/MEDLoaderTest4.py index afce1182a..203f7f578 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest4.py +++ b/src/MEDLoader/Swig/MEDLoaderTest4.py @@ -3410,7 +3410,86 @@ class MEDLoaderTest4(unittest.TestCase): self.assertTrue(v.isEqual(vExp,1e-12)) pass - + def test24(self): + """ Non regression test for cartesian mesh whose the 3rd direction has only one node. It a false 3D mesh. + """ + fname="ForMEDReader24.med" + fieldName0="zeFieldNode" + cmesh=MEDCouplingCMesh("mesh") + arr0=DataArrayDouble([0.,1.1,2.2,3.3,4.4]) + arr1=DataArrayDouble([0.,1.4,2.3]) + arr2=DataArrayDouble([5.]) + cmesh.setCoords(arr0,arr1,arr2) + fmts0=MEDFileFieldMultiTS() + fmts0.setDtUnit("s") + # + t=(1.1,2,3) + f=MEDCouplingFieldDouble(ON_NODES) ; f.setName(fieldName0) + f.setMesh(cmesh) + arr=DataArrayDouble(15) ; arr.setInfoOnComponents(["tutu"]) ; arr.iota() + f.setArray(arr) + f.setTime(*t) + f1ts=MEDFileField1TS() + f1ts.setFieldNoProfileSBT(f) + fmts0.pushBackTimeStep(f1ts) + # + t=(3.3,4,5) + arr=DataArrayDouble(15) ; arr.setInfoOnComponents(["tutu"]) ; arr.iota() + arr.reverse() + f.setArray(arr) + f.setTime(*t) + f1ts=MEDFileField1TS() + f1ts.setFieldNoProfileSBT(f) + fmts0.pushBackTimeStep(f1ts) + # + mm=MEDFileCMesh() ; mm.setMesh(cmesh) + mm.write(fname,2) + fmts0.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) + allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]]) + self.assertEqual(len(allFMTSLeavesPerCommonSupport),1) + self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),1) + # + mst=MEDFileMeshStruct.New(ms[0]) + # + fcscp=allFMTSLeavesPerCommonSupport[0][1] + mml=fcscp.buildFromScratchDataSetSupport(0,fields) + mml2=mml.prepare() + self.assertTrue(isinstance(mml2,MEDCMeshMultiLev)) + a,b,c=mml2.buildVTUArrays() + self.assertTrue(a.isEqual(arr0,1e-12)) + self.assertTrue(b.isEqual(arr1,1e-12)) + self.assertTrue(c.isEqual(arr2,1e-12)) + for i in xrange(2): + 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(15) ; vExp.iota(0) ; vExp.setInfoOnComponents(["tutu"]) + if i==1: + vExp.reverse() + pass + self.assertTrue(v.isEqual(vExp,1e-12)) + pass + pass pass