]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/Swig/MEDLoaderTest3.py
Salome HOME
Typo-fix by Kunda
[tools/medcoupling.git] / src / MEDLoader / Swig / MEDLoaderTest3.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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 (EDF R&D)
21
22 from MEDLoader import *
23 import unittest
24 import platform
25 from math import pi,e,sqrt
26 from MEDLoaderDataForTest import MEDLoaderDataForTest
27 from distutils.version import LooseVersion
28
29 import sys
30 if sys.version_info.major < 3:
31     import cPickle as pickle
32 else:
33     import pickle
34
35 class StdOutRedirect(object):
36     def __init__(self,fileName):
37         import os,sys
38         sys.stderr.flush()
39         self.stdoutOld=os.dup(2)
40         self.fdOfSinkFile=os.open(fileName,os.O_CREAT | os.O_RDWR)
41         fd2=os.dup2(self.fdOfSinkFile,2)
42         self.origPyVal=sys.stderr
43         class FlushFile(object):
44             def __init__(self,f):
45                 self.f=f
46             def write(self,st):
47                 self.f.write(st)
48                 self.f.flush()
49             def flush(self):
50                 return self.f.flush()
51             def isatty(self):
52                 return self.f.isatty()
53             def close(self):
54                 os.fsync(self.f)
55                 self.f.close();
56         sys.stderr=FlushFile(os.fdopen(self.fdOfSinkFile,"w"))
57     def __del__(self):
58         import os,sys
59         sys.stderr.close()
60         sys.stderr=self.origPyVal
61         os.fsync(2)
62         os.dup2(self.stdoutOld,2)
63         os.close(self.stdoutOld)
64
65 class MEDLoaderTest3(unittest.TestCase):
66     def testMEDMesh1(self):
67         fileName="Pyfile18.med"
68         mname="ExampleOfMultiDimW"
69         medmesh=MEDFileMesh.New(fileName,mname)
70         self.assertRaises(InterpKernelException,MEDFileMesh.New,fileName,"")
71         self.assertEqual((0,-1),medmesh.getNonEmptyLevels())
72         m1_0=medmesh.getLevel0Mesh(True)
73         m1_1=ReadUMeshFromFile(fileName,mname,0)
74         self.assertTrue(m1_0.isEqual(m1_1,1e-12));
75         m2_0=medmesh.getLevelM1Mesh(True)
76         m2_1=ReadUMeshFromFile(fileName,mname,-1)
77         self.assertTrue(m2_0.isEqual(m2_1,1e-12));
78         pass
79
80     def testMEDMesh2(self):
81         fileName="Pyfile10.med"
82         mname="3DToto"
83         outFileName="MEDFileMesh1.med"
84         medmesh=MEDFileUMesh.New(fileName,mname)
85         self.assertEqual((0,),medmesh.getNonEmptyLevels())
86         m1_0=medmesh.getLevel0Mesh(True)
87         m1_1=ReadUMeshFromFile(fileName,mname,0)
88         self.assertTrue(m1_0.isEqual(m1_1,1e-12));
89         g1_0=medmesh.getGroup(0,"mesh2",True)
90         g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh2"]);
91         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
92         g1_0=medmesh.getGroup(0,"mesh3",True)
93         g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh3"]);
94         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
95         g1_0=medmesh.getGroups(0,["mesh3","mesh2"])
96         g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]);
97         g1_1.setName(g1_0.getName())
98         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
99         g1_0=medmesh.getFamily(0,"Family_-3",True)
100         g1_1=ReadUMeshFromFamilies(fileName,mname,0,["Family_-3"]);
101         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
102         g1_0=medmesh.getFamilies(0,["Family_-3","Family_-5"],True)
103         g1_1=ReadUMeshFromFamilies(fileName,mname,0,["Family_-3","Family_-5"]);
104         g1_1.setName(g1_0.getName())
105         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
106         self.assertTrue(g1_0.isEqual(g1_1,1e-12));
107         medmesh.write(outFileName,2);
108         self.assertEqual([1,2,4,13,15],medmesh.getGroupArr(0,"mesh2",True).getValues());
109         self.assertEqual([1,2,15],medmesh.getFamilyArr(0,"Family_-3",True).getValues());
110         self.assertEqual([1,2,4,13,15],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"],True).getValues());
111         self.assertEqual([18,1,2,3,4,13,14,15],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
112         famn=medmesh.getFamilyNameGivenId(0)
113         self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True);
114         #without renum
115         self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues());
116         self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_-3").getValues());
117         self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"]).getValues());
118         self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
119         self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False);
120         pass
121
122     # this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account
123     def testMEDMesh3(self):
124         outFileName="MEDFileMesh3.med"
125         c=DataArrayDouble.New()
126         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 ];
127         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
128         c.setValues(coords,9,2)
129         m=MEDCouplingUMesh.New();
130         m.setMeshDimension(2);
131         m.allocateCells(5);
132         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
133         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
134         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
135         m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
136         m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
137         m.finishInsertingCells();
138         m.setCoords(c)
139         m.checkConsistencyLight()
140         m1=MEDCouplingUMesh.New();
141         m1.setMeshDimension(1);
142         m1.allocateCells(3);
143         m1.insertNextCell(NORM_SEG2,2,[1,4])
144         m1.insertNextCell(NORM_SEG2,2,[3,6])
145         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
146         m1.finishInsertingCells();
147         m1.setCoords(c)
148         m1.checkConsistencyLight()
149         m2=MEDCouplingUMesh.New();
150         m2.setMeshDimension(0);
151         m2.allocateCells(4);
152         m2.insertNextCell(NORM_POINT1,1,[1])
153         m2.insertNextCell(NORM_POINT1,1,[3])
154         m2.insertNextCell(NORM_POINT1,1,[2])
155         m2.insertNextCell(NORM_POINT1,1,[6])
156         m2.finishInsertingCells();
157         m2.setCoords(c)
158         m2.checkConsistencyLight()
159         #
160         mm=MEDFileUMesh.New()
161         self.assertTrue(mm.getUnivNameWrStatus())
162         mm.setName("MyFirstMEDCouplingMEDmesh")
163         mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
164         mm.setCoords(c)
165         mm.setMeshAtLevel(-1,m1);
166         mm.setMeshAtLevel(0,m);
167         mm.setMeshAtLevel(-2,m2);
168         # playing with groups
169         g1_2=DataArrayInt.New()
170         g1_2.setValues([1,3],2,1)
171         g1_2.setName("G1")
172         g2_2=DataArrayInt.New()
173         g2_2.setValues([1,2,3],3,1)
174         g2_2.setName("G2")
175         mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
176         g1_1=DataArrayInt.New()
177         g1_1.setValues([0,1,2],3,1)
178         g1_1.setName("G1")
179         g2_1=DataArrayInt.New()
180         g2_1.setValues([0,2],2,1)
181         g2_1.setName("G2")
182         mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
183         g1_N=DataArrayInt.New()
184         g1_N.setValues(list(range(8)),8,1)
185         g1_N.setName("G1")
186         g2_N=DataArrayInt.New()
187         g2_N.setValues(list(range(9)),9,1)
188         g2_N.setName("G2")
189         mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
190         mm.createGroupOnAll(0,"GrpOnAllCell")
191         # check content of mm
192         t=mm.getGroupArr(0,"G1",False)
193         self.assertTrue(g1_2.isEqual(t));
194         t=mm.getGroupArr(0,"G2",False)
195         self.assertTrue(g2_2.isEqual(t));
196         t=mm.getGroupArr(-1,"G1",False)
197         self.assertTrue(g1_1.isEqual(t));
198         t=mm.getGroupArr(-1,"G2",False)
199         self.assertTrue(g2_1.isEqual(t));
200         t=mm.getGroupArr(1,"G1",False)
201         self.assertTrue(g1_N.isEqual(t));
202         t=mm.getGroupArr(1,"G2",False)
203         self.assertTrue(g2_N.isEqual(t));
204         self.assertTrue(mm.existsGroup("GrpOnAllCell"));
205         t=mm.getGroupArr(0,"GrpOnAllCell")
206         self.assertTrue(t.getValues()==list(range(5)))
207         #
208         mmCpy=mm.deepCopy()
209         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) ; del mm
210         mmCpy.write(outFileName,2);
211         #
212         mm=MEDFileMesh.New(outFileName)
213         #
214         self.assertEqual([NORM_TRI3,NORM_QUAD4,NORM_POLYGON],mm.getGeoTypesAtLevel(0))
215         self.assertEqual([NORM_SEG2,NORM_SEG3],mm.getGeoTypesAtLevel(-1))
216         self.assertEqual([NORM_POINT1],mm.getGeoTypesAtLevel(-2))
217         mm0=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POLYGON)
218         self.assertTrue(isinstance(mm0,MEDCoupling1DGTUMesh))
219         self.assertTrue(mm0.getNodalConnectivity().isEqual(DataArrayInt([6,7,4,3,7,8,5,4])))
220         self.assertTrue(mm0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8])))
221         lmm=mm.getDirectUndergroundSingleGeoTypeMeshes(0)
222         self.assertEqual(3,len(lmm))
223         self.assertTrue(isinstance(lmm[0],MEDCoupling1SGTUMesh))
224         self.assertTrue(isinstance(lmm[1],MEDCoupling1SGTUMesh))
225         self.assertTrue(isinstance(lmm[2],MEDCoupling1DGTUMesh))
226         #
227         self.assertTrue(mm.getUnivNameWrStatus())
228         self.assertTrue(isinstance(mm.getUnivName(),str))
229         self.assertTrue(len(mm.getUnivName())!=0)
230         mbis=mm.getMeshAtLevel(0)
231         m.setName(mm.getName()) ; m.setDescription(mm.getDescription())
232         self.assertTrue(m.isEqual(mbis,1e-12));
233         #
234         self.assertEqual(([[(3, 2), (4, 1), (5, 8)], [(1, 2), (2, 1)], [(0, 4)]], 2, 2, 9),GetUMeshGlobalInfo(outFileName,"MyFirstMEDCouplingMEDmesh"))
235         pass
236
237     # this test is the testMEDMesh3 except that permutation is dealed here
238     def testMEDMesh4(self):
239         outFileName="MEDFileMesh4.med"
240         c=DataArrayDouble.New()
241         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 ];
242         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
243         c.setValues(coords,9,2)
244         c.setInfoOnComponent(0,"abcdef [km]")
245         c.setInfoOnComponent(1,"ghij [MW]")
246         m=MEDCouplingUMesh.New();
247         m.setMeshDimension(2);
248         m.allocateCells(5);
249         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
250         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
251         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
252         m.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
253         m.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
254         m.finishInsertingCells();
255         m.setCoords(c)
256         m.checkConsistencyLight()
257         m1=MEDCouplingUMesh.New();
258         m1.setMeshDimension(1);
259         m1.allocateCells(3);
260         m1.insertNextCell(NORM_SEG2,2,[1,4])
261         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
262         m1.insertNextCell(NORM_SEG2,2,[3,6])
263         m1.finishInsertingCells();
264         m1.setCoords(c)
265         m1.checkConsistencyLight()
266         m2=MEDCouplingUMesh.New();
267         m2.setMeshDimension(0);
268         m2.allocateCells(4);
269         m2.insertNextCell(NORM_POINT1,1,[1])
270         m2.insertNextCell(NORM_POINT1,1,[3])
271         m2.insertNextCell(NORM_POINT1,1,[2])
272         m2.insertNextCell(NORM_POINT1,1,[6])
273         m2.finishInsertingCells();
274         m2.setCoords(c)
275         m2.checkConsistencyLight()
276         #
277         mm=MEDFileUMesh.New()
278         mm.setName("My2ndMEDCouplingMEDmesh")
279         mm.setDescription("ThisIsImpossibleToDoWithMEDMEM")
280         mm.setCoords(c)
281         renumNode=DataArrayInt.New()
282         renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1)
283         mm.setRenumFieldArr(1,renumNode)
284         mm.setMeshAtLevel(-1,m1,True);
285         mm.setMeshAtLevel(0,m,True);
286         mm.setMeshAtLevel(-2,m2,True);
287         mm.removeMeshAtLevel(-2)
288         mm.setMeshAtLevel(-2,m2,True);
289         # playing with groups
290         g1_2=DataArrayInt.New()
291         g1_2.setValues([2,3],2,1)
292         g1_2.setName("G1")
293         g2_2=DataArrayInt.New()
294         g2_2.setValues([2,0,3],3,1)
295         g2_2.setName("G2")
296         mm.setGroupsAtLevel(0,[g1_2,g2_2],True)
297         g1_1=DataArrayInt.New()
298         g1_1.setValues([0,2,1],3,1)
299         g1_1.setName("G1")
300         g2_1=DataArrayInt.New()
301         g2_1.setValues([0,2],2,1)
302         g2_1.setName("G2")
303         mm.setGroupsAtLevel(-1,[g1_1,g2_1],True)
304         g1_N=DataArrayInt.New()
305         g1_N.setValues([10,11,12,13,14,15,16,17],8,1)
306         g1_N.setName("G1")
307         g2_N=DataArrayInt.New()
308         g2_N.setValues([10,11,12,13,14,15,16,17,18],9,1)
309         g2_N.setName("G2")
310         mm.setGroupsAtLevel(1,[g1_N,g2_N],True)
311         # check content of mm
312         t=mm.getGroupArr(0,"G1",True)
313         self.assertTrue(g1_2.isEqual(t));
314         t=mm.getGroupArr(0,"G2",True)
315         self.assertTrue(g2_2.isEqual(t));
316         t=mm.getGroupArr(-1,"G1",True)
317         self.assertTrue(g1_1.isEqual(t));
318         t=mm.getGroupArr(-1,"G2",True)
319         self.assertTrue(g2_1.isEqual(t));
320         self.assertTrue(not mm.existsGroup("GrpOnAllCell"));
321         #
322         mm.write(outFileName,2);
323         mm2=MEDFileMesh.New(outFileName)
324         res=mm.isEqual(mm2,1e-12)
325         self.assertTrue(res[0])
326         l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
327         self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
328         mm2.keepFamIdsOnlyOnLevs([3],[-1])
329         for lev in mm.getGrpNonEmptyLevelsExt("G2"):
330             self.assertEqual(mm.getGroupArr(lev,"G2").getValues(),mm2.getGroupArr(lev,"G2").getValues())
331             pass
332         l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
333         self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
334         #
335         self.assertEqual([-7,-7,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
336         mm2.getFamilyFieldAtLevel(-1).setIJ(1,0,-8)
337         self.assertEqual([-7,-8,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
338         self.assertTrue(not mm2.existsFamily("Family_-8"))
339         mm2.createGroupOnAll(-1,"GrpOnAllFace")
340         self.assertTrue(mm2.existsFamily("Family_-8"))
341         self.assertEqual(list(range(3)),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
342         pass
343
344     #testing persistence of retrieved arrays
345     def testMEDMesh5(self):
346         fileName="Pyfile18.med"
347         mname="ExampleOfMultiDimW"
348         medmesh=MEDFileUMesh.New(fileName,mname)
349         m1_0=medmesh.getLevel0Mesh(True)
350         da1=medmesh.getFamilyFieldAtLevel(0)
351         del medmesh
352         self.assertEqual(20,m1_0.getNumberOfCells())
353         self.assertEqual(20,da1.getNumberOfTuples())
354         pass
355
356     def testMEDMesh6(self):
357         outFileName="MEDFileMesh5.med"
358         m=MEDFileCMesh.New()
359         m.setTime(-1,-1,2.3)
360         m1=MEDCouplingCMesh.New();
361         da=DataArrayDouble.New()
362         da.setValues([0.,1.,2.],3,1)
363         da.setInfoOnComponent(0,"XX [mm]")
364         m1.setCoordsAt(0,da)
365         da=DataArrayDouble.New()
366         da.setValues([0.,1.2],2,1)
367         da.setInfoOnComponent(0,"YY [km]")
368         m1.setCoordsAt(1,da)
369         da=DataArrayDouble.New()
370         da.setValues([0.,1.3],2,1)
371         da.setInfoOnComponent(0,"ZZ [um]")
372         m1.setCoordsAt(2,da)
373         m.setMesh(m1)
374         self.assertTrue(m[0].isEqual(m1,1e-12))
375         self.assertTrue(isinstance(m[0],MEDCouplingCMesh))
376         m.setName("myFirstCartMesh")
377         m.setDescription("mmmmpppppppp")
378         m.setTimeValue(2.3)
379         m.setTimeUnit("ms")
380         da=DataArrayInt.New()
381         da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1)
382         m.setFamilyFieldArr(1,da)
383         m.setFamilyId("family1",1)
384         da=m.getFamilyArr(1,"family1")
385         expected1=[2,4,9]
386         self.assertEqual(expected1,da.getValues())
387         self.assertTrue(m.getUnivNameWrStatus())
388         m.write(outFileName,2);
389         mm=MEDFileMesh.New(outFileName)
390         self.assertEqual([NORM_HEXA8],mm.getGeoTypesAtLevel(0))
391         self.assertTrue(isinstance(mm,MEDFileCMesh))
392         self.assertTrue(isinstance(mm.getUnivName(),str))
393         self.assertTrue(len(mm.getUnivName())!=0)
394         self.assertTrue(m.isEqual(mm,1e-12)[0])
395         self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
396         m2=mm.getMesh()
397         tt=m.getTime()
398         m1.setTime(tt[2],tt[0],tt[1])
399         m1.setName(m.getName())
400         m1.setTimeUnit(m.getTimeUnit())
401         m1.setDescription(m.getDescription())
402         self.assertTrue(m2.isEqual(m1,1e-12));
403         pass
404
405     def testMEDMesh7(self):
406         fileName="Pyfile24.med"
407         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
408         m=MEDFileUMesh.New()
409         m.setCoords(m2.getCoords())
410         m.setMeshAtLevel(0,m2)
411         m.setMeshAtLevel(-1,m1)
412         m.setMeshAtLevel(-2,m0)
413         m.setFamilyFieldArr(0,f2)
414         m.setFamilyFieldArr(-1,f1)
415         m.setFamilyFieldArr(-2,f0)
416         m.setFamilyFieldArr(1,p)
417         m.setRenumFieldArr(0,n2)
418         m.setRenumFieldArr(-1,n1)
419         m.setRenumFieldArr(-2,n0)
420         nbOfFams=len(fns)
421         for i in range(nbOfFams):
422             m.addFamily(fns[i],fids[i])
423             pass
424         nbOfGrps=len(grpns)
425         for i in range(nbOfGrps):
426             m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
427             pass
428         m.setName(m2.getName())
429         m.setDescription(m2.getDescription())
430         #
431         self.assertEqual((-1,),m.getGrpNonEmptyLevels("A2A4"))
432         self.assertEqual((),m.getGrpNonEmptyLevels("A1"))
433         self.assertEqual((-2,),m.getGrpNonEmptyLevels("AP2"))
434         self.assertEqual((-1,-2),m.getGrpsNonEmptyLevels(["A2A4","AP2"]))
435         self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________'))
436         self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________'))
437         self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________']))
438         self.assertEqual(('A1A2','A2A4','A3A1','A3C5','A4A3','B1C1','B2B4','B3B1','B4C3','C1C4','C2B2','C3C2','C4B3','C5A4'),m.getGroupsOnSpecifiedLev(-1))
439         self.assertEqual(('DALLE','DALQ1','DALQ2','DALT3','MESH'),m.getGroupsOnSpecifiedLev(0))
440         #
441         m.write(fileName,2)
442         self.assertRaises(InterpKernelException,MEDFileField1TS,fileName)#throw because no field in file fileName
443         pass
444
445     def funcToTestDelItem(self,ff):
446         del ff[[0.02,(3,4)]]
447         pass
448
449     #emulation of pointe.med file.
450     def testMEDField1(self):
451         mm=MEDFileMesh.New("Pyfile17.med")
452         mm.write("Pyfile17_bis.med",2)
453         ff=MEDFileFieldMultiTS("Pyfile17.med")
454         tsExpected=[[1,2],[3,4],[5,6]]
455         self.assertEqual(3,len(ff))
456         for pos,f1ts in enumerate(ff):
457             self.assertEqual(tsExpected[pos],f1ts.getTime()[:2])
458             self.assertEqual(type(f1ts),MEDFileField1TS)
459             pass
460         self.assertEqual("MeasureOfMesh_Extruded",ff.getName())
461         self.assertEqual([3,4],ff[1].getTime()[:-1])
462         self.assertEqual([3,4],ff[3,4].getTime()[:-1])
463         self.assertEqual([3,4],ff[0.01].getTime()[:-1])
464         ff.write("Pyfile17_bis.med",0)
465         #
466         ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
467         self.assertEqual([(1,2),(3,4),(5,6)],ts)
468         self.funcToTestDelItem(ff)
469         ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
470         self.assertEqual([(1,2)],ts)
471         pass
472
473     #profiles
474     def testMEDField2(self):
475         mm=MEDFileMesh.New("Pyfile19.med")
476         mm.write("Pyfile19_bis.med",2)
477         ff=MEDFileFieldMultiTS.New("Pyfile19.med")
478         ff.write("Pyfile19_bis.med",0)
479         self.assertEqual([('tyty','mm'),('uiop','MW')],GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes"))
480         pass
481
482     #gauss points
483     def testMEDField3(self):
484         mm=MEDFileMesh.New("Pyfile13.med")
485         mm.write("Pyfile13_bis.med",2)
486         ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
487         ff.write("Pyfile13_bis.med",0)
488         ff=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint",1,5)
489         f=ff.getFieldAtLevel(ON_GAUSS_PT,0)
490         f2=ReadFieldGauss("Pyfile13.med",'2DMesh_2',0,'MyFirstFieldOnGaussPoint',1,5)
491         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
492         ff3=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
493         f3=ff3.getFieldAtLevel(ON_GAUSS_PT,0)
494         self.assertTrue(f.isEqual(f3,1e-12,1e-12))
495         ff4=MEDFileField1TS.New("Pyfile13.med")
496         f4=ff4.getFieldAtLevel(ON_GAUSS_PT,0)
497         self.assertTrue(f.isEqual(f4,1e-12,1e-12))
498         pass
499
500     #gauss NE
501     def testMEDField4(self):
502         mm=MEDFileMesh.New("Pyfile14.med")
503         mm.write("Pyfile14_bis.med",2)
504         ff=MEDFileFieldMultiTS.New("Pyfile14.med","MyFieldOnGaussNE")
505         ff.write("Pyfile14_bis.med",0)
506         ff=MEDFileField1TS.New("Pyfile14.med","MyFieldOnGaussNE",1,5)
507         f=ff.getFieldAtLevel(ON_GAUSS_NE,0)
508         f2=ReadFieldGaussNE("Pyfile14.med",'2DMesh_2',0,"MyFieldOnGaussNE",1,5)
509         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
510         pass
511
512     # MEDField get/set on pointe.med
513     def testMEDField5(self):
514         ff=MEDFileField1TS.New("Pyfile17.med","MeasureOfMesh_Extruded",1,2)
515         f=ff.getFieldAtLevel(ON_CELLS,0)
516         f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
517         self.assertTrue(f.getMesh().getCoords().isEqual(f2.getMesh().getCoords(),1e-12))
518         f.getMesh().tryToShareSameCoords(f2.getMesh(),1e-12)
519         f.changeUnderlyingMesh(f2.getMesh(),22,1e-12)
520         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
521         # no with renumbering
522         f=ff.getFieldAtLevel(ON_CELLS,0,1)
523         f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
524         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
525         f=ff.getFieldAtLevel(ON_CELLS,0,3)
526         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
527         f=ff.getFieldAtLevel(ON_CELLS,0,2)
528         self.assertTrue(not f.isEqual(f2,1e-12,1e-12))
529         f.changeUnderlyingMesh(f2.getMesh(),12,1e-12)
530         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
531         pass
532
533     # MEDField get/set on profiles nodes
534     def testMEDField6(self):
535         ff=MEDFileFieldMultiTS.New("Pyfile7.med","VectorFieldOnNodes")
536         its=ff.getIterations()
537         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
538         f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
539         f2=ReadFieldNode("Pyfile7.med",'3DSurfMesh_1',0,"VectorFieldOnNodes",its[0][0],its[0][1])
540         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
541         ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes")
542         its=ff.getIterations()
543         f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
544         f2=ReadFieldNode("Pyfile19.med",'2DMesh_1',0,"VFieldOnNodes",its[0][0],its[0][1])
545         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
546         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
547         self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_NODES,its[0][0],its[0][1],0,1)#request renumber following mesh : it is on profile !
548         pass
549
550     # MEDField get/set on profiles cells
551     def testMEDField7(self):
552         ff=MEDFileFieldMultiTS.New("Pyfile12.med","VectorFieldOnCells")
553         its=ff.getIterations()
554         f=ff.getFieldAtLevel(ON_CELLS,its[0][0],its[0][1],0)
555         f2=ReadFieldCell("Pyfile12.med",'3DMesh_1',0,"VectorFieldOnCells",its[0][0],its[0][1])
556         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
557         pass
558
559     #first test of assignation. No profile and types sorted by type.
560     def testMEDField8(self):
561         fname="Pyfile25.med"
562         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
563         m1=f1.getMesh()
564         mm1=MEDFileUMesh.New()
565         mm1.setCoords(m1.getCoords())
566         mm1.setMeshAtLevel(0,m1)
567         mm1.setName(m1.getName())
568         mm1.write(fname,2)
569         ff1=MEDFileField1TS.New()
570         ff1.setFieldNoProfileSBT(f1)
571         ff1.write(fname,0)
572         f2=ReadFieldCell(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]);
573         itt,orr,ti=ff1.getTime()
574         self.assertEqual(0,itt); self.assertEqual(1,orr); self.assertAlmostEqual(2.,ti,14);
575         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
576         ff1.setTime(3,4,2.3)
577         itt,orr,ti=ff1.getTime()
578         self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14);
579         f1.setTime(5.5,7,8)
580         ff1.copyTimeInfoFrom(f1)
581         itt,orr,ti=ff1.getTime()
582         self.assertEqual(7,itt); self.assertEqual(8,orr); self.assertAlmostEqual(5.5,ti,14);
583         da,infos=ff1.getUndergroundDataArrayExt()
584         f2.getArray().setName(da.getName())#da has the same name than f2
585         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
586         self.assertEqual([((3, 0), (0, 2)), ((4, 0), (2, 4)), ((6, 0), (4, 5)), ((5, 0), (5, 6))],infos)
587         #
588         fname="Pyfile26.med"
589         f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
590         m1=f1.getMesh()
591         mm1=MEDFileUMesh.New()
592         mm1.setCoords(m1.getCoords())
593         mm1.setMeshAtLevel(0,m1)
594         mm1.setName(m1.getName())
595         mm1.write(fname,2)
596         ff1=MEDFileField1TS.New()
597         ff1.setFieldNoProfileSBT(f1)
598         nv=1456.
599         da=ff1.getUndergroundDataArray().setIJ(0,0,nv)
600         ff1.write(fname,0)
601         f2=ReadFieldNode(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
602         self.assertTrue(not f1.isEqual(f2,1e-12,1e-12))
603         f1.getArray().setIJ(0,0,nv)
604         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
605         #
606         fname="Pyfile27.med"
607         f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
608         m1=f1.getMesh()
609         mm1=MEDFileUMesh.New()
610         mm1.setCoords(m1.getCoords())
611         mm1.setMeshAtLevel(0,m1)
612         mm1.setName(m1.getName())
613         mm1.write(fname,2)
614         ff1=MEDFileField1TS.New()
615         ff1.setFieldNoProfileSBT(f1)
616         ff1.write(fname,0)
617         f2=ReadFieldGaussNE(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
618         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
619         da,infos=ff1.getUndergroundDataArrayExt()
620         f2.getArray().setName(da.getName())#da has the same name than f2
621         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
622         self.assertEqual([((3, 0), (0, 6)), ((4, 0), (6, 14)), ((6, 0), (14, 20))],infos)
623         #
624         fname="Pyfile28.med"
625         f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler();
626         f1InvalidCpy=f1.deepCopy()
627         f1InvalidCpy.setDiscretization(MEDCouplingFieldDiscretizationGauss())
628         f1InvalidCpy2=f1.deepCopy()
629         f1InvalidCpy2.setDiscretization(MEDCouplingFieldDiscretizationGauss())
630         m1=f1.getMesh()
631         mm1=MEDFileUMesh.New()
632         mm1.setCoords(m1.getCoords())
633         mm1.setMeshAtLevel(0,m1)
634         mm1.setName(m1.getName())
635         mm1.write(fname,2)
636         ff1=MEDFileField1TS.New()
637         self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy) # fails because no Gauss localization per cell set !*
638         f1InvalidCpy2.getDiscretization().setArrayOfDiscIds(f1.getDiscretization().getArrayOfDiscIds()) # fails because no Gauss localization set whereas gauss locid per cell given !
639         self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy2)
640         ff1.setFieldNoProfileSBT(f1)
641         ff1.write(fname,0)
642         ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2])
643         f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0)
644         self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
645         sbt=ff2.getFieldSplitedByType2()
646         loc1=ff2.getLocalization("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5")
647         self.assertEqual("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5",loc1.getName())
648         self.assertEqual((-1, 1,-1,-1,1,-1,-1,0,0,-1,0,0),loc1.getRefCoords())
649         self.assertEqual(6,loc1.getNumberOfPointsInCells())
650         self.assertEqual(3,loc1.getNumberOfGaussPoints())
651         self.assertEqual(2,loc1.getDimension())
652         da,infos=ff2.getUndergroundDataArrayExt()
653         f2.getArray().setName(da.getName())#da has the same name than f2
654         self.assertTrue(da.isEqual(f2.getArray(),1e-12))
655         self.assertEqual(53,da.getNumberOfTuples())
656         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)
657         #
658         pass
659     
660     def testMEDFileData1(self):
661         fname="Pyfile29.med"
662         d=MEDFileData.New()
663         #
664         m1=MEDLoaderDataForTest.build1DMesh_1()
665         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
666         mmm1=MEDFileMeshMultiTS.New() ;
667         mmm1.setOneTimeStep(mm1)
668         m2=MEDLoaderDataForTest.build2DCurveMesh_1()
669         mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName())
670         mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2)
671         ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2)
672         d.setMeshes(ms)
673         for name,mmm in zip(["1DMesh_1","2DCurveMesh_1"],ms):
674             self.assertEqual(name,mmm.getName())
675             self.assertEqual(type(mmm),MEDFileUMesh)
676             pass
677         self.assertEqual(('1DMesh_1', '2DCurveMesh_1'),d.getMeshes().getMeshesNames())
678         #
679         ff1=MEDFileFieldMultiTS.New()
680         ff21=MEDFileFieldMultiTS.New()
681         ff22=MEDFileFieldMultiTS.New()
682         f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False)
683         f1.getArray().setInfoOnComponent(0,"power [kW]")
684         ff1.appendFieldNoProfileSBT(f1)
685         f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False)
686         f21.getArray().setInfoOnComponent(0,"sta [mm]") ;
687         ff21.appendFieldNoProfileSBT(f21)
688         f22=f21.deepCopy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ;
689         f22.applyFunc(2,"3*x*IVec+2*x*JVec")
690         f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]")
691         ff22.appendFieldNoProfileSBT(f22)
692         fs=MEDFileFields.New()
693         fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22)
694         for name,fmts in zip(["f1","f21","f22"],fs):
695             self.assertEqual(name,fmts.getName())
696             pass
697         d.setFields(fs)
698         #
699         fname2="Pyfile29_2.med"
700         d.write(fname2,2)
701         #
702         d2=MEDFileData.New(fname2)
703         self.assertEqual(2,d2.getNumberOfMeshes())
704         self.assertEqual(3,d2.getNumberOfFields())
705         self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))
706         self.assertTrue(isinstance(d2.getMeshes()[0],MEDFileUMesh))
707         self.assertTrue(isinstance(d2.getMeshes()['2DCurveMesh_1'],MEDFileUMesh))
708         m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
709         self.assertTrue(m1.isEqual(m1bis,1e-12))
710         self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
711         self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
712         self.assertEqual([(-1,-1,0.0)],d2.getFields()[2].getTimeSteps())
713         self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
714         self.assertEqual([(-1,-1,0.0)],d2.getFields()["f21"].getTimeSteps())
715         pass
716     
717     def testMEDField9(self):
718         # first test field profile WR. Full type but with some type missing
719         fname="Pyfile30.med"
720         m1=MEDLoaderDataForTest.build2DMesh_3()
721         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
722         mm1.write(fname,2)
723         ff1=MEDFileField1TS.New()
724         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1")
725         d=DataArrayDouble.New() ; d.alloc(2*9,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
726         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.
727         da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1")
728         #
729         ff1.setFieldProfile(f1,mm1,0,da)
730         ff1.changePflsNames([(["sup1_NORM_QUAD4"],"ForV650")])
731         ff1=ff1.deepCopy()
732         ff1.write(fname,0)
733         #
734         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
735         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))# profiles names cannot be contracted in pfl array name
736         self.assertTrue(vals.isEqual(d,1e-14))
737         #
738         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
739         ff3=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
740         ff2.deepCpyGlobs(ff3)
741         sbt=ff2.getFieldSplitedByType2()
742         self.assertEqual(3,sbt[0][0])#TRI3
743         self.assertEqual(0,sbt[0][1][0][0])#CELL For TRI3
744         self.assertEqual("",sbt[0][1][0][2])#no profile For TRI3
745         self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],sbt[0][1][0][1].getValues())# values for TRI3
746         self.assertEqual(4,sbt[1][0])#QUAD4
747         self.assertEqual(0,sbt[1][1][0][0])#CELL For QUAD4
748         self.assertEqual("ForV650",sbt[1][1][0][2])# profile For QUAD4
749         self.assertEqual([19, 20, 21, 22, 23, 24],sbt[1][1][0][1].getValues())# values for QUAD4
750         self.assertEqual([0],ff2.getTypesOfFieldAvailable())
751         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
752         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
753         self.assertTrue(vals.isEqual(d,1e-14))
754         pass
755     
756     def testMEDField10(self):
757         fname="Pyfile31.med"
758         m1=MEDLoaderDataForTest.build2DMesh_1()
759         m1.renumberCells([0,1,4,2,3,5],False)
760         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
761         mm1.write(fname,2)
762         ff1=MEDFileFieldMultiTS.New()
763         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
764         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
765         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.
766         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
767         #
768         ff1.appendFieldProfile(f1,mm1,0,da)
769         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
770         ff1.appendFieldProfile(f1,mm1,0,da)
771         ff1=ff1.deepCopy()
772         ff1.write(fname,0)
773         #
774         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
775         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
776         self.assertTrue(vals.isEqual(e,1e-14))
777         vals,pfl=ff1.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
778         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
779         self.assertTrue(vals.isEqual(d,1e-14))
780         #
781         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
782         self.assertEqual([(-1,-1,0.0), (1,2,1.2)],ff2.getTimeSteps())
783         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
784         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
785         self.assertTrue(vals.isEqual(e,1e-14))
786         vals,pfl=ff2.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
787         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
788         self.assertTrue(vals.isEqual(d,1e-14))
789         pass
790     
791     # idem testMEDField9 method except that here testing profile on nodes and not on cells.
792     def testMEDField11(self):
793         fname="Pyfile32.med"
794         m1=MEDLoaderDataForTest.build2DMesh_1()
795         m1.renumberCells([0,1,4,2,3,5],False)
796         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
797         mm1.write(fname,2)
798         ff1=MEDFileField1TS.New()
799         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
800         d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
801         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.
802         da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
803         #
804         ff1.setFieldProfile(f1,mm1,0,da)
805         self.assertEqual(ff1.getNonEmptyLevels(),(-1, []))
806         ff1.write(fname,0)
807         #
808         vals,pfl=ff1.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
809         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
810         self.assertTrue(vals.isEqual(d,1e-14))
811         ## #
812         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
813         vals,pfl=ff2.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
814         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
815         self.assertTrue(vals.isEqual(d,1e-14))
816         pass
817
818     def testMEDField12(self):
819         fname="Pyfile33.med"
820         m1=MEDLoaderDataForTest.build2DMesh_1()
821         m1.renumberCells([0,1,4,2,3,5],False)
822         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
823         mm1.write(fname,2)
824         ff1=MEDFileFieldMultiTS.New()
825         f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
826         d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
827         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.
828         da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
829         #
830         ff1.appendFieldProfile(f1,mm1,0,da)
831         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
832         ff1.appendFieldProfile(f1,mm1,0,da)
833         ff1.write(fname,0)
834         #
835         vals,pfl=ff1.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
836         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
837         self.assertTrue(vals.isEqual(e,1e-14))
838         vals,pfl=ff1.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
839         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
840         self.assertTrue(vals.isEqual(d,1e-14))
841         #
842         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
843         vals,pfl=ff2.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
844         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
845         self.assertTrue(vals.isEqual(e,1e-14))
846         vals,pfl=ff2.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
847         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
848         self.assertTrue(vals.isEqual(d,1e-14))
849         pass
850
851     def testMEDField13(self):
852         fname="Pyfile34.med"
853         m1=MEDLoaderDataForTest.build2DMesh_1()
854         m1.renumberCells([0,1,4,2,3,5],False)
855         tmp=m1.getName();
856         m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
857         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
858         mm1.write(fname,2)
859         ff1=MEDFileField1TS.New()
860         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F3Node")
861         d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
862         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.
863         da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
864         #
865         ff1.setFieldProfile(f1,mm1,0,da)
866         ff1.write(fname,0)
867         #
868         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
869         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
870         self.assertTrue(vals.isEqual(d,1e-14))
871         #
872         ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
873         vals,pfl=ff2.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
874         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
875         self.assertTrue(vals.isEqual(d,1e-14))
876         pass
877
878     def testMEDField14(self):
879         fname="Pyfile35.med"
880         m1=MEDLoaderDataForTest.build2DMesh_1()
881         m1.renumberCells([0,1,4,2,3,5],False)
882         tmp=m1.getName();
883         m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
884         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
885         mm1.write(fname,2)
886         ff1=MEDFileFieldMultiTS.New()
887         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
888         d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
889         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.
890         da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
891         #
892         ff1.appendFieldProfile(f1,mm1,0,da)
893         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
894         ff1.appendFieldProfile(f1,mm1,0,da)
895         ff1.write(fname,0)
896         #
897         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
898         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
899         self.assertTrue(vals.isEqual(d,1e-14))
900         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
901         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
902         self.assertTrue(vals.isEqual(e,1e-14))
903         self.assertEqual([[3],[3]],ff1.getTypesOfFieldAvailable())
904         #
905         ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
906         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
907         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
908         self.assertTrue(vals.isEqual(d,1e-14))
909         vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
910         self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
911         self.assertTrue(vals.isEqual(e,1e-14))
912         pass
913     # 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.
914     # 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
915     # for the necessity of the test ! The idea is too create artificially a mesh having one more fictitious cell per type and to roll back right after !
916     def testMEDField15(self):
917         fname="Pyfile36.med"
918         m0=MEDLoaderDataForTest.build2DMesh_1()
919         m0.renumberCells([0,1,4,2,3,5],False)
920         tmp=m0.getName();
921         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
922         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
923         ff1=MEDFileField1TS.New()
924         f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
925         d=DataArrayDouble.New() ; d.alloc(2*20,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
926         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.
927         da=DataArrayInt.New(); da.setValues([0,1,3,4,6],5,1) ; da.setName("sup1NodeElt")
928         #
929         ff1.setFieldProfile(f1,mm1,0,da)
930         m1=m0.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
931         mm1.write(fname,2)
932         ff1.write(fname,0)
933         f1=ff1.getFieldOnMeshAtLevel(ON_GAUSS_NE,m1,0)
934         f2,p1=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; f2.setName("")
935         self.assertTrue(p1.isIota(5))
936         self.assertTrue(f1.getArray().isEqual(f2,1e-12))
937         pass
938     # Test for getFieldAtTopLevel method
939     def testMEDField16(self):
940         fname="Pyfile37.med"
941         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
942         m1=f1.getMesh()
943         mm1=MEDFileUMesh.New()
944         mm1.setCoords(m1.getCoords())
945         mm1.setMeshAtLevel(0,m1)
946         mm1.setName(m1.getName())
947         ff1=MEDFileField1TS.New()
948         ff1.setFieldNoProfileSBT(f1)
949         m2=m1.buildDescendingConnectivity()[0]
950         m2.sortCellsInMEDFileFrmt()
951         m2.setName(m1.getName())
952         mm1.setMeshAtLevel(-1,m2)
953         mm1.write(fname,2)
954         f2=m2.getMeasureField(True)
955         dd=DataArrayDouble.New()
956         dd.alloc(f2.getArray().getNumberOfTuples(),3)
957         dd[:,0]=f2.getArray()
958         dd[:,1]=2*f2.getArray()
959         dd[:,2]=3*f2.getArray()
960         f2=f2.buildNewTimeReprFromThis(ONE_TIME,False)
961         f2.setArray(dd)
962         f2.copyTinyStringsFrom(f1)
963         f2.copyTinyAttrFrom(f1)
964         ff1.setFieldNoProfileSBT(f2)
965         ff1.write(fname,0)
966         # Reading Pyfile37.med
967         ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
968         f1bis=ff2.getFieldAtLevel(ON_CELLS,0)
969         self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
970         f1bis=ff2.getFieldAtLevel(ON_CELLS,-1)
971         self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
972         f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
973         self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
974         # More complex
975         fname="Pyfile38.med"
976         mm1.write(fname,2)
977         ff1=MEDFileField1TS.New()
978         ff1.setFieldNoProfileSBT(f2)
979         ff1.write(fname,0)
980         ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
981         f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
982         self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
983         pass
984
985     # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
986     def testMEDField17(self):
987         fname="Pyfile39.med"
988         m1=MEDLoaderDataForTest.build2DMesh_1()
989         m1.renumberCells([0,1,4,2,3,5],False)
990         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
991         mm1.write(fname,2)
992         ffs=MEDFileFields.New()
993         ff1=MEDFileFieldMultiTS.New()
994         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
995         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
996         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.
997         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
998         #
999         ff1.appendFieldProfile(f1,mm1,0,da)
1000         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
1001         ff1.appendFieldProfile(f1,mm1,0,da)
1002         ffs.resize(1)
1003         ffs.setFieldAtPos(0,ff1)
1004         ffs=ffs.deepCopy()
1005         ffs.write(fname,0)
1006         #
1007         ffsr=MEDFileFields.New(fname)
1008         ff3=ffsr.getFieldAtPos(0)
1009         f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
1010         self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
1011         pass
1012
1013     # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
1014     def testMEDField18(self):
1015         fname="Pyfile40.med"
1016         m1=MEDLoaderDataForTest.build2DMesh_1()
1017         m1.renumberCells([0,1,4,2,3,5],False)
1018         mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
1019         mm1.write(fname,2)
1020         ffs=MEDFileFields.New()
1021         ff1=MEDFileFieldMultiTS.New()
1022         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
1023         d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
1024         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.
1025         da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
1026         #
1027         ff1.appendFieldProfile(f1,mm1,0,da)
1028         f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
1029         ff1.appendFieldProfile(f1,mm1,0,da)
1030         ffs.pushField(ff1)
1031         ffs.write(fname,0)
1032         #
1033         ffsr=MEDFileFields.New(fname)
1034         ff3=ffsr.getFieldAtPos(0)
1035         f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
1036         self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
1037         pass
1038
1039     def testMEDFieldBug1(self):
1040         fname="Pyfile13.med"
1041         d=MEDFileData.New(fname)
1042         self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs())
1043         pass
1044
1045     def testMEDMesh8(self):
1046         m=MEDLoaderDataForTest.build1DMesh_1()
1047         m.convertQuadraticCellsToLinear()
1048         mm=MEDFileUMesh.New()
1049         mm.setMeshAtLevel(0,m)
1050         g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1")
1051         g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2")
1052         g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3")
1053         mm.setGroupsAtLevel(0,[g1,g2],False)
1054         self.assertEqual(('g1','g2'),mm.getGroupsNames())
1055         self.assertEqual(('Family_-2','Family_-3'),mm.getFamiliesNames())
1056         self.assertEqual(('Family_-2',),mm.getFamiliesOnGroup('g1'))
1057         self.assertEqual(('Family_-3',),mm.getFamiliesOnGroup('g2'))
1058         mm.assignFamilyNameWithGroupName()
1059         self.assertEqual(('g1','g2'),mm.getGroupsNames())
1060         self.assertEqual(('g1','g2'),mm.getFamiliesNames())
1061         self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1'))
1062         self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2'))
1063         #
1064         mm=MEDFileUMesh.New()
1065         mm.setMeshAtLevel(0,m)
1066         mm.setGroupsAtLevel(0,[g1,g2,g3],False)
1067         self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1068         self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1069         self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1070         self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1071         self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1072         mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found
1073         self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1074         self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1075         self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1076         self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1077         self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1078         mm.changeFamilyId(5,6)
1079         g=mm.getGroupArr(0,"g3")
1080         self.assertTrue(g.isEqual(g3));
1081         g=mm.getGroupArr(0,"g2")
1082         self.assertTrue(g.isEqual(g2));
1083         g=mm.getGroupArr(0,"g1")
1084         self.assertTrue(g.isEqual(g1));
1085         pass
1086     
1087     # bug detected by gauthier
1088     def testMEDLoaderMEDLoaderNSReadFieldDoubleDataInMedFile(self):
1089         fname="Pyfile41.med"
1090         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
1091         m1=f1.getMesh()
1092         mm1=MEDFileUMesh.New()
1093         mm1.setCoords(m1.getCoords())
1094         mm1.setMeshAtLevel(0,m1)
1095         mm1.write(fname,2)
1096         ff1=MEDFileField1TS.New()
1097         ff1.setFieldNoProfileSBT(f1)
1098         ff1.write(fname,0)
1099         # writing mesh1 and field1, now creation of mesh2 and field2
1100         f2=f1.deepCopy()
1101         m2=f2.getMesh()
1102         m2.translate([0.5,0.6,0.7])
1103         m2.setName("3DSurfMesh_2")
1104         f2.getArray()[:]*=2.
1105         f2.setName("VectorFieldOnCells2")
1106         mm2=MEDFileUMesh.New()
1107         mm2.setCoords(m2.getCoords())
1108         mm2.setMeshAtLevel(0,m2)
1109         mm2.write(fname,0)
1110         ff2=MEDFileField1TS.New()
1111         ff2.setFieldNoProfileSBT(f2)
1112         ff2.write(fname,0)
1113         #
1114         f3=ReadFieldCell(fname,"3DSurfMesh_1",0,"VectorFieldOnCells",0,1)
1115         self.assertTrue(f3.isEqual(f1,1e-12,1e-12))
1116         f4=ReadFieldCell(fname,"3DSurfMesh_2",0,"VectorFieldOnCells2",0,1)
1117         self.assertTrue(f4.isEqual(f2,1e-12,1e-12))
1118         pass
1119
1120     def testMEDLoaderMultiLevelCellField1(self):
1121         fname="Pyfile42.med"
1122         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1123         m=MEDFileUMesh.New()
1124         m.setCoords(m2.getCoords())
1125         m.setMeshAtLevel(0,m2)
1126         m.setMeshAtLevel(-1,m1)
1127         m.setMeshAtLevel(-2,m0)
1128         m.write(fname,2)
1129         #
1130         FieldName1="Field1"
1131         compNames1=["comp1","comp2","comp3"]
1132         ff1=MEDFileField1TS.New()
1133         da2=DataArrayDouble.New()
1134         da2.alloc(m2.getNumberOfCells()*len(compNames1),1)
1135         da2.iota(7.)
1136         da2.rearrange(len(compNames1))
1137         da2.setInfoOnComponents(compNames1)
1138         f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f2.setName(FieldName1) ; f2.setArray(da2) ; f2.setMesh(m2) ; f2.checkConsistencyLight()
1139         ff1.setFieldNoProfileSBT(f2)
1140         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0]))
1141         da0=DataArrayDouble.New()
1142         da0.alloc(m0.getNumberOfCells()*len(compNames1),1)
1143         da0.iota(190.)
1144         da0.rearrange(len(compNames1))
1145         da0.setInfoOnComponents(compNames1)
1146         f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName1) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkConsistencyLight()
1147         ff1.setFieldNoProfileSBT(f0)
1148         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-2]))
1149         da1=DataArrayDouble.New()
1150         da1.alloc(m1.getNumberOfCells()*len(compNames1),1)
1151         da1.iota(90.)
1152         da1.rearrange(len(compNames1))
1153         da1.setInfoOnComponents(compNames1)
1154         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName1) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkConsistencyLight()
1155         ff1.setFieldNoProfileSBT(f1)
1156         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1157         #
1158         ff1.write(fname,0)
1159         #
1160         FieldName2="Field2"
1161         compNames2=["comp11","comp22"]
1162         ff2=MEDFileField1TS.New()
1163         da0=DataArrayDouble.New()
1164         da0.alloc(m0.getNumberOfCells()*2,1)
1165         da0.iota(-190.)
1166         da0.rearrange(2)
1167         da0.setInfoOnComponents(compNames2)
1168         f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName2) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkConsistencyLight()
1169         ff2.setFieldNoProfileSBT(f0)
1170         self.assertEqual(ff2.getNonEmptyLevels(),(0, [0]))
1171         da1=DataArrayDouble.New()
1172         da1.alloc(m1.getNumberOfCells()*len(compNames2),1)
1173         da1.iota(-90.)
1174         da1.rearrange(len(compNames2))
1175         da1.setInfoOnComponents(compNames2)
1176         f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName2) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkConsistencyLight()
1177         ff2.setFieldNoProfileSBT(f1)
1178         self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1179         #
1180         ff2.write(fname,0)
1181         #
1182         ff1=MEDFileField1TS.New(fname,FieldName1,-1,-1)
1183         self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1184         self.assertEqual(ff1.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')]), (3, [(0, (84, 148), '', '')]), (4, [(0, (148, 212), '', '')])])
1185         ff2=MEDFileField1TS.New(fname,FieldName2,-1,-1)
1186         self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1187         self.assertEqual(ff2.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')])])
1188         pass
1189
1190     def testFieldOnPflRetrieveOnMdimRelMax1(self):
1191         fname="Pyfile43.med"
1192         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1193         m=MEDFileUMesh.New()
1194         m.setMeshAtLevel(0,m2)
1195         m.setMeshAtLevel(-1,m1)
1196         m.setMeshAtLevel(-2,m0)
1197         f=MEDFileField1TS.New()
1198         ff=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
1199         ff.setName("NodeFieldPfl")
1200         arr=DataArrayDouble.New() ; arr.setValues([1.,10.,100.,2.,20.,200.],2,3)
1201         ff.setArray(arr)
1202         pfl=DataArrayInt.New() ; pfl.setValues([2,3],2,1) ; pfl.setName("PflNode")
1203         f.setFieldProfile(ff,m,-2,pfl)
1204         tes0=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1205         self.assertEqual(ON_NODES,tes0.getTypeOfField())
1206         self.assertEqual(1,tes0.getMesh().getMeshDimension())
1207         self.assertEqual(1,tes0.getMesh().getNumberOfCells())
1208         self.assertEqual(2,tes0.getMesh().getNumberOfNodes())
1209         self.assertEqual([1,0,1],tes0.getMesh().getNodalConnectivity().getValues())
1210         self.assertEqual([0,3],tes0.getMesh().getNodalConnectivityIndex().getValues())
1211         self.assertEqual(2,tes0.getArray().getNumberOfTuples())
1212         self.assertEqual(3,tes0.getArray().getNumberOfComponents())
1213         expected1=[1.,10.,100.,2.,20.,200.]
1214         nodeCoordsWithValue1=[10.,2.5,0.]
1215         nodeCoordsWithValue2=[10.,3.75,0.]
1216         for i in range(3):
1217             self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
1218             self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
1219             pass
1220         for i in range(6):
1221             self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
1222             pass
1223         del tes0
1224         #
1225         tes1=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1226         self.assertEqual(ON_CELLS,tes1.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1227         self.assertEqual(0,tes1.getMesh().getMeshDimension())
1228         self.assertEqual(2,tes1.getMesh().getNumberOfCells())
1229         self.assertEqual(135,tes1.getMesh().getNumberOfNodes())
1230         self.assertEqual([0,2,0,3],tes1.getMesh().getNodalConnectivity().getValues())
1231         self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
1232         self.assertEqual(2,tes1.getArray().getNumberOfTuples())
1233         self.assertEqual(3,tes1.getArray().getNumberOfComponents())
1234         for i in range(6):
1235             self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
1236             pass
1237         m.write(fname,2)
1238         f.write(fname,0)
1239         #
1240         pfl=DataArrayInt.New() ; pfl.setValues([3,2],2,1) ; pfl.setName("PflNode")
1241         f=MEDFileField1TS.New()
1242         f.setFieldProfile(ff,m,-2,pfl)
1243         tes2=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1244         self.assertEqual(ON_NODES,tes2.getTypeOfField())
1245         self.assertEqual(1,tes2.getMesh().getMeshDimension())
1246         self.assertEqual(1,tes2.getMesh().getNumberOfCells())
1247         self.assertEqual(2,tes2.getMesh().getNumberOfNodes())
1248         self.assertEqual([1,0,1],tes2.getMesh().getNodalConnectivity().getValues())
1249         self.assertEqual([0,3],tes2.getMesh().getNodalConnectivityIndex().getValues())
1250         self.assertEqual(2,tes2.getArray().getNumberOfTuples())
1251         self.assertEqual(3,tes2.getArray().getNumberOfComponents())
1252         expected2=[2.,20.,200.,1.,10.,100.]
1253         for i in range(3):
1254             self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
1255             self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
1256             pass
1257         for i in range(6):
1258             self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
1259             pass
1260         #
1261         tes3=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1262         self.assertEqual(ON_CELLS,tes3.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1263         self.assertEqual(0,tes3.getMesh().getMeshDimension())
1264         self.assertEqual(2,tes3.getMesh().getNumberOfCells())
1265         self.assertEqual(135,tes3.getMesh().getNumberOfNodes())
1266         self.assertEqual([0,3,0,2],tes3.getMesh().getNodalConnectivity().getValues())
1267         self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
1268         self.assertEqual(2,tes3.getArray().getNumberOfTuples())
1269         self.assertEqual(3,tes3.getArray().getNumberOfComponents())
1270         for i in range(6):
1271             self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
1272             pass
1273         pass
1274
1275     def testBuildInnerBoundaryAlongM1Group1(self):
1276         fname="Pyfile44.med"
1277         m=MEDCouplingCMesh.New()
1278         m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1279         m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1280         m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1281         m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1282         m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1283         m2.setName(m.getName())
1284         grp=DataArrayInt.New([4,6,8]) ; grp.setName("Grp")
1285         grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1286         mm=MEDFileUMesh.New()
1287         mm.setMeshAtLevel(0,m)
1288         mm.setMeshAtLevel(-1,m2)
1289         mm.setGroupsAtLevel(-1,[grp,grp2])
1290         grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1291         mm.setGroupsAtLevel(1,[grpNode])
1292         ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1293         ref1=[4,9,8,14,15,4,10,9,15,16,4,11,10,16,17]
1294         ref2=[4,9,8,14,30,4,10,9,30,31,4,11,10,31,32]
1295         #
1296         self.assertEqual(30,mm.getNumberOfNodes())
1297         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1298         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())
1299         #
1300         nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1301         self.assertEqual([15,16,17],nodes.getValues());
1302         self.assertEqual([7,8,9],cells.getValues());
1303         self.assertEqual([12,13,14],cells2.getValues());
1304         self.assertEqual(33,mm.getNumberOfNodes())
1305         self.assertEqual([4,6,8],mm.getGroupArr(-1,"Grp").getValues())
1306         self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1307         self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1308         self.assertEqual([17,18,19],mm.getGroupArr(-1,"Grp_dup").getValues())
1309         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
1310         self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())#
1311         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
1312         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1313         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])
1314         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1315         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1316         #
1317         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1318         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1319         refValues2=refValues[:] ; refValues2[7:10]=[1.365,1.26,1.35]
1320         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1321         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1322         mm.write(fname,2)
1323         pass
1324
1325     def testBuildInnerBoundaryAlongM1Group2(self):
1326         fname="Pyfile45.med"
1327         m=MEDCouplingCMesh.New()
1328         m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1329         m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1330         m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1331         m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1332         m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1333         m2.setName(m.getName())
1334         grp=DataArrayInt.New([4,6]) ; grp.setName("Grp")
1335         grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1336         mm=MEDFileUMesh.New()
1337         mm.setMeshAtLevel(0,m)
1338         mm.setMeshAtLevel(-1,m2)
1339         mm.setGroupsAtLevel(-1,[grp,grp2])
1340         grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1341         mm.setGroupsAtLevel(1,[grpNode])
1342         ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1343         ref1=[4,9,8,14,15,4,10,9,15,16]
1344         ref2=[4,9,8,14,30,4,10,9,30,16]
1345         #
1346         self.assertEqual(30,mm.getNumberOfNodes())
1347         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1348         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())
1349         #
1350         nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1351         self.assertEqual([15],nodes.getValues());
1352         self.assertEqual([7,8],cells.getValues());
1353         self.assertEqual([12,13],cells2.getValues());
1354         self.assertEqual(31,mm.getNumberOfNodes())
1355         self.assertEqual([4,6],mm.getGroupArr(-1,"Grp").getValues())
1356         self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1357         self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1358         self.assertEqual([17,18],mm.getGroupArr(-1,"Grp_dup").getValues())
1359         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
1360         self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())#
1361         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
1362         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1363         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])
1364         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1365         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1366         #
1367         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1368         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1369         refValues2=refValues[:] ; refValues2[7:9]=[1.365,1.47]
1370         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1371         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1372         mm.write(fname,2)       
1373         pass
1374
1375     def testBuildInnerBoundaryAlongM1Group3(self):
1376         """ Test buildInnerBoundaryAlongM1Group() with *non-connex* cracks """
1377         fname = "Pyfile73.med"
1378         m = MEDCouplingCMesh.New()
1379         m.setCoordsAt(0, DataArrayDouble([0.0,1.1,2.3,3.6,5.0]))
1380         m.setCoordsAt(1, DataArrayDouble([0.,1.,2.]))
1381         m = m.buildUnstructured(); m.setName("simple")
1382         m2 = m.buildDescendingConnectivity()[0]
1383         m2.setName(m.getName())
1384             
1385         # A crack in two non connected parts of the mesh:
1386         grpSeg = DataArrayInt([3,19]) ; grpSeg.setName("Grp") 
1387
1388         mm = MEDFileUMesh.New()
1389         mm.setMeshAtLevel(0,m)
1390         mm.setMeshAtLevel(-1,m2)
1391         mm.setGroupsAtLevel(-1,[grpSeg])
1392         nodes, cellsMod, cellsNotMod = mm.buildInnerBoundaryAlongM1Group("Grp")
1393         self.assertEqual([1,13],nodes.getValues());
1394         self.assertEqual([0,6],cellsMod.getValues());
1395         self.assertEqual([1,7],cellsNotMod.getValues());
1396         self.assertEqual(17,mm.getNumberOfNodes())
1397         self.assertEqual([3,19],mm.getGroupArr(-1,"Grp").getValues())
1398         self.assertEqual([22,23],mm.getGroupArr(-1,"Grp_dup").getValues())
1399         ref0=[4, 15, 0, 5, 6, 4, 8, 7, 12, 16]
1400         ref1=[4, 2, 1, 6, 7, 4, 9, 8, 13, 14]
1401         self.assertEqual(ref0,mm.getMeshAtLevel(0)[[0,6]].getNodalConnectivity().getValues())
1402         self.assertEqual(ref1,mm.getMeshAtLevel(0)[[1,7]].getNodalConnectivity().getValues())
1403         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
1404         mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1405
1406         refValues=DataArrayDouble([1.1, 1.2, 1.3, 1.4, 1.1, 1.2, 1.3, 1.4])
1407         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1408         self.assertTrue(delta.getMaxValue()[0]<1e-10)
1409         #
1410         mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1411         self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1412         refValues2=refValues[:] ; refValues2[0] = 1.265; refValues2[6] = 1.105
1413         valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ;     delta=(valsToTest-refValues2) ; delta.abs()
1414         self.assertTrue(delta.getMaxValue()[0]<1e-12)
1415         mm.write(fname,2)   
1416
1417     def testBuildInnerBoundaryAlongM1Group4(self):
1418         """ Test case where cells touch the M1 group on some nodes only and not on full edges (triangle mesh for ex)
1419         """
1420         coo = DataArrayDouble([0.,0., 1.,0., 2.,0., 3.,0.,
1421                                0.,1., 1.,1., 2.,1., 3.,1.,
1422                                0.,2., 1.,2., 2.,2., 3.,2.], 12, 2)
1423         conn = [3,0,4,1,  3,1,4,5,
1424                 3,5,9,10, 3,5,10,6,
1425                 3,2,6,7,  3,2,7,3,
1426                 3,4,8,9,  3,4,9,5,
1427                 3,1,5,6,  3,1,6,2,
1428                 3,6,10,11,3,6,11,7]
1429         # Only TRI3:
1430         connI = DataArrayInt()
1431         connI.alloc(13, 1); connI.iota(); connI *= 4
1432         m2 = MEDCouplingUMesh("2D", 2)
1433         m2.setCoords(coo)
1434         m2.setConnectivity(DataArrayInt(conn), connI)
1435         m2.checkConsistency()
1436         m1, _, _, _, _ = m2.buildDescendingConnectivity()
1437         grpIds = DataArrayInt([9,11]); grpIds.setName("group")
1438         grpIds2 = DataArrayInt([0,1]); grpIds2.setName("group2")
1439         mfu = MEDFileUMesh()
1440         mfu.setMeshAtLevel(0, m2)
1441         mfu.setMeshAtLevel(-1, m1)
1442         mfu.setGroupsAtLevel(-1, [grpIds, grpIds2])
1443         nNod = m2.getNumberOfNodes()
1444         nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1445         m2_bis = mfu.getMeshAtLevel(0)
1446         m2_bis.checkConsistency()
1447         m1_bis = mfu.getMeshAtLevel(-1)
1448         m1_bis.checkConsistency()
1449         self.assertEqual(nNod+2, mfu.getNumberOfNodes())
1450         self.assertEqual(nNod+2, m2_bis.getNumberOfNodes())
1451         self.assertEqual(nNod+2, m1_bis.getNumberOfNodes())
1452         self.assertEqual([6,7], nodesDup.getValues())
1453         self.assertEqual([2.,1., 3.,1.], m2_bis.getCoords()[nNod:].getValues())
1454         self.assertEqual(set([3,10,11]), set(cells1.getValues()))
1455         self.assertEqual(set([8,9,4,5]), set(cells2.getValues()))
1456         self.assertEqual([9,11],mfu.getGroupArr(-1,"group").getValues())
1457         self.assertEqual([23,24],mfu.getGroupArr(-1,"group_dup").getValues())
1458         self.assertEqual([0,1],mfu.getGroupArr(-1,"group2").getValues())
1459 #         mfu.getMeshAtLevel(0).writeVTK("/tmp/mfu_M0.vtu")
1460         ref0 =[3, 5, 10, 12, 3, 12, 10, 11, 3, 12, 11, 13]
1461         ref1 =[3, 2, 6, 7, 3, 2, 7, 3, 3, 1, 5, 6, 3, 1, 6, 2]
1462         self.assertEqual(ref0,mfu.getMeshAtLevel(0)[[3,10,11]].getNodalConnectivity().getValues())
1463         self.assertEqual(ref1,mfu.getMeshAtLevel(0)[[4,5,8,9]].getNodalConnectivity().getValues())
1464         self.assertRaises(InterpKernelException,mfu.getGroup(-1,"group_dup").checkGeoEquivalWith,mfu.getGroup(-1,"group"),2,1e-12) # Grp_dup and Grp are not equal considering connectivity only
1465         mfu.getGroup(-1,"group_dup").checkGeoEquivalWith(mfu.getGroup(-1,"group"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1466         m_bis0 = mfu.getMeshAtLevel(-1)
1467         m_desc, _, _, _, _ = m_bis0.buildDescendingConnectivity()
1468         m_bis0.checkDeepEquivalOnSameNodesWith(mfu.getMeshAtLevel(-1), 2, 9.9999999)
1469
1470     def testBuildInnerBoundary5(self):
1471         """ Full 3D test with tetras only. In this case a tri from the group is not duplicated because it is made only
1472         of non duplicated nodes. The tri in question is hence not part of the final new "dup" group. """
1473         coo = DataArrayDouble([200.0, 200.0, 0.0, 200.0, 200.0, 200.0, 200.0, 0.0, 200.0, 200.0, 0.0, 0.0, 0.0, 200.0, 0.0, 0.0, 200.0, 200.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
1474         200.0, 400.0, 200.0, 0.0, 400.0, 200.0, 200.0, 400.0, 0.0, 0.0, 400.0, 0.0, 200.0, 0.0, 100.00000000000016, 200.0, 63.15203310314546, 200.0, 200.0, 134.45205700643342,
1475          200.0, 200.0, 200.0, 100.00000000000016, 200.0, 63.15203310314546, 0.0, 200.0, 134.45205700643342, 0.0, 200.0, 0.0, 100.00000000000016, 0.0, 63.15203310314546, 
1476          200.0, 0.0, 134.45205700643342, 200.0, 0.0, 200.0, 100.00000000000016, 0.0, 63.15203310314546, 0.0, 0.0, 134.45205700643342, 0.0, 0.0, 200.0, 200.0, 100.02130053568538, 
1477          0.0, 200.0, 100.00938163175135, 200.0, 0.0, 100.02130053568538, 0.0, 0.0, 100.00938163175135, 299.3058739933347, 200.0, 200.0, 400.0, 98.68100542924483, 
1478          200.0, 302.8923433403344, 0.0, 200.0, 302.8923433403344, 200.0, 0.0, 400.0, 100.00000000000016, 0.0, 302.8923433403344, 0.0, 0.0, 400.0, 200.0, 98.55126825835082, 
1479          400.0, 0.0, 100.02162286181577, 99.31624553977466, 99.99999998882231, 200.0, 99.31624576683302, 100.00000010178034, 0.0, 99.31624560596512, 200.0, 100.0050761312483,
1480          99.31624560612883, 0.0, 100.00507613125338, 200.0, 99.99999995813045, 100.00950673487786, 0.0, 99.99999989928207, 100.0041870621175, 301.29063354383015, 
1481          100.0000000093269, 0.0, 301.29063360689975, 0.0, 100.00957769061164, 140.52853868782435, 99.99999963972768, 100.00509135751312, 297.87779091770784, 
1482          97.16750463405486, 97.18018457127863], 46, 3)
1483         c0 = [14, 45, 31, 21, 42, 14, 37, 38, 20, 44, 14, 39, 36, 41, 44, 14, 5, 25, 12, 13, 14, 38, 36, 44, 41, 14, 21, 20, 24, 44, 14, 38, 25, 41, 19, 14, 37, 38, 44, 41, 14, 16, 27,
1484          39, 41, 14, 21, 45, 26, 40, 14, 39, 37, 44, 41, 14, 14, 15, 24, 44, 14, 25, 38, 41, 13, 14, 27, 18, 6, 22, 14, 38, 36, 41, 13, 14, 44, 14, 15, 36, 14, 44, 23, 39, 26, 14,
1485          21,26, 23, 44, 14, 38, 44, 14, 24, 14, 39, 37, 41, 22, 14, 21, 33, 45, 42, 14, 27, 22, 39, 41, 14, 23, 26, 21, 3, 14, 27, 18, 22, 41, 14, 39, 36, 44, 17, 14, 21, 26, 44, 40,
1486          14, 39, 37, 22, 23, 14, 37, 38, 41, 19, 14, 25, 12, 13, 41, 14, 30, 26, 43, 45, 14, 38, 36, 13, 14, 14, 12, 36, 13, 41, 14, 20, 44, 21, 37, 14, 16, 36, 12, 41, 14, 39, 36,
1487          17, 16, 14, 44, 20, 24, 38, 14, 27, 16, 12, 41, 14, 26, 15, 17, 44, 14, 19, 18, 41, 37, 14, 40, 45, 26, 15, 14, 37, 38, 19, 20, 14, 17, 15, 26, 2, 14, 39, 36, 16, 41, 14,
1488          24, 21, 44, 40, 14, 16, 7, 27, 12, 14, 22, 18, 37, 41, 14, 21, 31, 45, 24, 14, 44, 40, 15, 24, 14, 24, 45, 15, 28, 14, 44, 40, 26, 15, 14, 24, 20, 21, 0, 14, 38, 36, 14,
1489          44, 14, 39, 37, 23, 44, 14, 45, 31, 42, 32, 14, 25, 18, 19, 4, 14, 36, 44, 17, 15, 14, 25, 19, 18, 41, 14, 24, 15, 14, 1, 14, 45, 24, 34, 28, 14, 35, 45, 30, 43, 14, 17,
1490          44, 39, 26, 14, 44, 23, 21, 37, 14, 30, 45, 29, 15, 14, 45, 35, 33, 43, 14, 30, 15, 26, 45, 14, 31, 21, 0, 24, 14, 33, 35, 32, 10, 14, 29, 45, 34, 28, 14, 32, 45, 34,
1491          29, 14, 45, 31, 32, 34, 14, 33, 26, 45, 43, 14, 45, 31, 34, 24, 14, 33, 26, 21, 45, 14, 11, 30, 35, 29, 14, 33, 35, 45, 32, 14, 33, 45, 42, 32, 14, 32, 8, 34, 31, 14,
1492          21, 26, 33, 3, 14, 35, 45, 32, 29, 14, 29, 34, 9, 28, 14, 15, 45, 24, 40, 14, 29, 45, 28, 15, 14, 21, 24, 45, 40, 14, 24, 15, 1, 28, 14, 35, 45, 29, 30, 14, 26, 15,
1493          30, 2]
1494         cI0 = [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,
1495          190, 195, 200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295, 300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 
1496          360, 365, 370, 375, 380, 385, 390, 395, 400, 405, 410, 415, 420, 425, 430]
1497         m3 = MEDCouplingUMesh("3D", 3)
1498         m3.setCoords(coo)
1499         m3.setConnectivity(DataArrayInt(c0), DataArrayInt(cI0))
1500         m3.checkConsistency()
1501         m2, _, _, _, _ = m3.buildDescendingConnectivity()
1502         grpIds = DataArrayInt([36,74]); grpIds.setName("group")
1503         mfu = MEDFileUMesh()
1504         mfu.setMeshAtLevel(0, m3)
1505         mfu.setMeshAtLevel(-1, m2)
1506         grpIds3D = DataArrayInt([0,1]); grpIds3D.setName("group_3d")
1507         mfu.setGroupsAtLevel(0, [grpIds3D])  # just to check preservation of 3D group
1508         mfu.setGroupsAtLevel(-1, [grpIds])
1509         nNod = m3.getNumberOfNodes()
1510         nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1511         m3_bis = mfu.getMeshAtLevel(0)
1512         m3_bis.checkConsistency()
1513         m2_bis = mfu.getMeshAtLevel(-1)
1514         m2_bis.checkConsistency()
1515         self.assertEqual(nNod+1, mfu.getNumberOfNodes())
1516         self.assertEqual(nNod+1, m3_bis.getNumberOfNodes())
1517         self.assertEqual(nNod+1, m2_bis.getNumberOfNodes())
1518         self.assertEqual([3], nodesDup.getValues())
1519         self.assertEqual(m3_bis.getCoords()[3].getValues(), m3_bis.getCoords()[nNod:].getValues())
1520         self.assertEqual(set([22]), set(cells1.getValues()))
1521         self.assertEqual(set([77]), set(cells2.getValues()))
1522         self.assertEqual([36,74],mfu.getGroupArr(-1,"group").getValues())
1523         self.assertEqual([0,1],mfu.getGroupArr(0,"group_3d").getValues())
1524         self.assertEqual([213],mfu.getGroupArr(-1,"group_dup").getValues())  # here only one cell has been duplicated
1525         m_bis0 = mfu.getMeshAtLevel(-1)
1526         m_desc, _, _, _, _ = m_bis0.buildDescendingConnectivity()
1527         m_bis0.checkDeepEquivalOnSameNodesWith(mfu.getMeshAtLevel(-1), 2, 9.9999999)
1528         pass
1529
1530     def testBasicConstructors(self):
1531         fname="Pyfile18.med"
1532         m=MEDFileMesh.New(fname)
1533         m=MEDFileMesh.New(fname,"ExampleOfMultiDimW",-1,-1)
1534         m=MEDFileMesh.New(fname)
1535         m=MEDFileUMesh(fname,"ExampleOfMultiDimW",-1,-1)
1536         m=MEDFileUMesh(fname)
1537         m=MEDFileUMesh()
1538         self.testMEDMesh6()
1539         m=MEDFileCMesh("MEDFileMesh5.med")
1540         m=MEDFileCMesh("MEDFileMesh5.med","myFirstCartMesh",-1,-1)
1541         m=MEDFileCMesh()
1542         m=MEDFileMeshMultiTS()
1543         m=MEDFileMeshMultiTS(fname)
1544         m=MEDFileMeshMultiTS(fname,"ExampleOfMultiDimW")
1545         m=MEDFileMeshes()
1546         m=MEDFileMeshes(fname)
1547         m=MEDFileField1TS()
1548         m=MEDFileField1TS(fname,"FieldOnFacesShuffle",2,7)
1549         m=MEDFileFieldMultiTS()
1550         m=MEDFileFieldMultiTS(fname,"FieldOnFacesShuffle")
1551         m=MEDFileFields()
1552         m=MEDFileFields(fname)
1553         m=MEDFileData()
1554         m=MEDFileData(fname)
1555         #
1556         m=DataArrayInt() ; m=DataArrayInt(5,2) ; m=DataArrayInt([6,5,4,3,2,1],3,2)
1557         m=DataArrayDouble() ; m=DataArrayDouble(5,2) ; m=DataArrayDouble([6,5,4,3,2,1],3,2)
1558         m=MEDCouplingUMesh("jjj",2) ; m=MEDCouplingUMesh()
1559         m=MEDCouplingCMesh()
1560         m=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1561         m=MEDCouplingFieldTemplate(ON_NODES)
1562         m=MEDCouplingMultiFields([])
1563         m=MEDCouplingFieldOverTime([])
1564         pass
1565
1566     # This is a non regression test. When a field lies partially on a mesh but fully on one of its geometric type.
1567     def testBugSemiPartialField(self):
1568         fname="Pyfile46.med"
1569         m=MEDLoaderDataForTest.build2DMesh_3()
1570         m=m[:10] ; m.setName("mesh")
1571         f=m.getMeasureField(False)
1572         f=f.buildNewTimeReprFromThis(ONE_TIME,False)
1573         f.setTime(5.5,3,4)
1574         f.setName("SemiPartialField")
1575         #
1576         f1=f[:6] ; f1.getMesh().setName(m.getName())
1577         f2=f[6:] ; f2.getMesh().setName(m.getName())
1578         #
1579         mm=MEDFileUMesh.New()
1580         mm.setMeshAtLevel(0,m)
1581         ff=MEDFileField1TS.New()
1582         ff.setFieldProfile(f1,mm,0,DataArrayInt.Range(0,6,1)) # no name on profile -> normally it is an error but in this special case
1583         mm.write(fname,2)
1584         ff.write(fname,0)
1585         #
1586         ff2=MEDFileField1TS.New(fname,f.getName(),f.getTime()[1],f.getTime()[2])
1587         fread=ff2.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
1588         fread2=ff2.getFieldAtLevel(ON_CELLS,0)
1589         #
1590         fread.checkConsistencyLight()
1591         fread2.checkConsistencyLight()
1592         self.assertTrue(fread.isEqual(f1,1e-12,1e-12))
1593         self.assertTrue(fread2.isEqual(f1,1e-12,1e-12))
1594         pass
1595
1596     def testUnPolyze1(self):
1597         fname="Pyfile47.med"
1598         mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1599         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]
1600         self.assertEqual(ref,mm.getFamilyFieldAtLevel(1).getValues())
1601         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]]))
1602         mm.write(fname,2)
1603         self.assertEqual(mm.getGroupArr(0,"grp0_L0").getValues(),[0,1,2,6])
1604         self.assertEqual(mm.getGroupArr(0,"grp1_L0").getValues(),[1,3,4,5,6])
1605         self.assertEqual(mm.getGroupArr(-1,"grp0_LM1").getValues(),[1,2,3,4,5])
1606         self.assertEqual(mm.getGroupArr(-1,"grp1_LM1").getValues(),[3,4,5,6])
1607         self.assertEqual(mm.getGroupArr(-1,"grp2_LM1").getValues(),[2,6,7,8])
1608         self.assertEqual(mm.getGroupArr(1,"grp0_Node").getValues(),[0,11,15,16])
1609         self.assertEqual(mm.getGroupArr(1,"grp1_Node").getValues(),[1,2,13,14,16])
1610         self.assertEqual(mm.getFamilyFieldAtLevel(1).getValues(),ref)
1611         # to test
1612         mm.setRenumFieldArr(0,None)
1613         mm.setFamilyFieldArr(-1,None)
1614         pass
1615
1616     def testUnPolyze2(self):
1617         fname="Pyfile48.med"
1618         mfd=MEDFileData.New()
1619         mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1620         meshes=MEDFileMeshes.New()
1621         meshes.pushMesh(mm)
1622         mfd.setMeshes(meshes)
1623         fields=MEDFileFields.New()
1624         mfd.setFields(fields)
1625         ff=MEDFileFieldMultiTS.New()
1626         fields.pushField(ff)
1627         #
1628         f0_0=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f0_0.setName("f0")
1629         f0_0.setTime(9.5,3,4)
1630         da=DataArrayDouble.New(38*2) ; da.iota(6.) ; da.rearrange(2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1631         f0_0.setArray(da)
1632         f0_0.setMesh(mm.getMeshAtLevel(0))
1633         ff.appendFieldNoProfileSBT(f0_0)
1634         ff0=ff.getTimeStepAtPos(0)
1635         f0_1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_1.setName("f0")
1636         f0_1.setTime(9.5,3,4)
1637         pfl=DataArrayInt.New([1,4,5,6]) ; pfl.setName("pfltest")
1638         f0_1.setMesh(mm.getMeshAtLevel(0)[pfl])
1639         da=DataArrayDouble.New([1401.,101401.,1602.,101602.,3100.,103100.,3101.,103101.],4,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1640         f0_1.setArray(da)
1641         ff0.setFieldProfile(f0_1,mm,0,pfl)
1642         f0_2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_2.setName("f0")#provoquer error
1643         f0_2.setTime(9.5,3,4)
1644         pfl2=DataArrayInt.New([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfltestM1")
1645         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
1646         f0_2.setMesh(mm.getMeshAtLevel(-1)[pfl2])
1647         f0_2.setArray(da)
1648         ff0.setFieldProfile(f0_2,mm,-1,pfl2)
1649         mfd.getFields().shallowCpyGlobs(ff0)
1650         #
1651         mfd.unPolyzeMeshes()
1652         #
1653         fmts=mfd.getFields()[0]
1654         self.assertEqual(fmts.getNumberOfTS(),1)
1655         self.assertEqual(fmts.getTimeSteps(),[(3,4,9.5)])
1656         arr,entry=fmts.getUndergroundDataArrayExt(3,4)
1657         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))])
1658         self.assertTrue(arr[38:40].isEqualWithoutConsideringStr(DataArrayDouble([300.0,100300.0,301.0,100301.0],2,2),1e-8))
1659         self.assertTrue(arr[40:43].isEqualWithoutConsideringStr(DataArrayDouble([400.0,100400.0,401.0,100401.0,402.0,100402.0],3,2),1e-8))
1660         self.assertTrue(arr[43:46].isEqualWithoutConsideringStr(DataArrayDouble([3200.0,103200.0,3201.0,103201.0,3203.0,103203.0],3,2),1e-8))
1661         self.assertTrue(arr[46:48].isEqualWithoutConsideringStr(DataArrayDouble([1401.0,101401.0,3100.0,103100.0],2,2),1e-8))
1662         self.assertTrue(arr[48:49].isEqualWithoutConsideringStr(DataArrayDouble([1602.0,101602.0],1,2),1e-8))
1663         self.assertTrue(arr[49:50].isEqualWithoutConsideringStr(DataArrayDouble([3101.0,103101.0],1,2),1e-8))
1664         self.assertEqual(('NewPfl_0','NewPfl_1','NewPfl_2'),fmts.getPflsReallyUsed())
1665         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))
1666         self.assertEqual(fmts.getProfile("NewPfl_0").getValues(),[0,1])
1667         self.assertEqual(fmts.getProfile("NewPfl_1").getValues(),[1,2])
1668         self.assertEqual(fmts.getProfile("NewPfl_2").getValues(),[2])
1669         ftest0=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,0,mfd.getMeshes()[0])
1670         self.assertTrue(ftest0.getArray().isEqualWithoutConsideringStr(DataArrayDouble([1401.,101401.,3100.,103100.,1602.,101602.,3101.,103101.],4,2),1e-8))
1671         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])
1672         self.assertEqual(ftest0.getMesh().getNodalConnectivityIndex().getValues(),[0,5,10,17,26])
1673         ftest1=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,-1,mfd.getMeshes()[0])
1674         self.assertTrue(ftest1.getArray().isEqualWithoutConsideringStr(DataArrayDouble([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.]),1e-8))
1675         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])
1676         self.assertEqual(ftest1.getMesh().getNodalConnectivityIndex().getValues(),[0,4,8,13,18,23,29,35,43])
1677         #
1678         mfd.write(fname,2)
1679         pass
1680
1681     def testGaussWriteOnPfl1(self):
1682         fname="Pyfile49.med"
1683         fname2="Pyfile50.med"
1684         coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
1685         mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
1686         mQ8.allocateCells(1)
1687         mQ8.insertNextCell(NORM_QUAD8,list(range(8)))
1688         mQ8.finishInsertingCells()
1689         mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
1690         mQ4.allocateCells(1)
1691         mQ4.insertNextCell(NORM_QUAD4,list(range(4)))
1692         mQ4.finishInsertingCells()
1693         mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
1694         mT3.allocateCells(1)
1695         mT3.insertNextCell(NORM_TRI3,list(range(3)))
1696         mT3.finishInsertingCells()
1697         
1698         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.]]
1699         ms=11*[mT3]+2*[mQ4]+7*[mQ8]
1700         ms[:]=(elt.deepCopy() for elt in ms)
1701         for m,t in zip(ms,tr):
1702             d=m.getCoords() ; d+= t
1703             pass
1704         m=MEDCouplingUMesh.MergeUMeshes(ms)
1705         m.setName("mesh")
1706         m2=m[:13] ; m2.setName(m.getName())
1707         ### 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.
1708         ### So here 2 pfls will be created (pfl_TRI3_loc_0 and pfl_TRI3_loc_1)
1709         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1710         f.setMesh(m2)
1711         f.setTime(4.5,1,2)
1712         da=DataArrayDouble(34) ; da.iota(3.)
1713         f.setArray(da)
1714         f.setName("fieldCellOnPflWithoutPfl")
1715         fInvalid=f.deepCopy()
1716         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])
1717         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])
1718         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])
1719         f.checkConsistencyLight()
1720         fInvalid2=fInvalid.deepCopy()
1721         fInvalid2.getDiscretization().setArrayOfDiscIds(f.getDiscretization().getArrayOfDiscIds())
1722         #
1723         mm=MEDFileUMesh()
1724         mm.setMeshAtLevel(0,m)
1725         mm.write(fname,2)
1726         #
1727         f1ts=MEDFileField1TS.New()
1728         pfl=DataArrayInt(list(range(13))) ; pfl.setName("pfl")
1729         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set !
1730         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given !
1731         f1ts.setFieldProfile(f,mm,0,pfl)
1732         f1ts.write(fname,0)
1733         #
1734         self.assertEqual(f1ts.getPfls(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1735         self.assertEqual(f1ts.getPflsReallyUsed(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1736         da1=DataArrayInt([0,1,2,3,4,5,6,7,8]) ; da1.setName("pfl_NORM_TRI3_loc_0")
1737         self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_0").isEqual(da1))
1738         da1=DataArrayInt([9,10]) ; da1.setName("pfl_NORM_TRI3_loc_1")
1739         self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_1").isEqual(da1))
1740         self.assertEqual(f1ts.getLocs(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1741         self.assertEqual(f1ts.getLocsReallyUsed(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1742         #
1743         dataRead=MEDFileData.New(fname)
1744         mRead=dataRead.getMeshes()[0]
1745         f1tsRead=dataRead.getFields()[0][0]
1746         f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1747         f2=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1748         self.assertTrue(f.isEqual(f2,1e-12,1e-12))
1749         f2_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1750         f2_bis.checkConsistencyLight()
1751         self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12))
1752         #
1753         WriteField(fname2,f,True)
1754         f2_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1755         self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12))
1756         ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc
1757         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1758         pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2")
1759         m2=m[pfl] ; m2.setName(m.getName())
1760         f.setMesh(m2)
1761         f.setTime(4.5,1,2)
1762         da=DataArrayDouble(35) ; da.iota(3.)
1763         f.setArray(da)
1764         f.setName("fieldCellOnPflWithoutPfl2")
1765         f.setGaussLocalizationOnCells([0,1,3],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1766         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])
1767         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])
1768         f.checkConsistencyLight()
1769         #
1770         mm=MEDFileUMesh()
1771         mm.setMeshAtLevel(0,m)
1772         mm.write(fname,2)
1773         f1ts=MEDFileField1TS.New()
1774         f1ts.setFieldProfile(f,mm,0,pfl)
1775         self.assertEqual(f1ts.getPfls(),('pfl2_NORM_TRI3_loc_0','pfl2_NORM_TRI3_loc_1','pfl2_NORM_QUAD8_loc_2'))
1776         self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_0").getValues(),[1,2,6])
1777         self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_1").getValues(),[5,8,9])
1778         self.assertEqual(f1ts.getProfile("pfl2_NORM_QUAD8_loc_2").getValues(),[2,3,4,5])
1779         f1ts.write(fname,0)
1780         dataRead=MEDFileData.New(fname)
1781         mRead=dataRead.getMeshes()[0]
1782         f1tsRead=dataRead.getFields()[0][0]
1783         f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1784         f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1785         f3.renumberCells([0,1,3,2,4,5,6,7,8,9])
1786         self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1787         f3_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1788         f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9])
1789         self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1790         #
1791         WriteField(fname2,f,True)
1792         f3_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1793         f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9])
1794         self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1795         ## Use case 3 : no pfl but creation of pfls due to gauss pts
1796         f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1797         f.setMesh(m)
1798         f.setTime(4.5,1,2)
1799         da=DataArrayDouble(60) ; da.iota(3.)
1800         f.setArray(da)
1801         f.setName("fieldCellWithoutPfl")
1802         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])
1803         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])
1804         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])
1805         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])
1806         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])
1807         f.checkConsistencyLight()
1808         mm=MEDFileUMesh()
1809         mm.setMeshAtLevel(0,m) 
1810         f1ts=MEDFileField1TS.New()
1811         f1ts.setFieldNoProfileSBT(f)
1812         self.assertEqual(f1ts.getPfls(),('Pfl_fieldCellWithoutPfl_NORM_TRI3_0','Pfl_fieldCellWithoutPfl_NORM_TRI3_1','Pfl_fieldCellWithoutPfl_NORM_QUAD8_3','Pfl_fieldCellWithoutPfl_NORM_QUAD8_4'))
1813         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_0").getValues(),[0,1,2,3,4,5,6,7,8])
1814         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_1").getValues(),[9,10])
1815         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_3").getValues(),[0,1,2,4,5])
1816         self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_4").getValues(),[3,6])
1817         mm.write(fname,2)
1818         f1ts.write(fname,0)
1819         #
1820         dataRead=MEDFileData.New(fname)
1821         mRead=dataRead.getMeshes()[0]
1822         f1tsRead=dataRead.getFields()[0][0]
1823         f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1824         f3.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1825         self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1826         f3_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1827         f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1828         self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1829         #
1830         WriteField(fname2,f,True)
1831         f3_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1832         f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1833         self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1834         pass
1835
1836     # Testing profile on nodes when the profile is identity but not on all nodes.
1837     def testMEDFieldPflOnNode1(self):
1838         fname="Pyfile51.med"
1839         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)
1840         m0=MEDCouplingUMesh("Mesh",2)
1841         m0.allocateCells(5)
1842         m0.insertNextCell(NORM_TRI3,[1,4,2])
1843         m0.insertNextCell(NORM_TRI3,[4,5,2])
1844         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1845         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1846         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1847         m0.finishInsertingCells()
1848         m0.setCoords(coo)
1849         m1=MEDCouplingUMesh(m0.getName(),1)
1850         m1.allocateCells(9)
1851         conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1852         for i in range(9):
1853             m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1854             pass
1855         m1.finishInsertingCells()
1856         m1.setCoords(coo)
1857         #
1858         m=MEDFileUMesh()
1859         m.setMeshAtLevel(0,m0)
1860         m.setMeshAtLevel(-1,m1)
1861         #
1862         dt=3 ; it=2 ; tim=4.5
1863         fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1864         fieldNode0.setName("fieldNode0")
1865         fieldNode0.setTime(tim,dt,it)
1866         pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
1867         arr=DataArrayDouble([10,11,12,13,14])
1868         fieldNode0.setArray(arr)
1869         f0=MEDFileField1TS()
1870         f0.setFieldProfile(fieldNode0,m,0,pfl0)
1871         m.write(fname,2) ; f0.write(fname,0)
1872         fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1873         fieldNode1.setName("fieldNode1")
1874         fieldNode1.setTime(tim,dt,it)
1875         pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1876         arr1=DataArrayDouble([20,21,22,23,24,25,26])
1877         fieldNode1.setArray(arr1)
1878         f1=MEDFileField1TS()
1879         f1.setFieldProfile(fieldNode1,m,-1,pfl1)
1880         f1.write(fname,0)
1881         del m,f0,m0,m1,f1
1882         ## Reading from file
1883         m=MEDFileMesh.New(fname)
1884         m0=m.getMeshAtLevel(0)
1885         m00=m0.deepCopy() ; m00=m00[[0,2]] ; m00.setName(m.getName()) ; m00.zipCoords()
1886         fieldNode0.setMesh(m00)
1887         f0=MEDFileField1TS.New(fname,fieldNode0.getName(),dt,it)
1888         ff0_1=f0.getFieldOnMeshAtLevel(ON_NODES,m0)
1889         ff0_1.checkConsistencyLight()
1890         self.assertTrue(ff0_1.isEqual(fieldNode0,1e-12,1e-12))
1891         ff0_2=f0.getFieldAtLevel(ON_NODES,0)
1892         ff0_2.checkConsistencyLight()
1893         self.assertTrue(ff0_2.isEqual(fieldNode0,1e-12,1e-12))
1894         ff0_3=f0.getFieldOnMeshAtLevel(ON_NODES,0,m)
1895         ff0_3.checkConsistencyLight()
1896         self.assertTrue(ff0_3.isEqual(fieldNode0,1e-12,1e-12))
1897         ff0_4=ReadFieldNode(fname,m.getName(),0,fieldNode0.getName(),dt,it)
1898         ff0_4.checkConsistencyLight()
1899         self.assertTrue(ff0_4.isEqual(fieldNode0,1e-12,1e-12))
1900         f1=MEDFileField1TS.New(fname,fieldNode1.getName(),dt,it)
1901         m1=m.getMeshAtLevel(-1)
1902         m10=m1.deepCopy() ; m10=m10[[0,1,2,3,4,5,6,7]] ; m10.setName(m.getName()) ; m10.zipCoords()
1903         fieldNode1.setMesh(m10)
1904         ff1_1=f1.getFieldOnMeshAtLevel(ON_NODES,m1)
1905         ff1_1.checkConsistencyLight()
1906         self.assertTrue(ff1_1.isEqual(fieldNode1,1e-12,1e-12))
1907         ff1_2=f1.getFieldAtLevel(ON_NODES,-1)
1908         ff1_2.checkConsistencyLight()
1909         self.assertTrue(ff1_2.isEqual(fieldNode1,1e-12,1e-12))
1910         ff1_3=f1.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1911         ff1_3.checkConsistencyLight()
1912         self.assertTrue(ff1_3.isEqual(fieldNode1,1e-12,1e-12))
1913         ff1_4=ReadFieldNode(fname,m.getName(),-1,fieldNode1.getName(),dt,it)
1914         ff1_4.checkConsistencyLight()
1915         self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1916         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]
1917         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]
1918         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]
1919         arr_r,pfl1_r=f1.getFieldWithProfile(ON_NODES,-1,m)
1920         arr_r.setName(fieldNode1.getArray().getName())
1921         self.assertTrue(arr_r.isEqual(fieldNode1.getArray(),1e-12))
1922         pfl1_r.setName(pfl1.getName())
1923         self.assertTrue(pfl1_r.isEqual(pfl1))
1924         pass
1925     
1926         # Testing profile on nodes when the profile is identity but not on all nodes.
1927     def testMEDFieldPflOnCell1(self):
1928         fname="Pyfile52.med"
1929         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)
1930         m0=MEDCouplingUMesh("Mesh",2)
1931         m0.allocateCells(5)
1932         m0.insertNextCell(NORM_TRI3,[1,4,2])
1933         m0.insertNextCell(NORM_TRI3,[4,5,2])
1934         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1935         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1936         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1937         m0.finishInsertingCells()
1938         m0.setCoords(coo)
1939         m1=MEDCouplingUMesh(m0.getName(),1)
1940         m1.allocateCells(9)
1941         conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1942         for i in range(9):
1943             m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1944             pass
1945         m1.finishInsertingCells()
1946         m1.setCoords(coo)
1947         #
1948         m=MEDFileUMesh()
1949         m.setMeshAtLevel(0,m0)
1950         m.setMeshAtLevel(-1,m1)
1951         #
1952         dt=3 ; it=2 ; tim=4.5
1953         fieldCell0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1954         fieldCell0.setName("fieldCell0")
1955         fieldCell0.setTime(tim,dt,it)
1956         pfl0=DataArrayInt([0,1,2]) ; pfl0.setName("PflIdentity0") # important to keep like that
1957         arr=DataArrayDouble([10,11,12])
1958         fieldCell0.setArray(arr)
1959         f0=MEDFileField1TS()
1960         f0.setFieldProfile(fieldCell0,m,0,pfl0)
1961         m.write(fname,2) ; f0.write(fname,0)
1962         fieldCell1=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1963         fieldCell1.setName("fieldCell1")
1964         fieldCell1.setTime(tim,dt,it)
1965         pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1966         arr1=DataArrayDouble([20,21,22,23,24,25,26])
1967         fieldCell1.setArray(arr1)
1968         f1=MEDFileField1TS()
1969         f1.setFieldProfile(fieldCell1,m,-1,pfl1)
1970         f1.write(fname,0)
1971         del m,f0,m0,m1,f1
1972         ## Reading from file
1973         m=MEDFileMesh.New(fname)
1974         m0=m.getMeshAtLevel(0)
1975         m00=m0.deepCopy() ; m00=m00[pfl0] ; m00.setName(m.getName())
1976         fieldCell0.setMesh(m00)
1977         f0=MEDFileField1TS.New(fname,fieldCell0.getName(),dt,it)
1978         ff0_1=f0.getFieldOnMeshAtLevel(ON_CELLS,m0)
1979         ff0_1.checkConsistencyLight()
1980         self.assertTrue(ff0_1.isEqual(fieldCell0,1e-12,1e-12))
1981         ff0_2=f0.getFieldAtLevel(ON_CELLS,0)
1982         ff0_2.checkConsistencyLight()
1983         self.assertTrue(ff0_2.isEqual(fieldCell0,1e-12,1e-12))
1984         ff0_3=f0.getFieldOnMeshAtLevel(ON_CELLS,0,m)
1985         ff0_3.checkConsistencyLight()
1986         self.assertTrue(ff0_3.isEqual(fieldCell0,1e-12,1e-12))
1987         ff0_4=ReadFieldCell(fname,m.getName(),0,fieldCell0.getName(),dt,it)
1988         ff0_4.checkConsistencyLight()
1989         self.assertTrue(ff0_4.isEqual(fieldCell0,1e-12,1e-12))
1990         f1=MEDFileField1TS.New(fname,fieldCell1.getName(),dt,it)
1991         m1=m.getMeshAtLevel(-1)
1992         m10=m1.deepCopy() ; m10=m10[pfl1] ; m10.setName(m.getName())
1993         fieldCell1.setMesh(m10)
1994         ff1_1=f1.getFieldOnMeshAtLevel(ON_CELLS,m1)
1995         ff1_1.checkConsistencyLight()
1996         self.assertTrue(ff1_1.isEqual(fieldCell1,1e-12,1e-12))
1997         ff1_2=f1.getFieldAtLevel(ON_CELLS,-1)
1998         ff1_2.checkConsistencyLight()
1999         self.assertTrue(ff1_2.isEqual(fieldCell1,1e-12,1e-12))
2000         ff1_3=f1.getFieldOnMeshAtLevel(ON_CELLS,-1,m)
2001         ff1_3.checkConsistencyLight()
2002         self.assertTrue(ff1_3.isEqual(fieldCell1,1e-12,1e-12))
2003         ff1_4=ReadFieldCell(fname,m.getName(),-1,fieldCell1.getName(),dt,it)
2004         ff1_4.checkConsistencyLight()
2005         self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
2006         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]
2007         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]
2008         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]
2009         arr_r,pfl1_r=f1.getFieldWithProfile(ON_CELLS,-1,m)
2010         arr_r.setName(fieldCell1.getArray().getName())
2011         self.assertTrue(arr_r.isEqual(fieldCell1.getArray(),1e-12))
2012         pfl1_r.setName(pfl1.getName())
2013         self.assertTrue(pfl1_r.isEqual(pfl1))
2014         pass
2015
2016     def testMEDFileUMeshZipCoords1(self):
2017         m=MEDFileUMesh()
2018         coo=DataArrayDouble(30) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2019         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])
2020         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2021         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2022         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2023         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2024         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2025         numCoo=DataArrayInt(10) ; numCoo.iota(3) ; m.setRenumFieldArr(1,numCoo)
2026         famCoo=DataArrayInt(10) ; famCoo.iota(4) ; m.setFamilyFieldArr(1,famCoo)
2027         da=DataArrayInt([20,30,40]) ; m.setRenumFieldArr(0,da) ; da=DataArrayInt([200,300,400]) ; m.setFamilyFieldArr(0,da)
2028         da=DataArrayInt([50,60]) ; m.setRenumFieldArr(-1,da) ; da=DataArrayInt([500,600]) ; m.setFamilyFieldArr(-1,da)
2029         da=DataArrayInt([70,80,90]) ; m.setRenumFieldArr(-2,da) ; da=DataArrayInt([700,800,900]) ; m.setFamilyFieldArr(-2,da)
2030         o2n=m.zipCoords()
2031         self.assertTrue(o2n.isEqual(DataArrayInt([-1,0,1,2,3,-1,4,5,6,-1])))
2032         self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt([4,5,6,7,9,10,11])))
2033         self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([5,6,7,8,10,11,12])))
2034         self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,4,1,3,2,3,5,0,4,4,4,1])))
2035         self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,9,15])))
2036         self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivity().isEqual(DataArrayInt([1,0,4,1,5,2])))
2037         self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6])))
2038         self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivity().isEqual(DataArrayInt([0,1,0,4,0,6])))
2039         self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivityIndex().isEqual(DataArrayInt([0,2,4,6])))
2040         pass
2041
2042     def testMEDUMeshAddNodeGroup1(self):
2043         fname="Pyfile53.med"
2044         m=MEDFileUMesh()
2045         coo=DataArrayDouble(39) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2046         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])
2047         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2048         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2049         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2050         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2051         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2052         #
2053         mm=m.deepCopy()
2054         famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(1,famCoo)
2055         da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(0,da0)
2056         da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
2057         da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
2058         mm.setFamilyId("MyFam",2)
2059         mm.setFamilyId("MyOtherFam",3)
2060         mm.setFamilyId("MyOther-1",-1)
2061         mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
2062         mm.setFamiliesOnGroup("grpA",["MyOther-1"])
2063         #
2064         self.assertTrue(mm.getNodeFamiliesArr(["MyFam","MyOtherFam"]).isEqual(DataArrayInt([1,3,4,12]))) # find family id 2 and 3 into famCoo
2065         #
2066         daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
2067         mm.addNodeGroup(daTest)
2068         self.assertTrue(mm.getNodeGroupArr(daTest.getName()).isEqual(daTest)) # the node group has been pushed right before -> now read it
2069         self.assertTrue(mm.getNodeGroupsArr(["grp1","grpA"]).isEqual(DataArrayInt([1,3,4,6,9,10,11,12])))#daTest+[11] because 11 is the rank of -1 (MyOther-1) in famCoo
2070         #
2071         expect1=DataArrayInt([1,4]) ; expect1.setName("MyFam")
2072         self.assertTrue(mm.getNodeFamilyArr(expect1.getName()).isEqual(expect1))
2073         #
2074         self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
2075         self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
2076         for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
2077             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2078             pass
2079         self.assertEqual(mm.getFamiliesNames(),('Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
2080         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2081         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2082         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2083         for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
2084             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2085             pass
2086         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_8'))
2087         da=DataArrayInt([3,12]) ; da.setName("grp0")
2088         self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
2089         da.setValues([1])
2090         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2091         mm.write(fname,2)
2092         mm=MEDFileMesh.New(fname)
2093         self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
2094         self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
2095         for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
2096             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2097             pass
2098         self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
2099         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2100         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2101         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2102         for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
2103             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2104             pass
2105         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_8','MyOtherFam'))
2106         da=DataArrayInt([3,12]) ; da.setName("grp0")
2107         self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
2108         da.setValues([1])
2109         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2110         pass
2111
2112     def testMEDUMeshAddGroup1(self):
2113         fname="Pyfile54.med"
2114         m=MEDFileUMesh()
2115         coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2116         m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
2117         for i in range(7):
2118             m0.insertNextCell(NORM_TRI3,[1,2,1])
2119             pass
2120         for i in range(4):
2121             m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
2122             pass
2123         for i in range(2):
2124             m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
2125             pass
2126         m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2127         m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2128         m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2129         m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2130         m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2131         #
2132         mm=m.deepCopy()
2133         famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(0,famCoo)
2134         da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(1,da0)
2135         da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
2136         da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
2137         mm.setFamilyId("MyFam",2)
2138         mm.setFamilyId("MyOtherFam",3)
2139         mm.setFamilyId("MyOther-1",-1)
2140         mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
2141         mm.setFamiliesOnGroup("grpA",["MyOther-1"])
2142         #
2143         daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
2144         mm.addGroup(0,daTest)
2145         self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2146         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2147         for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2148             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2149             pass
2150         self.assertEqual(mm.getFamiliesNames(),('Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2151         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2152         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2153         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2154         for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2155             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2156             pass
2157         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_-8'))
2158         da=DataArrayInt([3,12]) ; da.setName("grp0")
2159         self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2160         da.setValues([1])
2161         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2162         mm.write(fname,2)
2163         mm=MEDFileMesh.New(fname)
2164         self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2165         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2166         for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2167             self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2168             pass
2169         self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2170         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2171         self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2172         self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2173         for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2174             self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2175             pass
2176         self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_-8','MyOtherFam'))
2177         da=DataArrayInt([3,12]) ; da.setName("grp0")
2178         self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2179         da.setValues([1])
2180         self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2181         pass
2182
2183     def testHeapMem1(self):
2184         a=DataArrayInt() ; aa=a.getHeapMemorySize()
2185         a.alloc(0,1)
2186         strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
2187         #
2188         m=MEDCouplingCMesh()
2189         arr=DataArrayDouble(10,1) ; arr.iota(0)
2190         m.setCoords(arr,arr)
2191         m=m.buildUnstructured()
2192         m.setName("mm")
2193         f=m.getMeasureField(False)
2194         self.assertIn(m.getHeapMemorySize(), list(range(3552 - 100, 3552 + 100 + 4 * strMulFac)))
2195         self.assertIn(f.getHeapMemorySize(), list(range(4215 - 100, 4215 + 100 + 8 * strMulFac)))
2196         #
2197         mm=MEDFileUMesh()
2198         mm.setMeshAtLevel(0,m)
2199         self.assertIn(mm.getHeapMemorySize(), list(range(3889 - 100, 4225 + 100 + 10 * strMulFac)))
2200         ff=MEDFileField1TS()
2201         ff.setFieldNoProfileSBT(f)
2202         self.assertIn(ff.getHeapMemorySize(), list(range(771 - 40, 871 + 21 + (4 + 1) * strMulFac)))
2203         #
2204         fff=MEDFileFieldMultiTS()
2205         fff.appendFieldNoProfileSBT(f)
2206         self.assertIn(fff.getHeapMemorySize(), list(range(815 - 50, 915 + 30 + (6 + 2) * strMulFac)))
2207         f.setTime(1.,0,-1)
2208         fff.appendFieldNoProfileSBT(f)
2209         self.assertIn(fff.getHeapMemorySize(), list(range(1594 - 90, 1794 + 50 + (10 + 1) * strMulFac)))
2210         self.assertIn(fff[0, -1].getHeapMemorySize(), list(range(771 - 40, 871 + 20 + (4 + 1) * strMulFac)))
2211         f2=f[:50]
2212         f2.setTime(2.,1,-1)
2213         pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2214         fff.appendFieldProfile(f2,mm,0,pfl)
2215         self.assertIn(fff.getHeapMemorySize(), list(range(2348 - 130, 2608 + 100 + (10 + 2) * strMulFac)))
2216         self.assertIn(fff.getProfile("pfl").getHeapMemorySize(), list(range(204 - 10, 204 + 10 + 2 * strMulFac)))
2217         self.assertIn(fff[1, -1].getHeapMemorySize(), list(range(738 - 50, 838 + 30 + 4 * strMulFac)))
2218         pass
2219
2220     def testCurveLinearMesh1(self):
2221         fname="Pyfile55.med"
2222         mesh=MEDCouplingCurveLinearMesh();
2223         mesh.setTime(2.3,4,5);
2224         mesh.setTimeUnit("us");
2225         mesh.setName("Example of Cuve linear mesh");
2226         mesh.setDescription("buildCLMesh");
2227         a1=DataArrayDouble(3*20,1);
2228         a1.iota(7.) ; a1.rearrange(3);
2229         mesh.setCoords(a1);
2230         mesh.setNodeGridStructure([4,5]);
2231         mesh.checkConsistencyLight();
2232         #
2233         m=MEDFileCurveLinearMesh()
2234         m.setMesh(mesh)
2235         d=DataArrayInt(20) ; d.iota(4)
2236         m.setFamilyFieldArr(1,d)
2237         d3=DataArrayInt(20) ; d3.iota(400)
2238         m.setRenumFieldArr(1,d3)
2239         d2=DataArrayInt(12) ; d2.iota(40)
2240         m.setFamilyFieldArr(0,d2)
2241         d4=DataArrayInt(21) ; d4.iota(4000)
2242         self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2243         d4.popBackSilent()
2244         m.setRenumFieldArr(1,d4)
2245         m.write(fname,2)
2246         #
2247         m1=MEDFileCurveLinearMesh(fname)
2248         mm=m1.getMesh()
2249         self.assertTrue(mm.isEqual(mesh,1e-12))
2250         self.assertEqual(mm.getSpaceDimension(),3)
2251         self.assertEqual(mm.getSpaceDimensionOnNodeStruct(),2)
2252         #
2253         m1=MEDFileMesh.New(fname)
2254         self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2255         self.assertTrue(isinstance(m1.getUnivName(),str))
2256         self.assertTrue(len(m1.getUnivName())!=0)
2257         self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2258         pass
2259
2260     def testParameters1(self):
2261         fname="Pyfile56.med"
2262         m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2263         mm=MEDFileCMesh() ; mm.setMesh(m)
2264         ms=MEDFileMeshes() ; ms.pushMesh(mm)
2265         data=MEDFileData()
2266         p=MEDFileParameters()
2267         data.setParams(p) ; data.setMeshes(ms)
2268         pts=MEDFileParameterMultiTS()
2269         pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2270         pts.appendValue(1,2,3.4,567.89)
2271         pts.appendValue(2,3,5.6,999.123)
2272         pts2=pts.deepCopy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2273         p.pushParam(pts) ; p.pushParam(pts2)
2274         data.write(fname,2)
2275         p2=MEDFileParameters(fname)
2276         self.assertTrue(p.isEqual(p2,1e-14)[0])
2277         self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2278         p3=p.deepCopy()
2279         pts4=pts2.deepCopy()
2280         pts3=pts2.deepCopy()
2281         self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2282         pts2.eraseTimeStepIds([0])
2283         self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2284         del pts3[[3.4]]
2285         self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2286         self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2287         self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2288         self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2289         self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2290         p=p3
2291         self.assertTrue(p.isEqual(p2,1e-14)[0])
2292         self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2293         self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2294         self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2295         self.assertEqual(p.getParamsNames(),('A','B'))
2296         ptsr=MEDFileParameterMultiTS(fname,"B")
2297         self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2298         ptsr=MEDFileParameterMultiTS(fname)
2299         self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2300         p1tsr=MEDFileParameterDouble1TS(fname)
2301         self.assertEqual(p1tsr.getName(),"A")
2302         self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2303         p1tsr=MEDFileParameterDouble1TS(fname,"B")
2304         self.assertEqual(p1tsr.getName(),"B")
2305         self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2306         p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2307         self.assertEqual(p1tsr.getName(),"B")
2308         self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2309         data2=MEDFileData(fname)
2310         self.assertEqual(2,data2.getNumberOfParams())
2311         self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2312         pass
2313
2314     def testNamesOnCellAndNodesInMeshes1(self):
2315         fname="Pyfile58.med"
2316         fname2="Pyfile59.med"
2317         m=MEDLoaderDataForTest.build3DSurfMesh_1()
2318         m1=m.buildDescendingConnectivity()[0]
2319         m1.sortCellsInMEDFileFrmt()
2320         #
2321         mm=MEDFileUMesh()
2322         mm.setMeshAtLevel(0,m)
2323         mm.setMeshAtLevel(-1,m1)
2324         namesCellL0=DataArrayAsciiChar(6,16)
2325         namesCellL0[:] = ["CellL0#%.3d      " % (i) for i in range(6)]
2326         mm.setNameFieldAtLevel(0,namesCellL0)
2327         namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.subArray(2)])
2328         namesCellL1[:] = ["CellLM1#%.3d     " % (i) for i in range(16)]
2329         mm.setNameFieldAtLevel(-1,namesCellL1)
2330         namesNodes=namesCellL1.subArray(4,16)
2331         namesNodes[:] = ["Node#%.3d        " % (i) for i in range(12)]
2332         mm.setNameFieldAtLevel(1,namesNodes)
2333         mm.write(fname,2)
2334         #
2335         mmr=MEDFileMesh.New(fname)
2336         self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d      " % (i) for i in range(6)])))
2337         self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d     " % (i) for i in range(16)])))
2338         self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d        " % (i) for i in range(12)])))
2339         self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2340         mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2341         self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2342         mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2343         self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2344         mmCpy=mm.deepCopy()
2345         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2346         # remove names on nodes
2347         mmCpy.setNameFieldAtLevel(1,None)
2348         self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2349         mm.setNameFieldAtLevel(1,None)
2350         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2351         mm.setNameFieldAtLevel(-1,None)
2352         mm.write(fname,2)
2353         mmr=MEDFileMesh.New(fname)
2354         self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2355         self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d      " % (i) for i in range(6)])))
2356         self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2357         #
2358         c=MEDCouplingCMesh()
2359         arr=DataArrayDouble([0.,1.1,2.3])
2360         c.setCoords(arr,arr)
2361         c.setName("cmesh")
2362         cc=MEDFileCMesh()
2363         cc.setMesh(c)
2364         cc.setNameFieldAtLevel(0, DataArrayAsciiChar(["Cell#%.3d        " % (i) for i in range(4)]))
2365         cc.setNameFieldAtLevel(1, DataArrayAsciiChar(["Node#%.3d        " % (i) for i in range(9)]))
2366         cc.write(fname2,2)
2367         ccr=MEDFileMesh.New(fname2)
2368         self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d        " % (i) for i in range(4)])))
2369         self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d        " % (i) for i in range(9)])))
2370         self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2371         ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2372         self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2373         ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2374         self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2375         ccCpy=cc.deepCopy()
2376         self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2377         pass
2378
2379     def testToExportInExamples1(self):
2380         m=MEDCouplingCMesh()
2381         arr=DataArrayDouble([0.,1.,2.,3.,4.])
2382         m.setCoords(arr,arr)
2383         m=m.buildUnstructured() ; m.setName("mesh")
2384         grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2385         grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2386         m2=m.computeSkin()
2387         mm=MEDFileUMesh()
2388         mm.setMeshAtLevel(0,m)
2389         mm.setMeshAtLevel(-1,m2)
2390         mm.setGroupsAtLevel(0,[grp1,grp2])
2391         mm.write("example.med",2)
2392         #
2393         m0=mm.getMeshAtLevel(0)
2394         m1=mm.getMeshAtLevel(-1)
2395         grp1=mm.getGroupArr(0,"grp1")
2396         grp2=mm.getGroupArr(0,"grp2")
2397         grps=[grp1,grp2]
2398         whichGrp=DataArrayInt(m0.getNumberOfCells())
2399         whichGrp.fillWithValue(-1)
2400         for grpId,grp in enumerate(grps):
2401             whichGrp[grp]=grpId
2402             pass
2403         a,b,bI,c,cI=m0.buildDescendingConnectivity()
2404         e,f=a.areCellsIncludedIn(m1,2)
2405         self.assertTrue(e)
2406         c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2407         self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2408         c2.transformWithIndArr(whichGrp)
2409         splitOfM1=len(grps)*[None]
2410         for grpId,grp in enumerate(grps):
2411             tmp=c2.findIdsEqual(grpId)
2412             splitOfM1[grpId]=tmp
2413             pass
2414         splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2415         splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2416         pass
2417
2418     def testBugCorrection1(self):
2419         fs=MEDFileFields()
2420         fs.resize(3)
2421         self.assertEqual(fs[0],None)
2422         self.assertEqual(3,len(fs))
2423         pass
2424
2425     def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2426         f1Name="Pyfile60.med"
2427         f2Name="Pyfile61.med"
2428         d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2429         d1.write(f1Name,2)
2430         d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2431         d2.write(f2Name,2)
2432         # reading and compare
2433         d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2434         for mn in d1.getMeshes().getMeshesNames():
2435             m1=d1.getMeshes()[mn]
2436             m2=d2.getMeshes()[mn]
2437             for lev in m1.getNonEmptyLevels():
2438                 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2439                 for grpName in grpsNames:
2440                     self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2441                     pass
2442                 pass
2443             pass
2444         for fieldn in d1.getFields().getFieldsNames():
2445             f1=d1.getFields()[fieldn]
2446             f2=d2.getFields()[fieldn]
2447             for it,order,tim in f1.getTimeSteps():
2448                 f1t=f1[it,order]
2449                 f2t=f2[it,order]
2450                 if len(f1t.getPflsReallyUsed())!=0:
2451                     # profile case
2452                     for lev in f1t.getNonEmptyLevels()[1]:
2453                         arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2454                         arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2455                         self.assertTrue(pfl1.isEqual(pfl2))
2456                         self.assertTrue(arr1.isEqual(arr2,1e-10))
2457                         pass
2458                     pass
2459                 else:
2460                     # no profile case
2461                     for lev in f1t.getNonEmptyLevels()[1]:
2462                         f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2463                         f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2464                         self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2465                         pass
2466                     pass
2467                 pass
2468             pass
2469         pass
2470
2471     def testNonRegBugNormalizeFamIdsMEDFile1(self):
2472         m=MEDCouplingCMesh()
2473         arr=DataArrayDouble([0.,1.,2.,3.,4.])
2474         m.setCoords(arr,arr,arr)
2475         m=m.buildUnstructured()
2476         m2=m.buildDescendingConnectivity()[0]
2477         m.setName("mesh")
2478         g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2479         g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2480         g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2481         g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2482         g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2483         g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2484         mm=MEDFileUMesh()
2485         mm.setMeshAtLevel(0,m)
2486         mm.setGroupsAtLevel(0,[g1,g2])
2487         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2488         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2489         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2490         mm.normalizeFamIdsMEDFile()
2491         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2492         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2493         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2494         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2495         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2496         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2497         for g in mm.getGroupsOnSpecifiedLev(0):
2498             for f in mm.getFamiliesIdsOnGroup(g):
2499                 self.assertTrue(f<0)
2500                 pass
2501             pass
2502         #
2503         mm=MEDFileUMesh()
2504         mm.setMeshAtLevel(0,m)
2505         mm.setMeshAtLevel(-1,m2)
2506         mm.setGroupsAtLevel(0,[g1,g2])
2507         mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2508         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2509         s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2510         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2511         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2512         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2513         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2514         mm.normalizeFamIdsMEDFile()
2515         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2516         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2517         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2518         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2519         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2520         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2521         self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2522         self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2523         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2524         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2525         self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2526         self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2527         for lev in [0,-1]:
2528             for g in mm.getGroupsOnSpecifiedLev(lev):
2529                 for f in mm.getFamiliesIdsOnGroup(g):
2530                     self.assertTrue(f<0)
2531                     pass
2532                 pass
2533             pass
2534          #
2535         mm=MEDFileUMesh()
2536         mm.setMeshAtLevel(0,m)
2537         mm.setMeshAtLevel(-1,m2)
2538         mm.setGroupsAtLevel(0,[g1,g2])
2539         mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2540         mm.setGroupsAtLevel(1,[g1Node,g2Node])
2541         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2542         s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2543         s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2544         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2545         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2546         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2547         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2548         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2549         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2550         mm.normalizeFamIdsMEDFile()
2551         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2552         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2553         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2554         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2555         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2556         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2557         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2558         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2559         self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2560         self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2561         self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2562         self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2563         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2564         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2565         self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2566         self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2567         self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2568         self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2569         for lev in [0,-1]:
2570             for g in mm.getGroupsOnSpecifiedLev(lev):
2571                 for f in mm.getFamiliesIdsOnGroup(g):
2572                     self.assertTrue(f<0)
2573                     pass
2574                 pass
2575             pass
2576         for g in mm.getGroupsOnSpecifiedLev(1):
2577             for f in mm.getFamiliesIdsOnGroup(g):
2578                 self.assertTrue(f>0)
2579                 pass
2580             pass
2581         pass
2582     
2583     def testNonRegressionMantis22212ChangeGrpName(self):
2584         fileName="Pyfile62.med"
2585         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2586         m=MEDFileUMesh.New()
2587         m.setCoords(m2.getCoords())
2588         m.setMeshAtLevel(0,m2)
2589         m.setMeshAtLevel(-1,m1)
2590         m.setMeshAtLevel(-2,m0)
2591         m.setFamilyFieldArr(0,f2)
2592         m.setFamilyFieldArr(-1,f1)
2593         m.setFamilyFieldArr(-2,f0)
2594         m.setFamilyFieldArr(1,p)
2595         nbOfFams=len(fns)
2596         for i in range(nbOfFams):
2597             m.addFamily(fns[i],fids[i])
2598             pass
2599         nbOfGrps=len(grpns)
2600         for i in range(nbOfGrps):
2601             m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2602             pass
2603         m.setName(m2.getName())
2604         m.setDescription(m2.getDescription())
2605         m.write(fileName,2)
2606         #
2607         mm0=MEDFileMesh.New(fileName)
2608         mm1=MEDFileMesh.New(fileName)
2609         groupNamesIni=GetMeshGroupsNames(fileName,"ma")
2610         for name in groupNamesIni:
2611             mm1.changeGroupName(name,name+'N')
2612             pass
2613         mm1.write(fileName,2)
2614         del mm1
2615         #
2616         mm2=MEDFileMesh.New(fileName)
2617         for name in groupNamesIni:
2618             for lev in mm0.getGrpNonEmptyLevelsExt(name):
2619                 arr0=mm0.getGroupArr(lev,name)
2620                 arr2=mm2.getGroupArr(lev,name+'N')
2621                 arr0.setName(name+'N')
2622                 self.assertTrue(arr0.isEqual(arr2))
2623                 pass
2624             pass
2625         pass
2626
2627     def testInt32InMEDFileFieldStar1(self):
2628         fname="Pyfile63.med"
2629         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2630         f1=f1.convertToIntField()
2631         m1=f1.getMesh()
2632         mm1=MEDFileUMesh.New()
2633         mm1.setCoords(m1.getCoords())
2634         mm1.setMeshAtLevel(0,m1)
2635         mm1.setName(m1.getName())
2636         mm1.write(fname,2)
2637         ff1=MEDFileIntField1TS()
2638         ff1.setFieldNoProfileSBT(f1)
2639         a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2640         self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2641         self.assertTrue(a.isEqual(f1,1e-12,0))
2642         ff1.write(fname,0)
2643         a,b=ff1.getUndergroundDataArrayExt()
2644         self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
2645         self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
2646         ff2=MEDFileAnyTypeField1TS.New(fname)
2647         self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2648         self.assertEqual(ff2.getTime(),[0,1,2.0])
2649         self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2650         a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2651         self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2652         self.assertTrue(a.isEqual(f1,1e-12,0))
2653         ff2.setTime(1,2,3.)
2654         c=ff2.getUndergroundDataArray() ; c*=2
2655         ff2.write(fname,0) # 2 time steps in
2656         ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2657         self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2658         self.assertEqual(len(ffs1),2)
2659         self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2660         a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2661         self.assertTrue(a.isEqual(f1,1e-12,0))
2662         a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
2663         self.assertTrue(a.isEqual(f1,1e-12,0))
2664         it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2665         a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2666         self.assertTrue(a.getArray().isEqual(2*f1.getArray()))
2667         f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
2668         self.assertTrue(a.isEqual(f1,1e-12,0)) ; f1.getArray()[:]/=2
2669         bc=DataArrayInt(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2670         for it in ffs1:
2671             a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2672             bc+=a.getArray()
2673             pass
2674         self.assertTrue(bc.isEqual(3*f1.getArray()))
2675         nf1=MEDCouplingFieldInt(ON_NODES)
2676         nf1.setTime(9.,10,-1)
2677         nf1.setMesh(f1.getMesh())
2678         narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
2679         nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
2680         nff1=MEDFileIntField1TS.New()
2681         nff1.setFieldNoProfileSBT(nf1)
2682         self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2683         self.assertEqual(nff1.getTime(),[10,-1,9.0])
2684         nff1.write(fname,0)
2685         #
2686         nf2=MEDCouplingFieldInt(ON_NODES)
2687         nf2.setTime(19.,20,-11)
2688         nf2.setMesh(f1.getMesh())
2689         narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10  ; narr2[:,1]=3*narr2[:,0]
2690         nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
2691         nff2=MEDFileIntField1TS.New()
2692         npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
2693         nff2.setFieldProfile(nf2,mm1,0,npfl)
2694         nff2.getFieldWithProfile(ON_NODES,0,mm1)
2695         a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2696         self.assertTrue(b.isEqual(npfl))
2697         self.assertTrue(a.isEqual(narr2))
2698         nff2.write(fname,0)
2699         nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
2700         a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2701         self.assertTrue(b.isEqual(npfl))
2702         self.assertTrue(a.isEqual(narr2))
2703         #
2704         nf3=MEDCouplingFieldDouble(ON_NODES)
2705         nf3.setName("VectorFieldOnNodesDouble")
2706         nf3.setTime(29.,30,-21)
2707         nf3.setMesh(f1.getMesh())
2708         nf3.setArray(f1.getMesh().getCoords())
2709         nff3=MEDFileField1TS.New()
2710         nff3.setFieldNoProfileSBT(nf3)
2711         nff3.write(fname,0)
2712         fs=MEDFileFields(fname)
2713         self.assertEqual(len(fs),4)
2714         ffs=[it for it in fs]
2715         self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
2716         self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
2717         self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
2718         self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
2719         #
2720         self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray()))
2721         self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray()))
2722         self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
2723         self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
2724         self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2725         #
2726         nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
2727         self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2728         self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
2729         self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
2730         MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
2731         self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
2732         MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
2733         self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
2734         #
2735         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
2736         self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2737         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
2738         self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2739         pass
2740
2741     def testMEDFileFields1(self):
2742         fname="Pyfile64.med"
2743         f1=MEDCouplingFieldDouble(ON_NODES)
2744         f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
2745         c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
2746         mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
2747         f1.setMesh(m)
2748         arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=list(range(12)) ; arr[:,1]=2*arr[:,0]
2749         f1.setArray(arr)
2750         f1.setName("Field1")
2751         ff1=MEDFileField1TS.New()
2752         ff1.setFieldNoProfileSBT(f1)
2753         self.assertEqual(ff1.getDtUnit(),"us")
2754         ff1.write(fname,0)
2755         f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2756         f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2757         #
2758         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2759         ff1s=MEDFileFieldMultiTS(fname,"Field1")
2760         ff1s.setName("Field2")
2761         ff1s.write(fname,0)
2762         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2763         f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2764         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
2765         self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
2766         self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
2767         f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2768         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
2769         self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
2770         pass
2771
2772     # Multi time steps and multi fields management without Globals (profiles, locs) aspects
2773     def testMEDFileFields2(self):
2774         fname="Pyfile65.med"
2775         # to check that all is initialize 
2776         MEDFileField1TS().__str__()
2777         MEDFileFieldMultiTS().__str__()
2778         # building a mesh containing 4 tri3 + 5 quad4
2779         tri=MEDCouplingUMesh("tri",2)
2780         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2781         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2782         tris = [tri.deepCopy() for i in range(4)]
2783         for i,elt in enumerate(tris): elt.translate([i,0])
2784         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2785         quad=MEDCouplingUMesh("quad",2)
2786         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2787         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2788         quads = [quad.deepCopy() for i in range(5)]
2789         for i,elt in enumerate(quads): elt.translate([5+i,0])
2790         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2791         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2792         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2793         #
2794         fmts0_0=MEDFileFieldMultiTS()
2795         fmts0_1=MEDFileFieldMultiTS()
2796         # time steps
2797         for i in range(10):
2798             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2799             d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2800             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2801             f.setTime(float(i+1)+0.1,i+1,-i-1)
2802             fmts0_0.appendFieldNoProfileSBT(f)
2803             f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
2804             self.assertEqual(fmts0_1.getName(),name1)
2805             self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2806             self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2807             if i>1:
2808                 # components names have been modified to generate errors
2809                 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
2810                 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
2811                 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
2812                 f1ts.setInfo(['aa [bb]','eee [dd]'])
2813                 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
2814                 pass
2815             # add a mismatch of nb of compos
2816             pass
2817         fmts0_2=fmts0_0.deepCopy()
2818         fmts0_3=fmts0_0.deepCopy()
2819         fmts0_4=fmts0_0.deepCopy()
2820         fmts0_5=fmts0_0.shallowCpy()
2821         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)
2822         del fmts0_2[::2]
2823         self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
2824         del fmts0_3[[1.1,(6,-6),9]]
2825         self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
2826         fmts0_6=fmts0_4[[1.1,(6,-6),8]]
2827         self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
2828         self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
2829         fmts0_7=fmts0_4[::-3]
2830         self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
2831         self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
2832         #
2833         fs0=MEDFileFields()
2834         fs0.pushField(fmts0_0)
2835         fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2836         fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2837         fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2838         self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
2839         fs0.write(fname,2)
2840         fs0=MEDFileFields(fname)
2841         self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
2842         fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
2843         self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2844         del fs1[["2ndField",3]]
2845         self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2846         fs2=fs0[[0,"4thField"]]
2847         self.assertTrue(isinstance(fs2,MEDFileFields))
2848         self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
2849         #
2850         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
2851         pass
2852
2853     # Multi time steps and multi fields management with Globals (profiles, locs) aspects
2854     def testMEDFileFields3(self):
2855         fname="Pyfile66.med"
2856         # building a mesh containing 4 tri3 + 5 quad4
2857         tri=MEDCouplingUMesh("tri",2)
2858         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2859         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2860         tris = [tri.deepCopy() for i in range(4)]
2861         for i,elt in enumerate(tris): elt.translate([i,0])
2862         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2863         quad=MEDCouplingUMesh("quad",2)
2864         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2865         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2866         quads = [quad.deepCopy() for i in range(5)]
2867         for i,elt in enumerate(quads): elt.translate([5+i,0])
2868         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2869         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2870         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2871         #
2872         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2873         #
2874         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2875         pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2876         fmts0_0=MEDFileFieldMultiTS()
2877         fmts0_1=MEDFileFieldMultiTS()
2878         # time steps
2879         for i in range(10):
2880             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2881             d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2882             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2883             f.setTime(float(i+1)+0.1,i+1,-i-1)
2884             fmts0_0.appendFieldProfile(f,mm,0,pfl)
2885             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2886             self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2887             self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2888             pass
2889         #
2890         self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
2891         self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
2892         fmts0_0.zipPflsNames()
2893         self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
2894         self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
2895         fmts0_2=fmts0_0.deepCopy()
2896         fmts0_3=fmts0_0.deepCopy()
2897         fmts0_4=fmts0_0.deepCopy()
2898         fs0=MEDFileFields()
2899         fs0.pushField(fmts0_0)
2900         fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2901         fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2902         fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2903         self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
2904         #
2905         fmts0_5=MEDFileFieldMultiTS()
2906         for i in range(7):
2907             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2908             d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2909             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2910             f.setTime(float(i+1)+0.1,i+1,-i-1)
2911             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
2912             pass
2913         fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
2914         self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
2915         fs0.checkGlobsCoherency()
2916         fs0.write(fname,0)
2917         pass
2918     
2919     def testSplitComponents1(self):
2920         fname="Pyfile67.med"
2921         # building a mesh containing 4 tri3 + 5 quad4
2922         tri=MEDCouplingUMesh("tri",2)
2923         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2924         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2925         tris = [tri.deepCopy() for i in range(4)]
2926         for i,elt in enumerate(tris): elt.translate([i,0])
2927         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2928         quad=MEDCouplingUMesh("quad",2)
2929         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2930         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2931         quads = [quad.deepCopy() for i in range(5)]
2932         for i,elt in enumerate(quads): elt.translate([5+i,0])
2933         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2934         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2935         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2936         #
2937         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2938         #
2939         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2940         pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2941         fs=MEDFileFields()
2942         fmts0_1=MEDFileFieldMultiTS()
2943         # time steps
2944         infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
2945         for i in range(10):
2946             name1="1stField"
2947             d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2948             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2949             f.setTime(float(i+1)+0.1,i+1,-i-1)
2950             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2951             self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
2952             pass
2953         fs.pushField(fmts0_1)
2954         self.assertEqual(1,len(fs))
2955         l=fmts0_1.splitComponents()
2956         self.assertEqual(3,len(l))
2957         for elt in l: self.assertEqual(10,len(elt))
2958         for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
2959         for elt in l:
2960             elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
2961             pass
2962         fs.pushFields(l)
2963         self.assertEqual(4,len(fs))
2964         for elt in fs: self.assertEqual(10,len(elt))
2965         self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
2966         self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2967         #
2968         fs.write(fname,0) ; del fs
2969         #
2970         fs1=MEDFileFields(fname)
2971         self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
2972         self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2973         self.assertEqual(4,len(fs1))
2974         for i in range(10):
2975             for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
2976                 f1ts=fs1[fieldName][i]
2977                 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2978                 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
2979                 self.assertTrue(d.isEqual(f.getArray(),1e-13))
2980                 pass
2981             f1ts=fs1["1stField"][i]
2982             f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2983             d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2984             self.assertTrue(d.isEqual(f.getArray(),1e-13))
2985             pass
2986         pass
2987
2988     def testMEDFileFieldConvertTo1(self):
2989         fname="Pyfile68.med"
2990         # building a mesh containing 4 tri3 + 5 quad4
2991         tri=MEDCouplingUMesh("tri",2)
2992         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2993         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2994         tris = [tri.deepCopy() for i in range(4)]
2995         for i,elt in enumerate(tris): elt.translate([i,0])
2996         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2997         quad=MEDCouplingUMesh("quad",2)
2998         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2999         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3000         quads = [quad.deepCopy() for i in range(5)]
3001         for i,elt in enumerate(quads): elt.translate([5+i,0])
3002         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3003         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3004         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3005         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3006         #
3007         ff0=MEDFileField1TS()
3008         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")
3009         f0.checkConsistencyLight()
3010         ff0.setFieldNoProfileSBT(f0)
3011         #
3012         fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
3013         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3014         #
3015         ff0i=ff0.convertToInt()
3016         self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3017         self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3018         #
3019         ff1=ff0i.convertToDouble()
3020         self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3021         self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3022         # With profiles
3023         del arr,f0,ff0,ff1,ff0i,fspExp
3024         ff0=MEDFileField1TS()
3025         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")
3026         f0.checkConsistencyLight()
3027         pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
3028         ff0.setFieldProfile(f0,mm,0,pfl)
3029         fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
3030         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3031         #
3032         ff0i=ff0.convertToInt()
3033         self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
3034         self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3035         self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3036         #
3037         ff1=ff0i.convertToDouble()
3038         self.assertTrue(isinstance(ff1,MEDFileField1TS))
3039         self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3040         self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3041         ## MultiTimeSteps
3042         ff0=MEDFileFieldMultiTS()
3043         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)
3044         f0.checkConsistencyLight()
3045         ff0.appendFieldProfile(f0,mm,0,pfl)
3046         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)
3047         f0.checkConsistencyLight()
3048         ff0.appendFieldProfile(f0,mm,0,pfl)
3049         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)
3050         f0.checkConsistencyLight()
3051         ff0.appendFieldProfile(f0,mm,0,pfl)
3052         ff1=ff0.convertToInt()
3053         self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3054         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3055         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
3056             self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3057             arr=ff1.getUndergroundDataArray(dt,it)
3058             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
3059             pass
3060         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3061         #
3062         mm.write(fname,2)
3063         ff1.write(fname,0)
3064         #
3065         ff1=ff1.convertToDouble()
3066         self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
3067         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3068         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
3069             self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3070             arr=ff1.getUndergroundDataArray(dt,it)
3071             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
3072             pass
3073         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3074         #
3075         ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
3076         self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3077         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3078         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
3079             self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
3080             arr=ff1.getUndergroundDataArray(dt,it)
3081             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
3082             pass
3083         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
3084         pass
3085
3086     def testMEDFileFieldPartialLoading(self):
3087         fname="Pyfile69.med"
3088         #
3089         a=DataArrayInt() ; aa=a.getHeapMemorySize()
3090         a.alloc(0,1)
3091         strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
3092         # building a mesh containing 30 tri3 + 40 quad4
3093         tri=MEDCouplingUMesh("tri",2)
3094         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3095         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3096         tris = [tri.deepCopy() for i in range(30)]
3097         for i,elt in enumerate(tris): elt.translate([i,0])
3098         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3099         quad=MEDCouplingUMesh("quad",2)
3100         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3101         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3102         quads = [quad.deepCopy() for i in range(40)]
3103         for i,elt in enumerate(quads): elt.translate([40+i,0])
3104         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3105         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3106         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3107         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3108         #
3109         ff0=MEDFileField1TS()
3110         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")
3111         f0.checkConsistencyLight()
3112         ff0.setFieldNoProfileSBT(f0)
3113         ff0.write(fname,0)
3114         #
3115         fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
3116         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3117         # With profiles
3118         ff0=MEDFileField1TS()
3119         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")
3120         f0.checkConsistencyLight()
3121         pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
3122         ff0.setFieldProfile(f0,mm,0,pfl)
3123         fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
3124         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3125         ff0.write(fname,0)
3126         #
3127         ff0=MEDFileField1TS(fname,False)
3128         self.assertEqual(ff0.getName(),"FieldCell")
3129         self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
3130         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
3131         heap_memory_ref=ff0.getHeapMemorySize()
3132         self.assertIn(heap_memory_ref, list(range(182, 540 + 2 * strMulFac)))
3133         ff0.loadArrays() ##
3134         arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
3135         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3136         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
3137         #
3138         ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
3139         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
3140         heap_memory_ref=ff0.getHeapMemorySize()
3141         self.assertIn(heap_memory_ref, list(range(350, 600 + 6 * strMulFac)))
3142         ff0.loadArrays() ##
3143         arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
3144         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3145         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3146         ff0.loadArrays() ##
3147         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3148         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3149         ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3150         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3151         ff0.loadArrays() ##
3152         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3153         ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3154         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3155         ff0.loadArraysIfNecessary() ##
3156         self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
3157         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3158         heap_memory_ref=ff0.getHeapMemorySize()
3159         self.assertIn(heap_memory_ref, list(range(1100, 1400 + 2 * strMulFac)))
3160         ff0.unloadArrays()
3161         hmd=ff0.getHeapMemorySize()-heap_memory_ref
3162         self.assertEqual(hmd,-800) # -50*8*2
3163         ff0.loadArrays() ##
3164         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
3165         #
3166         ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
3167         heap_memory_ref=ff0.getHeapMemorySize()
3168         self.assertIn(heap_memory_ref, list(range(299, 620 + 6 * strMulFac)))
3169         ff0.loadArrays() ##
3170         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3171         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3172         #
3173         fieldName="FieldCellMultiTS"
3174         ff0=MEDFileFieldMultiTS()
3175         for t in range(20):
3176             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)
3177             f0.setTime(float(t)+0.1,t,100+t)
3178             f0.checkConsistencyLight()
3179             ff0.appendFieldNoProfileSBT(f0)
3180             pass
3181         ff0.write(fname,0)
3182         #
3183         ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
3184         heap_memory_ref=ff0.getHeapMemorySize()
3185         self.assertIn(heap_memory_ref, list(range(5536, 9212 + (80 + 26 + 1) * strMulFac)))
3186         ff0.loadArrays()
3187         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
3188         del ff0
3189         #
3190         ffs=MEDFileFields(fname,False)
3191         heap_memory_ref=ffs.getHeapMemorySize()
3192         self.assertIn(heap_memory_ref, list(range(5335, 10031 + (80 + 50 + len(ffs)) * strMulFac)))
3193         ffs.loadArrays()
3194         self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
3195         pass
3196
3197     def testMEDFileMeshReadSelector1(self):
3198         mrs=MEDFileMeshReadSelector()
3199         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3200         mrs.__str__() ; mrs.__repr__()
3201         #
3202         mrs=MEDFileMeshReadSelector(0)
3203         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())
3204         mrs=MEDFileMeshReadSelector(1)
3205         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3206         mrs=MEDFileMeshReadSelector(2)
3207         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3208         mrs=MEDFileMeshReadSelector(3)
3209         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3210         mrs=MEDFileMeshReadSelector(4)
3211         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3212         mrs=MEDFileMeshReadSelector(5)
3213         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3214         mrs=MEDFileMeshReadSelector(6)
3215         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3216         mrs=MEDFileMeshReadSelector(7)
3217         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3218         mrs=MEDFileMeshReadSelector(8)
3219         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3220         mrs=MEDFileMeshReadSelector(9)
3221         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3222         mrs=MEDFileMeshReadSelector(10)
3223         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3224         mrs=MEDFileMeshReadSelector(11)
3225         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3226         mrs=MEDFileMeshReadSelector(12)
3227         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3228         mrs=MEDFileMeshReadSelector(13)
3229         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3230         mrs=MEDFileMeshReadSelector(14)
3231         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3232         mrs=MEDFileMeshReadSelector(15)
3233         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3234         mrs=MEDFileMeshReadSelector(16)
3235         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3236         mrs=MEDFileMeshReadSelector(17)
3237         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3238         mrs=MEDFileMeshReadSelector(18)
3239         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3240         mrs=MEDFileMeshReadSelector(19)
3241         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3242         mrs=MEDFileMeshReadSelector(20)
3243         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3244         mrs=MEDFileMeshReadSelector(21)
3245         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3246         mrs=MEDFileMeshReadSelector(22)
3247         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3248         mrs=MEDFileMeshReadSelector(23)
3249         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3250         mrs=MEDFileMeshReadSelector(24)
3251         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3252         mrs=MEDFileMeshReadSelector(25)
3253         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3254         mrs=MEDFileMeshReadSelector(26)
3255         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3256         mrs=MEDFileMeshReadSelector(27)
3257         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3258         mrs=MEDFileMeshReadSelector(28)
3259         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3260         mrs=MEDFileMeshReadSelector(29)
3261         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3262         mrs=MEDFileMeshReadSelector(30)
3263         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3264         mrs=MEDFileMeshReadSelector(31)
3265         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3266         mrs=MEDFileMeshReadSelector(32)
3267         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3268         mrs=MEDFileMeshReadSelector(33)
3269         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3270         mrs=MEDFileMeshReadSelector(34)
3271         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3272         mrs=MEDFileMeshReadSelector(35)
3273         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3274         mrs=MEDFileMeshReadSelector(36)
3275         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3276         mrs=MEDFileMeshReadSelector(37)
3277         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3278         mrs=MEDFileMeshReadSelector(38)
3279         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3280         mrs=MEDFileMeshReadSelector(39)
3281         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3282         mrs=MEDFileMeshReadSelector(40)
3283         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3284         mrs=MEDFileMeshReadSelector(41)
3285         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3286         mrs=MEDFileMeshReadSelector(42)
3287         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3288         mrs=MEDFileMeshReadSelector(43)
3289         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3290         mrs=MEDFileMeshReadSelector(44)
3291         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3292         mrs=MEDFileMeshReadSelector(45)
3293         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3294         mrs=MEDFileMeshReadSelector(46)
3295         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3296         mrs=MEDFileMeshReadSelector(47)
3297         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3298         mrs=MEDFileMeshReadSelector(48)
3299         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3300         mrs=MEDFileMeshReadSelector(49)
3301         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3302         mrs=MEDFileMeshReadSelector(50)
3303         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3304         mrs=MEDFileMeshReadSelector(51)
3305         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3306         mrs=MEDFileMeshReadSelector(52)
3307         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3308         mrs=MEDFileMeshReadSelector(53)
3309         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3310         mrs=MEDFileMeshReadSelector(54)
3311         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3312         mrs=MEDFileMeshReadSelector(55)
3313         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3314         mrs=MEDFileMeshReadSelector(56)
3315         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3316         mrs=MEDFileMeshReadSelector(57)
3317         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3318         mrs=MEDFileMeshReadSelector(58)
3319         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3320         mrs=MEDFileMeshReadSelector(59)
3321         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3322         mrs=MEDFileMeshReadSelector(60)
3323         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3324         mrs=MEDFileMeshReadSelector(61)
3325         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3326         mrs=MEDFileMeshReadSelector(62)
3327         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3328         mrs=MEDFileMeshReadSelector(63)
3329         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3330         #
3331         mrs=MEDFileMeshReadSelector(63)
3332         mrs.setCellFamilyFieldReading(False)
3333         self.assertEqual(mrs.getCode(),62)
3334         mrs.setCellFamilyFieldReading(True)
3335         self.assertEqual(mrs.getCode(),63)
3336         mrs.setNodeFamilyFieldReading(False)
3337         self.assertEqual(mrs.getCode(),61)
3338         mrs.setNodeFamilyFieldReading(True)
3339         self.assertEqual(mrs.getCode(),63)
3340         mrs.setCellNameFieldReading(False)
3341         self.assertEqual(mrs.getCode(),59)
3342         mrs.setCellNameFieldReading(True)
3343         self.assertEqual(mrs.getCode(),63)
3344         mrs.setNodeNameFieldReading(False)
3345         self.assertEqual(mrs.getCode(),55)
3346         mrs.setNodeNameFieldReading(True)
3347         self.assertEqual(mrs.getCode(),63)
3348         mrs.setCellNumFieldReading(False)
3349         self.assertEqual(mrs.getCode(),47)
3350         mrs.setCellNumFieldReading(True)
3351         self.assertEqual(mrs.getCode(),63)
3352         mrs.setNodeNumFieldReading(False)
3353         self.assertEqual(mrs.getCode(),31)
3354         mrs.setNodeNumFieldReading(True)
3355         self.assertEqual(mrs.getCode(),63)
3356         pass
3357     
3358     def testPartialReadOfMeshes(self):
3359         fname="Pyfile70.med"
3360         # building a mesh containing 4 tri3 + 5 quad4
3361         tri=MEDCouplingUMesh("tri",2)
3362         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3363         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3364         tris = [tri.deepCopy() for i in range(4)]
3365         for i,elt in enumerate(tris): elt.translate([i,0])
3366         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3367         quad=MEDCouplingUMesh("quad",2)
3368         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3369         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3370         quads = [quad.deepCopy() for i in range(5)]
3371         for i,elt in enumerate(quads): elt.translate([5+i,0])
3372         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3373         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3374         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3375         m1=m.buildDescendingConnectivity()[0]
3376         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3377         #
3378         grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3379         grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3380         mm.setGroupsAtLevel(0,[grp0,grp1])
3381         grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3382         grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3383         mm.setGroupsAtLevel(-1,[grp2,grp3])
3384         grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3385         grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3386         mm.setGroupsAtLevel(1,[grp4,grp5])
3387         mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3388         mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3389         mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3390         #
3391         mm.write(fname,2)
3392         ##
3393         mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3394         b4_ref_heap_mem=mm.getHeapMemorySize()
3395         mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
3396         mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
3397         ref_heap_mem=mm.getHeapMemorySize()
3398         # check the gain of memory using 1GTUMesh instead of UMesh
3399         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
3400         #
3401         mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3402         self.assertEqual(len(mm.getGroupsNames()),0)
3403         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3404         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3405         self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3406         self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3407         self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3408         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3409         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3410         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3411         delta1=ref_heap_mem-mm.getHeapMemorySize()
3412         self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3413         #
3414         mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3415         self.assertEqual(len(mm.getGroupsNames()),6)
3416         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3417         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3418         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3419         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3420         self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3421         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3422         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3423         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3424         delta2=ref_heap_mem-mm.getHeapMemorySize()
3425         self.assertTrue(delta2<delta1)
3426         self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3427         #
3428         mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3429         self.assertEqual(len(mm.getGroupsNames()),6)
3430         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3431         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3432         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3433         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3434         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3435         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3436         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3437         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3438         delta3=ref_heap_mem-mm.getHeapMemorySize()
3439         self.assertTrue(delta3<delta2)
3440         self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3441         #
3442         mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3443         self.assertEqual(len(mm.getGroupsNames()),6)
3444         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3445         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3446         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3447         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3448         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3449         self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3450         self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3451         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3452         delta4=ref_heap_mem-mm.getHeapMemorySize()
3453         self.assertTrue(delta4<delta3)
3454         self.assertTrue(delta4>=32*4*2)
3455         #
3456         mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3457         self.assertEqual(len(mm.getGroupsNames()),6)
3458         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3459         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3460         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3461         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3462         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3463         self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3464         self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3465         self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3466         delta5=ref_heap_mem-mm.getHeapMemorySize()
3467         self.assertTrue(delta5<delta4)
3468         self.assertEqual(delta5,0)
3469         pass
3470
3471     # this test checks that setFieldProfile perform a check of the array length
3472     # compared to the profile length. This test also checks that mesh attribute of field
3473     # is not used by setFieldProfile (because across this test mesh is equal to None)
3474     def testCheckCompatibilityPfl1(self):
3475         # building a mesh containing 4 tri3 + 5 quad4
3476         tri=MEDCouplingUMesh("tri",2)
3477         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3478         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3479         tris = [tri.deepCopy() for i in range(4)]
3480         for i,elt in enumerate(tris): elt.translate([i,0])
3481         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3482         quad=MEDCouplingUMesh("quad",2)
3483         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3484         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3485         quads = [quad.deepCopy() for i in range(5)]
3486         for i,elt in enumerate(quads): elt.translate([5+i,0])
3487         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3488         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3489         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3490         m1=m.buildDescendingConnectivity()[0]
3491         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3492         #
3493         f1ts=MEDFileField1TS()
3494         f=MEDCouplingFieldDouble(ON_NODES)
3495         vals=DataArrayDouble(7) ; vals.iota(1000)
3496         f.setArray(vals)
3497         f.setName("anonymous") # f has no mesh it is not a bug
3498         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3499         f1ts.setFieldProfile(f,mm,0,pfl)
3500         #
3501         f1ts=MEDFileField1TS()
3502         f=MEDCouplingFieldDouble(ON_NODES)
3503         vals=DataArrayDouble(8) ; vals.iota(1000)
3504         f.setArray(vals)
3505         f.setName("anonymous") # f has no mesh it is not a bug
3506         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3507         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3508         #
3509         f1ts=MEDFileField1TS()
3510         f=MEDCouplingFieldDouble(ON_CELLS)
3511         vals=DataArrayDouble(7) ; vals.iota(1000)
3512         f.setArray(vals)
3513         f.setName("anonymous") # f has no mesh it is not a bug
3514         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3515         f1ts.setFieldProfile(f,mm,0,pfl)
3516         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3517         #
3518         f1ts=MEDFileField1TS()
3519         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3520         vals=DataArrayDouble(27) ; vals.iota(1000)
3521         f.setArray(vals)
3522         f.setName("anonymous") # f has no mesh it is not a bug
3523         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3524         f.setMesh(m[pfl])
3525         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])
3526         f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3527         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])
3528         f.setMesh(None)
3529         f1ts.setFieldProfile(f,mm,0,pfl)
3530         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3531         vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3532         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3533         vals=DataArrayDouble(27) ; vals.iota(1000)
3534         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3535         #
3536         f1ts=MEDFileField1TS()
3537         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3538         vals=DataArrayDouble(25) ; vals.iota(1000)
3539         f.setArray(vals)
3540         f.setName("anonymous") # f has no mesh it is not a bug
3541         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3542         f1ts.setFieldProfile(f,mm,0,pfl)
3543         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3544         vals2=DataArrayDouble(26) ; vals2.iota(1050)
3545         f.setArray(vals2)
3546         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3547         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3548         #
3549         f1ts=MEDFileField1TS()
3550         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3551         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3552         f.setArray(vals)
3553         f1ts.setFieldProfile(f,mm,0,pfl)
3554         pass
3555     
3556     def testWRMeshWithNoCells(self):
3557         fname="Pyfile71.med"
3558         a=DataArrayDouble(4) ; a.iota()
3559         c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
3560         m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
3561         m=MEDFileUMesh()
3562         m.setMeshAtLevel(0,m00)
3563         m.setRenumFieldArr(1,DataArrayInt(list(range(10,26))))
3564         m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
3565         m.write(fname,2)
3566         del m,a,c,m0,m00
3567         #
3568         m=MEDFileMesh.New(fname)
3569         self.assertEqual((),m.getNonEmptyLevels())
3570         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))
3571         self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(list(range(10,26)))))
3572         self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
3573         pass
3574
3575     def testWRQPolyg1(self):
3576         fname="Pyfile72.med"
3577         m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
3578         m.insertNextCell([0,2,1,3])
3579         m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
3580         #
3581         ms = [m.deepCopy() for i in range(4)]
3582         for i,elt in enumerate(ms):
3583             elt.translate([float(i)*1.5,0.])
3584             pass
3585         m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3586         m0.convertAllToPoly()
3587         #
3588         ms = [m.deepCopy() for i in range(5)]
3589         for i,elt in enumerate(ms):
3590             elt.translate([float(i)*1.5,1.5])
3591             pass
3592         m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3593         m1.convertAllToPoly()
3594         m1.convertLinearCellsToQuadratic()
3595         #
3596         m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
3597         ##
3598         mm=MEDFileUMesh()
3599         mm.setMeshAtLevel(0,m)
3600         grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
3601         grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
3602         grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
3603         mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3604         ##
3605         mm.write(fname,2)
3606         del mm
3607         #
3608         mm_read=MEDFileUMesh(fname)
3609         self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
3610         self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
3611         self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
3612         self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
3613         ##
3614         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
3615         f.setMesh(m)
3616         arr0=DataArrayDouble(9) ; arr0.iota()
3617         arr1=DataArrayDouble(9) ; arr1.iota(100)
3618         arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
3619         f.setArray(arr) ; f.checkConsistencyLight()
3620         f.setTime(5.6,1,2)
3621         ff=MEDFileField1TS()
3622         ff.setFieldNoProfileSBT(f)
3623         ff.write(fname,0)
3624         ##
3625         ff_read=MEDFileField1TS(fname)
3626         f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
3627         self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
3628         pass
3629
3630     def testLoadIfNecessaryOnFromScratchFields0(self):
3631         """
3632         This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
3633         """
3634         fname="Pyfile77.med"
3635         coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
3636         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
3637         m.allocateCells()
3638         m.insertNextCell(NORM_QUAD4,[0,5,3,2])
3639         m.insertNextCell(NORM_QUAD4,[4,2,3,1])
3640         m.finishInsertingCells()
3641         #
3642         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3643         ms=MEDFileMeshes() ; ms.pushMesh(mm)
3644         fs=MEDFileFields()
3645         arrs=4*[None]
3646         #
3647         ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
3648         f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
3649         f0.setTime(1.1,1,1)
3650         f0.setName("myELNOField")
3651         arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
3652         f0.setArray(arrs[0])
3653         ff0.appendFieldNoProfileSBT(f0)
3654         #
3655         f0.setTime(2.2,2,1)
3656         arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
3657         f0.setArray(arrs[1])
3658         ff0.appendFieldNoProfileSBT(f0)
3659         #
3660         f0.setTime(3.3,3,1)
3661         arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
3662         f0.setArray(arrs[2])
3663         ff0.appendFieldNoProfileSBT(f0)
3664         #
3665         f0.setTime(4.4,4,1)
3666         arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
3667         f0.setArray(arrs[3])
3668         ff0.appendFieldNoProfileSBT(f0)
3669         #
3670         for i,arr in enumerate(arrs):
3671             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3672             fs[0][i].loadArraysIfNecessary()
3673             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3674             pass
3675         fs.loadArraysIfNecessary()
3676         for i,arr in enumerate(arrs):
3677             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3678             pass
3679         fs[0].loadArraysIfNecessary()
3680         for i,arr in enumerate(arrs):
3681             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3682             pass
3683         pass
3684     
3685     def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
3686         """ 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.
3687         """
3688         fname="Pyfile78.med"
3689         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)
3690         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3691         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
3692         m0.allocateCells()
3693         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
3694             m0.insertNextCell(NORM_TETRA4,elt)
3695             pass
3696         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
3697             m0.insertNextCell(NORM_PYRA5,elt)
3698             pass
3699         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
3700             m0.insertNextCell(NORM_PENTA6,elt)
3701             pass
3702         m0.checkConsistency()
3703         m1=MEDCouplingUMesh(); m1.setName("mesh")
3704         m1.setMeshDimension(2);
3705         m1.allocateCells(5);
3706         m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3707         m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3708         m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3709         m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3710         m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3711         m1.setCoords(coords);
3712         m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
3713         m3.allocateCells()
3714         m3.insertNextCell(NORM_POINT1,[2])
3715         m3.insertNextCell(NORM_POINT1,[3])
3716         m3.insertNextCell(NORM_POINT1,[4])
3717         m3.insertNextCell(NORM_POINT1,[5])
3718         #
3719         mm=MEDFileUMesh()
3720         mm.setMeshAtLevel(0,m0)
3721         mm.setMeshAtLevel(-1,m1)
3722         mm.setMeshAtLevel(-3,m3)
3723         mm.write(fname,2)
3724         #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
3725         mm=MEDFileMesh.New(fname)
3726         fs=MEDFileFields()
3727         fmts=MEDFileFieldMultiTS()
3728         f1ts=MEDFileField1TS()
3729         for lev in mm.getNonEmptyLevels():
3730             for gt in mm.getGeoTypesAtLevel(lev):
3731                 p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
3732                 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
3733                 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
3734                 f.setArray(arr) ; f.setName("f0")
3735                 f1ts.setFieldNoProfileSBT(f)
3736                 pass
3737             pass
3738         self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
3739         for lev in [0,-1,-3]:
3740             mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
3741             pass
3742         fmts.pushBackTimeStep(f1ts)
3743         fs.pushField(fmts)
3744         fs.write(fname,0)
3745         del fs,fmts,f1ts
3746         #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
3747         fs=MEDFileFields(fname)
3748         self.assertEqual(len(fs),1)
3749         self.assertEqual(len(fs[0]),1)
3750         f1ts=fs[0][0]
3751         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),'','')])])
3752         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))
3753         pass
3754
3755     def testMEDFileUMeshSetName(self):
3756         """ This test is a small but important one for MEDReader in sauv mode. When .sauv file is loaded the conversion is performed in memory and a preparation is done then.
3757         This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
3758         """
3759         fname="Pyfile79.med"
3760         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3761         mm=MEDFileUMesh()
3762         m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
3763         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)
3764         m0.allocateCells(5);
3765         m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3766         m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3767         m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3768         m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3769         m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3770         m0.setCoords(coords);
3771         mm.setMeshAtLevel(0,m0)
3772         m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
3773         m2.allocateCells()
3774         m2.insertNextCell(NORM_POINT1,[2])
3775         m2.insertNextCell(NORM_POINT1,[3])
3776         m2.insertNextCell(NORM_POINT1,[4])
3777         m2.insertNextCell(NORM_POINT1,[5])
3778         mm.setMeshAtLevel(-2,m2)
3779         self.assertEqual(mm.getName(),"")
3780         self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
3781         mm.forceComputationOfParts()
3782         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
3783         mm.setName("abc")
3784         self.assertEqual(mm.getName(),"abc")
3785         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
3786         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
3787         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
3788         self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
3789         pass
3790
3791     def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
3792         fileName="Pyfile80.med"
3793         m=MEDCouplingCMesh() ; m.setName("cmesh")
3794         arr=DataArrayDouble(6) ; arr.iota()
3795         m.setCoords(arr,arr)
3796         nbCells=m.getNumberOfCells()
3797         self.assertEqual(25,nbCells)
3798         f=MEDCouplingFieldDouble(ON_CELLS)
3799         f.setName("FieldOnCell") ; f.setMesh(m)
3800         arr=DataArrayDouble(nbCells) ; arr.iota()
3801         mm=MEDFileCMesh()
3802         mm.setMesh(m)
3803         #
3804         fmts=MEDFileFieldMultiTS()
3805         #
3806         for i in range(nbCells):
3807             t=(float(i)+0.1,i+1,-i-2)
3808             f.setTime(*t)
3809             arr2=DataArrayDouble(nbCells)
3810             perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
3811             arr2[perm]=arr
3812             f.setArray(arr2)
3813             f1ts=MEDFileField1TS()
3814             f1ts.setFieldNoProfileSBT(f)
3815             fmts.pushBackTimeStep(f1ts)
3816             pass
3817         fmts.unloadArraysWithoutDataLoss()
3818         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))
3819         fs=MEDFileFields() ; fs.pushField(fmts)
3820         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))
3821         fs.unloadArraysWithoutDataLoss()
3822         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))
3823         f1ts=fs[0][0]
3824         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))
3825         f1ts.unloadArraysWithoutDataLoss()
3826         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))
3827         mm.write(fileName,2)
3828         fs.write(fileName,0)
3829         del m,fmts,mm,f,f1ts
3830         ##
3831         mm=MEDFileMesh.New(fileName)
3832         fmts=MEDFileFieldMultiTS(fileName)
3833         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))
3834         fmts.unloadArraysWithoutDataLoss()
3835         self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
3836         fmts.loadArraysIfNecessary()
3837         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))
3838         del mm,fmts
3839         fs=MEDFileFields(fileName)
3840         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))
3841         fs.unloadArraysWithoutDataLoss()
3842         self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
3843         fs.loadArraysIfNecessary()
3844         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))
3845         del fs
3846         f1ts=MEDFileField1TS(fileName)
3847         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))
3848         f1ts.unloadArraysWithoutDataLoss()
3849         self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
3850         f1ts.loadArraysIfNecessary()
3851         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))
3852         pass
3853
3854     def testMEDFileUMeshLoadPart1(self):
3855         """ 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
3856         memory of the returned instance.
3857         """
3858         fileName="Pyfile81.med"
3859         arr=DataArrayDouble(6) ; arr.iota()
3860         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3861         m=m.buildUnstructured()
3862         m.setName("Mesh")
3863         m.changeSpaceDimension(3,0.)
3864         infos=["aa [b]","cc [de]","gg [klm]"]
3865         m.getCoords().setInfoOnComponents(infos)
3866         m.checkConsistency()
3867         mm=MEDFileUMesh()
3868         mm.setMeshAtLevel(0,m)
3869         m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh") 
3870         m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
3871         mm.setMeshAtLevel(-1,m1)
3872         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])
3873         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])
3874         namesCellL0=DataArrayAsciiChar(25,16)
3875         namesCellL0[:] = ["Cell#%.3d        " % (i) for i in range(25)]
3876         renumM1=DataArrayInt([3,4,0,2,1])
3877         famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
3878         mm.setRenumFieldArr(0,renum0)
3879         mm.setFamilyFieldArr(0,famField0)
3880         mm.setNameFieldAtLevel(0,namesCellL0)
3881         mm.setRenumFieldArr(-1,renumM1)
3882         mm.setFamilyFieldArr(-1,famFieldM1)
3883         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])
3884         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])
3885         namesNodes=DataArrayAsciiChar(36,16)
3886         namesNodes[:] = ["Node#%.3d        " % (i) for i in range(36)]
3887         mm.setRenumFieldArr(1,renum1)
3888         mm.setFamilyFieldArr(1,famField1)
3889         mm.setNameFieldAtLevel(1,namesNodes)
3890         mm.setFamilyId("Fam7",77)
3891         mm.setFamilyId("Fam8",88)
3892         mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
3893         mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
3894         mm.write(fileName,2)
3895         #
3896         mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
3897         self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
3898         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])))
3899         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)
3900         self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
3901         self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
3902         self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
3903         self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
3904         self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
3905         self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
3906         self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
3907         #
3908         mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
3909         self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
3910         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])))
3911         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)
3912         self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
3913         self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
3914         self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
3915         self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
3916         self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
3917         self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
3918         self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
3919         #
3920         mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
3921         self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
3922         self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
3923         self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
3924         self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
3925         self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
3926         self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
3927         self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
3928         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])))
3929         self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
3930         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)
3931         self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
3932         self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
3933         self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
3934         self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
3935         pass
3936
3937     def testMEDFileFieldsLoadPart1(self):
3938         """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
3939         """
3940         fileName="Pyfile82.med"
3941         meshName="Mesh"
3942         compos=["aa [kg]","bbb [m/s]"]
3943         arr=DataArrayDouble(6) ; arr.iota()
3944         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3945         m=m.buildUnstructured()
3946         m.setName(meshName)
3947         m.changeSpaceDimension(3,0.)
3948         infos=["aa [b]","cc [de]","gg [klm]"]
3949         m.getCoords().setInfoOnComponents(infos)
3950         m.checkConsistency()
3951         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
3952         f.setName("Field")
3953         arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
3954         arr[:,0]=list(range(25))
3955         arr[:,1]=list(range(100,125))
3956         f.setArray(arr)
3957         WriteField(fileName,f,True)
3958         f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
3959         f.setName("FieldNode")
3960         arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
3961         arr[:,0]=list(range(200,236))
3962         arr[:,1]=list(range(300,336))
3963         f.setArray(arr)
3964         f.checkConsistencyLight()
3965         WriteFieldUsingAlreadyWrittenMesh(fileName,f)
3966         #
3967         ms=MEDFileMeshes()
3968         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
3969         ms.pushMesh(mm)
3970         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3971         self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
3972         #
3973         ms=MEDFileMeshes()
3974         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
3975         ms.pushMesh(mm)
3976         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3977         fs=fs.deepCopy()
3978         fs[0][0].loadArrays()
3979         arr = DataArrayDouble(12, 2) ; arr[:, 0] = list(range(3, 15)) ; arr[:, 1] = list(range(103, 115))
3980         arr.setInfoOnComponents(compos)
3981         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
3982         fs[1][0].loadArrays()
3983         arr = DataArrayDouble(21, 2) ; arr[:, 0] = list(range(203, 224)) ; arr[:, 1] = list(range(303, 324))
3984         arr.setInfoOnComponents(compos)
3985         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
3986         pass
3987
3988     def testMEDFileWithoutCells1(self):
3989         fileName="Pyfile83.med"
3990         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
3991         coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
3992         mm=MEDFileUMesh()
3993         mm.setCoords(coo)
3994         mm.setName("mesh")
3995         mm.write(fileName,2)
3996         #
3997         mm=MEDFileMesh.New(fileName)
3998         self.assertEqual(mm.getName(),"mesh")
3999         self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
4000         pass
4001
4002     def testZipCoordsWithLoadPart1(self):
4003         """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
4004         """
4005         fileName="Pyfile84.med"
4006         meshName="Mesh"
4007         compos=["aa [kg]","bbb [m/s]"]
4008         arr=DataArrayDouble(6) ; arr.iota()
4009         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4010         m=m.buildUnstructured()
4011         m.setName(meshName)
4012         m.changeSpaceDimension(3,0.)
4013         infos=["aa [b]","cc [de]","gg [klm]"]
4014         m.getCoords().setInfoOnComponents(infos)
4015         m.checkConsistency()
4016         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4017         f.setName("Field")
4018         arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4019         arr[:,0]=list(range(25))
4020         arr[:,1]=list(range(100,125))
4021         f.setArray(arr)
4022         WriteField(fileName,f,True)
4023         f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4024         f.setName("FieldNode")
4025         arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4026         arr[:,0]=list(range(200,236))
4027         arr[:,1]=list(range(300,336))
4028         f.setArray(arr)
4029         f.checkConsistencyLight()
4030         WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4031         #
4032         ms=MEDFileMeshes()
4033         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
4034         ms.pushMesh(mm)
4035         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4036         self.assertEqual(spd.getSlice(),slice(4,6,1))
4037         spd=mm.getPartDefAtLevel(1)
4038         self.assertEqual(spd.getSlice(),slice(4,14,1))
4039         self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4040         mm.zipCoords() # <- The important line is here !
4041         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4042         self.assertEqual(spd.getSlice(),slice(4,6,1))
4043         spd=mm.getPartDefAtLevel(1)
4044         self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4045         self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
4046         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4047         fs[0][0].loadArrays()
4048         arr=DataArrayDouble([(4,104),(5,105)])
4049         arr.setInfoOnComponents(compos)
4050         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4051         fs[1][0].loadArrays()
4052         arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
4053         arr.setInfoOnComponents(compos)
4054         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4055         pass
4056
4057     def testMEDFileCMeshSetGroupsAtLevel(self):
4058         """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
4059         """
4060         m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
4061         m.setName("Mesh")
4062         mm=MEDFileCMesh() ; mm.setMesh(m)
4063         grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
4064         mm.setGroupsAtLevel(0,[grp])
4065         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
4066         pass
4067
4068     def testMEDFileUMeshBuildExtrudedMesh1(self):
4069         """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
4070         fileName="Pyfile85.med"
4071         meshName2D="Mesh"
4072         meshName1D="Mesh1D"
4073         meshName3DOut="Mesh3D"
4074         #
4075         d1=DataArrayInt([0,4,20,24])
4076         d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
4077         #
4078         a=DataArrayDouble(6) ; a.iota()
4079         m=MEDCouplingCMesh() ; m.setCoords(a,a)
4080         m=m.buildUnstructured()
4081         d1c=d1.buildComplement(m.getNumberOfCells())
4082         m=m[d1c] ; m.zipCoords()
4083         m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
4084         m0.simplexize(0)
4085         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
4086         m.setName(meshName2D)
4087         mMinus1,a,b,c,d=m.buildDescendingConnectivity()
4088         e=d.deltaShiftIndex().findIdsEqual(1)
4089         #
4090         mm=MEDFileUMesh()
4091         mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
4092         grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
4093         mm.setGroupsAtLevel(0,[grp0])
4094         grp1=e ; grp1.setName("grp1")
4095         mm.setGroupsAtLevel(-1,[grp1])
4096         mm.write(fileName,2)
4097         #
4098         a=DataArrayDouble(3) ; a.iota()
4099         tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
4100         tmp.setName(meshName1D)
4101         tmp.changeSpaceDimension(3)
4102         tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
4103         mm1D=MEDFileUMesh()
4104         mm1D.setMeshAtLevel(0,tmp)
4105         mm1D.write(fileName,0)
4106         # test is here !
4107         mm2D=MEDFileMesh.New(fileName,meshName2D)
4108         mm1D=MEDFileMesh.New(fileName,meshName1D)
4109         m1D=mm1D.getMeshAtLevel(0)
4110         mm3D=mm2D.buildExtrudedMesh(m1D,0)
4111         #
4112         self.assertEqual(mm3D.getName(),mm2D.getName())
4113         self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
4114         self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
4115         self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
4116         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
4117         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
4118         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
4119         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
4120         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
4121         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
4122         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.)])
4123         self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
4124         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])
4125         self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
4126         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])
4127         self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
4128         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])
4129         self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
4130         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])
4131         self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
4132         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])
4133         self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
4134         d=DataArrayInt(129) ; d.iota() ; d*=3
4135         self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
4136         #
4137         self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
4138         self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
4139         self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
4140         self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
4141         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])))
4142         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])))
4143         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])))
4144         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])))
4145         mm3D.setName("MeshExtruded")
4146         mm3D.write(fileName,0)
4147         pass
4148
4149     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4150     def testMEDFileUMeshPickeling1(self):
4151         outFileName="Pyfile86.med"
4152         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)
4153         c.setInfoOnComponents(["aa","bbb"])
4154         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
4155         m=MEDCouplingUMesh();
4156         m.setMeshDimension(2);
4157         m.allocateCells(5);
4158         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
4159         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
4160         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
4161         m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
4162         m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
4163         m.finishInsertingCells();
4164         m.setCoords(c)
4165         m.checkConsistencyLight()
4166         m1=MEDCouplingUMesh.New();
4167         m1.setMeshDimension(1);
4168         m1.allocateCells(3);
4169         m1.insertNextCell(NORM_SEG2,2,[1,4])
4170         m1.insertNextCell(NORM_SEG2,2,[3,6])
4171         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
4172         m1.finishInsertingCells();
4173         m1.setCoords(c)
4174         m1.checkConsistencyLight()
4175         m2=MEDCouplingUMesh.New();
4176         m2.setMeshDimension(0);
4177         m2.allocateCells(4);
4178         m2.insertNextCell(NORM_POINT1,1,[1])
4179         m2.insertNextCell(NORM_POINT1,1,[3])
4180         m2.insertNextCell(NORM_POINT1,1,[2])
4181         m2.insertNextCell(NORM_POINT1,1,[6])
4182         m2.finishInsertingCells();
4183         m2.setCoords(c)
4184         m2.checkConsistencyLight()
4185         #
4186         mm=MEDFileUMesh.New()
4187         self.assertTrue(mm.getUnivNameWrStatus())
4188         mm.setName("MyFirstMEDCouplingMEDmesh")
4189         mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
4190         mm.setCoords(c)
4191         mm[-1]=m1;
4192         mm[0]=m;
4193         mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
4194         mm[-2]=m2;
4195         mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
4196         # playing with groups
4197         g1_2=DataArrayInt.New()
4198         g1_2.setValues([1,3],2,1)
4199         g1_2.setName("G1")
4200         g2_2=DataArrayInt.New()
4201         g2_2.setValues([1,2,3],3,1)
4202         g2_2.setName("G2")
4203         mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
4204         g1_1=DataArrayInt.New()
4205         g1_1.setValues([0,1,2],3,1)
4206         g1_1.setName("G1")
4207         g2_1=DataArrayInt.New()
4208         g2_1.setValues([0,2],2,1)
4209         g2_1.setName("G2")
4210         mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
4211         g1_N=DataArrayInt.New()
4212         g1_N.setValues(list(range(8)),8,1)
4213         g1_N.setName("G1")
4214         g2_N=DataArrayInt.New()
4215         g2_N.setValues(list(range(9)),9,1)
4216         g2_N.setName("G2")
4217         mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
4218         mm.createGroupOnAll(0,"GrpOnAllCell")
4219         # check content of mm
4220         t=mm.getGroupArr(0,"G1",False)
4221         self.assertTrue(g1_2.isEqual(t));
4222         t=mm.getGroupArr(0,"G2",False)
4223         self.assertTrue(g2_2.isEqual(t));
4224         t=mm.getGroupArr(-1,"G1",False)
4225         self.assertTrue(g1_1.isEqual(t));
4226         t=mm.getGroupArr(-1,"G2",False)
4227         self.assertTrue(g2_1.isEqual(t));
4228         t=mm.getGroupArr(1,"G1",False)
4229         self.assertTrue(g1_N.isEqual(t));
4230         t=mm.getGroupArr(1,"G2",False)
4231         self.assertTrue(g2_N.isEqual(t));
4232         self.assertTrue(mm.existsGroup("GrpOnAllCell"));
4233         t=mm.getGroupArr(0,"GrpOnAllCell")
4234         #
4235         st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4236         mm2=pickle.loads(st)
4237         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4238         self.assertEqual(mm.getAxisType(),AX_CART)
4239         #
4240         mm.setAxisType(AX_CYL)
4241         st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4242         mm2=pickle.loads(st)
4243         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4244         self.assertEqual(mm2.getAxisType(),AX_CYL)
4245         pass
4246
4247     def testMEDFileFieldsLoadSpecificEntities1(self):
4248         nbNodes=11
4249         fieldName="myField"
4250         fileName="Pyfile87.med"
4251         nbPdt=10
4252         meshName="Mesh"
4253         #
4254         m=MEDCouplingCMesh()
4255         arr=DataArrayDouble(nbNodes) ; arr.iota()
4256         m.setCoords(arr)
4257         m=m.buildUnstructured()
4258         m.setName(meshName)
4259         #
4260         fmts=MEDFileFieldMultiTS()
4261         for i in range(nbPdt):
4262             f=MEDCouplingFieldDouble(ON_NODES)
4263             f.setMesh(m)
4264             arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4265             f.setArray(arr)
4266             f.setName(fieldName)
4267             f.setTime(float(i),i,0)
4268             fmts.appendFieldNoProfileSBT(f)
4269             pass
4270         #
4271         mm=MEDFileUMesh() ; mm[0]=m
4272         fmts.write(fileName,2)
4273         mm.write(fileName,0)
4274         #
4275         fs=MEDFileFields(fileName,False)
4276         fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
4277         fs.loadArraysIfNecessary()
4278         fs2.loadArraysIfNecessary()
4279         for i in range(nbPdt):
4280             self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4281             pass
4282         m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
4283         m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
4284         m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
4285         fmts=MEDFileFieldMultiTS()
4286         for i in range(nbPdt):
4287             f=MEDCouplingFieldDouble(ON_CELLS)
4288             f.setMesh(m3)
4289             arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
4290             f.setArray(arr)
4291             f.setName(fieldName)
4292             f.setTime(float(i),i,0)
4293             fmts.appendFieldNoProfileSBT(f)
4294             pass
4295         mm=MEDFileUMesh() ; mm[0]=m3
4296         del mm[0]
4297         self.assertEqual(mm.getNonEmptyLevels(),())
4298         mm[0]=m3
4299         self.assertEqual(mm.getNonEmptyLevels(),(0,))
4300         fmts.write(fileName,2)
4301         fs=MEDFileFields(fileName,False)
4302         fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
4303         fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
4304         fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
4305         fs.loadArraysIfNecessary()
4306         fs2.loadArraysIfNecessary()
4307         fs3.loadArraysIfNecessary()
4308         fs4.loadArraysIfNecessary()
4309         for i in range(nbPdt):
4310             self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4311             self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
4312             self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
4313             pass
4314         pass
4315
4316     def testMEDFileLotsOfTSRW1(self):
4317         nbNodes=11
4318         fieldName="myField"
4319         fileName="Pyfile88.med"
4320         nbPdt=300 # <- perftest = 30000
4321         meshName="Mesh"
4322         #
4323         maxPdt=100 # <- optimum = 500
4324         m=MEDCouplingCMesh()
4325         arr=DataArrayDouble(nbNodes) ; arr.iota()
4326         m.setCoords(arr)
4327         m=m.buildUnstructured()
4328         m.setName(meshName)
4329         #
4330         nbOfField=nbPdt//maxPdt
4331         fs=MEDFileFields()
4332         for j in range(nbOfField):
4333             fmts=MEDFileFieldMultiTS()
4334             s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
4335             for i in range(s.start, s.stop, s.step):
4336                 f=MEDCouplingFieldDouble(ON_NODES)
4337                 f.setMesh(m)
4338                 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4339                 f.setArray(arr)
4340                 f.setName("%s_%d"%(fieldName,j))
4341                 f.setTime(float(i),i,0)
4342                 fmts.appendFieldNoProfileSBT(f)
4343                 pass
4344             fs.pushField(fmts)
4345             pass
4346         #
4347         mm=MEDFileUMesh() ; mm[0]=m
4348         fs.write(fileName,2)
4349         mm.write(fileName,0)
4350         ############
4351         def appendInDict(d,key,val):
4352             if key in d:
4353                 d[key].append(val)
4354             else:
4355                 d[key]=[val]
4356             pass
4357         import re
4358         allFields=GetAllFieldNames(fileName)
4359         allFieldsDict={}
4360         pat=re.compile("([\d]+)([\s\S]+)$")
4361         for st in allFields:
4362             stRev=st[::-1]
4363             m=pat.match(stRev)
4364             if m:
4365                 appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
4366                 pass
4367             else:
4368                 appendInDict(allFieldsDict,st,'')
4369                 pass
4370             pass
4371         fs2=MEDFileFields()
4372         for k in allFieldsDict:
4373             if allFieldsDict[k]!=['']:
4374                 allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
4375                 pass
4376             fmts2=[]
4377             for it in allFieldsDict[k]:
4378                 fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
4379                 pass
4380             fmts2.reverse()
4381             zeResu=fmts2.pop()
4382             nbIter=len(fmts2)
4383             for ii in range(nbIter):
4384                 zeResu.pushBackTimeSteps(fmts2.pop())
4385                 pass
4386             zeResu.setName(k)
4387             fs2.pushField(zeResu)
4388             pass
4389         self.assertEqual(fs2[0].getTimeSteps(), [(i, 0, float(i)) for i in range(nbPdt)])
4390         pass
4391     
4392     def testMEDFileMeshRearrangeFamIds1(self):
4393         """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
4394         fileName="Pyfile89.med"
4395         meshName='Maillage_2'
4396         mm=MEDFileUMesh()
4397         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)])
4398         #
4399         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])
4400         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])
4401         m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
4402         m0.setConnectivity(c0,c0i)
4403         mm[0]=m0
4404         #
4405         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])
4406         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])
4407         m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
4408         m1.setConnectivity(c1,c1i)
4409         mm[-1]=m1
4410         #
4411         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])
4412         m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4413         m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
4414         mm[-2]=m2.buildUnstructured()
4415         #
4416         ref0=DataArrayInt(55) ; ref0[:]=0
4417         mm.setFamilyFieldArr(0,ref0)
4418         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]))
4419         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])
4420         mm.setFamilyFieldArr(-1,ref1)
4421         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])
4422         mm.setFamilyFieldArr(-2,ref2)
4423         #
4424         for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
4425             mm.setFamilyId(f,fid)
4426         for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
4427             mm.setFamiliesOnGroup(grp,fams)
4428         mm.write(fileName,2)
4429         #
4430         mm=MEDFileMesh.New(fileName)
4431         grp=mm.getGroup(-1,"Groupe_1")
4432         dai=grp.computeFetchedNodeIds()
4433         dai.setName("TOTO")
4434         mm.addGroup(1,dai)
4435         mm.rearrangeFamilies() # <- the aim of the test
4436         self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
4437         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
4438         self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
4439         self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
4440         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])))
4441         allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
4442         allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
4443         self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
4444         for elt,fams in allGrps:
4445             self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
4446         self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
4447         for elt,eltId in allFams:
4448             self.assertEqual(mm.getFamilyId(elt),eltId)
4449         pass
4450
4451     def testNonRegrCMeshSetFieldPfl1(self):
4452         """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
4453         ff=MEDFileField1TS()
4454         meshName="mesh"
4455         mm=MEDFileCMesh()
4456         m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4457         m.setCoords(arr)
4458         m.setName(meshName)
4459         mm.setMesh(m)
4460         field=MEDCouplingFieldDouble(ON_CELLS)
4461         field.setMesh(m)
4462         field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4463         field.setName("Field")
4464         field.checkConsistencyLight()
4465         pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
4466         ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
4467         self.assertEqual(ff.getPfls(),())
4468         field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4469         self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4470         del ff,mm,field,field2,pfl
4471         # same with unstructured mesh
4472         ff=MEDFileField1TS()
4473         meshName="mesh"
4474         mm=MEDFileUMesh()
4475         m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4476         m.setCoords(arr)
4477         m.setName(meshName)
4478         m=m.buildUnstructured()
4479         mm[0]=m
4480         field=MEDCouplingFieldDouble(ON_CELLS)
4481         field.setMesh(m)
4482         field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4483         field.setName("Field")
4484         field.checkConsistencyLight()
4485         pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
4486         ff.setFieldProfile(field,mm,0,pfl)
4487         self.assertEqual(ff.getPfls(),())
4488         field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4489         self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4490         pass
4491
4492     def testMEDFileUMeshLinearToQuadraticAndRev1(self):
4493         meshName="mesh"
4494         fileName="Pyfile90.med"
4495         fileName2="Pyfile91.med"
4496         arr=DataArrayDouble(5) ; arr.iota()
4497         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4498         m=m.buildUnstructured()
4499         d=DataArrayInt([3,7,11,15])
4500         m1=m[d]
4501         m1.simplexize(0)
4502         m2=m[d.buildComplement(m.getNumberOfCells())]
4503         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
4504         m.changeSpaceDimension(3,0.)
4505         arr=DataArrayDouble(3) ; arr.iota()
4506         m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
4507         m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
4508         delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
4509         m3D=m.buildExtrudedMesh(m1D,0)
4510         m3D.sortCellsInMEDFileFrmt()
4511         m3D.setName(meshName)
4512         m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkConsistency()
4513         m1D=m2D.computeSkin() ; m1D.setName(meshName)
4514         m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
4515         #
4516         mm=MEDFileUMesh()
4517         mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
4518         grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
4519         grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
4520         grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
4521         grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
4522         diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
4523         vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
4524         vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
4525         mm.setGroupsAtLevel(0,[vol1,vol2])
4526         mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
4527         mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
4528         #
4529         mmOut1=mm.linearToQuadratic(0,0.)
4530         mmOut1.write(fileName2,2)
4531         mmOut2=mmOut1.quadraticToLinear(0.)
4532         self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
4533         pass
4534
4535     def testMEDFileMeshAddGroup1(self):
4536         m=MEDCouplingCMesh()
4537         arrX=DataArrayDouble(9) ; arrX.iota()
4538         arrY=DataArrayDouble(4) ; arrY.iota()
4539         m.setCoords(arrX,arrY)
4540         m.setName("mesh")
4541         mm=MEDFileCMesh()
4542         mm.setMesh(m)
4543         grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
4544         mm.addGroup(0,grp0)
4545         grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
4546         mm.addGroup(0,grp1)
4547         grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
4548         mm.addGroup(0,grp2)
4549         grp3=DataArrayInt([23]) ; grp3.setName("grp3")
4550         mm.addGroup(0,grp3)
4551         for grp in [grp0,grp1,grp2,grp3]:
4552             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4553         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
4554         delta=12
4555         for grp in [grp0,grp1,grp2,grp3]:
4556             grpNode=grp.deepCopy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
4557             mm.addGroup(1,grpNode)
4558         self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
4559         for grp in [grp0,grp1,grp2,grp3]:
4560             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4561         for grp in [grp0,grp1,grp2,grp3]:
4562             grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4563             self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4564         mm.normalizeFamIdsMEDFile()
4565         for grp in [grp0,grp1,grp2,grp3]:
4566             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4567         for grp in [grp0,grp1,grp2,grp3]:
4568             grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4569             self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4570         pass
4571     
4572     def testMEDFileJoint1(self):
4573         fileName="Pyfile92.med"
4574         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4575         coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4576         mm=MEDFileUMesh()
4577         mm.setCoords(coo)
4578         mm.setName("maa1")
4579         mm.setDescription("un maillage")
4580         mm.write(fileName,2)
4581         node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4582         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4583         one_step_joint=MEDFileJointOneStep()
4584         one_step_joint.pushCorrespondence(cell_correspond)
4585         one_step_joint.pushCorrespondence(node_correspond)
4586         one_joint=MEDFileJoint()
4587         one_joint.pushStep(one_step_joint)
4588         one_joint.setLocalMeshName("maa1")
4589         one_joint.setRemoteMeshName("maa1")
4590         one_joint.setDescription("joint_description")
4591         one_joint.setJointName("joint_1")
4592         one_joint.setDomainNumber(1)
4593         self.assertEqual( one_joint.getLocalMeshName(), "maa1")
4594         self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
4595         self.assertEqual( one_joint.getDescription(), "joint_description")
4596         self.assertEqual( one_joint.getJointName(), "joint_1")
4597         self.assertEqual( one_joint.getDomainNumber(), 1)
4598         joints=MEDFileJoints()
4599         joints.pushJoint(one_joint);
4600         joints.write(fileName,0)
4601         # read back
4602         jointsR=MEDFileJoints(fileName,mm.getName())
4603         self.assertEqual( jointsR.getNumberOfJoints(), 1 )
4604         jR = jointsR.getJointAtPos(0)
4605         self.assertTrue( jR.isEqual( one_joint ))
4606         self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
4607         self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
4608         jointsR.destroyJointAtPos(0)
4609         pass
4610     
4611     def testMEDFileJoint2(self):
4612         fileNameWr="Pyfile93.med"
4613         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4614         coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4615         mm=MEDFileUMesh()
4616         mm.setCoords(coo)
4617         mm.setName("maa1")
4618         mm.setDescription("un maillage")
4619         node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
4620         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
4621         one_step_joint=MEDFileJointOneStep()
4622         two_step_joint=MEDFileJointOneStep()
4623         one_joint=MEDFileJoint()
4624         two_joint=MEDFileJoint()
4625         one_step_joint.pushCorrespondence(node_correspond)
4626         one_joint.pushStep(one_step_joint)
4627         two_step_joint.pushCorrespondence(cell_correspond)
4628         two_step_joint.pushCorrespondence(node_correspond)
4629         two_joint.pushStep(two_step_joint)
4630         one_joint.setLocalMeshName("maa1")
4631         one_joint.setRemoteMeshName("maa1")
4632         one_joint.setDescription("joint_description_1")
4633         one_joint.setJointName("joint_1")
4634         one_joint.setDomainNumber(1)
4635         two_joint.setLocalMeshName("maa1")
4636         two_joint.setRemoteMeshName("maa1")
4637         two_joint.setDescription("joint_description_2")
4638         two_joint.setJointName("joint_2")
4639         two_joint.setDomainNumber(2)
4640         joints=MEDFileJoints()
4641         joints.pushJoint(one_joint)
4642         joints.pushJoint(two_joint)
4643         mm.setJoints( joints )
4644         mm.write(fileNameWr,2)
4645         #
4646         mm=MEDFileMesh.New(fileNameWr)
4647         self.assertEqual( mm.getNumberOfJoints(), 2)
4648         jointsR = mm.getJoints();
4649         self.assertEqual( jointsR.getMeshName(), mm.getName() )
4650         self.assertEqual( len( jointsR ), 2 )
4651         jointR1 = jointsR[0]
4652         jointR2 = jointsR[1]
4653         self.assertFalse( jointR1 is None )
4654         self.assertFalse( jointR2 is None )
4655         self.assertTrue( jointR1.isEqual( one_joint ))
4656         self.assertTrue( jointR2.isEqual( two_joint ))
4657         pass
4658
4659     def testMEDFileJoint1(self):
4660         node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4661         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4662         cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
4663         cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
4664         joint1st_1=MEDFileJointOneStep()
4665         joint1st_1.pushCorrespondence(cell_correspond)
4666         joint1st_1.pushCorrespondence(node_correspond)
4667         joint1st_2=MEDFileJointOneStep()
4668         joint1st_2.pushCorrespondence(cell_correspond)
4669         joint1st_2.pushCorrespondence(node_correspond)
4670         joint1st_3=MEDFileJointOneStep()
4671         joint1st_3.pushCorrespondence(node_correspond)
4672         joint1st_3.pushCorrespondence(cell_correspond)
4673         joint1st_4=MEDFileJointOneStep()
4674         joint1st_4.pushCorrespondence(cell_correspond)
4675         joint1st_5=MEDFileJointOneStep()
4676         joint1st_5.pushCorrespondence(cell_correspon2)
4677         joint1st_6=MEDFileJointOneStep()
4678         joint1st_6.pushCorrespondence(cell_correspon3)
4679         self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
4680         self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
4681         self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
4682         self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
4683         self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
4684         one_joint=MEDFileJoint()
4685         one_joint.pushStep(joint1st_1)
4686         one_joint.setLocalMeshName("maa1")
4687         one_joint.setRemoteMeshName("maa2")
4688         one_joint.setDescription("joint_description")
4689         one_joint.setJointName("joint_1")
4690         one_joint.setDomainNumber(1)
4691         self.assertEqual( "maa1", one_joint.getLocalMeshName())
4692         self.assertEqual( "maa2", one_joint.getRemoteMeshName())
4693         self.assertEqual( "joint_description", one_joint.getDescription())
4694         self.assertEqual( 1, one_joint.getDomainNumber())
4695         self.assertEqual( "joint_1", one_joint.getJointName())
4696         pass
4697
4698     @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
4699     def testMEDFileSafeCall0(self):
4700         """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
4701         fname="Pyfile94.med"
4702         errfname="Pyfile94.err"
4703         
4704         import os
4705         # first clean file if needed
4706         if os.path.exists(fname):
4707             os.remove(fname)
4708             pass
4709         # second : build a file from scratch
4710         m=MEDCouplingCMesh()
4711         arr=DataArrayDouble(11) ; arr.iota()
4712         m.setCoords(arr,arr)
4713         mm=MEDFileCMesh()
4714         mm.setMesh(m)
4715         mm.setName("mesh")
4716         mm.write(fname,2)
4717         # third : change permissions to remove write access on created file
4718         os.chmod(fname, 0o444)
4719         # four : try to append data on file -> check that it raises Exception
4720         f=MEDCouplingFieldDouble(ON_CELLS)
4721         f.setName("field")
4722         f.setMesh(m)
4723         f.setArray(DataArrayDouble(100))
4724         f.getArray()[:]=100.
4725         f.checkConsistencyLight()
4726         f1ts=MEDFileField1TS()
4727         f1ts.setFieldNoProfileSBT(f)
4728         # redirect stderr
4729         tmp=StdOutRedirect(errfname)
4730         self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
4731         del tmp
4732         #
4733         if os.path.exists(errfname):
4734             os.remove(errfname)
4735         #
4736         pass
4737
4738     def testUnivStatus1(self):
4739         """ Non regression test to check the effectiveness of univ write status."""
4740         fname="Pyfile95.med"
4741         arr=DataArrayDouble(10) ; arr.iota()
4742         m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
4743         mm=MEDFileCMesh() ; mm.setMesh(m)
4744         mm.setUnivNameWrStatus(False) # test is here
4745         mm.write(fname,2)
4746         mm=MEDFileCMesh(fname)
4747         self.assertEqual(mm.getUnivName(),"")
4748         mm.setUnivNameWrStatus(True)
4749         mm.write(fname,2)
4750         mm=MEDFileCMesh(fname)
4751         self.assertTrue(mm.getUnivName()!="")
4752         pass
4753     
4754     def testEmptyMesh(self):
4755       """ MEDLoader should be able to consistently write and read an empty mesh (coords array
4756       with 0 tuples """
4757       fname = "Pyfile96.med" 
4758       m = MEDCouplingUMesh('toto', 2)
4759       m.setCoords(DataArrayDouble([], 0, 2))
4760       m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
4761       mfu = MEDFileUMesh()
4762       mfu.setMeshAtLevel(0, m)
4763       mfu.write(fname, 2)
4764       mfu2 = MEDFileUMesh(fname)
4765       self.assertEqual('toto', mfu2.getName())
4766       lvl = mfu2.getNonEmptyLevels()
4767       self.assertEqual((), lvl)
4768
4769     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4770     def testMEDFileUMeshPickeling2(self):
4771       """ Check that pickalization can be performed on a unpickalized instance. Non regression test."""
4772       name="Mesh_1"
4773       grpName1="HAUT"
4774       grpName2="BASE"
4775       hauteur=1.
4776       nbOfNodesPerAxis=3
4777       arr=DataArrayDouble(nbOfNodesPerAxis) ; arr.iota() ; arr/=(nbOfNodesPerAxis-1) ; arr*=hauteur
4778       m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured() ; m.setName(name)
4779       mesh=MEDFileUMesh() ; mesh[0]=m
4780       m1=m.computeSkin() ; mesh[-1]=m1
4781       #
4782       bary1=m1.computeCellCenterOfMass()[:,2]
4783       grp1=bary1.findIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
4784       grp2=bary1.findIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
4785       mesh.setGroupsAtLevel(-1,[grp1,grp2])
4786       
4787       st=pickle.dumps(mesh,2)
4788       mm=pickle.loads(st)
4789       st2=pickle.dumps(mm,2)
4790       mm2=pickle.loads(st2)
4791       self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
4792       pass
4793
4794     def testMEDFileEquivalence1(self):
4795       """ First check of equivalence implementation in MEDFileMesh"""
4796       fileName="Pyfile97.med"
4797       meshName="M_01"
4798       mm=MEDFileUMesh()
4799       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)])
4800       coo.setInfoOnComponents(["X [Sans_unite]","Y [Sans_unite]","Z [Sans_unite]"])
4801       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])
4802       m1=MEDCoupling1SGTUMesh(meshName,NORM_QUAD4) ; m1.setCoords(coo) ; m1.setNodalConnectivity(connQ4) ; mm[-1]=m1
4803       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])
4804       m0=MEDCoupling1SGTUMesh(meshName,NORM_HEXA8) ; m0.setCoords(coo) ; m0.setNodalConnectivity(connH8) ; mm[0]=m0
4805       mm.getFamilyFieldAtLevel(-1)[:]=-2
4806       mm.getFamilyFieldAtLevel(0)[:]=0
4807       mm.addFamily("HOMARD________-1",-1)
4808       mm.addFamily("HOMARD________-2",-2)
4809       mm.addFamily("HOMARD________-3",-3)
4810       mm.setFamiliesIdsOnGroup("HOMARD",[-1,-2,-3])
4811       
4812       eqName="MAILLES_A_RECOLLER_APRES_HOMARD"
4813       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."
4814       mm.initializeEquivalences()
4815       eqs=mm.getEquivalences()
4816       eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4817       eq0.setDescription(descEq)
4818       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)])
4819       eq0.setArray(-1,corr)
4820       self.assertEqual(eq0.getCell().size(),1)
4821       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4822       eq0.getCell().clear()
4823       self.assertEqual(eq0.getCell().size(),0)
4824       eq0.getCell().setArrayForType(NORM_QUAD4,corr)
4825       self.assertEqual(eq0.getCell().size(),1)
4826       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4827       mm.killEquivalences()
4828       mm.initializeEquivalences()
4829       eqs=mm.getEquivalences()
4830       eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4831       eq0.setDescription(descEq)
4832       c=eq0.initCell()
4833       c.setArrayForType(NORM_QUAD4,corr)
4834       self.assertEqual(eq0.getCell().size(),1)
4835       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4836       mm2=mm.deepCopy()
4837       self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4838       self.assertEqual(mm2.getEquivalences().size(),1)
4839       self.assertTrue(mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4).isEqual(corr))
4840       mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=2
4841       self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
4842       mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=0
4843       self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4844       mm.write(fileName,2)
4845       #
4846       mm3=MEDFileMesh.New(fileName)
4847       self.assertTrue(mm.isEqual(mm3,1e-12)[0])
4848       pass
4849
4850     def testMEDFileForFamiliesPlayer1(self):
4851       """Non regression bug EDF11911. For serial killers using same family name to store both cells and nodes ! Only sky is the limit."""
4852       fileName="Pyfile98.med"
4853       meshName="mesh"
4854       magicSt="%s%%04i"%(MEDFileMesh.GetMagicFamilyStr())
4855       arr=DataArrayDouble(4) ; arr.iota()
4856       m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4857       m=m.buildUnstructured()
4858       mm=MEDFileUMesh()
4859       mm[0]=m
4860       mm.setName(meshName)
4861       mm.setFamilyId("FAMILLE_ZERO",0)
4862       mm.getFamilyFieldAtLevel(0)[-3:]=-4
4863       mm.setFamilyId("RIDF%s"%(magicSt%0),-4)
4864       mm.setGroupsOnFamily("RIDF%s"%(magicSt%0),["RID"])
4865       d=DataArrayInt(16) ; d[:]=0 ; d[[1,2,4,5]]=3
4866       mm.setFamilyFieldArr(1,d)
4867       mm.setFamilyId("RIDF%s"%(magicSt%1),3)
4868       mm.setGroupsOnFamily("RIDF%s"%(magicSt%1),["RID"])
4869       self.assertEqual(mm.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4870       self.assertEqual(mm.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF")) # <- the aim of test is here !
4871       self.assertEqual(mm.getFamiliesIdsOnGroup("RID"),(-4,3))
4872       mm.write(fileName,2)
4873       # now read such funny file !
4874       mm2=MEDFileMesh.New(fileName) # <- normally mdump of Pyfile98.med must contain only RID and FAMILLE_ZERO families.
4875       self.assertTrue(mm.isEqual(mm2,1e-16))
4876       self.assertEqual(mm2.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4877       self.assertEqual(mm2.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF"))
4878       self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too !
4879       pass
4880
4881     def testCartesianizer1(self):
4882       """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """
4883       # UMesh non cart
4884       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
4885       mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts()
4886       d0=DataArrayInt(16) ; d0[:]=0
4887       d1=DataArrayInt(9)  ; d1[:]=0
4888       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4889       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4890       ref0=mm.getCoords().getHiddenCppPointer()
4891       ref1=mm[0].getNodalConnectivity().getHiddenCppPointer()
4892       self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer())
4893       ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer()
4894       ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer()
4895       self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
4896       mm.setAxisType(AX_CYL) #<- important
4897       mm2=mm.cartesianize() # the trigger
4898       self.assertEqual(mm2.getAxisType(),AX_CART)
4899       mm.setAxisType(AX_CART) # this is here only to avoid complaints
4900       self.assertTrue(isinstance(mm2,MEDFileUMesh))
4901       self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
4902       self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important
4903       self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important
4904       self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer())
4905       self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
4906       self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important
4907       self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important
4908       self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important
4909       self.assertEqual(mm2.getName(),mm.getName())
4910       self.assertEqual(mm2.getDescription(),mm.getDescription())
4911       self.assertEqual(mm2.getTime(),mm.getTime())
4912       self.assertEqual(mm2.getTime(),mm.getTime())
4913       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4914       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4915       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4916       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4917       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4918       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4919       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4920       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4921       # UMesh cart
4922       mm.setAxisType(AX_CART)
4923       mm2=mm.cartesianize() # the trigger
4924       self.assertEqual(mm2.getAxisType(),AX_CART)
4925       self.assertTrue(isinstance(mm2,MEDFileUMesh))
4926       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4927       # CurveLinearMesh non cart
4928       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear()
4929       mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
4930       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4931       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4932       ref0=mm.getMesh().getCoords().getHiddenCppPointer()
4933       mm2=mm.cartesianize() # the trigger
4934       self.assertEqual(mm2.getAxisType(),AX_CART)
4935       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4936       self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
4937       self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important
4938       self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important
4939       self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
4940       self.assertEqual(mm2.getName(),mm.getName())
4941       self.assertEqual(mm2.getDescription(),mm.getDescription())
4942       self.assertEqual(mm2.getTime(),mm.getTime())
4943       self.assertEqual(mm2.getTime(),mm.getTime())
4944       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4945       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4946       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4947       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4948       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4949       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4950       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4951       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4952       # CurveLinearMesh cart
4953       mm.setAxisType(AX_CART)
4954       mm2=mm.cartesianize() # the trigger
4955       self.assertEqual(mm2.getAxisType(),AX_CART)
4956       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4957       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4958       # CMesh non cart
4959       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4960       mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
4961       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4962       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4963       mm2=mm.cartesianize() # the trigger
4964       self.assertEqual(mm2.getAxisType(),AX_CART)
4965       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4966       self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
4967       self.assertEqual(mm2.getName(),mm.getName())
4968       self.assertEqual(mm2.getDescription(),mm.getDescription())
4969       self.assertEqual(mm2.getTime(),mm.getTime())
4970       self.assertEqual(mm2.getTime(),mm.getTime())
4971       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4972       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4973       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4974       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4975       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4976       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4977       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4978       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4979       # CMesh cart
4980       mm.setAxisType(AX_CART)
4981       mm2=mm.cartesianize() # the trigger
4982       self.assertEqual(mm2.getAxisType(),AX_CART)
4983       self.assertTrue(isinstance(mm2,MEDFileCMesh))
4984       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4985       pass
4986
4987     def testCheckCoherency(self):
4988       m2 = MEDCouplingUMesh("2d", 2)
4989       m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2))  # whatever
4990       m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
4991       m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
4992       mum = MEDFileUMesh()
4993       mum.setMeshAtLevel(0, m2)
4994       mum.setMeshAtLevel(-1, m1)
4995       mum.checkConsistency()
4996       mum2 = mum.deepCopy()
4997
4998       # Nodes
4999       arr = DataArrayInt([2]*4)
5000       mum.setFamilyFieldArr(1, arr); arr.reAlloc(35);
5001       self.assertRaises(InterpKernelException, mum.checkConsistency)
5002       mum=mum2; mum2=mum.deepCopy();
5003       arr = DataArrayInt([2]*4)
5004       mum.setRenumFieldArr(1, arr); arr.reAlloc(35);
5005       self.assertRaises(InterpKernelException, mum.checkConsistency)
5006       mum=mum2; mum2=mum.deepCopy();
5007       mum.setRenumFieldArr(1, DataArrayInt([2]*4))
5008       self.assertRaises(InterpKernelException, mum.checkConsistency)
5009       mum=mum2; mum2=mum.deepCopy();
5010       arr = DataArrayAsciiChar(['tutu           x']*4)
5011       mum.setNameFieldAtLevel(1, arr); arr.reAlloc(35);
5012       self.assertRaises(InterpKernelException, mum.checkConsistency)
5013
5014       # 2D
5015       mum=mum2; mum2=mum.deepCopy();
5016       arr = DataArrayInt([2]*2)
5017       mum.setFamilyFieldArr(0, arr); arr.reAlloc(35);
5018       self.assertRaises(InterpKernelException, mum.checkConsistency)
5019       mum=mum2; mum2=mum.deepCopy();
5020       arr = DataArrayInt([2]*2)
5021       mum.setRenumFieldArr(0, arr); arr.reAlloc(35);
5022       self.assertRaises(InterpKernelException, mum.checkConsistency)
5023       mum=mum2; mum2=mum.deepCopy();
5024       mum.setRenumFieldArr(0, DataArrayInt([2]*2))
5025       self.assertRaises(InterpKernelException, mum.checkConsistency)
5026       mum=mum2; mum2=mum.deepCopy();
5027       arr = DataArrayAsciiChar(['tutu           x']*2)
5028       mum.setNameFieldAtLevel(0, arr); arr.reAlloc(35);
5029       self.assertRaises(InterpKernelException, mum.checkConsistency)
5030
5031       # 1D
5032       mum=mum2; mum2=mum.deepCopy();
5033       arr = DataArrayInt([2]*5)
5034       mum.setFamilyFieldArr(-1, arr); arr.reAlloc(35);
5035       self.assertRaises(InterpKernelException, mum.checkConsistency)
5036       mum=mum2; mum2=mum.deepCopy();
5037       arr = DataArrayInt([2]*5)
5038       mum.setRenumFieldArr(-1, arr); arr.reAlloc(35);
5039       self.assertRaises(InterpKernelException, mum.checkConsistency)
5040       mum=mum2; mum2=mum.deepCopy();
5041       mum.setRenumFieldArr(-1, DataArrayInt([2]*5))
5042       self.assertRaises(InterpKernelException, mum.checkConsistency)
5043       mum=mum2; mum2=mum.deepCopy();
5044       arr = DataArrayAsciiChar(['tutu           x']*5)
5045       mum.setNameFieldAtLevel(-1, arr); arr.reAlloc(35);
5046       self.assertRaises(InterpKernelException, mum.checkConsistency)
5047
5048     def testCheckSMESHConsistency(self):
5049       m2 = MEDCouplingUMesh("2d", 2)
5050       m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2))  # whatever
5051       m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5052       m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5053       mum = MEDFileUMesh()
5054       mum.setMeshAtLevel(0, m2)
5055       mum.setMeshAtLevel(-1, m1)
5056       mum.checkConsistency()
5057       mum.checkSMESHConsistency()
5058       n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5059       n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5060       mum.setRenumFieldArr(0, n2)
5061       mum.setRenumFieldArr(-1, n1)
5062       self.assertRaises(InterpKernelException, mum.checkSMESHConsistency)
5063       mum.setRenumFieldArr(-1, n1+100)
5064       mum.checkSMESHConsistency()
5065       pass
5066
5067     def testClearNodeAndCellNumbers(self):
5068       m2 = MEDCouplingUMesh("2d", 2)
5069       m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2))  # whatever
5070       m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5071       m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5072       mum = MEDFileUMesh()
5073       mum.setMeshAtLevel(0, m2)
5074       mum.setMeshAtLevel(-1, m1)
5075       mum.checkConsistency()
5076       n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5077       n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5078       mum.setRenumFieldArr(0, n2)
5079       mum.setRenumFieldArr(-1, n1)
5080       mum.clearNodeAndCellNumbers()
5081       mum.checkSMESHConsistency()
5082       pass
5083
5084     def testCMeshSetFamilyFieldArrNull(self):
5085       meshName="mesh"
5086       fname="Pyfile99.med"
5087       arrX=DataArrayDouble([0,1,2,3])
5088       arrY=DataArrayDouble([0,1,2])
5089       m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m.setName(meshName)
5090       mm=MEDFileCMesh() ; mm.setMesh(m)
5091       famCellIds=DataArrayInt([0,-2,-2,-1,-2,0])
5092       famNodeIds=DataArrayInt([0,0,0,3,4,1,2,7,2,1,0,0])
5093       mm.setFamilyFieldArr(0,famCellIds)
5094       mm.setFamilyFieldArr(1,famNodeIds)
5095       mm.write(fname,2)
5096       mm=MEDFileMesh.New(fname)
5097       self.assertTrue(mm.getFamilyFieldAtLevel(0) is not None)
5098       self.assertTrue(mm.getFamilyFieldAtLevel(1) is not None)
5099       mm.setFamilyFieldArr(0,None)#<- bug was here
5100       mm.setFamilyFieldArr(1,None)#<- bug was here
5101       self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
5102       self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
5103       mm3=mm.deepCopy()
5104       self.assertTrue(mm3.getFamilyFieldAtLevel(0) is None)
5105       self.assertTrue(mm3.getFamilyFieldAtLevel(1) is None)
5106       mm.write(fname,2)
5107       mm2=MEDFileMesh.New(fname)
5108       self.assertTrue(mm2.getFamilyFieldAtLevel(0) is None)
5109       self.assertTrue(mm2.getFamilyFieldAtLevel(1) is None)
5110       pass
5111
5112     def testAppendFieldProfileOnIntField(self):
5113       fname="Pyfile100.med"
5114       arrX=DataArrayDouble([0,1,2,3])
5115       arrY=DataArrayDouble([0,1,2])
5116       mesh=MEDCouplingCMesh() ; mesh.setCoords(arrX,arrY) ; mesh.setName("Mesh")
5117       mm=MEDFileCMesh()
5118       mm.setMesh(mesh)
5119       #
5120       fmts=MEDFileIntFieldMultiTS()
5121       pflName="PFL"
5122       pfl=DataArrayInt([1,3,5]) ; pfl.setName(pflName)
5123       f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(mesh)
5124       fieldName="FieldOnCell"
5125       f.setTime(1.2,1,1) ; f.setName(fieldName)
5126       arr=DataArrayInt([101,102,103]) ; f.setArray(arr)
5127       fmts.appendFieldProfile(f,mm,0,pfl)
5128       #
5129       mm.write(fname,2)
5130       fmts.write(fname,0)
5131       #
5132       mm=MEDFileMesh.New(fname)
5133       fmts=MEDFileAnyTypeFieldMultiTS.New(fname)
5134       self.assertTrue(isinstance(fmts,MEDFileIntFieldMultiTS))
5135       self.assertEqual(fmts.getName(),fieldName)
5136       self.assertEqual(len(fmts),1)
5137       f1ts=fmts[0]
5138       ftest,pfltest=f1ts.getFieldWithProfile(ON_CELLS,0,mm)
5139       self.assertEqual(pfltest.getName(),pflName)
5140       self.assertEqual(ftest.getName(),fieldName)
5141       self.assertTrue(ftest.isEqualWithoutConsideringStr(arr))
5142       ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
5143       self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr))
5144       self.assertEqual(ftest2.getTime(),f.getTime())
5145       self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr))
5146       pass
5147
5148     def testMEDFileFieldEasyField1(self):
5149       """Check for all spatial discretization of field (cells,nodes,elno,gauss) for double field that all is OK. Here no profile and only top level is considered."""
5150       ## Basic test on cells on top level
5151       fname="Pyfile101.med"
5152       fieldName="field1"
5153       mm=MEDFileUMesh()
5154       coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5155       m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5156       m.allocateCells()
5157       m.insertNextCell(NORM_TRI3,[0,1,2])
5158       m.insertNextCell(NORM_TRI3,[3,4,5])
5159       m.insertNextCell(NORM_TRI3,[6,7,8])
5160       m.insertNextCell(NORM_TRI3,[9,10,11])
5161       m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5162       m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5163       mm[0]=m
5164       mm.write(fname,2)
5165       arr0=DataArrayDouble([10,11,12,13,100,101])
5166       f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5167       f.setName(fieldName) ; f.setTime(2.,6,7)
5168       f0=f.deepCopy()
5169       ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5170       ff.write(fname,0)
5171       arr2=arr0+1000 ; f.setArray(arr2)
5172       f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f)
5173       ff.write(fname,0)
5174       f1=f.deepCopy()
5175       ##
5176       mm=MEDFileMesh.New(fname)
5177       f1ts=MEDFileField1TS(fname,fieldName,6,7)
5178       ftst0=f1ts.field(mm)
5179       self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12))
5180       f1ts=MEDFileField1TS(fname,fieldName,8,9)
5181       ftst1=f1ts.field(mm)
5182       self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12))
5183       fmts=MEDFileFieldMultiTS(fname,fieldName)
5184       self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12))
5185       ## Basic test on nodes on top level
5186       f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5187       f2.setName(fieldName)
5188       mm.write(fname,2)
5189       ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5190       #
5191       mm=MEDFileMesh.New(fname)
5192       f1ts=MEDFileField1TS(fname,fieldName,23,24)
5193       self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12))
5194       fmts=MEDFileFieldMultiTS(fname,fieldName)
5195       self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12))
5196       ## Node on elements
5197       f3=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
5198       f3.setName(fieldName) ; f3.checkConsistencyLight()
5199       mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5200       #
5201       mm=MEDFileMesh.New(fname)
5202       f1ts=MEDFileField1TS(fname,fieldName,2,3)
5203       self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5204       ## Gauss
5205       f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5206       f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,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.1,0.05,0.35])
5207       f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5)
5208       arr4=DataArrayDouble([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
5209       f4.checkConsistencyLight()
5210       mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5211       #
5212       mm=MEDFileMesh.New(fname)
5213       f1ts=MEDFileField1TS(fname,fieldName,4,5)
5214       self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5215       pass
5216   
5217     def testMEDFileFieldEasyField2(self):
5218         """Same thantestMEDFileFieldEasyField1 except that here intfields are considered.
5219         Check for all spatial discretization of field (cells,nodes,elno,gauss) for int field that all is OK. Here no profile and only top level is considered."""
5220         ## Basic test on cells on top level
5221         fname="Pyfile102.med"
5222         fieldName="field1"
5223         mm=MEDFileUMesh()
5224         coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5225         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5226         m.allocateCells()
5227         m.insertNextCell(NORM_TRI3,[0,1,2])
5228         m.insertNextCell(NORM_TRI3,[3,4,5])
5229         m.insertNextCell(NORM_TRI3,[6,7,8])
5230         m.insertNextCell(NORM_TRI3,[9,10,11])
5231         m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5232         m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5233         mm[0]=m
5234         mm.write(fname,2)
5235         arr0=DataArrayInt([10,11,12,13,100,101])
5236         f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5237         f.setName(fieldName) ; f.setTime(2.,6,7)
5238         f0=f.deepCopy()
5239         ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5240         ff.write(fname,0)
5241         arr2=arr0+1000 ; f.setArray(arr2)
5242         f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f)
5243         ff.write(fname,0)
5244         f1=f.deepCopy()
5245         ##
5246         mm=MEDFileMesh.New(fname)
5247         f1ts=MEDFileIntField1TS(fname,fieldName,6,7)
5248         ftst0=f1ts.field(mm)
5249         self.assertTrue(f0.isEqual(ftst0,1e-12,0))
5250         f1ts=MEDFileIntField1TS(fname,fieldName,8,9)
5251         ftst1=f1ts.field(mm)
5252         self.assertTrue(f1.isEqual(ftst1,1e-12,0))
5253         fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5254         self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,0))
5255         ## Basic test on nodes on top level
5256         f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5257         f2.setName(fieldName)
5258         mm.write(fname,2)
5259         ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5260         #
5261         mm=MEDFileMesh.New(fname)
5262         f1ts=MEDFileIntField1TS(fname,fieldName,23,24)
5263         self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,0))
5264         fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5265         self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,0))
5266         ## Node on elements
5267         f3=MEDCouplingFieldInt(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
5268         f3.setName(fieldName) ; f3.checkConsistencyLight()
5269         mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5270         #
5271         mm=MEDFileMesh.New(fname)
5272         f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5273         self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5274         ## Gauss
5275         f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5276         f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,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.1,0.05,0.35])
5277         f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5)
5278         arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
5279         f4.checkConsistencyLight()
5280         mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5281         #
5282         mm=MEDFileMesh.New(fname)
5283         f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5284         self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5285         pass
5286
5287     def testMEDFileFieldEasyField3(self):
5288         """Here a multi level mesh. And field on cells lying on different level of this mesh. Show how "field" method deal with that. Here on field double are considered."""
5289         fname="Pyfile103.med"
5290         fieldName="field1"
5291         mm=MEDFileUMesh()
5292         coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5293         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5294         m.allocateCells()
5295         m.insertNextCell(NORM_TRI3,[0,1,2])
5296         m.insertNextCell(NORM_TRI3,[3,4,5])
5297         m.insertNextCell(NORM_TRI3,[6,7,8])
5298         m.insertNextCell(NORM_TRI3,[9,10,11])
5299         m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5300         m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5301         mm[-1]=m
5302         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5303         m0.allocateCells()
5304         m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5305         m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5306         mm[0]=m0
5307         mm.write(fname,2)
5308         # start slowly
5309         f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5310         f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5311         #
5312         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2)
5313         self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5314         # here f1 lying on level -1 not 0 check if "field" method detect it !
5315         f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5316         f1.setMesh(mm[-1]) # -1 is very important
5317         f1.setTime(16.,3,4)
5318         f1.checkConsistencyLight()
5319         mm.write(fname,2)
5320         f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5321         #
5322         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4)
5323         self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5324         # nodes on elements
5325         f3=MEDCouplingFieldDouble(ON_GAUSS_NE)
5326         f3.setMesh(mm[-1]) # this line is important
5327         arr3=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
5328         f3.setName(fieldName) ; f3.checkConsistencyLight()
5329         mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5330         #
5331         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3)
5332         self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5333         # gauss
5334         f4=MEDCouplingFieldDouble(ON_GAUSS_PT)
5335         f4.setMesh(mm[-1]) # this line is important
5336         f4.setName(fieldName)
5337         f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,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.1,0.05,0.35])
5338         f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5)
5339         arr4=DataArrayDouble([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
5340         f4.checkConsistencyLight()
5341         mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5342         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5)
5343         self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5344         pass
5345
5346     def testMEDFileFieldEasyField4(self):
5347         """ Same than testMEDFileFieldEasyField3 but with integers"""
5348         fname="Pyfile104.med"
5349         fieldName="field1"
5350         mm=MEDFileUMesh()
5351         coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5352         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5353         m.allocateCells()
5354         m.insertNextCell(NORM_TRI3,[0,1,2])
5355         m.insertNextCell(NORM_TRI3,[3,4,5])
5356         m.insertNextCell(NORM_TRI3,[6,7,8])
5357         m.insertNextCell(NORM_TRI3,[9,10,11])
5358         m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5359         m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5360         mm[-1]=m
5361         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5362         m0.allocateCells()
5363         m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5364         m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5365         mm[0]=m0
5366         mm.write(fname,2)
5367         # start slowly
5368         f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5369         f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5370         #
5371         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2)
5372         self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5373         # here f1 lying on level -1 not 0 check if "field" method detect it !
5374         f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5375         f1.setMesh(mm[-1]) # -1 is very important
5376         f1.setTime(16.,3,4)
5377         f1.checkConsistencyLight()
5378         mm.write(fname,2)
5379         f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5380         #
5381         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4)
5382         self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5383         # nodes on elements
5384         f3=MEDCouplingFieldInt(ON_GAUSS_NE)
5385         f3.setMesh(mm[-1]) # this line is important
5386         arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
5387         f3.setName(fieldName) ; f3.checkConsistencyLight()
5388         mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5389         #
5390         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5391         self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5392         # gauss
5393         f4=MEDCouplingFieldInt(ON_GAUSS_PT)
5394         f4.setMesh(mm[-1]) # this line is important
5395         f4.setName(fieldName)
5396         f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,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.1,0.05,0.35])
5397         f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5)
5398         arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
5399         f4.checkConsistencyLight()
5400         mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5401         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5402         self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5403         pass
5404
5405     def testMEDFileFieldEasyField5(self):
5406         """More and more difficult now look at how profiles are managed by "field" method."""
5407         fname="Pyfile105.med"
5408         fieldName="field1"
5409         mm=MEDFileUMesh()
5410         coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5411         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5412         m.allocateCells()
5413         m.insertNextCell(NORM_TRI3,[0,1,2])
5414         m.insertNextCell(NORM_TRI3,[3,4,5])
5415         m.insertNextCell(NORM_TRI3,[6,7,8])
5416         m.insertNextCell(NORM_TRI3,[9,10,11])
5417         m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5418         m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5419         mm[0]=m
5420         mm.write(fname,2)
5421         pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl")
5422         m2=m.deepCopy()[pfl] ; m2.setName(m.getName())
5423         #
5424         arr0=DataArrayDouble([10,11,12,13])
5425         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2)
5426         f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight()
5427         ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile
5428         ff.write(fname,0)
5429         #
5430         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5431         self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5432         # more complicated -> multi level
5433         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5434         m0.allocateCells()
5435         m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5436         m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5437         mm2=MEDFileUMesh()
5438         mm2[0]=m0 ; mm2[-1]=m
5439         #
5440         ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl)
5441         #
5442         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5443         self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5444         pass
5445
5446     def testExtractPart1(self):
5447         coo=DataArrayDouble([(0,0),(1,0),(2,0),(3,0),(4,0),(0,1),(1,1),(2,1),(3,1),(4,1),(0,2),(1,2),(2,2),(3,2),(4,2)])
5448         meshName="mesh"
5449         m0=MEDCouplingUMesh(meshName,2) ; m0.setCoords(coo) ; m0.allocateCells()
5450         m0.insertNextCell(NORM_TRI3,[8,4,3])
5451         m0.insertNextCell(NORM_TRI3,[8,9,4])
5452         m0.insertNextCell(NORM_TRI3,[7,13,8])
5453         m0.insertNextCell(NORM_TRI3,[7,12,13])
5454         m0.insertNextCell(NORM_TRI3,[0,6,1])
5455         m0.insertNextCell(NORM_TRI3,[0,5,6])
5456         m0.insertNextCell(NORM_QUAD4,[1,6,7,2])
5457         m0.insertNextCell(NORM_QUAD4,[2,7,8,3])
5458         m0.insertNextCell(NORM_QUAD4,[8,13,14,9])
5459         m0.insertNextCell(NORM_QUAD4,[6,11,12,7])
5460         m0.insertNextCell(NORM_QUAD4,[5,10,11,6])
5461         #
5462         m1=MEDCouplingUMesh(meshName,1) ; m1.setCoords(coo) ; m1.allocateCells()
5463         m1.insertNextCell(NORM_SEG2,[10,5])
5464         m1.insertNextCell(NORM_SEG2,[5,0])
5465         m1.insertNextCell(NORM_SEG2,[0,1])
5466         m1.insertNextCell(NORM_SEG2,[1,2])
5467         m1.insertNextCell(NORM_SEG2,[2,3])
5468         m1.insertNextCell(NORM_SEG2,[3,4])
5469         m1.insertNextCell(NORM_SEG2,[4,9])
5470         m1.insertNextCell(NORM_SEG2,[9,14])
5471         m1.insertNextCell(NORM_SEG2,[14,13])
5472         m1.insertNextCell(NORM_SEG2,[13,12])
5473         m1.insertNextCell(NORM_SEG2,[12,11])
5474         m1.insertNextCell(NORM_SEG2,[11,10])
5475         mm=MEDFileUMesh()
5476         mm[0]=m0 ; mm[-1]=m1
5477         arr0=DataArrayInt([0,1,2,3,4,6,7,8,12,13])
5478         tab={} #
5479         tab[0]=DataArrayInt([0,2,3,4,6,7])
5480         tab[-1]=DataArrayInt([2,3,4,5,9])
5481         fs=MEDFileFields()
5482         self.assertTrue(mm.deduceNodeSubPartFromCellSubPart(tab).isEqual(arr0))
5483         tab[1]=arr0
5484         #
5485         fname0="Field0"
5486         fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5487         t0=(16.5,3,4)
5488         ic=["toto [m]"]
5489         arr0_0=DataArrayDouble([100,101,102,103,104,105,106,107,108,109,110]) ; arr0_0.setInfoOnComponents(ic)
5490         f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*t0) ; f0.setArray(arr0_0)
5491         f0.setMesh(m0) ; f0.setName(fname0)
5492         f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setTime(*t0) ; f1.setArray(DataArrayDouble([200,201,202,203,204,205,206,207,208,209,210,211]))
5493         f1.setMesh(m1) ; f1.setName(fname0) ; f1.getArray().setInfoOnComponents(ic)
5494         f2=MEDCouplingFieldDouble(ON_NODES) ; f2.setTime(*t0) ; f2.setArray(DataArrayDouble([300,301,302,303,304,305,306,307,308,309,310,311,312,313,314]))
5495         f2.setMesh(m0) ; f2.setName(fname0) ; f2.getArray().setInfoOnComponents(ic)
5496         f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.setFieldNoProfileSBT(f2)
5497         fmts.pushBackTimeStep(f1ts)
5498         #
5499         mmOut=mm.extractPart(tab)
5500         #
5501         fsPart0=fs.extractPart(tab,mm)
5502         self.assertEqual(len(fsPart0),1)
5503         fmtsP=fsPart0[0]
5504         self.assertEqual(len(fmtsP),1)
5505         f1ts=fmtsP[0]
5506         self.assertRaises(InterpKernelException,f1ts.field,mmOut)
5507         #
5508         self.assertTrue(mmOut[0].computeCellCenterOfMass().isEqual(m0[tab[0]].computeCellCenterOfMass(),1e-12))
5509         self.assertTrue(mmOut[-1].computeCellCenterOfMass().isEqual(m1[tab[-1]].computeCellCenterOfMass(),1e-12))
5510         #
5511         m0Part=m0.deepCopy()[tab[0]] ; m0Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m0Part.setName(m0.getName())
5512         self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5513         m1Part=m1.deepCopy()[tab[-1]] ; m1Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m1Part.setName(m0.getName())
5514         self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5515         self.assertTrue(mmOut[-1].isEqual(m1Part,1e-12))
5516         #
5517         f0Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mmOut) ; f0Part.checkConsistencyLight()
5518         self.assertEqual(f0Part.getTypeOfField(),ON_CELLS)
5519         self.assertTrue(f0Part.getMesh().isEqual(m0Part,1e-12))
5520         arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic)
5521         self.assertTrue(f0Part.getArray().isEqual(arr0Exp,1e-12)) ; self.assertEqual(f0Part.getTime(),list(t0))
5522         f1Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,-1,mmOut) ; f1Part.checkConsistencyLight()
5523         self.assertEqual(f1Part.getTypeOfField(),ON_CELLS)
5524         self.assertTrue(f1Part.getMesh().isEqual(m1Part,1e-12))
5525         arr1Exp=DataArrayDouble([202,203,204,205,209]) ; arr1Exp.setInfoOnComponents(ic)
5526         self.assertTrue(f1Part.getArray().isEqual(arr1Exp,1e-12)) ; self.assertEqual(f1Part.getTime(),list(t0))
5527         #
5528         f2Part=f1ts.getFieldOnMeshAtLevel(ON_NODES,0,mmOut) ; f2Part.checkConsistencyLight()
5529         arr2Exp=DataArrayDouble([300,301,302,303,304,306,307,308,312,313]) ; arr2Exp.setInfoOnComponents(ic)
5530         self.assertTrue(f2Part.getArray().isEqual(arr2Exp,1e-12)) ; self.assertEqual(f2Part.getTime(),list(t0))
5531         # multisteps
5532         fs=MEDFileFields() ; fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5533         tss=[(16.5,3,4),(17.5,4,5),(18.5,5,6)]
5534         for i,tt in enumerate(tss):
5535             f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*tt)
5536             myarr=arr0_0+i*1000.
5537             f0.setArray(myarr)
5538             f0.setMesh(m0) ; f0.setName(fname0) ; f0.getArray().setInfoOnComponents(ic)
5539             f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; fmts.pushBackTimeStep(f1ts)
5540             pass
5541         fsPart1=fs.extractPart(tab,mm)
5542         self.assertEqual(len(fsPart1),1)
5543         fmtsP=fsPart1[0]
5544         self.assertEqual(len(fmtsP),len(tss))
5545         for i,(f1tsP,tt) in enumerate(zip(fmtsP,tss)):
5546             fPart=f1tsP.field(mmOut) ; fPart.checkConsistencyLight()
5547             self.assertEqual(fPart.getTypeOfField(),ON_CELLS)
5548             arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic) ; arr0Exp+=i*1000.
5549             self.assertTrue(fPart.getMesh().isEqual(m0Part,1e-12))
5550             self.assertTrue(fPart.getArray().isEqual(arr0Exp,1e-12))
5551             self.assertEqual(fPart.getTime(),list(tt))
5552             pass
5553         pass
5554
5555     def testSymmetryPlusAggregationMFD1(self):
5556         """ Testing of MEDFileData::Aggregate and MEDFileUMesh::Aggregate and MEDFileUMesh::getAllDistributionOfType """
5557         fname1="Pyfile106_1.med"
5558         fname2="Pyfile106_2.med"
5559         fname3="Pyfile106_3.med"
5560         meshName="mesh"
5561         mm1=MEDFileUMesh()
5562         da1=DataArrayDouble([1,2,10,3,4,11,5,6,12,7,8,13],4,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5563         mm1.setCoords(da1)
5564         mm1_0=MEDCouplingUMesh(meshName,3) ; mm1_0.allocateCells()
5565         mm1_0.setCoords(da1)
5566         mm1_0.insertNextCell(NORM_TETRA4,[0,1,2,3])
5567         mm1_0.insertNextCell(NORM_TETRA4,[4,5,6,7])
5568         mm1_0.insertNextCell(NORM_PENTA6,[8,9,10,11,12,13])
5569         mm1_0.insertNextCell(NORM_PENTA6,[14,15,16,17,18,19])
5570         mm1_0.insertNextCell(NORM_PENTA6,[20,21,22,23,24,25])
5571         mm1[0]=mm1_0
5572         mm1.setFamilyFieldArr(0,DataArrayInt([1,2,3,4,5]))
5573         mm1.setRenumFieldArr(0,DataArrayInt([11,12,13,14,15]))
5574         #
5575         mm1_1=MEDCouplingUMesh(meshName,2) ; mm1_1.allocateCells()
5576         mm1_1.setCoords(da1)
5577         mm1_1.insertNextCell(NORM_TRI3,[0,1,2])
5578         mm1_1.insertNextCell(NORM_TRI3,[3,4,5])
5579         mm1_1.insertNextCell(NORM_QUAD4,[6,7,8,9])
5580         mm1_1.insertNextCell(NORM_QUAD4,[10,11,12,13])
5581         mm1_1.insertNextCell(NORM_QUAD4,[14,15,16,17])
5582         mm1_1.insertNextCell(NORM_QUAD4,[18,19,20,21])
5583         mm1[-1]=mm1_1
5584         mm1.setFamilyFieldArr(-1,DataArrayInt([6,7,8,9,10,11]))
5585         mm1.setRenumFieldArr(-1,DataArrayInt([16,17,18,19,20,21]))
5586         for i in range(1,10):
5587             mm1.setFamilyId("F%d"%i,i)
5588         mm1.setFamilyId("FAMILLE_ZERO",0)
5589         mm1.setFamilyId("H1",100)
5590         mm1.setFamiliesOnGroup("myGRP",["F2","F6"])
5591         mm1.setFamiliesOnGroup("myGRP1",["F2","F6"])
5592         mm1.setFamilyFieldArr(1,DataArrayInt([12,13,14,15]))
5593         mm1.setRenumFieldArr(1,DataArrayInt([22,23,24,25]))
5594         ##############
5595         mm2=MEDFileUMesh()
5596         da1=DataArrayDouble([9,10,30,11,12,31,13,14,32,15,16,33,17,18,34],5,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5597         mm2.setCoords(da1)
5598         mm2_0=MEDCouplingUMesh(meshName,3) ; mm2_0.allocateCells()
5599         mm2_0.setCoords(da1)
5600         mm2_0.insertNextCell(NORM_TETRA4,[100,101,102,103])
5601         mm2_0.insertNextCell(NORM_TETRA4,[104,105,106,107])
5602         mm2_0.insertNextCell(NORM_TETRA4,[108,109,110,111])
5603         mm2_0.insertNextCell(NORM_PENTA6,[112,113,114,115,116,117])
5604         mm2[0]=mm2_0
5605         mm2.setFamilyFieldArr(0,DataArrayInt([40,41,42,43]))
5606         mm2.setRenumFieldArr(0,DataArrayInt([50,51,52,53]))
5607         #
5608         mm2_1=MEDCouplingUMesh(meshName,2) ; mm2_1.allocateCells()
5609         mm2_1.setCoords(da1)
5610         mm2_1.insertNextCell(NORM_TRI3,[100,101,102])
5611         mm2_1.insertNextCell(NORM_TRI3,[103,104,105])
5612         mm2_1.insertNextCell(NORM_TRI3,[106,107,108])
5613         mm2_1.insertNextCell(NORM_QUAD4,[109,110,111,112])
5614         mm2_1.insertNextCell(NORM_QUAD4,[113,114,115,116])
5615         mm2_1.insertNextCell(NORM_QUAD4,[117,118,119,120])
5616         mm2_1.insertNextCell(NORM_QUAD4,[121,122,123,124])
5617         mm2_1.insertNextCell(NORM_QUAD4,[125,126,127,128])
5618         mm2[-1]=mm2_1
5619         mm2.setFamilyFieldArr(-1,DataArrayInt([200,201,202,203,204,205,206,207]))
5620         mm2.setRenumFieldArr(-1,DataArrayInt([300,301,302,303,304,305,306,307]))
5621         for i in range(1,12):
5622             mm2.setFamilyId("G%d"%i,i+30)
5623         mm2.setFamilyId("H1",100)
5624         mm2.setFamilyId("FAMILLE_ZERO",0)
5625         mm2.setFamiliesOnGroup("myGRP",["G2","G6"])
5626         mm2.setFamiliesOnGroup("myGRP2",["G4","G7"])
5627         mm2.setFamilyFieldArr(1,DataArrayInt([112,113,114,115,116]))
5628         mm2.setRenumFieldArr(1,DataArrayInt([122,123,124,125,126]))
5629         #
5630         mm=MEDFileUMesh.Aggregate([mm1,mm2])
5631         #######
5632         def CheckMesh(tester,mm):
5633             cooExp=DataArrayDouble([(1,2,10),(3,4,11),(5,6,12),(7,8,13),(9,10,30),(11,12,31),(13,14,32),(15,16,33),(17,18,34)]) ; cooExp.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5634             tester.assertTrue(mm.getCoords().isEqual(cooExp,1e-12))
5635             tester.assertTrue(mm[0].getNodalConnectivity().isEqual(DataArrayInt([14,0,1,2,3,14,4,5,6,7,14,104,105,106,107,14,108,109,110,111,14,112,113,114,115,16,8,9,10,11,12,13,16,14,15,16,17,18,19,16,20,21,22,23,24,25,16,116,117,118,119,120,121])))
5636             tester.assertTrue(mm[0].getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,32,39,46,53])))
5637             tester.assertTrue(mm[-1].getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,3,4,5,3,104,105,106,3,107,108,109,3,110,111,112,4,6,7,8,9,4,10,11,12,13,4,14,15,16,17,4,18,19,20,21,4,113,114,115,116,4,117,118,119,120,4,121,122,123,124,4,125,126,127,128,4,129,130,131,132])))
5638             tester.assertTrue(mm[-1].getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20,25,30,35,40,45,50,55,60,65])))
5639             tester.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([1,2,40,41,42,3,4,5,43])))
5640             tester.assertTrue(mm.getNumberFieldAtLevel(0).isEqual(DataArrayInt([11,12,50,51,52,13,14,15,53])))
5641             tester.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(DataArrayInt([6,7,200,201,202,8,9,10,11,203,204,205,206,207])))
5642             tester.assertTrue(mm.getNumberFieldAtLevel(-1).isEqual(DataArrayInt([16,17,300,301,302,18,19,20,21,303,304,305,306,307])))
5643             refFamIds=[("FAMILLE_ZERO",0),('F1',1),('F2',2),('F3',3),('F4',4),('F5',5),('F6',6),('F7',7),('F8',8),('F9',9),('G1',31),('G10',40),('G11',41),('G2',32),('G3',33),('G4',34),('G5',35),('G6',36),('G7',37),('G8',38),('G9',39),("H1",100)]
5644             tester.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
5645             tester.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
5646             tester.assertEqual(mm.getGroupsNames(),('myGRP','myGRP1','myGRP2'))
5647             tester.assertEqual(mm.getAllDistributionOfTypes(),[(NORM_TRI3,5),(NORM_QUAD4,9),(NORM_TETRA4,5),(NORM_PENTA6,4),(NORM_ERROR,9)])
5648             pass
5649         CheckMesh(self,mm)
5650         ##
5651         fieldName="zeField"
5652         t1=(2.3,3,5)
5653         t2=(5.6,7,12)
5654         infoc=["dd [W]","eee [kA]"]
5655         ##
5656         fmts1=MEDFileFieldMultiTS()
5657         f1ts1=MEDFileField1TS()
5658         f1_1=MEDCouplingFieldDouble(ON_CELLS) ; f1_1.setMesh(mm1[0]) ; f1_1.setName(fieldName)
5659         arr1=DataArrayDouble([(10,110),(11,111),(12,112),(13,113),(14,114)])
5660         arr1.setInfoOnComponents(infoc)
5661         f1_1.setArray(arr1) ; f1_1.setTime(*t1) ; f1_1.setTimeUnit("ms")
5662         f1_1.checkConsistencyLight()
5663         f1ts1.setFieldNoProfileSBT(f1_1)
5664         #
5665         f1_2=MEDCouplingFieldDouble(ON_CELLS) ; f1_2.setMesh(mm1[-1]) ; f1_2.setName(fieldName)
5666         arr2=DataArrayDouble([(15,115),(16,116),(17,117),(18,118),(19,119),(20,120)])
5667         arr2.setInfoOnComponents(infoc)
5668         f1_2.setArray(arr2) ; f1_2.setTime(*t1) ; f1_2.setTimeUnit("ms")
5669         f1_2.checkConsistencyLight()
5670         f1ts1.setFieldNoProfileSBT(f1_2)
5671         f1_3=MEDCouplingFieldDouble(ON_NODES) ; f1_3.setMesh(mm1[0]) ; f1_3.setName(fieldName)
5672         arr3=DataArrayDouble([(21,121),(22,122),(23,123),(24,124)])
5673         arr3.setInfoOnComponents(infoc)
5674         f1_3.setArray(arr3) ; f1_3.setTime(*t1) ; f1_3.setTimeUnit("ms")
5675         f1_3.checkConsistencyLight()
5676         f1ts1.setFieldNoProfileSBT(f1_3)
5677         fmts1.pushBackTimeStep(f1ts1)
5678         #
5679         f1ts2=f1ts1.deepCopy()
5680         f1ts2.setTime(t2[1],t2[2],t2[0])
5681         f1ts2.getUndergroundDataArray()[:]+=2000
5682         fmts1.pushBackTimeStep(f1ts2)
5683         ### fmts2
5684         fmts2=MEDFileFieldMultiTS()
5685         f1ts3=MEDFileField1TS()
5686         f2_1=MEDCouplingFieldDouble(ON_CELLS) ; f2_1.setMesh(mm2[0]) ; f2_1.setName(fieldName)
5687         arr4=DataArrayDouble([(50,150),(51,151),(52,152),(53,153)])
5688         arr4.setInfoOnComponents(infoc)
5689         f2_1.setArray(arr4) ; f2_1.setTime(*t1) ; f2_1.setTimeUnit("ms")
5690         f2_1.checkConsistencyLight()
5691         f1ts3.setFieldNoProfileSBT(f2_1)
5692         f2_2=MEDCouplingFieldDouble(ON_CELLS) ; f2_2.setMesh(mm2[-1]) ; f2_2.setName(fieldName)
5693         arr5=DataArrayDouble([(54,154),(55,155),(56,156),(57,157),(158,158),(59,159),(60,160),(61,161)])
5694         arr5.setInfoOnComponents(infoc)
5695         f2_2.setArray(arr5) ; f2_2.setTime(*t1) ; f2_2.setTimeUnit("ms")
5696         f2_2.checkConsistencyLight()
5697         f1ts3.setFieldNoProfileSBT(f2_2)
5698         f2_3=MEDCouplingFieldDouble(ON_NODES) ; f2_3.setMesh(mm2[0]) ; f2_3.setName(fieldName)
5699         arr6=DataArrayDouble([(62,162),(63,163),(64,164),(65,165),(66,166)])
5700         arr6.setInfoOnComponents(infoc)
5701         f2_3.setArray(arr6) ; f2_3.setTime(*t1) ; f2_3.setTimeUnit("ms")
5702         f2_3.checkConsistencyLight()
5703         f1ts3.setFieldNoProfileSBT(f2_3)
5704         fmts2.pushBackTimeStep(f1ts3)
5705         #
5706         f1ts4=f1ts3.deepCopy()
5707         f1ts4.setTime(t2[1],t2[2],t2[0])
5708         f1ts4.getUndergroundDataArray()[:]+=2000
5709         fmts2.pushBackTimeStep(f1ts4)
5710         #
5711         mfd1=MEDFileData()
5712         mfd1.setMeshes(MEDFileMeshes())
5713         mfd1.getMeshes().pushMesh(mm1)
5714         mfd1.setFields(MEDFileFields())
5715         mfd1.getFields().pushField(fmts1)
5716         #
5717         mfd2=MEDFileData()
5718         mfd2.setMeshes(MEDFileMeshes())
5719         mfd2.getMeshes().pushMesh(mm2)
5720         mfd2.setFields(MEDFileFields())
5721         mfd2.getFields().pushField(fmts2)
5722         # ze Call !
5723         mfd=MEDFileData.Aggregate([mfd1,mfd2])
5724         def CheckMFD(tester,mfd):
5725             tester.assertEqual(len(mfd.getMeshes()),1)
5726             tester.assertEqual(len(mfd.getFields()),1)
5727             CheckMesh(self,mfd.getMeshes()[0])
5728             tester.assertEqual(len(mfd.getFields()[0]),2)
5729             zeF1=mfd.getFields()[0][0]
5730             zeF1_1=zeF1.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5731             ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5732             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5733             ref.renumberCells(o2n)
5734             tester.assertTrue(ref.isEqual(zeF1_1,1e-12,1e-12))
5735             zeF1_2=zeF1.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5736             ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5737             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5738             ref.renumberCells(o2n)
5739             tester.assertTrue(ref.isEqual(zeF1_2,1e-12,1e-12))
5740             zeF1_3=zeF1.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5741             ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5742             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5743             ref.renumberCells(o2n)
5744             tester.assertTrue(ref.isEqual(zeF1_3,1e-12,1e-12))
5745             #
5746             zeF2=mfd.getFields()[0][1]
5747             zeF2_1=zeF2.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5748             ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5749             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5750             ref.renumberCells(o2n)
5751             ref.setTime(*t2) ; ref.getArray()[:]+=2000
5752             tester.assertTrue(ref.isEqual(zeF2_1,1e-12,1e-12))
5753             zeF2_2=zeF2.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5754             ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5755             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5756             ref.renumberCells(o2n)
5757             ref.setTime(*t2) ; ref.getArray()[:]+=2000
5758             tester.assertTrue(ref.isEqual(zeF2_2,1e-12,1e-12))
5759             zeF2_3=zeF2.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5760             ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5761             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5762             ref.renumberCells(o2n)
5763             ref.setTime(*t2) ; ref.getArray()[:]+=2000
5764             tester.assertTrue(ref.isEqual(zeF2_3,1e-12,1e-12))
5765         CheckMFD(self,mfd)
5766         mfd1.write(fname1,2) ; mfd2.write(fname2,2)
5767         mfd=MEDFileData.Aggregate([MEDFileData(fname1),MEDFileData(fname2)])
5768         CheckMFD(self,mfd)
5769         pass
5770
5771     def testExtrudedMesh1(self):
5772         fname="Pyfile107.med"
5773         arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5])
5774         mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ) ; mesh3D.setName("mesh")
5775         ex=MEDCouplingMappedExtrudedMesh(mesh3D)
5776         mm=MEDFileUMesh(ex)
5777         mm.write(fname,2)
5778         ex2=mm.convertToExtrudedMesh()
5779         mm2=MEDFileMesh.New(fname)
5780         ex3=mm2.convertToExtrudedMesh()
5781         self.assertTrue(ex.isEqual(ex2,1e-12))
5782         self.assertTrue(ex.isEqual(ex3,1e-12))
5783         pass
5784     
5785     @unittest.skipUnless(LooseVersion(MEDFileVersionStr())>=LooseVersion('3.2.1'),"This test requires at least MEDFile version 3.2.1")
5786     @unittest.skipUnless(LooseVersion(MEDFileVersionStr())<LooseVersion('4.0.0'),
5787                          "This test is not compatible with MEDFile version 4.0.0 and above")
5788     def testWriteInto30(self):
5789         fname="Pyfile108.med"
5790         fname2="Pyfile109.med"
5791         m=MEDCouplingUMesh("mesh",1) ; m.setCoords(DataArrayDouble([0,0,1,1],2,2)) ; m.allocateCells() ; m.insertNextCell(NORM_SEG2,[1,0])
5792         mm=MEDFileUMesh() ; mm[0]=m
5793         mm.setFamilyId("FAMILLE_ZERO",0)
5794         #
5795         mm.write30(fname,2)
5796         assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==[3,0]) # checks that just written MED file has a version == 3.0.x
5797         mm2=MEDFileUMesh(fname)
5798         self.assertTrue(mm.isEqual(mm2,1e-12))
5799         #
5800         mm.write(fname2,2)
5801         assert(LooseVersion(MEDFileVersionOfFileStr(fname2)).version[:2]==list(MEDFileVersion()[:2])) # checks that MED file version of written mesh is thoose of the current MED file lib
5802         pass
5803
5804     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
5805     def testPickelizationOfMEDFileObjects1(self):
5806         fname="Pyfile110.med"
5807         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)
5808         m0=MEDCouplingUMesh("Mesh",2)
5809         m0.allocateCells(5)
5810         m0.insertNextCell(NORM_TRI3,[1,4,2])
5811         m0.insertNextCell(NORM_TRI3,[4,5,2])
5812         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
5813         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
5814         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
5815         m0.finishInsertingCells()
5816         m0.setCoords(coo)
5817         m1=MEDCouplingUMesh(m0.getName(),1)
5818         m1.allocateCells(9)
5819         conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
5820         for i in range(9):
5821             m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
5822             pass
5823         m1.finishInsertingCells()
5824         m1.setCoords(coo)
5825         #
5826         m=MEDFileUMesh()
5827         m.setMeshAtLevel(0,m0)
5828         m.setMeshAtLevel(-1,m1)
5829         #
5830         dt=3 ; it=2 ; tim=4.5
5831         fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
5832         fieldNode0.setName("fieldNode0")
5833         fieldNode0.setTime(tim,dt,it)
5834         pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
5835         arr=DataArrayDouble([10,11,12,13,14])
5836         fieldNode0.setArray(arr)
5837         f0=MEDFileField1TS()
5838         f0.setFieldProfile(fieldNode0,m,0,pfl0)
5839         fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
5840         fieldNode1.setName("fieldNode1")
5841         fieldNode1.setTime(tim,dt,it)
5842         pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
5843         arr1=DataArrayDouble([20,21,22,23,24,25,26])
5844         fieldNode1.setArray(arr1)
5845         f1=MEDFileField1TS()
5846         f1.setFieldProfile(fieldNode1,m,-1,pfl1)
5847         mfd=MEDFileData()
5848         mfd.setMeshes(MEDFileMeshes()) ; mfd.setFields(MEDFileFields())
5849         mfd.getMeshes().pushMesh(m)
5850         fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(f0)
5851         mfd.getFields().pushField(fmts)
5852         # first start gently
5853         d=mfd.serialize()
5854         mfd2=MEDFileData(d)
5855         self.assertEqual(len(mfd2.getMeshes()),1)
5856         self.assertEqual(len(mfd2.getFields()),1)
5857         self.assertEqual(len(mfd2.getFields()[0]),1)
5858         self.assertTrue(mfd2.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
5859         ff2=mfd2.getFields()[0][0].field(mfd2.getMeshes()[0])
5860         ff =mfd.getFields()[0][0].field(mfd.getMeshes()[0])
5861         self.assertTrue(ff2.isEqual(ff,1e-12,1e-12))
5862         # OK now end of joke -> serialization of MEDFileData
5863         st=pickle.dumps(mfd,pickle.HIGHEST_PROTOCOL)
5864         mfd3=pickle.loads(st)
5865         # check of object
5866         self.assertEqual(len(mfd3.getMeshes()),1)
5867         self.assertEqual(len(mfd3.getFields()),1)
5868         self.assertEqual(len(mfd3.getFields()[0]),1)
5869         self.assertTrue(mfd3.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
5870         ff3=mfd3.getFields()[0][0].field(mfd3.getMeshes()[0])
5871         self.assertTrue(ff3.isEqual(ff,1e-12,1e-12))
5872         # serialization of MEDFileFields
5873         st=pickle.dumps(mfd.getFields(),pickle.HIGHEST_PROTOCOL)
5874         fs4=pickle.loads(st)
5875         ff4=fs4[0][0].field(mfd3.getMeshes()[0])
5876         self.assertTrue(ff4.isEqual(ff,1e-12,1e-12))
5877         # serialization of MEDFileFieldMulitTS
5878         st=pickle.dumps(mfd.getFields()[0],pickle.HIGHEST_PROTOCOL)
5879         fmts5=pickle.loads(st)
5880         ff5=fmts5[0].field(mfd3.getMeshes()[0])
5881         self.assertTrue(ff5.isEqual(ff,1e-12,1e-12))
5882         # serialization of MEDFileField1TS
5883         st=pickle.dumps(mfd.getFields()[0][0],pickle.HIGHEST_PROTOCOL)
5884         f1ts6=pickle.loads(st)
5885         ff6=f1ts6.field(mfd3.getMeshes()[0])
5886         self.assertTrue(ff6.isEqual(ff,1e-12,1e-12))
5887         # serialization of MEDFileMeshes
5888         st=pickle.dumps(mfd.getMeshes(),pickle.HIGHEST_PROTOCOL)
5889         ms7=pickle.loads(st)
5890         self.assertEqual(len(ms7),1)
5891         self.assertTrue(ms7[0].isEqual(mfd.getMeshes()[0],1e-12))
5892         pass
5893
5894     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
5895     def testPickelizationOfMEDFileObjects2(self):
5896         # CMesh
5897         self.testMEDMesh6() # generates MEDFileMesh5.med file
5898         mm=MEDFileMesh.New("MEDFileMesh5.med")
5899         self.assertTrue(isinstance(mm,MEDFileCMesh))
5900         st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
5901         mm2=pickle.loads(st)
5902         self.assertTrue(isinstance(mm2,MEDFileCMesh))
5903         self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12))
5904         # CurveLinear
5905         self.testCurveLinearMesh1() # generates Pyfile55.med
5906         mm=MEDFileMesh.New("Pyfile55.med")
5907         self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh))
5908         st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
5909         mm3=pickle.loads(st)
5910         self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh))
5911         self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12))
5912         self.testInt32InMEDFileFieldStar1()# generates Pyfile63.med
5913         # MEDFileIntFieldMultiTS
5914         fs4=MEDFileFields("Pyfile63.med")
5915         ms4=MEDFileMeshes("Pyfile63.med")
5916         self.assertTrue(isinstance(fs4[0],MEDFileIntFieldMultiTS))
5917         st=pickle.dumps(fs4[0],pickle.HIGHEST_PROTOCOL)
5918         fmts5=pickle.loads(st)
5919         self.assertEqual(len(fs4[0]),len(fmts5))
5920         self.assertTrue(isinstance(fmts5,MEDFileIntFieldMultiTS))
5921         self.assertTrue(fmts5[0].field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
5922         # MEDFileIntField1TS
5923         st=pickle.dumps(fs4[0][0],pickle.HIGHEST_PROTOCOL)
5924         f1ts6=pickle.loads(st)
5925         self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS))
5926         self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
5927         # MEDFileParameters
5928         self.testParameters1()# generates Pyfile56.med
5929         params=MEDFileParameters("Pyfile56.med")
5930         st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL)
5931         params7=pickle.loads(st)
5932         self.assertEqual(len(params),len(params7))
5933         for i in range(len(params)):
5934             self.assertTrue(params[i].isEqual(params7[i],1e-12)[0])
5935             pass
5936         pass
5937
5938     def testGlobalNumOnNodes1(self):
5939         """Test global number on nodes here. Used by partitionners."""
5940         fname="Pyfile112.med"
5941         arr=DataArrayDouble(5) ; arr.iota()
5942         m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
5943         m.setName("mesh")
5944         mm=MEDFileUMesh()
5945         mm[0]=m
5946         self.assertTrue(not mm.getGlobalNumFieldAtLevel(1))
5947         d=DataArrayInt([7,8,9,2,0])
5948         dRef=d.deepCopy()
5949         mm.setGlobalNumFieldAtLevel(1,d)
5950         mm.checkConsistency()
5951         self.assertRaises(InterpKernelException,mm.setGlobalNumFieldAtLevel,1,d[::2])
5952         mm.checkConsistency()
5953         self.assertEqual(d.getHiddenCppPointer(),mm.getGlobalNumFieldAtLevel(1).getHiddenCppPointer())
5954         self.assertTrue(mm.getGlobalNumFieldAtLevel(1).isEqual(dRef))
5955         mm.write(fname,2)
5956         mm2=MEDFileMesh.New(fname)
5957         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
5958         self.assertTrue(mm2.getGlobalNumFieldAtLevel(1).isEqual(dRef))
5959         mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,10)
5960         self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
5961         mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,7)
5962         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
5963         pass
5964
5965     def testPartialReadOfEntities1(self):
5966         """Test for advanced API on read to speed up read phase for users with "huge" number of time steps (more than 10 000)."""
5967         fname="Pyfile113.med"
5968         arr=DataArrayDouble(5) ; arr.iota()
5969         m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
5970         m.setName("mesh")
5971         mm=MEDFileUMesh()
5972         mm[0]=m
5973         #
5974         fieldName="Field"
5975         ts1=(5.,1,2)
5976         f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m) ; f1.setName(fieldName)
5977         f1.setArray(DataArrayDouble([0.,0.1,0.2,0.3,0.4]))
5978         f1.setTime(*ts1)
5979         f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m) ; f2.setName(fieldName)
5980         f2.setArray(DataArrayDouble([1.,1.1,1.2,1.3]))
5981         f2.setTime(*ts1)
5982         f1ts=MEDFileField1TS()
5983         f1ts.setFieldNoProfileSBT(f1)
5984         f1ts.setFieldNoProfileSBT(f2)
5985         self.assertEqual(set(f1ts.getTypesOfFieldAvailable()),set([ON_NODES,ON_CELLS]))
5986         f1ts_2=f1ts.deepCopy()
5987         f1ts_2.getUndergroundDataArray()[:]+=2
5988         f1ts_2.setTime(3,4,6.)
5989         fmts=MEDFileFieldMultiTS()
5990         fmts.pushBackTimeStep(f1ts)
5991         fmts.pushBackTimeStep(f1ts_2)
5992         #
5993         mm.write(fname,2)
5994         fmts.write(fname,0)
5995         #
5996         ent=MEDFileEntities.BuildFrom([(ON_NODES,NORM_ERROR)])
5997         mm=MEDFileMesh.New(fname)
5998         fs=MEDFileFields(fname,False,ent) # the important line is here - We specify to MEDFileFields to read only nodes part to speed up read phase (by avoiding to scan all entities time geo types)
5999         fs.loadArrays()
6000         self.assertEqual(len(fs),1)
6001         fmts=fs[0]
6002         self.assertEqual(len(fmts),2)
6003         ff0=fmts[0] ; ff1=fmts[1]
6004         self.assertEqual(ff0.getTypesOfFieldAvailable(),[ON_NODES]) # only NODES have been loaded
6005         self.assertTrue(ff0.field(mm).isEqual(f1,1e-12,1e-12))
6006         f3=f1.deepCopy() ; f3+=2. ; f3.setTime(6.,3,4)
6007         self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
6008         pass
6009     
6010     def testFloat32InMEDFileFieldStar1(self):
6011         """Like testInt32InMEDFileFieldStar1 but with float32 :)"""
6012         fname="Pyfile114.med"
6013         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
6014         f1=f1.convertToFloatField()
6015         m1=f1.getMesh()
6016         mm1=MEDFileUMesh.New()
6017         mm1.setCoords(m1.getCoords())
6018         mm1.setMeshAtLevel(0,m1)
6019         mm1.setName(m1.getName())
6020         mm1.write(fname,2)
6021         ff1=MEDFileFloatField1TS()
6022         ff1.setFieldNoProfileSBT(f1)
6023         a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6024         self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6025         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6026         ff1.write(fname,0)
6027         a,b=ff1.getUndergroundDataArrayExt()
6028         self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
6029         self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
6030         ff2=MEDFileAnyTypeField1TS.New(fname)
6031         self.assertEqual(ff2.getName(),"VectorFieldOnCells")
6032         self.assertEqual(ff2.getTime(),[0,1,2.0])
6033         self.assertTrue(isinstance(ff2,MEDFileFloatField1TS))
6034         a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6035         self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6036         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6037         ff2.setTime(1,2,3.)
6038         c=ff2.getUndergroundDataArray() ; c*=2
6039         ff2.write(fname,0) # 2 time steps in 
6040         ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
6041         self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
6042         self.assertEqual(len(ffs1),2)
6043         self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS))
6044         a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6045         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6046         a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
6047         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6048         it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
6049         a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6050         self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7))
6051         f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
6052         self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2
6053         bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6054         for it in ffs1:
6055             a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6056             bc+=a.getArray()
6057             pass
6058         self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7))
6059         nf1=MEDCouplingFieldFloat(ON_NODES)
6060         nf1.setTime(9.,10,-1)
6061         nf1.setMesh(f1.getMesh())
6062         narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
6063         nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
6064         nff1=MEDFileFloatField1TS.New()
6065         nff1.setFieldNoProfileSBT(nf1)
6066         self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
6067         self.assertEqual(nff1.getTime(),[10,-1,9.0])
6068         nff1.write(fname,0)
6069         #
6070         nf2=MEDCouplingFieldFloat(ON_NODES)
6071         nf2.setTime(19.,20,-11)
6072         nf2.setMesh(f1.getMesh())
6073         narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10  ; narr2[:,1]=3*narr2[:,0]
6074         nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
6075         nff2=MEDFileFloatField1TS.New()
6076         npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
6077         nff2.setFieldProfile(nf2,mm1,0,npfl)
6078         nff2.getFieldWithProfile(ON_NODES,0,mm1)
6079         a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6080         self.assertTrue(b.isEqual(npfl))
6081         self.assertTrue(a.isEqual(narr2,1e-7))
6082         nff2.write(fname,0)
6083         nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl")
6084         a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6085         self.assertTrue(b.isEqual(npfl))
6086         self.assertTrue(a.isEqual(narr2,1e-7))
6087         #
6088         nf3=MEDCouplingFieldDouble(ON_NODES)
6089         nf3.setName("VectorFieldOnNodesDouble")
6090         nf3.setTime(29.,30,-21)
6091         nf3.setMesh(f1.getMesh())
6092         nf3.setArray(f1.getMesh().getCoords())
6093         nff3=MEDFileField1TS.New()
6094         nff3.setFieldNoProfileSBT(nf3)
6095         nff3.write(fname,0)
6096         fs=MEDFileFields(fname)
6097         self.assertEqual(len(fs),4)
6098         ffs=[it for it in fs]
6099         self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS))
6100         self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS))
6101         self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
6102         self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS))
6103         #
6104         self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7))
6105         self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7))
6106         self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7))
6107         self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7))
6108         self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6109         #
6110         nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
6111         self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6112         self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
6113         self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
6114         MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
6115         self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
6116         MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1)
6117         self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
6118         #
6119         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
6120         self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6121         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
6122         self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6123         pass
6124
6125     def testPenta18_1(self):
6126         """EDF8478 : Test of read/write of penta18"""
6127         fname="Pyfile115.med"
6128         arr=DataArrayDouble([
6129             (0.,1.,1.),(0.,0.,1.),(1.,0.,1.),
6130             (0.,1.,0.),(0.,0.,0.),(1.,0.,0.),
6131             (0.,0.5,1.),(0.5,0.,1.),(0.5,0.5,1.),
6132             (0.,0.5,0.),(0.5,0.,0.),(0.5,0.5,0.),
6133             (0.,1.,0.5),(0.,0.,0.5),(1.,0.,0.5),
6134             (0.,0.5,0.5),(0.5,0.,0.5),(0.5,0.5,0.5)])
6135         m=MEDCouplingUMesh("mesh",3)
6136         m.setCoords(arr)
6137         m.allocateCells(1)
6138         m.insertNextCell(NORM_PENTA18,list(range(18)))
6139         m.checkConsistencyLight()
6140         #
6141         f=MEDCouplingFieldDouble(ON_NODES)
6142         f.setMesh(m)
6143         f.setName("FieldOnPenta18")
6144         f.setArray(DataArrayDouble(list(range(18))))
6145         f.checkConsistencyLight()
6146         #
6147         m2,d,di,rd,rdi=m.buildDescendingConnectivity()
6148         #
6149         f2=MEDCouplingFieldDouble(ON_NODES)
6150         f2.setMesh(m)
6151         f2.setName("FieldOnPenta18Sub")
6152         f2.setArray(DataArrayDouble(list(range(18))))
6153         f2.checkConsistencyLight()
6154         WriteField(fname,f2,True)
6155         f3=ReadField(fname)
6156         self.assertTrue(f2.isEqual(f3,1e-12,1e-12))
6157         self.assertEqual(f3.getMesh().getNumberOfCells(),1)
6158         self.assertEqual(f3.getMesh().getTypeOfCell(0),NORM_PENTA18)
6159         pass
6160
6161     @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
6162     @unittest.skipUnless(LooseVersion(MEDFileVersionStr())<LooseVersion('4.0.0'),
6163                          "This test is not compatible with MEDFile version 4.0.0 and above")
6164     def testMedFileCapabilityToCryOnNewFeatureWritingIntoOldFiles(self):
6165         fname="Pyfile116.med"
6166         errfname="Pyfile116.err"
6167         c=DataArrayDouble([0,1,2,3])
6168         m=MEDCouplingCMesh()
6169         m.setCoords(c,c)
6170         m=m.buildUnstructured()
6171         m.setName("mesh")
6172         mm=MEDFileUMesh()
6173         mm[0]=m
6174         f=MEDCouplingFieldInt(ON_CELLS)
6175         f.setMesh(m) ; arr2=DataArrayInt(m.getNumberOfCells()) ; arr2.iota()
6176         f.setArray(arr2)
6177         f.setName("field")
6178         f1ts=MEDFileIntField1TS()
6179         f1ts.setFieldNoProfileSBT(f)
6180         mm.write30(fname,2)
6181         f1ts.write30(fname,0)
6182         #
6183         f=MEDCouplingFieldFloat(ON_CELLS)
6184         f.setMesh(m) ; arr2=DataArrayFloat(m.getNumberOfCells()) ; arr2.iota()
6185         f.setArray(arr2)
6186         f.setName("field2")
6187         f1ts=MEDFileFloatField1TS()
6188         f1ts.setFieldNoProfileSBT(f)
6189         #
6190         import os,gc
6191         tmp=StdOutRedirect(errfname)
6192         self.assertRaises(InterpKernelException,f1ts.write30,fname,0)
6193         del tmp
6194         gc.collect(0)
6195         if os.path.exists(errfname):
6196             os.remove(errfname)
6197         pass
6198
6199     def testFieldsLinearToQuadratic(self):
6200         fname="Pyfile117.med"
6201         arr=DataArrayDouble([0,1])
6202         m=MEDCouplingCMesh();
6203         m.setCoords(arr,arr,arr)
6204         m=m.buildUnstructured()
6205         m2=m.deepCopy()
6206         m2.translate([2,0,0])
6207         m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6208         m3.setName("mesh")
6209         mm=MEDFileUMesh()
6210         mm[0]=m3
6211         mmq=mm.linearToQuadratic(0)
6212         mms=MEDFileMeshes() ; mms.pushMesh(mm)
6213         mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6214         #
6215         f=MEDCouplingFieldDouble(ON_NODES)
6216         f.setName("field")
6217         f.setMesh(m3)
6218         f.setTime(3.,1,2)
6219         arr=DataArrayDouble(m3.getNumberOfNodes())
6220         arr.iota()
6221         f.setArray(arr)
6222         f1ts=MEDFileField1TS()
6223         f1ts.setFieldNoProfileSBT(f)
6224         fmts=MEDFileFieldMultiTS()
6225         fmts.pushBackTimeStep(f1ts)
6226         f1ts_2=f1ts.deepCopy()
6227         f1ts_2.setTime(3,4,5.)
6228         f1ts_2.getUndergroundDataArray()[:]*=2.
6229         fmts.pushBackTimeStep(f1ts_2)
6230         fs=MEDFileFields()
6231         fs.pushField(fmts)
6232         fs2=fs.linearToQuadratic(mms,mmsq)
6233         self.myTester1(fs2,mmsq[0])
6234         # A small Write/Read and test again
6235         mms.write(fname,2) ; fs.write(fname,0)
6236         mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6237         mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6238         fs2=fs.linearToQuadratic(mms,mmqs)
6239         self.myTester1(fs2,mmqs[0])
6240         pass
6241     
6242     def myTester1(self,fs2,mmq):
6243         dataExp=DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.,1.,1.,0.,0.,0.,1.,1.,0.,1.,0.,1.,1.,1.,1.,1.,2.,0.,0.,3.,0.,0.,2.,1.,0.,3.,1.,0.,2.,0.,1.,3.,0.,1.,2.,1.,1.,3.,1.,1.,0.5, 0.,0.,0.,0.5, 0.,0.5, 1.,0.,1.,0.5, 0.,0.5, 0.,1.,0.,0.5, 1.,0.5, 1.,1.,1.,0.5, 1.,1.,0.,0.5, 0.,0.,0.5, 0.,1.,0.5, 1.,1.,0.5, 2.5, 0.,0.,2.,0.5, 0.,2.5, 1.,0.,3.,0.5, 0.,2.5, 0.,1.,2.,0.5, 1.,2.5, 1.,1.,3.,0.5, 1.,3.,0.,0.5, 2.,0.,0.5, 2.,1.,0.5, 3.,1.,0.5],40,3)
6244         dataExp1=DataArrayInt([1,0,2,3,5,4,6,7,16,17,18,19,20,21,22,23,24,25,26,27,9,8,10,11,13,12,14,15,28,29,30,31,32,33,34,35,36,37,38,39])
6245         dataExp2=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0.5,1,2.5,2,4.5,5,6.5,6,3,2,4,5,8.5,9,10.5,10,12.5,13,14.5,14,11,10,12,13])
6246         fToTest=fs2[0][0].field(mmq)
6247         self.assertEqual(fToTest.getTime(),[3.,1,2])
6248         mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6249         self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6250         self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6251         self.assertTrue(fToTest.getArray().isEqual(dataExp2,1e-12))
6252         # testing 2nd timestep
6253         fToTest=fs2[0][1].field(mmq)
6254         self.assertEqual(fToTest.getTime(),[5.,3,4])
6255         mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6256         self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6257         self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6258         self.assertTrue(fToTest.getArray().isEqual(2*dataExp2,1e-12))
6259         pass
6260
6261     def testFieldsLinearToQuadratic2(self):
6262         """Same than testFieldsLinearToQuadratic but with profile on NODES"""
6263         fname="Pyfile118.med"
6264         arr=DataArrayDouble([0,1])
6265         m=MEDCouplingCMesh();
6266         m.setCoords(arr,arr,arr)
6267         m=m.buildUnstructured()
6268         m2=m.deepCopy()
6269         m2.translate([2,0,0])
6270         m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6271         m3.setName("mesh")
6272         # add a point for fun
6273         m3.setCoords(DataArrayDouble.Aggregate(m3.getCoords(),DataArrayDouble([1.5,1.5,1.5],1,3)))
6274         #
6275         mm=MEDFileUMesh()
6276         mm[0]=m3
6277         mmq=mm.linearToQuadratic(0)
6278         mms=MEDFileMeshes() ; mms.pushMesh(mm)
6279         mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6280         #
6281         f=MEDCouplingFieldDouble(ON_NODES)
6282         f.setName("field")
6283         f.setMesh(m3)
6284         f.setTime(3.,1,2)
6285         arr=DataArrayDouble(8) ; arr.iota()
6286         arr.iota()
6287         f.setArray(arr)
6288         f1ts=MEDFileField1TS()
6289         pfl=DataArrayInt([8,9,10,11,12,13,14,15]) ; pfl.setName("pfl")
6290         f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 8 nodes of cell #1
6291         f1ts_2=f1ts.deepCopy()
6292         f1ts_2.setTime(3,4,5.)
6293         f1ts_2.getUndergroundDataArray()[:]*=4.
6294         fmts=MEDFileFieldMultiTS()
6295         fmts.pushBackTimeStep(f1ts)
6296         fmts.pushBackTimeStep(f1ts_2)
6297         fs=MEDFileFields()
6298         fs.pushField(fmts)
6299         fs2=fs.linearToQuadratic(mms,mmsq)
6300         mms.write(fname,2) ; fs.write(fname,0)
6301         #
6302         self.myTester2(fs2,mmq)
6303         # Read/write
6304         mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6305         mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6306         fs2=fs.linearToQuadratic(mms,mmqs)
6307         self.myTester2(fs2,mmq)
6308         ## More vicious add single node 16
6309         mm=MEDFileUMesh()
6310         mm[0]=m3
6311         mmq=mm.linearToQuadratic(0)
6312         mms=MEDFileMeshes() ; mms.pushMesh(mm)
6313         mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6314         #
6315         f=MEDCouplingFieldDouble(ON_NODES)
6316         f.setName("field")
6317         f.setMesh(m3)
6318         f.setTime(3.,1,2)
6319         arr=DataArrayDouble(9) ; arr.iota()
6320         arr.iota()
6321         f.setArray(arr)
6322         f1ts=MEDFileField1TS()
6323         pfl=DataArrayInt([8,9,10,11,12,13,14,15,16]) ; pfl.setName("pfl")
6324         f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 9 nodes of cell #1 + orphan node
6325         fmts=MEDFileFieldMultiTS()
6326         fmts.pushBackTimeStep(f1ts)
6327         fs=MEDFileFields()
6328         fs.pushField(fmts)
6329         fs2=fs.linearToQuadratic(mms,mmsq)
6330         #
6331         pflExpected=DataArrayInt([8,9,10,11,12,13,14,15,16,29,30,31,32,33,34,35,36,37,38,39,40]) ; pflExpected.setName("pfl_NODE")
6332         f1tsToTest=fs2[0][0]
6333         exp1=DataArrayDouble([0,1,2,3,4,5,6,7,8,0.5,1,2.5,2,4.5,5,6.5,6,3,2,4,5])
6334         assert(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6335         assert(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6336         assert(f1tsToTest.getFieldSplitedByType()==[(40,[(1,(0,21),'pfl_NODE','')])])
6337         pass
6338
6339     def myTester2(self,fs2,mmq):
6340         pflExpected=DataArrayInt([8,9,10,11,12,13,14,15,29,30,31,32,33,34,35,36,37,38,39,40]) ; pflExpected.setName("pfl_NODE")
6341         f1tsToTest=fs2[0][0]
6342         exp1=DataArrayDouble([0,1,2,3,4,5,6,7,0.5,1,2.5,2,4.5,5,6.5,6,3,2,4,5])
6343         self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6344         self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6345         self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6346         fToTest=fs2[0][0].field(mmq)
6347         self.assertEqual(fToTest.getTime(),[3.,1,2])
6348         mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6349         self.assertTrue(mTest.getNodalConnectivity().isEqual(DataArrayInt([1,0,2,3,5,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19])))
6350         self.assertTrue(mTest.getCoords().isEqual(DataArrayDouble([(2,0,0),(3,0,0),(2,1,0),(3,1,0),(2,0,1),(3,0,1),(2,1,1),(3,1,1),(2.5,0,0),(2,0.5,0),(2.5,1,0),(3,0.5,0),(2.5,0,1),(2,0.5,1),(2.5,1,1),(3,0.5,1),(3,0,0.5),(2,0,0.5),(2,1,0.5),(3,1,0.5)],20,3),1e-12))
6351         self.assertTrue(fToTest.getArray().isEqual(exp1,1e-12))
6352         # 2nd Time step
6353         f1tsToTest=fs2[0][1]
6354         self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6355         self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(4*exp1,1e-12))
6356         self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6357         fToTest=fs2[0][1].field(mmq)
6358         self.assertEqual(fToTest.getTime(),[5.,3,4])
6359         mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6360         self.assertTrue(mTest.getNodalConnectivity().isEqual(DataArrayInt([1,0,2,3,5,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19])))
6361         self.assertTrue(mTest.getCoords().isEqual(DataArrayDouble([(2,0,0),(3,0,0),(2,1,0),(3,1,0),(2,0,1),(3,0,1),(2,1,1),(3,1,1),(2.5,0,0),(2,0.5,0),(2.5,1,0),(3,0.5,0),(2.5,0,1),(2,0.5,1),(2.5,1,1),(3,0.5,1),(3,0,0.5),(2,0,0.5),(2,1,0.5),(3,1,0.5)],20,3),1e-12))
6362         self.assertTrue(fToTest.getArray().isEqual(4*exp1,1e-12))
6363         
6364         pass
6365     
6366     pass
6367
6368 if __name__ == "__main__":
6369     unittest.main()