1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015 CEA/DEN, EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Anthony Geay (CEA/DEN)
22 from MEDLoader import *
24 from math import pi,e,sqrt
26 class MEDLoaderTest4(unittest.TestCase):
28 Test series to emulate the future MEDReader plugin for PARAVIS.
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.
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
59 fs=MEDFileFieldMultiTS()
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)
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)
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)
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)
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)
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)
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)
128 fs.pushBackTimeStep(f)
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)
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)
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=[]
161 tmp=fmts.splitDiscretizations()
163 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
165 allFMTSLeavesToDisplay2+=tmp
167 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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
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]])
179 mst=MEDFileMeshStruct.New(ms[0])
180 fcscp=allFMTSLeavesPerCommonSupport[0][1]
181 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
183 self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
184 for i in xrange(1,5):
185 self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
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)
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)
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))
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.
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])
239 fs=MEDFileFieldMultiTS()
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
336 fs.pushBackTimeStep(f)
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)
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)
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)
362 fs.pushBackTimeStep(f)
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=[]
376 tmp=fmts.splitDiscretizations()
378 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
380 allFMTSLeavesToDisplay2+=tmp
382 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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
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)
396 mst=MEDFileMeshStruct.New(ms[0])
397 fcscp=allFMTSLeavesPerCommonSupport[0][1]
398 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
400 assert isinstance(mml2,MEDUMeshMultiLev)
401 for i in xrange(1,5):
402 self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
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)
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))
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))
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.
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])
457 fs=MEDFileFieldMultiTS()
458 ##### Time step 0 on cells
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
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
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)
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
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)
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)
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)
528 fs.pushBackTimeStep(f)
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=[]
542 tmp=fmts.splitDiscretizations()
544 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
546 allFMTSLeavesToDisplay2+=tmp
548 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
560 mst=MEDFileMeshStruct.New(ms[0])
561 fcscp=allFMTSLeavesPerCommonSupport[0][1] # start with the cells
562 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
564 self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
565 for i in xrange(1,3):
566 self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
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])))
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))
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)
594 self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
595 for i in xrange(1,2):
596 self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
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)
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))
619 """ This test defines 3 fields on nodes on the same mesh. All of these fields have no profile.
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])
639 fieldName1="zeField1"
640 fieldName2="zeField2"
641 fieldName3="zeField3"
642 fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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=[]
797 tmp=fmts.splitDiscretizations()
799 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
801 allFMTSLeavesToDisplay2+=tmp
803 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
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)
821 self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
822 for i in xrange(1,5):
823 self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
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
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))
844 # test all the time steps of the 1/1 time step serie, on field 2
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))
855 # test all the time steps of the 1/1 time step serie, on field 3
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))
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.
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]"])
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
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()
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)
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)
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)
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=[]
929 tmp=fmts.splitDiscretizations()
931 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
933 allFMTSLeavesToDisplay2+=tmp
935 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
948 mst=MEDFileMeshStruct.New(ms[0])
949 fcscp=allFMTSLeavesPerCommonSupport[0][1]
950 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
952 self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
953 for i in xrange(1,5):
954 self.assertTrue((fcscp.isDataSetSupportEqualToThePreviousOne(i,fields)))
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])))
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)
972 fieldNames=[fieldName1,fieldName2]
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))
985 # Let's go for the 2nd support
986 fcscp=allFMTSLeavesPerCommonSupport[1][1]
987 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
989 self.assertTrue(isinstance(mml2,MEDUMeshMultiLev))
990 for i in xrange(1,5):
991 self.assertTrue(fcscp.isDataSetSupportEqualToThePreviousOne(i,fields))
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)
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))
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.
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
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()
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)
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)
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)
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)
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)
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=[]
1095 tmp=fmts.splitDiscretizations()
1097 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1099 allFMTSLeavesToDisplay2+=tmp
1101 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
1114 mst=MEDFileMeshStruct.New(ms[0])
1116 fcscp=allFMTSLeavesPerCommonSupport[0][1]
1117 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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
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))
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))
1156 fcscp=allFMTSLeavesPerCommonSupport[1][1]
1157 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
1196 fcscp=allFMTSLeavesPerCommonSupport[2][1]
1197 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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
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))
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.
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]"])
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
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()
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)
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)
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)
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)
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)
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=[]
1304 tmp=fmts.splitDiscretizations()
1306 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1308 allFMTSLeavesToDisplay2+=tmp
1310 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
1323 mst=MEDFileMeshStruct.New(ms[0])
1325 fcscp=allFMTSLeavesPerCommonSupport[0][1]
1326 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
1362 fcscp=allFMTSLeavesPerCommonSupport[1][1]
1363 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
1399 fcscp=allFMTSLeavesPerCommonSupport[2][1]
1400 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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
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))
1432 """ This test plays with with gauss fields with no profiles.
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]"])
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])
1446 fieldName0="zeField0"
1447 fieldName1="zeField1"
1448 fieldName2="zeField2"
1449 fieldName3="zeField3"
1450 fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS() ; fs2=MEDFileFieldMultiTS() ; fs3=MEDFileFieldMultiTS()
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)
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)
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)
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)
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=[]
1503 tmp=fmts.splitDiscretizations()
1505 # self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1507 allFMTSLeavesToDisplay2+=tmp
1509 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
1520 mst=MEDFileMeshStruct.New(ms[0])
1522 fcscp=allFMTSLeavesPerCommonSupport[0][1]
1523 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
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))
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))
1578 """ This test plays with with gauss fields with profiles.
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]"])
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])
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()
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)
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)
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)
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)
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=[]
1651 tmp=fmts.splitDiscretizations()
1653 # self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1655 allFMTSLeavesToDisplay2+=tmp
1657 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
1668 mst=MEDFileMeshStruct.New(ms[0])
1670 fcscp=allFMTSLeavesPerCommonSupport[0][1]
1671 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
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))
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))
1725 """ This test plays with fields only on nodes containing profiles.
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]"])
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])
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()
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)
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)
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)
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=[]
1784 tmp=fmts.splitDiscretizations()
1786 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1788 allFMTSLeavesToDisplay2+=tmp
1790 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
1801 mst=MEDFileMeshStruct.New(ms[0])
1803 fcscp=allFMTSLeavesPerCommonSupport[0][1]
1804 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
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))
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.
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])
1859 fieldName0="zeField0"
1860 fs0=MEDFileFieldMultiTS()
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)
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=[]
1887 tmp=fmts.splitDiscretizations()
1889 # self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1891 allFMTSLeavesToDisplay2+=tmp
1893 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
1904 mst=MEDFileMeshStruct.New(ms[0])
1906 fcscp=allFMTSLeavesPerCommonSupport[0][1]
1907 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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]'])
1930 self.assertTrue(v.isEqual(vExp,1e-12))
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.
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])
1945 fieldName0="zeField0"
1946 fieldName1="zeField1"
1947 fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
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)
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)
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=[]
1982 tmp=fmts.splitDiscretizations()
1984 # self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
1986 allFMTSLeavesToDisplay2+=tmp
1988 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
1999 mst=MEDFileMeshStruct.New(ms[0])
2001 fcscp=allFMTSLeavesPerCommonSupport[0][1]
2002 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
2037 """ Testing polyhedrons mixed with hexa8"""
2038 fname="ForMEDReader13.med"
2039 m=MEDCouplingUMesh("mesh",3)
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]"])
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")
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)
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)
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)
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)
2087 fs0.write(fname,0) ; fs1.write(fname,0) ; fs2.write(fname,0) ; fs3.write(fname,0)
2088 a0Exp=mm.getCoords().deepCpy()
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=[]
2099 tmp=fmts.splitDiscretizations()
2101 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2103 allFMTSLeavesToDisplay2+=tmp
2105 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
2118 mst=MEDFileMeshStruct.New(ms[0])
2120 fcscp=allFMTSLeavesPerCommonSupport[0][1]
2121 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
2156 fcscp=allFMTSLeavesPerCommonSupport[1][1]
2157 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
2183 fcscp=allFMTSLeavesPerCommonSupport[2][1]
2184 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
2212 """ Testing only polyhedrons"""
2213 fname="ForMEDReader14.med"
2214 m=MEDCouplingUMesh("mesh",3)
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]"])
2221 mm=MEDFileUMesh() ; mm.setMeshes([m])
2222 fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
2223 fieldName0="zeField0"
2224 fieldName1="zeField1"
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)
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)
2243 fs0.write(fname,0) ; fs1.write(fname,0)
2244 a0Exp=mm.getCoords().deepCpy()
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=[]
2255 tmp=fmts.splitDiscretizations()
2257 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2259 allFMTSLeavesToDisplay2+=tmp
2261 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
2272 mst=MEDFileMeshStruct.New(ms[0])
2274 fcscp=allFMTSLeavesPerCommonSupport[0][1]
2275 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
2289 a6,a7=mml2.retrieveFamilyIdsOnCells()
2290 self.assertTrue(a6.isEqual(DataArrayInt([0,0,0])))
2292 a8,a9=mml2.retrieveNumberIdsOnCells()
2293 self.assertTrue(a8 is None)
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))
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))
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.
2323 fname="ForMEDReader15.med"
2324 m0=MEDCouplingCMesh()
2325 arr=DataArrayDouble(3) ; arr.iota(0)
2326 m0.setCoords(arr,arr,arr)
2328 m0=m0.buildUnstructured()
2331 fCell=MEDCouplingFieldDouble(ON_CELLS)
2332 fCell.setName(fieldName)
2335 fNode=MEDCouplingFieldDouble(ON_NODES)
2336 fNode.setName(fieldName)
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
2344 ffs=MEDFileFieldMultiTS()
2347 f1ts=MEDFileField1TS()
2348 a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2351 fCell.checkCoherency()
2352 a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2356 fNode.checkCoherency()
2357 f1ts.setFieldNoProfileSBT(fCell)
2358 f1ts.setFieldNoProfileSBT(fNode)
2359 ffs.pushBackTimeStep(f1ts)
2361 t=(2.1,1,0) ; off=100.
2362 f1ts=MEDFileField1TS()
2363 a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2366 fCell.checkCoherency()
2367 a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2371 fNode.checkCoherency()
2372 f1ts.setFieldNoProfileSBT(fCell)
2373 f1ts.setFieldNoProfileSBT(fNode)
2374 ffs.pushBackTimeStep(f1ts)
2376 t=(3.2,2,0) ; off=200.
2377 f1ts=MEDFileField1TS()
2378 a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2381 fCell.checkCoherency()
2382 a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2386 fNode.checkCoherency()
2387 f1ts.setFieldNoProfileSBT(fCell)
2388 f1ts.setFieldNoProfileSBT(fNode)
2389 ffs.pushBackTimeStep(f1ts)
2391 t=(4.3,3,1) ; off=300.
2392 f1ts=MEDFileField1TS()
2393 a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2396 fCell.checkCoherency()
2397 a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2401 fNode.checkCoherency()
2402 f1ts.setFieldNoProfileSBT(fCell)
2403 f1ts.setFieldNoProfileSBT(fNode)
2404 ffs.pushBackTimeStep(f1ts)
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=[]
2417 tmp=fmts.splitDiscretizations()
2419 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2421 allFMTSLeavesToDisplay2+=tmp
2423 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
2434 mst=MEDFileMeshStruct.New(ms[0])
2436 fcscp=allFMTSLeavesPerCommonSupport[0][1]
2437 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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
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
2462 fname="ForMEDReader16.med"
2463 m0=MEDCouplingCMesh()
2464 arr=DataArrayDouble(3) ; arr.iota(0)
2465 m0.setCoords(arr,arr,arr)
2467 m0=m0.buildUnstructured()
2469 fCell1=MEDCouplingFieldDouble(ON_CELLS)
2470 fCell1.setName("zeField1_0")
2473 fNode1=MEDCouplingFieldDouble(ON_NODES)
2474 fNode1.setName("zeField2_0")
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
2486 m1=m0.deepCpy() ; m1.translate([2.5,0.,0.]) ; m1.setName("mesh2")
2488 fCell2=MEDCouplingFieldDouble(ON_CELLS)
2489 fCell2.setName("zeField3_1")
2492 fNode2=MEDCouplingFieldDouble(ON_NODES)
2493 fNode2.setName("zeField4_1")
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()
2508 for elt in ffs1_1,ffs1_2,ffs2_1,ffs2_2:
2513 f1ts1=MEDFileField1TS()
2514 f1ts2=MEDFileField1TS()
2515 a=DataArrayDouble(m0.getNumberOfCells()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2518 fCell1.checkCoherency()
2519 a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2523 fNode1.checkCoherency()
2524 f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
2525 f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
2527 f1ts1=MEDFileField1TS()
2528 f1ts2=MEDFileField1TS()
2529 a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
2532 fCell2.checkCoherency()
2533 a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
2537 fNode2.checkCoherency()
2538 f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
2539 f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
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]"])
2547 fCell1.checkCoherency()
2548 a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2552 fNode1.checkCoherency()
2553 f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
2554 f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
2556 f1ts1=MEDFileField1TS()
2557 f1ts2=MEDFileField1TS()
2558 a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
2561 fCell2.checkCoherency()
2562 a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
2566 fNode2.checkCoherency()
2567 f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
2568 f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
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]"])
2576 fCell1.checkCoherency()
2577 a=DataArrayDouble(m0.getNumberOfNodes()) ; a.iota(off) ; a.setInfoOnComponents(["xx [m]"])
2581 fNode1.checkCoherency()
2582 f1ts1.setFieldNoProfileSBT(fCell1) ; ffs1_1.pushBackTimeStep(f1ts1)
2583 f1ts2.setFieldNoProfileSBT(fNode1) ; ffs1_2.pushBackTimeStep(f1ts2)
2585 f1ts1=MEDFileField1TS()
2586 f1ts2=MEDFileField1TS()
2587 a=DataArrayDouble(m1.getNumberOfCells()) ; a.iota(1000.+off) ; a.setInfoOnComponents(["xx [m]"])
2590 fCell2.checkCoherency()
2591 a=DataArrayDouble(m1.getNumberOfNodes()) ; a.iota(1000+off) ; a.setInfoOnComponents(["xx [m]"])
2595 fNode2.checkCoherency()
2596 f1ts1.setFieldNoProfileSBT(fCell2) ; ffs2_1.pushBackTimeStep(f1ts1)
2597 f1ts2.setFieldNoProfileSBT(fNode2) ; ffs2_2.pushBackTimeStep(f1ts2)
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=[]
2609 tmp=fmts.splitDiscretizations()
2611 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2613 allFMTSLeavesToDisplay2+=tmp
2615 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
2632 """ First test on GAUSS_NE (Elno). Here no Profiles.
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)
2643 m.insertNextCell(NORM_QUAD4,[0,3,4,1])
2644 m.insertNextCell(NORM_QUAD4,[1,4,5,2])
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)
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)
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)
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=[]
2685 tmp=fmts.splitDiscretizations()
2687 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2689 allFMTSLeavesToDisplay2+=tmp
2691 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
2702 mst=MEDFileMeshStruct.New(ms[0])
2704 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
2705 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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.])]
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))
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))
2747 """ First test on GAUSS_PT. Here no Profiles. 2 times steps.
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)
2757 m.insertNextCell(NORM_QUAD4,[0,3,4,1])
2758 m.insertNextCell(NORM_QUAD4,[1,4,5,2])
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)
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)
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)
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=[]
2801 tmp=fmts.splitDiscretizations()
2803 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2805 allFMTSLeavesToDisplay2+=tmp
2807 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
2818 mst=MEDFileMeshStruct.New(ms[0])
2820 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
2821 self.assertEqual([NORM_QUAD4],fcscp.getGeoTypesAt(0,ms[0]))
2822 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
2842 vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
2843 vExp1=[DataArrayDouble([3.,5.,4.,6.]),DataArrayDouble([5.,3.,6.,4.])]
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))
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))
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=[]
2870 tmp=fmts.splitDiscretizations()
2872 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2874 allFMTSLeavesToDisplay2+=tmp
2876 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
2887 mst=MEDFileMeshStruct.New(ms[0])
2889 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
2890 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
2910 vExp0=[DataArrayDouble([7.,11.]),DataArrayDouble([11.,7.])]
2911 vExp1=[DataArrayDouble([3.,5.,4.,6.]),DataArrayDouble([5.,3.,6.,4.])]
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))
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))
2932 This test is a simple non profile CELL field but lying on cells of dimension -1 (not 0 as "usual").
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
2942 mm.setMeshAtLevel(0,m0)
2943 mm.setMeshAtLevel(-1,m1)
2944 ff=MEDFileFieldMultiTS()
2947 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setTime(*t) ; f.setMesh(m1)
2948 f.setName(fieldName)
2949 arr=DataArrayDouble(24) ; arr.iota() ; arr.setInfoOnComponents(["AStr"])
2952 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f)
2953 ff.pushBackTimeStep(f1ts)
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"])
2961 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f)
2962 ff.pushBackTimeStep(f1ts)
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=[]
2975 tmp=fmts.splitDiscretizations()
2977 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
2979 allFMTSLeavesToDisplay2+=tmp
2981 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
2992 mst=MEDFileMeshStruct.New(ms[0])
2994 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
2995 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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 !
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")
3049 arr=DataArrayDouble(5) ; arr.iota()
3050 m=MEDCouplingCMesh("mesh") ; m.setCoords(arr,arr)
3051 m=m.buildUnstructured()
3053 mm.setMeshAtLevel(0,m)
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")
3065 f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m)
3066 f0.setName(fieldName0) ; f0.setTime(*t)
3067 da=m.getCoords().magnitude() ; da.setInfoOnComponents(["zeInfo"])
3070 f1ts=MEDFileField1TS()
3071 f1ts.setFieldNoProfileSBT(f0)
3072 fmts0.pushBackTimeStep(f1ts)
3074 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setMesh(m)
3075 f1.setName(fieldName1) ; f1.setTime(*t)
3076 da=m.getBarycenterAndOwner().magnitude() ; da.setInfoOnComponents(["zeInfoCell"])
3079 f1ts=MEDFileField1TS()
3080 f1ts.setFieldNoProfileSBT(f1)
3081 fmts1.pushBackTimeStep(f1ts)
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"])
3088 f1ts=MEDFileField1TS()
3089 f1ts.setFieldProfile(f2,mm,0,pfl2)
3090 fmts2.pushBackTimeStep(f1ts)
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"])
3097 f1ts=MEDFileField1TS()
3098 f1ts.setFieldProfile(f3,mm,0,pfl3)
3099 fmts3.pushBackTimeStep(f1ts)
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"])
3107 f1ts=MEDFileField1TS()
3108 f1ts.setFieldNoProfileSBT(f0)
3109 fmts0.pushBackTimeStep(f1ts)
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"])
3116 f1ts=MEDFileField1TS()
3117 f1ts.setFieldNoProfileSBT(f1)
3118 fmts1.pushBackTimeStep(f1ts)
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"])
3125 f1ts=MEDFileField1TS()
3126 f1ts.setFieldProfile(f2,mm,0,pfl2)
3127 fmts2.pushBackTimeStep(f1ts)
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"])
3134 f1ts=MEDFileField1TS()
3135 f1ts.setFieldProfile(f3,mm,0,pfl3)
3136 fmts3.pushBackTimeStep(f1ts)
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)
3147 fs.appendGlobs(fmts2,1e-12)
3148 fs.appendGlobs(fmts3,1e-12)
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=[]
3159 tmp=fmts.splitDiscretizations()
3161 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3163 allFMTSLeavesToDisplay2+=tmp
3165 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
3177 mst=MEDFileMeshStruct.New(ms[0])
3179 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
3180 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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))
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))
3229 ### Testing the 2nd support
3230 fcscp=allFMTSLeavesPerCommonSupport1[1][1]
3231 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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
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))
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))
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.
3284 fname="ForMEDReader21.med"
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])
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)
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])
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])
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).
3316 fname="ForMEDReader22.med"
3317 fieldName0="ANodeField"
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)
3326 fmts0=MEDFileFieldMultiTS() ; fs.pushField(fmts0)
3327 fmts0.setDtUnit("s")
3330 f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m1)
3331 f0.setName(fieldName0) ; f0.setTime(*t)
3332 da=DataArrayDouble(9) ; da.iota() ; da.setInfoOnComponents(["zeInfo"])
3335 f1ts=MEDFileField1TS()
3336 f1ts.setFieldNoProfileSBT(f0)
3337 fmts0.pushBackTimeStep(f1ts)
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"])
3345 f1ts=MEDFileField1TS()
3346 f1ts.setFieldNoProfileSBT(f0)
3347 fmts0.pushBackTimeStep(f1ts)
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=[]
3360 tmp=fmts.splitDiscretizations()
3362 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3364 allFMTSLeavesToDisplay2+=tmp
3366 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
3377 mst=MEDFileMeshStruct.New(ms[0])
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)
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
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))
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))
3425 """ Non regression test 2219 of modes. Idem than test22 except that here the node field is on profile.
3427 fname="ForMEDReader23.med"
3428 fieldName0="ANodeField"
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")
3439 pfl=DataArrayInt([0,1,2,4]) ; pfl.setName("pfl")
3440 pflCell=DataArrayInt([0,1,2]) ; m1Part=m1[pflCell] ; m1Part.zipCoords()
3443 f0=MEDCouplingFieldDouble(ON_NODES) ; f0.setMesh(m1Part)
3444 f0.setName(fieldName0) ; f0.setTime(*t)
3445 da=DataArrayDouble(4) ; da.iota() ; da.setInfoOnComponents(["zeInfo"])
3448 f1ts=MEDFileField1TS()
3449 f1ts.setFieldProfile(f0,mm,-1,pfl)
3450 fmts0.pushBackTimeStep(f1ts)
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"])
3458 f1ts=MEDFileField1TS()
3459 f1ts.setFieldProfile(f0,mm,-1,pfl)
3460 fmts0.pushBackTimeStep(f1ts)
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=[]
3472 tmp=fmts.splitDiscretizations()
3474 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3476 allFMTSLeavesToDisplay2+=tmp
3478 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
3489 mst=MEDFileMeshStruct.New(ms[0])
3491 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
3492 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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
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))
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))
3534 """ Non regression test for cartesian mesh whose the 3rd direction has only one node. It a false 3D mesh.
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")
3547 f=MEDCouplingFieldDouble(ON_NODES) ; f.setName(fieldName0)
3549 arr=DataArrayDouble(15) ; arr.setInfoOnComponents(["tutu"]) ; arr.iota()
3552 f1ts=MEDFileField1TS()
3553 f1ts.setFieldNoProfileSBT(f)
3554 fmts0.pushBackTimeStep(f1ts)
3557 arr=DataArrayDouble(15) ; arr.setInfoOnComponents(["tutu"]) ; arr.iota()
3561 f1ts=MEDFileField1TS()
3562 f1ts.setFieldNoProfileSBT(f)
3563 fmts0.pushBackTimeStep(f1ts)
3565 mm=MEDFileCMesh() ; mm.setMesh(cmesh)
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=[]
3577 tmp=fmts.splitDiscretizations()
3579 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3581 allFMTSLeavesToDisplay2+=tmp
3583 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
3594 mst=MEDFileMeshStruct.New(ms[0])
3596 fcscp=allFMTSLeavesPerCommonSupport[0][1]
3597 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
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"])
3616 self.assertTrue(v.isEqual(vExp,1e-12))
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.
3625 fname="ForMEDReader25.med"
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)
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)
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]))
3650 fmts=MEDFileFieldMultiTS()
3656 f1ts=MEDFileField1TS()
3657 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name0)
3658 arr=DataArrayDouble([(-1,-11),(-2,-22)]) ; arr.setInfoOnComponents(info0)
3660 pfl0=DataArrayInt([0,1]) ; pfl0.setName(pflName0)
3661 f1ts.setFieldProfile(f,m,-1,pfl0)
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)
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])
3671 f1ts.setFieldProfile(f2,m,0,pfl1)
3672 fmts.pushBackTimeStep(f1ts)
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=[]
3685 tmp=fmts.splitDiscretizations()
3687 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3689 allFMTSLeavesToDisplay2+=tmp
3691 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
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)
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))
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)
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)
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 !!!
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.
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)
3828 for elt in [[2,6,3],[6,7,3],[9,6,5],[9,10,6]]:
3829 m0.insertNextCell(NORM_TRI3,elt)
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)
3834 m0.setCoords(coords)
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]))
3841 f1ts0Node=MEDFileField1TS()
3842 f1ts1Node=MEDFileField1TS()
3843 f1ts2Cell=MEDFileField1TS()
3844 f1ts3Cell=MEDFileField1TS()
3845 f1ts4Cell=MEDFileField1TS()
3846 f1ts5Node=MEDFileField1TS()
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")
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)
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)
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)
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)
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)
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)
3883 for f in [f1ts0Node,f1ts1Node,f1ts2Cell,f1ts3Cell,f1ts4Cell,f1ts5Node]:
3884 fmts=MEDFileFieldMultiTS()
3885 fmts.pushBackTimeStep(f)
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=[]
3899 tmp=fmts.splitDiscretizations()
3901 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
3903 allFMTSLeavesToDisplay2+=tmp
3905 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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
3917 mst=MEDFileMeshStruct.New(ms[0])
3919 fcscp=allFMTSLeavesPerCommonSupport1[1][1]
3920 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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
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 !!!
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 !!!
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.
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)
3972 m0.setCoords(coords)
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]))
3978 f1ts0=MEDFileField1TS()
3979 f1ts1=MEDFileField1TS()
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.])
3985 f1ts0.setFieldNoProfileSBT(f0)
3986 self.assertEqual(f1ts0.getMeshName(),"mesh")
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])
3992 f1ts1.setFieldProfile(f1,mm,0,pfl1)
3993 self.assertEqual(f1ts1.getMeshName(),"mesh")
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")
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=[]
4018 tmp=fmts.splitDiscretizations()
4020 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4022 allFMTSLeavesToDisplay2+=tmp
4024 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4036 mst=MEDFileMeshStruct.New(ms[0])
4038 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4039 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)
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))
4060 fcscp=allFMTSLeavesPerCommonSupport1[1][1]
4061 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
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.
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)
4092 for elt in [[2,6,3],[6,7,3],[9,6,5],[9,10,6]]:
4093 m0.insertNextCell(NORM_TRI3,elt)
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)
4098 m0.setCoords(coords)
4099 m2=MEDCouplingUMesh("mesh",0) ; m2.setCoords(coords)
4101 for elt in [[8],[13]]:
4102 m2.insertNextCell(NORM_POINT1,elt)
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]))
4112 f1ts0Node=MEDFileField1TS()
4113 f1ts1Node=MEDFileField1TS()
4114 f1ts2Cell=MEDFileField1TS()
4115 f1ts3Cell=MEDFileField1TS()
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")
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)
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)
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)
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)
4140 arr3=DataArrayDouble([-1.1,-3.1]) ; f3Cell.setArray(arr3)
4141 f1ts3Cell.setFieldNoProfileSBT(f3Cell)
4144 for f in [f1ts0Node,f1ts1Node,f1ts2Cell,f1ts3Cell]:
4145 fmts=MEDFileFieldMultiTS()
4146 fmts.pushBackTimeStep(f)
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=[]
4160 tmp=fmts.splitDiscretizations()
4162 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4164 allFMTSLeavesToDisplay2+=tmp
4166 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4179 mst=MEDFileMeshStruct.New(ms[0])
4181 fcscp=allFMTSLeavesPerCommonSupport1[2][1]
4182 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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
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 !!!
4215 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4216 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
4244 fcscp=allFMTSLeavesPerCommonSupport1[1][1]
4245 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
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).
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)
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)
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")
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=[]
4298 tmp=fmts.splitDiscretizations()
4300 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4302 allFMTSLeavesToDisplay2+=tmp
4304 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4315 mst=MEDFileMeshStruct.New(ms[0])
4317 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4318 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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"])
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]
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.
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")
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"])
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)
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)
4389 f1ts.setFieldNoProfileSBT(fCells)
4390 fmts1.pushBackTimeStep(f1ts)
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=[]
4406 tmp=fmts.splitDiscretizations()
4408 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4410 allFMTSLeavesToDisplay2+=tmp
4412 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4424 mst=MEDFileMeshStruct.New(ms[0])
4426 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4427 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
4446 fcscp=allFMTSLeavesPerCommonSupport1[1][1]
4447 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
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")
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)
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=[]
4516 tmp=fmts.splitDiscretizations()
4518 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4520 allFMTSLeavesToDisplay2+=tmp
4522 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4533 mst=MEDFileMeshStruct.New(ms[0])
4535 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4536 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
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")
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)
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)
4599 f1ts.setFieldNoProfileSBT(fCells)
4600 fmts1.pushBackTimeStep(f1ts)
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=[]
4616 tmp=fmts.splitDiscretizations()
4618 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4620 allFMTSLeavesToDisplay2+=tmp
4622 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4634 mst=MEDFileMeshStruct.New(ms[0])
4636 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4637 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
4656 fcscp=allFMTSLeavesPerCommonSupport1[1][1]
4657 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)
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))
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)
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)]):
4698 m.insertNextCell(typ,c)
4701 mm.setMeshAtLevel(0,m)
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)
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=[]
4720 tmp=fmts.splitDiscretizations()
4722 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
4724 allFMTSLeavesToDisplay2+=tmp
4726 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4737 mst=MEDFileMeshStruct.New(ms[0])
4739 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
4740 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
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.
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])
4775 fieldName0="zeField0"
4776 fieldName1="zeField1"
4777 fs0=MEDFileFieldMultiTS() ; fs1=MEDFileFieldMultiTS()
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)
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)
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=[]
4812 tmp=fmts.splitDiscretizations()
4814 if itmp.presenceOfMultiDiscPerGeoType():
4815 tmp2=itmp.splitMultiDiscrPerGeoTypes()
4816 for iii,itmp2 in enumerate(tmp2):
4817 name="%s_%i"%(itmp2.getName(),iii)
4819 allFMTSLeavesToDisplay2.append(itmp2)
4823 allFMTSLeavesToDisplay2.append(itmp)
4826 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4837 self.assertEqual(len(allFMTSLeavesPerCommonSupport[i][0]),1)
4839 mst=MEDFileMeshStruct.New(ms[0])
4841 fcscp=allFMTSLeavesPerCommonSupport[4][1]
4842 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)))
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]'])
4865 self.assertTrue(v.isEqual(vExp,1e-12))
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]'])
4875 self.assertTrue(v.isEqual(vExp,1e-12))
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]'])
4885 self.assertTrue(v.isEqual(vExp,1e-12))
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]'])
4895 self.assertTrue(v.isEqual(vExp,1e-12))
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))
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));
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=[]
4929 tmp=fmts.splitDiscretizations()
4931 if itmp.presenceOfMultiDiscPerGeoType():
4932 tmp2=itmp.splitMultiDiscrPerGeoTypes()
4933 for iii,itmp2 in enumerate(tmp2):
4934 name="%s_%i"%(itmp2.getName(),iii)
4936 allFMTSLeavesToDisplay2.append(itmp2)
4940 allFMTSLeavesToDisplay2.append(itmp)
4943 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
4955 mst=MEDFileMeshStruct.New(ms[0])
4957 fcscp=allFMTSLeavesPerCommonSupport[0][1]
4958 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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))
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."""
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)
4988 m0.setNodalConnectivity(DataArrayInt([0,2,1,3,2,0,2,4,1]))
4991 m1=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4993 m1.setNodalConnectivity(DataArrayInt([5,0,0,3,3,2,2,6]))
4997 ff1=MEDFileField1TS()
4998 f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m0)
4999 arr=DataArrayDouble(7) ; arr.iota(2000)
5004 ff1.setFieldNoProfileSBT(f1)
5006 ff2=MEDFileField1TS()
5007 f2=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f2.setMesh(m0)
5008 arr=DataArrayDouble(9) ; arr.iota(4000)
5013 ff2.setFieldNoProfileSBT(f2)
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)
5023 ff3.setFieldNoProfileSBT(f3)
5025 ff4=MEDFileField1TS()
5026 m0d=m0.deepCpy() ; m0d.zipCoords()
5027 f4=MEDCouplingFieldDouble(ON_NODES) ; f4.setMesh(m0d)
5028 arr=DataArrayDouble(5) ; arr.iota(3000)
5033 pfl=DataArrayInt([0,1,2,3,4]) ; pfl.setName("PFL")
5034 ff4.setFieldProfile(f4,mm,0,pfl)
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=[]
5049 tmp=fmts.splitDiscretizations()
5051 self.assertTrue(not itmp.presenceOfMultiDiscPerGeoType())
5053 allFMTSLeavesToDisplay2+=tmp
5055 allFMTSLeavesToDisplay.append(allFMTSLeavesToDisplay2)
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)
5067 mst=MEDFileMeshStruct.New(ms[0])
5068 fcscp=allFMTSLeavesPerCommonSupport1[0][1]
5069 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)
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)
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)
5095 fcscp=allFMTSLeavesPerCommonSupport1[1][1]
5096 mml=fcscp.buildFromScratchDataSetSupport(0,fields)
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)
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)
5117 def testEmptyMesh(self):
5118 fname = "empty_mesh.med"
5119 m = MEDCouplingUMesh('toto', 2)
5120 m.setCoords(DataArrayDouble([], 0, 2))
5121 m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
5122 mfu = MEDFileUMesh()
5123 mfu.setMeshAtLevel(0, m)
5125 mfu2 = MEDFileUMesh(fname)
5126 self.assertEqual('toto', mfu2.getName())
5127 lvl = mfu2.getNonEmptyLevels()
5128 self.assertEqual((), lvl)
5132 if __name__ == "__main__":