]> SALOME platform Git repositories - modules/med.git/blob - src/MEDLoader/Swig/MEDLoaderTest3.py
Salome HOME
Correction of bug EDF10723 for 0D mesh.
[modules/med.git] / src / MEDLoader / Swig / MEDLoaderTest3.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015  CEA/DEN, EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author : Anthony Geay (CEA/DEN)
21
22 from MEDLoader import *
23 import unittest
24 import platform
25 from math import pi,e,sqrt
26 from MEDLoaderDataForTest import MEDLoaderDataForTest
27
28 class MEDLoaderTest(unittest.TestCase):
29     def testMEDMesh1(self):
30         fileName="Pyfile18.med"
31         mname="ExampleOfMultiDimW"
32         medmesh=MEDFileMesh.New(fileName,mname)
33         self.assertRaises(InterpKernelException,MEDFileMesh.New,fileName,"")
34         self.assertEqual((0,-1),medmesh.getNonEmptyLevels())
35         m1_0=medmesh.getLevel0Mesh(True)
36         m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
37         self.assertTrue(m1_0.isEqual(m1_1,1e-12));
38         m2_0=medmesh.getLevelM1Mesh(True)
39         m2_1=MEDLoader.ReadUMeshFromFile(fileName,mname,-1)
40         self.assertTrue(m2_0.isEqual(m2_1,1e-12));
41         pass
42
43     def testMEDMesh2(self):
44         fileName="Pyfile10.med"
45         mname="3DToto"
46         outFileName="MEDFileMesh1.med"
47         medmesh=MEDFileUMesh.New(fileName,mname)
48         self.assertEqual((0,),medmesh.getNonEmptyLevels())
49         m1_0=medmesh.getLevel0Mesh(True)
50         m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
51         self.assertTrue(m1_0.isEqual(m1_1,1e-12));
52         g1_0=medmesh.getGroup(0,"mesh2",True)
53         g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh2"]);
54         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
55         g1_0=medmesh.getGroup(0,"mesh3",True)
56         g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3"]);
57         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
58         g1_0=medmesh.getGroups(0,["mesh3","mesh2"])
59         g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]);
60         g1_1.setName(g1_0.getName())
61         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
62         g1_0=medmesh.getFamily(0,"Family_-3",True)
63         g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_-3"]);
64         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
65         g1_0=medmesh.getFamilies(0,["Family_-3","Family_-5"],True)
66         g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_-3","Family_-5"]);
67         g1_1.setName(g1_0.getName())
68         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
69         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
70         medmesh.write(outFileName,2);
71         self.assertEqual([1,2,4,13,15],medmesh.getGroupArr(0,"mesh2",True).getValues());
72         self.assertEqual([1,2,15],medmesh.getFamilyArr(0,"Family_-3",True).getValues());
73         self.assertEqual([1,2,4,13,15],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"],True).getValues());
74         self.assertEqual([18,1,2,3,4,13,14,15],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
75         famn=medmesh.getFamilyNameGivenId(0)
76         self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True);
77         #without renum
78         self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues());
79         self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_-3").getValues());
80         self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"]).getValues());
81         self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
82         self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False);
83         pass
84
85     # this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account
86     def testMEDMesh3(self):
87         outFileName="MEDFileMesh3.med"
88         c=DataArrayDouble.New()
89         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 ];
90         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
91         c.setValues(coords,9,2)
92         m=MEDCouplingUMesh.New();
93         m.setMeshDimension(2);
94         m.allocateCells(5);
95         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
96         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
97         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
98         m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
99         m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
100         m.finishInsertingCells();
101         m.setCoords(c)
102         m.checkCoherency()
103         m1=MEDCouplingUMesh.New();
104         m1.setMeshDimension(1);
105         m1.allocateCells(3);
106         m1.insertNextCell(NORM_SEG2,2,[1,4])
107         m1.insertNextCell(NORM_SEG2,2,[3,6])
108         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
109         m1.finishInsertingCells();
110         m1.setCoords(c)
111         m1.checkCoherency()
112         m2=MEDCouplingUMesh.New();
113         m2.setMeshDimension(0);
114         m2.allocateCells(4);
115         m2.insertNextCell(NORM_POINT1,1,[1])
116         m2.insertNextCell(NORM_POINT1,1,[3])
117         m2.insertNextCell(NORM_POINT1,1,[2])
118         m2.insertNextCell(NORM_POINT1,1,[6])
119         m2.finishInsertingCells();
120         m2.setCoords(c)
121         m2.checkCoherency()
122         #
123         mm=MEDFileUMesh.New()
124         self.assertTrue(mm.getUnivNameWrStatus())
125         mm.setName("MyFirstMEDCouplingMEDmesh")
126         mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
127         mm.setCoords(c)
128         mm.setMeshAtLevel(-1,m1);
129         mm.setMeshAtLevel(0,m);
130         mm.setMeshAtLevel(-2,m2);
131         # playing with groups
132         g1_2=DataArrayInt.New()
133         g1_2.setValues([1,3],2,1)
134         g1_2.setName("G1")
135         g2_2=DataArrayInt.New()
136         g2_2.setValues([1,2,3],3,1)
137         g2_2.setName("G2")
138         mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
139         g1_1=DataArrayInt.New()
140         g1_1.setValues([0,1,2],3,1)
141         g1_1.setName("G1")
142         g2_1=DataArrayInt.New()
143         g2_1.setValues([0,2],2,1)
144         g2_1.setName("G2")
145         mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
146         g1_N=DataArrayInt.New()
147         g1_N.setValues(range(8),8,1)
148         g1_N.setName("G1")
149         g2_N=DataArrayInt.New()
150         g2_N.setValues(range(9),9,1)
151         g2_N.setName("G2")
152         mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
153         mm.createGroupOnAll(0,"GrpOnAllCell")
154         # check content of mm
155         t=mm.getGroupArr(0,"G1",False)
156         self.assertTrue(g1_2.isEqual(t));
157         t=mm.getGroupArr(0,"G2",False)
158         self.assertTrue(g2_2.isEqual(t));
159         t=mm.getGroupArr(-1,"G1",False)
160         self.assertTrue(g1_1.isEqual(t));
161         t=mm.getGroupArr(-1,"G2",False)
162         self.assertTrue(g2_1.isEqual(t));
163         t=mm.getGroupArr(1,"G1",False)
164         self.assertTrue(g1_N.isEqual(t));
165         t=mm.getGroupArr(1,"G2",False)
166         self.assertTrue(g2_N.isEqual(t));
167         self.assertTrue(mm.existsGroup("GrpOnAllCell"));
168         t=mm.getGroupArr(0,"GrpOnAllCell")
169         self.assertTrue(t.getValues()==range(5))
170         #
171         mmCpy=mm.deepCpy()
172         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) ; del mm
173         mmCpy.write(outFileName,2);
174         #
175         mm=MEDFileMesh.New(outFileName)
176         #
177         self.assertEqual([NORM_TRI3,NORM_QUAD4,NORM_POLYGON],mm.getGeoTypesAtLevel(0))
178         self.assertEqual([NORM_SEG2,NORM_SEG3],mm.getGeoTypesAtLevel(-1))
179         self.assertEqual([NORM_POINT1],mm.getGeoTypesAtLevel(-2))
180         mm0=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POLYGON)
181         self.assertTrue(isinstance(mm0,MEDCoupling1DGTUMesh))
182         self.assertTrue(mm0.getNodalConnectivity().isEqual(DataArrayInt([6,7,4,3,7,8,5,4])))
183         self.assertTrue(mm0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8])))
184         lmm=mm.getDirectUndergroundSingleGeoTypeMeshes(0)
185         self.assertEqual(3,len(lmm))
186         self.assertTrue(isinstance(lmm[0],MEDCoupling1SGTUMesh))
187         self.assertTrue(isinstance(lmm[1],MEDCoupling1SGTUMesh))
188         self.assertTrue(isinstance(lmm[2],MEDCoupling1DGTUMesh))
189         #
190         self.assertTrue(mm.getUnivNameWrStatus())
191         self.assertTrue(isinstance(mm.getUnivName(),str))
192         self.assertTrue(len(mm.getUnivName())!=0)
193         mbis=mm.getMeshAtLevel(0)
194         m.setName(mm.getName()) ; m.setDescription(mm.getDescription())
195         self.assertTrue(m.isEqual(mbis,1e-12));
196         #
197         self.assertEqual(([[(3, 2), (4, 1), (5, 8)], [(1, 2), (2, 1)], [(0, 4)]], 2, 2, 9),MEDLoader.GetUMeshGlobalInfo(outFileName,"MyFirstMEDCouplingMEDmesh"))
198         pass
199
200     # this test is the testMEDMesh3 except that permutation is dealed here
201     def testMEDMesh4(self):
202         outFileName="MEDFileMesh4.med"
203         c=DataArrayDouble.New()
204         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 ];
205         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
206         c.setValues(coords,9,2)
207         c.setInfoOnComponent(0,"abcdef [km]")
208         c.setInfoOnComponent(1,"ghij [MW]")
209         m=MEDCouplingUMesh.New();
210         m.setMeshDimension(2);
211         m.allocateCells(5);
212         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
213         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
214         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
215         m.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
216         m.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
217         m.finishInsertingCells();
218         m.setCoords(c)
219         m.checkCoherency()
220         m1=MEDCouplingUMesh.New();
221         m1.setMeshDimension(1);
222         m1.allocateCells(3);
223         m1.insertNextCell(NORM_SEG2,2,[1,4])
224         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
225         m1.insertNextCell(NORM_SEG2,2,[3,6])
226         m1.finishInsertingCells();
227         m1.setCoords(c)
228         m1.checkCoherency()
229         m2=MEDCouplingUMesh.New();
230         m2.setMeshDimension(0);
231         m2.allocateCells(4);
232         m2.insertNextCell(NORM_POINT1,1,[1])
233         m2.insertNextCell(NORM_POINT1,1,[3])
234         m2.insertNextCell(NORM_POINT1,1,[2])
235         m2.insertNextCell(NORM_POINT1,1,[6])
236         m2.finishInsertingCells();
237         m2.setCoords(c)
238         m2.checkCoherency()
239         #
240         mm=MEDFileUMesh.New()
241         mm.setName("My2ndMEDCouplingMEDmesh")
242         mm.setDescription("ThisIsImpossibleToDoWithMEDMEM")
243         mm.setCoords(c)
244         renumNode=DataArrayInt.New()
245         renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1)
246         mm.setRenumFieldArr(1,renumNode)
247         mm.setMeshAtLevel(-1,m1,True);
248         mm.setMeshAtLevel(0,m,True);
249         mm.setMeshAtLevel(-2,m2,True);
250         mm.removeMeshAtLevel(-2)
251         mm.setMeshAtLevel(-2,m2,True);
252         # playing with groups
253         g1_2=DataArrayInt.New()
254         g1_2.setValues([2,3],2,1)
255         g1_2.setName("G1")
256         g2_2=DataArrayInt.New()
257         g2_2.setValues([2,0,3],3,1)
258         g2_2.setName("G2")
259         mm.setGroupsAtLevel(0,[g1_2,g2_2],True)
260         g1_1=DataArrayInt.New()
261         g1_1.setValues([0,2,1],3,1)
262         g1_1.setName("G1")
263         g2_1=DataArrayInt.New()
264         g2_1.setValues([0,2],2,1)
265         g2_1.setName("G2")
266         mm.setGroupsAtLevel(-1,[g1_1,g2_1],True)
267         g1_N=DataArrayInt.New()
268         g1_N.setValues([10,11,12,13,14,15,16,17],8,1)
269         g1_N.setName("G1")
270         g2_N=DataArrayInt.New()
271         g2_N.setValues([10,11,12,13,14,15,16,17,18],9,1)
272         g2_N.setName("G2")
273         mm.setGroupsAtLevel(1,[g1_N,g2_N],True)
274         # check content of mm
275         t=mm.getGroupArr(0,"G1",True)
276         self.assertTrue(g1_2.isEqual(t));
277         t=mm.getGroupArr(0,"G2",True)
278         self.assertTrue(g2_2.isEqual(t));
279         t=mm.getGroupArr(-1,"G1",True)
280         self.assertTrue(g1_1.isEqual(t));
281         t=mm.getGroupArr(-1,"G2",True)
282         self.assertTrue(g2_1.isEqual(t));
283         self.assertTrue(not mm.existsGroup("GrpOnAllCell"));
284         #
285         mm.write(outFileName,2);
286         mm2=MEDFileMesh.New(outFileName)
287         res=mm.isEqual(mm2,1e-12)
288         self.assertTrue(res[0])
289         l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
290         self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
291         mm2.keepFamIdsOnlyOnLevs([3],[-1])
292         for lev in mm.getGrpNonEmptyLevelsExt("G2"):
293             self.assertEqual(mm.getGroupArr(lev,"G2").getValues(),mm2.getGroupArr(lev,"G2").getValues())
294             pass
295         l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
296         self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
297         #
298         self.assertEqual([-7,-7,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
299         mm2.getFamilyFieldAtLevel(-1).setIJ(1,0,-8)
300         self.assertEqual([-7,-8,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
301         self.assertTrue(not mm2.existsFamily("Family_-8"))
302         mm2.createGroupOnAll(-1,"GrpOnAllFace")
303         self.assertTrue(mm2.existsFamily("Family_-8"))
304         self.assertEqual(range(3),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
305         pass
306
307     #testing persistence of retrieved arrays
308     def testMEDMesh5(self):
309         fileName="Pyfile18.med"
310         mname="ExampleOfMultiDimW"
311         medmesh=MEDFileUMesh.New(fileName,mname)
312         m1_0=medmesh.getLevel0Mesh(True)
313         da1=medmesh.getFamilyFieldAtLevel(0)
314         del medmesh
315         self.assertEqual(20,m1_0.getNumberOfCells())
316         self.assertEqual(20,da1.getNumberOfTuples())
317         pass
318
319     def testMEDMesh6(self):
320         outFileName="MEDFileMesh5.med"
321         m=MEDFileCMesh.New()
322         m.setTime(-1,-1,2.3)
323         m1=MEDCouplingCMesh.New();
324         da=DataArrayDouble.New()
325         da.setValues([0.,1.,2.],3,1)
326         da.setInfoOnComponent(0,"XX [mm]")
327         m1.setCoordsAt(0,da)
328         da=DataArrayDouble.New()
329         da.setValues([0.,1.2],2,1)
330         da.setInfoOnComponent(0,"YY [km]")
331         m1.setCoordsAt(1,da)
332         da=DataArrayDouble.New()
333         da.setValues([0.,1.3],2,1)
334         da.setInfoOnComponent(0,"ZZ [um]")
335         m1.setCoordsAt(2,da)
336         m.setMesh(m1)
337         self.assertTrue(m[0].isEqual(m1,1e-12))
338         self.assertTrue(isinstance(m[0],MEDCouplingCMesh))
339         m.setName("myFirstCartMesh")
340         m.setDescription("mmmmpppppppp")
341         m.setTimeValue(2.3)
342         m.setTimeUnit("ms")
343         da=DataArrayInt.New()
344         da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1)
345         m.setFamilyFieldArr(1,da)
346         m.setFamilyId("family1",1)
347         da=m.getFamilyArr(1,"family1")
348         expected1=[2,4,9]
349         self.assertEqual(expected1,da.getValues())
350         self.assertTrue(m.getUnivNameWrStatus())
351         m.write(outFileName,2);
352         mm=MEDFileMesh.New(outFileName)
353         self.assertEqual([NORM_HEXA8],mm.getGeoTypesAtLevel(0))
354         self.assertTrue(isinstance(mm,MEDFileCMesh))
355         self.assertTrue(isinstance(mm.getUnivName(),str))
356         self.assertTrue(len(mm.getUnivName())!=0)
357         self.assertTrue(m.isEqual(mm,1e-12)[0])
358         self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
359         m2=mm.getMesh()
360         tt=m.getTime()
361         m1.setTime(tt[2],tt[0],tt[1])
362         m1.setName(m.getName())
363         m1.setTimeUnit(m.getTimeUnit())
364         m1.setDescription(m.getDescription())
365         self.assertTrue(m2.isEqual(m1,1e-12));
366         pass
367
368     def testMEDMesh7(self):
369         fileName="Pyfile24.med"
370         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
371         m=MEDFileUMesh.New()
372         m.setCoords(m2.getCoords())
373         m.setMeshAtLevel(0,m2)
374         m.setMeshAtLevel(-1,m1)
375         m.setMeshAtLevel(-2,m0)
376         m.setFamilyFieldArr(0,f2)
377         m.setFamilyFieldArr(-1,f1)
378         m.setFamilyFieldArr(-2,f0)
379         m.setFamilyFieldArr(1,p)
380         m.setRenumFieldArr(0,n2)
381         m.setRenumFieldArr(-1,n1)
382         m.setRenumFieldArr(-2,n0)
383         nbOfFams=len(fns)
384         for i in xrange(nbOfFams):
385             m.addFamily(fns[i],fids[i])
386             pass
387         nbOfGrps=len(grpns)
388         for i in xrange(nbOfGrps):
389             m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
390             pass
391         m.setName(m2.getName())
392         m.setDescription(m2.getDescription())
393         #
394         self.assertEqual((-1,),m.getGrpNonEmptyLevels("A2A4"))
395         self.assertEqual((),m.getGrpNonEmptyLevels("A1"))
396         self.assertEqual((-2,),m.getGrpNonEmptyLevels("AP2"))
397         self.assertEqual((-1,-2),m.getGrpsNonEmptyLevels(["A2A4","AP2"]))
398         self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________'))
399         self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________'))
400         self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________']))
401         self.assertEqual(('A1A2','A2A4','A3A1','A3C5','A4A3','B1C1','B2B4','B3B1','B4C3','C1C4','C2B2','C3C2','C4B3','C5A4'),m.getGroupsOnSpecifiedLev(-1))
402         self.assertEqual(('DALLE','DALQ1','DALQ2','DALT3','MESH'),m.getGroupsOnSpecifiedLev(0))
403         #
404         m.write(fileName,2)
405         self.assertRaises(InterpKernelException,MEDFileField1TS,fileName)#throw because no field in file fileName
406         pass
407
408     def funcToTestDelItem(self,ff):
409         del ff[[0.02,(3,4)]]
410         pass
411
412     #emulation of pointe.med file.
413     def testMEDField1(self):
414         mm=MEDFileMesh.New("Pyfile17.med")
415         mm.write("Pyfile17_bis.med",2)
416         ff=MEDFileFieldMultiTS("Pyfile17.med")
417         tsExpected=[[1,2],[3,4],[5,6]]
418         self.assertEqual(3,len(ff))
419         for pos,f1ts in enumerate(ff):
420             self.assertEqual(tsExpected[pos],f1ts.getTime()[:2])
421             self.assertEqual(type(f1ts),MEDFileField1TS)
422             pass
423         self.assertEqual("MeasureOfMesh_Extruded",ff.getName())
424         self.assertEqual([3,4],ff[1].getTime()[:-1])
425         self.assertEqual([3,4],ff[3,4].getTime()[:-1])
426         self.assertEqual([3,4],ff[0.01].getTime()[:-1])
427         ff.write("Pyfile17_bis.med",0)
428         #
429         ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
430         self.assertEqual([(1,2),(3,4),(5,6)],ts)
431         self.funcToTestDelItem(ff)
432         ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
433         self.assertEqual([(1,2)],ts)
434         pass
435
436     #profiles
437     def testMEDField2(self):
438         mm=MEDFileMesh.New("Pyfile19.med")
439         mm.write("Pyfile19_bis.med",2)
440         ff=MEDFileFieldMultiTS.New("Pyfile19.med")
441         ff.write("Pyfile19_bis.med",0)
442         self.assertEqual([('tyty','mm'),('uiop','MW')],MEDLoader.GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes"))
443         pass
444
445     #gauss points
446     def testMEDField3(self):
447         mm=MEDFileMesh.New("Pyfile13.med")
448         mm.write("Pyfile13_bis.med",2)
449         ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
450         ff.write("Pyfile13_bis.med",0)
451         ff=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint",1,5)
452         f=ff.getFieldAtLevel(ON_GAUSS_PT,0)
453         f2=MEDLoader.ReadFieldGauss("Pyfile13.med",'2DMesh_2',0,'MyFirstFieldOnGaussPoint',1,5)
454         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
455         ff3=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
456         f3=ff3.getFieldAtLevel(ON_GAUSS_PT,0)
457         self.assertTrue(f.isEqual(f3,1e-12,1e-12))
458         ff4=MEDFileField1TS.New("Pyfile13.med")
459         f4=ff4.getFieldAtLevel(ON_GAUSS_PT,0)
460         self.assertTrue(f.isEqual(f4,1e-12,1e-12))
461         pass
462
463     #gauss NE
464     def testMEDField4(self):
465         mm=MEDFileMesh.New("Pyfile14.med")
466         mm.write("Pyfile14_bis.med",2)
467         ff=MEDFileFieldMultiTS.New("Pyfile14.med","MyFieldOnGaussNE")
468         ff.write("Pyfile14_bis.med",0)
469         ff=MEDFileField1TS.New("Pyfile14.med","MyFieldOnGaussNE",1,5)
470         f=ff.getFieldAtLevel(ON_GAUSS_NE,0)
471         f2=MEDLoader.ReadFieldGaussNE("Pyfile14.med",'2DMesh_2',0,"MyFieldOnGaussNE",1,5)
472         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
473         pass
474
475     # MEDField get/set on pointe.med
476     def testMEDField5(self):
477         ff=MEDFileField1TS.New("Pyfile17.med","MeasureOfMesh_Extruded",1,2)
478         f=ff.getFieldAtLevel(ON_CELLS,0)
479         f2=MEDLoader.ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
480         self.assertTrue(f.getMesh().getCoords().isEqual(f2.getMesh().getCoords(),1e-12))
481         f.getMesh().tryToShareSameCoords(f2.getMesh(),1e-12)
482         f.changeUnderlyingMesh(f2.getMesh(),22,1e-12)
483         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
484         # no with renumbering
485         f=ff.getFieldAtLevel(ON_CELLS,0,1)
486         f2=MEDLoader.ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
487         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
488         f=ff.getFieldAtLevel(ON_CELLS,0,3)
489         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
490         f=ff.getFieldAtLevel(ON_CELLS,0,2)
491         self.assertTrue(not f.isEqual(f2,1e-12,1e-12))
492         f.changeUnderlyingMesh(f2.getMesh(),12,1e-12)
493         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
494         pass
495
496     # MEDField get/set on profiles nodes
497     def testMEDField6(self):
498         ff=MEDFileFieldMultiTS.New("Pyfile7.med","VectorFieldOnNodes")
499         its=ff.getIterations()
500         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
501         f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
502         f2=MEDLoader.ReadFieldNode("Pyfile7.med",'3DSurfMesh_1',0,"VectorFieldOnNodes",its[0][0],its[0][1])
503         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
504         ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes")
505         its=ff.getIterations()
506         f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
507         f2=MEDLoader.ReadFieldNode("Pyfile19.med",'2DMesh_1',0,"VFieldOnNodes",its[0][0],its[0][1])
508         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
509         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
510         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_NODES,its[0][0],its[0][1],0,1)#request renumber following mesh : it is on profile !
511         pass
512
513     # MEDField get/set on profiles cells
514     def testMEDField7(self):
515         ff=MEDFileFieldMultiTS.New("Pyfile12.med","VectorFieldOnCells")
516         its=ff.getIterations()
517         f=ff.getFieldAtLevel(ON_CELLS,its[0][0],its[0][1],0)
518         f2=MEDLoader.ReadFieldCell("Pyfile12.med",'3DMesh_1',0,"VectorFieldOnCells",its[0][0],its[0][1])
519         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
520         pass
521
522     #first test of assignation. No profile and types sorted by type.
523     def testMEDField8(self):
524         fname="Pyfile25.med"
525         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
526         m1=f1.getMesh()
527         mm1=MEDFileUMesh.New()
528         mm1.setCoords(m1.getCoords())
529         mm1.setMeshAtLevel(0,m1)
530         mm1.setName(m1.getName())
531         mm1.write(fname,2)
532         ff1=MEDFileField1TS.New()
533         ff1.setFieldNoProfileSBT(f1)
534         ff1.write(fname,0)
535         f2=MEDLoader.ReadFieldCell(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]);
536         itt,orr,ti=ff1.getTime()
537         self.assertEqual(0,itt); self.assertEqual(1,orr); self.assertAlmostEqual(2.,ti,14);
538         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
539         ff1.setTime(3,4,2.3)
540         itt,orr,ti=ff1.getTime()
541         self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14);
542         da,infos=ff1.getUndergroundDataArrayExt()
543         f2.getArray().setName(da.getName())#da has the same name than f2
544         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
545         self.assertEqual([((3, 0), (0, 2)), ((4, 0), (2, 4)), ((6, 0), (4, 5)), ((5, 0), (5, 6))],infos)
546         #
547         fname="Pyfile26.med"
548         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
549         m1=f1.getMesh()
550         mm1=MEDFileUMesh.New()
551         mm1.setCoords(m1.getCoords())
552         mm1.setMeshAtLevel(0,m1)
553         mm1.setName(m1.getName())
554         mm1.write(fname,2)
555         ff1=MEDFileField1TS.New()
556         ff1.setFieldNoProfileSBT(f1)
557         nv=1456.
558         da=ff1.getUndergroundDataArray().setIJ(0,0,nv)
559         ff1.write(fname,0)
560         f2=MEDLoader.ReadFieldNode(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
561         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12))
562         f1.getArray().setIJ(0,0,nv)
563         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
564         #
565         fname="Pyfile27.med"
566         f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
567         m1=f1.getMesh()
568         mm1=MEDFileUMesh.New()
569         mm1.setCoords(m1.getCoords())
570         mm1.setMeshAtLevel(0,m1)
571         mm1.setName(m1.getName())
572         mm1.write(fname,2)
573         ff1=MEDFileField1TS.New()
574         ff1.setFieldNoProfileSBT(f1)
575         ff1.write(fname,0)
576         f2=MEDLoader.ReadFieldGaussNE(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
577         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
578         da,infos=ff1.getUndergroundDataArrayExt()
579         f2.getArray().setName(da.getName())#da has the same name than f2
580         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
581         self.assertEqual([((3, 0), (0, 6)), ((4, 0), (6, 14)), ((6, 0), (14, 20))],infos)
582         #
583         fname="Pyfile28.med"
584         f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler();
585         f1InvalidCpy=f1.deepCpy()
586         f1InvalidCpy.setDiscretization(MEDCouplingFieldDiscretizationGauss())
587         f1InvalidCpy2=f1.deepCpy()
588         f1InvalidCpy2.setDiscretization(MEDCouplingFieldDiscretizationGauss())
589         m1=f1.getMesh()
590         mm1=MEDFileUMesh.New()
591         mm1.setCoords(m1.getCoords())
592         mm1.setMeshAtLevel(0,m1)
593         mm1.setName(m1.getName())
594         mm1.write(fname,2)
595         ff1=MEDFileField1TS.New()
596         self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy) # fails because no Gauss localization per cell set !*
597         f1InvalidCpy2.getDiscretization().setArrayOfDiscIds(f1.getDiscretization().getArrayOfDiscIds()) # fails because no Gauss localization set whereas gauss locid per cell given !
598         self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy2)
599         ff1.setFieldNoProfileSBT(f1)
600         ff1.write(fname,0)
601         ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2])
602         f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0)
603         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
604         sbt=ff2.getFieldSplitedByType2()
605         loc1=ff2.getLocalization("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5")
606         self.assertEqual("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5",loc1.getName())
607         self.assertEqual((-1, 1,-1,-1,1,-1,-1,0,0,-1,0,0),loc1.getRefCoords())
608         self.assertEqual(6,loc1.getNumberOfPointsInCells())
609         self.assertEqual(3,loc1.getNumberOfGaussPoints())
610         self.assertEqual(2,loc1.getDimension())
611         da,infos=ff2.getUndergroundDataArrayExt()
612         f2.getArray().setName(da.getName())#da has the same name than f2
613         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
614         self.assertEqual(53,da.getNumberOfTuples())
615         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)
616         #
617         pass
618     
619     def testMEDFileData1(self):
620         fname="Pyfile29.med"
621         d=MEDFileData.New()
622         #
623         m1=MEDLoaderDataForTest.build1DMesh_1()
624         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
625         mmm1=MEDFileMeshMultiTS.New() ;
626         mmm1.setOneTimeStep(mm1)
627         m2=MEDLoaderDataForTest.build2DCurveMesh_1()
628         mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName())
629         mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2)
630         ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2)
631         d.setMeshes(ms)
632         for name,mmm in zip(["1DMesh_1","2DCurveMesh_1"],ms):
633             self.assertEqual(name,mmm.getName())
634             self.assertEqual(type(mmm),MEDFileUMesh)
635             pass
636         self.assertEqual(('1DMesh_1', '2DCurveMesh_1'),d.getMeshes().getMeshesNames())
637         #
638         ff1=MEDFileFieldMultiTS.New()
639         ff21=MEDFileFieldMultiTS.New()
640         ff22=MEDFileFieldMultiTS.New()
641         f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False)
642         f1.getArray().setInfoOnComponent(0,"power [kW]")
643         ff1.appendFieldNoProfileSBT(f1)
644         f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False)
645         f21.getArray().setInfoOnComponent(0,"sta [mm]") ;
646         ff21.appendFieldNoProfileSBT(f21)
647         f22=f21.deepCpy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ;
648         f22.applyFunc(2,"3*x*IVec+2*x*JVec")
649         f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]")
650         ff22.appendFieldNoProfileSBT(f22)
651         fs=MEDFileFields.New()
652         fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22)
653         for name,fmts in zip(["f1","f21","f22"],fs):
654             self.assertEqual(name,fmts.getName())
655             pass
656         d.setFields(fs)
657         #
658         fname2="Pyfile29_2.med"
659         d.write(fname2,2)
660         #
661         d2=MEDFileData.New(fname2)
662         self.assertEqual(2,d2.getNumberOfMeshes())
663         self.assertEqual(3,d2.getNumberOfFields())
664         self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))
665         self.assertTrue(isinstance(d2.getMeshes()[0],MEDFileUMesh))
666         self.assertTrue(isinstance(d2.getMeshes()['2DCurveMesh_1'],MEDFileUMesh))
667         m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
668         self.assertTrue(m1.isEqual(m1bis,1e-12))
669         self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
670         self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
671         self.assertEqual([(-1,-1,0.0)],d2.getFields()[2].getTimeSteps())
672         self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
673         self.assertEqual([(-1,-1,0.0)],d2.getFields()["f21"].getTimeSteps())
674         pass
675     
676     def testMEDField9(self):
677         # first test field profile WR. Full type but with some type missing
678         fname="Pyfile30.med"
679         m1=MEDLoaderDataForTest.build2DMesh_3()
680         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
681         mm1.write(fname,2)
682         ff1=MEDFileField1TS.New()
683         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1")
684         d=DataArrayDouble.New() ; d.alloc(2*9,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
685         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.
686         da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1")
687         #
688         ff1.setFieldProfile(f1,mm1,0,da)
689         ff1.changePflsNames([(["sup1_NORM_QUAD4"],"ForV650")])
690         ff1=ff1.deepCpy()
691         ff1.write(fname,0)
692         #
693         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
694         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))# profiles names cannot be contracted in pfl array name
695         self.assertTrue(vals.isEqual(d,1e-14))
696         #
697         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
698         ff3=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
699         ff2.deepCpyGlobs(ff3)
700         sbt=ff2.getFieldSplitedByType2()
701         self.assertEqual(3,sbt[0][0])#TRI3
702         self.assertEqual(0,sbt[0][1][0][0])#CELL For TRI3
703         self.assertEqual("",sbt[0][1][0][2])#no profile For TRI3
704         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],sbt[0][1][0][1].getValues())# values for TRI3
705         self.assertEqual(4,sbt[1][0])#QUAD4
706         self.assertEqual(0,sbt[1][1][0][0])#CELL For QUAD4
707         self.assertEqual("ForV650",sbt[1][1][0][2])# profile For QUAD4
708         self.assertEqual([19, 20, 21, 22, 23, 24],sbt[1][1][0][1].getValues())# values for QUAD4
709         self.assertEqual([0],ff2.getTypesOfFieldAvailable())
710         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
711         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
712         self.assertTrue(vals.isEqual(d,1e-14))
713         pass
714     
715     def testMEDField10(self):
716         fname="Pyfile31.med"
717         m1=MEDLoaderDataForTest.build2DMesh_1()
718         m1.renumberCells([0,1,4,2,3,5],False)
719         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
720         mm1.write(fname,2)
721         ff1=MEDFileFieldMultiTS.New()
722         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
723         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
724         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.
725         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
726         #
727         ff1.appendFieldProfile(f1,mm1,0,da)
728         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
729         ff1.appendFieldProfile(f1,mm1,0,da)
730         ff1=ff1.deepCpy()
731         ff1.write(fname,0)
732         #
733         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
734         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
735         self.assertTrue(vals.isEqual(e,1e-14))
736         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
737         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
738         self.assertTrue(vals.isEqual(d,1e-14))
739         #
740         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
741         self.assertEqual([(-1,-1,0.0), (1,2,1.2)],ff2.getTimeSteps())
742         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
743         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
744         self.assertTrue(vals.isEqual(e,1e-14))
745         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
746         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
747         self.assertTrue(vals.isEqual(d,1e-14))
748         pass
749     
750     # idem testMEDField9 method except that here testing profile on nodes and not on cells.
751     def testMEDField11(self):
752         fname="Pyfile32.med"
753         m1=MEDLoaderDataForTest.build2DMesh_1()
754         m1.renumberCells([0,1,4,2,3,5],False)
755         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
756         mm1.write(fname,2)
757         ff1=MEDFileField1TS.New()
758         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
759         d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
760         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.
761         da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
762         #
763         ff1.setFieldProfile(f1,mm1,0,da)
764         self.assertEqual(ff1.getNonEmptyLevels(),(-1, []))
765         ff1.write(fname,0)
766         #
767         vals,pfl=ff1.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
768         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
769         self.assertTrue(vals.isEqual(d,1e-14))
770         ## #
771         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
772         vals,pfl=ff2.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
773         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
774         self.assertTrue(vals.isEqual(d,1e-14))
775         pass
776
777     def testMEDField12(self):
778         fname="Pyfile33.med"
779         m1=MEDLoaderDataForTest.build2DMesh_1()
780         m1.renumberCells([0,1,4,2,3,5],False)
781         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
782         mm1.write(fname,2)
783         ff1=MEDFileFieldMultiTS.New()
784         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
785         d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
786         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.
787         da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
788         #
789         ff1.appendFieldProfile(f1,mm1,0,da)
790         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
791         ff1.appendFieldProfile(f1,mm1,0,da)
792         ff1.write(fname,0)
793         #
794         vals,pfl=ff1.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
795         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
796         self.assertTrue(vals.isEqual(e,1e-14))
797         vals,pfl=ff1.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
798         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
799         self.assertTrue(vals.isEqual(d,1e-14))
800         #
801         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
802         vals,pfl=ff2.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
803         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
804         self.assertTrue(vals.isEqual(e,1e-14))
805         vals,pfl=ff2.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
806         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
807         self.assertTrue(vals.isEqual(d,1e-14))
808         pass
809
810     def testMEDField13(self):
811         fname="Pyfile34.med"
812         m1=MEDLoaderDataForTest.build2DMesh_1()
813         m1.renumberCells([0,1,4,2,3,5],False)
814         tmp=m1.getName();
815         m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
816         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
817         mm1.write(fname,2)
818         ff1=MEDFileField1TS.New()
819         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F3Node")
820         d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
821         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.
822         da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
823         #
824         ff1.setFieldProfile(f1,mm1,0,da)
825         ff1.write(fname,0)
826         #
827         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
828         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
829         self.assertTrue(vals.isEqual(d,1e-14))
830         #
831         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
832         vals,pfl=ff2.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
833         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
834         self.assertTrue(vals.isEqual(d,1e-14))
835         pass
836
837     def testMEDField14(self):
838         fname="Pyfile35.med"
839         m1=MEDLoaderDataForTest.build2DMesh_1()
840         m1.renumberCells([0,1,4,2,3,5],False)
841         tmp=m1.getName();
842         m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
843         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
844         mm1.write(fname,2)
845         ff1=MEDFileFieldMultiTS.New()
846         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
847         d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
848         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.
849         da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
850         #
851         ff1.appendFieldProfile(f1,mm1,0,da)
852         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
853         ff1.appendFieldProfile(f1,mm1,0,da)
854         ff1.write(fname,0)
855         #
856         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
857         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
858         self.assertTrue(vals.isEqual(d,1e-14))
859         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
860         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
861         self.assertTrue(vals.isEqual(e,1e-14))
862         self.assertEqual([[3],[3]],ff1.getTypesOfFieldAvailable())
863         #
864         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
865         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
866         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
867         self.assertTrue(vals.isEqual(d,1e-14))
868         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
869         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
870         self.assertTrue(vals.isEqual(e,1e-14))
871         pass
872     # 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.
873     # 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
874     # 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 !
875     def testMEDField15(self):
876         fname="Pyfile36.med"
877         m0=MEDLoaderDataForTest.build2DMesh_1()
878         m0.renumberCells([0,1,4,2,3,5],False)
879         tmp=m0.getName();
880         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
881         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
882         ff1=MEDFileField1TS.New()
883         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
884         d=DataArrayDouble.New() ; d.alloc(2*20,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
885         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.
886         da=DataArrayInt.New(); da.setValues([0,1,3,4,6],5,1) ; da.setName("sup1NodeElt")
887         #
888         ff1.setFieldProfile(f1,mm1,0,da)
889         m1=m0.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
890         mm1.write(fname,2)
891         ff1.write(fname,0)
892         f1=ff1.getFieldOnMeshAtLevel(ON_GAUSS_NE,m1,0)
893         f2,p1=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; f2.setName("")
894         self.assertTrue(p1.isIdentity())
895         self.assertEqual(5,p1.getNumberOfTuples())
896         self.assertTrue(f1.getArray().isEqual(f2,1e-12))
897         pass
898     # Test for getFieldAtTopLevel method
899     def testMEDField16(self):
900         fname="Pyfile37.med"
901         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
902         m1=f1.getMesh()
903         mm1=MEDFileUMesh.New()
904         mm1.setCoords(m1.getCoords())
905         mm1.setMeshAtLevel(0,m1)
906         mm1.setName(m1.getName())
907         ff1=MEDFileField1TS.New()
908         ff1.setFieldNoProfileSBT(f1)
909         m2=m1.buildDescendingConnectivity()[0]
910         m2.sortCellsInMEDFileFrmt()
911         m2.setName(m1.getName())
912         mm1.setMeshAtLevel(-1,m2)
913         mm1.write(fname,2)
914         f2=m2.getMeasureField(True)
915         dd=DataArrayDouble.New()
916         dd.alloc(f2.getArray().getNumberOfTuples(),3)
917         dd[:,0]=f2.getArray()
918         dd[:,1]=2*f2.getArray()
919         dd[:,2]=3*f2.getArray()
920         f2=f2.buildNewTimeReprFromThis(ONE_TIME,False)
921         f2.setArray(dd)
922         f2.copyTinyStringsFrom(f1)
923         f2.copyTinyAttrFrom(f1)
924         ff1.setFieldNoProfileSBT(f2)
925         ff1.write(fname,0)
926         # Reading Pyfile37.med
927         ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
928         f1bis=ff2.getFieldAtLevel(ON_CELLS,0)
929         self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
930         f1bis=ff2.getFieldAtLevel(ON_CELLS,-1)
931         self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
932         f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
933         self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
934         # More complex
935         fname="Pyfile38.med"
936         mm1.write(fname,2)
937         ff1=MEDFileField1TS.New()
938         ff1.setFieldNoProfileSBT(f2)
939         ff1.write(fname,0)
940         ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
941         f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
942         self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
943         pass
944
945     # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
946     def testMEDField17(self):
947         fname="Pyfile39.med"
948         m1=MEDLoaderDataForTest.build2DMesh_1()
949         m1.renumberCells([0,1,4,2,3,5],False)
950         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
951         mm1.write(fname,2)
952         ffs=MEDFileFields.New()
953         ff1=MEDFileFieldMultiTS.New()
954         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
955         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
956         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.
957         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
958         #
959         ff1.appendFieldProfile(f1,mm1,0,da)
960         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
961         ff1.appendFieldProfile(f1,mm1,0,da)
962         ffs.resize(1)
963         ffs.setFieldAtPos(0,ff1)
964         ffs=ffs.deepCpy()
965         ffs.write(fname,0)
966         #
967         ffsr=MEDFileFields.New(fname)
968         ff3=ffsr.getFieldAtPos(0)
969         f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
970         self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
971         pass
972
973     # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
974     def testMEDField18(self):
975         fname="Pyfile40.med"
976         m1=MEDLoaderDataForTest.build2DMesh_1()
977         m1.renumberCells([0,1,4,2,3,5],False)
978         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
979         mm1.write(fname,2)
980         ffs=MEDFileFields.New()
981         ff1=MEDFileFieldMultiTS.New()
982         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
983         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
984         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.
985         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
986         #
987         ff1.appendFieldProfile(f1,mm1,0,da)
988         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
989         ff1.appendFieldProfile(f1,mm1,0,da)
990         ffs.pushField(ff1)
991         ffs.write(fname,0)
992         #
993         ffsr=MEDFileFields.New(fname)
994         ff3=ffsr.getFieldAtPos(0)
995         f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
996         self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
997         pass
998
999     def testMEDFieldBug1(self):
1000         fname="Pyfile13.med"
1001         d=MEDFileData.New(fname)
1002         self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs())
1003         pass
1004
1005     def testMEDMesh8(self):
1006         m=MEDLoaderDataForTest.build1DMesh_1()
1007         m.convertQuadraticCellsToLinear()
1008         mm=MEDFileUMesh.New()
1009         mm.setMeshAtLevel(0,m)
1010         g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1")
1011         g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2")
1012         g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3")
1013         mm.setGroupsAtLevel(0,[g1,g2],False)
1014         self.assertEqual(('g1','g2'),mm.getGroupsNames())
1015         self.assertEqual(('Family_-2','Family_-3'),mm.getFamiliesNames())
1016         self.assertEqual(('Family_-2',),mm.getFamiliesOnGroup('g1'))
1017         self.assertEqual(('Family_-3',),mm.getFamiliesOnGroup('g2'))
1018         mm.assignFamilyNameWithGroupName()
1019         self.assertEqual(('g1','g2'),mm.getGroupsNames())
1020         self.assertEqual(('g1','g2'),mm.getFamiliesNames())
1021         self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1'))
1022         self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2'))
1023         #
1024         mm=MEDFileUMesh.New()
1025         mm.setMeshAtLevel(0,m)
1026         mm.setGroupsAtLevel(0,[g1,g2,g3],False)
1027         self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1028         self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1029         self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1030         self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1031         self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1032         mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found
1033         self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1034         self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1035         self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1036         self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1037         self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1038         mm.changeFamilyId(5,6)
1039         g=mm.getGroupArr(0,"g3")
1040         self.assertTrue(g.isEqual(g3));
1041         g=mm.getGroupArr(0,"g2")
1042         self.assertTrue(g.isEqual(g2));
1043         g=mm.getGroupArr(0,"g1")
1044         self.assertTrue(g.isEqual(g1));
1045         pass
1046     
1047     # bug detected by gauthier
1048     def testMEDLoaderMEDLoaderNSReadFieldDoubleDataInMedFile(self):
1049         fname="Pyfile41.med"
1050         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
1051         m1=f1.getMesh()
1052         mm1=MEDFileUMesh.New()
1053         mm1.setCoords(m1.getCoords())
1054         mm1.setMeshAtLevel(0,m1)
1055         mm1.write(fname,2)
1056         ff1=MEDFileField1TS.New()
1057         ff1.setFieldNoProfileSBT(f1)
1058         ff1.write(fname,0)
1059         # writing mesh1 and field1, now creation of mesh2 and field2
1060         f2=f1.deepCpy()
1061         m2=f2.getMesh()
1062         m2.translate([0.5,0.6,0.7])
1063         m2.setName("3DSurfMesh_2")
1064         f2.getArray()[:]*=2.
1065         f2.setName("VectorFieldOnCells2")
1066         mm2=MEDFileUMesh.New()
1067         mm2.setCoords(m2.getCoords())
1068         mm2.setMeshAtLevel(0,m2)
1069         mm2.write(fname,0)
1070         ff2=MEDFileField1TS.New()
1071         ff2.setFieldNoProfileSBT(f2)
1072         ff2.write(fname,0)
1073         #
1074         f3=MEDLoader.ReadFieldCell(fname,"3DSurfMesh_1",0,"VectorFieldOnCells",0,1)
1075         self.assertTrue(f3.isEqual(f1,1e-12,1e-12))
1076         f4=MEDLoader.ReadFieldCell(fname,"3DSurfMesh_2",0,"VectorFieldOnCells2",0,1)
1077         self.assertTrue(f4.isEqual(f2,1e-12,1e-12))
1078         pass
1079
1080     def testMEDLoaderMultiLevelCellField1(self):
1081         fname="Pyfile42.med"
1082         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1083         m=MEDFileUMesh.New()
1084         m.setCoords(m2.getCoords())
1085         m.setMeshAtLevel(0,m2)
1086         m.setMeshAtLevel(-1,m1)
1087         m.setMeshAtLevel(-2,m0)
1088         m.write(fname,2)
1089         #
1090         FieldName1="Field1"
1091         compNames1=["comp1","comp2","comp3"]
1092         ff1=MEDFileField1TS.New()
1093         da2=DataArrayDouble.New()
1094         da2.alloc(m2.getNumberOfCells()*len(compNames1),1)
1095         da2.iota(7.)
1096         da2.rearrange(len(compNames1))
1097         da2.setInfoOnComponents(compNames1)
1098         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f2.setName(FieldName1) ; f2.setArray(da2) ; f2.setMesh(m2) ; f2.checkCoherency()
1099         ff1.setFieldNoProfileSBT(f2)
1100         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0]))
1101         da0=DataArrayDouble.New()
1102         da0.alloc(m0.getNumberOfCells()*len(compNames1),1)
1103         da0.iota(190.)
1104         da0.rearrange(len(compNames1))
1105         da0.setInfoOnComponents(compNames1)
1106         f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName1) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkCoherency()
1107         ff1.setFieldNoProfileSBT(f0)
1108         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-2]))
1109         da1=DataArrayDouble.New()
1110         da1.alloc(m1.getNumberOfCells()*len(compNames1),1)
1111         da1.iota(90.)
1112         da1.rearrange(len(compNames1))
1113         da1.setInfoOnComponents(compNames1)
1114         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName1) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkCoherency()
1115         ff1.setFieldNoProfileSBT(f1)
1116         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1117         #
1118         ff1.write(fname,0)
1119         #
1120         FieldName2="Field2"
1121         compNames2=["comp11","comp22"]
1122         ff2=MEDFileField1TS.New()
1123         da0=DataArrayDouble.New()
1124         da0.alloc(m0.getNumberOfCells()*2,1)
1125         da0.iota(-190.)
1126         da0.rearrange(2)
1127         da0.setInfoOnComponents(compNames2)
1128         f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName2) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkCoherency()
1129         ff2.setFieldNoProfileSBT(f0)
1130         self.assertEqual(ff2.getNonEmptyLevels(),(0, [0]))
1131         da1=DataArrayDouble.New()
1132         da1.alloc(m1.getNumberOfCells()*len(compNames2),1)
1133         da1.iota(-90.)
1134         da1.rearrange(len(compNames2))
1135         da1.setInfoOnComponents(compNames2)
1136         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName2) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkCoherency()
1137         ff2.setFieldNoProfileSBT(f1)
1138         self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1139         #
1140         ff2.write(fname,0)
1141         #
1142         ff1=MEDFileField1TS.New(fname,FieldName1,-1,-1)
1143         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1144         self.assertEqual(ff1.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')]), (3, [(0, (84, 148), '', '')]), (4, [(0, (148, 212), '', '')])])
1145         ff2=MEDFileField1TS.New(fname,FieldName2,-1,-1)
1146         self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1147         self.assertEqual(ff2.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')])])
1148         pass
1149
1150     def testFieldOnPflRetrieveOnMdimRelMax1(self):
1151         fname="Pyfile43.med"
1152         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1153         m=MEDFileUMesh.New()
1154         m.setMeshAtLevel(0,m2)
1155         m.setMeshAtLevel(-1,m1)
1156         m.setMeshAtLevel(-2,m0)
1157         f=MEDFileField1TS.New()
1158         ff=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
1159         ff.setName("NodeFieldPfl")
1160         arr=DataArrayDouble.New() ; arr.setValues([1.,10.,100.,2.,20.,200.],2,3)
1161         ff.setArray(arr)
1162         pfl=DataArrayInt.New() ; pfl.setValues([2,3],2,1) ; pfl.setName("PflNode")
1163         f.setFieldProfile(ff,m,-2,pfl)
1164         tes0=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1165         self.assertEqual(ON_NODES,tes0.getTypeOfField())
1166         self.assertEqual(1,tes0.getMesh().getMeshDimension())
1167         self.assertEqual(1,tes0.getMesh().getNumberOfCells())
1168         self.assertEqual(2,tes0.getMesh().getNumberOfNodes())
1169         self.assertEqual([1,0,1],tes0.getMesh().getNodalConnectivity().getValues())
1170         self.assertEqual([0,3],tes0.getMesh().getNodalConnectivityIndex().getValues())
1171         self.assertEqual(2,tes0.getArray().getNumberOfTuples())
1172         self.assertEqual(3,tes0.getArray().getNumberOfComponents())
1173         expected1=[1.,10.,100.,2.,20.,200.]
1174         nodeCoordsWithValue1=[10.,2.5,0.]
1175         nodeCoordsWithValue2=[10.,3.75,0.]
1176         for i in xrange(3):
1177             self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
1178             self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
1179             pass
1180         for i in xrange(6):
1181             self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
1182             pass
1183         del tes0
1184         #
1185         tes1=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1186         self.assertEqual(ON_CELLS,tes1.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1187         self.assertEqual(0,tes1.getMesh().getMeshDimension())
1188         self.assertEqual(2,tes1.getMesh().getNumberOfCells())
1189         self.assertEqual(135,tes1.getMesh().getNumberOfNodes())
1190         self.assertEqual([0,2,0,3],tes1.getMesh().getNodalConnectivity().getValues())
1191         self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
1192         self.assertEqual(2,tes1.getArray().getNumberOfTuples())
1193         self.assertEqual(3,tes1.getArray().getNumberOfComponents())
1194         for i in xrange(6):
1195             self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
1196             pass
1197         m.write(fname,2)
1198         f.write(fname,0)
1199         #
1200         pfl=DataArrayInt.New() ; pfl.setValues([3,2],2,1) ; pfl.setName("PflNode")
1201         f=MEDFileField1TS.New()
1202         f.setFieldProfile(ff,m,-2,pfl)
1203         tes2=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1204         self.assertEqual(ON_NODES,tes2.getTypeOfField())
1205         self.assertEqual(1,tes2.getMesh().getMeshDimension())
1206         self.assertEqual(1,tes2.getMesh().getNumberOfCells())
1207         self.assertEqual(2,tes2.getMesh().getNumberOfNodes())
1208         self.assertEqual([1,0,1],tes2.getMesh().getNodalConnectivity().getValues())
1209         self.assertEqual([0,3],tes2.getMesh().getNodalConnectivityIndex().getValues())
1210         self.assertEqual(2,tes2.getArray().getNumberOfTuples())
1211         self.assertEqual(3,tes2.getArray().getNumberOfComponents())
1212         expected2=[2.,20.,200.,1.,10.,100.]
1213         for i in xrange(3):
1214             self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
1215             self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
1216             pass
1217         for i in xrange(6):
1218             self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
1219             pass
1220         #
1221         tes3=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1222         self.assertEqual(ON_CELLS,tes3.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1223         self.assertEqual(0,tes3.getMesh().getMeshDimension())
1224         self.assertEqual(2,tes3.getMesh().getNumberOfCells())
1225         self.assertEqual(135,tes3.getMesh().getNumberOfNodes())
1226         self.assertEqual([0,3,0,2],tes3.getMesh().getNodalConnectivity().getValues())
1227         self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
1228         self.assertEqual(2,tes3.getArray().getNumberOfTuples())
1229         self.assertEqual(3,tes3.getArray().getNumberOfComponents())
1230         for i in xrange(6):
1231             self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
1232             pass
1233         pass
1234
1235     def testBuildInnerBoundaryAlongM1Group1(self):
1236         fname="Pyfile44.med"
1237         m=MEDCouplingCMesh.New()
1238         m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1239         m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1240         m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1241         m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1242         m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1243         m2.setName(m.getName())
1244         grp=DataArrayInt.New([4,6,8]) ; grp.setName("Grp")
1245         grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1246         mm=MEDFileUMesh.New()
1247         mm.setMeshAtLevel(0,m)
1248         mm.setMeshAtLevel(-1,m2)
1249         mm.setGroupsAtLevel(-1,[grp,grp2])
1250         grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1251         mm.setGroupsAtLevel(1,[grpNode])
1252         ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1253         ref1=[4,9,8,14,15,4,10,9,15,16,4,11,10,16,17]
1254         ref2=[4,9,8,14,30,4,10,9,30,31,4,11,10,31,32]
1255         #
1256         self.assertEqual(30,mm.getNumberOfNodes())
1257         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1258         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())
1259         #
1260         nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1261         self.assertEqual([15,16,17],nodes.getValues());
1262         self.assertEqual([7,8,9],cells.getValues());
1263         self.assertEqual([12,13,14],cells2.getValues());
1264         self.assertEqual(33,mm.getNumberOfNodes())
1265         self.assertEqual([4,6,8],mm.getGroupArr(-1,"Grp").getValues())
1266         self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1267         self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1268         self.assertEqual([17,18,19],mm.getGroupArr(-1,"Grp_dup").getValues())
1269         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())#cells 7,8,9 and 12,13,14 are lying on "Grp" but only 7,8 and 9 are renumbered
1270         self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())#
1271         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),2,1e-12);# Grp_dup and Grp are not equal considering connectivity only
1272         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1273         refValues=DataArrayDouble.New([1.21,1.32,1.43,1.54,1.65,1.32,1.44,1.56,1.68,1.8,1.43,1.56,1.69,1.82,1.95,1.54,1.68,1.82,1.96,2.1])
1274         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1275         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1276         #
1277         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1278         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1279         refValues2=refValues[:] ; refValues2[7:10]=[1.365,1.26,1.35]
1280         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1281         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1282         mm.write(fname,2)
1283         pass
1284
1285     def testBuildInnerBoundaryAlongM1Group2(self):
1286         fname="Pyfile45.med"
1287         m=MEDCouplingCMesh.New()
1288         m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1289         m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1290         m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1291         m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1292         m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1293         m2.setName(m.getName())
1294         grp=DataArrayInt.New([4,6]) ; grp.setName("Grp")
1295         grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1296         mm=MEDFileUMesh.New()
1297         mm.setMeshAtLevel(0,m)
1298         mm.setMeshAtLevel(-1,m2)
1299         mm.setGroupsAtLevel(-1,[grp,grp2])
1300         grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1301         mm.setGroupsAtLevel(1,[grpNode])
1302         ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1303         ref1=[4,9,8,14,15,4,10,9,15,16]
1304         ref2=[4,9,8,14,30,4,10,9,30,16]
1305         #
1306         self.assertEqual(30,mm.getNumberOfNodes())
1307         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1308         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())
1309         #
1310         nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1311         self.assertEqual([15],nodes.getValues());
1312         self.assertEqual([7,8],cells.getValues());
1313         self.assertEqual([12,13],cells2.getValues());
1314         self.assertEqual(31,mm.getNumberOfNodes())
1315         self.assertEqual([4,6],mm.getGroupArr(-1,"Grp").getValues())
1316         self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1317         self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1318         self.assertEqual([17,18],mm.getGroupArr(-1,"Grp_dup").getValues())
1319         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())#cells 7,8,9 and 12,13,14 are lying on "Grp" but only 7,8 and 9 are renumbered
1320         self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())#
1321         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),2,1e-12);# Grp_dup and Grp are not equal considering connectivity only
1322         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1323         refValues=DataArrayDouble.New([1.21,1.32,1.43,1.54,1.65,1.32,1.44,1.56,1.68,1.8,1.43,1.56,1.69,1.82,1.95,1.54,1.68,1.82,1.96,2.1])
1324         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1325         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1326         #
1327         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1328         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1329         refValues2=refValues[:] ; refValues2[7:9]=[1.365,1.47]
1330         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1331         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1332         mm.write(fname,2)       
1333         pass
1334
1335     def testBuildInnerBoundaryAlongM1Group3(self):
1336         """ Test buildInnerBoundaryAlongM1Group() with *non-connex* cracks """
1337         fname = "Pyfile73.med"
1338         m = MEDCouplingCMesh.New()
1339         m.setCoordsAt(0, DataArrayDouble([0.0,1.1,2.3,3.6,5.0]))
1340         m.setCoordsAt(1, DataArrayDouble([0.,1.,2.]))
1341         m = m.buildUnstructured(); m.setName("simple")
1342         m2 = m.buildDescendingConnectivity()[0]
1343         m2.setName(m.getName())
1344             
1345         # A crack in two non connected parts of the mesh:
1346         grpSeg = DataArrayInt([3,19]) ; grpSeg.setName("Grp") 
1347
1348         mm = MEDFileUMesh.New()
1349         mm.setMeshAtLevel(0,m)
1350         mm.setMeshAtLevel(-1,m2)
1351         mm.setGroupsAtLevel(-1,[grpSeg])
1352         nodes, cellsMod, cellsNotMod = mm.buildInnerBoundaryAlongM1Group("Grp")
1353         self.assertEqual([1,13],nodes.getValues());
1354         self.assertEqual([0,6],cellsMod.getValues());
1355         self.assertEqual([1,7],cellsNotMod.getValues());
1356         self.assertEqual(17,mm.getNumberOfNodes())
1357         self.assertEqual([3,19],mm.getGroupArr(-1,"Grp").getValues())
1358         self.assertEqual([22,23],mm.getGroupArr(-1,"Grp_dup").getValues())
1359         ref0=[4, 15, 0, 5, 6, 4, 8, 7, 12, 16]
1360         ref1=[4, 2, 1, 6, 7, 4, 9, 8, 13, 14]
1361         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[0,6]].getNodalConnectivity().getValues())
1362         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[1,7]].getNodalConnectivity().getValues())
1363         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),2,1e-12);# Grp_dup and Grp are not equal considering connectivity only
1364         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1365
1366         refValues=DataArrayDouble([1.1, 1.2, 1.3, 1.4, 1.1, 1.2, 1.3, 1.4])
1367         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1368         self.assertTrue(delta.getMaxValue()[0]<1e-10)
1369         #
1370         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1371         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1372         refValues2=refValues[:] ; refValues2[0] = 1.265; refValues2[6] = 1.105
1373         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ;     delta=(valsToTest-refValues2) ; delta.abs()
1374         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1375         mm.write(fname,2)   
1376
1377     def testBasicConstructors(self):
1378         fname="Pyfile18.med"
1379         m=MEDFileMesh.New(fname)
1380         m=MEDFileMesh.New(fname,"ExampleOfMultiDimW",-1,-1)
1381         m=MEDFileMesh.New(fname)
1382         m=MEDFileUMesh(fname,"ExampleOfMultiDimW",-1,-1)
1383         m=MEDFileUMesh(fname)
1384         m=MEDFileUMesh()
1385         self.testMEDMesh6()
1386         m=MEDFileCMesh("MEDFileMesh5.med")
1387         m=MEDFileCMesh("MEDFileMesh5.med","myFirstCartMesh",-1,-1)
1388         m=MEDFileCMesh()
1389         m=MEDFileMeshMultiTS()
1390         m=MEDFileMeshMultiTS(fname)
1391         m=MEDFileMeshMultiTS(fname,"ExampleOfMultiDimW")
1392         m=MEDFileMeshes()
1393         m=MEDFileMeshes(fname)
1394         m=MEDFileField1TS()
1395         m=MEDFileField1TS(fname,"FieldOnFacesShuffle",2,7)
1396         m=MEDFileFieldMultiTS()
1397         m=MEDFileFieldMultiTS(fname,"FieldOnFacesShuffle")
1398         m=MEDFileFields()
1399         m=MEDFileFields(fname)
1400         m=MEDFileData()
1401         m=MEDFileData(fname)
1402         #
1403         m=DataArrayInt() ; m=DataArrayInt(5,2) ; m=DataArrayInt([6,5,4,3,2,1],3,2)
1404         m=DataArrayDouble() ; m=DataArrayDouble(5,2) ; m=DataArrayDouble([6,5,4,3,2,1],3,2)
1405         m=MEDCouplingUMesh("jjj",2) ; m=MEDCouplingUMesh()
1406         m=MEDCouplingCMesh()
1407         m=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1408         m=MEDCouplingFieldTemplate(ON_NODES)
1409         m=MEDCouplingMultiFields([])
1410         m=MEDCouplingFieldOverTime([])
1411         pass
1412
1413     # This is a non regression test. When a field lies partially on a mesh but fully on one of its geometric type.
1414     def testBugSemiPartialField(self):
1415         fname="Pyfile46.med"
1416         m=MEDLoaderDataForTest.build2DMesh_3()
1417         m=m[:10] ; m.setName("mesh")
1418         f=m.getMeasureField(ON_CELLS)
1419         f=f.buildNewTimeReprFromThis(ONE_TIME,False)
1420         f.setTime(5.5,3,4)
1421         f.setName("SemiPartialField")
1422         #
1423         f1=f[:6] ; f1.getMesh().setName(m.getName())
1424         f2=f[6:] ; f2.getMesh().setName(m.getName())
1425         #
1426         mm=MEDFileUMesh.New()
1427         mm.setMeshAtLevel(0,m)
1428         ff=MEDFileField1TS.New()
1429         ff.setFieldProfile(f1,mm,0,DataArrayInt.Range(0,6,1)) # no name on profile -> normally it is an error but in this special case
1430         mm.write(fname,2)
1431         ff.write(fname,0)
1432         #
1433         ff2=MEDFileField1TS.New(fname,f.getName(),f.getTime()[1],f.getTime()[2])
1434         fread=ff2.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
1435         fread2=ff2.getFieldAtLevel(ON_CELLS,0)
1436         #
1437         fread.checkCoherency()
1438         fread2.checkCoherency()
1439         self.assertTrue(fread.isEqual(f1,1e-12,1e-12))
1440         self.assertTrue(fread2.isEqual(f1,1e-12,1e-12))
1441         pass
1442
1443     def testUnPolyze1(self):
1444         fname="Pyfile47.med"
1445         mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1446         ref=[13,14,14,12,12,12,12,12,12,12,12,13,12,14,14,13,15,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12]
1447         self.assertEqual(ref,mm.getFamilyFieldAtLevel(1).getValues())
1448         self.assertEqual(mm.unPolyze()[:3],(True,[[3,2,0],[4,3,2],[5,4,5],[14,2,9],[16,3,11],[31,2,14]],[[3,3,0],[4,3,3],[5,3,6],[14,3,9],[16,3,12],[18,1,15]]))
1449         mm.write(fname,2)
1450         self.assertEqual(mm.getGroupArr(0,"grp0_L0").getValues(),[0,1,2,6])
1451         self.assertEqual(mm.getGroupArr(0,"grp1_L0").getValues(),[1,3,4,5,6])
1452         self.assertEqual(mm.getGroupArr(-1,"grp0_LM1").getValues(),[1,2,3,4,5])
1453         self.assertEqual(mm.getGroupArr(-1,"grp1_LM1").getValues(),[3,4,5,6])
1454         self.assertEqual(mm.getGroupArr(-1,"grp2_LM1").getValues(),[2,6,7,8])
1455         self.assertEqual(mm.getGroupArr(1,"grp0_Node").getValues(),[0,11,15,16])
1456         self.assertEqual(mm.getGroupArr(1,"grp1_Node").getValues(),[1,2,13,14,16])
1457         self.assertEqual(mm.getFamilyFieldAtLevel(1).getValues(),ref)
1458         # to test
1459         mm.setRenumFieldArr(0,None)
1460         mm.setFamilyFieldArr(-1,None)
1461         pass
1462
1463     def testUnPolyze2(self):
1464         fname="Pyfile48.med"
1465         mfd=MEDFileData.New()
1466         mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1467         meshes=MEDFileMeshes.New()
1468         meshes.pushMesh(mm)
1469         mfd.setMeshes(meshes)
1470         fields=MEDFileFields.New()
1471         mfd.setFields(fields)
1472         ff=MEDFileFieldMultiTS.New()
1473         fields.pushField(ff)
1474         #
1475         f0_0=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f0_0.setName("f0")
1476         f0_0.setTime(9.5,3,4)
1477         da=DataArrayDouble.New(38*2) ; da.iota(6.) ; da.rearrange(2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1478         f0_0.setArray(da)
1479         f0_0.setMesh(mm.getMeshAtLevel(0))
1480         ff.appendFieldNoProfileSBT(f0_0)
1481         ff0=ff.getTimeStepAtPos(0)
1482         f0_1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_1.setName("f0")
1483         f0_1.setTime(9.5,3,4)
1484         pfl=DataArrayInt.New([1,4,5,6]) ; pfl.setName("pfltest")
1485         f0_1.setMesh(mm.getMeshAtLevel(0)[pfl])
1486         da=DataArrayDouble.New([1401.,101401.,1602.,101602.,3100.,103100.,3101.,103101.],4,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1487         f0_1.setArray(da)
1488         ff0.setFieldProfile(f0_1,mm,0,pfl)
1489         f0_2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_2.setName("f0")#provoquer error
1490         f0_2.setTime(9.5,3,4)
1491         pfl2=DataArrayInt.New([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfltestM1")
1492         da=DataArrayDouble.New([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.],8,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])#provoquer error
1493         f0_2.setMesh(mm.getMeshAtLevel(-1)[pfl2])
1494         f0_2.setArray(da)
1495         ff0.setFieldProfile(f0_2,mm,-1,pfl2)
1496         mfd.getFields().shallowCpyGlobs(ff0)
1497         #
1498         mfd.unPolyzeMeshes()
1499         #
1500         fmts=mfd.getFields()[0]
1501         self.assertEqual(fmts.getNumberOfTS(),1)
1502         self.assertEqual(fmts.getTimeSteps(),[(3,4,9.5)])
1503         arr,entry=fmts.getUndergroundDataArrayExt(3,4)
1504         self.assertEqual(entry,[((3,0),(38,40)),((4,0),(40,43)),((5,0),(43,46)),((14,0),(46,48)),((16,0),(48,49)),((18,0),(49,50)),((40,0),(0,38))])
1505         self.assertTrue(arr[38:40].isEqualWithoutConsideringStr(DataArrayDouble([300.0,100300.0,301.0,100301.0],2,2),1e-8))
1506         self.assertTrue(arr[40:43].isEqualWithoutConsideringStr(DataArrayDouble([400.0,100400.0,401.0,100401.0,402.0,100402.0],3,2),1e-8))
1507         self.assertTrue(arr[43:46].isEqualWithoutConsideringStr(DataArrayDouble([3200.0,103200.0,3201.0,103201.0,3203.0,103203.0],3,2),1e-8))
1508         self.assertTrue(arr[46:48].isEqualWithoutConsideringStr(DataArrayDouble([1401.0,101401.0,3100.0,103100.0],2,2),1e-8))
1509         self.assertTrue(arr[48:49].isEqualWithoutConsideringStr(DataArrayDouble([1602.0,101602.0],1,2),1e-8))
1510         self.assertTrue(arr[49:50].isEqualWithoutConsideringStr(DataArrayDouble([3101.0,103101.0],1,2),1e-8))
1511         self.assertEqual(('NewPfl_0','NewPfl_1','NewPfl_2'),fmts.getPflsReallyUsed())
1512         self.assertEqual([(3,[(0,(38,40),'NewPfl_0','')]),(4,[(0,(40,43),'','')]),(5,[(0,(43,46),'','')]),(14,[(0,(46,48),'NewPfl_1','')]),(16,[(0,(48,49),'NewPfl_2','')]),(18,[(0,(49,50),'','')]),(40,[(1,(0,38),'','')])],fmts.getFieldSplitedByType(3,4))
1513         self.assertEqual(fmts.getProfile("NewPfl_0").getValues(),[0,1])
1514         self.assertEqual(fmts.getProfile("NewPfl_1").getValues(),[1,2])
1515         self.assertEqual(fmts.getProfile("NewPfl_2").getValues(),[2])
1516         ftest0=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,0,mfd.getMeshes()[0])
1517         self.assertTrue(ftest0.getArray().isEqualWithoutConsideringStr(DataArrayDouble([1401.,101401.,3100.,103100.,1602.,101602.,3101.,103101.],4,2),1e-8))
1518         self.assertEqual(ftest0.getMesh().getNodalConnectivity().getValues(),[14,4,5,6,7,14,26,27,28,29,16,20,21,22,23,24,25,18,30,31,32,33,34,35,36,37])
1519         self.assertEqual(ftest0.getMesh().getNodalConnectivityIndex().getValues(),[0,5,10,17,26])
1520         ftest1=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,-1,mfd.getMeshes()[0])
1521         self.assertTrue(ftest1.getArray().isEqualWithoutConsideringStr(DataArrayDouble([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.]),1e-8))
1522         self.assertEqual(ftest1.getMesh().getNodalConnectivity().getValues(),[3,0,1,2,3,3,4,5,4,6,7,8,9,4,10,11,12,13,4,14,15,16,17,5,18,19,20,21,22,5,23,24,25,26,27,5,31,32,33,34,35,36,37])
1523         self.assertEqual(ftest1.getMesh().getNodalConnectivityIndex().getValues(),[0,4,8,13,18,23,29,35,43])
1524         #
1525         mfd.write(fname,2)
1526         pass
1527
1528     def testGaussWriteOnPfl1(self):
1529         fname="Pyfile49.med"
1530         fname2="Pyfile50.med"
1531         coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
1532         mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
1533         mQ8.allocateCells(1)
1534         mQ8.insertNextCell(NORM_QUAD8,range(8))
1535         mQ8.finishInsertingCells()
1536         mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
1537         mQ4.allocateCells(1)
1538         mQ4.insertNextCell(NORM_QUAD4,range(4))
1539         mQ4.finishInsertingCells()
1540         mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
1541         mT3.allocateCells(1)
1542         mT3.insertNextCell(NORM_TRI3,range(3))
1543         mT3.finishInsertingCells()
1544         
1545         tr=[[0.,4.],[2.,4.],[4.,4.],[6.,4.],[8.,4.],[10.,4.],[12.,4.],[14.,4.],[16.,4.],[18.,4.],[20.,4.],[0.,0.],[2.,0.], [0.,2.],[2.,2.],[4.,2.],[6.,2.],[8.,2.],[10.,2.],[12.,2.]]
1546         ms=11*[mT3]+2*[mQ4]+7*[mQ8]
1547         ms[:]=(elt.deepCpy() for elt in ms)
1548         for m,t in zip(ms,tr):
1549             d=m.getCoords() ; d+= t
1550             pass
1551         m=MEDCouplingUMesh.MergeUMeshes(ms)
1552         m.setName("mesh")
1553         m2=m[:13] ; m2.setName(m.getName())
1554         ### Use case 1 : Pfl on all tri3 and on all quad4. If we were on CELLS or GAUSS_NE no pfl were needed. But here 2 discs in tri3.
1555         ### So here 2 pfls will be created (pfl_TRI3_loc_0 and pfl_TRI3_loc_1)
1556         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1557         f.setMesh(m2)
1558         f.setTime(4.5,1,2)
1559         da=DataArrayDouble(34) ; da.iota(3.)
1560         f.setArray(da)
1561         f.setName("fieldCellOnPflWithoutPfl")
1562         fInvalid=f.deepCpy()
1563         f.setGaussLocalizationOnCells([0,1,2,3,4,5,6,7,8],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1564         f.setGaussLocalizationOnCells([9,10],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13])
1565         f.setGaussLocalizationOnCells([11,12],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02])
1566         f.checkCoherency()
1567         fInvalid2=fInvalid.deepCpy()
1568         fInvalid2.getDiscretization().setArrayOfDiscIds(f.getDiscretization().getArrayOfDiscIds())
1569         #
1570         mm=MEDFileUMesh()
1571         mm.setMeshAtLevel(0,m)
1572         mm.write(fname,2)
1573         #
1574         f1ts=MEDFileField1TS.New()
1575         pfl=DataArrayInt(range(13)) ; pfl.setName("pfl")
1576         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set !
1577         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given !
1578         f1ts.setFieldProfile(f,mm,0,pfl)
1579         f1ts.write(fname,0)
1580         #
1581         self.assertEqual(f1ts.getPfls(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1582         self.assertEqual(f1ts.getPflsReallyUsed(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1583         da1=DataArrayInt([0,1,2,3,4,5,6,7,8]) ; da1.setName("pfl_NORM_TRI3_loc_0")
1584         self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_0").isEqual(da1))
1585         da1=DataArrayInt([9,10]) ; da1.setName("pfl_NORM_TRI3_loc_1")
1586         self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_1").isEqual(da1))
1587         self.assertEqual(f1ts.getLocs(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1588         self.assertEqual(f1ts.getLocsReallyUsed(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1589         #
1590         dataRead=MEDFileData.New(fname)
1591         mRead=dataRead.getMeshes()[0]
1592         f1tsRead=dataRead.getFields()[0][0]
1593         f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1594         f2=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1595         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
1596         f2_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1597         f2_bis.checkCoherency()
1598         self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12))
1599         #
1600         MEDLoader.WriteField(fname2,f,True)
1601         f2_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1602         self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12))
1603         ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc
1604         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1605         pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2")
1606         m2=m[pfl] ; m2.setName(m.getName())
1607         f.setMesh(m2)
1608         f.setTime(4.5,1,2)
1609         da=DataArrayDouble(35) ; da.iota(3.)
1610         f.setArray(da)
1611         f.setName("fieldCellOnPflWithoutPfl2")
1612         f.setGaussLocalizationOnCells([0,1,3],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1613         f.setGaussLocalizationOnCells([2,4,5],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13])
1614         f.setGaussLocalizationOnCells([6,7,8,9],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02])
1615         f.checkCoherency()
1616         #
1617         mm=MEDFileUMesh()
1618         mm.setMeshAtLevel(0,m)
1619         mm.write(fname,2)
1620         f1ts=MEDFileField1TS.New()
1621         f1ts.setFieldProfile(f,mm,0,pfl)
1622         self.assertEqual(f1ts.getPfls(),('pfl2_NORM_TRI3_loc_0','pfl2_NORM_TRI3_loc_1','pfl2_NORM_QUAD8_loc_2'))
1623         self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_0").getValues(),[1,2,6])
1624         self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_1").getValues(),[5,8,9])
1625         self.assertEqual(f1ts.getProfile("pfl2_NORM_QUAD8_loc_2").getValues(),[2,3,4,5])
1626         f1ts.write(fname,0)
1627         dataRead=MEDFileData.New(fname)
1628         mRead=dataRead.getMeshes()[0]
1629         f1tsRead=dataRead.getFields()[0][0]
1630         f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1631         f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1632         f3.renumberCells([0,1,3,2,4,5,6,7,8,9])
1633         self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1634         f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1635         f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9])
1636         self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1637         #
1638         MEDLoader.WriteField(fname2,f,True)
1639         f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1640         f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9])
1641         self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1642         ## Use case 3 : no pfl but creation of pfls due to gauss pts
1643         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1644         f.setMesh(m)
1645         f.setTime(4.5,1,2)
1646         da=DataArrayDouble(60) ; da.iota(3.)
1647         f.setArray(da)
1648         f.setName("fieldCellWithoutPfl")
1649         f.setGaussLocalizationOnCells([0,1,2,3,4,5,6,7,8],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1650         f.setGaussLocalizationOnCells([9,10],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13])
1651         f.setGaussLocalizationOnCells([11,12],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02])
1652         f.setGaussLocalizationOnCells([13,14,15,17,18],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8],[0.8,0.1,0.03,0.07])
1653         f.setGaussLocalizationOnCells([16,19],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.1,0.1])
1654         f.checkCoherency()
1655         mm=MEDFileUMesh()
1656         mm.setMeshAtLevel(0,m) 
1657         f1ts=MEDFileField1TS.New()
1658         f1ts.setFieldNoProfileSBT(f)
1659         self.assertEqual(f1ts.getPfls(),('Pfl_fieldCellWithoutPfl_NORM_TRI3_0','Pfl_fieldCellWithoutPfl_NORM_TRI3_1','Pfl_fieldCellWithoutPfl_NORM_QUAD8_3','Pfl_fieldCellWithoutPfl_NORM_QUAD8_4'))
1660         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_0").getValues(),[0,1,2,3,4,5,6,7,8])
1661         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_1").getValues(),[9,10])
1662         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_3").getValues(),[0,1,2,4,5])
1663         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_4").getValues(),[3,6])
1664         mm.write(fname,2)
1665         f1ts.write(fname,0)
1666         #
1667         dataRead=MEDFileData.New(fname)
1668         mRead=dataRead.getMeshes()[0]
1669         f1tsRead=dataRead.getFields()[0][0]
1670         f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1671         f3.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1672         self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1673         f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1674         f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1675         self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1676         #
1677         MEDLoader.WriteField(fname2,f,True)
1678         f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1679         f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1680         self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1681         pass
1682
1683     # Testing profile on nodes when the profile is identity but not on all nodes.
1684     def testMEDFieldPflOnNode1(self):
1685         fname="Pyfile51.med"
1686         coo=DataArrayDouble([0.,0.,0.5,0.,1.,0.,0.,0.5,0.5,0.5,1.,0.5,0.,1.,0.5,1.,1.,1.],9,2)
1687         m0=MEDCouplingUMesh("Mesh",2)
1688         m0.allocateCells(5)
1689         m0.insertNextCell(NORM_TRI3,[1,4,2])
1690         m0.insertNextCell(NORM_TRI3,[4,5,2])
1691         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1692         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1693         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1694         m0.finishInsertingCells()
1695         m0.setCoords(coo)
1696         m1=MEDCouplingUMesh(m0.getName(),1)
1697         m1.allocateCells(9)
1698         conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1699         for i in xrange(9):
1700             m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1701             pass
1702         m1.finishInsertingCells()
1703         m1.setCoords(coo)
1704         #
1705         m=MEDFileUMesh()
1706         m.setMeshAtLevel(0,m0)
1707         m.setMeshAtLevel(-1,m1)
1708         #
1709         dt=3 ; it=2 ; tim=4.5
1710         fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1711         fieldNode0.setName("fieldNode0")
1712         fieldNode0.setTime(tim,dt,it)
1713         pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
1714         arr=DataArrayDouble([10,11,12,13,14])
1715         fieldNode0.setArray(arr)
1716         f0=MEDFileField1TS()
1717         f0.setFieldProfile(fieldNode0,m,0,pfl0)
1718         m.write(fname,2) ; f0.write(fname,0)
1719         fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1720         fieldNode1.setName("fieldNode1")
1721         fieldNode1.setTime(tim,dt,it)
1722         pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1723         arr1=DataArrayDouble([20,21,22,23,24,25,26])
1724         fieldNode1.setArray(arr1)
1725         f1=MEDFileField1TS()
1726         f1.setFieldProfile(fieldNode1,m,-1,pfl1)
1727         f1.write(fname,0)
1728         del m,f0,m0,m1,f1
1729         ## Reading from file
1730         m=MEDFileMesh.New(fname)
1731         m0=m.getMeshAtLevel(0)
1732         m00=m0.deepCpy() ; m00=m00[[0,2]] ; m00.setName(m.getName()) ; m00.zipCoords()
1733         fieldNode0.setMesh(m00)
1734         f0=MEDFileField1TS.New(fname,fieldNode0.getName(),dt,it)
1735         ff0_1=f0.getFieldOnMeshAtLevel(ON_NODES,m0)
1736         ff0_1.checkCoherency()
1737         self.assertTrue(ff0_1.isEqual(fieldNode0,1e-12,1e-12))
1738         ff0_2=f0.getFieldAtLevel(ON_NODES,0)
1739         ff0_2.checkCoherency()
1740         self.assertTrue(ff0_2.isEqual(fieldNode0,1e-12,1e-12))
1741         ff0_3=f0.getFieldOnMeshAtLevel(ON_NODES,0,m)
1742         ff0_3.checkCoherency()
1743         self.assertTrue(ff0_3.isEqual(fieldNode0,1e-12,1e-12))
1744         ff0_4=MEDLoader.ReadFieldNode(fname,m.getName(),0,fieldNode0.getName(),dt,it)
1745         ff0_4.checkCoherency()
1746         self.assertTrue(ff0_4.isEqual(fieldNode0,1e-12,1e-12))
1747         f1=MEDFileField1TS.New(fname,fieldNode1.getName(),dt,it)
1748         m1=m.getMeshAtLevel(-1)
1749         m10=m1.deepCpy() ; m10=m10[[0,1,2,3,4,5,6,7]] ; m10.setName(m.getName()) ; m10.zipCoords()
1750         fieldNode1.setMesh(m10)
1751         ff1_1=f1.getFieldOnMeshAtLevel(ON_NODES,m1)
1752         ff1_1.checkCoherency()
1753         self.assertTrue(ff1_1.isEqual(fieldNode1,1e-12,1e-12))
1754         ff1_2=f1.getFieldAtLevel(ON_NODES,-1)
1755         ff1_2.checkCoherency()
1756         self.assertTrue(ff1_2.isEqual(fieldNode1,1e-12,1e-12))
1757         ff1_3=f1.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1758         ff1_3.checkCoherency()
1759         self.assertTrue(ff1_3.isEqual(fieldNode1,1e-12,1e-12))
1760         ff1_4=MEDLoader.ReadFieldNode(fname,m.getName(),-1,fieldNode1.getName(),dt,it)
1761         ff1_4.checkCoherency()
1762         self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1763         self.assertRaises(InterpKernelException,f1.getFieldOnMeshAtLevel,ON_NODES,m0) # error because impossible to build a sub mesh at level 0 lying on nodes [0,1,2,3,4,5,6]
1764         self.assertRaises(InterpKernelException,f1.getFieldAtLevel,ON_NODES,0) # error because impossible to build a sub mesh at level 0 lying on nodes [0,1,2,3,4,5,6]
1765         self.assertRaises(InterpKernelException,f1.getFieldOnMeshAtLevel,ON_NODES,0,m) # error because impossible to build a sub mesh at level 0 lying on nodes [0,1,2,3,4,5,6]
1766         arr_r,pfl1_r=f1.getFieldWithProfile(ON_NODES,-1,m)
1767         arr_r.setName(fieldNode1.getArray().getName())
1768         self.assertTrue(arr_r.isEqual(fieldNode1.getArray(),1e-12))
1769         pfl1_r.setName(pfl1.getName())
1770         self.assertTrue(pfl1_r.isEqual(pfl1))
1771         pass
1772     
1773         # Testing profile on nodes when the profile is identity but not on all nodes.
1774     def testMEDFieldPflOnCell1(self):
1775         fname="Pyfile52.med"
1776         coo=DataArrayDouble([0.,0.,0.5,0.,1.,0.,0.,0.5,0.5,0.5,1.,0.5,0.,1.,0.5,1.,1.,1.],9,2)
1777         m0=MEDCouplingUMesh("Mesh",2)
1778         m0.allocateCells(5)
1779         m0.insertNextCell(NORM_TRI3,[1,4,2])
1780         m0.insertNextCell(NORM_TRI3,[4,5,2])
1781         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1782         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1783         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1784         m0.finishInsertingCells()
1785         m0.setCoords(coo)
1786         m1=MEDCouplingUMesh(m0.getName(),1)
1787         m1.allocateCells(9)
1788         conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1789         for i in xrange(9):
1790             m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1791             pass
1792         m1.finishInsertingCells()
1793         m1.setCoords(coo)
1794         #
1795         m=MEDFileUMesh()
1796         m.setMeshAtLevel(0,m0)
1797         m.setMeshAtLevel(-1,m1)
1798         #
1799         dt=3 ; it=2 ; tim=4.5
1800         fieldCell0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1801         fieldCell0.setName("fieldCell0")
1802         fieldCell0.setTime(tim,dt,it)
1803         pfl0=DataArrayInt([0,1,2]) ; pfl0.setName("PflIdentity0") # important to keep like that
1804         arr=DataArrayDouble([10,11,12])
1805         fieldCell0.setArray(arr)
1806         f0=MEDFileField1TS()
1807         f0.setFieldProfile(fieldCell0,m,0,pfl0)
1808         m.write(fname,2) ; f0.write(fname,0)
1809         fieldCell1=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1810         fieldCell1.setName("fieldCell1")
1811         fieldCell1.setTime(tim,dt,it)
1812         pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1813         arr1=DataArrayDouble([20,21,22,23,24,25,26])
1814         fieldCell1.setArray(arr1)
1815         f1=MEDFileField1TS()
1816         f1.setFieldProfile(fieldCell1,m,-1,pfl1)
1817         f1.write(fname,0)
1818         del m,f0,m0,m1,f1
1819         ## Reading from file
1820         m=MEDFileMesh.New(fname)
1821         m0=m.getMeshAtLevel(0)
1822         m00=m0.deepCpy() ; m00=m00[pfl0] ; m00.setName(m.getName())
1823         fieldCell0.setMesh(m00)
1824         f0=MEDFileField1TS.New(fname,fieldCell0.getName(),dt,it)
1825         ff0_1=f0.getFieldOnMeshAtLevel(ON_CELLS,m0)
1826         ff0_1.checkCoherency()
1827         self.assertTrue(ff0_1.isEqual(fieldCell0,1e-12,1e-12))
1828         ff0_2=f0.getFieldAtLevel(ON_CELLS,0)
1829         ff0_2.checkCoherency()
1830         self.assertTrue(ff0_2.isEqual(fieldCell0,1e-12,1e-12))
1831         ff0_3=f0.getFieldOnMeshAtLevel(ON_CELLS,0,m)
1832         ff0_3.checkCoherency()
1833         self.assertTrue(ff0_3.isEqual(fieldCell0,1e-12,1e-12))
1834         ff0_4=MEDLoader.ReadFieldCell(fname,m.getName(),0,fieldCell0.getName(),dt,it)
1835         ff0_4.checkCoherency()
1836         self.assertTrue(ff0_4.isEqual(fieldCell0,1e-12,1e-12))
1837         f1=MEDFileField1TS.New(fname,fieldCell1.getName(),dt,it)
1838         m1=m.getMeshAtLevel(-1)
1839         m10=m1.deepCpy() ; m10=m10[pfl1] ; m10.setName(m.getName())
1840         fieldCell1.setMesh(m10)
1841         ff1_1=f1.getFieldOnMeshAtLevel(ON_CELLS,m1)
1842         ff1_1.checkCoherency()
1843         self.assertTrue(ff1_1.isEqual(fieldCell1,1e-12,1e-12))
1844         ff1_2=f1.getFieldAtLevel(ON_CELLS,-1)
1845         ff1_2.checkCoherency()
1846         self.assertTrue(ff1_2.isEqual(fieldCell1,1e-12,1e-12))
1847         ff1_3=f1.getFieldOnMeshAtLevel(ON_CELLS,-1,m)
1848         ff1_3.checkCoherency()
1849         self.assertTrue(ff1_3.isEqual(fieldCell1,1e-12,1e-12))
1850         ff1_4=MEDLoader.ReadFieldCell(fname,m.getName(),-1,fieldCell1.getName(),dt,it)
1851         ff1_4.checkCoherency()
1852         self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1853         self.assertRaises(InterpKernelException,f1.getFieldOnMeshAtLevel,ON_CELLS,m0) # error because impossible to build a sub mesh at level 0 lying on cells [0,1,2,3,4,5,6]
1854         self.assertRaises(InterpKernelException,f1.getFieldAtLevel,ON_CELLS,0) # error because impossible to build a sub mesh at level 0 lying on cells [0,1,2,3,4,5,6]
1855         self.assertRaises(InterpKernelException,f1.getFieldOnMeshAtLevel,ON_CELLS,0,m) # error because impossible to build a sub mesh at level 0 lying on cells [0,1,2,3,4,5,6]
1856         arr_r,pfl1_r=f1.getFieldWithProfile(ON_CELLS,-1,m)
1857         arr_r.setName(fieldCell1.getArray().getName())
1858         self.assertTrue(arr_r.isEqual(fieldCell1.getArray(),1e-12))
1859         pfl1_r.setName(pfl1.getName())
1860         self.assertTrue(pfl1_r.isEqual(pfl1))
1861         pass
1862
1863     def testMEDFileUMeshZipCoords1(self):
1864         m=MEDFileUMesh()
1865         coo=DataArrayDouble(30) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1866         m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0) ; m0.insertNextCell(NORM_TRI3,[1,2,3]) ; m0.insertNextCell(NORM_QUAD4,[2,4,3,4]) ; m0.insertNextCell(NORM_POLYGON,[1,6,6,6,2])
1867         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1868         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1869         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1870         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1871         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1872         numCoo=DataArrayInt(10) ; numCoo.iota(3) ; m.setRenumFieldArr(1,numCoo)
1873         famCoo=DataArrayInt(10) ; famCoo.iota(4) ; m.setFamilyFieldArr(1,famCoo)
1874         da=DataArrayInt([20,30,40]) ; m.setRenumFieldArr(0,da) ; da=DataArrayInt([200,300,400]) ; m.setFamilyFieldArr(0,da)
1875         da=DataArrayInt([50,60]) ; m.setRenumFieldArr(-1,da) ; da=DataArrayInt([500,600]) ; m.setFamilyFieldArr(-1,da)
1876         da=DataArrayInt([70,80,90]) ; m.setRenumFieldArr(-2,da) ; da=DataArrayInt([700,800,900]) ; m.setFamilyFieldArr(-2,da)
1877         o2n=m.zipCoords()
1878         self.assertTrue(o2n.isEqual(DataArrayInt([-1,0,1,2,3,-1,4,5,6,-1])))
1879         self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt([4,5,6,7,9,10,11])))
1880         self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([5,6,7,8,10,11,12])))
1881         self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,4,1,3,2,3,5,0,4,4,4,1])))
1882         self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,9,15])))
1883         self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivity().isEqual(DataArrayInt([1,0,4,1,5,2])))
1884         self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6])))
1885         self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivity().isEqual(DataArrayInt([0,1,0,4,0,6])))
1886         self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivityIndex().isEqual(DataArrayInt([0,2,4,6])))
1887         pass
1888
1889     def testMEDUMeshAddNodeGroup1(self):
1890         fname="Pyfile53.med"
1891         m=MEDFileUMesh()
1892         coo=DataArrayDouble(39) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1893         m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0) ; m0.insertNextCell(NORM_TRI3,[1,2,3]) ; m0.insertNextCell(NORM_QUAD4,[2,4,3,4]) ; m0.insertNextCell(NORM_POLYGON,[1,6,6,6,2])
1894         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1895         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1896         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1897         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1898         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1899         #
1900         mm=m.deepCpy()
1901         famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(1,famCoo)
1902         da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(0,da0)
1903         da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
1904         da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
1905         mm.setFamilyId("MyFam",2)
1906         mm.setFamilyId("MyOtherFam",3)
1907         mm.setFamilyId("MyOther-1",-1)
1908         mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
1909         mm.setFamiliesOnGroup("grpA",["MyOther-1"])
1910         #
1911         daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
1912         mm.addNodeGroup(daTest)
1913         self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
1914         self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
1915         for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
1916             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1917             pass
1918         self.assertEqual(mm.getFamiliesNames(),('Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
1919         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1920         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1921         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1922         for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
1923             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1924             pass
1925         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_8'))
1926         da=DataArrayInt([3,12]) ; da.setName("grp0")
1927         self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
1928         da.setValues([1])
1929         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
1930         mm.write(fname,2)
1931         mm=MEDFileMesh.New(fname)
1932         self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
1933         self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
1934         for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
1935             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1936             pass
1937         self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
1938         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1939         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1940         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1941         for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
1942             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1943             pass
1944         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_8','MyOtherFam'))
1945         da=DataArrayInt([3,12]) ; da.setName("grp0")
1946         self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
1947         da.setValues([1])
1948         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
1949         pass
1950
1951     def testMEDUMeshAddGroup1(self):
1952         fname="Pyfile54.med"
1953         m=MEDFileUMesh()
1954         coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1955         m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
1956         for i in xrange(7):
1957             m0.insertNextCell(NORM_TRI3,[1,2,1])
1958             pass
1959         for i in xrange(4):
1960             m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
1961             pass
1962         for i in xrange(2):
1963             m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
1964             pass
1965         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1966         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1967         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1968         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1969         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1970         #
1971         mm=m.deepCpy()
1972         famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(0,famCoo)
1973         da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(1,da0)
1974         da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
1975         da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
1976         mm.setFamilyId("MyFam",2)
1977         mm.setFamilyId("MyOtherFam",3)
1978         mm.setFamilyId("MyOther-1",-1)
1979         mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
1980         mm.setFamiliesOnGroup("grpA",["MyOther-1"])
1981         #
1982         daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
1983         mm.addGroup(0,daTest)
1984         self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
1985         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
1986         for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
1987             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1988             pass
1989         self.assertEqual(mm.getFamiliesNames(),('Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
1990         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1991         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1992         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1993         for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
1994             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1995             pass
1996         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_-8'))
1997         da=DataArrayInt([3,12]) ; da.setName("grp0")
1998         self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
1999         da.setValues([1])
2000         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2001         mm.write(fname,2)
2002         mm=MEDFileMesh.New(fname)
2003         self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2004         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2005         for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2006             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2007             pass
2008         self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2009         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2010         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2011         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2012         for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2013             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2014             pass
2015         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_-8','MyOtherFam'))
2016         da=DataArrayInt([3,12]) ; da.setName("grp0")
2017         self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2018         da.setValues([1])
2019         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2020         pass
2021
2022     def testHeapMem1(self):
2023         a=DataArrayInt() ; aa=a.getHeapMemorySize()
2024         a.alloc(0,1)
2025         strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
2026         #
2027         m=MEDCouplingCMesh()
2028         arr=DataArrayDouble(10,1) ; arr.iota(0)
2029         m.setCoords(arr,arr)
2030         m=m.buildUnstructured()
2031         m.setName("mm")
2032         f=m.getMeasureField(ON_CELLS)
2033         self.assertIn(m.getHeapMemorySize(),xrange(3552-100,3552+100+4*strMulFac))
2034         self.assertIn(f.getHeapMemorySize(),xrange(4215-100,4215+100+8*strMulFac))
2035         #
2036         mm=MEDFileUMesh()
2037         mm.setMeshAtLevel(0,m)
2038         self.assertIn(mm.getHeapMemorySize(),xrange(3889-100,3889+100+10*strMulFac))
2039         ff=MEDFileField1TS()
2040         ff.setFieldNoProfileSBT(f)
2041         self.assertIn(ff.getHeapMemorySize(),xrange(771-40,771+21+(4+1)*strMulFac))
2042         #
2043         fff=MEDFileFieldMultiTS()
2044         fff.appendFieldNoProfileSBT(f)
2045         self.assertIn(fff.getHeapMemorySize(),xrange(815-50,815+30+(6+2)*strMulFac))
2046         f.setTime(1.,0,-1)
2047         fff.appendFieldNoProfileSBT(f)
2048         self.assertIn(fff.getHeapMemorySize(),xrange(1594-90,1594+50+(10+1)*strMulFac))
2049         self.assertIn(fff[0,-1].getHeapMemorySize(),xrange(771-40,771+20+(4+1)*strMulFac))
2050         f2=f[:50]
2051         f2.setTime(2.,1,-1)
2052         pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2053         fff.appendFieldProfile(f2,mm,0,pfl)
2054         self.assertIn(fff.getHeapMemorySize(),xrange(2348-130,2348+100+(10+2)*strMulFac))
2055         self.assertIn(fff.getProfile("pfl").getHeapMemorySize(),xrange(204-10,204+10+2*strMulFac))
2056         self.assertIn(fff[1,-1].getHeapMemorySize(),xrange(738-50,738+30+4*strMulFac))
2057         pass
2058
2059     def testCurveLinearMesh1(self):
2060         fname="Pyfile55.med"
2061         mesh=MEDCouplingCurveLinearMesh();
2062         mesh.setTime(2.3,4,5);
2063         mesh.setTimeUnit("us");
2064         mesh.setName("Example of Cuve linear mesh");
2065         mesh.setDescription("buildCLMesh");
2066         a1=DataArrayDouble(3*20,1);
2067         a1.iota(7.) ; a1.rearrange(3);
2068         mesh.setCoords(a1);
2069         mesh.setNodeGridStructure([4,5]);
2070         mesh.checkCoherency();
2071         #
2072         m=MEDFileCurveLinearMesh()
2073         m.setMesh(mesh)
2074         d=DataArrayInt(20) ; d.iota(4)
2075         m.setFamilyFieldArr(1,d)
2076         d3=DataArrayInt(20) ; d3.iota(400)
2077         m.setRenumFieldArr(1,d3)
2078         d2=DataArrayInt(12) ; d2.iota(40)
2079         m.setFamilyFieldArr(0,d2)
2080         d4=DataArrayInt(21) ; d4.iota(4000)
2081         self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2082         d4.popBackSilent()
2083         m.setRenumFieldArr(1,d4)
2084         m.write(fname,2)
2085         #
2086         m1=MEDFileCurveLinearMesh(fname)
2087         mm=m1.getMesh()
2088         self.assertTrue(mm.isEqual(mesh,1e-12))
2089         self.assertEqual(mm.getSpaceDimension(),3)
2090         self.assertEqual(mm.getSpaceDimensionOnNodeStruct(),2)
2091         #
2092         m1=MEDFileMesh.New(fname)
2093         self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2094         self.assertTrue(isinstance(m1.getUnivName(),str))
2095         self.assertTrue(len(m1.getUnivName())!=0)
2096         self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2097         pass
2098
2099     def testParameters1(self):
2100         fname="Pyfile56.med"
2101         m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2102         mm=MEDFileCMesh() ; mm.setMesh(m)
2103         ms=MEDFileMeshes() ; ms.pushMesh(mm)
2104         data=MEDFileData()
2105         p=MEDFileParameters()
2106         data.setParams(p) ; data.setMeshes(ms)
2107         pts=MEDFileParameterMultiTS()
2108         pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2109         pts.appendValue(1,2,3.4,567.89)
2110         pts.appendValue(2,3,5.6,999.123)
2111         pts2=pts.deepCpy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2112         p.pushParam(pts) ; p.pushParam(pts2)
2113         data.write(fname,2)
2114         p2=MEDFileParameters(fname)
2115         self.assertTrue(p.isEqual(p2,1e-14)[0])
2116         self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2117         p3=p.deepCpy()
2118         pts4=pts2.deepCpy()
2119         pts3=pts2.deepCpy()
2120         self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2121         pts2.eraseTimeStepIds([0])
2122         self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2123         del pts3[[3.4]]
2124         self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2125         self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2126         self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2127         self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2128         self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2129         p=p3
2130         self.assertTrue(p.isEqual(p2,1e-14)[0])
2131         self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2132         self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2133         self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2134         self.assertEqual(p.getParamsNames(),('A','B'))
2135         ptsr=MEDFileParameterMultiTS(fname,"B")
2136         self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2137         ptsr=MEDFileParameterMultiTS(fname)
2138         self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2139         p1tsr=MEDFileParameterDouble1TS(fname)
2140         self.assertEqual(p1tsr.getName(),"A")
2141         self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2142         p1tsr=MEDFileParameterDouble1TS(fname,"B")
2143         self.assertEqual(p1tsr.getName(),"B")
2144         self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2145         p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2146         self.assertEqual(p1tsr.getName(),"B")
2147         self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2148         data2=MEDFileData(fname)
2149         self.assertEqual(2,data2.getNumberOfParams())
2150         self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2151         pass
2152
2153     def testNamesOnCellAndNodesInMeshes1(self):
2154         fname="Pyfile58.med"
2155         fname2="Pyfile59.med"
2156         m=MEDLoaderDataForTest.build3DSurfMesh_1()
2157         m1=m.buildDescendingConnectivity()[0]
2158         m1.sortCellsInMEDFileFrmt()
2159         #
2160         mm=MEDFileUMesh()
2161         mm.setMeshAtLevel(0,m)
2162         mm.setMeshAtLevel(-1,m1)
2163         namesCellL0=DataArrayAsciiChar(6,16)
2164         namesCellL0[:]=["CellL0#%.3d      "%(i) for i in xrange(6)]
2165         mm.setNameFieldAtLevel(0,namesCellL0)
2166         namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.substr(2)])
2167         namesCellL1[:]=["CellLM1#%.3d     "%(i) for i in xrange(16)]
2168         mm.setNameFieldAtLevel(-1,namesCellL1)
2169         namesNodes=namesCellL1.substr(4,16)
2170         namesNodes[:]=["Node#%.3d        "%(i) for i in xrange(12)]
2171         mm.setNameFieldAtLevel(1,namesNodes)
2172         mm.write(fname,2)
2173         #
2174         mmr=MEDFileMesh.New(fname)
2175         self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d      "%(i) for i in xrange(6)])))
2176         self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d     "%(i) for i in xrange(16)])))
2177         self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d        "%(i) for i in xrange(12)])))
2178         self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2179         mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2180         self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2181         mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2182         self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2183         mmCpy=mm.deepCpy()
2184         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2185         # remove names on nodes
2186         mmCpy.setNameFieldAtLevel(1,None)
2187         self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2188         mm.setNameFieldAtLevel(1,None)
2189         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2190         mm.setNameFieldAtLevel(-1,None)
2191         mm.write(fname,2)
2192         mmr=MEDFileMesh.New(fname)
2193         self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2194         self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d      "%(i) for i in xrange(6)])))
2195         self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2196         #
2197         c=MEDCouplingCMesh()
2198         arr=DataArrayDouble([0.,1.1,2.3])
2199         c.setCoords(arr,arr)
2200         c.setName("cmesh")
2201         cc=MEDFileCMesh()
2202         cc.setMesh(c)
2203         cc.setNameFieldAtLevel(0,DataArrayAsciiChar(["Cell#%.3d        "%(i) for i in xrange(4)]))
2204         cc.setNameFieldAtLevel(1,DataArrayAsciiChar(["Node#%.3d        "%(i) for i in xrange(9)]))
2205         cc.write(fname2,2)
2206         ccr=MEDFileMesh.New(fname2)
2207         self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d        "%(i) for i in xrange(4)])))
2208         self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d        "%(i) for i in xrange(9)])))
2209         self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2210         ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2211         self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2212         ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2213         self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2214         ccCpy=cc.deepCpy()
2215         self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2216         pass
2217
2218     def testToExportInExamples1(self):
2219         m=MEDCouplingCMesh()
2220         arr=DataArrayDouble([0.,1.,2.,3.,4.])
2221         m.setCoords(arr,arr)
2222         m=m.buildUnstructured() ; m.setName("mesh")
2223         grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2224         grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2225         m2=m.computeSkin()
2226         mm=MEDFileUMesh()
2227         mm.setMeshAtLevel(0,m)
2228         mm.setMeshAtLevel(-1,m2)
2229         mm.setGroupsAtLevel(0,[grp1,grp2])
2230         mm.write("example.med",2)
2231         #
2232         m0=mm.getMeshAtLevel(0)
2233         m1=mm.getMeshAtLevel(-1)
2234         grp1=mm.getGroupArr(0,"grp1")
2235         grp2=mm.getGroupArr(0,"grp2")
2236         grps=[grp1,grp2]
2237         whichGrp=DataArrayInt(m0.getNumberOfCells())
2238         whichGrp.fillWithValue(-1)
2239         for grpId,grp in enumerate(grps):
2240             whichGrp[grp]=grpId
2241             pass
2242         a,b,bI,c,cI=m0.buildDescendingConnectivity()
2243         e,f=a.areCellsIncludedIn(m1,2)
2244         self.assertTrue(e)
2245         c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2246         self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2247         c2.transformWithIndArr(whichGrp)
2248         splitOfM1=len(grps)*[None]
2249         for grpId,grp in enumerate(grps):
2250             tmp=c2.getIdsEqual(grpId)
2251             splitOfM1[grpId]=tmp
2252             pass
2253         splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2254         splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2255         pass
2256
2257     def testBugCorrection1(self):
2258         fs=MEDFileFields()
2259         fs.resize(3)
2260         self.assertEqual(fs[0],None)
2261         self.assertEqual(3,len(fs))
2262         pass
2263
2264     def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2265         f1Name="Pyfile60.med"
2266         f2Name="Pyfile61.med"
2267         d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2268         d1.write(f1Name,2)
2269         d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2270         d2.write(f2Name,2)
2271         # reading and compare
2272         d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2273         for mn in d1.getMeshes().getMeshesNames():
2274             m1=d1.getMeshes()[mn]
2275             m2=d2.getMeshes()[mn]
2276             for lev in m1.getNonEmptyLevels():
2277                 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2278                 for grpName in grpsNames:
2279                     self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2280                     pass
2281                 pass
2282             pass
2283         for fieldn in d1.getFields().getFieldsNames():
2284             f1=d1.getFields()[fieldn]
2285             f2=d2.getFields()[fieldn]
2286             for it,order,tim in f1.getTimeSteps():
2287                 f1t=f1[it,order]
2288                 f2t=f2[it,order]
2289                 if len(f1t.getPflsReallyUsed())!=0:
2290                     # profile case
2291                     for lev in f1t.getNonEmptyLevels()[1]:
2292                         arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2293                         arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2294                         self.assertTrue(pfl1.isEqual(pfl2))
2295                         self.assertTrue(arr1.isEqual(arr2,1e-10))
2296                         pass
2297                     pass
2298                 else:
2299                     # no profile case
2300                     for lev in f1t.getNonEmptyLevels()[1]:
2301                         f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2302                         f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2303                         self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2304                         pass
2305                     pass
2306                 pass
2307             pass
2308         pass
2309
2310     def testNonRegBugNormalizeFamIdsMEDFile1(self):
2311         m=MEDCouplingCMesh()
2312         arr=DataArrayDouble([0.,1.,2.,3.,4.])
2313         m.setCoords(arr,arr,arr)
2314         m=m.buildUnstructured()
2315         m2=m.buildDescendingConnectivity()[0]
2316         m.setName("mesh")
2317         g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2318         g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2319         g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2320         g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2321         g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2322         g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2323         mm=MEDFileUMesh()
2324         mm.setMeshAtLevel(0,m)
2325         mm.setGroupsAtLevel(0,[g1,g2])
2326         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2327         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2328         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2329         mm.normalizeFamIdsMEDFile()
2330         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2331         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2332         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2333         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2334         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2335         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2336         for g in mm.getGroupsOnSpecifiedLev(0):
2337             for f in mm.getFamiliesIdsOnGroup(g):
2338                 self.assertTrue(f<0)
2339                 pass
2340             pass
2341         #
2342         mm=MEDFileUMesh()
2343         mm.setMeshAtLevel(0,m)
2344         mm.setMeshAtLevel(-1,m2)
2345         mm.setGroupsAtLevel(0,[g1,g2])
2346         mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2347         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2348         s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2349         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2350         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2351         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2352         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2353         mm.normalizeFamIdsMEDFile()
2354         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2355         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2356         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2357         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2358         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2359         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2360         self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2361         self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2362         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2363         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2364         self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2365         self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2366         for lev in [0,-1]:
2367             for g in mm.getGroupsOnSpecifiedLev(lev):
2368                 for f in mm.getFamiliesIdsOnGroup(g):
2369                     self.assertTrue(f<0)
2370                     pass
2371                 pass
2372             pass
2373          #
2374         mm=MEDFileUMesh()
2375         mm.setMeshAtLevel(0,m)
2376         mm.setMeshAtLevel(-1,m2)
2377         mm.setGroupsAtLevel(0,[g1,g2])
2378         mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2379         mm.setGroupsAtLevel(1,[g1Node,g2Node])
2380         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2381         s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2382         s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2383         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2384         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2385         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2386         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2387         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2388         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2389         mm.normalizeFamIdsMEDFile()
2390         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2391         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2392         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2393         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2394         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2395         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2396         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2397         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2398         self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2399         self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2400         self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2401         self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2402         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2403         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2404         self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2405         self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2406         self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2407         self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2408         for lev in [0,-1]:
2409             for g in mm.getGroupsOnSpecifiedLev(lev):
2410                 for f in mm.getFamiliesIdsOnGroup(g):
2411                     self.assertTrue(f<0)
2412                     pass
2413                 pass
2414             pass
2415         for g in mm.getGroupsOnSpecifiedLev(1):
2416             for f in mm.getFamiliesIdsOnGroup(g):
2417                 self.assertTrue(f>0)
2418                 pass
2419             pass
2420         pass
2421     
2422     def testNonRegressionMantis22212ChangeGrpName(self):
2423         fileName="Pyfile62.med"
2424         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2425         m=MEDFileUMesh.New()
2426         m.setCoords(m2.getCoords())
2427         m.setMeshAtLevel(0,m2)
2428         m.setMeshAtLevel(-1,m1)
2429         m.setMeshAtLevel(-2,m0)
2430         m.setFamilyFieldArr(0,f2)
2431         m.setFamilyFieldArr(-1,f1)
2432         m.setFamilyFieldArr(-2,f0)
2433         m.setFamilyFieldArr(1,p)
2434         nbOfFams=len(fns)
2435         for i in xrange(nbOfFams):
2436             m.addFamily(fns[i],fids[i])
2437             pass
2438         nbOfGrps=len(grpns)
2439         for i in xrange(nbOfGrps):
2440             m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2441             pass
2442         m.setName(m2.getName())
2443         m.setDescription(m2.getDescription())
2444         m.write(fileName,2)
2445         #
2446         mm0=MEDFileMesh.New(fileName)
2447         mm1=MEDFileMesh.New(fileName)
2448         groupNamesIni=MEDLoader.GetMeshGroupsNames(fileName,"ma")
2449         for name in groupNamesIni:
2450             mm1.changeGroupName(name,name+'N')
2451             pass
2452         mm1.write(fileName,2)
2453         del mm1
2454         #
2455         mm2=MEDFileMesh.New(fileName)
2456         for name in groupNamesIni:
2457             for lev in mm0.getGrpNonEmptyLevelsExt(name):
2458                 arr0=mm0.getGroupArr(lev,name)
2459                 arr2=mm2.getGroupArr(lev,name+'N')
2460                 arr0.setName(name+'N')
2461                 self.assertTrue(arr0.isEqual(arr2))
2462                 pass
2463             pass
2464         pass
2465
2466     def testInt32InMEDFileFieldStar1(self):
2467         fname="Pyfile63.med"
2468         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2469         arr=f1.getArray().convertToIntArr()
2470         f1.setArray(None)
2471         m1=f1.getMesh()
2472         mm1=MEDFileUMesh.New()
2473         mm1.setCoords(m1.getCoords())
2474         mm1.setMeshAtLevel(0,m1)
2475         mm1.setName(m1.getName())
2476         mm1.write(fname,2)
2477         ff1=MEDFileIntField1TS()
2478         ff1.setFieldNoProfileSBT(f1,arr)
2479         a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2480         self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2481         self.assertTrue(b.isEqual(arr))
2482         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2483         ff1.write(fname,0)
2484         ff2=MEDFileAnyTypeField1TS.New(fname)
2485         self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2486         self.assertEqual(ff2.getTime(),[0,1,2.0])
2487         self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2488         a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2489         self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2490         self.assertTrue(b.isEqual(arr))
2491         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2492         ff2.setTime(1,2,3.)
2493         c=ff2.getUndergroundDataArray() ; c*=2
2494         ff2.write(fname,0) # 2 time steps in 
2495         ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2496         self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2497         self.assertEqual(len(ffs1),2)
2498         self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2499         a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2500         self.assertTrue(b.isEqual(arr))
2501         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2502         a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2503         self.assertTrue(b.isEqual(arr))
2504         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2505         it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2506         a,b=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2507         self.assertTrue(b.isEqual(2*arr))
2508         f1.setTime(3.,1,2)
2509         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2510         bc=DataArrayInt(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2511         for it in ffs1:
2512             a,b=it.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2513             bc+=b
2514             pass
2515         self.assertTrue(bc.isEqual(3*arr))
2516         nf1=MEDCouplingFieldDouble(ON_NODES)
2517         nf1.setTime(9.,10,-1)
2518         nf1.setMesh(f1.getMesh())
2519         narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=range(12) ; narr[:,1]=2*narr[:,0]
2520         nf1.setName("VectorFieldOnNodes")
2521         nff1=MEDFileIntField1TS.New()
2522         nff1.setFieldNoProfileSBT(nf1,narr)
2523         self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2524         self.assertEqual(nff1.getTime(),[10,-1,9.0])
2525         nff1.write(fname,0)
2526         #
2527         nf2=MEDCouplingFieldDouble(ON_NODES)
2528         nf2.setTime(19.,20,-11)
2529         nf2.setMesh(f1.getMesh())
2530         narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=range(8) ; narr2[:,0]+=10  ; narr2[:,1]=3*narr2[:,0]
2531         nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName())
2532         nff2=MEDFileIntField1TS.New()
2533         npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
2534         nff2.setFieldProfile(nf2,narr2,mm1,0,npfl)
2535         nff2.getFieldWithProfile(ON_NODES,0,mm1)
2536         a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2537         self.assertTrue(b.isEqual(npfl))
2538         self.assertTrue(a.isEqual(narr2))
2539         nff2.write(fname,0)
2540         nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
2541         a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2542         self.assertTrue(b.isEqual(npfl))
2543         self.assertTrue(a.isEqual(narr2))
2544         #
2545         nf3=MEDCouplingFieldDouble(ON_NODES)
2546         nf3.setName("VectorFieldOnNodesDouble")
2547         nf3.setTime(29.,30,-21)
2548         nf3.setMesh(f1.getMesh())
2549         nf3.setArray(f1.getMesh().getCoords())
2550         nff3=MEDFileField1TS.New()
2551         nff3.setFieldNoProfileSBT(nf3)
2552         nff3.write(fname,0)
2553         fs=MEDFileFields(fname)
2554         self.assertEqual(len(fs),4)
2555         ffs=[it for it in fs]
2556         self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
2557         self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
2558         self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
2559         self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
2560         #
2561         self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(arr))
2562         self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*arr))
2563         self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
2564         self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
2565         self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2566         #
2567         nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
2568         self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2569         self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
2570         self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
2571         MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
2572         self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
2573         MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
2574         self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
2575         #
2576         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
2577         self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2578         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
2579         self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2580         pass
2581
2582     def testMEDFileFields1(self):
2583         fname="Pyfile64.med"
2584         f1=MEDCouplingFieldDouble(ON_NODES)
2585         f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
2586         c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
2587         mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
2588         f1.setMesh(m)
2589         arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=range(12) ; arr[:,1]=2*arr[:,0]
2590         f1.setArray(arr)
2591         f1.setName("Field1")
2592         ff1=MEDFileField1TS.New()
2593         ff1.setFieldNoProfileSBT(f1)
2594         self.assertEqual(ff1.getDtUnit(),"us")
2595         ff1.write(fname,0)
2596         f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2597         f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2598         #
2599         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2600         ff1s=MEDFileFieldMultiTS(fname,"Field1")
2601         ff1s.setName("Field2")
2602         ff1s.write(fname,0)
2603         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2604         f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2605         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
2606         self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
2607         self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
2608         f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2609         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
2610         self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
2611         pass
2612
2613     # Multi time steps and multi fields management without Globals (profiles, locs) aspects
2614     def testMEDFileFields2(self):
2615         fname="Pyfile65.med"
2616         # to check that all is initialize 
2617         MEDFileField1TS().__str__()
2618         MEDFileFieldMultiTS().__str__()
2619         # building a mesh containing 4 tri3 + 5 quad4
2620         tri=MEDCouplingUMesh("tri",2)
2621         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2622         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2623         tris=[tri.deepCpy() for i in xrange(4)]
2624         for i,elt in enumerate(tris): elt.translate([i,0])
2625         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2626         quad=MEDCouplingUMesh("quad",2)
2627         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2628         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2629         quads=[quad.deepCpy() for i in xrange(5)]
2630         for i,elt in enumerate(quads): elt.translate([5+i,0])
2631         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2632         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2633         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2634         #
2635         fmts0_0=MEDFileFieldMultiTS()
2636         fmts0_1=MEDFileFieldMultiTS()
2637         # time steps
2638         for i in xrange(10):
2639             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2640             d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2641             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2642             f.setTime(float(i+1)+0.1,i+1,-i-1)
2643             fmts0_0.appendFieldNoProfileSBT(f)
2644             f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
2645             self.assertEqual(fmts0_1.getName(),name1)
2646             self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2647             self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2648             if i>1:
2649                 # components names have been modified to generate errors
2650                 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
2651                 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
2652                 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
2653                 f1ts.setInfo(['aa [bb]','eee [dd]'])
2654                 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
2655                 pass
2656             # add a mismatch of nb of compos
2657             pass
2658         fmts0_2=fmts0_0.deepCpy()
2659         fmts0_3=fmts0_0.deepCpy()
2660         fmts0_4=fmts0_0.deepCpy()
2661         fmts0_5=fmts0_0.shallowCpy()
2662         self.assertTrue(len(fmts0_0)==10 and len(fmts0_1)==10 and len(fmts0_2)==10 and len(fmts0_3)==10 and len(fmts0_4)==10 and len(fmts0_5)==10)
2663         del fmts0_2[::2]
2664         self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
2665         del fmts0_3[[1.1,(6,-6),9]]
2666         self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
2667         fmts0_6=fmts0_4[[1.1,(6,-6),8]]
2668         self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
2669         self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
2670         fmts0_7=fmts0_4[::-3]
2671         self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
2672         self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
2673         #
2674         fs0=MEDFileFields()
2675         fs0.pushField(fmts0_0)
2676         fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2677         fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2678         fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2679         self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
2680         fs0.write(fname,2)
2681         fs0=MEDFileFields(fname)
2682         self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
2683         fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
2684         self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2685         del fs1[["2ndField",3]]
2686         self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2687         fs2=fs0[[0,"4thField"]]
2688         self.assertTrue(isinstance(fs2,MEDFileFields))
2689         self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
2690         #
2691         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
2692         pass
2693
2694     # Multi time steps and multi fields management with Globals (profiles, locs) aspects
2695     def testMEDFileFields3(self):
2696         fname="Pyfile66.med"
2697         # building a mesh containing 4 tri3 + 5 quad4
2698         tri=MEDCouplingUMesh("tri",2)
2699         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2700         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2701         tris=[tri.deepCpy() for i in xrange(4)]
2702         for i,elt in enumerate(tris): elt.translate([i,0])
2703         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2704         quad=MEDCouplingUMesh("quad",2)
2705         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2706         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2707         quads=[quad.deepCpy() for i in xrange(5)]
2708         for i,elt in enumerate(quads): elt.translate([5+i,0])
2709         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2710         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2711         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2712         #
2713         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2714         #
2715         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2716         pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2717         fmts0_0=MEDFileFieldMultiTS()
2718         fmts0_1=MEDFileFieldMultiTS()
2719         # time steps
2720         for i in xrange(10):
2721             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2722             d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2723             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2724             f.setTime(float(i+1)+0.1,i+1,-i-1)
2725             fmts0_0.appendFieldProfile(f,mm,0,pfl)
2726             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2727             self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2728             self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2729             pass
2730         #
2731         self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
2732         self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
2733         fmts0_0.zipPflsNames()
2734         self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
2735         self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
2736         fmts0_2=fmts0_0.deepCpy()
2737         fmts0_3=fmts0_0.deepCpy()
2738         fmts0_4=fmts0_0.deepCpy()
2739         fs0=MEDFileFields()
2740         fs0.pushField(fmts0_0)
2741         fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2742         fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2743         fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2744         self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
2745         #
2746         fmts0_5=MEDFileFieldMultiTS()
2747         for i in xrange(7):
2748             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2749             d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2750             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2751             f.setTime(float(i+1)+0.1,i+1,-i-1)
2752             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
2753             pass
2754         fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
2755         self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
2756         fs0.checkGlobsCoherency()
2757         fs0.write(fname,0)
2758         pass
2759     
2760     def testSplitComponents1(self):
2761         fname="Pyfile67.med"
2762         # building a mesh containing 4 tri3 + 5 quad4
2763         tri=MEDCouplingUMesh("tri",2)
2764         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2765         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2766         tris=[tri.deepCpy() for i in xrange(4)]
2767         for i,elt in enumerate(tris): elt.translate([i,0])
2768         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2769         quad=MEDCouplingUMesh("quad",2)
2770         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2771         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2772         quads=[quad.deepCpy() for i in xrange(5)]
2773         for i,elt in enumerate(quads): elt.translate([5+i,0])
2774         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2775         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2776         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2777         #
2778         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2779         #
2780         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2781         pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2782         fs=MEDFileFields()
2783         fmts0_1=MEDFileFieldMultiTS()
2784         # time steps
2785         infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
2786         for i in xrange(10):
2787             name1="1stField"
2788             d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2789             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2790             f.setTime(float(i+1)+0.1,i+1,-i-1)
2791             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2792             self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
2793             pass
2794         fs.pushField(fmts0_1)
2795         self.assertEqual(1,len(fs))
2796         l=fmts0_1.splitComponents()
2797         self.assertEqual(3,len(l))
2798         for elt in l: self.assertEqual(10,len(elt))
2799         for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
2800         for elt in l:
2801             elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
2802             pass
2803         fs.pushFields(l)
2804         self.assertEqual(4,len(fs))
2805         for elt in fs: self.assertEqual(10,len(elt))
2806         self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
2807         self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2808         #
2809         fs.write(fname,0) ; del fs
2810         #
2811         fs1=MEDFileFields(fname)
2812         self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
2813         self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2814         self.assertEqual(4,len(fs1))
2815         for i in xrange(10):
2816             for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
2817                 f1ts=fs1[fieldName][i]
2818                 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2819                 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
2820                 self.assertTrue(d.isEqual(f.getArray(),1e-13))
2821                 pass
2822             f1ts=fs1["1stField"][i]
2823             f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2824             d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2825             self.assertTrue(d.isEqual(f.getArray(),1e-13))
2826             pass
2827         pass
2828
2829     def testMEDFileFieldConvertTo1(self):
2830         fname="Pyfile68.med"
2831         # building a mesh containing 4 tri3 + 5 quad4
2832         tri=MEDCouplingUMesh("tri",2)
2833         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2834         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2835         tris=[tri.deepCpy() for i in xrange(4)]
2836         for i,elt in enumerate(tris): elt.translate([i,0])
2837         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2838         quad=MEDCouplingUMesh("quad",2)
2839         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2840         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2841         quads=[quad.deepCpy() for i in xrange(5)]
2842         for i,elt in enumerate(quads): elt.translate([5+i,0])
2843         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2844         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2845         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2846         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
2847         #
2848         ff0=MEDFileField1TS()
2849         f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCell")
2850         f0.checkCoherency()
2851         ff0.setFieldNoProfileSBT(f0)
2852         #
2853         fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
2854         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2855         #
2856         ff0i=ff0.convertToInt()
2857         self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
2858         self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
2859         #
2860         ff1=ff0i.convertToDouble()
2861         self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
2862         self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
2863         # With profiles
2864         del arr,f0,ff0,ff1,ff0i,fspExp
2865         ff0=MEDFileField1TS()
2866         f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["XX [pm]","YYY [hm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellPfl")
2867         f0.checkCoherency()
2868         pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
2869         ff0.setFieldProfile(f0,mm,0,pfl)
2870         fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
2871         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2872         #
2873         ff0i=ff0.convertToInt()
2874         self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
2875         self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
2876         self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
2877         #
2878         ff1=ff0i.convertToDouble()
2879         self.assertTrue(isinstance(ff1,MEDFileField1TS))
2880         self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
2881         self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
2882         ## MultiTimeSteps
2883         ff0=MEDFileFieldMultiTS()
2884         f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(0.1,0,10)
2885         f0.checkCoherency()
2886         ff0.appendFieldProfile(f0,mm,0,pfl)
2887         f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota(100) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(1.1,1,11)
2888         f0.checkCoherency()
2889         ff0.appendFieldProfile(f0,mm,0,pfl)
2890         f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota(200) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(2.1,2,12)
2891         f0.checkCoherency()
2892         ff0.appendFieldProfile(f0,mm,0,pfl)
2893         ff1=ff0.convertToInt()
2894         self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
2895         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2896         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
2897             self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
2898             arr=ff1.getUndergroundDataArray(dt,it)
2899             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
2900             pass
2901         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
2902         #
2903         mm.write(fname,2)
2904         ff1.write(fname,0)
2905         #
2906         ff1=ff1.convertToDouble()
2907         self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
2908         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2909         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
2910             self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
2911             arr=ff1.getUndergroundDataArray(dt,it)
2912             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
2913             pass
2914         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
2915         #
2916         ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
2917         self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
2918         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2919         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
2920             self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
2921             arr=ff1.getUndergroundDataArray(dt,it)
2922             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
2923             pass
2924         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
2925         pass
2926
2927     def testMEDFileFieldPartialLoading(self):
2928         fname="Pyfile69.med"
2929         #
2930         a=DataArrayInt() ; aa=a.getHeapMemorySize()
2931         a.alloc(0,1)
2932         strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
2933         # building a mesh containing 30 tri3 + 40 quad4
2934         tri=MEDCouplingUMesh("tri",2)
2935         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2936         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2937         tris=[tri.deepCpy() for i in xrange(30)]
2938         for i,elt in enumerate(tris): elt.translate([i,0])
2939         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2940         quad=MEDCouplingUMesh("quad",2)
2941         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2942         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2943         quads=[quad.deepCpy() for i in xrange(40)]
2944         for i,elt in enumerate(quads): elt.translate([40+i,0])
2945         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2946         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2947         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2948         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2949         #
2950         ff0=MEDFileField1TS()
2951         f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCell")
2952         f0.checkCoherency()
2953         ff0.setFieldNoProfileSBT(f0)
2954         ff0.write(fname,0)
2955         #
2956         fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
2957         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2958         # With profiles
2959         ff0=MEDFileField1TS()
2960         f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:50]) ; arr=DataArrayDouble(50*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["XX [pm]","YYY [hm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellPfl")
2961         f0.checkCoherency()
2962         pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2963         ff0.setFieldProfile(f0,mm,0,pfl)
2964         fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
2965         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2966         ff0.write(fname,0)
2967         #
2968         ff0=MEDFileField1TS(fname,False)
2969         self.assertEqual(ff0.getName(),"FieldCell")
2970         self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
2971         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
2972         heap_memory_ref=ff0.getHeapMemorySize()
2973         self.assertIn(heap_memory_ref,xrange(182,298+2*strMulFac))
2974         ff0.loadArrays() ##
2975         arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
2976         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2977         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
2978         #
2979         ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
2980         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
2981         heap_memory_ref=ff0.getHeapMemorySize()
2982         self.assertIn(heap_memory_ref,xrange(350,415+6*strMulFac))
2983         ff0.loadArrays() ##
2984         arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
2985         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2986         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
2987         ff0.loadArrays() ##
2988         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2989         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
2990         ff0.getUndergroundDataArray().setIJ(30,1,5.5)
2991         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2992         ff0.loadArrays() ##
2993         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2994         ff0.getUndergroundDataArray().setIJ(30,1,5.5)
2995         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2996         ff0.loadArraysIfNecessary() ##
2997         self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
2998         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2999         heap_memory_ref=ff0.getHeapMemorySize()
3000         self.assertIn(heap_memory_ref,xrange(1100,1215+2*strMulFac))
3001         ff0.unloadArrays()
3002         hmd=ff0.getHeapMemorySize()-heap_memory_ref
3003         self.assertEqual(hmd,-800) # -50*8*2
3004         ff0.loadArrays() ##
3005         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
3006         #
3007         ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
3008         heap_memory_ref=ff0.getHeapMemorySize()
3009         self.assertIn(heap_memory_ref,xrange(299,415+6*strMulFac))
3010         ff0.loadArrays() ##
3011         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3012         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3013         #
3014         fieldName="FieldCellMultiTS"
3015         ff0=MEDFileFieldMultiTS()
3016         for t in xrange(20):
3017             f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota(float(t+1000)) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName(fieldName)
3018             f0.setTime(float(t)+0.1,t,100+t)
3019             f0.checkCoherency()
3020             ff0.appendFieldNoProfileSBT(f0)
3021             pass
3022         ff0.write(fname,0)
3023         #
3024         ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
3025         heap_memory_ref=ff0.getHeapMemorySize()
3026         self.assertIn(heap_memory_ref,xrange(5536,5956+(80+26)*strMulFac))
3027         ff0.loadArrays()
3028         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
3029         del ff0
3030         #
3031         ffs=MEDFileFields(fname,False)
3032         heap_memory_ref=ffs.getHeapMemorySize()
3033         self.assertIn(heap_memory_ref,xrange(5335,6687+(80+50)*strMulFac))
3034         ffs.loadArrays()
3035         self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
3036         pass
3037
3038     def testMEDFileMeshReadSelector1(self):
3039         mrs=MEDFileMeshReadSelector()
3040         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3041         mrs.__str__() ; mrs.__repr__()
3042         #
3043         mrs=MEDFileMeshReadSelector(0)
3044         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3045         mrs=MEDFileMeshReadSelector(1)
3046         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3047         mrs=MEDFileMeshReadSelector(2)
3048         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3049         mrs=MEDFileMeshReadSelector(3)
3050         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3051         mrs=MEDFileMeshReadSelector(4)
3052         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3053         mrs=MEDFileMeshReadSelector(5)
3054         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3055         mrs=MEDFileMeshReadSelector(6)
3056         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3057         mrs=MEDFileMeshReadSelector(7)
3058         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3059         mrs=MEDFileMeshReadSelector(8)
3060         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3061         mrs=MEDFileMeshReadSelector(9)
3062         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3063         mrs=MEDFileMeshReadSelector(10)
3064         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3065         mrs=MEDFileMeshReadSelector(11)
3066         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3067         mrs=MEDFileMeshReadSelector(12)
3068         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3069         mrs=MEDFileMeshReadSelector(13)
3070         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3071         mrs=MEDFileMeshReadSelector(14)
3072         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3073         mrs=MEDFileMeshReadSelector(15)
3074         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3075         mrs=MEDFileMeshReadSelector(16)
3076         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3077         mrs=MEDFileMeshReadSelector(17)
3078         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3079         mrs=MEDFileMeshReadSelector(18)
3080         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3081         mrs=MEDFileMeshReadSelector(19)
3082         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3083         mrs=MEDFileMeshReadSelector(20)
3084         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3085         mrs=MEDFileMeshReadSelector(21)
3086         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3087         mrs=MEDFileMeshReadSelector(22)
3088         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3089         mrs=MEDFileMeshReadSelector(23)
3090         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3091         mrs=MEDFileMeshReadSelector(24)
3092         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3093         mrs=MEDFileMeshReadSelector(25)
3094         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3095         mrs=MEDFileMeshReadSelector(26)
3096         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3097         mrs=MEDFileMeshReadSelector(27)
3098         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3099         mrs=MEDFileMeshReadSelector(28)
3100         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3101         mrs=MEDFileMeshReadSelector(29)
3102         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3103         mrs=MEDFileMeshReadSelector(30)
3104         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3105         mrs=MEDFileMeshReadSelector(31)
3106         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3107         mrs=MEDFileMeshReadSelector(32)
3108         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3109         mrs=MEDFileMeshReadSelector(33)
3110         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3111         mrs=MEDFileMeshReadSelector(34)
3112         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3113         mrs=MEDFileMeshReadSelector(35)
3114         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3115         mrs=MEDFileMeshReadSelector(36)
3116         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3117         mrs=MEDFileMeshReadSelector(37)
3118         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3119         mrs=MEDFileMeshReadSelector(38)
3120         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3121         mrs=MEDFileMeshReadSelector(39)
3122         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3123         mrs=MEDFileMeshReadSelector(40)
3124         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3125         mrs=MEDFileMeshReadSelector(41)
3126         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3127         mrs=MEDFileMeshReadSelector(42)
3128         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3129         mrs=MEDFileMeshReadSelector(43)
3130         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3131         mrs=MEDFileMeshReadSelector(44)
3132         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3133         mrs=MEDFileMeshReadSelector(45)
3134         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3135         mrs=MEDFileMeshReadSelector(46)
3136         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3137         mrs=MEDFileMeshReadSelector(47)
3138         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3139         mrs=MEDFileMeshReadSelector(48)
3140         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3141         mrs=MEDFileMeshReadSelector(49)
3142         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3143         mrs=MEDFileMeshReadSelector(50)
3144         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3145         mrs=MEDFileMeshReadSelector(51)
3146         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3147         mrs=MEDFileMeshReadSelector(52)
3148         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3149         mrs=MEDFileMeshReadSelector(53)
3150         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3151         mrs=MEDFileMeshReadSelector(54)
3152         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3153         mrs=MEDFileMeshReadSelector(55)
3154         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3155         mrs=MEDFileMeshReadSelector(56)
3156         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3157         mrs=MEDFileMeshReadSelector(57)
3158         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3159         mrs=MEDFileMeshReadSelector(58)
3160         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3161         mrs=MEDFileMeshReadSelector(59)
3162         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3163         mrs=MEDFileMeshReadSelector(60)
3164         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3165         mrs=MEDFileMeshReadSelector(61)
3166         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3167         mrs=MEDFileMeshReadSelector(62)
3168         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3169         mrs=MEDFileMeshReadSelector(63)
3170         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3171         #
3172         mrs=MEDFileMeshReadSelector(63)
3173         mrs.setCellFamilyFieldReading(False)
3174         self.assertEqual(mrs.getCode(),62)
3175         mrs.setCellFamilyFieldReading(True)
3176         self.assertEqual(mrs.getCode(),63)
3177         mrs.setNodeFamilyFieldReading(False)
3178         self.assertEqual(mrs.getCode(),61)
3179         mrs.setNodeFamilyFieldReading(True)
3180         self.assertEqual(mrs.getCode(),63)
3181         mrs.setCellNameFieldReading(False)
3182         self.assertEqual(mrs.getCode(),59)
3183         mrs.setCellNameFieldReading(True)
3184         self.assertEqual(mrs.getCode(),63)
3185         mrs.setNodeNameFieldReading(False)
3186         self.assertEqual(mrs.getCode(),55)
3187         mrs.setNodeNameFieldReading(True)
3188         self.assertEqual(mrs.getCode(),63)
3189         mrs.setCellNumFieldReading(False)
3190         self.assertEqual(mrs.getCode(),47)
3191         mrs.setCellNumFieldReading(True)
3192         self.assertEqual(mrs.getCode(),63)
3193         mrs.setNodeNumFieldReading(False)
3194         self.assertEqual(mrs.getCode(),31)
3195         mrs.setNodeNumFieldReading(True)
3196         self.assertEqual(mrs.getCode(),63)
3197         pass
3198     
3199     def testPartialReadOfMeshes(self):
3200         fname="Pyfile70.med"
3201         # building a mesh containing 4 tri3 + 5 quad4
3202         tri=MEDCouplingUMesh("tri",2)
3203         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3204         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3205         tris=[tri.deepCpy() for i in xrange(4)]
3206         for i,elt in enumerate(tris): elt.translate([i,0])
3207         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3208         quad=MEDCouplingUMesh("quad",2)
3209         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3210         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3211         quads=[quad.deepCpy() for i in xrange(5)]
3212         for i,elt in enumerate(quads): elt.translate([5+i,0])
3213         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3214         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3215         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3216         m1=m.buildDescendingConnectivity()[0]
3217         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3218         #
3219         grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3220         grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3221         mm.setGroupsAtLevel(0,[grp0,grp1])
3222         grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3223         grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3224         mm.setGroupsAtLevel(-1,[grp2,grp3])
3225         grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3226         grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3227         mm.setGroupsAtLevel(1,[grp4,grp5])
3228         mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3229         mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3230         mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3231         #
3232         mm.write(fname,2)
3233         ##
3234         mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3235         b4_ref_heap_mem=mm.getHeapMemorySize()
3236         mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
3237         mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
3238         ref_heap_mem=mm.getHeapMemorySize()
3239         # check the gain of memory using 1GTUMesh instead of UMesh
3240         self.assertTrue(ref_heap_mem-b4_ref_heap_mem>=(32+9)*4*2-32)# 32+9=nbCells 4=sizeof(int) 2=the types+index -32=loss linked to vector
3241         #
3242         mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3243         self.assertEqual(len(mm.getGroupsNames()),0)
3244         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3245         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3246         self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3247         self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3248         self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3249         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3250         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3251         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3252         delta1=ref_heap_mem-mm.getHeapMemorySize()
3253         self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3254         #
3255         mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3256         self.assertEqual(len(mm.getGroupsNames()),6)
3257         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3258         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3259         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3260         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3261         self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3262         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3263         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3264         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3265         delta2=ref_heap_mem-mm.getHeapMemorySize()
3266         self.assertTrue(delta2<delta1)
3267         self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3268         #
3269         mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3270         self.assertEqual(len(mm.getGroupsNames()),6)
3271         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3272         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3273         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3274         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3275         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3276         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3277         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3278         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3279         delta3=ref_heap_mem-mm.getHeapMemorySize()
3280         self.assertTrue(delta3<delta2)
3281         self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3282         #
3283         mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3284         self.assertEqual(len(mm.getGroupsNames()),6)
3285         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3286         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3287         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3288         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3289         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3290         self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3291         self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3292         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3293         delta4=ref_heap_mem-mm.getHeapMemorySize()
3294         self.assertTrue(delta4<delta3)
3295         self.assertTrue(delta4>=32*4*2)
3296         #
3297         mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3298         self.assertEqual(len(mm.getGroupsNames()),6)
3299         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3300         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3301         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3302         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3303         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3304         self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3305         self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3306         self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3307         delta5=ref_heap_mem-mm.getHeapMemorySize()
3308         self.assertTrue(delta5<delta4)
3309         self.assertEqual(delta5,0)
3310         pass
3311
3312     # this test checks that setFieldProfile perform a check of the array length
3313     # compared to the profile length. This test also checks that mesh attribute of field
3314     # is not used by setFieldProfile (because across this test mesh is equal to None)
3315     def testCheckCompatibilityPfl1(self):
3316         # building a mesh containing 4 tri3 + 5 quad4
3317         tri=MEDCouplingUMesh("tri",2)
3318         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3319         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3320         tris=[tri.deepCpy() for i in xrange(4)]
3321         for i,elt in enumerate(tris): elt.translate([i,0])
3322         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3323         quad=MEDCouplingUMesh("quad",2)
3324         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3325         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3326         quads=[quad.deepCpy() for i in xrange(5)]
3327         for i,elt in enumerate(quads): elt.translate([5+i,0])
3328         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3329         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3330         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3331         m1=m.buildDescendingConnectivity()[0]
3332         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3333         #
3334         f1ts=MEDFileField1TS()
3335         f=MEDCouplingFieldDouble(ON_NODES)
3336         vals=DataArrayDouble(7) ; vals.iota(1000)
3337         f.setArray(vals)
3338         f.setName("anonymous") # f has no mesh it is not a bug
3339         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3340         f1ts.setFieldProfile(f,mm,0,pfl)
3341         #
3342         f1ts=MEDFileField1TS()
3343         f=MEDCouplingFieldDouble(ON_NODES)
3344         vals=DataArrayDouble(8) ; vals.iota(1000)
3345         f.setArray(vals)
3346         f.setName("anonymous") # f has no mesh it is not a bug
3347         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3348         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3349         #
3350         f1ts=MEDFileField1TS()
3351         f=MEDCouplingFieldDouble(ON_CELLS)
3352         vals=DataArrayDouble(7) ; vals.iota(1000)
3353         f.setArray(vals)
3354         f.setName("anonymous") # f has no mesh it is not a bug
3355         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3356         f1ts.setFieldProfile(f,mm,0,pfl)
3357         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3358         #
3359         f1ts=MEDFileField1TS()
3360         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3361         vals=DataArrayDouble(27) ; vals.iota(1000)
3362         f.setArray(vals)
3363         f.setName("anonymous") # f has no mesh it is not a bug
3364         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3365         f.setMesh(m[pfl])
3366         f.setGaussLocalizationOnCells([0,1],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.1,0.1],[0.3,0.6,0.1])
3367         f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3368         f.setGaussLocalizationOnCells([3,4,5,6],[0.,0.,1.,0.,1.,1.,0.,1.],[0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.5,0.5],[0.2,0.3,0.4,0.07,0.03])
3369         f.setMesh(None)
3370         f1ts.setFieldProfile(f,mm,0,pfl)
3371         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3372         vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3373         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3374         vals=DataArrayDouble(27) ; vals.iota(1000)
3375         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3376         #
3377         f1ts=MEDFileField1TS()
3378         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3379         vals=DataArrayDouble(25) ; vals.iota(1000)
3380         f.setArray(vals)
3381         f.setName("anonymous") # f has no mesh it is not a bug
3382         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3383         f1ts.setFieldProfile(f,mm,0,pfl)
3384         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3385         vals2=DataArrayDouble(26) ; vals2.iota(1050)
3386         f.setArray(vals2)
3387         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3388         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3389         #
3390         f1ts=MEDFileField1TS()
3391         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3392         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3393         f.setArray(vals)
3394         f1ts.setFieldProfile(f,mm,0,pfl)
3395         pass
3396     
3397     def testWRMeshWithNoCells(self):
3398         fname="Pyfile71.med"
3399         a=DataArrayDouble(4) ; a.iota()
3400         c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
3401         m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
3402         m=MEDFileUMesh()
3403         m.setMeshAtLevel(0,m00)
3404         m.setRenumFieldArr(1,DataArrayInt(range(10,26)))
3405         m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
3406         m.write(fname,2)
3407         del m,a,c,m0,m00
3408         #
3409         m=MEDFileMesh.New(fname)
3410         self.assertEqual((),m.getNonEmptyLevels())
3411         self.assertTrue(m.getCoords().isEqual(DataArrayDouble([(0,0),(1,0),(2,0),(3,0),(0,1),(1,1),(2,1),(3,1),(0,2),(1,2),(2,2),(3,2),(0,3),(1,3),(2,3),(3,3)]),1e-12))
3412         self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(range(10,26))))
3413         self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
3414         pass
3415
3416     def testWRQPolyg1(self):
3417         fname="Pyfile72.med"
3418         m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
3419         m.insertNextCell([0,2,1,3])
3420         m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
3421         #
3422         ms=[m.deepCpy() for i in xrange(4)]
3423         for i,elt in enumerate(ms):
3424             elt.translate([float(i)*1.5,0.])
3425             pass
3426         m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3427         m0.convertAllToPoly()
3428         #
3429         ms=[m.deepCpy() for i in xrange(5)]
3430         for i,elt in enumerate(ms):
3431             elt.translate([float(i)*1.5,1.5])
3432             pass
3433         m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3434         m1.convertAllToPoly()
3435         m1.convertLinearCellsToQuadratic()
3436         #
3437         m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
3438         ##
3439         mm=MEDFileUMesh()
3440         mm.setMeshAtLevel(0,m)
3441         grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
3442         grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
3443         grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
3444         mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3445         ##
3446         mm.write(fname,2)
3447         del mm
3448         #
3449         mm_read=MEDFileUMesh(fname)
3450         self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
3451         self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
3452         self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
3453         self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
3454         ##
3455         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
3456         f.setMesh(m)
3457         arr0=DataArrayDouble(9) ; arr0.iota()
3458         arr1=DataArrayDouble(9) ; arr1.iota(100)
3459         arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
3460         f.setArray(arr) ; f.checkCoherency()
3461         f.setTime(5.6,1,2)
3462         ff=MEDFileField1TS()
3463         ff.setFieldNoProfileSBT(f)
3464         ff.write(fname,0)
3465         ##
3466         ff_read=MEDFileField1TS(fname)
3467         f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
3468         self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
3469         pass
3470
3471     def testLoadIfNecessaryOnFromScratchFields0(self):
3472         """
3473         This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
3474         """
3475         fname="Pyfile77.med"
3476         coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
3477         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
3478         m.allocateCells()
3479         m.insertNextCell(NORM_QUAD4,[0,5,3,2])
3480         m.insertNextCell(NORM_QUAD4,[4,2,3,1])
3481         m.finishInsertingCells()
3482         #
3483         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3484         ms=MEDFileMeshes() ; ms.pushMesh(mm)
3485         fs=MEDFileFields()
3486         arrs=4*[None]
3487         #
3488         ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
3489         f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
3490         f0.setTime(1.1,1,1)
3491         f0.setName("myELNOField")
3492         arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
3493         f0.setArray(arrs[0])
3494         ff0.appendFieldNoProfileSBT(f0)
3495         #
3496         f0.setTime(2.2,2,1)
3497         arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
3498         f0.setArray(arrs[1])
3499         ff0.appendFieldNoProfileSBT(f0)
3500         #
3501         f0.setTime(3.3,3,1)
3502         arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
3503         f0.setArray(arrs[2])
3504         ff0.appendFieldNoProfileSBT(f0)
3505         #
3506         f0.setTime(4.4,4,1)
3507         arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
3508         f0.setArray(arrs[3])
3509         ff0.appendFieldNoProfileSBT(f0)
3510         #
3511         for i,arr in enumerate(arrs):
3512             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3513             fs[0][i].loadArraysIfNecessary()
3514             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3515             pass
3516         fs.loadArraysIfNecessary()
3517         for i,arr in enumerate(arrs):
3518             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3519             pass
3520         fs[0].loadArraysIfNecessary()
3521         for i,arr in enumerate(arrs):
3522             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3523             pass
3524         pass
3525     
3526     def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
3527         """ This test is very important, because the same mechanism is used by the MEDReader to generate a field on all the mesh without any processing and memory.
3528         """
3529         fname="Pyfile78.med"
3530         coords=DataArrayDouble([-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ],9,3)
3531         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3532         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
3533         m0.allocateCells()
3534         for elt in [[0,1,2,3],[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7],[5,6,7,8]]:#6
3535             m0.insertNextCell(NORM_TETRA4,elt)
3536             pass
3537         for elt in [[0,1,2,3,4],[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8]]:#5
3538             m0.insertNextCell(NORM_PYRA5,elt)
3539             pass
3540         for elt in [[0,1,2,3,4,5],[1,2,3,4,5,6],[2,3,4,5,6,7],[3,4,5,6,7,8]]:#4
3541             m0.insertNextCell(NORM_PENTA6,elt)
3542             pass
3543         m0.checkCoherency2()
3544         m1=MEDCouplingUMesh(); m1.setName("mesh")
3545         m1.setMeshDimension(2);
3546         m1.allocateCells(5);
3547         m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3548         m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3549         m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3550         m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3551         m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3552         m1.setCoords(coords);
3553         m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
3554         m3.allocateCells()
3555         m3.insertNextCell(NORM_POINT1,[2])
3556         m3.insertNextCell(NORM_POINT1,[3])
3557         m3.insertNextCell(NORM_POINT1,[4])
3558         m3.insertNextCell(NORM_POINT1,[5])
3559         #
3560         mm=MEDFileUMesh()
3561         mm.setMeshAtLevel(0,m0)
3562         mm.setMeshAtLevel(-1,m1)
3563         mm.setMeshAtLevel(-3,m3)
3564         mm.write(fname,2)
3565         #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
3566         mm=MEDFileMesh.New(fname)
3567         fs=MEDFileFields()
3568         fmts=MEDFileFieldMultiTS()
3569         f1ts=MEDFileField1TS()
3570         for lev in mm.getNonEmptyLevels():
3571             for gt in mm.getGeoTypesAtLevel(lev):
3572                 p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
3573                 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
3574                 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
3575                 f.setArray(arr) ; f.setName("f0")
3576                 f1ts.setFieldNoProfileSBT(f)
3577                 pass
3578             pass
3579         self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
3580         for lev in [0,-1,-3]:
3581             mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
3582             pass
3583         fmts.pushBackTimeStep(f1ts)
3584         fs.pushField(fmts)
3585         fs.write(fname,0)
3586         del fs,fmts,f1ts
3587         #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
3588         fs=MEDFileFields(fname)
3589         self.assertEqual(len(fs),1)
3590         self.assertEqual(len(fs[0]),1)
3591         f1ts=fs[0][0]
3592         self.assertEqual(f1ts.getFieldSplitedByType(),[(0,[(0,(0,4),'','')]),(3,[(0,(4,6),'','')]),(4,[(0,(6,9),'','')]),(14,[(0,(9,15),'','')]),(15,[(0,(15,20),'','')]),(16,[(0,(20,24),'','')])])
3593         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0,1,2,3,0,1,0,1,2,0,1,2,3,4,5,0,1,2,3,4,0,1,2,3]),1e-12))
3594         pass
3595
3596     def testMEDFileUMeshSetName(self):
3597         """ This test is a small but important one for MEDReader in sauv mode. When .sauv file is loaded the convertion is performed in memory and a preparation is done then.
3598         This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
3599         """
3600         fname="Pyfile79.med"
3601         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3602         mm=MEDFileUMesh()
3603         m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
3604         coords=DataArrayDouble([-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ],9,3)
3605         m0.allocateCells(5);
3606         m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3607         m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3608         m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3609         m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3610         m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3611         m0.setCoords(coords);
3612         mm.setMeshAtLevel(0,m0)
3613         m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
3614         m2.allocateCells()
3615         m2.insertNextCell(NORM_POINT1,[2])
3616         m2.insertNextCell(NORM_POINT1,[3])
3617         m2.insertNextCell(NORM_POINT1,[4])
3618         m2.insertNextCell(NORM_POINT1,[5])
3619         mm.setMeshAtLevel(-2,m2)
3620         self.assertEqual(mm.getName(),"")
3621         self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
3622         mm.forceComputationOfParts()
3623         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
3624         mm.setName("abc")
3625         self.assertEqual(mm.getName(),"abc")
3626         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
3627         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
3628         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
3629         self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
3630         pass
3631
3632     def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
3633         fileName="Pyfile80.med"
3634         m=MEDCouplingCMesh() ; m.setName("cmesh")
3635         arr=DataArrayDouble(6) ; arr.iota()
3636         m.setCoords(arr,arr)
3637         nbCells=m.getNumberOfCells()
3638         self.assertEqual(25,nbCells)
3639         f=MEDCouplingFieldDouble(ON_CELLS)
3640         f.setName("FieldOnCell") ; f.setMesh(m)
3641         arr=DataArrayDouble(nbCells) ; arr.iota()
3642         mm=MEDFileCMesh()
3643         mm.setMesh(m)
3644         #
3645         fmts=MEDFileFieldMultiTS()
3646         #
3647         for i in xrange(nbCells):
3648             t=(float(i)+0.1,i+1,-i-2)
3649             f.setTime(*t)
3650             arr2=DataArrayDouble(nbCells)
3651             perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
3652             arr2[perm]=arr
3653             f.setArray(arr2)
3654             f1ts=MEDFileField1TS()
3655             f1ts.setFieldNoProfileSBT(f)
3656             fmts.pushBackTimeStep(f1ts)
3657             pass
3658         fmts.unloadArraysWithoutDataLoss()
3659         self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3660         fs=MEDFileFields() ; fs.pushField(fmts)
3661         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3662         fs.unloadArraysWithoutDataLoss()
3663         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3664         f1ts=fs[0][0]
3665         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3666         f1ts.unloadArraysWithoutDataLoss()
3667         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3668         mm.write(fileName,2)
3669         fs.write(fileName,0)
3670         del m,fmts,mm,f,f1ts
3671         ##
3672         mm=MEDFileMesh.New(fileName)
3673         fmts=MEDFileFieldMultiTS(fileName)
3674         self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3675         fmts.unloadArraysWithoutDataLoss()
3676         self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
3677         fmts.loadArraysIfNecessary()
3678         self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3679         del mm,fmts
3680         fs=MEDFileFields(fileName)
3681         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3682         fs.unloadArraysWithoutDataLoss()
3683         self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
3684         fs.loadArraysIfNecessary()
3685         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3686         del fs
3687         f1ts=MEDFileField1TS(fileName)
3688         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3689         f1ts.unloadArraysWithoutDataLoss()
3690         self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
3691         f1ts.loadArraysIfNecessary()
3692         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3693         pass
3694
3695     def testMEDFileUMeshLoadPart1(self):
3696         """ This method tests MEDFileUMesh.LoadPart that loads only a part of a specified mesh in a MED file. The part is specfied using a slice of cell ids. Only nodes on which cells lies are loaded to reduce at most the amount of
3697         memory of the returned instance.
3698         """
3699         fileName="Pyfile81.med"
3700         arr=DataArrayDouble(6) ; arr.iota()
3701         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3702         m=m.buildUnstructured()
3703         m.setName("Mesh")
3704         m.changeSpaceDimension(3,0.)
3705         infos=["aa [b]","cc [de]","gg [klm]"]
3706         m.getCoords().setInfoOnComponents(infos)
3707         m.checkCoherency2()
3708         mm=MEDFileUMesh()
3709         mm.setMeshAtLevel(0,m)
3710         m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh") 
3711         m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
3712         mm.setMeshAtLevel(-1,m1)
3713         renum0=DataArrayInt([3,6,7,10,11,0,2,1,9,8,5,4,12,13,14,24,23,22,21,20,19,18,17,16,15])
3714         famField0=DataArrayInt([-3,-6,-7,-10,-11,0,-2,-1,-9,-8,-5,-4,-12,-13,-14,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15])
3715         namesCellL0=DataArrayAsciiChar(25,16)
3716         namesCellL0[:]=["Cell#%.3d        "%(i) for i in xrange(25)]
3717         renumM1=DataArrayInt([3,4,0,2,1])
3718         famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
3719         mm.setRenumFieldArr(0,renum0)
3720         mm.setFamilyFieldArr(0,famField0)
3721         mm.setNameFieldAtLevel(0,namesCellL0)
3722         mm.setRenumFieldArr(-1,renumM1)
3723         mm.setFamilyFieldArr(-1,famFieldM1)
3724         renum1=DataArrayInt([13,16,17,20,21,10,12,11,19,18,15,14,22,23,24,34,33,32,31,30,29,28,27,26,25,45,44,43,42,41,40,39,38,37,36,35])
3725         famField1=DataArrayInt([-13,-16,-17,-20,-21,-10,-12,-11,-19,-18,-15,-14,-22,-23,-24,-34,-33,-32,-31,-30,-29,-28,-27,-26,-25,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35])
3726         namesNodes=DataArrayAsciiChar(36,16)
3727         namesNodes[:]=["Node#%.3d        "%(i) for i in xrange(36)]
3728         mm.setRenumFieldArr(1,renum1)
3729         mm.setFamilyFieldArr(1,famField1)
3730         mm.setNameFieldAtLevel(1,namesNodes)
3731         mm.setFamilyId("Fam7",77)
3732         mm.setFamilyId("Fam8",88)
3733         mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
3734         mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
3735         mm.write(fileName,2)
3736         #
3737         mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
3738         self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
3739         self.assertTrue(mm0.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,11,10,16,17])))
3740         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),(5,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(4,1,0),(5,1,0),(0,2,0),(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0)]) ; coo.setInfoOnComponents(infos)
3741         self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
3742         self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
3743         self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
3744         self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
3745         self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
3746         self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
3747         self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
3748         #
3749         mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
3750         self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
3751         self.assertTrue(mm1.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,6,5,11,12,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,12,11,17,18,13,12,18,19,14,13,19,20,15,14,20,21,16,15,21,22])))
3752         coo=DataArrayDouble([(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0),(0,3,0),(1,3,0),(2,3,0),(3,3,0),(4,3,0),(5,3,0),(0,4,0),(1,4,0),(2,4,0),(3,4,0),(4,4,0),(5,4,0),(0,5,0),(1,5,0),(2,5,0),(3,5,0),(4,5,0),(5,5,0)]) ; coo.setInfoOnComponents(infos)
3753         self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
3754         self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
3755         self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
3756         self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
3757         self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
3758         self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
3759         self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
3760         #
3761         mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
3762         self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
3763         self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
3764         self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
3765         self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
3766         self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
3767         self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
3768         self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
3769         self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,11,10,16,17])))
3770         self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
3771         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),(5,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(4,1,0),(5,1,0),(0,2,0),(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0)]) ; coo.setInfoOnComponents(infos)
3772         self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
3773         self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
3774         self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
3775         self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
3776         pass
3777
3778     def testMEDFileFieldsLoadPart1(self):
3779         """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
3780         """
3781         fileName="Pyfile82.med"
3782         meshName="Mesh"
3783         compos=["aa [kg]","bbb [m/s]"]
3784         arr=DataArrayDouble(6) ; arr.iota()
3785         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3786         m=m.buildUnstructured()
3787         m.setName(meshName)
3788         m.changeSpaceDimension(3,0.)
3789         infos=["aa [b]","cc [de]","gg [klm]"]
3790         m.getCoords().setInfoOnComponents(infos)
3791         m.checkCoherency2()
3792         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
3793         f.setName("Field")
3794         arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
3795         arr[:,0]=range(25)
3796         arr[:,1]=range(100,125)
3797         f.setArray(arr)
3798         MEDLoader.WriteField(fileName,f,2)
3799         f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
3800         f.setName("FieldNode")
3801         arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
3802         arr[:,0]=range(200,236)
3803         arr[:,1]=range(300,336)
3804         f.setArray(arr)
3805         f.checkCoherency()
3806         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f)
3807         #
3808         ms=MEDFileMeshes()
3809         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
3810         ms.pushMesh(mm)
3811         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3812         self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
3813         #
3814         ms=MEDFileMeshes()
3815         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
3816         ms.pushMesh(mm)
3817         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3818         fs=fs.deepCpy()
3819         fs[0][0].loadArrays()
3820         arr=DataArrayDouble(12,2) ; arr[:,0]=range(3,15) ; arr[:,1]=range(103,115)
3821         arr.setInfoOnComponents(compos)
3822         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
3823         fs[1][0].loadArrays()
3824         arr=DataArrayDouble(21,2) ; arr[:,0]=range(203,224) ; arr[:,1]=range(303,324)
3825         arr.setInfoOnComponents(compos)
3826         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
3827         pass
3828
3829     def testMEDFileWithoutCells1(self):
3830         fileName="Pyfile83.med"
3831         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
3832         coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
3833         mm=MEDFileUMesh()
3834         mm.setCoords(coo)
3835         mm.setName("mesh")
3836         mm.write(fileName,2)
3837         #
3838         mm=MEDFileMesh.New(fileName)
3839         self.assertEqual(mm.getName(),"mesh")
3840         self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
3841         pass
3842
3843     def testZipCoordsWithLoadPart1(self):
3844         """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
3845         """
3846         fileName="Pyfile84.med"
3847         meshName="Mesh"
3848         compos=["aa [kg]","bbb [m/s]"]
3849         arr=DataArrayDouble(6) ; arr.iota()
3850         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3851         m=m.buildUnstructured()
3852         m.setName(meshName)
3853         m.changeSpaceDimension(3,0.)
3854         infos=["aa [b]","cc [de]","gg [klm]"]
3855         m.getCoords().setInfoOnComponents(infos)
3856         m.checkCoherency2()
3857         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
3858         f.setName("Field")
3859         arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
3860         arr[:,0]=range(25)
3861         arr[:,1]=range(100,125)
3862         f.setArray(arr)
3863         MEDLoader.WriteField(fileName,f,2)
3864         f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
3865         f.setName("FieldNode")
3866         arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
3867         arr[:,0]=range(200,236)
3868         arr[:,1]=range(300,336)
3869         f.setArray(arr)
3870         f.checkCoherency()
3871         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f)
3872         #
3873         ms=MEDFileMeshes()
3874         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
3875         ms.pushMesh(mm)
3876         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
3877         self.assertEqual(spd.getSlice(),slice(4,6,1))
3878         spd=mm.getPartDefAtLevel(1)
3879         self.assertEqual(spd.getSlice(),slice(4,14,1))
3880         self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
3881         mm.zipCoords() # <- The important line is here !
3882         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
3883         self.assertEqual(spd.getSlice(),slice(4,6,1))
3884         spd=mm.getPartDefAtLevel(1)
3885         self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
3886         self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
3887         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3888         fs[0][0].loadArrays()
3889         arr=DataArrayDouble([(4,104),(5,105)])
3890         arr.setInfoOnComponents(compos)
3891         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
3892         fs[1][0].loadArrays()
3893         arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
3894         arr.setInfoOnComponents(compos)
3895         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
3896         pass
3897
3898     def testMEDFileCMeshSetGroupsAtLevel(self):
3899         """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
3900         """
3901         m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
3902         m.setName("Mesh")
3903         mm=MEDFileCMesh() ; mm.setMesh(m)
3904         grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
3905         mm.setGroupsAtLevel(0,[grp])
3906         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
3907         pass
3908
3909     def testMEDFileUMeshBuildExtrudedMesh1(self):
3910         """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
3911         fileName="Pyfile85.med"
3912         meshName2D="Mesh"
3913         meshName1D="Mesh1D"
3914         meshName3DOut="Mesh3D"
3915         #
3916         d1=DataArrayInt([0,4,20,24])
3917         d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
3918         #
3919         a=DataArrayDouble(6) ; a.iota()
3920         m=MEDCouplingCMesh() ; m.setCoords(a,a)
3921         m=m.buildUnstructured()
3922         d1c=d1.buildComplement(m.getNumberOfCells())
3923         m=m[d1c] ; m.zipCoords()
3924         m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
3925         m0.simplexize(0)
3926         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
3927         m.setName(meshName2D)
3928         mMinus1,a,b,c,d=m.buildDescendingConnectivity()
3929         e=d.deltaShiftIndex().getIdsEqual(1)
3930         #
3931         mm=MEDFileUMesh()
3932         mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
3933         grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
3934         mm.setGroupsAtLevel(0,[grp0])
3935         grp1=e ; grp1.setName("grp1")
3936         mm.setGroupsAtLevel(-1,[grp1])
3937         mm.write(fileName,2)
3938         #
3939         a=DataArrayDouble(3) ; a.iota()
3940         tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
3941         tmp.setName(meshName1D)
3942         tmp.changeSpaceDimension(3)
3943         tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
3944         mm1D=MEDFileUMesh()
3945         mm1D.setMeshAtLevel(0,tmp)
3946         mm1D.write(fileName,0)
3947         # test is here !
3948         mm2D=MEDFileMesh.New(fileName,meshName2D)
3949         mm1D=MEDFileMesh.New(fileName,meshName1D)
3950         m1D=mm1D.getMeshAtLevel(0)
3951         mm3D=mm2D.buildExtrudedMesh(m1D,0)
3952         #
3953         self.assertEqual(mm3D.getName(),mm2D.getName())
3954         self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
3955         self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
3956         self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
3957         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
3958         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
3959         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
3960         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
3961         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
3962         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
3963         d=DataArrayDouble([(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(4.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(4.,1.,0.),(5.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(4.,2.,0.),(5.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.),(4.,3.,0.),(5.,3.,0.),(0.,4.,0.),(1.,4.,0.),(2.,4.,0.),(3.,4.,0.),(4.,4.,0.),(5.,4.,0.),(1.,5.,0.),(2.,5.,0.),(3.,5.,0.),(4.,5.,0.),(1.,0.,1.),(2.,0.,1.),(3.,0.,1.),(4.,0.,1.),(0.,1.,1.),(1.,1.,1.),(2.,1.,1.),(3.,1.,1.),(4.,1.,1.),(5.,1.,1.),(0.,2.,1.),(1.,2.,1.),(2.,2.,1.),(3.,2.,1.),(4.,2.,1.),(5.,2.,1.),(0.,3.,1.),(1.,3.,1.),(2.,3.,1.),(3.,3.,1.),(4.,3.,1.),(5.,3.,1.),(0.,4.,1.),(1.,4.,1.),(2.,4.,1.),(3.,4.,1.),(4.,4.,1.),(5.,4.,1.),(1.,5.,1.),(2.,5.,1.),(3.,5.,1.),(4.,5.,1.),(1.,0.,2.),(2.,0.,2.),(3.,0.,2.),(4.,0.,2.),(0.,1.,2.),(1.,1.,2.),(2.,1.,2.),(3.,1.,2.),(4.,1.,2.),(5.,1.,2.),(0.,2.,2.),(1.,2.,2.),(2.,2.,2.),(3.,2.,2.),(4.,2.,2.),(5.,2.,2.),(0.,3.,2.),(1.,3.,2.),(2.,3.,2.),(3.,3.,2.),(4.,3.,2.),(5.,3.,2.),(0.,4.,2.),(1.,4.,2.),(2.,4.,2.),(3.,4.,2.),(4.,4.,2.),(5.,4.,2.),(1.,5.,2.),(2.,5.,2.),(3.,5.,2.),(4.,5.,2.)])
3964         self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
3965         d=DataArrayInt([16,1,0,5,33,32,37,16,1,5,6,33,37,38,16,2,1,6,34,33,38,16,2,6,7,34,38,39,16,3,2,7,35,34,39,16,3,7,8,35,39,40,16,5,4,10,37,36,42,16,5,10,11,37,42,43,16,9,8,14,41,40,46,16,9,14,15,41,46,47,16,11,10,16,43,42,48,16,11,16,17,43,48,49,16,15,14,20,47,46,52,16,15,20,21,47,52,53,16,17,16,22,49,48,54,16,17,22,23,49,54,55,16,21,20,26,53,52,58,16,21,26,27,53,58,59,16,24,23,28,56,55,60,16,24,28,29,56,60,61,16,25,24,29,57,56,61,16,25,29,30,57,61,62,16,26,25,30,58,57,62,16,26,30,31,58,62,63,16,33,32,37,65,64,69,16,33,37,38,65,69,70,16,34,33,38,66,65,70,16,34,38,39,66,70,71,16,35,34,39,67,66,71,16,35,39,40,67,71,72,16,37,36,42,69,68,74,16,37,42,43,69,74,75,16,41,40,46,73,72,78,16,41,46,47,73,78,79,16,43,42,48,75,74,80,16,43,48,49,75,80,81,16,47,46,52,79,78,84,16,47,52,53,79,84,85,16,49,48,54,81,80,86,16,49,54,55,81,86,87,16,53,52,58,85,84,90,16,53,58,59,85,90,91,16,56,55,60,88,87,92,16,56,60,61,88,92,93,16,57,56,61,89,88,93,16,57,61,62,89,93,94,16,58,57,62,90,89,94,16,58,62,63,90,94,95,18,6,5,11,12,38,37,43,44,18,7,6,12,13,39,38,44,45,18,8,7,13,14,40,39,45,46,18,12,11,17,18,44,43,49,50,18,13,12,18,19,45,44,50,51,18,14,13,19,20,46,45,51,52,18,18,17,23,24,50,49,55,56,18,19,18,24,25,51,50,56,57,18,20,19,25,26,52,51,57,58,18,38,37,43,44,70,69,75,76,18,39,38,44,45,71,70,76,77,18,40,39,45,46,72,71,77,78,18,44,43,49,50,76,75,81,82,18,45,44,50,51,77,76,82,83,18,46,45,51,52,78,77,83,84,18,50,49,55,56,82,81,87,88,18,51,50,56,57,83,82,88,89,18,52,51,57,58,84,83,89,90])
3966         self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
3967         d=DataArrayInt([0,7,14,21,28,35,42,49,56,63,70,77,84,91,98,105,112,119,126,133,140,147,154,161,168,175,182,189,196,203,210,217,224,231,238,245,252,259,266,273,280,287,294,301,308,315,322,329,336,345,354,363,372,381,390,399,408,417,426,435,444,453,462,471,480,489,498])
3968         self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
3969         d=DataArrayInt([3,1,0,5,3,1,5,6,3,2,1,6,3,2,6,7,3,3,2,7,3,3,7,8,3,5,4,10,3,5,10,11,3,9,8,14,3,9,14,15,3,11,10,16,3,11,16,17,3,15,14,20,3,15,20,21,3,17,16,22,3,17,22,23,3,21,20,26,3,21,26,27,3,24,23,28,3,24,28,29,3,25,24,29,3,25,29,30,3,26,25,30,3,26,30,31,3,65,64,69,3,65,69,70,3,66,65,70,3,66,70,71,3,67,66,71,3,67,71,72,3,69,68,74,3,69,74,75,3,73,72,78,3,73,78,79,3,75,74,80,3,75,80,81,3,79,78,84,3,79,84,85,3,81,80,86,3,81,86,87,3,85,84,90,3,85,90,91,3,88,87,92,3,88,92,93,3,89,88,93,3,89,93,94,3,90,89,94,3,90,94,95,4,1,0,32,33,4,0,5,37,32,4,5,1,33,37,4,5,6,38,37,4,6,1,33,38,4,2,1,33,34,4,6,2,34,38,4,6,7,39,38,4,7,2,34,39,4,3,2,34,35,4,7,3,35,39,4,7,8,40,39,4,8,3,35,40,4,5,4,36,37,4,4,10,42,36,4,10,5,37,42,4,10,11,43,42,4,11,5,37,43,4,9,8,40,41,4,8,14,46,40,4,14,9,41,46,4,14,15,47,46,4,15,9,41,47,4,10,16,48,42,4,16,11,43,48,4,16,17,49,48,4,17,11,43,49,4,14,20,52,46,4,20,15,47,52,4,20,21,53,52,4,21,15,47,53,4,16,22,54,48,4,22,17,49,54,4,22,23,55,54,4,23,17,49,55,4,20,26,58,52,4,26,21,53,58,4,26,27,59,58,4,27,21,53,59,4,24,23,55,56,4,23,28,60,55,4,28,24,56,60,4,28,29,61,60,4,29,24,56,61,4,25,24,56,57,4,29,25,57,61,4,29,30,62,61,4,30,25,57,62,4,26,25,57,58,4,30,26,58,62,4,30,31,63,62,4,31,26,58,63,4,11,12,44,43,4,12,6,38,44,4,12,13,45,44,4,13,7,39,45,4,13,14,46,45,4,17,18,50,49,4,18,12,44,50,4,18,19,51,50,4,19,13,45,51,4,19,20,52,51,4,24,18,50,56,4,25,19,51,57,4,33,32,64,65,4,32,37,69,64,4,37,33,65,69,4,37,38,70,69,4,38,33,65,70,4,34,33,65,66,4,38,34,66,70,4,38,39,71,70,4,39,34,66,71,4,35,34,66,67,4,39,35,67,71,4,39,40,72,71,4,40,35,67,72,4,37,36,68,69,4,36,42,74,68,4,42,37,69,74,4,42,43,75,74,4,43,37,69,75,4,41,40,72,73,4,40,46,78,72,4,46,41,73,78,4,46,47,79,78,4,47,41,73,79,4,42,48,80,74,4,48,43,75,80,4,48,49,81,80,4,49,43,75,81,4,46,52,84,78,4,52,47,79,84,4,52,53,85,84,4,53,47,79,85,4,48,54,86,80,4,54,49,81,86,4,54,55,87,86,4,55,49,81,87,4,52,58,90,84,4,58,53,85,90,4,58,59,91,90,4,59,53,85,91,4,56,55,87,88,4,55,60,92,87,4,60,56,88,92,4,60,61,93,92,4,61,56,88,93,4,57,56,88,89,4,61,57,89,93,4,61,62,94,93,4,62,57,89,94,4,58,57,89,90,4,62,58,90,94,4,62,63,95,94,4,63,58,90,95,4,43,44,76,75,4,44,38,70,76,4,44,45,77,76,4,45,39,71,77,4,45,46,78,77,4,49,50,82,81,4,50,44,76,82,4,50,51,83,82,4,51,45,77,83,4,51,52,84,83,4,56,50,82,88,4,57,51,83,89,4,6,5,11,12,4,7,6,12,13,4,8,7,13,14,4,12,11,17,18,4,13,12,18,19,4,14,13,19,20,4,18,17,23,24,4,19,18,24,25,4,20,19,25,26,4,70,69,75,76,4,71,70,76,77,4,72,71,77,78,4,76,75,81,82,4,77,76,82,83,4,78,77,83,84,4,82,81,87,88,4,83,82,88,89,4,84,83,89,90])
3970         self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
3971         d=DataArrayInt([0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,197,202,207,212,217,222,227,232,237,242,247,252,257,262,267,272,277,282,287,292,297,302,307,312,317,322,327,332,337,342,347,352,357,362,367,372,377,382,387,392,397,402,407,412,417,422,427,432,437,442,447,452,457,462,467,472,477,482,487,492,497,502,507,512,517,522,527,532,537,542,547,552,557,562,567,572,577,582,587,592,597,602,607,612,617,622,627,632,637,642,647,652,657,662,667,672,677,682,687,692,697,702,707,712,717,722,727,732,737,742,747,752,757,762,767,772,777,782,787,792,797,802,807,812,817,822,827,832,837,842,847,852,857,862,867,872,877,882,887,892,897,902,907,912,917,922])
3972         self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
3973         d=DataArrayInt([1,1,0,1,0,5,1,5,1,1,5,6,1,6,1,1,2,1,1,6,2,1,6,7,1,7,2,1,3,2,1,7,3,1,7,8,1,8,3,1,5,4,1,4,10,1,10,5,1,10,11,1,11,5,1,9,8,1,8,14,1,14,9,1,14,15,1,15,9,1,10,16,1,16,11,1,16,17,1,17,11,1,14,20,1,20,15,1,20,21,1,21,15,1,16,22,1,22,17,1,22,23,1,23,17,1,20,26,1,26,21,1,26,27,1,27,21,1,24,23,1,23,28,1,28,24,1,28,29,1,29,24,1,25,24,1,29,25,1,29,30,1,30,25,1,26,25,1,30,26,1,30,31,1,31,26,1,11,12,1,12,6,1,12,13,1,13,7,1,13,14,1,17,18,1,18,12,1,18,19,1,19,13,1,19,20,1,24,18,1,25,19,1,65,64,1,64,69,1,69,65,1,69,70,1,70,65,1,66,65,1,70,66,1,70,71,1,71,66,1,67,66,1,71,67,1,71,72,1,72,67,1,69,68,1,68,74,1,74,69,1,74,75,1,75,69,1,73,72,1,72,78,1,78,73,1,78,79,1,79,73,1,74,80,1,80,75,1,80,81,1,81,75,1,78,84,1,84,79,1,84,85,1,85,79,1,80,86,1,86,81,1,86,87,1,87,81,1,84,90,1,90,85,1,90,91,1,91,85,1,88,87,1,87,92,1,92,88,1,92,93,1,93,88,1,89,88,1,93,89,1,93,94,1,94,89,1,90,89,1,94,90,1,94,95,1,95,90,1,75,76,1,76,70,1,76,77,1,77,71,1,77,78,1,81,82,1,82,76,1,82,83,1,83,77,1,83,84,1,88,82,1,89,83])
3974         self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
3975         d=DataArrayInt(129) ; d.iota() ; d*=3
3976         self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
3977         #
3978         self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
3979         self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
3980         self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
3981         self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
3982         self.assertTrue(mm3D.getGroupArr(-2,"grp1").isEqualWithoutConsideringStr(DataArrayInt([0,1,5,9,12,13,14,18,22,23,30,31,33,37,38,40,42,46,50,51])))
3983         self.assertTrue(mm3D.getGroupArr(-2,"grp1_top").isEqualWithoutConsideringStr(DataArrayInt([64,65,69,73,76,77,78,82,86,87,94,95,97,101,102,104,106,110,114,115])))
3984         self.assertTrue(mm3D.getGroupArr(0,"grp0_extruded").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,24,25,26,27,28,29,48,49,50,57,58,59])))
3985         self.assertTrue(mm3D.getGroupArr(-1,"grp1_extruded").isEqualWithoutConsideringStr(DataArrayInt([48,49,53,57,60,61,62,66,70,71,78,79,81,85,86,88,90,94,98,99,112,113,117,121,124,125,126,130,134,135,142,143,145,149,150,152,154,158,162,163])))
3986         mm3D.setName("MeshExtruded")
3987         mm3D.write(fileName,0)
3988         pass
3989
3990     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
3991     def testMEDFileUMeshPickeling1(self):
3992         import cPickle
3993         outFileName="Pyfile86.med"
3994         c=DataArrayDouble([-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 ],9,2)
3995         c.setInfoOnComponents(["aa","bbb"])
3996         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
3997         m=MEDCouplingUMesh();
3998         m.setMeshDimension(2);
3999         m.allocateCells(5);
4000         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
4001         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
4002         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
4003         m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
4004         m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
4005         m.finishInsertingCells();
4006         m.setCoords(c)
4007         m.checkCoherency()
4008         m1=MEDCouplingUMesh.New();
4009         m1.setMeshDimension(1);
4010         m1.allocateCells(3);
4011         m1.insertNextCell(NORM_SEG2,2,[1,4])
4012         m1.insertNextCell(NORM_SEG2,2,[3,6])
4013         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
4014         m1.finishInsertingCells();
4015         m1.setCoords(c)
4016         m1.checkCoherency()
4017         m2=MEDCouplingUMesh.New();
4018         m2.setMeshDimension(0);
4019         m2.allocateCells(4);
4020         m2.insertNextCell(NORM_POINT1,1,[1])
4021         m2.insertNextCell(NORM_POINT1,1,[3])
4022         m2.insertNextCell(NORM_POINT1,1,[2])
4023         m2.insertNextCell(NORM_POINT1,1,[6])
4024         m2.finishInsertingCells();
4025         m2.setCoords(c)
4026         m2.checkCoherency()
4027         #
4028         mm=MEDFileUMesh.New()
4029         self.assertTrue(mm.getUnivNameWrStatus())
4030         mm.setName("MyFirstMEDCouplingMEDmesh")
4031         mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
4032         mm.setCoords(c)
4033         mm[-1]=m1;
4034         mm[0]=m;
4035         mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
4036         mm[-2]=m2;
4037         mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
4038         # playing with groups
4039         g1_2=DataArrayInt.New()
4040         g1_2.setValues([1,3],2,1)
4041         g1_2.setName("G1")
4042         g2_2=DataArrayInt.New()
4043         g2_2.setValues([1,2,3],3,1)
4044         g2_2.setName("G2")
4045         mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
4046         g1_1=DataArrayInt.New()
4047         g1_1.setValues([0,1,2],3,1)
4048         g1_1.setName("G1")
4049         g2_1=DataArrayInt.New()
4050         g2_1.setValues([0,2],2,1)
4051         g2_1.setName("G2")
4052         mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
4053         g1_N=DataArrayInt.New()
4054         g1_N.setValues(range(8),8,1)
4055         g1_N.setName("G1")
4056         g2_N=DataArrayInt.New()
4057         g2_N.setValues(range(9),9,1)
4058         g2_N.setName("G2")
4059         mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
4060         mm.createGroupOnAll(0,"GrpOnAllCell")
4061         # check content of mm
4062         t=mm.getGroupArr(0,"G1",False)
4063         self.assertTrue(g1_2.isEqual(t));
4064         t=mm.getGroupArr(0,"G2",False)
4065         self.assertTrue(g2_2.isEqual(t));
4066         t=mm.getGroupArr(-1,"G1",False)
4067         self.assertTrue(g1_1.isEqual(t));
4068         t=mm.getGroupArr(-1,"G2",False)
4069         self.assertTrue(g2_1.isEqual(t));
4070         t=mm.getGroupArr(1,"G1",False)
4071         self.assertTrue(g1_N.isEqual(t));
4072         t=mm.getGroupArr(1,"G2",False)
4073         self.assertTrue(g2_N.isEqual(t));
4074         self.assertTrue(mm.existsGroup("GrpOnAllCell"));
4075         t=mm.getGroupArr(0,"GrpOnAllCell")
4076         #
4077         st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
4078         mm2=cPickle.loads(st)
4079         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4080         pass
4081
4082     def testMEDFileFieldsLoadSpecificEntities1(self):
4083         nbNodes=11
4084         fieldName="myField"
4085         fileName="Pyfile87.med"
4086         nbPdt=10
4087         meshName="Mesh"
4088         #
4089         m=MEDCouplingCMesh()
4090         arr=DataArrayDouble(nbNodes) ; arr.iota()
4091         m.setCoords(arr)
4092         m=m.buildUnstructured()
4093         m.setName(meshName)
4094         #
4095         fmts=MEDFileFieldMultiTS()
4096         for i in xrange(nbPdt):
4097             f=MEDCouplingFieldDouble(ON_NODES)
4098             f.setMesh(m)
4099             arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4100             f.setArray(arr)
4101             f.setName(fieldName)
4102             f.setTime(float(i),i,0)
4103             fmts.appendFieldNoProfileSBT(f)
4104             pass
4105         #
4106         mm=MEDFileUMesh() ; mm[0]=m
4107         fmts.write(fileName,2)
4108         mm.write(fileName,0)
4109         #
4110         fs=MEDFileFields(fileName,False)
4111         fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
4112         fs.loadArraysIfNecessary()
4113         fs2.loadArraysIfNecessary()
4114         for i in xrange(nbPdt):
4115             self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4116             pass
4117         m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
4118         m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
4119         m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
4120         fmts=MEDFileFieldMultiTS()
4121         for i in xrange(nbPdt):
4122             f=MEDCouplingFieldDouble(ON_CELLS)
4123             f.setMesh(m3)
4124             arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
4125             f.setArray(arr)
4126             f.setName(fieldName)
4127             f.setTime(float(i),i,0)
4128             fmts.appendFieldNoProfileSBT(f)
4129             pass
4130         mm=MEDFileUMesh() ; mm[0]=m3
4131         del mm[0]
4132         self.assertEqual(mm.getNonEmptyLevels(),())
4133         mm[0]=m3
4134         self.assertEqual(mm.getNonEmptyLevels(),(0,))
4135         fmts.write(fileName,2)
4136         fs=MEDFileFields(fileName,False)
4137         fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
4138         fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
4139         fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
4140         fs.loadArraysIfNecessary()
4141         fs2.loadArraysIfNecessary()
4142         fs3.loadArraysIfNecessary()
4143         fs4.loadArraysIfNecessary()
4144         for i in xrange(nbPdt):
4145             self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4146             self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
4147             self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
4148             pass
4149         pass
4150
4151     def testMEDFileLotsOfTSRW1(self):
4152         nbNodes=11
4153         fieldName="myField"
4154         fileName="Pyfile88.med"
4155         nbPdt=300 # <- perftest = 30000
4156         meshName="Mesh"
4157         #
4158         maxPdt=100 # <- optimum = 500
4159         m=MEDCouplingCMesh()
4160         arr=DataArrayDouble(nbNodes) ; arr.iota()
4161         m.setCoords(arr)
4162         m=m.buildUnstructured()
4163         m.setName(meshName)
4164         #
4165         nbOfField=nbPdt/maxPdt
4166         fs=MEDFileFields()
4167         for j in xrange(nbOfField):
4168             fmts=MEDFileFieldMultiTS()
4169             s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
4170             for i in xrange(s.start,s.stop,s.step):
4171                 f=MEDCouplingFieldDouble(ON_NODES)
4172                 f.setMesh(m)
4173                 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4174                 f.setArray(arr)
4175                 f.setName("%s_%d"%(fieldName,j))
4176                 f.setTime(float(i),i,0)
4177                 fmts.appendFieldNoProfileSBT(f)
4178                 pass
4179             fs.pushField(fmts)
4180             pass
4181         #
4182         mm=MEDFileUMesh() ; mm[0]=m
4183         fs.write(fileName,2)
4184         mm.write(fileName,0)
4185         ############
4186         def appendInDict(d,key,val):
4187             if key in d:
4188                 d[key].append(val)
4189             else:
4190                 d[key]=[val]
4191             pass
4192         import re
4193         allFields=MEDLoader.GetAllFieldNames(fileName)
4194         allFieldsDict={}
4195         pat=re.compile("([\d]+)([\s\S]+)$")
4196         for st in allFields:
4197             stRev=st[::-1]
4198             m=pat.match(stRev)
4199             if m:
4200                 appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
4201                 pass
4202             else:
4203                 appendInDict(allFieldsDict,st,'')
4204                 pass
4205             pass
4206         fs2=MEDFileFields()
4207         for k in allFieldsDict:
4208             if allFieldsDict[k]!=['']:
4209                 allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
4210                 pass
4211             fmts2=[]
4212             for it in allFieldsDict[k]:
4213                 fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
4214                 pass
4215             fmts2.reverse()
4216             zeResu=fmts2.pop()
4217             nbIter=len(fmts2)
4218             for ii in xrange(nbIter):
4219                 zeResu.pushBackTimeSteps(fmts2.pop())
4220                 pass
4221             zeResu.setName(k)
4222             fs2.pushField(zeResu)
4223             pass
4224         self.assertEqual(fs2[0].getTimeSteps(),[(i,0,float(i)) for i in xrange(nbPdt)])
4225         pass
4226     
4227     def testMEDFileMeshRearrangeFamIds1(self):
4228         """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
4229         fileName="Pyfile89.med"
4230         meshName='Maillage_2'
4231         mm=MEDFileUMesh()
4232         coords=DataArrayDouble([(0.,0.,0.),(0.,0.,200.),(0.,200.,200.),(0.,200.,0.),(200.,0.,0.),(200.,0.,200.),(200.,200.,200.),(200.,200.,0.),(0.,0.,100.),(0.,100.,200.),(0.,200.,100.),(0.,100.,0.),(200.,0.,100.),(200.,100.,200.),(200.,200.,100.),(200.,100.,0.),(100.,0.,0.),(100.,0.,200.),(100.,200.,0.),(100.,200.,200.),(0.,116.87743909766768,83.12256090233232),(200.,116.87743909766768,83.12256090233232),(116.87743909766769,0.,116.87743909766769),(116.87743909766769,200.,116.87743909766769),(116.87743909766769,116.87743909766769,0.),(116.87743909766769,116.87743909766769,200.),(63.3851584383713,56.1391811199829,119.728314479261),(138.008709441123,116.039297556044,119.903790959468)])
4233         #
4234         c0=DataArrayInt([14,1,26,9,8,14,17,26,1,8,14,27,26,17,22,14,26,16,20,8,14,8,0,16,11,14,16,20,11,24,14,25,20,26,27,14,22,26,24,27,14,26,16,22,24,14,8,26,22,17,14,20,9,25,26,14,19,20,25,23,14,23,6,27,25,14,19,23,10,20,14,27,22,21,24,14,27,21,14,18,14,26,9,25,17,14,13,27,25,17,14,27,18,24,21,14,22,21,15,12,14,27,20,24,18,14,23,25,27,20,14,13,27,6,25,14,23,27,6,14,14,15,16,22,12,14,27,17,13,22,14,22,27,21,13,14,24,16,22,15,14,24,18,7,21,14,12,4,15,16,14,22,12,5,13,14,8,26,16,22,14,13,27,21,14,14,20,18,10,3,14,14,27,18,23,14,14,27,6,13,14,21,22,13,12,14,25,26,17,27,14,19,9,25,20,14,26,24,20,16,14,22,24,15,21,14,9,26,1,17,14,23,27,18,20,14,20,11,18,3,14,14,18,21,7,14,19,2,9,10,14,19,23,25,6,14,18,23,20,10,14,20,26,8,9,14,22,13,5,17,14,24,11,18,20,14,21,15,7,24,14,19,20,10,9,14,20,26,27,24,14,16,8,11,20])
4235         c0i=DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275])
4236         m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
4237         m0.setConnectivity(c0,c0i)
4238         mm[0]=m0
4239         #
4240         c1=DataArrayInt([3,8,20,11,3,8,9,20,3,9,2,10,3,20,9,10,3,0,8,11,3,9,8,1,3,20,10,3,3,11,20,3,3,15,21,12,3,5,12,13,3,21,13,12,3,15,12,4,3,14,6,13,3,14,13,21,3,7,14,21,3,7,21,15,3,5,22,12,3,4,12,16,3,17,1,8,3,16,8,0,3,5,17,22,3,12,22,16,3,22,17,8,3,16,22,8,3,10,2,19,3,7,18,14,3,14,23,6,3,3,10,18,3,23,19,6,3,18,23,14,3,10,19,23,3,10,23,18,3,3,18,11,3,7,24,18,3,15,4,16,3,11,16,0,3,7,15,24,3,18,24,11,3,24,15,16,3,11,24,16,3,9,19,2,3,19,25,6,3,17,5,13,3,1,17,9,3,25,13,6,3,9,25,19,3,17,13,25,3,17,25,9])
4241         c1i=DataArrayInt([0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192])
4242         m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
4243         m1.setConnectivity(c1,c1i)
4244         mm[-1]=m1
4245         #
4246         c2=DataArrayInt([0,8,8,1,1,9,9,2,3,10,10,2,0,11,11,3,4,12,12,5,5,13,13,6,7,14,14,6,4,15,15,7,0,16,16,4,1,17,17,5,3,18,18,7,2,19,19,6])
4247         m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4248         m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
4249         mm[-2]=m2.buildUnstructured()
4250         #
4251         ref0=DataArrayInt(55) ; ref0[:]=0
4252         mm.setFamilyFieldArr(0,ref0)
4253         mm.setFamilyFieldArr(1,DataArrayInt([0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
4254         ref1=DataArrayInt([0,0,0,0,0,0,0,0,-6,-6,-6,-6,-6,-6,-6,-6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
4255         mm.setFamilyFieldArr(-1,ref1)
4256         ref2=DataArrayInt([0,0,-7,-7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
4257         mm.setFamilyFieldArr(-2,ref2)
4258         #
4259         for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
4260             mm.setFamilyId(f,fid)
4261         for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
4262             mm.setFamiliesOnGroup(grp,fams)
4263         mm.write(fileName,2)
4264         #
4265         mm=MEDFileMesh.New(fileName)
4266         grp=mm.getGroup(-1,"Groupe_1")
4267         dai=grp.computeFetchedNodeIds()
4268         dai.setName("TOTO")
4269         mm.addGroup(1,dai)
4270         mm.rearrangeFamilies() # <- the aim of the test
4271         self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
4272         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
4273         self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
4274         self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
4275         self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([0,0,2,0,9,9,9,9,0,0,0,0,9,9,9,9,0,0,0,0,0,9,0,0,0,0,0,0])))
4276         allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
4277         allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
4278         self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
4279         for elt,fams in allGrps:
4280             self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
4281         self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
4282         for elt,eltId in allFams:
4283             self.assertEqual(mm.getFamilyId(elt),eltId)
4284         pass
4285
4286     def testNonRegrCMeshSetFieldPfl1(self):
4287         """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
4288         ff=MEDFileField1TS()
4289         meshName="mesh"
4290         mm=MEDFileCMesh()
4291         m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4292         m.setCoords(arr)
4293         m.setName(meshName)
4294         mm.setMesh(m)
4295         field=MEDCouplingFieldDouble(ON_CELLS)
4296         field.setMesh(m)
4297         field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4298         field.setName("Field")
4299         field.checkCoherency()
4300         pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
4301         ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
4302         self.assertEqual(ff.getPfls(),())
4303         field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4304         self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4305         del ff,mm,field,field2,pfl
4306         # same with unstructured mesh
4307         ff=MEDFileField1TS()
4308         meshName="mesh"
4309         mm=MEDFileUMesh()
4310         m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4311         m.setCoords(arr)
4312         m.setName(meshName)
4313         m=m.buildUnstructured()
4314         mm[0]=m
4315         field=MEDCouplingFieldDouble(ON_CELLS)
4316         field.setMesh(m)
4317         field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4318         field.setName("Field")
4319         field.checkCoherency()
4320         pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
4321         ff.setFieldProfile(field,mm,0,pfl)
4322         self.assertEqual(ff.getPfls(),())
4323         field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4324         self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4325         pass
4326
4327     def testMEDFileUMeshLinearToQuadraticAndRev1(self):
4328         meshName="mesh"
4329         fileName="Pyfile90.med"
4330         fileName2="Pyfile91.med"
4331         arr=DataArrayDouble(5) ; arr.iota()
4332         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4333         m=m.buildUnstructured()
4334         d=DataArrayInt([3,7,11,15])
4335         m1=m[d]
4336         m1.simplexize(0)
4337         m2=m[d.buildComplement(m.getNumberOfCells())]
4338         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
4339         m.changeSpaceDimension(3,0.)
4340         arr=DataArrayDouble(3) ; arr.iota()
4341         m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
4342         m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
4343         delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
4344         m3D=m.buildExtrudedMesh(m1D,0)
4345         m3D.sortCellsInMEDFileFrmt()
4346         m3D.setName(meshName)
4347         m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkCoherency2()
4348         m1D=m2D.computeSkin() ; m1D.setName(meshName)
4349         m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
4350         #
4351         mm=MEDFileUMesh()
4352         mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
4353         grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
4354         grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
4355         grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
4356         grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
4357         diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
4358         vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
4359         vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
4360         mm.setGroupsAtLevel(0,[vol1,vol2])
4361         mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
4362         mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
4363         #
4364         mmOut1=mm.linearToQuadratic(0,0.)
4365         mmOut1.write(fileName2,2)
4366         mmOut2=mmOut1.quadraticToLinear(0.)
4367         self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
4368         pass
4369
4370     def testMEDFileMeshAddGroup1(self):
4371         m=MEDCouplingCMesh()
4372         arrX=DataArrayDouble(9) ; arrX.iota()
4373         arrY=DataArrayDouble(4) ; arrY.iota()
4374         m.setCoords(arrX,arrY)
4375         m.setName("mesh")
4376         mm=MEDFileCMesh()
4377         mm.setMesh(m)
4378         grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
4379         mm.addGroup(0,grp0)
4380         grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
4381         mm.addGroup(0,grp1)
4382         grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
4383         mm.addGroup(0,grp2)
4384         grp3=DataArrayInt([23]) ; grp3.setName("grp3")
4385         mm.addGroup(0,grp3)
4386         for grp in [grp0,grp1,grp2,grp3]:
4387             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4388         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
4389         delta=12
4390         for grp in [grp0,grp1,grp2,grp3]:
4391             grpNode=grp.deepCpy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
4392             mm.addGroup(1,grpNode)
4393         self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
4394         for grp in [grp0,grp1,grp2,grp3]:
4395             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4396         for grp in [grp0,grp1,grp2,grp3]:
4397             grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4398             self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4399         mm.normalizeFamIdsMEDFile()
4400         for grp in [grp0,grp1,grp2,grp3]:
4401             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4402         for grp in [grp0,grp1,grp2,grp3]:
4403             grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4404             self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4405         pass
4406
4407     pass
4408     def testMEDFileJoint1(self):
4409         fileName="Pyfile92.med"
4410         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4411         coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4412         mm=MEDFileUMesh()
4413         mm.setCoords(coo)
4414         mm.setName("maa1")
4415         mm.setDescription("un maillage")
4416         mm.write(fileName,2)
4417         node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4418         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4419         one_step_joint=MEDFileJointOneStep()
4420         one_step_joint.pushCorrespondence(cell_correspond)
4421         one_step_joint.pushCorrespondence(node_correspond)
4422         one_joint=MEDFileJoint()
4423         one_joint.pushStep(one_step_joint)
4424         one_joint.setLocalMeshName("maa1")
4425         one_joint.setRemoteMeshName("maa1")
4426         one_joint.setDescription("joint_description")
4427         one_joint.setJointName("joint_1")
4428         one_joint.setDomainNumber(1)
4429         self.assertEqual( one_joint.getLocalMeshName(), "maa1")
4430         self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
4431         self.assertEqual( one_joint.getDescription(), "joint_description")
4432         self.assertEqual( one_joint.getJointName(), "joint_1")
4433         self.assertEqual( one_joint.getDomainNumber(), 1)
4434         joints=MEDFileJoints()
4435         joints.pushJoint(one_joint);
4436         joints.write(fileName,0)
4437         # read back
4438         jointsR=MEDFileJoints(fileName,mm.getName())
4439         self.assertEqual( jointsR.getNumberOfJoints(), 1 )
4440         jR = jointsR.getJointAtPos(0)
4441         self.assertTrue( jR.isEqual( one_joint ))
4442         self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
4443         self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
4444         jointsR.destroyJointAtPos(0)
4445         
4446     pass
4447     def testMEDFileJoint2(self):
4448         fileNameWr="Pyfile93.med"
4449         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4450         coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4451         mm=MEDFileUMesh()
4452         mm.setCoords(coo)
4453         mm.setName("maa1")
4454         mm.setDescription("un maillage")
4455         node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
4456         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
4457         one_step_joint=MEDFileJointOneStep()
4458         two_step_joint=MEDFileJointOneStep()
4459         one_joint=MEDFileJoint()
4460         two_joint=MEDFileJoint()
4461         one_step_joint.pushCorrespondence(node_correspond)
4462         one_joint.pushStep(one_step_joint)
4463         two_step_joint.pushCorrespondence(cell_correspond)
4464         two_step_joint.pushCorrespondence(node_correspond)
4465         two_joint.pushStep(two_step_joint)
4466         one_joint.setLocalMeshName("maa1")
4467         one_joint.setRemoteMeshName("maa1")
4468         one_joint.setDescription("joint_description_1")
4469         one_joint.setJointName("joint_1")
4470         one_joint.setDomainNumber(1)
4471         two_joint.setLocalMeshName("maa1")
4472         two_joint.setRemoteMeshName("maa1")
4473         two_joint.setDescription("joint_description_2")
4474         two_joint.setJointName("joint_2")
4475         two_joint.setDomainNumber(2)
4476         joints=MEDFileJoints()
4477         joints.pushJoint(one_joint)
4478         joints.pushJoint(two_joint)
4479         mm.setJoints( joints )
4480         mm.write(fileNameWr,2)
4481         #
4482         mm=MEDFileMesh.New(fileNameWr)
4483         self.assertEqual( mm.getNumberOfJoints(), 2)
4484         jointsR = mm.getJoints();
4485         self.assertEqual( jointsR.getMeshName(), mm.getName() )
4486         self.assertEqual( len( jointsR ), 2 )
4487         jointR1 = jointsR[0]
4488         jointR2 = jointsR[1]
4489         self.assertFalse( jointR1 is None )
4490         self.assertFalse( jointR2 is None )
4491         self.assertTrue( jointR1.isEqual( one_joint ))
4492         self.assertTrue( jointR2.isEqual( two_joint ))
4493         pass
4494
4495     def testMEDFileJoint1(self):
4496         node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4497         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4498         cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
4499         cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
4500         joint1st_1=MEDFileJointOneStep()
4501         joint1st_1.pushCorrespondence(cell_correspond)
4502         joint1st_1.pushCorrespondence(node_correspond)
4503         joint1st_2=MEDFileJointOneStep()
4504         joint1st_2.pushCorrespondence(cell_correspond)
4505         joint1st_2.pushCorrespondence(node_correspond)
4506         joint1st_3=MEDFileJointOneStep()
4507         joint1st_3.pushCorrespondence(node_correspond)
4508         joint1st_3.pushCorrespondence(cell_correspond)
4509         joint1st_4=MEDFileJointOneStep()
4510         joint1st_4.pushCorrespondence(cell_correspond)
4511         joint1st_5=MEDFileJointOneStep()
4512         joint1st_5.pushCorrespondence(cell_correspon2)
4513         joint1st_6=MEDFileJointOneStep()
4514         joint1st_6.pushCorrespondence(cell_correspon3)
4515         self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
4516         self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
4517         self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
4518         self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
4519         self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
4520         one_joint=MEDFileJoint()
4521         one_joint.pushStep(joint1st_1)
4522         one_joint.setLocalMeshName("maa1")
4523         one_joint.setRemoteMeshName("maa2")
4524         one_joint.setDescription("joint_description")
4525         one_joint.setJointName("joint_1")
4526         one_joint.setDomainNumber(1)
4527         self.assertEqual( "maa1", one_joint.getLocalMeshName())
4528         self.assertEqual( "maa2", one_joint.getRemoteMeshName())
4529         self.assertEqual( "joint_description", one_joint.getDescription())
4530         self.assertEqual( 1, one_joint.getDomainNumber())
4531         self.assertEqual( "joint_1", one_joint.getJointName())
4532         pass
4533
4534     @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
4535     def testMEDFileSafeCall0(self):
4536         """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
4537         fname="Pyfile94.med"
4538         errfname="Pyfile94.err"
4539         class StdOutRedirect(object):
4540             def __init__(self,fileName):
4541                 import os,sys
4542                 sys.stderr.flush()
4543                 self.stdoutOld=os.dup(2)
4544                 self.fdOfSinkFile=os.open(fileName,os.O_CREAT | os.O_RDWR)
4545                 fd2=os.dup2(self.fdOfSinkFile,2)
4546                 self.origPyVal=sys.stderr
4547                 class FlushFile(object):
4548                     def __init__(self,f):
4549                         self.f=f
4550                     def write(self,st):
4551                         self.f.write(st)
4552                         self.f.flush()
4553                     def flush(self):
4554                         return self.f.flush()
4555                     def isatty(self):
4556                         return self.f.isatty()
4557                 sys.stderr=FlushFile(os.fdopen(self.fdOfSinkFile,"w"))
4558             def __del__(self):
4559                 import os,sys
4560                 sys.stderr=self.origPyVal
4561                 #os.fsync(self.fdOfSinkFile)
4562                 os.fsync(2)
4563                 os.dup2(self.stdoutOld,2)
4564                 os.close(self.stdoutOld)
4565         import os
4566         # first clean file if needed
4567         if os.path.exists(fname):
4568             os.remove(fname)
4569             pass
4570         # second : build a file from scratch
4571         m=MEDCouplingCMesh()
4572         arr=DataArrayDouble(11) ; arr.iota()
4573         m.setCoords(arr,arr)
4574         mm=MEDFileCMesh()
4575         mm.setMesh(m)
4576         mm.setName("mesh")
4577         mm.write(fname,2)
4578         # third : change permissions to remove write access on created file
4579         os.chmod(fname,0444)
4580         # four : try to append data on file -> check that it raises Exception
4581         f=MEDCouplingFieldDouble(ON_CELLS)
4582         f.setName("field")
4583         f.setMesh(m)
4584         f.setArray(DataArrayDouble(100))
4585         f.getArray()[:]=100.
4586         f.checkCoherency()
4587         f1ts=MEDFileField1TS()
4588         f1ts.setFieldNoProfileSBT(f)
4589         # redirect stderr
4590         tmp=StdOutRedirect(errfname)
4591         self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
4592         del tmp
4593         #
4594         if os.path.exists(errfname):
4595             os.remove(errfname)
4596         #
4597         pass
4598
4599     def testUnivStatus1(self):
4600         """ Non regression test to check the effectiveness of univ write status."""
4601         fname="Pyfile95.med"
4602         arr=DataArrayDouble(10) ; arr.iota()
4603         m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
4604         mm=MEDFileCMesh() ; mm.setMesh(m)
4605         mm.setUnivNameWrStatus(False) # test is here
4606         mm.write(fname,2)
4607         mm=MEDFileCMesh(fname)
4608         self.assertEqual(mm.getUnivName(),"")
4609         mm.setUnivNameWrStatus(True)
4610         mm.write(fname,2)
4611         mm=MEDFileCMesh(fname)
4612         self.assertTrue(mm.getUnivName()!="")
4613         pass
4614
4615     def testEmptyMesh(self):
4616       """ MEDLoader should be able to consistently write and read an empty mesh (coords array
4617       with 0 tuples """
4618       fname = "Pyfile96.med" 
4619       m = MEDCouplingUMesh('toto', 2)
4620       m.setCoords(DataArrayDouble([], 0, 2))
4621       m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
4622       mfu = MEDFileUMesh()
4623       mfu.setMeshAtLevel(0, m)
4624       mfu.write(fname, 2)
4625       mfu2 = MEDFileUMesh(fname)
4626       self.assertEqual('toto', mfu2.getName())
4627       lvl = mfu2.getNonEmptyLevels()
4628       self.assertEqual((), lvl)
4629
4630     pass
4631
4632 if __name__ == "__main__":
4633   unittest.main()