]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Context manager for MEDFile*Field1TS
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 27 Sep 2018 07:35:15 +0000 (09:35 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 27 Sep 2018 07:35:15 +0000 (09:35 +0200)
src/MEDLoader/Swig/MEDLoaderCommon.i
src/MEDLoader/Swig/MEDLoaderTest3.py

index 460be09dec786653b248b0904397dafd34c49564..359f8be11c5de07259158e4a86a54786a65b5cf9 100644 (file)
@@ -4113,3 +4113,14 @@ namespace MEDCoupling
     }
   };
 }
+
+%pythoncode %{
+def enter1TS(self):
+    self.loadArrays()
+    pass
+def exit1TS(self, exctype, exc, tb):
+    self.unloadArrays()
+    pass
+MEDFileAnyTypeField1TS.__enter__=enter1TS
+MEDFileAnyTypeField1TS.__exit__=exit1TS
+%}
index 65295157d212b163fe0c26ad325be57f61d1ed3d..b8a8936a03046cd36558f7cbe35f719e29c5359f 100644 (file)
@@ -6488,6 +6488,35 @@ class MEDLoaderTest3(unittest.TestCase):
             pass
         pass
 
+    def tessContxtMger1TS(self):
+        fname="Pyfile119.med"
+        coo=DataArrayDouble(1000) ; coo.iota()
+        m=MEDCouplingUMesh.Build0DMeshFromCoords(coo)
+        m.setName("mesh")
+        WriteMesh(fname,m,True)
+        f=MEDCouplingFieldDouble(ON_CELLS)
+        f.setMesh(m)
+        f.setName("Field")
+        arr=DataArrayDouble(m.getNumberOfCells())
+        f.setArray(arr)
+        f.checkConsistencyLight()
+        for i in range(10):
+            arr[:]=float(i+1)
+            f.setTime(float(i),i,0)
+            WriteFieldUsingAlreadyWrittenMesh(fname,f)
+            pass
+        #
+        mm=MEDFileMesh.New(fname)
+        fmts=MEDFileFieldMultiTS(fname,False)
+        refSize=fmts.getHeapMemorySize()
+        for f1ts in fmts:
+            with f1ts:
+                f=f1ts.field(mm)
+                pass
+            pass
+        self.assertIn(fmts.getHeapMemorySize(),range(refSize,refSize+refSize//10))
+        pass
+
     pass
 
 if __name__ == "__main__":