]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/Swig/MEDLoaderTest4.py
Salome HOME
706b63b09e1622a3a73f07b4a708dc806ecfa464
[tools/medcoupling.git] / src / MEDLoader / Swig / MEDLoaderTest4.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015  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 (CEA/DEN)
21
22 from MEDLoader import *
23 import unittest
24 from math import pi,e,sqrt
25
26 class MEDLoaderTest4(unittest.TestCase):
27     """
28     Test series to emulate the future MEDReader plugin for PARAVIS.
29     """
30     def test1(self):
31         """
32         This test is the most simple one. One time serie of one field with only cell fields with no profiles.
33         The only "difficulty" is that the cell field is lying on different levels (2D and 1D) to maximize the compatibility with ParaVIS.
34         """
35         fname="ForMEDReader1.med"
36         # building a mesh containing 4 tri3 + 5 quad4
37         tri=MEDCouplingUMesh("tri",2)
38         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
39         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
40         tris=[tri.deepCpy() for i in xrange(4)]
41         for i,elt in enumerate(tris): elt.translate([i,0])
42         tris=MEDCouplingUMesh.MergeUMeshes(tris)
43         quad=MEDCouplingUMesh("quad",2)
44         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
45         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
46         quads=[quad.deepCpy() for i in xrange(5)]
47         for i,elt in enumerate(quads): elt.translate([5+i,0])
48         quads=MEDCouplingUMesh.MergeUMeshes(quads)
49         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
50         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
51         m1=m.buildDescendingConnectivity()[0]
52         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
53         fam=DataArrayInt(9) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam)
54         fam=DataArrayInt(32) ; fam.iota(20) ; mm.setFamilyFieldArr(-1,fam) ; del fam
55         num=DataArrayInt(9) ; num.iota(100) ; mm.setRenumFieldArr(0,num)
56         num=DataArrayInt(32) ; num.iota(120) ; mm.setRenumFieldArr(-1,num) ; del num
57         #
58         fieldName="zeField"
59         fs=MEDFileFieldMultiTS()
60         ##### Time step 0
61         i=0
62         f=MEDFileField1TS()
63         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
64         fCell0.setName(fieldName) ; fCell0.setMesh(m)
65         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(100) ; arr.rearrange(2)
66         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
67         fCell0.checkCoherency()
68         f.setFieldNoProfileSBT(fCell0)
69         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
70         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
71         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(200) ; arr.rearrange(2)
72         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
73         fCell1.checkCoherency()
74         f.setFieldNoProfileSBT(fCell1)
75         fs.pushBackTimeStep(f)
76         ##### Time step 1
77         i=1
78         f=MEDFileField1TS()
79         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
80         fCell0.setName(fieldName) ; fCell0.setMesh(m)
81         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(1100) ; arr.rearrange(2)
82         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
83         fCell0.checkCoherency()
84         f.setFieldNoProfileSBT(fCell0)
85         #
86         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
87         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
88         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(1200) ; arr.rearrange(2)
89         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
90         fCell1.checkCoherency()
91         f.setFieldNoProfileSBT(fCell1)
92         fs.pushBackTimeStep(f)
93         ##### Time step 2
94         i=2
95         f=MEDFileField1TS()
96         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
97         fCell0.setName(fieldName) ; fCell0.setMesh(m)
98         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(2100) ; arr.rearrange(2)
99         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
100         fCell0.checkCoherency()
101         f.setFieldNoProfileSBT(fCell0)
102         #
103         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
104         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
105         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(2200) ; arr.rearrange(2)
106         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
107         fCell1.checkCoherency()
108         f.setFieldNoProfileSBT(fCell1)
109         fs.pushBackTimeStep(f)
110         ##### Time step 3
111         i=3
112         f=MEDFileField1TS()
113         #
114         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
115         fCell0.setName(fieldName) ; fCell0.setMesh(m)
116         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(3100) ; arr.rearrange(2)
117         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
118         fCell0.checkCoherency()
119         f.setFieldNoProfileSBT(fCell0)
120         #
121         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
122         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
123         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(3200) ; arr.rearrange(2)
124         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
125         fCell1.checkCoherency()
126         f.setFieldNoProfileSBT(fCell1)
127         #
128         fs.pushBackTimeStep(f)
129         ##### Time step 4
130         i=4
131         f=MEDFileField1TS()
132         #
133         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
134         fCell0.setName(fieldName) ; fCell0.setMesh(m)
135         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(4100) ; arr.rearrange(2)
136         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
137         fCell0.checkCoherency()
138         f.setFieldNoProfileSBT(fCell0)
139         #
140         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
141         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
142         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(4200) ; arr.rearrange(2)
143         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
144         fCell1.checkCoherency()
145         f.setFieldNoProfileSBT(fCell1)
146         fs.pushBackTimeStep(f)
147         mm.write(fname,2)
148         fs.write(fname,0)
149         a0Exp=mm.getCoords().deepCpy()
150         del m,m1,mm,fs,f,fCell0,fCell1
151         ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values
152         ms=MEDFileMeshes(fname)
153         fields=MEDFileFields(fname,False) # False is important to not read the values
154         fields.removeFieldsWithoutAnyTimeStep()
155         refMem=fields.getHeapMemorySize()
156         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
157         allFMTSLeavesToDisplay=[]
158         for fields in fields_per_mesh:
159             allFMTSLeavesToDisplay2=[]
160             for fmts in fields:
161                 tmp=fmts.splitDiscretizations()
162                 for itmp in tmp:
163                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
164                     pass
165                 allFMTSLeavesToDisplay2+=tmp
166                 pass
167             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
168             pass
169         self.assertEqual(len(allFMTSLeavesToDisplay),1)
170         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
171         for fmts in allFMTSLeavesToDisplay[0]:
172             self.assertEqual(fmts.getTimeSteps(),[(0,0,0.),(1,0,1.),(2,0,2.),(3,0,3.),(4,0,4.)]) # All discretizations have the same time series
173             pass
174         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
175         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
176         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
177         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
178         #
179         mst=MEDFileMeshStruct.New(ms[0])
180         fcscp=allFMTSLeavesPerCommonSupport[0][1]
181         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
182         mml2=mml.prepare()
183         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
184         for i in xrange(1,5):
185             self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
186             pass
187         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
188         self.assertTrue(not ncc)
189         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
190         self.assertTrue(a1.isEqual(DataArrayByte([3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,5,5,5,5,9,9,9,9,9])))
191         self.assertTrue(a2.isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,100,104,108,112,117,122,127,132])))
192         self.assertTrue(a3.isEqual(DataArrayInt([2,0,1,2,1,2,2,2,0,2,3,4,2,4,5,2,5,3,2,6,7,2,7,8,2,8,6,2,9,10,2,10,11,2,11,9,2,12,13,2,13,14,2,14,15,2,15,12,2,16,17,2,17,18,2,18,19,2,19,16,2,20,21,2,21,22,2,22,23,2,23,20,2,24,25,2,25,26,2,26,27,2,27,24,2,28,29,2,29,30,2,30,31,2,31,28,3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
193         self.assertTrue(a4 is None)
194         self.assertTrue(a5 is None)
195         a6,a7=mml2.retrieveFamilyIdsOnCells()
196         self.assertTrue(a6.isEqual(DataArrayInt([20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,0,1,2,3,4,5,6,7,8])))
197         self.assertTrue(not a7)
198         a8,a9=mml2.retrieveNumberIdsOnCells()
199         self.assertTrue(a8.isEqual(DataArrayInt([120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,100,101,102,103,104,105,106,107,108])))
200         self.assertTrue(not a9)
201         for i in xrange(5):
202             fsst=MEDFileField1TSStructItem.BuildItemFrom(fields[0][i],mst)
203             fields[0][i].loadArraysIfNecessary()
204             tmpMem=fields.getHeapMemorySize()
205             self.assertTrue(tmpMem-refMem>=41*2*8)
206             refMem=tmpMem
207             v=mml.buildDataArray(fsst,fields,fields[0][i].getUndergroundDataArray())
208             self.assertEqual(v.getHiddenCppPointer(),fields[0][i].getUndergroundDataArray().getHiddenCppPointer())
209             vExp=DataArrayDouble([200.,201.,202.,203.,204.,205.,206.,207.,208.,209.,210.,211.,212.,213.,214.,215.,216.,217.,218.,219.,220.,221.,222.,223.,224.,225.,226.,227.,228.,229.,230.,231.,232.,233.,234.,235.,236.,237.,238.,239.,240.,241.,242.,243.,244.,245.,246.,247.,248.,249.,250.,251.,252.,253.,254.,255.,256.,257.,258.,259.,260.,261.,262.,263.,100.,101.,102.,103.,104.,105.,106.,107.,108.,109.,110.,111.,112.,113.,114.,115.,116.,117.],41,2) ; vExp.setInfoOnComponents(['Comp1 [m]','Com2 [s^2]']) ; vExp+=i*1000
210             self.assertTrue(v.isEqual(vExp,1e-12))
211             pass
212         pass
213
214     def test2(self):
215         """
216         One time serie of one field with cell and node discretization in the same field with no profiles.
217         Here as there is no profile only one VTK support is requested.
218         """
219         fname="ForMEDReader2.med"
220         # building a mesh containing 4 tri3 + 5 quad4
221         tri=MEDCouplingUMesh("tri",2)
222         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
223         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
224         tris=[tri.deepCpy() for i in xrange(4)]
225         for i,elt in enumerate(tris): elt.translate([i,0])
226         tris=MEDCouplingUMesh.MergeUMeshes(tris)
227         quad=MEDCouplingUMesh("quad",2)
228         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
229         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
230         quads=[quad.deepCpy() for i in xrange(5)]
231         for i,elt in enumerate(quads): elt.translate([5+i,0])
232         quads=MEDCouplingUMesh.MergeUMeshes(quads)
233         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
234         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
235         m1=m.buildDescendingConnectivity()[0]
236         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
237         #
238         fieldName="zeField"
239         fs=MEDFileFieldMultiTS()
240         ##### Time step 0
241         i=0
242         f=MEDFileField1TS()
243         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
244         fCell0.setName(fieldName) ; fCell0.setMesh(m)
245         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(100) ; arr.rearrange(2)
246         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
247         fCell0.checkCoherency()
248         f.setFieldNoProfileSBT(fCell0)
249         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
250         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
251         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(200) ; arr.rearrange(2)
252         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
253         fCell1.checkCoherency()
254         f.setFieldNoProfileSBT(fCell1)
255         #
256         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
257         fNode.setName(fieldName) ; fNode.setMesh(m1)
258         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(300) ; arr.rearrange(2)
259         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
260         fNode.checkCoherency()
261         f.setFieldNoProfileSBT(fNode)
262         fs.pushBackTimeStep(f)
263         ##### Time step 1
264         i=1
265         f=MEDFileField1TS()
266         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
267         fCell0.setName(fieldName) ; fCell0.setMesh(m)
268         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(1100) ; arr.rearrange(2)
269         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
270         fCell0.checkCoherency()
271         f.setFieldNoProfileSBT(fCell0)
272         #
273         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
274         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
275         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(1200) ; arr.rearrange(2)
276         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
277         fCell1.checkCoherency()
278         f.setFieldNoProfileSBT(fCell1)
279         #
280         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
281         fNode.setName(fieldName) ; fNode.setMesh(m1)
282         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(1300) ; arr.rearrange(2)
283         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
284         fNode.checkCoherency()
285         f.setFieldNoProfileSBT(fNode)
286         fs.pushBackTimeStep(f)
287         ##### Time step 2
288         i=2
289         f=MEDFileField1TS()
290         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
291         fNode.setName(fieldName) ; fNode.setMesh(m1)
292         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(2300) ; arr.rearrange(2)
293         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
294         fNode.checkCoherency()
295         f.setFieldNoProfileSBT(fNode)
296         #
297         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
298         fCell0.setName(fieldName) ; fCell0.setMesh(m)
299         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(2100) ; arr.rearrange(2)
300         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
301         fCell0.checkCoherency()
302         f.setFieldNoProfileSBT(fCell0)
303         #
304         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
305         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
306         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(2200) ; arr.rearrange(2)
307         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
308         fCell1.checkCoherency()
309         f.setFieldNoProfileSBT(fCell1)
310         fs.pushBackTimeStep(f)
311         ##### Time step 3
312         i=3
313         f=MEDFileField1TS()
314         #
315         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
316         fCell0.setName(fieldName) ; fCell0.setMesh(m)
317         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(3100) ; arr.rearrange(2)
318         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
319         fCell0.checkCoherency()
320         f.setFieldNoProfileSBT(fCell0)
321         #
322         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
323         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
324         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(3200) ; arr.rearrange(2)
325         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
326         fCell1.checkCoherency()
327         f.setFieldNoProfileSBT(fCell1)
328         #
329         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
330         fNode.setName(fieldName) ; fNode.setMesh(m1)
331         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(3300) ; arr.rearrange(2)
332         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
333         fNode.checkCoherency()
334         f.setFieldNoProfileSBT(fNode)
335         #
336         fs.pushBackTimeStep(f)
337         ##### Time step 4
338         i=4
339         f=MEDFileField1TS()
340         #
341         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
342         fCell0.setName(fieldName) ; fCell0.setMesh(m)
343         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(4100) ; arr.rearrange(2)
344         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
345         fCell0.checkCoherency()
346         f.setFieldNoProfileSBT(fCell0)
347         #
348         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
349         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
350         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(4200) ; arr.rearrange(2)
351         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
352         fCell1.checkCoherency()
353         f.setFieldNoProfileSBT(fCell1)
354         #
355         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
356         fNode.setName(fieldName) ; fNode.setMesh(m1)
357         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(4300) ; arr.rearrange(2)
358         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
359         fNode.checkCoherency()
360         f.setFieldNoProfileSBT(fNode)
361         #
362         fs.pushBackTimeStep(f)
363         mm.write(fname,2)
364         fs.write(fname,0)
365         a0Exp=mm.getCoords().deepCpy()
366         del m,m1,mm,fs,f,fCell0,fCell1
367         ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values
368         ms=MEDFileMeshes(fname)
369         fields=MEDFileFields(fname,False)
370         fields.removeFieldsWithoutAnyTimeStep()
371         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
372         allFMTSLeavesToDisplay=[]
373         for fields in fields_per_mesh:
374             allFMTSLeavesToDisplay2=[]
375             for fmts in fields:
376                 tmp=fmts.splitDiscretizations()
377                 for itmp in tmp:
378                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
379                     pass
380                 allFMTSLeavesToDisplay2+=tmp
381                 pass
382             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
383             pass
384         self.assertEqual(len(allFMTSLeavesToDisplay),1)
385         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
386         for fmts in allFMTSLeavesToDisplay[0]:
387             self.assertEqual(fmts.getTimeSteps(),[(0,0,0.),(1,0,1.),(2,0,2.),(3,0,3.),(4,0,4.)]) # All discretizations have the same time series
388             pass
389         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
390         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
391         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
392         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
393         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
394         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
395         #
396         mst=MEDFileMeshStruct.New(ms[0])
397         fcscp=allFMTSLeavesPerCommonSupport[0][1]
398         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
399         mml2=mml.prepare()
400         assert isinstance(mml2,MEDUMeshMultiLev)
401         for i in xrange(1,5):
402             self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
403             pass
404         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
405         self.assertTrue(not ncc)
406         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
407         self.assertTrue(a1.isEqual(DataArrayByte([3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,5,5,5,5,9,9,9,9,9])))
408         self.assertTrue(a2.isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,100,104,108,112,117,122,127,132])))
409         self.assertTrue(a3.isEqual(DataArrayInt([2,0,1,2,1,2,2,2,0,2,3,4,2,4,5,2,5,3,2,6,7,2,7,8,2,8,6,2,9,10,2,10,11,2,11,9,2,12,13,2,13,14,2,14,15,2,15,12,2,16,17,2,17,18,2,18,19,2,19,16,2,20,21,2,21,22,2,22,23,2,23,20,2,24,25,2,25,26,2,26,27,2,27,24,2,28,29,2,29,30,2,30,31,2,31,28,3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
410         self.assertTrue(a4 is None)
411         self.assertTrue(a5 is None)
412         # for cells
413         for i in xrange(5):
414             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
415             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)# Second 0 is for cells
416             f.loadArraysIfNecessary()
417             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
418             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
419             vExp=DataArrayDouble([200.,201.,202.,203.,204.,205.,206.,207.,208.,209.,210.,211.,212.,213.,214.,215.,216.,217.,218.,219.,220.,221.,222.,223.,224.,225.,226.,227.,228.,229.,230.,231.,232.,233.,234.,235.,236.,237.,238.,239.,240.,241.,242.,243.,244.,245.,246.,247.,248.,249.,250.,251.,252.,253.,254.,255.,256.,257.,258.,259.,260.,261.,262.,263.,100.,101.,102.,103.,104.,105.,106.,107.,108.,109.,110.,111.,112.,113.,114.,115.,116.,117.],41,2) ; vExp.setInfoOnComponents(['Comp1 [m]','Com2 [s^2]']) ; vExp+=i*1000
420             self.assertTrue(v.isEqual(vExp,1e-12))
421             pass
422         for i in xrange(5):
423             f=allFMTSLeavesPerCommonSupport[0][0][1][i]
424             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)# Second 0 is for cells
425             f.loadArraysIfNecessary()
426             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
427             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
428             vExp=DataArrayDouble([300.,301.,302.,303.,304.,305.,306.,307.,308.,309.,310.,311.,312.,313.,314.,315.,316.,317.,318.,319.,320.,321.,322.,323.,324.,325.,326.,327.,328.,329.,330.,331.,332.,333.,334.,335.,336.,337.,338.,339.,340.,341.,342.,343.,344.,345.,346.,347.,348.,349.,350.,351.,352.,353.,354.,355.,356.,357.,358.,359.,360.,361.,362.,363.],32,2) ; vExp.setInfoOnComponents(['Comp1 [m]','Com2 [s^2]']) ; vExp.setInfoOnComponents(['Comp1 [m]','Com2 [s^2]']) ; vExp+=i*1000
429             self.assertTrue(v.isEqual(vExp,1e-12))
430             pass
431         pass
432
433     def test3(self):
434         """ This test is more advanced a same field is defined on CELLS for time steps 0, 2 and 4, and on NODES for time steps 1 and 3.
435         So two time step series on the same field. No profile here neither on cells nor on nodes.
436         """
437         fname="ForMEDReader3.med"
438         # building a mesh containing 4 tri3 + 5 quad4
439         tri=MEDCouplingUMesh("tri",2)
440         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
441         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
442         tris=[tri.deepCpy() for i in xrange(4)]
443         for i,elt in enumerate(tris): elt.translate([i,0])
444         tris=MEDCouplingUMesh.MergeUMeshes(tris)
445         quad=MEDCouplingUMesh("quad",2)
446         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
447         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
448         quads=[quad.deepCpy() for i in xrange(5)]
449         for i,elt in enumerate(quads): elt.translate([5+i,0])
450         quads=MEDCouplingUMesh.MergeUMeshes(quads)
451         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
452         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
453         m1=m.buildDescendingConnectivity()[0]
454         mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
455         #
456         fieldName="zeField"
457         fs=MEDFileFieldMultiTS()
458         ##### Time step 0 on cells
459         i=0
460         f=MEDFileField1TS()
461         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
462         fCell0.setName(fieldName) ; fCell0.setMesh(m)
463         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(100) ; arr.rearrange(2)
464         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
465         fCell0.checkCoherency()
466         f.setFieldNoProfileSBT(fCell0)
467         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
468         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
469         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(200) ; arr.rearrange(2)
470         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
471         fCell1.checkCoherency()
472         f.setFieldNoProfileSBT(fCell1)
473         fs.pushBackTimeStep(f)
474         ##### Time step 1 on nodes
475         i=1
476         f=MEDFileField1TS()
477         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
478         fNode.setName(fieldName) ; fNode.setMesh(m1)
479         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(1300) ; arr.rearrange(2)
480         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
481         fNode.checkCoherency()
482         f.setFieldNoProfileSBT(fNode)
483         fs.pushBackTimeStep(f)
484         ##### Time step 2 on cells
485         i=2
486         f=MEDFileField1TS()
487         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
488         fCell0.setName(fieldName) ; fCell0.setMesh(m)
489         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(2100) ; arr.rearrange(2)
490         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
491         fCell0.checkCoherency()
492         f.setFieldNoProfileSBT(fCell0)
493         #
494         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
495         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
496         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(2200) ; arr.rearrange(2)
497         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
498         fCell1.checkCoherency()
499         f.setFieldNoProfileSBT(fCell1)
500         fs.pushBackTimeStep(f)
501         ##### Time step 3 on nodes
502         i=3
503         f=MEDFileField1TS()
504         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
505         fNode.setName(fieldName) ; fNode.setMesh(m1)
506         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(3300) ; arr.rearrange(2)
507         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
508         fNode.checkCoherency()
509         f.setFieldNoProfileSBT(fNode)
510         fs.pushBackTimeStep(f)
511         ##### Time step 4
512         i=4
513         f=MEDFileField1TS()
514         fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i),i,0)
515         fCell0.setName(fieldName) ; fCell0.setMesh(m)
516         arr=DataArrayDouble(2*m.getNumberOfCells()) ; arr.iota(4100) ; arr.rearrange(2)
517         fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
518         fCell0.checkCoherency()
519         f.setFieldNoProfileSBT(fCell0)
520         #
521         fCell1=MEDCouplingFieldDouble(ON_CELLS) ; fCell1.setTime(float(i),i,0)
522         fCell1.setName(fieldName) ; fCell1.setMesh(m1)
523         arr=DataArrayDouble(2*m1.getNumberOfCells()) ; arr.iota(4200) ; arr.rearrange(2)
524         fCell1.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]","Com2 [s^2]"])
525         fCell1.checkCoherency()
526         f.setFieldNoProfileSBT(fCell1)
527         #
528         fs.pushBackTimeStep(f)
529         mm.write(fname,2)
530         fs.write(fname,0)
531         a0Exp=mm.getCoords().deepCpy()
532         del m,m1,mm,fs,f,fCell0,fCell1
533         ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values
534         ms=MEDFileMeshes(fname)
535         fields=MEDFileFields(fname,False)
536         fields.removeFieldsWithoutAnyTimeStep()
537         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
538         allFMTSLeavesToDisplay=[]
539         for fields in fields_per_mesh:
540             allFMTSLeavesToDisplay2=[]
541             for fmts in fields:
542                 tmp=fmts.splitDiscretizations()
543                 for itmp in tmp:
544                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
545                     pass
546                 allFMTSLeavesToDisplay2+=tmp
547                 pass
548             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
549             pass
550         self.assertEqual(len(allFMTSLeavesToDisplay),1)
551         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
552         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
553         self.assertEqual(len(allFMTSLeavesPerTimeSeries),2) # two time series here : one for the cells, the second one for the nodes
554         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
555         self.assertEqual(len(allFMTSLeavesPerTimeSeries[1]),1)
556         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
557         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
558         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),1)
559         #
560         mst=MEDFileMeshStruct.New(ms[0])
561         fcscp=allFMTSLeavesPerCommonSupport[0][1] # start with the cells
562         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
563         mml2=mml.prepare()
564         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
565         for i in xrange(1,3):
566             self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
567             pass
568         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
569         self.assertTrue(not ncc)
570         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
571         self.assertTrue(a1.isEqual(DataArrayByte([3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,5,5,5,5,9,9,9,9,9])))
572         self.assertTrue(a2.isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,100,104,108,112,117,122,127,132])))
573         self.assertTrue(a3.isEqual(DataArrayInt([2,0,1,2,1,2,2,2,0,2,3,4,2,4,5,2,5,3,2,6,7,2,7,8,2,8,6,2,9,10,2,10,11,2,11,9,2,12,13,2,13,14,2,14,15,2,15,12,2,16,17,2,17,18,2,18,19,2,19,16,2,20,21,2,21,22,2,22,23,2,23,20,2,24,25,2,25,26,2,26,27,2,27,24,2,28,29,2,29,30,2,30,31,2,31,28,3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
574         assert a4 is None
575         assert a5 is None
576         # for cells
577         for i in xrange(3):
578             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
579             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)# Second 0 is for cells
580             f.loadArraysIfNecessary()
581             self.assertEqual(f.getName(),"zeField")
582             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
583             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
584             vExp=DataArrayDouble([200.,201.,202.,203.,204.,205.,206.,207.,208.,209.,210.,211.,212.,213.,214.,215.,216.,217.,218.,219.,220.,221.,222.,223.,224.,225.,226.,227.,228.,229.,230.,231.,232.,233.,234.,235.,236.,237.,238.,239.,240.,241.,242.,243.,244.,245.,246.,247.,248.,249.,250.,251.,252.,253.,254.,255.,256.,257.,258.,259.,260.,261.,262.,263.,100.,101.,102.,103.,104.,105.,106.,107.,108.,109.,110.,111.,112.,113.,114.,115.,116.,117.],41,2) ; vExp.setInfoOnComponents(['Comp1 [m]','Com2 [s^2]']) ; vExp+=i*2000
585             self.assertTrue(v.isEqual(vExp,1e-12))
586             pass
587         # for nodes
588         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[1],ms[ms.getMeshesNames()[0]])
589         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
590         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),1)
591         fcscp=allFMTSLeavesPerCommonSupport[0][1]
592         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
593         mml2=mml.prepare()
594         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
595         for i in xrange(1,2):
596             self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
597             pass
598         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
599         self.assertTrue(not ncc)
600         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
601         self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,9,9,9,9,9,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3])))
602         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,21,26,31,36,41,44,47,50,53,56,59,62,65,68,71,74,77,80,83,86,89,92,95,98,101,104,107,110,113,116,119,122,125,128,131,134])))
603         self.assertTrue(a3.isEqual(DataArrayInt([3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31,2,0,1,2,1,2,2,2,0,2,3,4,2,4,5,2,5,3,2,6,7,2,7,8,2,8,6,2,9,10,2,10,11,2,11,9,2,12,13,2,13,14,2,14,15,2,15,12,2,16,17,2,17,18,2,18,19,2,19,16,2,20,21,2,21,22,2,22,23,2,23,20,2,24,25,2,25,26,2,26,27,2,27,24,2,28,29,2,29,30,2,30,31,2,31,28])))
604         self.assertTrue(a4 is None)
605         self.assertTrue(a5 is None)
606         for i in xrange(2):
607             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
608             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)# Second 0 is for cells
609             f.loadArraysIfNecessary()
610             self.assertEqual(f.getName(),"zeField")
611             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
612             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
613             vExp=DataArrayDouble([300.,301.,302.,303.,304.,305.,306.,307.,308.,309.,310.,311.,312.,313.,314.,315.,316.,317.,318.,319.,320.,321.,322.,323.,324.,325.,326.,327.,328.,329.,330.,331.,332.,333.,334.,335.,336.,337.,338.,339.,340.,341.,342.,343.,344.,345.,346.,347.,348.,349.,350.,351.,352.,353.,354.,355.,356.,357.,358.,359.,360.,361.,362.,363.],32,2) ; vExp.setInfoOnComponents(['Comp1 [m]','Com2 [s^2]']) ; vExp.setInfoOnComponents(['Comp1 [m]','Com2 [s^2]']) ; vExp+=i*2000+1000
614             self.assertTrue(v.isEqual(vExp,1e-12))
615             pass
616         pass
617
618     def test4(self):
619         """ This test defines 3 fields on nodes on the same mesh. All of these fields have no profile.
620         """
621         fname="ForMEDReader4.med"
622         # building a mesh containing 4 tri3 + 5 quad4
623         tri=MEDCouplingUMesh("tri",2)
624         tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
625         tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
626         tris=[tri.deepCpy() for i in xrange(4)]
627         for i,elt in enumerate(tris): elt.translate([i,0])
628         tris=MEDCouplingUMesh.MergeUMeshes(tris)
629         quad=MEDCouplingUMesh("quad",2)
630         quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
631         quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
632         quads=[quad.deepCpy() for i in xrange(5)]
633         for i,elt in enumerate(quads): elt.translate([5+i,0])
634         quads=MEDCouplingUMesh.MergeUMeshes(quads)
635         m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
636         m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
637         mm=MEDFileUMesh() ; mm.setMeshes([m])
638         #
639         fieldName1="zeField1"
640         fieldName2="zeField2"
641         fieldName3="zeField3"
642         fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
643         ##### Time step 0
644         i=0
645         f=MEDFileField1TS()
646         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
647         fNode.setName(fieldName1) ; fNode.setMesh(m)
648         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(0+1000*i) ; arr.rearrange(2)
649         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
650         fNode.checkCoherency()
651         f.setFieldNoProfileSBT(fNode)
652         fs1.pushBackTimeStep(f)
653         #
654         f=MEDFileField1TS()
655         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
656         fNode.setName(fieldName2) ; fNode.setMesh(m)
657         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2)
658         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
659         fNode.checkCoherency()
660         f.setFieldNoProfileSBT(fNode)
661         fs2.pushBackTimeStep(f)
662         #
663         f=MEDFileField1TS()
664         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
665         fNode.setName(fieldName3) ; fNode.setMesh(m)
666         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2)
667         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
668         fNode.checkCoherency()
669         f.setFieldNoProfileSBT(fNode)
670         fs3.pushBackTimeStep(f)
671         ##### Time step 1
672         i=1
673         f=MEDFileField1TS()
674         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
675         fNode.setName(fieldName1) ; fNode.setMesh(m)
676         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(0+1000*i) ; arr.rearrange(2)
677         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
678         fNode.checkCoherency()
679         f.setFieldNoProfileSBT(fNode)
680         fs1.pushBackTimeStep(f)
681         #
682         f=MEDFileField1TS()
683         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
684         fNode.setName(fieldName2) ; fNode.setMesh(m)
685         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2)
686         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
687         fNode.checkCoherency()
688         f.setFieldNoProfileSBT(fNode)
689         fs2.pushBackTimeStep(f)
690         #
691         f=MEDFileField1TS()
692         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
693         fNode.setName(fieldName3) ; fNode.setMesh(m)
694         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2)
695         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
696         fNode.checkCoherency()
697         f.setFieldNoProfileSBT(fNode)
698         fs3.pushBackTimeStep(f)
699         ##### Time step 2
700         i=2
701         f=MEDFileField1TS()
702         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
703         fNode.setName(fieldName1) ; fNode.setMesh(m)
704         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(0+1000*i) ; arr.rearrange(2)
705         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
706         fNode.checkCoherency()
707         f.setFieldNoProfileSBT(fNode)
708         fs1.pushBackTimeStep(f)
709         #
710         f=MEDFileField1TS()
711         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
712         fNode.setName(fieldName2) ; fNode.setMesh(m)
713         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2)
714         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
715         fNode.checkCoherency()
716         f.setFieldNoProfileSBT(fNode)
717         fs2.pushBackTimeStep(f)
718         #
719         f=MEDFileField1TS()
720         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
721         fNode.setName(fieldName3) ; fNode.setMesh(m)
722         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2)
723         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
724         fNode.checkCoherency()
725         f.setFieldNoProfileSBT(fNode)
726         fs3.pushBackTimeStep(f)
727         ##### Time step 3
728         i=3
729         f=MEDFileField1TS()
730         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
731         fNode.setName(fieldName1) ; fNode.setMesh(m)
732         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(0+1000*i) ; arr.rearrange(2)
733         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
734         fNode.checkCoherency()
735         f.setFieldNoProfileSBT(fNode)
736         fs1.pushBackTimeStep(f)
737         #
738         f=MEDFileField1TS()
739         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
740         fNode.setName(fieldName2) ; fNode.setMesh(m)
741         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2)
742         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
743         fNode.checkCoherency()
744         f.setFieldNoProfileSBT(fNode)
745         fs2.pushBackTimeStep(f)
746         #
747         f=MEDFileField1TS()
748         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
749         fNode.setName(fieldName3) ; fNode.setMesh(m)
750         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2)
751         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
752         fNode.checkCoherency()
753         f.setFieldNoProfileSBT(fNode)
754         fs3.pushBackTimeStep(f)
755         ##### Time step 4
756         i=4
757         f=MEDFileField1TS()
758         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
759         fNode.setName(fieldName1) ; fNode.setMesh(m)
760         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(0+1000*i) ; arr.rearrange(2)
761         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
762         fNode.checkCoherency()
763         f.setFieldNoProfileSBT(fNode)
764         fs1.pushBackTimeStep(f)
765         #
766         f=MEDFileField1TS()
767         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
768         fNode.setName(fieldName2) ; fNode.setMesh(m)
769         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(100+1000*i) ; arr.rearrange(2)
770         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
771         fNode.checkCoherency()
772         f.setFieldNoProfileSBT(fNode)
773         fs2.pushBackTimeStep(f)
774         #
775         f=MEDFileField1TS()
776         fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
777         fNode.setName(fieldName3) ; fNode.setMesh(m)
778         arr=DataArrayDouble(2*m.getNumberOfNodes()) ; arr.iota(200+1000*i) ; arr.rearrange(2)
779         fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
780         fNode.checkCoherency()
781         f.setFieldNoProfileSBT(fNode)
782         fs3.pushBackTimeStep(f)
783         #
784         mm.write(fname,2)
785         fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0)
786         a0Exp=mm.getCoords().deepCpy()
787         del m,mm,fs1,fs2,fs3,f,fNode
788         ########## GO for reading in MEDReader, by not loading all. Mesh is fully loaded but not fields values
789         ms=MEDFileMeshes(fname)
790         fields=MEDFileFields(fname,False)
791         fields.removeFieldsWithoutAnyTimeStep()
792         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
793         allFMTSLeavesToDisplay=[]
794         for fields in fields_per_mesh:
795             allFMTSLeavesToDisplay2=[]
796             for fmts in fields:
797                 tmp=fmts.splitDiscretizations()
798                 for itmp in tmp:
799                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
800                     pass
801                 allFMTSLeavesToDisplay2+=tmp
802                 pass
803             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
804             pass
805         self.assertEqual(len(allFMTSLeavesToDisplay),1)
806         self.assertEqual(len(allFMTSLeavesToDisplay[0]),3)
807         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
808         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 3 fields are defined on the same time steps
809         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
810         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
811         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
812         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),3)
813         #
814         mst=MEDFileMeshStruct.New(ms[0])
815         fcscp=allFMTSLeavesPerCommonSupport[0][1]
816         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
817         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),3)
818         fcscp=allFMTSLeavesPerCommonSupport[0][1]
819         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
820         mml2=mml.prepare()
821         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
822         for i in xrange(1,5):
823             self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
824             pass
825         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
826         self.assertTrue(not ncc)
827         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
828         self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,9,9,9,9,9])))
829         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,21,26,31,36])))
830         self.assertTrue(a3.isEqual(DataArrayInt([3,0,1,2,3,3,4,5,3,6,7,8,3,9,10,11,4,12,13,14,15,4,16,17,18,19,4,20,21,22,23,4,24,25,26,27,4,28,29,30,31])))
831         self.assertTrue(a4 is None)
832         self.assertTrue(a5 is None)
833         # test all the time steps of the 1/1 time step serie, on field 1
834         for i in xrange(5):
835             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
836             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
837             f.loadArraysIfNecessary()
838             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
839             self.assertEqual(f.getName(),fieldName1)
840             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
841             vExp=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.,25.,26.,27.,28.,29.,30.,31.,32.,33.,34.,35.,36.,37.,38.,39.,40.,41.,42.,43.,44.,45.,46.,47.,48.,49.,50.,51.,52.,53.,54.,55.,56.,57.,58.,59.,60.,61.,62.,63.],32,2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]']) ; vExp+=i*1000
842             self.assertTrue(v.isEqual(vExp,1e-12))
843             pass
844         # test all the time steps of the 1/1 time step serie, on field 2
845         for i in xrange(5):
846             f=allFMTSLeavesPerCommonSupport[0][0][1][i]
847             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
848             f.loadArraysIfNecessary()
849             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
850             self.assertEqual(f.getName(),fieldName2)
851             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
852             vExp=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.,25.,26.,27.,28.,29.,30.,31.,32.,33.,34.,35.,36.,37.,38.,39.,40.,41.,42.,43.,44.,45.,46.,47.,48.,49.,50.,51.,52.,53.,54.,55.,56.,57.,58.,59.,60.,61.,62.,63.],32,2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]']) ; vExp+=i*1000+100
853             self.assertTrue(v.isEqual(vExp,1e-12))
854             pass
855         # test all the time steps of the 1/1 time step serie, on field 3
856         for i in xrange(5):
857             f=allFMTSLeavesPerCommonSupport[0][0][2][i]
858             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
859             f.loadArraysIfNecessary()
860             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
861             self.assertEqual(f.getName(),fieldName3)
862             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
863             vExp=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.,25.,26.,27.,28.,29.,30.,31.,32.,33.,34.,35.,36.,37.,38.,39.,40.,41.,42.,43.,44.,45.,46.,47.,48.,49.,50.,51.,52.,53.,54.,55.,56.,57.,58.,59.,60.,61.,62.,63.],32,2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]']) ; vExp+=i*1000+200
864             self.assertTrue(v.isEqual(vExp,1e-12))
865             pass
866         pass
867     
868     def test5(self):
869         """ This test plays with profiles both cell profiles and node profiles. Two first fields (resp on cells and on nodes) lie on the same mesh support whereas the third
870         mesh lies on a different mesh.
871         """
872         fname="ForMEDReader5.med"
873         # building a mesh containing 6 tri3 + 5 quad4
874         m=MEDCouplingUMesh("mesh",2)
875         coords=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)]) ; coords.setInfoOnComponents(["XX [m]","YYY [km]"])
876         m.setCoords(coords)
877         m.allocateCells()
878         m.insertNextCell(NORM_TRI3,[2,7,3]) ; m.insertNextCell(NORM_TRI3,[7,8,3]) ; m.insertNextCell(NORM_TRI3,[3,8,4]) ; m.insertNextCell(NORM_TRI3,[8,9,4])
879         m.insertNextCell(NORM_TRI3,[13,9,8]) ; m.insertNextCell(NORM_TRI3,[13,14,9])
880         m.insertNextCell(NORM_QUAD4,[0,5,6,1]) ; m.insertNextCell(NORM_QUAD4,[1,6,7,2]) ; m.insertNextCell(NORM_QUAD4,[5,10,11,6]) ; m.insertNextCell(NORM_QUAD4,[6,11,12,7])
881         m.insertNextCell(NORM_QUAD4,[12,13,8,7])
882         mm=MEDFileUMesh() ; mm.setMeshes([m])
883         fam=DataArrayInt(11) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam) ; del fam
884         num=DataArrayInt(11) ; num.iota(100) ; mm.setRenumFieldArr(0,num) ; del num
885         #
886         fieldName1="zeField1" ; pfl1=DataArrayInt([0,1,2,3,4,5]) ; pfl1.setName("pfl1") # on cells
887         fieldName2="zeField2" ; pfl2=DataArrayInt([2,3,4,7,8,9,13,14]) ; pfl2.setName("pfl2") # on nodes
888         fieldName3="zeField3" ; pfl3=DataArrayInt([0,1,2,3,4,5,9,10]) ; pfl3.setName("pfl3") # on cells but different support
889         fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
890         #
891         for i in xrange(5):
892             f=MEDFileField1TS()
893             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
894             fNode.setName(fieldName1)
895             arr=DataArrayDouble(2*6) ; arr.iota(0+1000*i) ; arr.rearrange(2)
896             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
897             f.setFieldProfile(fNode,mm,0,pfl1)
898             fs1.pushBackTimeStep(f)
899             #
900             f=MEDFileField1TS()
901             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
902             fNode.setName(fieldName2)
903             arr=DataArrayDouble(2*8) ; arr.iota(100+1000*i) ; arr.rearrange(2)
904             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
905             f.setFieldProfile(fNode,mm,0,pfl2)
906             fs2.pushBackTimeStep(f)
907             #
908             f=MEDFileField1TS()
909             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
910             fNode.setName(fieldName3)
911             arr=DataArrayDouble(2*8) ; arr.iota(200+1000*i) ; arr.rearrange(2)
912             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
913             f.setFieldProfile(fNode,mm,0,pfl3)
914             fs3.pushBackTimeStep(f)
915             pass
916         mm.write(fname,2)
917         fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0)
918         a0Exp=mm.getCoords().deepCpy()
919         del m,mm,fs1,fs2,fs3,f,fNode
920         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
921         ms=MEDFileMeshes(fname)
922         fields=MEDFileFields(fname,False)
923         fields.removeFieldsWithoutAnyTimeStep()
924         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
925         allFMTSLeavesToDisplay=[]
926         for fields in fields_per_mesh:
927             allFMTSLeavesToDisplay2=[]
928             for fmts in fields:
929                 tmp=fmts.splitDiscretizations()
930                 for itmp in tmp:
931                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
932                     pass
933                 allFMTSLeavesToDisplay2+=tmp
934                 pass
935             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
936             pass
937         self.assertEqual(len(allFMTSLeavesToDisplay),1)
938         self.assertEqual(len(allFMTSLeavesToDisplay[0]),3)
939         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
940         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 3 fields are defined on the same time steps
941         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
942         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
943         ms[0].getDirectUndergroundSingleGeoTypeMeshes(0)
944         self.assertEqual(len(allFMTSLeavesPerCommonSupport),2) # 2 support here
945         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
946         self.assertEqual(len(allFMTSLeavesPerCommonSupport[1][0]),1)
947         #
948         mst=MEDFileMeshStruct.New(ms[0])
949         fcscp=allFMTSLeavesPerCommonSupport[0][1]
950         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
951         mml2=mml.prepare()
952         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
953         for i in xrange(1,5):
954             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
955             pass
956         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
957         self.assertTrue(not ncc)
958         self.assertTrue(a0.isEqual(a0Exp[pfl2].changeNbOfComponents(3,0.),1e-12))
959         self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,5,5])))
960         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,20])))
961         self.assertTrue(a3.isEqual(DataArrayInt([3,0,3,1,3,3,4,1,3,1,4,2,3,4,5,2,3,6,5,4,3,6,7,5])))
962         assert a4 is None
963         assert a5 is None
964         a6,a7=mml2.retrieveFamilyIdsOnCells()
965         self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5])))
966         self.assertTrue(not a7)
967         a8,a9=mml2.retrieveNumberIdsOnCells()
968         self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105])))
969         self.assertTrue(not a9)
970         for i in xrange(5):
971             nbOfT=[6,8]
972             fieldNames=[fieldName1,fieldName2]
973             for j in xrange(2):
974                 m={"i":j}
975                 f=allFMTSLeavesPerCommonSupport[0][0][j][i]
976                 fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
977                 f.loadArraysIfNecessary()
978                 v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
979                 self.assertEqual(f.getName(),fieldNames[j])
980                 self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
981                 vExp=DataArrayDouble(nbOfT[j]*2) ; vExp.iota(j*100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_%(i)i [m]'%m,'Com2_%(i)i [s^2]'%m])
982                 self.assertTrue(v.isEqual(vExp,1e-12))
983                 pass
984             pass
985         # Let's go for the 2nd support
986         fcscp=allFMTSLeavesPerCommonSupport[1][1]
987         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
988         mml2=mml.prepare()
989         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
990         for i in xrange(1,5):
991             self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
992             pass
993         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
994         self.assertTrue(not ncc)
995         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
996         self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,5,5,9,9])))
997         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,20,24,29])))
998         self.assertTrue(a3.isEqual(DataArrayInt([3,2,7,3,3,7,8,3,3,3,8,4,3,8,9,4,3,13,9,8,3,13,14,9,4,6,11,12,7,4,12,13,8,7])))
999         self.assertTrue(a4 is None)
1000         self.assertTrue(a5 is None)
1001         a6,a7=mml2.retrieveFamilyIdsOnCells()
1002         self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5,9,10])))
1003         self.assertTrue(not a7)
1004         a8,a9=mml2.retrieveNumberIdsOnCells()
1005         self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,109,110])))
1006         self.assertTrue(not a9)
1007         for i in xrange(5):
1008             f=allFMTSLeavesPerCommonSupport[1][0][0][i]
1009             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1010             f.loadArraysIfNecessary()
1011             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1012             self.assertEqual(f.getName(),"zeField3")
1013             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1014             vExp=DataArrayDouble(8*2) ; vExp.iota(200+1000*i) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]'%m,'Com2_2 [s^2]'%m])
1015             self.assertTrue(v.isEqual(vExp,1e-12))
1016             pass
1017         pass
1018     
1019     def test6(self):
1020         """ This test plays with cartesian mesh and profiles. When a sub cartesian mesh can also be considered as a cartesian mesh it is done.
1021         """
1022         fname="ForMEDReader6.med"
1023         m=MEDCouplingCMesh("mesh")
1024         coordsX=DataArrayDouble([0,1.1,2.2,3.3,4.4]) ; coordsX.setInfoOnComponents(["XX [m]"])
1025         coordsY=DataArrayDouble([0,1.7,3.4]) ; coordsY.setInfoOnComponents(["YYY [km]"])
1026         m.setCoords(coordsX,coordsY)
1027         mm=MEDFileCMesh() ; mm.setMesh(m)
1028         fam=DataArrayInt(8) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam) ; del fam
1029         num=DataArrayInt(8) ; num.iota(100) ; mm.setRenumFieldArr(0,num) ; del num
1030         num=DataArrayInt(15) ; num.iota(200) ; mm.setRenumFieldArr(1,num) ; del num
1031         #
1032         fieldName0="zeField0" ; # on cells
1033         fieldName1="zeField1" ; pfl1=DataArrayInt([2,3,6,7]) ; pfl1.setName("pfl1") # on cells
1034         fieldName2="zeField2" ; pfl2=DataArrayInt([2,3,4,7,8,9,12,13,14]) ; pfl2.setName("pfl2") # on nodes
1035         fieldName3="zeField3" ; pfl3=DataArrayInt([2,3,5,7]) ; pfl3.setName("pfl3") # on cells but different support
1036         fieldName4="zeField4" ;# on nodes
1037         fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS() ; fs4=MEDFileFieldMultiTS()
1038         #
1039         for i in xrange(5):
1040             f=MEDFileField1TS()
1041             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1042             fNode.setName(fieldName0) ; fNode.setMesh(m)
1043             arr=DataArrayDouble(2*8) ; arr.iota(0+1000*i) ; arr.rearrange(2)
1044             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
1045             f.setFieldNoProfileSBT(fNode)
1046             fs0.pushBackTimeStep(f)
1047             #
1048             f=MEDFileField1TS()
1049             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1050             fNode.setName(fieldName1)
1051             arr=DataArrayDouble(2*4) ; arr.iota(100+1000*i) ; arr.rearrange(2)
1052             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
1053             f.setFieldProfile(fNode,mm,0,pfl1)
1054             self.assertEqual(pfl1.getName(),"pfl1")
1055             fs1.pushBackTimeStep(f)
1056             #
1057             f=MEDFileField1TS()
1058             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1059             fNode.setName(fieldName2)
1060             arr=DataArrayDouble(2*9) ; arr.iota(200+1000*i) ; arr.rearrange(2)
1061             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
1062             f.setFieldProfile(fNode,mm,0,pfl2)
1063             self.assertEqual(pfl2.getName(),"pfl2")
1064             fs2.pushBackTimeStep(f)
1065             #
1066             f=MEDFileField1TS()
1067             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1068             fNode.setName(fieldName3)
1069             arr=DataArrayDouble(2*4) ; arr.iota(300+1000*i) ; arr.rearrange(2)
1070             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_3 [m]","Com2_3 [s^2]"])
1071             f.setFieldProfile(fNode,mm,0,pfl3)
1072             self.assertEqual(pfl3.getName(),"pfl3")
1073             fs3.pushBackTimeStep(f)
1074             #
1075             f=MEDFileField1TS()
1076             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1077             fNode.setName(fieldName4) ; fNode.setMesh(m)
1078             arr=DataArrayDouble(2*15) ; arr.iota(400+1000*i) ; arr.rearrange(2)
1079             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_4 [m]","Com2_4 [s^2]"]) ; fNode.checkCoherency()
1080             f.setFieldNoProfileSBT(fNode)
1081             fs4.pushBackTimeStep(f)
1082             pass
1083         mm.write(fname,2)
1084         fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0) ; fs4.write(fname,0)
1085         del m,mm,fs1,fs2,fs3,f,fNode
1086         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
1087         ms=MEDFileMeshes(fname)
1088         fields=MEDFileFields(fname,False)
1089         fields.removeFieldsWithoutAnyTimeStep()
1090         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
1091         allFMTSLeavesToDisplay=[]
1092         for fields in fields_per_mesh:
1093             allFMTSLeavesToDisplay2=[]
1094             for fmts in fields:
1095                 tmp=fmts.splitDiscretizations()
1096                 for itmp in tmp:
1097                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1098                     pass
1099                 allFMTSLeavesToDisplay2+=tmp
1100                 pass
1101             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
1102             pass
1103         self.assertEqual(len(allFMTSLeavesToDisplay),1)
1104         self.assertEqual(len(allFMTSLeavesToDisplay[0]),5)
1105         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
1106         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 5 fields are defined on the same time steps
1107         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),5)
1108         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
1109         self.assertEqual(len(allFMTSLeavesPerCommonSupport),3)
1110         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
1111         self.assertEqual(len(allFMTSLeavesPerCommonSupport[1][0]),2)
1112         self.assertEqual(len(allFMTSLeavesPerCommonSupport[2][0]),1)
1113         #
1114         mst=MEDFileMeshStruct.New(ms[0])
1115         #
1116         fcscp=allFMTSLeavesPerCommonSupport[0][1]
1117         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1118         mml2=mml.prepare()
1119         (a,b),c=mml2.buildVTUArrays()
1120         self.assertTrue(c)# c is True here because the returned array is directly those coming from internal structure
1121         self.assertTrue(a.isEqual(coordsX,1e-12))
1122         self.assertTrue(b.isEqual(coordsY,1e-12))
1123         self.assertTrue(isinstance(mml2,MEDCMeshMultiLev))
1124         for i in xrange(1,5):
1125             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
1126             pass
1127         a6,a7=mml2.retrieveFamilyIdsOnCells()
1128         self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5,6,7])))
1129         self.assertTrue(a7) # True because no copy
1130         a8,a9=mml2.retrieveNumberIdsOnCells()
1131         self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,106,107])))
1132         self.assertTrue(a9) # True because no copy
1133         a10,a11=mml2.retrieveNumberIdsOnNodes()
1134         self.assertTrue(a10.isEqual(DataArrayInt([200,201,202,203,204,205,206,207,208,209,210,211,212,213,214])))
1135         self.assertTrue(a11) # True because no copy
1136         for i in xrange(5):
1137             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
1138             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1139             f.loadArraysIfNecessary()
1140             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1141             self.assertEqual(f.getName(),fieldName0)
1142             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1143             vExp=DataArrayDouble(8*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
1144             self.assertTrue(v.isEqual(vExp,1e-12))
1145             #
1146             f=allFMTSLeavesPerCommonSupport[0][0][1][i]
1147             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1148             f.loadArraysIfNecessary()
1149             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1150             self.assertEqual(f.getName(),fieldName4)
1151             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1152             vExp=DataArrayDouble(15*2) ; vExp.iota(400+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_4 [m]','Com2_4 [s^2]'])
1153             self.assertTrue(v.isEqual(vExp,1e-12))
1154             pass
1155         
1156         fcscp=allFMTSLeavesPerCommonSupport[1][1]
1157         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1158         mml2=mml.prepare()
1159         self.assertTrue(isinstance(mml2,MEDCMeshMultiLev)) # here the 2nd support is a part of CMesh that is also a CMesh -> CMesh not a UMesh
1160         (a,b),c=mml2.buildVTUArrays()
1161         self.assertTrue(not c)# c is False because this a sub support specialy built for buildVTUArrays
1162         self.assertTrue(a.isEqual(coordsX[[2,3,4]],1e-12))
1163         self.assertTrue(b.isEqual(coordsY,1e-12))
1164         a6,a7=mml2.retrieveFamilyIdsOnCells()
1165         self.assertTrue(a6.isEqual(DataArrayInt([2,3,6,7])))
1166         self.assertTrue(not a7) # False because copy
1167         a8,a9=mml2.retrieveNumberIdsOnCells()
1168         self.assertTrue(a8.isEqual(DataArrayInt([102,103,106,107])))
1169         self.assertTrue(not a9) # False because copy
1170         a10,a11=mml2.retrieveNumberIdsOnNodes()
1171         self.assertTrue(a10.isEqual(DataArrayInt([202,203,204,207,208,209,212,213,214])))
1172         self.assertTrue(not a11) # False because copy
1173         for i in xrange(1,5):
1174             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
1175             pass
1176         for i in xrange(5):
1177             f=allFMTSLeavesPerCommonSupport[1][0][0][i]
1178             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1179             f.loadArraysIfNecessary()
1180             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1181             self.assertEqual(f.getName(),fieldName1)
1182             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1183             vExp=DataArrayDouble(4*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
1184             self.assertTrue(v.isEqual(vExp,1e-12))
1185             #
1186             f=allFMTSLeavesPerCommonSupport[1][0][1][i]
1187             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1188             f.loadArraysIfNecessary()
1189             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1190             self.assertEqual(f.getName(),fieldName2)
1191             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1192             vExp=DataArrayDouble(9*2) ; vExp.iota(200+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]'])
1193             self.assertTrue(v.isEqual(vExp,1e-12))
1194             pass
1195         #
1196         fcscp=allFMTSLeavesPerCommonSupport[2][1]
1197         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1198         mml2=mml.prepare()
1199         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) # here the 3rd support is a part of CMesh but impossible to simplify more than a UMesh
1200         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
1201         self.assertTrue(not ncc)
1202         a0Exp=DataArrayDouble([0.,0.,1.1,0.,2.2,0.,3.3,0.,4.4,0.,0.,1.7,1.1,1.7,2.2,1.7,3.3,1.7,4.4,1.7,0.,3.4,1.1,3.4,2.2,3.4,3.3,3.4,4.4,3.4],15,2)
1203         a0Exp.setInfoOnComponents(["XX [m]","YYY [km]"])
1204         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
1205         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9])))
1206         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15])))
1207         self.assertTrue(a3.isEqual(DataArrayInt([4,3,2,7,8,4,4,3,8,9,4,7,6,11,12,4,9,8,13,14])))
1208         self.assertTrue(a4 is None)
1209         self.assertTrue(a5 is None)
1210         a6,a7=mml2.retrieveFamilyIdsOnCells()
1211         self.assertTrue(a6.isEqual(DataArrayInt([2,3,5,7])))
1212         self.assertTrue(not a7) # False because copy
1213         a8,a9=mml2.retrieveNumberIdsOnCells()
1214         self.assertTrue(a8.isEqual(DataArrayInt([102,103,105,107])))
1215         self.assertTrue(not a9) # False because copy
1216         for i in xrange(5):
1217             f=allFMTSLeavesPerCommonSupport[2][0][0][i]
1218             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1219             f.loadArraysIfNecessary()
1220             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1221             self.assertEqual(f.getName(),fieldName3)
1222             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1223             vExp=DataArrayDouble(4*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_3 [m]','Com2_3 [s^2]'])
1224             self.assertTrue(v.isEqual(vExp,1e-12))
1225             pass
1226         pass
1227
1228     def test7(self):
1229         """ This test plays with curvilinear mesh and profiles. When a sub curvilinear mesh can also be considered as a cartesian mesh it is done.
1230         This test is very similar to the test6.
1231         """
1232         fname="ForMEDReader7.med"
1233         m=MEDCouplingCurveLinearMesh("mesh") ; m.setNodeGridStructure([5,3])
1234         a0Exp=DataArrayDouble([0.,0.,1.1,0.,2.2,0.,3.3,0.,4.4,0.,0.,1.7,1.1,1.7,2.2,1.7,3.3,1.7,4.4,1.7,0.,3.4,1.1,3.4,2.2,3.4,3.3,3.4,4.4,3.4],15,2)
1235         a0Exp.setInfoOnComponents(["XX [m]","YYY [km]"])
1236         m.setCoords(a0Exp)
1237         mm=MEDFileCurveLinearMesh() ; mm.setMesh(m)
1238         fam=DataArrayInt(8) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam) ; del fam
1239         num=DataArrayInt(8) ; num.iota(100) ; mm.setRenumFieldArr(0,num) ; del num
1240         #
1241         fieldName0="zeField0" ; # on cells
1242         fieldName1="zeField1" ; pfl1=DataArrayInt([2,3,6,7]) ; pfl1.setName("pfl1") # on cells
1243         fieldName2="zeField2" ; pfl2=DataArrayInt([2,3,4,7,8,9,12,13,14]) ; pfl2.setName("pfl2") # on nodes
1244         fieldName3="zeField3" ; pfl3=DataArrayInt([2,3,5,7]) ; pfl3.setName("pfl3") # on cells but different support
1245         fieldName4="zeField4" ;# on nodes
1246         fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS() ; fs4=MEDFileFieldMultiTS()
1247         #
1248         for i in xrange(5):
1249             f=MEDFileField1TS()
1250             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1251             fNode.setName(fieldName0) ; fNode.setMesh(m)
1252             arr=DataArrayDouble(2*8) ; arr.iota(0+1000*i) ; arr.rearrange(2)
1253             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
1254             f.setFieldNoProfileSBT(fNode)
1255             fs0.pushBackTimeStep(f)
1256             #
1257             f=MEDFileField1TS()
1258             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1259             fNode.setName(fieldName1)
1260             arr=DataArrayDouble(2*4) ; arr.iota(100+1000*i) ; arr.rearrange(2)
1261             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
1262             f.setFieldProfile(fNode,mm,0,pfl1)
1263             self.assertEqual(pfl1.getName(),"pfl1")
1264             fs1.pushBackTimeStep(f)
1265             #
1266             f=MEDFileField1TS()
1267             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1268             fNode.setName(fieldName2)
1269             arr=DataArrayDouble(2*9) ; arr.iota(200+1000*i) ; arr.rearrange(2)
1270             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
1271             f.setFieldProfile(fNode,mm,0,pfl2)
1272             self.assertEqual(pfl2.getName(),"pfl2")
1273             fs2.pushBackTimeStep(f)
1274             #
1275             f=MEDFileField1TS()
1276             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1277             fNode.setName(fieldName3)
1278             arr=DataArrayDouble(2*4) ; arr.iota(300+1000*i) ; arr.rearrange(2)
1279             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_3 [m]","Com2_3 [s^2]"])
1280             f.setFieldProfile(fNode,mm,0,pfl3)
1281             self.assertEqual(pfl3.getName(),"pfl3")
1282             fs3.pushBackTimeStep(f)
1283             #
1284             f=MEDFileField1TS()
1285             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1286             fNode.setName(fieldName4) ; fNode.setMesh(m)
1287             arr=DataArrayDouble(2*15) ; arr.iota(400+1000*i) ; arr.rearrange(2)
1288             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_4 [m]","Com2_4 [s^2]"]) ; fNode.checkCoherency()
1289             f.setFieldNoProfileSBT(fNode)
1290             fs4.pushBackTimeStep(f)
1291             pass
1292         mm.write(fname,2)
1293         fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0) ; fs4.write(fname,0)
1294         del m,mm,fs1,fs2,fs3,f,fNode
1295         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
1296         ms=MEDFileMeshes(fname)
1297         fields=MEDFileFields(fname,False)
1298         fields.removeFieldsWithoutAnyTimeStep()
1299         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
1300         allFMTSLeavesToDisplay=[]
1301         for fields in fields_per_mesh:
1302             allFMTSLeavesToDisplay2=[]
1303             for fmts in fields:
1304                 tmp=fmts.splitDiscretizations()
1305                 for itmp in tmp:
1306                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1307                     pass
1308                 allFMTSLeavesToDisplay2+=tmp
1309                 pass
1310             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
1311             pass
1312         self.assertEqual(len(allFMTSLeavesToDisplay),1)
1313         self.assertEqual(len(allFMTSLeavesToDisplay[0]),5)
1314         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
1315         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 5 fields are defined on the same time steps
1316         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),5)
1317         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
1318         self.assertEqual(len(allFMTSLeavesPerCommonSupport),3)
1319         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
1320         self.assertEqual(len(allFMTSLeavesPerCommonSupport[1][0]),2)
1321         self.assertEqual(len(allFMTSLeavesPerCommonSupport[2][0]),1)
1322         #
1323         mst=MEDFileMeshStruct.New(ms[0])
1324         #
1325         fcscp=allFMTSLeavesPerCommonSupport[0][1]
1326         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1327         mml2=mml.prepare()
1328         self.assertTrue(isinstance(mml2,MEDCurveLinearMeshMultiLev))
1329         a,b,c=mml2.buildVTUArrays()
1330         self.assertTrue(c)#True here because a is directly coming from internal data without copy
1331         self.assertTrue(a.isEqual(a0Exp,1e-12))
1332         self.assertEqual(b,[5,3])
1333         a6,a7=mml2.retrieveFamilyIdsOnCells()
1334         self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5,6,7])))
1335         self.assertTrue(a7) # True because no copy
1336         a8,a9=mml2.retrieveNumberIdsOnCells()
1337         self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,106,107])))
1338         self.assertTrue(a9) # True because no copy
1339         for i in xrange(1,5):
1340             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
1341             pass
1342         for i in xrange(5):
1343             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
1344             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1345             f.loadArraysIfNecessary()
1346             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1347             self.assertEqual(f.getName(),fieldName0)
1348             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1349             vExp=DataArrayDouble(8*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
1350             self.assertTrue(v.isEqual(vExp,1e-12))
1351             #
1352             f=allFMTSLeavesPerCommonSupport[0][0][1][i]
1353             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1354             f.loadArraysIfNecessary()
1355             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1356             self.assertEqual(f.getName(),fieldName4)
1357             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1358             vExp=DataArrayDouble(15*2) ; vExp.iota(400+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_4 [m]','Com2_4 [s^2]'])
1359             self.assertTrue(v.isEqual(vExp,1e-12))
1360             pass
1361         #
1362         fcscp=allFMTSLeavesPerCommonSupport[1][1]
1363         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1364         mml2=mml.prepare()
1365         self.assertTrue(isinstance(mml2,MEDCurveLinearMeshMultiLev)) # here the 2nd support is a part of CMesh that is also a CMesh -> CMesh not a UMesh
1366         a,b,c=mml2.buildVTUArrays()
1367         self.assertTrue(not c)#False here because a is the result of a computation not the internal strucutre
1368         self.assertTrue(a.isEqual(a0Exp[pfl2],1e-12))
1369         self.assertEqual(b,[3,3])
1370         a6,a7=mml2.retrieveFamilyIdsOnCells()
1371         self.assertTrue(a6.isEqual(DataArrayInt([2,3,6,7])))
1372         self.assertTrue(not a7) # False because copy
1373         a8,a9=mml2.retrieveNumberIdsOnCells()
1374         self.assertTrue(a8.isEqual(DataArrayInt([102,103,106,107])))
1375         self.assertTrue(not a9) # False because copy
1376         for i in xrange(1,5):
1377             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
1378             pass
1379         for i in xrange(5):
1380             f=allFMTSLeavesPerCommonSupport[1][0][0][i]
1381             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1382             f.loadArraysIfNecessary()
1383             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1384             self.assertEqual(f.getName(),fieldName1)
1385             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1386             vExp=DataArrayDouble(4*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
1387             self.assertTrue(v.isEqual(vExp,1e-12))
1388             #
1389             f=allFMTSLeavesPerCommonSupport[1][0][1][i]
1390             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1391             f.loadArraysIfNecessary()
1392             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1393             self.assertEqual(f.getName(),fieldName2)
1394             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1395             vExp=DataArrayDouble(9*2) ; vExp.iota(200+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]'])
1396             self.assertTrue(v.isEqual(vExp,1e-12))
1397             pass
1398         #
1399         fcscp=allFMTSLeavesPerCommonSupport[2][1]
1400         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1401         mml2=mml.prepare()
1402         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) # here the 3rd support is a part of CMesh but impossible to simplify more than a UMesh
1403         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
1404         self.assertTrue(not ncc)
1405         a0Exp=DataArrayDouble([0.,0.,1.1,0.,2.2,0.,3.3,0.,4.4,0.,0.,1.7,1.1,1.7,2.2,1.7,3.3,1.7,4.4,1.7,0.,3.4,1.1,3.4,2.2,3.4,3.3,3.4,4.4,3.4],15,2)
1406         a0Exp.setInfoOnComponents(["XX [m]","YYY [km]"])
1407         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
1408         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9])))
1409         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15])))
1410         self.assertTrue(a3.isEqual(DataArrayInt([4,3,2,7,8,4,4,3,8,9,4,7,6,11,12,4,9,8,13,14])))
1411         self.assertTrue(a4 is None)
1412         self.assertTrue(a5 is None)
1413         a6,a7=mml2.retrieveFamilyIdsOnCells()
1414         self.assertTrue(a6.isEqual(DataArrayInt([2,3,5,7])))
1415         self.assertTrue(not a7) # False because copy
1416         a8,a9=mml2.retrieveNumberIdsOnCells()
1417         self.assertTrue(a8.isEqual(DataArrayInt([102,103,105,107])))
1418         self.assertTrue(not a9) # False because copy
1419         for i in xrange(5):
1420             f=allFMTSLeavesPerCommonSupport[2][0][0][i]
1421             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1422             f.loadArraysIfNecessary()
1423             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1424             self.assertEqual(f.getName(),fieldName3)
1425             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1426             vExp=DataArrayDouble(4*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_3 [m]','Com2_3 [s^2]'])
1427             self.assertTrue(v.isEqual(vExp,1e-12))
1428             pass
1429         pass
1430
1431     def test8(self):
1432         """ This test plays with with gauss fields with no profiles.
1433         """
1434         fname="ForMEDReader8.med"
1435         # building a mesh containing 6 tri3 + 5 quad4
1436         m=MEDCouplingUMesh("mesh",2)
1437         coords=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)]) ; coords.setInfoOnComponents(["XX [m]","YYY [km]"])
1438         m.setCoords(coords)
1439         m.allocateCells()
1440         m.insertNextCell(NORM_TRI3,[2,7,3]) ; m.insertNextCell(NORM_TRI3,[7,8,3]) ; m.insertNextCell(NORM_TRI3,[3,8,4]) ; m.insertNextCell(NORM_TRI3,[8,9,4])
1441         m.insertNextCell(NORM_TRI3,[13,9,8]) ; m.insertNextCell(NORM_TRI3,[13,14,9])
1442         m.insertNextCell(NORM_QUAD4,[0,5,6,1]) ; m.insertNextCell(NORM_QUAD4,[1,6,7,2]) ; m.insertNextCell(NORM_QUAD4,[5,10,11,6]) ; m.insertNextCell(NORM_QUAD4,[6,11,12,7])
1443         m.insertNextCell(NORM_QUAD4,[12,13,8,7])
1444         mm=MEDFileUMesh() ; mm.setMeshes([m])
1445         #
1446         fieldName0="zeField0"
1447         fieldName1="zeField1"
1448         fieldName2="zeField2"
1449         fieldName3="zeField3"
1450         fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
1451         for i in xrange(5):
1452             f=MEDFileField1TS()
1453             fNode=MEDCouplingFieldDouble(ON_GAUSS_NE) ; fNode.setTime(float(i),i,0)
1454             fNode.setName(fieldName0) ; fNode.setMesh(m)
1455             arr=DataArrayDouble(2*38) ; arr.iota(0+1000*i) ; arr.rearrange(2)
1456             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
1457             f.setFieldNoProfileSBT(fNode)
1458             fs0.pushBackTimeStep(f)
1459             #
1460             f=MEDFileField1TS()
1461             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1462             fNode.setName(fieldName1) ; fNode.setMesh(m)
1463             arr=DataArrayDouble(2*11) ; arr.iota(100+1000*i) ; arr.rearrange(2)
1464             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) ; fNode.checkCoherency()
1465             f.setFieldNoProfileSBT(fNode)
1466             fs1.pushBackTimeStep(f)
1467             #
1468             f=MEDFileField1TS()
1469             fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
1470             fNode.setName(fieldName2) ; fNode.setMesh(m)
1471             fNode.setGaussLocalizationOnCells([0,1,2,3],[0.,0.,1.,0.,0.,1.],[0.5,0.5,0.7,0.7],[0.8,0.2])
1472             fNode.setGaussLocalizationOnCells([4,5],[0.,0.,1.,0.,0.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3],[0.8,0.05,0.1,0.04,0.01])
1473             fNode.setGaussLocalizationOnCells([6,7,8],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2],[0.8,0.05,0.1,0.04])
1474             fNode.setGaussLocalizationOnCells([9,10],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.8,0.8],[0.8,0.05,0.1,0.01,0.02,0.005,0.005])
1475             arr=DataArrayDouble(2*(4*2+2*5+3*4+2*7)) ; arr.iota(300+1000*i) ; arr.rearrange(2)
1476             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) ; fNode.checkCoherency()
1477             f.setFieldNoProfileSBT(fNode)
1478             fs2.pushBackTimeStep(f)
1479             #
1480             f=MEDFileField1TS()
1481             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1482             fNode.setName(fieldName3) ; fNode.setMesh(m)
1483             arr=DataArrayDouble(2*15) ; arr.iota(400+1000*i) ; arr.rearrange(2)
1484             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_3 [m]","Com2_3 [s^2]"]) ; fNode.checkCoherency()
1485             f.setFieldNoProfileSBT(fNode)
1486             fs3.pushBackTimeStep(f)
1487             #
1488             pass
1489         #
1490         mm.write(fname,2)
1491         fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0)
1492         a0Exp=mm.getCoords().deepCpy()
1493         del m,mm,fs1,fs2,fs3,f,fNode
1494         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
1495         ms=MEDFileMeshes(fname)
1496         fields=MEDFileFields(fname,False)
1497         fields.removeFieldsWithoutAnyTimeStep()
1498         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
1499         allFMTSLeavesToDisplay=[]
1500         for fields in fields_per_mesh:
1501             allFMTSLeavesToDisplay2=[]
1502             for fmts in fields:
1503                 tmp=fmts.splitDiscretizations()
1504                 #for itmp in tmp:
1505                 #    self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1506                 #    pass
1507                 allFMTSLeavesToDisplay2+=tmp
1508                 pass
1509             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
1510             pass
1511         self.assertEqual(len(allFMTSLeavesToDisplay),1)
1512         self.assertEqual(len(allFMTSLeavesToDisplay[0]),4)
1513         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
1514         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 4 fields are defined on the same time steps
1515         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
1516         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
1517         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
1518         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),4)
1519         #
1520         mst=MEDFileMeshStruct.New(ms[0])
1521         #
1522         fcscp=allFMTSLeavesPerCommonSupport[0][1]
1523         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1524         mml2=mml.prepare()
1525         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
1526         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
1527         self.assertTrue(not ncc)
1528         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
1529         self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,5,5,5,9,9,9,9,9])))
1530         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,16,20,24,29,34,39,44])))
1531         self.assertTrue(a3.isEqual(DataArrayInt([3,2,7,3,3,7,8,3,3,3,8,4,3,8,9,4,3,13,9,8,3,13,14,9,4,0,5,6,1,4,1,6,7,2,4,5,10,11,6,4,6,11,12,7,4,12,13,8,7])))
1532         self.assertTrue(a4 is None)
1533         self.assertTrue(a5 is None)
1534         for i in xrange(1,5):
1535             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
1536             pass
1537         for i in xrange(5):
1538             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
1539             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1540             f.loadArraysIfNecessary()
1541             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1542             self.assertEqual(f.getName(),fieldName0)
1543             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1544             vExp=DataArrayDouble(38*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
1545             self.assertTrue(v.isEqual(vExp,1e-12))
1546             #
1547             f=allFMTSLeavesPerCommonSupport[0][0][1][i]
1548             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1549             f.loadArraysIfNecessary()
1550             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1551             self.assertEqual(f.getName(),fieldName1)
1552             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1553             vExp=DataArrayDouble(11*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
1554             self.assertTrue(v.isEqual(vExp,1e-12))
1555             #
1556             f=allFMTSLeavesPerCommonSupport[0][0][2][i]
1557             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1558             f.loadArraysIfNecessary()
1559             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1560             self.assertEqual(f.getName(),fieldName2)
1561             #self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) # not a bug
1562             vExp=DataArrayDouble(44*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]'])
1563             self.assertTrue(v.isEqual(vExp,1e-12))
1564             #
1565             f=allFMTSLeavesPerCommonSupport[0][0][3][i]
1566             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1567             f.loadArraysIfNecessary()
1568             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1569             self.assertEqual(f.getName(),fieldName3)
1570             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1571             vExp=DataArrayDouble(15*2) ; vExp.iota(400+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_3 [m]','Com2_3 [s^2]'])
1572             self.assertTrue(v.isEqual(vExp,1e-12))
1573             pass
1574         #
1575         pass
1576
1577     def test9(self):
1578         """ This test plays with with gauss fields with profiles.
1579         """
1580         fname="ForMEDReader9.med"
1581         # building a mesh containing 6 tri3 + 5 quad4
1582         m=MEDCouplingUMesh("mesh",2)
1583         coords=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)]) ; coords.setInfoOnComponents(["XX [m]","YYY [km]"])
1584         m.setCoords(coords)
1585         m.allocateCells()
1586         m.insertNextCell(NORM_TRI3,[2,7,3]) ; m.insertNextCell(NORM_TRI3,[7,8,3]) ; m.insertNextCell(NORM_TRI3,[3,8,4]) ; m.insertNextCell(NORM_TRI3,[8,9,4])
1587         m.insertNextCell(NORM_TRI3,[13,9,8]) ; m.insertNextCell(NORM_TRI3,[13,14,9])
1588         m.insertNextCell(NORM_QUAD4,[0,5,6,1]) ; m.insertNextCell(NORM_QUAD4,[1,6,7,2]) ; m.insertNextCell(NORM_QUAD4,[5,10,11,6]) ; m.insertNextCell(NORM_QUAD4,[6,11,12,7])
1589         m.insertNextCell(NORM_QUAD4,[12,13,8,7])
1590         mm=MEDFileUMesh() ; mm.setMeshes([m])
1591         #
1592         fieldName0="zeField0"
1593         fieldName1="zeField1"
1594         fieldName2="zeField2"
1595         fieldName3="zeField3"
1596         pfl1=DataArrayInt([0,1,7,9,10]) ; pfl1.setName("pfl1") # on cells
1597         pfl2=DataArrayInt([1,2,3,6,7,8,11,12,13]) ; pfl2.setName("pfl2") # on nodes
1598         fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
1599         for i in xrange(5):
1600             f=MEDFileField1TS()
1601             fNode=MEDCouplingFieldDouble(ON_GAUSS_NE) ; fNode.setTime(float(i),i,0)
1602             fNode.setName(fieldName0)
1603             arr=DataArrayDouble(2*18) ; arr.iota(0+1000*i) ; arr.rearrange(2)
1604             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
1605             f.setFieldProfile(fNode,mm,0,pfl1)
1606             fs0.pushBackTimeStep(f)
1607             #
1608             f=MEDFileField1TS()
1609             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1610             fNode.setName(fieldName1)
1611             arr=DataArrayDouble(2*5) ; arr.iota(100+1000*i) ; arr.rearrange(2)
1612             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
1613             f.setFieldProfile(fNode,mm,0,pfl1)
1614             fs1.pushBackTimeStep(f)
1615             #
1616             f=MEDFileField1TS()
1617             fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
1618             fNode.setName(fieldName2) ; fNode.setMesh(m[pfl1])
1619             fNode.setGaussLocalizationOnCells([0],[0.,0.,1.,0.,0.,1.],[0.5,0.5,0.7,0.7],[0.8,0.2])
1620             fNode.setGaussLocalizationOnCells([1],[0.,0.,1.,0.,0.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3],[0.8,0.05,0.1,0.04,0.01])
1621             fNode.setGaussLocalizationOnCells([2,3],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2],[0.8,0.05,0.1,0.04])
1622             fNode.setGaussLocalizationOnCells([4],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.8,0.8],[0.8,0.05,0.1,0.01,0.02,0.005,0.005])
1623             arr=DataArrayDouble(2*(2*1+5*1+4*2+7*1)) ; arr.iota(300+1000*i) ; arr.rearrange(2)
1624             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) ; fNode.checkCoherency()
1625             f.setFieldProfile(fNode,mm,0,pfl1)
1626             fs2.pushBackTimeStep(f)
1627             #
1628             f=MEDFileField1TS()
1629             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1630             fNode.setName(fieldName3)
1631             arr=DataArrayDouble(2*9) ; arr.iota(400+1000*i) ; arr.rearrange(2)
1632             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_3 [m]","Com2_3 [s^2]"])
1633             f.setFieldProfile(fNode,mm,0,pfl2)
1634             fs3.pushBackTimeStep(f)
1635             #
1636             pass
1637         #
1638         mm.write(fname,2)
1639         fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0)
1640         a0Exp=mm.getCoords().deepCpy()
1641         del m,mm,fs1,fs2,fs3,f,fNode
1642         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
1643         ms=MEDFileMeshes(fname)
1644         fields=MEDFileFields(fname,False)
1645         fields.removeFieldsWithoutAnyTimeStep()
1646         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
1647         allFMTSLeavesToDisplay=[]
1648         for fields in fields_per_mesh:
1649             allFMTSLeavesToDisplay2=[]
1650             for fmts in fields:
1651                 tmp=fmts.splitDiscretizations()
1652                 #for itmp in tmp:
1653                 #    self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1654                 #    pass
1655                 allFMTSLeavesToDisplay2+=tmp
1656                 pass
1657             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
1658             pass
1659         self.assertEqual(len(allFMTSLeavesToDisplay),1)
1660         self.assertEqual(len(allFMTSLeavesToDisplay[0]),4)
1661         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
1662         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 4 fields are defined on the same time steps
1663         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
1664         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
1665         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
1666         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),4)
1667         #
1668         mst=MEDFileMeshStruct.New(ms[0])
1669         #
1670         fcscp=allFMTSLeavesPerCommonSupport[0][1]
1671         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1672         mml2=mml.prepare()
1673         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
1674         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
1675         self.assertTrue(not ncc)
1676         self.assertTrue(a0.isEqual(a0Exp[pfl2].changeNbOfComponents(3,0.),1e-12))
1677         self.assertTrue(a1.isEqual(DataArrayByte([5,5,9,9,9])))
1678         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,13,18])))
1679         self.assertTrue(a3.isEqual(DataArrayInt([3,1,4,2,3,4,5,2,4,0,3,4,1,4,3,6,7,4,4,7,8,5,4])))
1680         self.assertTrue(a4 is None)
1681         self.assertTrue(a5 is None)
1682         for i in xrange(1,5):
1683             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
1684             pass
1685         for i in xrange(5):
1686             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
1687             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1688             f.loadArraysIfNecessary()
1689             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1690             self.assertEqual(f.getName(),fieldName0)
1691             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1692             vExp=DataArrayDouble(18*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
1693             self.assertTrue(v.isEqual(vExp,1e-12))
1694             #
1695             f=allFMTSLeavesPerCommonSupport[0][0][1][i]
1696             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1697             f.loadArraysIfNecessary()
1698             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1699             self.assertEqual(f.getName(),fieldName1)
1700             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1701             vExp=DataArrayDouble(5*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
1702             self.assertTrue(v.isEqual(vExp,1e-12))
1703             #
1704             f=allFMTSLeavesPerCommonSupport[0][0][2][i]
1705             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1706             f.loadArraysIfNecessary()
1707             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1708             self.assertEqual(f.getName(),fieldName2)
1709             #self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) # not a bug
1710             vExp=DataArrayDouble(22*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]'])
1711             self.assertTrue(v.isEqual(vExp,1e-12))
1712             #
1713             f=allFMTSLeavesPerCommonSupport[0][0][3][i]
1714             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1715             f.loadArraysIfNecessary()
1716             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1717             self.assertEqual(f.getName(),fieldName3)
1718             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1719             vExp=DataArrayDouble(9*2) ; vExp.iota(400+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_3 [m]','Com2_3 [s^2]'])
1720             self.assertTrue(v.isEqual(vExp,1e-12))
1721             pass
1722         pass
1723     
1724     def test10(self):
1725         """ This test plays with fields only on nodes containing profiles.
1726         """
1727         fname="ForMEDReader10.med"
1728         # building a mesh containing 6 tri3 + 5 quad4
1729         m=MEDCouplingUMesh("mesh",2)
1730         coords=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)]) ; coords.setInfoOnComponents(["XX [m]","YYY [km]"])
1731         m.setCoords(coords)
1732         m.allocateCells()
1733         m.insertNextCell(NORM_TRI3,[2,7,3]) ; m.insertNextCell(NORM_TRI3,[7,8,3]) ; m.insertNextCell(NORM_TRI3,[3,8,4]) ; m.insertNextCell(NORM_TRI3,[8,9,4])
1734         m.insertNextCell(NORM_TRI3,[13,9,8]) ; m.insertNextCell(NORM_TRI3,[13,14,9])
1735         m.insertNextCell(NORM_QUAD4,[0,5,6,1]) ; m.insertNextCell(NORM_QUAD4,[1,6,7,2]) ; m.insertNextCell(NORM_QUAD4,[5,10,11,6]) ; m.insertNextCell(NORM_QUAD4,[6,11,12,7])
1736         m.insertNextCell(NORM_QUAD4,[12,13,8,7])
1737         mm=MEDFileUMesh() ; mm.setMeshes([m])
1738         #
1739         fieldName0="zeField0"
1740         fieldName1="zeField1"
1741         fieldName2="zeField2"
1742         pfl1=DataArrayInt([1,2,3,6,7,8,11,12,13]) ; pfl1.setName("pfl1") # on nodes
1743         fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS()
1744         for i in xrange(5):
1745             f=MEDFileField1TS()
1746             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1747             fNode.setName(fieldName0)
1748             arr=DataArrayDouble(2*9) ; arr.iota(0+1000*i) ; arr.rearrange(2)
1749             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"])
1750             f.setFieldProfile(fNode,mm,0,pfl1)
1751             fs0.pushBackTimeStep(f)
1752             #
1753             f=MEDFileField1TS()
1754             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1755             fNode.setName(fieldName1)
1756             arr=DataArrayDouble(2*9) ; arr.iota(100+1000*i) ; arr.rearrange(2)
1757             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"])
1758             f.setFieldProfile(fNode,mm,0,pfl1)
1759             fs1.pushBackTimeStep(f)
1760             #
1761             f=MEDFileField1TS()
1762             fNode=MEDCouplingFieldDouble(ON_NODES) ; fNode.setTime(float(i),i,0)
1763             fNode.setName(fieldName2)
1764             arr=DataArrayDouble(2*9) ; arr.iota(200+1000*i) ; arr.rearrange(2)
1765             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"])
1766             f.setFieldProfile(fNode,mm,0,pfl1)
1767             fs2.pushBackTimeStep(f)
1768             #
1769             pass
1770         #
1771         mm.write(fname,2)
1772         fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0)
1773         a0Exp=mm.getCoords().deepCpy()
1774         del m,mm,fs1,fs2,f,fNode
1775         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
1776         ms=MEDFileMeshes(fname)
1777         fields=MEDFileFields(fname,False)
1778         fields.removeFieldsWithoutAnyTimeStep()
1779         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
1780         allFMTSLeavesToDisplay=[]
1781         for fields in fields_per_mesh:
1782             allFMTSLeavesToDisplay2=[]
1783             for fmts in fields:
1784                 tmp=fmts.splitDiscretizations()
1785                 for itmp in tmp:
1786                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1787                     pass
1788                 allFMTSLeavesToDisplay2+=tmp
1789                 pass
1790             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
1791             pass
1792         self.assertEqual(len(allFMTSLeavesToDisplay),1)
1793         self.assertEqual(len(allFMTSLeavesToDisplay[0]),3)
1794         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
1795         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 4 fields are defined on the same time steps
1796         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
1797         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
1798         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
1799         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),3)
1800         #
1801         mst=MEDFileMeshStruct.New(ms[0])
1802         #
1803         fcscp=allFMTSLeavesPerCommonSupport[0][1]
1804         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1805         mml2=mml.prepare()
1806         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
1807         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
1808         self.assertTrue(not ncc)
1809         self.assertTrue(a0.isEqual(a0Exp[pfl1].changeNbOfComponents(3,0.),1e-12))
1810         self.assertTrue(a1.isEqual(DataArrayByte([5,5,9,9,9])))
1811         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,13,18])))
1812         self.assertTrue(a3.isEqual(DataArrayInt([3,1,4,2,3,4,5,2,4,0,3,4,1,4,3,6,7,4,4,7,8,5,4])))
1813         self.assertTrue(a4 is None)
1814         self.assertTrue(a5 is None)
1815         for i in xrange(1,5):
1816             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
1817             pass
1818         for i in xrange(5):
1819             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
1820             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1821             f.loadArraysIfNecessary()
1822             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1823             self.assertEqual(f.getName(),fieldName0)
1824             #self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) # not a bug
1825             vExp=DataArrayDouble(9*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
1826             self.assertTrue(v.isEqual(vExp,1e-12))
1827             #
1828             f=allFMTSLeavesPerCommonSupport[0][0][1][i]
1829             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1830             f.loadArraysIfNecessary()
1831             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1832             self.assertEqual(f.getName(),fieldName1)
1833             #self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) # not a bug
1834             vExp=DataArrayDouble(9*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
1835             self.assertTrue(v.isEqual(vExp,1e-12))
1836             #
1837             f=allFMTSLeavesPerCommonSupport[0][0][2][i]
1838             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1839             f.loadArraysIfNecessary()
1840             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1841             self.assertEqual(f.getName(),fieldName2)
1842             #self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) # not a bug
1843             vExp=DataArrayDouble(9*2) ; vExp.iota(200+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]'])
1844             self.assertTrue(v.isEqual(vExp,1e-12))
1845             pass
1846         pass
1847     
1848     def test11(self):
1849         """ This test is the ultimate test for the profiles with gauss points. It tests that even if there is non contiguous parts in definition of gauss points, it works !
1850         WARNING here, as no other discretizations exists, the priority is given to the field -> the mesh is renumbered to accelerate the build of array of field.
1851         """
1852         fname="ForMEDReader11.med"
1853         m=MEDCouplingCMesh("mesh")
1854         arr=DataArrayDouble(5) ; arr.iota()
1855         m.setCoords(arr,arr)
1856         m=m.buildUnstructured() ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
1857         mm=MEDFileUMesh() ; mm.setMeshes([m])
1858         #
1859         fieldName0="zeField0"
1860         fs0=MEDFileFieldMultiTS()
1861         for i in xrange(5):
1862             f=MEDFileField1TS()
1863             fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
1864             fNode.setName(fieldName0) ; fNode.setMesh(m)
1865             fNode.setGaussLocalizationOnCells([0,2,3,4,7,15],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7],[0.8,0.2])
1866             fNode.setGaussLocalizationOnCells([1,5,8,9],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3],[0.8,0.05,0.1,0.04,0.01])
1867             fNode.setGaussLocalizationOnCells([6,10,13],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2],[0.8,0.05,0.1,0.04])
1868             fNode.setGaussLocalizationOnCells([11,12,14],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.8,0.8],[0.8,0.05,0.1,0.01,0.02,0.005,0.005])
1869             arr=DataArrayDouble(2*(2*6+5*4+4*3+7*3)) ; arr.iota(0+1000*i) ; arr.rearrange(2)
1870             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
1871             f.setFieldNoProfileSBT(fNode)
1872             fs0.pushBackTimeStep(f)
1873             pass
1874         mm.write(fname,2)
1875         fs0.write(fname,0)
1876         a0Exp=mm.getCoords().deepCpy()
1877         del m,mm,fs0,f,fNode
1878         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
1879         ms=MEDFileMeshes(fname)
1880         fields=MEDFileFields(fname,False)
1881         fields.removeFieldsWithoutAnyTimeStep()
1882         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
1883         allFMTSLeavesToDisplay=[]
1884         for fields in fields_per_mesh:
1885             allFMTSLeavesToDisplay2=[]
1886             for fmts in fields:
1887                 tmp=fmts.splitDiscretizations()
1888                 #for itmp in tmp:
1889                 #    self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1890                 #    pass
1891                 allFMTSLeavesToDisplay2+=tmp
1892                 pass
1893             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
1894             pass
1895         self.assertEqual(len(allFMTSLeavesToDisplay),1)
1896         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
1897         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
1898         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 1 field is defined on the same time steps
1899         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
1900         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
1901         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
1902         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),1)
1903         #
1904         mst=MEDFileMeshStruct.New(ms[0])
1905         #
1906         fcscp=allFMTSLeavesPerCommonSupport[0][1]
1907         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
1908         mml2=mml.prepare()
1909         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
1910         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
1911         self.assertTrue(not ncc)
1912         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
1913         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
1914         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75])))
1915         self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,5,6,4,3,2,7,8,4,4,3,8,9,4,6,5,10,11,4,9,8,13,14,4,19,18,23,24,4,2,1,6,7,4,7,6,11,12,4,11,10,15,16,4,12,11,16,17,4,8,7,12,13,4,13,12,17,18,4,17,16,21,22,4,14,13,18,19,4,16,15,20,21,4,18,17,22,23]))) # <- here the mesh is renumbered : the mesh is equal to m[[0,2,3,4,7,15, 1,5,8,9, 6,10,13, 11,12,14]]
1916         self.assertTrue(a4 is None)
1917         self.assertTrue(a5 is None)
1918         for i in xrange(1,5):
1919             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
1920             pass
1921         for i in xrange(5):
1922             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
1923             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
1924             f.loadArraysIfNecessary()
1925             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
1926             self.assertEqual(f.getName(),fieldName0)
1927             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
1928             vExp=DataArrayDouble([0.,1.,2.,3.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.,25.,44.,45.,46.,47.,126.,127.,128.,129.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,26.,27.,28.,29.,30.,31.,32.,33.,34.,35.,48.,49.,50.,51.,52.,53.,54.,55.,56.,57.,58.,59.,60.,61.,62.,63.,64.,65.,66.,67.,36.,37.,38.,39.,40.,41.,42.,43.,68.,69.,70.,71.,72.,73.,74.,75.,104.,105.,106.,107.,108.,109.,110.,111.,76.,77.,78.,79.,80.,81.,82.,83.,84.,85.,86.,87.,88.,89.,90.,91.,92.,93.,94.,95.,96.,97.,98.,99.,100.,101.,102.,103.,112.,113.,114.,115.,116.,117.,118.,119.,120.,121.,122.,123.,124.,125.],65,2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
1929             vExp+=i*1000
1930             self.assertTrue(v.isEqual(vExp,1e-12))
1931             pass
1932         pass
1933
1934     def test12(self):
1935         """ This test is the second ultimate test for the profiles with gauss points.
1936         This test is close to test11 but here a 2nd field on cells without profile. So here the mesh is expected to be the same than m.
1937         """
1938         fname="ForMEDReader12.med"
1939         m=MEDCouplingCMesh("mesh")
1940         arr=DataArrayDouble(5) ; arr.iota()
1941         m.setCoords(arr,arr)
1942         m=m.buildUnstructured() ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
1943         mm=MEDFileUMesh() ; mm.setMeshes([m])
1944         #
1945         fieldName0="zeField0"
1946         fieldName1="zeField1"
1947         fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
1948         for i in xrange(5):
1949             f=MEDFileField1TS()
1950             fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
1951             fNode.setName(fieldName0) ; fNode.setMesh(m)
1952             fNode.setGaussLocalizationOnCells([0,2,3,4,7,15],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7],[0.8,0.2])
1953             fNode.setGaussLocalizationOnCells([1,5,8,9],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3],[0.8,0.05,0.1,0.04,0.01])
1954             fNode.setGaussLocalizationOnCells([6,10,13],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2],[0.8,0.05,0.1,0.04])
1955             fNode.setGaussLocalizationOnCells([11,12,14],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.8,0.8],[0.8,0.05,0.1,0.01,0.02,0.005,0.005])
1956             arr=DataArrayDouble(2*(2*6+5*4+4*3+7*3)) ; arr.iota(0+1000*i) ; arr.rearrange(2)
1957             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
1958             f.setFieldNoProfileSBT(fNode)
1959             fs0.pushBackTimeStep(f)
1960             #
1961             f=MEDFileField1TS()
1962             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
1963             fNode.setName(fieldName1) ; fNode.setMesh(m)
1964             arr=DataArrayDouble(2*16) ; arr.iota(300+1000*i) ; arr.rearrange(2)
1965             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) ; fNode.checkCoherency()
1966             f.setFieldNoProfileSBT(fNode)
1967             fs1.pushBackTimeStep(f)
1968             pass
1969         mm.write(fname,2)
1970         fs0.write(fname,0) ; fs1.write(fname,0)
1971         a0Exp=mm.getCoords().deepCpy()
1972         del m,mm,fs0,fs1,f,fNode
1973         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
1974         ms=MEDFileMeshes(fname)
1975         fields=MEDFileFields(fname,False)
1976         fields.removeFieldsWithoutAnyTimeStep()
1977         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
1978         allFMTSLeavesToDisplay=[]
1979         for fields in fields_per_mesh:
1980             allFMTSLeavesToDisplay2=[]
1981             for fmts in fields:
1982                 tmp=fmts.splitDiscretizations()
1983                 #for itmp in tmp:
1984                 #    self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1985                 #    pass
1986                 allFMTSLeavesToDisplay2+=tmp
1987                 pass
1988             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
1989             pass
1990         self.assertEqual(len(allFMTSLeavesToDisplay),1)
1991         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
1992         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
1993         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
1994         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
1995         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
1996         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
1997         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
1998         #
1999         mst=MEDFileMeshStruct.New(ms[0])
2000         #
2001         fcscp=allFMTSLeavesPerCommonSupport[0][1]
2002         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2003         mml2=mml.prepare()
2004         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2005         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2006         self.assertTrue(not ncc)
2007         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
2008         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
2009         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75])))
2010         self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,5,6,4,2,1,6,7,4,3,2,7,8,4,4,3,8,9,4,6,5,10,11,4,7,6,11,12,4,8,7,12,13,4,9,8,13,14,4,11,10,15,16,4,12,11,16,17,4,13,12,17,18,4,14,13,18,19,4,16,15,20,21,4,17,16,21,22,4,18,17,22,23,4,19,18,23,24]))) # <- here the mesh is NOT renumbered : the mesh is equal to m
2011         self.assertTrue(a4 is None)
2012         self.assertTrue(a5 is None)
2013         for i in xrange(1,5):
2014             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
2015             pass
2016         for i in xrange(5):
2017             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
2018             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2019             f.loadArraysIfNecessary()
2020             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2021             self.assertEqual(f.getName(),fieldName0)
2022             #self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) # not a bug : huge reordering performed !
2023             vExp=DataArrayDouble(65*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
2024             self.assertTrue(v.isEqual(vExp,1e-12))
2025             #
2026             f=allFMTSLeavesPerCommonSupport[0][0][1][i]
2027             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2028             f.loadArraysIfNecessary()
2029             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2030             self.assertEqual(f.getName(),fieldName1)
2031             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer()) # not a bug : huge reordering performed !
2032             vExp=DataArrayDouble(16*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
2033             self.assertTrue(v.isEqual(vExp,1e-12))
2034             pass
2035
2036     def test13(self):
2037             """ Testing polyhedrons mixed with hexa8"""
2038             fname="ForMEDReader13.med"
2039             m=MEDCouplingUMesh("mesh",3)
2040             m.allocateCells()
2041             m.insertNextCell(NORM_HEXA8,[1,0,6,7,13,12,18,19]) ; m.insertNextCell(NORM_HEXA8,[2,1,7,8,14,13,19,20])
2042             m.insertNextCell(NORM_POLYHED,[3,2,8,9,-1,15,21,20,14,-1,3,15,14,2,-1,2,14,20,8,-1,8,20,21,9,-1,9,21,15,3])
2043             m.insertNextCell(NORM_POLYHED,[4,3,9,10,-1,16,22,21,15,-1,4,16,15,3,-1,3,15,21,9,-1,9,21,22,10,-1,10,22,16,4])
2044             m.insertNextCell(NORM_POLYHED,[5,4,10,11,-1,17,23,22,16,-1,5,17,16,4,-1,4,16,22,10,-1,10,22,23,11,-1,11,23,17,5])
2045             coords=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.,0.,1.,1.,0.,1.,2.,0.,1.,3.,0.,1.,4.,0.,1.,5.,0.,1.,0.,1.,1.,1.,1.,1.,2.,1.,1.,3.,1.,1.,4.,1.,1.,5.,1.,1.],24,3) ; coords.setInfoOnComponents(["XX [m]","YYY [km]","ZZZZ [Mm]"])
2046             m.setCoords(coords)
2047             mm=MEDFileUMesh() ; mm.setMeshes([m])
2048             fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
2049             fieldName0="zeField0"
2050             fieldName1="zeField1"
2051             fieldName2="zeField2" ; pfl1=DataArrayInt([2,3]) ; pfl1.setName("pfl1")
2052             fieldName3="zefield3" ; pfl2=DataArrayInt([2,3,4]) ; pfl2.setName("pfl2")
2053             for i in xrange(5):
2054                 f=MEDFileField1TS()
2055                 fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
2056                 fNode.setName(fieldName0) ; fNode.setMesh(m)
2057                 arr=DataArrayDouble(2*5) ; arr.iota(0+1000*i) ; arr.rearrange(2)
2058                 fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
2059                 f.setFieldNoProfileSBT(fNode)
2060                 fs0.pushBackTimeStep(f)
2061                 #
2062                 f=MEDFileField1TS()
2063                 fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
2064                 fNode.setName(fieldName1) ; fNode.setMesh(m)
2065                 arr=DataArrayDouble(2*5) ; arr.iota(100+1000*i) ; arr.rearrange(2)
2066                 fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) ; fNode.checkCoherency()
2067                 f.setFieldNoProfileSBT(fNode)
2068                 fs1.pushBackTimeStep(f)
2069                 #
2070                 f=MEDFileField1TS()
2071                 fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
2072                 fNode.setName(fieldName2) ; fNode.setMesh(m[pfl1])
2073                 arr=DataArrayDouble(2*2) ; arr.iota(200+1000*i) ; arr.rearrange(2)
2074                 fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_2 [m]","Com2_2 [s^2]"]) ; fNode.checkCoherency()
2075                 f.setFieldProfile(fNode,mm,0,pfl1)
2076                 fs2.pushBackTimeStep(f)
2077                 #
2078                 f=MEDFileField1TS()
2079                 fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
2080                 fNode.setName(fieldName3) ; fNode.setMesh(m[pfl2])
2081                 arr=DataArrayDouble(2*3) ; arr.iota(300+1000*i) ; arr.rearrange(2)
2082                 fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_3 [m]","Com2_3 [s^2]"]) ; fNode.checkCoherency()
2083                 f.setFieldProfile(fNode,mm,0,pfl2)
2084                 fs3.pushBackTimeStep(f)
2085                 pass
2086             mm.write(fname,2)
2087             fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0)
2088             a0Exp=mm.getCoords().deepCpy()
2089             del m,mm,fs0
2090             ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
2091             ms=MEDFileMeshes(fname)
2092             fields=MEDFileFields(fname,False)
2093             fields.removeFieldsWithoutAnyTimeStep()
2094             fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
2095             allFMTSLeavesToDisplay=[]
2096             for fields in fields_per_mesh:
2097                 allFMTSLeavesToDisplay2=[]
2098                 for fmts in fields:
2099                     tmp=fmts.splitDiscretizations()
2100                     for itmp in tmp:
2101                         self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2102                         pass
2103                     allFMTSLeavesToDisplay2+=tmp
2104                     pass
2105                 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
2106                 pass
2107             self.assertEqual(len(allFMTSLeavesToDisplay),1)
2108             self.assertEqual(len(allFMTSLeavesToDisplay[0]),4)
2109             allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
2110             self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
2111             self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
2112             allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
2113             self.assertEqual(len(allFMTSLeavesPerCommonSupport),3)
2114             self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
2115             self.assertEqual(len(allFMTSLeavesPerCommonSupport[1][0]),1)
2116             self.assertEqual(len(allFMTSLeavesPerCommonSupport[2][0]),1)
2117             #
2118             mst=MEDFileMeshStruct.New(ms[0])
2119             #
2120             fcscp=allFMTSLeavesPerCommonSupport[0][1]
2121             mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2122             mml2=mml.prepare()
2123             self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2124             ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2125             self.assertTrue(ncc)
2126             self.assertTrue(a0.isEqual(a0Exp,1e-12))
2127             self.assertTrue(a1.isEqual(DataArrayByte([12,12,42,42,42])))
2128             self.assertTrue(a2.isEqual(DataArrayInt([0,9,18,27,36])))
2129             self.assertTrue(a3.isEqual(DataArrayInt([8,1,0,6,7,13,12,18,19,8,2,1,7,8,14,13,19,20,8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22,8,4,5,10,11,16,17,22,23])))
2130             self.assertTrue(a4.isEqual(DataArrayInt([-1,-1,0,31,62])))
2131             self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
2132             for i in xrange(1,5):
2133                 self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
2134                 pass
2135             pass
2136             for i in xrange(5):
2137                 f=allFMTSLeavesPerCommonSupport[0][0][0][i]
2138                 fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2139                 f.loadArraysIfNecessary()
2140                 v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2141                 self.assertEqual(f.getName(),fieldName0)
2142                 self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2143                 vExp=DataArrayDouble(5*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
2144                 self.assertTrue(v.isEqual(vExp,1e-12))
2145                 #
2146                 f=allFMTSLeavesPerCommonSupport[0][0][1][i]
2147                 fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2148                 f.loadArraysIfNecessary()
2149                 v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2150                 self.assertEqual(f.getName(),fieldName1)
2151                 self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2152                 vExp=DataArrayDouble(5*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
2153                 self.assertTrue(v.isEqual(vExp,1e-12))
2154                 pass
2155             #
2156             fcscp=allFMTSLeavesPerCommonSupport[1][1]
2157             mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2158             mml2=mml.prepare()
2159             self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2160             ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2161             self.assertTrue(ncc)
2162             self.assertTrue(a0.isEqual(a0Exp,1e-12))
2163             self.assertTrue(a1.isEqual(DataArrayByte([42,42])))
2164             self.assertTrue(a2.isEqual(DataArrayInt([0,9])))
2165             self.assertTrue(a3.isEqual(DataArrayInt([8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22])))
2166             self.assertTrue(a4.isEqual(DataArrayInt([0,31])))
2167             self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4])))
2168             for i in xrange(1,5):
2169                 self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
2170                 pass
2171             pass
2172             for i in xrange(5):
2173                 f=allFMTSLeavesPerCommonSupport[1][0][0][i]
2174                 fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2175                 f.loadArraysIfNecessary()
2176                 v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2177                 self.assertEqual(f.getName(),fieldName2)
2178                 self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2179                 vExp=DataArrayDouble(2*2) ; vExp.iota(200+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_2 [m]','Com2_2 [s^2]'])
2180                 self.assertTrue(v.isEqual(vExp,1e-12))
2181                 pass
2182             #
2183             fcscp=allFMTSLeavesPerCommonSupport[2][1]
2184             mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2185             mml2=mml.prepare()
2186             self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2187             ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2188             self.assertTrue(ncc)
2189             self.assertTrue(a0.isEqual(a0Exp,1e-12))
2190             self.assertTrue(a1.isEqual(DataArrayByte([42,42,42])))
2191             self.assertTrue(a2.isEqual(DataArrayInt([0,9,18])))
2192             self.assertTrue(a3.isEqual(DataArrayInt([8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22,8,4,5,10,11,16,17,22,23])))
2193             self.assertTrue(a4.isEqual(DataArrayInt([0,31,62])))
2194             self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
2195             for i in xrange(1,5):
2196                 self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
2197                 pass
2198             pass
2199             for i in xrange(5):
2200                 f=allFMTSLeavesPerCommonSupport[2][0][0][i]
2201                 fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2202                 f.loadArraysIfNecessary()
2203                 v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2204                 self.assertEqual(f.getName(),fieldName3)
2205                 self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2206                 vExp=DataArrayDouble(3*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_3 [m]','Com2_3 [s^2]'])
2207                 self.assertTrue(v.isEqual(vExp,1e-12))
2208                 pass
2209             pass
2210
2211     def test14(self):
2212             """ Testing only polyhedrons"""
2213             fname="ForMEDReader14.med"
2214             m=MEDCouplingUMesh("mesh",3)
2215             m.allocateCells()
2216             m.insertNextCell(NORM_POLYHED,[3,2,8,9,-1,15,21,20,14,-1,3,15,14,2,-1,2,14,20,8,-1,8,20,21,9,-1,9,21,15,3])
2217             m.insertNextCell(NORM_POLYHED,[4,3,9,10,-1,16,22,21,15,-1,4,16,15,3,-1,3,15,21,9,-1,9,21,22,10,-1,10,22,16,4])
2218             m.insertNextCell(NORM_POLYHED,[5,4,10,11,-1,17,23,22,16,-1,5,17,16,4,-1,4,16,22,10,-1,10,22,23,11,-1,11,23,17,5])
2219             coords=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.,0.,1.,1.,0.,1.,2.,0.,1.,3.,0.,1.,4.,0.,1.,5.,0.,1.,0.,1.,1.,1.,1.,1.,2.,1.,1.,3.,1.,1.,4.,1.,1.,5.,1.,1.],24,3) ; coords.setInfoOnComponents(["XX [m]","YYY [km]","ZZZZ [Mm]"])
2220             m.setCoords(coords)
2221             mm=MEDFileUMesh() ; mm.setMeshes([m])
2222             fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
2223             fieldName0="zeField0"
2224             fieldName1="zeField1"
2225             for i in xrange(5):
2226                 f=MEDFileField1TS()
2227                 fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
2228                 fNode.setName(fieldName0) ; fNode.setMesh(m)
2229                 arr=DataArrayDouble(2*3) ; arr.iota(0+1000*i) ; arr.rearrange(2)
2230                 fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
2231                 f.setFieldNoProfileSBT(fNode)
2232                 fs0.pushBackTimeStep(f)
2233                 #
2234                 f=MEDFileField1TS()
2235                 fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
2236                 fNode.setName(fieldName1) ; fNode.setMesh(m)
2237                 arr=DataArrayDouble(2*3) ; arr.iota(100+1000*i) ; arr.rearrange(2)
2238                 fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) ; fNode.checkCoherency()
2239                 f.setFieldNoProfileSBT(fNode)
2240                 fs1.pushBackTimeStep(f)
2241                 pass
2242             mm.write(fname,2)
2243             fs0.write(fname,0) ; fs1.write(fname,0)
2244             a0Exp=mm.getCoords().deepCpy()
2245             del m,mm,fs0
2246             ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
2247             ms=MEDFileMeshes(fname)
2248             fields=MEDFileFields(fname,False)
2249             fields.removeFieldsWithoutAnyTimeStep()
2250             fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
2251             allFMTSLeavesToDisplay=[]
2252             for fields in fields_per_mesh:
2253                 allFMTSLeavesToDisplay2=[]
2254                 for fmts in fields:
2255                     tmp=fmts.splitDiscretizations()
2256                     for itmp in tmp:
2257                         self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2258                         pass
2259                     allFMTSLeavesToDisplay2+=tmp
2260                     pass
2261                 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
2262                 pass
2263             self.assertEqual(len(allFMTSLeavesToDisplay),1)
2264             self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
2265             allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
2266             self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
2267             self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
2268             allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
2269             self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
2270             self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
2271             #
2272             mst=MEDFileMeshStruct.New(ms[0])
2273             #
2274             fcscp=allFMTSLeavesPerCommonSupport[0][1]
2275             mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2276             mml2=mml.prepare()
2277             self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2278             ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2279             self.assertTrue(ncc)
2280             self.assertTrue(a0.isEqual(a0Exp,1e-12))
2281             self.assertTrue(a1.isEqual(DataArrayByte([42,42,42])))
2282             self.assertTrue(a2.isEqual(DataArrayInt([0,9,18])))
2283             self.assertTrue(a3.isEqual(DataArrayInt([8,2,3,8,9,14,15,20,21,8,3,4,9,10,15,16,21,22,8,4,5,10,11,16,17,22,23])))
2284             self.assertTrue(a4.isEqual(DataArrayInt([0,31,62])))
2285             self.assertTrue(a5.isEqual(DataArrayInt([6,4,3,2,8,9,4,15,21,20,14,4,3,15,14,2,4,2,14,20,8,4,8,20,21,9,4,9,21,15,3,6,4,4,3,9,10,4,16,22,21,15,4,4,16,15,3,4,3,15,21,9,4,9,21,22,10,4,10,22,16,4,6,4,5,4,10,11,4,17,23,22,16,4,5,17,16,4,4,4,16,22,10,4,10,22,23,11,4,11,23,17,5])))
2286             for i in xrange(1,5):
2287                 self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
2288                 pass
2289             a6,a7=mml2.retrieveFamilyIdsOnCells()
2290             self.assertTrue(a6.isEqual(DataArrayInt([0,0,0])))
2291             self.assertTrue(a7)
2292             a8,a9=mml2.retrieveNumberIdsOnCells()
2293             self.assertTrue(a8 is None)
2294             self.assertTrue(a9)
2295             for i in xrange(5):
2296                 f=allFMTSLeavesPerCommonSupport[0][0][0][i]
2297                 fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2298                 f.loadArraysIfNecessary()
2299                 v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2300                 self.assertEqual(f.getName(),fieldName0)
2301                 self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2302                 vExp=DataArrayDouble(3*2) ; vExp.iota(0+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
2303                 self.assertTrue(v.isEqual(vExp,1e-12))
2304                 #
2305                 f=allFMTSLeavesPerCommonSupport[0][0][1][i]
2306                 fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2307                 f.loadArraysIfNecessary()
2308                 v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2309                 self.assertEqual(f.getName(),fieldName1)
2310                 self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2311                 vExp=DataArrayDouble(3*2) ; vExp.iota(100+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
2312                 self.assertTrue(v.isEqual(vExp,1e-12))
2313                 pass
2314             pass
2315
2316     def test15(self):
2317         """
2318         "ForMEDReader15.med" file has a spaceDim 3 mesh "mesh" (it is important !)
2319         and a field "zeField" lying on a single geometric type for Cell discr and node part.
2320         Test that can appear the most simple but it hides a big issue of MEDReader
2321         that copies are reduced at most. So it can leads to SIGSEGV if the memory management is not OK for int* and double * similar between VTK and MEDCoupling.
2322         """
2323         fname="ForMEDReader15.med"
2324         m0=MEDCouplingCMesh()
2325         arr=DataArrayDouble(3) ; arr.iota(0)
2326         m0.setCoords(arr,arr,arr)
2327         m0.setName("mesh")
2328         m0=m0.buildUnstructured()
2329         #
2330         fieldName="zeField"
2331         fCell=MEDCouplingFieldDouble(ON_CELLS)
2332         fCell.setName(fieldName)
2333         fCell.setMesh(m0)
2334         #
2335         fNode=MEDCouplingFieldDouble(ON_NODES)
2336         fNode.setName(fieldName)
2337         fNode.setMesh(m0)
2338         #
2339         mm=MEDFileUMesh()
2340         mm.setMeshAtLevel(0,m0)
2341         fam=DataArrayInt(8) ; fam.iota(0) ; mm.setFamilyFieldArr(0,fam) ; del fam
2342         num=DataArrayInt(8) ; num.iota(100) ; mm.setRenumFieldArr(0,num) ; del num
2343         #
2344         ffs=MEDFileFieldMultiTS()
2345         # TimeStep 0
2346         t=(1.,0,0) ; off=0.
2347         f1ts=MEDFileField1TS()
2348         a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2349         fCell.setArray(a)
2350         fCell.setTime(*t)
2351         fCell.checkCoherency()
2352         a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2353         a=a.negate()
2354         fNode.setArray(a)
2355         fNode.setTime(*t)
2356         fNode.checkCoherency()
2357         f1ts.setFieldNoProfileSBT(fCell)
2358         f1ts.setFieldNoProfileSBT(fNode)
2359         ffs.pushBackTimeStep(f1ts)
2360         # TimeStep 1
2361         t=(2.1,1,0) ; off=100.
2362         f1ts=MEDFileField1TS()
2363         a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2364         fCell.setArray(a)
2365         fCell.setTime(*t)
2366         fCell.checkCoherency()
2367         a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2368         a=a.negate()
2369         fNode.setArray(a)
2370         fNode.setTime(*t)
2371         fNode.checkCoherency()
2372         f1ts.setFieldNoProfileSBT(fCell)
2373         f1ts.setFieldNoProfileSBT(fNode)
2374         ffs.pushBackTimeStep(f1ts)
2375         # TimeStep 2
2376         t=(3.2,2,0) ; off=200.
2377         f1ts=MEDFileField1TS()
2378         a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2379         fCell.setArray(a)
2380         fCell.setTime(*t)
2381         fCell.checkCoherency()
2382         a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2383         a=a.negate()
2384         fNode.setArray(a)
2385         fNode.setTime(*t)
2386         fNode.checkCoherency()
2387         f1ts.setFieldNoProfileSBT(fCell)
2388         f1ts.setFieldNoProfileSBT(fNode)
2389         ffs.pushBackTimeStep(f1ts)
2390         # TimeStep 3
2391         t=(4.3,3,1) ; off=300.
2392         f1ts=MEDFileField1TS()
2393         a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2394         fCell.setArray(a)
2395         fCell.setTime(*t)
2396         fCell.checkCoherency()
2397         a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2398         a=a.negate()
2399         fNode.setArray(a)
2400         fNode.setTime(*t)
2401         fNode.checkCoherency()
2402         f1ts.setFieldNoProfileSBT(fCell)
2403         f1ts.setFieldNoProfileSBT(fNode)
2404         ffs.pushBackTimeStep(f1ts)
2405         #
2406         mm.write(fname,2)
2407         ffs.write(fname,0)
2408         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
2409         ms=MEDFileMeshes(fname)
2410         fields=MEDFileFields(fname,False)
2411         fields.removeFieldsWithoutAnyTimeStep()
2412         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
2413         allFMTSLeavesToDisplay=[]
2414         for fields in fields_per_mesh:
2415             allFMTSLeavesToDisplay2=[]
2416             for fmts in fields:
2417                 tmp=fmts.splitDiscretizations()
2418                 for itmp in tmp:
2419                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2420                     pass
2421                 allFMTSLeavesToDisplay2+=tmp
2422                 pass
2423             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
2424             pass
2425         self.assertEqual(len(allFMTSLeavesToDisplay),1)
2426         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
2427         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
2428         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
2429         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
2430         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
2431         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
2432         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),2)
2433         #
2434         mst=MEDFileMeshStruct.New(ms[0])
2435         #
2436         fcscp=allFMTSLeavesPerCommonSupport[0][1]
2437         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2438         mml2=mml.prepare()
2439         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2440         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2441         self.assertTrue(ncc)
2442         self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,2.,2.,0.,0.,0.,1.,1.,0.,1.,2.,0.,1.,0.,1.,1.,1.,1.,1.,2.,1.,1.,0.,2.,1.,1.,2.,1.,2.,2.,1.,0.,0.,2.,1.,0.,2.,2.,0.,2.,0.,1.,2.,1.,1.,2.,2.,1.,2.,0.,2.,2.,1.,2.,2.,2.,2.,2.0],27,3),1e-12))
2443         self.assertTrue(a1.isEqual(DataArrayByte([12,12,12,12,12,12,12,12])))
2444         self.assertTrue(a2.isEqual(DataArrayInt([0,9,18,27,36,45,54,63])))
2445         self.assertTrue(a3.isEqual(DataArrayInt([8,1,0,3,4,10,9,12,13,8,2,1,4,5,11,10,13,14,8,4,3,6,7,13,12,15,16,8,5,4,7,8,14,13,16,17,8,10,9,12,13,19,18,21,22,8,11,10,13,14,20,19,22,23,8,13,12,15,16,22,21,24,25,8,14,13,16,17,23,22,25,26])))
2446         self.assertTrue(a4 is None)
2447         self.assertTrue(a5 is None)
2448         a6,a7=mml2.retrieveFamilyIdsOnCells()
2449         self.assertTrue(a6.isEqual(DataArrayInt([0,1,2,3,4,5,6,7])))
2450         self.assertTrue(a7) # no copy here
2451         a8,a9=mml2.retrieveNumberIdsOnCells()
2452         self.assertTrue(a8.isEqual(DataArrayInt([100,101,102,103,104,105,106,107])))
2453         self.assertTrue(a9) # no copy here
2454         pass
2455
2456     def test16(self):
2457         """ Here 2 meshes "mesh1" and "mesh2" and 4 fields (no profiles here) :
2458         - "zeField1_0" (CELLS) and "zeField2_0" (NODES) on "mesh1"
2459         - "zeField3_1" (CELLS) and "zeField4_1" (NODES) on "mesh2"
2460         time steps series are the same for the whole 4 fields
2461         """
2462         fname="ForMEDReader16.med"
2463         m0=MEDCouplingCMesh()
2464         arr=DataArrayDouble(3) ; arr.iota(0)
2465         m0.setCoords(arr,arr,arr)
2466         m0.setName("mesh1")
2467         m0=m0.buildUnstructured()
2468         #
2469         fCell1=MEDCouplingFieldDouble(ON_CELLS)
2470         fCell1.setName("zeField1_0")
2471         fCell1.setMesh(m0)
2472         #
2473         fNode1=MEDCouplingFieldDouble(ON_NODES)
2474         fNode1.setName("zeField2_0")
2475         fNode1.setMesh(m0)
2476         #
2477         mms=MEDFileMeshes()
2478         mm1=MEDFileUMesh()
2479         mm1.setMeshAtLevel(0,m0)
2480         fam=DataArrayInt([0,1,0,1,2,3,2,3]); mm1.setFamilyFieldArr(0,fam) ; del fam
2481         num=DataArrayInt(8) ; num.iota(100) ; mm1.setRenumFieldArr(0,num) ; del num
2482         mm1.setFamilyId("FAMILLE_ZERO",0) ; mm1.setFamilyId("Family1_1",1) ; mm1.setFamilyId("Family1_2",2) ; mm1.setFamilyId("Family1_3",3) ; mm1.setFamilyId("Family1_4",4)
2483         mm1.setFamiliesIdsOnGroup("Grp1_1",[0,1]) ; mm1.setFamiliesIdsOnGroup("Grp1_2",[2,3])
2484         mms.pushMesh(mm1) ; del mm1
2485         #
2486         m1=m0.deepCpy() ; m1.translate([2.5,0.,0.]) ; m1.setName("mesh2")
2487         #
2488         fCell2=MEDCouplingFieldDouble(ON_CELLS)
2489         fCell2.setName("zeField3_1")
2490         fCell2.setMesh(m1)
2491         #
2492         fNode2=MEDCouplingFieldDouble(ON_NODES)
2493         fNode2.setName("zeField4_1")
2494         fNode2.setMesh(m1)
2495         #
2496         mm2=MEDFileUMesh()
2497         mm2.setMeshAtLevel(0,m1)
2498         fam=DataArrayInt([0,1,0,1,2,3,2,3]); mm2.setFamilyFieldArr(0,fam) ; del fam
2499         num=DataArrayInt(8) ; num.iota(200) ; mm2.setRenumFieldArr(0,num) ; del num
2500         mm2.setFamilyId("FAMILLE_ZERO",0) ; mm2.setFamilyId("Family2_1",1) ; mm2.setFamilyId("Family2_2",2) ; mm2.setFamilyId("Family2_3",3) ; mm2.setFamilyId("Family2_4",4)
2501         mm2.setFamiliesIdsOnGroup("Grp2_1",[0,1]) ; mm2.setFamiliesIdsOnGroup("Grp2_2",[2,3]) ; mm2.setFamiliesIdsOnGroup("Grp2_3",[1,2,3])
2502         mms.pushMesh(mm2) ; del mm2
2503         ffs1_1=MEDFileFieldMultiTS()
2504         ffs1_2=MEDFileFieldMultiTS()
2505         ffs2_1=MEDFileFieldMultiTS()
2506         ffs2_2=MEDFileFieldMultiTS()
2507         mts=MEDFileFields()
2508         for elt in ffs1_1,ffs1_2,ffs2_1,ffs2_2:
2509             mts.pushField(elt)
2510             pass
2511         # TimeStep 0
2512         t=(1.,0,0) ; off=0.
2513         f1ts1=MEDFileField1TS()
2514         f1ts2=MEDFileField1TS()
2515         a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2516         fCell1.setArray(a)
2517         fCell1.setTime(*t)
2518         fCell1.checkCoherency()
2519         a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2520         a=a.negate()
2521         fNode1.setArray(a)
2522         fNode1.setTime(*t)
2523         fNode1.checkCoherency()
2524         f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
2525         f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
2526         #
2527         f1ts1=MEDFileField1TS()
2528         f1ts2=MEDFileField1TS()
2529         a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
2530         fCell2.setArray(a)
2531         fCell2.setTime(*t)
2532         fCell2.checkCoherency()
2533         a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
2534         a=a.negate()
2535         fNode2.setArray(a)
2536         fNode2.setTime(*t)
2537         fNode2.checkCoherency()
2538         f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
2539         f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
2540         # TimeStep 1
2541         t=(2.1,1,0) ; off=100.
2542         f1ts1=MEDFileField1TS()
2543         f1ts2=MEDFileField1TS()
2544         a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2545         fCell1.setArray(a)
2546         fCell1.setTime(*t)
2547         fCell1.checkCoherency()
2548         a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2549         a=a.negate()
2550         fNode1.setArray(a)
2551         fNode1.setTime(*t)
2552         fNode1.checkCoherency()
2553         f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
2554         f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
2555         #
2556         f1ts1=MEDFileField1TS()
2557         f1ts2=MEDFileField1TS()
2558         a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
2559         fCell2.setArray(a)
2560         fCell2.setTime(*t)
2561         fCell2.checkCoherency()
2562         a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
2563         a=a.negate()
2564         fNode2.setArray(a)
2565         fNode2.setTime(*t)
2566         fNode2.checkCoherency()
2567         f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
2568         f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
2569         # TimeStep 2
2570         t=(3.1,2,0) ; off=200.
2571         f1ts1=MEDFileField1TS()
2572         f1ts2=MEDFileField1TS()
2573         a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2574         fCell1.setArray(a)
2575         fCell1.setTime(*t)
2576         fCell1.checkCoherency()
2577         a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2578         a=a.negate()
2579         fNode1.setArray(a)
2580         fNode1.setTime(*t)
2581         fNode1.checkCoherency()
2582         f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
2583         f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
2584         #
2585         f1ts1=MEDFileField1TS()
2586         f1ts2=MEDFileField1TS()
2587         a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
2588         fCell2.setArray(a)
2589         fCell2.setTime(*t)
2590         fCell2.checkCoherency()
2591         a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
2592         a=a.negate()
2593         fNode2.setArray(a)
2594         fNode2.setTime(*t)
2595         fNode2.checkCoherency()
2596         f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
2597         f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
2598         #
2599         mms.write(fname,2) ; mts.write(fname,0)
2600         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
2601         ms=MEDFileMeshes(fname)
2602         fields=MEDFileFields(fname,False)
2603         fields.removeFieldsWithoutAnyTimeStep()
2604         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
2605         allFMTSLeavesToDisplay=[]
2606         for fields in fields_per_mesh:
2607             allFMTSLeavesToDisplay2=[]
2608             for fmts in fields:
2609                 tmp=fmts.splitDiscretizations()
2610                 for itmp in tmp:
2611                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2612                     pass
2613                 allFMTSLeavesToDisplay2+=tmp
2614                 pass
2615             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
2616             pass
2617         self.assertEqual(len(allFMTSLeavesToDisplay),2)
2618         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
2619         self.assertEqual(len(allFMTSLeavesToDisplay[1]),2)
2620         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
2621         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
2622         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
2623         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
2624         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
2625         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),2)
2626         allFMTSLeavesPerCommonSupport2=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
2627         self.assertEqual(len(allFMTSLeavesPerCommonSupport2),1)
2628         self.assertEqual(len(allFMTSLeavesPerCommonSupport2[0][0]),2)
2629         pass
2630
2631     def test17(self):
2632         """ First test on GAUSS_NE (Elno). Here no Profiles.
2633         2 times steps.
2634         """
2635         fname="ForMEDReader17.med"
2636         fieldName1="MyFirstElno"
2637         fieldName2="ACellField"
2638         fieldName3="ANodeField"
2639         coo=DataArrayDouble([0.,0.,1.,0.,2.,0.,0.,1.,1.,1.,2.,1.],6,2)
2640         m=MEDCouplingUMesh("mesh",2)
2641         m.setCoords(coo)
2642         m.allocateCells()
2643         m.insertNextCell(NORM_QUAD4,[0,3,4,1])
2644         m.insertNextCell(NORM_QUAD4,[1,4,5,2])
2645         m.checkCoherency2()
2646         #
2647         t=(1.1,0,-1)
2648         f=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f.setTime(*t) ; f.setMesh(m)
2649         f.setArray(DataArrayDouble([3.,5.,7.,6.,2.,3.,11.,8.]))
2650         f.setName(fieldName1)
2651         f.checkCoherency()
2652         MEDLoader.WriteField(fname,f,True)
2653         f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(*t) ; f2.setMesh(m)
2654         f2.setArray(DataArrayDouble([7.,11.],2,1))
2655         f2.setName(fieldName2)
2656         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
2657         f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setTime(*t) ; f3.setMesh(m)
2658         f3.setArray(DataArrayDouble([1.,2.,4.,1.,2.,4.],6,1))
2659         f3.setName(fieldName3)
2660         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
2661         #
2662         t=(2.1,1,-1)
2663         f=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f.setTime(*t) ; f.setMesh(m)
2664         f.setArray(DataArrayDouble([7.,6.,3.,5.,11.,8.,2.,3.]))
2665         f.setName(fieldName1)
2666         f.checkCoherency()
2667         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f)
2668         f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(*t) ; f2.setMesh(m)
2669         f2.setArray(DataArrayDouble([11.,7.],2,1))
2670         f2.setName(fieldName2)
2671         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
2672         f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setTime(*t) ; f3.setMesh(m)
2673         f3.setArray(DataArrayDouble([4.,2.,1.,4.,2.,1.],6,1))
2674         f3.setName(fieldName3)
2675         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
2676         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
2677         ms=MEDFileMeshes(fname)
2678         fields=MEDFileFields(fname,False)
2679         fields.removeFieldsWithoutAnyTimeStep()
2680         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
2681         allFMTSLeavesToDisplay=[]
2682         for fields in fields_per_mesh:
2683             allFMTSLeavesToDisplay2=[]
2684             for fmts in fields:
2685                 tmp=fmts.splitDiscretizations()
2686                 for itmp in tmp:
2687                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2688                     pass
2689                 allFMTSLeavesToDisplay2+=tmp
2690                 pass
2691             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
2692             pass
2693         self.assertEqual(len(allFMTSLeavesToDisplay),1)
2694         self.assertEqual(len(allFMTSLeavesToDisplay[0]),3)
2695         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
2696         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
2697         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
2698         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
2699         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
2700         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),3)
2701         #
2702         mst=MEDFileMeshStruct.New(ms[0])
2703         #
2704         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
2705         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2706         mml2=mml.prepare()
2707         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2708         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2709         self.assertTrue(not ncc) # spaceDim 2 -> VTK wants 3D
2710         self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.],6,3),1e-12))
2711         self.assertTrue(a1.isEqual(DataArrayByte([9,9])))
2712         self.assertTrue(a2.isEqual(DataArrayInt([0,5])))
2713         self.assertTrue(a3.isEqual(DataArrayInt([4,0,3,4,1,4,1,4,5,2])))
2714         self.assertTrue(a4 is None)
2715         self.assertTrue(a5 is None)
2716         a6,a7=mml2.retrieveFamilyIdsOnCells()
2717         self.assertTrue(a6.isEqual(DataArrayInt([0,0])))
2718         self.assertTrue(a7) # no copy here
2719         a8,a9=mml2.retrieveNumberIdsOnCells()
2720         self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
2721         self.assertTrue(a9) # no copy here
2722         for i in xrange(1,2):
2723             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
2724             pass
2725         vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
2726         vExp1=[DataArrayDouble([3.,5.,7.,6.,2.,3.,11.,8.]),DataArrayDouble([7.,6.,3.,5.,11.,8.,2.,3.])]
2727         for i in xrange(2):
2728             f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
2729             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2730             f.loadArraysIfNecessary()
2731             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2732             self.assertEqual(f.getName(),fieldName2)
2733             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2734             self.assertTrue(v.isEqual(vExp0[i],1e-12))
2735             #
2736             f=allFMTSLeavesPerCommonSupport1[0][0][1][i]
2737             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2738             f.loadArraysIfNecessary()
2739             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2740             self.assertEqual(f.getName(),fieldName1)
2741             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2742             self.assertTrue(v.isEqual(vExp1[i],1e-12))
2743             pass
2744         pass
2745     
2746     def test18(self):
2747         """ First test on GAUSS_PT. Here no Profiles. 2 times steps.
2748         """
2749         fname="ForMEDReader18.med"
2750         fieldName1="MyFirstGauss"
2751         fieldName2="ACellField"
2752         fieldName3="ANodeField"
2753         coo=DataArrayDouble([0.,0.,1.,0.,2.,0.,0.,1.,1.,1.,2.,1.],6,2)
2754         m=MEDCouplingUMesh("mesh",2)
2755         m.setCoords(coo)
2756         m.allocateCells()
2757         m.insertNextCell(NORM_QUAD4,[0,3,4,1])
2758         m.insertNextCell(NORM_QUAD4,[1,4,5,2])
2759         m.checkCoherency2()
2760         #
2761         t=(1.1,0,-1)
2762         f=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f.setTime(*t) ; f.setMesh(m)
2763         f.setGaussLocalizationOnType(NORM_QUAD4,[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.2,0.2,0.8,0.8],[0.7,0.3])
2764         f.setArray(DataArrayDouble([3.,5.,4.,6.])) ; f.getArray().setInfoOnComponents(["Smth"])
2765         f.setName(fieldName1)
2766         f.checkCoherency()
2767         MEDLoader.WriteField(fname,f,True)
2768         f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(*t) ; f2.setMesh(m)
2769         f2.setArray(DataArrayDouble([7.,11.],2,1))
2770         f2.setName(fieldName2)
2771         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
2772         f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setTime(*t) ; f3.setMesh(m)
2773         f3.setArray(DataArrayDouble([1.,2.,4.,1.,2.,4.],6,1))
2774         f3.setName(fieldName3)
2775         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
2776         #
2777         t=(2.1,1,-1)
2778         f=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f.setTime(*t) ; f.setMesh(m)
2779         f.setGaussLocalizationOnType(NORM_QUAD4,[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.2,0.2,0.8,0.8],[0.7,0.3])
2780         f.setArray(DataArrayDouble([5.,3.,6.,4.])) ; f.getArray().setInfoOnComponents(["Smth"])
2781         f.setName(fieldName1)
2782         f.checkCoherency()
2783         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f)
2784         f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setTime(*t) ; f2.setMesh(m)
2785         f2.setArray(DataArrayDouble([11.,7.],2,1))
2786         f2.setName(fieldName2)
2787         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f2)
2788         f3=MEDCouplingFieldDouble(ON_NODES) ; f3.setTime(*t) ; f3.setMesh(m)
2789         f3.setArray(DataArrayDouble([4.,2.,1.,4.,2.,1.],6,1))
2790         f3.setName(fieldName3)
2791         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f3)
2792         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
2793         ms=MEDFileMeshes(fname)
2794         fields=MEDFileFields(fname,False)
2795         fields.removeFieldsWithoutAnyTimeStep()
2796         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
2797         allFMTSLeavesToDisplay=[]
2798         for fields in fields_per_mesh:
2799             allFMTSLeavesToDisplay2=[]
2800             for fmts in fields:
2801                 tmp=fmts.splitDiscretizations()
2802                 for itmp in tmp:
2803                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2804                     pass
2805                 allFMTSLeavesToDisplay2+=tmp
2806                 pass
2807             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
2808             pass
2809         self.assertEqual(len(allFMTSLeavesToDisplay),1)
2810         self.assertEqual(len(allFMTSLeavesToDisplay[0]),3)
2811         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
2812         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
2813         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
2814         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
2815         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
2816         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),3)
2817         #
2818         mst=MEDFileMeshStruct.New(ms[0])
2819         #
2820         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
2821         self.assertEqual([NORM_QUAD4],fcscp.getGeoTypesAt(0,ms[0]))
2822         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2823         mml2=mml.prepare()
2824         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2825         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2826         self.assertTrue(not ncc) # spaceDim 2 -> VTK wants 3D
2827         self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.],6,3),1e-12))
2828         self.assertTrue(a1.isEqual(DataArrayByte([9,9])))
2829         self.assertTrue(a2.isEqual(DataArrayInt([0,5])))
2830         self.assertTrue(a3.isEqual(DataArrayInt([4,0,3,4,1,4,1,4,5,2])))
2831         self.assertTrue(a4 is None)
2832         self.assertTrue(a5 is None)
2833         a6,a7=mml2.retrieveFamilyIdsOnCells()
2834         self.assertTrue(a6.isEqual(DataArrayInt([0,0])))
2835         self.assertTrue(a7) # no copy here
2836         a8,a9=mml2.retrieveNumberIdsOnCells()
2837         self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
2838         self.assertTrue(a9) # no copy here
2839         for i in xrange(1,2):
2840             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
2841             pass
2842         vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
2843         vExp1=[DataArrayDouble([3.,5.,4.,6.]),DataArrayDouble([5.,3.,6.,4.])]
2844         for i in xrange(2):
2845             f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
2846             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2847             f.loadArraysIfNecessary()
2848             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2849             self.assertEqual(f.getName(),fieldName2)
2850             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2851             self.assertTrue(v.isEqual(vExp0[i],1e-12))
2852             #
2853             f=allFMTSLeavesPerCommonSupport1[0][0][1][i]
2854             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
2855             f.loadArraysIfNecessary()
2856             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2857             self.assertEqual(f.getName(),fieldName1)
2858             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2859             vExp1[i].setInfoOnComponents(["Smth"])
2860             self.assertTrue(v.isEqual(vExp1[i],1e-12))
2861             pass
2862         ## Now same exercise but with a different load strategy. All is load directly.
2863         ms=MEDFileMeshes(fname)
2864         fields=MEDFileFields(fname) # here all is read, the SauvReader (or other Reader) is emulated
2865         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
2866         allFMTSLeavesToDisplay=[]
2867         for fields in fields_per_mesh:
2868             allFMTSLeavesToDisplay2=[]
2869             for fmts in fields:
2870                 tmp=fmts.splitDiscretizations()
2871                 for itmp in tmp:
2872                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2873                     pass
2874                 allFMTSLeavesToDisplay2+=tmp
2875                 pass
2876             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
2877             pass
2878         self.assertEqual(len(allFMTSLeavesToDisplay),1)
2879         self.assertEqual(len(allFMTSLeavesToDisplay[0]),3)
2880         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
2881         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
2882         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
2883         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
2884         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
2885         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),3)
2886         #
2887         mst=MEDFileMeshStruct.New(ms[0])
2888         #
2889         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
2890         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2891         mml2=mml.prepare()
2892         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2893         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2894         self.assertTrue(not ncc) # spaceDim 2 -> VTK wants 3D
2895         self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.],6,3),1e-12))
2896         self.assertTrue(a1.isEqual(DataArrayByte([9,9])))
2897         self.assertTrue(a2.isEqual(DataArrayInt([0,5])))
2898         self.assertTrue(a3.isEqual(DataArrayInt([4,0,3,4,1,4,1,4,5,2])))
2899         self.assertTrue(a4 is None)
2900         self.assertTrue(a5 is None)
2901         a6,a7=mml2.retrieveFamilyIdsOnCells()
2902         self.assertTrue(a6.isEqual(DataArrayInt([0,0])))
2903         self.assertTrue(a7) # no copy here
2904         a8,a9=mml2.retrieveNumberIdsOnCells()
2905         self.assertTrue(a8.isEqual(DataArrayInt([0,1])))
2906         self.assertTrue(a9) # no copy here
2907         for i in xrange(1,2):
2908             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
2909             pass
2910         vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
2911         vExp1=[DataArrayDouble([3.,5.,4.,6.]),DataArrayDouble([5.,3.,6.,4.])]
2912         for i in xrange(2):
2913             f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
2914             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst) # no load needed here
2915             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2916             self.assertEqual(f.getName(),fieldName2)
2917             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2918             self.assertTrue(v.isEqual(vExp0[i],1e-12))
2919             #
2920             f=allFMTSLeavesPerCommonSupport1[0][0][1][i]
2921             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst) # no load needed here
2922             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
2923             self.assertEqual(f.getName(),fieldName1)
2924             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
2925             vExp1[i].setInfoOnComponents(["Smth"])
2926             self.assertTrue(v.isEqual(vExp1[i],1e-12))
2927             pass
2928         pass
2929     
2930     def test19(self):
2931         """
2932         This test is a simple non profile CELL field but lying on cells of dimension -1 (not 0 as "usual").
2933         """
2934         fname="ForMEDReader19.med"
2935         fieldName="ACellFieldOnDimM1"
2936         coo=DataArrayDouble(3) ; coo.iota()
2937         m=MEDCouplingCMesh() ; m.setCoords(coo,coo,coo) ; m.setName("mesh")
2938         m0=m.buildUnstructured() ; del m
2939         m1=m0.computeSkin()
2940         #
2941         mm=MEDFileUMesh()                                
2942         mm.setMeshAtLevel(0,m0)
2943         mm.setMeshAtLevel(-1,m1)
2944         ff=MEDFileFieldMultiTS()
2945         # time 0
2946         t=(1.1,1,-1)
2947         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setTime(*t) ; f.setMesh(m1)
2948         f.setName(fieldName)
2949         arr=DataArrayDouble(24) ; arr.iota() ; arr.setInfoOnComponents(["AStr"])
2950         f.setArray(arr)
2951         f.checkCoherency()
2952         f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f)
2953         ff.pushBackTimeStep(f1ts)
2954         # time 1
2955         t=(2.1,2,-2)
2956         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setTime(*t) ; f.setMesh(m1)
2957         f.setName(fieldName)
2958         arr=DataArrayDouble(24) ; arr.iota() ; arr.reverse() ; arr.setInfoOnComponents(["AStr"])
2959         f.setArray(arr)
2960         f.checkCoherency()
2961         f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f)
2962         ff.pushBackTimeStep(f1ts)
2963         #
2964         mm.write(fname,2)
2965         ff.write(fname,0)
2966         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
2967         ms=MEDFileMeshes(fname)
2968         fields=MEDFileFields(fname,False)
2969         fields.removeFieldsWithoutAnyTimeStep()
2970         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
2971         allFMTSLeavesToDisplay=[]
2972         for fields in fields_per_mesh:
2973             allFMTSLeavesToDisplay2=[]
2974             for fmts in fields:
2975                 tmp=fmts.splitDiscretizations()
2976                 for itmp in tmp:
2977                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2978                     pass
2979                 allFMTSLeavesToDisplay2+=tmp
2980                 pass
2981             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
2982             pass
2983         self.assertEqual(len(allFMTSLeavesToDisplay),1)
2984         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
2985         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
2986         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
2987         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
2988         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
2989         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
2990         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
2991         #
2992         mst=MEDFileMeshStruct.New(ms[0])
2993         #
2994         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
2995         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
2996         mml2=mml.prepare()
2997         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
2998         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
2999         self.assertTrue(ncc)
3000         self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,2.,2.,0.,0.,0.,1.,1.,0.,1.,2.,0.,1.,0.,1.,1.,1.,1.,1.,2.,1.,1.,0.,2.,1.,1.,2.,1.,2.,2.,1.,0.,0.,2.,1.,0.,2.,2.,0.,2.,0.,1.,2.,1.,1.,2.,2.,1.,2.,0.,2.,2.,1.,2.,2.,2.,2.,2.],27,3),1e-12))
3001         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
3002         self.assertTrue(a2.isEqual(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])))
3003         self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,3,4,4,1,10,9,0,4,0,9,12,3,4,2,1,4,5,4,2,11,10,1,4,5,14,11,2,4,4,3,6,7,4,3,12,15,6,4,6,15,16,7,4,5,4,7,8,4,7,16,17,8,4,8,17,14,5,4,19,22,21,18,4,10,19,18,9,4,9,18,21,12,4,20,23,22,19,4,11,20,19,10,4,14,23,20,11,4,22,25,24,21,4,12,21,24,15,4,15,24,25,16,4,23,26,25,22,4,16,25,26,17,4,17,26,23,14])))
3004         self.assertTrue(a4 is None)
3005         self.assertTrue(a5 is None)
3006         a6,a7=mml2.retrieveFamilyIdsOnCells()
3007         self.assertTrue(a6.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])))
3008         self.assertTrue(a7) # no copy here
3009         a8,a9=mml2.retrieveNumberIdsOnCells()
3010         self.assertTrue(a8 is None)
3011         self.assertTrue(a9) # no copy here
3012         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3013         self.assertTrue(not a10)
3014         self.assertTrue(a11) # no copy here
3015         a12,a13=mml2.retrieveNumberIdsOnNodes()
3016         self.assertTrue(not a12)
3017         self.assertTrue(a13) # no copy here
3018         for i in xrange(1,2):
3019             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
3020             pass
3021         for i in xrange(2):
3022             f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
3023             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3024             f.loadArraysIfNecessary()
3025             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3026             self.assertEqual(f.getName(),fieldName)
3027             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
3028             vExp=DataArrayDouble(24) ; vExp.iota()
3029             if i==1: vExp.reverse()
3030             vExp.setInfoOnComponents(["AStr"])
3031             self.assertTrue(v.isEqual(vExp,1e-12))
3032             pass
3033         pass
3034
3035     def test20(self):
3036         """ This test works with groups/families on cells AND on nodes. Here 4 fields each on same time steps (2).
3037         1 field on CELLS without profile, 1 field on CELLS with profile, 1 field on NODES without profile, 1 field on NODES with profile.
3038         All of these 4 fields lies on a single mesh "mesh". The 2 fields on profile lies on a same support.
3039         One drawback of this test : no multi geom type. Coming soon !
3040         """
3041         fname="ForMEDReader20.med"
3042         fieldName0="ANodeField"
3043         fieldName1="ACellField"
3044         fieldName2="ANodeFieldPfl"
3045         fieldName3="ACellFieldPfl"
3046         pfl2=DataArrayInt([5,6,7,10,11,12,15,16,17,20,21,22]) ; pfl2.setName("pfl2")
3047         pfl3=DataArrayInt([4,5,8,9,12,13]) ; pfl3.setName("pfl3")
3048         #
3049         arr=DataArrayDouble(5) ; arr.iota()
3050         m=MEDCouplingCMesh("mesh") ; m.setCoords(arr,arr)
3051         m=m.buildUnstructured()
3052         mm=MEDFileUMesh()
3053         mm.setMeshAtLevel(0,m)
3054         fs=MEDFileFields()
3055         fmts0=MEDFileFieldMultiTS() ; fs.pushField(fmts0)
3056         fmts0.setDtUnit("s")
3057         fmts1=MEDFileFieldMultiTS() ; fs.pushField(fmts1)
3058         fmts1.setDtUnit("s")
3059         fmts2=MEDFileFieldMultiTS() ; fs.pushField(fmts2)
3060         fmts2.setDtUnit("s")
3061         fmts3=MEDFileFieldMultiTS() ; fs.pushField(fmts3)
3062         fmts3.setDtUnit("s")
3063         ####
3064         t=(1.1,0,-2)
3065         f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m)
3066         f0.setName(fieldName0) ; f0.setTime(*t)
3067         da=m.getCoords().magnitude() ; da.setInfoOnComponents(["zeInfo"])
3068         f0.setArray(da)
3069         f0.checkCoherency()
3070         f1ts=MEDFileField1TS()
3071         f1ts.setFieldNoProfileSBT(f0)
3072         fmts0.pushBackTimeStep(f1ts)
3073         #
3074         f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setMesh(m)
3075         f1.setName(fieldName1) ; f1.setTime(*t)
3076         da=m.getBarycenterAndOwner().magnitude() ; da.setInfoOnComponents(["zeInfoCell"])
3077         f1.setArray(da)
3078         f1.checkCoherency()
3079         f1ts=MEDFileField1TS()
3080         f1ts.setFieldNoProfileSBT(f1)
3081         fmts1.pushBackTimeStep(f1ts)
3082         #
3083         f2=MEDCouplingFieldDouble(ON_NODES) ; mTmp=m[pfl3] ; mTmp.zipCoords() ; mTmp.setName(m.getName()) ; f2.setMesh(mTmp)
3084         f2.setName(fieldName2) ; f2.setTime(*t)
3085         da=m.getCoords().magnitude()[pfl2] ; da.setInfoOnComponents(["zzzz"])
3086         f2.setArray(da)
3087         f2.checkCoherency()
3088         f1ts=MEDFileField1TS()
3089         f1ts.setFieldProfile(f2,mm,0,pfl2)
3090         fmts2.pushBackTimeStep(f1ts)
3091         #
3092         f3=MEDCouplingFieldDouble(ON_CELLS) ; mTmp=m[pfl3] ; mTmp.setName(m.getName()) ; f3.setMesh(mTmp)
3093         f3.setName(fieldName3) ; f3.setTime(*t)
3094         da=mTmp.getBarycenterAndOwner().magnitude() ; da.setInfoOnComponents(["abcdefg"])
3095         f3.setArray(da)
3096         f3.checkCoherency()
3097         f1ts=MEDFileField1TS()
3098         f1ts.setFieldProfile(f3,mm,0,pfl3)
3099         fmts3.pushBackTimeStep(f1ts)
3100         ####
3101         t=(2.1,1,-3)
3102         f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m)
3103         f0.setName(fieldName0) ; f0.setTime(*t)
3104         da=m.getCoords().magnitude() ; da.reverse() ; da.setInfoOnComponents(["zeInfo"])
3105         f0.setArray(da)
3106         f0.checkCoherency()
3107         f1ts=MEDFileField1TS()
3108         f1ts.setFieldNoProfileSBT(f0)
3109         fmts0.pushBackTimeStep(f1ts)
3110         #
3111         f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setMesh(m)
3112         f1.setName(fieldName1) ; f1.setTime(*t)
3113         da=m.getBarycenterAndOwner().magnitude() ; da.reverse() ; da.setInfoOnComponents(["zeInfoCell"])
3114         f1.setArray(da)
3115         f1.checkCoherency()
3116         f1ts=MEDFileField1TS()
3117         f1ts.setFieldNoProfileSBT(f1)
3118         fmts1.pushBackTimeStep(f1ts)
3119         #
3120         f2=MEDCouplingFieldDouble(ON_NODES) ; mTmp=m[pfl3] ; mTmp.zipCoords() ; mTmp.setName(m.getName()) ; f2.setMesh(mTmp)
3121         f2.setName(fieldName2) ; f2.setTime(*t)
3122         da=m.getCoords().magnitude()[pfl2] ; da.reverse() ; da.setInfoOnComponents(["zzzz"])
3123         f2.setArray(da)
3124         f2.checkCoherency()
3125         f1ts=MEDFileField1TS()
3126         f1ts.setFieldProfile(f2,mm,0,pfl2)
3127         fmts2.pushBackTimeStep(f1ts)
3128         #
3129         f3=MEDCouplingFieldDouble(ON_CELLS) ; mTmp=m[pfl3] ; mTmp.setName(m.getName()) ; f3.setMesh(mTmp)
3130         f3.setName(fieldName3) ; f3.setTime(*t)
3131         da=mTmp.getBarycenterAndOwner().magnitude() ; da.reverse() ; da.setInfoOnComponents(["abcdefg"])
3132         f3.setArray(da)
3133         f3.checkCoherency()
3134         f1ts=MEDFileField1TS()
3135         f1ts.setFieldProfile(f3,mm,0,pfl3)
3136         fmts3.pushBackTimeStep(f1ts)
3137         ####
3138         grp1=DataArrayInt([6,7,8,11,12,13,16,17,18]) ; grp1.setName("grp1")
3139         grp2=DataArrayInt([10,11,15,16,20,21]) ; grp2.setName("grp2")
3140         mm.setGroupsAtLevel(1,[grp1,grp2])
3141         grp3=DataArrayInt([4,5,6]) ; grp3.setName("grp3")
3142         grp4=DataArrayInt([8,9,10]) ; grp4.setName("grp4")
3143         mm.setGroupsAtLevel(0,[grp3,grp4])
3144         d=DataArrayInt(25) ; d.iota() ; d*=10 ;  mm.setRenumFieldArr(1,d)
3145         d=DataArrayInt(16) ; d.iota() ; d*=11 ;  mm.setRenumFieldArr(0,d)
3146         mm.write(fname,2)
3147         fs.appendGlobs(fmts2,1e-12)
3148         fs.appendGlobs(fmts3,1e-12)
3149         fs.write(fname,0)
3150         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
3151         ms=MEDFileMeshes(fname)
3152         fields=MEDFileFields(fname,False)
3153         fields.removeFieldsWithoutAnyTimeStep()
3154         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
3155         allFMTSLeavesToDisplay=[]
3156         for fields in fields_per_mesh:
3157             allFMTSLeavesToDisplay2=[]
3158             for fmts in fields:
3159                 tmp=fmts.splitDiscretizations()
3160                 for itmp in tmp:
3161                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3162                     pass
3163                 allFMTSLeavesToDisplay2+=tmp
3164                 pass
3165             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
3166             pass
3167         self.assertEqual(len(allFMTSLeavesToDisplay),1)
3168         self.assertEqual(len(allFMTSLeavesToDisplay[0]),4)
3169         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
3170         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
3171         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
3172         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
3173         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),2)
3174         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),2)
3175         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),2)
3176         #
3177         mst=MEDFileMeshStruct.New(ms[0])
3178         #
3179         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
3180         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3181         mml2=mml.prepare()
3182         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
3183         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
3184         self.assertTrue(not ncc)
3185         self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,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.,0.,2.,0.,1.,2.,0.,2.,2.,0.,3.,2.,0.,4.,2.,0.,0.,3.,0.,1.,3.,0.,2.,3.,0.,3.,3.,0.,4.,3.,0.,0.,4.,0.,1.,4.,0.,2.,4.,0.,3.,4.,0.,4.,4.,0.],25,3),1e-12))
3186         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
3187         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75])))
3188         self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,5,6,4,2,1,6,7,4,3,2,7,8,4,4,3,8,9,4,6,5,10,11,4,7,6,11,12,4,8,7,12,13,4,9,8,13,14,4,11,10,15,16,4,12,11,16,17,4,13,12,17,18,4,14,13,18,19,4,16,15,20,21,4,17,16,21,22,4,18,17,22,23,4,19,18,23,24])))
3189         self.assertTrue(a4 is None)
3190         self.assertTrue(a5 is None)
3191         a6,a7=mml2.retrieveFamilyIdsOnCells()
3192         self.assertTrue(a6.isEqual(DataArrayInt([-5,-5,-5,-5,-6,-6,-6,-5,-7,-7,-7,-5,-5,-5,-5,-5])))
3193         self.assertTrue(a7) # no copy here
3194         a8,a9=mml2.retrieveNumberIdsOnCells()
3195         self.assertTrue(a8.isEqual(DataArrayInt([0,11,22,33,44,55,66,77,88,99,110,121,132,143,154,165])))
3196         self.assertTrue(a9) # no copy here
3197         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3198         self.assertTrue(a10.isEqual(DataArrayInt([1,1,1,1,1,1,2,2,2,1,3,4,2,2,1,3,4,2,2,1,3,3,1,1,1])))
3199         self.assertTrue(a11) # no copy here
3200         a12,a13=mml2.retrieveNumberIdsOnNodes()
3201         self.assertTrue(a12.isEqual(DataArrayInt([0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170,180,190,200,210,220,230,240])))
3202         self.assertTrue(a13) # no copy here
3203         for i in xrange(1,2):
3204             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
3205             pass
3206         for i in xrange(2):
3207             f=allFMTSLeavesPerCommonSupport1[0][0][0][i]
3208             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3209             f.loadArraysIfNecessary()
3210             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3211             self.assertEqual(f.getName(),fieldName1)
3212             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
3213             vExp=DataArrayDouble([0.7071067811865476,1.5811388300841898,2.5495097567963922,3.5355339059327378,1.5811388300841898,2.1213203435596424,2.9154759474226504,3.8078865529319543,2.5495097567963922,2.9154759474226504,3.5355339059327378,4.301162633521313,3.5355339059327378,3.8078865529319543,4.301162633521313,4.949747468305833])
3214             if i==1: vExp.reverse()
3215             vExp.setInfoOnComponents(["zeInfoCell"])
3216             self.assertTrue(v.isEqual(vExp,1e-12))
3217             #
3218             f=allFMTSLeavesPerCommonSupport1[0][0][1][i]
3219             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3220             f.loadArraysIfNecessary()
3221             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3222             self.assertEqual(f.getName(),fieldName0)
3223             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
3224             vExp=DataArrayDouble([0.,1.,2.,3.,4.,1.,1.4142135623730951,2.23606797749979,3.1622776601683795,4.123105625617661,2.,2.23606797749979,2.8284271247461903,3.605551275463989,4.47213595499958,3.,3.1622776601683795,3.605551275463989,4.242640687119285,5.,4.,4.123105625617661,4.47213595499958,5.,5.656854249492381])
3225             if i==1: vExp.reverse()
3226             vExp.setInfoOnComponents(["zeInfo"])
3227             self.assertTrue(v.isEqual(vExp,1e-12))
3228             pass
3229         ### Testing the 2nd support
3230         fcscp=allFMTSLeavesPerCommonSupport1[1][1]
3231         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3232         mml2=mml.prepare()
3233         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
3234         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
3235         self.assertTrue(not ncc)
3236         self.assertTrue(not ncc)
3237         self.assertTrue(a0.isEqual(DataArrayDouble([0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,2.,2.,0.,0.,3.,0.,1.,3.,0.,2.,3.,0.,0.,4.,0.,1.,4.,0.,2.,4.,0.],12,3),1e-12))
3238         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9])))
3239         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25])))
3240         self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,3,4,4,2,1,4,5,4,4,3,6,7,4,5,4,7,8,4,7,6,9,10,4,8,7,10,11])))
3241         self.assertTrue(a4 is None)
3242         self.assertTrue(a5 is None)
3243         a6,a7=mml2.retrieveFamilyIdsOnCells()
3244         self.assertTrue(a6.isEqual(DataArrayInt([-6,-6,-7,-7,-5,-5])))
3245         self.assertTrue(not a7) # copy here
3246         a8,a9=mml2.retrieveNumberIdsOnCells()
3247         self.assertTrue(a8.isEqual(DataArrayInt([44,55,88,99,132,143])))
3248         self.assertTrue(not a9) # copy here
3249         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3250         self.assertTrue(a10.isEqual(DataArrayInt([1,2,2,3,4,2,3,4,2,3,3,1])))
3251         self.assertTrue(not a11) # copy here
3252         a12,a13=mml2.retrieveNumberIdsOnNodes()
3253         self.assertTrue(a12.isEqual(DataArrayInt([50,60,70,100,110,120,150,160,170,200,210,220])))
3254         self.assertTrue(not a13) # copy here
3255         for i in xrange(2):
3256             f=allFMTSLeavesPerCommonSupport1[1][0][0][i]
3257             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3258             f.loadArraysIfNecessary()
3259             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3260             self.assertEqual(f.getName(),fieldName3)
3261             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
3262             vExp=DataArrayDouble([1.5811388300842,2.1213203435596,2.5495097567964,2.9154759474227,3.5355339059327,3.807886552932])
3263             if i==1: vExp.reverse()
3264             vExp.setInfoOnComponents(["abcdefg"])
3265             self.assertTrue(v.isEqual(vExp,1e-12))
3266             #
3267             f=allFMTSLeavesPerCommonSupport1[1][0][1][i]
3268             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3269             f.loadArraysIfNecessary()
3270             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3271             self.assertEqual(f.getName(),fieldName2)
3272             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
3273             vExp=DataArrayDouble([1.,1.4142135623731,2.2360679774998,2.,2.2360679774998,2.8284271247462,3.,3.1622776601684,3.605551275464,4.,4.1231056256177,4.4721359549996])
3274             if i==1: vExp.reverse()
3275             vExp.setInfoOnComponents(["zzzz"])
3276             self.assertTrue(v.isEqual(vExp,1e-12))
3277             pass
3278         pass
3279
3280     def test21(self):
3281         """ Here the created MED file contains only a mesh. The aim here is to test capability of MEDReader to support no fields.
3282         This test checks nothing but write a MED file to be used by MEDReader tests.
3283         """
3284         fname="ForMEDReader21.med"
3285         mm=MEDFileUMesh()
3286         #
3287         m0=MEDCouplingCMesh("mesh") ; arr=DataArrayDouble(5) ; arr.iota() ; m0.setCoords(arr,arr) ; m0=m0.buildUnstructured()
3288         mm.setMeshAtLevel(0,m0)
3289         grp0=DataArrayInt([5,6,9,10]) ; grp0.setName("Inside2D")
3290         grp1=DataArrayInt([0,1,2,3,4,7,8,11,12,13,14,15]) ; grp1.setName("Border2D")
3291         grp2=DataArrayInt([2,3,6,7]) ; grp2.setName("LowerRight2D")
3292         mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3293         #
3294         m1=MEDCouplingUMesh(m0.getName(),1) ; m1.setCoords(m0.getCoords()) ; m1.allocateCells()
3295         for elt in [[0,1],[1,2],[2,3],[3,4],[4,9],[9,14],[14,19],[19,24],[24,23],[23,22],[22,21],[21,20],[20,15],[15,10],[10,5],[5,0],[2,7],[7,12],[12,17],[17,22],
3296                     [10,11],[11,12],[12,13],[13,14]]:
3297             m1.insertNextCell(NORM_SEG2,elt)
3298             pass
3299         mm.setMeshAtLevel(-1,m1)
3300         grp4=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]) ; grp4.setName("Border1D")
3301         grp5=DataArrayInt([16,17,18,19,20,21,22,23]) ; grp5.setName("Inside1D")
3302         grp6=DataArrayInt([18,19,22,23]) ; grp6.setName("UpperRight1D")
3303         mm.setGroupsAtLevel(-1,[grp4,grp5,grp6])
3304         #
3305         grp7=DataArrayInt([1,2,3,6,7,8,11,12,13,16,17,18,21,22,23]) ; grp7.setName("InsideYNode")
3306         grp8=DataArrayInt([5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; grp8.setName("InsideXNode")
3307         mm.setGroupsAtLevel(1,[grp7,grp8])
3308         #
3309         mm.write(fname,2)
3310         pass
3311
3312     def test22(self):
3313         """ Use case where a field on nodes (ANodeField) on a mesh defined both in meshdim 2 and meshdim 1.
3314         The only possible geometrical support that suits the field is those with meshdim equal to 1 (-1 in relative).
3315         """
3316         fname="ForMEDReader22.med"
3317         fieldName0="ANodeField"
3318         mm=MEDFileUMesh()
3319         coo=DataArrayDouble([(4.,3.),(7.,3.),(2.,5.),(6.,5.),(9.,5.),(4.,7.),(8.,7.),(3.,8.),(9.,8.)])
3320         m0=MEDCouplingUMesh("mesh",2) ; m0.setCoords(coo) ; m0.allocateCells() ; m0.insertNextCell(NORM_TRI3,[2,3,0]) ; m0.insertNextCell(NORM_TRI3,[3,1,0]) ; m0.insertNextCell(NORM_TRI3,[3,4,1])
3321         mm.setMeshAtLevel(0,m0)
3322         m1=MEDCouplingUMesh("mesh",1) ; m1.setCoords(coo) ; m1.allocateCells() ; m1.insertNextCell(NORM_SEG2,[2,0]) ;  m1.insertNextCell(NORM_SEG2,[0,1]) ; m1.insertNextCell(NORM_SEG2,[1,4])
3323         m1.insertNextCell(NORM_SEG2,[3,5]) ; m1.insertNextCell(NORM_SEG2,[5,7]) ; m1.insertNextCell(NORM_SEG2,[3,6]) ; m1.insertNextCell(NORM_SEG2,[6,8])
3324         mm.setMeshAtLevel(-1,m1)
3325         fs=MEDFileFields()
3326         fmts0=MEDFileFieldMultiTS() ; fs.pushField(fmts0)
3327         fmts0.setDtUnit("s")
3328         #
3329         t=(1.1,0,-2)
3330         f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m1)
3331         f0.setName(fieldName0) ; f0.setTime(*t)
3332         da=DataArrayDouble(9) ; da.iota() ; da.setInfoOnComponents(["zeInfo"])
3333         f0.setArray(da)
3334         f0.checkCoherency()
3335         f1ts=MEDFileField1TS()
3336         f1ts.setFieldNoProfileSBT(f0)
3337         fmts0.pushBackTimeStep(f1ts)
3338         #
3339         t=(2.1,1,-3)
3340         f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m1)
3341         f0.setName(fieldName0) ; f0.setTime(*t)
3342         da=DataArrayDouble(9) ; da.iota() ; da.reverse() ; da.setInfoOnComponents(["zeInfo"])
3343         f0.setArray(da)
3344         f0.checkCoherency()
3345         f1ts=MEDFileField1TS()
3346         f1ts.setFieldNoProfileSBT(f0)
3347         fmts0.pushBackTimeStep(f1ts)
3348         #
3349         mm.write(fname,2)
3350         fs.write(fname,0)
3351         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
3352         ms=MEDFileMeshes(fname)
3353         fields=MEDFileFields(fname,False)
3354         fields.removeFieldsWithoutAnyTimeStep()
3355         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
3356         allFMTSLeavesToDisplay=[]
3357         for fields in fields_per_mesh:
3358             allFMTSLeavesToDisplay2=[]
3359             for fmts in fields:
3360                 tmp=fmts.splitDiscretizations()
3361                 for itmp in tmp:
3362                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3363                     pass
3364                 allFMTSLeavesToDisplay2+=tmp
3365                 pass
3366             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
3367             pass
3368         self.assertEqual(len(allFMTSLeavesToDisplay),1)
3369         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
3370         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
3371         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
3372         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
3373         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
3374         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
3375         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
3376         #
3377         mst=MEDFileMeshStruct.New(ms[0])
3378         #
3379         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
3380         self.assertEqual([NORM_TRI3,NORM_SEG2],fcscp.getGeoTypesAt(0,ms[0]))#contains all cell types of underlying mesh because only nodes with no profiles
3381         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3382         mml2=mml.prepare()
3383         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
3384         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
3385         self.assertTrue(not ncc)
3386         self.assertTrue(a0.isEqual(DataArrayDouble([(4.,3.,0.),(7.,3.,0.),(2.,5.,0.),(6.,5.,0.),(9.,5.,0.),(4.,7.,0.),(8.,7.,0.),(3.,8.,0.),(9.,8.,0.)]),1e-12))
3387         self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,3,3,3,3,3,3,3])))
3388         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,15,18,21,24,27,30])))
3389         self.assertTrue(a3.isEqual(DataArrayInt([3,2,3,0,3,3,1,0,3,3,4,1,2,2,0,2,0,1,2,1,4,2,3,5,2,5,7,2,3,6,2,6,8])))
3390         self.assertTrue(a4 is None)
3391         self.assertTrue(a5 is None)
3392         a6,a7=mml2.retrieveFamilyIdsOnCells()
3393         self.assertTrue(a6.isEqual(DataArrayInt([0,0,0,0,0,0,0,0,0,0])))
3394         self.assertTrue(not a7) # copy here
3395         a8,a9=mml2.retrieveNumberIdsOnCells()
3396         self.assertTrue(not a8)
3397         self.assertTrue(a9) # nocopy here
3398         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3399         self.assertTrue(not a10)
3400         self.assertTrue(a11) # no copy here
3401         a12,a13=mml2.retrieveNumberIdsOnNodes()
3402         self.assertTrue(not a12)
3403         self.assertTrue(a13) # no copy here
3404         #
3405         f=allFMTSLeavesPerCommonSupport1[0][0][0][0]
3406         fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3407         f.loadArraysIfNecessary()
3408         v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3409         self.assertEqual(f.getName(),fieldName0)
3410         self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
3411         vExp=DataArrayDouble(9) ; vExp.iota() ; vExp.setInfoOnComponents(["zeInfo"])
3412         self.assertTrue(v.isEqual(vExp,1e-12))
3413         #
3414         f=allFMTSLeavesPerCommonSupport1[0][0][0][1]
3415         fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3416         f.loadArraysIfNecessary()
3417         v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3418         self.assertEqual(f.getName(),fieldName0)
3419         self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
3420         vExp=DataArrayDouble(9) ; vExp.iota() ; vExp.setInfoOnComponents(["zeInfo"]) ; vExp.reverse()
3421         self.assertTrue(v.isEqual(vExp,1e-12))
3422         pass 
3423     
3424     def test23(self):
3425         """ Non regression test 2219 of modes. Idem than test22 except that here the node field is on profile.
3426         """
3427         fname="ForMEDReader23.med"
3428         fieldName0="ANodeField"
3429         mm=MEDFileUMesh()
3430         coo=DataArrayDouble([(4.,3.),(7.,3.),(2.,5.),(6.,5.),(9.,5.),(4.,7.),(8.,7.),(3.,8.),(9.,8.)])
3431         m0=MEDCouplingUMesh("mesh",2) ; m0.setCoords(coo) ; m0.allocateCells() ; m0.insertNextCell(NORM_TRI3,[2,3,0]) ; m0.insertNextCell(NORM_TRI3,[3,1,0]) ; m0.insertNextCell(NORM_TRI3,[3,4,1])
3432         mm.setMeshAtLevel(0,m0)
3433         m1=MEDCouplingUMesh("mesh",1) ; m1.setCoords(coo) ; m1.allocateCells() ; m1.insertNextCell(NORM_SEG2,[2,0]) ;  m1.insertNextCell(NORM_SEG2,[0,1]) ; m1.insertNextCell(NORM_SEG2,[1,4])
3434         m1.insertNextCell(NORM_SEG2,[3,5]) ; m1.insertNextCell(NORM_SEG2,[5,7]) ; m1.insertNextCell(NORM_SEG2,[3,6]) ; m1.insertNextCell(NORM_SEG2,[6,8])
3435         mm.setMeshAtLevel(-1,m1)
3436         fmts0=MEDFileFieldMultiTS()
3437         fmts0.setDtUnit("s")
3438         #
3439         pfl=DataArrayInt([0,1,2,4]) ; pfl.setName("pfl")
3440         pflCell=DataArrayInt([0,1,2]) ; m1Part=m1[pflCell] ; m1Part.zipCoords()
3441         #
3442         t=(1.1,0,-2)
3443         f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m1Part)
3444         f0.setName(fieldName0) ; f0.setTime(*t)
3445         da=DataArrayDouble(4) ; da.iota() ; da.setInfoOnComponents(["zeInfo"])
3446         f0.setArray(da)
3447         f0.checkCoherency()
3448         f1ts=MEDFileField1TS()
3449         f1ts.setFieldProfile(f0,mm,-1,pfl)
3450         fmts0.pushBackTimeStep(f1ts)
3451         #
3452         t=(2.1,1,-3)
3453         f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m1Part)
3454         f0.setName(fieldName0) ; f0.setTime(*t)
3455         da=DataArrayDouble(4) ; da.iota() ; da.reverse() ; da.setInfoOnComponents(["zeInfo"])
3456         f0.setArray(da)
3457         f0.checkCoherency()
3458         f1ts=MEDFileField1TS()
3459         f1ts.setFieldProfile(f0,mm,-1,pfl)
3460         fmts0.pushBackTimeStep(f1ts)
3461         mm.write(fname,2)
3462         fmts0.write(fname,0)
3463         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
3464         ms=MEDFileMeshes(fname)
3465         fields=MEDFileFields(fname,False)
3466         fields.removeFieldsWithoutAnyTimeStep()
3467         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
3468         allFMTSLeavesToDisplay=[]
3469         for fields in fields_per_mesh:
3470             allFMTSLeavesToDisplay2=[]
3471             for fmts in fields:
3472                 tmp=fmts.splitDiscretizations()
3473                 for itmp in tmp:
3474                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3475                     pass
3476                 allFMTSLeavesToDisplay2+=tmp
3477                 pass
3478             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
3479             pass
3480         self.assertEqual(len(allFMTSLeavesToDisplay),1)
3481         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
3482         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
3483         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
3484         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
3485         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
3486         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
3487         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
3488         #
3489         mst=MEDFileMeshStruct.New(ms[0])
3490         #
3491         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
3492         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3493         mml2=mml.prepare()
3494         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
3495         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
3496         self.assertTrue(not ncc)
3497         self.assertTrue(a0.isEqual(DataArrayDouble([(4.,3.,0.),(7.,3.,0.),(2.,5.,0.),(9.,5.,0.)]),1e-12))
3498         self.assertTrue(a1.isEqual(DataArrayByte([3,3,3])))
3499         self.assertTrue(a2.isEqual(DataArrayInt([0,3,6])))
3500         self.assertTrue(a3.isEqual(DataArrayInt([2,2,0,2,0,1,2,1,3])))
3501         self.assertTrue(a4 is None)
3502         self.assertTrue(a5 is None)
3503         a6,a7=mml2.retrieveFamilyIdsOnCells()
3504         self.assertTrue(a6.isEqual(DataArrayInt([0,0,0])))
3505         self.assertTrue(not a7) # copy here
3506         a8,a9=mml2.retrieveNumberIdsOnCells()
3507         self.assertTrue(not a8)
3508         self.assertTrue(a9) # nocopy here
3509         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3510         self.assertTrue(not a10)
3511         self.assertTrue(a11) # no copy here
3512         a12,a13=mml2.retrieveNumberIdsOnNodes()
3513         self.assertTrue(not a12)
3514         self.assertTrue(a13) # no copy here
3515         #
3516         f=allFMTSLeavesPerCommonSupport1[0][0][0][0]
3517         fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3518         f.loadArraysIfNecessary()
3519         v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3520         self.assertEqual(f.getName(),fieldName0)
3521         vExp=DataArrayDouble(4) ; vExp.iota() ; vExp.setInfoOnComponents(["zeInfo"])
3522         self.assertTrue(v.isEqual(vExp,1e-12))
3523         #
3524         f=allFMTSLeavesPerCommonSupport1[0][0][0][1]
3525         fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3526         f.loadArraysIfNecessary()
3527         v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3528         self.assertEqual(f.getName(),fieldName0)
3529         vExp=DataArrayDouble(4) ; vExp.iota() ; vExp.setInfoOnComponents(["zeInfo"]) ; vExp.reverse()
3530         self.assertTrue(v.isEqual(vExp,1e-12))
3531         pass
3532
3533     def test24(self):
3534         """ Non regression test for cartesian mesh whose the 3rd direction has only one node. It a false 3D mesh.
3535         """
3536         fname="ForMEDReader24.med"
3537         fieldName0="zeFieldNode"
3538         cmesh=MEDCouplingCMesh("mesh")
3539         arr0=DataArrayDouble([0.,1.1,2.2,3.3,4.4])
3540         arr1=DataArrayDouble([0.,1.4,2.3])
3541         arr2=DataArrayDouble([5.])
3542         cmesh.setCoords(arr0,arr1,arr2)
3543         fmts0=MEDFileFieldMultiTS()
3544         fmts0.setDtUnit("s")
3545         #
3546         t=(1.1,2,3)
3547         f=MEDCouplingFieldDouble(ON_NODES) ; f.setName(fieldName0)
3548         f.setMesh(cmesh)
3549         arr=DataArrayDouble(15) ; arr.setInfoOnComponents(["tutu"]) ; arr.iota()
3550         f.setArray(arr)
3551         f.setTime(*t)
3552         f1ts=MEDFileField1TS()
3553         f1ts.setFieldNoProfileSBT(f)
3554         fmts0.pushBackTimeStep(f1ts)
3555         #
3556         t=(3.3,4,5)
3557         arr=DataArrayDouble(15) ; arr.setInfoOnComponents(["tutu"]) ; arr.iota()
3558         arr.reverse()
3559         f.setArray(arr)
3560         f.setTime(*t)
3561         f1ts=MEDFileField1TS()
3562         f1ts.setFieldNoProfileSBT(f)
3563         fmts0.pushBackTimeStep(f1ts)
3564         #
3565         mm=MEDFileCMesh() ; mm.setMesh(cmesh)
3566         mm.write(fname,2)
3567         fmts0.write(fname,0)
3568         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
3569         ms=MEDFileMeshes(fname)
3570         fields=MEDFileFields(fname,False)
3571         fields.removeFieldsWithoutAnyTimeStep()
3572         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
3573         allFMTSLeavesToDisplay=[]
3574         for fields in fields_per_mesh:
3575             allFMTSLeavesToDisplay2=[]
3576             for fmts in fields:
3577                 tmp=fmts.splitDiscretizations()
3578                 for itmp in tmp:
3579                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3580                     pass
3581                 allFMTSLeavesToDisplay2+=tmp
3582                 pass
3583             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
3584             pass
3585         self.assertEqual(len(allFMTSLeavesToDisplay),1)
3586         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
3587         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
3588         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
3589         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
3590         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
3591         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
3592         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),1)
3593         #
3594         mst=MEDFileMeshStruct.New(ms[0])
3595         #
3596         fcscp=allFMTSLeavesPerCommonSupport[0][1]
3597         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3598         mml2=mml.prepare()
3599         self.assertTrue(isinstance(mml2,MEDCMeshMultiLev))
3600         (a,b,c),d=mml2.buildVTUArrays()
3601         self.assertTrue(d)#d is True because the a,b and c are directly those in the internal data structure
3602         self.assertTrue(a.isEqual(arr0,1e-12))
3603         self.assertTrue(b.isEqual(arr1,1e-12))
3604         self.assertTrue(c.isEqual(arr2,1e-12))
3605         for i in xrange(2):
3606             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
3607             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
3608             f.loadArraysIfNecessary()
3609             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
3610             self.assertEqual(f.getName(),fieldName0)
3611             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
3612             vExp=DataArrayDouble(15) ; vExp.iota(0) ; vExp.setInfoOnComponents(["tutu"])
3613             if i==1:
3614                 vExp.reverse()
3615                 pass
3616             self.assertTrue(v.isEqual(vExp,1e-12))
3617             pass
3618         pass
3619
3620     def test25(self):
3621         """ A tricky test that reproduces an invalid behaviour
3622         Here a same field is defined both on CELLS and GAUSS_PT, with a profile for each.
3623         The problem appears on array computation when performing CELLS then GAUSS_PT and CELLS again.
3624         """
3625         fname="ForMEDReader25.med"
3626         m=MEDFileUMesh()
3627         coords=DataArrayDouble([0.,0.,1.,0.,2.,0.,0.,1.,1.,1.,2.,1.,0.,2.,1.,2.,2.,2.,0.,3.,1.,3.,2.,3.,1.,4.,1.,5.,1.,6.],15,2)
3628         m0=MEDCouplingUMesh("mesh",2) ; m0.setCoords(coords)
3629         m0.allocateCells()
3630         m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
3631         m0.insertNextCell(NORM_QUAD4,[1,4,5,2])
3632         m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
3633         m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
3634         m0.insertNextCell(NORM_QUAD4,[6,9,10,7])
3635         m0.insertNextCell(NORM_QUAD4,[7,10,11,8])
3636         m.setMeshAtLevel(0,m0)
3637         m1=MEDCouplingUMesh("mesh",1) ; m1.setCoords(coords)
3638         m1.allocateCells()
3639         m1.insertNextCell(NORM_SEG2,[10,12])
3640         m1.insertNextCell(NORM_SEG2,[12,13])
3641         m1.insertNextCell(NORM_SEG2,[13,14])
3642         m.setMeshAtLevel(-1,m1)
3643         m.setFamilyFieldArr(0,DataArrayInt([-1,-2,-3,-4,-5,-6]))
3644         m.setFamilyFieldArr(-1,DataArrayInt([-7,-8,-9]))
3645         m.setFamilyFieldArr(1,DataArrayInt([3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]))
3646         m.setRenumFieldArr(0,DataArrayInt([101,102,103,104,105,106]))
3647         m.setRenumFieldArr(-1,DataArrayInt([107,108,109]))
3648         m.setRenumFieldArr(1,DataArrayInt([203,204,205,206,207,208,209,210,211,212,213,214,215,216,217]))
3649         #
3650         fmts=MEDFileFieldMultiTS()
3651         info0=["aa","bbb"]
3652         name0="zeField"
3653         pflName0="pfl"
3654         pflName1="pfl2"
3655         #
3656         f1ts=MEDFileField1TS()
3657         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name0)
3658         arr=DataArrayDouble([(-1,-11),(-2,-22)]) ; arr.setInfoOnComponents(info0)
3659         f.setArray(arr)
3660         pfl0=DataArrayInt([0,1]) ; pfl0.setName(pflName0)
3661         f1ts.setFieldProfile(f,m,-1,pfl0)
3662         del f
3663         f2=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f2.setName(name0)
3664         arr=DataArrayDouble(15) ; arr.iota(1)
3665         arr=DataArrayDouble.Meld(arr,arr+10) ; arr.setInfoOnComponents(info0)
3666         f2.setArray(arr)
3667         pfl1=DataArrayInt([1,3,5]) ; pfl1.setName(pflName1)
3668         tmp=m0[pfl1] ; f2.setMesh(tmp)
3669         f2.setGaussLocalizationOnType(NORM_QUAD4,[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[-0.5,-0.5,0.5,-0.5,0.5,0.5,-0.5,0.5,0.,0.],[0.1,0.1,0.1,0.1,0.6])
3670         f2.checkCoherency()
3671         f1ts.setFieldProfile(f2,m,0,pfl1)
3672         fmts.pushBackTimeStep(f1ts)
3673         #
3674         m.write(fname,2)
3675         fmts.write(fname,0)
3676         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
3677         ms=MEDFileMeshes(fname)
3678         fields=MEDFileFields(fname,False) # false is absolutely necessary for the test
3679         fields.removeFieldsWithoutAnyTimeStep()
3680         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
3681         allFMTSLeavesToDisplay=[]
3682         for fields in fields_per_mesh:
3683             allFMTSLeavesToDisplay2=[]
3684             for fmts in fields:
3685                 tmp=fmts.splitDiscretizations()
3686                 for itmp in tmp:
3687                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3688                     pass
3689                 allFMTSLeavesToDisplay2+=tmp
3690                 pass
3691             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
3692             pass
3693         self.assertEqual(len(allFMTSLeavesToDisplay),1)
3694         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
3695         ### here the test is important !!! Pointers must be different !
3696         self.assertTrue(allFMTSLeavesToDisplay[0][0][0].getUndergroundDataArray().getHiddenCppPointer()!=allFMTSLeavesToDisplay[0][1][0].getUndergroundDataArray().getHiddenCppPointer())
3697         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
3698         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
3699         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
3700         ### here the test is important !!! Pointers must be different !
3701         self.assertTrue(allFMTSLeavesToDisplay[0][0][0].getUndergroundDataArray().getHiddenCppPointer()!=allFMTSLeavesToDisplay[0][1][0].getUndergroundDataArray().getHiddenCppPointer())
3702         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
3703         self.assertTrue(allFMTSLeavesToDisplay[0][0][0].getUndergroundDataArray().getHiddenCppPointer()!=allFMTSLeavesToDisplay[0][1][0].getUndergroundDataArray().getHiddenCppPointer())
3704         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),2)
3705         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
3706         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),1)
3707         #
3708         mst=MEDFileMeshStruct.New(ms[0])
3709         # emulate first click
3710         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
3711         self.assertEqual([NORM_SEG2],fcscp.getGeoTypesAt(0,ms[0]))
3712         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3713         mml2=mml.prepare()
3714         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
3715         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
3716         self.assertTrue(not ncc) # copy here because 2D -> 3D
3717         expCoords=coords.changeNbOfComponents(3,0.)
3718         self.assertTrue(a0.isEqual(expCoords,1e-12))
3719         self.assertTrue(a1.isEqual(DataArrayByte([3,3])))
3720         self.assertTrue(a2.isEqual(DataArrayInt([0,3])))
3721         self.assertTrue(a3.isEqual(DataArrayInt([2,10,12,2,12,13])))
3722         self.assertTrue(a4 is None)
3723         self.assertTrue(a5 is None)
3724         a6,a7=mml2.retrieveFamilyIdsOnCells()
3725         self.assertTrue(a6.isEqual(DataArrayInt([-7,-8])))
3726         self.assertTrue(not a7) # copy here because profile on cells
3727         a8,a9=mml2.retrieveNumberIdsOnCells()
3728         self.assertTrue(a8.isEqual(DataArrayInt([107,108])))
3729         self.assertTrue(not a9) # copy here because profile on cells
3730         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3731         self.assertTrue(a10.isEqual(DataArrayInt([3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])))
3732         self.assertTrue(a11) # no copy here
3733         a12,a13=mml2.retrieveNumberIdsOnNodes()
3734         self.assertTrue(a12.isEqual(DataArrayInt([203,204,205,206,207,208,209,210,211,212,213,214,215,216,217])))
3735         self.assertTrue(a13) # no copy here
3736         fff0=allFMTSLeavesPerCommonSupport1[0][0][0][0]
3737         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff0,mst)
3738         fff0.loadArraysIfNecessary()
3739         self.assertEqual([ON_CELLS],fff0.getTypesOfFieldAvailable())
3740         v=mml.buildDataArray(fsst,fields,fff0.getUndergroundDataArray())
3741         self.assertEqual(fff0.getName(),name0)
3742         self.assertEqual(v.getHiddenCppPointer(),fff0.getUndergroundDataArray().getHiddenCppPointer())
3743         vExp=DataArrayDouble([(-1,-11),(-2,-22)]) ; vExp.setInfoOnComponents(info0)
3744         self.assertTrue(v.isEqual(vExp,1e-12))
3745         del fff0
3746         # emulate second click
3747         fcscp=allFMTSLeavesPerCommonSupport1[1][1]
3748         self.assertEqual([NORM_QUAD4],fcscp.getGeoTypesAt(0,ms[0]))
3749         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3750         mml2=mml.prepare()
3751         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
3752         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
3753         self.assertTrue(not ncc) # copy here because 2D -> 3D
3754         expCoords=coords.changeNbOfComponents(3,0.)
3755         self.assertTrue(a0.isEqual(expCoords,1e-12))
3756         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9])))
3757         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10])))
3758         self.assertTrue(a3.isEqual(DataArrayInt([4,1,4,5,2,4,4,7,8,5,4,7,10,11,8])))
3759         self.assertTrue(a4 is None)
3760         self.assertTrue(a5 is None)
3761         a6,a7=mml2.retrieveFamilyIdsOnCells()
3762         self.assertTrue(a6.isEqual(DataArrayInt([-2,-4,-6])))
3763         self.assertTrue(not a7) # copy here because profile on cells
3764         a8,a9=mml2.retrieveNumberIdsOnCells()
3765         self.assertTrue(a8.isEqual(DataArrayInt([102,104,106])))
3766         self.assertTrue(not a9) # copy here because profile on cells
3767         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3768         self.assertTrue(a10.isEqual(DataArrayInt([3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])))
3769         self.assertTrue(a11) # no copy here
3770         a12,a13=mml2.retrieveNumberIdsOnNodes()
3771         self.assertTrue(a12.isEqual(DataArrayInt([203,204,205,206,207,208,209,210,211,212,213,214,215,216,217])))
3772         self.assertTrue(a13) # no copy here
3773         fff1=allFMTSLeavesPerCommonSupport1[1][0][0][0]
3774         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff1,mst)
3775         fff1.loadArraysIfNecessary()
3776         self.assertEqual([ON_GAUSS_PT],fff1.getTypesOfFieldAvailable())
3777         v=mml.buildDataArray(fsst,fields,fff1.getUndergroundDataArray())
3778         self.assertEqual(fff1.getName(),name0)
3779         self.assertEqual(v.getHiddenCppPointer(),fff1.getUndergroundDataArray().getHiddenCppPointer())
3780         vExp=DataArrayDouble([1.,11.,2.,12.,3.,13.,4.,14.,5.,15.,6.,16.,7.,17.,8.,18.,9.,19.,10.,20.,11.,21.,12.,22.,13.,23.,14.,24.,15.,25.],15,2) ; vExp.setInfoOnComponents(info0)
3781         self.assertTrue(v.isEqual(vExp,1e-12))
3782         # emulate third click
3783         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
3784         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3785         mml2=mml.prepare()
3786         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
3787         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
3788         self.assertTrue(not ncc) # copy here because 2D -> 3D
3789         expCoords=coords.changeNbOfComponents(3,0.)
3790         self.assertTrue(a0.isEqual(expCoords,1e-12))
3791         self.assertTrue(a1.isEqual(DataArrayByte([3,3])))
3792         self.assertTrue(a2.isEqual(DataArrayInt([0,3])))
3793         self.assertTrue(a3.isEqual(DataArrayInt([2,10,12,2,12,13])))
3794         self.assertTrue(a4 is None)
3795         self.assertTrue(a5 is None)
3796         a6,a7=mml2.retrieveFamilyIdsOnCells()
3797         self.assertTrue(a6.isEqual(DataArrayInt([-7,-8])))
3798         self.assertTrue(not a7) # copy here because profile on cells
3799         a8,a9=mml2.retrieveNumberIdsOnCells()
3800         self.assertTrue(a8.isEqual(DataArrayInt([107,108])))
3801         self.assertTrue(not a9) # copy here because profile on cells
3802         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3803         self.assertTrue(a10.isEqual(DataArrayInt([3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])))
3804         self.assertTrue(a11) # no copy here
3805         a12,a13=mml2.retrieveNumberIdsOnNodes()
3806         self.assertTrue(a12.isEqual(DataArrayInt([203,204,205,206,207,208,209,210,211,212,213,214,215,216,217])))
3807         self.assertTrue(a13) # no copy here
3808         fff0=allFMTSLeavesPerCommonSupport1[0][0][0][0]
3809         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff0,mst)
3810         fff0.loadArraysIfNecessary()
3811         self.assertEqual([ON_CELLS],fff0.getTypesOfFieldAvailable())
3812         v=mml.buildDataArray(fsst,fields,fff0.getUndergroundDataArray())
3813         self.assertEqual(fff0.getName(),name0)
3814         self.assertEqual(v.getHiddenCppPointer(),fff0.getUndergroundDataArray().getHiddenCppPointer())
3815         vExp=DataArrayDouble([(-1,-11),(-2,-22)]) ; vExp.setInfoOnComponents(info0)
3816         self.assertTrue(v.isEqual(vExp,1e-12)) # <- THE test is here !!!
3817         del fff0
3818         pass
3819
3820     def test26(self):
3821         """ Test focused on field on nodes (here f0Node and f1Node) lying on a profile of nodes that do not match perfectly a sub set of cells of its underlying mesh. See bug EDF 2405 and 2177.
3822         For this type of fields the support will contain only vertices.
3823         """
3824         fname="ForMEDReader26.med"
3825         coords=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.)])
3826         m0=MEDCouplingUMesh("mesh",2)
3827         m0.allocateCells()
3828         for elt in [[2,6,3],[6,7,3],[9,6,5],[9,10,6]]:
3829             m0.insertNextCell(NORM_TRI3,elt)
3830             pass
3831         for elt in [[0,4,5,1],[1,5,6,2],[4,8,9,5],[6,10,11,7],[8,12,13,9],[9,13,14,10],[10,14,15,11]]:
3832             m0.insertNextCell(NORM_QUAD4,elt)
3833             pass
3834         m0.setCoords(coords)
3835         ##
3836         mm=MEDFileUMesh()
3837         mm.setMeshAtLevel(0,m0)
3838         mm.setFamilyFieldArr(0,DataArrayInt([-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11]))
3839         mm.setFamilyFieldArr(1,DataArrayInt([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]))
3840         #
3841         f1ts0Node=MEDFileField1TS()
3842         f1ts1Node=MEDFileField1TS()
3843         f1ts2Cell=MEDFileField1TS()
3844         f1ts3Cell=MEDFileField1TS()
3845         f1ts4Cell=MEDFileField1TS()
3846         f1ts5Node=MEDFileField1TS()
3847         #
3848         pfl0=DataArrayInt([4,5,6,8,9,12]) ; pfl0.setName("pfl0")
3849         pfl1=DataArrayInt([0,1,4,5,7,10]) ; pfl1.setName("pfl1")
3850         pfl2=DataArrayInt([0,1,2,3,4,5,6,7,10,11,14,15]) ; pfl2.setName("pfl2")
3851         #
3852         f0Node=MEDCouplingFieldDouble(ON_NODES) ; f0Node.setName("f0Node")
3853         arr0=DataArrayDouble(6) ; arr0.iota()
3854         f0Node.setArray(arr0)
3855         f1ts0Node.setFieldProfile(f0Node,mm,0,pfl0)
3856         #
3857         f1Node=MEDCouplingFieldDouble(ON_NODES) ; f1Node.setName("f1Node")
3858         arr1=DataArrayDouble(6) ; arr1.iota() ; arr1.reverse()
3859         f1Node.setArray(arr1)
3860         f1ts1Node.setFieldProfile(f1Node,mm,0,pfl0)
3861         #
3862         f2Cell=MEDCouplingFieldDouble(ON_CELLS) ; f2Cell.setName("f2Cell")
3863         arr2=DataArrayDouble([2,3,0,1,4,5])
3864         f2Cell.setArray(arr2)
3865         f1ts2Cell.setFieldProfile(f2Cell,mm,0,pfl1)
3866         #
3867         f3Cell=MEDCouplingFieldDouble(ON_CELLS) ; f3Cell.setName("f3Cell")
3868         arr3=DataArrayDouble([5,4,3,2,1,0])
3869         f3Cell.setArray(arr3)
3870         f1ts3Cell.setFieldProfile(f3Cell,mm,0,pfl1)
3871         #
3872         f4Cell=MEDCouplingFieldDouble(ON_CELLS) ; f4Cell.setName("f4Cell")
3873         arr4=DataArrayDouble([2,2,0,1,1,0])
3874         f4Cell.setArray(arr4)
3875         f1ts4Cell.setFieldProfile(f4Cell,mm,0,pfl1)
3876         #
3877         f5Node=MEDCouplingFieldDouble(ON_NODES) ; f5Node.setName("f5Node")
3878         arr5=DataArrayDouble([0,1,2,3,10,11,13,2,11,1,10,0])
3879         f5Node.setArray(arr5)
3880         f1ts5Node.setFieldProfile(f5Node,mm,0,pfl2)
3881         #
3882         fs=MEDFileFields()
3883         for f in [f1ts0Node,f1ts1Node,f1ts2Cell,f1ts3Cell,f1ts4Cell,f1ts5Node]:
3884             fmts=MEDFileFieldMultiTS()
3885             fmts.pushBackTimeStep(f)
3886             fs.pushField(fmts)
3887             pass
3888         mm.write(fname,2)
3889         fs.write(fname,0)
3890         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
3891         ms=MEDFileMeshes(fname)
3892         fields=MEDFileFields(fname,False)
3893         fields.removeFieldsWithoutAnyTimeStep()
3894         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
3895         allFMTSLeavesToDisplay=[]
3896         for fields in fields_per_mesh:
3897             allFMTSLeavesToDisplay2=[]
3898             for fmts in fields:
3899                 tmp=fmts.splitDiscretizations()
3900                 for itmp in tmp:
3901                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3902                     pass
3903                 allFMTSLeavesToDisplay2+=tmp
3904                 pass
3905             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
3906             pass
3907         self.assertEqual(len(allFMTSLeavesToDisplay),1)
3908         self.assertEqual(len(allFMTSLeavesToDisplay[0]),6)
3909         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
3910         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
3911         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),6)
3912         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
3913         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),2)
3914         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),4)
3915         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),2)# <- the smart one is here
3916         #
3917         mst=MEDFileMeshStruct.New(ms[0])
3918         #
3919         fcscp=allFMTSLeavesPerCommonSupport1[1][1]
3920         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
3921         mml2=mml.prepare()
3922         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
3923         self.assertEqual([3,4,0],mml2.getGeoTypes())
3924         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
3925         self.assertTrue(not ncc)
3926         self.assertTrue(a0.isEqual(DataArrayDouble([0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,0.,3.,0.],6,3),1e-12))
3927         self.assertTrue(a1.isEqual(DataArrayByte([5,9,1])))
3928         self.assertTrue(a2.isEqual(DataArrayInt([0,4,9])))
3929         self.assertTrue(a3.isEqual(DataArrayInt([3,4,2,1,4,0,3,4,1,1,5])))
3930         self.assertTrue(a4 is None)
3931         self.assertTrue(a5 is None)
3932         a6,a7=mml2.retrieveFamilyIdsOnCells()
3933         self.assertTrue(a6.isEqual(DataArrayInt([-3,-7,13])))
3934         self.assertTrue(not a7) # copy here because profile on cells
3935         a8,a9=mml2.retrieveNumberIdsOnCells()
3936         self.assertTrue(a8 is None)
3937         self.assertTrue(a9) # no copy here because no number field
3938         a10,a11=mml2.retrieveFamilyIdsOnNodes()
3939         self.assertTrue(a10.isEqual(DataArrayInt([5,6,7,9,10,13])))
3940         self.assertTrue(not a11) # copy here
3941         a12,a13=mml2.retrieveNumberIdsOnNodes()
3942         self.assertTrue(a12 is None)
3943         self.assertTrue(a13) # no copy here because no number field
3944         #
3945         fff0=allFMTSLeavesPerCommonSupport1[1][0][0][0]
3946         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff0,mst)
3947         fff0.loadArraysIfNecessary()
3948         v=mml2.buildDataArray(fsst,fields,fff0.getUndergroundDataArray())
3949         self.assertEqual(fff0.getName(),"f0Node")
3950         self.assertEqual(v.getHiddenCppPointer(),fff0.getUndergroundDataArray().getHiddenCppPointer())
3951         vExp=DataArrayDouble([0.,1.,2.,3.,4.,5.])
3952         self.assertTrue(v.isEqual(vExp,1e-12)) # <- THE test is here !!!
3953         #
3954         fff1=allFMTSLeavesPerCommonSupport1[1][0][1][0]
3955         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff1,mst)
3956         fff1.loadArraysIfNecessary()
3957         v=mml2.buildDataArray(fsst,fields,fff1.getUndergroundDataArray())
3958         self.assertEqual(fff1.getName(),"f1Node")
3959         self.assertEqual(v.getHiddenCppPointer(),fff1.getUndergroundDataArray().getHiddenCppPointer())
3960         vExp=DataArrayDouble([5.,4.,3.,2.,1.,0.])
3961         self.assertTrue(v.isEqual(vExp,1e-12)) # <- THE test is here !!!
3962         pass
3963
3964     def test27(self):
3965         """ This test defines 2 fields f0 and f1 on nodes lying on an unstructured mesh with no cells.
3966         f0 is a field on all nodes. f1 is a partial field on nodes.
3967         """
3968         fname="ForMEDReader27.med"
3969         coords=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.)])
3970         m0=MEDCouplingUMesh("mesh",2)
3971         m0.allocateCells()
3972         m0.setCoords(coords)
3973         ##
3974         mm=MEDFileUMesh()
3975         mm.setMeshAtLevel(0,m0)
3976         mm.setFamilyFieldArr(1,DataArrayInt([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]))
3977         #
3978         f1ts0=MEDFileField1TS()
3979         f1ts1=MEDFileField1TS()
3980         #
3981         f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m0) ; f0.setName("f0NoPfl")
3982         arr0=DataArrayDouble([0.,1.,2.,3.,1.,1.5,2.2,3.1,2.,2.2,3.,3.1,3.,3.1,3.5,4.])
3983         f0.setArray(arr0)
3984         f0.checkCoherency()
3985         f1ts0.setFieldNoProfileSBT(f0)
3986         self.assertEqual(f1ts0.getMeshName(),"mesh")
3987         #
3988         pfl1=DataArrayInt([0,1,2,3,4,5,6,8,9,12]) ; pfl1.setName("pfl1")
3989         f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setName("f1Pfl")
3990         arr1=DataArrayDouble([3.,2.,1.,0.,2.,1.5,0.,1.,0.,0.2])
3991         f1.setArray(arr1)
3992         f1ts1.setFieldProfile(f1,mm,0,pfl1)
3993         self.assertEqual(f1ts1.getMeshName(),"mesh")
3994         #
3995         fs=MEDFileFields()
3996         fmts0=MEDFileFieldMultiTS()
3997         fmts0.pushBackTimeStep(f1ts0)
3998         fmts1=MEDFileFieldMultiTS()
3999         fmts1.pushBackTimeStep(f1ts1)
4000         fs.pushField(fmts0) ; fs.pushField(fmts1)
4001         self.assertEqual(fs[0].getMeshName(),"mesh")
4002         self.assertEqual(fs[1].getMeshName(),"mesh")
4003         mm.write(fname,2)
4004         fs.write(fname,0)
4005         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4006         ms=MEDFileMeshes(fname)
4007         fields=MEDFileFields(fname,False)
4008         fields.removeFieldsWithoutAnyTimeStep()
4009         self.assertEqual(fields[0].getMeshName(),"mesh")
4010         self.assertEqual(fields[1].getMeshName(),"mesh")
4011         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4012         self.assertEqual(fields_per_mesh[0][0].getMeshName(),"mesh")
4013         self.assertEqual(fields_per_mesh[0][1].getMeshName(),"mesh")
4014         allFMTSLeavesToDisplay=[]
4015         for fields in fields_per_mesh:
4016             allFMTSLeavesToDisplay2=[]
4017             for fmts in fields:
4018                 tmp=fmts.splitDiscretizations()
4019                 for itmp in tmp:
4020                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4021                     pass
4022                 allFMTSLeavesToDisplay2+=tmp
4023                 pass
4024             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4025             pass
4026         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4027         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
4028         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4029         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
4030         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
4031         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
4032         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),2)
4033         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
4034         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),1)
4035         #
4036         mst=MEDFileMeshStruct.New(ms[0])
4037         #
4038         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4039         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4040         mml2=mml.prepare()
4041         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4042         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4043         self.assertTrue(ncc)
4044         self.assertTrue(a0.isEqual(DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.)]),1e-12))
4045         self.assertTrue(a1.isEqual(DataArrayByte([])))
4046         self.assertTrue(a2.isEqual(DataArrayInt([])))
4047         self.assertTrue(a3.isEqual(DataArrayInt([])))
4048         self.assertTrue(a4 is None)
4049         self.assertTrue(a5 is None)
4050         #
4051         fff0=allFMTSLeavesPerCommonSupport1[0][0][0][0]
4052         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff0,mst)
4053         fff0.loadArraysIfNecessary()
4054         v=mml2.buildDataArray(fsst,fields,fff0.getUndergroundDataArray())
4055         self.assertEqual(fff0.getName(),"f0NoPfl")
4056         self.assertEqual(v.getHiddenCppPointer(),fff0.getUndergroundDataArray().getHiddenCppPointer())
4057         vExp=DataArrayDouble([0.,1.,2.,3.,1.,1.5,2.2,3.1,2.,2.2,3.,3.1,3.,3.1,3.5,4])
4058         self.assertTrue(v.isEqual(vExp,1e-12))
4059         #
4060         fcscp=allFMTSLeavesPerCommonSupport1[1][1]
4061         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4062         mml2=mml.prepare()
4063         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4064         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4065         self.assertTrue(not ncc)
4066         self.assertTrue(a0.isEqual(DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(3,0,0),(0,1,0),(1,1,0),(2,1,0),(0,2,0),(1,2,0),(0,3,0)]),1e-12))
4067         self.assertTrue(a1.isEqual(DataArrayByte([])))
4068         self.assertTrue(a2.isEqual(DataArrayInt([])))
4069         self.assertTrue(a3.isEqual(DataArrayInt([])))
4070         self.assertTrue(a4 is None)
4071         self.assertTrue(a5 is None)
4072         fff1=allFMTSLeavesPerCommonSupport1[1][0][0][0]
4073         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff1,mst)
4074         fff1.loadArraysIfNecessary()
4075         v=mml2.buildDataArray(fsst,fields,fff1.getUndergroundDataArray())
4076         self.assertEqual(fff1.getName(),"f1Pfl")
4077         self.assertNotEqual(v.getHiddenCppPointer(),fff1.getUndergroundDataArray().getHiddenCppPointer()) # pointers are not equal because Profile
4078         vExp=DataArrayDouble([3.,2.,1.,0.,2.,1.5,0.,1.,0.,0.2])
4079         self.assertTrue(v.isEqual(vExp,1e-12))
4080         pass
4081
4082     def test28(self):
4083         """ This test defines 2 fields f0,f1,f2,f3 lying on an unstructured mesh whith cells including NORM_POINT1.
4084         Both f0 and f1 are on NODES and f2 and f3 are on cells. f1 and f2 share the same support.
4085         f0 is on a nodal support that is not matchable with any cells (including NORM_POINT1)
4086         This test is a more aggressive version of test26.
4087         """
4088         fname="ForMEDReader28.med"
4089         coords=DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.)])
4090         m0=MEDCouplingUMesh("mesh",2)
4091         m0.allocateCells()
4092         for elt in [[2,6,3],[6,7,3],[9,6,5],[9,10,6]]:
4093             m0.insertNextCell(NORM_TRI3,elt)
4094             pass
4095         for elt in [[0,4,5,1],[1,5,6,2],[4,8,9,5],[6,10,11,7],[8,12,13,9],[9,13,14,10],[10,14,15,11]]:
4096             m0.insertNextCell(NORM_QUAD4,elt)
4097             pass
4098         m0.setCoords(coords)
4099         m2=MEDCouplingUMesh("mesh",0) ; m2.setCoords(coords)
4100         m2.allocateCells()
4101         for elt in [[8],[13]]:
4102             m2.insertNextCell(NORM_POINT1,elt)
4103             pass
4104         ##
4105         mm=MEDFileUMesh()
4106         mm.setMeshAtLevel(0,m0)
4107         mm.setMeshAtLevel(-2,m2)
4108         mm.setFamilyFieldArr(0,DataArrayInt([-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11]))
4109         mm.setFamilyFieldArr(-2,DataArrayInt([-12,-13]))
4110         mm.setFamilyFieldArr(1,DataArrayInt([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]))
4111         #
4112         f1ts0Node=MEDFileField1TS()
4113         f1ts1Node=MEDFileField1TS()
4114         f1ts2Cell=MEDFileField1TS()
4115         f1ts3Cell=MEDFileField1TS()
4116         #
4117         pfl0=DataArrayInt([4,5,6,8,9,12]) ; pfl0.setName("pfl0")
4118         pfl1=DataArrayInt([0,1,4,5,7,10]) ; pfl1.setName("pfl1")
4119         pfl2=DataArrayInt([0,1,2,3,4,5,6,7,10,11,14,15]) ; pfl2.setName("pfl2")
4120         #
4121         f0Node=MEDCouplingFieldDouble(ON_NODES) ; f0Node.setName("f0Node")
4122         arr0=DataArrayDouble(6) ; arr0.iota()
4123         f0Node.setArray(arr0)
4124         f1ts0Node.setFieldProfile(f0Node,mm,0,pfl0)
4125         #
4126         f1Node=MEDCouplingFieldDouble(ON_NODES) ; f1Node.setName("f1Node")
4127         arr1=DataArrayDouble(12) ; arr1.iota() ; arr1.reverse()
4128         f1Node.setArray(arr1)
4129         f1ts1Node.setFieldProfile(f1Node,mm,0,pfl2)
4130         #
4131         f2Cell=MEDCouplingFieldDouble(ON_CELLS) ; f2Cell.setName("f2Cell")
4132         arr2=DataArrayDouble([2,3,0,1,4,5])
4133         f2Cell.setArray(arr2)
4134         f1ts2Cell.setFieldProfile(f2Cell,mm,0,pfl1)
4135         #
4136         f3Cell=MEDCouplingFieldDouble(ON_CELLS) ; f3Cell.setName("f3Cell")
4137         arr3=DataArrayDouble([5,4,3,2,1,0]) ; f3Cell.setArray(arr3)
4138         f1ts3Cell.setFieldProfile(f3Cell,mm,0,pfl1)
4139         f3Cell.setMesh(m2)
4140         arr3=DataArrayDouble([-1.1,-3.1]) ; f3Cell.setArray(arr3)
4141         f1ts3Cell.setFieldNoProfileSBT(f3Cell)
4142         #
4143         fs=MEDFileFields()
4144         for f in [f1ts0Node,f1ts1Node,f1ts2Cell,f1ts3Cell]:
4145             fmts=MEDFileFieldMultiTS()
4146             fmts.pushBackTimeStep(f)
4147             fs.pushField(fmts)
4148             pass
4149         mm.write(fname,2)
4150         fs.write(fname,0)
4151         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4152         ms=MEDFileMeshes(fname)
4153         fields=MEDFileFields(fname,False)
4154         fields.removeFieldsWithoutAnyTimeStep()
4155         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4156         allFMTSLeavesToDisplay=[]
4157         for fields in fields_per_mesh:
4158             allFMTSLeavesToDisplay2=[]
4159             for fmts in fields:
4160                 tmp=fmts.splitDiscretizations()
4161                 for itmp in tmp:
4162                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4163                     pass
4164                 allFMTSLeavesToDisplay2+=tmp
4165                 pass
4166             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4167             pass
4168         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4169         self.assertEqual(len(allFMTSLeavesToDisplay[0]),4)
4170         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4171         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
4172         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),4)
4173         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
4174         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),3)
4175         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),2)
4176         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),1)
4177         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[2][0]),1)
4178         #
4179         mst=MEDFileMeshStruct.New(ms[0])
4180         #
4181         fcscp=allFMTSLeavesPerCommonSupport1[2][1]
4182         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4183         mml2=mml.prepare()
4184         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4185         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4186         self.assertTrue(not ncc)
4187         self.assertTrue(a0.isEqual(DataArrayDouble([0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,0.,3.,0.],6,3),1e-12))
4188         self.assertTrue(a1.isEqual(DataArrayByte([5,9,1,1])))
4189         self.assertTrue(a2.isEqual(DataArrayInt([0,4,9,11])))
4190         self.assertTrue(a3.isEqual(DataArrayInt([3,4,2,1,4,0,3,4,1,1,3,1,5])))
4191         self.assertTrue(a4 is None)
4192         self.assertTrue(a5 is None)
4193         a6,a7=mml2.retrieveFamilyIdsOnCells()
4194         self.assertTrue(a6.isEqual(DataArrayInt([-3,-7,-12,13])))
4195         self.assertTrue(not a7) # copy here because profile on cells
4196         a8,a9=mml2.retrieveNumberIdsOnCells()
4197         self.assertTrue(a8 is None)
4198         self.assertTrue(a9) # no copy here because no number field
4199         a10,a11=mml2.retrieveFamilyIdsOnNodes()
4200         self.assertTrue(a10.isEqual(DataArrayInt([5,6,7,9,10,13])))
4201         self.assertTrue(not a11) # copy here
4202         a12,a13=mml2.retrieveNumberIdsOnNodes()
4203         self.assertTrue(a12 is None)
4204         self.assertTrue(a13) # no copy here because no number field
4205         #
4206         fff0=allFMTSLeavesPerCommonSupport1[2][0][0][0]
4207         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff0,mst)
4208         fff0.loadArraysIfNecessary()
4209         v=mml2.buildDataArray(fsst,fields,fff0.getUndergroundDataArray())
4210         self.assertEqual(fff0.getName(),"f0Node")
4211         self.assertEqual(v.getHiddenCppPointer(),fff0.getUndergroundDataArray().getHiddenCppPointer())
4212         vExp=DataArrayDouble([0.,1.,2.,3.,4.,5.])
4213         self.assertTrue(v.isEqual(vExp,1e-12)) # <- THE test is here !!!
4214         ###
4215         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4216         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4217         mml2=mml.prepare()
4218         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4219         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4220         self.assertTrue(not ncc)
4221         self.assertTrue(a0.isEqual(DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(3,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(2,2,0),(3,2,0),(2,3,0),(3,3,0)]),1e-12))
4222         self.assertTrue(a1.isEqual(DataArrayByte([5,5,9,9,9,9])))
4223         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,13,18,23])))
4224         self.assertTrue(a3.isEqual(DataArrayInt([3,2,6,3,3,6,7,3,4,0,4,5,1,4,1,5,6,2,4,6,8,9,7,4,8,10,11,9])))
4225         self.assertTrue(a4 is None)
4226         self.assertTrue(a5 is None)
4227         fff1=allFMTSLeavesPerCommonSupport1[0][0][0][0]
4228         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff1,mst)
4229         fff1.loadArraysIfNecessary()
4230         v=mml2.buildDataArray(fsst,fields,fff1.getUndergroundDataArray())
4231         self.assertEqual(fff1.getName(),"f2Cell")
4232         self.assertNotEqual(v.getHiddenCppPointer(),fff0.getUndergroundDataArray().getHiddenCppPointer())
4233         vExp=DataArrayDouble([2,3,0,1,4,5])
4234         self.assertTrue(v.isEqual(vExp,1e-12))
4235         fff2=allFMTSLeavesPerCommonSupport1[0][0][1][0]
4236         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff2,mst)
4237         fff2.loadArraysIfNecessary()
4238         v=mml2.buildDataArray(fsst,fields,fff2.getUndergroundDataArray())
4239         self.assertEqual(fff2.getName(),"f1Node")
4240         self.assertNotEqual(v.getHiddenCppPointer(),fff0.getUndergroundDataArray().getHiddenCppPointer())
4241         vExp=DataArrayDouble([11,10,9,8,7,6,5,4,3,2,1,0])
4242         self.assertTrue(v.isEqual(vExp,1e-12))
4243         ###
4244         fcscp=allFMTSLeavesPerCommonSupport1[1][1]
4245         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4246         mml2=mml.prepare()
4247         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4248         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4249         self.assertTrue(ncc)# here all the 16 nodes are taken
4250         self.assertTrue(a0.isEqual(DataArrayDouble([(0.,0.,0.),(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.)]),1e-12))
4251         self.assertTrue(a1.isEqual(DataArrayByte([1,1,5,5,9,9,9,9])))
4252         self.assertTrue(a2.isEqual(DataArrayInt([0,2,4,8,12,17,22,27])))
4253         self.assertTrue(a3.isEqual(DataArrayInt([1,8,1,13,3,2,6,3,3,6,7,3,4,0,4,5,1,4,1,5,6,2,4,6,10,11,7,4,10,14,15,11])))
4254         self.assertTrue(a4 is None)
4255         self.assertTrue(a5 is None)
4256         fff3=allFMTSLeavesPerCommonSupport1[1][0][0][0]
4257         fsst=MEDFileField1TSStructItem.BuildItemFrom(fff3,mst)
4258         fff3.loadArraysIfNecessary()
4259         v=mml2.buildDataArray(fsst,fields,fff3.getUndergroundDataArray())
4260         self.assertEqual(fff3.getName(),"f3Cell")
4261         self.assertNotEqual(v.getHiddenCppPointer(),fff0.getUndergroundDataArray().getHiddenCppPointer())
4262         vExp=DataArrayDouble([-1.1,-3.1,5,4,3,2,1,0])
4263         self.assertTrue(v.isEqual(vExp,1e-12))
4264         pass
4265
4266     def test29(self):
4267         """ This test focused on HEXA27 cell for which the MED numbering is not equal to the VTK numbering. So here the HEXA27 cell is those in MED file documentation (reference element).
4268         """
4269         fname="ForMEDReader29.med"
4270         coo=DataArrayDouble([[0.,2.,2.],[0.,0.,2.],[2.,0.,2.],[2.,2.,2.],[0.,2.,0.],[0.,0.,0.],[2.,0.,0.],[2.,2.,0.], [0.,1.,2.],[1.,0.,2.],[2.,1.,2.],[1.,2.,2.], [0.,1.,0.],[1.,0.,0.],[2.,1.,0.],[1.,2.,0.], [0.,2.,1.],[0.,0.,1.],[2.,0.,1.],[2.,2.,1.], [1.,1.,2.], [0.,1.,1.],[1.,0.,1.],[2.,1.,1.],[1.,2.,1.], [1.,1.,0.], [1.,1.,1.]])
4271         m=MEDCouplingUMesh("mesh",3) ; m.setCoords(coo)
4272         m.allocateCells()
4273         # MED = [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,25,26]
4274         # VTK = [0,1,2,3,4,5,6,7, 8,9,10,11,12,13,14,15,16,17,18,19,24,22,21,23,20,25,26]
4275         m.insertNextCell(NORM_HEXA27,[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,25,26])
4276         fCell=MEDCouplingFieldDouble(ON_CELLS) ; fCell.setName("fCell")
4277         arrCell=DataArrayDouble([7.]) ; arrCell.setInfoOnComponent(0,"smth") ; fCell.setArray(arrCell)
4278         fCell.setMesh(m)
4279         MEDLoader.WriteField(fname,fCell,True)
4280         refCoo=[-1.,-1.,-1.,-1.,1.,-1.,1.,1.,-1.,1.,-1.,-1.,-1.,-1.,1.,-1.,1.,1.,1.,1.,1.,1.,-1.,1.,-1.,0.,-1.,0.,1.,-1.,1.,0.,-1.,0.,-1.,-1.,-1.,0.,1.,0.,1.,1.,1.,0.,1.,0.,-1.,1.,-1.,-1.,0.,-1.,1.,0.,1.,1.,0.,1.,-1.,0.,0.,0.,-1.,-1.,0.,0.,0.,1.,0.,1.,0.,0.,0.,-1.,0.,0.,0.,1.,0.,0.,0.]
4281         weights=[0.1714677640603571,0.27434842249657115,0.1714677640603571,0.27434842249657115,0.43895747599451346,0.27434842249657115,0.1714677640603571,0.27434842249657115,0.1714677640603571,0.27434842249657115,0.43895747599451346,0.27434842249657115,0.43895747599451346,0.7023319615912209,0.43895747599451346,0.27434842249657115,0.43895747599451346,0.27434842249657115,0.1714677640603571,0.27434842249657115,0.1714677640603571,0.27434842249657115,0.43895747599451346,0.27434842249657115,0.1714677640603571,0.27434842249657115,0.1714677640603571]
4282         gCoords=[-0.774596669241483,-0.774596669241483,-0.774596669241483,-0.774596669241483,-0.774596669241483,0.0,-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.0,-0.774596669241483,-0.774596669241483,0.0,0.0,-0.774596669241483,0.0,0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,-0.774596669241483,0.774596669241483,0.0,-0.774596669241483,0.774596669241483,0.774596669241483,0.0,-0.774596669241483,-0.774596669241483,0.0,-0.774596669241483,0.0,0.0,-0.774596669241483,0.774596669241483,0.0,0.0,-0.774596669241483,0.0,0.0,0.0,0.0,0.0,0.774596669241483,0.0,0.774596669241483,-0.774596669241483,0.0,0.774596669241483,0.0,0.0,0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,-0.774596669241483,0.774596669241483,-0.774596669241483,0.0,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,0.0,-0.774596669241483,0.774596669241483,0.0,0.0,0.774596669241483,0.0,0.774596669241483,0.774596669241483,0.774596669241483,-0.774596669241483,0.774596669241483,0.774596669241483,0.0,0.774596669241483,0.774596669241483,0.774596669241483]
4283         fGauss=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fGauss.setName("fGauss")
4284         fGauss.setMesh(m)
4285         fGauss.setGaussLocalizationOnType(NORM_HEXA27,refCoo,gCoords,weights)
4286         arrGauss=DataArrayDouble(fGauss.getNumberOfTuplesExpected()) ; arrGauss.setInfoOnComponent(0,"gaussc") ; arrGauss.iota()
4287         fGauss.setArray(arrGauss)
4288         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,fGauss)
4289         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4290         ms=MEDFileMeshes(fname)
4291         fields=MEDFileFields(fname,False)
4292         fields.removeFieldsWithoutAnyTimeStep()
4293         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4294         allFMTSLeavesToDisplay=[]
4295         for fields in fields_per_mesh:
4296             allFMTSLeavesToDisplay2=[]
4297             for fmts in fields:
4298                 tmp=fmts.splitDiscretizations()
4299                 for itmp in tmp:
4300                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4301                     pass
4302                 allFMTSLeavesToDisplay2+=tmp
4303                 pass
4304             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4305             pass
4306         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4307         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
4308         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4309         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
4310         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
4311         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
4312         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
4313         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),2)
4314         #
4315         mst=MEDFileMeshStruct.New(ms[0])
4316         #
4317         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4318         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4319         mml2=mml.prepare()
4320         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4321         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4322         self.assertTrue(a0.isEqual(coo,1e-12))
4323         self.assertTrue(a1.isEqual(DataArrayByte([29])))
4324         self.assertTrue(a2.isEqual(DataArrayInt([0])))
4325         # the connectivity must be not a iota as declared in m.insertNextCell
4326         self.assertTrue(a3.isEqual(DataArrayInt([27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,24,22,21,23,20,25,26])))# the test is on this line to check that connectivity has been processed for HEXA27
4327         self.assertTrue(a4 is None)
4328         self.assertTrue(a5 is None)
4329         ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][0]
4330         fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
4331         ffCell.loadArraysIfNecessary()
4332         v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
4333         self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
4334         self.assertEqual(ffCell.getName(),"fCell")
4335         self.assertTrue(v.isEqual(arrCell,1e-12)) ; self.assertTrue(v.isEqualWithoutConsideringStr(DataArrayDouble([7.]),1e-12)) ; self.assertEqual(v.getInfoOnComponents(),["smth"])
4336         del ffCell
4337         #
4338         ffGauss=allFMTSLeavesPerCommonSupport1[0][0][1][0]
4339         fsst=MEDFileField1TSStructItem.BuildItemFrom(ffGauss,mst)
4340         ffGauss.loadArraysIfNecessary()
4341         v=mml2.buildDataArray(fsst,fields,ffGauss.getUndergroundDataArray())
4342         self.assertEqual(v.getHiddenCppPointer(),ffGauss.getUndergroundDataArray().getHiddenCppPointer())
4343         self.assertEqual(ffGauss.getName(),"fGauss")
4344         self.assertTrue(v.isEqual(arrGauss,1e-12)) ; self.assertTrue(v.isEqualWithoutConsideringStr(DataArrayDouble(range(27)),1e-12)) ; self.assertEqual(v.getInfoOnComponents(),["gaussc"])
4345         ffGauss=allFMTSLeavesPerCommonSupport1[0][0][1][0]
4346         pass
4347
4348     def test30(self):
4349         """ This test is focused on cartesian meshes. Here the cartesian mesh "CartMesh" has a field on HEXA8 (FieldOnCells) and a field on QUAD4 (FieldOnFaces).
4350         So the first one (FieldOnCells) lies on a cartesian mesh whereas the second one lies on unstructured one.
4351         """
4352         fname="ForMEDReader30.med"
4353         c=MEDCouplingCMesh()
4354         arrX=DataArrayDouble(3) ; arrX.iota()
4355         arrY=DataArrayDouble(4) ; arrY.iota()
4356         arrZ=DataArrayDouble(5) ; arrZ.iota()
4357         c.setCoords(arrX,arrY,arrZ)
4358         c.setName("CartMesh")
4359         cc=MEDFileCMesh()
4360         cc.setMesh(c)
4361         tmpFacesMesh=c.build1SGTSubLevelMesh()
4362         famIdFaces=DataArrayInt(98) ; famIdFaces[:36]=-1 ; famIdFaces[36:68]=-2 ; famIdFaces[68:]=-3
4363         famIdCells=DataArrayInt(24) ; famIdCells[:]=0
4364         #cc.setFamilyFieldArr(0,famIdCells)
4365         #cc.setFamilyFieldArr(-1,famIdFaces)
4366         cc.addFamily("FacesX",-1) ; cc.addFamily("FacesY",-2) ; cc.addFamily("FacesZ",-3)
4367         cc.setFamiliesOnGroup("FacesX1",["FacesX"])
4368         cc.setFamiliesOnGroup("FacesY1",["FacesY"])
4369         cc.setFamiliesOnGroup("FacesZ1",["FacesZ"])
4370         #
4371         fmts0=MEDFileFieldMultiTS()
4372         fmts1=MEDFileFieldMultiTS()
4373         for i in xrange(30):
4374             f1ts=MEDFileField1TS()
4375             fFaces=MEDCouplingFieldDouble(ON_CELLS) ; fFaces.setName("FieldOnFaces")
4376             arr=DataArrayDouble(98) ; arr.iota() ; arr[i]=100.
4377             fFaces.setArray(arr)
4378             fFaces.setTime(float(i)+0.1,i,-1)
4379             fFaces.setMesh(tmpFacesMesh)
4380             f1ts.setFieldNoProfileSBT(fFaces)
4381             fmts0.pushBackTimeStep(f1ts)
4382             #
4383             f1ts=MEDFileField1TS()
4384             fCells=MEDCouplingFieldDouble(ON_CELLS) ; fCells.setName("FieldOnCells")
4385             arr=DataArrayDouble(24) ; arr.iota() ; arr[i%24]=30.
4386             fCells.setArray(arr)
4387             fCells.setTime(float(i)+0.1,i,-1)
4388             fCells.setMesh(c)
4389             f1ts.setFieldNoProfileSBT(fCells)
4390             fmts1.pushBackTimeStep(f1ts)
4391             pass
4392         fs=MEDFileFields()
4393         fs.pushField(fmts0)
4394         fs.pushField(fmts1)
4395         cc.write(fname,2)
4396         fs.write(fname,0)
4397         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4398         ms=MEDFileMeshes(fname)
4399         fields=MEDFileFields(fname,False)
4400         fields.removeFieldsWithoutAnyTimeStep()
4401         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4402         allFMTSLeavesToDisplay=[]
4403         for fields in fields_per_mesh:
4404             allFMTSLeavesToDisplay2=[]
4405             for fmts in fields:
4406                 tmp=fmts.splitDiscretizations()
4407                 for itmp in tmp:
4408                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4409                     pass
4410                 allFMTSLeavesToDisplay2+=tmp
4411                 pass
4412             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4413             pass
4414         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4415         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
4416         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4417         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
4418         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
4419         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
4420         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),2)
4421         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
4422         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),1)
4423         #
4424         mst=MEDFileMeshStruct.New(ms[0])
4425         #
4426         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4427         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4428         mml2=mml.prepare()
4429         self.assertTrue(isinstance(mml2,MEDCMeshMultiLev)) # here CMesh is important
4430         (a,b,c),d=mml2.buildVTUArrays()
4431         self.assertTrue(d)#d is True because the a,b and c are directly those in the internal data structure
4432         self.assertTrue(a.isEqual(arrX,1e-12))
4433         self.assertTrue(b.isEqual(arrY,1e-12))
4434         self.assertTrue(c.isEqual(arrZ,1e-12))
4435         for i in xrange(30):
4436             ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
4437             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
4438             ffCell.loadArraysIfNecessary()
4439             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
4440             self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
4441             myarr=DataArrayDouble(24) ; myarr.iota() ; myarr[i%24]=30.
4442             self.assertEqual(ffCell.getName(),"FieldOnCells")
4443             self.assertTrue(v.isEqual(myarr,1e-12))
4444             pass
4445         #
4446         fcscp=allFMTSLeavesPerCommonSupport1[1][1]
4447         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4448         mml2=mml.prepare()
4449         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) # here UMesh is important
4450         ref=ms[0].getImplicitFaceMesh().getCoords().getHiddenCppPointer()
4451         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4452         self.assertEqual(ref,a0.getHiddenCppPointer())
4453         self.assertTrue(ncc)
4454         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
4455         self.assertTrue(a2.isEqual(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,280,285,290,295,300,305,310,315,320,325,330,335,340,345,350,355,360,365,370,375,380,385,390,395,400,405,410,415,420,425,430,435,440,445,450,455,460,465,470,475,480,485])))
4456         self.assertTrue(a3.isEqual(DataArrayInt([4,0,12,15,3,4,12,24,27,15,4,24,36,39,27,4,36,48,51,39,4,3,15,18,6,4,15,27,30,18,4,27,39,42,30,4,39,51,54,42,4,6,18,21,9,4,18,30,33,21,4,30,42,45,33,4,42,54,57,45,4,1,13,16,4,4,13,25,28,16,4,25,37,40,28,4,37,49,52,40,4,4,16,19,7,4,16,28,31,19,4,28,40,43,31,4,40,52,55,43,4,7,19,22,10,4,19,31,34,22,4,31,43,46,34,4,43,55,58,46,4,2,14,17,5,4,14,26,29,17,4,26,38,41,29,4,38,50,53,41,4,5,17,20,8,4,17,29,32,20,4,29,41,44,32,4,41,53,56,44,4,8,20,23,11,4,20,32,35,23,4,32,44,47,35,4,44,56,59,47,4,0,12,13,1,4,12,24,25,13,4,24,36,37,25,4,36,48,49,37,4,1,13,14,2,4,13,25,26,14,4,25,37,38,26,4,37,49,50,38,4,3,15,16,4,4,15,27,28,16,4,27,39,40,28,4,39,51,52,40,4,4,16,17,5,4,16,28,29,17,4,28,40,41,29,4,40,52,53,41,4,6,18,19,7,4,18,30,31,19,4,30,42,43,31,4,42,54,55,43,4,7,19,20,8,4,19,31,32,20,4,31,43,44,32,4,43,55,56,44,4,9,21,22,10,4,21,33,34,22,4,33,45,46,34,4,45,57,58,46,4,10,22,23,11,4,22,34,35,23,4,34,46,47,35,4,46,58,59,47,4,0,1,4,3,4,3,4,7,6,4,6,7,10,9,4,1,2,5,4,4,4,5,8,7,4,7,8,11,10,4,12,13,16,15,4,15,16,19,18,4,18,19,22,21,4,13,14,17,16,4,16,17,20,19,4,19,20,23,22,4,24,25,28,27,4,27,28,31,30,4,30,31,34,33,4,25,26,29,28,4,28,29,32,31,4,31,32,35,34,4,36,37,40,39,4,39,40,43,42,4,42,43,46,45,4,37,38,41,40,4,40,41,44,43,4,43,44,47,46,4,48,49,52,51,4,51,52,55,54,4,54,55,58,57,4,49,50,53,52,4,52,53,56,55,4,55,56,59,58])))
4457         self.assertTrue(a4 is None)
4458         self.assertTrue(a5 is None)
4459         for i in xrange(30):
4460             ffCell=allFMTSLeavesPerCommonSupport1[1][0][0][i]
4461             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
4462             ffCell.loadArraysIfNecessary()
4463             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
4464             self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
4465             myarr=DataArrayDouble(98) ; myarr.iota() ; myarr[i]=100.
4466             self.assertEqual(ffCell.getName(),"FieldOnFaces")
4467             self.assertTrue(v.isEqual(myarr,1e-12))
4468             pass
4469         pass
4470
4471     def test31(self):
4472         """non regression test of EDF 7972"""
4473         fname="ForMEDReader31.med"
4474         c=MEDCouplingCMesh()
4475         arrX=DataArrayDouble(3) ; arrX.iota()
4476         arrY=DataArrayDouble(4) ; arrY.iota()
4477         arrZ=DataArrayDouble(5) ; arrZ.iota()
4478         c.setCoords(arrX,arrY,arrZ)
4479         c.setName("CartMesh")
4480         cc=MEDFileCMesh()
4481         cc.setMesh(c)
4482         famIdCells=DataArrayInt(24) ; famIdCells[:]=0
4483         cc.setFamilyFieldArr(0,famIdCells)
4484         #cc.setFamilyFieldArr(-1,famIdFaces)
4485         cc.addFamily("FacesX",-1) ; cc.addFamily("FacesY",-2) ; cc.addFamily("FacesZ",-3)
4486         cc.setFamiliesOnGroup("FacesX1",["FacesX"])
4487         cc.setFamiliesOnGroup("FacesY1",["FacesY"])
4488         cc.setFamiliesOnGroup("FacesZ1",["FacesZ"])
4489         fmts0=MEDFileFieldMultiTS()
4490         fmts1=MEDFileFieldMultiTS()
4491         pfl=DataArrayInt(11) ; pfl.iota() ; pfl.setName("PflOnHECA8")
4492         for i in xrange(30):
4493             f1ts=MEDFileField1TS()
4494             fFaces=MEDCouplingFieldDouble(ON_CELLS) ; fFaces.setName("FieldOnCells")
4495             arr=DataArrayDouble(11) ; arr.iota() ; arr[i%11]=100.
4496             fFaces.setArray(arr)
4497             fFaces.setTime(float(i)+0.1,i,-1)
4498             fFaces.setMesh(c.buildUnstructured()[:11])
4499             f1ts.setFieldProfile(fFaces,cc,0,pfl)# here, a test is done to check that "NORM_HEXA8" string is not 30 times appended at the end of pfl name.
4500             self.assertEqual("PflOnHECA8",pfl.getName())
4501             fmts0.pushBackTimeStep(f1ts)
4502             pass
4503         fs=MEDFileFields()
4504         fs.pushField(fmts0)
4505         cc.write(fname,2)
4506         fs.write(fname,0)
4507         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4508         ms=MEDFileMeshes(fname)
4509         fields=MEDFileFields(fname,False)
4510         fields.removeFieldsWithoutAnyTimeStep()
4511         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4512         allFMTSLeavesToDisplay=[]
4513         for fields in fields_per_mesh:
4514             allFMTSLeavesToDisplay2=[]
4515             for fmts in fields:
4516                 tmp=fmts.splitDiscretizations()
4517                 for itmp in tmp:
4518                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4519                     pass
4520                 allFMTSLeavesToDisplay2+=tmp
4521                 pass
4522             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4523             pass
4524         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4525         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
4526         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4527         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
4528         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
4529         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
4530         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
4531         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
4532         #
4533         mst=MEDFileMeshStruct.New(ms[0])
4534         #
4535         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4536         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4537         mml2=mml.prepare()
4538         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) # here UMesh is important
4539         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4540         self.assertTrue(not ncc)# here ncc=False because the coordinates are not in ms neither in children. This is the most important line in the test.
4541         self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,2.,2.,0.,0.,3.,0.,1.,3.,0.,2.,3.,0.,0.,0.,1.,1.,0.,1.,2.,0.,1.,0.,1.,1.,1.,1.,1.,2.,1.,1.,0.,2.,1.,1.,2.,1.,2.,2.,1.,0.,3.,1.,1.,3.,1.,2.,3.,1.,0.,0.,2.,1.,0.,2.,2.,0.,2.,0.,1.,2.,1.,1.,2.,2.,1.,2.,0.,2.,2.,1.,2.,2.,2.,2.,2.,0.,3.,2.,1.,3.,2.,2.,3.,2.,0.,0.,3.,1.,0.,3.,2.,0.,3.,0.,1.,3.,1.,1.,3.,2.,1.,3.,0.,2.,3.,1.,2.,3.,2.,2.,3.,0.,3.,3.,1.,3.,3.,2.,3.,3.,0.,0.,4.,1.,0.,4.,2.,0.,4.,0.,1.,4.,1.,1.,4.,2.,1.,4.,0.,2.,4.,1.,2.,4.,2.,2.,4.,0.,3.,4.,1.,3.,4.,2.,3.,4.],60,3),1e-12))
4542         self.assertTrue(a1.isEqual(DataArrayByte([12,12,12,12,12,12,12,12,12,12,12])))
4543         self.assertTrue(a2.isEqual(DataArrayInt([0,9,18,27,36,45,54,63,72,81,90])))
4544         self.assertTrue(a3.isEqual(DataArrayInt([8,1,0,3,4,13,12,15,16,8,2,1,4,5,14,13,16,17,8,4,3,6,7,16,15,18,19,8,5,4,7,8,17,16,19,20,8,7,6,9,10,19,18,21,22,8,8,7,10,11,20,19,22,23,8,13,12,15,16,25,24,27,28,8,14,13,16,17,26,25,28,29,8,16,15,18,19,28,27,30,31,8,17,16,19,20,29,28,31,32,8,19,18,21,22,31,30,33,34])))
4545         self.assertTrue(a4 is None)
4546         self.assertTrue(a5 is None)
4547         for i in xrange(30):
4548             ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
4549             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
4550             ffCell.loadArraysIfNecessary()
4551             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
4552             # self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer()) # to be improved... maybe this line could be true
4553             myarr=DataArrayDouble(11) ; myarr.iota() ; myarr[i%11]=100.
4554             self.assertEqual(ffCell.getName(),"FieldOnCells")
4555             self.assertTrue(v.isEqual(myarr,1e-12))
4556             pass
4557         pass
4558
4559     def test32(self):
4560         """ This test is close to test30 except that here the profiles on dim-1 of structured mesh is considered here."""
4561         fname="ForMEDReader32.med"
4562         c=MEDCouplingCMesh()
4563         arrX=DataArrayDouble(3) ; arrX.iota()
4564         arrY=DataArrayDouble(4) ; arrY.iota()
4565         arrZ=DataArrayDouble(5) ; arrZ.iota()
4566         c.setCoords(arrX,arrY,arrZ)
4567         c.setName("CartMesh")
4568         cc=MEDFileCMesh()
4569         cc.setMesh(c)
4570         tmpFacesMesh=c.build1SGTSubLevelMesh()
4571         famIdFaces=DataArrayInt(98) ; famIdFaces[:36]=-1 ; famIdFaces[36:68]=-2 ; famIdFaces[68:]=-3
4572         famIdCells=DataArrayInt(24) ; famIdCells[:]=0
4573         cc.setFamilyFieldArr(0,famIdCells)
4574         #cc.setFamilyFieldArr(-1,famIdFaces)
4575         cc.addFamily("FacesX",-1) ; cc.addFamily("FacesY",-2) ; cc.addFamily("FacesZ",-3)
4576         cc.setFamiliesOnGroup("FacesX1",["FacesX"])
4577         cc.setFamiliesOnGroup("FacesY1",["FacesY"])
4578         cc.setFamiliesOnGroup("FacesZ1",["FacesZ"])
4579         fmts0=MEDFileFieldMultiTS()
4580         fmts1=MEDFileFieldMultiTS()
4581         pfl=DataArrayInt(31) ; pfl.iota() ; pfl.setName("PflOnQUAD4")
4582         for i in xrange(30):
4583             f1ts=MEDFileField1TS()
4584             fFaces=MEDCouplingFieldDouble(ON_CELLS) ; fFaces.setName("FieldOnFaces")
4585             arr=DataArrayDouble(31) ; arr.iota() ; arr[i]=100.
4586             fFaces.setArray(arr)
4587             fFaces.setTime(float(i)+0.1,i,-1)
4588             fFaces.setMesh(tmpFacesMesh[:31])
4589             f1ts.setFieldProfile(fFaces,cc,-1,pfl)# here, a test is done to check that "NORM_QUAD4" string is not 30 times appended at the end of pfl name.
4590             self.assertEqual("PflOnQUAD4",pfl.getName())
4591             fmts0.pushBackTimeStep(f1ts)
4592             #
4593             f1ts=MEDFileField1TS()
4594             fCells=MEDCouplingFieldDouble(ON_CELLS) ; fCells.setName("FieldOnCells")
4595             arr=DataArrayDouble(24) ; arr.iota() ; arr[i%24]=30.
4596             fCells.setArray(arr)
4597             fCells.setTime(float(i)+0.1,i,-1)
4598             fCells.setMesh(c)
4599             f1ts.setFieldNoProfileSBT(fCells)
4600             fmts1.pushBackTimeStep(f1ts)
4601             pass
4602         fs=MEDFileFields()
4603         fs.pushField(fmts0)
4604         fs.pushField(fmts1)
4605         cc.write(fname,2)
4606         fs.write(fname,0)
4607         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4608         ms=MEDFileMeshes(fname)
4609         fields=MEDFileFields(fname,False)
4610         fields.removeFieldsWithoutAnyTimeStep()
4611         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4612         allFMTSLeavesToDisplay=[]
4613         for fields in fields_per_mesh:
4614             allFMTSLeavesToDisplay2=[]
4615             for fmts in fields:
4616                 tmp=fmts.splitDiscretizations()
4617                 for itmp in tmp:
4618                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4619                     pass
4620                 allFMTSLeavesToDisplay2+=tmp
4621                 pass
4622             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4623             pass
4624         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4625         self.assertEqual(len(allFMTSLeavesToDisplay[0]),2)
4626         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4627         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
4628         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),2)
4629         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
4630         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),2)
4631         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
4632         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),1)
4633         #
4634         mst=MEDFileMeshStruct.New(ms[0])
4635         #
4636         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4637         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4638         mml2=mml.prepare()
4639         self.assertTrue(isinstance(mml2,MEDCMeshMultiLev)) # here CMesh is important
4640         (a,b,c),d=mml2.buildVTUArrays()
4641         self.assertTrue(d)#d is True because the a,b and c are directly those in the internal data structure
4642         self.assertTrue(a.isEqual(arrX,1e-12))
4643         self.assertTrue(b.isEqual(arrY,1e-12))
4644         self.assertTrue(c.isEqual(arrZ,1e-12))
4645         for i in xrange(30):
4646             ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
4647             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
4648             ffCell.loadArraysIfNecessary()
4649             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
4650             self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
4651             myarr=DataArrayDouble(24) ; myarr.iota() ; myarr[i%24]=30.
4652             self.assertEqual(ffCell.getName(),"FieldOnCells")
4653             self.assertTrue(v.isEqual(myarr,1e-12))
4654             pass
4655         #
4656         fcscp=allFMTSLeavesPerCommonSupport1[1][1]
4657         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4658         mml2=mml.prepare()
4659         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev)) # here UMesh is important
4660         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4661         self.assertTrue(ncc)# True because, the coords are computed by the implicit unstructured level -1 structured mesh
4662         self.assertTrue(a0.isEqual(DataArrayDouble([0.,0.,0.,1.,0.,0.,2.,0.,0.,0.,1.,0.,1.,1.,0.,2.,1.,0.,0.,2.,0.,1.,2.,0.,2.,2.,0.,0.,3.,0.,1.,3.,0.,2.,3.,0.,0.,0.,1.,1.,0.,1.,2.,0.,1.,0.,1.,1.,1.,1.,1.,2.,1.,1.,0.,2.,1.,1.,2.,1.,2.,2.,1.,0.,3.,1.,1.,3.,1.,2.,3.,1.,0.,0.,2.,1.,0.,2.,2.,0.,2.,0.,1.,2.,1.,1.,2.,2.,1.,2.,0.,2.,2.,1.,2.,2.,2.,2.,2.,0.,3.,2.,1.,3.,2.,2.,3.,2.,0.,0.,3.,1.,0.,3.,2.,0.,3.,0.,1.,3.,1.,1.,3.,2.,1.,3.,0.,2.,3.,1.,2.,3.,2.,2.,3.,0.,3.,3.,1.,3.,3.,2.,3.,3.,0.,0.,4.,1.,0.,4.,2.,0.,4.,0.,1.,4.,1.,1.,4.,2.,1.,4.,0.,2.,4.,1.,2.,4.,2.,2.,4.,0.,3.,4.,1.,3.,4.,2.,3.,4.],60,3),1e-12))
4663         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
4664         self.assertTrue(a2.isEqual(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])))
4665         self.assertTrue(a3.isEqual(DataArrayInt([4,0,12,15,3,4,12,24,27,15,4,24,36,39,27,4,36,48,51,39,4,3,15,18,6,4,15,27,30,18,4,27,39,42,30,4,39,51,54,42,4,6,18,21,9,4,18,30,33,21,4,30,42,45,33,4,42,54,57,45,4,1,13,16,4,4,13,25,28,16,4,25,37,40,28,4,37,49,52,40,4,4,16,19,7,4,16,28,31,19,4,28,40,43,31,4,40,52,55,43,4,7,19,22,10,4,19,31,34,22,4,31,43,46,34,4,43,55,58,46,4,2,14,17,5,4,14,26,29,17,4,26,38,41,29,4,38,50,53,41,4,5,17,20,8,4,17,29,32,20,4,29,41,44,32])))
4666         self.assertTrue(a4 is None)
4667         self.assertTrue(a5 is None)
4668         a6,a7=mml2.retrieveFamilyIdsOnCells()
4669         self.assertTrue(a6 is None)
4670         self.assertTrue(a7)
4671         for i in xrange(30):
4672             ffCell=allFMTSLeavesPerCommonSupport1[1][0][0][i]
4673             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
4674             ffCell.loadArraysIfNecessary()
4675             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
4676             self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
4677             myarr=DataArrayDouble(31) ; myarr.iota() ; myarr[i]=100.
4678             self.assertEqual(ffCell.getName(),"FieldOnFaces")
4679             self.assertTrue(v.isEqual(myarr,1e-12))
4680             pass
4681         pass
4682     
4683     def test33(self):
4684         """Non regression test concerning polygons. Thanks Adrien. This bug can't be shown by simply reading an displaying a MED file containing only polygons. A filter must be applied on it to show it. The a2 array was responsible of that bug."""
4685         fname="ForMEDReader33.med"
4686         fieldName="ACellField"
4687         coo=DataArrayDouble([(5.5,0.5),(5.5,-0.5),(6.5,0.5),(6.5,-0.5),(6.5,1.5),(7.5,0.5),(7.5,-0.5),(7.5,1.5),(7.5,2.5),(8.5,0.5),(8.5,-0.5),(8.5,1.5),(8.5,2.5),(8.5,3.5),(8.55,0.5),(8.55,-0.5),(8.55,1.5),(8.55,2.5),(8.55,3.5)])
4688         m=MEDCouplingUMesh("mesh",2)
4689         m.setCoords(coo)
4690         m.allocateCells()
4691         for i,c in enumerate([(1,0,2,3),(3,2,5,6),(2,4,7,5),(6,5,9,10),(5,7,11,9),(7,8,12,11),(10,9,14,15),(9,11,16,14),(11,12,17,16),(12,13,18,17)]):
4692             if i<6:
4693                 typ=NORM_QUAD4
4694                 pass
4695             else:
4696                 typ=NORM_POLYGON
4697                 pass
4698             m.insertNextCell(typ,c)
4699             pass
4700         mm=MEDFileUMesh()
4701         mm.setMeshAtLevel(0,m)
4702         mm.write(fname,2)
4703         for i in xrange(15):
4704             fCell0=MEDCouplingFieldDouble(ON_CELLS) ; fCell0.setTime(float(i)+0.1,i,0)
4705             fCell0.setName(fieldName) ; fCell0.setMesh(m)
4706             arr=DataArrayDouble(m.getNumberOfCells()) ; arr.iota(0) ; arr[i%10]=100.
4707             fCell0.setArray(arr) ; arr.setInfoOnComponents(["Comp1 [m]"])
4708             fCell0.checkCoherency()
4709             MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,fCell0)
4710             pass
4711         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4712         ms=MEDFileMeshes(fname)
4713         fields=MEDFileFields(fname,False)
4714         fields.removeFieldsWithoutAnyTimeStep()
4715         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4716         allFMTSLeavesToDisplay=[]
4717         for fields in fields_per_mesh:
4718             allFMTSLeavesToDisplay2=[]
4719             for fmts in fields:
4720                 tmp=fmts.splitDiscretizations()
4721                 for itmp in tmp:
4722                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4723                     pass
4724                 allFMTSLeavesToDisplay2+=tmp
4725                 pass
4726             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4727             pass
4728         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4729         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
4730         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4731         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
4732         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
4733         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
4734         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),1)
4735         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),1)
4736         #
4737         mst=MEDFileMeshStruct.New(ms[0])
4738         #
4739         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4740         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4741         mml2=mml.prepare()
4742         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4743         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4744         self.assertTrue(not ncc)# false beacause 2D in MED file
4745         self.assertTrue(a0.isEqual(DataArrayDouble([(5.5,0.5,0),(5.5,-0.5,0),(6.5,0.5,0),(6.5,-0.5,0),(6.5,1.5,0),(7.5,0.5,0),(7.5,-0.5,0),(7.5,1.5,0),(7.5,2.5,0),(8.5,0.5,0),(8.5,-0.5,0),(8.5,1.5,0),(8.5,2.5,0),(8.5,3.5,0),(8.55,0.5,0),(8.55,-0.5,0),(8.55,1.5,0),(8.55,2.5,0),(8.55,3.5,0)]),1e-12))
4746         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,7,7,7,7])))
4747         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45])))# the bug was here.
4748         self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,2,3,4,3,2,5,6,4,2,4,7,5,4,6,5,9,10,4,5,7,11,9,4,7,8,12,11,4,10,9,14,15,4,9,11,16,14,4,11,12,17,16,4,12,13,18,17])))
4749         self.assertTrue(a4 is None)
4750         self.assertTrue(a5 is None)
4751         for i in xrange(15):
4752             ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
4753             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
4754             ffCell.loadArraysIfNecessary()
4755             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
4756             self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
4757             myarr=DataArrayDouble(10) ; myarr.iota() ; myarr[i%10]=100. ; myarr.setInfoOnComponent(0,"Comp1 [m]")
4758             self.assertEqual(ffCell.getName(),fieldName)
4759             self.assertTrue(v.isEqual(myarr,1e-12))
4760             pass
4761         pass
4762
4763     def test34(self):
4764         """ This test is the thirs ultimate test (base on test12) for the profiles with gauss points.
4765         This test highlight the hidden imp linked to bug #8655.
4766         This test is close to test11 but here a 2nd field on cells without profile. So here the mesh is expected to be the same than m.
4767         """
4768         fname="ForMEDReader34.med"
4769         m=MEDCouplingCMesh("mesh")
4770         arr=DataArrayDouble(5) ; arr.iota()
4771         m.setCoords(arr,arr)
4772         m=m.buildUnstructured() ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
4773         mm=MEDFileUMesh() ; mm.setMeshes([m])
4774         #
4775         fieldName0="zeField0"
4776         fieldName1="zeField1"
4777         fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
4778         for i in xrange(5):
4779             f=MEDFileField1TS()
4780             fNode=MEDCouplingFieldDouble(ON_GAUSS_PT) ; fNode.setTime(float(i),i,0)
4781             fNode.setName(fieldName0) ; fNode.setMesh(m)
4782             fNode.setGaussLocalizationOnCells([0,2,3,4,7,15],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7],[0.8,0.2])
4783             fNode.setGaussLocalizationOnCells([1,5,8,9],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3],[0.8,0.05,0.1,0.04,0.01])
4784             fNode.setGaussLocalizationOnCells([6,10,13],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2],[0.8,0.05,0.1,0.04])
4785             fNode.setGaussLocalizationOnCells([11,12,14],[-1.,-1.,1.,-1.,1.,1.,-1.,1.],[0.5,0.5,0.7,0.7,0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.8,0.8],[0.8,0.05,0.1,0.01,0.02,0.005,0.005])
4786             arr=DataArrayDouble(2*(2*6+5*4+4*3+7*3)) ; arr.iota(0+1000*i) ; arr.rearrange(2)
4787             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_0 [m]","Com2_0 [s^2]"]) ; fNode.checkCoherency()
4788             f.setFieldNoProfileSBT(fNode)
4789             fs0.pushBackTimeStep(f)
4790             #
4791             f=MEDFileField1TS()
4792             fNode=MEDCouplingFieldDouble(ON_CELLS) ; fNode.setTime(float(i),i,0)
4793             fNode.setName(fieldName1) ; fNode.setMesh(m)
4794             arr=DataArrayDouble(2*16) ; arr.iota(300+1000*i) ; arr.rearrange(2)
4795             fNode.setArray(arr) ; arr.setInfoOnComponents(["Comp1_1 [m]","Com2_1 [s^2]"]) ; fNode.checkCoherency()
4796             f.setFieldNoProfileSBT(fNode)
4797             fs1.pushBackTimeStep(f)
4798             pass
4799         mm.write(fname,2)
4800         fs0.write(fname,0) ; fs1.write(fname,0)
4801         a0Exp=mm.getCoords().deepCpy()
4802         del m,mm,fs0,fs1,f,fNode
4803         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4804         ms=MEDFileMeshes(fname)
4805         fields=MEDFileFields(fname,False)
4806         fields.removeFieldsWithoutAnyTimeStep()
4807         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4808         allFMTSLeavesToDisplay=[]
4809         for fields in fields_per_mesh:
4810             allFMTSLeavesToDisplay2=[]
4811             for fmts in fields:
4812                 tmp=fmts.splitDiscretizations()
4813                 for itmp in tmp:
4814                     if itmp.presenceOfMultiDiscPerGeoType():
4815                         tmp2=itmp.splitMultiDiscrPerGeoTypes()
4816                         for iii,itmp2 in enumerate(tmp2):
4817                             name="%s_%i"%(itmp2.getName(),iii)
4818                             itmp2.setName(name)
4819                             allFMTSLeavesToDisplay2.append(itmp2)
4820                             pass
4821                         pass
4822                     else:
4823                         allFMTSLeavesToDisplay2.append(itmp)
4824                         pass
4825                 pass
4826             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4827             pass
4828         # Here 2 MED fields in input and at the end 5 ! 1+4 ! 4 fields have been built from zeField0 due to subspliting per dis / per geo type
4829         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4830         self.assertEqual(len(allFMTSLeavesToDisplay[0]),5)
4831         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4832         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
4833         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),5)
4834         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
4835         self.assertEqual(len(allFMTSLeavesPerCommonSupport),5)
4836         for i in xrange(5):
4837             self.assertEqual(len(allFMTSLeavesPerCommonSupport[i][0]),1)
4838         #
4839         mst=MEDFileMeshStruct.New(ms[0])
4840         #
4841         fcscp=allFMTSLeavesPerCommonSupport[4][1]
4842         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4843         mml2=mml.prepare()
4844         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4845         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4846         self.assertTrue(not ncc)
4847         self.assertTrue(a0.isEqual(a0Exp.changeNbOfComponents(3,0.),1e-12))
4848         self.assertTrue(a1.isEqual(DataArrayByte([9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9])))
4849         self.assertTrue(a2.isEqual(DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75])))
4850         self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,5,6,4,2,1,6,7,4,3,2,7,8,4,4,3,8,9,4,6,5,10,11,4,7,6,11,12,4,8,7,12,13,4,9,8,13,14,4,11,10,15,16,4,12,11,16,17,4,13,12,17,18,4,14,13,18,19,4,16,15,20,21,4,17,16,21,22,4,18,17,22,23,4,19,18,23,24]))) # <- here the mesh is NOT renumbered : the mesh is equal to m
4851         self.assertTrue(a4 is None)
4852         self.assertTrue(a5 is None)
4853         for i in xrange(1,5):
4854             self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
4855             pass
4856         for i in xrange(5):
4857             f=allFMTSLeavesPerCommonSupport[0][0][0][i]
4858             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
4859             f.loadArraysIfNecessary()
4860             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
4861             self.assertEqual(f.getName(),fieldName0)
4862             vExp=DataArrayDouble([(0.,1.),(2.,3.),(14.,15.),(16.,17.),(18.,19.),(20.,21.),(22.,23.),(24.,25.),(44.,45.),(46.,47.),(126.,127.),(128.,129.)])
4863             vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
4864             vExp+=i*1000
4865             self.assertTrue(v.isEqual(vExp,1e-12))
4866             #
4867             f=allFMTSLeavesPerCommonSupport[1][0][0][i]
4868             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
4869             f.loadArraysIfNecessary()
4870             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
4871             self.assertEqual(f.getName(),fieldName0)
4872             vExp=DataArrayDouble([(4.,5.),(6.,7.),(8.,9.),(10.,11.),(12.,13.),(26.,27.),(28.,29.),(30.,31.),(32.,33.),(34.,35.),(48.,49.),(50.,51.),(52.,53.),(54.,55.),(56.,57.),(58.,59.),(60.,61.),(62.,63.),(64.,65.),(66.,67.)])
4873             vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
4874             vExp+=i*1000
4875             self.assertTrue(v.isEqual(vExp,1e-12))
4876             #
4877             f=allFMTSLeavesPerCommonSupport[2][0][0][i]
4878             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
4879             f.loadArraysIfNecessary()
4880             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
4881             self.assertEqual(f.getName(),fieldName0)
4882             vExp=DataArrayDouble([(36.,37.),(38.,39.),(40.,41.),(42.,43.),(68.,69.),(70.,71.),(72.,73.),(74.,75.),(104.,105.),(106.,107.),(108.,109.),(110.,111.)])
4883             vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
4884             vExp+=i*1000
4885             self.assertTrue(v.isEqual(vExp,1e-12))
4886             #
4887             f=allFMTSLeavesPerCommonSupport[3][0][0][i]
4888             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
4889             f.loadArraysIfNecessary()
4890             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
4891             self.assertEqual(f.getName(),fieldName0)
4892             vExp=DataArrayDouble([(76,77),(78,79),(80,81),(82,83),(84,85),(86,87),(88,89),(90,91),(92,93),(94,95),(96,97),(98,99),(100,101),(102,103),(112,113),(114,115),(116,117),(118,119),(120,121),(122,123),(124,125)])
4893             vExp.setInfoOnComponents(['Comp1_0 [m]','Com2_0 [s^2]'])
4894             vExp+=i*1000
4895             self.assertTrue(v.isEqual(vExp,1e-12))
4896             #
4897             f=allFMTSLeavesPerCommonSupport[4][0][0][i]
4898             fsst=MEDFileField1TSStructItem.BuildItemFrom(f,mst)
4899             f.loadArraysIfNecessary()
4900             v=mml.buildDataArray(fsst,fields,f.getUndergroundDataArray())
4901             self.assertEqual(f.getName(),fieldName1)
4902             self.assertEqual(v.getHiddenCppPointer(),f.getUndergroundDataArray().getHiddenCppPointer())
4903             vExp=DataArrayDouble(16*2) ; vExp.iota(300+i*1000) ; vExp.rearrange(2) ; vExp.setInfoOnComponents(['Comp1_1 [m]','Com2_1 [s^2]'])
4904             self.assertTrue(v.isEqual(vExp,1e-12))
4905             pass
4906         pass
4907
4908     def test35(self):
4909         """ Emulate MEDReader in // mode context. Here a Simple mesh having more nodes than really needed. This test focuses on that point particulary."""
4910         fname="ForMEDReader35.med"
4911         arrX=DataArrayDouble(7) ; arrX.iota()
4912         arrY=DataArrayDouble([0.,1.])
4913         m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m=m.buildUnstructured() ; m=m[[0,5,1,4,2,3]] ; m.changeSpaceDimension(3,0.) ; m.setName("Mesh")
4914         f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(m) ; f.setName("Field") ; f.setArray(DataArrayDouble([(0.1,1.1),(2.1,3.1),(4.1,5.1),(6.1,7.1),(8.1,9.1),(10.1,11.1)])) ; f.getArray().setInfoOnComponents(["aa","bbb"])
4915         MEDLoader.WriteUMesh(fname,m,True)
4916         MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname,f)
4917         ########## GO for reading in MEDReader,by not loading all. Mesh is fully loaded but not fields values
4918         ms=MEDFileMeshes() # here we reproduce what is done by ParaMEDFileMeshes.ParaNew
4919         ms.pushMesh(MEDFileUMesh.LoadPartOf(fname,"Mesh",[NORM_QUAD4],[0,2,1],-1,-1));
4920         ms[0].zipCoords() 
4921         #
4922         fields=MEDFileFields.LoadPartOf(fname,False,ms);
4923         fields.removeFieldsWithoutAnyTimeStep()
4924         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
4925         allFMTSLeavesToDisplay=[]
4926         for fields in fields_per_mesh:
4927             allFMTSLeavesToDisplay2=[]
4928             for fmts in fields:
4929                 tmp=fmts.splitDiscretizations()
4930                 for itmp in tmp:
4931                     if itmp.presenceOfMultiDiscPerGeoType():
4932                         tmp2=itmp.splitMultiDiscrPerGeoTypes()
4933                         for iii,itmp2 in enumerate(tmp2):
4934                             name="%s_%i"%(itmp2.getName(),iii)
4935                             itmp2.setName(name)
4936                             allFMTSLeavesToDisplay2.append(itmp2)
4937                             pass
4938                         pass
4939                     else:
4940                         allFMTSLeavesToDisplay2.append(itmp)
4941                         pass
4942                 pass
4943             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
4944             pass
4945         #
4946         self.assertEqual(len(allFMTSLeavesToDisplay),1)
4947         self.assertEqual(len(allFMTSLeavesToDisplay[0]),1)
4948         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
4949         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1) # one time serie here : because the 2 fields are defined on the same time steps
4950         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),1)
4951         allFMTSLeavesPerCommonSupport=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesPerTimeSeries[0],ms[ms.getMeshesNames()[0]])
4952         self.assertEqual(len(allFMTSLeavesPerCommonSupport),1)
4953         self.assertEqual(len(allFMTSLeavesPerCommonSupport[0][0]),1)
4954         #
4955         mst=MEDFileMeshStruct.New(ms[0])
4956         #
4957         fcscp=allFMTSLeavesPerCommonSupport[0][1]
4958         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
4959         mml2=mml.prepare()
4960         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
4961         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
4962         self.assertTrue(ncc)
4963         self.assertTrue(a0.isEqual(m.getCoords()[[0,1,5,6,7,8,12,13]],1e-12))# <- the aim of the test
4964         self.assertTrue(a1.isEqual(DataArrayByte([9,9])))
4965         self.assertTrue(a2.isEqual(DataArrayInt([0,5])))
4966         self.assertTrue(a3.isEqual(DataArrayInt([4,1,0,4,5,4,3,2,6,7])))
4967         self.assertTrue(a4 is None)
4968         self.assertTrue(a5 is None)
4969         f2=allFMTSLeavesPerCommonSupport[0][0][0][0]
4970         fsst=MEDFileField1TSStructItem.BuildItemFrom(f2,mst)
4971         f2.loadArraysIfNecessary()
4972         v=mml.buildDataArray(fsst,fields,f2.getUndergroundDataArray())
4973         self.assertEqual(f2.getName(),f.getName())
4974         vExp=DataArrayDouble([(0.1,1.1),(2.1,3.1)])
4975         vExp.setInfoOnComponents(['aa','bbb'])
4976         self.assertTrue(v.isEqual(vExp,1e-12))
4977         pass
4978
4979     def test36(self):
4980         """Bug EDF11027. Here mesh at level 0 (TRI3) does not fetch all the nodes. Level -1 (SEG2) does not fetch all the nodes neither. But all TRI3 + all SEG2 fetch all nodes.
4981         aaa field on GAUSSPoints lying only on TRI3 share the same support than profile node field ccc.
4982         But bbb field on all nodes is not on the same support. Past optimization that make the assumtion a support on all lev0 cells lies on all nodes is now over."""
4983         meshName="mesh"
4984         fname="ForMEDReader36.med"
4985         c=DataArrayDouble([(0,0),(1,0),(1,1),(0,1),(2,0),(-1,0),(1,2)])
4986         m0=MEDCoupling1SGTUMesh(meshName,NORM_TRI3)
4987         m0.setCoords(c)
4988         m0.setNodalConnectivity(DataArrayInt([0,2,1,3,2,0,2,4,1]))
4989         mm=MEDFileUMesh()
4990         mm[0]=m0
4991         m1=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4992         m1.setCoords(c)
4993         m1.setNodalConnectivity(DataArrayInt([5,0,0,3,3,2,2,6]))
4994         mm[-1]=m1
4995         #
4996         zeTime=(1.1,2,3)
4997         ff1=MEDFileField1TS()
4998         f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m0)
4999         arr=DataArrayDouble(7) ; arr.iota(2000)
5000         f1.setArray(arr)
5001         f1.setName("bbb")
5002         f1.checkCoherency()
5003         f1.setTime(*zeTime)
5004         ff1.setFieldNoProfileSBT(f1)
5005         #
5006         ff2=MEDFileField1TS()
5007         f2=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f2.setMesh(m0)
5008         arr=DataArrayDouble(9) ; arr.iota(4000)
5009         f2.setArray(arr)
5010         f2.setName("ddd")
5011         f2.checkCoherency()
5012         f2.setTime(*zeTime)
5013         ff2.setFieldNoProfileSBT(f2)
5014         #
5015         ff3=MEDFileField1TS()
5016         f3=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f3.setMesh(m0)
5017         f3.setGaussLocalizationOnType(NORM_TRI3,[0,0,1,0,0,1],[0.333333,0.333333],[0.5])
5018         arr=DataArrayDouble(3) ; arr.iota(1000)
5019         f3.setArray(arr)
5020         f3.checkCoherency()
5021         f3.setTime(*zeTime)
5022         f3.setName("aaa")
5023         ff3.setFieldNoProfileSBT(f3)
5024         #
5025         ff4=MEDFileField1TS()
5026         m0d=m0.deepCpy() ; m0d.zipCoords()
5027         f4=MEDCouplingFieldDouble(ON_NODES) ; f4.setMesh(m0d)
5028         arr=DataArrayDouble(5) ; arr.iota(3000)
5029         f4.setArray(arr)
5030         f4.setName("ccc")
5031         f4.checkCoherency()
5032         f4.setTime(*zeTime)
5033         pfl=DataArrayInt([0,1,2,3,4]) ; pfl.setName("PFL")
5034         ff4.setFieldProfile(f4,mm,0,pfl)
5035         #
5036         mm.write(fname,2)
5037         ff3.write(fname,0)
5038         ff1.write(fname,0)
5039         ff4.write(fname,0)
5040         ###
5041         ms=MEDFileMeshes(fname)
5042         fields=MEDFileFields(fname,False)
5043         fields.removeFieldsWithoutAnyTimeStep()
5044         fields_per_mesh=[fields.partOfThisLyingOnSpecifiedMeshName(meshName) for meshName in ms.getMeshesNames()]
5045         allFMTSLeavesToDisplay=[]
5046         for fields in fields_per_mesh:
5047             allFMTSLeavesToDisplay2=[]
5048             for fmts in fields:
5049                 tmp=fmts.splitDiscretizations()
5050                 for itmp in tmp:
5051                     self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
5052                     pass
5053                 allFMTSLeavesToDisplay2+=tmp
5054                 pass
5055             allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
5056             pass
5057         self.assertEqual(len(allFMTSLeavesToDisplay),1)
5058         self.assertEqual(len(allFMTSLeavesToDisplay[0]),3)
5059         allFMTSLeavesPerTimeSeries=MEDFileAnyTypeFieldMultiTS.SplitIntoCommonTimeSeries(sum(allFMTSLeavesToDisplay,[]))
5060         self.assertEqual(len(allFMTSLeavesPerTimeSeries),1)
5061         self.assertEqual(len(allFMTSLeavesPerTimeSeries[0]),3)
5062         allFMTSLeavesPerCommonSupport1=MEDFileAnyTypeFieldMultiTS.SplitPerCommonSupport(allFMTSLeavesToDisplay[0],ms[ms.getMeshesNames()[0]])
5063         self.assertEqual(len(allFMTSLeavesPerCommonSupport1),2)
5064         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[0][0]),2)
5065         self.assertEqual(len(allFMTSLeavesPerCommonSupport1[1][0]),1)
5066         #
5067         mst=MEDFileMeshStruct.New(ms[0])
5068         fcscp=allFMTSLeavesPerCommonSupport1[0][1]
5069         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
5070         mml2=mml.prepare()
5071         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
5072         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
5073         self.assertTrue(not ncc)# here ncc=False because the coordinates are not in ms neither in children.
5074         self.assertTrue(a0.isEqual(DataArrayDouble([(0,0,0),(1,0,0),(1,1,0),(0,1,0),(2,0,0)]),1e-12))
5075         self.assertTrue(a1.isEqual(DataArrayByte([5,5,5])))
5076         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8])))
5077         self.assertTrue(a3.isEqual(DataArrayInt([3,0,2,1,3,3,2,0,3,2,4,1])))
5078         self.assertTrue(a4 is None)
5079         self.assertTrue(a5 is None)
5080         for i in xrange(1):
5081             ffCell=allFMTSLeavesPerCommonSupport1[0][0][0][i]
5082             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
5083             ffCell.loadArraysIfNecessary()
5084             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
5085             self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
5086             v.isEqual(DataArrayDouble([1000,1001,1002]),1e-12)
5087             #
5088             ffCell=allFMTSLeavesPerCommonSupport1[0][0][1][i]
5089             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
5090             ffCell.loadArraysIfNecessary()
5091             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
5092             self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
5093             v.isEqual(DataArrayDouble([3000,3001,3002,3003,3004]),1e-12)
5094             pass
5095         fcscp=allFMTSLeavesPerCommonSupport1[1][1]
5096         mml=fcscp.buildFromScratchDataSetSupport(0,fields)
5097         mml2=mml.prepare()
5098         self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
5099         ncc,a0,a1,a2,a3,a4,a5=mml2.buildVTUArrays()
5100         self.assertTrue(not ncc)# here ncc=False because the coordinates are not in ms neither in children.
5101         self.assertTrue(a0.isEqual(DataArrayDouble([(0,0,0),(1,0,0),(1,1,0),(0,1,0),(2,0,0),(-1,0,0),(1,2,0)]),1e-12))
5102         self.assertTrue(a1.isEqual(DataArrayByte([5,5,5,3,3,3,3])))
5103         self.assertTrue(a2.isEqual(DataArrayInt([0,4,8,12,15,18,21])))
5104         self.assertTrue(a3.isEqual(DataArrayInt([3,0,2,1,3,3,2,0,3,2,4,1,2,5,0,2,0,3,2,3,2,2,2,6])))
5105         self.assertTrue(a4 is None)
5106         self.assertTrue(a5 is None)
5107         for i in xrange(1):
5108             ffCell=allFMTSLeavesPerCommonSupport1[1][0][0][i]
5109             fsst=MEDFileField1TSStructItem.BuildItemFrom(ffCell,mst)
5110             ffCell.loadArraysIfNecessary()
5111             v=mml2.buildDataArray(fsst,fields,ffCell.getUndergroundDataArray())
5112             self.assertEqual(v.getHiddenCppPointer(),ffCell.getUndergroundDataArray().getHiddenCppPointer())
5113             v.isEqual(DataArrayDouble([2000,2001,2002,2003,2004,2005,2006]),1e-12)
5114             pass
5115         pass
5116
5117     pass
5118
5119 if __name__ == "__main__":
5120   unittest.main()