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