]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Correct bug on CMesh with no profiles !
authorageay <ageay>
Wed, 15 Jan 2014 15:47:46 +0000 (15:47 +0000)
committerageay <ageay>
Wed, 15 Jan 2014 15:47:46 +0000 (15:47 +0000)
src/MEDLoader/MEDFileFieldOverView.cxx
src/MEDLoader/Swig/MEDLoaderCommon.i
src/MEDLoader/Swig/MEDLoaderTest.py
src/MEDLoader/Swig/MEDLoaderTest4.py

index d8ed26f422288f61899baea4da6f5973a20b97bb..c7c3e5287ff3d619b487e924b43b8aaf53c49cac 100644 (file)
@@ -1143,13 +1143,14 @@ MEDCMeshMultiLev::MEDCMeshMultiLev(const MEDFileCMesh *m, const std::vector<int>
     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;i<mdim;i++)
+  int sdim(m->getSpaceDimension());
+  _coords.resize(sdim);
+  for(int i=0;i<sdim;i++)
     {
       DataArrayDouble *elt(const_cast<DataArrayDouble *>(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<int> 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<DataArrayInt> nnr;
   std::vector<int> cgs,ngs(getNodeGridStructure());
   cgs.resize(ngs.size());
index 06607db5edcd98a4f1004a22754c9ebba2838554..7c557c9ab81345d8e94cea841a0d9f7b8e64cd1c 100644 (file)
@@ -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()
index 441ee661045fe59bf058109d26c6d446bde0fdb0..bfd1b3bbe27195e7cece51797fedc4fa205fa6f4 100644 (file)
@@ -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()
index afce1182a659cd6b0e8d89103921485e76cb98ef..203f7f5788b2671c95a7ab209e134401b996730c 100644 (file)
@@ -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