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