# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013 CEA/DEN, EDF R&D
+# Copyright (C) 2007-2014 CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
d.alloc(1,1)
d.iota(1.)
# seting a long name
- d.setInfoOnComponent(0,"CONCENTRATION of I129")
+ d.setInfoOnComponent(0,"CONCENTRATION of I129")
f.setArray(d)
f.setName("field")
#
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()