]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/Swig/MEDLoaderTest3.py
Salome HOME
Merge branch 'master' into V7_dev - taking only stuff not for V8
[tools/medcoupling.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 MEDLoaderTest3(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.isIdentity2(5))
895         self.assertTrue(f1.getArray().isEqual(f2,1e-12))
896         pass
897     # Test for getFieldAtTopLevel method
898     def testMEDField16(self):
899         fname="Pyfile37.med"
900         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
901         m1=f1.getMesh()
902         mm1=MEDFileUMesh.New()
903         mm1.setCoords(m1.getCoords())
904         mm1.setMeshAtLevel(0,m1)
905         mm1.setName(m1.getName())
906         ff1=MEDFileField1TS.New()
907         ff1.setFieldNoProfileSBT(f1)
908         m2=m1.buildDescendingConnectivity()[0]
909         m2.sortCellsInMEDFileFrmt()
910         m2.setName(m1.getName())
911         mm1.setMeshAtLevel(-1,m2)
912         mm1.write(fname,2)
913         f2=m2.getMeasureField(True)
914         dd=DataArrayDouble.New()
915         dd.alloc(f2.getArray().getNumberOfTuples(),3)
916         dd[:,0]=f2.getArray()
917         dd[:,1]=2*f2.getArray()
918         dd[:,2]=3*f2.getArray()
919         f2=f2.buildNewTimeReprFromThis(ONE_TIME,False)
920         f2.setArray(dd)
921         f2.copyTinyStringsFrom(f1)
922         f2.copyTinyAttrFrom(f1)
923         ff1.setFieldNoProfileSBT(f2)
924         ff1.write(fname,0)
925         # Reading Pyfile37.med
926         ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
927         f1bis=ff2.getFieldAtLevel(ON_CELLS,0)
928         self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
929         f1bis=ff2.getFieldAtLevel(ON_CELLS,-1)
930         self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
931         f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
932         self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
933         # More complex
934         fname="Pyfile38.med"
935         mm1.write(fname,2)
936         ff1=MEDFileField1TS.New()
937         ff1.setFieldNoProfileSBT(f2)
938         ff1.write(fname,0)
939         ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
940         f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
941         self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
942         pass
943
944     # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
945     def testMEDField17(self):
946         fname="Pyfile39.med"
947         m1=MEDLoaderDataForTest.build2DMesh_1()
948         m1.renumberCells([0,1,4,2,3,5],False)
949         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
950         mm1.write(fname,2)
951         ffs=MEDFileFields.New()
952         ff1=MEDFileFieldMultiTS.New()
953         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
954         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
955         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.
956         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
957         #
958         ff1.appendFieldProfile(f1,mm1,0,da)
959         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
960         ff1.appendFieldProfile(f1,mm1,0,da)
961         ffs.resize(1)
962         ffs.setFieldAtPos(0,ff1)
963         ffs=ffs.deepCpy()
964         ffs.write(fname,0)
965         #
966         ffsr=MEDFileFields.New(fname)
967         ff3=ffsr.getFieldAtPos(0)
968         f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
969         self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
970         pass
971
972     # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
973     def testMEDField18(self):
974         fname="Pyfile40.med"
975         m1=MEDLoaderDataForTest.build2DMesh_1()
976         m1.renumberCells([0,1,4,2,3,5],False)
977         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
978         mm1.write(fname,2)
979         ffs=MEDFileFields.New()
980         ff1=MEDFileFieldMultiTS.New()
981         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
982         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
983         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.
984         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
985         #
986         ff1.appendFieldProfile(f1,mm1,0,da)
987         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
988         ff1.appendFieldProfile(f1,mm1,0,da)
989         ffs.pushField(ff1)
990         ffs.write(fname,0)
991         #
992         ffsr=MEDFileFields.New(fname)
993         ff3=ffsr.getFieldAtPos(0)
994         f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
995         self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
996         pass
997
998     def testMEDFieldBug1(self):
999         fname="Pyfile13.med"
1000         d=MEDFileData.New(fname)
1001         self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs())
1002         pass
1003
1004     def testMEDMesh8(self):
1005         m=MEDLoaderDataForTest.build1DMesh_1()
1006         m.convertQuadraticCellsToLinear()
1007         mm=MEDFileUMesh.New()
1008         mm.setMeshAtLevel(0,m)
1009         g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1")
1010         g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2")
1011         g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3")
1012         mm.setGroupsAtLevel(0,[g1,g2],False)
1013         self.assertEqual(('g1','g2'),mm.getGroupsNames())
1014         self.assertEqual(('Family_-2','Family_-3'),mm.getFamiliesNames())
1015         self.assertEqual(('Family_-2',),mm.getFamiliesOnGroup('g1'))
1016         self.assertEqual(('Family_-3',),mm.getFamiliesOnGroup('g2'))
1017         mm.assignFamilyNameWithGroupName()
1018         self.assertEqual(('g1','g2'),mm.getGroupsNames())
1019         self.assertEqual(('g1','g2'),mm.getFamiliesNames())
1020         self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1'))
1021         self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2'))
1022         #
1023         mm=MEDFileUMesh.New()
1024         mm.setMeshAtLevel(0,m)
1025         mm.setGroupsAtLevel(0,[g1,g2,g3],False)
1026         self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1027         self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1028         self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1029         self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1030         self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1031         mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found
1032         self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1033         self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1034         self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1035         self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1036         self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1037         mm.changeFamilyId(5,6)
1038         g=mm.getGroupArr(0,"g3")
1039         self.assertTrue(g.isEqual(g3));
1040         g=mm.getGroupArr(0,"g2")
1041         self.assertTrue(g.isEqual(g2));
1042         g=mm.getGroupArr(0,"g1")
1043         self.assertTrue(g.isEqual(g1));
1044         pass
1045     
1046     # bug detected by gauthier
1047     def testMEDLoaderMEDLoaderNSReadFieldDoubleDataInMedFile(self):
1048         fname="Pyfile41.med"
1049         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
1050         m1=f1.getMesh()
1051         mm1=MEDFileUMesh.New()
1052         mm1.setCoords(m1.getCoords())
1053         mm1.setMeshAtLevel(0,m1)
1054         mm1.write(fname,2)
1055         ff1=MEDFileField1TS.New()
1056         ff1.setFieldNoProfileSBT(f1)
1057         ff1.write(fname,0)
1058         # writing mesh1 and field1, now creation of mesh2 and field2
1059         f2=f1.deepCpy()
1060         m2=f2.getMesh()
1061         m2.translate([0.5,0.6,0.7])
1062         m2.setName("3DSurfMesh_2")
1063         f2.getArray()[:]*=2.
1064         f2.setName("VectorFieldOnCells2")
1065         mm2=MEDFileUMesh.New()
1066         mm2.setCoords(m2.getCoords())
1067         mm2.setMeshAtLevel(0,m2)
1068         mm2.write(fname,0)
1069         ff2=MEDFileField1TS.New()
1070         ff2.setFieldNoProfileSBT(f2)
1071         ff2.write(fname,0)
1072         #
1073         f3=MEDLoader.ReadFieldCell(fname,"3DSurfMesh_1",0,"VectorFieldOnCells",0,1)
1074         self.assertTrue(f3.isEqual(f1,1e-12,1e-12))
1075         f4=MEDLoader.ReadFieldCell(fname,"3DSurfMesh_2",0,"VectorFieldOnCells2",0,1)
1076         self.assertTrue(f4.isEqual(f2,1e-12,1e-12))
1077         pass
1078
1079     def testMEDLoaderMultiLevelCellField1(self):
1080         fname="Pyfile42.med"
1081         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1082         m=MEDFileUMesh.New()
1083         m.setCoords(m2.getCoords())
1084         m.setMeshAtLevel(0,m2)
1085         m.setMeshAtLevel(-1,m1)
1086         m.setMeshAtLevel(-2,m0)
1087         m.write(fname,2)
1088         #
1089         FieldName1="Field1"
1090         compNames1=["comp1","comp2","comp3"]
1091         ff1=MEDFileField1TS.New()
1092         da2=DataArrayDouble.New()
1093         da2.alloc(m2.getNumberOfCells()*len(compNames1),1)
1094         da2.iota(7.)
1095         da2.rearrange(len(compNames1))
1096         da2.setInfoOnComponents(compNames1)
1097         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f2.setName(FieldName1) ; f2.setArray(da2) ; f2.setMesh(m2) ; f2.checkCoherency()
1098         ff1.setFieldNoProfileSBT(f2)
1099         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0]))
1100         da0=DataArrayDouble.New()
1101         da0.alloc(m0.getNumberOfCells()*len(compNames1),1)
1102         da0.iota(190.)
1103         da0.rearrange(len(compNames1))
1104         da0.setInfoOnComponents(compNames1)
1105         f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName1) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkCoherency()
1106         ff1.setFieldNoProfileSBT(f0)
1107         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-2]))
1108         da1=DataArrayDouble.New()
1109         da1.alloc(m1.getNumberOfCells()*len(compNames1),1)
1110         da1.iota(90.)
1111         da1.rearrange(len(compNames1))
1112         da1.setInfoOnComponents(compNames1)
1113         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName1) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkCoherency()
1114         ff1.setFieldNoProfileSBT(f1)
1115         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1116         #
1117         ff1.write(fname,0)
1118         #
1119         FieldName2="Field2"
1120         compNames2=["comp11","comp22"]
1121         ff2=MEDFileField1TS.New()
1122         da0=DataArrayDouble.New()
1123         da0.alloc(m0.getNumberOfCells()*2,1)
1124         da0.iota(-190.)
1125         da0.rearrange(2)
1126         da0.setInfoOnComponents(compNames2)
1127         f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName2) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkCoherency()
1128         ff2.setFieldNoProfileSBT(f0)
1129         self.assertEqual(ff2.getNonEmptyLevels(),(0, [0]))
1130         da1=DataArrayDouble.New()
1131         da1.alloc(m1.getNumberOfCells()*len(compNames2),1)
1132         da1.iota(-90.)
1133         da1.rearrange(len(compNames2))
1134         da1.setInfoOnComponents(compNames2)
1135         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName2) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkCoherency()
1136         ff2.setFieldNoProfileSBT(f1)
1137         self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1138         #
1139         ff2.write(fname,0)
1140         #
1141         ff1=MEDFileField1TS.New(fname,FieldName1,-1,-1)
1142         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1143         self.assertEqual(ff1.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')]), (3, [(0, (84, 148), '', '')]), (4, [(0, (148, 212), '', '')])])
1144         ff2=MEDFileField1TS.New(fname,FieldName2,-1,-1)
1145         self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1146         self.assertEqual(ff2.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')])])
1147         pass
1148
1149     def testFieldOnPflRetrieveOnMdimRelMax1(self):
1150         fname="Pyfile43.med"
1151         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1152         m=MEDFileUMesh.New()
1153         m.setMeshAtLevel(0,m2)
1154         m.setMeshAtLevel(-1,m1)
1155         m.setMeshAtLevel(-2,m0)
1156         f=MEDFileField1TS.New()
1157         ff=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
1158         ff.setName("NodeFieldPfl")
1159         arr=DataArrayDouble.New() ; arr.setValues([1.,10.,100.,2.,20.,200.],2,3)
1160         ff.setArray(arr)
1161         pfl=DataArrayInt.New() ; pfl.setValues([2,3],2,1) ; pfl.setName("PflNode")
1162         f.setFieldProfile(ff,m,-2,pfl)
1163         tes0=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1164         self.assertEqual(ON_NODES,tes0.getTypeOfField())
1165         self.assertEqual(1,tes0.getMesh().getMeshDimension())
1166         self.assertEqual(1,tes0.getMesh().getNumberOfCells())
1167         self.assertEqual(2,tes0.getMesh().getNumberOfNodes())
1168         self.assertEqual([1,0,1],tes0.getMesh().getNodalConnectivity().getValues())
1169         self.assertEqual([0,3],tes0.getMesh().getNodalConnectivityIndex().getValues())
1170         self.assertEqual(2,tes0.getArray().getNumberOfTuples())
1171         self.assertEqual(3,tes0.getArray().getNumberOfComponents())
1172         expected1=[1.,10.,100.,2.,20.,200.]
1173         nodeCoordsWithValue1=[10.,2.5,0.]
1174         nodeCoordsWithValue2=[10.,3.75,0.]
1175         for i in xrange(3):
1176             self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
1177             self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
1178             pass
1179         for i in xrange(6):
1180             self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
1181             pass
1182         del tes0
1183         #
1184         tes1=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1185         self.assertEqual(ON_CELLS,tes1.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1186         self.assertEqual(0,tes1.getMesh().getMeshDimension())
1187         self.assertEqual(2,tes1.getMesh().getNumberOfCells())
1188         self.assertEqual(135,tes1.getMesh().getNumberOfNodes())
1189         self.assertEqual([0,2,0,3],tes1.getMesh().getNodalConnectivity().getValues())
1190         self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
1191         self.assertEqual(2,tes1.getArray().getNumberOfTuples())
1192         self.assertEqual(3,tes1.getArray().getNumberOfComponents())
1193         for i in xrange(6):
1194             self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
1195             pass
1196         m.write(fname,2)
1197         f.write(fname,0)
1198         #
1199         pfl=DataArrayInt.New() ; pfl.setValues([3,2],2,1) ; pfl.setName("PflNode")
1200         f=MEDFileField1TS.New()
1201         f.setFieldProfile(ff,m,-2,pfl)
1202         tes2=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1203         self.assertEqual(ON_NODES,tes2.getTypeOfField())
1204         self.assertEqual(1,tes2.getMesh().getMeshDimension())
1205         self.assertEqual(1,tes2.getMesh().getNumberOfCells())
1206         self.assertEqual(2,tes2.getMesh().getNumberOfNodes())
1207         self.assertEqual([1,0,1],tes2.getMesh().getNodalConnectivity().getValues())
1208         self.assertEqual([0,3],tes2.getMesh().getNodalConnectivityIndex().getValues())
1209         self.assertEqual(2,tes2.getArray().getNumberOfTuples())
1210         self.assertEqual(3,tes2.getArray().getNumberOfComponents())
1211         expected2=[2.,20.,200.,1.,10.,100.]
1212         for i in xrange(3):
1213             self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
1214             self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
1215             pass
1216         for i in xrange(6):
1217             self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
1218             pass
1219         #
1220         tes3=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1221         self.assertEqual(ON_CELLS,tes3.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1222         self.assertEqual(0,tes3.getMesh().getMeshDimension())
1223         self.assertEqual(2,tes3.getMesh().getNumberOfCells())
1224         self.assertEqual(135,tes3.getMesh().getNumberOfNodes())
1225         self.assertEqual([0,3,0,2],tes3.getMesh().getNodalConnectivity().getValues())
1226         self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
1227         self.assertEqual(2,tes3.getArray().getNumberOfTuples())
1228         self.assertEqual(3,tes3.getArray().getNumberOfComponents())
1229         for i in xrange(6):
1230             self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
1231             pass
1232         pass
1233
1234     def testBuildInnerBoundaryAlongM1Group1(self):
1235         fname="Pyfile44.med"
1236         m=MEDCouplingCMesh.New()
1237         m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1238         m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1239         m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1240         m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1241         m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1242         m2.setName(m.getName())
1243         grp=DataArrayInt.New([4,6,8]) ; grp.setName("Grp")
1244         grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1245         mm=MEDFileUMesh.New()
1246         mm.setMeshAtLevel(0,m)
1247         mm.setMeshAtLevel(-1,m2)
1248         mm.setGroupsAtLevel(-1,[grp,grp2])
1249         grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1250         mm.setGroupsAtLevel(1,[grpNode])
1251         ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1252         ref1=[4,9,8,14,15,4,10,9,15,16,4,11,10,16,17]
1253         ref2=[4,9,8,14,30,4,10,9,30,31,4,11,10,31,32]
1254         #
1255         self.assertEqual(30,mm.getNumberOfNodes())
1256         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1257         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())
1258         #
1259         nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1260         self.assertEqual([15,16,17],nodes.getValues());
1261         self.assertEqual([7,8,9],cells.getValues());
1262         self.assertEqual([12,13,14],cells2.getValues());
1263         self.assertEqual(33,mm.getNumberOfNodes())
1264         self.assertEqual([4,6,8],mm.getGroupArr(-1,"Grp").getValues())
1265         self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1266         self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1267         self.assertEqual([17,18,19],mm.getGroupArr(-1,"Grp_dup").getValues())
1268         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
1269         self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())#
1270         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
1271         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1272         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])
1273         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1274         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1275         #
1276         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1277         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1278         refValues2=refValues[:] ; refValues2[7:10]=[1.365,1.26,1.35]
1279         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1280         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1281         mm.write(fname,2)
1282         pass
1283
1284     def testBuildInnerBoundaryAlongM1Group2(self):
1285         fname="Pyfile45.med"
1286         m=MEDCouplingCMesh.New()
1287         m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1288         m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1289         m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1290         m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1291         m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1292         m2.setName(m.getName())
1293         grp=DataArrayInt.New([4,6]) ; grp.setName("Grp")
1294         grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1295         mm=MEDFileUMesh.New()
1296         mm.setMeshAtLevel(0,m)
1297         mm.setMeshAtLevel(-1,m2)
1298         mm.setGroupsAtLevel(-1,[grp,grp2])
1299         grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1300         mm.setGroupsAtLevel(1,[grpNode])
1301         ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1302         ref1=[4,9,8,14,15,4,10,9,15,16]
1303         ref2=[4,9,8,14,30,4,10,9,30,16]
1304         #
1305         self.assertEqual(30,mm.getNumberOfNodes())
1306         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1307         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())
1308         #
1309         nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1310         self.assertEqual([15],nodes.getValues());
1311         self.assertEqual([7,8],cells.getValues());
1312         self.assertEqual([12,13],cells2.getValues());
1313         self.assertEqual(31,mm.getNumberOfNodes())
1314         self.assertEqual([4,6],mm.getGroupArr(-1,"Grp").getValues())
1315         self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1316         self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1317         self.assertEqual([17,18],mm.getGroupArr(-1,"Grp_dup").getValues())
1318         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
1319         self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())#
1320         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
1321         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1322         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])
1323         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1324         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1325         #
1326         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1327         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1328         refValues2=refValues[:] ; refValues2[7:9]=[1.365,1.47]
1329         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1330         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1331         mm.write(fname,2)       
1332         pass
1333
1334     def testBuildInnerBoundaryAlongM1Group3(self):
1335         """ Test buildInnerBoundaryAlongM1Group() with *non-connex* cracks """
1336         fname = "Pyfile73.med"
1337         m = MEDCouplingCMesh.New()
1338         m.setCoordsAt(0, DataArrayDouble([0.0,1.1,2.3,3.6,5.0]))
1339         m.setCoordsAt(1, DataArrayDouble([0.,1.,2.]))
1340         m = m.buildUnstructured(); m.setName("simple")
1341         m2 = m.buildDescendingConnectivity()[0]
1342         m2.setName(m.getName())
1343             
1344         # A crack in two non connected parts of the mesh:
1345         grpSeg = DataArrayInt([3,19]) ; grpSeg.setName("Grp") 
1346
1347         mm = MEDFileUMesh.New()
1348         mm.setMeshAtLevel(0,m)
1349         mm.setMeshAtLevel(-1,m2)
1350         mm.setGroupsAtLevel(-1,[grpSeg])
1351         nodes, cellsMod, cellsNotMod = mm.buildInnerBoundaryAlongM1Group("Grp")
1352         self.assertEqual([1,13],nodes.getValues());
1353         self.assertEqual([0,6],cellsMod.getValues());
1354         self.assertEqual([1,7],cellsNotMod.getValues());
1355         self.assertEqual(17,mm.getNumberOfNodes())
1356         self.assertEqual([3,19],mm.getGroupArr(-1,"Grp").getValues())
1357         self.assertEqual([22,23],mm.getGroupArr(-1,"Grp_dup").getValues())
1358         ref0=[4, 15, 0, 5, 6, 4, 8, 7, 12, 16]
1359         ref1=[4, 2, 1, 6, 7, 4, 9, 8, 13, 14]
1360         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[0,6]].getNodalConnectivity().getValues())
1361         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[1,7]].getNodalConnectivity().getValues())
1362         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
1363         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1364
1365         refValues=DataArrayDouble([1.1, 1.2, 1.3, 1.4, 1.1, 1.2, 1.3, 1.4])
1366         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1367         self.assertTrue(delta.getMaxValue()[0]<1e-10)
1368         #
1369         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1370         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1371         refValues2=refValues[:] ; refValues2[0] = 1.265; refValues2[6] = 1.105
1372         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ;     delta=(valsToTest-refValues2) ; delta.abs()
1373         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1374         mm.write(fname,2)   
1375
1376     def testBasicConstructors(self):
1377         fname="Pyfile18.med"
1378         m=MEDFileMesh.New(fname)
1379         m=MEDFileMesh.New(fname,"ExampleOfMultiDimW",-1,-1)
1380         m=MEDFileMesh.New(fname)
1381         m=MEDFileUMesh(fname,"ExampleOfMultiDimW",-1,-1)
1382         m=MEDFileUMesh(fname)
1383         m=MEDFileUMesh()
1384         self.testMEDMesh6()
1385         m=MEDFileCMesh("MEDFileMesh5.med")
1386         m=MEDFileCMesh("MEDFileMesh5.med","myFirstCartMesh",-1,-1)
1387         m=MEDFileCMesh()
1388         m=MEDFileMeshMultiTS()
1389         m=MEDFileMeshMultiTS(fname)
1390         m=MEDFileMeshMultiTS(fname,"ExampleOfMultiDimW")
1391         m=MEDFileMeshes()
1392         m=MEDFileMeshes(fname)
1393         m=MEDFileField1TS()
1394         m=MEDFileField1TS(fname,"FieldOnFacesShuffle",2,7)
1395         m=MEDFileFieldMultiTS()
1396         m=MEDFileFieldMultiTS(fname,"FieldOnFacesShuffle")
1397         m=MEDFileFields()
1398         m=MEDFileFields(fname)
1399         m=MEDFileData()
1400         m=MEDFileData(fname)
1401         #
1402         m=DataArrayInt() ; m=DataArrayInt(5,2) ; m=DataArrayInt([6,5,4,3,2,1],3,2)
1403         m=DataArrayDouble() ; m=DataArrayDouble(5,2) ; m=DataArrayDouble([6,5,4,3,2,1],3,2)
1404         m=MEDCouplingUMesh("jjj",2) ; m=MEDCouplingUMesh()
1405         m=MEDCouplingCMesh()
1406         m=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1407         m=MEDCouplingFieldTemplate(ON_NODES)
1408         m=MEDCouplingMultiFields([])
1409         m=MEDCouplingFieldOverTime([])
1410         pass
1411
1412     # This is a non regression test. When a field lies partially on a mesh but fully on one of its geometric type.
1413     def testBugSemiPartialField(self):
1414         fname="Pyfile46.med"
1415         m=MEDLoaderDataForTest.build2DMesh_3()
1416         m=m[:10] ; m.setName("mesh")
1417         f=m.getMeasureField(ON_CELLS)
1418         f=f.buildNewTimeReprFromThis(ONE_TIME,False)
1419         f.setTime(5.5,3,4)
1420         f.setName("SemiPartialField")
1421         #
1422         f1=f[:6] ; f1.getMesh().setName(m.getName())
1423         f2=f[6:] ; f2.getMesh().setName(m.getName())
1424         #
1425         mm=MEDFileUMesh.New()
1426         mm.setMeshAtLevel(0,m)
1427         ff=MEDFileField1TS.New()
1428         ff.setFieldProfile(f1,mm,0,DataArrayInt.Range(0,6,1)) # no name on profile -> normally it is an error but in this special case
1429         mm.write(fname,2)
1430         ff.write(fname,0)
1431         #
1432         ff2=MEDFileField1TS.New(fname,f.getName(),f.getTime()[1],f.getTime()[2])
1433         fread=ff2.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
1434         fread2=ff2.getFieldAtLevel(ON_CELLS,0)
1435         #
1436         fread.checkCoherency()
1437         fread2.checkCoherency()
1438         self.assertTrue(fread.isEqual(f1,1e-12,1e-12))
1439         self.assertTrue(fread2.isEqual(f1,1e-12,1e-12))
1440         pass
1441
1442     def testUnPolyze1(self):
1443         fname="Pyfile47.med"
1444         mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1445         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]
1446         self.assertEqual(ref,mm.getFamilyFieldAtLevel(1).getValues())
1447         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]]))
1448         mm.write(fname,2)
1449         self.assertEqual(mm.getGroupArr(0,"grp0_L0").getValues(),[0,1,2,6])
1450         self.assertEqual(mm.getGroupArr(0,"grp1_L0").getValues(),[1,3,4,5,6])
1451         self.assertEqual(mm.getGroupArr(-1,"grp0_LM1").getValues(),[1,2,3,4,5])
1452         self.assertEqual(mm.getGroupArr(-1,"grp1_LM1").getValues(),[3,4,5,6])
1453         self.assertEqual(mm.getGroupArr(-1,"grp2_LM1").getValues(),[2,6,7,8])
1454         self.assertEqual(mm.getGroupArr(1,"grp0_Node").getValues(),[0,11,15,16])
1455         self.assertEqual(mm.getGroupArr(1,"grp1_Node").getValues(),[1,2,13,14,16])
1456         self.assertEqual(mm.getFamilyFieldAtLevel(1).getValues(),ref)
1457         # to test
1458         mm.setRenumFieldArr(0,None)
1459         mm.setFamilyFieldArr(-1,None)
1460         pass
1461
1462     def testUnPolyze2(self):
1463         fname="Pyfile48.med"
1464         mfd=MEDFileData.New()
1465         mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1466         meshes=MEDFileMeshes.New()
1467         meshes.pushMesh(mm)
1468         mfd.setMeshes(meshes)
1469         fields=MEDFileFields.New()
1470         mfd.setFields(fields)
1471         ff=MEDFileFieldMultiTS.New()
1472         fields.pushField(ff)
1473         #
1474         f0_0=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f0_0.setName("f0")
1475         f0_0.setTime(9.5,3,4)
1476         da=DataArrayDouble.New(38*2) ; da.iota(6.) ; da.rearrange(2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1477         f0_0.setArray(da)
1478         f0_0.setMesh(mm.getMeshAtLevel(0))
1479         ff.appendFieldNoProfileSBT(f0_0)
1480         ff0=ff.getTimeStepAtPos(0)
1481         f0_1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_1.setName("f0")
1482         f0_1.setTime(9.5,3,4)
1483         pfl=DataArrayInt.New([1,4,5,6]) ; pfl.setName("pfltest")
1484         f0_1.setMesh(mm.getMeshAtLevel(0)[pfl])
1485         da=DataArrayDouble.New([1401.,101401.,1602.,101602.,3100.,103100.,3101.,103101.],4,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1486         f0_1.setArray(da)
1487         ff0.setFieldProfile(f0_1,mm,0,pfl)
1488         f0_2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_2.setName("f0")#provoquer error
1489         f0_2.setTime(9.5,3,4)
1490         pfl2=DataArrayInt.New([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfltestM1")
1491         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
1492         f0_2.setMesh(mm.getMeshAtLevel(-1)[pfl2])
1493         f0_2.setArray(da)
1494         ff0.setFieldProfile(f0_2,mm,-1,pfl2)
1495         mfd.getFields().shallowCpyGlobs(ff0)
1496         #
1497         mfd.unPolyzeMeshes()
1498         #
1499         fmts=mfd.getFields()[0]
1500         self.assertEqual(fmts.getNumberOfTS(),1)
1501         self.assertEqual(fmts.getTimeSteps(),[(3,4,9.5)])
1502         arr,entry=fmts.getUndergroundDataArrayExt(3,4)
1503         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))])
1504         self.assertTrue(arr[38:40].isEqualWithoutConsideringStr(DataArrayDouble([300.0,100300.0,301.0,100301.0],2,2),1e-8))
1505         self.assertTrue(arr[40:43].isEqualWithoutConsideringStr(DataArrayDouble([400.0,100400.0,401.0,100401.0,402.0,100402.0],3,2),1e-8))
1506         self.assertTrue(arr[43:46].isEqualWithoutConsideringStr(DataArrayDouble([3200.0,103200.0,3201.0,103201.0,3203.0,103203.0],3,2),1e-8))
1507         self.assertTrue(arr[46:48].isEqualWithoutConsideringStr(DataArrayDouble([1401.0,101401.0,3100.0,103100.0],2,2),1e-8))
1508         self.assertTrue(arr[48:49].isEqualWithoutConsideringStr(DataArrayDouble([1602.0,101602.0],1,2),1e-8))
1509         self.assertTrue(arr[49:50].isEqualWithoutConsideringStr(DataArrayDouble([3101.0,103101.0],1,2),1e-8))
1510         self.assertEqual(('NewPfl_0','NewPfl_1','NewPfl_2'),fmts.getPflsReallyUsed())
1511         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))
1512         self.assertEqual(fmts.getProfile("NewPfl_0").getValues(),[0,1])
1513         self.assertEqual(fmts.getProfile("NewPfl_1").getValues(),[1,2])
1514         self.assertEqual(fmts.getProfile("NewPfl_2").getValues(),[2])
1515         ftest0=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,0,mfd.getMeshes()[0])
1516         self.assertTrue(ftest0.getArray().isEqualWithoutConsideringStr(DataArrayDouble([1401.,101401.,3100.,103100.,1602.,101602.,3101.,103101.],4,2),1e-8))
1517         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])
1518         self.assertEqual(ftest0.getMesh().getNodalConnectivityIndex().getValues(),[0,5,10,17,26])
1519         ftest1=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,-1,mfd.getMeshes()[0])
1520         self.assertTrue(ftest1.getArray().isEqualWithoutConsideringStr(DataArrayDouble([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.]),1e-8))
1521         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])
1522         self.assertEqual(ftest1.getMesh().getNodalConnectivityIndex().getValues(),[0,4,8,13,18,23,29,35,43])
1523         #
1524         mfd.write(fname,2)
1525         pass
1526
1527     def testGaussWriteOnPfl1(self):
1528         fname="Pyfile49.med"
1529         fname2="Pyfile50.med"
1530         coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
1531         mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
1532         mQ8.allocateCells(1)
1533         mQ8.insertNextCell(NORM_QUAD8,range(8))
1534         mQ8.finishInsertingCells()
1535         mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
1536         mQ4.allocateCells(1)
1537         mQ4.insertNextCell(NORM_QUAD4,range(4))
1538         mQ4.finishInsertingCells()
1539         mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
1540         mT3.allocateCells(1)
1541         mT3.insertNextCell(NORM_TRI3,range(3))
1542         mT3.finishInsertingCells()
1543         
1544         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.]]
1545         ms=11*[mT3]+2*[mQ4]+7*[mQ8]
1546         ms[:]=(elt.deepCpy() for elt in ms)
1547         for m,t in zip(ms,tr):
1548             d=m.getCoords() ; d+= t
1549             pass
1550         m=MEDCouplingUMesh.MergeUMeshes(ms)
1551         m.setName("mesh")
1552         m2=m[:13] ; m2.setName(m.getName())
1553         ### 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.
1554         ### So here 2 pfls will be created (pfl_TRI3_loc_0 and pfl_TRI3_loc_1)
1555         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1556         f.setMesh(m2)
1557         f.setTime(4.5,1,2)
1558         da=DataArrayDouble(34) ; da.iota(3.)
1559         f.setArray(da)
1560         f.setName("fieldCellOnPflWithoutPfl")
1561         fInvalid=f.deepCpy()
1562         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])
1563         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])
1564         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])
1565         f.checkCoherency()
1566         fInvalid2=fInvalid.deepCpy()
1567         fInvalid2.getDiscretization().setArrayOfDiscIds(f.getDiscretization().getArrayOfDiscIds())
1568         #
1569         mm=MEDFileUMesh()
1570         mm.setMeshAtLevel(0,m)
1571         mm.write(fname,2)
1572         #
1573         f1ts=MEDFileField1TS.New()
1574         pfl=DataArrayInt(range(13)) ; pfl.setName("pfl")
1575         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set !
1576         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given !
1577         f1ts.setFieldProfile(f,mm,0,pfl)
1578         f1ts.write(fname,0)
1579         #
1580         self.assertEqual(f1ts.getPfls(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1581         self.assertEqual(f1ts.getPflsReallyUsed(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1582         da1=DataArrayInt([0,1,2,3,4,5,6,7,8]) ; da1.setName("pfl_NORM_TRI3_loc_0")
1583         self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_0").isEqual(da1))
1584         da1=DataArrayInt([9,10]) ; da1.setName("pfl_NORM_TRI3_loc_1")
1585         self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_1").isEqual(da1))
1586         self.assertEqual(f1ts.getLocs(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1587         self.assertEqual(f1ts.getLocsReallyUsed(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1588         #
1589         dataRead=MEDFileData.New(fname)
1590         mRead=dataRead.getMeshes()[0]
1591         f1tsRead=dataRead.getFields()[0][0]
1592         f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1593         f2=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1594         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
1595         f2_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1596         f2_bis.checkCoherency()
1597         self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12))
1598         #
1599         MEDLoader.WriteField(fname2,f,True)
1600         f2_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1601         self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12))
1602         ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc
1603         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1604         pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2")
1605         m2=m[pfl] ; m2.setName(m.getName())
1606         f.setMesh(m2)
1607         f.setTime(4.5,1,2)
1608         da=DataArrayDouble(35) ; da.iota(3.)
1609         f.setArray(da)
1610         f.setName("fieldCellOnPflWithoutPfl2")
1611         f.setGaussLocalizationOnCells([0,1,3],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1612         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])
1613         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])
1614         f.checkCoherency()
1615         #
1616         mm=MEDFileUMesh()
1617         mm.setMeshAtLevel(0,m)
1618         mm.write(fname,2)
1619         f1ts=MEDFileField1TS.New()
1620         f1ts.setFieldProfile(f,mm,0,pfl)
1621         self.assertEqual(f1ts.getPfls(),('pfl2_NORM_TRI3_loc_0','pfl2_NORM_TRI3_loc_1','pfl2_NORM_QUAD8_loc_2'))
1622         self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_0").getValues(),[1,2,6])
1623         self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_1").getValues(),[5,8,9])
1624         self.assertEqual(f1ts.getProfile("pfl2_NORM_QUAD8_loc_2").getValues(),[2,3,4,5])
1625         f1ts.write(fname,0)
1626         dataRead=MEDFileData.New(fname)
1627         mRead=dataRead.getMeshes()[0]
1628         f1tsRead=dataRead.getFields()[0][0]
1629         f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1630         f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1631         f3.renumberCells([0,1,3,2,4,5,6,7,8,9])
1632         self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1633         f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1634         f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9])
1635         self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1636         #
1637         MEDLoader.WriteField(fname2,f,True)
1638         f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1639         f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9])
1640         self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1641         ## Use case 3 : no pfl but creation of pfls due to gauss pts
1642         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1643         f.setMesh(m)
1644         f.setTime(4.5,1,2)
1645         da=DataArrayDouble(60) ; da.iota(3.)
1646         f.setArray(da)
1647         f.setName("fieldCellWithoutPfl")
1648         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])
1649         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])
1650         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])
1651         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])
1652         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])
1653         f.checkCoherency()
1654         mm=MEDFileUMesh()
1655         mm.setMeshAtLevel(0,m) 
1656         f1ts=MEDFileField1TS.New()
1657         f1ts.setFieldNoProfileSBT(f)
1658         self.assertEqual(f1ts.getPfls(),('Pfl_fieldCellWithoutPfl_NORM_TRI3_0','Pfl_fieldCellWithoutPfl_NORM_TRI3_1','Pfl_fieldCellWithoutPfl_NORM_QUAD8_3','Pfl_fieldCellWithoutPfl_NORM_QUAD8_4'))
1659         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_0").getValues(),[0,1,2,3,4,5,6,7,8])
1660         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_1").getValues(),[9,10])
1661         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_3").getValues(),[0,1,2,4,5])
1662         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_4").getValues(),[3,6])
1663         mm.write(fname,2)
1664         f1ts.write(fname,0)
1665         #
1666         dataRead=MEDFileData.New(fname)
1667         mRead=dataRead.getMeshes()[0]
1668         f1tsRead=dataRead.getFields()[0][0]
1669         f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1670         f3.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1671         self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1672         f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1673         f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1674         self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1675         #
1676         MEDLoader.WriteField(fname2,f,True)
1677         f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1678         f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1679         self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1680         pass
1681
1682     # Testing profile on nodes when the profile is identity but not on all nodes.
1683     def testMEDFieldPflOnNode1(self):
1684         fname="Pyfile51.med"
1685         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)
1686         m0=MEDCouplingUMesh("Mesh",2)
1687         m0.allocateCells(5)
1688         m0.insertNextCell(NORM_TRI3,[1,4,2])
1689         m0.insertNextCell(NORM_TRI3,[4,5,2])
1690         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1691         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1692         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1693         m0.finishInsertingCells()
1694         m0.setCoords(coo)
1695         m1=MEDCouplingUMesh(m0.getName(),1)
1696         m1.allocateCells(9)
1697         conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1698         for i in xrange(9):
1699             m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1700             pass
1701         m1.finishInsertingCells()
1702         m1.setCoords(coo)
1703         #
1704         m=MEDFileUMesh()
1705         m.setMeshAtLevel(0,m0)
1706         m.setMeshAtLevel(-1,m1)
1707         #
1708         dt=3 ; it=2 ; tim=4.5
1709         fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1710         fieldNode0.setName("fieldNode0")
1711         fieldNode0.setTime(tim,dt,it)
1712         pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
1713         arr=DataArrayDouble([10,11,12,13,14])
1714         fieldNode0.setArray(arr)
1715         f0=MEDFileField1TS()
1716         f0.setFieldProfile(fieldNode0,m,0,pfl0)
1717         m.write(fname,2) ; f0.write(fname,0)
1718         fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1719         fieldNode1.setName("fieldNode1")
1720         fieldNode1.setTime(tim,dt,it)
1721         pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1722         arr1=DataArrayDouble([20,21,22,23,24,25,26])
1723         fieldNode1.setArray(arr1)
1724         f1=MEDFileField1TS()
1725         f1.setFieldProfile(fieldNode1,m,-1,pfl1)
1726         f1.write(fname,0)
1727         del m,f0,m0,m1,f1
1728         ## Reading from file
1729         m=MEDFileMesh.New(fname)
1730         m0=m.getMeshAtLevel(0)
1731         m00=m0.deepCpy() ; m00=m00[[0,2]] ; m00.setName(m.getName()) ; m00.zipCoords()
1732         fieldNode0.setMesh(m00)
1733         f0=MEDFileField1TS.New(fname,fieldNode0.getName(),dt,it)
1734         ff0_1=f0.getFieldOnMeshAtLevel(ON_NODES,m0)
1735         ff0_1.checkCoherency()
1736         self.assertTrue(ff0_1.isEqual(fieldNode0,1e-12,1e-12))
1737         ff0_2=f0.getFieldAtLevel(ON_NODES,0)
1738         ff0_2.checkCoherency()
1739         self.assertTrue(ff0_2.isEqual(fieldNode0,1e-12,1e-12))
1740         ff0_3=f0.getFieldOnMeshAtLevel(ON_NODES,0,m)
1741         ff0_3.checkCoherency()
1742         self.assertTrue(ff0_3.isEqual(fieldNode0,1e-12,1e-12))
1743         ff0_4=MEDLoader.ReadFieldNode(fname,m.getName(),0,fieldNode0.getName(),dt,it)
1744         ff0_4.checkCoherency()
1745         self.assertTrue(ff0_4.isEqual(fieldNode0,1e-12,1e-12))
1746         f1=MEDFileField1TS.New(fname,fieldNode1.getName(),dt,it)
1747         m1=m.getMeshAtLevel(-1)
1748         m10=m1.deepCpy() ; m10=m10[[0,1,2,3,4,5,6,7]] ; m10.setName(m.getName()) ; m10.zipCoords()
1749         fieldNode1.setMesh(m10)
1750         ff1_1=f1.getFieldOnMeshAtLevel(ON_NODES,m1)
1751         ff1_1.checkCoherency()
1752         self.assertTrue(ff1_1.isEqual(fieldNode1,1e-12,1e-12))
1753         ff1_2=f1.getFieldAtLevel(ON_NODES,-1)
1754         ff1_2.checkCoherency()
1755         self.assertTrue(ff1_2.isEqual(fieldNode1,1e-12,1e-12))
1756         ff1_3=f1.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1757         ff1_3.checkCoherency()
1758         self.assertTrue(ff1_3.isEqual(fieldNode1,1e-12,1e-12))
1759         ff1_4=MEDLoader.ReadFieldNode(fname,m.getName(),-1,fieldNode1.getName(),dt,it)
1760         ff1_4.checkCoherency()
1761         self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1762         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]
1763         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]
1764         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]
1765         arr_r,pfl1_r=f1.getFieldWithProfile(ON_NODES,-1,m)
1766         arr_r.setName(fieldNode1.getArray().getName())
1767         self.assertTrue(arr_r.isEqual(fieldNode1.getArray(),1e-12))
1768         pfl1_r.setName(pfl1.getName())
1769         self.assertTrue(pfl1_r.isEqual(pfl1))
1770         pass
1771     
1772         # Testing profile on nodes when the profile is identity but not on all nodes.
1773     def testMEDFieldPflOnCell1(self):
1774         fname="Pyfile52.med"
1775         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)
1776         m0=MEDCouplingUMesh("Mesh",2)
1777         m0.allocateCells(5)
1778         m0.insertNextCell(NORM_TRI3,[1,4,2])
1779         m0.insertNextCell(NORM_TRI3,[4,5,2])
1780         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1781         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1782         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1783         m0.finishInsertingCells()
1784         m0.setCoords(coo)
1785         m1=MEDCouplingUMesh(m0.getName(),1)
1786         m1.allocateCells(9)
1787         conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1788         for i in xrange(9):
1789             m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1790             pass
1791         m1.finishInsertingCells()
1792         m1.setCoords(coo)
1793         #
1794         m=MEDFileUMesh()
1795         m.setMeshAtLevel(0,m0)
1796         m.setMeshAtLevel(-1,m1)
1797         #
1798         dt=3 ; it=2 ; tim=4.5
1799         fieldCell0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1800         fieldCell0.setName("fieldCell0")
1801         fieldCell0.setTime(tim,dt,it)
1802         pfl0=DataArrayInt([0,1,2]) ; pfl0.setName("PflIdentity0") # important to keep like that
1803         arr=DataArrayDouble([10,11,12])
1804         fieldCell0.setArray(arr)
1805         f0=MEDFileField1TS()
1806         f0.setFieldProfile(fieldCell0,m,0,pfl0)
1807         m.write(fname,2) ; f0.write(fname,0)
1808         fieldCell1=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1809         fieldCell1.setName("fieldCell1")
1810         fieldCell1.setTime(tim,dt,it)
1811         pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1812         arr1=DataArrayDouble([20,21,22,23,24,25,26])
1813         fieldCell1.setArray(arr1)
1814         f1=MEDFileField1TS()
1815         f1.setFieldProfile(fieldCell1,m,-1,pfl1)
1816         f1.write(fname,0)
1817         del m,f0,m0,m1,f1
1818         ## Reading from file
1819         m=MEDFileMesh.New(fname)
1820         m0=m.getMeshAtLevel(0)
1821         m00=m0.deepCpy() ; m00=m00[pfl0] ; m00.setName(m.getName())
1822         fieldCell0.setMesh(m00)
1823         f0=MEDFileField1TS.New(fname,fieldCell0.getName(),dt,it)
1824         ff0_1=f0.getFieldOnMeshAtLevel(ON_CELLS,m0)
1825         ff0_1.checkCoherency()
1826         self.assertTrue(ff0_1.isEqual(fieldCell0,1e-12,1e-12))
1827         ff0_2=f0.getFieldAtLevel(ON_CELLS,0)
1828         ff0_2.checkCoherency()
1829         self.assertTrue(ff0_2.isEqual(fieldCell0,1e-12,1e-12))
1830         ff0_3=f0.getFieldOnMeshAtLevel(ON_CELLS,0,m)
1831         ff0_3.checkCoherency()
1832         self.assertTrue(ff0_3.isEqual(fieldCell0,1e-12,1e-12))
1833         ff0_4=MEDLoader.ReadFieldCell(fname,m.getName(),0,fieldCell0.getName(),dt,it)
1834         ff0_4.checkCoherency()
1835         self.assertTrue(ff0_4.isEqual(fieldCell0,1e-12,1e-12))
1836         f1=MEDFileField1TS.New(fname,fieldCell1.getName(),dt,it)
1837         m1=m.getMeshAtLevel(-1)
1838         m10=m1.deepCpy() ; m10=m10[pfl1] ; m10.setName(m.getName())
1839         fieldCell1.setMesh(m10)
1840         ff1_1=f1.getFieldOnMeshAtLevel(ON_CELLS,m1)
1841         ff1_1.checkCoherency()
1842         self.assertTrue(ff1_1.isEqual(fieldCell1,1e-12,1e-12))
1843         ff1_2=f1.getFieldAtLevel(ON_CELLS,-1)
1844         ff1_2.checkCoherency()
1845         self.assertTrue(ff1_2.isEqual(fieldCell1,1e-12,1e-12))
1846         ff1_3=f1.getFieldOnMeshAtLevel(ON_CELLS,-1,m)
1847         ff1_3.checkCoherency()
1848         self.assertTrue(ff1_3.isEqual(fieldCell1,1e-12,1e-12))
1849         ff1_4=MEDLoader.ReadFieldCell(fname,m.getName(),-1,fieldCell1.getName(),dt,it)
1850         ff1_4.checkCoherency()
1851         self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1852         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]
1853         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]
1854         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]
1855         arr_r,pfl1_r=f1.getFieldWithProfile(ON_CELLS,-1,m)
1856         arr_r.setName(fieldCell1.getArray().getName())
1857         self.assertTrue(arr_r.isEqual(fieldCell1.getArray(),1e-12))
1858         pfl1_r.setName(pfl1.getName())
1859         self.assertTrue(pfl1_r.isEqual(pfl1))
1860         pass
1861
1862     def testMEDFileUMeshZipCoords1(self):
1863         m=MEDFileUMesh()
1864         coo=DataArrayDouble(30) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1865         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])
1866         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1867         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1868         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1869         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1870         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1871         numCoo=DataArrayInt(10) ; numCoo.iota(3) ; m.setRenumFieldArr(1,numCoo)
1872         famCoo=DataArrayInt(10) ; famCoo.iota(4) ; m.setFamilyFieldArr(1,famCoo)
1873         da=DataArrayInt([20,30,40]) ; m.setRenumFieldArr(0,da) ; da=DataArrayInt([200,300,400]) ; m.setFamilyFieldArr(0,da)
1874         da=DataArrayInt([50,60]) ; m.setRenumFieldArr(-1,da) ; da=DataArrayInt([500,600]) ; m.setFamilyFieldArr(-1,da)
1875         da=DataArrayInt([70,80,90]) ; m.setRenumFieldArr(-2,da) ; da=DataArrayInt([700,800,900]) ; m.setFamilyFieldArr(-2,da)
1876         o2n=m.zipCoords()
1877         self.assertTrue(o2n.isEqual(DataArrayInt([-1,0,1,2,3,-1,4,5,6,-1])))
1878         self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt([4,5,6,7,9,10,11])))
1879         self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([5,6,7,8,10,11,12])))
1880         self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,4,1,3,2,3,5,0,4,4,4,1])))
1881         self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,9,15])))
1882         self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivity().isEqual(DataArrayInt([1,0,4,1,5,2])))
1883         self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6])))
1884         self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivity().isEqual(DataArrayInt([0,1,0,4,0,6])))
1885         self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivityIndex().isEqual(DataArrayInt([0,2,4,6])))
1886         pass
1887
1888     def testMEDUMeshAddNodeGroup1(self):
1889         fname="Pyfile53.med"
1890         m=MEDFileUMesh()
1891         coo=DataArrayDouble(39) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1892         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])
1893         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1894         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1895         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1896         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1897         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1898         #
1899         mm=m.deepCpy()
1900         famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(1,famCoo)
1901         da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(0,da0)
1902         da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
1903         da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
1904         mm.setFamilyId("MyFam",2)
1905         mm.setFamilyId("MyOtherFam",3)
1906         mm.setFamilyId("MyOther-1",-1)
1907         mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
1908         mm.setFamiliesOnGroup("grpA",["MyOther-1"])
1909         #
1910         daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
1911         mm.addNodeGroup(daTest)
1912         self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
1913         self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
1914         for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
1915             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1916             pass
1917         self.assertEqual(mm.getFamiliesNames(),('Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
1918         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1919         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1920         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1921         for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
1922             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1923             pass
1924         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_8'))
1925         da=DataArrayInt([3,12]) ; da.setName("grp0")
1926         self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
1927         da.setValues([1])
1928         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
1929         mm.write(fname,2)
1930         mm=MEDFileMesh.New(fname)
1931         self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
1932         self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
1933         for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
1934             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1935             pass
1936         self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
1937         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1938         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1939         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1940         for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
1941             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1942             pass
1943         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_8','MyOtherFam'))
1944         da=DataArrayInt([3,12]) ; da.setName("grp0")
1945         self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
1946         da.setValues([1])
1947         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
1948         pass
1949
1950     def testMEDUMeshAddGroup1(self):
1951         fname="Pyfile54.med"
1952         m=MEDFileUMesh()
1953         coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1954         m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
1955         for i in xrange(7):
1956             m0.insertNextCell(NORM_TRI3,[1,2,1])
1957             pass
1958         for i in xrange(4):
1959             m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
1960             pass
1961         for i in xrange(2):
1962             m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
1963             pass
1964         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1965         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1966         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1967         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1968         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1969         #
1970         mm=m.deepCpy()
1971         famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(0,famCoo)
1972         da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(1,da0)
1973         da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
1974         da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
1975         mm.setFamilyId("MyFam",2)
1976         mm.setFamilyId("MyOtherFam",3)
1977         mm.setFamilyId("MyOther-1",-1)
1978         mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
1979         mm.setFamiliesOnGroup("grpA",["MyOther-1"])
1980         #
1981         daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
1982         mm.addGroup(0,daTest)
1983         self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
1984         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
1985         for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
1986             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1987             pass
1988         self.assertEqual(mm.getFamiliesNames(),('Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
1989         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1990         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1991         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1992         for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
1993             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1994             pass
1995         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_-8'))
1996         da=DataArrayInt([3,12]) ; da.setName("grp0")
1997         self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
1998         da.setValues([1])
1999         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2000         mm.write(fname,2)
2001         mm=MEDFileMesh.New(fname)
2002         self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2003         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2004         for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2005             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2006             pass
2007         self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2008         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2009         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2010         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2011         for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2012             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2013             pass
2014         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_-8','MyOtherFam'))
2015         da=DataArrayInt([3,12]) ; da.setName("grp0")
2016         self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2017         da.setValues([1])
2018         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2019         pass
2020
2021     def testHeapMem1(self):
2022         a=DataArrayInt() ; aa=a.getHeapMemorySize()
2023         a.alloc(0,1)
2024         strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
2025         #
2026         m=MEDCouplingCMesh()
2027         arr=DataArrayDouble(10,1) ; arr.iota(0)
2028         m.setCoords(arr,arr)
2029         m=m.buildUnstructured()
2030         m.setName("mm")
2031         f=m.getMeasureField(ON_CELLS)
2032         self.assertIn(m.getHeapMemorySize(),xrange(3552-100,3552+100+4*strMulFac))
2033         self.assertIn(f.getHeapMemorySize(),xrange(4215-100,4215+100+8*strMulFac))
2034         #
2035         mm=MEDFileUMesh()
2036         mm.setMeshAtLevel(0,m)
2037         self.assertIn(mm.getHeapMemorySize(),xrange(3889-100,3889+100+10*strMulFac))
2038         ff=MEDFileField1TS()
2039         ff.setFieldNoProfileSBT(f)
2040         self.assertIn(ff.getHeapMemorySize(),xrange(771-40,771+21+(4+1)*strMulFac))
2041         #
2042         fff=MEDFileFieldMultiTS()
2043         fff.appendFieldNoProfileSBT(f)
2044         self.assertIn(fff.getHeapMemorySize(),xrange(815-50,815+30+(6+2)*strMulFac))
2045         f.setTime(1.,0,-1)
2046         fff.appendFieldNoProfileSBT(f)
2047         self.assertIn(fff.getHeapMemorySize(),xrange(1594-90,1594+50+(10+1)*strMulFac))
2048         self.assertIn(fff[0,-1].getHeapMemorySize(),xrange(771-40,771+20+(4+1)*strMulFac))
2049         f2=f[:50]
2050         f2.setTime(2.,1,-1)
2051         pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2052         fff.appendFieldProfile(f2,mm,0,pfl)
2053         self.assertIn(fff.getHeapMemorySize(),xrange(2348-130,2348+100+(10+2)*strMulFac))
2054         self.assertIn(fff.getProfile("pfl").getHeapMemorySize(),xrange(204-10,204+10+2*strMulFac))
2055         self.assertIn(fff[1,-1].getHeapMemorySize(),xrange(738-50,738+30+4*strMulFac))
2056         pass
2057
2058     def testCurveLinearMesh1(self):
2059         fname="Pyfile55.med"
2060         mesh=MEDCouplingCurveLinearMesh();
2061         mesh.setTime(2.3,4,5);
2062         mesh.setTimeUnit("us");
2063         mesh.setName("Example of Cuve linear mesh");
2064         mesh.setDescription("buildCLMesh");
2065         a1=DataArrayDouble(3*20,1);
2066         a1.iota(7.) ; a1.rearrange(3);
2067         mesh.setCoords(a1);
2068         mesh.setNodeGridStructure([4,5]);
2069         mesh.checkCoherency();
2070         #
2071         m=MEDFileCurveLinearMesh()
2072         m.setMesh(mesh)
2073         d=DataArrayInt(20) ; d.iota(4)
2074         m.setFamilyFieldArr(1,d)
2075         d3=DataArrayInt(20) ; d3.iota(400)
2076         m.setRenumFieldArr(1,d3)
2077         d2=DataArrayInt(12) ; d2.iota(40)
2078         m.setFamilyFieldArr(0,d2)
2079         d4=DataArrayInt(21) ; d4.iota(4000)
2080         self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2081         d4.popBackSilent()
2082         m.setRenumFieldArr(1,d4)
2083         m.write(fname,2)
2084         #
2085         m1=MEDFileCurveLinearMesh(fname)
2086         mm=m1.getMesh()
2087         self.assertTrue(mm.isEqual(mesh,1e-12))
2088         self.assertEqual(mm.getSpaceDimension(),3)
2089         self.assertEqual(mm.getSpaceDimensionOnNodeStruct(),2)
2090         #
2091         m1=MEDFileMesh.New(fname)
2092         self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2093         self.assertTrue(isinstance(m1.getUnivName(),str))
2094         self.assertTrue(len(m1.getUnivName())!=0)
2095         self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2096         pass
2097
2098     def testParameters1(self):
2099         fname="Pyfile56.med"
2100         m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2101         mm=MEDFileCMesh() ; mm.setMesh(m)
2102         ms=MEDFileMeshes() ; ms.pushMesh(mm)
2103         data=MEDFileData()
2104         p=MEDFileParameters()
2105         data.setParams(p) ; data.setMeshes(ms)
2106         pts=MEDFileParameterMultiTS()
2107         pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2108         pts.appendValue(1,2,3.4,567.89)
2109         pts.appendValue(2,3,5.6,999.123)
2110         pts2=pts.deepCpy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2111         p.pushParam(pts) ; p.pushParam(pts2)
2112         data.write(fname,2)
2113         p2=MEDFileParameters(fname)
2114         self.assertTrue(p.isEqual(p2,1e-14)[0])
2115         self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2116         p3=p.deepCpy()
2117         pts4=pts2.deepCpy()
2118         pts3=pts2.deepCpy()
2119         self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2120         pts2.eraseTimeStepIds([0])
2121         self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2122         del pts3[[3.4]]
2123         self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2124         self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2125         self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2126         self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2127         self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2128         p=p3
2129         self.assertTrue(p.isEqual(p2,1e-14)[0])
2130         self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2131         self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2132         self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2133         self.assertEqual(p.getParamsNames(),('A','B'))
2134         ptsr=MEDFileParameterMultiTS(fname,"B")
2135         self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2136         ptsr=MEDFileParameterMultiTS(fname)
2137         self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2138         p1tsr=MEDFileParameterDouble1TS(fname)
2139         self.assertEqual(p1tsr.getName(),"A")
2140         self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2141         p1tsr=MEDFileParameterDouble1TS(fname,"B")
2142         self.assertEqual(p1tsr.getName(),"B")
2143         self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2144         p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2145         self.assertEqual(p1tsr.getName(),"B")
2146         self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2147         data2=MEDFileData(fname)
2148         self.assertEqual(2,data2.getNumberOfParams())
2149         self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2150         pass
2151
2152     def testNamesOnCellAndNodesInMeshes1(self):
2153         fname="Pyfile58.med"
2154         fname2="Pyfile59.med"
2155         m=MEDLoaderDataForTest.build3DSurfMesh_1()
2156         m1=m.buildDescendingConnectivity()[0]
2157         m1.sortCellsInMEDFileFrmt()
2158         #
2159         mm=MEDFileUMesh()
2160         mm.setMeshAtLevel(0,m)
2161         mm.setMeshAtLevel(-1,m1)
2162         namesCellL0=DataArrayAsciiChar(6,16)
2163         namesCellL0[:]=["CellL0#%.3d      "%(i) for i in xrange(6)]
2164         mm.setNameFieldAtLevel(0,namesCellL0)
2165         namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.substr(2)])
2166         namesCellL1[:]=["CellLM1#%.3d     "%(i) for i in xrange(16)]
2167         mm.setNameFieldAtLevel(-1,namesCellL1)
2168         namesNodes=namesCellL1.substr(4,16)
2169         namesNodes[:]=["Node#%.3d        "%(i) for i in xrange(12)]
2170         mm.setNameFieldAtLevel(1,namesNodes)
2171         mm.write(fname,2)
2172         #
2173         mmr=MEDFileMesh.New(fname)
2174         self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d      "%(i) for i in xrange(6)])))
2175         self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d     "%(i) for i in xrange(16)])))
2176         self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d        "%(i) for i in xrange(12)])))
2177         self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2178         mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2179         self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2180         mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2181         self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2182         mmCpy=mm.deepCpy()
2183         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2184         # remove names on nodes
2185         mmCpy.setNameFieldAtLevel(1,None)
2186         self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2187         mm.setNameFieldAtLevel(1,None)
2188         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2189         mm.setNameFieldAtLevel(-1,None)
2190         mm.write(fname,2)
2191         mmr=MEDFileMesh.New(fname)
2192         self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2193         self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d      "%(i) for i in xrange(6)])))
2194         self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2195         #
2196         c=MEDCouplingCMesh()
2197         arr=DataArrayDouble([0.,1.1,2.3])
2198         c.setCoords(arr,arr)
2199         c.setName("cmesh")
2200         cc=MEDFileCMesh()
2201         cc.setMesh(c)
2202         cc.setNameFieldAtLevel(0,DataArrayAsciiChar(["Cell#%.3d        "%(i) for i in xrange(4)]))
2203         cc.setNameFieldAtLevel(1,DataArrayAsciiChar(["Node#%.3d        "%(i) for i in xrange(9)]))
2204         cc.write(fname2,2)
2205         ccr=MEDFileMesh.New(fname2)
2206         self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d        "%(i) for i in xrange(4)])))
2207         self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d        "%(i) for i in xrange(9)])))
2208         self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2209         ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2210         self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2211         ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2212         self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2213         ccCpy=cc.deepCpy()
2214         self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2215         pass
2216
2217     def testToExportInExamples1(self):
2218         m=MEDCouplingCMesh()
2219         arr=DataArrayDouble([0.,1.,2.,3.,4.])
2220         m.setCoords(arr,arr)
2221         m=m.buildUnstructured() ; m.setName("mesh")
2222         grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2223         grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2224         m2=m.computeSkin()
2225         mm=MEDFileUMesh()
2226         mm.setMeshAtLevel(0,m)
2227         mm.setMeshAtLevel(-1,m2)
2228         mm.setGroupsAtLevel(0,[grp1,grp2])
2229         mm.write("example.med",2)
2230         #
2231         m0=mm.getMeshAtLevel(0)
2232         m1=mm.getMeshAtLevel(-1)
2233         grp1=mm.getGroupArr(0,"grp1")
2234         grp2=mm.getGroupArr(0,"grp2")
2235         grps=[grp1,grp2]
2236         whichGrp=DataArrayInt(m0.getNumberOfCells())
2237         whichGrp.fillWithValue(-1)
2238         for grpId,grp in enumerate(grps):
2239             whichGrp[grp]=grpId
2240             pass
2241         a,b,bI,c,cI=m0.buildDescendingConnectivity()
2242         e,f=a.areCellsIncludedIn(m1,2)
2243         self.assertTrue(e)
2244         c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2245         self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2246         c2.transformWithIndArr(whichGrp)
2247         splitOfM1=len(grps)*[None]
2248         for grpId,grp in enumerate(grps):
2249             tmp=c2.getIdsEqual(grpId)
2250             splitOfM1[grpId]=tmp
2251             pass
2252         splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2253         splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2254         pass
2255
2256     def testBugCorrection1(self):
2257         fs=MEDFileFields()
2258         fs.resize(3)
2259         self.assertEqual(fs[0],None)
2260         self.assertEqual(3,len(fs))
2261         pass
2262
2263     def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2264         f1Name="Pyfile60.med"
2265         f2Name="Pyfile61.med"
2266         d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2267         d1.write(f1Name,2)
2268         d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2269         d2.write(f2Name,2)
2270         # reading and compare
2271         d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2272         for mn in d1.getMeshes().getMeshesNames():
2273             m1=d1.getMeshes()[mn]
2274             m2=d2.getMeshes()[mn]
2275             for lev in m1.getNonEmptyLevels():
2276                 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2277                 for grpName in grpsNames:
2278                     self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2279                     pass
2280                 pass
2281             pass
2282         for fieldn in d1.getFields().getFieldsNames():
2283             f1=d1.getFields()[fieldn]
2284             f2=d2.getFields()[fieldn]
2285             for it,order,tim in f1.getTimeSteps():
2286                 f1t=f1[it,order]
2287                 f2t=f2[it,order]
2288                 if len(f1t.getPflsReallyUsed())!=0:
2289                     # profile case
2290                     for lev in f1t.getNonEmptyLevels()[1]:
2291                         arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2292                         arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2293                         self.assertTrue(pfl1.isEqual(pfl2))
2294                         self.assertTrue(arr1.isEqual(arr2,1e-10))
2295                         pass
2296                     pass
2297                 else:
2298                     # no profile case
2299                     for lev in f1t.getNonEmptyLevels()[1]:
2300                         f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2301                         f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2302                         self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2303                         pass
2304                     pass
2305                 pass
2306             pass
2307         pass
2308
2309     def testNonRegBugNormalizeFamIdsMEDFile1(self):
2310         m=MEDCouplingCMesh()
2311         arr=DataArrayDouble([0.,1.,2.,3.,4.])
2312         m.setCoords(arr,arr,arr)
2313         m=m.buildUnstructured()
2314         m2=m.buildDescendingConnectivity()[0]
2315         m.setName("mesh")
2316         g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2317         g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2318         g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2319         g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2320         g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2321         g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2322         mm=MEDFileUMesh()
2323         mm.setMeshAtLevel(0,m)
2324         mm.setGroupsAtLevel(0,[g1,g2])
2325         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2326         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2327         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2328         mm.normalizeFamIdsMEDFile()
2329         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2330         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2331         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2332         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2333         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2334         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2335         for g in mm.getGroupsOnSpecifiedLev(0):
2336             for f in mm.getFamiliesIdsOnGroup(g):
2337                 self.assertTrue(f<0)
2338                 pass
2339             pass
2340         #
2341         mm=MEDFileUMesh()
2342         mm.setMeshAtLevel(0,m)
2343         mm.setMeshAtLevel(-1,m2)
2344         mm.setGroupsAtLevel(0,[g1,g2])
2345         mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2346         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2347         s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2348         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2349         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2350         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2351         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2352         mm.normalizeFamIdsMEDFile()
2353         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2354         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2355         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2356         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2357         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2358         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2359         self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2360         self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2361         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2362         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2363         self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2364         self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2365         for lev in [0,-1]:
2366             for g in mm.getGroupsOnSpecifiedLev(lev):
2367                 for f in mm.getFamiliesIdsOnGroup(g):
2368                     self.assertTrue(f<0)
2369                     pass
2370                 pass
2371             pass
2372          #
2373         mm=MEDFileUMesh()
2374         mm.setMeshAtLevel(0,m)
2375         mm.setMeshAtLevel(-1,m2)
2376         mm.setGroupsAtLevel(0,[g1,g2])
2377         mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2378         mm.setGroupsAtLevel(1,[g1Node,g2Node])
2379         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2380         s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2381         s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2382         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2383         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2384         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2385         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2386         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2387         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2388         mm.normalizeFamIdsMEDFile()
2389         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2390         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2391         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2392         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2393         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2394         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2395         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2396         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2397         self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2398         self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2399         self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2400         self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2401         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2402         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2403         self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2404         self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2405         self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2406         self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2407         for lev in [0,-1]:
2408             for g in mm.getGroupsOnSpecifiedLev(lev):
2409                 for f in mm.getFamiliesIdsOnGroup(g):
2410                     self.assertTrue(f<0)
2411                     pass
2412                 pass
2413             pass
2414         for g in mm.getGroupsOnSpecifiedLev(1):
2415             for f in mm.getFamiliesIdsOnGroup(g):
2416                 self.assertTrue(f>0)
2417                 pass
2418             pass
2419         pass
2420     
2421     def testNonRegressionMantis22212ChangeGrpName(self):
2422         fileName="Pyfile62.med"
2423         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2424         m=MEDFileUMesh.New()
2425         m.setCoords(m2.getCoords())
2426         m.setMeshAtLevel(0,m2)
2427         m.setMeshAtLevel(-1,m1)
2428         m.setMeshAtLevel(-2,m0)
2429         m.setFamilyFieldArr(0,f2)
2430         m.setFamilyFieldArr(-1,f1)
2431         m.setFamilyFieldArr(-2,f0)
2432         m.setFamilyFieldArr(1,p)
2433         nbOfFams=len(fns)
2434         for i in xrange(nbOfFams):
2435             m.addFamily(fns[i],fids[i])
2436             pass
2437         nbOfGrps=len(grpns)
2438         for i in xrange(nbOfGrps):
2439             m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2440             pass
2441         m.setName(m2.getName())
2442         m.setDescription(m2.getDescription())
2443         m.write(fileName,2)
2444         #
2445         mm0=MEDFileMesh.New(fileName)
2446         mm1=MEDFileMesh.New(fileName)
2447         groupNamesIni=MEDLoader.GetMeshGroupsNames(fileName,"ma")
2448         for name in groupNamesIni:
2449             mm1.changeGroupName(name,name+'N')
2450             pass
2451         mm1.write(fileName,2)
2452         del mm1
2453         #
2454         mm2=MEDFileMesh.New(fileName)
2455         for name in groupNamesIni:
2456             for lev in mm0.getGrpNonEmptyLevelsExt(name):
2457                 arr0=mm0.getGroupArr(lev,name)
2458                 arr2=mm2.getGroupArr(lev,name+'N')
2459                 arr0.setName(name+'N')
2460                 self.assertTrue(arr0.isEqual(arr2))
2461                 pass
2462             pass
2463         pass
2464
2465     def testInt32InMEDFileFieldStar1(self):
2466         fname="Pyfile63.med"
2467         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2468         arr=f1.getArray().convertToIntArr()
2469         f1.setArray(None)
2470         m1=f1.getMesh()
2471         mm1=MEDFileUMesh.New()
2472         mm1.setCoords(m1.getCoords())
2473         mm1.setMeshAtLevel(0,m1)
2474         mm1.setName(m1.getName())
2475         mm1.write(fname,2)
2476         ff1=MEDFileIntField1TS()
2477         ff1.setFieldNoProfileSBT(f1,arr)
2478         a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2479         self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2480         self.assertTrue(b.isEqual(arr))
2481         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2482         ff1.write(fname,0)
2483         ff2=MEDFileAnyTypeField1TS.New(fname)
2484         self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2485         self.assertEqual(ff2.getTime(),[0,1,2.0])
2486         self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2487         a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2488         self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2489         self.assertTrue(b.isEqual(arr))
2490         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2491         ff2.setTime(1,2,3.)
2492         c=ff2.getUndergroundDataArray() ; c*=2
2493         ff2.write(fname,0) # 2 time steps in 
2494         ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2495         self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2496         self.assertEqual(len(ffs1),2)
2497         self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2498         a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2499         self.assertTrue(b.isEqual(arr))
2500         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2501         a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2502         self.assertTrue(b.isEqual(arr))
2503         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2504         it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2505         a,b=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2506         self.assertTrue(b.isEqual(2*arr))
2507         f1.setTime(3.,1,2)
2508         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2509         bc=DataArrayInt(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2510         for it in ffs1:
2511             a,b=it.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2512             bc+=b
2513             pass
2514         self.assertTrue(bc.isEqual(3*arr))
2515         nf1=MEDCouplingFieldDouble(ON_NODES)
2516         nf1.setTime(9.,10,-1)
2517         nf1.setMesh(f1.getMesh())
2518         narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=range(12) ; narr[:,1]=2*narr[:,0]
2519         nf1.setName("VectorFieldOnNodes")
2520         nff1=MEDFileIntField1TS.New()
2521         nff1.setFieldNoProfileSBT(nf1,narr)
2522         self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2523         self.assertEqual(nff1.getTime(),[10,-1,9.0])
2524         nff1.write(fname,0)
2525         #
2526         nf2=MEDCouplingFieldDouble(ON_NODES)
2527         nf2.setTime(19.,20,-11)
2528         nf2.setMesh(f1.getMesh())
2529         narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=range(8) ; narr2[:,0]+=10  ; narr2[:,1]=3*narr2[:,0]
2530         nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName())
2531         nff2=MEDFileIntField1TS.New()
2532         npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
2533         nff2.setFieldProfile(nf2,narr2,mm1,0,npfl)
2534         nff2.getFieldWithProfile(ON_NODES,0,mm1)
2535         a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2536         self.assertTrue(b.isEqual(npfl))
2537         self.assertTrue(a.isEqual(narr2))
2538         nff2.write(fname,0)
2539         nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
2540         a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2541         self.assertTrue(b.isEqual(npfl))
2542         self.assertTrue(a.isEqual(narr2))
2543         #
2544         nf3=MEDCouplingFieldDouble(ON_NODES)
2545         nf3.setName("VectorFieldOnNodesDouble")
2546         nf3.setTime(29.,30,-21)
2547         nf3.setMesh(f1.getMesh())
2548         nf3.setArray(f1.getMesh().getCoords())
2549         nff3=MEDFileField1TS.New()
2550         nff3.setFieldNoProfileSBT(nf3)
2551         nff3.write(fname,0)
2552         fs=MEDFileFields(fname)
2553         self.assertEqual(len(fs),4)
2554         ffs=[it for it in fs]
2555         self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
2556         self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
2557         self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
2558         self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
2559         #
2560         self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(arr))
2561         self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*arr))
2562         self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
2563         self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
2564         self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2565         #
2566         nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
2567         self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2568         self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
2569         self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
2570         MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
2571         self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
2572         MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
2573         self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
2574         #
2575         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
2576         self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2577         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
2578         self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2579         pass
2580
2581     def testMEDFileFields1(self):
2582         fname="Pyfile64.med"
2583         f1=MEDCouplingFieldDouble(ON_NODES)
2584         f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
2585         c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
2586         mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
2587         f1.setMesh(m)
2588         arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=range(12) ; arr[:,1]=2*arr[:,0]
2589         f1.setArray(arr)
2590         f1.setName("Field1")
2591         ff1=MEDFileField1TS.New()
2592         ff1.setFieldNoProfileSBT(f1)
2593         self.assertEqual(ff1.getDtUnit(),"us")
2594         ff1.write(fname,0)
2595         f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2596         f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2597         #
2598         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2599         ff1s=MEDFileFieldMultiTS(fname,"Field1")
2600         ff1s.setName("Field2")
2601         ff1s.write(fname,0)
2602         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2603         f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2604         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
2605         self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
2606         self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
2607         f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2608         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
2609         self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
2610         pass
2611
2612     # Multi time steps and multi fields management without Globals (profiles, locs) aspects
2613     def testMEDFileFields2(self):
2614         fname="Pyfile65.med"
2615         # to check that all is initialize 
2616         MEDFileField1TS().__str__()
2617         MEDFileFieldMultiTS().__str__()
2618         # building a mesh containing 4 tri3 + 5 quad4
2619         tri=MEDCouplingUMesh("tri",2)
2620         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2621         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2622         tris=[tri.deepCpy() for i in xrange(4)]
2623         for i,elt in enumerate(tris): elt.translate([i,0])
2624         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2625         quad=MEDCouplingUMesh("quad",2)
2626         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2627         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2628         quads=[quad.deepCpy() for i in xrange(5)]
2629         for i,elt in enumerate(quads): elt.translate([5+i,0])
2630         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2631         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2632         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2633         #
2634         fmts0_0=MEDFileFieldMultiTS()
2635         fmts0_1=MEDFileFieldMultiTS()
2636         # time steps
2637         for i in xrange(10):
2638             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2639             d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2640             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2641             f.setTime(float(i+1)+0.1,i+1,-i-1)
2642             fmts0_0.appendFieldNoProfileSBT(f)
2643             f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
2644             self.assertEqual(fmts0_1.getName(),name1)
2645             self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2646             self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2647             if i>1:
2648                 # components names have been modified to generate errors
2649                 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
2650                 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
2651                 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
2652                 f1ts.setInfo(['aa [bb]','eee [dd]'])
2653                 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
2654                 pass
2655             # add a mismatch of nb of compos
2656             pass
2657         fmts0_2=fmts0_0.deepCpy()
2658         fmts0_3=fmts0_0.deepCpy()
2659         fmts0_4=fmts0_0.deepCpy()
2660         fmts0_5=fmts0_0.shallowCpy()
2661         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)
2662         del fmts0_2[::2]
2663         self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
2664         del fmts0_3[[1.1,(6,-6),9]]
2665         self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
2666         fmts0_6=fmts0_4[[1.1,(6,-6),8]]
2667         self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
2668         self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
2669         fmts0_7=fmts0_4[::-3]
2670         self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
2671         self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
2672         #
2673         fs0=MEDFileFields()
2674         fs0.pushField(fmts0_0)
2675         fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2676         fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2677         fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2678         self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
2679         fs0.write(fname,2)
2680         fs0=MEDFileFields(fname)
2681         self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
2682         fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
2683         self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2684         del fs1[["2ndField",3]]
2685         self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2686         fs2=fs0[[0,"4thField"]]
2687         self.assertTrue(isinstance(fs2,MEDFileFields))
2688         self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
2689         #
2690         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
2691         pass
2692
2693     # Multi time steps and multi fields management with Globals (profiles, locs) aspects
2694     def testMEDFileFields3(self):
2695         fname="Pyfile66.med"
2696         # building a mesh containing 4 tri3 + 5 quad4
2697         tri=MEDCouplingUMesh("tri",2)
2698         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2699         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2700         tris=[tri.deepCpy() for i in xrange(4)]
2701         for i,elt in enumerate(tris): elt.translate([i,0])
2702         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2703         quad=MEDCouplingUMesh("quad",2)
2704         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2705         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2706         quads=[quad.deepCpy() for i in xrange(5)]
2707         for i,elt in enumerate(quads): elt.translate([5+i,0])
2708         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2709         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2710         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2711         #
2712         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2713         #
2714         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2715         pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2716         fmts0_0=MEDFileFieldMultiTS()
2717         fmts0_1=MEDFileFieldMultiTS()
2718         # time steps
2719         for i in xrange(10):
2720             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2721             d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2722             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2723             f.setTime(float(i+1)+0.1,i+1,-i-1)
2724             fmts0_0.appendFieldProfile(f,mm,0,pfl)
2725             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2726             self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2727             self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2728             pass
2729         #
2730         self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
2731         self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
2732         fmts0_0.zipPflsNames()
2733         self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
2734         self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
2735         fmts0_2=fmts0_0.deepCpy()
2736         fmts0_3=fmts0_0.deepCpy()
2737         fmts0_4=fmts0_0.deepCpy()
2738         fs0=MEDFileFields()
2739         fs0.pushField(fmts0_0)
2740         fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2741         fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2742         fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2743         self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
2744         #
2745         fmts0_5=MEDFileFieldMultiTS()
2746         for i in xrange(7):
2747             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2748             d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2749             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2750             f.setTime(float(i+1)+0.1,i+1,-i-1)
2751             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
2752             pass
2753         fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
2754         self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
2755         fs0.checkGlobsCoherency()
2756         fs0.write(fname,0)
2757         pass
2758     
2759     def testSplitComponents1(self):
2760         fname="Pyfile67.med"
2761         # building a mesh containing 4 tri3 + 5 quad4
2762         tri=MEDCouplingUMesh("tri",2)
2763         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2764         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2765         tris=[tri.deepCpy() for i in xrange(4)]
2766         for i,elt in enumerate(tris): elt.translate([i,0])
2767         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2768         quad=MEDCouplingUMesh("quad",2)
2769         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2770         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2771         quads=[quad.deepCpy() for i in xrange(5)]
2772         for i,elt in enumerate(quads): elt.translate([5+i,0])
2773         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2774         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2775         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2776         #
2777         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2778         #
2779         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2780         pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2781         fs=MEDFileFields()
2782         fmts0_1=MEDFileFieldMultiTS()
2783         # time steps
2784         infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
2785         for i in xrange(10):
2786             name1="1stField"
2787             d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2788             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2789             f.setTime(float(i+1)+0.1,i+1,-i-1)
2790             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2791             self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
2792             pass
2793         fs.pushField(fmts0_1)
2794         self.assertEqual(1,len(fs))
2795         l=fmts0_1.splitComponents()
2796         self.assertEqual(3,len(l))
2797         for elt in l: self.assertEqual(10,len(elt))
2798         for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
2799         for elt in l:
2800             elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
2801             pass
2802         fs.pushFields(l)
2803         self.assertEqual(4,len(fs))
2804         for elt in fs: self.assertEqual(10,len(elt))
2805         self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
2806         self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2807         #
2808         fs.write(fname,0) ; del fs
2809         #
2810         fs1=MEDFileFields(fname)
2811         self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
2812         self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2813         self.assertEqual(4,len(fs1))
2814         for i in xrange(10):
2815             for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
2816                 f1ts=fs1[fieldName][i]
2817                 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2818                 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
2819                 self.assertTrue(d.isEqual(f.getArray(),1e-13))
2820                 pass
2821             f1ts=fs1["1stField"][i]
2822             f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2823             d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2824             self.assertTrue(d.isEqual(f.getArray(),1e-13))
2825             pass
2826         pass
2827
2828     def testMEDFileFieldConvertTo1(self):
2829         fname="Pyfile68.med"
2830         # building a mesh containing 4 tri3 + 5 quad4
2831         tri=MEDCouplingUMesh("tri",2)
2832         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2833         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2834         tris=[tri.deepCpy() for i in xrange(4)]
2835         for i,elt in enumerate(tris): elt.translate([i,0])
2836         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2837         quad=MEDCouplingUMesh("quad",2)
2838         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2839         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2840         quads=[quad.deepCpy() for i in xrange(5)]
2841         for i,elt in enumerate(quads): elt.translate([5+i,0])
2842         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2843         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2844         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2845         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
2846         #
2847         ff0=MEDFileField1TS()
2848         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")
2849         f0.checkCoherency()
2850         ff0.setFieldNoProfileSBT(f0)
2851         #
2852         fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
2853         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2854         #
2855         ff0i=ff0.convertToInt()
2856         self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
2857         self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
2858         #
2859         ff1=ff0i.convertToDouble()
2860         self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
2861         self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
2862         # With profiles
2863         del arr,f0,ff0,ff1,ff0i,fspExp
2864         ff0=MEDFileField1TS()
2865         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")
2866         f0.checkCoherency()
2867         pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
2868         ff0.setFieldProfile(f0,mm,0,pfl)
2869         fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
2870         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2871         #
2872         ff0i=ff0.convertToInt()
2873         self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
2874         self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
2875         self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
2876         #
2877         ff1=ff0i.convertToDouble()
2878         self.assertTrue(isinstance(ff1,MEDFileField1TS))
2879         self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
2880         self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
2881         ## MultiTimeSteps
2882         ff0=MEDFileFieldMultiTS()
2883         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)
2884         f0.checkCoherency()
2885         ff0.appendFieldProfile(f0,mm,0,pfl)
2886         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)
2887         f0.checkCoherency()
2888         ff0.appendFieldProfile(f0,mm,0,pfl)
2889         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)
2890         f0.checkCoherency()
2891         ff0.appendFieldProfile(f0,mm,0,pfl)
2892         ff1=ff0.convertToInt()
2893         self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
2894         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2895         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
2896             self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
2897             arr=ff1.getUndergroundDataArray(dt,it)
2898             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
2899             pass
2900         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
2901         #
2902         mm.write(fname,2)
2903         ff1.write(fname,0)
2904         #
2905         ff1=ff1.convertToDouble()
2906         self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
2907         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2908         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
2909             self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
2910             arr=ff1.getUndergroundDataArray(dt,it)
2911             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
2912             pass
2913         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
2914         #
2915         ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
2916         self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
2917         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2918         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
2919             self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
2920             arr=ff1.getUndergroundDataArray(dt,it)
2921             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
2922             pass
2923         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
2924         pass
2925
2926     def testMEDFileFieldPartialLoading(self):
2927         fname="Pyfile69.med"
2928         #
2929         a=DataArrayInt() ; aa=a.getHeapMemorySize()
2930         a.alloc(0,1)
2931         strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
2932         # building a mesh containing 30 tri3 + 40 quad4
2933         tri=MEDCouplingUMesh("tri",2)
2934         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2935         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2936         tris=[tri.deepCpy() for i in xrange(30)]
2937         for i,elt in enumerate(tris): elt.translate([i,0])
2938         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2939         quad=MEDCouplingUMesh("quad",2)
2940         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2941         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2942         quads=[quad.deepCpy() for i in xrange(40)]
2943         for i,elt in enumerate(quads): elt.translate([40+i,0])
2944         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2945         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2946         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2947         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2948         #
2949         ff0=MEDFileField1TS()
2950         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")
2951         f0.checkCoherency()
2952         ff0.setFieldNoProfileSBT(f0)
2953         ff0.write(fname,0)
2954         #
2955         fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
2956         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2957         # With profiles
2958         ff0=MEDFileField1TS()
2959         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")
2960         f0.checkCoherency()
2961         pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2962         ff0.setFieldProfile(f0,mm,0,pfl)
2963         fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
2964         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2965         ff0.write(fname,0)
2966         #
2967         ff0=MEDFileField1TS(fname,False)
2968         self.assertEqual(ff0.getName(),"FieldCell")
2969         self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
2970         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
2971         heap_memory_ref=ff0.getHeapMemorySize()
2972         self.assertIn(heap_memory_ref,xrange(182,298+2*strMulFac))
2973         ff0.loadArrays() ##
2974         arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
2975         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2976         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
2977         #
2978         ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
2979         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
2980         heap_memory_ref=ff0.getHeapMemorySize()
2981         self.assertIn(heap_memory_ref,xrange(350,415+6*strMulFac))
2982         ff0.loadArrays() ##
2983         arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
2984         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2985         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
2986         ff0.loadArrays() ##
2987         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2988         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
2989         ff0.getUndergroundDataArray().setIJ(30,1,5.5)
2990         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2991         ff0.loadArrays() ##
2992         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2993         ff0.getUndergroundDataArray().setIJ(30,1,5.5)
2994         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2995         ff0.loadArraysIfNecessary() ##
2996         self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
2997         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2998         heap_memory_ref=ff0.getHeapMemorySize()
2999         self.assertIn(heap_memory_ref,xrange(1100,1215+2*strMulFac))
3000         ff0.unloadArrays()
3001         hmd=ff0.getHeapMemorySize()-heap_memory_ref
3002         self.assertEqual(hmd,-800) # -50*8*2
3003         ff0.loadArrays() ##
3004         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
3005         #
3006         ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
3007         heap_memory_ref=ff0.getHeapMemorySize()
3008         self.assertIn(heap_memory_ref,xrange(299,415+6*strMulFac))
3009         ff0.loadArrays() ##
3010         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3011         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3012         #
3013         fieldName="FieldCellMultiTS"
3014         ff0=MEDFileFieldMultiTS()
3015         for t in xrange(20):
3016             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)
3017             f0.setTime(float(t)+0.1,t,100+t)
3018             f0.checkCoherency()
3019             ff0.appendFieldNoProfileSBT(f0)
3020             pass
3021         ff0.write(fname,0)
3022         #
3023         ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
3024         heap_memory_ref=ff0.getHeapMemorySize()
3025         self.assertIn(heap_memory_ref,xrange(5536,5956+(80+26)*strMulFac))
3026         ff0.loadArrays()
3027         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
3028         del ff0
3029         #
3030         ffs=MEDFileFields(fname,False)
3031         heap_memory_ref=ffs.getHeapMemorySize()
3032         self.assertIn(heap_memory_ref,xrange(5335,6687+(80+50)*strMulFac))
3033         ffs.loadArrays()
3034         self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
3035         pass
3036
3037     def testMEDFileMeshReadSelector1(self):
3038         mrs=MEDFileMeshReadSelector()
3039         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3040         mrs.__str__() ; mrs.__repr__()
3041         #
3042         mrs=MEDFileMeshReadSelector(0)
3043         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())
3044         mrs=MEDFileMeshReadSelector(1)
3045         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3046         mrs=MEDFileMeshReadSelector(2)
3047         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3048         mrs=MEDFileMeshReadSelector(3)
3049         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3050         mrs=MEDFileMeshReadSelector(4)
3051         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3052         mrs=MEDFileMeshReadSelector(5)
3053         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3054         mrs=MEDFileMeshReadSelector(6)
3055         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3056         mrs=MEDFileMeshReadSelector(7)
3057         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3058         mrs=MEDFileMeshReadSelector(8)
3059         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3060         mrs=MEDFileMeshReadSelector(9)
3061         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3062         mrs=MEDFileMeshReadSelector(10)
3063         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3064         mrs=MEDFileMeshReadSelector(11)
3065         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3066         mrs=MEDFileMeshReadSelector(12)
3067         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3068         mrs=MEDFileMeshReadSelector(13)
3069         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3070         mrs=MEDFileMeshReadSelector(14)
3071         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3072         mrs=MEDFileMeshReadSelector(15)
3073         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3074         mrs=MEDFileMeshReadSelector(16)
3075         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3076         mrs=MEDFileMeshReadSelector(17)
3077         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3078         mrs=MEDFileMeshReadSelector(18)
3079         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3080         mrs=MEDFileMeshReadSelector(19)
3081         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3082         mrs=MEDFileMeshReadSelector(20)
3083         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3084         mrs=MEDFileMeshReadSelector(21)
3085         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3086         mrs=MEDFileMeshReadSelector(22)
3087         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3088         mrs=MEDFileMeshReadSelector(23)
3089         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3090         mrs=MEDFileMeshReadSelector(24)
3091         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3092         mrs=MEDFileMeshReadSelector(25)
3093         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3094         mrs=MEDFileMeshReadSelector(26)
3095         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3096         mrs=MEDFileMeshReadSelector(27)
3097         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3098         mrs=MEDFileMeshReadSelector(28)
3099         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3100         mrs=MEDFileMeshReadSelector(29)
3101         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3102         mrs=MEDFileMeshReadSelector(30)
3103         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3104         mrs=MEDFileMeshReadSelector(31)
3105         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3106         mrs=MEDFileMeshReadSelector(32)
3107         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3108         mrs=MEDFileMeshReadSelector(33)
3109         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3110         mrs=MEDFileMeshReadSelector(34)
3111         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3112         mrs=MEDFileMeshReadSelector(35)
3113         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3114         mrs=MEDFileMeshReadSelector(36)
3115         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3116         mrs=MEDFileMeshReadSelector(37)
3117         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3118         mrs=MEDFileMeshReadSelector(38)
3119         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3120         mrs=MEDFileMeshReadSelector(39)
3121         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3122         mrs=MEDFileMeshReadSelector(40)
3123         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3124         mrs=MEDFileMeshReadSelector(41)
3125         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3126         mrs=MEDFileMeshReadSelector(42)
3127         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3128         mrs=MEDFileMeshReadSelector(43)
3129         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3130         mrs=MEDFileMeshReadSelector(44)
3131         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3132         mrs=MEDFileMeshReadSelector(45)
3133         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3134         mrs=MEDFileMeshReadSelector(46)
3135         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3136         mrs=MEDFileMeshReadSelector(47)
3137         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3138         mrs=MEDFileMeshReadSelector(48)
3139         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3140         mrs=MEDFileMeshReadSelector(49)
3141         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3142         mrs=MEDFileMeshReadSelector(50)
3143         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3144         mrs=MEDFileMeshReadSelector(51)
3145         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3146         mrs=MEDFileMeshReadSelector(52)
3147         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3148         mrs=MEDFileMeshReadSelector(53)
3149         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3150         mrs=MEDFileMeshReadSelector(54)
3151         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3152         mrs=MEDFileMeshReadSelector(55)
3153         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3154         mrs=MEDFileMeshReadSelector(56)
3155         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3156         mrs=MEDFileMeshReadSelector(57)
3157         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3158         mrs=MEDFileMeshReadSelector(58)
3159         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3160         mrs=MEDFileMeshReadSelector(59)
3161         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3162         mrs=MEDFileMeshReadSelector(60)
3163         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3164         mrs=MEDFileMeshReadSelector(61)
3165         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3166         mrs=MEDFileMeshReadSelector(62)
3167         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3168         mrs=MEDFileMeshReadSelector(63)
3169         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3170         #
3171         mrs=MEDFileMeshReadSelector(63)
3172         mrs.setCellFamilyFieldReading(False)
3173         self.assertEqual(mrs.getCode(),62)
3174         mrs.setCellFamilyFieldReading(True)
3175         self.assertEqual(mrs.getCode(),63)
3176         mrs.setNodeFamilyFieldReading(False)
3177         self.assertEqual(mrs.getCode(),61)
3178         mrs.setNodeFamilyFieldReading(True)
3179         self.assertEqual(mrs.getCode(),63)
3180         mrs.setCellNameFieldReading(False)
3181         self.assertEqual(mrs.getCode(),59)
3182         mrs.setCellNameFieldReading(True)
3183         self.assertEqual(mrs.getCode(),63)
3184         mrs.setNodeNameFieldReading(False)
3185         self.assertEqual(mrs.getCode(),55)
3186         mrs.setNodeNameFieldReading(True)
3187         self.assertEqual(mrs.getCode(),63)
3188         mrs.setCellNumFieldReading(False)
3189         self.assertEqual(mrs.getCode(),47)
3190         mrs.setCellNumFieldReading(True)
3191         self.assertEqual(mrs.getCode(),63)
3192         mrs.setNodeNumFieldReading(False)
3193         self.assertEqual(mrs.getCode(),31)
3194         mrs.setNodeNumFieldReading(True)
3195         self.assertEqual(mrs.getCode(),63)
3196         pass
3197     
3198     def testPartialReadOfMeshes(self):
3199         fname="Pyfile70.med"
3200         # building a mesh containing 4 tri3 + 5 quad4
3201         tri=MEDCouplingUMesh("tri",2)
3202         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3203         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3204         tris=[tri.deepCpy() for i in xrange(4)]
3205         for i,elt in enumerate(tris): elt.translate([i,0])
3206         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3207         quad=MEDCouplingUMesh("quad",2)
3208         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3209         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3210         quads=[quad.deepCpy() for i in xrange(5)]
3211         for i,elt in enumerate(quads): elt.translate([5+i,0])
3212         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3213         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3214         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3215         m1=m.buildDescendingConnectivity()[0]
3216         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3217         #
3218         grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3219         grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3220         mm.setGroupsAtLevel(0,[grp0,grp1])
3221         grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3222         grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3223         mm.setGroupsAtLevel(-1,[grp2,grp3])
3224         grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3225         grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3226         mm.setGroupsAtLevel(1,[grp4,grp5])
3227         mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3228         mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3229         mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3230         #
3231         mm.write(fname,2)
3232         ##
3233         mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3234         b4_ref_heap_mem=mm.getHeapMemorySize()
3235         mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
3236         mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
3237         ref_heap_mem=mm.getHeapMemorySize()
3238         # check the gain of memory using 1GTUMesh instead of UMesh
3239         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
3240         #
3241         mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3242         self.assertEqual(len(mm.getGroupsNames()),0)
3243         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3244         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3245         self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3246         self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3247         self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3248         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3249         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3250         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3251         delta1=ref_heap_mem-mm.getHeapMemorySize()
3252         self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3253         #
3254         mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3255         self.assertEqual(len(mm.getGroupsNames()),6)
3256         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3257         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3258         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3259         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3260         self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3261         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3262         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3263         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3264         delta2=ref_heap_mem-mm.getHeapMemorySize()
3265         self.assertTrue(delta2<delta1)
3266         self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3267         #
3268         mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3269         self.assertEqual(len(mm.getGroupsNames()),6)
3270         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3271         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3272         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3273         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3274         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3275         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3276         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3277         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3278         delta3=ref_heap_mem-mm.getHeapMemorySize()
3279         self.assertTrue(delta3<delta2)
3280         self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3281         #
3282         mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3283         self.assertEqual(len(mm.getGroupsNames()),6)
3284         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3285         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3286         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3287         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3288         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3289         self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3290         self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3291         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3292         delta4=ref_heap_mem-mm.getHeapMemorySize()
3293         self.assertTrue(delta4<delta3)
3294         self.assertTrue(delta4>=32*4*2)
3295         #
3296         mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3297         self.assertEqual(len(mm.getGroupsNames()),6)
3298         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3299         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3300         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3301         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3302         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3303         self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3304         self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3305         self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3306         delta5=ref_heap_mem-mm.getHeapMemorySize()
3307         self.assertTrue(delta5<delta4)
3308         self.assertEqual(delta5,0)
3309         pass
3310
3311     # this test checks that setFieldProfile perform a check of the array length
3312     # compared to the profile length. This test also checks that mesh attribute of field
3313     # is not used by setFieldProfile (because across this test mesh is equal to None)
3314     def testCheckCompatibilityPfl1(self):
3315         # building a mesh containing 4 tri3 + 5 quad4
3316         tri=MEDCouplingUMesh("tri",2)
3317         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3318         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3319         tris=[tri.deepCpy() for i in xrange(4)]
3320         for i,elt in enumerate(tris): elt.translate([i,0])
3321         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3322         quad=MEDCouplingUMesh("quad",2)
3323         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3324         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3325         quads=[quad.deepCpy() for i in xrange(5)]
3326         for i,elt in enumerate(quads): elt.translate([5+i,0])
3327         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3328         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3329         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3330         m1=m.buildDescendingConnectivity()[0]
3331         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3332         #
3333         f1ts=MEDFileField1TS()
3334         f=MEDCouplingFieldDouble(ON_NODES)
3335         vals=DataArrayDouble(7) ; vals.iota(1000)
3336         f.setArray(vals)
3337         f.setName("anonymous") # f has no mesh it is not a bug
3338         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3339         f1ts.setFieldProfile(f,mm,0,pfl)
3340         #
3341         f1ts=MEDFileField1TS()
3342         f=MEDCouplingFieldDouble(ON_NODES)
3343         vals=DataArrayDouble(8) ; vals.iota(1000)
3344         f.setArray(vals)
3345         f.setName("anonymous") # f has no mesh it is not a bug
3346         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3347         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3348         #
3349         f1ts=MEDFileField1TS()
3350         f=MEDCouplingFieldDouble(ON_CELLS)
3351         vals=DataArrayDouble(7) ; vals.iota(1000)
3352         f.setArray(vals)
3353         f.setName("anonymous") # f has no mesh it is not a bug
3354         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3355         f1ts.setFieldProfile(f,mm,0,pfl)
3356         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3357         #
3358         f1ts=MEDFileField1TS()
3359         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3360         vals=DataArrayDouble(27) ; vals.iota(1000)
3361         f.setArray(vals)
3362         f.setName("anonymous") # f has no mesh it is not a bug
3363         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3364         f.setMesh(m[pfl])
3365         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])
3366         f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3367         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])
3368         f.setMesh(None)
3369         f1ts.setFieldProfile(f,mm,0,pfl)
3370         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3371         vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3372         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3373         vals=DataArrayDouble(27) ; vals.iota(1000)
3374         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3375         #
3376         f1ts=MEDFileField1TS()
3377         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3378         vals=DataArrayDouble(25) ; vals.iota(1000)
3379         f.setArray(vals)
3380         f.setName("anonymous") # f has no mesh it is not a bug
3381         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3382         f1ts.setFieldProfile(f,mm,0,pfl)
3383         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3384         vals2=DataArrayDouble(26) ; vals2.iota(1050)
3385         f.setArray(vals2)
3386         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3387         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3388         #
3389         f1ts=MEDFileField1TS()
3390         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3391         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3392         f.setArray(vals)
3393         f1ts.setFieldProfile(f,mm,0,pfl)
3394         pass
3395     
3396     def testWRMeshWithNoCells(self):
3397         fname="Pyfile71.med"
3398         a=DataArrayDouble(4) ; a.iota()
3399         c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
3400         m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
3401         m=MEDFileUMesh()
3402         m.setMeshAtLevel(0,m00)
3403         m.setRenumFieldArr(1,DataArrayInt(range(10,26)))
3404         m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
3405         m.write(fname,2)
3406         del m,a,c,m0,m00
3407         #
3408         m=MEDFileMesh.New(fname)
3409         self.assertEqual((),m.getNonEmptyLevels())
3410         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))
3411         self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(range(10,26))))
3412         self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
3413         pass
3414
3415     def testWRQPolyg1(self):
3416         fname="Pyfile72.med"
3417         m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
3418         m.insertNextCell([0,2,1,3])
3419         m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
3420         #
3421         ms=[m.deepCpy() for i in xrange(4)]
3422         for i,elt in enumerate(ms):
3423             elt.translate([float(i)*1.5,0.])
3424             pass
3425         m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3426         m0.convertAllToPoly()
3427         #
3428         ms=[m.deepCpy() for i in xrange(5)]
3429         for i,elt in enumerate(ms):
3430             elt.translate([float(i)*1.5,1.5])
3431             pass
3432         m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3433         m1.convertAllToPoly()
3434         m1.convertLinearCellsToQuadratic()
3435         #
3436         m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
3437         ##
3438         mm=MEDFileUMesh()
3439         mm.setMeshAtLevel(0,m)
3440         grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
3441         grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
3442         grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
3443         mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3444         ##
3445         mm.write(fname,2)
3446         del mm
3447         #
3448         mm_read=MEDFileUMesh(fname)
3449         self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
3450         self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
3451         self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
3452         self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
3453         ##
3454         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
3455         f.setMesh(m)
3456         arr0=DataArrayDouble(9) ; arr0.iota()
3457         arr1=DataArrayDouble(9) ; arr1.iota(100)
3458         arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
3459         f.setArray(arr) ; f.checkCoherency()
3460         f.setTime(5.6,1,2)
3461         ff=MEDFileField1TS()
3462         ff.setFieldNoProfileSBT(f)
3463         ff.write(fname,0)
3464         ##
3465         ff_read=MEDFileField1TS(fname)
3466         f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
3467         self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
3468         pass
3469
3470     def testLoadIfNecessaryOnFromScratchFields0(self):
3471         """
3472         This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
3473         """
3474         fname="Pyfile77.med"
3475         coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
3476         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
3477         m.allocateCells()
3478         m.insertNextCell(NORM_QUAD4,[0,5,3,2])
3479         m.insertNextCell(NORM_QUAD4,[4,2,3,1])
3480         m.finishInsertingCells()
3481         #
3482         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3483         ms=MEDFileMeshes() ; ms.pushMesh(mm)
3484         fs=MEDFileFields()
3485         arrs=4*[None]
3486         #
3487         ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
3488         f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
3489         f0.setTime(1.1,1,1)
3490         f0.setName("myELNOField")
3491         arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
3492         f0.setArray(arrs[0])
3493         ff0.appendFieldNoProfileSBT(f0)
3494         #
3495         f0.setTime(2.2,2,1)
3496         arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
3497         f0.setArray(arrs[1])
3498         ff0.appendFieldNoProfileSBT(f0)
3499         #
3500         f0.setTime(3.3,3,1)
3501         arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
3502         f0.setArray(arrs[2])
3503         ff0.appendFieldNoProfileSBT(f0)
3504         #
3505         f0.setTime(4.4,4,1)
3506         arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
3507         f0.setArray(arrs[3])
3508         ff0.appendFieldNoProfileSBT(f0)
3509         #
3510         for i,arr in enumerate(arrs):
3511             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3512             fs[0][i].loadArraysIfNecessary()
3513             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3514             pass
3515         fs.loadArraysIfNecessary()
3516         for i,arr in enumerate(arrs):
3517             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3518             pass
3519         fs[0].loadArraysIfNecessary()
3520         for i,arr in enumerate(arrs):
3521             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3522             pass
3523         pass
3524     
3525     def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
3526         """ 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.
3527         """
3528         fname="Pyfile78.med"
3529         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)
3530         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3531         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
3532         m0.allocateCells()
3533         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
3534             m0.insertNextCell(NORM_TETRA4,elt)
3535             pass
3536         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
3537             m0.insertNextCell(NORM_PYRA5,elt)
3538             pass
3539         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
3540             m0.insertNextCell(NORM_PENTA6,elt)
3541             pass
3542         m0.checkCoherency1()
3543         m1=MEDCouplingUMesh(); m1.setName("mesh")
3544         m1.setMeshDimension(2);
3545         m1.allocateCells(5);
3546         m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3547         m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3548         m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3549         m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3550         m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3551         m1.setCoords(coords);
3552         m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
3553         m3.allocateCells()
3554         m3.insertNextCell(NORM_POINT1,[2])
3555         m3.insertNextCell(NORM_POINT1,[3])
3556         m3.insertNextCell(NORM_POINT1,[4])
3557         m3.insertNextCell(NORM_POINT1,[5])
3558         #
3559         mm=MEDFileUMesh()
3560         mm.setMeshAtLevel(0,m0)
3561         mm.setMeshAtLevel(-1,m1)
3562         mm.setMeshAtLevel(-3,m3)
3563         mm.write(fname,2)
3564         #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
3565         mm=MEDFileMesh.New(fname)
3566         fs=MEDFileFields()
3567         fmts=MEDFileFieldMultiTS()
3568         f1ts=MEDFileField1TS()
3569         for lev in mm.getNonEmptyLevels():
3570             for gt in mm.getGeoTypesAtLevel(lev):
3571                 p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
3572                 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
3573                 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
3574                 f.setArray(arr) ; f.setName("f0")
3575                 f1ts.setFieldNoProfileSBT(f)
3576                 pass
3577             pass
3578         self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
3579         for lev in [0,-1,-3]:
3580             mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
3581             pass
3582         fmts.pushBackTimeStep(f1ts)
3583         fs.pushField(fmts)
3584         fs.write(fname,0)
3585         del fs,fmts,f1ts
3586         #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
3587         fs=MEDFileFields(fname)
3588         self.assertEqual(len(fs),1)
3589         self.assertEqual(len(fs[0]),1)
3590         f1ts=fs[0][0]
3591         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),'','')])])
3592         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))
3593         pass
3594
3595     def testMEDFileUMeshSetName(self):
3596         """ 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.
3597         This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
3598         """
3599         fname="Pyfile79.med"
3600         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3601         mm=MEDFileUMesh()
3602         m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
3603         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)
3604         m0.allocateCells(5);
3605         m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3606         m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3607         m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3608         m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3609         m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3610         m0.setCoords(coords);
3611         mm.setMeshAtLevel(0,m0)
3612         m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
3613         m2.allocateCells()
3614         m2.insertNextCell(NORM_POINT1,[2])
3615         m2.insertNextCell(NORM_POINT1,[3])
3616         m2.insertNextCell(NORM_POINT1,[4])
3617         m2.insertNextCell(NORM_POINT1,[5])
3618         mm.setMeshAtLevel(-2,m2)
3619         self.assertEqual(mm.getName(),"")
3620         self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
3621         mm.forceComputationOfParts()
3622         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
3623         mm.setName("abc")
3624         self.assertEqual(mm.getName(),"abc")
3625         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
3626         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
3627         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
3628         self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
3629         pass
3630
3631     def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
3632         fileName="Pyfile80.med"
3633         m=MEDCouplingCMesh() ; m.setName("cmesh")
3634         arr=DataArrayDouble(6) ; arr.iota()
3635         m.setCoords(arr,arr)
3636         nbCells=m.getNumberOfCells()
3637         self.assertEqual(25,nbCells)
3638         f=MEDCouplingFieldDouble(ON_CELLS)
3639         f.setName("FieldOnCell") ; f.setMesh(m)
3640         arr=DataArrayDouble(nbCells) ; arr.iota()
3641         mm=MEDFileCMesh()
3642         mm.setMesh(m)
3643         #
3644         fmts=MEDFileFieldMultiTS()
3645         #
3646         for i in xrange(nbCells):
3647             t=(float(i)+0.1,i+1,-i-2)
3648             f.setTime(*t)
3649             arr2=DataArrayDouble(nbCells)
3650             perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
3651             arr2[perm]=arr
3652             f.setArray(arr2)
3653             f1ts=MEDFileField1TS()
3654             f1ts.setFieldNoProfileSBT(f)
3655             fmts.pushBackTimeStep(f1ts)
3656             pass
3657         fmts.unloadArraysWithoutDataLoss()
3658         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))
3659         fs=MEDFileFields() ; fs.pushField(fmts)
3660         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))
3661         fs.unloadArraysWithoutDataLoss()
3662         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))
3663         f1ts=fs[0][0]
3664         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))
3665         f1ts.unloadArraysWithoutDataLoss()
3666         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))
3667         mm.write(fileName,2)
3668         fs.write(fileName,0)
3669         del m,fmts,mm,f,f1ts
3670         ##
3671         mm=MEDFileMesh.New(fileName)
3672         fmts=MEDFileFieldMultiTS(fileName)
3673         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))
3674         fmts.unloadArraysWithoutDataLoss()
3675         self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
3676         fmts.loadArraysIfNecessary()
3677         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))
3678         del mm,fmts
3679         fs=MEDFileFields(fileName)
3680         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))
3681         fs.unloadArraysWithoutDataLoss()
3682         self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
3683         fs.loadArraysIfNecessary()
3684         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))
3685         del fs
3686         f1ts=MEDFileField1TS(fileName)
3687         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))
3688         f1ts.unloadArraysWithoutDataLoss()
3689         self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
3690         f1ts.loadArraysIfNecessary()
3691         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))
3692         pass
3693
3694     def testMEDFileUMeshLoadPart1(self):
3695         """ 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
3696         memory of the returned instance.
3697         """
3698         fileName="Pyfile81.med"
3699         arr=DataArrayDouble(6) ; arr.iota()
3700         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3701         m=m.buildUnstructured()
3702         m.setName("Mesh")
3703         m.changeSpaceDimension(3,0.)
3704         infos=["aa [b]","cc [de]","gg [klm]"]
3705         m.getCoords().setInfoOnComponents(infos)
3706         m.checkCoherency1()
3707         mm=MEDFileUMesh()
3708         mm.setMeshAtLevel(0,m)
3709         m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh") 
3710         m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
3711         mm.setMeshAtLevel(-1,m1)
3712         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])
3713         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])
3714         namesCellL0=DataArrayAsciiChar(25,16)
3715         namesCellL0[:]=["Cell#%.3d        "%(i) for i in xrange(25)]
3716         renumM1=DataArrayInt([3,4,0,2,1])
3717         famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
3718         mm.setRenumFieldArr(0,renum0)
3719         mm.setFamilyFieldArr(0,famField0)
3720         mm.setNameFieldAtLevel(0,namesCellL0)
3721         mm.setRenumFieldArr(-1,renumM1)
3722         mm.setFamilyFieldArr(-1,famFieldM1)
3723         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])
3724         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])
3725         namesNodes=DataArrayAsciiChar(36,16)
3726         namesNodes[:]=["Node#%.3d        "%(i) for i in xrange(36)]
3727         mm.setRenumFieldArr(1,renum1)
3728         mm.setFamilyFieldArr(1,famField1)
3729         mm.setNameFieldAtLevel(1,namesNodes)
3730         mm.setFamilyId("Fam7",77)
3731         mm.setFamilyId("Fam8",88)
3732         mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
3733         mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
3734         mm.write(fileName,2)
3735         #
3736         mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
3737         self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
3738         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])))
3739         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)
3740         self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
3741         self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
3742         self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
3743         self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
3744         self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
3745         self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
3746         self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
3747         #
3748         mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
3749         self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
3750         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])))
3751         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)
3752         self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
3753         self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
3754         self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
3755         self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
3756         self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
3757         self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
3758         self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
3759         #
3760         mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
3761         self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
3762         self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
3763         self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
3764         self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
3765         self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
3766         self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
3767         self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
3768         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])))
3769         self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
3770         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)
3771         self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
3772         self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
3773         self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
3774         self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
3775         pass
3776
3777     def testMEDFileFieldsLoadPart1(self):
3778         """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
3779         """
3780         fileName="Pyfile82.med"
3781         meshName="Mesh"
3782         compos=["aa [kg]","bbb [m/s]"]
3783         arr=DataArrayDouble(6) ; arr.iota()
3784         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3785         m=m.buildUnstructured()
3786         m.setName(meshName)
3787         m.changeSpaceDimension(3,0.)
3788         infos=["aa [b]","cc [de]","gg [klm]"]
3789         m.getCoords().setInfoOnComponents(infos)
3790         m.checkCoherency1()
3791         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
3792         f.setName("Field")
3793         arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
3794         arr[:,0]=range(25)
3795         arr[:,1]=range(100,125)
3796         f.setArray(arr)
3797         MEDLoader.WriteField(fileName,f,2)
3798         f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
3799         f.setName("FieldNode")
3800         arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
3801         arr[:,0]=range(200,236)
3802         arr[:,1]=range(300,336)
3803         f.setArray(arr)
3804         f.checkCoherency()
3805         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f)
3806         #
3807         ms=MEDFileMeshes()
3808         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
3809         ms.pushMesh(mm)
3810         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3811         self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
3812         #
3813         ms=MEDFileMeshes()
3814         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
3815         ms.pushMesh(mm)
3816         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3817         fs=fs.deepCpy()
3818         fs[0][0].loadArrays()
3819         arr=DataArrayDouble(12,2) ; arr[:,0]=range(3,15) ; arr[:,1]=range(103,115)
3820         arr.setInfoOnComponents(compos)
3821         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
3822         fs[1][0].loadArrays()
3823         arr=DataArrayDouble(21,2) ; arr[:,0]=range(203,224) ; arr[:,1]=range(303,324)
3824         arr.setInfoOnComponents(compos)
3825         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
3826         pass
3827
3828     def testMEDFileWithoutCells1(self):
3829         fileName="Pyfile83.med"
3830         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
3831         coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
3832         mm=MEDFileUMesh()
3833         mm.setCoords(coo)
3834         mm.setName("mesh")
3835         mm.write(fileName,2)
3836         #
3837         mm=MEDFileMesh.New(fileName)
3838         self.assertEqual(mm.getName(),"mesh")
3839         self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
3840         pass
3841
3842     def testZipCoordsWithLoadPart1(self):
3843         """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
3844         """
3845         fileName="Pyfile84.med"
3846         meshName="Mesh"
3847         compos=["aa [kg]","bbb [m/s]"]
3848         arr=DataArrayDouble(6) ; arr.iota()
3849         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3850         m=m.buildUnstructured()
3851         m.setName(meshName)
3852         m.changeSpaceDimension(3,0.)
3853         infos=["aa [b]","cc [de]","gg [klm]"]
3854         m.getCoords().setInfoOnComponents(infos)
3855         m.checkCoherency1()
3856         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
3857         f.setName("Field")
3858         arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
3859         arr[:,0]=range(25)
3860         arr[:,1]=range(100,125)
3861         f.setArray(arr)
3862         MEDLoader.WriteField(fileName,f,2)
3863         f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
3864         f.setName("FieldNode")
3865         arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
3866         arr[:,0]=range(200,236)
3867         arr[:,1]=range(300,336)
3868         f.setArray(arr)
3869         f.checkCoherency()
3870         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fileName,f)
3871         #
3872         ms=MEDFileMeshes()
3873         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
3874         ms.pushMesh(mm)
3875         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
3876         self.assertEqual(spd.getSlice(),slice(4,6,1))
3877         spd=mm.getPartDefAtLevel(1)
3878         self.assertEqual(spd.getSlice(),slice(4,14,1))
3879         self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
3880         mm.zipCoords() # <- The important line is here !
3881         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
3882         self.assertEqual(spd.getSlice(),slice(4,6,1))
3883         spd=mm.getPartDefAtLevel(1)
3884         self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
3885         self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
3886         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3887         fs[0][0].loadArrays()
3888         arr=DataArrayDouble([(4,104),(5,105)])
3889         arr.setInfoOnComponents(compos)
3890         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
3891         fs[1][0].loadArrays()
3892         arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
3893         arr.setInfoOnComponents(compos)
3894         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
3895         pass
3896
3897     def testMEDFileCMeshSetGroupsAtLevel(self):
3898         """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
3899         """
3900         m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
3901         m.setName("Mesh")
3902         mm=MEDFileCMesh() ; mm.setMesh(m)
3903         grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
3904         mm.setGroupsAtLevel(0,[grp])
3905         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
3906         pass
3907
3908     def testMEDFileUMeshBuildExtrudedMesh1(self):
3909         """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
3910         fileName="Pyfile85.med"
3911         meshName2D="Mesh"
3912         meshName1D="Mesh1D"
3913         meshName3DOut="Mesh3D"
3914         #
3915         d1=DataArrayInt([0,4,20,24])
3916         d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
3917         #
3918         a=DataArrayDouble(6) ; a.iota()
3919         m=MEDCouplingCMesh() ; m.setCoords(a,a)
3920         m=m.buildUnstructured()
3921         d1c=d1.buildComplement(m.getNumberOfCells())
3922         m=m[d1c] ; m.zipCoords()
3923         m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
3924         m0.simplexize(0)
3925         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
3926         m.setName(meshName2D)
3927         mMinus1,a,b,c,d=m.buildDescendingConnectivity()
3928         e=d.deltaShiftIndex().getIdsEqual(1)
3929         #
3930         mm=MEDFileUMesh()
3931         mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
3932         grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
3933         mm.setGroupsAtLevel(0,[grp0])
3934         grp1=e ; grp1.setName("grp1")
3935         mm.setGroupsAtLevel(-1,[grp1])
3936         mm.write(fileName,2)
3937         #
3938         a=DataArrayDouble(3) ; a.iota()
3939         tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
3940         tmp.setName(meshName1D)
3941         tmp.changeSpaceDimension(3)
3942         tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
3943         mm1D=MEDFileUMesh()
3944         mm1D.setMeshAtLevel(0,tmp)
3945         mm1D.write(fileName,0)
3946         # test is here !
3947         mm2D=MEDFileMesh.New(fileName,meshName2D)
3948         mm1D=MEDFileMesh.New(fileName,meshName1D)
3949         m1D=mm1D.getMeshAtLevel(0)
3950         mm3D=mm2D.buildExtrudedMesh(m1D,0)
3951         #
3952         self.assertEqual(mm3D.getName(),mm2D.getName())
3953         self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
3954         self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
3955         self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
3956         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
3957         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
3958         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
3959         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
3960         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
3961         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
3962         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.)])
3963         self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
3964         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])
3965         self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
3966         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])
3967         self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
3968         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])
3969         self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
3970         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])
3971         self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
3972         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])
3973         self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
3974         d=DataArrayInt(129) ; d.iota() ; d*=3
3975         self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
3976         #
3977         self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
3978         self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
3979         self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
3980         self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
3981         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])))
3982         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])))
3983         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])))
3984         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])))
3985         mm3D.setName("MeshExtruded")
3986         mm3D.write(fileName,0)
3987         pass
3988
3989     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
3990     def testMEDFileUMeshPickeling1(self):
3991         import cPickle
3992         outFileName="Pyfile86.med"
3993         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)
3994         c.setInfoOnComponents(["aa","bbb"])
3995         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
3996         m=MEDCouplingUMesh();
3997         m.setMeshDimension(2);
3998         m.allocateCells(5);
3999         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
4000         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
4001         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
4002         m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
4003         m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
4004         m.finishInsertingCells();
4005         m.setCoords(c)
4006         m.checkCoherency()
4007         m1=MEDCouplingUMesh.New();
4008         m1.setMeshDimension(1);
4009         m1.allocateCells(3);
4010         m1.insertNextCell(NORM_SEG2,2,[1,4])
4011         m1.insertNextCell(NORM_SEG2,2,[3,6])
4012         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
4013         m1.finishInsertingCells();
4014         m1.setCoords(c)
4015         m1.checkCoherency()
4016         m2=MEDCouplingUMesh.New();
4017         m2.setMeshDimension(0);
4018         m2.allocateCells(4);
4019         m2.insertNextCell(NORM_POINT1,1,[1])
4020         m2.insertNextCell(NORM_POINT1,1,[3])
4021         m2.insertNextCell(NORM_POINT1,1,[2])
4022         m2.insertNextCell(NORM_POINT1,1,[6])
4023         m2.finishInsertingCells();
4024         m2.setCoords(c)
4025         m2.checkCoherency()
4026         #
4027         mm=MEDFileUMesh.New()
4028         self.assertTrue(mm.getUnivNameWrStatus())
4029         mm.setName("MyFirstMEDCouplingMEDmesh")
4030         mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
4031         mm.setCoords(c)
4032         mm[-1]=m1;
4033         mm[0]=m;
4034         mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
4035         mm[-2]=m2;
4036         mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
4037         # playing with groups
4038         g1_2=DataArrayInt.New()
4039         g1_2.setValues([1,3],2,1)
4040         g1_2.setName("G1")
4041         g2_2=DataArrayInt.New()
4042         g2_2.setValues([1,2,3],3,1)
4043         g2_2.setName("G2")
4044         mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
4045         g1_1=DataArrayInt.New()
4046         g1_1.setValues([0,1,2],3,1)
4047         g1_1.setName("G1")
4048         g2_1=DataArrayInt.New()
4049         g2_1.setValues([0,2],2,1)
4050         g2_1.setName("G2")
4051         mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
4052         g1_N=DataArrayInt.New()
4053         g1_N.setValues(range(8),8,1)
4054         g1_N.setName("G1")
4055         g2_N=DataArrayInt.New()
4056         g2_N.setValues(range(9),9,1)
4057         g2_N.setName("G2")
4058         mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
4059         mm.createGroupOnAll(0,"GrpOnAllCell")
4060         # check content of mm
4061         t=mm.getGroupArr(0,"G1",False)
4062         self.assertTrue(g1_2.isEqual(t));
4063         t=mm.getGroupArr(0,"G2",False)
4064         self.assertTrue(g2_2.isEqual(t));
4065         t=mm.getGroupArr(-1,"G1",False)
4066         self.assertTrue(g1_1.isEqual(t));
4067         t=mm.getGroupArr(-1,"G2",False)
4068         self.assertTrue(g2_1.isEqual(t));
4069         t=mm.getGroupArr(1,"G1",False)
4070         self.assertTrue(g1_N.isEqual(t));
4071         t=mm.getGroupArr(1,"G2",False)
4072         self.assertTrue(g2_N.isEqual(t));
4073         self.assertTrue(mm.existsGroup("GrpOnAllCell"));
4074         t=mm.getGroupArr(0,"GrpOnAllCell")
4075         #
4076         st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
4077         mm2=cPickle.loads(st)
4078         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4079         self.assertEqual(mm.getAxType(),AX_CART)
4080         #
4081         mm.setAxType(AX_CYL)
4082         st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
4083         mm2=cPickle.loads(st)
4084         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4085         self.assertEqual(mm2.getAxType(),AX_CYL)
4086         pass
4087
4088     def testMEDFileFieldsLoadSpecificEntities1(self):
4089         nbNodes=11
4090         fieldName="myField"
4091         fileName="Pyfile87.med"
4092         nbPdt=10
4093         meshName="Mesh"
4094         #
4095         m=MEDCouplingCMesh()
4096         arr=DataArrayDouble(nbNodes) ; arr.iota()
4097         m.setCoords(arr)
4098         m=m.buildUnstructured()
4099         m.setName(meshName)
4100         #
4101         fmts=MEDFileFieldMultiTS()
4102         for i in xrange(nbPdt):
4103             f=MEDCouplingFieldDouble(ON_NODES)
4104             f.setMesh(m)
4105             arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4106             f.setArray(arr)
4107             f.setName(fieldName)
4108             f.setTime(float(i),i,0)
4109             fmts.appendFieldNoProfileSBT(f)
4110             pass
4111         #
4112         mm=MEDFileUMesh() ; mm[0]=m
4113         fmts.write(fileName,2)
4114         mm.write(fileName,0)
4115         #
4116         fs=MEDFileFields(fileName,False)
4117         fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
4118         fs.loadArraysIfNecessary()
4119         fs2.loadArraysIfNecessary()
4120         for i in xrange(nbPdt):
4121             self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4122             pass
4123         m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
4124         m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
4125         m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
4126         fmts=MEDFileFieldMultiTS()
4127         for i in xrange(nbPdt):
4128             f=MEDCouplingFieldDouble(ON_CELLS)
4129             f.setMesh(m3)
4130             arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
4131             f.setArray(arr)
4132             f.setName(fieldName)
4133             f.setTime(float(i),i,0)
4134             fmts.appendFieldNoProfileSBT(f)
4135             pass
4136         mm=MEDFileUMesh() ; mm[0]=m3
4137         del mm[0]
4138         self.assertEqual(mm.getNonEmptyLevels(),())
4139         mm[0]=m3
4140         self.assertEqual(mm.getNonEmptyLevels(),(0,))
4141         fmts.write(fileName,2)
4142         fs=MEDFileFields(fileName,False)
4143         fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
4144         fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
4145         fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
4146         fs.loadArraysIfNecessary()
4147         fs2.loadArraysIfNecessary()
4148         fs3.loadArraysIfNecessary()
4149         fs4.loadArraysIfNecessary()
4150         for i in xrange(nbPdt):
4151             self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4152             self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
4153             self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
4154             pass
4155         pass
4156
4157     def testMEDFileLotsOfTSRW1(self):
4158         nbNodes=11
4159         fieldName="myField"
4160         fileName="Pyfile88.med"
4161         nbPdt=300 # <- perftest = 30000
4162         meshName="Mesh"
4163         #
4164         maxPdt=100 # <- optimum = 500
4165         m=MEDCouplingCMesh()
4166         arr=DataArrayDouble(nbNodes) ; arr.iota()
4167         m.setCoords(arr)
4168         m=m.buildUnstructured()
4169         m.setName(meshName)
4170         #
4171         nbOfField=nbPdt/maxPdt
4172         fs=MEDFileFields()
4173         for j in xrange(nbOfField):
4174             fmts=MEDFileFieldMultiTS()
4175             s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
4176             for i in xrange(s.start,s.stop,s.step):
4177                 f=MEDCouplingFieldDouble(ON_NODES)
4178                 f.setMesh(m)
4179                 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4180                 f.setArray(arr)
4181                 f.setName("%s_%d"%(fieldName,j))
4182                 f.setTime(float(i),i,0)
4183                 fmts.appendFieldNoProfileSBT(f)
4184                 pass
4185             fs.pushField(fmts)
4186             pass
4187         #
4188         mm=MEDFileUMesh() ; mm[0]=m
4189         fs.write(fileName,2)
4190         mm.write(fileName,0)
4191         ############
4192         def appendInDict(d,key,val):
4193             if key in d:
4194                 d[key].append(val)
4195             else:
4196                 d[key]=[val]
4197             pass
4198         import re
4199         allFields=MEDLoader.GetAllFieldNames(fileName)
4200         allFieldsDict={}
4201         pat=re.compile("([\d]+)([\s\S]+)$")
4202         for st in allFields:
4203             stRev=st[::-1]
4204             m=pat.match(stRev)
4205             if m:
4206                 appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
4207                 pass
4208             else:
4209                 appendInDict(allFieldsDict,st,'')
4210                 pass
4211             pass
4212         fs2=MEDFileFields()
4213         for k in allFieldsDict:
4214             if allFieldsDict[k]!=['']:
4215                 allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
4216                 pass
4217             fmts2=[]
4218             for it in allFieldsDict[k]:
4219                 fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
4220                 pass
4221             fmts2.reverse()
4222             zeResu=fmts2.pop()
4223             nbIter=len(fmts2)
4224             for ii in xrange(nbIter):
4225                 zeResu.pushBackTimeSteps(fmts2.pop())
4226                 pass
4227             zeResu.setName(k)
4228             fs2.pushField(zeResu)
4229             pass
4230         self.assertEqual(fs2[0].getTimeSteps(),[(i,0,float(i)) for i in xrange(nbPdt)])
4231         pass
4232     
4233     def testMEDFileMeshRearrangeFamIds1(self):
4234         """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
4235         fileName="Pyfile89.med"
4236         meshName='Maillage_2'
4237         mm=MEDFileUMesh()
4238         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)])
4239         #
4240         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])
4241         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])
4242         m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
4243         m0.setConnectivity(c0,c0i)
4244         mm[0]=m0
4245         #
4246         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])
4247         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])
4248         m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
4249         m1.setConnectivity(c1,c1i)
4250         mm[-1]=m1
4251         #
4252         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])
4253         m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4254         m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
4255         mm[-2]=m2.buildUnstructured()
4256         #
4257         ref0=DataArrayInt(55) ; ref0[:]=0
4258         mm.setFamilyFieldArr(0,ref0)
4259         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]))
4260         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])
4261         mm.setFamilyFieldArr(-1,ref1)
4262         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])
4263         mm.setFamilyFieldArr(-2,ref2)
4264         #
4265         for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
4266             mm.setFamilyId(f,fid)
4267         for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
4268             mm.setFamiliesOnGroup(grp,fams)
4269         mm.write(fileName,2)
4270         #
4271         mm=MEDFileMesh.New(fileName)
4272         grp=mm.getGroup(-1,"Groupe_1")
4273         dai=grp.computeFetchedNodeIds()
4274         dai.setName("TOTO")
4275         mm.addGroup(1,dai)
4276         mm.rearrangeFamilies() # <- the aim of the test
4277         self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
4278         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
4279         self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
4280         self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
4281         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])))
4282         allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
4283         allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
4284         self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
4285         for elt,fams in allGrps:
4286             self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
4287         self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
4288         for elt,eltId in allFams:
4289             self.assertEqual(mm.getFamilyId(elt),eltId)
4290         pass
4291
4292     def testNonRegrCMeshSetFieldPfl1(self):
4293         """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
4294         ff=MEDFileField1TS()
4295         meshName="mesh"
4296         mm=MEDFileCMesh()
4297         m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4298         m.setCoords(arr)
4299         m.setName(meshName)
4300         mm.setMesh(m)
4301         field=MEDCouplingFieldDouble(ON_CELLS)
4302         field.setMesh(m)
4303         field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4304         field.setName("Field")
4305         field.checkCoherency()
4306         pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
4307         ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
4308         self.assertEqual(ff.getPfls(),())
4309         field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4310         self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4311         del ff,mm,field,field2,pfl
4312         # same with unstructured mesh
4313         ff=MEDFileField1TS()
4314         meshName="mesh"
4315         mm=MEDFileUMesh()
4316         m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4317         m.setCoords(arr)
4318         m.setName(meshName)
4319         m=m.buildUnstructured()
4320         mm[0]=m
4321         field=MEDCouplingFieldDouble(ON_CELLS)
4322         field.setMesh(m)
4323         field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4324         field.setName("Field")
4325         field.checkCoherency()
4326         pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
4327         ff.setFieldProfile(field,mm,0,pfl)
4328         self.assertEqual(ff.getPfls(),())
4329         field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4330         self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4331         pass
4332
4333     def testMEDFileUMeshLinearToQuadraticAndRev1(self):
4334         meshName="mesh"
4335         fileName="Pyfile90.med"
4336         fileName2="Pyfile91.med"
4337         arr=DataArrayDouble(5) ; arr.iota()
4338         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4339         m=m.buildUnstructured()
4340         d=DataArrayInt([3,7,11,15])
4341         m1=m[d]
4342         m1.simplexize(0)
4343         m2=m[d.buildComplement(m.getNumberOfCells())]
4344         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
4345         m.changeSpaceDimension(3,0.)
4346         arr=DataArrayDouble(3) ; arr.iota()
4347         m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
4348         m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
4349         delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
4350         m3D=m.buildExtrudedMesh(m1D,0)
4351         m3D.sortCellsInMEDFileFrmt()
4352         m3D.setName(meshName)
4353         m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkCoherency1()
4354         m1D=m2D.computeSkin() ; m1D.setName(meshName)
4355         m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
4356         #
4357         mm=MEDFileUMesh()
4358         mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
4359         grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
4360         grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
4361         grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
4362         grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
4363         diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
4364         vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
4365         vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
4366         mm.setGroupsAtLevel(0,[vol1,vol2])
4367         mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
4368         mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
4369         #
4370         mmOut1=mm.linearToQuadratic(0,0.)
4371         mmOut1.write(fileName2,2)
4372         mmOut2=mmOut1.quadraticToLinear(0.)
4373         self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
4374         pass
4375
4376     def testMEDFileMeshAddGroup1(self):
4377         m=MEDCouplingCMesh()
4378         arrX=DataArrayDouble(9) ; arrX.iota()
4379         arrY=DataArrayDouble(4) ; arrY.iota()
4380         m.setCoords(arrX,arrY)
4381         m.setName("mesh")
4382         mm=MEDFileCMesh()
4383         mm.setMesh(m)
4384         grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
4385         mm.addGroup(0,grp0)
4386         grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
4387         mm.addGroup(0,grp1)
4388         grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
4389         mm.addGroup(0,grp2)
4390         grp3=DataArrayInt([23]) ; grp3.setName("grp3")
4391         mm.addGroup(0,grp3)
4392         for grp in [grp0,grp1,grp2,grp3]:
4393             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4394         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
4395         delta=12
4396         for grp in [grp0,grp1,grp2,grp3]:
4397             grpNode=grp.deepCpy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
4398             mm.addGroup(1,grpNode)
4399         self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
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         mm.normalizeFamIdsMEDFile()
4406         for grp in [grp0,grp1,grp2,grp3]:
4407             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4408         for grp in [grp0,grp1,grp2,grp3]:
4409             grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4410             self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4411         pass
4412
4413     pass
4414     def testMEDFileJoint1(self):
4415         fileName="Pyfile92.med"
4416         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4417         coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4418         mm=MEDFileUMesh()
4419         mm.setCoords(coo)
4420         mm.setName("maa1")
4421         mm.setDescription("un maillage")
4422         mm.write(fileName,2)
4423         node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4424         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4425         one_step_joint=MEDFileJointOneStep()
4426         one_step_joint.pushCorrespondence(cell_correspond)
4427         one_step_joint.pushCorrespondence(node_correspond)
4428         one_joint=MEDFileJoint()
4429         one_joint.pushStep(one_step_joint)
4430         one_joint.setLocalMeshName("maa1")
4431         one_joint.setRemoteMeshName("maa1")
4432         one_joint.setDescription("joint_description")
4433         one_joint.setJointName("joint_1")
4434         one_joint.setDomainNumber(1)
4435         self.assertEqual( one_joint.getLocalMeshName(), "maa1")
4436         self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
4437         self.assertEqual( one_joint.getDescription(), "joint_description")
4438         self.assertEqual( one_joint.getJointName(), "joint_1")
4439         self.assertEqual( one_joint.getDomainNumber(), 1)
4440         joints=MEDFileJoints()
4441         joints.pushJoint(one_joint);
4442         joints.write(fileName,0)
4443         # read back
4444         jointsR=MEDFileJoints(fileName,mm.getName())
4445         self.assertEqual( jointsR.getNumberOfJoints(), 1 )
4446         jR = jointsR.getJointAtPos(0)
4447         self.assertTrue( jR.isEqual( one_joint ))
4448         self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
4449         self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
4450         jointsR.destroyJointAtPos(0)
4451         
4452     pass
4453     def testMEDFileJoint2(self):
4454         fileNameWr="Pyfile93.med"
4455         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4456         coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4457         mm=MEDFileUMesh()
4458         mm.setCoords(coo)
4459         mm.setName("maa1")
4460         mm.setDescription("un maillage")
4461         node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
4462         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
4463         one_step_joint=MEDFileJointOneStep()
4464         two_step_joint=MEDFileJointOneStep()
4465         one_joint=MEDFileJoint()
4466         two_joint=MEDFileJoint()
4467         one_step_joint.pushCorrespondence(node_correspond)
4468         one_joint.pushStep(one_step_joint)
4469         two_step_joint.pushCorrespondence(cell_correspond)
4470         two_step_joint.pushCorrespondence(node_correspond)
4471         two_joint.pushStep(two_step_joint)
4472         one_joint.setLocalMeshName("maa1")
4473         one_joint.setRemoteMeshName("maa1")
4474         one_joint.setDescription("joint_description_1")
4475         one_joint.setJointName("joint_1")
4476         one_joint.setDomainNumber(1)
4477         two_joint.setLocalMeshName("maa1")
4478         two_joint.setRemoteMeshName("maa1")
4479         two_joint.setDescription("joint_description_2")
4480         two_joint.setJointName("joint_2")
4481         two_joint.setDomainNumber(2)
4482         joints=MEDFileJoints()
4483         joints.pushJoint(one_joint)
4484         joints.pushJoint(two_joint)
4485         mm.setJoints( joints )
4486         mm.write(fileNameWr,2)
4487         #
4488         mm=MEDFileMesh.New(fileNameWr)
4489         self.assertEqual( mm.getNumberOfJoints(), 2)
4490         jointsR = mm.getJoints();
4491         self.assertEqual( jointsR.getMeshName(), mm.getName() )
4492         self.assertEqual( len( jointsR ), 2 )
4493         jointR1 = jointsR[0]
4494         jointR2 = jointsR[1]
4495         self.assertFalse( jointR1 is None )
4496         self.assertFalse( jointR2 is None )
4497         self.assertTrue( jointR1.isEqual( one_joint ))
4498         self.assertTrue( jointR2.isEqual( two_joint ))
4499         pass
4500
4501     def testMEDFileJoint1(self):
4502         node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4503         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4504         cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
4505         cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
4506         joint1st_1=MEDFileJointOneStep()
4507         joint1st_1.pushCorrespondence(cell_correspond)
4508         joint1st_1.pushCorrespondence(node_correspond)
4509         joint1st_2=MEDFileJointOneStep()
4510         joint1st_2.pushCorrespondence(cell_correspond)
4511         joint1st_2.pushCorrespondence(node_correspond)
4512         joint1st_3=MEDFileJointOneStep()
4513         joint1st_3.pushCorrespondence(node_correspond)
4514         joint1st_3.pushCorrespondence(cell_correspond)
4515         joint1st_4=MEDFileJointOneStep()
4516         joint1st_4.pushCorrespondence(cell_correspond)
4517         joint1st_5=MEDFileJointOneStep()
4518         joint1st_5.pushCorrespondence(cell_correspon2)
4519         joint1st_6=MEDFileJointOneStep()
4520         joint1st_6.pushCorrespondence(cell_correspon3)
4521         self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
4522         self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
4523         self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
4524         self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
4525         self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
4526         one_joint=MEDFileJoint()
4527         one_joint.pushStep(joint1st_1)
4528         one_joint.setLocalMeshName("maa1")
4529         one_joint.setRemoteMeshName("maa2")
4530         one_joint.setDescription("joint_description")
4531         one_joint.setJointName("joint_1")
4532         one_joint.setDomainNumber(1)
4533         self.assertEqual( "maa1", one_joint.getLocalMeshName())
4534         self.assertEqual( "maa2", one_joint.getRemoteMeshName())
4535         self.assertEqual( "joint_description", one_joint.getDescription())
4536         self.assertEqual( 1, one_joint.getDomainNumber())
4537         self.assertEqual( "joint_1", one_joint.getJointName())
4538         pass
4539
4540     @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
4541     def testMEDFileSafeCall0(self):
4542         """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
4543         fname="Pyfile94.med"
4544         errfname="Pyfile94.err"
4545         class StdOutRedirect(object):
4546             def __init__(self,fileName):
4547                 import os,sys
4548                 sys.stderr.flush()
4549                 self.stdoutOld=os.dup(2)
4550                 self.fdOfSinkFile=os.open(fileName,os.O_CREAT | os.O_RDWR)
4551                 fd2=os.dup2(self.fdOfSinkFile,2)
4552                 self.origPyVal=sys.stderr
4553                 class FlushFile(object):
4554                     def __init__(self,f):
4555                         self.f=f
4556                     def write(self,st):
4557                         self.f.write(st)
4558                         self.f.flush()
4559                     def flush(self):
4560                         return self.f.flush()
4561                     def isatty(self):
4562                         return self.f.isatty()
4563                 sys.stderr=FlushFile(os.fdopen(self.fdOfSinkFile,"w"))
4564             def __del__(self):
4565                 import os,sys
4566                 sys.stderr=self.origPyVal
4567                 #os.fsync(self.fdOfSinkFile)
4568                 os.fsync(2)
4569                 os.dup2(self.stdoutOld,2)
4570                 os.close(self.stdoutOld)
4571         import os
4572         # first clean file if needed
4573         if os.path.exists(fname):
4574             os.remove(fname)
4575             pass
4576         # second : build a file from scratch
4577         m=MEDCouplingCMesh()
4578         arr=DataArrayDouble(11) ; arr.iota()
4579         m.setCoords(arr,arr)
4580         mm=MEDFileCMesh()
4581         mm.setMesh(m)
4582         mm.setName("mesh")
4583         mm.write(fname,2)
4584         # third : change permissions to remove write access on created file
4585         os.chmod(fname,0444)
4586         # four : try to append data on file -> check that it raises Exception
4587         f=MEDCouplingFieldDouble(ON_CELLS)
4588         f.setName("field")
4589         f.setMesh(m)
4590         f.setArray(DataArrayDouble(100))
4591         f.getArray()[:]=100.
4592         f.checkCoherency()
4593         f1ts=MEDFileField1TS()
4594         f1ts.setFieldNoProfileSBT(f)
4595         # redirect stderr
4596         tmp=StdOutRedirect(errfname)
4597         self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
4598         del tmp
4599         #
4600         if os.path.exists(errfname):
4601             os.remove(errfname)
4602         #
4603         pass
4604
4605     def testUnivStatus1(self):
4606         """ Non regression test to check the effectiveness of univ write status."""
4607         fname="Pyfile95.med"
4608         arr=DataArrayDouble(10) ; arr.iota()
4609         m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
4610         mm=MEDFileCMesh() ; mm.setMesh(m)
4611         mm.setUnivNameWrStatus(False) # test is here
4612         mm.write(fname,2)
4613         mm=MEDFileCMesh(fname)
4614         self.assertEqual(mm.getUnivName(),"")
4615         mm.setUnivNameWrStatus(True)
4616         mm.write(fname,2)
4617         mm=MEDFileCMesh(fname)
4618         self.assertTrue(mm.getUnivName()!="")
4619         pass
4620
4621     def testEmptyMesh(self):
4622       """ MEDLoader should be able to consistently write and read an empty mesh (coords array
4623       with 0 tuples """
4624       fname = "Pyfile96.med" 
4625       m = MEDCouplingUMesh('toto', 2)
4626       m.setCoords(DataArrayDouble([], 0, 2))
4627       m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
4628       mfu = MEDFileUMesh()
4629       mfu.setMeshAtLevel(0, m)
4630       mfu.write(fname, 2)
4631       mfu2 = MEDFileUMesh(fname)
4632       self.assertEqual('toto', mfu2.getName())
4633       lvl = mfu2.getNonEmptyLevels()
4634       self.assertEqual((), lvl)
4635
4636     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4637     def testMEDFileUMeshPickeling2(self):
4638       """ Check that pickalization can be performed on a unpickalized instance. Non regression test."""
4639       name="Mesh_1"
4640       grpName1="HAUT"
4641       grpName2="BASE"
4642       hauteur=1.
4643       nbOfNodesPerAxis=3
4644       arr=DataArrayDouble(nbOfNodesPerAxis) ; arr.iota() ; arr/=(nbOfNodesPerAxis-1) ; arr*=hauteur
4645       m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured() ; m.setName(name)
4646       mesh=MEDFileUMesh() ; mesh[0]=m
4647       m1=m.computeSkin() ; mesh[-1]=m1
4648       #
4649       bary1=m1.getBarycenterAndOwner()[:,2]
4650       grp1=bary1.getIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
4651       grp2=bary1.getIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
4652       mesh.setGroupsAtLevel(-1,[grp1,grp2])
4653       
4654       import cPickle
4655       st=cPickle.dumps(mesh,2)
4656       mm=cPickle.loads(st)
4657       st2=cPickle.dumps(mm,2)
4658       mm2=cPickle.loads(st2)
4659       self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
4660       pass
4661
4662     def testMEDFileEquivalence1(self):
4663       """ First check of equivalence implementation in MEDFileMesh"""
4664       fileName="Pyfile97.med"
4665       meshName="M_01"
4666       mm=MEDFileUMesh()
4667       coo=DataArrayDouble([(0,0,0),(6,0,0),(19,0,0),(36,0,0),(0,4,0),(6,4,0),(19,4,0),(36,4,0),(0,13,0),(6,13,0),(19,13,0),(36,13,0),(0,24,0),(6,24,0),(19,24,0),(36,24,0),(0,0,6),(6,0,6),(19,0,6),(36,0,6),(0,4,6),(6,4,6),(19,4,6),(36,4,6),(0,13,6),(6,13,6),(19,13,6),(36,13,6),(0,24,6),(6,24,6),(19,24,6),(36,24,6),(6,0,3),(6,2,0),(12.5,0,0),(19,0,3),(19,2,0),(6,4,3),(12.5,4,0),(19,4,3),(6,2,6),(12.5,0,6),(19,2,6),(12.5,4,6),(6,2,3),(12.5,0,3),(12.5,2,0),(19,2,3),(12.5,4,3),(12.5,2,6),(12.5,2,3)])
4668       coo.setInfoOnComponents(["X [Sans_unite]","Y [Sans_unite]","Z [Sans_unite]"])
4669       connQ4=DataArrayInt([1,17,21,5,2,18,22,6,21,5,6,22,1,32,44,33,17,40,44,32,21,37,44,40,5,33,44,37,2,35,47,36,18,42,47,35,22,39,47,42,6,36,47,39,21,37,48,43,5,38,48,37,6,39,48,38,22,43,48,39])
4670       m1=MEDCoupling1SGTUMesh(meshName,NORM_QUAD4) ; m1.setCoords(coo) ; m1.setNodalConnectivity(connQ4) ; mm[-1]=m1
4671       connH8=DataArrayInt([20,16,17,21,4,0,1,5,22,18,19,23,6,2,3,7,24,20,21,25,8,4,5,9,25,21,22,26,9,5,6,10,26,22,23,27,10,6,7,11,28,24,25,29,12,8,9,13,29,25,26,30,13,9,10,14,30,26,27,31,14,10,11,15,21,40,49,43,37,44,50,48,40,17,41,49,44,32,45,50,49,41,18,42,50,45,35,47,43,49,42,22,48,50,47,39,44,32,45,50,33,1,34,46,37,44,50,48,5,33,46,38,48,50,47,39,38,46,36,6,50,45,35,47,46,34,2,36])
4672       m0=MEDCoupling1SGTUMesh(meshName,NORM_HEXA8) ; m0.setCoords(coo) ; m0.setNodalConnectivity(connH8) ; mm[0]=m0
4673       mm.getFamilyFieldAtLevel(-1)[:]=-2
4674       mm.getFamilyFieldAtLevel(0)[:]=0
4675       mm.addFamily("HOMARD________-1",-1)
4676       mm.addFamily("HOMARD________-2",-2)
4677       mm.addFamily("HOMARD________-3",-3)
4678       mm.setFamiliesIdsOnGroup("HOMARD",[-1,-2,-3])
4679       
4680       eqName="MAILLES_A_RECOLLER_APRES_HOMARD"
4681       descEq="Cette equivalence decrit les mailles a recoller. Dans chaque correspondance, le premier numero est celui de la maille coupee ; le second numero est celui d'une des petites mailles en regard."
4682       mm.initializeEquivalences()
4683       eqs=mm.getEquivalences()
4684       eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4685       eq0.setDescription(descEq)
4686       corr=DataArrayInt([(0,3),(0,4),(0,5),(0,6),(1,7),(1,8),(1,9),(1,10),(2,11),(2,12),(2,13),(2,14)])
4687       eq0.setArray(-1,corr)
4688       self.assertEqual(eq0.getCell().size(),1)
4689       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4690       eq0.getCell().clear()
4691       self.assertEqual(eq0.getCell().size(),0)
4692       eq0.getCell().setArrayForType(NORM_QUAD4,corr)
4693       self.assertEqual(eq0.getCell().size(),1)
4694       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4695       mm.killEquivalences()
4696       mm.initializeEquivalences()
4697       eqs=mm.getEquivalences()
4698       eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4699       eq0.setDescription(descEq)
4700       c=eq0.initCell()
4701       c.setArrayForType(NORM_QUAD4,corr)
4702       self.assertEqual(eq0.getCell().size(),1)
4703       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4704       mm2=mm.deepCpy()
4705       self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4706       self.assertEqual(mm2.getEquivalences().size(),1)
4707       self.assertTrue(mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4).isEqual(corr))
4708       mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=2
4709       self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
4710       mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=0
4711       self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4712       mm.write(fileName,2)
4713       #
4714       mm3=MEDFileMesh.New(fileName)
4715       self.assertTrue(mm.isEqual(mm3,1e-12)[0])
4716       pass
4717
4718     def testMEDFileForFamiliesPlayer1(self):
4719       """Non regression bug EDF11911. For serial killers using same family name to store both cells and nodes ! Only sky is the limit."""
4720       fileName="Pyfile98.med"
4721       meshName="mesh"
4722       magicSt="%s%%04i"%(MEDFileMesh.GetMagicFamilyStr())
4723       arr=DataArrayDouble(4) ; arr.iota()
4724       m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4725       m=m.buildUnstructured()
4726       mm=MEDFileUMesh()
4727       mm[0]=m
4728       mm.setName(meshName)
4729       mm.setFamilyId("FAMILLE_ZERO",0)
4730       mm.getFamilyFieldAtLevel(0)[-3:]=-4
4731       mm.setFamilyId("RIDF%s"%(magicSt%0),-4)
4732       mm.setGroupsOnFamily("RIDF%s"%(magicSt%0),["RID"])
4733       d=DataArrayInt(16) ; d[:]=0 ; d[[1,2,4,5]]=3
4734       mm.setFamilyFieldArr(1,d)
4735       mm.setFamilyId("RIDF%s"%(magicSt%1),3)
4736       mm.setGroupsOnFamily("RIDF%s"%(magicSt%1),["RID"])
4737       self.assertEqual(mm.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4738       self.assertEqual(mm.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF")) # <- the aim of test is here !
4739       self.assertEqual(mm.getFamiliesIdsOnGroup("RID"),(-4,3))
4740       mm.write(fileName,2)
4741       # now read such funny file !
4742       mm2=MEDFileMesh.New(fileName) # <- normaly mdump of Pyfile98.med must contain only RID and FAMILLE_ZERO families.
4743       self.assertTrue(mm.isEqual(mm2,1e-16))
4744       self.assertEqual(mm2.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4745       self.assertEqual(mm2.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF"))
4746       self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too !
4747       pass
4748
4749     def testCartesianizer1(self):
4750       """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """
4751       # UMesh non cart
4752       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
4753       mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts()
4754       d0=DataArrayInt(16) ; d0[:]=0
4755       d1=DataArrayInt(9)  ; d1[:]=0
4756       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4757       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4758       ref0=mm.getCoords().getHiddenCppPointer()
4759       ref1=mm[0].getNodalConnectivity().getHiddenCppPointer()
4760       self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer())
4761       ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer()
4762       ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer()
4763       self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
4764       mm.setAxType(AX_CYL) #<- important
4765       mm2=mm.cartesianize() # the trigger
4766       self.assertEqual(mm2.getAxType(),AX_CART)
4767       mm.setAxType(AX_CART) # this is here only to avoid complaints
4768       self.assertTrue(isinstance(mm2,MEDFileUMesh))
4769       self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
4770       self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important
4771       self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important
4772       self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer())
4773       self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
4774       self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important
4775       self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important
4776       self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important
4777       self.assertEqual(mm2.getName(),mm.getName())
4778       self.assertEqual(mm2.getDescription(),mm.getDescription())
4779       self.assertEqual(mm2.getTime(),mm.getTime())
4780       self.assertEqual(mm2.getTime(),mm.getTime())
4781       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4782       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4783       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4784       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4785       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4786       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4787       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4788       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4789       # UMesh cart
4790       mm.setAxType(AX_CART)
4791       mm2=mm.cartesianize() # the trigger
4792       self.assertEqual(mm2.getAxType(),AX_CART)
4793       self.assertTrue(isinstance(mm2,MEDFileUMesh))
4794       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4795       # CurveLinearMesh non cart
4796       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear()
4797       mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxType(AX_CYL) #<- important
4798       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4799       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4800       ref0=mm.getMesh().getCoords().getHiddenCppPointer()
4801       mm2=mm.cartesianize() # the trigger
4802       self.assertEqual(mm2.getAxType(),AX_CART)
4803       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4804       self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
4805       self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important
4806       self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important
4807       self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
4808       self.assertEqual(mm2.getName(),mm.getName())
4809       self.assertEqual(mm2.getDescription(),mm.getDescription())
4810       self.assertEqual(mm2.getTime(),mm.getTime())
4811       self.assertEqual(mm2.getTime(),mm.getTime())
4812       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4813       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4814       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4815       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4816       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4817       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4818       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4819       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4820       # CurveLinearMesh cart
4821       mm.setAxType(AX_CART)
4822       mm2=mm.cartesianize() # the trigger
4823       self.assertEqual(mm2.getAxType(),AX_CART)
4824       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4825       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4826       # CMesh non cart
4827       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4828       mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxType(AX_CYL) #<- important
4829       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4830       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4831       mm2=mm.cartesianize() # the trigger
4832       self.assertEqual(mm2.getAxType(),AX_CART)
4833       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4834       self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
4835       self.assertEqual(mm2.getName(),mm.getName())
4836       self.assertEqual(mm2.getDescription(),mm.getDescription())
4837       self.assertEqual(mm2.getTime(),mm.getTime())
4838       self.assertEqual(mm2.getTime(),mm.getTime())
4839       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4840       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4841       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4842       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4843       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4844       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4845       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4846       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4847       # CMesh cart
4848       mm.setAxType(AX_CART)
4849       mm2=mm.cartesianize() # the trigger
4850       self.assertEqual(mm2.getAxType(),AX_CART)
4851       self.assertTrue(isinstance(mm2,MEDFileCMesh))
4852       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4853       pass
4854
4855     pass
4856
4857 if __name__ == "__main__":
4858   unittest.main()