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