1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 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.
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
25 from MEDLoaderDataForTest import MEDLoaderDataForTest
27 class MEDLoaderTest(unittest.TestCase):
28 def testMEDMesh1(self):
29 fileName="Pyfile18.med"
30 mname="ExampleOfMultiDimW"
31 medmesh=MEDFileMesh.New(fileName,mname)
32 self.assertRaises(InterpKernelException,MEDFileMesh.New,fileName,"")
33 self.assertEqual((0,-1),medmesh.getNonEmptyLevels())
34 m1_0=medmesh.getLevel0Mesh(True)
35 m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
36 self.assertTrue(m1_0.isEqual(m1_1,1e-12));
37 m2_0=medmesh.getLevelM1Mesh(True)
38 m2_1=MEDLoader.ReadUMeshFromFile(fileName,mname,-1)
39 self.assertTrue(m2_0.isEqual(m2_1,1e-12));
42 def testMEDMesh2(self):
43 fileName="Pyfile10.med"
45 outFileName="MEDFileMesh1.med"
46 medmesh=MEDFileUMesh.New(fileName,mname)
47 self.assertEqual((0,),medmesh.getNonEmptyLevels())
48 m1_0=medmesh.getLevel0Mesh(True)
49 m1_1=MEDLoader.ReadUMeshFromFile(fileName,mname,0)
50 self.assertTrue(m1_0.isEqual(m1_1,1e-12));
51 g1_0=medmesh.getGroup(0,"mesh2",True)
52 g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh2"]);
53 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
54 g1_0=medmesh.getGroup(0,"mesh3",True)
55 g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3"]);
56 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
57 g1_0=medmesh.getGroups(0,["mesh3","mesh2"])
58 g1_1=MEDLoader.ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]);
59 g1_1.setName(g1_0.getName())
60 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
61 g1_0=medmesh.getFamily(0,"Family_-3",True)
62 g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_-3"]);
63 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
64 g1_0=medmesh.getFamilies(0,["Family_-3","Family_-5"],True)
65 g1_1=MEDLoader.ReadUMeshFromFamilies(fileName,mname,0,["Family_-3","Family_-5"]);
66 g1_1.setName(g1_0.getName())
67 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
68 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
69 medmesh.write(outFileName,2);
70 self.assertEqual([1,2,4,13,15],medmesh.getGroupArr(0,"mesh2",True).getValues());
71 self.assertEqual([1,2,15],medmesh.getFamilyArr(0,"Family_-3",True).getValues());
72 self.assertEqual([1,2,4,13,15],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"],True).getValues());
73 self.assertEqual([18,1,2,3,4,13,14,15],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
74 famn=medmesh.getFamilyNameGivenId(0)
75 self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True);
77 self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues());
78 self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_-3").getValues());
79 self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"]).getValues());
80 self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
81 self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False);
84 # this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account
85 def testMEDMesh3(self):
86 outFileName="MEDFileMesh3.med"
87 c=DataArrayDouble.New()
88 coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ];
89 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
90 c.setValues(coords,9,2)
91 m=MEDCouplingUMesh.New();
92 m.setMeshDimension(2);
94 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
95 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
96 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
97 m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
98 m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
99 m.finishInsertingCells();
102 m1=MEDCouplingUMesh.New();
103 m1.setMeshDimension(1);
105 m1.insertNextCell(NORM_SEG2,2,[1,4])
106 m1.insertNextCell(NORM_SEG2,2,[3,6])
107 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
108 m1.finishInsertingCells();
111 m2=MEDCouplingUMesh.New();
112 m2.setMeshDimension(0);
114 m2.insertNextCell(NORM_POINT1,1,[1])
115 m2.insertNextCell(NORM_POINT1,1,[3])
116 m2.insertNextCell(NORM_POINT1,1,[2])
117 m2.insertNextCell(NORM_POINT1,1,[6])
118 m2.finishInsertingCells();
122 mm=MEDFileUMesh.New()
123 self.assertTrue(mm.getUnivNameWrStatus())
124 mm.setName("MyFirstMEDCouplingMEDmesh")
125 mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
127 mm.setMeshAtLevel(-1,m1);
128 mm.setMeshAtLevel(0,m);
129 mm.setMeshAtLevel(-2,m2);
130 # playing with groups
131 g1_2=DataArrayInt.New()
132 g1_2.setValues([1,3],2,1)
134 g2_2=DataArrayInt.New()
135 g2_2.setValues([1,2,3],3,1)
137 mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
138 g1_1=DataArrayInt.New()
139 g1_1.setValues([0,1,2],3,1)
141 g2_1=DataArrayInt.New()
142 g2_1.setValues([0,2],2,1)
144 mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
145 g1_N=DataArrayInt.New()
146 g1_N.setValues(range(8),8,1)
148 g2_N=DataArrayInt.New()
149 g2_N.setValues(range(9),9,1)
151 mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
152 mm.createGroupOnAll(0,"GrpOnAllCell")
153 # check content of mm
154 t=mm.getGroupArr(0,"G1",False)
155 self.assertTrue(g1_2.isEqual(t));
156 t=mm.getGroupArr(0,"G2",False)
157 self.assertTrue(g2_2.isEqual(t));
158 t=mm.getGroupArr(-1,"G1",False)
159 self.assertTrue(g1_1.isEqual(t));
160 t=mm.getGroupArr(-1,"G2",False)
161 self.assertTrue(g2_1.isEqual(t));
162 t=mm.getGroupArr(1,"G1",False)
163 self.assertTrue(g1_N.isEqual(t));
164 t=mm.getGroupArr(1,"G2",False)
165 self.assertTrue(g2_N.isEqual(t));
166 self.assertTrue(mm.existsGroup("GrpOnAllCell"));
167 t=mm.getGroupArr(0,"GrpOnAllCell")
168 self.assertTrue(t.getValues()==range(5))
171 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) ; del mm
172 mmCpy.write(outFileName,2);
174 mm=MEDFileMesh.New(outFileName)
175 self.assertTrue(mm.getUnivNameWrStatus())
176 self.assertTrue(isinstance(mm.getUnivName(),str))
177 self.assertTrue(len(mm.getUnivName())!=0)
178 mbis=mm.getMeshAtLevel(0)
179 m.setName(mm.getName()) ; m.setDescription(mm.getDescription())
180 self.assertTrue(m.isEqual(mbis,1e-12));
182 self.assertEqual(([[(3, 2), (4, 1), (5, 8)], [(1, 2), (2, 1)], [(0, 4)]], 2, 2, 9),MEDLoader.GetUMeshGlobalInfo(outFileName,"MyFirstMEDCouplingMEDmesh"))
185 # this test is the testMEDMesh3 except that permutation is dealed here
186 def testMEDMesh4(self):
187 outFileName="MEDFileMesh4.med"
188 c=DataArrayDouble.New()
189 coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ];
190 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
191 c.setValues(coords,9,2)
192 c.setInfoOnComponent(0,"abcdef [km]")
193 c.setInfoOnComponent(1,"ghij [MW]")
194 m=MEDCouplingUMesh.New();
195 m.setMeshDimension(2);
197 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
198 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
199 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
200 m.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
201 m.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
202 m.finishInsertingCells();
205 m1=MEDCouplingUMesh.New();
206 m1.setMeshDimension(1);
208 m1.insertNextCell(NORM_SEG2,2,[1,4])
209 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
210 m1.insertNextCell(NORM_SEG2,2,[3,6])
211 m1.finishInsertingCells();
214 m2=MEDCouplingUMesh.New();
215 m2.setMeshDimension(0);
217 m2.insertNextCell(NORM_POINT1,1,[1])
218 m2.insertNextCell(NORM_POINT1,1,[3])
219 m2.insertNextCell(NORM_POINT1,1,[2])
220 m2.insertNextCell(NORM_POINT1,1,[6])
221 m2.finishInsertingCells();
225 mm=MEDFileUMesh.New()
226 mm.setName("My2ndMEDCouplingMEDmesh")
227 mm.setDescription("ThisIsImpossibleToDoWithMEDMEM")
229 renumNode=DataArrayInt.New()
230 renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1)
231 mm.setRenumFieldArr(1,renumNode)
232 mm.setMeshAtLevel(-1,m1,True);
233 mm.setMeshAtLevel(0,m,True);
234 mm.setMeshAtLevel(-2,m2,True);
235 mm.removeMeshAtLevel(-2)
236 mm.setMeshAtLevel(-2,m2,True);
237 # playing with groups
238 g1_2=DataArrayInt.New()
239 g1_2.setValues([2,3],2,1)
241 g2_2=DataArrayInt.New()
242 g2_2.setValues([2,0,3],3,1)
244 mm.setGroupsAtLevel(0,[g1_2,g2_2],True)
245 g1_1=DataArrayInt.New()
246 g1_1.setValues([0,2,1],3,1)
248 g2_1=DataArrayInt.New()
249 g2_1.setValues([0,2],2,1)
251 mm.setGroupsAtLevel(-1,[g1_1,g2_1],True)
252 g1_N=DataArrayInt.New()
253 g1_N.setValues([10,11,12,13,14,15,16,17],8,1)
255 g2_N=DataArrayInt.New()
256 g2_N.setValues([10,11,12,13,14,15,16,17,18],9,1)
258 mm.setGroupsAtLevel(1,[g1_N,g2_N],True)
259 # check content of mm
260 t=mm.getGroupArr(0,"G1",True)
261 self.assertTrue(g1_2.isEqual(t));
262 t=mm.getGroupArr(0,"G2",True)
263 self.assertTrue(g2_2.isEqual(t));
264 t=mm.getGroupArr(-1,"G1",True)
265 self.assertTrue(g1_1.isEqual(t));
266 t=mm.getGroupArr(-1,"G2",True)
267 self.assertTrue(g2_1.isEqual(t));
268 self.assertTrue(not mm.existsGroup("GrpOnAllCell"));
270 mm.write(outFileName,2);
271 mm2=MEDFileMesh.New(outFileName)
272 res=mm.isEqual(mm2,1e-12)
273 self.assertTrue(res[0])
274 l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
275 self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
276 mm2.keepFamIdsOnlyOnLevs([3],[-1])
277 for lev in mm.getGrpNonEmptyLevelsExt("G2"):
278 self.assertEqual(mm.getGroupArr(lev,"G2").getValues(),mm2.getGroupArr(lev,"G2").getValues())
280 l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
281 self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
283 self.assertEqual([-7,-7,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
284 mm2.getFamilyFieldAtLevel(-1).setIJ(1,0,-8)
285 self.assertEqual([-7,-8,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
286 self.assertTrue(not mm2.existsFamily("Family_-8"))
287 mm2.createGroupOnAll(-1,"GrpOnAllFace")
288 self.assertTrue(mm2.existsFamily("Family_-8"))
289 self.assertEqual(range(3),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
292 #testing persistence of retrieved arrays
293 def testMEDMesh5(self):
294 fileName="Pyfile18.med"
295 mname="ExampleOfMultiDimW"
296 medmesh=MEDFileUMesh.New(fileName,mname)
297 m1_0=medmesh.getLevel0Mesh(True)
298 da1=medmesh.getFamilyFieldAtLevel(0)
300 self.assertEqual(20,m1_0.getNumberOfCells())
301 self.assertEqual(20,da1.getNumberOfTuples())
304 def testMEDMesh6(self):
305 outFileName="MEDFileMesh5.med"
308 m1=MEDCouplingCMesh.New();
309 da=DataArrayDouble.New()
310 da.setValues([0.,1.,2.],3,1)
311 da.setInfoOnComponent(0,"XX [mm]")
313 da=DataArrayDouble.New()
314 da.setValues([0.,1.2],2,1)
315 da.setInfoOnComponent(0,"YY [km]")
317 da=DataArrayDouble.New()
318 da.setValues([0.,1.3],2,1)
319 da.setInfoOnComponent(0,"ZZ [um]")
322 m.setName("myFirstCartMesh")
323 m.setDescription("mmmmpppppppp")
326 da=DataArrayInt.New()
327 da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1)
328 m.setFamilyFieldArr(1,da)
329 m.setFamilyId("family1",1)
330 da=m.getFamilyArr(1,"family1")
332 self.assertEqual(expected1,da.getValues())
333 self.assertTrue(m.getUnivNameWrStatus())
334 m.write(outFileName,2);
335 mm=MEDFileMesh.New(outFileName)
336 self.assertTrue(isinstance(mm,MEDFileCMesh))
337 self.assertTrue(isinstance(mm.getUnivName(),str))
338 self.assertTrue(len(mm.getUnivName())!=0)
339 self.assertTrue(m.isEqual(mm,1e-12)[0])
340 self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
343 m1.setTime(tt[2],tt[0],tt[1])
344 m1.setName(m.getName())
345 m1.setTimeUnit(m.getTimeUnit())
346 m1.setDescription(m.getDescription())
347 self.assertTrue(m2.isEqual(m1,1e-12));
350 def testMEDMesh7(self):
351 fileName="Pyfile24.med"
352 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
354 m.setCoords(m2.getCoords())
355 m.setMeshAtLevel(0,m2)
356 m.setMeshAtLevel(-1,m1)
357 m.setMeshAtLevel(-2,m0)
358 m.setFamilyFieldArr(0,f2)
359 m.setFamilyFieldArr(-1,f1)
360 m.setFamilyFieldArr(-2,f0)
361 m.setFamilyFieldArr(1,p)
362 m.setRenumFieldArr(0,n2)
363 m.setRenumFieldArr(-1,n1)
364 m.setRenumFieldArr(-2,n0)
366 for i in xrange(nbOfFams):
367 m.addFamily(fns[i],fids[i])
370 for i in xrange(nbOfGrps):
371 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
373 m.setName(m2.getName())
374 m.setDescription(m2.getDescription())
376 self.assertEqual((-1,),m.getGrpNonEmptyLevels("A2A4"))
377 self.assertEqual((),m.getGrpNonEmptyLevels("A1"))
378 self.assertEqual((-2,),m.getGrpNonEmptyLevels("AP2"))
379 self.assertEqual((-1,-2),m.getGrpsNonEmptyLevels(["A2A4","AP2"]))
380 self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________'))
381 self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________'))
382 self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________']))
383 self.assertEqual(('A1A2','A2A4','A3A1','A3C5','A4A3','B1C1','B2B4','B3B1','B4C3','C1C4','C2B2','C3C2','C4B3','C5A4'),m.getGroupsOnSpecifiedLev(-1))
384 self.assertEqual(('DALLE','DALQ1','DALQ2','DALT3','MESH'),m.getGroupsOnSpecifiedLev(0))
387 self.assertRaises(InterpKernelException,MEDFileField1TS,fileName)#throw because no field in file fileName
390 def funcToTestDelItem(self,ff):
394 #emulation of pointe.med file.
395 def testMEDField1(self):
396 mm=MEDFileMesh.New("Pyfile17.med")
397 mm.write("Pyfile17_bis.med",2)
398 ff=MEDFileFieldMultiTS("Pyfile17.med")
399 tsExpected=[[1,2],[3,4],[5,6]]
400 self.assertEqual(3,len(ff))
401 for pos,f1ts in enumerate(ff):
402 self.assertEqual(tsExpected[pos],f1ts.getTime()[:2])
403 self.assertEqual(type(f1ts),MEDFileField1TS)
405 self.assertEqual("MeasureOfMesh_Extruded",ff.getName())
406 self.assertEqual([3,4],ff[1].getTime()[:-1])
407 self.assertEqual([3,4],ff[3,4].getTime()[:-1])
408 self.assertEqual([3,4],ff[0.01].getTime()[:-1])
409 ff.write("Pyfile17_bis.med",0)
411 ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
412 self.assertEqual([(1,2),(3,4),(5,6)],ts)
413 self.funcToTestDelItem(ff)
414 ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
415 self.assertEqual([(1,2)],ts)
419 def testMEDField2(self):
420 mm=MEDFileMesh.New("Pyfile19.med")
421 mm.write("Pyfile19_bis.med",2)
422 ff=MEDFileFieldMultiTS.New("Pyfile19.med")
423 ff.write("Pyfile19_bis.med",0)
424 self.assertEqual([('tyty','mm'),('uiop','MW')],MEDLoader.GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes"))
428 def testMEDField3(self):
429 mm=MEDFileMesh.New("Pyfile13.med")
430 mm.write("Pyfile13_bis.med",2)
431 ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
432 ff.write("Pyfile13_bis.med",0)
433 ff=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint",1,5)
434 f=ff.getFieldAtLevel(ON_GAUSS_PT,0)
435 f2=MEDLoader.ReadFieldGauss("Pyfile13.med",'2DMesh_2',0,'MyFirstFieldOnGaussPoint',1,5)
436 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
437 ff3=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
438 f3=ff3.getFieldAtLevel(ON_GAUSS_PT,0)
439 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
440 ff4=MEDFileField1TS.New("Pyfile13.med")
441 f4=ff4.getFieldAtLevel(ON_GAUSS_PT,0)
442 self.assertTrue(f.isEqual(f4,1e-12,1e-12))
446 def testMEDField4(self):
447 mm=MEDFileMesh.New("Pyfile14.med")
448 mm.write("Pyfile14_bis.med",2)
449 ff=MEDFileFieldMultiTS.New("Pyfile14.med","MyFieldOnGaussNE")
450 ff.write("Pyfile14_bis.med",0)
451 ff=MEDFileField1TS.New("Pyfile14.med","MyFieldOnGaussNE",1,5)
452 f=ff.getFieldAtLevel(ON_GAUSS_NE,0)
453 f2=MEDLoader.ReadFieldGaussNE("Pyfile14.med",'2DMesh_2',0,"MyFieldOnGaussNE",1,5)
454 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
457 # MEDField get/set on pointe.med
458 def testMEDField5(self):
459 ff=MEDFileField1TS.New("Pyfile17.med","MeasureOfMesh_Extruded",1,2)
460 f=ff.getFieldAtLevel(ON_CELLS,0)
461 f2=MEDLoader.ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
462 self.assertTrue(f.getMesh().getCoords().isEqual(f2.getMesh().getCoords(),1e-12))
463 f.getMesh().tryToShareSameCoords(f2.getMesh(),1e-12)
464 f.changeUnderlyingMesh(f2.getMesh(),22,1e-12)
465 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
466 # no with renumbering
467 f=ff.getFieldAtLevel(ON_CELLS,0,1)
468 f2=MEDLoader.ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
469 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
470 f=ff.getFieldAtLevel(ON_CELLS,0,3)
471 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
472 f=ff.getFieldAtLevel(ON_CELLS,0,2)
473 self.assertTrue(not f.isEqual(f2,1e-12,1e-12))
474 f.changeUnderlyingMesh(f2.getMesh(),12,1e-12)
475 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
478 # MEDField get/set on profiles nodes
479 def testMEDField6(self):
480 ff=MEDFileFieldMultiTS.New("Pyfile7.med","VectorFieldOnNodes")
481 its=ff.getIterations()
482 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
483 f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
484 f2=MEDLoader.ReadFieldNode("Pyfile7.med",'3DSurfMesh_1',0,"VectorFieldOnNodes",its[0][0],its[0][1])
485 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
486 ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes")
487 its=ff.getIterations()
488 f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
489 f2=MEDLoader.ReadFieldNode("Pyfile19.med",'2DMesh_1',0,"VFieldOnNodes",its[0][0],its[0][1])
490 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
491 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
492 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_NODES,its[0][0],its[0][1],0,1)#request renumber following mesh : it is on profile !
495 # MEDField get/set on profiles cells
496 def testMEDField7(self):
497 ff=MEDFileFieldMultiTS.New("Pyfile12.med","VectorFieldOnCells")
498 its=ff.getIterations()
499 f=ff.getFieldAtLevel(ON_CELLS,its[0][0],its[0][1],0)
500 f2=MEDLoader.ReadFieldCell("Pyfile12.med",'3DMesh_1',0,"VectorFieldOnCells",its[0][0],its[0][1])
501 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
504 #first test of assignation. No profile and types sorted by type.
505 def testMEDField8(self):
507 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
509 mm1=MEDFileUMesh.New()
510 mm1.setCoords(m1.getCoords())
511 mm1.setMeshAtLevel(0,m1)
512 mm1.setName(m1.getName())
514 ff1=MEDFileField1TS.New()
515 ff1.setFieldNoProfileSBT(f1)
517 f2=MEDLoader.ReadFieldCell(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]);
518 itt,orr,ti=ff1.getTime()
519 self.assertEqual(0,itt); self.assertEqual(1,orr); self.assertAlmostEqual(2.,ti,14);
520 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
522 itt,orr,ti=ff1.getTime()
523 self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14);
524 da,infos=ff1.getUndergroundDataArrayExt()
525 f2.getArray().setName(da.getName())#da has the same name than f2
526 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
527 self.assertEqual([((3, 0), (0, 2)), ((4, 0), (2, 4)), ((6, 0), (4, 5)), ((5, 0), (5, 6))],infos)
530 f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
532 mm1=MEDFileUMesh.New()
533 mm1.setCoords(m1.getCoords())
534 mm1.setMeshAtLevel(0,m1)
535 mm1.setName(m1.getName())
537 ff1=MEDFileField1TS.New()
538 ff1.setFieldNoProfileSBT(f1)
540 da=ff1.getUndergroundDataArray().setIJ(0,0,nv)
542 f2=MEDLoader.ReadFieldNode(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
543 self.assertTrue(not f1.isEqual(f2,1e-12,1e-12))
544 f1.getArray().setIJ(0,0,nv)
545 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
548 f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
550 mm1=MEDFileUMesh.New()
551 mm1.setCoords(m1.getCoords())
552 mm1.setMeshAtLevel(0,m1)
553 mm1.setName(m1.getName())
555 ff1=MEDFileField1TS.New()
556 ff1.setFieldNoProfileSBT(f1)
558 f2=MEDLoader.ReadFieldGaussNE(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
559 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
560 da,infos=ff1.getUndergroundDataArrayExt()
561 f2.getArray().setName(da.getName())#da has the same name than f2
562 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
563 self.assertEqual([((3, 0), (0, 6)), ((4, 0), (6, 14)), ((6, 0), (14, 20))],infos)
566 f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler();
567 f1InvalidCpy=f1.deepCpy()
568 f1InvalidCpy.setDiscretization(MEDCouplingFieldDiscretizationGauss())
569 f1InvalidCpy2=f1.deepCpy()
570 f1InvalidCpy2.setDiscretization(MEDCouplingFieldDiscretizationGauss())
572 mm1=MEDFileUMesh.New()
573 mm1.setCoords(m1.getCoords())
574 mm1.setMeshAtLevel(0,m1)
575 mm1.setName(m1.getName())
577 ff1=MEDFileField1TS.New()
578 self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy) # fails because no Gauss localization per cell set !*
579 f1InvalidCpy2.getDiscretization().setArrayOfDiscIds(f1.getDiscretization().getArrayOfDiscIds()) # fails because no Gauss localization set whereas gauss locid per cell given !
580 self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy2)
581 ff1.setFieldNoProfileSBT(f1)
583 ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2])
584 f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0)
585 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
586 sbt=ff2.getFieldSplitedByType2()
587 loc1=ff2.getLocalization("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5")
588 self.assertEqual("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5",loc1.getName())
589 self.assertEqual((-1, 1,-1,-1,1,-1,-1,0,0,-1,0,0),loc1.getRefCoords())
590 self.assertEqual(6,loc1.getNumberOfPointsInCells())
591 self.assertEqual(3,loc1.getNumberOfGaussPoints())
592 self.assertEqual(2,loc1.getDimension())
593 da,infos=ff2.getUndergroundDataArrayExt()
594 f2.getArray().setName(da.getName())#da has the same name than f2
595 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
596 self.assertEqual(53,da.getNumberOfTuples())
597 self.assertEqual([((3, 0), (0, 18)), ((3, 1), (18, 30)), ((3, 2), (30, 36)), ((4, 0), (36, 42)), ((4, 1), (42, 44)), ((6, 0), (44, 53))],infos)
601 def testMEDFileData1(self):
605 m1=MEDLoaderDataForTest.build1DMesh_1()
606 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
607 mmm1=MEDFileMeshMultiTS.New() ;
608 mmm1.setOneTimeStep(mm1)
609 m2=MEDLoaderDataForTest.build2DCurveMesh_1()
610 mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName())
611 mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2)
612 ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2)
614 for name,mmm in zip(["1DMesh_1","2DCurveMesh_1"],ms):
615 self.assertEqual(name,mmm.getName())
616 self.assertEqual(type(mmm),MEDFileUMesh)
618 self.assertEqual(('1DMesh_1', '2DCurveMesh_1'),d.getMeshes().getMeshesNames())
620 ff1=MEDFileFieldMultiTS.New()
621 ff21=MEDFileFieldMultiTS.New()
622 ff22=MEDFileFieldMultiTS.New()
623 f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False)
624 f1.getArray().setInfoOnComponent(0,"power [kW]")
625 ff1.appendFieldNoProfileSBT(f1)
626 f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False)
627 f21.getArray().setInfoOnComponent(0,"sta [mm]") ;
628 ff21.appendFieldNoProfileSBT(f21)
629 f22=f21.deepCpy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ;
630 f22.applyFunc(2,"3*x*IVec+2*x*JVec")
631 f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]")
632 ff22.appendFieldNoProfileSBT(f22)
633 fs=MEDFileFields.New()
634 fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22)
635 for name,fmts in zip(["f1","f21","f22"],fs):
636 self.assertEqual(name,fmts.getName())
640 fname2="Pyfile29_2.med"
643 d2=MEDFileData.New(fname2)
644 self.assertEqual(2,d2.getNumberOfMeshes())
645 self.assertEqual(3,d2.getNumberOfFields())
646 self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))
647 self.assertTrue(isinstance(d2.getMeshes()[0],MEDFileUMesh))
648 self.assertTrue(isinstance(d2.getMeshes()['2DCurveMesh_1'],MEDFileUMesh))
649 m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
650 self.assertTrue(m1.isEqual(m1bis,1e-12))
651 self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
652 self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
653 self.assertEqual([(-1,-1,0.0)],d2.getFields()[2].getTimeSteps())
654 self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
655 self.assertEqual([(-1,-1,0.0)],d2.getFields()["f21"].getTimeSteps())
658 def testMEDField9(self):
659 # first test field profile WR. Full type but with some type missing
661 m1=MEDLoaderDataForTest.build2DMesh_3()
662 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
664 ff1=MEDFileField1TS.New()
665 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1")
666 d=DataArrayDouble.New() ; d.alloc(2*9,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
667 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
668 da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1")
670 ff1.setFieldProfile(f1,mm1,0,da)
671 ff1.changePflsNames([(["sup1_NORM_QUAD4"],"ForV650")])
675 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
676 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))# profiles names cannot be contracted in pfl array name
677 self.assertTrue(vals.isEqual(d,1e-14))
679 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
680 ff3=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
681 ff2.deepCpyGlobs(ff3)
682 sbt=ff2.getFieldSplitedByType2()
683 self.assertEqual(3,sbt[0][0])#TRI3
684 self.assertEqual(0,sbt[0][1][0][0])#CELL For TRI3
685 self.assertEqual("",sbt[0][1][0][2])#no profile For TRI3
686 self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],sbt[0][1][0][1].getValues())# values for TRI3
687 self.assertEqual(4,sbt[1][0])#QUAD4
688 self.assertEqual(0,sbt[1][1][0][0])#CELL For QUAD4
689 self.assertEqual("ForV650",sbt[1][1][0][2])# profile For QUAD4
690 self.assertEqual([19, 20, 21, 22, 23, 24],sbt[1][1][0][1].getValues())# values for QUAD4
691 self.assertEqual([0],ff2.getTypesOfFieldAvailable())
692 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
693 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
694 self.assertTrue(vals.isEqual(d,1e-14))
697 def testMEDField10(self):
699 m1=MEDLoaderDataForTest.build2DMesh_1()
700 m1.renumberCells([0,1,4,2,3,5],False)
701 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
703 ff1=MEDFileFieldMultiTS.New()
704 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
705 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
706 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
707 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
709 ff1.appendFieldProfile(f1,mm1,0,da)
710 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
711 ff1.appendFieldProfile(f1,mm1,0,da)
715 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
716 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
717 self.assertTrue(vals.isEqual(e,1e-14))
718 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
719 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
720 self.assertTrue(vals.isEqual(d,1e-14))
722 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
723 self.assertEqual([(-1,-1,0.0), (1,2,1.2)],ff2.getTimeSteps())
724 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
725 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
726 self.assertTrue(vals.isEqual(e,1e-14))
727 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
728 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
729 self.assertTrue(vals.isEqual(d,1e-14))
732 # idem testMEDField9 method except that here testing profile on nodes and not on cells.
733 def testMEDField11(self):
735 m1=MEDLoaderDataForTest.build2DMesh_1()
736 m1.renumberCells([0,1,4,2,3,5],False)
737 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
739 ff1=MEDFileField1TS.New()
740 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
741 d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
742 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
743 da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
745 ff1.setFieldProfile(f1,mm1,0,da)
746 self.assertEqual(ff1.getNonEmptyLevels(),(-1, []))
749 vals,pfl=ff1.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
750 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
751 self.assertTrue(vals.isEqual(d,1e-14))
753 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
754 vals,pfl=ff2.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
755 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
756 self.assertTrue(vals.isEqual(d,1e-14))
759 def testMEDField12(self):
761 m1=MEDLoaderDataForTest.build2DMesh_1()
762 m1.renumberCells([0,1,4,2,3,5],False)
763 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
765 ff1=MEDFileFieldMultiTS.New()
766 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
767 d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
768 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
769 da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
771 ff1.appendFieldProfile(f1,mm1,0,da)
772 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
773 ff1.appendFieldProfile(f1,mm1,0,da)
776 vals,pfl=ff1.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
777 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
778 self.assertTrue(vals.isEqual(e,1e-14))
779 vals,pfl=ff1.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
780 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
781 self.assertTrue(vals.isEqual(d,1e-14))
783 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
784 vals,pfl=ff2.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
785 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
786 self.assertTrue(vals.isEqual(e,1e-14))
787 vals,pfl=ff2.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
788 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
789 self.assertTrue(vals.isEqual(d,1e-14))
792 def testMEDField13(self):
794 m1=MEDLoaderDataForTest.build2DMesh_1()
795 m1.renumberCells([0,1,4,2,3,5],False)
797 m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
798 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
800 ff1=MEDFileField1TS.New()
801 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F3Node")
802 d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
803 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
804 da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
806 ff1.setFieldProfile(f1,mm1,0,da)
809 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
810 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
811 self.assertTrue(vals.isEqual(d,1e-14))
813 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
814 vals,pfl=ff2.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
815 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
816 self.assertTrue(vals.isEqual(d,1e-14))
819 def testMEDField14(self):
821 m1=MEDLoaderDataForTest.build2DMesh_1()
822 m1.renumberCells([0,1,4,2,3,5],False)
824 m1=m1.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
825 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
827 ff1=MEDFileFieldMultiTS.New()
828 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
829 d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
830 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
831 da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
833 ff1.appendFieldProfile(f1,mm1,0,da)
834 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
835 ff1.appendFieldProfile(f1,mm1,0,da)
838 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
839 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
840 self.assertTrue(vals.isEqual(d,1e-14))
841 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
842 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
843 self.assertTrue(vals.isEqual(e,1e-14))
844 self.assertEqual([[3],[3]],ff1.getTypesOfFieldAvailable())
846 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
847 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
848 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
849 self.assertTrue(vals.isEqual(d,1e-14))
850 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
851 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
852 self.assertTrue(vals.isEqual(e,1e-14))
854 # Tricky test of the case of in a MED file containing a Field on GAUSS_NE is lying on a profile that is reality represents all the geom entities of a level.
855 # By default when using setFieldProfile method such profile is not created because it is not useful ! So here a trick is used to force MEDLoader to do that
856 # for the necessity of the test ! The idea is too create artificially a mesh having one more fictious cell per type and to roll back right after !
857 def testMEDField15(self):
859 m0=MEDLoaderDataForTest.build2DMesh_1()
860 m0.renumberCells([0,1,4,2,3,5],False)
862 m1=m0.buildPartOfMySelf([0,1,1,2,3,3,4,4],True) ; m1.setName(tmp) # suppression of last cell that is a polygon and creation of one more cell per type
863 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
864 ff1=MEDFileField1TS.New()
865 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
866 d=DataArrayDouble.New() ; d.alloc(2*20,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
867 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
868 da=DataArrayInt.New(); da.setValues([0,1,3,4,6],5,1) ; da.setName("sup1NodeElt")
870 ff1.setFieldProfile(f1,mm1,0,da)
871 m1=m0.buildPartOfMySelf(range(5),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
874 f1=ff1.getFieldOnMeshAtLevel(ON_GAUSS_NE,m1,0)
875 f2,p1=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; f2.setName("")
876 self.assertTrue(p1.isIdentity())
877 self.assertEqual(5,p1.getNumberOfTuples())
878 self.assertTrue(f1.getArray().isEqual(f2,1e-12))
880 # Test for getFieldAtTopLevel method
881 def testMEDField16(self):
883 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
885 mm1=MEDFileUMesh.New()
886 mm1.setCoords(m1.getCoords())
887 mm1.setMeshAtLevel(0,m1)
888 mm1.setName(m1.getName())
889 ff1=MEDFileField1TS.New()
890 ff1.setFieldNoProfileSBT(f1)
891 m2=m1.buildDescendingConnectivity()[0]
892 m2.sortCellsInMEDFileFrmt()
893 m2.setName(m1.getName())
894 mm1.setMeshAtLevel(-1,m2)
896 f2=m2.getMeasureField(True)
897 dd=DataArrayDouble.New()
898 dd.alloc(f2.getArray().getNumberOfTuples(),3)
899 dd[:,0]=f2.getArray()
900 dd[:,1]=2*f2.getArray()
901 dd[:,2]=3*f2.getArray()
902 f2=f2.buildNewTimeReprFromThis(ONE_TIME,False)
904 f2.copyTinyStringsFrom(f1)
905 f2.copyTinyAttrFrom(f1)
906 ff1.setFieldNoProfileSBT(f2)
908 # Reading Pyfile37.med
909 ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
910 f1bis=ff2.getFieldAtLevel(ON_CELLS,0)
911 self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
912 f1bis=ff2.getFieldAtLevel(ON_CELLS,-1)
913 self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
914 f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
915 self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
919 ff1=MEDFileField1TS.New()
920 ff1.setFieldNoProfileSBT(f2)
922 ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
923 f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
924 self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
927 # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
928 def testMEDField17(self):
930 m1=MEDLoaderDataForTest.build2DMesh_1()
931 m1.renumberCells([0,1,4,2,3,5],False)
932 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
934 ffs=MEDFileFields.New()
935 ff1=MEDFileFieldMultiTS.New()
936 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
937 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
938 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
939 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
941 ff1.appendFieldProfile(f1,mm1,0,da)
942 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
943 ff1.appendFieldProfile(f1,mm1,0,da)
945 ffs.setFieldAtPos(0,ff1)
949 ffsr=MEDFileFields.New(fname)
950 ff3=ffsr.getFieldAtPos(0)
951 f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
952 self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
955 # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
956 def testMEDField18(self):
958 m1=MEDLoaderDataForTest.build2DMesh_1()
959 m1.renumberCells([0,1,4,2,3,5],False)
960 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
962 ffs=MEDFileFields.New()
963 ff1=MEDFileFieldMultiTS.New()
964 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
965 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
966 f1.setArray(d) # note that f1 is NOT defined fully (no mesh !). It is not a bug of test it is too test that MEDFileField1TS.appendFieldProfile is NOT sensible of that.
967 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
969 ff1.appendFieldProfile(f1,mm1,0,da)
970 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
971 ff1.appendFieldProfile(f1,mm1,0,da)
975 ffsr=MEDFileFields.New(fname)
976 ff3=ffsr.getFieldAtPos(0)
977 f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
978 self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
981 def testMEDFieldBug1(self):
983 d=MEDFileData.New(fname)
984 self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs())
987 def testMEDMesh8(self):
988 m=MEDLoaderDataForTest.build1DMesh_1()
989 m.convertQuadraticCellsToLinear()
990 mm=MEDFileUMesh.New()
991 mm.setMeshAtLevel(0,m)
992 g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1")
993 g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2")
994 g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3")
995 mm.setGroupsAtLevel(0,[g1,g2],False)
996 self.assertEqual(('g1','g2'),mm.getGroupsNames())
997 self.assertEqual(('Family_-2','Family_-3'),mm.getFamiliesNames())
998 self.assertEqual(('Family_-2',),mm.getFamiliesOnGroup('g1'))
999 self.assertEqual(('Family_-3',),mm.getFamiliesOnGroup('g2'))
1000 mm.assignFamilyNameWithGroupName()
1001 self.assertEqual(('g1','g2'),mm.getGroupsNames())
1002 self.assertEqual(('g1','g2'),mm.getFamiliesNames())
1003 self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1'))
1004 self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2'))
1006 mm=MEDFileUMesh.New()
1007 mm.setMeshAtLevel(0,m)
1008 mm.setGroupsAtLevel(0,[g1,g2,g3],False)
1009 self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1010 self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1011 self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1012 self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1013 self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1014 mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found
1015 self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1016 self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1017 self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1018 self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1019 self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1020 mm.changeFamilyId(5,6)
1021 g=mm.getGroupArr(0,"g3")
1022 self.assertTrue(g.isEqual(g3));
1023 g=mm.getGroupArr(0,"g2")
1024 self.assertTrue(g.isEqual(g2));
1025 g=mm.getGroupArr(0,"g1")
1026 self.assertTrue(g.isEqual(g1));
1029 # bug detected by gauthier
1030 def testMEDLoaderMEDLoaderNSReadFieldDoubleDataInMedFile(self):
1031 fname="Pyfile41.med"
1032 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
1034 mm1=MEDFileUMesh.New()
1035 mm1.setCoords(m1.getCoords())
1036 mm1.setMeshAtLevel(0,m1)
1038 ff1=MEDFileField1TS.New()
1039 ff1.setFieldNoProfileSBT(f1)
1041 # writing mesh1 and field1, now creation of mesh2 and field2
1044 m2.translate([0.5,0.6,0.7])
1045 m2.setName("3DSurfMesh_2")
1046 f2.getArray()[:]*=2.
1047 f2.setName("VectorFieldOnCells2")
1048 mm2=MEDFileUMesh.New()
1049 mm2.setCoords(m2.getCoords())
1050 mm2.setMeshAtLevel(0,m2)
1052 ff2=MEDFileField1TS.New()
1053 ff2.setFieldNoProfileSBT(f2)
1056 f3=MEDLoader.ReadFieldCell(fname,"3DSurfMesh_1",0,"VectorFieldOnCells",0,1)
1057 self.assertTrue(f3.isEqual(f1,1e-12,1e-12))
1058 f4=MEDLoader.ReadFieldCell(fname,"3DSurfMesh_2",0,"VectorFieldOnCells2",0,1)
1059 self.assertTrue(f4.isEqual(f2,1e-12,1e-12))
1062 def testMEDLoaderMultiLevelCellField1(self):
1063 fname="Pyfile42.med"
1064 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1065 m=MEDFileUMesh.New()
1066 m.setCoords(m2.getCoords())
1067 m.setMeshAtLevel(0,m2)
1068 m.setMeshAtLevel(-1,m1)
1069 m.setMeshAtLevel(-2,m0)
1073 compNames1=["comp1","comp2","comp3"]
1074 ff1=MEDFileField1TS.New()
1075 da2=DataArrayDouble.New()
1076 da2.alloc(m2.getNumberOfCells()*len(compNames1),1)
1078 da2.rearrange(len(compNames1))
1079 da2.setInfoOnComponents(compNames1)
1080 f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f2.setName(FieldName1) ; f2.setArray(da2) ; f2.setMesh(m2) ; f2.checkCoherency()
1081 ff1.setFieldNoProfileSBT(f2)
1082 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0]))
1083 da0=DataArrayDouble.New()
1084 da0.alloc(m0.getNumberOfCells()*len(compNames1),1)
1086 da0.rearrange(len(compNames1))
1087 da0.setInfoOnComponents(compNames1)
1088 f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName1) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkCoherency()
1089 ff1.setFieldNoProfileSBT(f0)
1090 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-2]))
1091 da1=DataArrayDouble.New()
1092 da1.alloc(m1.getNumberOfCells()*len(compNames1),1)
1094 da1.rearrange(len(compNames1))
1095 da1.setInfoOnComponents(compNames1)
1096 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName1) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkCoherency()
1097 ff1.setFieldNoProfileSBT(f1)
1098 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1103 compNames2=["comp11","comp22"]
1104 ff2=MEDFileField1TS.New()
1105 da0=DataArrayDouble.New()
1106 da0.alloc(m0.getNumberOfCells()*2,1)
1109 da0.setInfoOnComponents(compNames2)
1110 f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName2) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkCoherency()
1111 ff2.setFieldNoProfileSBT(f0)
1112 self.assertEqual(ff2.getNonEmptyLevels(),(0, [0]))
1113 da1=DataArrayDouble.New()
1114 da1.alloc(m1.getNumberOfCells()*len(compNames2),1)
1116 da1.rearrange(len(compNames2))
1117 da1.setInfoOnComponents(compNames2)
1118 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName2) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkCoherency()
1119 ff2.setFieldNoProfileSBT(f1)
1120 self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1124 ff1=MEDFileField1TS.New(fname,FieldName1,-1,-1)
1125 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1126 self.assertEqual(ff1.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')]), (3, [(0, (84, 148), '', '')]), (4, [(0, (148, 212), '', '')])])
1127 ff2=MEDFileField1TS.New(fname,FieldName2,-1,-1)
1128 self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1129 self.assertEqual(ff2.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')])])
1132 def testFieldOnPflRetrieveOnMdimRelMax1(self):
1133 fname="Pyfile43.med"
1134 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1135 m=MEDFileUMesh.New()
1136 m.setMeshAtLevel(0,m2)
1137 m.setMeshAtLevel(-1,m1)
1138 m.setMeshAtLevel(-2,m0)
1139 f=MEDFileField1TS.New()
1140 ff=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
1141 ff.setName("NodeFieldPfl")
1142 arr=DataArrayDouble.New() ; arr.setValues([1.,10.,100.,2.,20.,200.],2,3)
1144 pfl=DataArrayInt.New() ; pfl.setValues([2,3],2,1) ; pfl.setName("PflNode")
1145 f.setFieldProfile(ff,m,-2,pfl)
1146 tes0=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1147 self.assertEqual(ON_NODES,tes0.getTypeOfField())
1148 self.assertEqual(1,tes0.getMesh().getMeshDimension())
1149 self.assertEqual(1,tes0.getMesh().getNumberOfCells())
1150 self.assertEqual(2,tes0.getMesh().getNumberOfNodes())
1151 self.assertEqual([1,0,1],tes0.getMesh().getNodalConnectivity().getValues())
1152 self.assertEqual([0,3],tes0.getMesh().getNodalConnectivityIndex().getValues())
1153 self.assertEqual(2,tes0.getArray().getNumberOfTuples())
1154 self.assertEqual(3,tes0.getArray().getNumberOfComponents())
1155 expected1=[1.,10.,100.,2.,20.,200.]
1156 nodeCoordsWithValue1=[10.,2.5,0.]
1157 nodeCoordsWithValue2=[10.,3.75,0.]
1159 self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
1160 self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
1163 self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
1167 tes1=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1168 self.assertEqual(ON_CELLS,tes1.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1169 self.assertEqual(0,tes1.getMesh().getMeshDimension())
1170 self.assertEqual(2,tes1.getMesh().getNumberOfCells())
1171 self.assertEqual(135,tes1.getMesh().getNumberOfNodes())
1172 self.assertEqual([0,2,0,3],tes1.getMesh().getNodalConnectivity().getValues())
1173 self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
1174 self.assertEqual(2,tes1.getArray().getNumberOfTuples())
1175 self.assertEqual(3,tes1.getArray().getNumberOfComponents())
1177 self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
1182 pfl=DataArrayInt.New() ; pfl.setValues([3,2],2,1) ; pfl.setName("PflNode")
1183 f=MEDFileField1TS.New()
1184 f.setFieldProfile(ff,m,-2,pfl)
1185 tes2=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1186 self.assertEqual(ON_NODES,tes2.getTypeOfField())
1187 self.assertEqual(1,tes2.getMesh().getMeshDimension())
1188 self.assertEqual(1,tes2.getMesh().getNumberOfCells())
1189 self.assertEqual(2,tes2.getMesh().getNumberOfNodes())
1190 self.assertEqual([1,0,1],tes2.getMesh().getNodalConnectivity().getValues())
1191 self.assertEqual([0,3],tes2.getMesh().getNodalConnectivityIndex().getValues())
1192 self.assertEqual(2,tes2.getArray().getNumberOfTuples())
1193 self.assertEqual(3,tes2.getArray().getNumberOfComponents())
1194 expected2=[2.,20.,200.,1.,10.,100.]
1196 self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
1197 self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
1200 self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
1203 tes3=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1204 self.assertEqual(ON_CELLS,tes3.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1205 self.assertEqual(0,tes3.getMesh().getMeshDimension())
1206 self.assertEqual(2,tes3.getMesh().getNumberOfCells())
1207 self.assertEqual(135,tes3.getMesh().getNumberOfNodes())
1208 self.assertEqual([0,3,0,2],tes3.getMesh().getNodalConnectivity().getValues())
1209 self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
1210 self.assertEqual(2,tes3.getArray().getNumberOfTuples())
1211 self.assertEqual(3,tes3.getArray().getNumberOfComponents())
1213 self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
1217 def testDuplicateNodesOnM1Group1(self):
1218 fname="Pyfile44.med"
1219 m=MEDCouplingCMesh.New()
1220 m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1221 m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1222 m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1223 m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1224 m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1225 m2.setName(m.getName())
1226 grp=DataArrayInt.New([4,6,8]) ; grp.setName("Grp")
1227 grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1228 mm=MEDFileUMesh.New()
1229 mm.setMeshAtLevel(0,m)
1230 mm.setMeshAtLevel(-1,m2)
1231 mm.setGroupsAtLevel(-1,[grp,grp2])
1232 grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1233 mm.setGroupsAtLevel(1,[grpNode])
1234 ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1235 ref1=[4,9,8,14,15,4,10,9,15,16,4,11,10,16,17]
1236 ref2=[4,9,8,14,30,4,10,9,30,31,4,11,10,31,32]
1238 self.assertEqual(30,mm.getNumberOfNodes())
1239 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1240 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())
1242 nodes,cells,cells2=mm.duplicateNodesOnM1Group("Grp")
1243 self.assertEqual([15,16,17],nodes.getValues());
1244 self.assertEqual([7,8,9],cells.getValues());
1245 self.assertEqual([12,13,14],cells2.getValues());
1246 self.assertEqual(33,mm.getNumberOfNodes())
1247 self.assertEqual([4,6,8],mm.getGroupArr(-1,"Grp").getValues())
1248 self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1249 self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1250 self.assertEqual([17,18,19],mm.getGroupArr(-1,"Grp_dup").getValues())
1251 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())#cells 7,8,9 and 12,13,14 are lying on "Grp" but only 7,8 and 9 are renumbered
1252 self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())#
1253 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),2,1e-12);# Grp_dup and Grp are not equal considering connectivity only
1254 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1255 refValues=DataArrayDouble.New([1.21,1.32,1.43,1.54,1.65,1.32,1.44,1.56,1.68,1.8,1.43,1.56,1.69,1.82,1.95,1.54,1.68,1.82,1.96,2.1])
1256 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1257 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1259 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1260 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1261 refValues2=refValues[:] ; refValues2[7:10]=[1.365,1.26,1.35]
1262 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1263 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1267 def testDuplicateNodesOnM1Group2(self):
1268 fname="Pyfile45.med"
1269 m=MEDCouplingCMesh.New()
1270 m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1271 m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1272 m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1273 m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1274 m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1275 m2.setName(m.getName())
1276 grp=DataArrayInt.New([4,6]) ; grp.setName("Grp")
1277 grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1278 mm=MEDFileUMesh.New()
1279 mm.setMeshAtLevel(0,m)
1280 mm.setMeshAtLevel(-1,m2)
1281 mm.setGroupsAtLevel(-1,[grp,grp2])
1282 grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1283 mm.setGroupsAtLevel(1,[grpNode])
1284 ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1285 ref1=[4,9,8,14,15,4,10,9,15,16]
1286 ref2=[4,9,8,14,30,4,10,9,30,16]
1288 self.assertEqual(30,mm.getNumberOfNodes())
1289 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1290 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())
1292 nodes,cells,cells2=mm.duplicateNodesOnM1Group("Grp")
1293 self.assertEqual([15],nodes.getValues());
1294 self.assertEqual([7,8],cells.getValues());
1295 self.assertEqual([12,13],cells2.getValues());
1296 self.assertEqual(31,mm.getNumberOfNodes())
1297 self.assertEqual([4,6],mm.getGroupArr(-1,"Grp").getValues())
1298 self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1299 self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1300 self.assertEqual([17,18],mm.getGroupArr(-1,"Grp_dup").getValues())
1301 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())#cells 7,8,9 and 12,13,14 are lying on "Grp" but only 7,8 and 9 are renumbered
1302 self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())#
1303 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),2,1e-12);# Grp_dup and Grp are not equal considering connectivity only
1304 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1305 refValues=DataArrayDouble.New([1.21,1.32,1.43,1.54,1.65,1.32,1.44,1.56,1.68,1.8,1.43,1.56,1.69,1.82,1.95,1.54,1.68,1.82,1.96,2.1])
1306 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1307 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1309 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1310 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1311 refValues2=refValues[:] ; refValues2[7:9]=[1.365,1.47]
1312 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1313 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1317 def testBasicConstructors(self):
1318 fname="Pyfile18.med"
1319 m=MEDFileMesh.New(fname)
1320 m=MEDFileMesh.New(fname,"ExampleOfMultiDimW",-1,-1)
1321 m=MEDFileMesh.New(fname)
1322 m=MEDFileUMesh(fname,"ExampleOfMultiDimW",-1,-1)
1323 m=MEDFileUMesh(fname)
1326 m=MEDFileCMesh("MEDFileMesh5.med")
1327 m=MEDFileCMesh("MEDFileMesh5.med","myFirstCartMesh",-1,-1)
1329 m=MEDFileMeshMultiTS()
1330 m=MEDFileMeshMultiTS(fname)
1331 m=MEDFileMeshMultiTS(fname,"ExampleOfMultiDimW")
1333 m=MEDFileMeshes(fname)
1335 m=MEDFileField1TS(fname,"FieldOnFacesShuffle",2,7)
1336 m=MEDFileFieldMultiTS()
1337 m=MEDFileFieldMultiTS(fname,"FieldOnFacesShuffle")
1339 m=MEDFileFields(fname)
1341 m=MEDFileData(fname)
1343 m=DataArrayInt() ; m=DataArrayInt(5,2) ; m=DataArrayInt([6,5,4,3,2,1],3,2)
1344 m=DataArrayDouble() ; m=DataArrayDouble(5,2) ; m=DataArrayDouble([6,5,4,3,2,1],3,2)
1345 m=MEDCouplingUMesh("jjj",2) ; m=MEDCouplingUMesh()
1346 m=MEDCouplingCMesh()
1347 m=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1348 m=MEDCouplingFieldTemplate(ON_NODES)
1349 m=MEDCouplingMultiFields([])
1350 m=MEDCouplingFieldOverTime([])
1353 # This is a non regression test. When a field lies partially on a mesh but fully on one of its geometric type.
1354 def testBugSemiPartialField(self):
1355 fname="Pyfile46.med"
1356 m=MEDLoaderDataForTest.build2DMesh_3()
1357 m=m[:10] ; m.setName("mesh")
1358 f=m.getMeasureField(ON_CELLS)
1359 f=f.buildNewTimeReprFromThis(ONE_TIME,False)
1361 f.setName("SemiPartialField")
1363 f1=f[:6] ; f1.getMesh().setName(m.getName())
1364 f2=f[6:] ; f2.getMesh().setName(m.getName())
1366 mm=MEDFileUMesh.New()
1367 mm.setMeshAtLevel(0,m)
1368 ff=MEDFileField1TS.New()
1369 ff.setFieldProfile(f1,mm,0,DataArrayInt.Range(0,6,1)) # no name on profile -> normally it is an error but in this special case
1373 ff2=MEDFileField1TS.New(fname,f.getName(),f.getTime()[1],f.getTime()[2])
1374 fread=ff2.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
1375 fread2=ff2.getFieldAtLevel(ON_CELLS,0)
1377 fread.checkCoherency()
1378 fread2.checkCoherency()
1379 self.assertTrue(fread.isEqual(f1,1e-12,1e-12))
1380 self.assertTrue(fread2.isEqual(f1,1e-12,1e-12))
1383 def testUnPolyze1(self):
1384 fname="Pyfile47.med"
1385 mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1386 ref=[13,14,14,12,12,12,12,12,12,12,12,13,12,14,14,13,15,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12]
1387 self.assertEqual(ref,mm.getFamilyFieldAtLevel(1).getValues())
1388 self.assertEqual(mm.unPolyze()[:3],(True,[[3,2,0],[4,3,2],[5,4,5],[14,2,9],[16,3,11],[31,2,14]],[[3,3,0],[4,3,3],[5,3,6],[14,3,9],[16,3,12],[18,1,15]]))
1390 self.assertEqual(mm.getGroupArr(0,"grp0_L0").getValues(),[0,1,2,6])
1391 self.assertEqual(mm.getGroupArr(0,"grp1_L0").getValues(),[1,3,4,5,6])
1392 self.assertEqual(mm.getGroupArr(-1,"grp0_LM1").getValues(),[1,2,3,4,5])
1393 self.assertEqual(mm.getGroupArr(-1,"grp1_LM1").getValues(),[3,4,5,6])
1394 self.assertEqual(mm.getGroupArr(-1,"grp2_LM1").getValues(),[2,6,7,8])
1395 self.assertEqual(mm.getGroupArr(1,"grp0_Node").getValues(),[0,11,15,16])
1396 self.assertEqual(mm.getGroupArr(1,"grp1_Node").getValues(),[1,2,13,14,16])
1397 self.assertEqual(mm.getFamilyFieldAtLevel(1).getValues(),ref)
1399 mm.setRenumFieldArr(0,None)
1400 mm.setFamilyFieldArr(-1,None)
1403 def testUnPolyze2(self):
1404 fname="Pyfile48.med"
1405 mfd=MEDFileData.New()
1406 mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1407 meshes=MEDFileMeshes.New()
1409 mfd.setMeshes(meshes)
1410 fields=MEDFileFields.New()
1411 mfd.setFields(fields)
1412 ff=MEDFileFieldMultiTS.New()
1413 fields.pushField(ff)
1415 f0_0=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f0_0.setName("f0")
1416 f0_0.setTime(9.5,3,4)
1417 da=DataArrayDouble.New(38*2) ; da.iota(6.) ; da.rearrange(2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1419 f0_0.setMesh(mm.getMeshAtLevel(0))
1420 ff.appendFieldNoProfileSBT(f0_0)
1421 ff0=ff.getTimeStepAtPos(0)
1422 f0_1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_1.setName("f0")
1423 f0_1.setTime(9.5,3,4)
1424 pfl=DataArrayInt.New([1,4,5,6]) ; pfl.setName("pfltest")
1425 f0_1.setMesh(mm.getMeshAtLevel(0)[pfl])
1426 da=DataArrayDouble.New([1401.,101401.,1602.,101602.,3100.,103100.,3101.,103101.],4,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1428 ff0.setFieldProfile(f0_1,mm,0,pfl)
1429 f0_2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_2.setName("f0")#provoquer error
1430 f0_2.setTime(9.5,3,4)
1431 pfl2=DataArrayInt.New([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfltestM1")
1432 da=DataArrayDouble.New([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.],8,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])#provoquer error
1433 f0_2.setMesh(mm.getMeshAtLevel(-1)[pfl2])
1435 ff0.setFieldProfile(f0_2,mm,-1,pfl2)
1436 mfd.getFields().shallowCpyGlobs(ff0)
1438 mfd.unPolyzeMeshes()
1440 fmts=mfd.getFields()[0]
1441 self.assertEqual(fmts.getNumberOfTS(),1)
1442 self.assertEqual(fmts.getTimeSteps(),[(3,4,9.5)])
1443 arr,entry=fmts.getUndergroundDataArrayExt(3,4)
1444 self.assertEqual(entry,[((3,0),(38,40)),((4,0),(40,43)),((5,0),(43,46)),((14,0),(46,48)),((16,0),(48,49)),((18,0),(49,50)),((40,0),(0,38))])
1445 self.assertTrue(arr[38:40].isEqualWithoutConsideringStr(DataArrayDouble([300.0,100300.0,301.0,100301.0],2,2),1e-8))
1446 self.assertTrue(arr[40:43].isEqualWithoutConsideringStr(DataArrayDouble([400.0,100400.0,401.0,100401.0,402.0,100402.0],3,2),1e-8))
1447 self.assertTrue(arr[43:46].isEqualWithoutConsideringStr(DataArrayDouble([3200.0,103200.0,3201.0,103201.0,3203.0,103203.0],3,2),1e-8))
1448 self.assertTrue(arr[46:48].isEqualWithoutConsideringStr(DataArrayDouble([1401.0,101401.0,3100.0,103100.0],2,2),1e-8))
1449 self.assertTrue(arr[48:49].isEqualWithoutConsideringStr(DataArrayDouble([1602.0,101602.0],1,2),1e-8))
1450 self.assertTrue(arr[49:50].isEqualWithoutConsideringStr(DataArrayDouble([3101.0,103101.0],1,2),1e-8))
1451 self.assertEqual(('NewPfl_0','NewPfl_1','NewPfl_2'),fmts.getPflsReallyUsed())
1452 self.assertEqual([(3,[(0,(38,40),'NewPfl_0','')]),(4,[(0,(40,43),'','')]),(5,[(0,(43,46),'','')]),(14,[(0,(46,48),'NewPfl_1','')]),(16,[(0,(48,49),'NewPfl_2','')]),(18,[(0,(49,50),'','')]),(40,[(1,(0,38),'','')])],fmts.getFieldSplitedByType(3,4))
1453 self.assertEqual(fmts.getProfile("NewPfl_0").getValues(),[0,1])
1454 self.assertEqual(fmts.getProfile("NewPfl_1").getValues(),[1,2])
1455 self.assertEqual(fmts.getProfile("NewPfl_2").getValues(),[2])
1456 ftest0=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,0,mfd.getMeshes()[0])
1457 self.assertTrue(ftest0.getArray().isEqualWithoutConsideringStr(DataArrayDouble([1401.,101401.,3100.,103100.,1602.,101602.,3101.,103101.],4,2),1e-8))
1458 self.assertEqual(ftest0.getMesh().getNodalConnectivity().getValues(),[14,4,5,6,7,14,26,27,28,29,16,20,21,22,23,24,25,18,30,31,32,33,34,35,36,37])
1459 self.assertEqual(ftest0.getMesh().getNodalConnectivityIndex().getValues(),[0,5,10,17,26])
1460 ftest1=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,-1,mfd.getMeshes()[0])
1461 self.assertTrue(ftest1.getArray().isEqualWithoutConsideringStr(DataArrayDouble([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.]),1e-8))
1462 self.assertEqual(ftest1.getMesh().getNodalConnectivity().getValues(),[3,0,1,2,3,3,4,5,4,6,7,8,9,4,10,11,12,13,4,14,15,16,17,5,18,19,20,21,22,5,23,24,25,26,27,5,31,32,33,34,35,36,37])
1463 self.assertEqual(ftest1.getMesh().getNodalConnectivityIndex().getValues(),[0,4,8,13,18,23,29,35,43])
1468 def testGaussWriteOnPfl1(self):
1469 fname="Pyfile49.med"
1470 fname2="Pyfile50.med"
1471 coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
1472 mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
1473 mQ8.allocateCells(1)
1474 mQ8.insertNextCell(NORM_QUAD8,range(8))
1475 mQ8.finishInsertingCells()
1476 mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
1477 mQ4.allocateCells(1)
1478 mQ4.insertNextCell(NORM_QUAD4,range(4))
1479 mQ4.finishInsertingCells()
1480 mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
1481 mT3.allocateCells(1)
1482 mT3.insertNextCell(NORM_TRI3,range(3))
1483 mT3.finishInsertingCells()
1485 tr=[[0.,4.],[2.,4.],[4.,4.],[6.,4.],[8.,4.],[10.,4.],[12.,4.],[14.,4.],[16.,4.],[18.,4.],[20.,4.],[0.,0.],[2.,0.], [0.,2.],[2.,2.],[4.,2.],[6.,2.],[8.,2.],[10.,2.],[12.,2.]]
1486 ms=11*[mT3]+2*[mQ4]+7*[mQ8]
1487 ms[:]=(elt.deepCpy() for elt in ms)
1488 for m,t in zip(ms,tr):
1489 d=m.getCoords() ; d+= t
1491 m=MEDCouplingUMesh.MergeUMeshes(ms)
1493 m2=m[:13] ; m2.setName(m.getName())
1494 ### Use case 1 : Pfl on all tri3 and on all quad4. If we were on CELLS or GAUSS_NE no pfl were needed. But here 2 discs in tri3.
1495 ### So here 2 pfls will be created (pfl_TRI3_loc_0 and pfl_TRI3_loc_1)
1496 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1499 da=DataArrayDouble(34) ; da.iota(3.)
1501 f.setName("fieldCellOnPflWithoutPfl")
1502 fInvalid=f.deepCpy()
1503 f.setGaussLocalizationOnCells([0,1,2,3,4,5,6,7,8],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1504 f.setGaussLocalizationOnCells([9,10],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13])
1505 f.setGaussLocalizationOnCells([11,12],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02])
1507 fInvalid2=fInvalid.deepCpy()
1508 fInvalid2.getDiscretization().setArrayOfDiscIds(f.getDiscretization().getArrayOfDiscIds())
1511 mm.setMeshAtLevel(0,m)
1514 f1ts=MEDFileField1TS.New()
1515 pfl=DataArrayInt(range(13)) ; pfl.setName("pfl")
1516 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set !
1517 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given !
1518 f1ts.setFieldProfile(f,mm,0,pfl)
1521 self.assertEqual(f1ts.getPfls(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1522 self.assertEqual(f1ts.getPflsReallyUsed(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1523 da1=DataArrayInt([0,1,2,3,4,5,6,7,8]) ; da1.setName("pfl_NORM_TRI3_loc_0")
1524 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_0").isEqual(da1))
1525 da1=DataArrayInt([9,10]) ; da1.setName("pfl_NORM_TRI3_loc_1")
1526 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_1").isEqual(da1))
1527 self.assertEqual(f1ts.getLocs(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1528 self.assertEqual(f1ts.getLocsReallyUsed(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1530 dataRead=MEDFileData.New(fname)
1531 mRead=dataRead.getMeshes()[0]
1532 f1tsRead=dataRead.getFields()[0][0]
1533 f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1534 f2=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1535 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
1536 f2_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1537 f2_bis.checkCoherency()
1538 self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12))
1540 MEDLoader.WriteField(fname2,f,True)
1541 f2_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1542 self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12))
1543 ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc
1544 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1545 pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2")
1546 m2=m[pfl] ; m2.setName(m.getName())
1549 da=DataArrayDouble(35) ; da.iota(3.)
1551 f.setName("fieldCellOnPflWithoutPfl2")
1552 f.setGaussLocalizationOnCells([0,1,3],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1553 f.setGaussLocalizationOnCells([2,4,5],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13])
1554 f.setGaussLocalizationOnCells([6,7,8,9],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02])
1558 mm.setMeshAtLevel(0,m)
1560 f1ts=MEDFileField1TS.New()
1561 f1ts.setFieldProfile(f,mm,0,pfl)
1562 self.assertEqual(f1ts.getPfls(),('pfl2_NORM_TRI3_loc_0','pfl2_NORM_TRI3_loc_1','pfl2_NORM_QUAD8_loc_2'))
1563 self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_0").getValues(),[1,2,6])
1564 self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_1").getValues(),[5,8,9])
1565 self.assertEqual(f1ts.getProfile("pfl2_NORM_QUAD8_loc_2").getValues(),[2,3,4,5])
1567 dataRead=MEDFileData.New(fname)
1568 mRead=dataRead.getMeshes()[0]
1569 f1tsRead=dataRead.getFields()[0][0]
1570 f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1571 f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1572 f3.renumberCells([0,1,3,2,4,5,6,7,8,9])
1573 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1574 f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1575 f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9])
1576 self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1578 MEDLoader.WriteField(fname2,f,True)
1579 f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1580 f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9])
1581 self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1582 ## Use case 3 : no pfl but creation of pfls due to gauss pts
1583 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1586 da=DataArrayDouble(60) ; da.iota(3.)
1588 f.setName("fieldCellWithoutPfl")
1589 f.setGaussLocalizationOnCells([0,1,2,3,4,5,6,7,8],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1590 f.setGaussLocalizationOnCells([9,10],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13])
1591 f.setGaussLocalizationOnCells([11,12],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02])
1592 f.setGaussLocalizationOnCells([13,14,15,17,18],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8],[0.8,0.1,0.03,0.07])
1593 f.setGaussLocalizationOnCells([16,19],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.1,0.1])
1596 mm.setMeshAtLevel(0,m)
1597 f1ts=MEDFileField1TS.New()
1598 f1ts.setFieldNoProfileSBT(f)
1599 self.assertEqual(f1ts.getPfls(),('Pfl_fieldCellWithoutPfl_NORM_TRI3_0','Pfl_fieldCellWithoutPfl_NORM_TRI3_1','Pfl_fieldCellWithoutPfl_NORM_QUAD8_3','Pfl_fieldCellWithoutPfl_NORM_QUAD8_4'))
1600 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_0").getValues(),[0,1,2,3,4,5,6,7,8])
1601 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_1").getValues(),[9,10])
1602 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_3").getValues(),[0,1,2,4,5])
1603 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_4").getValues(),[3,6])
1607 dataRead=MEDFileData.New(fname)
1608 mRead=dataRead.getMeshes()[0]
1609 f1tsRead=dataRead.getFields()[0][0]
1610 f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1611 f3.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1612 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1613 f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1614 f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1615 self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1617 MEDLoader.WriteField(fname2,f,True)
1618 f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1619 f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1620 self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1623 # Testing profile on nodes when the profile is identity but not on all nodes.
1624 def testMEDFieldPflOnNode1(self):
1625 fname="Pyfile51.med"
1626 coo=DataArrayDouble([0.,0.,0.5,0.,1.,0.,0.,0.5,0.5,0.5,1.,0.5,0.,1.,0.5,1.,1.,1.],9,2)
1627 m0=MEDCouplingUMesh("Mesh",2)
1629 m0.insertNextCell(NORM_TRI3,[1,4,2])
1630 m0.insertNextCell(NORM_TRI3,[4,5,2])
1631 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1632 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1633 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1634 m0.finishInsertingCells()
1636 m1=MEDCouplingUMesh(m0.getName(),1)
1638 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1640 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1642 m1.finishInsertingCells()
1646 m.setMeshAtLevel(0,m0)
1647 m.setMeshAtLevel(-1,m1)
1649 dt=3 ; it=2 ; tim=4.5
1650 fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1651 fieldNode0.setName("fieldNode0")
1652 fieldNode0.setTime(tim,dt,it)
1653 pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
1654 arr=DataArrayDouble([10,11,12,13,14])
1655 fieldNode0.setArray(arr)
1656 f0=MEDFileField1TS()
1657 f0.setFieldProfile(fieldNode0,m,0,pfl0)
1658 m.write(fname,2) ; f0.write(fname,0)
1659 fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1660 fieldNode1.setName("fieldNode1")
1661 fieldNode1.setTime(tim,dt,it)
1662 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1663 arr1=DataArrayDouble([20,21,22,23,24,25,26])
1664 fieldNode1.setArray(arr1)
1665 f1=MEDFileField1TS()
1666 f1.setFieldProfile(fieldNode1,m,-1,pfl1)
1669 ## Reading from file
1670 m=MEDFileMesh.New(fname)
1671 m0=m.getMeshAtLevel(0)
1672 m00=m0.deepCpy() ; m00=m00[[0,2]] ; m00.setName(m.getName()) ; m00.zipCoords()
1673 fieldNode0.setMesh(m00)
1674 f0=MEDFileField1TS.New(fname,fieldNode0.getName(),dt,it)
1675 ff0_1=f0.getFieldOnMeshAtLevel(ON_NODES,m0)
1676 ff0_1.checkCoherency()
1677 self.assertTrue(ff0_1.isEqual(fieldNode0,1e-12,1e-12))
1678 ff0_2=f0.getFieldAtLevel(ON_NODES,0)
1679 ff0_2.checkCoherency()
1680 self.assertTrue(ff0_2.isEqual(fieldNode0,1e-12,1e-12))
1681 ff0_3=f0.getFieldOnMeshAtLevel(ON_NODES,0,m)
1682 ff0_3.checkCoherency()
1683 self.assertTrue(ff0_3.isEqual(fieldNode0,1e-12,1e-12))
1684 ff0_4=MEDLoader.ReadFieldNode(fname,m.getName(),0,fieldNode0.getName(),dt,it)
1685 ff0_4.checkCoherency()
1686 self.assertTrue(ff0_4.isEqual(fieldNode0,1e-12,1e-12))
1687 f1=MEDFileField1TS.New(fname,fieldNode1.getName(),dt,it)
1688 m1=m.getMeshAtLevel(-1)
1689 m10=m1.deepCpy() ; m10=m10[[0,1,2,3,4,5,6,7]] ; m10.setName(m.getName()) ; m10.zipCoords()
1690 fieldNode1.setMesh(m10)
1691 ff1_1=f1.getFieldOnMeshAtLevel(ON_NODES,m1)
1692 ff1_1.checkCoherency()
1693 self.assertTrue(ff1_1.isEqual(fieldNode1,1e-12,1e-12))
1694 ff1_2=f1.getFieldAtLevel(ON_NODES,-1)
1695 ff1_2.checkCoherency()
1696 self.assertTrue(ff1_2.isEqual(fieldNode1,1e-12,1e-12))
1697 ff1_3=f1.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1698 ff1_3.checkCoherency()
1699 self.assertTrue(ff1_3.isEqual(fieldNode1,1e-12,1e-12))
1700 ff1_4=MEDLoader.ReadFieldNode(fname,m.getName(),-1,fieldNode1.getName(),dt,it)
1701 ff1_4.checkCoherency()
1702 self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1703 self.assertRaises(InterpKernelException,f1.getFieldOnMeshAtLevel,ON_NODES,m0) # error because impossible to build a sub mesh at level 0 lying on nodes [0,1,2,3,4,5,6]
1704 self.assertRaises(InterpKernelException,f1.getFieldAtLevel,ON_NODES,0) # error because impossible to build a sub mesh at level 0 lying on nodes [0,1,2,3,4,5,6]
1705 self.assertRaises(InterpKernelException,f1.getFieldOnMeshAtLevel,ON_NODES,0,m) # error because impossible to build a sub mesh at level 0 lying on nodes [0,1,2,3,4,5,6]
1706 arr_r,pfl1_r=f1.getFieldWithProfile(ON_NODES,-1,m)
1707 arr_r.setName(fieldNode1.getArray().getName())
1708 self.assertTrue(arr_r.isEqual(fieldNode1.getArray(),1e-12))
1709 pfl1_r.setName(pfl1.getName())
1710 self.assertTrue(pfl1_r.isEqual(pfl1))
1713 # Testing profile on nodes when the profile is identity but not on all nodes.
1714 def testMEDFieldPflOnCell1(self):
1715 fname="Pyfile52.med"
1716 coo=DataArrayDouble([0.,0.,0.5,0.,1.,0.,0.,0.5,0.5,0.5,1.,0.5,0.,1.,0.5,1.,1.,1.],9,2)
1717 m0=MEDCouplingUMesh("Mesh",2)
1719 m0.insertNextCell(NORM_TRI3,[1,4,2])
1720 m0.insertNextCell(NORM_TRI3,[4,5,2])
1721 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1722 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1723 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1724 m0.finishInsertingCells()
1726 m1=MEDCouplingUMesh(m0.getName(),1)
1728 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1730 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1732 m1.finishInsertingCells()
1736 m.setMeshAtLevel(0,m0)
1737 m.setMeshAtLevel(-1,m1)
1739 dt=3 ; it=2 ; tim=4.5
1740 fieldCell0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1741 fieldCell0.setName("fieldCell0")
1742 fieldCell0.setTime(tim,dt,it)
1743 pfl0=DataArrayInt([0,1,2]) ; pfl0.setName("PflIdentity0") # important to keep like that
1744 arr=DataArrayDouble([10,11,12])
1745 fieldCell0.setArray(arr)
1746 f0=MEDFileField1TS()
1747 f0.setFieldProfile(fieldCell0,m,0,pfl0)
1748 m.write(fname,2) ; f0.write(fname,0)
1749 fieldCell1=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1750 fieldCell1.setName("fieldCell1")
1751 fieldCell1.setTime(tim,dt,it)
1752 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1753 arr1=DataArrayDouble([20,21,22,23,24,25,26])
1754 fieldCell1.setArray(arr1)
1755 f1=MEDFileField1TS()
1756 f1.setFieldProfile(fieldCell1,m,-1,pfl1)
1759 ## Reading from file
1760 m=MEDFileMesh.New(fname)
1761 m0=m.getMeshAtLevel(0)
1762 m00=m0.deepCpy() ; m00=m00[pfl0] ; m00.setName(m.getName())
1763 fieldCell0.setMesh(m00)
1764 f0=MEDFileField1TS.New(fname,fieldCell0.getName(),dt,it)
1765 ff0_1=f0.getFieldOnMeshAtLevel(ON_CELLS,m0)
1766 ff0_1.checkCoherency()
1767 self.assertTrue(ff0_1.isEqual(fieldCell0,1e-12,1e-12))
1768 ff0_2=f0.getFieldAtLevel(ON_CELLS,0)
1769 ff0_2.checkCoherency()
1770 self.assertTrue(ff0_2.isEqual(fieldCell0,1e-12,1e-12))
1771 ff0_3=f0.getFieldOnMeshAtLevel(ON_CELLS,0,m)
1772 ff0_3.checkCoherency()
1773 self.assertTrue(ff0_3.isEqual(fieldCell0,1e-12,1e-12))
1774 ff0_4=MEDLoader.ReadFieldCell(fname,m.getName(),0,fieldCell0.getName(),dt,it)
1775 ff0_4.checkCoherency()
1776 self.assertTrue(ff0_4.isEqual(fieldCell0,1e-12,1e-12))
1777 f1=MEDFileField1TS.New(fname,fieldCell1.getName(),dt,it)
1778 m1=m.getMeshAtLevel(-1)
1779 m10=m1.deepCpy() ; m10=m10[pfl1] ; m10.setName(m.getName())
1780 fieldCell1.setMesh(m10)
1781 ff1_1=f1.getFieldOnMeshAtLevel(ON_CELLS,m1)
1782 ff1_1.checkCoherency()
1783 self.assertTrue(ff1_1.isEqual(fieldCell1,1e-12,1e-12))
1784 ff1_2=f1.getFieldAtLevel(ON_CELLS,-1)
1785 ff1_2.checkCoherency()
1786 self.assertTrue(ff1_2.isEqual(fieldCell1,1e-12,1e-12))
1787 ff1_3=f1.getFieldOnMeshAtLevel(ON_CELLS,-1,m)
1788 ff1_3.checkCoherency()
1789 self.assertTrue(ff1_3.isEqual(fieldCell1,1e-12,1e-12))
1790 ff1_4=MEDLoader.ReadFieldCell(fname,m.getName(),-1,fieldCell1.getName(),dt,it)
1791 ff1_4.checkCoherency()
1792 self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1793 self.assertRaises(InterpKernelException,f1.getFieldOnMeshAtLevel,ON_CELLS,m0) # error because impossible to build a sub mesh at level 0 lying on cells [0,1,2,3,4,5,6]
1794 self.assertRaises(InterpKernelException,f1.getFieldAtLevel,ON_CELLS,0) # error because impossible to build a sub mesh at level 0 lying on cells [0,1,2,3,4,5,6]
1795 self.assertRaises(InterpKernelException,f1.getFieldOnMeshAtLevel,ON_CELLS,0,m) # error because impossible to build a sub mesh at level 0 lying on cells [0,1,2,3,4,5,6]
1796 arr_r,pfl1_r=f1.getFieldWithProfile(ON_CELLS,-1,m)
1797 arr_r.setName(fieldCell1.getArray().getName())
1798 self.assertTrue(arr_r.isEqual(fieldCell1.getArray(),1e-12))
1799 pfl1_r.setName(pfl1.getName())
1800 self.assertTrue(pfl1_r.isEqual(pfl1))
1803 def testMEDFileUMeshZipCoords1(self):
1805 coo=DataArrayDouble(30) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1806 m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0) ; m0.insertNextCell(NORM_TRI3,[1,2,3]) ; m0.insertNextCell(NORM_QUAD4,[2,4,3,4]) ; m0.insertNextCell(NORM_POLYGON,[1,6,6,6,2])
1807 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1808 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1809 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1810 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1811 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1812 numCoo=DataArrayInt(10) ; numCoo.iota(3) ; m.setRenumFieldArr(1,numCoo)
1813 famCoo=DataArrayInt(10) ; famCoo.iota(4) ; m.setFamilyFieldArr(1,famCoo)
1814 da=DataArrayInt([20,30,40]) ; m.setRenumFieldArr(0,da) ; da=DataArrayInt([200,300,400]) ; m.setFamilyFieldArr(0,da)
1815 da=DataArrayInt([50,60]) ; m.setRenumFieldArr(-1,da) ; da=DataArrayInt([500,600]) ; m.setFamilyFieldArr(-1,da)
1816 da=DataArrayInt([70,80,90]) ; m.setRenumFieldArr(-2,da) ; da=DataArrayInt([700,800,900]) ; m.setFamilyFieldArr(-2,da)
1818 self.assertTrue(o2n.isEqual(DataArrayInt([-1,0,1,2,3,-1,4,5,6,-1])))
1819 self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt([4,5,6,7,9,10,11])))
1820 self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([5,6,7,8,10,11,12])))
1821 self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,4,1,3,2,3,5,0,4,4,4,1])))
1822 self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,9,15])))
1823 self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivity().isEqual(DataArrayInt([1,0,4,1,5,2])))
1824 self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6])))
1825 self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivity().isEqual(DataArrayInt([0,1,0,4,0,6])))
1826 self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivityIndex().isEqual(DataArrayInt([0,2,4,6])))
1829 def testMEDUMeshAddNodeGroup1(self):
1830 fname="Pyfile53.med"
1832 coo=DataArrayDouble(39) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1833 m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0) ; m0.insertNextCell(NORM_TRI3,[1,2,3]) ; m0.insertNextCell(NORM_QUAD4,[2,4,3,4]) ; m0.insertNextCell(NORM_POLYGON,[1,6,6,6,2])
1834 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1835 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1836 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1837 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1838 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1841 famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(1,famCoo)
1842 da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(0,da0)
1843 da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
1844 da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
1845 mm.setFamilyId("MyFam",2)
1846 mm.setFamilyId("MyOtherFam",3)
1847 mm.setFamilyId("MyOther-1",-1)
1848 mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
1849 mm.setFamiliesOnGroup("grpA",["MyOther-1"])
1851 daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
1852 mm.addNodeGroup(daTest)
1853 self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
1854 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
1855 for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
1856 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1858 self.assertEqual(mm.getFamiliesNames(),('Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
1859 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1860 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1861 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1862 for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
1863 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1865 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_8'))
1866 da=DataArrayInt([3,12]) ; da.setName("grp0")
1867 self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
1869 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
1871 mm=MEDFileMesh.New(fname)
1872 self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
1873 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
1874 for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
1875 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1877 self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
1878 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1879 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1880 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1881 for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
1882 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1884 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_8','MyOtherFam'))
1885 da=DataArrayInt([3,12]) ; da.setName("grp0")
1886 self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
1888 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
1891 def testMEDUMeshAddGroup1(self):
1892 fname="Pyfile54.med"
1894 coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1895 m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
1897 m0.insertNextCell(NORM_TRI3,[1,2,1])
1900 m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
1903 m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
1905 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1906 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1907 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1908 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1909 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1912 famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(0,famCoo)
1913 da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(1,da0)
1914 da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
1915 da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
1916 mm.setFamilyId("MyFam",2)
1917 mm.setFamilyId("MyOtherFam",3)
1918 mm.setFamilyId("MyOther-1",-1)
1919 mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
1920 mm.setFamiliesOnGroup("grpA",["MyOther-1"])
1922 daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
1923 mm.addGroup(0,daTest)
1924 self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
1925 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
1926 for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
1927 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1929 self.assertEqual(mm.getFamiliesNames(),('Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
1930 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1931 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1932 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1933 for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
1934 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1936 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_-8'))
1937 da=DataArrayInt([3,12]) ; da.setName("grp0")
1938 self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
1940 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
1942 mm=MEDFileMesh.New(fname)
1943 self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
1944 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
1945 for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
1946 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
1948 self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
1949 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
1950 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
1951 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
1952 for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
1953 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
1955 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_-8','MyOtherFam'))
1956 da=DataArrayInt([3,12]) ; da.setName("grp0")
1957 self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
1959 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
1962 def testHeapMem1(self):
1963 m=MEDCouplingCMesh()
1964 arr=DataArrayDouble(10,1) ; arr.iota(0)
1965 m.setCoords(arr,arr)
1966 m=m.buildUnstructured()
1968 f=m.getMeasureField(ON_CELLS)
1969 self.assertIn(m.getHeapMemorySize(),xrange(3552-100,3552+100))
1970 self.assertIn(f.getHeapMemorySize(),xrange(4215-100,4215+100))
1973 mm.setMeshAtLevel(0,m)
1974 self.assertIn(mm.getHeapMemorySize(),xrange(3889-100,3889+100))
1975 ff=MEDFileField1TS()
1976 ff.setFieldNoProfileSBT(f)
1977 self.assertIn(ff.getHeapMemorySize(),xrange(711-20,711+20))
1979 fff=MEDFileFieldMultiTS()
1980 fff.appendFieldNoProfileSBT(f)
1981 self.assertIn(fff.getHeapMemorySize(),xrange(743-30,743+30))
1983 fff.appendFieldNoProfileSBT(f)
1984 self.assertIn(fff.getHeapMemorySize(),xrange(1462-50,1462+50))
1985 self.assertIn(fff[0,-1].getHeapMemorySize(),xrange(711-20,711+20))
1988 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
1989 fff.appendFieldProfile(f2,mm,0,pfl)
1990 self.assertIn(fff.getHeapMemorySize(),xrange(2178-100,2178+100))
1991 self.assertIn(fff.getProfile("pfl_NORM_QUAD4").getHeapMemorySize(),xrange(215-10,215+10))
1992 self.assertIn(fff[1,-1].getHeapMemorySize(),xrange(700-30,700+30))
1995 def testCurveLinearMesh1(self):
1996 fname="Pyfile55.med"
1997 mesh=MEDCouplingCurveLinearMesh();
1998 mesh.setTime(2.3,4,5);
1999 mesh.setTimeUnit("us");
2000 mesh.setName("Example of Cuve linear mesh");
2001 mesh.setDescription("buildCLMesh");
2002 a1=DataArrayDouble(3*20,1);
2003 a1.iota(7.) ; a1.rearrange(3);
2005 mesh.setNodeGridStructure([4,5]);
2006 mesh.checkCoherency();
2008 m=MEDFileCurveLinearMesh()
2010 d=DataArrayInt(20) ; d.iota(4)
2011 m.setFamilyFieldArr(1,d)
2012 d3=DataArrayInt(20) ; d3.iota(400)
2013 m.setRenumFieldArr(1,d3)
2014 d2=DataArrayInt(12) ; d2.iota(40)
2015 m.setFamilyFieldArr(0,d2)
2016 d4=DataArrayInt(21) ; d4.iota(4000)
2017 self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2019 m.setRenumFieldArr(1,d4)
2022 m1=MEDFileCurveLinearMesh(fname)
2024 self.assertTrue(mm.isEqual(mesh,1e-12))
2026 m1=MEDFileMesh.New(fname)
2027 self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2028 self.assertTrue(isinstance(m1.getUnivName(),str))
2029 self.assertTrue(len(m1.getUnivName())!=0)
2030 self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2033 def testParameters1(self):
2034 fname="Pyfile56.med"
2035 m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2036 mm=MEDFileCMesh() ; mm.setMesh(m)
2037 ms=MEDFileMeshes() ; ms.pushMesh(mm)
2039 p=MEDFileParameters()
2040 data.setParams(p) ; data.setMeshes(ms)
2041 pts=MEDFileParameterMultiTS()
2042 pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2043 pts.appendValue(1,2,3.4,567.89)
2044 pts.appendValue(2,3,5.6,999.123)
2045 pts2=pts.deepCpy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2046 p.pushParam(pts) ; p.pushParam(pts2)
2048 p2=MEDFileParameters(fname)
2049 self.assertTrue(p.isEqual(p2,1e-14)[0])
2050 self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2054 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2055 pts2.eraseTimeStepIds([0])
2056 self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2058 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2059 self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2060 self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2061 self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2062 self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2064 self.assertTrue(p.isEqual(p2,1e-14)[0])
2065 self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2066 self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2067 self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2068 self.assertEqual(p.getParamsNames(),('A','B'))
2069 ptsr=MEDFileParameterMultiTS(fname,"B")
2070 self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2071 ptsr=MEDFileParameterMultiTS(fname)
2072 self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2073 p1tsr=MEDFileParameterDouble1TS(fname)
2074 self.assertEqual(p1tsr.getName(),"A")
2075 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2076 p1tsr=MEDFileParameterDouble1TS(fname,"B")
2077 self.assertEqual(p1tsr.getName(),"B")
2078 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2079 p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2080 self.assertEqual(p1tsr.getName(),"B")
2081 self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2082 data2=MEDFileData(fname)
2083 self.assertEqual(2,data2.getNumberOfParams())
2084 self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2087 def testNamesOnCellAndNodesInMeshes1(self):
2088 fname="Pyfile58.med"
2089 fname2="Pyfile59.med"
2090 m=MEDLoaderDataForTest.build3DSurfMesh_1()
2091 m1=m.buildDescendingConnectivity()[0]
2092 m1.sortCellsInMEDFileFrmt()
2095 mm.setMeshAtLevel(0,m)
2096 mm.setMeshAtLevel(-1,m1)
2097 namesCellL0=DataArrayAsciiChar(6,16)
2098 namesCellL0[:]=["CellL0#%.3d "%(i) for i in xrange(6)]
2099 mm.setNameFieldAtLevel(0,namesCellL0)
2100 namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.substr(2)])
2101 namesCellL1[:]=["CellLM1#%.3d "%(i) for i in xrange(16)]
2102 mm.setNameFieldAtLevel(-1,namesCellL1)
2103 namesNodes=namesCellL1.substr(4,16)
2104 namesNodes[:]=["Node#%.3d "%(i) for i in xrange(12)]
2105 mm.setNameFieldAtLevel(1,namesNodes)
2108 mmr=MEDFileMesh.New(fname)
2109 self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d "%(i) for i in xrange(6)])))
2110 self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d "%(i) for i in xrange(16)])))
2111 self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(12)])))
2112 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2113 mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2114 self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2115 mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2116 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2118 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2119 # remove names on nodes
2120 mmCpy.setNameFieldAtLevel(1,None)
2121 self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2122 mm.setNameFieldAtLevel(1,None)
2123 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2124 mm.setNameFieldAtLevel(-1,None)
2126 mmr=MEDFileMesh.New(fname)
2127 self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2128 self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d "%(i) for i in xrange(6)])))
2129 self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2131 c=MEDCouplingCMesh()
2132 arr=DataArrayDouble([0.,1.1,2.3])
2133 c.setCoords(arr,arr)
2137 cc.setNameFieldAtLevel(0,DataArrayAsciiChar(["Cell#%.3d "%(i) for i in xrange(4)]))
2138 cc.setNameFieldAtLevel(1,DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(9)]))
2140 ccr=MEDFileMesh.New(fname2)
2141 self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d "%(i) for i in xrange(4)])))
2142 self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d "%(i) for i in xrange(9)])))
2143 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2144 ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2145 self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2146 ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2147 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2149 self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2152 def testToExportInExamples1(self):
2153 m=MEDCouplingCMesh()
2154 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2155 m.setCoords(arr,arr)
2156 m=m.buildUnstructured() ; m.setName("mesh")
2157 grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2158 grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2161 mm.setMeshAtLevel(0,m)
2162 mm.setMeshAtLevel(-1,m2)
2163 mm.setGroupsAtLevel(0,[grp1,grp2])
2164 mm.write("example.med",2)
2166 m0=mm.getMeshAtLevel(0)
2167 m1=mm.getMeshAtLevel(-1)
2168 grp1=mm.getGroupArr(0,"grp1")
2169 grp2=mm.getGroupArr(0,"grp2")
2171 whichGrp=DataArrayInt(m0.getNumberOfCells())
2172 whichGrp.fillWithValue(-1)
2173 for grpId,grp in enumerate(grps):
2176 a,b,bI,c,cI=m0.buildDescendingConnectivity()
2177 e,f=a.areCellsIncludedIn(m1,2)
2179 c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2180 self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2181 c2.transformWithIndArr(whichGrp)
2182 splitOfM1=len(grps)*[None]
2183 for grpId,grp in enumerate(grps):
2184 tmp=c2.getIdsEqual(grpId)
2185 splitOfM1[grpId]=tmp
2187 splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2188 splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2191 def testBugCorrection1(self):
2194 self.assertEqual(fs[0],None)
2195 self.assertEqual(3,len(fs))
2198 def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2199 f1Name="Pyfile60.med"
2200 f2Name="Pyfile61.med"
2201 d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2203 d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2205 # reading and compare
2206 d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2207 for mn in d1.getMeshes().getMeshesNames():
2208 m1=d1.getMeshes()[mn]
2209 m2=d2.getMeshes()[mn]
2210 for lev in m1.getNonEmptyLevels():
2211 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2212 for grpName in grpsNames:
2213 self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2217 for fieldn in d1.getFields().getFieldsNames():
2218 f1=d1.getFields()[fieldn]
2219 f2=d2.getFields()[fieldn]
2220 for it,order,tim in f1.getTimeSteps():
2223 if len(f1t.getPflsReallyUsed())!=0:
2225 for lev in f1t.getNonEmptyLevels()[1]:
2226 arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2227 arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2228 self.assertTrue(pfl1.isEqual(pfl2))
2229 self.assertTrue(arr1.isEqual(arr2,1e-10))
2234 for lev in f1t.getNonEmptyLevels()[1]:
2235 f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2236 f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2237 self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2244 def testNonRegBugNormalizeFamIdsMEDFile1(self):
2245 m=MEDCouplingCMesh()
2246 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2247 m.setCoords(arr,arr,arr)
2248 m=m.buildUnstructured()
2249 m2=m.buildDescendingConnectivity()[0]
2251 g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2252 g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2253 g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2254 g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2255 g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2256 g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2258 mm.setMeshAtLevel(0,m)
2259 mm.setGroupsAtLevel(0,[g1,g2])
2260 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2261 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2262 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2263 mm.normalizeFamIdsMEDFile()
2264 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2265 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2266 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2267 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2268 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2269 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2270 for g in mm.getGroupsOnSpecifiedLev(0):
2271 for f in mm.getFamiliesIdsOnGroup(g):
2272 self.assertTrue(f<0)
2277 mm.setMeshAtLevel(0,m)
2278 mm.setMeshAtLevel(-1,m2)
2279 mm.setGroupsAtLevel(0,[g1,g2])
2280 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2281 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2282 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2283 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2284 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2285 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2286 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2287 mm.normalizeFamIdsMEDFile()
2288 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2289 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2290 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2291 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2292 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2293 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2294 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2295 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2296 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2297 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2298 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2299 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2301 for g in mm.getGroupsOnSpecifiedLev(lev):
2302 for f in mm.getFamiliesIdsOnGroup(g):
2303 self.assertTrue(f<0)
2309 mm.setMeshAtLevel(0,m)
2310 mm.setMeshAtLevel(-1,m2)
2311 mm.setGroupsAtLevel(0,[g1,g2])
2312 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2313 mm.setGroupsAtLevel(1,[g1Node,g2Node])
2314 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2315 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2316 s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2317 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2318 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2319 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2320 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2321 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2322 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2323 mm.normalizeFamIdsMEDFile()
2324 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2325 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2326 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2327 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2328 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2329 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2330 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2331 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2332 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2333 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2334 self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2335 self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2336 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2337 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2338 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2339 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2340 self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2341 self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2343 for g in mm.getGroupsOnSpecifiedLev(lev):
2344 for f in mm.getFamiliesIdsOnGroup(g):
2345 self.assertTrue(f<0)
2349 for g in mm.getGroupsOnSpecifiedLev(1):
2350 for f in mm.getFamiliesIdsOnGroup(g):
2351 self.assertTrue(f>0)
2356 def testNonRegressionMantis22212ChangeGrpName(self):
2357 fileName="Pyfile62.med"
2358 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2359 m=MEDFileUMesh.New()
2360 m.setCoords(m2.getCoords())
2361 m.setMeshAtLevel(0,m2)
2362 m.setMeshAtLevel(-1,m1)
2363 m.setMeshAtLevel(-2,m0)
2364 m.setFamilyFieldArr(0,f2)
2365 m.setFamilyFieldArr(-1,f1)
2366 m.setFamilyFieldArr(-2,f0)
2367 m.setFamilyFieldArr(1,p)
2369 for i in xrange(nbOfFams):
2370 m.addFamily(fns[i],fids[i])
2373 for i in xrange(nbOfGrps):
2374 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2376 m.setName(m2.getName())
2377 m.setDescription(m2.getDescription())
2380 mm0=MEDFileMesh.New(fileName)
2381 mm1=MEDFileMesh.New(fileName)
2382 groupNamesIni=MEDLoader.GetMeshGroupsNames(fileName,"ma")
2383 for name in groupNamesIni:
2384 mm1.changeGroupName(name,name+'N')
2386 mm1.write(fileName,2)
2389 mm2=MEDFileMesh.New(fileName)
2390 for name in groupNamesIni:
2391 for lev in mm0.getGrpNonEmptyLevelsExt(name):
2392 arr0=mm0.getGroupArr(lev,name)
2393 arr2=mm2.getGroupArr(lev,name+'N')
2394 arr0.setName(name+'N')
2395 self.assertTrue(arr0.isEqual(arr2))
2400 def testInt32InMEDFileFieldStar1(self):
2401 fname="Pyfile63.med"
2402 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2403 arr=f1.getArray().convertToIntArr()
2406 mm1=MEDFileUMesh.New()
2407 mm1.setCoords(m1.getCoords())
2408 mm1.setMeshAtLevel(0,m1)
2409 mm1.setName(m1.getName())
2411 ff1=MEDFileIntField1TS()
2412 ff1.setFieldNoProfileSBT(f1,arr)
2413 a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2414 self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2415 self.assertTrue(b.isEqual(arr))
2416 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2418 ff2=MEDFileAnyTypeField1TS.New(fname)
2419 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2420 self.assertEqual(ff2.getTime(),[0,1,2.0])
2421 self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2422 a,b=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2423 self.assertEqual(b.getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2424 self.assertTrue(b.isEqual(arr))
2425 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2427 c=ff2.getUndergroundDataArray() ; c*=2
2428 ff2.write(fname,0) # 2 time steps in
2429 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2430 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2431 self.assertEqual(len(ffs1),2)
2432 self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2433 a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2434 self.assertTrue(b.isEqual(arr))
2435 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2436 a,b=ffs1[2.].getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2437 self.assertTrue(b.isEqual(arr))
2438 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2439 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2440 a,b=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2441 self.assertTrue(b.isEqual(2*arr))
2443 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
2444 bc=DataArrayInt(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2446 a,b=it.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2449 self.assertTrue(bc.isEqual(3*arr))
2450 nf1=MEDCouplingFieldDouble(ON_NODES)
2451 nf1.setTime(9.,10,-1)
2452 nf1.setMesh(f1.getMesh())
2453 narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=range(12) ; narr[:,1]=2*narr[:,0]
2454 nf1.setName("VectorFieldOnNodes")
2455 nff1=MEDFileIntField1TS.New()
2456 nff1.setFieldNoProfileSBT(nf1,narr)
2457 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2458 self.assertEqual(nff1.getTime(),[10,-1,9.0])
2461 nf2=MEDCouplingFieldDouble(ON_NODES)
2462 nf2.setTime(19.,20,-11)
2463 nf2.setMesh(f1.getMesh())
2464 narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=range(8) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
2465 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName())
2466 nff2=MEDFileIntField1TS.New()
2467 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
2468 nff2.setFieldProfile(nf2,narr2,mm1,0,npfl)
2469 nff2.getFieldWithProfile(ON_NODES,0,mm1)
2470 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2471 self.assertTrue(b.isEqual(npfl))
2472 self.assertTrue(a.isEqual(narr2))
2474 nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
2475 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2476 self.assertTrue(b.isEqual(npfl))
2477 self.assertTrue(a.isEqual(narr2))
2479 nf3=MEDCouplingFieldDouble(ON_NODES)
2480 nf3.setName("VectorFieldOnNodesDouble")
2481 nf3.setTime(29.,30,-21)
2482 nf3.setMesh(f1.getMesh())
2483 nf3.setArray(f1.getMesh().getCoords())
2484 nff3=MEDFileField1TS.New()
2485 nff3.setFieldNoProfileSBT(nf3)
2487 fs=MEDFileFields(fname)
2488 self.assertEqual(len(fs),4)
2489 ffs=[it for it in fs]
2490 self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
2491 self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
2492 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
2493 self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
2495 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(arr))
2496 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*arr))
2497 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
2498 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
2499 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2501 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
2502 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2503 self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
2504 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
2505 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
2506 self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
2507 MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
2508 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
2510 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
2511 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2512 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
2513 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2516 def testMEDFileFields1(self):
2517 fname="Pyfile64.med"
2518 f1=MEDCouplingFieldDouble(ON_NODES)
2519 f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
2520 c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
2521 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
2523 arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=range(12) ; arr[:,1]=2*arr[:,0]
2525 f1.setName("Field1")
2526 ff1=MEDFileField1TS.New()
2527 ff1.setFieldNoProfileSBT(f1)
2528 self.assertEqual(ff1.getDtUnit(),"us")
2530 f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2531 f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2533 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2534 ff1s=MEDFileFieldMultiTS(fname,"Field1")
2535 ff1s.setName("Field2")
2537 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2538 f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2539 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
2540 self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
2541 self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
2542 f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2543 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
2544 self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
2547 # Multi time steps and multi fields management without Globals (profiles, locs) aspects
2548 def testMEDFileFields2(self):
2549 fname="Pyfile65.med"
2550 # to check that all is initialize
2551 MEDFileField1TS().__str__()
2552 MEDFileFieldMultiTS().__str__()
2553 # building a mesh containing 4 tri3 + 5 quad4
2554 tri=MEDCouplingUMesh("tri",2)
2555 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2556 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2557 tris=[tri.deepCpy() for i in xrange(4)]
2558 for i,elt in enumerate(tris): elt.translate([i,0])
2559 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2560 quad=MEDCouplingUMesh("quad",2)
2561 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2562 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2563 quads=[quad.deepCpy() for i in xrange(5)]
2564 for i,elt in enumerate(quads): elt.translate([5+i,0])
2565 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2566 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2567 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2569 fmts0_0=MEDFileFieldMultiTS()
2570 fmts0_1=MEDFileFieldMultiTS()
2572 for i in xrange(10):
2573 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2574 d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2575 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2576 f.setTime(float(i+1)+0.1,i+1,-i-1)
2577 fmts0_0.appendFieldNoProfileSBT(f)
2578 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
2579 self.assertEqual(fmts0_1.getName(),name1)
2580 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2581 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2583 # components names have been modified to generate errors
2584 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
2585 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
2586 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
2587 f1ts.setInfo(['aa [bb]','eee [dd]'])
2588 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
2590 # add a mismatch of nb of compos
2592 fmts0_2=fmts0_0.deepCpy()
2593 fmts0_3=fmts0_0.deepCpy()
2594 fmts0_4=fmts0_0.deepCpy()
2595 fmts0_5=fmts0_0.shallowCpy()
2596 self.assertTrue(len(fmts0_0)==10 and len(fmts0_1)==10 and len(fmts0_2)==10 and len(fmts0_3)==10 and len(fmts0_4)==10 and len(fmts0_5)==10)
2598 self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
2599 del fmts0_3[[1.1,(6,-6),9]]
2600 self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
2601 fmts0_6=fmts0_4[[1.1,(6,-6),8]]
2602 self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
2603 self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
2604 fmts0_7=fmts0_4[::-3]
2605 self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
2606 self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
2609 fs0.pushField(fmts0_0)
2610 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2611 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2612 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2613 self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
2615 fs0=MEDFileFields(fname)
2616 self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
2617 fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
2618 self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2619 del fs1[["2ndField",3]]
2620 self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2621 fs2=fs0[[0,"4thField"]]
2622 self.assertTrue(isinstance(fs2,MEDFileFields))
2623 self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
2625 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
2628 # Multi time steps and multi fields management with Globals (profiles, locs) aspects
2629 def testMEDFileFields3(self):
2630 fname="Pyfile66.med"
2631 # building a mesh containing 4 tri3 + 5 quad4
2632 tri=MEDCouplingUMesh("tri",2)
2633 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2634 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2635 tris=[tri.deepCpy() for i in xrange(4)]
2636 for i,elt in enumerate(tris): elt.translate([i,0])
2637 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2638 quad=MEDCouplingUMesh("quad",2)
2639 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2640 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2641 quads=[quad.deepCpy() for i in xrange(5)]
2642 for i,elt in enumerate(quads): elt.translate([5+i,0])
2643 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2644 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2645 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2647 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2649 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2650 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2651 fmts0_0=MEDFileFieldMultiTS()
2652 fmts0_1=MEDFileFieldMultiTS()
2654 for i in xrange(10):
2655 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2656 d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2657 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2658 f.setTime(float(i+1)+0.1,i+1,-i-1)
2659 fmts0_0.appendFieldProfile(f,mm,0,pfl)
2660 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2661 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2662 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2665 self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
2666 self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
2667 fmts0_0.zipPflsNames()
2668 self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
2669 self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
2670 fmts0_2=fmts0_0.deepCpy()
2671 fmts0_3=fmts0_0.deepCpy()
2672 fmts0_4=fmts0_0.deepCpy()
2674 fs0.pushField(fmts0_0)
2675 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2676 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2677 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2678 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
2680 fmts0_5=MEDFileFieldMultiTS()
2682 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2683 d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2684 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2685 f.setTime(float(i+1)+0.1,i+1,-i-1)
2686 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
2688 fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
2689 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
2690 fs0.checkGlobsCoherency()
2694 def testSplitComponents1(self):
2695 fname="Pyfile67.med"
2696 # building a mesh containing 4 tri3 + 5 quad4
2697 tri=MEDCouplingUMesh("tri",2)
2698 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2699 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2700 tris=[tri.deepCpy() for i in xrange(4)]
2701 for i,elt in enumerate(tris): elt.translate([i,0])
2702 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2703 quad=MEDCouplingUMesh("quad",2)
2704 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2705 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2706 quads=[quad.deepCpy() for i in xrange(5)]
2707 for i,elt in enumerate(quads): elt.translate([5+i,0])
2708 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2709 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2710 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2712 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2714 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2715 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2717 fmts0_1=MEDFileFieldMultiTS()
2719 infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
2720 for i in xrange(10):
2722 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2723 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2724 f.setTime(float(i+1)+0.1,i+1,-i-1)
2725 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2726 self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
2728 fs.pushField(fmts0_1)
2729 self.assertEqual(1,len(fs))
2730 l=fmts0_1.splitComponents()
2731 self.assertEqual(3,len(l))
2732 for elt in l: self.assertEqual(10,len(elt))
2733 for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
2735 elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
2738 self.assertEqual(4,len(fs))
2739 for elt in fs: self.assertEqual(10,len(elt))
2740 self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
2741 self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2743 fs.write(fname,0) ; del fs
2745 fs1=MEDFileFields(fname)
2746 self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
2747 self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2748 self.assertEqual(4,len(fs1))
2749 for i in xrange(10):
2750 for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
2751 f1ts=fs1[fieldName][i]
2752 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2753 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
2754 self.assertTrue(d.isEqual(f.getArray(),1e-13))
2756 f1ts=fs1["1stField"][i]
2757 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2758 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2759 self.assertTrue(d.isEqual(f.getArray(),1e-13))
2763 def testMEDFileFieldConvertTo1(self):
2764 fname="Pyfile68.med"
2765 # building a mesh containing 4 tri3 + 5 quad4
2766 tri=MEDCouplingUMesh("tri",2)
2767 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2768 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2769 tris=[tri.deepCpy() for i in xrange(4)]
2770 for i,elt in enumerate(tris): elt.translate([i,0])
2771 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2772 quad=MEDCouplingUMesh("quad",2)
2773 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2774 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2775 quads=[quad.deepCpy() for i in xrange(5)]
2776 for i,elt in enumerate(quads): elt.translate([5+i,0])
2777 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2778 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2779 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2780 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
2782 ff0=MEDFileField1TS()
2783 f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCell")
2785 ff0.setFieldNoProfileSBT(f0)
2787 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
2788 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2790 ff0i=ff0.convertToInt()
2791 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
2792 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
2794 ff1=ff0i.convertToDouble()
2795 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
2796 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
2798 del arr,f0,ff0,ff1,ff0i,fspExp
2799 ff0=MEDFileField1TS()
2800 f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["XX [pm]","YYY [hm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellPfl")
2802 pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
2803 ff0.setFieldProfile(f0,mm,0,pfl)
2804 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
2805 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2807 ff0i=ff0.convertToInt()
2808 self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
2809 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
2810 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
2812 ff1=ff0i.convertToDouble()
2813 self.assertTrue(isinstance(ff1,MEDFileField1TS))
2814 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
2815 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
2817 ff0=MEDFileFieldMultiTS()
2818 f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(0.1,0,10)
2820 ff0.appendFieldProfile(f0,mm,0,pfl)
2821 f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota(100) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(1.1,1,11)
2823 ff0.appendFieldProfile(f0,mm,0,pfl)
2824 f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:7]) ; arr=DataArrayDouble(7*2) ; arr.iota(200) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellMTime") ; f0.setTime(2.1,2,12)
2826 ff0.appendFieldProfile(f0,mm,0,pfl)
2827 ff1=ff0.convertToInt()
2828 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
2829 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2830 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
2831 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
2832 arr=ff1.getUndergroundDataArray(dt,it)
2833 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
2835 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
2840 ff1=ff1.convertToDouble()
2841 self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
2842 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2843 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
2844 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
2845 arr=ff1.getUndergroundDataArray(dt,it)
2846 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
2848 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
2850 ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
2851 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
2852 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
2853 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
2854 self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
2855 arr=ff1.getUndergroundDataArray(dt,it)
2856 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
2858 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
2861 def testMEDFileFieldPartialLoading(self):
2862 fname="Pyfile69.med"
2863 # building a mesh containing 30 tri3 + 40 quad4
2864 tri=MEDCouplingUMesh("tri",2)
2865 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2866 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2867 tris=[tri.deepCpy() for i in xrange(30)]
2868 for i,elt in enumerate(tris): elt.translate([i,0])
2869 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2870 quad=MEDCouplingUMesh("quad",2)
2871 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2872 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2873 quads=[quad.deepCpy() for i in xrange(40)]
2874 for i,elt in enumerate(quads): elt.translate([40+i,0])
2875 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2876 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2877 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2878 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2880 ff0=MEDFileField1TS()
2881 f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName("FieldCell")
2883 ff0.setFieldNoProfileSBT(f0)
2886 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
2887 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2889 ff0=MEDFileField1TS()
2890 f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m[:50]) ; arr=DataArrayDouble(50*2) ; arr.iota() ; arr.rearrange(2) ; arr.setInfoOnComponents(["XX [pm]","YYY [hm]"]) ; f0.setArray(arr) ; f0.setName("FieldCellPfl")
2892 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2893 ff0.setFieldProfile(f0,mm,0,pfl)
2894 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
2895 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2898 ff0=MEDFileField1TS(fname,False)
2899 self.assertEqual(ff0.getName(),"FieldCell")
2900 self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
2901 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
2902 heap_memory_ref=ff0.getHeapMemorySize()
2903 self.assertTrue(heap_memory_ref>=100 and heap_memory_ref<=200)
2905 arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
2906 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2907 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
2909 ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
2910 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
2911 heap_memory_ref=ff0.getHeapMemorySize()
2912 self.assertTrue(heap_memory_ref>=150 and heap_memory_ref<=250)
2914 arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
2915 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2916 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
2918 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2919 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
2920 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
2921 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2923 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2924 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
2925 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2926 ff0.loadArraysIfNecessary() ##
2927 self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
2928 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2929 heap_memory_ref=ff0.getHeapMemorySize()
2930 self.assertTrue(heap_memory_ref>=1000 and heap_memory_ref<=1100)
2932 hmd=ff0.getHeapMemorySize()-heap_memory_ref
2933 self.assertEqual(hmd,-800) # -50*8*2
2935 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
2937 ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
2938 heap_memory_ref=ff0.getHeapMemorySize()
2939 self.assertTrue(heap_memory_ref>=150 and heap_memory_ref<=250)
2941 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
2942 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
2944 fieldName="FieldCellMultiTS"
2945 ff0=MEDFileFieldMultiTS()
2946 for t in xrange(20):
2947 f0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f0.setMesh(m) ; arr=DataArrayDouble(m.getNumberOfCells()*2) ; arr.iota(float(t+1000)) ; arr.rearrange(2) ; arr.setInfoOnComponents(["X [km]","YY [mm]"]) ; f0.setArray(arr) ; f0.setName(fieldName)
2948 f0.setTime(float(t)+0.1,t,100+t)
2950 ff0.appendFieldNoProfileSBT(f0)
2954 ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
2955 heap_memory_ref=ff0.getHeapMemorySize()
2956 self.assertTrue(heap_memory_ref>=2000 and heap_memory_ref<=3000)
2958 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
2961 ffs=MEDFileFields(fname,False)
2962 heap_memory_ref=ffs.getHeapMemorySize()
2963 self.assertTrue(heap_memory_ref>=2500 and heap_memory_ref<=3500)
2965 self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
2968 def testMEDFileMeshReadSelector1(self):
2969 mrs=MEDFileMeshReadSelector()
2970 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
2971 mrs.__str__() ; mrs.__repr__()
2973 mrs=MEDFileMeshReadSelector(0)
2974 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2975 mrs=MEDFileMeshReadSelector(1)
2976 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2977 mrs=MEDFileMeshReadSelector(2)
2978 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2979 mrs=MEDFileMeshReadSelector(3)
2980 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2981 mrs=MEDFileMeshReadSelector(4)
2982 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2983 mrs=MEDFileMeshReadSelector(5)
2984 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2985 mrs=MEDFileMeshReadSelector(6)
2986 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2987 mrs=MEDFileMeshReadSelector(7)
2988 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2989 mrs=MEDFileMeshReadSelector(8)
2990 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2991 mrs=MEDFileMeshReadSelector(9)
2992 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2993 mrs=MEDFileMeshReadSelector(10)
2994 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2995 mrs=MEDFileMeshReadSelector(11)
2996 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2997 mrs=MEDFileMeshReadSelector(12)
2998 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
2999 mrs=MEDFileMeshReadSelector(13)
3000 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3001 mrs=MEDFileMeshReadSelector(14)
3002 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3003 mrs=MEDFileMeshReadSelector(15)
3004 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3005 mrs=MEDFileMeshReadSelector(16)
3006 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3007 mrs=MEDFileMeshReadSelector(17)
3008 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3009 mrs=MEDFileMeshReadSelector(18)
3010 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3011 mrs=MEDFileMeshReadSelector(19)
3012 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3013 mrs=MEDFileMeshReadSelector(20)
3014 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3015 mrs=MEDFileMeshReadSelector(21)
3016 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3017 mrs=MEDFileMeshReadSelector(22)
3018 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3019 mrs=MEDFileMeshReadSelector(23)
3020 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3021 mrs=MEDFileMeshReadSelector(24)
3022 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3023 mrs=MEDFileMeshReadSelector(25)
3024 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3025 mrs=MEDFileMeshReadSelector(26)
3026 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3027 mrs=MEDFileMeshReadSelector(27)
3028 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3029 mrs=MEDFileMeshReadSelector(28)
3030 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3031 mrs=MEDFileMeshReadSelector(29)
3032 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3033 mrs=MEDFileMeshReadSelector(30)
3034 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3035 mrs=MEDFileMeshReadSelector(31)
3036 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3037 mrs=MEDFileMeshReadSelector(32)
3038 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3039 mrs=MEDFileMeshReadSelector(33)
3040 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3041 mrs=MEDFileMeshReadSelector(34)
3042 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3043 mrs=MEDFileMeshReadSelector(35)
3044 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3045 mrs=MEDFileMeshReadSelector(36)
3046 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3047 mrs=MEDFileMeshReadSelector(37)
3048 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3049 mrs=MEDFileMeshReadSelector(38)
3050 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3051 mrs=MEDFileMeshReadSelector(39)
3052 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3053 mrs=MEDFileMeshReadSelector(40)
3054 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3055 mrs=MEDFileMeshReadSelector(41)
3056 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3057 mrs=MEDFileMeshReadSelector(42)
3058 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3059 mrs=MEDFileMeshReadSelector(43)
3060 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3061 mrs=MEDFileMeshReadSelector(44)
3062 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3063 mrs=MEDFileMeshReadSelector(45)
3064 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3065 mrs=MEDFileMeshReadSelector(46)
3066 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3067 mrs=MEDFileMeshReadSelector(47)
3068 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3069 mrs=MEDFileMeshReadSelector(48)
3070 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3071 mrs=MEDFileMeshReadSelector(49)
3072 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3073 mrs=MEDFileMeshReadSelector(50)
3074 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3075 mrs=MEDFileMeshReadSelector(51)
3076 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3077 mrs=MEDFileMeshReadSelector(52)
3078 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3079 mrs=MEDFileMeshReadSelector(53)
3080 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3081 mrs=MEDFileMeshReadSelector(54)
3082 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3083 mrs=MEDFileMeshReadSelector(55)
3084 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3085 mrs=MEDFileMeshReadSelector(56)
3086 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3087 mrs=MEDFileMeshReadSelector(57)
3088 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3089 mrs=MEDFileMeshReadSelector(58)
3090 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3091 mrs=MEDFileMeshReadSelector(59)
3092 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3093 mrs=MEDFileMeshReadSelector(60)
3094 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3095 mrs=MEDFileMeshReadSelector(61)
3096 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3097 mrs=MEDFileMeshReadSelector(62)
3098 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3099 mrs=MEDFileMeshReadSelector(63)
3100 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3102 mrs=MEDFileMeshReadSelector(63)
3103 mrs.setCellFamilyFieldReading(False)
3104 self.assertEqual(mrs.getCode(),62)
3105 mrs.setCellFamilyFieldReading(True)
3106 self.assertEqual(mrs.getCode(),63)
3107 mrs.setNodeFamilyFieldReading(False)
3108 self.assertEqual(mrs.getCode(),61)
3109 mrs.setNodeFamilyFieldReading(True)
3110 self.assertEqual(mrs.getCode(),63)
3111 mrs.setCellNameFieldReading(False)
3112 self.assertEqual(mrs.getCode(),59)
3113 mrs.setCellNameFieldReading(True)
3114 self.assertEqual(mrs.getCode(),63)
3115 mrs.setNodeNameFieldReading(False)
3116 self.assertEqual(mrs.getCode(),55)
3117 mrs.setNodeNameFieldReading(True)
3118 self.assertEqual(mrs.getCode(),63)
3119 mrs.setCellNumFieldReading(False)
3120 self.assertEqual(mrs.getCode(),47)
3121 mrs.setCellNumFieldReading(True)
3122 self.assertEqual(mrs.getCode(),63)
3123 mrs.setNodeNumFieldReading(False)
3124 self.assertEqual(mrs.getCode(),31)
3125 mrs.setNodeNumFieldReading(True)
3126 self.assertEqual(mrs.getCode(),63)
3129 def testPartialReadOfMeshes(self):
3130 fname="Pyfile70.med"
3131 # building a mesh containing 4 tri3 + 5 quad4
3132 tri=MEDCouplingUMesh("tri",2)
3133 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3134 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3135 tris=[tri.deepCpy() for i in xrange(4)]
3136 for i,elt in enumerate(tris): elt.translate([i,0])
3137 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3138 quad=MEDCouplingUMesh("quad",2)
3139 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3140 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3141 quads=[quad.deepCpy() for i in xrange(5)]
3142 for i,elt in enumerate(quads): elt.translate([5+i,0])
3143 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3144 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3145 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3146 m1=m.buildDescendingConnectivity()[0]
3147 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3149 grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3150 grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3151 mm.setGroupsAtLevel(0,[grp0,grp1])
3152 grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3153 grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3154 mm.setGroupsAtLevel(-1,[grp2,grp3])
3155 grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3156 grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3157 mm.setGroupsAtLevel(1,[grp4,grp5])
3158 mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3159 mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3160 mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3164 mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3165 ref_heap_mem=mm.getHeapMemorySize()
3167 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3168 self.assertEqual(len(mm.getGroupsNames()),0)
3169 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3170 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3171 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3172 self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3173 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3174 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3175 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3176 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3177 delta1=ref_heap_mem-mm.getHeapMemorySize()
3178 self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3180 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3181 self.assertEqual(len(mm.getGroupsNames()),6)
3182 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3183 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3184 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3185 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3186 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3187 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3188 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3189 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3190 delta2=ref_heap_mem-mm.getHeapMemorySize()
3191 self.assertTrue(delta2<delta1)
3192 self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3194 mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3195 self.assertEqual(len(mm.getGroupsNames()),6)
3196 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3197 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3198 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3199 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3200 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3201 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3202 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3203 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3204 delta3=ref_heap_mem-mm.getHeapMemorySize()
3205 self.assertTrue(delta3<delta2)
3206 self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3208 mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3209 self.assertEqual(len(mm.getGroupsNames()),6)
3210 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3211 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3212 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3213 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3214 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3215 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3216 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3217 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3218 delta4=ref_heap_mem-mm.getHeapMemorySize()
3219 self.assertTrue(delta4<delta3)
3220 self.assertTrue(delta4>=32*4*2)
3222 mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3223 self.assertEqual(len(mm.getGroupsNames()),6)
3224 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3225 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3226 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3227 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3228 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3229 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3230 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3231 self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3232 delta5=ref_heap_mem-mm.getHeapMemorySize()
3233 self.assertTrue(delta5<delta4)
3234 self.assertEqual(delta5,0)
3237 # this test checks that setFieldProfile perform a check of the array length
3238 # compared to the profile length. This test also checks that mesh attribute of field
3239 # is not used by setFieldProfile (because across this test mesh is equal to None)
3240 def testCheckCompatibilityPfl1(self):
3241 # building a mesh containing 4 tri3 + 5 quad4
3242 tri=MEDCouplingUMesh("tri",2)
3243 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3244 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3245 tris=[tri.deepCpy() for i in xrange(4)]
3246 for i,elt in enumerate(tris): elt.translate([i,0])
3247 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3248 quad=MEDCouplingUMesh("quad",2)
3249 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3250 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3251 quads=[quad.deepCpy() for i in xrange(5)]
3252 for i,elt in enumerate(quads): elt.translate([5+i,0])
3253 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3254 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3255 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3256 m1=m.buildDescendingConnectivity()[0]
3257 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3259 f1ts=MEDFileField1TS()
3260 f=MEDCouplingFieldDouble(ON_NODES)
3261 vals=DataArrayDouble(7) ; vals.iota(1000)
3263 f.setName("anonymous") # f has no mesh it is not a bug
3264 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3265 f1ts.setFieldProfile(f,mm,0,pfl)
3267 f1ts=MEDFileField1TS()
3268 f=MEDCouplingFieldDouble(ON_NODES)
3269 vals=DataArrayDouble(8) ; vals.iota(1000)
3271 f.setName("anonymous") # f has no mesh it is not a bug
3272 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3273 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3275 f1ts=MEDFileField1TS()
3276 f=MEDCouplingFieldDouble(ON_CELLS)
3277 vals=DataArrayDouble(7) ; vals.iota(1000)
3279 f.setName("anonymous") # f has no mesh it is not a bug
3280 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3281 f1ts.setFieldProfile(f,mm,0,pfl)
3282 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3284 f1ts=MEDFileField1TS()
3285 f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3286 vals=DataArrayDouble(27) ; vals.iota(1000)
3288 f.setName("anonymous") # f has no mesh it is not a bug
3289 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3291 f.setGaussLocalizationOnCells([0,1],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.1,0.1],[0.3,0.6,0.1])
3292 f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3293 f.setGaussLocalizationOnCells([3,4,5,6],[0.,0.,1.,0.,1.,1.,0.,1.],[0.1,0.1,0.2,0.2,0.3,0.3,0.4,0.4,0.5,0.5],[0.2,0.3,0.4,0.07,0.03])
3295 f1ts.setFieldProfile(f,mm,0,pfl)
3296 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3297 vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3298 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3299 vals=DataArrayDouble(27) ; vals.iota(1000)
3300 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3302 f1ts=MEDFileField1TS()
3303 f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3304 vals=DataArrayDouble(25) ; vals.iota(1000)
3306 f.setName("anonymous") # f has no mesh it is not a bug
3307 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3308 f1ts.setFieldProfile(f,mm,0,pfl)
3309 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3310 vals2=DataArrayDouble(26) ; vals2.iota(1050)
3312 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3313 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3315 f1ts=MEDFileField1TS()
3316 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3317 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3319 f1ts.setFieldProfile(f,mm,0,pfl)