]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/Swig/MEDLoaderTest3.py
Salome HOME
Non reg test linked to previous commit
[tools/medcoupling.git] / src / MEDLoader / Swig / MEDLoaderTest3.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2020  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         delta = (m.getHeapMemorySize()-meshMem)//3 # std::string::capacity behaves differently
2265         self.assertIn(f.getHeapMemorySize(), list(range(meshMem + 81*8 - (100 + 3*delta), meshMem + 81*8 + (100+3*delta) + 8 * strMulFac)))
2266         #
2267         mm=MEDFileUMesh()
2268         mm.setMeshAtLevel(0,m)
2269         self.assertIn(mm.getHeapMemorySize(), list(range(meshMem + 81*(MEDCouplingSizeOfIDs()//8) - (100+3*delta), meshMem + 81*(MEDCouplingSizeOfIDs()//8) + (100+3*delta) + 10 * strMulFac)))
2270         ff=MEDFileField1TS()
2271         ff.setFieldNoProfileSBT(f)
2272         self.assertIn(ff.getHeapMemorySize(), list(range(771 - 40, 871 + 21 + (4 + 1) * strMulFac)))
2273         #
2274         fff=MEDFileFieldMultiTS()
2275         fff.appendFieldNoProfileSBT(f)
2276         self.assertIn(fff.getHeapMemorySize(), list(range(815 - 50, 915 + 30 + (6 + 2) * strMulFac)))
2277         f.setTime(1.,0,-1)
2278         fff.appendFieldNoProfileSBT(f)
2279         self.assertIn(fff.getHeapMemorySize(), list(range(1594 - 90, 1794 + 50 + (10 + 1) * strMulFac)))
2280         self.assertIn(fff[0, -1].getHeapMemorySize(), list(range(771 - 40, 871 + 20 + (4 + 1) * strMulFac)))
2281         f2=f[:50]
2282         f2.setTime(2.,1,-1)
2283         pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2284         fff.appendFieldProfile(f2,mm,0,pfl)
2285         self.assertIn(fff.getHeapMemorySize(), range(2348 - 130, 2608 + 400 + (10 + 2) * strMulFac))
2286         self.assertIn(fff.getProfile("pfl").getHeapMemorySize(), list(range(50 *(MEDCouplingSizeOfIDs()//8) - 10, 50 *(MEDCouplingSizeOfIDs()//8) + 10 + 2 * strMulFac)))
2287         self.assertIn(fff[1, -1].getHeapMemorySize(), range(538 + (50 *(MEDCouplingSizeOfIDs()//8)) - 50, 900 + (50 *(MEDCouplingSizeOfIDs()//8))  + 30 + 4 * strMulFac))
2288         pass
2289
2290     def internalCurveLinearMesh1(self):
2291         fname="Pyfile55.med"
2292         mesh=MEDCouplingCurveLinearMesh();
2293         mesh.setTime(2.3,4,5);
2294         mesh.setTimeUnit("us");
2295         mesh.setName("Example of Cuve linear mesh");
2296         mesh.setDescription("buildCLMesh");
2297         a1=DataArrayDouble(3*20,1);
2298         a1.iota(7.) ; a1.rearrange(3);
2299         mesh.setCoords(a1);
2300         mesh.setNodeGridStructure([4,5]);
2301         mesh.checkConsistencyLight();
2302         #
2303         m=MEDFileCurveLinearMesh()
2304         m.setMesh(mesh)
2305         d=DataArrayInt(20) ; d.iota(4)
2306         m.setFamilyFieldArr(1,d)
2307         d3=DataArrayInt(20) ; d3.iota(400)
2308         m.setRenumFieldArr(1,d3)
2309         d2=DataArrayInt(12) ; d2.iota(40)
2310         m.setFamilyFieldArr(0,d2)
2311         d4=DataArrayInt(21) ; d4.iota(4000)
2312         self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2313         d4.popBackSilent()
2314         m.setRenumFieldArr(1,d4)
2315         m.write(fname,2)
2316         #
2317         m1=MEDFileCurveLinearMesh(fname)
2318         mm=m1.getMesh()
2319         self.assertTrue(mm.isEqual(mesh,1e-12))
2320         self.assertEqual(mm.getSpaceDimension(),3)
2321         self.assertEqual(mm.getSpaceDimensionOnNodeStruct(),2)
2322         #
2323         m1=MEDFileMesh.New(fname)
2324         self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2325         self.assertTrue(isinstance(m1.getUnivName(),str))
2326         self.assertTrue(len(m1.getUnivName())!=0)
2327         self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2328         pass
2329
2330     @WriteInTmpDir
2331     def testCurveLinearMesh1(self):
2332         self.internalCurveLinearMesh1()
2333
2334     @WriteInTmpDir
2335     def testParameters1(self):
2336         self.internalParameters1()
2337
2338     def internalParameters1(self):
2339         fname="Pyfile56.med"
2340         m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2341         mm=MEDFileCMesh() ; mm.setMesh(m)
2342         ms=MEDFileMeshes() ; ms.pushMesh(mm)
2343         data=MEDFileData()
2344         p=MEDFileParameters()
2345         data.setParams(p) ; data.setMeshes(ms)
2346         pts=MEDFileParameterMultiTS()
2347         pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2348         pts.appendValue(1,2,3.4,567.89)
2349         pts.appendValue(2,3,5.6,999.123)
2350         pts2=pts.deepCopy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2351         p.pushParam(pts) ; p.pushParam(pts2)
2352         data.write(fname,2)
2353         p2=MEDFileParameters(fname)
2354         self.assertTrue(p.isEqual(p2,1e-14)[0])
2355         self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2356         p3=p.deepCopy()
2357         pts4=pts2.deepCopy()
2358         pts3=pts2.deepCopy()
2359         self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2360         pts2.eraseTimeStepIds([0])
2361         self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2362         del pts3[[3.4]]
2363         self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2364         self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2365         self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2366         self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2367         self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2368         p=p3
2369         self.assertTrue(p.isEqual(p2,1e-14)[0])
2370         self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2371         self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2372         self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2373         self.assertEqual(p.getParamsNames(),('A','B'))
2374         ptsr=MEDFileParameterMultiTS(fname,"B")
2375         self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2376         ptsr=MEDFileParameterMultiTS(fname)
2377         self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2378         p1tsr=MEDFileParameterDouble1TS(fname)
2379         self.assertEqual(p1tsr.getName(),"A")
2380         self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2381         p1tsr=MEDFileParameterDouble1TS(fname,"B")
2382         self.assertEqual(p1tsr.getName(),"B")
2383         self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2384         p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2385         self.assertEqual(p1tsr.getName(),"B")
2386         self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2387         data2=MEDFileData(fname)
2388         self.assertEqual(2,data2.getNumberOfParams())
2389         self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2390         pass
2391
2392     @WriteInTmpDir
2393     def testNamesOnCellAndNodesInMeshes1(self):
2394         fname="Pyfile58.med"
2395         fname2="Pyfile59.med"
2396         m=MEDLoaderDataForTest.build3DSurfMesh_1()
2397         m1=m.buildDescendingConnectivity()[0]
2398         m1.sortCellsInMEDFileFrmt()
2399         #
2400         mm=MEDFileUMesh()
2401         mm.setMeshAtLevel(0,m)
2402         mm.setMeshAtLevel(-1,m1)
2403         namesCellL0=DataArrayAsciiChar(6,16)
2404         namesCellL0[:] = ["CellL0#%.3d      " % (i) for i in range(6)]
2405         mm.setNameFieldAtLevel(0,namesCellL0)
2406         namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.subArray(2)])
2407         namesCellL1[:] = ["CellLM1#%.3d     " % (i) for i in range(16)]
2408         mm.setNameFieldAtLevel(-1,namesCellL1)
2409         namesNodes=namesCellL1.subArray(4,16)
2410         namesNodes[:] = ["Node#%.3d        " % (i) for i in range(12)]
2411         mm.setNameFieldAtLevel(1,namesNodes)
2412         mm.write(fname,2)
2413         #
2414         mmr=MEDFileMesh.New(fname)
2415         self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d      " % (i) for i in range(6)])))
2416         self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d     " % (i) for i in range(16)])))
2417         self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d        " % (i) for i in range(12)])))
2418         self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2419         mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2420         self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2421         mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2422         self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2423         mmCpy=mm.deepCopy()
2424         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2425         # remove names on nodes
2426         mmCpy.setNameFieldAtLevel(1,None)
2427         self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2428         mm.setNameFieldAtLevel(1,None)
2429         self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2430         mm.setNameFieldAtLevel(-1,None)
2431         mm.write(fname,2)
2432         mmr=MEDFileMesh.New(fname)
2433         self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2434         self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d      " % (i) for i in range(6)])))
2435         self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2436         #
2437         c=MEDCouplingCMesh()
2438         arr=DataArrayDouble([0.,1.1,2.3])
2439         c.setCoords(arr,arr)
2440         c.setName("cmesh")
2441         cc=MEDFileCMesh()
2442         cc.setMesh(c)
2443         cc.setNameFieldAtLevel(0, DataArrayAsciiChar(["Cell#%.3d        " % (i) for i in range(4)]))
2444         cc.setNameFieldAtLevel(1, DataArrayAsciiChar(["Node#%.3d        " % (i) for i in range(9)]))
2445         cc.write(fname2,2)
2446         ccr=MEDFileMesh.New(fname2)
2447         self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d        " % (i) for i in range(4)])))
2448         self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d        " % (i) for i in range(9)])))
2449         self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2450         ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2451         self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2452         ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2453         self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2454         ccCpy=cc.deepCopy()
2455         self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2456         pass
2457
2458     @WriteInTmpDir
2459     def testToExportInExamples1(self):
2460         m=MEDCouplingCMesh()
2461         arr=DataArrayDouble([0.,1.,2.,3.,4.])
2462         m.setCoords(arr,arr)
2463         m=m.buildUnstructured() ; m.setName("mesh")
2464         grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2465         grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2466         m2=m.computeSkin()
2467         mm=MEDFileUMesh()
2468         mm.setMeshAtLevel(0,m)
2469         mm.setMeshAtLevel(-1,m2)
2470         mm.setGroupsAtLevel(0,[grp1,grp2])
2471         mm.write("example.med",2)
2472         #
2473         m0=mm.getMeshAtLevel(0)
2474         m1=mm.getMeshAtLevel(-1)
2475         grp1=mm.getGroupArr(0,"grp1")
2476         grp2=mm.getGroupArr(0,"grp2")
2477         grps=[grp1,grp2]
2478         whichGrp=DataArrayInt(m0.getNumberOfCells())
2479         whichGrp.fillWithValue(-1)
2480         for grpId,grp in enumerate(grps):
2481             whichGrp[grp]=grpId
2482             pass
2483         a,b,bI,c,cI=m0.buildDescendingConnectivity()
2484         e,f=a.areCellsIncludedIn(m1,2)
2485         self.assertTrue(e)
2486         c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2487         self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2488         c2.transformWithIndArr(whichGrp)
2489         splitOfM1=len(grps)*[None]
2490         for grpId,grp in enumerate(grps):
2491             tmp=c2.findIdsEqual(grpId)
2492             splitOfM1[grpId]=tmp
2493             pass
2494         splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2495         splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2496         pass
2497
2498     @WriteInTmpDir
2499     def testBugCorrection1(self):
2500         fs=MEDFileFields()
2501         fs.resize(3)
2502         self.assertEqual(fs[0],None)
2503         self.assertEqual(3,len(fs))
2504         pass
2505
2506     @WriteInTmpDir
2507     def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2508         f1Name="Pyfile60.med"
2509         f2Name="Pyfile61.med"
2510         d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2511         d1.write(f1Name,2)
2512         d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2513         d2.write(f2Name,2)
2514         # reading and compare
2515         d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2516         for mn in d1.getMeshes().getMeshesNames():
2517             m1=d1.getMeshes()[mn]
2518             m2=d2.getMeshes()[mn]
2519             for lev in m1.getNonEmptyLevels():
2520                 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2521                 for grpName in grpsNames:
2522                     self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2523                     pass
2524                 pass
2525             pass
2526         for fieldn in d1.getFields().getFieldsNames():
2527             f1=d1.getFields()[fieldn]
2528             f2=d2.getFields()[fieldn]
2529             for it,order,tim in f1.getTimeSteps():
2530                 f1t=f1[it,order]
2531                 f2t=f2[it,order]
2532                 if len(f1t.getPflsReallyUsed())!=0:
2533                     # profile case
2534                     for lev in f1t.getNonEmptyLevels()[1]:
2535                         arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2536                         arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2537                         self.assertTrue(pfl1.isEqual(pfl2))
2538                         self.assertTrue(arr1.isEqual(arr2,1e-10))
2539                         pass
2540                     pass
2541                 else:
2542                     # no profile case
2543                     for lev in f1t.getNonEmptyLevels()[1]:
2544                         f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2545                         f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2546                         self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2547                         pass
2548                     pass
2549                 pass
2550             pass
2551         pass
2552
2553     @WriteInTmpDir
2554     def testNonRegBugNormalizeFamIdsMEDFile1(self):
2555         m=MEDCouplingCMesh()
2556         arr=DataArrayDouble([0.,1.,2.,3.,4.])
2557         m.setCoords(arr,arr,arr)
2558         m=m.buildUnstructured()
2559         m2=m.buildDescendingConnectivity()[0]
2560         m.setName("mesh")
2561         g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2562         g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2563         g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2564         g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2565         g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2566         g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2567         mm=MEDFileUMesh()
2568         mm.setMeshAtLevel(0,m)
2569         mm.setGroupsAtLevel(0,[g1,g2])
2570         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2571         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2572         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2573         mm.normalizeFamIdsMEDFile()
2574         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2575         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2576         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2577         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2578         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2579         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2580         for g in mm.getGroupsOnSpecifiedLev(0):
2581             for f in mm.getFamiliesIdsOnGroup(g):
2582                 self.assertTrue(f<0)
2583                 pass
2584             pass
2585         #
2586         mm=MEDFileUMesh()
2587         mm.setMeshAtLevel(0,m)
2588         mm.setMeshAtLevel(-1,m2)
2589         mm.setGroupsAtLevel(0,[g1,g2])
2590         mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2591         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2592         s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2593         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2594         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2595         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2596         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2597         mm.normalizeFamIdsMEDFile()
2598         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2599         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2600         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2601         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2602         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2603         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2604         self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2605         self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2606         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2607         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2608         self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2609         self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2610         for lev in [0,-1]:
2611             for g in mm.getGroupsOnSpecifiedLev(lev):
2612                 for f in mm.getFamiliesIdsOnGroup(g):
2613                     self.assertTrue(f<0)
2614                     pass
2615                 pass
2616             pass
2617          #
2618         mm=MEDFileUMesh()
2619         mm.setMeshAtLevel(0,m)
2620         mm.setMeshAtLevel(-1,m2)
2621         mm.setGroupsAtLevel(0,[g1,g2])
2622         mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2623         mm.setGroupsAtLevel(1,[g1Node,g2Node])
2624         s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2625         s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2626         s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2627         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2628         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2629         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2630         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2631         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2632         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2633         mm.normalizeFamIdsMEDFile()
2634         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2635         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2636         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2637         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2638         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2639         self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2640         self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2641         self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2642         self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2643         self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2644         self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2645         self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2646         self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2647         self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2648         self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2649         self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2650         self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2651         self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2652         for lev in [0,-1]:
2653             for g in mm.getGroupsOnSpecifiedLev(lev):
2654                 for f in mm.getFamiliesIdsOnGroup(g):
2655                     self.assertTrue(f<0)
2656                     pass
2657                 pass
2658             pass
2659         for g in mm.getGroupsOnSpecifiedLev(1):
2660             for f in mm.getFamiliesIdsOnGroup(g):
2661                 self.assertTrue(f>0)
2662                 pass
2663             pass
2664         pass
2665
2666     @WriteInTmpDir
2667     def testNonRegressionMantis22212ChangeGrpName(self):
2668         fileName="Pyfile62.med"
2669         m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2670         m=MEDFileUMesh.New()
2671         m.setCoords(m2.getCoords())
2672         m.setMeshAtLevel(0,m2)
2673         m.setMeshAtLevel(-1,m1)
2674         m.setMeshAtLevel(-2,m0)
2675         m.setFamilyFieldArr(0,f2)
2676         m.setFamilyFieldArr(-1,f1)
2677         m.setFamilyFieldArr(-2,f0)
2678         m.setFamilyFieldArr(1,p)
2679         nbOfFams=len(fns)
2680         for i in range(nbOfFams):
2681             m.addFamily(fns[i],fids[i])
2682             pass
2683         nbOfGrps=len(grpns)
2684         for i in range(nbOfGrps):
2685             m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2686             pass
2687         m.setName(m2.getName())
2688         m.setDescription(m2.getDescription())
2689         m.write(fileName,2)
2690         #
2691         mm0=MEDFileMesh.New(fileName)
2692         mm1=MEDFileMesh.New(fileName)
2693         groupNamesIni=GetMeshGroupsNames(fileName,"ma")
2694         for name in groupNamesIni:
2695             mm1.changeGroupName(name,name+'N')
2696             pass
2697         mm1.write(fileName,2)
2698         del mm1
2699         #
2700         mm2=MEDFileMesh.New(fileName)
2701         for name in groupNamesIni:
2702             for lev in mm0.getGrpNonEmptyLevelsExt(name):
2703                 arr0=mm0.getGroupArr(lev,name)
2704                 arr2=mm2.getGroupArr(lev,name+'N')
2705                 arr0.setName(name+'N')
2706                 self.assertTrue(arr0.isEqual(arr2))
2707                 pass
2708             pass
2709         pass
2710
2711     @WriteInTmpDir
2712     def testInt32InMEDFileFieldStar1(self):
2713         self.internalInt32InMEDFileFieldStar1()
2714
2715     def internalInt32InMEDFileFieldStar1(self):
2716         fname="Pyfile63.med"
2717         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2718         f1=f1.convertToIntField()
2719         m1=f1.getMesh()
2720         mm1=MEDFileUMesh.New()
2721         mm1.setCoords(m1.getCoords())
2722         mm1.setMeshAtLevel(0,m1)
2723         mm1.setName(m1.getName())
2724         mm1.write(fname,2)
2725         ff1=MEDFileIntField1TS()
2726         ff1.setFieldNoProfileSBT(f1)
2727         a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2728         self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2729         self.assertTrue(a.isEqual(f1,1e-12,0))
2730         ff1.write(fname,0)
2731         a,b=ff1.getUndergroundDataArrayExt()
2732         self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
2733         self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
2734         ff2=MEDFileAnyTypeField1TS.New(fname)
2735         self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2736         self.assertEqual(ff2.getTime(),[0,1,2.0])
2737         self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2738         a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2739         self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2740         self.assertTrue(a.isEqual(f1,1e-12,0))
2741         ff2.setTime(1,2,3.)
2742         c=ff2.getUndergroundDataArray() ; c*=2
2743         ff2.write(fname,0) # 2 time steps in
2744         ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2745         self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2746         self.assertEqual(len(ffs1),2)
2747         self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2748         a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2749         self.assertTrue(a.isEqual(f1,1e-12,0))
2750         a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
2751         self.assertTrue(a.isEqual(f1,1e-12,0))
2752         it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2753         a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2754         self.assertTrue(a.getArray().isEqual(2*f1.getArray()))
2755         f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
2756         self.assertTrue(a.isEqual(f1,1e-12,0)) ; f1.getArray()[:]/=2
2757         bc=DataArrayInt32(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2758         for it in ffs1:
2759             a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2760             bc+=a.getArray()
2761             pass
2762         self.assertTrue(bc.isEqual(3*f1.getArray()))
2763         nf1=MEDCouplingFieldInt(ON_NODES)
2764         nf1.setTime(9.,10,-1)
2765         nf1.setMesh(f1.getMesh())
2766         narr=DataArrayInt32(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
2767         nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
2768         nff1=MEDFileIntField1TS.New()
2769         nff1.setFieldNoProfileSBT(nf1)
2770         self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2771         self.assertEqual(nff1.getTime(),[10,-1,9.0])
2772         nff1.write(fname,0)
2773         #
2774         nf2=MEDCouplingFieldInt(ON_NODES)
2775         nf2.setTime(19.,20,-11)
2776         nf2.setMesh(f1.getMesh())
2777         narr2=DataArrayInt32(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10  ; narr2[:,1]=3*narr2[:,0]
2778         nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
2779         nff2=MEDFileIntField1TS.New()
2780         npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
2781         nff2.setFieldProfile(nf2,mm1,0,npfl)
2782         nff2.getFieldWithProfile(ON_NODES,0,mm1)
2783         a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2784         self.assertTrue(b.isEqual(npfl))
2785         self.assertTrue(a.isEqual(narr2))
2786         nff2.write(fname,0)
2787         nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
2788         a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2789         self.assertTrue(b.isEqual(npfl))
2790         self.assertTrue(a.isEqual(narr2))
2791         #
2792         nf3=MEDCouplingFieldDouble(ON_NODES)
2793         nf3.setName("VectorFieldOnNodesDouble")
2794         nf3.setTime(29.,30,-21)
2795         nf3.setMesh(f1.getMesh())
2796         nf3.setArray(f1.getMesh().getCoords())
2797         nff3=MEDFileField1TS.New()
2798         nff3.setFieldNoProfileSBT(nf3)
2799         nff3.write(fname,0)
2800         fs=MEDFileFields(fname)
2801         self.assertEqual(len(fs),4)
2802         ffs=[it for it in fs]
2803         self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
2804         self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
2805         self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
2806         self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
2807         #
2808         self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray()))
2809         self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray()))
2810         self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
2811         self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
2812         self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2813         #
2814         nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
2815         self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2816         self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
2817         self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
2818         MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
2819         self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
2820         MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
2821         self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
2822         #
2823         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
2824         self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2825         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
2826         self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2827         pass
2828
2829     @WriteInTmpDir
2830     def testMEDFileFields1(self):
2831         fname="Pyfile64.med"
2832         f1=MEDCouplingFieldDouble(ON_NODES)
2833         f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
2834         c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
2835         mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
2836         f1.setMesh(m)
2837         arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=list(range(12)) ; arr[:,1]=2*arr[:,0]
2838         f1.setArray(arr)
2839         f1.setName("Field1")
2840         ff1=MEDFileField1TS.New()
2841         ff1.setFieldNoProfileSBT(f1)
2842         self.assertEqual(ff1.getDtUnit(),"us")
2843         ff1.write(fname,0)
2844         f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2845         f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2846         #
2847         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2848         ff1s=MEDFileFieldMultiTS(fname,"Field1")
2849         ff1s.setName("Field2")
2850         ff1s.write(fname,0)
2851         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2852         f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2853         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
2854         self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
2855         self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
2856         f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2857         self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
2858         self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
2859         pass
2860
2861     # Multi time steps and multi fields management without Globals (profiles, locs) aspects
2862     @WriteInTmpDir
2863     def testMEDFileFields2(self):
2864         fname="Pyfile65.med"
2865         # to check that all is initialize
2866         MEDFileField1TS().__str__()
2867         MEDFileFieldMultiTS().__str__()
2868         # building a mesh containing 4 tri3 + 5 quad4
2869         tri=MEDCouplingUMesh("tri",2)
2870         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2871         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2872         tris = [tri.deepCopy() for i in range(4)]
2873         for i,elt in enumerate(tris): elt.translate([i,0])
2874         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2875         quad=MEDCouplingUMesh("quad",2)
2876         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2877         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2878         quads = [quad.deepCopy() for i in range(5)]
2879         for i,elt in enumerate(quads): elt.translate([5+i,0])
2880         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2881         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2882         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2883         #
2884         fmts0_0=MEDFileFieldMultiTS()
2885         fmts0_1=MEDFileFieldMultiTS()
2886         # time steps
2887         for i in range(10):
2888             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2889             d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2890             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2891             f.setTime(float(i+1)+0.1,i+1,-i-1)
2892             fmts0_0.appendFieldNoProfileSBT(f)
2893             f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
2894             self.assertEqual(fmts0_1.getName(),name1)
2895             self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2896             self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2897             if i>1:
2898                 # components names have been modified to generate errors
2899                 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
2900                 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
2901                 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
2902                 f1ts.setInfo(['aa [bb]','eee [dd]'])
2903                 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
2904                 pass
2905             # add a mismatch of nb of compos
2906             pass
2907         fmts0_2=fmts0_0.deepCopy()
2908         fmts0_3=fmts0_0.deepCopy()
2909         fmts0_4=fmts0_0.deepCopy()
2910         fmts0_5=fmts0_0.shallowCpy()
2911         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)
2912         del fmts0_2[::2]
2913         self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
2914         del fmts0_3[[1.1,(6,-6),9]]
2915         self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
2916         fmts0_6=fmts0_4[[1.1,(6,-6),8]]
2917         self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
2918         self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
2919         fmts0_7=fmts0_4[::-3]
2920         self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
2921         self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
2922         #
2923         fs0=MEDFileFields()
2924         fs0.pushField(fmts0_0)
2925         fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2926         fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2927         fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2928         self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
2929         fs0.write(fname,2)
2930         fs0=MEDFileFields(fname)
2931         self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
2932         fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
2933         self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2934         del fs1[["2ndField",3]]
2935         self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2936         fs2=fs0[[0,"4thField"]]
2937         self.assertTrue(isinstance(fs2,MEDFileFields))
2938         self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
2939         #
2940         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
2941         pass
2942
2943     # Multi time steps and multi fields management with Globals (profiles, locs) aspects
2944     @WriteInTmpDir
2945     def testMEDFileFields3(self):
2946         fname="Pyfile66.med"
2947         # building a mesh containing 4 tri3 + 5 quad4
2948         tri=MEDCouplingUMesh("tri",2)
2949         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2950         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2951         tris = [tri.deepCopy() for i in range(4)]
2952         for i,elt in enumerate(tris): elt.translate([i,0])
2953         tris=MEDCouplingUMesh.MergeUMeshes(tris)
2954         quad=MEDCouplingUMesh("quad",2)
2955         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2956         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2957         quads = [quad.deepCopy() for i in range(5)]
2958         for i,elt in enumerate(quads): elt.translate([5+i,0])
2959         quads=MEDCouplingUMesh.MergeUMeshes(quads)
2960         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2961         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2962         #
2963         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2964         #
2965         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2966         pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2967         fmts0_0=MEDFileFieldMultiTS()
2968         fmts0_1=MEDFileFieldMultiTS()
2969         # time steps
2970         for i in range(10):
2971             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2972             d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2973             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2974             f.setTime(float(i+1)+0.1,i+1,-i-1)
2975             fmts0_0.appendFieldProfile(f,mm,0,pfl)
2976             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2977             self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2978             self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2979             pass
2980         #
2981         self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
2982         self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
2983         fmts0_0.zipPflsNames()
2984         self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
2985         self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
2986         fmts0_2=fmts0_0.deepCopy()
2987         fmts0_3=fmts0_0.deepCopy()
2988         fmts0_4=fmts0_0.deepCopy()
2989         fs0=MEDFileFields()
2990         fs0.pushField(fmts0_0)
2991         fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2992         fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2993         fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2994         self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
2995         #
2996         fmts0_5=MEDFileFieldMultiTS()
2997         for i in range(7):
2998             infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2999             d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
3000             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3001             f.setTime(float(i+1)+0.1,i+1,-i-1)
3002             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
3003             pass
3004         fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
3005         self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
3006         fs0.checkGlobsCoherency()
3007         fs0.write(fname,0)
3008         pass
3009
3010     @WriteInTmpDir
3011     def testSplitComponents1(self):
3012         fname="Pyfile67.med"
3013         # building a mesh containing 4 tri3 + 5 quad4
3014         tri=MEDCouplingUMesh("tri",2)
3015         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3016         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3017         tris = [tri.deepCopy() for i in range(4)]
3018         for i,elt in enumerate(tris): elt.translate([i,0])
3019         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3020         quad=MEDCouplingUMesh("quad",2)
3021         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3022         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3023         quads = [quad.deepCopy() for i in range(5)]
3024         for i,elt in enumerate(quads): elt.translate([5+i,0])
3025         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3026         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3027         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3028         #
3029         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3030         #
3031         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3032         pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
3033         fs=MEDFileFields()
3034         fmts0_1=MEDFileFieldMultiTS()
3035         # time steps
3036         infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
3037         for i in range(10):
3038             name1="1stField"
3039             d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
3040             f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3041             f.setTime(float(i+1)+0.1,i+1,-i-1)
3042             f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
3043             self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
3044             pass
3045         fs.pushField(fmts0_1)
3046         self.assertEqual(1,len(fs))
3047         l=fmts0_1.splitComponents()
3048         self.assertEqual(3,len(l))
3049         for elt in l: self.assertEqual(10,len(elt))
3050         for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
3051         for elt in l:
3052             elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
3053             pass
3054         fs.pushFields(l)
3055         self.assertEqual(4,len(fs))
3056         for elt in fs: self.assertEqual(10,len(elt))
3057         self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
3058         self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
3059         #
3060         fs.write(fname,0) ; del fs
3061         #
3062         fs1=MEDFileFields(fname)
3063         self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
3064         self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
3065         self.assertEqual(4,len(fs1))
3066         for i in range(10):
3067             for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
3068                 f1ts=fs1[fieldName][i]
3069                 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
3070                 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
3071                 self.assertTrue(d.isEqual(f.getArray(),1e-13))
3072                 pass
3073             f1ts=fs1["1stField"][i]
3074             f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
3075             d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
3076             self.assertTrue(d.isEqual(f.getArray(),1e-13))
3077             pass
3078         pass
3079
3080     @WriteInTmpDir
3081     def testMEDFileFieldConvertTo1(self):
3082         fname="Pyfile68.med"
3083         # building a mesh containing 4 tri3 + 5 quad4
3084         tri=MEDCouplingUMesh("tri",2)
3085         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3086         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3087         tris = [tri.deepCopy() for i in range(4)]
3088         for i,elt in enumerate(tris): elt.translate([i,0])
3089         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3090         quad=MEDCouplingUMesh("quad",2)
3091         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3092         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3093         quads = [quad.deepCopy() for i in range(5)]
3094         for i,elt in enumerate(quads): elt.translate([5+i,0])
3095         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3096         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3097         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3098         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3099         #
3100         ff0=MEDFileField1TS()
3101         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")
3102         f0.checkConsistencyLight()
3103         ff0.setFieldNoProfileSBT(f0)
3104         #
3105         fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
3106         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3107         #
3108         ff0i=ff0.convertToInt()
3109         self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3110         self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3111         #
3112         ff1=ff0i.convertToDouble()
3113         self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3114         self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3115         # With profiles
3116         del arr,f0,ff0,ff1,ff0i,fspExp
3117         ff0=MEDFileField1TS()
3118         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")
3119         f0.checkConsistencyLight()
3120         pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
3121         ff0.setFieldProfile(f0,mm,0,pfl)
3122         fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
3123         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3124         #
3125         ff0i=ff0.convertToInt()
3126         self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
3127         self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3128         self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3129         #
3130         ff1=ff0i.convertToDouble()
3131         self.assertTrue(isinstance(ff1,MEDFileField1TS))
3132         self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3133         self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3134         ## MultiTimeSteps
3135         ff0=MEDFileFieldMultiTS()
3136         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)
3137         f0.checkConsistencyLight()
3138         ff0.appendFieldProfile(f0,mm,0,pfl)
3139         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)
3140         f0.checkConsistencyLight()
3141         ff0.appendFieldProfile(f0,mm,0,pfl)
3142         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)
3143         f0.checkConsistencyLight()
3144         ff0.appendFieldProfile(f0,mm,0,pfl)
3145         ff1=ff0.convertToInt()
3146         self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3147         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3148         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
3149             self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3150             arr=ff1.getUndergroundDataArray(dt,it)
3151             arr.isEqualWithoutConsideringStr(DataArrayInt32.Range(delt,delt+7,1))
3152             pass
3153         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3154         #
3155         mm.write(fname,2)
3156         ff1.write(fname,0)
3157         #
3158         ff1=ff1.convertToDouble()
3159         self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
3160         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3161         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
3162             self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3163             arr=ff1.getUndergroundDataArray(dt,it)
3164             arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
3165             pass
3166         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3167         #
3168         ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
3169         self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3170         self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3171         for delt,(dt,it,t) in  zip([0,100,200],ff1.getTimeSteps()):
3172             self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
3173             arr=ff1.getUndergroundDataArray(dt,it)
3174             arr.isEqualWithoutConsideringStr(DataArrayInt32.Range(delt,delt+7,1))
3175             pass
3176         self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
3177         pass
3178
3179     @WriteInTmpDir
3180     def testMEDFileFieldPartialLoading(self):
3181         fname="Pyfile69.med"
3182         #
3183         a=DataArrayInt() ; aa=a.getHeapMemorySize()
3184         a.alloc(0,1)
3185         strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
3186         # building a mesh containing 30 tri3 + 40 quad4
3187         tri=MEDCouplingUMesh("tri",2)
3188         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3189         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3190         tris = [tri.deepCopy() for i in range(30)]
3191         for i,elt in enumerate(tris): elt.translate([i,0])
3192         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3193         quad=MEDCouplingUMesh("quad",2)
3194         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3195         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3196         quads = [quad.deepCopy() for i in range(40)]
3197         for i,elt in enumerate(quads): elt.translate([40+i,0])
3198         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3199         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3200         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3201         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3202         #
3203         ff0=MEDFileField1TS()
3204         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")
3205         f0.checkConsistencyLight()
3206         ff0.setFieldNoProfileSBT(f0)
3207         ff0.write(fname,0)
3208         #
3209         fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
3210         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3211         # With profiles
3212         ff0=MEDFileField1TS()
3213         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")
3214         f0.checkConsistencyLight()
3215         pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
3216         ff0.setFieldProfile(f0,mm,0,pfl)
3217         fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
3218         self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3219         ff0.write(fname,0)
3220         #
3221         ff0=MEDFileField1TS(fname,False)
3222         self.assertEqual(ff0.getName(),"FieldCell")
3223         self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
3224         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
3225         heap_memory_ref=ff0.getHeapMemorySize()
3226         self.assertIn(heap_memory_ref, list(range(182, 540 + 2 * strMulFac)))
3227         ff0.loadArrays() ##
3228         arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
3229         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3230         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
3231         #
3232         ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
3233         self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
3234         heap_memory_ref=ff0.getHeapMemorySize()
3235         self.assertIn(heap_memory_ref, list(range(350, 700 + 6 * strMulFac)))
3236         ff0.loadArrays() ##
3237         arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
3238         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3239         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3240         ff0.loadArrays() ##
3241         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3242         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3243         ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3244         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3245         ff0.loadArrays() ##
3246         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3247         ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3248         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3249         ff0.loadArraysIfNecessary() ##
3250         self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
3251         self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3252         heap_memory_ref=ff0.getHeapMemorySize()
3253         self.assertIn(heap_memory_ref, list(range(1100, 1600 + 2 * strMulFac)))
3254         ff0.unloadArrays()
3255         hmd=ff0.getHeapMemorySize()-heap_memory_ref
3256         self.assertEqual(hmd,-800) # -50*8*2
3257         ff0.loadArrays() ##
3258         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
3259         #
3260         ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
3261         heap_memory_ref=ff0.getHeapMemorySize()
3262         self.assertIn(heap_memory_ref, list(range(299, 670 + 6 * strMulFac)))
3263         ff0.loadArrays() ##
3264         self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3265         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3266         #
3267         fieldName="FieldCellMultiTS"
3268         ff0=MEDFileFieldMultiTS()
3269         for t in range(20):
3270             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)
3271             f0.setTime(float(t)+0.1,t,100+t)
3272             f0.checkConsistencyLight()
3273             ff0.appendFieldNoProfileSBT(f0)
3274             pass
3275         ff0.write(fname,0)
3276         #
3277         ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
3278         heap_memory_ref=ff0.getHeapMemorySize()
3279         self.assertIn(heap_memory_ref, range(5536, 9212 + (80 + 26 + 1) * strMulFac))
3280         ff0.loadArrays()
3281         self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
3282         del ff0
3283         #
3284         ffs=MEDFileFields(fname,False)
3285         heap_memory_ref=ffs.getHeapMemorySize()
3286         self.assertIn(heap_memory_ref, range(5335, 10331 + (80 + 50 + len(ffs)) * strMulFac))
3287         ffs.loadArrays()
3288         self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
3289         pass
3290
3291     @WriteInTmpDir
3292     def testMEDFileMeshReadSelector1(self):
3293         mrs=MEDFileMeshReadSelector()
3294         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3295         mrs.__str__() ; mrs.__repr__()
3296         #
3297         mrs=MEDFileMeshReadSelector(0)
3298         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())
3299         mrs=MEDFileMeshReadSelector(1)
3300         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3301         mrs=MEDFileMeshReadSelector(2)
3302         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3303         mrs=MEDFileMeshReadSelector(3)
3304         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3305         mrs=MEDFileMeshReadSelector(4)
3306         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3307         mrs=MEDFileMeshReadSelector(5)
3308         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3309         mrs=MEDFileMeshReadSelector(6)
3310         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3311         mrs=MEDFileMeshReadSelector(7)
3312         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3313         mrs=MEDFileMeshReadSelector(8)
3314         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3315         mrs=MEDFileMeshReadSelector(9)
3316         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3317         mrs=MEDFileMeshReadSelector(10)
3318         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3319         mrs=MEDFileMeshReadSelector(11)
3320         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3321         mrs=MEDFileMeshReadSelector(12)
3322         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3323         mrs=MEDFileMeshReadSelector(13)
3324         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3325         mrs=MEDFileMeshReadSelector(14)
3326         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3327         mrs=MEDFileMeshReadSelector(15)
3328         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3329         mrs=MEDFileMeshReadSelector(16)
3330         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3331         mrs=MEDFileMeshReadSelector(17)
3332         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3333         mrs=MEDFileMeshReadSelector(18)
3334         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3335         mrs=MEDFileMeshReadSelector(19)
3336         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3337         mrs=MEDFileMeshReadSelector(20)
3338         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3339         mrs=MEDFileMeshReadSelector(21)
3340         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3341         mrs=MEDFileMeshReadSelector(22)
3342         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3343         mrs=MEDFileMeshReadSelector(23)
3344         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3345         mrs=MEDFileMeshReadSelector(24)
3346         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3347         mrs=MEDFileMeshReadSelector(25)
3348         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3349         mrs=MEDFileMeshReadSelector(26)
3350         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3351         mrs=MEDFileMeshReadSelector(27)
3352         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3353         mrs=MEDFileMeshReadSelector(28)
3354         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3355         mrs=MEDFileMeshReadSelector(29)
3356         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3357         mrs=MEDFileMeshReadSelector(30)
3358         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3359         mrs=MEDFileMeshReadSelector(31)
3360         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3361         mrs=MEDFileMeshReadSelector(32)
3362         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3363         mrs=MEDFileMeshReadSelector(33)
3364         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3365         mrs=MEDFileMeshReadSelector(34)
3366         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3367         mrs=MEDFileMeshReadSelector(35)
3368         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3369         mrs=MEDFileMeshReadSelector(36)
3370         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3371         mrs=MEDFileMeshReadSelector(37)
3372         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3373         mrs=MEDFileMeshReadSelector(38)
3374         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3375         mrs=MEDFileMeshReadSelector(39)
3376         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3377         mrs=MEDFileMeshReadSelector(40)
3378         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3379         mrs=MEDFileMeshReadSelector(41)
3380         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3381         mrs=MEDFileMeshReadSelector(42)
3382         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3383         mrs=MEDFileMeshReadSelector(43)
3384         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3385         mrs=MEDFileMeshReadSelector(44)
3386         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3387         mrs=MEDFileMeshReadSelector(45)
3388         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3389         mrs=MEDFileMeshReadSelector(46)
3390         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3391         mrs=MEDFileMeshReadSelector(47)
3392         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3393         mrs=MEDFileMeshReadSelector(48)
3394         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3395         mrs=MEDFileMeshReadSelector(49)
3396         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3397         mrs=MEDFileMeshReadSelector(50)
3398         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3399         mrs=MEDFileMeshReadSelector(51)
3400         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3401         mrs=MEDFileMeshReadSelector(52)
3402         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3403         mrs=MEDFileMeshReadSelector(53)
3404         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3405         mrs=MEDFileMeshReadSelector(54)
3406         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3407         mrs=MEDFileMeshReadSelector(55)
3408         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3409         mrs=MEDFileMeshReadSelector(56)
3410         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3411         mrs=MEDFileMeshReadSelector(57)
3412         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3413         mrs=MEDFileMeshReadSelector(58)
3414         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3415         mrs=MEDFileMeshReadSelector(59)
3416         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3417         mrs=MEDFileMeshReadSelector(60)
3418         self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3419         mrs=MEDFileMeshReadSelector(61)
3420         self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3421         mrs=MEDFileMeshReadSelector(62)
3422         self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3423         mrs=MEDFileMeshReadSelector(63)
3424         self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3425         #
3426         mrs=MEDFileMeshReadSelector(63)
3427         mrs.setCellFamilyFieldReading(False)
3428         self.assertEqual(mrs.getCode(),62)
3429         mrs.setCellFamilyFieldReading(True)
3430         self.assertEqual(mrs.getCode(),63)
3431         mrs.setNodeFamilyFieldReading(False)
3432         self.assertEqual(mrs.getCode(),61)
3433         mrs.setNodeFamilyFieldReading(True)
3434         self.assertEqual(mrs.getCode(),63)
3435         mrs.setCellNameFieldReading(False)
3436         self.assertEqual(mrs.getCode(),59)
3437         mrs.setCellNameFieldReading(True)
3438         self.assertEqual(mrs.getCode(),63)
3439         mrs.setNodeNameFieldReading(False)
3440         self.assertEqual(mrs.getCode(),55)
3441         mrs.setNodeNameFieldReading(True)
3442         self.assertEqual(mrs.getCode(),63)
3443         mrs.setCellNumFieldReading(False)
3444         self.assertEqual(mrs.getCode(),47)
3445         mrs.setCellNumFieldReading(True)
3446         self.assertEqual(mrs.getCode(),63)
3447         mrs.setNodeNumFieldReading(False)
3448         self.assertEqual(mrs.getCode(),31)
3449         mrs.setNodeNumFieldReading(True)
3450         self.assertEqual(mrs.getCode(),63)
3451         pass
3452
3453     @WriteInTmpDir
3454     def testPartialReadOfMeshes(self):
3455         fname="Pyfile70.med"
3456         # building a mesh containing 4 tri3 + 5 quad4
3457         tri=MEDCouplingUMesh("tri",2)
3458         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3459         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3460         tris = [tri.deepCopy() for i in range(4)]
3461         for i,elt in enumerate(tris): elt.translate([i,0])
3462         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3463         quad=MEDCouplingUMesh("quad",2)
3464         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3465         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3466         quads = [quad.deepCopy() for i in range(5)]
3467         for i,elt in enumerate(quads): elt.translate([5+i,0])
3468         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3469         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3470         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3471         m1=m.buildDescendingConnectivity()[0]
3472         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3473         #
3474         grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3475         grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3476         mm.setGroupsAtLevel(0,[grp0,grp1])
3477         grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3478         grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3479         mm.setGroupsAtLevel(-1,[grp2,grp3])
3480         grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3481         grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3482         mm.setGroupsAtLevel(1,[grp4,grp5])
3483         mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3484         mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3485         mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3486         #
3487         mm.write(fname,2)
3488         ##
3489         mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3490         b4_ref_heap_mem=mm.getHeapMemorySize()
3491         mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
3492         mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
3493         ref_heap_mem=mm.getHeapMemorySize()
3494         # check the gain of memory using 1GTUMesh instead of UMesh
3495         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
3496         #
3497         mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3498         self.assertEqual(len(mm.getGroupsNames()),0)
3499         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3500         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3501         self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3502         self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3503         self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3504         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3505         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3506         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3507         delta1=ref_heap_mem-mm.getHeapMemorySize()
3508         self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3509         #
3510         mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3511         self.assertEqual(len(mm.getGroupsNames()),6)
3512         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3513         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3514         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3515         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3516         self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3517         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3518         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3519         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3520         delta2=ref_heap_mem-mm.getHeapMemorySize()
3521         self.assertTrue(delta2<delta1)
3522         self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3523         #
3524         mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3525         self.assertEqual(len(mm.getGroupsNames()),6)
3526         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3527         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3528         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3529         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3530         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3531         self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3532         self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3533         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3534         delta3=ref_heap_mem-mm.getHeapMemorySize()
3535         self.assertTrue(delta3<delta2)
3536         self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3537         #
3538         mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3539         self.assertEqual(len(mm.getGroupsNames()),6)
3540         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3541         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3542         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3543         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3544         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3545         self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3546         self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3547         self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3548         delta4=ref_heap_mem-mm.getHeapMemorySize()
3549         self.assertTrue(delta4<delta3)
3550         self.assertTrue(delta4>=32*4*2)
3551         #
3552         mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3553         self.assertEqual(len(mm.getGroupsNames()),6)
3554         self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3555         self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3556         self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3557         self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3558         self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3559         self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3560         self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3561         self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3562         delta5=ref_heap_mem-mm.getHeapMemorySize()
3563         self.assertTrue(delta5<delta4)
3564         self.assertEqual(delta5,0)
3565         pass
3566
3567     # this test checks that setFieldProfile perform a check of the array length
3568     # compared to the profile length. This test also checks that mesh attribute of field
3569     # is not used by setFieldProfile (because across this test mesh is equal to None)
3570     @WriteInTmpDir
3571     def testCheckCompatibilityPfl1(self):
3572         # building a mesh containing 4 tri3 + 5 quad4
3573         tri=MEDCouplingUMesh("tri",2)
3574         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3575         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3576         tris = [tri.deepCopy() for i in range(4)]
3577         for i,elt in enumerate(tris): elt.translate([i,0])
3578         tris=MEDCouplingUMesh.MergeUMeshes(tris)
3579         quad=MEDCouplingUMesh("quad",2)
3580         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3581         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3582         quads = [quad.deepCopy() for i in range(5)]
3583         for i,elt in enumerate(quads): elt.translate([5+i,0])
3584         quads=MEDCouplingUMesh.MergeUMeshes(quads)
3585         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3586         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3587         m1=m.buildDescendingConnectivity()[0]
3588         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3589         #
3590         f1ts=MEDFileField1TS()
3591         f=MEDCouplingFieldDouble(ON_NODES)
3592         vals=DataArrayDouble(7) ; vals.iota(1000)
3593         f.setArray(vals)
3594         f.setName("anonymous") # f has no mesh it is not a bug
3595         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3596         f1ts.setFieldProfile(f,mm,0,pfl)
3597         #
3598         f1ts=MEDFileField1TS()
3599         f=MEDCouplingFieldDouble(ON_NODES)
3600         vals=DataArrayDouble(8) ; vals.iota(1000)
3601         f.setArray(vals)
3602         f.setName("anonymous") # f has no mesh it is not a bug
3603         pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3604         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3605         #
3606         f1ts=MEDFileField1TS()
3607         f=MEDCouplingFieldDouble(ON_CELLS)
3608         vals=DataArrayDouble(7) ; vals.iota(1000)
3609         f.setArray(vals)
3610         f.setName("anonymous") # f has no mesh it is not a bug
3611         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3612         f1ts.setFieldProfile(f,mm,0,pfl)
3613         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3614         #
3615         f1ts=MEDFileField1TS()
3616         f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3617         vals=DataArrayDouble(27) ; vals.iota(1000)
3618         f.setArray(vals)
3619         f.setName("anonymous") # f has no mesh it is not a bug
3620         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3621         f.setMesh(m[pfl])
3622         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])
3623         f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3624         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])
3625         f.setMesh(None)
3626         f1ts.setFieldProfile(f,mm,0,pfl)
3627         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3628         vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3629         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3630         vals=DataArrayDouble(27) ; vals.iota(1000)
3631         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3632         #
3633         f1ts=MEDFileField1TS()
3634         f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3635         vals=DataArrayDouble(25) ; vals.iota(1000)
3636         f.setArray(vals)
3637         f.setName("anonymous") # f has no mesh it is not a bug
3638         pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3639         f1ts.setFieldProfile(f,mm,0,pfl)
3640         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3641         vals2=DataArrayDouble(26) ; vals2.iota(1050)
3642         f.setArray(vals2)
3643         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3644         self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3645         #
3646         f1ts=MEDFileField1TS()
3647         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3648         self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3649         f.setArray(vals)
3650         f1ts.setFieldProfile(f,mm,0,pfl)
3651         pass
3652
3653     @WriteInTmpDir
3654     def testWRMeshWithNoCells(self):
3655         fname="Pyfile71.med"
3656         a=DataArrayDouble(4) ; a.iota()
3657         c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
3658         m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
3659         m=MEDFileUMesh()
3660         m.setMeshAtLevel(0,m00)
3661         m.setRenumFieldArr(1,DataArrayInt(list(range(10,26))))
3662         m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
3663         m.write(fname,2)
3664         del m,a,c,m0,m00
3665         #
3666         m=MEDFileMesh.New(fname)
3667         self.assertEqual((),m.getNonEmptyLevels())
3668         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))
3669         self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(list(range(10,26)))))
3670         self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
3671         pass
3672
3673     @WriteInTmpDir
3674     def testWRQPolyg1(self):
3675         fname="Pyfile72.med"
3676         m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
3677         m.insertNextCell([0,2,1,3])
3678         m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
3679         #
3680         ms = [m.deepCopy() for i in range(4)]
3681         for i,elt in enumerate(ms):
3682             elt.translate([float(i)*1.5,0.])
3683             pass
3684         m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3685         m0.convertAllToPoly()
3686         #
3687         ms = [m.deepCopy() for i in range(5)]
3688         for i,elt in enumerate(ms):
3689             elt.translate([float(i)*1.5,1.5])
3690             pass
3691         m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3692         m1.convertAllToPoly()
3693         m1.convertLinearCellsToQuadratic()
3694         #
3695         m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
3696         ##
3697         mm=MEDFileUMesh()
3698         mm.setMeshAtLevel(0,m)
3699         grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
3700         grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
3701         grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
3702         mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3703         ##
3704         mm.write(fname,2)
3705         del mm
3706         #
3707         mm_read=MEDFileUMesh(fname)
3708         self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
3709         self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
3710         self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
3711         self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
3712         ##
3713         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
3714         f.setMesh(m)
3715         arr0=DataArrayDouble(9) ; arr0.iota()
3716         arr1=DataArrayDouble(9) ; arr1.iota(100)
3717         arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
3718         f.setArray(arr) ; f.checkConsistencyLight()
3719         f.setTime(5.6,1,2)
3720         ff=MEDFileField1TS()
3721         ff.setFieldNoProfileSBT(f)
3722         ff.write(fname,0)
3723         ##
3724         ff_read=MEDFileField1TS(fname)
3725         f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
3726         self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
3727         pass
3728
3729     @WriteInTmpDir
3730     def testLoadIfNecessaryOnFromScratchFields0(self):
3731         """
3732         This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
3733         """
3734         fname="Pyfile77.med"
3735         coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
3736         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
3737         m.allocateCells()
3738         m.insertNextCell(NORM_QUAD4,[0,5,3,2])
3739         m.insertNextCell(NORM_QUAD4,[4,2,3,1])
3740         m.finishInsertingCells()
3741         #
3742         mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3743         ms=MEDFileMeshes() ; ms.pushMesh(mm)
3744         fs=MEDFileFields()
3745         arrs=4*[None]
3746         #
3747         ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
3748         f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
3749         f0.setTime(1.1,1,1)
3750         f0.setName("myELNOField")
3751         arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
3752         f0.setArray(arrs[0])
3753         ff0.appendFieldNoProfileSBT(f0)
3754         #
3755         f0.setTime(2.2,2,1)
3756         arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
3757         f0.setArray(arrs[1])
3758         ff0.appendFieldNoProfileSBT(f0)
3759         #
3760         f0.setTime(3.3,3,1)
3761         arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
3762         f0.setArray(arrs[2])
3763         ff0.appendFieldNoProfileSBT(f0)
3764         #
3765         f0.setTime(4.4,4,1)
3766         arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
3767         f0.setArray(arrs[3])
3768         ff0.appendFieldNoProfileSBT(f0)
3769         #
3770         for i,arr in enumerate(arrs):
3771             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3772             fs[0][i].loadArraysIfNecessary()
3773             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3774             pass
3775         fs.loadArraysIfNecessary()
3776         for i,arr in enumerate(arrs):
3777             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3778             pass
3779         fs[0].loadArraysIfNecessary()
3780         for i,arr in enumerate(arrs):
3781             self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3782             pass
3783         pass
3784
3785     @WriteInTmpDir
3786     def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
3787         """ 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.
3788         """
3789         fname="Pyfile78.med"
3790         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)
3791         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3792         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
3793         m0.allocateCells()
3794         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
3795             m0.insertNextCell(NORM_TETRA4,elt)
3796             pass
3797         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
3798             m0.insertNextCell(NORM_PYRA5,elt)
3799             pass
3800         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
3801             m0.insertNextCell(NORM_PENTA6,elt)
3802             pass
3803         m0.checkConsistency()
3804         m1=MEDCouplingUMesh(); m1.setName("mesh")
3805         m1.setMeshDimension(2);
3806         m1.allocateCells(5);
3807         m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3808         m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3809         m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3810         m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3811         m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3812         m1.setCoords(coords);
3813         m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
3814         m3.allocateCells()
3815         m3.insertNextCell(NORM_POINT1,[2])
3816         m3.insertNextCell(NORM_POINT1,[3])
3817         m3.insertNextCell(NORM_POINT1,[4])
3818         m3.insertNextCell(NORM_POINT1,[5])
3819         #
3820         mm=MEDFileUMesh()
3821         mm.setMeshAtLevel(0,m0)
3822         mm.setMeshAtLevel(-1,m1)
3823         mm.setMeshAtLevel(-3,m3)
3824         mm.write(fname,2)
3825         #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
3826         mm=MEDFileMesh.New(fname)
3827         fs=MEDFileFields()
3828         fmts=MEDFileFieldMultiTS()
3829         f1ts=MEDFileField1TS()
3830         for lev in mm.getNonEmptyLevels():
3831             for gt in mm.getGeoTypesAtLevel(lev):
3832                 p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
3833                 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
3834                 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
3835                 f.setArray(arr) ; f.setName("f0")
3836                 f1ts.setFieldNoProfileSBT(f)
3837                 pass
3838             pass
3839         self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
3840         for lev in [0,-1,-3]:
3841             mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
3842             pass
3843         fmts.pushBackTimeStep(f1ts)
3844         fs.pushField(fmts)
3845         fs.write(fname,0)
3846         del fs,fmts,f1ts
3847         #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
3848         fs=MEDFileFields(fname)
3849         self.assertEqual(len(fs),1)
3850         self.assertEqual(len(fs[0]),1)
3851         f1ts=fs[0][0]
3852         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),'','')])])
3853         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))
3854         pass
3855
3856     @WriteInTmpDir
3857     def testMEDFileUMeshSetName(self):
3858         """ 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.
3859         This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
3860         """
3861         fname="Pyfile79.med"
3862         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3863         mm=MEDFileUMesh()
3864         m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
3865         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)
3866         m0.allocateCells(5);
3867         m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3868         m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3869         m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3870         m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3871         m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3872         m0.setCoords(coords);
3873         mm.setMeshAtLevel(0,m0)
3874         m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
3875         m2.allocateCells()
3876         m2.insertNextCell(NORM_POINT1,[2])
3877         m2.insertNextCell(NORM_POINT1,[3])
3878         m2.insertNextCell(NORM_POINT1,[4])
3879         m2.insertNextCell(NORM_POINT1,[5])
3880         mm.setMeshAtLevel(-2,m2)
3881         self.assertEqual(mm.getName(),"")
3882         self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
3883         mm.forceComputationOfParts()
3884         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
3885         mm.setName("abc")
3886         self.assertEqual(mm.getName(),"abc")
3887         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
3888         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
3889         self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
3890         self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
3891         pass
3892
3893     @WriteInTmpDir
3894     def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
3895         fileName="Pyfile80.med"
3896         m=MEDCouplingCMesh() ; m.setName("cmesh")
3897         arr=DataArrayDouble(6) ; arr.iota()
3898         m.setCoords(arr,arr)
3899         nbCells=m.getNumberOfCells()
3900         self.assertEqual(25,nbCells)
3901         f=MEDCouplingFieldDouble(ON_CELLS)
3902         f.setName("FieldOnCell") ; f.setMesh(m)
3903         arr=DataArrayDouble(nbCells) ; arr.iota()
3904         mm=MEDFileCMesh()
3905         mm.setMesh(m)
3906         #
3907         fmts=MEDFileFieldMultiTS()
3908         #
3909         for i in range(nbCells):
3910             t=(float(i)+0.1,i+1,-i-2)
3911             f.setTime(*t)
3912             arr2=DataArrayDouble(nbCells)
3913             perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
3914             arr2[perm]=arr
3915             f.setArray(arr2)
3916             f1ts=MEDFileField1TS()
3917             f1ts.setFieldNoProfileSBT(f)
3918             fmts.pushBackTimeStep(f1ts)
3919             pass
3920         fmts.unloadArraysWithoutDataLoss()
3921         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))
3922         fs=MEDFileFields() ; fs.pushField(fmts)
3923         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))
3924         fs.unloadArraysWithoutDataLoss()
3925         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))
3926         f1ts=fs[0][0]
3927         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))
3928         f1ts.unloadArraysWithoutDataLoss()
3929         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))
3930         mm.write(fileName,2)
3931         fs.write(fileName,0)
3932         del m,fmts,mm,f,f1ts
3933         ##
3934         mm=MEDFileMesh.New(fileName)
3935         fmts=MEDFileFieldMultiTS(fileName)
3936         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))
3937         fmts.unloadArraysWithoutDataLoss()
3938         self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
3939         fmts.loadArraysIfNecessary()
3940         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))
3941         del mm,fmts
3942         fs=MEDFileFields(fileName)
3943         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))
3944         fs.unloadArraysWithoutDataLoss()
3945         self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
3946         fs.loadArraysIfNecessary()
3947         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))
3948         del fs
3949         f1ts=MEDFileField1TS(fileName)
3950         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))
3951         f1ts.unloadArraysWithoutDataLoss()
3952         self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
3953         f1ts.loadArraysIfNecessary()
3954         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))
3955         pass
3956
3957     @WriteInTmpDir
3958     def testMEDFileUMeshLoadPart1(self):
3959         """ 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
3960         memory of the returned instance.
3961         """
3962         fileName="Pyfile81.med"
3963         arr=DataArrayDouble(6) ; arr.iota()
3964         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3965         m=m.buildUnstructured()
3966         m.setName("Mesh")
3967         m.changeSpaceDimension(3,0.)
3968         infos=["aa [b]","cc [de]","gg [klm]"]
3969         m.getCoords().setInfoOnComponents(infos)
3970         m.checkConsistency()
3971         mm=MEDFileUMesh()
3972         mm.setMeshAtLevel(0,m)
3973         m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh")
3974         m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
3975         mm.setMeshAtLevel(-1,m1)
3976         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])
3977         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])
3978         namesCellL0=DataArrayAsciiChar(25,16)
3979         namesCellL0[:] = ["Cell#%.3d        " % (i) for i in range(25)]
3980         renumM1=DataArrayInt([3,4,0,2,1])
3981         famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
3982         mm.setRenumFieldArr(0,renum0)
3983         mm.setFamilyFieldArr(0,famField0)
3984         mm.setNameFieldAtLevel(0,namesCellL0)
3985         mm.setRenumFieldArr(-1,renumM1)
3986         mm.setFamilyFieldArr(-1,famFieldM1)
3987         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])
3988         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])
3989         namesNodes=DataArrayAsciiChar(36,16)
3990         namesNodes[:] = ["Node#%.3d        " % (i) for i in range(36)]
3991         mm.setRenumFieldArr(1,renum1)
3992         mm.setFamilyFieldArr(1,famField1)
3993         mm.setNameFieldAtLevel(1,namesNodes)
3994         mm.setFamilyId("Fam7",77)
3995         mm.setFamilyId("Fam8",88)
3996         mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
3997         mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
3998         mm.write(fileName,2)
3999         #
4000         mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
4001         self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
4002         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])))
4003         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)
4004         self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
4005         self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
4006         self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
4007         self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
4008         self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
4009         self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
4010         self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
4011         #
4012         mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
4013         self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
4014         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])))
4015         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)
4016         self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
4017         self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
4018         self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
4019         self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
4020         self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
4021         self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
4022         self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
4023         #
4024         mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
4025         self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
4026         self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
4027         self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
4028         self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
4029         self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
4030         self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
4031         self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
4032         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])))
4033         self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
4034         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)
4035         self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
4036         self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
4037         self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
4038         self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
4039         pass
4040
4041     @WriteInTmpDir
4042     def testMEDFileFieldsLoadPart1(self):
4043         """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
4044         """
4045         fileName="Pyfile82.med"
4046         meshName="Mesh"
4047         compos=["aa [kg]","bbb [m/s]"]
4048         arr=DataArrayDouble(6) ; arr.iota()
4049         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4050         m=m.buildUnstructured()
4051         m.setName(meshName)
4052         m.changeSpaceDimension(3,0.)
4053         infos=["aa [b]","cc [de]","gg [klm]"]
4054         m.getCoords().setInfoOnComponents(infos)
4055         m.checkConsistency()
4056         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4057         f.setName("Field")
4058         arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4059         arr[:,0]=list(range(25))
4060         arr[:,1]=list(range(100,125))
4061         f.setArray(arr)
4062         WriteField(fileName,f,True)
4063         f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4064         f.setName("FieldNode")
4065         arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4066         arr[:,0]=list(range(200,236))
4067         arr[:,1]=list(range(300,336))
4068         f.setArray(arr)
4069         f.checkConsistencyLight()
4070         WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4071         #
4072         ms=MEDFileMeshes()
4073         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
4074         ms.pushMesh(mm)
4075         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4076         self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
4077         #
4078         ms=MEDFileMeshes()
4079         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
4080         ms.pushMesh(mm)
4081         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4082         fs=fs.deepCopy()
4083         fs[0][0].loadArrays()
4084         arr = DataArrayDouble(12, 2) ; arr[:, 0] = list(range(3, 15)) ; arr[:, 1] = list(range(103, 115))
4085         arr.setInfoOnComponents(compos)
4086         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4087         fs[1][0].loadArrays()
4088         arr = DataArrayDouble(21, 2) ; arr[:, 0] = list(range(203, 224)) ; arr[:, 1] = list(range(303, 324))
4089         arr.setInfoOnComponents(compos)
4090         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4091         pass
4092
4093     @WriteInTmpDir
4094     def testMEDFileWithoutCells1(self):
4095         fileName="Pyfile83.med"
4096         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4097         coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
4098         mm=MEDFileUMesh()
4099         mm.setCoords(coo)
4100         mm.setName("mesh")
4101         mm.write(fileName,2)
4102         #
4103         mm=MEDFileMesh.New(fileName)
4104         self.assertEqual(mm.getName(),"mesh")
4105         self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
4106         pass
4107
4108     @WriteInTmpDir
4109     def testZipCoordsWithLoadPart1(self):
4110         """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
4111         """
4112         fileName="Pyfile84.med"
4113         meshName="Mesh"
4114         compos=["aa [kg]","bbb [m/s]"]
4115         arr=DataArrayDouble(6) ; arr.iota()
4116         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4117         m=m.buildUnstructured()
4118         m.setName(meshName)
4119         m.changeSpaceDimension(3,0.)
4120         infos=["aa [b]","cc [de]","gg [klm]"]
4121         m.getCoords().setInfoOnComponents(infos)
4122         m.checkConsistency()
4123         f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4124         f.setName("Field")
4125         arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4126         arr[:,0]=list(range(25))
4127         arr[:,1]=list(range(100,125))
4128         f.setArray(arr)
4129         WriteField(fileName,f,True)
4130         f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4131         f.setName("FieldNode")
4132         arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4133         arr[:,0]=list(range(200,236))
4134         arr[:,1]=list(range(300,336))
4135         f.setArray(arr)
4136         f.checkConsistencyLight()
4137         WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4138         #
4139         ms=MEDFileMeshes()
4140         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
4141         ms.pushMesh(mm)
4142         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4143         self.assertEqual(spd.getSlice(),slice(4,6,1))
4144         spd=mm.getPartDefAtLevel(1)
4145         self.assertEqual(spd.getSlice(),slice(4,14,1))
4146         self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4147         mm.zipCoords() # <- The important line is here !
4148         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4149         self.assertEqual(spd.getSlice(),slice(4,6,1))
4150         spd=mm.getPartDefAtLevel(1)
4151         self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4152         self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
4153         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4154         fs[0][0].loadArrays()
4155         arr=DataArrayDouble([(4,104),(5,105)])
4156         arr.setInfoOnComponents(compos)
4157         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4158         fs[1][0].loadArrays()
4159         arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
4160         arr.setInfoOnComponents(compos)
4161         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4162         m_ref = mm[0].deepCopy()
4163         # now read it in 2 load sessions to avoid memory peak. zipCoords is no more requested here.
4164         ms=MEDFileMeshes()
4165         mrs = MEDFileMeshReadSelector()
4166         mrs.setNumberOfCoordsLoadSessions(2)
4167         mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1],-1,-1,mrs)
4168         ms.pushMesh(mm)
4169         spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4170         self.assertEqual(spd.getSlice(),slice(4,6,1))
4171         spd=mm.getPartDefAtLevel(1)
4172         self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4173         self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
4174         fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4175         fs[0][0].loadArrays()
4176         arr=DataArrayDouble([(4,104),(5,105)])
4177         arr.setInfoOnComponents(compos)
4178         self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4179         fs[1][0].loadArrays()
4180         arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
4181         arr.setInfoOnComponents(compos)
4182         self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4183         self.assertTrue( mm[0].deepCopy().isEqual(m_ref,1e-12) )
4184         pass
4185
4186     @WriteInTmpDir
4187     def testMEDFileCMeshSetGroupsAtLevel(self):
4188         """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
4189         """
4190         m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
4191         m.setName("Mesh")
4192         mm=MEDFileCMesh() ; mm.setMesh(m)
4193         grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
4194         mm.setGroupsAtLevel(0,[grp])
4195         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
4196         pass
4197
4198     @WriteInTmpDir
4199     def testMEDFileUMeshBuildExtrudedMesh1(self):
4200         """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
4201         fileName="Pyfile85.med"
4202         meshName2D="Mesh"
4203         meshName1D="Mesh1D"
4204         meshName3DOut="Mesh3D"
4205         #
4206         d1=DataArrayInt([0,4,20,24])
4207         d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
4208         #
4209         a=DataArrayDouble(6) ; a.iota()
4210         m=MEDCouplingCMesh() ; m.setCoords(a,a)
4211         m=m.buildUnstructured()
4212         d1c=d1.buildComplement(m.getNumberOfCells())
4213         m=m[d1c] ; m.zipCoords()
4214         m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
4215         m0.simplexize(0)
4216         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
4217         m.setName(meshName2D)
4218         mMinus1,a,b,c,d=m.buildDescendingConnectivity()
4219         e=d.deltaShiftIndex().findIdsEqual(1)
4220         #
4221         mm=MEDFileUMesh()
4222         mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
4223         grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
4224         mm.setGroupsAtLevel(0,[grp0])
4225         grp1=e ; grp1.setName("grp1")
4226         mm.setGroupsAtLevel(-1,[grp1])
4227         mm.write(fileName,2)
4228         #
4229         a=DataArrayDouble(3) ; a.iota()
4230         tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
4231         tmp.setName(meshName1D)
4232         tmp.changeSpaceDimension(3)
4233         tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
4234         mm1D=MEDFileUMesh()
4235         mm1D.setMeshAtLevel(0,tmp)
4236         mm1D.write(fileName,0)
4237         # test is here !
4238         mm2D=MEDFileMesh.New(fileName,meshName2D)
4239         mm1D=MEDFileMesh.New(fileName,meshName1D)
4240         m1D=mm1D.getMeshAtLevel(0)
4241         mm3D=mm2D.buildExtrudedMesh(m1D,0)
4242         #
4243         self.assertEqual(mm3D.getName(),mm2D.getName())
4244         self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
4245         self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
4246         self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
4247         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
4248         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
4249         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
4250         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
4251         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
4252         self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
4253         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.)])
4254         self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
4255         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])
4256         self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
4257         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])
4258         self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
4259         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])
4260         self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
4261         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])
4262         self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
4263         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])
4264         self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
4265         d=DataArrayInt(129) ; d.iota() ; d*=3
4266         self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
4267         #
4268         self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
4269         self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
4270         self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
4271         self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
4272         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])))
4273         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])))
4274         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])))
4275         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])))
4276         mm3D.setName("MeshExtruded")
4277         mm3D.write(fileName,0)
4278         pass
4279
4280     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4281     @WriteInTmpDir
4282     def testMEDFileUMeshPickeling1(self):
4283         outFileName="Pyfile86.med"
4284         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)
4285         c.setInfoOnComponents(["aa","bbb"])
4286         targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
4287         m=MEDCouplingUMesh();
4288         m.setMeshDimension(2);
4289         m.allocateCells(5);
4290         m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
4291         m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
4292         m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
4293         m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
4294         m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
4295         m.finishInsertingCells();
4296         m.setCoords(c)
4297         m.checkConsistencyLight()
4298         m1=MEDCouplingUMesh.New();
4299         m1.setMeshDimension(1);
4300         m1.allocateCells(3);
4301         m1.insertNextCell(NORM_SEG2,2,[1,4])
4302         m1.insertNextCell(NORM_SEG2,2,[3,6])
4303         m1.insertNextCell(NORM_SEG3,3,[2,8,5])
4304         m1.finishInsertingCells();
4305         m1.setCoords(c)
4306         m1.checkConsistencyLight()
4307         m2=MEDCouplingUMesh.New();
4308         m2.setMeshDimension(0);
4309         m2.allocateCells(4);
4310         m2.insertNextCell(NORM_POINT1,1,[1])
4311         m2.insertNextCell(NORM_POINT1,1,[3])
4312         m2.insertNextCell(NORM_POINT1,1,[2])
4313         m2.insertNextCell(NORM_POINT1,1,[6])
4314         m2.finishInsertingCells();
4315         m2.setCoords(c)
4316         m2.checkConsistencyLight()
4317         #
4318         mm=MEDFileUMesh.New()
4319         self.assertTrue(mm.getUnivNameWrStatus())
4320         mm.setName("MyFirstMEDCouplingMEDmesh")
4321         mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
4322         mm.setCoords(c)
4323         mm[-1]=m1;
4324         mm[0]=m;
4325         mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
4326         mm[-2]=m2;
4327         mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
4328         # playing with groups
4329         g1_2=DataArrayInt.New()
4330         g1_2.setValues([1,3],2,1)
4331         g1_2.setName("G1")
4332         g2_2=DataArrayInt.New()
4333         g2_2.setValues([1,2,3],3,1)
4334         g2_2.setName("G2")
4335         mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
4336         g1_1=DataArrayInt.New()
4337         g1_1.setValues([0,1,2],3,1)
4338         g1_1.setName("G1")
4339         g2_1=DataArrayInt.New()
4340         g2_1.setValues([0,2],2,1)
4341         g2_1.setName("G2")
4342         mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
4343         g1_N=DataArrayInt.New()
4344         g1_N.setValues(list(range(8)),8,1)
4345         g1_N.setName("G1")
4346         g2_N=DataArrayInt.New()
4347         g2_N.setValues(list(range(9)),9,1)
4348         g2_N.setName("G2")
4349         mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
4350         mm.createGroupOnAll(0,"GrpOnAllCell")
4351         # check content of mm
4352         t=mm.getGroupArr(0,"G1",False)
4353         self.assertTrue(g1_2.isEqual(t));
4354         t=mm.getGroupArr(0,"G2",False)
4355         self.assertTrue(g2_2.isEqual(t));
4356         t=mm.getGroupArr(-1,"G1",False)
4357         self.assertTrue(g1_1.isEqual(t));
4358         t=mm.getGroupArr(-1,"G2",False)
4359         self.assertTrue(g2_1.isEqual(t));
4360         t=mm.getGroupArr(1,"G1",False)
4361         self.assertTrue(g1_N.isEqual(t));
4362         t=mm.getGroupArr(1,"G2",False)
4363         self.assertTrue(g2_N.isEqual(t));
4364         self.assertTrue(mm.existsGroup("GrpOnAllCell"));
4365         t=mm.getGroupArr(0,"GrpOnAllCell")
4366         #
4367         st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4368         mm2=pickle.loads(st)
4369         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4370         self.assertEqual(mm.getAxisType(),AX_CART)
4371         #
4372         mm.setAxisType(AX_CYL)
4373         st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4374         mm2=pickle.loads(st)
4375         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4376         self.assertEqual(mm2.getAxisType(),AX_CYL)
4377         pass
4378
4379     @WriteInTmpDir
4380     def testMEDFileFieldsLoadSpecificEntities1(self):
4381         nbNodes=11
4382         fieldName="myField"
4383         fileName="Pyfile87.med"
4384         nbPdt=10
4385         meshName="Mesh"
4386         #
4387         m=MEDCouplingCMesh()
4388         arr=DataArrayDouble(nbNodes) ; arr.iota()
4389         m.setCoords(arr)
4390         m=m.buildUnstructured()
4391         m.setName(meshName)
4392         #
4393         fmts=MEDFileFieldMultiTS()
4394         for i in range(nbPdt):
4395             f=MEDCouplingFieldDouble(ON_NODES)
4396             f.setMesh(m)
4397             arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4398             f.setArray(arr)
4399             f.setName(fieldName)
4400             f.setTime(float(i),i,0)
4401             fmts.appendFieldNoProfileSBT(f)
4402             pass
4403         #
4404         mm=MEDFileUMesh() ; mm[0]=m
4405         fmts.write(fileName,2)
4406         mm.write(fileName,0)
4407         #
4408         fs=MEDFileFields(fileName,False)
4409         fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
4410         fs.loadArraysIfNecessary()
4411         fs2.loadArraysIfNecessary()
4412         for i in range(nbPdt):
4413             self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4414             pass
4415         m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
4416         m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
4417         m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
4418         fmts=MEDFileFieldMultiTS()
4419         for i in range(nbPdt):
4420             f=MEDCouplingFieldDouble(ON_CELLS)
4421             f.setMesh(m3)
4422             arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
4423             f.setArray(arr)
4424             f.setName(fieldName)
4425             f.setTime(float(i),i,0)
4426             fmts.appendFieldNoProfileSBT(f)
4427             pass
4428         mm=MEDFileUMesh() ; mm[0]=m3
4429         del mm[0]
4430         self.assertEqual(mm.getNonEmptyLevels(),())
4431         mm[0]=m3
4432         self.assertEqual(mm.getNonEmptyLevels(),(0,))
4433         fmts.write(fileName,2)
4434         fs=MEDFileFields(fileName,False)
4435         fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
4436         fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
4437         fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
4438         fs.loadArraysIfNecessary()
4439         fs2.loadArraysIfNecessary()
4440         fs3.loadArraysIfNecessary()
4441         fs4.loadArraysIfNecessary()
4442         for i in range(nbPdt):
4443             self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4444             self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
4445             self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
4446             pass
4447         pass
4448
4449     @WriteInTmpDir
4450     def testMEDFileLotsOfTSRW1(self):
4451         nbNodes=11
4452         fieldName="myField"
4453         fileName="Pyfile88.med"
4454         nbPdt=300 # <- perftest = 30000
4455         meshName="Mesh"
4456         #
4457         maxPdt=100 # <- optimum = 500
4458         m=MEDCouplingCMesh()
4459         arr=DataArrayDouble(nbNodes) ; arr.iota()
4460         m.setCoords(arr)
4461         m=m.buildUnstructured()
4462         m.setName(meshName)
4463         #
4464         nbOfField=nbPdt//maxPdt
4465         fs=MEDFileFields()
4466         for j in range(nbOfField):
4467             fmts=MEDFileFieldMultiTS()
4468             s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
4469             for i in range(s.start, s.stop, s.step):
4470                 f=MEDCouplingFieldDouble(ON_NODES)
4471                 f.setMesh(m)
4472                 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4473                 f.setArray(arr)
4474                 f.setName("%s_%d"%(fieldName,j))
4475                 f.setTime(float(i),i,0)
4476                 fmts.appendFieldNoProfileSBT(f)
4477                 pass
4478             fs.pushField(fmts)
4479             pass
4480         #
4481         mm=MEDFileUMesh() ; mm[0]=m
4482         fs.write(fileName,2)
4483         mm.write(fileName,0)
4484         ############
4485         def appendInDict(d,key,val):
4486             if key in d:
4487                 d[key].append(val)
4488             else:
4489                 d[key]=[val]
4490             pass
4491         import re
4492         allFields=GetAllFieldNames(fileName)
4493         allFieldsDict={}
4494         pat=re.compile("([\d]+)([\s\S]+)$")
4495         for st in allFields:
4496             stRev=st[::-1]
4497             m=pat.match(stRev)
4498             if m:
4499                 appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
4500                 pass
4501             else:
4502                 appendInDict(allFieldsDict,st,'')
4503                 pass
4504             pass
4505         fs2=MEDFileFields()
4506         for k in allFieldsDict:
4507             if allFieldsDict[k]!=['']:
4508                 allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
4509                 pass
4510             fmts2=[]
4511             for it in allFieldsDict[k]:
4512                 fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
4513                 pass
4514             fmts2.reverse()
4515             zeResu=fmts2.pop()
4516             nbIter=len(fmts2)
4517             for ii in range(nbIter):
4518                 zeResu.pushBackTimeSteps(fmts2.pop())
4519                 pass
4520             zeResu.setName(k)
4521             fs2.pushField(zeResu)
4522             pass
4523         self.assertEqual(fs2[0].getTimeSteps(), [(i, 0, float(i)) for i in range(nbPdt)])
4524         pass
4525
4526     @WriteInTmpDir
4527     def testMEDFileMeshRearrangeFamIds1(self):
4528         """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
4529         fileName="Pyfile89.med"
4530         meshName='Maillage_2'
4531         mm=MEDFileUMesh()
4532         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)])
4533         #
4534         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])
4535         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])
4536         m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
4537         m0.setConnectivity(c0,c0i)
4538         mm[0]=m0
4539         #
4540         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])
4541         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])
4542         m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
4543         m1.setConnectivity(c1,c1i)
4544         mm[-1]=m1
4545         #
4546         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])
4547         m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4548         m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
4549         mm[-2]=m2.buildUnstructured()
4550         #
4551         ref0=DataArrayInt(55) ; ref0[:]=0
4552         mm.setFamilyFieldArr(0,ref0)
4553         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]))
4554         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])
4555         mm.setFamilyFieldArr(-1,ref1)
4556         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])
4557         mm.setFamilyFieldArr(-2,ref2)
4558         #
4559         for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
4560             mm.setFamilyId(f,fid)
4561         for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
4562             mm.setFamiliesOnGroup(grp,fams)
4563         mm.write(fileName,2)
4564         #
4565         mm=MEDFileMesh.New(fileName)
4566         grp=mm.getGroup(-1,"Groupe_1")
4567         dai=grp.computeFetchedNodeIds()
4568         dai.setName("TOTO")
4569         mm.addGroup(1,dai)
4570         mm.rearrangeFamilies() # <- the aim of the test
4571         self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
4572         self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
4573         self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
4574         self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
4575         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])))
4576         allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
4577         allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
4578         self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
4579         for elt,fams in allGrps:
4580             self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
4581         self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
4582         for elt,eltId in allFams:
4583             self.assertEqual(mm.getFamilyId(elt),eltId)
4584         pass
4585
4586     @WriteInTmpDir
4587     def testNonRegrCMeshSetFieldPfl1(self):
4588         """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
4589         ff=MEDFileField1TS()
4590         meshName="mesh"
4591         mm=MEDFileCMesh()
4592         m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4593         m.setCoords(arr)
4594         m.setName(meshName)
4595         mm.setMesh(m)
4596         field=MEDCouplingFieldDouble(ON_CELLS)
4597         field.setMesh(m)
4598         field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4599         field.setName("Field")
4600         field.checkConsistencyLight()
4601         pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
4602         ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
4603         self.assertEqual(ff.getPfls(),())
4604         field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4605         self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4606         del ff,mm,field,field2,pfl
4607         # same with unstructured mesh
4608         ff=MEDFileField1TS()
4609         meshName="mesh"
4610         mm=MEDFileUMesh()
4611         m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4612         m.setCoords(arr)
4613         m.setName(meshName)
4614         m=m.buildUnstructured()
4615         mm[0]=m
4616         field=MEDCouplingFieldDouble(ON_CELLS)
4617         field.setMesh(m)
4618         field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4619         field.setName("Field")
4620         field.checkConsistencyLight()
4621         pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
4622         ff.setFieldProfile(field,mm,0,pfl)
4623         self.assertEqual(ff.getPfls(),())
4624         field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4625         self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4626         pass
4627
4628     @WriteInTmpDir
4629     def testMEDFileUMeshLinearToQuadraticAndRev1(self):
4630         meshName="mesh"
4631         fileName="Pyfile90.med"
4632         fileName2="Pyfile91.med"
4633         arr=DataArrayDouble(5) ; arr.iota()
4634         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4635         m=m.buildUnstructured()
4636         d=DataArrayInt([3,7,11,15])
4637         m1=m[d]
4638         m1.simplexize(0)
4639         m2=m[d.buildComplement(m.getNumberOfCells())]
4640         m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
4641         m.changeSpaceDimension(3,0.)
4642         arr=DataArrayDouble(3) ; arr.iota()
4643         m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
4644         m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
4645         delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
4646         m3D=m.buildExtrudedMesh(m1D,0)
4647         m3D.sortCellsInMEDFileFrmt()
4648         m3D.setName(meshName)
4649         m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkConsistency()
4650         m1D=m2D.computeSkin() ; m1D.setName(meshName)
4651         m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
4652         #
4653         mm=MEDFileUMesh()
4654         mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
4655         grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
4656         grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
4657         grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
4658         grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
4659         diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
4660         vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
4661         vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
4662         mm.setGroupsAtLevel(0,[vol1,vol2])
4663         mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
4664         mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
4665         #
4666         mmOut1=mm.linearToQuadratic(0,0.)
4667         mmOut1.write(fileName2,2)
4668         mmOut2=mmOut1.quadraticToLinear(0.)
4669         self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
4670         pass
4671
4672     @WriteInTmpDir
4673     def testMEDFileMeshAddGroup1(self):
4674         m=MEDCouplingCMesh()
4675         arrX=DataArrayDouble(9) ; arrX.iota()
4676         arrY=DataArrayDouble(4) ; arrY.iota()
4677         m.setCoords(arrX,arrY)
4678         m.setName("mesh")
4679         mm=MEDFileCMesh()
4680         mm.setMesh(m)
4681         grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
4682         mm.addGroup(0,grp0)
4683         grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
4684         mm.addGroup(0,grp1)
4685         grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
4686         mm.addGroup(0,grp2)
4687         grp3=DataArrayInt([23]) ; grp3.setName("grp3")
4688         mm.addGroup(0,grp3)
4689         for grp in [grp0,grp1,grp2,grp3]:
4690             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4691         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
4692         delta=12
4693         for grp in [grp0,grp1,grp2,grp3]:
4694             grpNode=grp.deepCopy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
4695             mm.addGroup(1,grpNode)
4696         self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
4697         for grp in [grp0,grp1,grp2,grp3]:
4698             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4699         for grp in [grp0,grp1,grp2,grp3]:
4700             grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4701             self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4702         mm.normalizeFamIdsMEDFile()
4703         for grp in [grp0,grp1,grp2,grp3]:
4704             self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4705         for grp in [grp0,grp1,grp2,grp3]:
4706             grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4707             self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4708         pass
4709
4710     @WriteInTmpDir
4711     def testMEDFileJoint1(self):
4712         fileName="Pyfile92.med"
4713         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4714         coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4715         mm=MEDFileUMesh()
4716         mm.setCoords(coo)
4717         mm.setName("maa1")
4718         mm.setDescription("un maillage")
4719         mm.write(fileName,2)
4720         node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4721         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4722         one_step_joint=MEDFileJointOneStep()
4723         one_step_joint.pushCorrespondence(cell_correspond)
4724         one_step_joint.pushCorrespondence(node_correspond)
4725         one_joint=MEDFileJoint()
4726         one_joint.pushStep(one_step_joint)
4727         one_joint.setLocalMeshName("maa1")
4728         one_joint.setRemoteMeshName("maa1")
4729         one_joint.setDescription("joint_description")
4730         one_joint.setJointName("joint_1")
4731         one_joint.setDomainNumber(1)
4732         self.assertEqual( one_joint.getLocalMeshName(), "maa1")
4733         self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
4734         self.assertEqual( one_joint.getDescription(), "joint_description")
4735         self.assertEqual( one_joint.getJointName(), "joint_1")
4736         self.assertEqual( one_joint.getDomainNumber(), 1)
4737         joints=MEDFileJoints()
4738         joints.pushJoint(one_joint);
4739         joints.write(fileName,0)
4740         # read back
4741         jointsR=MEDFileJoints(fileName,mm.getName())
4742         self.assertEqual( jointsR.getNumberOfJoints(), 1 )
4743         jR = jointsR.getJointAtPos(0)
4744         self.assertTrue( jR.isEqual( one_joint ))
4745         self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
4746         self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
4747         jointsR.destroyJointAtPos(0)
4748         pass
4749
4750     @WriteInTmpDir
4751     def testMEDFileJoint2(self):
4752         fileNameWr="Pyfile93.med"
4753         coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4754         coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4755         mm=MEDFileUMesh()
4756         mm.setCoords(coo)
4757         mm.setName("maa1")
4758         mm.setDescription("un maillage")
4759         node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
4760         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
4761         one_step_joint=MEDFileJointOneStep()
4762         two_step_joint=MEDFileJointOneStep()
4763         one_joint=MEDFileJoint()
4764         two_joint=MEDFileJoint()
4765         one_step_joint.pushCorrespondence(node_correspond)
4766         one_joint.pushStep(one_step_joint)
4767         two_step_joint.pushCorrespondence(cell_correspond)
4768         two_step_joint.pushCorrespondence(node_correspond)
4769         two_joint.pushStep(two_step_joint)
4770         one_joint.setLocalMeshName("maa1")
4771         one_joint.setRemoteMeshName("maa1")
4772         one_joint.setDescription("joint_description_1")
4773         one_joint.setJointName("joint_1")
4774         one_joint.setDomainNumber(1)
4775         two_joint.setLocalMeshName("maa1")
4776         two_joint.setRemoteMeshName("maa1")
4777         two_joint.setDescription("joint_description_2")
4778         two_joint.setJointName("joint_2")
4779         two_joint.setDomainNumber(2)
4780         joints=MEDFileJoints()
4781         joints.pushJoint(one_joint)
4782         joints.pushJoint(two_joint)
4783         mm.setJoints( joints )
4784         mm.write(fileNameWr,2)
4785         #
4786         mm=MEDFileMesh.New(fileNameWr)
4787         self.assertEqual( mm.getNumberOfJoints(), 2)
4788         jointsR = mm.getJoints();
4789         self.assertEqual( jointsR.getMeshName(), mm.getName() )
4790         self.assertEqual( len( jointsR ), 2 )
4791         jointR1 = jointsR[0]
4792         jointR2 = jointsR[1]
4793         self.assertFalse( jointR1 is None )
4794         self.assertFalse( jointR2 is None )
4795         self.assertTrue( jointR1.isEqual( one_joint ))
4796         self.assertTrue( jointR2.isEqual( two_joint ))
4797         pass
4798
4799     @WriteInTmpDir
4800     def testMEDFileJoint1(self):
4801         node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4802         cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4803         cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
4804         cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
4805         joint1st_1=MEDFileJointOneStep()
4806         joint1st_1.pushCorrespondence(cell_correspond)
4807         joint1st_1.pushCorrespondence(node_correspond)
4808         joint1st_2=MEDFileJointOneStep()
4809         joint1st_2.pushCorrespondence(cell_correspond)
4810         joint1st_2.pushCorrespondence(node_correspond)
4811         joint1st_3=MEDFileJointOneStep()
4812         joint1st_3.pushCorrespondence(node_correspond)
4813         joint1st_3.pushCorrespondence(cell_correspond)
4814         joint1st_4=MEDFileJointOneStep()
4815         joint1st_4.pushCorrespondence(cell_correspond)
4816         joint1st_5=MEDFileJointOneStep()
4817         joint1st_5.pushCorrespondence(cell_correspon2)
4818         joint1st_6=MEDFileJointOneStep()
4819         joint1st_6.pushCorrespondence(cell_correspon3)
4820         self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
4821         self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
4822         self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
4823         self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
4824         self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
4825         one_joint=MEDFileJoint()
4826         one_joint.pushStep(joint1st_1)
4827         one_joint.setLocalMeshName("maa1")
4828         one_joint.setRemoteMeshName("maa2")
4829         one_joint.setDescription("joint_description")
4830         one_joint.setJointName("joint_1")
4831         one_joint.setDomainNumber(1)
4832         self.assertEqual( "maa1", one_joint.getLocalMeshName())
4833         self.assertEqual( "maa2", one_joint.getRemoteMeshName())
4834         self.assertEqual( "joint_description", one_joint.getDescription())
4835         self.assertEqual( 1, one_joint.getDomainNumber())
4836         self.assertEqual( "joint_1", one_joint.getJointName())
4837         pass
4838
4839     @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
4840     @WriteInTmpDir
4841     def testMEDFileSafeCall0(self):
4842         """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
4843         fname="Pyfile94.med"
4844         errfname="Pyfile94.err"
4845
4846         import os
4847         # first clean file if needed
4848         if os.path.exists(fname):
4849             os.remove(fname)
4850             pass
4851         # second : build a file from scratch
4852         m=MEDCouplingCMesh()
4853         arr=DataArrayDouble(11) ; arr.iota()
4854         m.setCoords(arr,arr)
4855         mm=MEDFileCMesh()
4856         mm.setMesh(m)
4857         mm.setName("mesh")
4858         mm.write(fname,2)
4859         # third : change permissions to remove write access on created file
4860         os.chmod(fname, 0o444)
4861         # four : try to append data on file -> check that it raises Exception
4862         f=MEDCouplingFieldDouble(ON_CELLS)
4863         f.setName("field")
4864         f.setMesh(m)
4865         f.setArray(DataArrayDouble(100))
4866         f.getArray()[:]=100.
4867         f.checkConsistencyLight()
4868         f1ts=MEDFileField1TS()
4869         f1ts.setFieldNoProfileSBT(f)
4870         # redirect stderr
4871         tmp=StdOutRedirect(errfname)
4872         self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
4873         del tmp
4874         #
4875         if os.path.exists(errfname):
4876             os.remove(errfname)
4877         #
4878         pass
4879
4880     @WriteInTmpDir
4881     def testUnivStatus1(self):
4882         """ Non regression test to check the effectiveness of univ write status."""
4883         fname="Pyfile95.med"
4884         arr=DataArrayDouble(10) ; arr.iota()
4885         m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
4886         mm=MEDFileCMesh() ; mm.setMesh(m)
4887         mm.setUnivNameWrStatus(False) # test is here
4888         mm.write(fname,2)
4889         mm=MEDFileCMesh(fname)
4890         self.assertEqual(mm.getUnivName(),"")
4891         mm.setUnivNameWrStatus(True)
4892         mm.write(fname,2)
4893         mm=MEDFileCMesh(fname)
4894         self.assertTrue(mm.getUnivName()!="")
4895         pass
4896
4897     @WriteInTmpDir
4898     def testEmptyMesh(self):
4899       """ MEDLoader should be able to consistently write and read an empty mesh (coords array
4900       with 0 tuples """
4901       fname = "Pyfile96.med"
4902       m = MEDCouplingUMesh('toto', 2)
4903       m.setCoords(DataArrayDouble([], 0, 2))
4904       m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
4905       mfu = MEDFileUMesh()
4906       mfu.setMeshAtLevel(0, m)
4907       mfu.write(fname, 2)
4908       mfu2 = MEDFileUMesh(fname)
4909       self.assertEqual('toto', mfu2.getName())
4910       lvl = mfu2.getNonEmptyLevels()
4911       self.assertEqual((), lvl)
4912
4913     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4914     def testMEDFileUMeshPickeling2(self):
4915       """ Check that pickalization can be performed on a unpickalized instance. Non regression test."""
4916       name="Mesh_1"
4917       grpName1="HAUT"
4918       grpName2="BASE"
4919       hauteur=1.
4920       nbOfNodesPerAxis=3
4921       arr=DataArrayDouble(nbOfNodesPerAxis) ; arr.iota() ; arr/=(nbOfNodesPerAxis-1) ; arr*=hauteur
4922       m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured() ; m.setName(name)
4923       mesh=MEDFileUMesh() ; mesh[0]=m
4924       m1=m.computeSkin() ; mesh[-1]=m1
4925       #
4926       bary1=m1.computeCellCenterOfMass()[:,2]
4927       grp1=bary1.findIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
4928       grp2=bary1.findIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
4929       mesh.setGroupsAtLevel(-1,[grp1,grp2])
4930
4931       st=pickle.dumps(mesh,2)
4932       mm=pickle.loads(st)
4933       st2=pickle.dumps(mm,2)
4934       mm2=pickle.loads(st2)
4935       self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
4936       pass
4937
4938     @WriteInTmpDir
4939     def testMEDFileEquivalence1(self):
4940       """ First check of equivalence implementation in MEDFileMesh"""
4941       fileName="Pyfile97.med"
4942       meshName="M_01"
4943       mm=MEDFileUMesh()
4944       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)])
4945       coo.setInfoOnComponents(["X [Sans_unite]","Y [Sans_unite]","Z [Sans_unite]"])
4946       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])
4947       m1=MEDCoupling1SGTUMesh(meshName,NORM_QUAD4) ; m1.setCoords(coo) ; m1.setNodalConnectivity(connQ4) ; mm[-1]=m1
4948       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])
4949       m0=MEDCoupling1SGTUMesh(meshName,NORM_HEXA8) ; m0.setCoords(coo) ; m0.setNodalConnectivity(connH8) ; mm[0]=m0
4950       mm.getFamilyFieldAtLevel(-1)[:]=-2
4951       mm.getFamilyFieldAtLevel(0)[:]=0
4952       mm.addFamily("HOMARD________-1",-1)
4953       mm.addFamily("HOMARD________-2",-2)
4954       mm.addFamily("HOMARD________-3",-3)
4955       mm.setFamiliesIdsOnGroup("HOMARD",[-1,-2,-3])
4956
4957       eqName="MAILLES_A_RECOLLER_APRES_HOMARD"
4958       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."
4959       mm.initializeEquivalences()
4960       eqs=mm.getEquivalences()
4961       eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4962       eq0.setDescription(descEq)
4963       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)])
4964       eq0.setArray(-1,corr)
4965       self.assertEqual(eq0.getCell().size(),1)
4966       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4967       eq0.getCell().clear()
4968       self.assertEqual(eq0.getCell().size(),0)
4969       eq0.getCell().setArrayForType(NORM_QUAD4,corr)
4970       self.assertEqual(eq0.getCell().size(),1)
4971       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4972       mm.killEquivalences()
4973       mm.initializeEquivalences()
4974       eqs=mm.getEquivalences()
4975       eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4976       eq0.setDescription(descEq)
4977       c=eq0.initCell()
4978       c.setArrayForType(NORM_QUAD4,corr)
4979       self.assertEqual(eq0.getCell().size(),1)
4980       self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4981       mm2=mm.deepCopy()
4982       self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4983       self.assertEqual(mm2.getEquivalences().size(),1)
4984       self.assertTrue(mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4).isEqual(corr))
4985       mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=2
4986       self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
4987       mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=0
4988       self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4989       mm.write(fileName,2)
4990       #
4991       mm3=MEDFileMesh.New(fileName)
4992       self.assertTrue(mm.isEqual(mm3,1e-12)[0])
4993       pass
4994
4995     @WriteInTmpDir
4996     def testMEDFileForFamiliesPlayer1(self):
4997       """Non regression bug EDF11911. For serial killers using same family name to store both cells and nodes ! Only sky is the limit."""
4998       fileName="Pyfile98.med"
4999       meshName="mesh"
5000       magicSt="%s%%04i"%(MEDFileMesh.GetMagicFamilyStr())
5001       arr=DataArrayDouble(4) ; arr.iota()
5002       m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
5003       m=m.buildUnstructured()
5004       mm=MEDFileUMesh()
5005       mm[0]=m
5006       mm.setName(meshName)
5007       mm.setFamilyId("FAMILLE_ZERO",0)
5008       mm.getFamilyFieldAtLevel(0)[-3:]=-4
5009       mm.setFamilyId("RIDF%s"%(magicSt%0),-4)
5010       mm.setGroupsOnFamily("RIDF%s"%(magicSt%0),["RID"])
5011       d=DataArrayInt(16) ; d[:]=0 ; d[[1,2,4,5]]=3
5012       mm.setFamilyFieldArr(1,d)
5013       mm.setFamilyId("RIDF%s"%(magicSt%1),3)
5014       mm.setGroupsOnFamily("RIDF%s"%(magicSt%1),["RID"])
5015       self.assertEqual(mm.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
5016       self.assertEqual(mm.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF")) # <- the aim of test is here !
5017       self.assertEqual(mm.getFamiliesIdsOnGroup("RID"),(-4,3))
5018       mm.write(fileName,2)
5019       # now read such funny file !
5020       mm2=MEDFileMesh.New(fileName) # <- normally mdump of Pyfile98.med must contain only RID and FAMILLE_ZERO families.
5021       self.assertTrue(mm.isEqual(mm2,1e-16))
5022       self.assertEqual(mm2.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
5023       self.assertEqual(mm2.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF"))
5024       self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too !
5025       pass
5026
5027     @WriteInTmpDir
5028     def testCartesianizer1(self):
5029       """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """
5030       # UMesh non cart
5031       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
5032       mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts()
5033       d0=DataArrayInt(16) ; d0[:]=0
5034       d1=DataArrayInt(9)  ; d1[:]=0
5035       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5036       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5037       ref0=mm.getCoords().getHiddenCppPointer()
5038       ref1=mm[0].getNodalConnectivity().getHiddenCppPointer()
5039       self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer())
5040       ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer()
5041       ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer()
5042       self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
5043       mm.setAxisType(AX_CYL) #<- important
5044       mm2=mm.cartesianize() # the trigger
5045       self.assertEqual(mm2.getAxisType(),AX_CART)
5046       mm.setAxisType(AX_CART) # this is here only to avoid complaints
5047       self.assertTrue(isinstance(mm2,MEDFileUMesh))
5048       self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
5049       self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important
5050       self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important
5051       self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer())
5052       self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
5053       self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important
5054       self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important
5055       self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important
5056       self.assertEqual(mm2.getName(),mm.getName())
5057       self.assertEqual(mm2.getDescription(),mm.getDescription())
5058       self.assertEqual(mm2.getTime(),mm.getTime())
5059       self.assertEqual(mm2.getTime(),mm.getTime())
5060       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5061       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5062       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5063       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5064       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5065       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5066       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5067       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5068       # UMesh cart
5069       mm.setAxisType(AX_CART)
5070       mm2=mm.cartesianize() # the trigger
5071       self.assertEqual(mm2.getAxisType(),AX_CART)
5072       self.assertTrue(isinstance(mm2,MEDFileUMesh))
5073       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5074       # CurveLinearMesh non cart
5075       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear()
5076       mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
5077       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5078       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5079       ref0=mm.getMesh().getCoords().getHiddenCppPointer()
5080       mm2=mm.cartesianize() # the trigger
5081       self.assertEqual(mm2.getAxisType(),AX_CART)
5082       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5083       self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
5084       self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important
5085       self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important
5086       self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
5087       self.assertEqual(mm2.getName(),mm.getName())
5088       self.assertEqual(mm2.getDescription(),mm.getDescription())
5089       self.assertEqual(mm2.getTime(),mm.getTime())
5090       self.assertEqual(mm2.getTime(),mm.getTime())
5091       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5092       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5093       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5094       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5095       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5096       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5097       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5098       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5099       # CurveLinearMesh cart
5100       mm.setAxisType(AX_CART)
5101       mm2=mm.cartesianize() # the trigger
5102       self.assertEqual(mm2.getAxisType(),AX_CART)
5103       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5104       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5105       # CMesh non cart
5106       arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
5107       mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
5108       mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5109       mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5110       mm2=mm.cartesianize() # the trigger
5111       self.assertEqual(mm2.getAxisType(),AX_CART)
5112       self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5113       self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
5114       self.assertEqual(mm2.getName(),mm.getName())
5115       self.assertEqual(mm2.getDescription(),mm.getDescription())
5116       self.assertEqual(mm2.getTime(),mm.getTime())
5117       self.assertEqual(mm2.getTime(),mm.getTime())
5118       self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5119       self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5120       self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5121       self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5122       self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5123       self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5124       self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5125       self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5126       # CMesh cart
5127       mm.setAxisType(AX_CART)
5128       mm2=mm.cartesianize() # the trigger
5129       self.assertEqual(mm2.getAxisType(),AX_CART)
5130       self.assertTrue(isinstance(mm2,MEDFileCMesh))
5131       self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5132       pass
5133
5134     @WriteInTmpDir
5135     def testCheckCoherency(self):
5136       m2 = MEDCouplingUMesh("2d", 2)
5137       m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2))  # whatever
5138       m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5139       m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5140       mum = MEDFileUMesh()
5141       mum.setMeshAtLevel(0, m2)
5142       mum.setMeshAtLevel(-1, m1)
5143       mum.checkConsistency()
5144       mum2 = mum.deepCopy()
5145
5146       # Nodes
5147       arr = DataArrayInt([2]*4)
5148       mum.setFamilyFieldArr(1, arr); arr.reAlloc(35);
5149       self.assertRaises(InterpKernelException, mum.checkConsistency)
5150       mum=mum2; mum2=mum.deepCopy();
5151       arr = DataArrayInt([2]*4)
5152       mum.setRenumFieldArr(1, arr); arr.reAlloc(35);
5153       self.assertRaises(InterpKernelException, mum.checkConsistency)
5154       mum=mum2; mum2=mum.deepCopy();
5155       mum.setRenumFieldArr(1, DataArrayInt([2]*4))
5156       self.assertRaises(InterpKernelException, mum.checkConsistency)
5157       mum=mum2; mum2=mum.deepCopy();
5158       arr = DataArrayAsciiChar(['tutu           x']*4)
5159       mum.setNameFieldAtLevel(1, arr); arr.reAlloc(35);
5160       self.assertRaises(InterpKernelException, mum.checkConsistency)
5161
5162       # 2D
5163       mum=mum2; mum2=mum.deepCopy();
5164       arr = DataArrayInt([2]*2)
5165       mum.setFamilyFieldArr(0, arr); arr.reAlloc(35);
5166       self.assertRaises(InterpKernelException, mum.checkConsistency)
5167       mum=mum2; mum2=mum.deepCopy();
5168       arr = DataArrayInt([2]*2)
5169       mum.setRenumFieldArr(0, arr); arr.reAlloc(35);
5170       self.assertRaises(InterpKernelException, mum.checkConsistency)
5171       mum=mum2; mum2=mum.deepCopy();
5172       mum.setRenumFieldArr(0, DataArrayInt([2]*2))
5173       self.assertRaises(InterpKernelException, mum.checkConsistency)
5174       mum=mum2; mum2=mum.deepCopy();
5175       arr = DataArrayAsciiChar(['tutu           x']*2)
5176       mum.setNameFieldAtLevel(0, arr); arr.reAlloc(35);
5177       self.assertRaises(InterpKernelException, mum.checkConsistency)
5178
5179       # 1D
5180       mum=mum2; mum2=mum.deepCopy();
5181       arr = DataArrayInt([2]*5)
5182       mum.setFamilyFieldArr(-1, arr); arr.reAlloc(35);
5183       self.assertRaises(InterpKernelException, mum.checkConsistency)
5184       mum=mum2; mum2=mum.deepCopy();
5185       arr = DataArrayInt([2]*5)
5186       mum.setRenumFieldArr(-1, arr); arr.reAlloc(35);
5187       self.assertRaises(InterpKernelException, mum.checkConsistency)
5188       mum=mum2; mum2=mum.deepCopy();
5189       mum.setRenumFieldArr(-1, DataArrayInt([2]*5))
5190       self.assertRaises(InterpKernelException, mum.checkConsistency)
5191       mum=mum2; mum2=mum.deepCopy();
5192       arr = DataArrayAsciiChar(['tutu           x']*5)
5193       mum.setNameFieldAtLevel(-1, arr); arr.reAlloc(35);
5194       self.assertRaises(InterpKernelException, mum.checkConsistency)
5195
5196     @WriteInTmpDir
5197     def testCheckSMESHConsistency(self):
5198       m2 = MEDCouplingUMesh("2d", 2)
5199       m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2))  # whatever
5200       m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5201       m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5202       mum = MEDFileUMesh()
5203       mum.setMeshAtLevel(0, m2)
5204       mum.setMeshAtLevel(-1, m1)
5205       mum.checkConsistency()
5206       mum.checkSMESHConsistency()
5207       n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5208       n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5209       mum.setRenumFieldArr(0, n2)
5210       mum.setRenumFieldArr(-1, n1)
5211       self.assertRaises(InterpKernelException, mum.checkSMESHConsistency)
5212       mum.setRenumFieldArr(-1, n1+100)
5213       mum.checkSMESHConsistency()
5214       pass
5215
5216     @WriteInTmpDir
5217     def testClearNodeAndCellNumbers(self):
5218       m2 = MEDCouplingUMesh("2d", 2)
5219       m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2))  # whatever
5220       m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5221       m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5222       mum = MEDFileUMesh()
5223       mum.setMeshAtLevel(0, m2)
5224       mum.setMeshAtLevel(-1, m1)
5225       mum.checkConsistency()
5226       n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5227       n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5228       mum.setRenumFieldArr(0, n2)
5229       mum.setRenumFieldArr(-1, n1)
5230       mum.clearNodeAndCellNumbers()
5231       mum.checkSMESHConsistency()
5232       pass
5233
5234     @WriteInTmpDir
5235     def testCMeshSetFamilyFieldArrNull(self):
5236       meshName="mesh"
5237       fname="Pyfile99.med"
5238       arrX=DataArrayDouble([0,1,2,3])
5239       arrY=DataArrayDouble([0,1,2])
5240       m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m.setName(meshName)
5241       mm=MEDFileCMesh() ; mm.setMesh(m)
5242       famCellIds=DataArrayInt([0,-2,-2,-1,-2,0])
5243       famNodeIds=DataArrayInt([0,0,0,3,4,1,2,7,2,1,0,0])
5244       mm.setFamilyFieldArr(0,famCellIds)
5245       mm.setFamilyFieldArr(1,famNodeIds)
5246       mm.write(fname,2)
5247       mm=MEDFileMesh.New(fname)
5248       self.assertTrue(mm.getFamilyFieldAtLevel(0) is not None)
5249       self.assertTrue(mm.getFamilyFieldAtLevel(1) is not None)
5250       mm.setFamilyFieldArr(0,None)#<- bug was here
5251       mm.setFamilyFieldArr(1,None)#<- bug was here
5252       self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
5253       self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
5254       mm3=mm.deepCopy()
5255       self.assertTrue(mm3.getFamilyFieldAtLevel(0) is None)
5256       self.assertTrue(mm3.getFamilyFieldAtLevel(1) is None)
5257       mm.write(fname,2)
5258       mm2=MEDFileMesh.New(fname)
5259       self.assertTrue(mm2.getFamilyFieldAtLevel(0) is None)
5260       self.assertTrue(mm2.getFamilyFieldAtLevel(1) is None)
5261       pass
5262
5263     @WriteInTmpDir
5264     def testAppendFieldProfileOnIntField(self):
5265       fname="Pyfile100.med"
5266       arrX=DataArrayDouble([0,1,2,3])
5267       arrY=DataArrayDouble([0,1,2])
5268       mesh=MEDCouplingCMesh() ; mesh.setCoords(arrX,arrY) ; mesh.setName("Mesh")
5269       mm=MEDFileCMesh()
5270       mm.setMesh(mesh)
5271       #
5272       fmts=MEDFileIntFieldMultiTS()
5273       pflName="PFL"
5274       pfl=DataArrayInt([1,3,5]) ; pfl.setName(pflName)
5275       f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(mesh)
5276       fieldName="FieldOnCell"
5277       f.setTime(1.2,1,1) ; f.setName(fieldName)
5278       arr=DataArrayInt32([101,102,103]) ; f.setArray(arr)
5279       fmts.appendFieldProfile(f,mm,0,pfl)
5280       #
5281       mm.write(fname,2)
5282       fmts.write(fname,0)
5283       #
5284       mm=MEDFileMesh.New(fname)
5285       fmts=MEDFileAnyTypeFieldMultiTS.New(fname)
5286       self.assertTrue(isinstance(fmts,MEDFileIntFieldMultiTS))
5287       self.assertEqual(fmts.getName(),fieldName)
5288       self.assertEqual(len(fmts),1)
5289       f1ts=fmts[0]
5290       ftest,pfltest=f1ts.getFieldWithProfile(ON_CELLS,0,mm)
5291       self.assertEqual(pfltest.getName(),pflName)
5292       self.assertEqual(ftest.getName(),fieldName)
5293       self.assertTrue(ftest.isEqualWithoutConsideringStr(arr))
5294       ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
5295       self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr))
5296       self.assertEqual(ftest2.getTime(),f.getTime())
5297       self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr))
5298       pass
5299
5300     @WriteInTmpDir
5301     def testMEDFileFieldEasyField1(self):
5302       """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."""
5303       ## Basic test on cells on top level
5304       fname="Pyfile101.med"
5305       fieldName="field1"
5306       mm=MEDFileUMesh()
5307       coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5308       m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5309       m.allocateCells()
5310       m.insertNextCell(NORM_TRI3,[0,1,2])
5311       m.insertNextCell(NORM_TRI3,[3,4,5])
5312       m.insertNextCell(NORM_TRI3,[6,7,8])
5313       m.insertNextCell(NORM_TRI3,[9,10,11])
5314       m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5315       m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5316       mm[0]=m
5317       mm.write(fname,2)
5318       arr0=DataArrayDouble([10,11,12,13,100,101])
5319       f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5320       f.setName(fieldName) ; f.setTime(2.,6,7)
5321       f0=f.deepCopy()
5322       ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5323       ff.write(fname,0)
5324       arr2=arr0+1000 ; f.setArray(arr2)
5325       f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f)
5326       ff.write(fname,0)
5327       f1=f.deepCopy()
5328       ##
5329       mm=MEDFileMesh.New(fname)
5330       f1ts=MEDFileField1TS(fname,fieldName,6,7)
5331       ftst0=f1ts.field(mm)
5332       self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12))
5333       f1ts=MEDFileField1TS(fname,fieldName,8,9)
5334       ftst1=f1ts.field(mm)
5335       self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12))
5336       fmts=MEDFileFieldMultiTS(fname,fieldName)
5337       self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12))
5338       ## Basic test on nodes on top level
5339       f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5340       f2.setName(fieldName)
5341       mm.write(fname,2)
5342       ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5343       #
5344       mm=MEDFileMesh.New(fname)
5345       f1ts=MEDFileField1TS(fname,fieldName,23,24)
5346       self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12))
5347       fmts=MEDFileFieldMultiTS(fname,fieldName)
5348       self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12))
5349       ## Node on elements
5350       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)
5351       f3.setName(fieldName) ; f3.checkConsistencyLight()
5352       mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5353       #
5354       mm=MEDFileMesh.New(fname)
5355       f1ts=MEDFileField1TS(fname,fieldName,2,3)
5356       self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5357       ## Gauss
5358       f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5359       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])
5360       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)
5361       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)
5362       f4.checkConsistencyLight()
5363       mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5364       #
5365       mm=MEDFileMesh.New(fname)
5366       f1ts=MEDFileField1TS(fname,fieldName,4,5)
5367       self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5368       pass
5369
5370     @WriteInTmpDir
5371     def testMEDFileFieldEasyField2(self):
5372         """Same thantestMEDFileFieldEasyField1 except that here intfields are considered.
5373         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."""
5374         ## Basic test on cells on top level
5375         fname="Pyfile102.med"
5376         fieldName="field1"
5377         mm=MEDFileUMesh()
5378         coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5379         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5380         m.allocateCells()
5381         m.insertNextCell(NORM_TRI3,[0,1,2])
5382         m.insertNextCell(NORM_TRI3,[3,4,5])
5383         m.insertNextCell(NORM_TRI3,[6,7,8])
5384         m.insertNextCell(NORM_TRI3,[9,10,11])
5385         m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5386         m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5387         mm[0]=m
5388         mm.write(fname,2)
5389         arr0=DataArrayInt32([10,11,12,13,100,101])
5390         f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5391         f.setName(fieldName) ; f.setTime(2.,6,7)
5392         f0=f.deepCopy()
5393         ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5394         ff.write(fname,0)
5395         arr2=arr0+1000 ; f.setArray(arr2)
5396         f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f)
5397         ff.write(fname,0)
5398         f1=f.deepCopy()
5399         ##
5400         mm=MEDFileMesh.New(fname)
5401         f1ts=MEDFileIntField1TS(fname,fieldName,6,7)
5402         ftst0=f1ts.field(mm)
5403         self.assertTrue(f0.isEqual(ftst0,1e-12,0))
5404         f1ts=MEDFileIntField1TS(fname,fieldName,8,9)
5405         ftst1=f1ts.field(mm)
5406         self.assertTrue(f1.isEqual(ftst1,1e-12,0))
5407         fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5408         self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,0))
5409         ## Basic test on nodes on top level
5410         f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt32([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5411         f2.setName(fieldName)
5412         mm.write(fname,2)
5413         ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5414         #
5415         mm=MEDFileMesh.New(fname)
5416         f1ts=MEDFileIntField1TS(fname,fieldName,23,24)
5417         self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,0))
5418         fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5419         self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,0))
5420         ## Node on elements
5421         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)
5422         f3.setName(fieldName) ; f3.checkConsistencyLight()
5423         mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5424         #
5425         mm=MEDFileMesh.New(fname)
5426         f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5427         self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5428         ## Gauss
5429         f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5430         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])
5431         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)
5432         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)
5433         f4.checkConsistencyLight()
5434         mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5435         #
5436         mm=MEDFileMesh.New(fname)
5437         f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5438         self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5439         pass
5440
5441     @WriteInTmpDir
5442     def testMEDFileFieldEasyField3(self):
5443         """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."""
5444         fname="Pyfile103.med"
5445         fieldName="field1"
5446         mm=MEDFileUMesh()
5447         coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5448         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5449         m.allocateCells()
5450         m.insertNextCell(NORM_TRI3,[0,1,2])
5451         m.insertNextCell(NORM_TRI3,[3,4,5])
5452         m.insertNextCell(NORM_TRI3,[6,7,8])
5453         m.insertNextCell(NORM_TRI3,[9,10,11])
5454         m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5455         m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5456         mm[-1]=m
5457         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5458         m0.allocateCells()
5459         m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5460         m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5461         mm[0]=m0
5462         mm.write(fname,2)
5463         # start slowly
5464         f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5465         f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5466         #
5467         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2)
5468         self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5469         # here f1 lying on level -1 not 0 check if "field" method detect it !
5470         f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5471         f1.setMesh(mm[-1]) # -1 is very important
5472         f1.setTime(16.,3,4)
5473         f1.checkConsistencyLight()
5474         mm.write(fname,2)
5475         f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5476         #
5477         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4)
5478         self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5479         # nodes on elements
5480         f3=MEDCouplingFieldDouble(ON_GAUSS_NE)
5481         f3.setMesh(mm[-1]) # this line is important
5482         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)
5483         f3.setName(fieldName) ; f3.checkConsistencyLight()
5484         mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5485         #
5486         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3)
5487         self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5488         # gauss
5489         f4=MEDCouplingFieldDouble(ON_GAUSS_PT)
5490         f4.setMesh(mm[-1]) # this line is important
5491         f4.setName(fieldName)
5492         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])
5493         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)
5494         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)
5495         f4.checkConsistencyLight()
5496         mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5497         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5)
5498         self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5499         pass
5500
5501     @WriteInTmpDir
5502     def testMEDFileFieldEasyField4(self):
5503         """ Same than testMEDFileFieldEasyField3 but with integers"""
5504         fname="Pyfile104.med"
5505         fieldName="field1"
5506         mm=MEDFileUMesh()
5507         coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5508         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5509         m.allocateCells()
5510         m.insertNextCell(NORM_TRI3,[0,1,2])
5511         m.insertNextCell(NORM_TRI3,[3,4,5])
5512         m.insertNextCell(NORM_TRI3,[6,7,8])
5513         m.insertNextCell(NORM_TRI3,[9,10,11])
5514         m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5515         m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5516         mm[-1]=m
5517         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5518         m0.allocateCells()
5519         m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5520         m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5521         mm[0]=m0
5522         mm.write(fname,2)
5523         # start slowly
5524         f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt32([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5525         f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5526         #
5527         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2)
5528         self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5529         # here f1 lying on level -1 not 0 check if "field" method detect it !
5530         f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt32([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5531         f1.setMesh(mm[-1]) # -1 is very important
5532         f1.setTime(16.,3,4)
5533         f1.checkConsistencyLight()
5534         mm.write(fname,2)
5535         f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5536         #
5537         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4)
5538         self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5539         # nodes on elements
5540         f3=MEDCouplingFieldInt(ON_GAUSS_NE)
5541         f3.setMesh(mm[-1]) # this line is important
5542         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)
5543         f3.setName(fieldName) ; f3.checkConsistencyLight()
5544         mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5545         #
5546         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5547         self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5548         # gauss
5549         f4=MEDCouplingFieldInt(ON_GAUSS_PT)
5550         f4.setMesh(mm[-1]) # this line is important
5551         f4.setName(fieldName)
5552         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])
5553         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)
5554         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)
5555         f4.checkConsistencyLight()
5556         mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5557         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5558         self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5559         pass
5560
5561     @WriteInTmpDir
5562     def testMEDFileFieldEasyField5(self):
5563         """More and more difficult now look at how profiles are managed by "field" method."""
5564         fname="Pyfile105.med"
5565         fieldName="field1"
5566         mm=MEDFileUMesh()
5567         coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5568         m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5569         m.allocateCells()
5570         m.insertNextCell(NORM_TRI3,[0,1,2])
5571         m.insertNextCell(NORM_TRI3,[3,4,5])
5572         m.insertNextCell(NORM_TRI3,[6,7,8])
5573         m.insertNextCell(NORM_TRI3,[9,10,11])
5574         m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5575         m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5576         mm[0]=m
5577         mm.write(fname,2)
5578         pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl")
5579         m2=m.deepCopy()[pfl] ; m2.setName(m.getName())
5580         #
5581         arr0=DataArrayDouble([10,11,12,13])
5582         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2)
5583         f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight()
5584         ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile
5585         ff.write(fname,0)
5586         #
5587         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5588         self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5589         # more complicated -> multi level
5590         m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5591         m0.allocateCells()
5592         m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5593         m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5594         mm2=MEDFileUMesh()
5595         mm2[0]=m0 ; mm2[-1]=m
5596         #
5597         ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl)
5598         #
5599         mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5600         self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5601         pass
5602
5603     @WriteInTmpDir
5604     def testExtractPart1(self):
5605         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)])
5606         meshName="mesh"
5607         m0=MEDCouplingUMesh(meshName,2) ; m0.setCoords(coo) ; m0.allocateCells()
5608         m0.insertNextCell(NORM_TRI3,[8,4,3])
5609         m0.insertNextCell(NORM_TRI3,[8,9,4])
5610         m0.insertNextCell(NORM_TRI3,[7,13,8])
5611         m0.insertNextCell(NORM_TRI3,[7,12,13])
5612         m0.insertNextCell(NORM_TRI3,[0,6,1])
5613         m0.insertNextCell(NORM_TRI3,[0,5,6])
5614         m0.insertNextCell(NORM_QUAD4,[1,6,7,2])
5615         m0.insertNextCell(NORM_QUAD4,[2,7,8,3])
5616         m0.insertNextCell(NORM_QUAD4,[8,13,14,9])
5617         m0.insertNextCell(NORM_QUAD4,[6,11,12,7])
5618         m0.insertNextCell(NORM_QUAD4,[5,10,11,6])
5619         #
5620         m1=MEDCouplingUMesh(meshName,1) ; m1.setCoords(coo) ; m1.allocateCells()
5621         m1.insertNextCell(NORM_SEG2,[10,5])
5622         m1.insertNextCell(NORM_SEG2,[5,0])
5623         m1.insertNextCell(NORM_SEG2,[0,1])
5624         m1.insertNextCell(NORM_SEG2,[1,2])
5625         m1.insertNextCell(NORM_SEG2,[2,3])
5626         m1.insertNextCell(NORM_SEG2,[3,4])
5627         m1.insertNextCell(NORM_SEG2,[4,9])
5628         m1.insertNextCell(NORM_SEG2,[9,14])
5629         m1.insertNextCell(NORM_SEG2,[14,13])
5630         m1.insertNextCell(NORM_SEG2,[13,12])
5631         m1.insertNextCell(NORM_SEG2,[12,11])
5632         m1.insertNextCell(NORM_SEG2,[11,10])
5633         mm=MEDFileUMesh()
5634         mm[0]=m0 ; mm[-1]=m1
5635         arr0=DataArrayInt([0,1,2,3,4,6,7,8,12,13])
5636         tab={} #
5637         tab[0]=DataArrayInt([0,2,3,4,6,7])
5638         tab[-1]=DataArrayInt([2,3,4,5,9])
5639         fs=MEDFileFields()
5640         self.assertTrue(mm.deduceNodeSubPartFromCellSubPart(tab).isEqual(arr0))
5641         tab[1]=arr0
5642         #
5643         fname0="Field0"
5644         fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5645         t0=(16.5,3,4)
5646         ic=["toto [m]"]
5647         arr0_0=DataArrayDouble([100,101,102,103,104,105,106,107,108,109,110]) ; arr0_0.setInfoOnComponents(ic)
5648         f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*t0) ; f0.setArray(arr0_0)
5649         f0.setMesh(m0) ; f0.setName(fname0)
5650         f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setTime(*t0) ; f1.setArray(DataArrayDouble([200,201,202,203,204,205,206,207,208,209,210,211]))
5651         f1.setMesh(m1) ; f1.setName(fname0) ; f1.getArray().setInfoOnComponents(ic)
5652         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]))
5653         f2.setMesh(m0) ; f2.setName(fname0) ; f2.getArray().setInfoOnComponents(ic)
5654         f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.setFieldNoProfileSBT(f2)
5655         fmts.pushBackTimeStep(f1ts)
5656         #
5657         mmOut=mm.extractPart(tab)
5658         #
5659         fsPart0=fs.extractPart(tab,mm)
5660         self.assertEqual(len(fsPart0),1)
5661         fmtsP=fsPart0[0]
5662         self.assertEqual(len(fmtsP),1)
5663         f1ts=fmtsP[0]
5664         self.assertRaises(InterpKernelException,f1ts.field,mmOut)
5665         #
5666         self.assertTrue(mmOut[0].computeCellCenterOfMass().isEqual(m0[tab[0]].computeCellCenterOfMass(),1e-12))
5667         self.assertTrue(mmOut[-1].computeCellCenterOfMass().isEqual(m1[tab[-1]].computeCellCenterOfMass(),1e-12))
5668         #
5669         m0Part=m0.deepCopy()[tab[0]] ; m0Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m0Part.setName(m0.getName())
5670         self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5671         m1Part=m1.deepCopy()[tab[-1]] ; m1Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m1Part.setName(m0.getName())
5672         self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5673         self.assertTrue(mmOut[-1].isEqual(m1Part,1e-12))
5674         #
5675         f0Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mmOut) ; f0Part.checkConsistencyLight()
5676         self.assertEqual(f0Part.getTypeOfField(),ON_CELLS)
5677         self.assertTrue(f0Part.getMesh().isEqual(m0Part,1e-12))
5678         arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic)
5679         self.assertTrue(f0Part.getArray().isEqual(arr0Exp,1e-12)) ; self.assertEqual(f0Part.getTime(),list(t0))
5680         f1Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,-1,mmOut) ; f1Part.checkConsistencyLight()
5681         self.assertEqual(f1Part.getTypeOfField(),ON_CELLS)
5682         self.assertTrue(f1Part.getMesh().isEqual(m1Part,1e-12))
5683         arr1Exp=DataArrayDouble([202,203,204,205,209]) ; arr1Exp.setInfoOnComponents(ic)
5684         self.assertTrue(f1Part.getArray().isEqual(arr1Exp,1e-12)) ; self.assertEqual(f1Part.getTime(),list(t0))
5685         #
5686         f2Part=f1ts.getFieldOnMeshAtLevel(ON_NODES,0,mmOut) ; f2Part.checkConsistencyLight()
5687         arr2Exp=DataArrayDouble([300,301,302,303,304,306,307,308,312,313]) ; arr2Exp.setInfoOnComponents(ic)
5688         self.assertTrue(f2Part.getArray().isEqual(arr2Exp,1e-12)) ; self.assertEqual(f2Part.getTime(),list(t0))
5689         # multisteps
5690         fs=MEDFileFields() ; fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5691         tss=[(16.5,3,4),(17.5,4,5),(18.5,5,6)]
5692         for i,tt in enumerate(tss):
5693             f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*tt)
5694             myarr=arr0_0+i*1000.
5695             f0.setArray(myarr)
5696             f0.setMesh(m0) ; f0.setName(fname0) ; f0.getArray().setInfoOnComponents(ic)
5697             f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; fmts.pushBackTimeStep(f1ts)
5698             pass
5699         fsPart1=fs.extractPart(tab,mm)
5700         self.assertEqual(len(fsPart1),1)
5701         fmtsP=fsPart1[0]
5702         self.assertEqual(len(fmtsP),len(tss))
5703         for i,(f1tsP,tt) in enumerate(zip(fmtsP,tss)):
5704             fPart=f1tsP.field(mmOut) ; fPart.checkConsistencyLight()
5705             self.assertEqual(fPart.getTypeOfField(),ON_CELLS)
5706             arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic) ; arr0Exp+=i*1000.
5707             self.assertTrue(fPart.getMesh().isEqual(m0Part,1e-12))
5708             self.assertTrue(fPart.getArray().isEqual(arr0Exp,1e-12))
5709             self.assertEqual(fPart.getTime(),list(tt))
5710             pass
5711         pass
5712
5713     @WriteInTmpDir
5714     def testSymmetryPlusAggregationMFD1(self):
5715         """ Testing of MEDFileData::Aggregate and MEDFileUMesh::Aggregate and MEDFileUMesh::getAllDistributionOfType """
5716         fname1="Pyfile106_1.med"
5717         fname2="Pyfile106_2.med"
5718         fname3="Pyfile106_3.med"
5719         meshName="mesh"
5720         mm1=MEDFileUMesh()
5721         da1=DataArrayDouble([1,2,10,3,4,11,5,6,12,7,8,13],4,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5722         mm1.setCoords(da1)
5723         mm1_0=MEDCouplingUMesh(meshName,3) ; mm1_0.allocateCells()
5724         mm1_0.setCoords(da1)
5725         mm1_0.insertNextCell(NORM_TETRA4,[0,1,2,3])
5726         mm1_0.insertNextCell(NORM_TETRA4,[4,5,6,7])
5727         mm1_0.insertNextCell(NORM_PENTA6,[8,9,10,11,12,13])
5728         mm1_0.insertNextCell(NORM_PENTA6,[14,15,16,17,18,19])
5729         mm1_0.insertNextCell(NORM_PENTA6,[20,21,22,23,24,25])
5730         mm1[0]=mm1_0
5731         mm1.setFamilyFieldArr(0,DataArrayInt([1,2,3,4,5]))
5732         mm1.setRenumFieldArr(0,DataArrayInt([11,12,13,14,15]))
5733         #
5734         mm1_1=MEDCouplingUMesh(meshName,2) ; mm1_1.allocateCells()
5735         mm1_1.setCoords(da1)
5736         mm1_1.insertNextCell(NORM_TRI3,[0,1,2])
5737         mm1_1.insertNextCell(NORM_TRI3,[3,4,5])
5738         mm1_1.insertNextCell(NORM_QUAD4,[6,7,8,9])
5739         mm1_1.insertNextCell(NORM_QUAD4,[10,11,12,13])
5740         mm1_1.insertNextCell(NORM_QUAD4,[14,15,16,17])
5741         mm1_1.insertNextCell(NORM_QUAD4,[18,19,20,21])
5742         mm1[-1]=mm1_1
5743         mm1.setFamilyFieldArr(-1,DataArrayInt([6,7,8,9,10,11]))
5744         mm1.setRenumFieldArr(-1,DataArrayInt([16,17,18,19,20,21]))
5745         for i in range(1,10):
5746             mm1.setFamilyId("F%d"%i,i)
5747         mm1.setFamilyId("FAMILLE_ZERO",0)
5748         mm1.setFamilyId("H1",100)
5749         mm1.setFamiliesOnGroup("myGRP",["F2","F6"])
5750         mm1.setFamiliesOnGroup("myGRP1",["F2","F6"])
5751         mm1.setFamilyFieldArr(1,DataArrayInt([12,13,14,15]))
5752         mm1.setRenumFieldArr(1,DataArrayInt([22,23,24,25]))
5753         ##############
5754         mm2=MEDFileUMesh()
5755         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]"])
5756         mm2.setCoords(da1)
5757         mm2_0=MEDCouplingUMesh(meshName,3) ; mm2_0.allocateCells()
5758         mm2_0.setCoords(da1)
5759         mm2_0.insertNextCell(NORM_TETRA4,[100,101,102,103])
5760         mm2_0.insertNextCell(NORM_TETRA4,[104,105,106,107])
5761         mm2_0.insertNextCell(NORM_TETRA4,[108,109,110,111])
5762         mm2_0.insertNextCell(NORM_PENTA6,[112,113,114,115,116,117])
5763         mm2[0]=mm2_0
5764         mm2.setFamilyFieldArr(0,DataArrayInt([40,41,42,43]))
5765         mm2.setRenumFieldArr(0,DataArrayInt([50,51,52,53]))
5766         #
5767         mm2_1=MEDCouplingUMesh(meshName,2) ; mm2_1.allocateCells()
5768         mm2_1.setCoords(da1)
5769         mm2_1.insertNextCell(NORM_TRI3,[100,101,102])
5770         mm2_1.insertNextCell(NORM_TRI3,[103,104,105])
5771         mm2_1.insertNextCell(NORM_TRI3,[106,107,108])
5772         mm2_1.insertNextCell(NORM_QUAD4,[109,110,111,112])
5773         mm2_1.insertNextCell(NORM_QUAD4,[113,114,115,116])
5774         mm2_1.insertNextCell(NORM_QUAD4,[117,118,119,120])
5775         mm2_1.insertNextCell(NORM_QUAD4,[121,122,123,124])
5776         mm2_1.insertNextCell(NORM_QUAD4,[125,126,127,128])
5777         mm2[-1]=mm2_1
5778         mm2.setFamilyFieldArr(-1,DataArrayInt([200,201,202,203,204,205,206,207]))
5779         mm2.setRenumFieldArr(-1,DataArrayInt([300,301,302,303,304,305,306,307]))
5780         for i in range(1,12):
5781             mm2.setFamilyId("G%d"%i,i+30)
5782         mm2.setFamilyId("H1",100)
5783         mm2.setFamilyId("FAMILLE_ZERO",0)
5784         mm2.setFamiliesOnGroup("myGRP",["G2","G6"])
5785         mm2.setFamiliesOnGroup("myGRP2",["G4","G7"])
5786         mm2.setFamilyFieldArr(1,DataArrayInt([112,113,114,115,116]))
5787         mm2.setRenumFieldArr(1,DataArrayInt([122,123,124,125,126]))
5788         #
5789         mm=MEDFileUMesh.Aggregate([mm1,mm2])
5790         #######
5791         def CheckMesh(tester,mm):
5792             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]"])
5793             tester.assertTrue(mm.getCoords().isEqual(cooExp,1e-12))
5794             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])))
5795             tester.assertTrue(mm[0].getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,32,39,46,53])))
5796             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])))
5797             tester.assertTrue(mm[-1].getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20,25,30,35,40,45,50,55,60,65])))
5798             tester.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([1,2,40,41,42,3,4,5,43])))
5799             tester.assertTrue(mm.getNumberFieldAtLevel(0).isEqual(DataArrayInt([11,12,50,51,52,13,14,15,53])))
5800             tester.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(DataArrayInt([6,7,200,201,202,8,9,10,11,203,204,205,206,207])))
5801             tester.assertTrue(mm.getNumberFieldAtLevel(-1).isEqual(DataArrayInt([16,17,300,301,302,18,19,20,21,303,304,305,306,307])))
5802             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)]
5803             tester.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
5804             tester.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
5805             tester.assertEqual(mm.getGroupsNames(),('myGRP','myGRP1','myGRP2'))
5806             tester.assertEqual(mm.getAllDistributionOfTypes(),[(NORM_TRI3,5),(NORM_QUAD4,9),(NORM_TETRA4,5),(NORM_PENTA6,4),(NORM_ERROR,9)])
5807             pass
5808         CheckMesh(self,mm)
5809         ##
5810         fieldName="zeField"
5811         t1=(2.3,3,5)
5812         t2=(5.6,7,12)
5813         infoc=["dd [W]","eee [kA]"]
5814         ##
5815         fmts1=MEDFileFieldMultiTS()
5816         f1ts1=MEDFileField1TS()
5817         f1_1=MEDCouplingFieldDouble(ON_CELLS) ; f1_1.setMesh(mm1[0]) ; f1_1.setName(fieldName)
5818         arr1=DataArrayDouble([(10,110),(11,111),(12,112),(13,113),(14,114)])
5819         arr1.setInfoOnComponents(infoc)
5820         f1_1.setArray(arr1) ; f1_1.setTime(*t1) ; f1_1.setTimeUnit("ms")
5821         f1_1.checkConsistencyLight()
5822         f1ts1.setFieldNoProfileSBT(f1_1)
5823         #
5824         f1_2=MEDCouplingFieldDouble(ON_CELLS) ; f1_2.setMesh(mm1[-1]) ; f1_2.setName(fieldName)
5825         arr2=DataArrayDouble([(15,115),(16,116),(17,117),(18,118),(19,119),(20,120)])
5826         arr2.setInfoOnComponents(infoc)
5827         f1_2.setArray(arr2) ; f1_2.setTime(*t1) ; f1_2.setTimeUnit("ms")
5828         f1_2.checkConsistencyLight()
5829         f1ts1.setFieldNoProfileSBT(f1_2)
5830         f1_3=MEDCouplingFieldDouble(ON_NODES) ; f1_3.setMesh(mm1[0]) ; f1_3.setName(fieldName)
5831         arr3=DataArrayDouble([(21,121),(22,122),(23,123),(24,124)])
5832         arr3.setInfoOnComponents(infoc)
5833         f1_3.setArray(arr3) ; f1_3.setTime(*t1) ; f1_3.setTimeUnit("ms")
5834         f1_3.checkConsistencyLight()
5835         f1ts1.setFieldNoProfileSBT(f1_3)
5836         fmts1.pushBackTimeStep(f1ts1)
5837         #
5838         f1ts2=f1ts1.deepCopy()
5839         f1ts2.setTime(t2[1],t2[2],t2[0])
5840         f1ts2.getUndergroundDataArray()[:]+=2000
5841         fmts1.pushBackTimeStep(f1ts2)
5842         ### fmts2
5843         fmts2=MEDFileFieldMultiTS()
5844         f1ts3=MEDFileField1TS()
5845         f2_1=MEDCouplingFieldDouble(ON_CELLS) ; f2_1.setMesh(mm2[0]) ; f2_1.setName(fieldName)
5846         arr4=DataArrayDouble([(50,150),(51,151),(52,152),(53,153)])
5847         arr4.setInfoOnComponents(infoc)
5848         f2_1.setArray(arr4) ; f2_1.setTime(*t1) ; f2_1.setTimeUnit("ms")
5849         f2_1.checkConsistencyLight()
5850         f1ts3.setFieldNoProfileSBT(f2_1)
5851         f2_2=MEDCouplingFieldDouble(ON_CELLS) ; f2_2.setMesh(mm2[-1]) ; f2_2.setName(fieldName)
5852         arr5=DataArrayDouble([(54,154),(55,155),(56,156),(57,157),(158,158),(59,159),(60,160),(61,161)])
5853         arr5.setInfoOnComponents(infoc)
5854         f2_2.setArray(arr5) ; f2_2.setTime(*t1) ; f2_2.setTimeUnit("ms")
5855         f2_2.checkConsistencyLight()
5856         f1ts3.setFieldNoProfileSBT(f2_2)
5857         f2_3=MEDCouplingFieldDouble(ON_NODES) ; f2_3.setMesh(mm2[0]) ; f2_3.setName(fieldName)
5858         arr6=DataArrayDouble([(62,162),(63,163),(64,164),(65,165),(66,166)])
5859         arr6.setInfoOnComponents(infoc)
5860         f2_3.setArray(arr6) ; f2_3.setTime(*t1) ; f2_3.setTimeUnit("ms")
5861         f2_3.checkConsistencyLight()
5862         f1ts3.setFieldNoProfileSBT(f2_3)
5863         fmts2.pushBackTimeStep(f1ts3)
5864         #
5865         f1ts4=f1ts3.deepCopy()
5866         f1ts4.setTime(t2[1],t2[2],t2[0])
5867         f1ts4.getUndergroundDataArray()[:]+=2000
5868         fmts2.pushBackTimeStep(f1ts4)
5869         #
5870         mfd1=MEDFileData()
5871         mfd1.setMeshes(MEDFileMeshes())
5872         mfd1.getMeshes().pushMesh(mm1)
5873         mfd1.setFields(MEDFileFields())
5874         mfd1.getFields().pushField(fmts1)
5875         #
5876         mfd2=MEDFileData()
5877         mfd2.setMeshes(MEDFileMeshes())
5878         mfd2.getMeshes().pushMesh(mm2)
5879         mfd2.setFields(MEDFileFields())
5880         mfd2.getFields().pushField(fmts2)
5881         # ze Call !
5882         mfd=MEDFileData.Aggregate([mfd1,mfd2])
5883         def CheckMFD(tester,mfd):
5884             tester.assertEqual(len(mfd.getMeshes()),1)
5885             tester.assertEqual(len(mfd.getFields()),1)
5886             CheckMesh(self,mfd.getMeshes()[0])
5887             tester.assertEqual(len(mfd.getFields()[0]),2)
5888             zeF1=mfd.getFields()[0][0]
5889             zeF1_1=zeF1.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5890             ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5891             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5892             ref.renumberCells(o2n)
5893             tester.assertTrue(ref.isEqual(zeF1_1,1e-12,1e-12))
5894             zeF1_2=zeF1.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5895             ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5896             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5897             ref.renumberCells(o2n)
5898             tester.assertTrue(ref.isEqual(zeF1_2,1e-12,1e-12))
5899             zeF1_3=zeF1.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5900             ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5901             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5902             ref.renumberCells(o2n)
5903             tester.assertTrue(ref.isEqual(zeF1_3,1e-12,1e-12))
5904             #
5905             zeF2=mfd.getFields()[0][1]
5906             zeF2_1=zeF2.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5907             ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5908             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5909             ref.renumberCells(o2n)
5910             ref.setTime(*t2) ; ref.getArray()[:]+=2000
5911             tester.assertTrue(ref.isEqual(zeF2_1,1e-12,1e-12))
5912             zeF2_2=zeF2.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5913             ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5914             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5915             ref.renumberCells(o2n)
5916             ref.setTime(*t2) ; ref.getArray()[:]+=2000
5917             tester.assertTrue(ref.isEqual(zeF2_2,1e-12,1e-12))
5918             zeF2_3=zeF2.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5919             ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5920             o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5921             ref.renumberCells(o2n)
5922             ref.setTime(*t2) ; ref.getArray()[:]+=2000
5923             tester.assertTrue(ref.isEqual(zeF2_3,1e-12,1e-12))
5924         CheckMFD(self,mfd)
5925         mfd1.write(fname1,2) ; mfd2.write(fname2,2)
5926         mfd=MEDFileData.Aggregate([MEDFileData(fname1),MEDFileData(fname2)])
5927         CheckMFD(self,mfd)
5928         pass
5929
5930     @WriteInTmpDir
5931     def testAggregateWithGroups(self):
5932         """ Testing MEDFileUMesh::Aggretate when groups are present. """
5933         def generate(grp_name, offset):
5934             coo = DataArrayDouble([0., 1., 2.])
5935             coo += offset
5936             m = MEDCouplingCMesh("toto")
5937             m.setCoords(coo, coo)
5938             m = m.buildUnstructured()
5939             mu = MEDFileUMesh.New()
5940             mu.setMeshAtLevel(0, m)
5941             g = DataArrayInt([0])
5942             g.setName(grp_name)
5943             g2 = DataArrayInt([1])
5944             g2.setName("common")  # make a common group for all meshes being merged
5945             mu.setGroupsAtLevel(0, [g, g2])
5946             return mu
5947
5948         m1 = generate("A", 0.)
5949         m2 = generate("B", 2.)
5950         mm = MEDFileUMesh.Aggregate([m1,m2])
5951
5952         self.assertEqual(mm.getFamilyFieldAtLevel(0).getValues(), [-2, -3, -1, -1, -4, -5, -1, -1])
5953         self.assertEqual(mm.getNumberFieldAtLevel(0), None)
5954         refFamIds=[('Family_-1',-1),('Family_-2',-2),('Family_-3',-3), ('Family_-4',-4), ('Family_-5',-5)]
5955         self.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
5956         self.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
5957         self.assertEqual(mm.getGroupsNames(),('A','B', 'common'))
5958         self.assertEqual(mm.getGroupArr(0, 'A').getValues(), [0])
5959         self.assertEqual(mm.getGroupArr(0, 'B').getValues(), [4])
5960         self.assertEqual(mm.getGroupArr(0, 'common').getValues(), [1,5])
5961
5962         pass
5963
5964     @WriteInTmpDir
5965     def testExtrudedMesh1(self):
5966         fname="Pyfile107.med"
5967         arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5])
5968         mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ) ; mesh3D.setName("mesh")
5969         ex=MEDCouplingMappedExtrudedMesh(mesh3D)
5970         mm=MEDFileUMesh(ex)
5971         mm.write(fname,2)
5972         ex2=mm.convertToExtrudedMesh()
5973         mm2=MEDFileMesh.New(fname)
5974         ex3=mm2.convertToExtrudedMesh()
5975         self.assertTrue(ex.isEqual(ex2,1e-12))
5976         self.assertTrue(ex.isEqual(ex3,1e-12))
5977         pass
5978
5979     @unittest.skipUnless(LooseVersion(MEDFileVersionStr())>=LooseVersion('3.2.1'),"This test requires at least MEDFile version 3.2.1")
5980     @WriteInTmpDir
5981     def testWriteInto30(self):
5982         fname="Pyfile108.med"
5983         fname2="Pyfile109.med"
5984         m=MEDCouplingUMesh("mesh",1) ; m.setCoords(DataArrayDouble([0,0,1,1],2,2)) ; m.allocateCells() ; m.insertNextCell(NORM_SEG2,[1,0])
5985         mm=MEDFileUMesh() ; mm[0]=m
5986         mm.setFamilyId("FAMILLE_ZERO",0)
5987         #
5988         mm.write33(fname,2)
5989         assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==[3,3]) # checks that just written MED file has a version == 3.0.x
5990         mm2=MEDFileUMesh(fname)
5991         self.assertTrue(mm.isEqual(mm2,1e-12))
5992         #
5993         mm.write(fname2,2)
5994         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
5995         pass
5996
5997     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
5998     @WriteInTmpDir
5999     def testPickelizationOfMEDFileObjects1(self):
6000         fname="Pyfile110.med"
6001         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)
6002         m0=MEDCouplingUMesh("Mesh",2)
6003         m0.allocateCells(5)
6004         m0.insertNextCell(NORM_TRI3,[1,4,2])
6005         m0.insertNextCell(NORM_TRI3,[4,5,2])
6006         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
6007         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
6008         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
6009         m0.finishInsertingCells()
6010         m0.setCoords(coo)
6011         m1=MEDCouplingUMesh(m0.getName(),1)
6012         m1.allocateCells(9)
6013         conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
6014         for i in range(9):
6015             m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
6016             pass
6017         m1.finishInsertingCells()
6018         m1.setCoords(coo)
6019         #
6020         m=MEDFileUMesh()
6021         m.setMeshAtLevel(0,m0)
6022         m.setMeshAtLevel(-1,m1)
6023         #
6024         dt=3 ; it=2 ; tim=4.5
6025         fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
6026         fieldNode0.setName("fieldNode0")
6027         fieldNode0.setTime(tim,dt,it)
6028         pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
6029         arr=DataArrayDouble([10,11,12,13,14])
6030         fieldNode0.setArray(arr)
6031         f0=MEDFileField1TS()
6032         f0.setFieldProfile(fieldNode0,m,0,pfl0)
6033         fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
6034         fieldNode1.setName("fieldNode1")
6035         fieldNode1.setTime(tim,dt,it)
6036         pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
6037         arr1=DataArrayDouble([20,21,22,23,24,25,26])
6038         fieldNode1.setArray(arr1)
6039         f1=MEDFileField1TS()
6040         f1.setFieldProfile(fieldNode1,m,-1,pfl1)
6041         mfd=MEDFileData()
6042         mfd.setMeshes(MEDFileMeshes()) ; mfd.setFields(MEDFileFields())
6043         mfd.getMeshes().pushMesh(m)
6044         fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(f0)
6045         mfd.getFields().pushField(fmts)
6046         # first start gently
6047         d=mfd.serialize()
6048         mfd2=MEDFileData(d)
6049         self.assertEqual(len(mfd2.getMeshes()),1)
6050         self.assertEqual(len(mfd2.getFields()),1)
6051         self.assertEqual(len(mfd2.getFields()[0]),1)
6052         self.assertTrue(mfd2.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
6053         ff2=mfd2.getFields()[0][0].field(mfd2.getMeshes()[0])
6054         ff =mfd.getFields()[0][0].field(mfd.getMeshes()[0])
6055         self.assertTrue(ff2.isEqual(ff,1e-12,1e-12))
6056         # OK now end of joke -> serialization of MEDFileData
6057         st=pickle.dumps(mfd,pickle.HIGHEST_PROTOCOL)
6058         mfd3=pickle.loads(st)
6059         # check of object
6060         self.assertEqual(len(mfd3.getMeshes()),1)
6061         self.assertEqual(len(mfd3.getFields()),1)
6062         self.assertEqual(len(mfd3.getFields()[0]),1)
6063         self.assertTrue(mfd3.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
6064         ff3=mfd3.getFields()[0][0].field(mfd3.getMeshes()[0])
6065         self.assertTrue(ff3.isEqual(ff,1e-12,1e-12))
6066         # serialization of MEDFileFields
6067         st=pickle.dumps(mfd.getFields(),pickle.HIGHEST_PROTOCOL)
6068         fs4=pickle.loads(st)
6069         ff4=fs4[0][0].field(mfd3.getMeshes()[0])
6070         self.assertTrue(ff4.isEqual(ff,1e-12,1e-12))
6071         # serialization of MEDFileFieldMulitTS
6072         st=pickle.dumps(mfd.getFields()[0],pickle.HIGHEST_PROTOCOL)
6073         fmts5=pickle.loads(st)
6074         ff5=fmts5[0].field(mfd3.getMeshes()[0])
6075         self.assertTrue(ff5.isEqual(ff,1e-12,1e-12))
6076         # serialization of MEDFileField1TS
6077         st=pickle.dumps(mfd.getFields()[0][0],pickle.HIGHEST_PROTOCOL)
6078         f1ts6=pickle.loads(st)
6079         ff6=f1ts6.field(mfd3.getMeshes()[0])
6080         self.assertTrue(ff6.isEqual(ff,1e-12,1e-12))
6081         # serialization of MEDFileMeshes
6082         st=pickle.dumps(mfd.getMeshes(),pickle.HIGHEST_PROTOCOL)
6083         ms7=pickle.loads(st)
6084         self.assertEqual(len(ms7),1)
6085         self.assertTrue(ms7[0].isEqual(mfd.getMeshes()[0],1e-12))
6086         pass
6087
6088     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
6089     @WriteInTmpDir
6090     def testPickelizationOfMEDFileObjects2(self):
6091         # CMesh
6092         self.internalMEDMesh6() # generates MEDFileMesh5.med file
6093         mm=MEDFileMesh.New("MEDFileMesh5.med")
6094         self.assertTrue(isinstance(mm,MEDFileCMesh))
6095         st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
6096         mm2=pickle.loads(st)
6097         self.assertTrue(isinstance(mm2,MEDFileCMesh))
6098         self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12))
6099         # CurveLinear
6100         self.internalCurveLinearMesh1() # generates Pyfile55.med
6101         mm=MEDFileMesh.New("Pyfile55.med")
6102         self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh))
6103         st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
6104         mm3=pickle.loads(st)
6105         self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh))
6106         self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12))
6107         self.internalInt32InMEDFileFieldStar1()# generates Pyfile63.med
6108         # MEDFileIntFieldMultiTS
6109         fs4=MEDFileFields("Pyfile63.med")
6110         ms4=MEDFileMeshes("Pyfile63.med")
6111         self.assertTrue(isinstance(fs4[0],MEDFileIntFieldMultiTS))
6112         st=pickle.dumps(fs4[0],pickle.HIGHEST_PROTOCOL)
6113         fmts5=pickle.loads(st)
6114         self.assertEqual(len(fs4[0]),len(fmts5))
6115         self.assertTrue(isinstance(fmts5,MEDFileIntFieldMultiTS))
6116         self.assertTrue(fmts5[0].field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
6117         # MEDFileIntField1TS
6118         st=pickle.dumps(fs4[0][0],pickle.HIGHEST_PROTOCOL)
6119         f1ts6=pickle.loads(st)
6120         self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS))
6121         self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
6122         # MEDFileParameters
6123         self.internalParameters1()# generates Pyfile56.med
6124         params=MEDFileParameters("Pyfile56.med")
6125         st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL)
6126         params7=pickle.loads(st)
6127         self.assertEqual(len(params),len(params7))
6128         for i in range(len(params)):
6129             self.assertTrue(params[i].isEqual(params7[i],1e-12)[0])
6130             pass
6131         pass
6132
6133     @WriteInTmpDir
6134     def testGlobalNumOnNodes1(self):
6135         """Test global number on nodes here. Used by partitionners."""
6136         fname="Pyfile112.med"
6137         arr=DataArrayDouble(5) ; arr.iota()
6138         m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
6139         m.setName("mesh")
6140         mm=MEDFileUMesh()
6141         mm[0]=m
6142         self.assertTrue(not mm.getGlobalNumFieldAtLevel(1))
6143         d=DataArrayInt([7,8,9,2,0])
6144         dRef=d.deepCopy()
6145         mm.setGlobalNumFieldAtLevel(1,d)
6146         mm.checkConsistency()
6147         self.assertRaises(InterpKernelException,mm.setGlobalNumFieldAtLevel,1,d[::2])
6148         mm.checkConsistency()
6149         self.assertEqual(d.getHiddenCppPointer(),mm.getGlobalNumFieldAtLevel(1).getHiddenCppPointer())
6150         self.assertTrue(mm.getGlobalNumFieldAtLevel(1).isEqual(dRef))
6151         mm.write(fname,2)
6152         mm2=MEDFileMesh.New(fname)
6153         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
6154         self.assertTrue(mm2.getGlobalNumFieldAtLevel(1).isEqual(dRef))
6155         mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,10)
6156         self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
6157         mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,7)
6158         self.assertTrue(mm.isEqual(mm2,1e-12)[0])
6159         pass
6160
6161     @WriteInTmpDir
6162     def testPartialReadOfEntities1(self):
6163         """Test for advanced API on read to speed up read phase for users with "huge" number of time steps (more than 10 000)."""
6164         fname="Pyfile113.med"
6165         arr=DataArrayDouble(5) ; arr.iota()
6166         m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
6167         m.setName("mesh")
6168         mm=MEDFileUMesh()
6169         mm[0]=m
6170         #
6171         fieldName="Field"
6172         ts1=(5.,1,2)
6173         f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m) ; f1.setName(fieldName)
6174         f1.setArray(DataArrayDouble([0.,0.1,0.2,0.3,0.4]))
6175         f1.setTime(*ts1)
6176         f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m) ; f2.setName(fieldName)
6177         f2.setArray(DataArrayDouble([1.,1.1,1.2,1.3]))
6178         f2.setTime(*ts1)
6179         f1ts=MEDFileField1TS()
6180         f1ts.setFieldNoProfileSBT(f1)
6181         f1ts.setFieldNoProfileSBT(f2)
6182         self.assertEqual(set(f1ts.getTypesOfFieldAvailable()),set([ON_NODES,ON_CELLS]))
6183         f1ts_2=f1ts.deepCopy()
6184         f1ts_2.getUndergroundDataArray()[:]+=2
6185         f1ts_2.setTime(3,4,6.)
6186         fmts=MEDFileFieldMultiTS()
6187         fmts.pushBackTimeStep(f1ts)
6188         fmts.pushBackTimeStep(f1ts_2)
6189         #
6190         mm.write(fname,2)
6191         fmts.write(fname,0)
6192         #
6193         ent=MEDFileEntities.BuildFrom([(ON_NODES,NORM_ERROR)])
6194         mm=MEDFileMesh.New(fname)
6195         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)
6196         fs.loadArrays()
6197         self.assertEqual(len(fs),1)
6198         fmts=fs[0]
6199         self.assertEqual(len(fmts),2)
6200         ff0=fmts[0] ; ff1=fmts[1]
6201         self.assertEqual(ff0.getTypesOfFieldAvailable(),[ON_NODES]) # only NODES have been loaded
6202         self.assertTrue(ff0.field(mm).isEqual(f1,1e-12,1e-12))
6203         f3=f1.deepCopy() ; f3+=2. ; f3.setTime(6.,3,4)
6204         self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
6205         pass
6206
6207     @WriteInTmpDir
6208     def testFloat32InMEDFileFieldStar1(self):
6209         """Like testInt32InMEDFileFieldStar1 but with float32 :)"""
6210         fname="Pyfile114.med"
6211         f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
6212         f1=f1.convertToFloatField()
6213         m1=f1.getMesh()
6214         mm1=MEDFileUMesh.New()
6215         mm1.setCoords(m1.getCoords())
6216         mm1.setMeshAtLevel(0,m1)
6217         mm1.setName(m1.getName())
6218         mm1.write(fname,2)
6219         ff1=MEDFileFloatField1TS()
6220         ff1.setFieldNoProfileSBT(f1)
6221         a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6222         self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6223         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6224         ff1.write(fname,0)
6225         a,b=ff1.getUndergroundDataArrayExt()
6226         self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
6227         self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
6228         ff2=MEDFileAnyTypeField1TS.New(fname)
6229         self.assertEqual(ff2.getName(),"VectorFieldOnCells")
6230         self.assertEqual(ff2.getTime(),[0,1,2.0])
6231         self.assertTrue(isinstance(ff2,MEDFileFloatField1TS))
6232         a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6233         self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6234         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6235         ff2.setTime(1,2,3.)
6236         c=ff2.getUndergroundDataArray() ; c*=2
6237         ff2.write(fname,0) # 2 time steps in
6238         ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
6239         self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
6240         self.assertEqual(len(ffs1),2)
6241         self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS))
6242         a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6243         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6244         a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
6245         self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6246         it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
6247         a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6248         self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7))
6249         f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
6250         self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2
6251         bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6252         for it in ffs1:
6253             a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6254             bc+=a.getArray()
6255             pass
6256         self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7))
6257         nf1=MEDCouplingFieldFloat(ON_NODES)
6258         nf1.setTime(9.,10,-1)
6259         nf1.setMesh(f1.getMesh())
6260         narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
6261         nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
6262         nff1=MEDFileFloatField1TS.New()
6263         nff1.setFieldNoProfileSBT(nf1)
6264         self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
6265         self.assertEqual(nff1.getTime(),[10,-1,9.0])
6266         nff1.write(fname,0)
6267         #
6268         nf2=MEDCouplingFieldFloat(ON_NODES)
6269         nf2.setTime(19.,20,-11)
6270         nf2.setMesh(f1.getMesh())
6271         narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10  ; narr2[:,1]=3*narr2[:,0]
6272         nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
6273         nff2=MEDFileFloatField1TS.New()
6274         npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
6275         nff2.setFieldProfile(nf2,mm1,0,npfl)
6276         nff2.getFieldWithProfile(ON_NODES,0,mm1)
6277         a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6278         self.assertTrue(b.isEqual(npfl))
6279         self.assertTrue(a.isEqual(narr2,1e-7))
6280         nff2.write(fname,0)
6281         nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl")
6282         a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6283         self.assertTrue(b.isEqual(npfl))
6284         self.assertTrue(a.isEqual(narr2,1e-7))
6285         #
6286         nf3=MEDCouplingFieldDouble(ON_NODES)
6287         nf3.setName("VectorFieldOnNodesDouble")
6288         nf3.setTime(29.,30,-21)
6289         nf3.setMesh(f1.getMesh())
6290         nf3.setArray(f1.getMesh().getCoords())
6291         nff3=MEDFileField1TS.New()
6292         nff3.setFieldNoProfileSBT(nf3)
6293         nff3.write(fname,0)
6294         fs=MEDFileFields(fname)
6295         self.assertEqual(len(fs),4)
6296         ffs=[it for it in fs]
6297         self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS))
6298         self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS))
6299         self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
6300         self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS))
6301         #
6302         self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7))
6303         self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7))
6304         self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7))
6305         self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7))
6306         self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6307         #
6308         nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
6309         self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6310         self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
6311         self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
6312         MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
6313         self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
6314         MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1)
6315         self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
6316         #
6317         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
6318         self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6319         self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
6320         self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6321         pass
6322
6323     @WriteInTmpDir
6324     def testPenta18_1(self):
6325         """EDF8478 : Test of read/write of penta18"""
6326         fname="Pyfile115.med"
6327         arr=DataArrayDouble([
6328             (0.,1.,1.),(0.,0.,1.),(1.,0.,1.),
6329             (0.,1.,0.),(0.,0.,0.),(1.,0.,0.),
6330             (0.,0.5,1.),(0.5,0.,1.),(0.5,0.5,1.),
6331             (0.,0.5,0.),(0.5,0.,0.),(0.5,0.5,0.),
6332             (0.,1.,0.5),(0.,0.,0.5),(1.,0.,0.5),
6333             (0.,0.5,0.5),(0.5,0.,0.5),(0.5,0.5,0.5)])
6334         m=MEDCouplingUMesh("mesh",3)
6335         m.setCoords(arr)
6336         m.allocateCells(1)
6337         m.insertNextCell(NORM_PENTA18,list(range(18)))
6338         m.checkConsistencyLight()
6339         #
6340         f=MEDCouplingFieldDouble(ON_NODES)
6341         f.setMesh(m)
6342         f.setName("FieldOnPenta18")
6343         f.setArray(DataArrayDouble(list(range(18))))
6344         f.checkConsistencyLight()
6345         #
6346         m2,d,di,rd,rdi=m.buildDescendingConnectivity()
6347         #
6348         f2=MEDCouplingFieldDouble(ON_NODES)
6349         f2.setMesh(m)
6350         f2.setName("FieldOnPenta18Sub")
6351         f2.setArray(DataArrayDouble(list(range(18))))
6352         f2.checkConsistencyLight()
6353         WriteField(fname,f2,True)
6354         f3=ReadField(fname)
6355         self.assertTrue(f2.isEqual(f3,1e-12,1e-12))
6356         self.assertEqual(f3.getMesh().getNumberOfCells(),1)
6357         self.assertEqual(f3.getMesh().getTypeOfCell(0),NORM_PENTA18)
6358         pass
6359
6360     @WriteInTmpDir
6361     def testFieldsLinearToQuadratic(self):
6362         fname="Pyfile117.med"
6363         arr=DataArrayDouble([0,1])
6364         m=MEDCouplingCMesh();
6365         m.setCoords(arr,arr,arr)
6366         m=m.buildUnstructured()
6367         m2=m.deepCopy()
6368         m2.translate([2,0,0])
6369         m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6370         m3.setName("mesh")
6371         mm=MEDFileUMesh()
6372         mm[0]=m3
6373         mmq=mm.linearToQuadratic(0)
6374         mms=MEDFileMeshes() ; mms.pushMesh(mm)
6375         mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6376         #
6377         f=MEDCouplingFieldDouble(ON_NODES)
6378         f.setName("field")
6379         f.setMesh(m3)
6380         f.setTime(3.,1,2)
6381         arr=DataArrayDouble(m3.getNumberOfNodes())
6382         arr.iota()
6383         f.setArray(arr)
6384         f1ts=MEDFileField1TS()
6385         f1ts.setFieldNoProfileSBT(f)
6386         fmts=MEDFileFieldMultiTS()
6387         fmts.pushBackTimeStep(f1ts)
6388         f1ts_2=f1ts.deepCopy()
6389         f1ts_2.setTime(3,4,5.)
6390         f1ts_2.getUndergroundDataArray()[:]*=2.
6391         fmts.pushBackTimeStep(f1ts_2)
6392         fs=MEDFileFields()
6393         fs.pushField(fmts)
6394         fs2=fs.linearToQuadratic(mms,mmsq)
6395         self.myTester1(fs2,mmsq[0])
6396         # A small Write/Read and test again
6397         mms.write(fname,2) ; fs.write(fname,0)
6398         mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6399         mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6400         fs2=fs.linearToQuadratic(mms,mmqs)
6401         self.myTester1(fs2,mmqs[0])
6402         pass
6403
6404     def myTester1(self,fs2,mmq):
6405         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)
6406         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])
6407         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])
6408         fToTest=fs2[0][0].field(mmq)
6409         self.assertEqual(fToTest.getTime(),[3.,1,2])
6410         mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6411         self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6412         self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6413         self.assertTrue(fToTest.getArray().isEqual(dataExp2,1e-12))
6414         # testing 2nd timestep
6415         fToTest=fs2[0][1].field(mmq)
6416         self.assertEqual(fToTest.getTime(),[5.,3,4])
6417         mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6418         self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6419         self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6420         self.assertTrue(fToTest.getArray().isEqual(2*dataExp2,1e-12))
6421         pass
6422
6423     @WriteInTmpDir
6424     def testFieldsLinearToQuadratic2(self):
6425         """Same than testFieldsLinearToQuadratic but with profile on NODES"""
6426         GeneratePyfile18(self)
6427         fname="Pyfile118.med"
6428         arr=DataArrayDouble([0,1])
6429         m=MEDCouplingCMesh();
6430         m.setCoords(arr,arr,arr)
6431         m=m.buildUnstructured()
6432         m2=m.deepCopy()
6433         m2.translate([2,0,0])
6434         m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6435         m3.setName("mesh")
6436         # add a point for fun
6437         m3.setCoords(DataArrayDouble.Aggregate(m3.getCoords(),DataArrayDouble([1.5,1.5,1.5],1,3)))
6438         #
6439         mm=MEDFileUMesh()
6440         mm[0]=m3
6441         mmq=mm.linearToQuadratic(0)
6442         mms=MEDFileMeshes() ; mms.pushMesh(mm)
6443         mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6444         #
6445         f=MEDCouplingFieldDouble(ON_NODES)
6446         f.setName("field")
6447         f.setMesh(m3)
6448         f.setTime(3.,1,2)
6449         arr=DataArrayDouble(8) ; arr.iota()
6450         arr.iota()
6451         f.setArray(arr)
6452         f1ts=MEDFileField1TS()
6453         pfl=DataArrayInt([8,9,10,11,12,13,14,15]) ; pfl.setName("pfl")
6454         f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 8 nodes of cell #1
6455         f1ts_2=f1ts.deepCopy()
6456         f1ts_2.setTime(3,4,5.)
6457         f1ts_2.getUndergroundDataArray()[:]*=4.
6458         fmts=MEDFileFieldMultiTS()
6459         fmts.pushBackTimeStep(f1ts)
6460         fmts.pushBackTimeStep(f1ts_2)
6461         fs=MEDFileFields()
6462         fs.pushField(fmts)
6463         fs2=fs.linearToQuadratic(mms,mmsq)
6464         mms.write(fname,2) ; fs.write(fname,0)
6465         #
6466         self.myTester2(fs2,mmq)
6467         # Read/write
6468         mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6469         mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6470         fs2=fs.linearToQuadratic(mms,mmqs)
6471         self.myTester2(fs2,mmq)
6472         ## More vicious add single node 16
6473         mm=MEDFileUMesh()
6474         mm[0]=m3
6475         mmq=mm.linearToQuadratic(0)
6476         mms=MEDFileMeshes() ; mms.pushMesh(mm)
6477         mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6478         #
6479         f=MEDCouplingFieldDouble(ON_NODES)
6480         f.setName("field")
6481         f.setMesh(m3)
6482         f.setTime(3.,1,2)
6483         arr=DataArrayDouble(9) ; arr.iota()
6484         arr.iota()
6485         f.setArray(arr)
6486         f1ts=MEDFileField1TS()
6487         pfl=DataArrayInt([8,9,10,11,12,13,14,15,16]) ; pfl.setName("pfl")
6488         f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 9 nodes of cell #1 + orphan node
6489         fmts=MEDFileFieldMultiTS()
6490         fmts.pushBackTimeStep(f1ts)
6491         fs=MEDFileFields()
6492         fs.pushField(fmts)
6493         fs2=fs.linearToQuadratic(mms,mmsq)
6494         #
6495         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")
6496         f1tsToTest=fs2[0][0]
6497         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])
6498         assert(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6499         assert(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6500         assert(f1tsToTest.getFieldSplitedByType()==[(40,[(1,(0,21),'pfl_NODE','')])])
6501         pass
6502
6503     def myTester2(self,fs2,mmq):
6504         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")
6505         f1tsToTest=fs2[0][0]
6506         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])
6507         self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6508         self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6509         self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6510         fToTest=fs2[0][0].field(mmq)
6511         self.assertEqual(fToTest.getTime(),[3.,1,2])
6512         mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6513         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])))
6514         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))
6515         self.assertTrue(fToTest.getArray().isEqual(exp1,1e-12))
6516         # 2nd Time step
6517         f1tsToTest=fs2[0][1]
6518         self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6519         self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(4*exp1,1e-12))
6520         self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6521         fToTest=fs2[0][1].field(mmq)
6522         self.assertEqual(fToTest.getTime(),[5.,3,4])
6523         mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6524         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])))
6525         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))
6526         self.assertTrue(fToTest.getArray().isEqual(4*exp1,1e-12))
6527
6528         pass
6529
6530     @WriteInTmpDir
6531     def testSetFieldProfileFlatly1(self):
6532         """ 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
6533         a profile."""
6534         arr=DataArrayDouble(10) ; arr.iota()
6535         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
6536         m=m.buildUnstructured()
6537         m2=m.deepCopy()
6538         m2.simplexize(0)
6539         m=MEDCouplingUMesh.MergeUMeshes(m2,m)
6540         m.setName("mesh")
6541         mm=MEDFileUMesh()
6542         mm[0]=m
6543         f=MEDCouplingFieldDouble(ON_CELLS)
6544         f.setMesh(m)
6545         arr=DataArrayDouble(m.getNumberOfCells())
6546         arr.iota()
6547         f.setArray(arr)
6548         f.setName("field")
6549         pfl=DataArrayInt(m.getNumberOfCells()) ; pfl.iota() ; pfl.setName("pfl")
6550         #
6551         refSp=[(3,[(0,(0,162),'','')]),(4,[(0,(162,243),'','')])]
6552         refSp1=[(3,[(0,(0,162),'pfl_NORM_TRI3','')]),(4,[(0,(162,243),'pfl_NORM_QUAD4','')])]
6553         #
6554         f1ts=MEDFileField1TS()
6555         f1ts.setFieldProfile(f,mm,0,pfl)
6556         self.assertEqual(f1ts.getPfls(),()) # here setFieldProfile has detected useless pfl -> no pfl
6557         self.assertEqual(f1ts.getFieldSplitedByType(),refSp)
6558         self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
6559         #
6560         f1ts=MEDFileField1TS()
6561         f1ts.setFieldProfileFlatly(f,mm,0,pfl) # no optimization attempt. Create pfl unconditionally
6562         self.assertEqual(f1ts.getPfls(),("%s_NORM_TRI3"%pfl.getName(),"%s_NORM_QUAD4"%pfl.getName()))
6563         self.assertEqual(f1ts.getFieldSplitedByType(),refSp1)
6564         self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
6565         self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3").isIota(162))
6566         self.assertTrue(f1ts.getProfile("pfl_NORM_QUAD4").isIota(81))
6567         pass
6568
6569     @WriteInTmpDir
6570     def testRmGroupAtSpeLevelAndMultiLevGrpCreation(self):
6571         """ Here multi level groups are created"""
6572         arr=DataArrayDouble(11) ; arr.iota()
6573         m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
6574         m=m.buildUnstructured()
6575         m.setName("mesh")
6576         m1=m.buildDescendingConnectivity()[0]
6577         mm=MEDFileUMesh()
6578         mm[0]=m ; mm[-1]=m1
6579         ################
6580         grpName="grp0"
6581         grp0_0=DataArrayInt([0,1,2,6]) ; grp0_0.setName(grpName)
6582         grp0_1=DataArrayInt([0,1,2,7]) ; grp0_1.setName(grpName)
6583         grp1=DataArrayInt([1,2,3,5,6]) ; grp1.setName("grp1")
6584         grp2=DataArrayInt([2,3,5,8]) ; grp2.setName("grp2")
6585         ################ ajouter un groupe sur plusieurs niveau
6586         mm.addGroup(0,grp1)
6587         mm.addGroup(-1,grp2)
6588         mm.addGroup(0,grp0_0)
6589         mm.addGroup(-1,grp0_1)
6590         self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
6591         self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6592         self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6593         self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6594         self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6595         self.assertRaises(InterpKernelException,mm.addGroup,-1,grp0_1) # raise
6596         self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6597         self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6598         self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6599         self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6600         mm.removeGroupAtLevel(0,grpName)
6601         self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(-1,))
6602         self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6603         self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6604         self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6605         mm.removeGroupAtLevel(-1,grpName)
6606         self.assertEqual(mm.getGrpNonEmptyLevels(grpName),())
6607         self.assertRaises(InterpKernelException,mm.removeGroupAtLevel,-2,grpName)
6608         mm.addGroup(-1,grp0_1)
6609         mm.addGroup(0,grp0_0)
6610         self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
6611         self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6612         self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6613         self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6614         self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6615         pass
6616
6617     @WriteInTmpDir
6618     def testYutaka(self):
6619         """ 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...
6620         Then rearrange method removes unused entites by putting 0 on them -> Previously group has been modified by rearrange. Should not !"""
6621         mn="mesh"
6622         m=MEDCouplingCMesh()
6623         arr=DataArrayDouble(4) ; arr.iota()
6624         m.setCoords(arr,arr,arr)
6625         m=m.buildUnstructured()
6626         m.setName(mn)
6627         #
6628         m=m.buildUnstructured()
6629         m1=m.buildDescendingConnectivity()[0]
6630         #
6631         mm=MEDFileUMesh()
6632         mm[0]=m
6633         mm[-1]=m1
6634         #
6635         grp0=DataArrayInt([0,1,2]) ; grp0.setName("grp0")
6636         mm.addGroup(0,grp0)
6637         grp1=DataArrayInt([3,4,5,6]) ; grp1.setName("grp1")
6638         mm.addGroup(0,grp1)
6639         grp2=DataArrayInt([7,8,9]) ; grp2.setName("grp2")
6640         mm.addGroup(0,grp2)
6641         grp3=DataArrayInt.Range(0,m1.getNumberOfCells(),1) ; grp3.setName("grp3")
6642         mm.addGroup(-1,grp3)
6643         self.assertNotIn(0,mm.getFamiliesIdsOnGroup("grp3")) # bug was here !
6644         grp4=DataArrayInt([3,5,8,10]) ; grp4.setName("grp4")
6645         mm.addNodeGroup(grp4)
6646         mm.rearrangeFamilies()
6647         self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp0"),(0,))
6648         self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp1"),(0,))
6649         self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp2"),(0,))
6650         self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp3"),(-1,))
6651         self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp4"),(1,))
6652
6653         for grp in [grp0,grp1,grp2,grp3,grp4]:
6654             self.assertTrue(mm.getGroupArr(mm.getGrpNonEmptyLevelsExt(grp.getName())[0],grp.getName()).isEqual(grp))
6655             pass
6656         pass
6657
6658     @WriteInTmpDir
6659     def testContxtMger1TS(self):
6660         fname="Pyfile119.med"
6661         coo=DataArrayDouble(1000) ; coo.iota()
6662         m=MEDCouplingUMesh.Build0DMeshFromCoords(coo)
6663         m.setName("mesh")
6664         WriteMesh(fname,m,True)
6665         f=MEDCouplingFieldDouble(ON_CELLS)
6666         f.setMesh(m)
6667         f.setName("Field")
6668         arr=DataArrayDouble(m.getNumberOfCells())
6669         f.setArray(arr)
6670         f.checkConsistencyLight()
6671         for i in range(10):
6672             arr[:]=float(i+1)
6673             f.setTime(float(i),i,0)
6674             WriteFieldUsingAlreadyWrittenMesh(fname,f)
6675             pass
6676         #
6677         mm=MEDFileMesh.New(fname)
6678         fmts=MEDFileFieldMultiTS(fname,False)
6679         refSize=fmts.getHeapMemorySize()
6680         for f1ts in fmts:
6681             with f1ts:
6682                 f=f1ts.field(mm)
6683                 pass
6684             pass
6685         self.assertIn(fmts.getHeapMemorySize(),range(refSize,refSize+refSize//10))
6686         pass
6687
6688     def testZipFamilies1(self):
6689         """
6690         MEDFileMesh.zipFamilies tries to reduce family partitions under groups.
6691         """
6692         mname="mesh" 
6693         arr=DataArrayDouble(10) ; arr.iota()
6694         m=MEDCouplingCMesh()
6695         m.setCoords(arr,arr)
6696         m=m.buildUnstructured()
6697         m.setName(mname)
6698         #
6699         mm=MEDFileUMesh()
6700         mm[0]=m
6701         for i in range(m.getNumberOfCells()):
6702             d = DataArrayInt([i])
6703             d.setName("grp%d"%i)
6704             mm.addGroup(0,d)
6705             pass
6706         
6707         grp_all = DataArrayInt.Range(0,m.getNumberOfCells(),1)
6708         grp_all.setName("grp_all")
6709         mm.addGroup(0,grp_all)
6710         for i in range(m.getNumberOfCells()):
6711             mm.removeGroup("grp{}".format(i))
6712             pass
6713         #
6714         mm.zipFamilies() # the method to test
6715         #
6716         self.assertEqual(mm.getGroupsNames(),("grp_all",))
6717         self.assertEqual(len(mm.getFamiliesNames()),1)
6718         self.assertTrue(mm.getGroupArr(0,"grp_all").isEqualWithoutConsideringStr(DataArrayInt.Range(0,81,1)))
6719         pass
6720
6721     def testZipFamilies2(self):
6722         """
6723         MEDFileMesh.zipFamilies tries to reduce family partitions under groups.
6724         """
6725         mname="mesh" 
6726         arr=DataArrayDouble(21) ; arr.iota()
6727         m=MEDCouplingCMesh()
6728         m.setCoords(arr)
6729         m=m.buildUnstructured()
6730         m.setName(mname)
6731         #
6732         mm=MEDFileUMesh()
6733         mm[0]=m
6734         # 1 and 3 to be merged
6735         # 2 and 5 to be merged
6736         mm.setFamilyFieldArr(0,DataArrayInt([-1,-1,-2,-3,-8, 0,-7,-7,-1,0, -6,-2,-5,-5,-2, -2,-2,-5,-4,-3]))
6737         for i in range(1,9):
6738             mm.setFamilyId("Fam_{}".format(i),-i)
6739         mm.setFamiliesOnGroup("grp0",["Fam_1","Fam_3","Fam_6"])
6740         mm.setFamiliesOnGroup("grp1",["Fam_1","Fam_2","Fam_3","Fam_5","Fam_6"])
6741         mm.setFamiliesOnGroup("grp2",["Fam_2","Fam_5","Fam_6","Fam_7"])
6742         #
6743         grp0=DataArrayInt([0,1,3,8,10,19])
6744         grp1=DataArrayInt([0,1,2,3,8,10,11,12,13,14,15,16,17,19])
6745         grp2=DataArrayInt([2,6,7,10,11,12,13,14,15,16,17])
6746         self.assertTrue(mm.getGroupArr(0,"grp0").isEqualWithoutConsideringStr(grp0))
6747         self.assertTrue(mm.getGroupArr(0,"grp1").isEqualWithoutConsideringStr(grp1))
6748         self.assertTrue(mm.getGroupArr(0,"grp2").isEqualWithoutConsideringStr(grp2))
6749         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2'))
6750         mm.zipFamilies()
6751         self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2'))
6752         self.assertTrue(mm.getGroupArr(0,"grp0").isEqualWithoutConsideringStr(grp0))
6753         self.assertTrue(mm.getGroupArr(0,"grp1").isEqualWithoutConsideringStr(grp1))
6754         self.assertTrue(mm.getGroupArr(0,"grp2").isEqualWithoutConsideringStr(grp2))
6755         self.assertEqual(mm.getFamiliesNames(),('Fam_1','Fam_2','Fam_6','Fam_7'))
6756         pass
6757
6758     def testMeshConvertFromMEDFileGeoType(self):
6759         self.assertEqual(MEDFileMesh.ConvertFromMEDFileGeoType(320),NORM_HEXA20)
6760     
6761     @WriteInTmpDir
6762     def testFieldInt64_0(self):
6763         """
6764         Small basic test with I/O of field in int64.
6765         """
6766         fname="Pyfile120.med"
6767         arr = DataArrayDouble([0,1])
6768         m = MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh") ; m=m.buildUnstructured()
6769         f = MEDCouplingFieldInt64(ON_CELLS) ; f.setName("field")
6770         v = 1234567890123456
6771         f.setArray(DataArrayInt64([v]))
6772         f.setMesh(m)
6773         mm = MEDFileUMesh()
6774         mm[0] = m
6775         f1ts = MEDFileInt64Field1TS()
6776         f1ts.setFieldNoProfileSBT(f)
6777         fmts = MEDFileInt64FieldMultiTS()
6778         fmts.pushBackTimeStep(f1ts)
6779         fs = MEDFileFields()
6780         fs.pushField(fmts)
6781         mm.write(fname,2)
6782         fs.write(fname,0)
6783         #
6784         mm = MEDFileMesh.New(fname)
6785         fs = MEDFileFields(fname)
6786         f = fs[0][0].field(mm)
6787         self.assertTrue( isinstance(f,MEDCouplingFieldInt64) )
6788         self.assertEqual( f.getArray().getIJ(0,0) , v )
6789
6790     @WriteInTmpDir
6791     def testNonRegUMeshSubParts(self):
6792         """
6793         Non regression test focuses on accordance between time stamp and active data structure in MEDFileUMeshAggregateCompute class.
6794         """
6795         fname = "Pyfile121.med"
6796         m0 = MEDCouplingUMesh("mesh",1)
6797         coords = DataArrayDouble([(0,0),(1,0),(2,0)])
6798         m0.setCoords(coords)
6799         m0.allocateCells()
6800         m0.insertNextCell(NORM_SEG2,[1,2])
6801         mm = MEDFileUMesh()
6802         mm[0] = m0
6803         m1 = MEDCoupling1SGTUMesh(m0.getName(), NORM_POINT1)
6804         m1.setCoords(m0.getCoords())
6805         m1.setNodalConnectivity(DataArrayInt([1,2]))
6806         m1.setName(m0.getName())
6807         mm[-1] = m1
6808         fni = mm.computeFetchedNodeIds() # <- This invokation of const method implies 1SGTU parts computation
6809         mm.zipCoords() # <- This call changes the coords and connectivity
6810         mm.write(fname,2)
6811         #
6812         mm = MEDFileMesh.New(fname)
6813         mm[0].checkConsistency() # <- check that correct DS has been taken at write time into MEDFileUMeshAggregateCompute
6814         self.assertTrue( m0.isEqual(mm[0],1e-12) )
6815         pass
6816
6817     pass
6818
6819 if __name__ == "__main__":
6820     unittest.main()