Back to index

salome-med  6.5.0
MEDLoaderTest3.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 
00021 from MEDLoader import *
00022 import unittest
00023 from math import pi,e,sqrt
00024 from MEDLoaderDataForTest import MEDLoaderDataForTest
00025 
00026 class MEDLoaderTest(unittest.TestCase):
00027     def testMEDMesh1(self):
00028         fileName="Pyfile18.med"
00029         mname="ExampleOfMultiDimW"
00030         medmesh=MEDFileMesh.New(fileName,mname)
00031         self.assertEqual((0,-1),medmesh.getNonEmptyLevels())
00032         m1_0=medmesh.getLevel0Mesh(True)
00033         m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
00034         self.assertTrue(m1_0.isEqual(m1_1,1e-12));
00035         m2_0=medmesh.getLevelM1Mesh(True)
00036         m2_1=MEDLoader.ReadUMeshFromFile(fileName,mname,-1)
00037         self.assertTrue(m2_0.isEqual(m2_1,1e-12));
00038         pass
00039     def testMEDMesh2(self):
00040         fileName="Pyfile10.med"
00041         mname="3DToto"
00042         outFileName="MEDFileMesh1.med"
00043         medmesh=MEDFileUMesh.New(fileName,mname)
00044         self.assertEqual((0,),medmesh.getNonEmptyLevels())
00045         m1_0=medmesh.getLevel0Mesh(True)
00046         m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
00047         self.assertTrue(m1_0.isEqual(m1_1,1e-12));
00048         g1_0=medmesh.getGroup(0,"mesh2",True)
00049         g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh2"]);
00050         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
00051         g1_0=medmesh.getGroup(0,"mesh3",True)
00052         g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3"]);
00053         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
00054         g1_0=medmesh.getGroups(0,["mesh3","mesh2"])
00055         g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]);
00056         g1_1.setName(g1_0.getName())
00057         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
00058         g1_0=medmesh.getFamily(0,"Family_2",True)
00059         g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2"]);
00060         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
00061         g1_0=medmesh.getFamilies(0,["Family_2","Family_4"],True)
00062         g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_2","Family_4"]);
00063         g1_1.setName(g1_0.getName())
00064         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
00065         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
00066         medmesh.write(outFileName,2);
00067         self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",True).getValues());
00068         self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",True).getValues());
00069         self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],True).getValues());
00070         self.assertEqual([19,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
00071         famn=medmesh.getFamilyNameGivenId(0)
00072         self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True);
00073         #without renum
00074         self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2",False).getValues());
00075         self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_2",False).getValues());
00076         self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_4","Family_2"],False).getValues());
00077         self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
00078         self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False);
00079         pass
00080 
00081     # this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account
00082     def testMEDMesh3(self):
00083         outFileName="MEDFileMesh3.med"
00084         c=DataArrayDouble.New()
00085         coords=[-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 ];
00086         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
00087         c.setValues(coords,9,2)
00088         m=MEDCouplingUMesh.New();
00089         m.setMeshDimension(2);
00090         m.allocateCells(5);
00091         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
00092         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
00093         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
00094         m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
00095         m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
00096         m.finishInsertingCells();
00097         m.setCoords(c)
00098         m.checkCoherency()
00099         m1=MEDCouplingUMesh.New();
00100         m1.setMeshDimension(1);
00101         m1.allocateCells(3);
00102         m1.insertNextCell(NORM_SEG2,2,[1,4])
00103         m1.insertNextCell(NORM_SEG2,2,[3,6])
00104         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
00105         m1.finishInsertingCells();
00106         m1.setCoords(c)
00107         m1.checkCoherency()
00108         m2=MEDCouplingUMesh.New();
00109         m2.setMeshDimension(0);
00110         m2.allocateCells(4);
00111         m2.insertNextCell(NORM_POINT1,1,[1])
00112         m2.insertNextCell(NORM_POINT1,1,[3])
00113         m2.insertNextCell(NORM_POINT1,1,[2])
00114         m2.insertNextCell(NORM_POINT1,1,[6])
00115         m2.finishInsertingCells();
00116         m2.setCoords(c)
00117         m2.checkCoherency()
00118         #
00119         mm=MEDFileUMesh.New()
00120         mm.setName("MyFirstMEDCouplingMEDmesh")
00121         mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
00122         mm.setCoords(c)
00123         mm.setMeshAtLevel(-1,m1);
00124         mm.setMeshAtLevel(0,m);
00125         mm.setMeshAtLevel(-2,m2);
00126         # playing with groups
00127         g1_2=DataArrayInt.New()
00128         g1_2.setValues([1,3],2,1)
00129         g1_2.setName("G1")
00130         g2_2=DataArrayInt.New()
00131         g2_2.setValues([1,2,3],3,1)
00132         g2_2.setName("G2")
00133         mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
00134         g1_1=DataArrayInt.New()
00135         g1_1.setValues([0,1,2],3,1)
00136         g1_1.setName("G1")
00137         g2_1=DataArrayInt.New()
00138         g2_1.setValues([0,2],2,1)
00139         g2_1.setName("G2")
00140         mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
00141         g1_N=DataArrayInt.New()
00142         g1_N.setValues(range(8),8,1)
00143         g1_N.setName("G1")
00144         g2_N=DataArrayInt.New()
00145         g2_N.setValues(range(9),9,1)
00146         g2_N.setName("G2")
00147         mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
00148         mm.createGroupOnAll(0,"GrpOnAllCell")
00149         # check content of mm
00150         t=mm.getGroupArr(0,"G1",False)
00151         self.assertTrue(g1_2.isEqual(t));
00152         t=mm.getGroupArr(0,"G2",False)
00153         self.assertTrue(g2_2.isEqual(t));
00154         t=mm.getGroupArr(-1,"G1",False)
00155         self.assertTrue(g1_1.isEqual(t));
00156         t=mm.getGroupArr(-1,"G2",False)
00157         self.assertTrue(g2_1.isEqual(t));
00158         t=mm.getGroupArr(1,"G1",False)
00159         self.assertTrue(g1_N.isEqual(t));
00160         t=mm.getGroupArr(1,"G2",False)
00161         self.assertTrue(g2_N.isEqual(t));
00162         self.assertTrue(mm.existsGroup("GrpOnAllCell"));
00163         t=mm.getGroupArr(0,"GrpOnAllCell")
00164         self.assertTrue(t.getValues()==range(5))
00165         #
00166         mm.write(outFileName,2);
00167         #
00168         mm=MEDFileMesh.New(outFileName)
00169         mbis=mm.getMeshAtLevel(0)
00170         m.setName(mm.getName()) ; m.setDescription(mm.getDescription())
00171         self.assertTrue(m.isEqual(mbis,1e-12));
00172         #
00173         self.assertEqual(([[(3, 2), (4, 1), (5, 8)], [(1, 2), (2, 1)], [(0, 4)]], 2, 2, 9),MEDLoader.GetUMeshGlobalInfo(outFileName,"MyFirstMEDCouplingMEDmesh"))
00174         pass
00175 
00176     # this test is the testMEDMesh3 except that permutation is dealed here
00177     def testMEDMesh4(self):
00178         outFileName="MEDFileMesh4.med"
00179         c=DataArrayDouble.New()
00180         coords=[-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 ];
00181         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
00182         c.setValues(coords,9,2)
00183         c.setInfoOnComponent(0,"abcdef [km]")
00184         c.setInfoOnComponent(1,"ghij [MW]")
00185         m=MEDCouplingUMesh.New();
00186         m.setMeshDimension(2);
00187         m.allocateCells(5);
00188         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
00189         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
00190         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
00191         m.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
00192         m.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
00193         m.finishInsertingCells();
00194         m.setCoords(c)
00195         m.checkCoherency()
00196         m1=MEDCouplingUMesh.New();
00197         m1.setMeshDimension(1);
00198         m1.allocateCells(3);
00199         m1.insertNextCell(NORM_SEG2,2,[1,4])
00200         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
00201         m1.insertNextCell(NORM_SEG2,2,[3,6])
00202         m1.finishInsertingCells();
00203         m1.setCoords(c)
00204         m1.checkCoherency()
00205         m2=MEDCouplingUMesh.New();
00206         m2.setMeshDimension(0);
00207         m2.allocateCells(4);
00208         m2.insertNextCell(NORM_POINT1,1,[1])
00209         m2.insertNextCell(NORM_POINT1,1,[3])
00210         m2.insertNextCell(NORM_POINT1,1,[2])
00211         m2.insertNextCell(NORM_POINT1,1,[6])
00212         m2.finishInsertingCells();
00213         m2.setCoords(c)
00214         m2.checkCoherency()
00215         #
00216         mm=MEDFileUMesh.New()
00217         mm.setName("My2ndMEDCouplingMEDmesh")
00218         mm.setDescription("ThisIsImpossibleToDoWithMEDMEM")
00219         mm.setCoords(c)
00220         renumNode=DataArrayInt.New()
00221         renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1)
00222         mm.setRenumFieldArr(1,renumNode)
00223         mm.setMeshAtLevel(-1,m1,True);
00224         mm.setMeshAtLevel(0,m,True);
00225         mm.setMeshAtLevel(-2,m2,True);
00226         mm.removeMeshAtLevel(-2)
00227         mm.setMeshAtLevel(-2,m2,True);
00228         # playing with groups
00229         g1_2=DataArrayInt.New()
00230         g1_2.setValues([2,3],2,1)
00231         g1_2.setName("G1")
00232         g2_2=DataArrayInt.New()
00233         g2_2.setValues([2,0,3],3,1)
00234         g2_2.setName("G2")
00235         mm.setGroupsAtLevel(0,[g1_2,g2_2],True)
00236         g1_1=DataArrayInt.New()
00237         g1_1.setValues([0,2,1],3,1)
00238         g1_1.setName("G1")
00239         g2_1=DataArrayInt.New()
00240         g2_1.setValues([0,2],2,1)
00241         g2_1.setName("G2")
00242         mm.setGroupsAtLevel(-1,[g1_1,g2_1],True)
00243         g1_N=DataArrayInt.New()
00244         g1_N.setValues([10,11,12,13,14,15,16,17],8,1)
00245         g1_N.setName("G1")
00246         g2_N=DataArrayInt.New()
00247         g2_N.setValues([10,11,12,13,14,15,16,17,18],9,1)
00248         g2_N.setName("G2")
00249         mm.setGroupsAtLevel(1,[g1_N,g2_N],True)
00250         # check content of mm
00251         t=mm.getGroupArr(0,"G1",True)
00252         self.assertTrue(g1_2.isEqual(t));
00253         t=mm.getGroupArr(0,"G2",True)
00254         self.assertTrue(g2_2.isEqual(t));
00255         t=mm.getGroupArr(-1,"G1",True)
00256         self.assertTrue(g1_1.isEqual(t));
00257         t=mm.getGroupArr(-1,"G2",True)
00258         self.assertTrue(g2_1.isEqual(t));
00259         self.assertTrue(not mm.existsGroup("GrpOnAllCell"));
00260         #
00261         mm.write(outFileName,2);
00262         mm2=MEDFileMesh.New(outFileName)
00263         res=mm.isEqual(mm2,1e-12)
00264         self.assertTrue(res[0])
00265         l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
00266         self.assertEqual(['Family_10','Family_11','Family_3','Family_4','Family_7'],l)
00267         mm2.keepFamIdsOnlyOnLevs([3],[-1])
00268         for lev in mm.getGrpNonEmptyLevelsExt("G2"):
00269             self.assertEqual(mm.getGroupArr(lev,"G2").getValues(),mm2.getGroupArr(lev,"G2").getValues())
00270             pass
00271         l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
00272         self.assertEqual(['Family_10','Family_11','Family_12','Family_3','Family_4','Family_7'],l)
00273         #
00274         self.assertEqual([7,7,6],mm2.getFamilyFieldAtLevel(-1).getValues())
00275         mm2.getFamilyFieldAtLevel(-1).setIJ(1,0,8)
00276         self.assertEqual([7,8,6],mm2.getFamilyFieldAtLevel(-1).getValues())
00277         self.assertTrue(not mm2.existsFamily("Family_8"))
00278         mm2.createGroupOnAll(-1,"GrpOnAllFace")
00279         self.assertTrue(mm2.existsFamily("Family_8"))
00280         self.assertEqual(range(3),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
00281         pass
00282 
00283     #testing persistence of retrieved arrays
00284     def testMEDMesh5(self):
00285         fileName="Pyfile18.med"
00286         mname="ExampleOfMultiDimW"
00287         medmesh=MEDFileUMesh.New(fileName,mname)
00288         m1_0=medmesh.getLevel0Mesh(True)
00289         da1=medmesh.getFamilyFieldAtLevel(0)
00290         del medmesh
00291         self.assertEqual(20,m1_0.getNumberOfCells())
00292         self.assertEqual(20,da1.getNumberOfTuples())
00293         pass
00294 
00295     def testMEDMesh6(self):
00296         outFileName="MEDFileMesh5.med"
00297         m=MEDFileCMesh.New()
00298         m.setTime(2.3,-1,-1)
00299         m1=MEDCouplingCMesh.New();
00300         da=DataArrayDouble.New()
00301         da.setValues([0.,1.,2.],3,1)
00302         da.setInfoOnComponent(0,"XX [mm]")
00303         m1.setCoordsAt(0,da)
00304         da=DataArrayDouble.New()
00305         da.setValues([0.,1.2],2,1)
00306         da.setInfoOnComponent(0,"YY [km]")
00307         m1.setCoordsAt(1,da)
00308         da=DataArrayDouble.New()
00309         da.setValues([0.,1.3],2,1)
00310         da.setInfoOnComponent(0,"ZZ [um]")
00311         m1.setCoordsAt(2,da)
00312         m.setMesh(m1)
00313         m.setName("myFirstCartMesh")
00314         m.setDescription("mmmmpppppppp")
00315         m.setTimeValue(2.3)
00316         m.setTimeUnit("ms")
00317         da=DataArrayInt.New()
00318         da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1)
00319         m.setFamilyFieldArr(1,da)
00320         m.setFamilyId("family1",1)
00321         da=m.getFamilyArr(1,"family1")
00322         expected1=[2,4,9]
00323         self.assertEqual(expected1,da.getValues())
00324         m.write(outFileName,2);
00325         mm=MEDFileMesh.New(outFileName)
00326         self.assertTrue(m.isEqual(mm,1e-12)[0])
00327         self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
00328         m2=mm.getMesh()
00329         tt=m.getTime()
00330         m1.setTime(tt[0],tt[1],tt[2])
00331         m1.setName(m.getName())
00332         m1.setTimeUnit(m.getTimeUnit())
00333         m1.setDescription(m.getDescription())
00334         self.assertTrue(m2.isEqual(m1,1e-12));
00335         pass
00336 
00337     def testMEDMesh7(self):
00338         fileName="Pyfile24.med"
00339         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
00340         m=MEDFileUMesh.New()
00341         m.setCoords(m2.getCoords())
00342         m.setMeshAtLevel(0,m2)
00343         m.setMeshAtLevel(-1,m1)
00344         m.setMeshAtLevel(-2,m0)
00345         m.setFamilyFieldArr(0,f2)
00346         m.setFamilyFieldArr(-1,f1)
00347         m.setFamilyFieldArr(-2,f0)
00348         m.setFamilyFieldArr(1,p)
00349         m.setRenumFieldArr(0,n2)
00350         m.setRenumFieldArr(-1,n1)
00351         m.setRenumFieldArr(-2,n0)
00352         nbOfFams=len(fns)
00353         for i in xrange(nbOfFams):
00354             m.addFamily(fns[i],fids[i])
00355             pass
00356         nbOfGrps=len(grpns)
00357         for i in xrange(nbOfGrps):
00358             m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
00359             pass
00360         m.setName(m2.getName())
00361         m.setDescription(m2.getDescription())
00362         #
00363         self.assertEqual((-1,),m.getGrpNonEmptyLevels("A2A4"))
00364         self.assertEqual((),m.getGrpNonEmptyLevels("A1"))
00365         self.assertEqual((-2,),m.getGrpNonEmptyLevels("AP2"))
00366         self.assertEqual((-1,-2),m.getGrpsNonEmptyLevels(["A2A4","AP2"]))
00367         self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________'))
00368         self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________'))
00369         self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________']))
00370         self.assertEqual(('A1A2','A2A4','A3A1','A3C5','A4A3','B1C1','B2B4','B3B1','B4C3','C1C4','C2B2','C3C2','C4B3','C5A4'),m.getGroupsOnSpecifiedLev(-1))
00371         self.assertEqual(('DALLE','DALQ1','DALQ2','DALT3','MESH'),m.getGroupsOnSpecifiedLev(0))
00372         #
00373         m.write(fileName,2)
00374         pass
00375 
00376     #emulation of pointe.med file.
00377     def testMEDField1(self):
00378         mm=MEDFileMesh.New("Pyfile17.med")
00379         mm.write("Pyfile17_bis.med",2)
00380         ff=MEDFileFieldMultiTS.New("Pyfile17.med","MeasureOfMesh_Extruded")
00381         ff.write("Pyfile17_bis.med",0)
00382         pass
00383 
00384     #profiles
00385     def testMEDField2(self):
00386         mm=MEDFileMesh.New("Pyfile19.med")
00387         mm.write("Pyfile19_bis.med",2)
00388         ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes")
00389         ff.write("Pyfile19_bis.med",0)
00390         self.assertEqual([('tyty','mm'),('uiop','MW')],MEDLoader.GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes"))
00391         pass
00392 
00393     #gauss points
00394     def testMEDField3(self):
00395         mm=MEDFileMesh.New("Pyfile13.med")
00396         mm.write("Pyfile13_bis.med",2)
00397         ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
00398         ff.write("Pyfile13_bis.med",0)
00399         ff=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint",1,5)
00400         f=ff.getFieldAtLevel(ON_GAUSS_PT,0)
00401         f2=MEDLoader.ReadFieldGauss("Pyfile13.med",'2DMesh_2',0,'MyFirstFieldOnGaussPoint',1,5)
00402         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00403         pass
00404 
00405     #gauss NE
00406     def testMEDField4(self):
00407         mm=MEDFileMesh.New("Pyfile14.med")
00408         mm.write("Pyfile14_bis.med",2)
00409         ff=MEDFileFieldMultiTS.New("Pyfile14.med","MyFieldOnGaussNE")
00410         ff.write("Pyfile14_bis.med",0)
00411         ff=MEDFileField1TS.New("Pyfile14.med","MyFieldOnGaussNE",1,5)
00412         f=ff.getFieldAtLevel(ON_GAUSS_NE,0)
00413         f2=MEDLoader.ReadFieldGaussNE("Pyfile14.med",'2DMesh_2',0,"MyFieldOnGaussNE",1,5)
00414         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00415         pass
00416 
00417     # MEDField get/set on pointe.med
00418     def testMEDField5(self):
00419         ff=MEDFileField1TS.New("Pyfile17.med","MeasureOfMesh_Extruded",1,2)
00420         f=ff.getFieldAtLevel(ON_CELLS,0)
00421         f2=MEDLoader.ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
00422         self.assertTrue(f.getMesh().getCoords().isEqual(f2.getMesh().getCoords(),1e-12))
00423         f.getMesh().tryToShareSameCoords(f2.getMesh(),1e-12)
00424         f.changeUnderlyingMesh(f2.getMesh(),22,1e-12)
00425         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00426         # no with renumbering
00427         f=ff.getFieldAtLevel(ON_CELLS,0,1)
00428         f2=MEDLoader.ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
00429         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00430         f=ff.getFieldAtLevel(ON_CELLS,0,3)
00431         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00432         f=ff.getFieldAtLevel(ON_CELLS,0,2)
00433         self.assertTrue(not f.isEqual(f2,1e-12,1e-12))
00434         f.changeUnderlyingMesh(f2.getMesh(),12,1e-12)
00435         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00436         pass
00437 
00438     # MEDField get/set on profiles nodes
00439     def testMEDField6(self):
00440         ff=MEDFileFieldMultiTS.New("Pyfile7.med","VectorFieldOnNodes")
00441         its=ff.getIterations()
00442         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
00443         f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
00444         f2=MEDLoader.ReadFieldNode("Pyfile7.med",'3DSurfMesh_1',0,"VectorFieldOnNodes",its[0][0],its[0][1])
00445         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00446         ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes")
00447         its=ff.getIterations()
00448         f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
00449         f2=MEDLoader.ReadFieldNode("Pyfile19.med",'2DMesh_1',0,"VFieldOnNodes",its[0][0],its[0][1])
00450         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00451         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
00452         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_NODES,its[0][0],its[0][1],0,1)#request renumber following mesh : it is on profile !
00453         pass
00454 
00455     # MEDField get/set on profiles cells
00456     def testMEDField7(self):
00457         ff=MEDFileFieldMultiTS.New("Pyfile12.med","VectorFieldOnCells")
00458         its=ff.getIterations()
00459         f=ff.getFieldAtLevel(ON_CELLS,its[0][0],its[0][1],0)
00460         f2=MEDLoader.ReadFieldCell("Pyfile12.med",'3DMesh_1',0,"VectorFieldOnCells",its[0][0],its[0][1])
00461         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
00462         pass
00463 
00464     #first test of assignation. No profile and types sorted by type.
00465     def testMEDField8(self):
00466         fname="Pyfile25.med"
00467         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00468         m1=f1.getMesh()
00469         mm1=MEDFileUMesh.New()
00470         mm1.setCoords(m1.getCoords())
00471         mm1.setMeshAtLevel(0,m1)
00472         mm1.setName(m1.getName())
00473         mm1.write(fname,2)
00474         ff1=MEDFileField1TS.New()
00475         ff1.setFieldNoProfileSBT(f1)
00476         ff1.write(fname,0)
00477         f2=MEDLoader.ReadFieldCell(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]);
00478         ti,itt,orr=ff1.getTime()
00479         self.assertEqual(0,itt); self.assertEqual(1,orr); self.assertAlmostEqual(2.,ti,14);
00480         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
00481         ff1.setTime(2.3,3,4)
00482         ti,itt,orr=ff1.getTime()
00483         self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14);
00484         da,infos=ff1.getUndergroundDataArrayExt()
00485         f2.getArray().setName(da.getName())#da has the same name than f2
00486         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
00487         self.assertEqual([((3, 0), (0, 2)), ((4, 0), (2, 4)), ((6, 0), (4, 5)), ((5, 0), (5, 6))],infos)
00488         #
00489         fname="Pyfile26.med"
00490         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
00491         m1=f1.getMesh()
00492         mm1=MEDFileUMesh.New()
00493         mm1.setCoords(m1.getCoords())
00494         mm1.setMeshAtLevel(0,m1)
00495         mm1.setName(m1.getName())
00496         mm1.write(fname,2)
00497         ff1=MEDFileField1TS.New()
00498         ff1.setFieldNoProfileSBT(f1)
00499         nv=1456.
00500         da=ff1.getUndergroundDataArray().setIJ(0,0,nv)
00501         ff1.write(fname,0)
00502         f2=MEDLoader.ReadFieldNode(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
00503         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12))
00504         f1.getArray().setIJ(0,0,nv)
00505         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
00506         #
00507         fname="Pyfile27.med"
00508         f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
00509         m1=f1.getMesh()
00510         mm1=MEDFileUMesh.New()
00511         mm1.setCoords(m1.getCoords())
00512         mm1.setMeshAtLevel(0,m1)
00513         mm1.setName(m1.getName())
00514         mm1.write(fname,2)
00515         ff1=MEDFileField1TS.New()
00516         ff1.setFieldNoProfileSBT(f1)
00517         ff1.write(fname,0)
00518         f2=MEDLoader.ReadFieldGaussNE(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
00519         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
00520         da,infos=ff1.getUndergroundDataArrayExt()
00521         f2.getArray().setName(da.getName())#da has the same name than f2
00522         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
00523         self.assertEqual([((3, 0), (0, 6)), ((4, 0), (6, 14)), ((6, 0), (14, 20))],infos)
00524         #
00525         fname="Pyfile28.med"
00526         f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler();
00527         m1=f1.getMesh()
00528         mm1=MEDFileUMesh.New()
00529         mm1.setCoords(m1.getCoords())
00530         mm1.setMeshAtLevel(0,m1)
00531         mm1.setName(m1.getName())
00532         mm1.write(fname,2)
00533         ff1=MEDFileField1TS.New()
00534         ff1.setFieldNoProfileSBT(f1)
00535         ff1.write(fname,0)
00536         ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2])
00537         f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0)
00538         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
00539         sbt=ff2.getFieldSplitedByType2()
00540         loc1=ff2.getLocalization("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5")
00541         self.assertEqual("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5",loc1.getName())
00542         self.assertEqual((-1, 1,-1,-1,1,-1,-1,0,0,-1,0,0),loc1.getRefCoords())
00543         self.assertEqual(6,loc1.getNumberOfPointsInCells())
00544         self.assertEqual(3,loc1.getNumberOfGaussPoints())
00545         self.assertEqual(2,loc1.getDimension())
00546         da,infos=ff2.getUndergroundDataArrayExt()
00547         f2.getArray().setName(da.getName())#da has the same name than f2
00548         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
00549         self.assertEqual(53,da.getNumberOfTuples())
00550         self.assertEqual([((3, 0), (0, 18)), ((3, 1), (18, 30)), ((3, 2), (30, 36)), ((4, 0), (36, 42)), ((4, 1), (42, 44)), ((6, 0), (44, 53))],infos)
00551         #
00552         pass
00553     
00554     def testMEDFileData1(self):
00555         fname="Pyfile29.med"
00556         d=MEDFileData.New()
00557         #
00558         m1=MEDLoaderDataForTest.build1DMesh_1()
00559         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
00560         mmm1=MEDFileMeshMultiTS.New() ;
00561         mmm1.setOneTimeStep(mm1)
00562         m2=MEDLoaderDataForTest.build2DCurveMesh_1()
00563         mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName())
00564         mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2)
00565         ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2)
00566         d.setMeshes(ms)
00567         self.assertEqual(('1DMesh_1', '2DCurveMesh_1'),d.getMeshes().getMeshesNames())
00568         #
00569         ff1=MEDFileFieldMultiTS.New()
00570         ff21=MEDFileFieldMultiTS.New()
00571         ff22=MEDFileFieldMultiTS.New()
00572         f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False)
00573         f1.getArray().setInfoOnComponent(0,"power [kW]")
00574         ff1.appendFieldNoProfileSBT(f1)
00575         f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False)
00576         f21.getArray().setInfoOnComponent(0,"sta [mm]") ;
00577         ff21.appendFieldNoProfileSBT(f21)
00578         f22=f21.deepCpy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ;
00579         f22.applyFunc(2,"3*x*IVec+2*x*JVec")
00580         f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]")
00581         ff22.appendFieldNoProfileSBT(f22)
00582         fs=MEDFileFields.New()
00583         fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22)
00584         d.setFields(fs)
00585         #
00586         fname2="Pyfile29_2.med"
00587         d.write(fname2,2)
00588         #
00589         d2=MEDFileData.New(fname2)
00590         self.assertEqual(2,d2.getNumberOfMeshes())
00591         self.assertEqual(3,d2.getNumberOfFields())
00592         self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))
00593         m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
00594         self.assertTrue(m1.isEqual(m1bis,1e-12))
00595         self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
00596         self.assertEqual([(-1, -1, 0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
00597         self.assertEqual([(-1, -1, 0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
00598         pass
00599     
00600     def testMEDField9(self):
00601         # first test field profile WR. Full type but with some type missing
00602         fname="Pyfile30.med"
00603         m1=MEDLoaderDataForTest.build2DMesh_3()
00604         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
00605         mm1.write(fname,2)
00606         ff1=MEDFileField1TS.New()
00607         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1")
00608         d=DataArrayDouble.New() ; d.alloc(2*9,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00609         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00610         da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1")
00611         #
00612         ff1.setFieldProfile(f1,mm1,0,da)
00613         ff1.changePflsNames([(["sup1_NORM_QUAD4"],"ForV650")])
00614         ff1.write(fname,0)
00615         #
00616         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
00617         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))# profiles names cannot be contracted in pfl array name
00618         self.assertTrue(vals.isEqual(d,1e-14))
00619         #
00620         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
00621         sbt=ff2.getFieldSplitedByType2()
00622         self.assertEqual(3,sbt[0][0])#TRI3
00623         self.assertEqual(0,sbt[0][1][0][0])#CELL For TRI3
00624         self.assertEqual("",sbt[0][1][0][2])#no profile For TRI3
00625         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],sbt[0][1][0][1].getValues())# values for TRI3
00626         self.assertEqual(4,sbt[1][0])#QUAD4
00627         self.assertEqual(0,sbt[1][1][0][0])#CELL For QUAD4
00628         self.assertEqual("ForV650",sbt[1][1][0][2])# profile For QUAD4
00629         self.assertEqual([19, 20, 21, 22, 23, 24],sbt[1][1][0][1].getValues())# values for QUAD4
00630         self.assertEqual([0],ff2.getTypesOfFieldAvailable())
00631         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
00632         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00633         self.assertTrue(vals.isEqual(d,1e-14))
00634         pass
00635     
00636     def testMEDField10(self):
00637         fname="Pyfile31.med"
00638         m1=MEDLoaderDataForTest.build2DMesh_1()
00639         m1.renumberCells([0,1,4,2,3,5],False)
00640         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
00641         mm1.write(fname,2)
00642         ff1=MEDFileFieldMultiTS.New()
00643         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
00644         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00645         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00646         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
00647         #
00648         ff1.appendFieldProfile(f1,mm1,0,da)
00649         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
00650         ff1.appendFieldProfile(f1,mm1,0,da)
00651         ff1.write(fname,0)
00652         #
00653         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
00654         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00655         self.assertTrue(vals.isEqual(e,1e-14))
00656         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
00657         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00658         self.assertTrue(vals.isEqual(d,1e-14))
00659         #
00660         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
00661         self.assertEqual([(-1, -1, 0.0), (1, 2, 1.2)],ff2.getTimeSteps())
00662         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
00663         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00664         self.assertTrue(vals.isEqual(e,1e-14))
00665         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
00666         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00667         self.assertTrue(vals.isEqual(d,1e-14))
00668         pass
00669     
00670     # idem testMEDField9 method except that here testing profile on nodes and not on cells.
00671     def testMEDField11(self):
00672         fname="Pyfile32.med"
00673         m1=MEDLoaderDataForTest.build2DMesh_1()
00674         m1.renumberCells([0,1,4,2,3,5],False)
00675         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
00676         mm1.write(fname,2)
00677         ff1=MEDFileField1TS.New()
00678         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
00679         d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00680         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00681         da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
00682         #
00683         ff1.setFieldProfile(f1,mm1,0,da)
00684         self.assertEqual(ff1.getNonEmptyLevels(),(-1, []))
00685         ff1.write(fname,0)
00686         #
00687         vals,pfl=ff1.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
00688         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00689         self.assertTrue(vals.isEqual(d,1e-14))
00690         ## #
00691         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
00692         vals,pfl=ff2.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
00693         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00694         self.assertTrue(vals.isEqual(d,1e-14))
00695         pass
00696 
00697     def testMEDField12(self):
00698         fname="Pyfile33.med"
00699         m1=MEDLoaderDataForTest.build2DMesh_1()
00700         m1.renumberCells([0,1,4,2,3,5],False)
00701         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
00702         mm1.write(fname,2)
00703         ff1=MEDFileFieldMultiTS.New()
00704         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
00705         d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00706         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00707         da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
00708         #
00709         ff1.appendFieldProfile(f1,mm1,0,da)
00710         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
00711         ff1.appendFieldProfile(f1,mm1,0,da)
00712         ff1.write(fname,0)
00713         #
00714         vals,pfl=ff1.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
00715         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00716         self.assertTrue(vals.isEqual(e,1e-14))
00717         vals,pfl=ff1.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
00718         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00719         self.assertTrue(vals.isEqual(d,1e-14))
00720         #
00721         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
00722         vals,pfl=ff2.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
00723         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00724         self.assertTrue(vals.isEqual(e,1e-14))
00725         vals,pfl=ff2.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
00726         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00727         self.assertTrue(vals.isEqual(d,1e-14))
00728         pass
00729 
00730     def testMEDField13(self):
00731         fname="Pyfile34.med"
00732         m1=MEDLoaderDataForTest.build2DMesh_1()
00733         m1.renumberCells([0,1,4,2,3,5],False)
00734         tmp=m1.getName();
00735         m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
00736         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
00737         mm1.write(fname,2)
00738         ff1=MEDFileField1TS.New()
00739         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F3Node")
00740         d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00741         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00742         da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
00743         #
00744         ff1.setFieldProfile(f1,mm1,0,da)
00745         ff1.write(fname,0)
00746         #
00747         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
00748         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00749         self.assertTrue(vals.isEqual(d,1e-14))
00750         #
00751         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
00752         vals,pfl=ff2.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
00753         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00754         self.assertTrue(vals.isEqual(d,1e-14))
00755         pass
00756 
00757     def testMEDField14(self):
00758         fname="Pyfile35.med"
00759         m1=MEDLoaderDataForTest.build2DMesh_1()
00760         m1.renumberCells([0,1,4,2,3,5],False)
00761         tmp=m1.getName();
00762         m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
00763         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
00764         mm1.write(fname,2)
00765         ff1=MEDFileFieldMultiTS.New()
00766         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
00767         d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00768         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00769         da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
00770         #
00771         ff1.appendFieldProfile(f1,mm1,0,da)
00772         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
00773         ff1.appendFieldProfile(f1,mm1,0,da)
00774         ff1.write(fname,0)
00775         #
00776         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
00777         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00778         self.assertTrue(vals.isEqual(d,1e-14))
00779         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
00780         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00781         self.assertTrue(vals.isEqual(e,1e-14))
00782         self.assertEqual([[3],[3]],ff1.getTypesOfFieldAvailable())
00783         #
00784         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
00785         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
00786         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00787         self.assertTrue(vals.isEqual(d,1e-14))
00788         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
00789         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
00790         self.assertTrue(vals.isEqual(e,1e-14))
00791         pass
00792     # Tricky test of the case of in a MED file containing a Field on GAUSS_NE is lying on a profile that is reality represents all the geom entities of a level.
00793     # By default when using setFieldProfile method such profile is not created because it is not useful ! So here a trick is used to force MEDLoader to do that
00794     # for the necessity of the test ! The idea is too create artificially a mesh having one more fictious cell per type and to roll back right after !
00795     def testMEDField15(self):
00796         fname="Pyfile36.med"
00797         m0=MEDLoaderDataForTest.build2DMesh_1()
00798         m0.renumberCells([0,1,4,2,3,5],False)
00799         tmp=m0.getName();
00800         m1=m0.buildPartOfMySelf([0,1,1,2,3,3,4,4],True) ; m1.setName(tmp) # suppression of last cell that is a polygon and creation of one more cell per type
00801         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
00802         ff1=MEDFileField1TS.New()
00803         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
00804         d=DataArrayDouble.New() ; d.alloc(2*20,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00805         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00806         da=DataArrayInt.New(); da.setValues([0,1,3,4,6],5,1) ; da.setName("sup1NodeElt")
00807         #
00808         ff1.setFieldProfile(f1,mm1,0,da)
00809         m1=m0.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
00810         mm1.write(fname,2)
00811         ff1.write(fname,0)
00812         f1=ff1.getFieldOnMeshAtLevel(ON_GAUSS_NE,m1,0)
00813         f2,p1=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; f2.setName("")
00814         self.assertTrue(p1.isIdentity())
00815         self.assertEqual(5,p1.getNumberOfTuples())
00816         self.assertTrue(f1.getArray().isEqual(f2,1e-12))
00817         pass
00818     # Test for getFieldAtTopLevel method
00819     def testMEDField16(self):
00820         fname="Pyfile37.med"
00821         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00822         m1=f1.getMesh()
00823         mm1=MEDFileUMesh.New()
00824         mm1.setCoords(m1.getCoords())
00825         mm1.setMeshAtLevel(0,m1)
00826         mm1.setName(m1.getName())
00827         ff1=MEDFileField1TS.New()
00828         ff1.setFieldNoProfileSBT(f1)
00829         m2=m1.buildDescendingConnectivity()[0]
00830         m2.sortCellsInMEDFileFrmt()
00831         m2.setName(m1.getName())
00832         mm1.setMeshAtLevel(-1,m2)
00833         mm1.write(fname,2)
00834         f2=m2.getMeasureField(True)
00835         dd=DataArrayDouble.New()
00836         dd.alloc(f2.getArray().getNumberOfTuples(),3)
00837         dd[:,0]=f2.getArray()
00838         dd[:,1]=2*f2.getArray()
00839         dd[:,2]=3*f2.getArray()
00840         f2=f2.buildNewTimeReprFromThis(ONE_TIME,False)
00841         f2.setArray(dd)
00842         f2.copyTinyStringsFrom(f1)
00843         f2.copyTinyAttrFrom(f1)
00844         ff1.setFieldNoProfileSBT(f2)
00845         ff1.write(fname,0)
00846         # Reading Pyfile37.med
00847         ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
00848         f1bis=ff2.getFieldAtLevel(ON_CELLS,0)
00849         self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
00850         f1bis=ff2.getFieldAtLevel(ON_CELLS,-1)
00851         self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
00852         f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
00853         self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
00854         # More complex
00855         fname="Pyfile38.med"
00856         mm1.write(fname,2)
00857         ff1=MEDFileField1TS.New()
00858         ff1.setFieldNoProfileSBT(f2)
00859         ff1.write(fname,0)
00860         ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
00861         f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
00862         self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
00863         pass
00864 
00865     # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
00866     def testMEDField17(self):
00867         fname="Pyfile39.med"
00868         m1=MEDLoaderDataForTest.build2DMesh_1()
00869         m1.renumberCells([0,1,4,2,3,5],False)
00870         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
00871         mm1.write(fname,2)
00872         ffs=MEDFileFields.New()
00873         ff1=MEDFileFieldMultiTS.New()
00874         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
00875         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00876         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00877         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
00878         #
00879         ff1.appendFieldProfile(f1,mm1,0,da)
00880         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
00881         ff1.appendFieldProfile(f1,mm1,0,da)
00882         ffs.resize(1)
00883         ffs.setFieldAtPos(0,ff1)
00884         ffs.write(fname,0)
00885         #
00886         ffsr=MEDFileFields.New(fname)
00887         ff3=ffsr.getFieldAtPos(0)
00888         f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
00889         self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
00890         pass
00891 
00892     # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
00893     def testMEDField18(self):
00894         fname="Pyfile40.med"
00895         m1=MEDLoaderDataForTest.build2DMesh_1()
00896         m1.renumberCells([0,1,4,2,3,5],False)
00897         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
00898         mm1.write(fname,2)
00899         ffs=MEDFileFields.New()
00900         ff1=MEDFileFieldMultiTS.New()
00901         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
00902         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
00903         f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
00904         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
00905         #
00906         ff1.appendFieldProfile(f1,mm1,0,da)
00907         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
00908         ff1.appendFieldProfile(f1,mm1,0,da)
00909         ffs.pushField(ff1)
00910         ffs.write(fname,0)
00911         #
00912         ffsr=MEDFileFields.New(fname)
00913         ff3=ffsr.getFieldAtPos(0)
00914         f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
00915         self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
00916         pass
00917 
00918     def testMEDFieldBug1(self):
00919         fname="Pyfile13.med"
00920         d=MEDFileData.New(fname)
00921         self.assertEqual(('GP_MyFirstFieldOnGaussPoint0', 'GP_MyFirstFieldOnGaussPoint1', 'GP_MyFirstFieldOnGaussPoint2'),d.getFields().getFieldAtPos(0).getLocs())
00922         pass
00923 
00924     def testMEDMesh8(self):
00925         m=MEDLoaderDataForTest.build1DMesh_1()
00926         m.convertQuadraticCellsToLinear()
00927         mm=MEDFileUMesh.New()
00928         mm.setMeshAtLevel(0,m)
00929         g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1")
00930         g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2")
00931         g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3")
00932         mm.setGroupsAtLevel(0,[g1,g2],False)
00933         self.assertEqual(('g1','g2'),mm.getGroupsNames())
00934         self.assertEqual(('Family_2','Family_3'),mm.getFamiliesNames())
00935         self.assertEqual(('Family_2',),mm.getFamiliesOnGroup('g1'))
00936         self.assertEqual(('Family_3',),mm.getFamiliesOnGroup('g2'))
00937         mm.assignFamilyNameWithGroupName()
00938         self.assertEqual(('g1','g2'),mm.getGroupsNames())
00939         self.assertEqual(('g1','g2'),mm.getFamiliesNames())
00940         self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1'))
00941         self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2'))
00942         #
00943         mm=MEDFileUMesh.New()
00944         mm.setMeshAtLevel(0,m)
00945         mm.setGroupsAtLevel(0,[g1,g2,g3],False)
00946         self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
00947         self.assertEqual(('Family_2', 'Family_4', 'Family_5'),mm.getFamiliesNames())
00948         self.assertEqual(('Family_2', 'Family_4'),mm.getFamiliesOnGroup('g1'))
00949         self.assertEqual(('Family_5',),mm.getFamiliesOnGroup('g2'))
00950         self.assertEqual(('Family_4','Family_5',),mm.getFamiliesOnGroup('g3'))
00951         mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found
00952         self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
00953         self.assertEqual(('Family_2', 'Family_4', 'Family_5'),mm.getFamiliesNames())
00954         self.assertEqual(('Family_2', 'Family_4'),mm.getFamiliesOnGroup('g1'))
00955         self.assertEqual(('Family_5',),mm.getFamiliesOnGroup('g2'))
00956         self.assertEqual(('Family_4','Family_5',),mm.getFamiliesOnGroup('g3'))
00957         mm.changeFamilyId(5,6)
00958         g=mm.getGroupArr(0,"g3")
00959         self.assertTrue(g.isEqual(g3));
00960         g=mm.getGroupArr(0,"g2")
00961         self.assertTrue(g.isEqual(g2));
00962         g=mm.getGroupArr(0,"g1")
00963         self.assertTrue(g.isEqual(g1));
00964         pass
00965     
00966     # bug detected by gauthier
00967     def testMEDLoaderMEDLoaderNSReadFieldDoubleDataInMedFile(self):
00968         fname="Pyfile41.med"
00969         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
00970         m1=f1.getMesh()
00971         mm1=MEDFileUMesh.New()
00972         mm1.setCoords(m1.getCoords())
00973         mm1.setMeshAtLevel(0,m1)
00974         mm1.write(fname,2)
00975         ff1=MEDFileField1TS.New()
00976         ff1.setFieldNoProfileSBT(f1)
00977         ff1.write(fname,0)
00978         # writing mesh1 and field1, now creation of mesh2 and field2
00979         f2=f1.deepCpy()
00980         m2=f2.getMesh()
00981         m2.translate([0.5,0.6,0.7])
00982         m2.setName("3DSurfMesh_2")
00983         f2.getArray()[:]*=2.
00984         f2.setName("VectorFieldOnCells2")
00985         mm2=MEDFileUMesh.New()
00986         mm2.setCoords(m2.getCoords())
00987         mm2.setMeshAtLevel(0,m2)
00988         mm2.write(fname,0)
00989         ff2=MEDFileField1TS.New()
00990         ff2.setFieldNoProfileSBT(f2)
00991         ff2.write(fname,0)
00992         #
00993         f3=MEDLoader.ReadFieldCell(fname,"3DSurfMesh_1",0,"VectorFieldOnCells",0,1)
00994         self.assertTrue(f3.isEqual(f1,1e-12,1e-12))
00995         f4=MEDLoader.ReadFieldCell(fname,"3DSurfMesh_2",0,"VectorFieldOnCells2",0,1)
00996         self.assertTrue(f4.isEqual(f2,1e-12,1e-12))
00997         pass
00998 
00999     def testMEDLoaderMultiLevelCellField1(self):
01000         fname="Pyfile42.med"
01001         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
01002         m=MEDFileUMesh.New()
01003         m.setCoords(m2.getCoords())
01004         m.setMeshAtLevel(0,m2)
01005         m.setMeshAtLevel(-1,m1)
01006         m.setMeshAtLevel(-2,m0)
01007         m.write(fname,2)
01008         #
01009         FieldName1="Field1"
01010         compNames1=["comp1","comp2","comp3"]
01011         ff1=MEDFileField1TS.New()
01012         da2=DataArrayDouble.New()
01013         da2.alloc(m2.getNumberOfCells()*len(compNames1),1)
01014         da2.iota(7.)
01015         da2.rearrange(len(compNames1))
01016         da2.setInfoOnComponents(compNames1)
01017         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f2.setName(FieldName1) ; f2.setArray(da2) ; f2.setMesh(m2) ; f2.checkCoherency()
01018         ff1.setFieldNoProfileSBT(f2)
01019         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0]))
01020         da0=DataArrayDouble.New()
01021         da0.alloc(m0.getNumberOfCells()*len(compNames1),1)
01022         da0.iota(190.)
01023         da0.rearrange(len(compNames1))
01024         da0.setInfoOnComponents(compNames1)
01025         f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName1) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkCoherency()
01026         ff1.setFieldNoProfileSBT(f0)
01027         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-2]))
01028         da1=DataArrayDouble.New()
01029         da1.alloc(m1.getNumberOfCells()*len(compNames1),1)
01030         da1.iota(90.)
01031         da1.rearrange(len(compNames1))
01032         da1.setInfoOnComponents(compNames1)
01033         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName1) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkCoherency()
01034         ff1.setFieldNoProfileSBT(f1)
01035         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
01036         #
01037         ff1.write(fname,0)
01038         #
01039         FieldName2="Field2"
01040         compNames2=["comp11","comp22"]
01041         ff2=MEDFileField1TS.New()
01042         da0=DataArrayDouble.New()
01043         da0.alloc(m0.getNumberOfCells()*2,1)
01044         da0.iota(-190.)
01045         da0.rearrange(2)
01046         da0.setInfoOnComponents(compNames2)
01047         f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName2) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkCoherency()
01048         ff2.setFieldNoProfileSBT(f0)
01049         self.assertEqual(ff2.getNonEmptyLevels(),(0, [0]))
01050         da1=DataArrayDouble.New()
01051         da1.alloc(m1.getNumberOfCells()*len(compNames2),1)
01052         da1.iota(-90.)
01053         da1.rearrange(len(compNames2))
01054         da1.setInfoOnComponents(compNames2)
01055         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName2) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkCoherency()
01056         ff2.setFieldNoProfileSBT(f1)
01057         self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
01058         #
01059         ff2.write(fname,0)
01060         #
01061         ff1=MEDFileField1TS.New(fname,FieldName1,-1,-1)
01062         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
01063         self.assertEqual(ff1.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')]), (3, [(0, (84, 148), '', '')]), (4, [(0, (148, 212), '', '')])])
01064         ff2=MEDFileField1TS.New(fname,FieldName2,-1,-1)
01065         self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
01066         self.assertEqual(ff2.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')])])
01067         pass
01068 
01069     def testFieldOnPflRetrieveOnMdimRelMax1(self):
01070         fname="Pyfile43.med"
01071         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
01072         m=MEDFileUMesh.New()
01073         m.setMeshAtLevel(0,m2)
01074         m.setMeshAtLevel(-1,m1)
01075         m.setMeshAtLevel(-2,m0)
01076         f=MEDFileField1TS.New()
01077         ff=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
01078         ff.setName("NodeFieldPfl")
01079         arr=DataArrayDouble.New() ; arr.setValues([1.,10.,100.,2.,20.,200.],2,3)
01080         ff.setArray(arr)
01081         pfl=DataArrayInt.New() ; pfl.setValues([2,3],2,1) ; pfl.setName("PflNode")
01082         f.setFieldProfile(ff,m,-2,pfl)
01083         tes0=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
01084         self.assertEqual(ON_NODES,tes0.getTypeOfField())
01085         self.assertEqual(1,tes0.getMesh().getMeshDimension())
01086         self.assertEqual(1,tes0.getMesh().getNumberOfCells())
01087         self.assertEqual(2,tes0.getMesh().getNumberOfNodes())
01088         self.assertEqual([1,0,1],tes0.getMesh().getNodalConnectivity().getValues())
01089         self.assertEqual([0,3],tes0.getMesh().getNodalConnectivityIndex().getValues())
01090         self.assertEqual(2,tes0.getArray().getNumberOfTuples())
01091         self.assertEqual(3,tes0.getArray().getNumberOfComponents())
01092         expected1=[1.,10.,100.,2.,20.,200.]
01093         nodeCoordsWithValue1=[10.,2.5,0.]
01094         nodeCoordsWithValue2=[10.,3.75,0.]
01095         for i in xrange(3):
01096             self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
01097             self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
01098             pass
01099         for i in xrange(6):
01100             self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
01101             pass
01102         del tes0
01103         #
01104         tes1=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
01105         self.assertEqual(ON_CELLS,tes1.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
01106         self.assertEqual(0,tes1.getMesh().getMeshDimension())
01107         self.assertEqual(2,tes1.getMesh().getNumberOfCells())
01108         self.assertEqual(135,tes1.getMesh().getNumberOfNodes())
01109         self.assertEqual([0,2,0,3],tes1.getMesh().getNodalConnectivity().getValues())
01110         self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
01111         self.assertEqual(2,tes1.getArray().getNumberOfTuples())
01112         self.assertEqual(3,tes1.getArray().getNumberOfComponents())
01113         for i in xrange(6):
01114             self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
01115             pass
01116         m.write(fname,2)
01117         f.write(fname,0)
01118         #
01119         pfl=DataArrayInt.New() ; pfl.setValues([3,2],2,1) ; pfl.setName("PflNode")
01120         f=MEDFileField1TS.New()
01121         f.setFieldProfile(ff,m,-2,pfl)
01122         tes2=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
01123         self.assertEqual(ON_NODES,tes2.getTypeOfField())
01124         self.assertEqual(1,tes2.getMesh().getMeshDimension())
01125         self.assertEqual(1,tes2.getMesh().getNumberOfCells())
01126         self.assertEqual(2,tes2.getMesh().getNumberOfNodes())
01127         self.assertEqual([1,0,1],tes2.getMesh().getNodalConnectivity().getValues())
01128         self.assertEqual([0,3],tes2.getMesh().getNodalConnectivityIndex().getValues())
01129         self.assertEqual(2,tes2.getArray().getNumberOfTuples())
01130         self.assertEqual(3,tes2.getArray().getNumberOfComponents())
01131         expected2=[2.,20.,200.,1.,10.,100.]
01132         for i in xrange(3):
01133             self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
01134             self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
01135             pass
01136         for i in xrange(6):
01137             self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
01138             pass
01139         #
01140         tes3=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
01141         self.assertEqual(ON_CELLS,tes3.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
01142         self.assertEqual(0,tes3.getMesh().getMeshDimension())
01143         self.assertEqual(2,tes3.getMesh().getNumberOfCells())
01144         self.assertEqual(135,tes3.getMesh().getNumberOfNodes())
01145         self.assertEqual([0,3,0,2],tes3.getMesh().getNodalConnectivity().getValues())
01146         self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
01147         self.assertEqual(2,tes3.getArray().getNumberOfTuples())
01148         self.assertEqual(3,tes3.getArray().getNumberOfComponents())
01149         for i in xrange(6):
01150             self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
01151             pass
01152         pass
01153     pass
01154 
01155 unittest.main()