From 9d2f3857ae07a226d92d79d730e65966134fb989 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 24 Nov 2021 16:10:58 +0100 Subject: [PATCH] Test mesh deletion before writing field --- CDMATH/tests/swig/testFieldCreationAndSave.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/CDMATH/tests/swig/testFieldCreationAndSave.py b/CDMATH/tests/swig/testFieldCreationAndSave.py index d7f5e50..25e7e20 100644 --- a/CDMATH/tests/swig/testFieldCreationAndSave.py +++ b/CDMATH/tests/swig/testFieldCreationAndSave.py @@ -3,11 +3,13 @@ from math import sqrt import cdmath +import medcoupling as mc print("Loading a triangular mesh of a 2D square") filename = "./meshSquare" M=cdmath.Mesh(filename+".med") +#Extract groups in the mesh print("Checking boundary group names") boundaryFaceGroupNames=M.getNameOfFaceGroups() boundaryNodeGroupNames=M.getNameOfNodeGroups() @@ -69,3 +71,46 @@ for i in range(nbNodes): temperature_field_nodes[i] = Tout temperature_field_nodes.writeMED(filename, False) + +#### Delete mesh and still save field in a med file +m = mc.MEDCouplingCMesh() +x = mc.DataArrayDouble([0.,1.,2.]) +y = mc.DataArrayDouble([0.,1.,2.]) +m.setCoords(x, y) +m = m.buildUnstructured() +m.setName("mesh") + +f = mc.MEDCouplingFieldDouble(mc.ON_CELLS, mc.ONE_TIME) +f.setMesh(m) +f.setName("F") + +da = mc.DataArrayDouble([1,2,3,4]) +f.setArray(da) +f.setTime(0.0,0,0) + +# Maillage d'abord: +fName = "./michael.med" +mc.WriteUMesh(fName, m, True) + +# Maintenant juste les champs: +ff = mc.MEDFileField1TS() +ff.setFieldNoProfileSBT(f) +ff.write(fName, 0) + +# Tue le maillage +m = 0 +del m +import gc +gc.collect() # Make sure Python interp has called mesh destructor ... + +# Ecrit encore du champ: +da2 = da.deepCopy() +f.setTime(1.0,1,0) +da2 += 1 +print(da2.getValues()) +f.setArray(da2) + +ff = mc.MEDFileField1TS() +ff.setFieldNoProfileSBT(f) # le maillage n'existe plus, tant pis :-) +ff.write(fName, 0) +ff.write(fName, 0) # 1 append -- 2.39.2