--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2010 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.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from libMEDLoader_Swig import *
+from math import pi,e,sqrt
+
+class MEDLoaderDataForTest:
+ def build1DMesh_1(cls):
+ coords=[ 0.0, 0.3, 0.75, 1.0, 1.4, 1.3 ]
+ conn=[ 0,1, 1,2, 2,3 , 3,4,5]
+ mesh=MEDCouplingUMesh.New();
+ mesh.setName("1DMesh_1");
+ mesh.setMeshDimension(1);
+ mesh.allocateCells(4);
+ mesh.insertNextCell(NORM_SEG2,2,conn[0:2])
+ mesh.insertNextCell(NORM_SEG2,2,conn[2:4])
+ mesh.insertNextCell(NORM_SEG2,2,conn[4:6])
+ mesh.insertNextCell(NORM_SEG3,3,conn[6:9])
+ mesh.finishInsertingCells();
+ myCoords=DataArrayDouble.New();
+ myCoords.setValues(coords,6,1);
+ myCoords.setInfoOnComponent(0,"tototototototot (m*m*m*m*m*m*m*m)");
+ mesh.setCoords(myCoords);
+ return mesh;
+
+ def build2DCurveMesh_1(cls):
+ coords=[ 0.0,0.0, 0.3,0.3, 0.75,0.75, 1.0,1.0, 1.4,1.4, 1.3,1.3 ]
+ conn=[ 0,1, 1,2, 2,3 , 3,4,5]
+ mesh=MEDCouplingUMesh.New();
+ mesh.setName("2DCurveMesh_1");
+ mesh.setMeshDimension(1);
+ mesh.allocateCells(4);
+ mesh.insertNextCell(NORM_SEG2,2,conn[0:2])
+ mesh.insertNextCell(NORM_SEG2,2,conn[2:4])
+ mesh.insertNextCell(NORM_SEG2,2,conn[4:6])
+ mesh.insertNextCell(NORM_SEG3,3,conn[6:9])
+ mesh.finishInsertingCells();
+ myCoords=DataArrayDouble.New();
+ myCoords.setValues(coords,6,2);
+ mesh.setCoords(myCoords);
+ return mesh;
+
+ def build2DMesh_1(cls):
+ targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
+ -0.05,0.95, 0.2,1.2, 0.45,0.95]
+ targetConn=[1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4]
+ targetMesh=MEDCouplingUMesh.New();
+ targetMesh.setMeshDimension(2);
+ targetMesh.allocateCells(6);
+ targetMesh.setName("2DMesh_1");
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
+ targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[12:16])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[16:20])
+ targetMesh.insertNextCell(NORM_POLYGON,4,targetConn[20:24])
+ targetMesh.finishInsertingCells();
+ myCoords=DataArrayDouble.New();
+ myCoords.setValues(targetCoords,12,2);
+ myCoords.setInfoOnComponent(0,"tototototototot (m)");
+ myCoords.setInfoOnComponent(1,"energie (kW)");
+ targetMesh.setCoords(myCoords)
+ return targetMesh;
+
+ def build2DMesh_2(cls):
+ targetCoords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7,
+ -0.05,0.95, 0.2,1.2, 0.45,0.95]
+ targetConn=[1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4]
+ targetMesh=MEDCouplingUMesh.New();
+ targetMesh.setMeshDimension(2);
+ targetMesh.allocateCells(5);
+ targetMesh.setName("2DMesh_2");
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
+ targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[12:16])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[16:20])
+ targetMesh.finishInsertingCells();
+ myCoords=DataArrayDouble.New();
+ myCoords.setValues(targetCoords,12,2);
+ myCoords.setInfoOnComponent(0,"toto (m)");
+ myCoords.setInfoOnComponent(1,"energie (kW)");
+ targetMesh.setCoords(myCoords);
+ return targetMesh;
+
+ def build3DMesh_1(cls):
+ coords=[0.,0.,0., 1.,1.,0., 1.,1.25,0., 0.,1.,0., 1.,1.5,0., 2.,0.,0., 2.,1.,0., 1.,2.,0., 0.,2.,0., 3.,1.,0.,
+ 3.,2.,0., 0.,1.,0., 1.,3.,0., 2.,2.,0., 2.,3.,0.,
+ 0.,0.,1., 1.,1.,1., 1.,1.25,1., 0.,1.,1., 1.,1.5,1., 2.,0.,1., 2.,1.,1., 1.,2.,1., 0.,2.,1., 3.,1.,1.,
+ 3.,2.,1., 0.,1.,1., 1.,3.,1., 2.,2.,1., 2.,3.,1.,
+ 0.,0.,2., 1.,1.,2., 1.,1.25,2., 0.,1.,2., 1.,1.5,2., 2.,0.,2., 2.,1.,2., 1.,2.,2., 0.,2.,2., 3.,1.,2.,
+ 3.,2.,2., 0.,1.,2., 1.,3.,2., 2.,2.,2., 2.,3.,2.,
+ 0.,0.,3., 1.,1.,3., 1.,1.25,3., 0.,1.,3., 1.,1.5,3., 2.,0.,3., 2.,1.,3., 1.,2.,3., 0.,2.,3., 3.,1.,3.,
+ 3.,2.,3., 0.,1.,3., 1.,3.,3., 2.,2.,3., 2.,3.,3.]
+ conn=[
+ # 0
+ 0,11,1,3,15,26,16,18, 1,2,4,7,13,6,-1,1,16,21,6,-1,6,21,28,13,-1,13,7,22,28,-1,7,4,19,22,-1,4,2,17,19,-1,2,1,16,17,-1,16,21,28,22,19,17,
+ 1,6,5,3,16,21,20,18, 13,10,9,6,28,25,24,21,
+ 11,8,7,4,2,1,-1,11,26,16,1,-1,1,16,17,2,-1,2,17,19,4,-1,4,19,22,7,-1,7,8,23,22,-1,8,11,26,23,-1,26,16,17,19,22,23,
+ 7,12,14,13,22,27,29,28,
+ # 1
+ 15,26,16,18,30,41,31,33, 16,17,19,22,28,21,-1,16,31,36,21,-1,21,36,43,28,-1,28,22,37,43,-1,22,19,34,37,-1,19,17,32,34,-1,17,16,31,32,-1,31,36,43,37,34,32,
+ 16,21,20,18,31,36,35,33, 28,25,24,21,43,40,39,36,
+ 26,23,22,19,17,16,-1,26,41,31,16,-1,16,31,32,17,-1,17,32,34,19,-1,19,34,37,22,-1,22,23,38,37,-1,23,26,41,38,-1,41,31,32,34,37,38,
+ 22,27,29,28,37,42,44,43,
+ # 2
+ 30,41,31,33,45,56,46,48, 31,32,34,37,43,36,-1,31,46,51,36,-1,36,51,58,43,-1,43,37,52,58,-1,37,34,49,52,-1,34,32,47,49,-1,32,31,46,47,-1,46,51,58,52,49,47,
+ 31,36,35,33,46,51,50,48, 43,40,39,36,58,55,54,51,
+ 41,38,37,34,32,31,-1,41,56,46,31,-1,31,46,47,32,-1,32,47,49,34,-1,34,49,52,37,-1,37,38,53,52,-1,38,41,56,53,-1,56,46,47,49,52,53,
+ 37,42,44,43,52,57,59,58]
+ #
+ ret=MEDCouplingUMesh.New();
+ ret.setName("3DMesh_1");
+ ret.setMeshDimension(3);
+ ret.allocateCells(18);
+ #
+ ret.insertNextCell(NORM_HEXA8,8,conn[0:8])
+ ret.insertNextCell(NORM_HEXA8,8,conn[51:59])
+ ret.insertNextCell(NORM_HEXA8,8,conn[59:67])
+ ret.insertNextCell(NORM_HEXA8,8,conn[110:118])
+ #
+ ret.insertNextCell(NORM_HEXA8,8,conn[118:126])
+ ret.insertNextCell(NORM_HEXA8,8,conn[169:177])
+ ret.insertNextCell(NORM_HEXA8,8,conn[177:185])
+ ret.insertNextCell(NORM_HEXA8,8,conn[228:236])
+ #
+ ret.insertNextCell(NORM_HEXA8,8,conn[236:244])
+ ret.insertNextCell(NORM_HEXA8,8,conn[287:295])
+ ret.insertNextCell(NORM_HEXA8,8,conn[295:303])
+ ret.insertNextCell(NORM_HEXA8,8,conn[346:354])
+ #
+ ret.insertNextCell(NORM_POLYHED,43,conn[8:51])
+ ret.insertNextCell(NORM_POLYHED,43,conn[67:110])
+ ret.insertNextCell(NORM_POLYHED,43,conn[126:169])
+ ret.insertNextCell(NORM_POLYHED,43,conn[185:228])
+ ret.insertNextCell(NORM_POLYHED,43,conn[244:287])
+ ret.insertNextCell(NORM_POLYHED,43,conn[303:346])
+ #
+ ret.finishInsertingCells();
+ myCoords=DataArrayDouble.New();
+ myCoords.setValues(coords,60,3);
+ myCoords.setInfoOnComponent(0,"titi (m)");
+ myCoords.setInfoOnComponent(1,"density power (MW/m^3)");
+ myCoords.setInfoOnComponent(2,"t (kW)");
+ ret.setCoords(myCoords);
+ return ret;
+
+ def build3DSurfMesh_1(cls):
+ targetCoords=[-0.3,-0.3,-0.3, 0.2,-0.3,-0.3, 0.7,-0.3,-0.3, -0.3,0.2,-0.3, 0.2,0.2,-0.3, 0.7,0.2,-0.3, -0.3,0.7,-0.3, 0.2,0.7,-0.3, 0.7,0.7,-0.3
+ ,-0.05,0.95,-0.3, 0.2,1.2,-0.3, 0.45,0.95,-0.3]
+ targetConn=[1,4,2, 4,5,2, 6,10,8,9,11,7, 0,3,4,1, 6,7,4,3, 7,8,5,4]
+ targetMesh=MEDCouplingUMesh.New();
+ targetMesh.setMeshDimension(2);
+ targetMesh.allocateCells(6);
+ targetMesh.setName("3DSurfMesh_1");
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[0:3])
+ targetMesh.insertNextCell(NORM_TRI3,3,targetConn[3:6])
+ targetMesh.insertNextCell(NORM_TRI6,6,targetConn[6:12])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[12:16])
+ targetMesh.insertNextCell(NORM_QUAD4,4,targetConn[16:20])
+ targetMesh.insertNextCell(NORM_POLYGON,4,targetConn[20:24])
+ targetMesh.finishInsertingCells();
+ myCoords=DataArrayDouble.New();
+ myCoords.setValues(targetCoords,12,3);
+ myCoords.setInfoOnComponent(0,"toto (m)");
+ myCoords.setInfoOnComponent(2,"ff (km)");#component 1 is not set for test
+ targetMesh.setCoords(myCoords);
+ return targetMesh;
+
+ def build3DMesh_2(cls):
+ m3dsurfBase=MEDLoaderDataForTest.build3DSurfMesh_1();
+ numbers=[0,1,3,4,5]
+ m3dsurf=m3dsurfBase.buildPartOfMySelf(numbers,False);
+ m1dBase=MEDLoaderDataForTest.build1DMesh_1();
+ numbers2=[0,1,2,3]
+ m1d=m1dBase.buildPartOfMySelf(numbers2,False);
+ m1d.changeSpaceDimension(3);
+ vec=[0.,1.,0.]
+ pt=[0.,0.,0.]
+ m1d.rotate(pt,vec,-pi/2.);
+ ret=m3dsurf.buildExtrudedMeshFromThis(m1d,0);
+ return ret;
+
+ def buildVecFieldOnCells_1(cls):
+ mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
+ nbOfCells=mesh.getNumberOfCells();
+ f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+ f1.setName("VectorFieldOnCells");
+ f1.setMesh(mesh);
+ array=DataArrayDouble.New();
+ arr1=[0.,10.,20.,1.,11.,21.,2.,12.,22.,3.,13.,23.,4.,14.,24.,5.,15.,25.]
+ array.setValues(arr1,nbOfCells,3);
+ array.setInfoOnComponent(0,"power (MW/m^3)");
+ array.setInfoOnComponent(1,"density (g/cm^3)");
+ array.setInfoOnComponent(2,"temperature (K)");
+ f1.setArray(array);
+ tmp=array.getPointer();
+ f1.setTime(2.,0,1);
+ f1.checkCoherency();
+ return f1;
+
+ def buildVecFieldOnNodes_1(cls):
+ mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
+ nbOfNodes=mesh.getNumberOfNodes();
+ f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME);
+ f1.setName("VectorFieldOnNodes");
+ f1.setMesh(mesh);
+ array=DataArrayDouble.New();
+ f1.setArray(array);
+ arr1=[70.,80.,90.,71.,81.,91.,72.,82.,92.,73.,83.,93.,74.,84.,94.,75.,85.,95.,
+ 1000.,10010.,10020.,1001.,10011.,10021.,1002.,10012.,10022.,1003.,10013.,10023.,1004.,10014.,10024.,1005.,10015.,10025.]
+ array.setValues(arr1,nbOfNodes,3);
+ array.setInfoOnComponent(0,"power (MW/m^3)");
+ array.setInfoOnComponent(1,"density (g/cm^3)");
+ array.setInfoOnComponent(2,"temperature (K)");
+ f1.setTime(2.12,2,3);
+ f1.checkCoherency();
+ return f1;
+
+ def buildVecFieldOnGauss_1(cls):
+ _a=0.446948490915965;
+ _b=0.091576213509771;
+ _p1=0.11169079483905;
+ _p2=0.0549758718227661;
+ refCoo1=[ 0.,0., 1.,0., 0.,1. ]
+ gsCoo1=[ 2*_b-1, 1-4*_b, 2*_b-1, 2.07*_b-1, 1-4*_b,
+ 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 ];
+ wg1=[ 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 ]
+ _refCoo1=refCoo1;
+ _gsCoo1=gsCoo1;
+ _wg1=wg1;
+ m=MEDLoaderDataForTest.build2DMesh_2();
+ f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME);
+ f.setTime(3.14,1,5);
+ f.setMesh(m);
+ f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1);
+ refCoo2=[-1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 ]
+ _refCoo2=refCoo2;
+ _gsCoo1=_gsCoo1[0:6];
+ _wg1=_wg1[0:3];
+ f.setGaussLocalizationOnType(NORM_TRI6,_refCoo2,_gsCoo1,_wg1);
+ refCoo3=[ 0.,0., 1.,0., 1.,1., 0.,1. ]
+ _refCoo3=refCoo3;
+ _gsCoo1=_gsCoo1[0:4];
+ _wg1=_wg1[0:2];
+ f.setGaussLocalizationOnType(NORM_QUAD4,_refCoo3,_gsCoo1,_wg1);
+ array=DataArrayDouble.New();
+ array.alloc(19,2);
+ ptr=array.getPointer();
+ for i in xrange(19*2):
+ array.setIJ(0,i,float(i+7));
+ pass
+ f.setArray(array);
+ f.setName("MyFirstFieldOnGaussPoint");
+ array.setInfoOnComponent(0,"power (MW/m^3)");
+ array.setInfoOnComponent(1,"density");
+ f.checkCoherency();
+ return f;
+
+ def buildVecFieldOnGaussNE_1(cls):
+ m=MEDLoaderDataForTest.build2DMesh_2();
+ f=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME);
+ f.setTime(3.14,1,5);
+ f.setMesh(m);
+ array=DataArrayDouble.New();
+ array.alloc(20,2);
+ for i in xrange(2*20):
+ array.setIJ(0,i,float(i+8));
+ f.setArray(array);
+ array.setInfoOnComponent(0,"power (W)");
+ array.setInfoOnComponent(1,"temperature");
+ f.setName("MyFieldOnGaussNE");
+ f.checkCoherency();
+ return f;
+
+ build1DMesh_1=classmethod(build1DMesh_1)
+ build2DCurveMesh_1=classmethod(build2DCurveMesh_1)
+ build2DMesh_1=classmethod(build2DMesh_1)
+ build2DMesh_2=classmethod(build2DMesh_2)
+ build3DMesh_1=classmethod(build3DMesh_1)
+ build3DSurfMesh_1=classmethod(build3DSurfMesh_1)
+ build3DMesh_2=classmethod(build3DMesh_2)
+ buildVecFieldOnCells_1=classmethod(buildVecFieldOnCells_1)
+ buildVecFieldOnNodes_1=classmethod(buildVecFieldOnNodes_1)
+ buildVecFieldOnGauss_1=classmethod(buildVecFieldOnGauss_1)
+ buildVecFieldOnGaussNE_1=classmethod(buildVecFieldOnGaussNE_1)
+ pass
--- /dev/null
+# -*- coding: iso-8859-1 -*-
+# Copyright (C) 2007-2010 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.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+from libMEDLoader_Swig import *
+import unittest
+from math import pi,e,sqrt
+from MEDLoaderDataForTest import MEDLoaderDataForTest
+
+class MEDLoaderTest(unittest.TestCase):
+ def testMesh1DRW(self):
+ mesh=MEDLoaderDataForTest.build1DMesh_1();
+ mesh.checkCoherency();
+ MEDLoader.WriteUMesh("Pyfile1.med",mesh,True);
+ mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile1.med",mesh.getName(),0);
+ self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
+ pass
+
+ def testMesh2DCurveRW(self):
+ mesh=MEDLoaderDataForTest.build2DCurveMesh_1();
+ mesh.checkCoherency();
+ MEDLoader.WriteUMesh("Pyfile2.med",mesh,True);
+ mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile2.med",mesh.getName(),0);
+ self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
+ pass
+
+ def testMesh2DRW(self):
+ mesh=MEDLoaderDataForTest.build2DMesh_1();
+ mesh.checkCoherency();
+ MEDLoader.WriteUMesh("Pyfile3.med",mesh,True);
+ mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile3.med",mesh.getName(),0);
+ self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
+ pass
+
+ def testMesh3DSurfRW(self):
+ mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
+ mesh.checkCoherency();
+ MEDLoader.WriteUMesh("Pyfile4.med",mesh,True);
+ mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile4.med",mesh.getName(),0);
+ self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
+ pass
+
+ def testMesh3DRW(self):
+ mesh=MEDLoaderDataForTest.build3DMesh_1();
+ mesh.checkCoherency();
+ MEDLoader.WriteUMesh("Pyfile5.med",mesh,True);
+ mesh_rw=MEDLoader.ReadUMeshFromFile("Pyfile5.med",mesh.getName(),0);
+ self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
+ pass
+
+ def testFieldRW1(self):
+ f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
+ MEDLoader.WriteField("Pyfile6.med",f1,True);
+ f2=MEDLoader.ReadFieldDoubleCell("Pyfile6.med",f1.getMesh().getName(),0,f1.getName(),0,1);
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ #
+ f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
+ MEDLoader.WriteField("Pyfile7.med",f1,True);
+ f2=MEDLoader.ReadFieldDoubleNode("Pyfile7.med",f1.getMesh().getName(),0,f1.getName(),2,3);
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ pass
+
+ def testFieldRW2(self):
+ fileName="Pyfile8.med";
+ VAL1=12345.67890314;
+ VAL2=-1111111111111.;
+ f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
+ MEDLoader.WriteField(fileName,f1,True);
+ f1.setTime(10.,8,9);
+ f1.getArray().setIJ(0,0,VAL1);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1.setTime(10.14,18,19);
+ f1.getArray().setIJ(0,0,VAL2);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ #retrieving time steps...
+ f2=MEDLoader.ReadFieldDoubleCell(fileName,f1.getMesh().getName(),0,f1.getName(),8,9);
+ f1.setTime(10.,8,9);
+ f1.getArray().setIJ(0,0,VAL1);
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ f2=MEDLoader.ReadFieldDoubleCell(fileName,f1.getMesh().getName(),0,f1.getName(),0,1);
+ f3=MEDLoaderDataForTest.buildVecFieldOnCells_1();
+ self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
+ f2=MEDLoader.ReadFieldDoubleCell(fileName,f1.getMesh().getName(),0,f1.getName(),18,19);
+ f1.setTime(10.14,18,19);
+ f1.getArray().setIJ(0,0,VAL2);
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ #ON NODES
+ f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
+ fileName2="Pyfile9.med";
+ MEDLoader.WriteField(fileName2,f1,True);
+ f1.setTime(110.,108,109);
+ tmp=f1.getArray().getPointer();
+ f1.getArray().setIJ(0,3,VAL1);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
+ f1.setTime(210.,208,209);
+ f1.getArray().setIJ(0,3,VAL2);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName2,f1);
+ f2=MEDLoader.ReadFieldDoubleNode(fileName2,f1.getMesh().getName(),0,f1.getName(),108,109);
+ f1.setTime(110.,108,109);
+ f1.getArray().setIJ(0,3,VAL1);
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ f2=MEDLoader.ReadFieldDoubleNode(fileName2,f1.getMesh().getName(),0,f1.getName(),2,3);
+ f3=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
+ self.assertTrue(f3.isEqual(f2,1e-12,1e-12));
+ f2=MEDLoader.ReadFieldDoubleNode(fileName2,f1.getMesh().getName(),0,f1.getName(),208,209);
+ f1.setTime(210.,208,209);
+ f1.getArray().setIJ(0,3,VAL2);
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ pass
+
+ #
+ # Multi field in a same file, but this field has several
+ #
+ def testFieldRW3(self):
+ fileName="Pyfile11.med";
+ VAL1=12345.67890314;
+ VAL2=-1111111111111.;
+ name1="AField";
+ name3="AMesh1";
+ name2="AMesh2";
+ f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
+ f1.getMesh().setName(name3);
+ f1.setName(name1);
+ f1.setTime(10.,8,9);
+ tmp=f1.getArray().getPointer();
+ f1.getArray().setIJ(0,0,VAL1);
+ MEDLoader.WriteField(fileName,f1,True);
+ f1.setTime(10.14,18,19);
+ f1.getArray().setIJ(0,0,VAL2);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1.getMesh().setName(name2);
+ f1.setTime(10.55,28,29);
+ f1.getArray().setIJ(0,0,3*VAL1);
+ MEDLoader.WriteField(fileName,f1,False);
+ f1.setTime(10.66,38,39);
+ f1.getArray().setIJ(0,0,3*VAL2);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1.setTime(10.77,48,49);
+ f1.getArray().setIJ(0,0,4*VAL2);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ #ON NODES
+ f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
+ f1.setName(name1);
+ f1.getMesh().setName(name2);
+ f1.setTime(110.,8,9);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1.setTime(110.,108,109);
+ tmp=f1.getArray().getPointer();
+ f1.getArray().setIJ(0,3,VAL1);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1.setTime(210.,208,209);
+ f1.getArray().setIJ(0,3,VAL2);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ #
+ it1=MEDLoader.GetCellFieldIterations(fileName,name3,name1);
+ self.assertEqual(2,len(it1));
+ self.assertEqual(8,it1[0][0]); self.assertEqual(9,it1[0][1]);
+ self.assertEqual(18,it1[1][0]); self.assertEqual(19,it1[1][1]);
+ it2=MEDLoader.GetCellFieldIterations(fileName,name2,name1);
+ self.assertEqual(3,len(it2));
+ self.assertEqual(28,it2[0][0]); self.assertEqual(29,it2[0][1]);
+ self.assertEqual(38,it2[1][0]); self.assertEqual(39,it2[1][1]);
+ self.assertEqual(48,it2[2][0]); self.assertEqual(49,it2[2][1]);
+ it3=MEDLoader.GetNodeFieldIterations(fileName,name2,name1);
+ self.assertEqual(3,len(it3));
+ self.assertEqual(8,it3[0][0]); self.assertEqual(9,it3[0][1]);
+ self.assertEqual(108,it3[1][0]); self.assertEqual(109,it3[1][1]);
+ self.assertEqual(208,it3[2][0]); self.assertEqual(209,it3[2][1]);
+ it4=MEDLoader.GetNodeFieldIterations(fileName,name3,name1);
+ self.assertTrue(len(it4)==0);
+ #
+ #
+ f1=MEDLoader.ReadFieldDoubleCell(fileName,name3,0,name1,8,9);
+ self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,0),13);
+ f1=MEDLoader.ReadFieldDoubleCell(fileName,name3,0,name1,18,19);
+ self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,0),13);
+ f1=MEDLoader.ReadFieldDoubleCell(fileName,name2,0,name1,28,29);
+ self.assertAlmostEqual(3*VAL1,f1.getArray().getIJ(0,0),13);
+ f1=MEDLoader.ReadFieldDoubleCell(fileName,name2,0,name1,38,39);
+ self.assertAlmostEqual(3*VAL2,f1.getArray().getIJ(0,0),13);
+ f1=MEDLoader.ReadFieldDoubleCell(fileName,name2,0,name1,48,49);
+ self.assertAlmostEqual(4*VAL2,f1.getArray().getIJ(0,0),13);
+ #
+ f1=MEDLoader.ReadFieldDoubleNode(fileName,name2,0,name1,8,9);
+ self.assertAlmostEqual(71.,f1.getArray().getIJ(0,3),13);
+ f1=MEDLoader.ReadFieldDoubleNode(fileName,name2,0,name1,108,109);
+ self.assertAlmostEqual(VAL1,f1.getArray().getIJ(0,3),13);
+ f1=MEDLoader.ReadFieldDoubleNode(fileName,name2,0,name1,208,209);
+ self.assertAlmostEqual(VAL2,f1.getArray().getIJ(0,3),13);
+ pass
+
+ def testMultiMeshRW1(self):
+ fileName="Pyfile10.med";
+ mesh1=MEDLoaderDataForTest.build3DMesh_1();
+ part1=[1,2,4,13,15]
+ mesh2=mesh1.buildPartOfMySelf(part1,True);
+ mesh2.setName("mesh2");
+ part2=[3,4,13,14]
+ mesh3=mesh1.buildPartOfMySelf(part2,True);
+ mesh3.setName("mesh3");
+ mesh4=MEDCouplingUMesh.New();
+ mesh4.setName("mesh4");
+ mesh4.setMeshDimension(3);
+ mesh4.allocateCells(1);
+ conn=[0,11,1,3]
+ mesh4.insertNextCell(NORM_TETRA4,4,conn[0:4])
+ mesh4.finishInsertingCells();
+ mesh4.setCoords(mesh1.getCoords());
+ meshes=[mesh1,mesh2,mesh3,mesh4]
+ mnane="3DToto";
+ MEDLoader.WriteUMeshes(fileName,mnane,meshes,True);
+ #
+ mesh5=MEDLoader.ReadUMeshFromFile(fileName,mnane);
+ mesh1.setName(mnane);
+ part3=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]
+ mesh6=mesh5.buildPartOfMySelf(part3,True);
+ mesh6.setName(mnane);
+ self.assertTrue(mesh6.isEqual(mesh1,1e-12));
+ grps=MEDLoader.GetMeshGroupsNames(fileName,mnane);
+ self.assertEqual(4,len(grps));
+ grps.index("mesh2");
+ grps.index("mesh3");
+ grps.index("mesh4");
+ grps.index("3DMesh_1");
+ #
+ vec=["mesh2"];
+ mesh2_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
+ self.assertTrue(mesh2_2.isEqual(mesh2,1e-12));
+ vec=["mesh3"];
+ mesh3_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
+ self.assertTrue(mesh3_2.isEqual(mesh3,1e-12));
+ vec=["mesh4"];
+ mesh4_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
+ self.assertTrue(mesh4_2.isEqual(mesh4,1e-12));
+ vec=["3DMesh_1"];
+ mesh1_2=MEDLoader.ReadUMeshFromGroups(fileName,mnane,0,vec);
+ mesh1.setName("3DMesh_1");
+ self.assertTrue(mesh1_2.isEqual(mesh1,1e-12));
+ #
+ vec=["Family_4","Family_2"];
+ mesh2_2=MEDLoader.ReadUMeshFromFamilies(fileName,mnane,0,vec);
+ mesh2_2.setName("mesh2");
+ self.assertTrue(mesh2_2.isEqual(mesh2,1e-12));
+ pass
+
+ def testFieldProfilRW1(self):
+ fileName="Pyfile12.med";
+ mesh1=MEDLoaderDataForTest.build3DMesh_1();
+ da,b=mesh1.mergeNodes(1e-12);
+ MEDLoader.WriteUMesh(fileName,mesh1,True);
+ part1=[1,2,4,13,15]
+ mesh2=mesh1.buildPartOfMySelf(part1,True);
+ mesh2.setName(mesh1.getName());#<- important for the test
+ #
+ nbOfCells=mesh2.getNumberOfCells();
+ self.assertEqual(5,nbOfCells);
+ f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME);
+ f1.setName("VectorFieldOnCells");
+ f1.setMesh(mesh2);
+ array=DataArrayDouble.New();
+ array.alloc(nbOfCells,2);
+ f1.setArray(array);
+ arr1=[71.,171.,10.,110.,20.,120.,30.,130.,40.,140.]
+ array.setValues(arr1,nbOfCells,2);
+ f1.setTime(3.14,2,7);
+ f1.checkCoherency();
+ #
+ MEDLoader.WriteField(fileName,f1,False);#<- False important for the test
+ #
+ f2=MEDLoader.ReadFieldDoubleCell(fileName,f1.getMesh().getName(),0,f1.getName(),2,7);
+ f2.checkCoherency();
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ #
+ pass
+
+ def testFieldGaussRW1(self):
+ fileName="Pyfile13.med";
+ f1=MEDLoaderDataForTest.buildVecFieldOnGauss_1();
+ MEDLoader.WriteField(fileName,f1,True);
+ f2=MEDLoader.ReadFieldDouble(ON_GAUSS_PT,fileName,f1.getMesh().getName(),0,f1.getName(),1,5);
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ pass
+
+ def testFieldGaussNERW1(self):
+ fileName="Pyfile14.med";
+ f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
+ MEDLoader.WriteField(fileName,f1,True);
+ f2=MEDLoader.ReadFieldDouble(ON_GAUSS_NE,fileName,f1.getMesh().getName(),0,f1.getName(),1,5);
+ self.assertTrue(f1.isEqual(f2,1e-12,1e-12));
+ pass
+
+ def testMesh3DSurfShuffleRW(self):
+ fileName="Pyfile15.med";
+ mesh=MEDLoaderDataForTest.build3DSurfMesh_1();
+ renumber1=[2,5,1,0,3,4]
+ mesh.renumberCells(renumber1,False);
+ mesh.checkCoherency();
+ MEDLoader.WriteUMesh(fileName,mesh,True);
+ mesh_rw=MEDLoader.ReadUMeshFromFile(fileName,mesh.getName(),0);
+ self.assertTrue(mesh.isEqual(mesh_rw,1e-12));
+ pass
+
+ def testMultiFieldShuffleRW1(self):
+ fileName="Pyfile17.med";
+ m=MEDLoaderDataForTest.build3DMesh_2();
+ self.assertEqual(20,m.getNumberOfCells());
+ self.assertEqual(45,m.getNumberOfNodes());
+ polys=[1,4,6]
+ m.convertToPolyTypes(polys);
+ renum=[1,3,2,8,9,12,13,16,19,0,4,7,5,15,14,17,10,18,6,11]
+ m.renumberCells(renum,False);
+ m.orientCorrectlyPolyhedrons();
+ # Writing
+ MEDLoader.WriteUMesh(fileName,m,True);
+ f1Tmp=m.getMeasureField(False);
+ f1=f1Tmp.buildNewTimeReprFromThis(ONE_TIME,False);
+ f1.setTime(0.,1,2);
+ f_1=f1.cloneWithMesh(True);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1.applyFunc("2*x");
+ f1.setTime(0.01,3,4);
+ f_2=f1.cloneWithMesh(True);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ f1.applyFunc("2*x/3");
+ f1.setTime(0.02,5,6);
+ f_3=f1.cloneWithMesh(True);
+ MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f1);
+ # Reading
+ its=[(1,2),(3,4),(5,6)];
+ fs=MEDLoader.ReadFieldsDoubleOnSameMesh(ON_CELLS,fileName,f_1.getMesh().getName(),0,f_1.getName(),its);
+ self.assertEqual(3,len(fs));
+ self.assertTrue(fs[0].isEqual(f_1,1e-12,1e-12));
+ self.assertTrue(fs[1].isEqual(f_2,1e-12,1e-12));
+ self.assertTrue(fs[2].isEqual(f_3,1e-12,1e-12));
+ pass
+ pass
+
+unittest.main()