1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author : Anthony Geay (EDF R&D)
22 from MEDLoader import *
25 from math import pi,e,sqrt
26 from MEDLoaderDataForTest import MEDLoaderDataForTest
27 from distutils.version import LooseVersion
30 if sys.version_info.major < 3:
31 import cPickle as pickle
35 class MEDLoaderTest3(unittest.TestCase):
36 def testMEDMesh1(self):
37 fileName="Pyfile18.med"
38 mname="ExampleOfMultiDimW"
39 medmesh=MEDFileMesh.New(fileName,mname)
40 self.assertRaises(InterpKernelException,MEDFileMesh.New,fileName,"")
41 self.assertEqual((0,-1),medmesh.getNonEmptyLevels())
42 m1_0=medmesh.getLevel0Mesh(True)
43 m1_1=ReadUMeshFromFile(fileName,mname,0)
44 self.assertTrue(m1_0.isEqual(m1_1,1e-12));
45 m2_0=medmesh.getLevelM1Mesh(True)
46 m2_1=ReadUMeshFromFile(fileName,mname,-1)
47 self.assertTrue(m2_0.isEqual(m2_1,1e-12));
50 def testMEDMesh2(self):
51 fileName="Pyfile10.med"
53 outFileName="MEDFileMesh1.med"
54 medmesh=MEDFileUMesh.New(fileName,mname)
55 self.assertEqual((0,),medmesh.getNonEmptyLevels())
56 m1_0=medmesh.getLevel0Mesh(True)
57 m1_1=ReadUMeshFromFile(fileName,mname,0)
58 self.assertTrue(m1_0.isEqual(m1_1,1e-12));
59 g1_0=medmesh.getGroup(0,"mesh2",True)
60 g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh2"]);
61 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
62 g1_0=medmesh.getGroup(0,"mesh3",True)
63 g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh3"]);
64 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
65 g1_0=medmesh.getGroups(0,["mesh3","mesh2"])
66 g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]);
67 g1_1.setName(g1_0.getName())
68 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
69 g1_0=medmesh.getFamily(0,"Family_-3",True)
70 g1_1=ReadUMeshFromFamilies(fileName,mname,0,["Family_-3"]);
71 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
72 g1_0=medmesh.getFamilies(0,["Family_-3","Family_-5"],True)
73 g1_1=ReadUMeshFromFamilies(fileName,mname,0,["Family_-3","Family_-5"]);
74 g1_1.setName(g1_0.getName())
75 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
76 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
77 medmesh.write(outFileName,2);
78 self.assertEqual([1,2,4,13,15],medmesh.getGroupArr(0,"mesh2",True).getValues());
79 self.assertEqual([1,2,15],medmesh.getFamilyArr(0,"Family_-3",True).getValues());
80 self.assertEqual([1,2,4,13,15],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"],True).getValues());
81 self.assertEqual([18,1,2,3,4,13,14,15],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
82 famn=medmesh.getFamilyNameGivenId(0)
83 self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True);
85 self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues());
86 self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_-3").getValues());
87 self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"]).getValues());
88 self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
89 self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False);
92 # this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account
93 def testMEDMesh3(self):
94 outFileName="MEDFileMesh3.med"
95 c=DataArrayDouble.New()
96 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 ];
97 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
98 c.setValues(coords,9,2)
99 m=MEDCouplingUMesh.New();
100 m.setMeshDimension(2);
102 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
103 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
104 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
105 m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
106 m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
107 m.finishInsertingCells();
109 m.checkConsistencyLight()
110 m1=MEDCouplingUMesh.New();
111 m1.setMeshDimension(1);
113 m1.insertNextCell(NORM_SEG2,2,[1,4])
114 m1.insertNextCell(NORM_SEG2,2,[3,6])
115 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
116 m1.finishInsertingCells();
118 m1.checkConsistencyLight()
119 m2=MEDCouplingUMesh.New();
120 m2.setMeshDimension(0);
122 m2.insertNextCell(NORM_POINT1,1,[1])
123 m2.insertNextCell(NORM_POINT1,1,[3])
124 m2.insertNextCell(NORM_POINT1,1,[2])
125 m2.insertNextCell(NORM_POINT1,1,[6])
126 m2.finishInsertingCells();
128 m2.checkConsistencyLight()
130 mm=MEDFileUMesh.New()
131 self.assertTrue(mm.getUnivNameWrStatus())
132 mm.setName("MyFirstMEDCouplingMEDmesh")
133 mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
135 mm.setMeshAtLevel(-1,m1);
136 mm.setMeshAtLevel(0,m);
137 mm.setMeshAtLevel(-2,m2);
138 # playing with groups
139 g1_2=DataArrayInt.New()
140 g1_2.setValues([1,3],2,1)
142 g2_2=DataArrayInt.New()
143 g2_2.setValues([1,2,3],3,1)
145 mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
146 g1_1=DataArrayInt.New()
147 g1_1.setValues([0,1,2],3,1)
149 g2_1=DataArrayInt.New()
150 g2_1.setValues([0,2],2,1)
152 mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
153 g1_N=DataArrayInt.New()
154 g1_N.setValues(list(range(8)),8,1)
156 g2_N=DataArrayInt.New()
157 g2_N.setValues(list(range(9)),9,1)
159 mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
160 mm.createGroupOnAll(0,"GrpOnAllCell")
161 # check content of mm
162 t=mm.getGroupArr(0,"G1",False)
163 self.assertTrue(g1_2.isEqual(t));
164 t=mm.getGroupArr(0,"G2",False)
165 self.assertTrue(g2_2.isEqual(t));
166 t=mm.getGroupArr(-1,"G1",False)
167 self.assertTrue(g1_1.isEqual(t));
168 t=mm.getGroupArr(-1,"G2",False)
169 self.assertTrue(g2_1.isEqual(t));
170 t=mm.getGroupArr(1,"G1",False)
171 self.assertTrue(g1_N.isEqual(t));
172 t=mm.getGroupArr(1,"G2",False)
173 self.assertTrue(g2_N.isEqual(t));
174 self.assertTrue(mm.existsGroup("GrpOnAllCell"));
175 t=mm.getGroupArr(0,"GrpOnAllCell")
176 self.assertTrue(t.getValues()==list(range(5)))
179 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) ; del mm
180 mmCpy.write(outFileName,2);
182 mm=MEDFileMesh.New(outFileName)
184 self.assertEqual([NORM_TRI3,NORM_QUAD4,NORM_POLYGON],mm.getGeoTypesAtLevel(0))
185 self.assertEqual([NORM_SEG2,NORM_SEG3],mm.getGeoTypesAtLevel(-1))
186 self.assertEqual([NORM_POINT1],mm.getGeoTypesAtLevel(-2))
187 mm0=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POLYGON)
188 self.assertTrue(isinstance(mm0,MEDCoupling1DGTUMesh))
189 self.assertTrue(mm0.getNodalConnectivity().isEqual(DataArrayInt([6,7,4,3,7,8,5,4])))
190 self.assertTrue(mm0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8])))
191 lmm=mm.getDirectUndergroundSingleGeoTypeMeshes(0)
192 self.assertEqual(3,len(lmm))
193 self.assertTrue(isinstance(lmm[0],MEDCoupling1SGTUMesh))
194 self.assertTrue(isinstance(lmm[1],MEDCoupling1SGTUMesh))
195 self.assertTrue(isinstance(lmm[2],MEDCoupling1DGTUMesh))
197 self.assertTrue(mm.getUnivNameWrStatus())
198 self.assertTrue(isinstance(mm.getUnivName(),str))
199 self.assertTrue(len(mm.getUnivName())!=0)
200 mbis=mm.getMeshAtLevel(0)
201 m.setName(mm.getName()) ; m.setDescription(mm.getDescription())
202 self.assertTrue(m.isEqual(mbis,1e-12));
204 self.assertEqual(([[(3, 2), (4, 1), (5, 8)], [(1, 2), (2, 1)], [(0, 4)]], 2, 2, 9),GetUMeshGlobalInfo(outFileName,"MyFirstMEDCouplingMEDmesh"))
207 # this test is the testMEDMesh3 except that permutation is dealed here
208 def testMEDMesh4(self):
209 outFileName="MEDFileMesh4.med"
210 c=DataArrayDouble.New()
211 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 ];
212 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
213 c.setValues(coords,9,2)
214 c.setInfoOnComponent(0,"abcdef [km]")
215 c.setInfoOnComponent(1,"ghij [MW]")
216 m=MEDCouplingUMesh.New();
217 m.setMeshDimension(2);
219 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
220 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
221 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
222 m.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
223 m.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
224 m.finishInsertingCells();
226 m.checkConsistencyLight()
227 m1=MEDCouplingUMesh.New();
228 m1.setMeshDimension(1);
230 m1.insertNextCell(NORM_SEG2,2,[1,4])
231 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
232 m1.insertNextCell(NORM_SEG2,2,[3,6])
233 m1.finishInsertingCells();
235 m1.checkConsistencyLight()
236 m2=MEDCouplingUMesh.New();
237 m2.setMeshDimension(0);
239 m2.insertNextCell(NORM_POINT1,1,[1])
240 m2.insertNextCell(NORM_POINT1,1,[3])
241 m2.insertNextCell(NORM_POINT1,1,[2])
242 m2.insertNextCell(NORM_POINT1,1,[6])
243 m2.finishInsertingCells();
245 m2.checkConsistencyLight()
247 mm=MEDFileUMesh.New()
248 mm.setName("My2ndMEDCouplingMEDmesh")
249 mm.setDescription("ThisIsImpossibleToDoWithMEDMEM")
251 renumNode=DataArrayInt.New()
252 renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1)
253 mm.setRenumFieldArr(1,renumNode)
254 mm.setMeshAtLevel(-1,m1,True);
255 mm.setMeshAtLevel(0,m,True);
256 mm.setMeshAtLevel(-2,m2,True);
257 mm.removeMeshAtLevel(-2)
258 mm.setMeshAtLevel(-2,m2,True);
259 # playing with groups
260 g1_2=DataArrayInt.New()
261 g1_2.setValues([2,3],2,1)
263 g2_2=DataArrayInt.New()
264 g2_2.setValues([2,0,3],3,1)
266 mm.setGroupsAtLevel(0,[g1_2,g2_2],True)
267 g1_1=DataArrayInt.New()
268 g1_1.setValues([0,2,1],3,1)
270 g2_1=DataArrayInt.New()
271 g2_1.setValues([0,2],2,1)
273 mm.setGroupsAtLevel(-1,[g1_1,g2_1],True)
274 g1_N=DataArrayInt.New()
275 g1_N.setValues([10,11,12,13,14,15,16,17],8,1)
277 g2_N=DataArrayInt.New()
278 g2_N.setValues([10,11,12,13,14,15,16,17,18],9,1)
280 mm.setGroupsAtLevel(1,[g1_N,g2_N],True)
281 # check content of mm
282 t=mm.getGroupArr(0,"G1",True)
283 self.assertTrue(g1_2.isEqual(t));
284 t=mm.getGroupArr(0,"G2",True)
285 self.assertTrue(g2_2.isEqual(t));
286 t=mm.getGroupArr(-1,"G1",True)
287 self.assertTrue(g1_1.isEqual(t));
288 t=mm.getGroupArr(-1,"G2",True)
289 self.assertTrue(g2_1.isEqual(t));
290 self.assertTrue(not mm.existsGroup("GrpOnAllCell"));
292 mm.write(outFileName,2);
293 mm2=MEDFileMesh.New(outFileName)
294 res=mm.isEqual(mm2,1e-12)
295 self.assertTrue(res[0])
296 l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
297 self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
298 mm2.keepFamIdsOnlyOnLevs([3],[-1])
299 for lev in mm.getGrpNonEmptyLevelsExt("G2"):
300 self.assertEqual(mm.getGroupArr(lev,"G2").getValues(),mm2.getGroupArr(lev,"G2").getValues())
302 l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
303 self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
305 self.assertEqual([-7,-7,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
306 mm2.getFamilyFieldAtLevel(-1).setIJ(1,0,-8)
307 self.assertEqual([-7,-8,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
308 self.assertTrue(not mm2.existsFamily("Family_-8"))
309 mm2.createGroupOnAll(-1,"GrpOnAllFace")
310 self.assertTrue(mm2.existsFamily("Family_-8"))
311 self.assertEqual(list(range(3)),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
314 #testing persistence of retrieved arrays
315 def testMEDMesh5(self):
316 fileName="Pyfile18.med"
317 mname="ExampleOfMultiDimW"
318 medmesh=MEDFileUMesh.New(fileName,mname)
319 m1_0=medmesh.getLevel0Mesh(True)
320 da1=medmesh.getFamilyFieldAtLevel(0)
322 self.assertEqual(20,m1_0.getNumberOfCells())
323 self.assertEqual(20,da1.getNumberOfTuples())
326 def testMEDMesh6(self):
327 outFileName="MEDFileMesh5.med"
330 m1=MEDCouplingCMesh.New();
331 da=DataArrayDouble.New()
332 da.setValues([0.,1.,2.],3,1)
333 da.setInfoOnComponent(0,"XX [mm]")
335 da=DataArrayDouble.New()
336 da.setValues([0.,1.2],2,1)
337 da.setInfoOnComponent(0,"YY [km]")
339 da=DataArrayDouble.New()
340 da.setValues([0.,1.3],2,1)
341 da.setInfoOnComponent(0,"ZZ [um]")
344 self.assertTrue(m[0].isEqual(m1,1e-12))
345 self.assertTrue(isinstance(m[0],MEDCouplingCMesh))
346 m.setName("myFirstCartMesh")
347 m.setDescription("mmmmpppppppp")
350 da=DataArrayInt.New()
351 da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1)
352 m.setFamilyFieldArr(1,da)
353 m.setFamilyId("family1",1)
354 da=m.getFamilyArr(1,"family1")
356 self.assertEqual(expected1,da.getValues())
357 self.assertTrue(m.getUnivNameWrStatus())
358 m.write(outFileName,2);
359 mm=MEDFileMesh.New(outFileName)
360 self.assertEqual([NORM_HEXA8],mm.getGeoTypesAtLevel(0))
361 self.assertTrue(isinstance(mm,MEDFileCMesh))
362 self.assertTrue(isinstance(mm.getUnivName(),str))
363 self.assertTrue(len(mm.getUnivName())!=0)
364 self.assertTrue(m.isEqual(mm,1e-12)[0])
365 self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
368 m1.setTime(tt[2],tt[0],tt[1])
369 m1.setName(m.getName())
370 m1.setTimeUnit(m.getTimeUnit())
371 m1.setDescription(m.getDescription())
372 self.assertTrue(m2.isEqual(m1,1e-12));
375 def testMEDMesh7(self):
376 fileName="Pyfile24.med"
377 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
379 m.setCoords(m2.getCoords())
380 m.setMeshAtLevel(0,m2)
381 m.setMeshAtLevel(-1,m1)
382 m.setMeshAtLevel(-2,m0)
383 m.setFamilyFieldArr(0,f2)
384 m.setFamilyFieldArr(-1,f1)
385 m.setFamilyFieldArr(-2,f0)
386 m.setFamilyFieldArr(1,p)
387 m.setRenumFieldArr(0,n2)
388 m.setRenumFieldArr(-1,n1)
389 m.setRenumFieldArr(-2,n0)
391 for i in range(nbOfFams):
392 m.addFamily(fns[i],fids[i])
395 for i in range(nbOfGrps):
396 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
398 m.setName(m2.getName())
399 m.setDescription(m2.getDescription())
401 self.assertEqual((-1,),m.getGrpNonEmptyLevels("A2A4"))
402 self.assertEqual((),m.getGrpNonEmptyLevels("A1"))
403 self.assertEqual((-2,),m.getGrpNonEmptyLevels("AP2"))
404 self.assertEqual((-1,-2),m.getGrpsNonEmptyLevels(["A2A4","AP2"]))
405 self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________'))
406 self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________'))
407 self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________']))
408 self.assertEqual(('A1A2','A2A4','A3A1','A3C5','A4A3','B1C1','B2B4','B3B1','B4C3','C1C4','C2B2','C3C2','C4B3','C5A4'),m.getGroupsOnSpecifiedLev(-1))
409 self.assertEqual(('DALLE','DALQ1','DALQ2','DALT3','MESH'),m.getGroupsOnSpecifiedLev(0))
412 self.assertRaises(InterpKernelException,MEDFileField1TS,fileName)#throw because no field in file fileName
415 def funcToTestDelItem(self,ff):
419 #emulation of pointe.med file.
420 def testMEDField1(self):
421 mm=MEDFileMesh.New("Pyfile17.med")
422 mm.write("Pyfile17_bis.med",2)
423 ff=MEDFileFieldMultiTS("Pyfile17.med")
424 tsExpected=[[1,2],[3,4],[5,6]]
425 self.assertEqual(3,len(ff))
426 for pos,f1ts in enumerate(ff):
427 self.assertEqual(tsExpected[pos],f1ts.getTime()[:2])
428 self.assertEqual(type(f1ts),MEDFileField1TS)
430 self.assertEqual("MeasureOfMesh_Extruded",ff.getName())
431 self.assertEqual([3,4],ff[1].getTime()[:-1])
432 self.assertEqual([3,4],ff[3,4].getTime()[:-1])
433 self.assertEqual([3,4],ff[0.01].getTime()[:-1])
434 ff.write("Pyfile17_bis.med",0)
436 ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
437 self.assertEqual([(1,2),(3,4),(5,6)],ts)
438 self.funcToTestDelItem(ff)
439 ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
440 self.assertEqual([(1,2)],ts)
444 def testMEDField2(self):
445 mm=MEDFileMesh.New("Pyfile19.med")
446 mm.write("Pyfile19_bis.med",2)
447 ff=MEDFileFieldMultiTS.New("Pyfile19.med")
448 ff.write("Pyfile19_bis.med",0)
449 self.assertEqual([('tyty','mm'),('uiop','MW')],GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes"))
453 def testMEDField3(self):
454 mm=MEDFileMesh.New("Pyfile13.med")
455 mm.write("Pyfile13_bis.med",2)
456 ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
457 ff.write("Pyfile13_bis.med",0)
458 ff=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint",1,5)
459 f=ff.getFieldAtLevel(ON_GAUSS_PT,0)
460 f2=ReadFieldGauss("Pyfile13.med",'2DMesh_2',0,'MyFirstFieldOnGaussPoint',1,5)
461 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
462 ff3=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
463 f3=ff3.getFieldAtLevel(ON_GAUSS_PT,0)
464 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
465 ff4=MEDFileField1TS.New("Pyfile13.med")
466 f4=ff4.getFieldAtLevel(ON_GAUSS_PT,0)
467 self.assertTrue(f.isEqual(f4,1e-12,1e-12))
471 def testMEDField4(self):
472 mm=MEDFileMesh.New("Pyfile14.med")
473 mm.write("Pyfile14_bis.med",2)
474 ff=MEDFileFieldMultiTS.New("Pyfile14.med","MyFieldOnGaussNE")
475 ff.write("Pyfile14_bis.med",0)
476 ff=MEDFileField1TS.New("Pyfile14.med","MyFieldOnGaussNE",1,5)
477 f=ff.getFieldAtLevel(ON_GAUSS_NE,0)
478 f2=ReadFieldGaussNE("Pyfile14.med",'2DMesh_2',0,"MyFieldOnGaussNE",1,5)
479 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
482 # MEDField get/set on pointe.med
483 def testMEDField5(self):
484 ff=MEDFileField1TS.New("Pyfile17.med","MeasureOfMesh_Extruded",1,2)
485 f=ff.getFieldAtLevel(ON_CELLS,0)
486 f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
487 self.assertTrue(f.getMesh().getCoords().isEqual(f2.getMesh().getCoords(),1e-12))
488 f.getMesh().tryToShareSameCoords(f2.getMesh(),1e-12)
489 f.changeUnderlyingMesh(f2.getMesh(),22,1e-12)
490 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
491 # no with renumbering
492 f=ff.getFieldAtLevel(ON_CELLS,0,1)
493 f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
494 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
495 f=ff.getFieldAtLevel(ON_CELLS,0,3)
496 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
497 f=ff.getFieldAtLevel(ON_CELLS,0,2)
498 self.assertTrue(not f.isEqual(f2,1e-12,1e-12))
499 f.changeUnderlyingMesh(f2.getMesh(),12,1e-12)
500 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
503 # MEDField get/set on profiles nodes
504 def testMEDField6(self):
505 ff=MEDFileFieldMultiTS.New("Pyfile7.med","VectorFieldOnNodes")
506 its=ff.getIterations()
507 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
508 f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
509 f2=ReadFieldNode("Pyfile7.med",'3DSurfMesh_1',0,"VectorFieldOnNodes",its[0][0],its[0][1])
510 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
511 ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes")
512 its=ff.getIterations()
513 f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
514 f2=ReadFieldNode("Pyfile19.med",'2DMesh_1',0,"VFieldOnNodes",its[0][0],its[0][1])
515 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
516 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
517 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_NODES,its[0][0],its[0][1],0,1)#request renumber following mesh : it is on profile !
520 # MEDField get/set on profiles cells
521 def testMEDField7(self):
522 ff=MEDFileFieldMultiTS.New("Pyfile12.med","VectorFieldOnCells")
523 its=ff.getIterations()
524 f=ff.getFieldAtLevel(ON_CELLS,its[0][0],its[0][1],0)
525 f2=ReadFieldCell("Pyfile12.med",'3DMesh_1',0,"VectorFieldOnCells",its[0][0],its[0][1])
526 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
529 #first test of assignation. No profile and types sorted by type.
530 def testMEDField8(self):
532 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
534 mm1=MEDFileUMesh.New()
535 mm1.setCoords(m1.getCoords())
536 mm1.setMeshAtLevel(0,m1)
537 mm1.setName(m1.getName())
539 ff1=MEDFileField1TS.New()
540 ff1.setFieldNoProfileSBT(f1)
542 f2=ReadFieldCell(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]);
543 itt,orr,ti=ff1.getTime()
544 self.assertEqual(0,itt); self.assertEqual(1,orr); self.assertAlmostEqual(2.,ti,14);
545 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
547 itt,orr,ti=ff1.getTime()
548 self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14);
549 da,infos=ff1.getUndergroundDataArrayExt()
550 f2.getArray().setName(da.getName())#da has the same name than f2
551 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
552 self.assertEqual([((3, 0), (0, 2)), ((4, 0), (2, 4)), ((6, 0), (4, 5)), ((5, 0), (5, 6))],infos)
555 f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
557 mm1=MEDFileUMesh.New()
558 mm1.setCoords(m1.getCoords())
559 mm1.setMeshAtLevel(0,m1)
560 mm1.setName(m1.getName())
562 ff1=MEDFileField1TS.New()
563 ff1.setFieldNoProfileSBT(f1)
565 da=ff1.getUndergroundDataArray().setIJ(0,0,nv)
567 f2=ReadFieldNode(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
568 self.assertTrue(not f1.isEqual(f2,1e-12,1e-12))
569 f1.getArray().setIJ(0,0,nv)
570 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
573 f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
575 mm1=MEDFileUMesh.New()
576 mm1.setCoords(m1.getCoords())
577 mm1.setMeshAtLevel(0,m1)
578 mm1.setName(m1.getName())
580 ff1=MEDFileField1TS.New()
581 ff1.setFieldNoProfileSBT(f1)
583 f2=ReadFieldGaussNE(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
584 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
585 da,infos=ff1.getUndergroundDataArrayExt()
586 f2.getArray().setName(da.getName())#da has the same name than f2
587 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
588 self.assertEqual([((3, 0), (0, 6)), ((4, 0), (6, 14)), ((6, 0), (14, 20))],infos)
591 f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler();
592 f1InvalidCpy=f1.deepCopy()
593 f1InvalidCpy.setDiscretization(MEDCouplingFieldDiscretizationGauss())
594 f1InvalidCpy2=f1.deepCopy()
595 f1InvalidCpy2.setDiscretization(MEDCouplingFieldDiscretizationGauss())
597 mm1=MEDFileUMesh.New()
598 mm1.setCoords(m1.getCoords())
599 mm1.setMeshAtLevel(0,m1)
600 mm1.setName(m1.getName())
602 ff1=MEDFileField1TS.New()
603 self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy) # fails because no Gauss localization per cell set !*
604 f1InvalidCpy2.getDiscretization().setArrayOfDiscIds(f1.getDiscretization().getArrayOfDiscIds()) # fails because no Gauss localization set whereas gauss locid per cell given !
605 self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy2)
606 ff1.setFieldNoProfileSBT(f1)
608 ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2])
609 f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0)
610 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
611 sbt=ff2.getFieldSplitedByType2()
612 loc1=ff2.getLocalization("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5")
613 self.assertEqual("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5",loc1.getName())
614 self.assertEqual((-1, 1,-1,-1,1,-1,-1,0,0,-1,0,0),loc1.getRefCoords())
615 self.assertEqual(6,loc1.getNumberOfPointsInCells())
616 self.assertEqual(3,loc1.getNumberOfGaussPoints())
617 self.assertEqual(2,loc1.getDimension())
618 da,infos=ff2.getUndergroundDataArrayExt()
619 f2.getArray().setName(da.getName())#da has the same name than f2
620 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
621 self.assertEqual(53,da.getNumberOfTuples())
622 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)
626 def testMEDFileData1(self):
630 m1=MEDLoaderDataForTest.build1DMesh_1()
631 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
632 mmm1=MEDFileMeshMultiTS.New() ;
633 mmm1.setOneTimeStep(mm1)
634 m2=MEDLoaderDataForTest.build2DCurveMesh_1()
635 mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName())
636 mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2)
637 ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2)
639 for name,mmm in zip(["1DMesh_1","2DCurveMesh_1"],ms):
640 self.assertEqual(name,mmm.getName())
641 self.assertEqual(type(mmm),MEDFileUMesh)
643 self.assertEqual(('1DMesh_1', '2DCurveMesh_1'),d.getMeshes().getMeshesNames())
645 ff1=MEDFileFieldMultiTS.New()
646 ff21=MEDFileFieldMultiTS.New()
647 ff22=MEDFileFieldMultiTS.New()
648 f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False)
649 f1.getArray().setInfoOnComponent(0,"power [kW]")
650 ff1.appendFieldNoProfileSBT(f1)
651 f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False)
652 f21.getArray().setInfoOnComponent(0,"sta [mm]") ;
653 ff21.appendFieldNoProfileSBT(f21)
654 f22=f21.deepCopy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ;
655 f22.applyFunc(2,"3*x*IVec+2*x*JVec")
656 f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]")
657 ff22.appendFieldNoProfileSBT(f22)
658 fs=MEDFileFields.New()
659 fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22)
660 for name,fmts in zip(["f1","f21","f22"],fs):
661 self.assertEqual(name,fmts.getName())
665 fname2="Pyfile29_2.med"
668 d2=MEDFileData.New(fname2)
669 self.assertEqual(2,d2.getNumberOfMeshes())
670 self.assertEqual(3,d2.getNumberOfFields())
671 self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))
672 self.assertTrue(isinstance(d2.getMeshes()[0],MEDFileUMesh))
673 self.assertTrue(isinstance(d2.getMeshes()['2DCurveMesh_1'],MEDFileUMesh))
674 m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
675 self.assertTrue(m1.isEqual(m1bis,1e-12))
676 self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
677 self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
678 self.assertEqual([(-1,-1,0.0)],d2.getFields()[2].getTimeSteps())
679 self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
680 self.assertEqual([(-1,-1,0.0)],d2.getFields()["f21"].getTimeSteps())
683 def testMEDField9(self):
684 # first test field profile WR. Full type but with some type missing
686 m1=MEDLoaderDataForTest.build2DMesh_3()
687 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
689 ff1=MEDFileField1TS.New()
690 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1")
691 d=DataArrayDouble.New() ; d.alloc(2*9,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
692 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.
693 da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1")
695 ff1.setFieldProfile(f1,mm1,0,da)
696 ff1.changePflsNames([(["sup1_NORM_QUAD4"],"ForV650")])
700 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
701 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))# profiles names cannot be contracted in pfl array name
702 self.assertTrue(vals.isEqual(d,1e-14))
704 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
705 ff3=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
706 ff2.deepCpyGlobs(ff3)
707 sbt=ff2.getFieldSplitedByType2()
708 self.assertEqual(3,sbt[0][0])#TRI3
709 self.assertEqual(0,sbt[0][1][0][0])#CELL For TRI3
710 self.assertEqual("",sbt[0][1][0][2])#no profile For TRI3
711 self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],sbt[0][1][0][1].getValues())# values for TRI3
712 self.assertEqual(4,sbt[1][0])#QUAD4
713 self.assertEqual(0,sbt[1][1][0][0])#CELL For QUAD4
714 self.assertEqual("ForV650",sbt[1][1][0][2])# profile For QUAD4
715 self.assertEqual([19, 20, 21, 22, 23, 24],sbt[1][1][0][1].getValues())# values for QUAD4
716 self.assertEqual([0],ff2.getTypesOfFieldAvailable())
717 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
718 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
719 self.assertTrue(vals.isEqual(d,1e-14))
722 def testMEDField10(self):
724 m1=MEDLoaderDataForTest.build2DMesh_1()
725 m1.renumberCells([0,1,4,2,3,5],False)
726 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
728 ff1=MEDFileFieldMultiTS.New()
729 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
730 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
731 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.
732 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
734 ff1.appendFieldProfile(f1,mm1,0,da)
735 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
736 ff1.appendFieldProfile(f1,mm1,0,da)
740 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
741 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
742 self.assertTrue(vals.isEqual(e,1e-14))
743 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
744 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
745 self.assertTrue(vals.isEqual(d,1e-14))
747 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
748 self.assertEqual([(-1,-1,0.0), (1,2,1.2)],ff2.getTimeSteps())
749 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
750 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
751 self.assertTrue(vals.isEqual(e,1e-14))
752 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
753 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
754 self.assertTrue(vals.isEqual(d,1e-14))
757 # idem testMEDField9 method except that here testing profile on nodes and not on cells.
758 def testMEDField11(self):
760 m1=MEDLoaderDataForTest.build2DMesh_1()
761 m1.renumberCells([0,1,4,2,3,5],False)
762 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
764 ff1=MEDFileField1TS.New()
765 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
766 d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
767 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.
768 da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
770 ff1.setFieldProfile(f1,mm1,0,da)
771 self.assertEqual(ff1.getNonEmptyLevels(),(-1, []))
774 vals,pfl=ff1.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
775 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
776 self.assertTrue(vals.isEqual(d,1e-14))
778 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
779 vals,pfl=ff2.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
780 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
781 self.assertTrue(vals.isEqual(d,1e-14))
784 def testMEDField12(self):
786 m1=MEDLoaderDataForTest.build2DMesh_1()
787 m1.renumberCells([0,1,4,2,3,5],False)
788 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
790 ff1=MEDFileFieldMultiTS.New()
791 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
792 d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
793 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.
794 da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
796 ff1.appendFieldProfile(f1,mm1,0,da)
797 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
798 ff1.appendFieldProfile(f1,mm1,0,da)
801 vals,pfl=ff1.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
802 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
803 self.assertTrue(vals.isEqual(e,1e-14))
804 vals,pfl=ff1.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
805 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
806 self.assertTrue(vals.isEqual(d,1e-14))
808 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
809 vals,pfl=ff2.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
810 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
811 self.assertTrue(vals.isEqual(e,1e-14))
812 vals,pfl=ff2.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
813 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
814 self.assertTrue(vals.isEqual(d,1e-14))
817 def testMEDField13(self):
819 m1=MEDLoaderDataForTest.build2DMesh_1()
820 m1.renumberCells([0,1,4,2,3,5],False)
822 m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
823 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
825 ff1=MEDFileField1TS.New()
826 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F3Node")
827 d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
828 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.
829 da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
831 ff1.setFieldProfile(f1,mm1,0,da)
834 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
835 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
836 self.assertTrue(vals.isEqual(d,1e-14))
838 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
839 vals,pfl=ff2.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
840 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
841 self.assertTrue(vals.isEqual(d,1e-14))
844 def testMEDField14(self):
846 m1=MEDLoaderDataForTest.build2DMesh_1()
847 m1.renumberCells([0,1,4,2,3,5],False)
849 m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
850 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
852 ff1=MEDFileFieldMultiTS.New()
853 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
854 d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
855 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.
856 da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
858 ff1.appendFieldProfile(f1,mm1,0,da)
859 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
860 ff1.appendFieldProfile(f1,mm1,0,da)
863 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
864 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
865 self.assertTrue(vals.isEqual(d,1e-14))
866 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
867 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
868 self.assertTrue(vals.isEqual(e,1e-14))
869 self.assertEqual([[3],[3]],ff1.getTypesOfFieldAvailable())
871 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
872 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
873 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
874 self.assertTrue(vals.isEqual(d,1e-14))
875 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
876 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
877 self.assertTrue(vals.isEqual(e,1e-14))
879 # 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.
880 # 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
881 # 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 !
882 def testMEDField15(self):
884 m0=MEDLoaderDataForTest.build2DMesh_1()
885 m0.renumberCells([0,1,4,2,3,5],False)
887 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
888 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
889 ff1=MEDFileField1TS.New()
890 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
891 d=DataArrayDouble.New() ; d.alloc(2*20,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
892 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.
893 da=DataArrayInt.New(); da.setValues([0,1,3,4,6],5,1) ; da.setName("sup1NodeElt")
895 ff1.setFieldProfile(f1,mm1,0,da)
896 m1=m0.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
899 f1=ff1.getFieldOnMeshAtLevel(ON_GAUSS_NE,m1,0)
900 f2,p1=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; f2.setName("")
901 self.assertTrue(p1.isIota(5))
902 self.assertTrue(f1.getArray().isEqual(f2,1e-12))
904 # Test for getFieldAtTopLevel method
905 def testMEDField16(self):
907 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
909 mm1=MEDFileUMesh.New()
910 mm1.setCoords(m1.getCoords())
911 mm1.setMeshAtLevel(0,m1)
912 mm1.setName(m1.getName())
913 ff1=MEDFileField1TS.New()
914 ff1.setFieldNoProfileSBT(f1)
915 m2=m1.buildDescendingConnectivity()[0]
916 m2.sortCellsInMEDFileFrmt()
917 m2.setName(m1.getName())
918 mm1.setMeshAtLevel(-1,m2)
920 f2=m2.getMeasureField(True)
921 dd=DataArrayDouble.New()
922 dd.alloc(f2.getArray().getNumberOfTuples(),3)
923 dd[:,0]=f2.getArray()
924 dd[:,1]=2*f2.getArray()
925 dd[:,2]=3*f2.getArray()
926 f2=f2.buildNewTimeReprFromThis(ONE_TIME,False)
928 f2.copyTinyStringsFrom(f1)
929 f2.copyTinyAttrFrom(f1)
930 ff1.setFieldNoProfileSBT(f2)
932 # Reading Pyfile37.med
933 ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
934 f1bis=ff2.getFieldAtLevel(ON_CELLS,0)
935 self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
936 f1bis=ff2.getFieldAtLevel(ON_CELLS,-1)
937 self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
938 f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
939 self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
943 ff1=MEDFileField1TS.New()
944 ff1.setFieldNoProfileSBT(f2)
946 ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
947 f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
948 self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
951 # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
952 def testMEDField17(self):
954 m1=MEDLoaderDataForTest.build2DMesh_1()
955 m1.renumberCells([0,1,4,2,3,5],False)
956 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
958 ffs=MEDFileFields.New()
959 ff1=MEDFileFieldMultiTS.New()
960 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
961 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
962 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.
963 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
965 ff1.appendFieldProfile(f1,mm1,0,da)
966 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
967 ff1.appendFieldProfile(f1,mm1,0,da)
969 ffs.setFieldAtPos(0,ff1)
973 ffsr=MEDFileFields.New(fname)
974 ff3=ffsr.getFieldAtPos(0)
975 f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
976 self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
979 # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
980 def testMEDField18(self):
982 m1=MEDLoaderDataForTest.build2DMesh_1()
983 m1.renumberCells([0,1,4,2,3,5],False)
984 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
986 ffs=MEDFileFields.New()
987 ff1=MEDFileFieldMultiTS.New()
988 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
989 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
990 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.
991 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
993 ff1.appendFieldProfile(f1,mm1,0,da)
994 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
995 ff1.appendFieldProfile(f1,mm1,0,da)
999 ffsr=MEDFileFields.New(fname)
1000 ff3=ffsr.getFieldAtPos(0)
1001 f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
1002 self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
1005 def testMEDFieldBug1(self):
1006 fname="Pyfile13.med"
1007 d=MEDFileData.New(fname)
1008 self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs())
1011 def testMEDMesh8(self):
1012 m=MEDLoaderDataForTest.build1DMesh_1()
1013 m.convertQuadraticCellsToLinear()
1014 mm=MEDFileUMesh.New()
1015 mm.setMeshAtLevel(0,m)
1016 g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1")
1017 g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2")
1018 g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3")
1019 mm.setGroupsAtLevel(0,[g1,g2],False)
1020 self.assertEqual(('g1','g2'),mm.getGroupsNames())
1021 self.assertEqual(('Family_-2','Family_-3'),mm.getFamiliesNames())
1022 self.assertEqual(('Family_-2',),mm.getFamiliesOnGroup('g1'))
1023 self.assertEqual(('Family_-3',),mm.getFamiliesOnGroup('g2'))
1024 mm.assignFamilyNameWithGroupName()
1025 self.assertEqual(('g1','g2'),mm.getGroupsNames())
1026 self.assertEqual(('g1','g2'),mm.getFamiliesNames())
1027 self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1'))
1028 self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2'))
1030 mm=MEDFileUMesh.New()
1031 mm.setMeshAtLevel(0,m)
1032 mm.setGroupsAtLevel(0,[g1,g2,g3],False)
1033 self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1034 self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1035 self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1036 self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1037 self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1038 mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found
1039 self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1040 self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1041 self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1042 self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1043 self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1044 mm.changeFamilyId(5,6)
1045 g=mm.getGroupArr(0,"g3")
1046 self.assertTrue(g.isEqual(g3));
1047 g=mm.getGroupArr(0,"g2")
1048 self.assertTrue(g.isEqual(g2));
1049 g=mm.getGroupArr(0,"g1")
1050 self.assertTrue(g.isEqual(g1));
1053 # bug detected by gauthier
1054 def testMEDLoaderMEDLoaderNSReadFieldDoubleDataInMedFile(self):
1055 fname="Pyfile41.med"
1056 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
1058 mm1=MEDFileUMesh.New()
1059 mm1.setCoords(m1.getCoords())
1060 mm1.setMeshAtLevel(0,m1)
1062 ff1=MEDFileField1TS.New()
1063 ff1.setFieldNoProfileSBT(f1)
1065 # writing mesh1 and field1, now creation of mesh2 and field2
1068 m2.translate([0.5,0.6,0.7])
1069 m2.setName("3DSurfMesh_2")
1070 f2.getArray()[:]*=2.
1071 f2.setName("VectorFieldOnCells2")
1072 mm2=MEDFileUMesh.New()
1073 mm2.setCoords(m2.getCoords())
1074 mm2.setMeshAtLevel(0,m2)
1076 ff2=MEDFileField1TS.New()
1077 ff2.setFieldNoProfileSBT(f2)
1080 f3=ReadFieldCell(fname,"3DSurfMesh_1",0,"VectorFieldOnCells",0,1)
1081 self.assertTrue(f3.isEqual(f1,1e-12,1e-12))
1082 f4=ReadFieldCell(fname,"3DSurfMesh_2",0,"VectorFieldOnCells2",0,1)
1083 self.assertTrue(f4.isEqual(f2,1e-12,1e-12))
1086 def testMEDLoaderMultiLevelCellField1(self):
1087 fname="Pyfile42.med"
1088 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1089 m=MEDFileUMesh.New()
1090 m.setCoords(m2.getCoords())
1091 m.setMeshAtLevel(0,m2)
1092 m.setMeshAtLevel(-1,m1)
1093 m.setMeshAtLevel(-2,m0)
1097 compNames1=["comp1","comp2","comp3"]
1098 ff1=MEDFileField1TS.New()
1099 da2=DataArrayDouble.New()
1100 da2.alloc(m2.getNumberOfCells()*len(compNames1),1)
1102 da2.rearrange(len(compNames1))
1103 da2.setInfoOnComponents(compNames1)
1104 f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f2.setName(FieldName1) ; f2.setArray(da2) ; f2.setMesh(m2) ; f2.checkConsistencyLight()
1105 ff1.setFieldNoProfileSBT(f2)
1106 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0]))
1107 da0=DataArrayDouble.New()
1108 da0.alloc(m0.getNumberOfCells()*len(compNames1),1)
1110 da0.rearrange(len(compNames1))
1111 da0.setInfoOnComponents(compNames1)
1112 f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName1) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkConsistencyLight()
1113 ff1.setFieldNoProfileSBT(f0)
1114 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-2]))
1115 da1=DataArrayDouble.New()
1116 da1.alloc(m1.getNumberOfCells()*len(compNames1),1)
1118 da1.rearrange(len(compNames1))
1119 da1.setInfoOnComponents(compNames1)
1120 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName1) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkConsistencyLight()
1121 ff1.setFieldNoProfileSBT(f1)
1122 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1127 compNames2=["comp11","comp22"]
1128 ff2=MEDFileField1TS.New()
1129 da0=DataArrayDouble.New()
1130 da0.alloc(m0.getNumberOfCells()*2,1)
1133 da0.setInfoOnComponents(compNames2)
1134 f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName2) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkConsistencyLight()
1135 ff2.setFieldNoProfileSBT(f0)
1136 self.assertEqual(ff2.getNonEmptyLevels(),(0, [0]))
1137 da1=DataArrayDouble.New()
1138 da1.alloc(m1.getNumberOfCells()*len(compNames2),1)
1140 da1.rearrange(len(compNames2))
1141 da1.setInfoOnComponents(compNames2)
1142 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName2) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkConsistencyLight()
1143 ff2.setFieldNoProfileSBT(f1)
1144 self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1148 ff1=MEDFileField1TS.New(fname,FieldName1,-1,-1)
1149 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1150 self.assertEqual(ff1.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')]), (3, [(0, (84, 148), '', '')]), (4, [(0, (148, 212), '', '')])])
1151 ff2=MEDFileField1TS.New(fname,FieldName2,-1,-1)
1152 self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1153 self.assertEqual(ff2.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')])])
1156 def testFieldOnPflRetrieveOnMdimRelMax1(self):
1157 fname="Pyfile43.med"
1158 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1159 m=MEDFileUMesh.New()
1160 m.setMeshAtLevel(0,m2)
1161 m.setMeshAtLevel(-1,m1)
1162 m.setMeshAtLevel(-2,m0)
1163 f=MEDFileField1TS.New()
1164 ff=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
1165 ff.setName("NodeFieldPfl")
1166 arr=DataArrayDouble.New() ; arr.setValues([1.,10.,100.,2.,20.,200.],2,3)
1168 pfl=DataArrayInt.New() ; pfl.setValues([2,3],2,1) ; pfl.setName("PflNode")
1169 f.setFieldProfile(ff,m,-2,pfl)
1170 tes0=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1171 self.assertEqual(ON_NODES,tes0.getTypeOfField())
1172 self.assertEqual(1,tes0.getMesh().getMeshDimension())
1173 self.assertEqual(1,tes0.getMesh().getNumberOfCells())
1174 self.assertEqual(2,tes0.getMesh().getNumberOfNodes())
1175 self.assertEqual([1,0,1],tes0.getMesh().getNodalConnectivity().getValues())
1176 self.assertEqual([0,3],tes0.getMesh().getNodalConnectivityIndex().getValues())
1177 self.assertEqual(2,tes0.getArray().getNumberOfTuples())
1178 self.assertEqual(3,tes0.getArray().getNumberOfComponents())
1179 expected1=[1.,10.,100.,2.,20.,200.]
1180 nodeCoordsWithValue1=[10.,2.5,0.]
1181 nodeCoordsWithValue2=[10.,3.75,0.]
1183 self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
1184 self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
1187 self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
1191 tes1=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1192 self.assertEqual(ON_CELLS,tes1.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1193 self.assertEqual(0,tes1.getMesh().getMeshDimension())
1194 self.assertEqual(2,tes1.getMesh().getNumberOfCells())
1195 self.assertEqual(135,tes1.getMesh().getNumberOfNodes())
1196 self.assertEqual([0,2,0,3],tes1.getMesh().getNodalConnectivity().getValues())
1197 self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
1198 self.assertEqual(2,tes1.getArray().getNumberOfTuples())
1199 self.assertEqual(3,tes1.getArray().getNumberOfComponents())
1201 self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
1206 pfl=DataArrayInt.New() ; pfl.setValues([3,2],2,1) ; pfl.setName("PflNode")
1207 f=MEDFileField1TS.New()
1208 f.setFieldProfile(ff,m,-2,pfl)
1209 tes2=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1210 self.assertEqual(ON_NODES,tes2.getTypeOfField())
1211 self.assertEqual(1,tes2.getMesh().getMeshDimension())
1212 self.assertEqual(1,tes2.getMesh().getNumberOfCells())
1213 self.assertEqual(2,tes2.getMesh().getNumberOfNodes())
1214 self.assertEqual([1,0,1],tes2.getMesh().getNodalConnectivity().getValues())
1215 self.assertEqual([0,3],tes2.getMesh().getNodalConnectivityIndex().getValues())
1216 self.assertEqual(2,tes2.getArray().getNumberOfTuples())
1217 self.assertEqual(3,tes2.getArray().getNumberOfComponents())
1218 expected2=[2.,20.,200.,1.,10.,100.]
1220 self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
1221 self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
1224 self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
1227 tes3=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1228 self.assertEqual(ON_CELLS,tes3.getTypeOfField())# it is not a bug even if ON_NODES has been sepecified
1229 self.assertEqual(0,tes3.getMesh().getMeshDimension())
1230 self.assertEqual(2,tes3.getMesh().getNumberOfCells())
1231 self.assertEqual(135,tes3.getMesh().getNumberOfNodes())
1232 self.assertEqual([0,3,0,2],tes3.getMesh().getNodalConnectivity().getValues())
1233 self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
1234 self.assertEqual(2,tes3.getArray().getNumberOfTuples())
1235 self.assertEqual(3,tes3.getArray().getNumberOfComponents())
1237 self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
1241 def testBuildInnerBoundaryAlongM1Group1(self):
1242 fname="Pyfile44.med"
1243 m=MEDCouplingCMesh.New()
1244 m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1245 m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1246 m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1247 m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1248 m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1249 m2.setName(m.getName())
1250 grp=DataArrayInt.New([4,6,8]) ; grp.setName("Grp")
1251 grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1252 mm=MEDFileUMesh.New()
1253 mm.setMeshAtLevel(0,m)
1254 mm.setMeshAtLevel(-1,m2)
1255 mm.setGroupsAtLevel(-1,[grp,grp2])
1256 grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1257 mm.setGroupsAtLevel(1,[grpNode])
1258 ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1259 ref1=[4,9,8,14,15,4,10,9,15,16,4,11,10,16,17]
1260 ref2=[4,9,8,14,30,4,10,9,30,31,4,11,10,31,32]
1262 self.assertEqual(30,mm.getNumberOfNodes())
1263 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1264 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())
1266 nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1267 self.assertEqual([15,16,17],nodes.getValues());
1268 self.assertEqual([7,8,9],cells.getValues());
1269 self.assertEqual([12,13,14],cells2.getValues());
1270 self.assertEqual(33,mm.getNumberOfNodes())
1271 self.assertEqual([4,6,8],mm.getGroupArr(-1,"Grp").getValues())
1272 self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1273 self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1274 self.assertEqual([17,18,19],mm.getGroupArr(-1,"Grp_dup").getValues())
1275 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
1276 self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())#
1277 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
1278 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1279 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])
1280 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1281 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1283 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1284 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1285 refValues2=refValues[:] ; refValues2[7:10]=[1.365,1.26,1.35]
1286 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1287 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1291 def testBuildInnerBoundaryAlongM1Group2(self):
1292 fname="Pyfile45.med"
1293 m=MEDCouplingCMesh.New()
1294 m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1295 m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1296 m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1297 m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1298 m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1299 m2.setName(m.getName())
1300 grp=DataArrayInt.New([4,6]) ; grp.setName("Grp")
1301 grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1302 mm=MEDFileUMesh.New()
1303 mm.setMeshAtLevel(0,m)
1304 mm.setMeshAtLevel(-1,m2)
1305 mm.setGroupsAtLevel(-1,[grp,grp2])
1306 grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1307 mm.setGroupsAtLevel(1,[grpNode])
1308 ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1309 ref1=[4,9,8,14,15,4,10,9,15,16]
1310 ref2=[4,9,8,14,30,4,10,9,30,16]
1312 self.assertEqual(30,mm.getNumberOfNodes())
1313 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1314 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())
1316 nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1317 self.assertEqual([15],nodes.getValues());
1318 self.assertEqual([7,8],cells.getValues());
1319 self.assertEqual([12,13],cells2.getValues());
1320 self.assertEqual(31,mm.getNumberOfNodes())
1321 self.assertEqual([4,6],mm.getGroupArr(-1,"Grp").getValues())
1322 self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1323 self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1324 self.assertEqual([17,18],mm.getGroupArr(-1,"Grp_dup").getValues())
1325 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
1326 self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())#
1327 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
1328 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1329 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])
1330 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1331 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1333 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1334 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1335 refValues2=refValues[:] ; refValues2[7:9]=[1.365,1.47]
1336 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1337 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1341 def testBuildInnerBoundaryAlongM1Group3(self):
1342 """ Test buildInnerBoundaryAlongM1Group() with *non-connex* cracks """
1343 fname = "Pyfile73.med"
1344 m = MEDCouplingCMesh.New()
1345 m.setCoordsAt(0, DataArrayDouble([0.0,1.1,2.3,3.6,5.0]))
1346 m.setCoordsAt(1, DataArrayDouble([0.,1.,2.]))
1347 m = m.buildUnstructured(); m.setName("simple")
1348 m2 = m.buildDescendingConnectivity()[0]
1349 m2.setName(m.getName())
1351 # A crack in two non connected parts of the mesh:
1352 grpSeg = DataArrayInt([3,19]) ; grpSeg.setName("Grp")
1354 mm = MEDFileUMesh.New()
1355 mm.setMeshAtLevel(0,m)
1356 mm.setMeshAtLevel(-1,m2)
1357 mm.setGroupsAtLevel(-1,[grpSeg])
1358 nodes, cellsMod, cellsNotMod = mm.buildInnerBoundaryAlongM1Group("Grp")
1359 self.assertEqual([1,13],nodes.getValues());
1360 self.assertEqual([0,6],cellsMod.getValues());
1361 self.assertEqual([1,7],cellsNotMod.getValues());
1362 self.assertEqual(17,mm.getNumberOfNodes())
1363 self.assertEqual([3,19],mm.getGroupArr(-1,"Grp").getValues())
1364 self.assertEqual([22,23],mm.getGroupArr(-1,"Grp_dup").getValues())
1365 ref0=[4, 15, 0, 5, 6, 4, 8, 7, 12, 16]
1366 ref1=[4, 2, 1, 6, 7, 4, 9, 8, 13, 14]
1367 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[0,6]].getNodalConnectivity().getValues())
1368 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[1,7]].getNodalConnectivity().getValues())
1369 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
1370 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1372 refValues=DataArrayDouble([1.1, 1.2, 1.3, 1.4, 1.1, 1.2, 1.3, 1.4])
1373 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1374 self.assertTrue(delta.getMaxValue()[0]<1e-10)
1376 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1377 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1378 refValues2=refValues[:] ; refValues2[0] = 1.265; refValues2[6] = 1.105
1379 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1380 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1383 def testBuildInnerBoundaryAlongM1Group4(self):
1384 """ Test case where cells touch the M1 group on some nodes only and not on full egdes (triangle mesh for ex)
1386 coo = DataArrayDouble([0.,0., 1.,0., 2.,0., 3.,0.,
1387 0.,1., 1.,1., 2.,1., 3.,1.,
1388 0.,2., 1.,2., 2.,2., 3.,2.], 12, 2)
1389 conn = [3,0,4,1, 3,1,4,5,
1396 connI = DataArrayInt()
1397 connI.alloc(13, 1); connI.iota(); connI *= 4
1398 m2 = MEDCouplingUMesh("2D", 2)
1400 m2.setConnectivity(DataArrayInt(conn), connI)
1401 m2.checkConsistency()
1402 m1, _, _, _, _ = m2.buildDescendingConnectivity()
1403 grpIds = DataArrayInt([9,11]); grpIds.setName("group")
1404 grpIds2 = DataArrayInt([0,1]); grpIds2.setName("group2")
1405 mfu = MEDFileUMesh()
1406 mfu.setMeshAtLevel(0, m2)
1407 mfu.setMeshAtLevel(-1, m1)
1408 mfu.setGroupsAtLevel(-1, [grpIds, grpIds2])
1409 nNod = m2.getNumberOfNodes()
1410 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1411 m2_bis = mfu.getMeshAtLevel(0)
1412 m2_bis.checkConsistency()
1413 m1_bis = mfu.getMeshAtLevel(-1)
1414 m1_bis.checkConsistency()
1415 self.assertEqual(nNod+2, mfu.getNumberOfNodes())
1416 self.assertEqual(nNod+2, m2_bis.getNumberOfNodes())
1417 self.assertEqual(nNod+2, m1_bis.getNumberOfNodes())
1418 self.assertEqual([6,7], nodesDup.getValues())
1419 self.assertEqual([2.,1., 3.,1.], m2_bis.getCoords()[nNod:].getValues())
1420 self.assertEqual(set([3,10,11]), set(cells1.getValues()))
1421 self.assertEqual(set([8,9,4,5]), set(cells2.getValues()))
1422 self.assertEqual([9,11],mfu.getGroupArr(-1,"group").getValues())
1423 self.assertEqual([23,24],mfu.getGroupArr(-1,"group_dup").getValues())
1424 self.assertEqual([0,1],mfu.getGroupArr(-1,"group2").getValues())
1425 # mfu.getMeshAtLevel(0).writeVTK("/tmp/mfu_M0.vtu")
1426 ref0 =[3, 5, 10, 12, 3, 12, 10, 11, 3, 12, 11, 13]
1427 ref1 =[3, 2, 6, 7, 3, 2, 7, 3, 3, 1, 5, 6, 3, 1, 6, 2]
1428 self.assertEqual(ref0,mfu.getMeshAtLevel(0)[[3,10,11]].getNodalConnectivity().getValues())
1429 self.assertEqual(ref1,mfu.getMeshAtLevel(0)[[4,5,8,9]].getNodalConnectivity().getValues())
1430 self.assertRaises(InterpKernelException,mfu.getGroup(-1,"group_dup").checkGeoEquivalWith,mfu.getGroup(-1,"group"),2,1e-12) # Grp_dup and Grp are not equal considering connectivity only
1431 mfu.getGroup(-1,"group_dup").checkGeoEquivalWith(mfu.getGroup(-1,"group"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1432 m_bis0 = mfu.getMeshAtLevel(-1)
1433 m_desc, _, _, _, _ = m_bis0.buildDescendingConnectivity()
1434 m_bis0.checkDeepEquivalOnSameNodesWith(mfu.getMeshAtLevel(-1), 2, 9.9999999)
1436 def testBuildInnerBoundary5(self):
1437 """ Full 3D test with tetras only. In this case a tri from the group is not duplicated because it is made only
1438 of non duplicated nodes. The tri in question is hence not part of the final new "dup" group. """
1439 coo = DataArrayDouble([200.0, 200.0, 0.0, 200.0, 200.0, 200.0, 200.0, 0.0, 200.0, 200.0, 0.0, 0.0, 0.0, 200.0, 0.0, 0.0, 200.0, 200.0, 0.0, 0.0, 0.0, 0.0, 0.0,
1440 200.0, 400.0, 200.0, 0.0, 400.0, 200.0, 200.0, 400.0, 0.0, 0.0, 400.0, 0.0, 200.0, 0.0, 100.00000000000016, 200.0, 63.15203310314546, 200.0, 200.0, 134.45205700643342,
1441 200.0, 200.0, 200.0, 100.00000000000016, 200.0, 63.15203310314546, 0.0, 200.0, 134.45205700643342, 0.0, 200.0, 0.0, 100.00000000000016, 0.0, 63.15203310314546,
1442 200.0, 0.0, 134.45205700643342, 200.0, 0.0, 200.0, 100.00000000000016, 0.0, 63.15203310314546, 0.0, 0.0, 134.45205700643342, 0.0, 0.0, 200.0, 200.0, 100.02130053568538,
1443 0.0, 200.0, 100.00938163175135, 200.0, 0.0, 100.02130053568538, 0.0, 0.0, 100.00938163175135, 299.3058739933347, 200.0, 200.0, 400.0, 98.68100542924483,
1444 200.0, 302.8923433403344, 0.0, 200.0, 302.8923433403344, 200.0, 0.0, 400.0, 100.00000000000016, 0.0, 302.8923433403344, 0.0, 0.0, 400.0, 200.0, 98.55126825835082,
1445 400.0, 0.0, 100.02162286181577, 99.31624553977466, 99.99999998882231, 200.0, 99.31624576683302, 100.00000010178034, 0.0, 99.31624560596512, 200.0, 100.0050761312483,
1446 99.31624560612883, 0.0, 100.00507613125338, 200.0, 99.99999995813045, 100.00950673487786, 0.0, 99.99999989928207, 100.0041870621175, 301.29063354383015,
1447 100.0000000093269, 0.0, 301.29063360689975, 0.0, 100.00957769061164, 140.52853868782435, 99.99999963972768, 100.00509135751312, 297.87779091770784,
1448 97.16750463405486, 97.18018457127863], 46, 3)
1449 c0 = [14, 45, 31, 21, 42, 14, 37, 38, 20, 44, 14, 39, 36, 41, 44, 14, 5, 25, 12, 13, 14, 38, 36, 44, 41, 14, 21, 20, 24, 44, 14, 38, 25, 41, 19, 14, 37, 38, 44, 41, 14, 16, 27,
1450 39, 41, 14, 21, 45, 26, 40, 14, 39, 37, 44, 41, 14, 14, 15, 24, 44, 14, 25, 38, 41, 13, 14, 27, 18, 6, 22, 14, 38, 36, 41, 13, 14, 44, 14, 15, 36, 14, 44, 23, 39, 26, 14,
1451 21,26, 23, 44, 14, 38, 44, 14, 24, 14, 39, 37, 41, 22, 14, 21, 33, 45, 42, 14, 27, 22, 39, 41, 14, 23, 26, 21, 3, 14, 27, 18, 22, 41, 14, 39, 36, 44, 17, 14, 21, 26, 44, 40,
1452 14, 39, 37, 22, 23, 14, 37, 38, 41, 19, 14, 25, 12, 13, 41, 14, 30, 26, 43, 45, 14, 38, 36, 13, 14, 14, 12, 36, 13, 41, 14, 20, 44, 21, 37, 14, 16, 36, 12, 41, 14, 39, 36,
1453 17, 16, 14, 44, 20, 24, 38, 14, 27, 16, 12, 41, 14, 26, 15, 17, 44, 14, 19, 18, 41, 37, 14, 40, 45, 26, 15, 14, 37, 38, 19, 20, 14, 17, 15, 26, 2, 14, 39, 36, 16, 41, 14,
1454 24, 21, 44, 40, 14, 16, 7, 27, 12, 14, 22, 18, 37, 41, 14, 21, 31, 45, 24, 14, 44, 40, 15, 24, 14, 24, 45, 15, 28, 14, 44, 40, 26, 15, 14, 24, 20, 21, 0, 14, 38, 36, 14,
1455 44, 14, 39, 37, 23, 44, 14, 45, 31, 42, 32, 14, 25, 18, 19, 4, 14, 36, 44, 17, 15, 14, 25, 19, 18, 41, 14, 24, 15, 14, 1, 14, 45, 24, 34, 28, 14, 35, 45, 30, 43, 14, 17,
1456 44, 39, 26, 14, 44, 23, 21, 37, 14, 30, 45, 29, 15, 14, 45, 35, 33, 43, 14, 30, 15, 26, 45, 14, 31, 21, 0, 24, 14, 33, 35, 32, 10, 14, 29, 45, 34, 28, 14, 32, 45, 34,
1457 29, 14, 45, 31, 32, 34, 14, 33, 26, 45, 43, 14, 45, 31, 34, 24, 14, 33, 26, 21, 45, 14, 11, 30, 35, 29, 14, 33, 35, 45, 32, 14, 33, 45, 42, 32, 14, 32, 8, 34, 31, 14,
1458 21, 26, 33, 3, 14, 35, 45, 32, 29, 14, 29, 34, 9, 28, 14, 15, 45, 24, 40, 14, 29, 45, 28, 15, 14, 21, 24, 45, 40, 14, 24, 15, 1, 28, 14, 35, 45, 29, 30, 14, 26, 15,
1460 cI0 = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 185,
1461 190, 195, 200, 205, 210, 215, 220, 225, 230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295, 300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355,
1462 360, 365, 370, 375, 380, 385, 390, 395, 400, 405, 410, 415, 420, 425, 430]
1463 m3 = MEDCouplingUMesh("3D", 3)
1465 m3.setConnectivity(DataArrayInt(c0), DataArrayInt(cI0))
1466 m3.checkConsistency()
1467 m2, _, _, _, _ = m3.buildDescendingConnectivity()
1468 grpIds = DataArrayInt([36,74]); grpIds.setName("group")
1469 mfu = MEDFileUMesh()
1470 mfu.setMeshAtLevel(0, m3)
1471 mfu.setMeshAtLevel(-1, m2)
1472 grpIds3D = DataArrayInt([0,1]); grpIds3D.setName("group_3d")
1473 mfu.setGroupsAtLevel(0, [grpIds3D]) # just to check preservation of 3D group
1474 mfu.setGroupsAtLevel(-1, [grpIds])
1475 nNod = m3.getNumberOfNodes()
1476 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1477 m3_bis = mfu.getMeshAtLevel(0)
1478 m3_bis.checkConsistency()
1479 m2_bis = mfu.getMeshAtLevel(-1)
1480 m2_bis.checkConsistency()
1481 self.assertEqual(nNod+1, mfu.getNumberOfNodes())
1482 self.assertEqual(nNod+1, m3_bis.getNumberOfNodes())
1483 self.assertEqual(nNod+1, m2_bis.getNumberOfNodes())
1484 self.assertEqual([3], nodesDup.getValues())
1485 self.assertEqual(m3_bis.getCoords()[3].getValues(), m3_bis.getCoords()[nNod:].getValues())
1486 self.assertEqual(set([22]), set(cells1.getValues()))
1487 self.assertEqual(set([77]), set(cells2.getValues()))
1488 self.assertEqual([36,74],mfu.getGroupArr(-1,"group").getValues())
1489 self.assertEqual([0,1],mfu.getGroupArr(0,"group_3d").getValues())
1490 self.assertEqual([213],mfu.getGroupArr(-1,"group_dup").getValues()) # here only one cell has been duplicated
1491 m_bis0 = mfu.getMeshAtLevel(-1)
1492 m_desc, _, _, _, _ = m_bis0.buildDescendingConnectivity()
1493 m_bis0.checkDeepEquivalOnSameNodesWith(mfu.getMeshAtLevel(-1), 2, 9.9999999)
1496 def testBasicConstructors(self):
1497 fname="Pyfile18.med"
1498 m=MEDFileMesh.New(fname)
1499 m=MEDFileMesh.New(fname,"ExampleOfMultiDimW",-1,-1)
1500 m=MEDFileMesh.New(fname)
1501 m=MEDFileUMesh(fname,"ExampleOfMultiDimW",-1,-1)
1502 m=MEDFileUMesh(fname)
1505 m=MEDFileCMesh("MEDFileMesh5.med")
1506 m=MEDFileCMesh("MEDFileMesh5.med","myFirstCartMesh",-1,-1)
1508 m=MEDFileMeshMultiTS()
1509 m=MEDFileMeshMultiTS(fname)
1510 m=MEDFileMeshMultiTS(fname,"ExampleOfMultiDimW")
1512 m=MEDFileMeshes(fname)
1514 m=MEDFileField1TS(fname,"FieldOnFacesShuffle",2,7)
1515 m=MEDFileFieldMultiTS()
1516 m=MEDFileFieldMultiTS(fname,"FieldOnFacesShuffle")
1518 m=MEDFileFields(fname)
1520 m=MEDFileData(fname)
1522 m=DataArrayInt() ; m=DataArrayInt(5,2) ; m=DataArrayInt([6,5,4,3,2,1],3,2)
1523 m=DataArrayDouble() ; m=DataArrayDouble(5,2) ; m=DataArrayDouble([6,5,4,3,2,1],3,2)
1524 m=MEDCouplingUMesh("jjj",2) ; m=MEDCouplingUMesh()
1525 m=MEDCouplingCMesh()
1526 m=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1527 m=MEDCouplingFieldTemplate(ON_NODES)
1528 m=MEDCouplingMultiFields([])
1529 m=MEDCouplingFieldOverTime([])
1532 # This is a non regression test. When a field lies partially on a mesh but fully on one of its geometric type.
1533 def testBugSemiPartialField(self):
1534 fname="Pyfile46.med"
1535 m=MEDLoaderDataForTest.build2DMesh_3()
1536 m=m[:10] ; m.setName("mesh")
1537 f=m.getMeasureField(False)
1538 f=f.buildNewTimeReprFromThis(ONE_TIME,False)
1540 f.setName("SemiPartialField")
1542 f1=f[:6] ; f1.getMesh().setName(m.getName())
1543 f2=f[6:] ; f2.getMesh().setName(m.getName())
1545 mm=MEDFileUMesh.New()
1546 mm.setMeshAtLevel(0,m)
1547 ff=MEDFileField1TS.New()
1548 ff.setFieldProfile(f1,mm,0,DataArrayInt.Range(0,6,1)) # no name on profile -> normally it is an error but in this special case
1552 ff2=MEDFileField1TS.New(fname,f.getName(),f.getTime()[1],f.getTime()[2])
1553 fread=ff2.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
1554 fread2=ff2.getFieldAtLevel(ON_CELLS,0)
1556 fread.checkConsistencyLight()
1557 fread2.checkConsistencyLight()
1558 self.assertTrue(fread.isEqual(f1,1e-12,1e-12))
1559 self.assertTrue(fread2.isEqual(f1,1e-12,1e-12))
1562 def testUnPolyze1(self):
1563 fname="Pyfile47.med"
1564 mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1565 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]
1566 self.assertEqual(ref,mm.getFamilyFieldAtLevel(1).getValues())
1567 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]]))
1569 self.assertEqual(mm.getGroupArr(0,"grp0_L0").getValues(),[0,1,2,6])
1570 self.assertEqual(mm.getGroupArr(0,"grp1_L0").getValues(),[1,3,4,5,6])
1571 self.assertEqual(mm.getGroupArr(-1,"grp0_LM1").getValues(),[1,2,3,4,5])
1572 self.assertEqual(mm.getGroupArr(-1,"grp1_LM1").getValues(),[3,4,5,6])
1573 self.assertEqual(mm.getGroupArr(-1,"grp2_LM1").getValues(),[2,6,7,8])
1574 self.assertEqual(mm.getGroupArr(1,"grp0_Node").getValues(),[0,11,15,16])
1575 self.assertEqual(mm.getGroupArr(1,"grp1_Node").getValues(),[1,2,13,14,16])
1576 self.assertEqual(mm.getFamilyFieldAtLevel(1).getValues(),ref)
1578 mm.setRenumFieldArr(0,None)
1579 mm.setFamilyFieldArr(-1,None)
1582 def testUnPolyze2(self):
1583 fname="Pyfile48.med"
1584 mfd=MEDFileData.New()
1585 mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1586 meshes=MEDFileMeshes.New()
1588 mfd.setMeshes(meshes)
1589 fields=MEDFileFields.New()
1590 mfd.setFields(fields)
1591 ff=MEDFileFieldMultiTS.New()
1592 fields.pushField(ff)
1594 f0_0=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f0_0.setName("f0")
1595 f0_0.setTime(9.5,3,4)
1596 da=DataArrayDouble.New(38*2) ; da.iota(6.) ; da.rearrange(2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1598 f0_0.setMesh(mm.getMeshAtLevel(0))
1599 ff.appendFieldNoProfileSBT(f0_0)
1600 ff0=ff.getTimeStepAtPos(0)
1601 f0_1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_1.setName("f0")
1602 f0_1.setTime(9.5,3,4)
1603 pfl=DataArrayInt.New([1,4,5,6]) ; pfl.setName("pfltest")
1604 f0_1.setMesh(mm.getMeshAtLevel(0)[pfl])
1605 da=DataArrayDouble.New([1401.,101401.,1602.,101602.,3100.,103100.,3101.,103101.],4,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1607 ff0.setFieldProfile(f0_1,mm,0,pfl)
1608 f0_2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_2.setName("f0")#provoquer error
1609 f0_2.setTime(9.5,3,4)
1610 pfl2=DataArrayInt.New([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfltestM1")
1611 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
1612 f0_2.setMesh(mm.getMeshAtLevel(-1)[pfl2])
1614 ff0.setFieldProfile(f0_2,mm,-1,pfl2)
1615 mfd.getFields().shallowCpyGlobs(ff0)
1617 mfd.unPolyzeMeshes()
1619 fmts=mfd.getFields()[0]
1620 self.assertEqual(fmts.getNumberOfTS(),1)
1621 self.assertEqual(fmts.getTimeSteps(),[(3,4,9.5)])
1622 arr,entry=fmts.getUndergroundDataArrayExt(3,4)
1623 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))])
1624 self.assertTrue(arr[38:40].isEqualWithoutConsideringStr(DataArrayDouble([300.0,100300.0,301.0,100301.0],2,2),1e-8))
1625 self.assertTrue(arr[40:43].isEqualWithoutConsideringStr(DataArrayDouble([400.0,100400.0,401.0,100401.0,402.0,100402.0],3,2),1e-8))
1626 self.assertTrue(arr[43:46].isEqualWithoutConsideringStr(DataArrayDouble([3200.0,103200.0,3201.0,103201.0,3203.0,103203.0],3,2),1e-8))
1627 self.assertTrue(arr[46:48].isEqualWithoutConsideringStr(DataArrayDouble([1401.0,101401.0,3100.0,103100.0],2,2),1e-8))
1628 self.assertTrue(arr[48:49].isEqualWithoutConsideringStr(DataArrayDouble([1602.0,101602.0],1,2),1e-8))
1629 self.assertTrue(arr[49:50].isEqualWithoutConsideringStr(DataArrayDouble([3101.0,103101.0],1,2),1e-8))
1630 self.assertEqual(('NewPfl_0','NewPfl_1','NewPfl_2'),fmts.getPflsReallyUsed())
1631 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))
1632 self.assertEqual(fmts.getProfile("NewPfl_0").getValues(),[0,1])
1633 self.assertEqual(fmts.getProfile("NewPfl_1").getValues(),[1,2])
1634 self.assertEqual(fmts.getProfile("NewPfl_2").getValues(),[2])
1635 ftest0=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,0,mfd.getMeshes()[0])
1636 self.assertTrue(ftest0.getArray().isEqualWithoutConsideringStr(DataArrayDouble([1401.,101401.,3100.,103100.,1602.,101602.,3101.,103101.],4,2),1e-8))
1637 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])
1638 self.assertEqual(ftest0.getMesh().getNodalConnectivityIndex().getValues(),[0,5,10,17,26])
1639 ftest1=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,-1,mfd.getMeshes()[0])
1640 self.assertTrue(ftest1.getArray().isEqualWithoutConsideringStr(DataArrayDouble([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.]),1e-8))
1641 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])
1642 self.assertEqual(ftest1.getMesh().getNodalConnectivityIndex().getValues(),[0,4,8,13,18,23,29,35,43])
1647 def testGaussWriteOnPfl1(self):
1648 fname="Pyfile49.med"
1649 fname2="Pyfile50.med"
1650 coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
1651 mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
1652 mQ8.allocateCells(1)
1653 mQ8.insertNextCell(NORM_QUAD8,list(range(8)))
1654 mQ8.finishInsertingCells()
1655 mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
1656 mQ4.allocateCells(1)
1657 mQ4.insertNextCell(NORM_QUAD4,list(range(4)))
1658 mQ4.finishInsertingCells()
1659 mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
1660 mT3.allocateCells(1)
1661 mT3.insertNextCell(NORM_TRI3,list(range(3)))
1662 mT3.finishInsertingCells()
1664 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.]]
1665 ms=11*[mT3]+2*[mQ4]+7*[mQ8]
1666 ms[:]=(elt.deepCopy() for elt in ms)
1667 for m,t in zip(ms,tr):
1668 d=m.getCoords() ; d+= t
1670 m=MEDCouplingUMesh.MergeUMeshes(ms)
1672 m2=m[:13] ; m2.setName(m.getName())
1673 ### 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.
1674 ### So here 2 pfls will be created (pfl_TRI3_loc_0 and pfl_TRI3_loc_1)
1675 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1678 da=DataArrayDouble(34) ; da.iota(3.)
1680 f.setName("fieldCellOnPflWithoutPfl")
1681 fInvalid=f.deepCopy()
1682 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])
1683 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])
1684 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])
1685 f.checkConsistencyLight()
1686 fInvalid2=fInvalid.deepCopy()
1687 fInvalid2.getDiscretization().setArrayOfDiscIds(f.getDiscretization().getArrayOfDiscIds())
1690 mm.setMeshAtLevel(0,m)
1693 f1ts=MEDFileField1TS.New()
1694 pfl=DataArrayInt(list(range(13))) ; pfl.setName("pfl")
1695 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set !
1696 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given !
1697 f1ts.setFieldProfile(f,mm,0,pfl)
1700 self.assertEqual(f1ts.getPfls(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1701 self.assertEqual(f1ts.getPflsReallyUsed(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1702 da1=DataArrayInt([0,1,2,3,4,5,6,7,8]) ; da1.setName("pfl_NORM_TRI3_loc_0")
1703 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_0").isEqual(da1))
1704 da1=DataArrayInt([9,10]) ; da1.setName("pfl_NORM_TRI3_loc_1")
1705 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_1").isEqual(da1))
1706 self.assertEqual(f1ts.getLocs(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1707 self.assertEqual(f1ts.getLocsReallyUsed(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1709 dataRead=MEDFileData.New(fname)
1710 mRead=dataRead.getMeshes()[0]
1711 f1tsRead=dataRead.getFields()[0][0]
1712 f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1713 f2=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1714 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
1715 f2_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1716 f2_bis.checkConsistencyLight()
1717 self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12))
1719 WriteField(fname2,f,True)
1720 f2_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1721 self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12))
1722 ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc
1723 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1724 pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2")
1725 m2=m[pfl] ; m2.setName(m.getName())
1728 da=DataArrayDouble(35) ; da.iota(3.)
1730 f.setName("fieldCellOnPflWithoutPfl2")
1731 f.setGaussLocalizationOnCells([0,1,3],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1732 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])
1733 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])
1734 f.checkConsistencyLight()
1737 mm.setMeshAtLevel(0,m)
1739 f1ts=MEDFileField1TS.New()
1740 f1ts.setFieldProfile(f,mm,0,pfl)
1741 self.assertEqual(f1ts.getPfls(),('pfl2_NORM_TRI3_loc_0','pfl2_NORM_TRI3_loc_1','pfl2_NORM_QUAD8_loc_2'))
1742 self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_0").getValues(),[1,2,6])
1743 self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_1").getValues(),[5,8,9])
1744 self.assertEqual(f1ts.getProfile("pfl2_NORM_QUAD8_loc_2").getValues(),[2,3,4,5])
1746 dataRead=MEDFileData.New(fname)
1747 mRead=dataRead.getMeshes()[0]
1748 f1tsRead=dataRead.getFields()[0][0]
1749 f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1750 f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1751 f3.renumberCells([0,1,3,2,4,5,6,7,8,9])
1752 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1753 f3_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1754 f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9])
1755 self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1757 WriteField(fname2,f,True)
1758 f3_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1759 f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9])
1760 self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1761 ## Use case 3 : no pfl but creation of pfls due to gauss pts
1762 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1765 da=DataArrayDouble(60) ; da.iota(3.)
1767 f.setName("fieldCellWithoutPfl")
1768 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])
1769 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])
1770 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])
1771 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])
1772 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])
1773 f.checkConsistencyLight()
1775 mm.setMeshAtLevel(0,m)
1776 f1ts=MEDFileField1TS.New()
1777 f1ts.setFieldNoProfileSBT(f)
1778 self.assertEqual(f1ts.getPfls(),('Pfl_fieldCellWithoutPfl_NORM_TRI3_0','Pfl_fieldCellWithoutPfl_NORM_TRI3_1','Pfl_fieldCellWithoutPfl_NORM_QUAD8_3','Pfl_fieldCellWithoutPfl_NORM_QUAD8_4'))
1779 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_0").getValues(),[0,1,2,3,4,5,6,7,8])
1780 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_1").getValues(),[9,10])
1781 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_3").getValues(),[0,1,2,4,5])
1782 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_4").getValues(),[3,6])
1786 dataRead=MEDFileData.New(fname)
1787 mRead=dataRead.getMeshes()[0]
1788 f1tsRead=dataRead.getFields()[0][0]
1789 f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1790 f3.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1791 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1792 f3_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1793 f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1794 self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1796 WriteField(fname2,f,True)
1797 f3_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1798 f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1799 self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1802 # Testing profile on nodes when the profile is identity but not on all nodes.
1803 def testMEDFieldPflOnNode1(self):
1804 fname="Pyfile51.med"
1805 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)
1806 m0=MEDCouplingUMesh("Mesh",2)
1808 m0.insertNextCell(NORM_TRI3,[1,4,2])
1809 m0.insertNextCell(NORM_TRI3,[4,5,2])
1810 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1811 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1812 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1813 m0.finishInsertingCells()
1815 m1=MEDCouplingUMesh(m0.getName(),1)
1817 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1819 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1821 m1.finishInsertingCells()
1825 m.setMeshAtLevel(0,m0)
1826 m.setMeshAtLevel(-1,m1)
1828 dt=3 ; it=2 ; tim=4.5
1829 fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1830 fieldNode0.setName("fieldNode0")
1831 fieldNode0.setTime(tim,dt,it)
1832 pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
1833 arr=DataArrayDouble([10,11,12,13,14])
1834 fieldNode0.setArray(arr)
1835 f0=MEDFileField1TS()
1836 f0.setFieldProfile(fieldNode0,m,0,pfl0)
1837 m.write(fname,2) ; f0.write(fname,0)
1838 fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1839 fieldNode1.setName("fieldNode1")
1840 fieldNode1.setTime(tim,dt,it)
1841 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1842 arr1=DataArrayDouble([20,21,22,23,24,25,26])
1843 fieldNode1.setArray(arr1)
1844 f1=MEDFileField1TS()
1845 f1.setFieldProfile(fieldNode1,m,-1,pfl1)
1848 ## Reading from file
1849 m=MEDFileMesh.New(fname)
1850 m0=m.getMeshAtLevel(0)
1851 m00=m0.deepCopy() ; m00=m00[[0,2]] ; m00.setName(m.getName()) ; m00.zipCoords()
1852 fieldNode0.setMesh(m00)
1853 f0=MEDFileField1TS.New(fname,fieldNode0.getName(),dt,it)
1854 ff0_1=f0.getFieldOnMeshAtLevel(ON_NODES,m0)
1855 ff0_1.checkConsistencyLight()
1856 self.assertTrue(ff0_1.isEqual(fieldNode0,1e-12,1e-12))
1857 ff0_2=f0.getFieldAtLevel(ON_NODES,0)
1858 ff0_2.checkConsistencyLight()
1859 self.assertTrue(ff0_2.isEqual(fieldNode0,1e-12,1e-12))
1860 ff0_3=f0.getFieldOnMeshAtLevel(ON_NODES,0,m)
1861 ff0_3.checkConsistencyLight()
1862 self.assertTrue(ff0_3.isEqual(fieldNode0,1e-12,1e-12))
1863 ff0_4=ReadFieldNode(fname,m.getName(),0,fieldNode0.getName(),dt,it)
1864 ff0_4.checkConsistencyLight()
1865 self.assertTrue(ff0_4.isEqual(fieldNode0,1e-12,1e-12))
1866 f1=MEDFileField1TS.New(fname,fieldNode1.getName(),dt,it)
1867 m1=m.getMeshAtLevel(-1)
1868 m10=m1.deepCopy() ; m10=m10[[0,1,2,3,4,5,6,7]] ; m10.setName(m.getName()) ; m10.zipCoords()
1869 fieldNode1.setMesh(m10)
1870 ff1_1=f1.getFieldOnMeshAtLevel(ON_NODES,m1)
1871 ff1_1.checkConsistencyLight()
1872 self.assertTrue(ff1_1.isEqual(fieldNode1,1e-12,1e-12))
1873 ff1_2=f1.getFieldAtLevel(ON_NODES,-1)
1874 ff1_2.checkConsistencyLight()
1875 self.assertTrue(ff1_2.isEqual(fieldNode1,1e-12,1e-12))
1876 ff1_3=f1.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1877 ff1_3.checkConsistencyLight()
1878 self.assertTrue(ff1_3.isEqual(fieldNode1,1e-12,1e-12))
1879 ff1_4=ReadFieldNode(fname,m.getName(),-1,fieldNode1.getName(),dt,it)
1880 ff1_4.checkConsistencyLight()
1881 self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1882 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]
1883 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]
1884 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]
1885 arr_r,pfl1_r=f1.getFieldWithProfile(ON_NODES,-1,m)
1886 arr_r.setName(fieldNode1.getArray().getName())
1887 self.assertTrue(arr_r.isEqual(fieldNode1.getArray(),1e-12))
1888 pfl1_r.setName(pfl1.getName())
1889 self.assertTrue(pfl1_r.isEqual(pfl1))
1892 # Testing profile on nodes when the profile is identity but not on all nodes.
1893 def testMEDFieldPflOnCell1(self):
1894 fname="Pyfile52.med"
1895 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)
1896 m0=MEDCouplingUMesh("Mesh",2)
1898 m0.insertNextCell(NORM_TRI3,[1,4,2])
1899 m0.insertNextCell(NORM_TRI3,[4,5,2])
1900 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1901 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1902 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1903 m0.finishInsertingCells()
1905 m1=MEDCouplingUMesh(m0.getName(),1)
1907 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1909 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1911 m1.finishInsertingCells()
1915 m.setMeshAtLevel(0,m0)
1916 m.setMeshAtLevel(-1,m1)
1918 dt=3 ; it=2 ; tim=4.5
1919 fieldCell0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1920 fieldCell0.setName("fieldCell0")
1921 fieldCell0.setTime(tim,dt,it)
1922 pfl0=DataArrayInt([0,1,2]) ; pfl0.setName("PflIdentity0") # important to keep like that
1923 arr=DataArrayDouble([10,11,12])
1924 fieldCell0.setArray(arr)
1925 f0=MEDFileField1TS()
1926 f0.setFieldProfile(fieldCell0,m,0,pfl0)
1927 m.write(fname,2) ; f0.write(fname,0)
1928 fieldCell1=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1929 fieldCell1.setName("fieldCell1")
1930 fieldCell1.setTime(tim,dt,it)
1931 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1932 arr1=DataArrayDouble([20,21,22,23,24,25,26])
1933 fieldCell1.setArray(arr1)
1934 f1=MEDFileField1TS()
1935 f1.setFieldProfile(fieldCell1,m,-1,pfl1)
1938 ## Reading from file
1939 m=MEDFileMesh.New(fname)
1940 m0=m.getMeshAtLevel(0)
1941 m00=m0.deepCopy() ; m00=m00[pfl0] ; m00.setName(m.getName())
1942 fieldCell0.setMesh(m00)
1943 f0=MEDFileField1TS.New(fname,fieldCell0.getName(),dt,it)
1944 ff0_1=f0.getFieldOnMeshAtLevel(ON_CELLS,m0)
1945 ff0_1.checkConsistencyLight()
1946 self.assertTrue(ff0_1.isEqual(fieldCell0,1e-12,1e-12))
1947 ff0_2=f0.getFieldAtLevel(ON_CELLS,0)
1948 ff0_2.checkConsistencyLight()
1949 self.assertTrue(ff0_2.isEqual(fieldCell0,1e-12,1e-12))
1950 ff0_3=f0.getFieldOnMeshAtLevel(ON_CELLS,0,m)
1951 ff0_3.checkConsistencyLight()
1952 self.assertTrue(ff0_3.isEqual(fieldCell0,1e-12,1e-12))
1953 ff0_4=ReadFieldCell(fname,m.getName(),0,fieldCell0.getName(),dt,it)
1954 ff0_4.checkConsistencyLight()
1955 self.assertTrue(ff0_4.isEqual(fieldCell0,1e-12,1e-12))
1956 f1=MEDFileField1TS.New(fname,fieldCell1.getName(),dt,it)
1957 m1=m.getMeshAtLevel(-1)
1958 m10=m1.deepCopy() ; m10=m10[pfl1] ; m10.setName(m.getName())
1959 fieldCell1.setMesh(m10)
1960 ff1_1=f1.getFieldOnMeshAtLevel(ON_CELLS,m1)
1961 ff1_1.checkConsistencyLight()
1962 self.assertTrue(ff1_1.isEqual(fieldCell1,1e-12,1e-12))
1963 ff1_2=f1.getFieldAtLevel(ON_CELLS,-1)
1964 ff1_2.checkConsistencyLight()
1965 self.assertTrue(ff1_2.isEqual(fieldCell1,1e-12,1e-12))
1966 ff1_3=f1.getFieldOnMeshAtLevel(ON_CELLS,-1,m)
1967 ff1_3.checkConsistencyLight()
1968 self.assertTrue(ff1_3.isEqual(fieldCell1,1e-12,1e-12))
1969 ff1_4=ReadFieldCell(fname,m.getName(),-1,fieldCell1.getName(),dt,it)
1970 ff1_4.checkConsistencyLight()
1971 self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1972 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]
1973 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]
1974 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]
1975 arr_r,pfl1_r=f1.getFieldWithProfile(ON_CELLS,-1,m)
1976 arr_r.setName(fieldCell1.getArray().getName())
1977 self.assertTrue(arr_r.isEqual(fieldCell1.getArray(),1e-12))
1978 pfl1_r.setName(pfl1.getName())
1979 self.assertTrue(pfl1_r.isEqual(pfl1))
1982 def testMEDFileUMeshZipCoords1(self):
1984 coo=DataArrayDouble(30) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
1985 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])
1986 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
1987 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
1988 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
1989 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
1990 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
1991 numCoo=DataArrayInt(10) ; numCoo.iota(3) ; m.setRenumFieldArr(1,numCoo)
1992 famCoo=DataArrayInt(10) ; famCoo.iota(4) ; m.setFamilyFieldArr(1,famCoo)
1993 da=DataArrayInt([20,30,40]) ; m.setRenumFieldArr(0,da) ; da=DataArrayInt([200,300,400]) ; m.setFamilyFieldArr(0,da)
1994 da=DataArrayInt([50,60]) ; m.setRenumFieldArr(-1,da) ; da=DataArrayInt([500,600]) ; m.setFamilyFieldArr(-1,da)
1995 da=DataArrayInt([70,80,90]) ; m.setRenumFieldArr(-2,da) ; da=DataArrayInt([700,800,900]) ; m.setFamilyFieldArr(-2,da)
1997 self.assertTrue(o2n.isEqual(DataArrayInt([-1,0,1,2,3,-1,4,5,6,-1])))
1998 self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt([4,5,6,7,9,10,11])))
1999 self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([5,6,7,8,10,11,12])))
2000 self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,4,1,3,2,3,5,0,4,4,4,1])))
2001 self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,9,15])))
2002 self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivity().isEqual(DataArrayInt([1,0,4,1,5,2])))
2003 self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6])))
2004 self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivity().isEqual(DataArrayInt([0,1,0,4,0,6])))
2005 self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivityIndex().isEqual(DataArrayInt([0,2,4,6])))
2008 def testMEDUMeshAddNodeGroup1(self):
2009 fname="Pyfile53.med"
2011 coo=DataArrayDouble(39) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2012 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])
2013 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2014 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2015 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2016 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2017 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2020 famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(1,famCoo)
2021 da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(0,da0)
2022 da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
2023 da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
2024 mm.setFamilyId("MyFam",2)
2025 mm.setFamilyId("MyOtherFam",3)
2026 mm.setFamilyId("MyOther-1",-1)
2027 mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
2028 mm.setFamiliesOnGroup("grpA",["MyOther-1"])
2030 daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
2031 mm.addNodeGroup(daTest)
2032 self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
2033 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
2034 for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
2035 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2037 self.assertEqual(mm.getFamiliesNames(),('Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
2038 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2039 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2040 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2041 for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
2042 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2044 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_8'))
2045 da=DataArrayInt([3,12]) ; da.setName("grp0")
2046 self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
2048 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2050 mm=MEDFileMesh.New(fname)
2051 self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
2052 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
2053 for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
2054 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2056 self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
2057 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2058 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2059 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2060 for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
2061 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2063 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_8','MyOtherFam'))
2064 da=DataArrayInt([3,12]) ; da.setName("grp0")
2065 self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
2067 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2070 def testMEDUMeshAddGroup1(self):
2071 fname="Pyfile54.med"
2073 coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2074 m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
2076 m0.insertNextCell(NORM_TRI3,[1,2,1])
2079 m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
2082 m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
2084 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2085 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2086 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2087 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2088 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2091 famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(0,famCoo)
2092 da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(1,da0)
2093 da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
2094 da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
2095 mm.setFamilyId("MyFam",2)
2096 mm.setFamilyId("MyOtherFam",3)
2097 mm.setFamilyId("MyOther-1",-1)
2098 mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
2099 mm.setFamiliesOnGroup("grpA",["MyOther-1"])
2101 daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
2102 mm.addGroup(0,daTest)
2103 self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2104 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2105 for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2106 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2108 self.assertEqual(mm.getFamiliesNames(),('Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2109 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2110 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2111 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2112 for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2113 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2115 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_-8'))
2116 da=DataArrayInt([3,12]) ; da.setName("grp0")
2117 self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2119 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2121 mm=MEDFileMesh.New(fname)
2122 self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2123 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2124 for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2125 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2127 self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2128 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2129 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2130 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2131 for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2132 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2134 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_-8','MyOtherFam'))
2135 da=DataArrayInt([3,12]) ; da.setName("grp0")
2136 self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2138 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2141 def testHeapMem1(self):
2142 a=DataArrayInt() ; aa=a.getHeapMemorySize()
2144 strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
2146 m=MEDCouplingCMesh()
2147 arr=DataArrayDouble(10,1) ; arr.iota(0)
2148 m.setCoords(arr,arr)
2149 m=m.buildUnstructured()
2151 f=m.getMeasureField(False)
2152 self.assertIn(m.getHeapMemorySize(), list(range(3552 - 100, 3552 + 100 + 4 * strMulFac)))
2153 self.assertIn(f.getHeapMemorySize(), list(range(4215 - 100, 4215 + 100 + 8 * strMulFac)))
2156 mm.setMeshAtLevel(0,m)
2157 self.assertIn(mm.getHeapMemorySize(), list(range(3889 - 100, 4225 + 100 + 10 * strMulFac)))
2158 ff=MEDFileField1TS()
2159 ff.setFieldNoProfileSBT(f)
2160 self.assertIn(ff.getHeapMemorySize(), list(range(771 - 40, 871 + 21 + (4 + 1) * strMulFac)))
2162 fff=MEDFileFieldMultiTS()
2163 fff.appendFieldNoProfileSBT(f)
2164 self.assertIn(fff.getHeapMemorySize(), list(range(815 - 50, 915 + 30 + (6 + 2) * strMulFac)))
2166 fff.appendFieldNoProfileSBT(f)
2167 self.assertIn(fff.getHeapMemorySize(), list(range(1594 - 90, 1794 + 50 + (10 + 1) * strMulFac)))
2168 self.assertIn(fff[0, -1].getHeapMemorySize(), list(range(771 - 40, 871 + 20 + (4 + 1) * strMulFac)))
2171 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2172 fff.appendFieldProfile(f2,mm,0,pfl)
2173 self.assertIn(fff.getHeapMemorySize(), list(range(2348 - 130, 2608 + 100 + (10 + 2) * strMulFac)))
2174 self.assertIn(fff.getProfile("pfl").getHeapMemorySize(), list(range(204 - 10, 204 + 10 + 2 * strMulFac)))
2175 self.assertIn(fff[1, -1].getHeapMemorySize(), list(range(738 - 50, 838 + 30 + 4 * strMulFac)))
2178 def testCurveLinearMesh1(self):
2179 fname="Pyfile55.med"
2180 mesh=MEDCouplingCurveLinearMesh();
2181 mesh.setTime(2.3,4,5);
2182 mesh.setTimeUnit("us");
2183 mesh.setName("Example of Cuve linear mesh");
2184 mesh.setDescription("buildCLMesh");
2185 a1=DataArrayDouble(3*20,1);
2186 a1.iota(7.) ; a1.rearrange(3);
2188 mesh.setNodeGridStructure([4,5]);
2189 mesh.checkConsistencyLight();
2191 m=MEDFileCurveLinearMesh()
2193 d=DataArrayInt(20) ; d.iota(4)
2194 m.setFamilyFieldArr(1,d)
2195 d3=DataArrayInt(20) ; d3.iota(400)
2196 m.setRenumFieldArr(1,d3)
2197 d2=DataArrayInt(12) ; d2.iota(40)
2198 m.setFamilyFieldArr(0,d2)
2199 d4=DataArrayInt(21) ; d4.iota(4000)
2200 self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2202 m.setRenumFieldArr(1,d4)
2205 m1=MEDFileCurveLinearMesh(fname)
2207 self.assertTrue(mm.isEqual(mesh,1e-12))
2208 self.assertEqual(mm.getSpaceDimension(),3)
2209 self.assertEqual(mm.getSpaceDimensionOnNodeStruct(),2)
2211 m1=MEDFileMesh.New(fname)
2212 self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2213 self.assertTrue(isinstance(m1.getUnivName(),str))
2214 self.assertTrue(len(m1.getUnivName())!=0)
2215 self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2218 def testParameters1(self):
2219 fname="Pyfile56.med"
2220 m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2221 mm=MEDFileCMesh() ; mm.setMesh(m)
2222 ms=MEDFileMeshes() ; ms.pushMesh(mm)
2224 p=MEDFileParameters()
2225 data.setParams(p) ; data.setMeshes(ms)
2226 pts=MEDFileParameterMultiTS()
2227 pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2228 pts.appendValue(1,2,3.4,567.89)
2229 pts.appendValue(2,3,5.6,999.123)
2230 pts2=pts.deepCopy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2231 p.pushParam(pts) ; p.pushParam(pts2)
2233 p2=MEDFileParameters(fname)
2234 self.assertTrue(p.isEqual(p2,1e-14)[0])
2235 self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2237 pts4=pts2.deepCopy()
2238 pts3=pts2.deepCopy()
2239 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2240 pts2.eraseTimeStepIds([0])
2241 self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2243 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2244 self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2245 self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2246 self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2247 self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2249 self.assertTrue(p.isEqual(p2,1e-14)[0])
2250 self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2251 self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2252 self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2253 self.assertEqual(p.getParamsNames(),('A','B'))
2254 ptsr=MEDFileParameterMultiTS(fname,"B")
2255 self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2256 ptsr=MEDFileParameterMultiTS(fname)
2257 self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2258 p1tsr=MEDFileParameterDouble1TS(fname)
2259 self.assertEqual(p1tsr.getName(),"A")
2260 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2261 p1tsr=MEDFileParameterDouble1TS(fname,"B")
2262 self.assertEqual(p1tsr.getName(),"B")
2263 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2264 p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2265 self.assertEqual(p1tsr.getName(),"B")
2266 self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2267 data2=MEDFileData(fname)
2268 self.assertEqual(2,data2.getNumberOfParams())
2269 self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2272 def testNamesOnCellAndNodesInMeshes1(self):
2273 fname="Pyfile58.med"
2274 fname2="Pyfile59.med"
2275 m=MEDLoaderDataForTest.build3DSurfMesh_1()
2276 m1=m.buildDescendingConnectivity()[0]
2277 m1.sortCellsInMEDFileFrmt()
2280 mm.setMeshAtLevel(0,m)
2281 mm.setMeshAtLevel(-1,m1)
2282 namesCellL0=DataArrayAsciiChar(6,16)
2283 namesCellL0[:] = ["CellL0#%.3d " % (i) for i in range(6)]
2284 mm.setNameFieldAtLevel(0,namesCellL0)
2285 namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.subArray(2)])
2286 namesCellL1[:] = ["CellLM1#%.3d " % (i) for i in range(16)]
2287 mm.setNameFieldAtLevel(-1,namesCellL1)
2288 namesNodes=namesCellL1.subArray(4,16)
2289 namesNodes[:] = ["Node#%.3d " % (i) for i in range(12)]
2290 mm.setNameFieldAtLevel(1,namesNodes)
2293 mmr=MEDFileMesh.New(fname)
2294 self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
2295 self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d " % (i) for i in range(16)])))
2296 self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(12)])))
2297 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2298 mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2299 self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2300 mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2301 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2303 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2304 # remove names on nodes
2305 mmCpy.setNameFieldAtLevel(1,None)
2306 self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2307 mm.setNameFieldAtLevel(1,None)
2308 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2309 mm.setNameFieldAtLevel(-1,None)
2311 mmr=MEDFileMesh.New(fname)
2312 self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2313 self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
2314 self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2316 c=MEDCouplingCMesh()
2317 arr=DataArrayDouble([0.,1.1,2.3])
2318 c.setCoords(arr,arr)
2322 cc.setNameFieldAtLevel(0, DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)]))
2323 cc.setNameFieldAtLevel(1, DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)]))
2325 ccr=MEDFileMesh.New(fname2)
2326 self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)])))
2327 self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)])))
2328 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2329 ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2330 self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2331 ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2332 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2334 self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2337 def testToExportInExamples1(self):
2338 m=MEDCouplingCMesh()
2339 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2340 m.setCoords(arr,arr)
2341 m=m.buildUnstructured() ; m.setName("mesh")
2342 grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2343 grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2346 mm.setMeshAtLevel(0,m)
2347 mm.setMeshAtLevel(-1,m2)
2348 mm.setGroupsAtLevel(0,[grp1,grp2])
2349 mm.write("example.med",2)
2351 m0=mm.getMeshAtLevel(0)
2352 m1=mm.getMeshAtLevel(-1)
2353 grp1=mm.getGroupArr(0,"grp1")
2354 grp2=mm.getGroupArr(0,"grp2")
2356 whichGrp=DataArrayInt(m0.getNumberOfCells())
2357 whichGrp.fillWithValue(-1)
2358 for grpId,grp in enumerate(grps):
2361 a,b,bI,c,cI=m0.buildDescendingConnectivity()
2362 e,f=a.areCellsIncludedIn(m1,2)
2364 c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2365 self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2366 c2.transformWithIndArr(whichGrp)
2367 splitOfM1=len(grps)*[None]
2368 for grpId,grp in enumerate(grps):
2369 tmp=c2.findIdsEqual(grpId)
2370 splitOfM1[grpId]=tmp
2372 splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2373 splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2376 def testBugCorrection1(self):
2379 self.assertEqual(fs[0],None)
2380 self.assertEqual(3,len(fs))
2383 def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2384 f1Name="Pyfile60.med"
2385 f2Name="Pyfile61.med"
2386 d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2388 d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2390 # reading and compare
2391 d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2392 for mn in d1.getMeshes().getMeshesNames():
2393 m1=d1.getMeshes()[mn]
2394 m2=d2.getMeshes()[mn]
2395 for lev in m1.getNonEmptyLevels():
2396 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2397 for grpName in grpsNames:
2398 self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2402 for fieldn in d1.getFields().getFieldsNames():
2403 f1=d1.getFields()[fieldn]
2404 f2=d2.getFields()[fieldn]
2405 for it,order,tim in f1.getTimeSteps():
2408 if len(f1t.getPflsReallyUsed())!=0:
2410 for lev in f1t.getNonEmptyLevels()[1]:
2411 arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2412 arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2413 self.assertTrue(pfl1.isEqual(pfl2))
2414 self.assertTrue(arr1.isEqual(arr2,1e-10))
2419 for lev in f1t.getNonEmptyLevels()[1]:
2420 f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2421 f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2422 self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2429 def testNonRegBugNormalizeFamIdsMEDFile1(self):
2430 m=MEDCouplingCMesh()
2431 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2432 m.setCoords(arr,arr,arr)
2433 m=m.buildUnstructured()
2434 m2=m.buildDescendingConnectivity()[0]
2436 g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2437 g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2438 g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2439 g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2440 g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2441 g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2443 mm.setMeshAtLevel(0,m)
2444 mm.setGroupsAtLevel(0,[g1,g2])
2445 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2446 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2447 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2448 mm.normalizeFamIdsMEDFile()
2449 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2450 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2451 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2452 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2453 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2454 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2455 for g in mm.getGroupsOnSpecifiedLev(0):
2456 for f in mm.getFamiliesIdsOnGroup(g):
2457 self.assertTrue(f<0)
2462 mm.setMeshAtLevel(0,m)
2463 mm.setMeshAtLevel(-1,m2)
2464 mm.setGroupsAtLevel(0,[g1,g2])
2465 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2466 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2467 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2468 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2469 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2470 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2471 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2472 mm.normalizeFamIdsMEDFile()
2473 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2474 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2475 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2476 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2477 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2478 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2479 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2480 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2481 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2482 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2483 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2484 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2486 for g in mm.getGroupsOnSpecifiedLev(lev):
2487 for f in mm.getFamiliesIdsOnGroup(g):
2488 self.assertTrue(f<0)
2494 mm.setMeshAtLevel(0,m)
2495 mm.setMeshAtLevel(-1,m2)
2496 mm.setGroupsAtLevel(0,[g1,g2])
2497 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2498 mm.setGroupsAtLevel(1,[g1Node,g2Node])
2499 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2500 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2501 s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2502 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2503 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2504 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2505 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2506 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2507 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2508 mm.normalizeFamIdsMEDFile()
2509 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2510 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2511 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2512 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2513 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2514 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2515 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2516 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2517 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2518 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2519 self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2520 self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2521 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2522 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2523 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2524 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2525 self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2526 self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2528 for g in mm.getGroupsOnSpecifiedLev(lev):
2529 for f in mm.getFamiliesIdsOnGroup(g):
2530 self.assertTrue(f<0)
2534 for g in mm.getGroupsOnSpecifiedLev(1):
2535 for f in mm.getFamiliesIdsOnGroup(g):
2536 self.assertTrue(f>0)
2541 def testNonRegressionMantis22212ChangeGrpName(self):
2542 fileName="Pyfile62.med"
2543 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2544 m=MEDFileUMesh.New()
2545 m.setCoords(m2.getCoords())
2546 m.setMeshAtLevel(0,m2)
2547 m.setMeshAtLevel(-1,m1)
2548 m.setMeshAtLevel(-2,m0)
2549 m.setFamilyFieldArr(0,f2)
2550 m.setFamilyFieldArr(-1,f1)
2551 m.setFamilyFieldArr(-2,f0)
2552 m.setFamilyFieldArr(1,p)
2554 for i in range(nbOfFams):
2555 m.addFamily(fns[i],fids[i])
2558 for i in range(nbOfGrps):
2559 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2561 m.setName(m2.getName())
2562 m.setDescription(m2.getDescription())
2565 mm0=MEDFileMesh.New(fileName)
2566 mm1=MEDFileMesh.New(fileName)
2567 groupNamesIni=GetMeshGroupsNames(fileName,"ma")
2568 for name in groupNamesIni:
2569 mm1.changeGroupName(name,name+'N')
2571 mm1.write(fileName,2)
2574 mm2=MEDFileMesh.New(fileName)
2575 for name in groupNamesIni:
2576 for lev in mm0.getGrpNonEmptyLevelsExt(name):
2577 arr0=mm0.getGroupArr(lev,name)
2578 arr2=mm2.getGroupArr(lev,name+'N')
2579 arr0.setName(name+'N')
2580 self.assertTrue(arr0.isEqual(arr2))
2585 def testInt32InMEDFileFieldStar1(self):
2586 fname="Pyfile63.med"
2587 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2588 f1=f1.convertToIntField()
2590 mm1=MEDFileUMesh.New()
2591 mm1.setCoords(m1.getCoords())
2592 mm1.setMeshAtLevel(0,m1)
2593 mm1.setName(m1.getName())
2595 ff1=MEDFileIntField1TS()
2596 ff1.setFieldNoProfileSBT(f1)
2597 a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2598 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2599 self.assertTrue(a.isEqual(f1,1e-12,0))
2601 ff2=MEDFileAnyTypeField1TS.New(fname)
2602 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2603 self.assertEqual(ff2.getTime(),[0,1,2.0])
2604 self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2605 a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2606 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2607 self.assertTrue(a.isEqual(f1,1e-12,0))
2609 c=ff2.getUndergroundDataArray() ; c*=2
2610 ff2.write(fname,0) # 2 time steps in
2611 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2612 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2613 self.assertEqual(len(ffs1),2)
2614 self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2615 a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2616 self.assertTrue(a.isEqual(f1,1e-12,0))
2617 a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
2618 self.assertTrue(a.isEqual(f1,1e-12,0))
2619 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2620 a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2621 self.assertTrue(a.getArray().isEqual(2*f1.getArray()))
2622 f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
2623 self.assertTrue(a.isEqual(f1,1e-12,0)) ; f1.getArray()[:]/=2
2624 bc=DataArrayInt(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2626 a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2629 self.assertTrue(bc.isEqual(3*f1.getArray()))
2630 nf1=MEDCouplingFieldInt(ON_NODES)
2631 nf1.setTime(9.,10,-1)
2632 nf1.setMesh(f1.getMesh())
2633 narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
2634 nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
2635 nff1=MEDFileIntField1TS.New()
2636 nff1.setFieldNoProfileSBT(nf1)
2637 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2638 self.assertEqual(nff1.getTime(),[10,-1,9.0])
2641 nf2=MEDCouplingFieldInt(ON_NODES)
2642 nf2.setTime(19.,20,-11)
2643 nf2.setMesh(f1.getMesh())
2644 narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
2645 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
2646 nff2=MEDFileIntField1TS.New()
2647 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
2648 nff2.setFieldProfile(nf2,mm1,0,npfl)
2649 nff2.getFieldWithProfile(ON_NODES,0,mm1)
2650 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2651 self.assertTrue(b.isEqual(npfl))
2652 self.assertTrue(a.isEqual(narr2))
2654 nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
2655 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2656 self.assertTrue(b.isEqual(npfl))
2657 self.assertTrue(a.isEqual(narr2))
2659 nf3=MEDCouplingFieldDouble(ON_NODES)
2660 nf3.setName("VectorFieldOnNodesDouble")
2661 nf3.setTime(29.,30,-21)
2662 nf3.setMesh(f1.getMesh())
2663 nf3.setArray(f1.getMesh().getCoords())
2664 nff3=MEDFileField1TS.New()
2665 nff3.setFieldNoProfileSBT(nf3)
2667 fs=MEDFileFields(fname)
2668 self.assertEqual(len(fs),4)
2669 ffs=[it for it in fs]
2670 self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
2671 self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
2672 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
2673 self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
2675 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray()))
2676 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray()))
2677 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
2678 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
2679 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2681 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
2682 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2683 self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
2684 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
2685 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
2686 self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
2687 MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
2688 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
2690 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
2691 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2692 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
2693 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2696 def testMEDFileFields1(self):
2697 fname="Pyfile64.med"
2698 f1=MEDCouplingFieldDouble(ON_NODES)
2699 f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
2700 c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
2701 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
2703 arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=list(range(12)) ; arr[:,1]=2*arr[:,0]
2705 f1.setName("Field1")
2706 ff1=MEDFileField1TS.New()
2707 ff1.setFieldNoProfileSBT(f1)
2708 self.assertEqual(ff1.getDtUnit(),"us")
2710 f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2711 f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2713 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2714 ff1s=MEDFileFieldMultiTS(fname,"Field1")
2715 ff1s.setName("Field2")
2717 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2718 f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2719 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
2720 self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
2721 self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
2722 f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2723 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
2724 self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
2727 # Multi time steps and multi fields management without Globals (profiles, locs) aspects
2728 def testMEDFileFields2(self):
2729 fname="Pyfile65.med"
2730 # to check that all is initialize
2731 MEDFileField1TS().__str__()
2732 MEDFileFieldMultiTS().__str__()
2733 # building a mesh containing 4 tri3 + 5 quad4
2734 tri=MEDCouplingUMesh("tri",2)
2735 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2736 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2737 tris = [tri.deepCopy() for i in range(4)]
2738 for i,elt in enumerate(tris): elt.translate([i,0])
2739 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2740 quad=MEDCouplingUMesh("quad",2)
2741 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2742 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2743 quads = [quad.deepCopy() for i in range(5)]
2744 for i,elt in enumerate(quads): elt.translate([5+i,0])
2745 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2746 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2747 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2749 fmts0_0=MEDFileFieldMultiTS()
2750 fmts0_1=MEDFileFieldMultiTS()
2753 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2754 d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2755 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2756 f.setTime(float(i+1)+0.1,i+1,-i-1)
2757 fmts0_0.appendFieldNoProfileSBT(f)
2758 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
2759 self.assertEqual(fmts0_1.getName(),name1)
2760 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2761 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2763 # components names have been modified to generate errors
2764 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
2765 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
2766 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
2767 f1ts.setInfo(['aa [bb]','eee [dd]'])
2768 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
2770 # add a mismatch of nb of compos
2772 fmts0_2=fmts0_0.deepCopy()
2773 fmts0_3=fmts0_0.deepCopy()
2774 fmts0_4=fmts0_0.deepCopy()
2775 fmts0_5=fmts0_0.shallowCpy()
2776 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)
2778 self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
2779 del fmts0_3[[1.1,(6,-6),9]]
2780 self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
2781 fmts0_6=fmts0_4[[1.1,(6,-6),8]]
2782 self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
2783 self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
2784 fmts0_7=fmts0_4[::-3]
2785 self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
2786 self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
2789 fs0.pushField(fmts0_0)
2790 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2791 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2792 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2793 self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
2795 fs0=MEDFileFields(fname)
2796 self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
2797 fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
2798 self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2799 del fs1[["2ndField",3]]
2800 self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2801 fs2=fs0[[0,"4thField"]]
2802 self.assertTrue(isinstance(fs2,MEDFileFields))
2803 self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
2805 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
2808 # Multi time steps and multi fields management with Globals (profiles, locs) aspects
2809 def testMEDFileFields3(self):
2810 fname="Pyfile66.med"
2811 # building a mesh containing 4 tri3 + 5 quad4
2812 tri=MEDCouplingUMesh("tri",2)
2813 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2814 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2815 tris = [tri.deepCopy() for i in range(4)]
2816 for i,elt in enumerate(tris): elt.translate([i,0])
2817 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2818 quad=MEDCouplingUMesh("quad",2)
2819 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2820 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2821 quads = [quad.deepCopy() for i in range(5)]
2822 for i,elt in enumerate(quads): elt.translate([5+i,0])
2823 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2824 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2825 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2827 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2829 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2830 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2831 fmts0_0=MEDFileFieldMultiTS()
2832 fmts0_1=MEDFileFieldMultiTS()
2835 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2836 d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2837 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2838 f.setTime(float(i+1)+0.1,i+1,-i-1)
2839 fmts0_0.appendFieldProfile(f,mm,0,pfl)
2840 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2841 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2842 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2845 self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
2846 self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
2847 fmts0_0.zipPflsNames()
2848 self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
2849 self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
2850 fmts0_2=fmts0_0.deepCopy()
2851 fmts0_3=fmts0_0.deepCopy()
2852 fmts0_4=fmts0_0.deepCopy()
2854 fs0.pushField(fmts0_0)
2855 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2856 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2857 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2858 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
2860 fmts0_5=MEDFileFieldMultiTS()
2862 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2863 d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2864 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2865 f.setTime(float(i+1)+0.1,i+1,-i-1)
2866 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
2868 fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
2869 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
2870 fs0.checkGlobsCoherency()
2874 def testSplitComponents1(self):
2875 fname="Pyfile67.med"
2876 # building a mesh containing 4 tri3 + 5 quad4
2877 tri=MEDCouplingUMesh("tri",2)
2878 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2879 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2880 tris = [tri.deepCopy() for i in range(4)]
2881 for i,elt in enumerate(tris): elt.translate([i,0])
2882 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2883 quad=MEDCouplingUMesh("quad",2)
2884 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2885 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2886 quads = [quad.deepCopy() for i in range(5)]
2887 for i,elt in enumerate(quads): elt.translate([5+i,0])
2888 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2889 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2890 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2892 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2894 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2895 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2897 fmts0_1=MEDFileFieldMultiTS()
2899 infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
2902 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2903 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2904 f.setTime(float(i+1)+0.1,i+1,-i-1)
2905 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2906 self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
2908 fs.pushField(fmts0_1)
2909 self.assertEqual(1,len(fs))
2910 l=fmts0_1.splitComponents()
2911 self.assertEqual(3,len(l))
2912 for elt in l: self.assertEqual(10,len(elt))
2913 for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
2915 elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
2918 self.assertEqual(4,len(fs))
2919 for elt in fs: self.assertEqual(10,len(elt))
2920 self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
2921 self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2923 fs.write(fname,0) ; del fs
2925 fs1=MEDFileFields(fname)
2926 self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
2927 self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
2928 self.assertEqual(4,len(fs1))
2930 for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
2931 f1ts=fs1[fieldName][i]
2932 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2933 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
2934 self.assertTrue(d.isEqual(f.getArray(),1e-13))
2936 f1ts=fs1["1stField"][i]
2937 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
2938 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
2939 self.assertTrue(d.isEqual(f.getArray(),1e-13))
2943 def testMEDFileFieldConvertTo1(self):
2944 fname="Pyfile68.med"
2945 # building a mesh containing 4 tri3 + 5 quad4
2946 tri=MEDCouplingUMesh("tri",2)
2947 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2948 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2949 tris = [tri.deepCopy() for i in range(4)]
2950 for i,elt in enumerate(tris): elt.translate([i,0])
2951 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2952 quad=MEDCouplingUMesh("quad",2)
2953 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2954 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2955 quads = [quad.deepCopy() for i in range(5)]
2956 for i,elt in enumerate(quads): elt.translate([5+i,0])
2957 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2958 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2959 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2960 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
2962 ff0=MEDFileField1TS()
2963 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")
2964 f0.checkConsistencyLight()
2965 ff0.setFieldNoProfileSBT(f0)
2967 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
2968 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2970 ff0i=ff0.convertToInt()
2971 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
2972 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
2974 ff1=ff0i.convertToDouble()
2975 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
2976 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
2978 del arr,f0,ff0,ff1,ff0i,fspExp
2979 ff0=MEDFileField1TS()
2980 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")
2981 f0.checkConsistencyLight()
2982 pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
2983 ff0.setFieldProfile(f0,mm,0,pfl)
2984 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
2985 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
2987 ff0i=ff0.convertToInt()
2988 self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
2989 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
2990 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
2992 ff1=ff0i.convertToDouble()
2993 self.assertTrue(isinstance(ff1,MEDFileField1TS))
2994 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
2995 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
2997 ff0=MEDFileFieldMultiTS()
2998 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)
2999 f0.checkConsistencyLight()
3000 ff0.appendFieldProfile(f0,mm,0,pfl)
3001 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)
3002 f0.checkConsistencyLight()
3003 ff0.appendFieldProfile(f0,mm,0,pfl)
3004 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)
3005 f0.checkConsistencyLight()
3006 ff0.appendFieldProfile(f0,mm,0,pfl)
3007 ff1=ff0.convertToInt()
3008 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3009 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3010 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3011 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3012 arr=ff1.getUndergroundDataArray(dt,it)
3013 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
3015 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3020 ff1=ff1.convertToDouble()
3021 self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
3022 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3023 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3024 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3025 arr=ff1.getUndergroundDataArray(dt,it)
3026 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
3028 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3030 ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
3031 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3032 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3033 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3034 self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
3035 arr=ff1.getUndergroundDataArray(dt,it)
3036 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
3038 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
3041 def testMEDFileFieldPartialLoading(self):
3042 fname="Pyfile69.med"
3044 a=DataArrayInt() ; aa=a.getHeapMemorySize()
3046 strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
3047 # building a mesh containing 30 tri3 + 40 quad4
3048 tri=MEDCouplingUMesh("tri",2)
3049 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3050 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3051 tris = [tri.deepCopy() for i in range(30)]
3052 for i,elt in enumerate(tris): elt.translate([i,0])
3053 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3054 quad=MEDCouplingUMesh("quad",2)
3055 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3056 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3057 quads = [quad.deepCopy() for i in range(40)]
3058 for i,elt in enumerate(quads): elt.translate([40+i,0])
3059 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3060 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3061 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3062 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3064 ff0=MEDFileField1TS()
3065 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")
3066 f0.checkConsistencyLight()
3067 ff0.setFieldNoProfileSBT(f0)
3070 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
3071 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3073 ff0=MEDFileField1TS()
3074 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")
3075 f0.checkConsistencyLight()
3076 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
3077 ff0.setFieldProfile(f0,mm,0,pfl)
3078 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
3079 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3082 ff0=MEDFileField1TS(fname,False)
3083 self.assertEqual(ff0.getName(),"FieldCell")
3084 self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
3085 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
3086 heap_memory_ref=ff0.getHeapMemorySize()
3087 self.assertIn(heap_memory_ref, list(range(182, 540 + 2 * strMulFac)))
3089 arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
3090 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3091 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
3093 ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
3094 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
3095 heap_memory_ref=ff0.getHeapMemorySize()
3096 self.assertIn(heap_memory_ref, list(range(350, 600 + 6 * strMulFac)))
3098 arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
3099 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3100 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3102 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3103 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3104 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3105 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3107 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3108 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3109 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3110 ff0.loadArraysIfNecessary() ##
3111 self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
3112 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3113 heap_memory_ref=ff0.getHeapMemorySize()
3114 self.assertIn(heap_memory_ref, list(range(1100, 1400 + 2 * strMulFac)))
3116 hmd=ff0.getHeapMemorySize()-heap_memory_ref
3117 self.assertEqual(hmd,-800) # -50*8*2
3119 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
3121 ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
3122 heap_memory_ref=ff0.getHeapMemorySize()
3123 self.assertIn(heap_memory_ref, list(range(299, 620 + 6 * strMulFac)))
3125 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3126 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3128 fieldName="FieldCellMultiTS"
3129 ff0=MEDFileFieldMultiTS()
3131 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)
3132 f0.setTime(float(t)+0.1,t,100+t)
3133 f0.checkConsistencyLight()
3134 ff0.appendFieldNoProfileSBT(f0)
3138 ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
3139 heap_memory_ref=ff0.getHeapMemorySize()
3140 self.assertIn(heap_memory_ref, list(range(5536, 9212 + (80 + 26 + 1) * strMulFac)))
3142 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
3145 ffs=MEDFileFields(fname,False)
3146 heap_memory_ref=ffs.getHeapMemorySize()
3147 self.assertIn(heap_memory_ref, list(range(5335, 10031 + (80 + 50 + len(ffs)) * strMulFac)))
3149 self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
3152 def testMEDFileMeshReadSelector1(self):
3153 mrs=MEDFileMeshReadSelector()
3154 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3155 mrs.__str__() ; mrs.__repr__()
3157 mrs=MEDFileMeshReadSelector(0)
3158 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())
3159 mrs=MEDFileMeshReadSelector(1)
3160 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3161 mrs=MEDFileMeshReadSelector(2)
3162 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3163 mrs=MEDFileMeshReadSelector(3)
3164 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3165 mrs=MEDFileMeshReadSelector(4)
3166 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3167 mrs=MEDFileMeshReadSelector(5)
3168 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3169 mrs=MEDFileMeshReadSelector(6)
3170 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3171 mrs=MEDFileMeshReadSelector(7)
3172 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3173 mrs=MEDFileMeshReadSelector(8)
3174 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3175 mrs=MEDFileMeshReadSelector(9)
3176 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3177 mrs=MEDFileMeshReadSelector(10)
3178 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3179 mrs=MEDFileMeshReadSelector(11)
3180 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3181 mrs=MEDFileMeshReadSelector(12)
3182 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3183 mrs=MEDFileMeshReadSelector(13)
3184 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3185 mrs=MEDFileMeshReadSelector(14)
3186 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3187 mrs=MEDFileMeshReadSelector(15)
3188 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3189 mrs=MEDFileMeshReadSelector(16)
3190 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3191 mrs=MEDFileMeshReadSelector(17)
3192 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3193 mrs=MEDFileMeshReadSelector(18)
3194 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3195 mrs=MEDFileMeshReadSelector(19)
3196 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3197 mrs=MEDFileMeshReadSelector(20)
3198 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3199 mrs=MEDFileMeshReadSelector(21)
3200 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3201 mrs=MEDFileMeshReadSelector(22)
3202 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3203 mrs=MEDFileMeshReadSelector(23)
3204 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3205 mrs=MEDFileMeshReadSelector(24)
3206 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3207 mrs=MEDFileMeshReadSelector(25)
3208 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3209 mrs=MEDFileMeshReadSelector(26)
3210 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3211 mrs=MEDFileMeshReadSelector(27)
3212 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3213 mrs=MEDFileMeshReadSelector(28)
3214 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3215 mrs=MEDFileMeshReadSelector(29)
3216 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3217 mrs=MEDFileMeshReadSelector(30)
3218 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3219 mrs=MEDFileMeshReadSelector(31)
3220 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3221 mrs=MEDFileMeshReadSelector(32)
3222 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3223 mrs=MEDFileMeshReadSelector(33)
3224 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3225 mrs=MEDFileMeshReadSelector(34)
3226 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3227 mrs=MEDFileMeshReadSelector(35)
3228 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3229 mrs=MEDFileMeshReadSelector(36)
3230 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3231 mrs=MEDFileMeshReadSelector(37)
3232 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3233 mrs=MEDFileMeshReadSelector(38)
3234 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3235 mrs=MEDFileMeshReadSelector(39)
3236 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3237 mrs=MEDFileMeshReadSelector(40)
3238 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3239 mrs=MEDFileMeshReadSelector(41)
3240 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3241 mrs=MEDFileMeshReadSelector(42)
3242 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3243 mrs=MEDFileMeshReadSelector(43)
3244 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3245 mrs=MEDFileMeshReadSelector(44)
3246 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3247 mrs=MEDFileMeshReadSelector(45)
3248 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3249 mrs=MEDFileMeshReadSelector(46)
3250 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3251 mrs=MEDFileMeshReadSelector(47)
3252 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3253 mrs=MEDFileMeshReadSelector(48)
3254 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3255 mrs=MEDFileMeshReadSelector(49)
3256 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3257 mrs=MEDFileMeshReadSelector(50)
3258 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3259 mrs=MEDFileMeshReadSelector(51)
3260 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3261 mrs=MEDFileMeshReadSelector(52)
3262 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3263 mrs=MEDFileMeshReadSelector(53)
3264 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3265 mrs=MEDFileMeshReadSelector(54)
3266 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3267 mrs=MEDFileMeshReadSelector(55)
3268 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3269 mrs=MEDFileMeshReadSelector(56)
3270 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3271 mrs=MEDFileMeshReadSelector(57)
3272 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3273 mrs=MEDFileMeshReadSelector(58)
3274 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3275 mrs=MEDFileMeshReadSelector(59)
3276 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3277 mrs=MEDFileMeshReadSelector(60)
3278 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3279 mrs=MEDFileMeshReadSelector(61)
3280 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3281 mrs=MEDFileMeshReadSelector(62)
3282 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3283 mrs=MEDFileMeshReadSelector(63)
3284 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3286 mrs=MEDFileMeshReadSelector(63)
3287 mrs.setCellFamilyFieldReading(False)
3288 self.assertEqual(mrs.getCode(),62)
3289 mrs.setCellFamilyFieldReading(True)
3290 self.assertEqual(mrs.getCode(),63)
3291 mrs.setNodeFamilyFieldReading(False)
3292 self.assertEqual(mrs.getCode(),61)
3293 mrs.setNodeFamilyFieldReading(True)
3294 self.assertEqual(mrs.getCode(),63)
3295 mrs.setCellNameFieldReading(False)
3296 self.assertEqual(mrs.getCode(),59)
3297 mrs.setCellNameFieldReading(True)
3298 self.assertEqual(mrs.getCode(),63)
3299 mrs.setNodeNameFieldReading(False)
3300 self.assertEqual(mrs.getCode(),55)
3301 mrs.setNodeNameFieldReading(True)
3302 self.assertEqual(mrs.getCode(),63)
3303 mrs.setCellNumFieldReading(False)
3304 self.assertEqual(mrs.getCode(),47)
3305 mrs.setCellNumFieldReading(True)
3306 self.assertEqual(mrs.getCode(),63)
3307 mrs.setNodeNumFieldReading(False)
3308 self.assertEqual(mrs.getCode(),31)
3309 mrs.setNodeNumFieldReading(True)
3310 self.assertEqual(mrs.getCode(),63)
3313 def testPartialReadOfMeshes(self):
3314 fname="Pyfile70.med"
3315 # building a mesh containing 4 tri3 + 5 quad4
3316 tri=MEDCouplingUMesh("tri",2)
3317 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3318 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3319 tris = [tri.deepCopy() for i in range(4)]
3320 for i,elt in enumerate(tris): elt.translate([i,0])
3321 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3322 quad=MEDCouplingUMesh("quad",2)
3323 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3324 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3325 quads = [quad.deepCopy() for i in range(5)]
3326 for i,elt in enumerate(quads): elt.translate([5+i,0])
3327 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3328 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3329 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3330 m1=m.buildDescendingConnectivity()[0]
3331 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3333 grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3334 grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3335 mm.setGroupsAtLevel(0,[grp0,grp1])
3336 grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3337 grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3338 mm.setGroupsAtLevel(-1,[grp2,grp3])
3339 grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3340 grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3341 mm.setGroupsAtLevel(1,[grp4,grp5])
3342 mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3343 mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3344 mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3348 mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3349 b4_ref_heap_mem=mm.getHeapMemorySize()
3350 mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
3351 mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
3352 ref_heap_mem=mm.getHeapMemorySize()
3353 # check the gain of memory using 1GTUMesh instead of UMesh
3354 self.assertTrue(ref_heap_mem-b4_ref_heap_mem>=(32+9)*4*2-32)# 32+9=nbCells 4=sizeof(int) 2=the types+index -32=loss linked to vector
3356 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3357 self.assertEqual(len(mm.getGroupsNames()),0)
3358 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3359 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3360 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3361 self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3362 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3363 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3364 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3365 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3366 delta1=ref_heap_mem-mm.getHeapMemorySize()
3367 self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3369 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3370 self.assertEqual(len(mm.getGroupsNames()),6)
3371 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3372 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3373 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3374 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3375 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3376 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3377 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3378 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3379 delta2=ref_heap_mem-mm.getHeapMemorySize()
3380 self.assertTrue(delta2<delta1)
3381 self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3383 mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3384 self.assertEqual(len(mm.getGroupsNames()),6)
3385 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3386 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3387 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3388 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3389 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3390 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3391 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3392 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3393 delta3=ref_heap_mem-mm.getHeapMemorySize()
3394 self.assertTrue(delta3<delta2)
3395 self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3397 mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3398 self.assertEqual(len(mm.getGroupsNames()),6)
3399 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3400 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3401 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3402 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3403 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3404 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3405 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3406 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3407 delta4=ref_heap_mem-mm.getHeapMemorySize()
3408 self.assertTrue(delta4<delta3)
3409 self.assertTrue(delta4>=32*4*2)
3411 mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3412 self.assertEqual(len(mm.getGroupsNames()),6)
3413 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3414 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3415 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3416 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3417 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3418 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3419 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3420 self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3421 delta5=ref_heap_mem-mm.getHeapMemorySize()
3422 self.assertTrue(delta5<delta4)
3423 self.assertEqual(delta5,0)
3426 # this test checks that setFieldProfile perform a check of the array length
3427 # compared to the profile length. This test also checks that mesh attribute of field
3428 # is not used by setFieldProfile (because across this test mesh is equal to None)
3429 def testCheckCompatibilityPfl1(self):
3430 # building a mesh containing 4 tri3 + 5 quad4
3431 tri=MEDCouplingUMesh("tri",2)
3432 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3433 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3434 tris = [tri.deepCopy() for i in range(4)]
3435 for i,elt in enumerate(tris): elt.translate([i,0])
3436 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3437 quad=MEDCouplingUMesh("quad",2)
3438 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3439 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3440 quads = [quad.deepCopy() for i in range(5)]
3441 for i,elt in enumerate(quads): elt.translate([5+i,0])
3442 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3443 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3444 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3445 m1=m.buildDescendingConnectivity()[0]
3446 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3448 f1ts=MEDFileField1TS()
3449 f=MEDCouplingFieldDouble(ON_NODES)
3450 vals=DataArrayDouble(7) ; vals.iota(1000)
3452 f.setName("anonymous") # f has no mesh it is not a bug
3453 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3454 f1ts.setFieldProfile(f,mm,0,pfl)
3456 f1ts=MEDFileField1TS()
3457 f=MEDCouplingFieldDouble(ON_NODES)
3458 vals=DataArrayDouble(8) ; vals.iota(1000)
3460 f.setName("anonymous") # f has no mesh it is not a bug
3461 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3462 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3464 f1ts=MEDFileField1TS()
3465 f=MEDCouplingFieldDouble(ON_CELLS)
3466 vals=DataArrayDouble(7) ; vals.iota(1000)
3468 f.setName("anonymous") # f has no mesh it is not a bug
3469 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3470 f1ts.setFieldProfile(f,mm,0,pfl)
3471 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3473 f1ts=MEDFileField1TS()
3474 f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3475 vals=DataArrayDouble(27) ; vals.iota(1000)
3477 f.setName("anonymous") # f has no mesh it is not a bug
3478 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3480 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])
3481 f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3482 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])
3484 f1ts.setFieldProfile(f,mm,0,pfl)
3485 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3486 vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3487 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3488 vals=DataArrayDouble(27) ; vals.iota(1000)
3489 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3491 f1ts=MEDFileField1TS()
3492 f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3493 vals=DataArrayDouble(25) ; vals.iota(1000)
3495 f.setName("anonymous") # f has no mesh it is not a bug
3496 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3497 f1ts.setFieldProfile(f,mm,0,pfl)
3498 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3499 vals2=DataArrayDouble(26) ; vals2.iota(1050)
3501 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3502 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3504 f1ts=MEDFileField1TS()
3505 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3506 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3508 f1ts.setFieldProfile(f,mm,0,pfl)
3511 def testWRMeshWithNoCells(self):
3512 fname="Pyfile71.med"
3513 a=DataArrayDouble(4) ; a.iota()
3514 c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
3515 m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
3517 m.setMeshAtLevel(0,m00)
3518 m.setRenumFieldArr(1,DataArrayInt(list(range(10,26))))
3519 m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
3523 m=MEDFileMesh.New(fname)
3524 self.assertEqual((),m.getNonEmptyLevels())
3525 self.assertTrue(m.getCoords().isEqual(DataArrayDouble([(0,0),(1,0),(2,0),(3,0),(0,1),(1,1),(2,1),(3,1),(0,2),(1,2),(2,2),(3,2),(0,3),(1,3),(2,3),(3,3)]),1e-12))
3526 self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(list(range(10,26)))))
3527 self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
3530 def testWRQPolyg1(self):
3531 fname="Pyfile72.med"
3532 m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
3533 m.insertNextCell([0,2,1,3])
3534 m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
3536 ms = [m.deepCopy() for i in range(4)]
3537 for i,elt in enumerate(ms):
3538 elt.translate([float(i)*1.5,0.])
3540 m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3541 m0.convertAllToPoly()
3543 ms = [m.deepCopy() for i in range(5)]
3544 for i,elt in enumerate(ms):
3545 elt.translate([float(i)*1.5,1.5])
3547 m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3548 m1.convertAllToPoly()
3549 m1.convertLinearCellsToQuadratic()
3551 m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
3554 mm.setMeshAtLevel(0,m)
3555 grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
3556 grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
3557 grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
3558 mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3563 mm_read=MEDFileUMesh(fname)
3564 self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
3565 self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
3566 self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
3567 self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
3569 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
3571 arr0=DataArrayDouble(9) ; arr0.iota()
3572 arr1=DataArrayDouble(9) ; arr1.iota(100)
3573 arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
3574 f.setArray(arr) ; f.checkConsistencyLight()
3576 ff=MEDFileField1TS()
3577 ff.setFieldNoProfileSBT(f)
3580 ff_read=MEDFileField1TS(fname)
3581 f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
3582 self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
3585 def testLoadIfNecessaryOnFromScratchFields0(self):
3587 This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
3589 fname="Pyfile77.med"
3590 coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
3591 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
3593 m.insertNextCell(NORM_QUAD4,[0,5,3,2])
3594 m.insertNextCell(NORM_QUAD4,[4,2,3,1])
3595 m.finishInsertingCells()
3597 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3598 ms=MEDFileMeshes() ; ms.pushMesh(mm)
3602 ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
3603 f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
3605 f0.setName("myELNOField")
3606 arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
3607 f0.setArray(arrs[0])
3608 ff0.appendFieldNoProfileSBT(f0)
3611 arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
3612 f0.setArray(arrs[1])
3613 ff0.appendFieldNoProfileSBT(f0)
3616 arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
3617 f0.setArray(arrs[2])
3618 ff0.appendFieldNoProfileSBT(f0)
3621 arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
3622 f0.setArray(arrs[3])
3623 ff0.appendFieldNoProfileSBT(f0)
3625 for i,arr in enumerate(arrs):
3626 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3627 fs[0][i].loadArraysIfNecessary()
3628 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3630 fs.loadArraysIfNecessary()
3631 for i,arr in enumerate(arrs):
3632 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3634 fs[0].loadArraysIfNecessary()
3635 for i,arr in enumerate(arrs):
3636 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3640 def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
3641 """ This test is very important, because the same mechanism is used by the MEDReader to generate a field on all the mesh without any processing and memory.
3643 fname="Pyfile78.med"
3644 coords=DataArrayDouble([-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ],9,3)
3645 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3646 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
3648 for elt in [[0,1,2,3],[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7],[5,6,7,8]]:#6
3649 m0.insertNextCell(NORM_TETRA4,elt)
3651 for elt in [[0,1,2,3,4],[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7],[4,5,6,7,8]]:#5
3652 m0.insertNextCell(NORM_PYRA5,elt)
3654 for elt in [[0,1,2,3,4,5],[1,2,3,4,5,6],[2,3,4,5,6,7],[3,4,5,6,7,8]]:#4
3655 m0.insertNextCell(NORM_PENTA6,elt)
3657 m0.checkConsistency()
3658 m1=MEDCouplingUMesh(); m1.setName("mesh")
3659 m1.setMeshDimension(2);
3660 m1.allocateCells(5);
3661 m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3662 m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3663 m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3664 m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3665 m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3666 m1.setCoords(coords);
3667 m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
3669 m3.insertNextCell(NORM_POINT1,[2])
3670 m3.insertNextCell(NORM_POINT1,[3])
3671 m3.insertNextCell(NORM_POINT1,[4])
3672 m3.insertNextCell(NORM_POINT1,[5])
3675 mm.setMeshAtLevel(0,m0)
3676 mm.setMeshAtLevel(-1,m1)
3677 mm.setMeshAtLevel(-3,m3)
3679 #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
3680 mm=MEDFileMesh.New(fname)
3682 fmts=MEDFileFieldMultiTS()
3683 f1ts=MEDFileField1TS()
3684 for lev in mm.getNonEmptyLevels():
3685 for gt in mm.getGeoTypesAtLevel(lev):
3686 p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
3687 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
3688 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
3689 f.setArray(arr) ; f.setName("f0")
3690 f1ts.setFieldNoProfileSBT(f)
3693 self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
3694 for lev in [0,-1,-3]:
3695 mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
3697 fmts.pushBackTimeStep(f1ts)
3701 #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
3702 fs=MEDFileFields(fname)
3703 self.assertEqual(len(fs),1)
3704 self.assertEqual(len(fs[0]),1)
3706 self.assertEqual(f1ts.getFieldSplitedByType(),[(0,[(0,(0,4),'','')]),(3,[(0,(4,6),'','')]),(4,[(0,(6,9),'','')]),(14,[(0,(9,15),'','')]),(15,[(0,(15,20),'','')]),(16,[(0,(20,24),'','')])])
3707 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0,1,2,3,0,1,0,1,2,0,1,2,3,4,5,0,1,2,3,4,0,1,2,3]),1e-12))
3710 def testMEDFileUMeshSetName(self):
3711 """ This test is a small but important one for MEDReader in sauv mode. When .sauv file is loaded the convertion is performed in memory and a preparation is done then.
3712 This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
3714 fname="Pyfile79.med"
3715 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3717 m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
3718 coords=DataArrayDouble([-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ],9,3)
3719 m0.allocateCells(5);
3720 m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3721 m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3722 m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3723 m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3724 m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3725 m0.setCoords(coords);
3726 mm.setMeshAtLevel(0,m0)
3727 m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
3729 m2.insertNextCell(NORM_POINT1,[2])
3730 m2.insertNextCell(NORM_POINT1,[3])
3731 m2.insertNextCell(NORM_POINT1,[4])
3732 m2.insertNextCell(NORM_POINT1,[5])
3733 mm.setMeshAtLevel(-2,m2)
3734 self.assertEqual(mm.getName(),"")
3735 self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
3736 mm.forceComputationOfParts()
3737 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
3739 self.assertEqual(mm.getName(),"abc")
3740 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
3741 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
3742 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
3743 self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
3746 def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
3747 fileName="Pyfile80.med"
3748 m=MEDCouplingCMesh() ; m.setName("cmesh")
3749 arr=DataArrayDouble(6) ; arr.iota()
3750 m.setCoords(arr,arr)
3751 nbCells=m.getNumberOfCells()
3752 self.assertEqual(25,nbCells)
3753 f=MEDCouplingFieldDouble(ON_CELLS)
3754 f.setName("FieldOnCell") ; f.setMesh(m)
3755 arr=DataArrayDouble(nbCells) ; arr.iota()
3759 fmts=MEDFileFieldMultiTS()
3761 for i in range(nbCells):
3762 t=(float(i)+0.1,i+1,-i-2)
3764 arr2=DataArrayDouble(nbCells)
3765 perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
3768 f1ts=MEDFileField1TS()
3769 f1ts.setFieldNoProfileSBT(f)
3770 fmts.pushBackTimeStep(f1ts)
3772 fmts.unloadArraysWithoutDataLoss()
3773 self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3774 fs=MEDFileFields() ; fs.pushField(fmts)
3775 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3776 fs.unloadArraysWithoutDataLoss()
3777 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3779 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3780 f1ts.unloadArraysWithoutDataLoss()
3781 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3782 mm.write(fileName,2)
3783 fs.write(fileName,0)
3784 del m,fmts,mm,f,f1ts
3786 mm=MEDFileMesh.New(fileName)
3787 fmts=MEDFileFieldMultiTS(fileName)
3788 self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3789 fmts.unloadArraysWithoutDataLoss()
3790 self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
3791 fmts.loadArraysIfNecessary()
3792 self.assertTrue(fmts[0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3794 fs=MEDFileFields(fileName)
3795 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3796 fs.unloadArraysWithoutDataLoss()
3797 self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
3798 fs.loadArraysIfNecessary()
3799 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3801 f1ts=MEDFileField1TS(fileName)
3802 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3803 f1ts.unloadArraysWithoutDataLoss()
3804 self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
3805 f1ts.loadArraysIfNecessary()
3806 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(DataArrayDouble([0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.,22.,23.,24.]),1e-12))
3809 def testMEDFileUMeshLoadPart1(self):
3810 """ This method tests MEDFileUMesh.LoadPart that loads only a part of a specified mesh in a MED file. The part is specfied using a slice of cell ids. Only nodes on which cells lies are loaded to reduce at most the amount of
3811 memory of the returned instance.
3813 fileName="Pyfile81.med"
3814 arr=DataArrayDouble(6) ; arr.iota()
3815 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3816 m=m.buildUnstructured()
3818 m.changeSpaceDimension(3,0.)
3819 infos=["aa [b]","cc [de]","gg [klm]"]
3820 m.getCoords().setInfoOnComponents(infos)
3821 m.checkConsistency()
3823 mm.setMeshAtLevel(0,m)
3824 m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh")
3825 m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
3826 mm.setMeshAtLevel(-1,m1)
3827 renum0=DataArrayInt([3,6,7,10,11,0,2,1,9,8,5,4,12,13,14,24,23,22,21,20,19,18,17,16,15])
3828 famField0=DataArrayInt([-3,-6,-7,-10,-11,0,-2,-1,-9,-8,-5,-4,-12,-13,-14,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15])
3829 namesCellL0=DataArrayAsciiChar(25,16)
3830 namesCellL0[:] = ["Cell#%.3d " % (i) for i in range(25)]
3831 renumM1=DataArrayInt([3,4,0,2,1])
3832 famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
3833 mm.setRenumFieldArr(0,renum0)
3834 mm.setFamilyFieldArr(0,famField0)
3835 mm.setNameFieldAtLevel(0,namesCellL0)
3836 mm.setRenumFieldArr(-1,renumM1)
3837 mm.setFamilyFieldArr(-1,famFieldM1)
3838 renum1=DataArrayInt([13,16,17,20,21,10,12,11,19,18,15,14,22,23,24,34,33,32,31,30,29,28,27,26,25,45,44,43,42,41,40,39,38,37,36,35])
3839 famField1=DataArrayInt([-13,-16,-17,-20,-21,-10,-12,-11,-19,-18,-15,-14,-22,-23,-24,-34,-33,-32,-31,-30,-29,-28,-27,-26,-25,-45,-44,-43,-42,-41,-40,-39,-38,-37,-36,-35])
3840 namesNodes=DataArrayAsciiChar(36,16)
3841 namesNodes[:] = ["Node#%.3d " % (i) for i in range(36)]
3842 mm.setRenumFieldArr(1,renum1)
3843 mm.setFamilyFieldArr(1,famField1)
3844 mm.setNameFieldAtLevel(1,namesNodes)
3845 mm.setFamilyId("Fam7",77)
3846 mm.setFamilyId("Fam8",88)
3847 mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
3848 mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
3849 mm.write(fileName,2)
3851 mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
3852 self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
3853 self.assertTrue(mm0.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,11,10,16,17])))
3854 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),(5,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(4,1,0),(5,1,0),(0,2,0),(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0)]) ; coo.setInfoOnComponents(infos)
3855 self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
3856 self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
3857 self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
3858 self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
3859 self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
3860 self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
3861 self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
3863 mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
3864 self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
3865 self.assertTrue(mm1.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([1,0,6,7,2,1,7,8,3,2,8,9,4,3,9,10,6,5,11,12,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,12,11,17,18,13,12,18,19,14,13,19,20,15,14,20,21,16,15,21,22])))
3866 coo=DataArrayDouble([(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0),(0,3,0),(1,3,0),(2,3,0),(3,3,0),(4,3,0),(5,3,0),(0,4,0),(1,4,0),(2,4,0),(3,4,0),(4,4,0),(5,4,0),(0,5,0),(1,5,0),(2,5,0),(3,5,0),(4,5,0),(5,5,0)]) ; coo.setInfoOnComponents(infos)
3867 self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
3868 self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
3869 self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
3870 self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
3871 self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
3872 self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
3873 self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
3875 mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
3876 self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
3877 self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
3878 self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
3879 self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
3880 self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
3881 self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
3882 self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
3883 self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().isEqual(DataArrayInt([2,1,7,8,3,2,8,9,4,3,9,10,5,4,10,11,7,6,12,13,8,7,13,14,9,8,14,15,10,9,15,16,11,10,16,17])))
3884 self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
3885 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),(5,0,0),(0,1,0),(1,1,0),(2,1,0),(3,1,0),(4,1,0),(5,1,0),(0,2,0),(1,2,0),(2,2,0),(3,2,0),(4,2,0),(5,2,0)]) ; coo.setInfoOnComponents(infos)
3886 self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
3887 self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
3888 self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
3889 self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
3892 def testMEDFileFieldsLoadPart1(self):
3893 """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
3895 fileName="Pyfile82.med"
3897 compos=["aa [kg]","bbb [m/s]"]
3898 arr=DataArrayDouble(6) ; arr.iota()
3899 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3900 m=m.buildUnstructured()
3902 m.changeSpaceDimension(3,0.)
3903 infos=["aa [b]","cc [de]","gg [klm]"]
3904 m.getCoords().setInfoOnComponents(infos)
3905 m.checkConsistency()
3906 f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
3908 arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
3909 arr[:,0]=list(range(25))
3910 arr[:,1]=list(range(100,125))
3912 WriteField(fileName,f,True)
3913 f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
3914 f.setName("FieldNode")
3915 arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
3916 arr[:,0]=list(range(200,236))
3917 arr[:,1]=list(range(300,336))
3919 f.checkConsistencyLight()
3920 WriteFieldUsingAlreadyWrittenMesh(fileName,f)
3923 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
3925 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3926 self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
3929 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
3931 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
3933 fs[0][0].loadArrays()
3934 arr = DataArrayDouble(12, 2) ; arr[:, 0] = list(range(3, 15)) ; arr[:, 1] = list(range(103, 115))
3935 arr.setInfoOnComponents(compos)
3936 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
3937 fs[1][0].loadArrays()
3938 arr = DataArrayDouble(21, 2) ; arr[:, 0] = list(range(203, 224)) ; arr[:, 1] = list(range(303, 324))
3939 arr.setInfoOnComponents(compos)
3940 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
3943 def testMEDFileWithoutCells1(self):
3944 fileName="Pyfile83.med"
3945 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
3946 coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
3950 mm.write(fileName,2)
3952 mm=MEDFileMesh.New(fileName)
3953 self.assertEqual(mm.getName(),"mesh")
3954 self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
3957 def testZipCoordsWithLoadPart1(self):
3958 """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
3960 fileName="Pyfile84.med"
3962 compos=["aa [kg]","bbb [m/s]"]
3963 arr=DataArrayDouble(6) ; arr.iota()
3964 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3965 m=m.buildUnstructured()
3967 m.changeSpaceDimension(3,0.)
3968 infos=["aa [b]","cc [de]","gg [klm]"]
3969 m.getCoords().setInfoOnComponents(infos)
3970 m.checkConsistency()
3971 f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
3973 arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
3974 arr[:,0]=list(range(25))
3975 arr[:,1]=list(range(100,125))
3977 WriteField(fileName,f,True)
3978 f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
3979 f.setName("FieldNode")
3980 arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
3981 arr[:,0]=list(range(200,236))
3982 arr[:,1]=list(range(300,336))
3984 f.checkConsistencyLight()
3985 WriteFieldUsingAlreadyWrittenMesh(fileName,f)
3988 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
3990 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
3991 self.assertEqual(spd.getSlice(),slice(4,6,1))
3992 spd=mm.getPartDefAtLevel(1)
3993 self.assertEqual(spd.getSlice(),slice(4,14,1))
3994 self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
3995 mm.zipCoords() # <- The important line is here !
3996 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
3997 self.assertEqual(spd.getSlice(),slice(4,6,1))
3998 spd=mm.getPartDefAtLevel(1)
3999 self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4000 self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
4001 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4002 fs[0][0].loadArrays()
4003 arr=DataArrayDouble([(4,104),(5,105)])
4004 arr.setInfoOnComponents(compos)
4005 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4006 fs[1][0].loadArrays()
4007 arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
4008 arr.setInfoOnComponents(compos)
4009 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4012 def testMEDFileCMeshSetGroupsAtLevel(self):
4013 """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
4015 m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
4017 mm=MEDFileCMesh() ; mm.setMesh(m)
4018 grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
4019 mm.setGroupsAtLevel(0,[grp])
4020 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
4023 def testMEDFileUMeshBuildExtrudedMesh1(self):
4024 """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
4025 fileName="Pyfile85.med"
4028 meshName3DOut="Mesh3D"
4030 d1=DataArrayInt([0,4,20,24])
4031 d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
4033 a=DataArrayDouble(6) ; a.iota()
4034 m=MEDCouplingCMesh() ; m.setCoords(a,a)
4035 m=m.buildUnstructured()
4036 d1c=d1.buildComplement(m.getNumberOfCells())
4037 m=m[d1c] ; m.zipCoords()
4038 m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
4040 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
4041 m.setName(meshName2D)
4042 mMinus1,a,b,c,d=m.buildDescendingConnectivity()
4043 e=d.deltaShiftIndex().findIdsEqual(1)
4046 mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
4047 grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
4048 mm.setGroupsAtLevel(0,[grp0])
4049 grp1=e ; grp1.setName("grp1")
4050 mm.setGroupsAtLevel(-1,[grp1])
4051 mm.write(fileName,2)
4053 a=DataArrayDouble(3) ; a.iota()
4054 tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
4055 tmp.setName(meshName1D)
4056 tmp.changeSpaceDimension(3)
4057 tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
4059 mm1D.setMeshAtLevel(0,tmp)
4060 mm1D.write(fileName,0)
4062 mm2D=MEDFileMesh.New(fileName,meshName2D)
4063 mm1D=MEDFileMesh.New(fileName,meshName1D)
4064 m1D=mm1D.getMeshAtLevel(0)
4065 mm3D=mm2D.buildExtrudedMesh(m1D,0)
4067 self.assertEqual(mm3D.getName(),mm2D.getName())
4068 self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
4069 self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
4070 self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
4071 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
4072 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
4073 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
4074 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
4075 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
4076 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
4077 d=DataArrayDouble([(1.,0.,0.),(2.,0.,0.),(3.,0.,0.),(4.,0.,0.),(0.,1.,0.),(1.,1.,0.),(2.,1.,0.),(3.,1.,0.),(4.,1.,0.),(5.,1.,0.),(0.,2.,0.),(1.,2.,0.),(2.,2.,0.),(3.,2.,0.),(4.,2.,0.),(5.,2.,0.),(0.,3.,0.),(1.,3.,0.),(2.,3.,0.),(3.,3.,0.),(4.,3.,0.),(5.,3.,0.),(0.,4.,0.),(1.,4.,0.),(2.,4.,0.),(3.,4.,0.),(4.,4.,0.),(5.,4.,0.),(1.,5.,0.),(2.,5.,0.),(3.,5.,0.),(4.,5.,0.),(1.,0.,1.),(2.,0.,1.),(3.,0.,1.),(4.,0.,1.),(0.,1.,1.),(1.,1.,1.),(2.,1.,1.),(3.,1.,1.),(4.,1.,1.),(5.,1.,1.),(0.,2.,1.),(1.,2.,1.),(2.,2.,1.),(3.,2.,1.),(4.,2.,1.),(5.,2.,1.),(0.,3.,1.),(1.,3.,1.),(2.,3.,1.),(3.,3.,1.),(4.,3.,1.),(5.,3.,1.),(0.,4.,1.),(1.,4.,1.),(2.,4.,1.),(3.,4.,1.),(4.,4.,1.),(5.,4.,1.),(1.,5.,1.),(2.,5.,1.),(3.,5.,1.),(4.,5.,1.),(1.,0.,2.),(2.,0.,2.),(3.,0.,2.),(4.,0.,2.),(0.,1.,2.),(1.,1.,2.),(2.,1.,2.),(3.,1.,2.),(4.,1.,2.),(5.,1.,2.),(0.,2.,2.),(1.,2.,2.),(2.,2.,2.),(3.,2.,2.),(4.,2.,2.),(5.,2.,2.),(0.,3.,2.),(1.,3.,2.),(2.,3.,2.),(3.,3.,2.),(4.,3.,2.),(5.,3.,2.),(0.,4.,2.),(1.,4.,2.),(2.,4.,2.),(3.,4.,2.),(4.,4.,2.),(5.,4.,2.),(1.,5.,2.),(2.,5.,2.),(3.,5.,2.),(4.,5.,2.)])
4078 self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
4079 d=DataArrayInt([16,1,0,5,33,32,37,16,1,5,6,33,37,38,16,2,1,6,34,33,38,16,2,6,7,34,38,39,16,3,2,7,35,34,39,16,3,7,8,35,39,40,16,5,4,10,37,36,42,16,5,10,11,37,42,43,16,9,8,14,41,40,46,16,9,14,15,41,46,47,16,11,10,16,43,42,48,16,11,16,17,43,48,49,16,15,14,20,47,46,52,16,15,20,21,47,52,53,16,17,16,22,49,48,54,16,17,22,23,49,54,55,16,21,20,26,53,52,58,16,21,26,27,53,58,59,16,24,23,28,56,55,60,16,24,28,29,56,60,61,16,25,24,29,57,56,61,16,25,29,30,57,61,62,16,26,25,30,58,57,62,16,26,30,31,58,62,63,16,33,32,37,65,64,69,16,33,37,38,65,69,70,16,34,33,38,66,65,70,16,34,38,39,66,70,71,16,35,34,39,67,66,71,16,35,39,40,67,71,72,16,37,36,42,69,68,74,16,37,42,43,69,74,75,16,41,40,46,73,72,78,16,41,46,47,73,78,79,16,43,42,48,75,74,80,16,43,48,49,75,80,81,16,47,46,52,79,78,84,16,47,52,53,79,84,85,16,49,48,54,81,80,86,16,49,54,55,81,86,87,16,53,52,58,85,84,90,16,53,58,59,85,90,91,16,56,55,60,88,87,92,16,56,60,61,88,92,93,16,57,56,61,89,88,93,16,57,61,62,89,93,94,16,58,57,62,90,89,94,16,58,62,63,90,94,95,18,6,5,11,12,38,37,43,44,18,7,6,12,13,39,38,44,45,18,8,7,13,14,40,39,45,46,18,12,11,17,18,44,43,49,50,18,13,12,18,19,45,44,50,51,18,14,13,19,20,46,45,51,52,18,18,17,23,24,50,49,55,56,18,19,18,24,25,51,50,56,57,18,20,19,25,26,52,51,57,58,18,38,37,43,44,70,69,75,76,18,39,38,44,45,71,70,76,77,18,40,39,45,46,72,71,77,78,18,44,43,49,50,76,75,81,82,18,45,44,50,51,77,76,82,83,18,46,45,51,52,78,77,83,84,18,50,49,55,56,82,81,87,88,18,51,50,56,57,83,82,88,89,18,52,51,57,58,84,83,89,90])
4080 self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
4081 d=DataArrayInt([0,7,14,21,28,35,42,49,56,63,70,77,84,91,98,105,112,119,126,133,140,147,154,161,168,175,182,189,196,203,210,217,224,231,238,245,252,259,266,273,280,287,294,301,308,315,322,329,336,345,354,363,372,381,390,399,408,417,426,435,444,453,462,471,480,489,498])
4082 self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
4083 d=DataArrayInt([3,1,0,5,3,1,5,6,3,2,1,6,3,2,6,7,3,3,2,7,3,3,7,8,3,5,4,10,3,5,10,11,3,9,8,14,3,9,14,15,3,11,10,16,3,11,16,17,3,15,14,20,3,15,20,21,3,17,16,22,3,17,22,23,3,21,20,26,3,21,26,27,3,24,23,28,3,24,28,29,3,25,24,29,3,25,29,30,3,26,25,30,3,26,30,31,3,65,64,69,3,65,69,70,3,66,65,70,3,66,70,71,3,67,66,71,3,67,71,72,3,69,68,74,3,69,74,75,3,73,72,78,3,73,78,79,3,75,74,80,3,75,80,81,3,79,78,84,3,79,84,85,3,81,80,86,3,81,86,87,3,85,84,90,3,85,90,91,3,88,87,92,3,88,92,93,3,89,88,93,3,89,93,94,3,90,89,94,3,90,94,95,4,1,0,32,33,4,0,5,37,32,4,5,1,33,37,4,5,6,38,37,4,6,1,33,38,4,2,1,33,34,4,6,2,34,38,4,6,7,39,38,4,7,2,34,39,4,3,2,34,35,4,7,3,35,39,4,7,8,40,39,4,8,3,35,40,4,5,4,36,37,4,4,10,42,36,4,10,5,37,42,4,10,11,43,42,4,11,5,37,43,4,9,8,40,41,4,8,14,46,40,4,14,9,41,46,4,14,15,47,46,4,15,9,41,47,4,10,16,48,42,4,16,11,43,48,4,16,17,49,48,4,17,11,43,49,4,14,20,52,46,4,20,15,47,52,4,20,21,53,52,4,21,15,47,53,4,16,22,54,48,4,22,17,49,54,4,22,23,55,54,4,23,17,49,55,4,20,26,58,52,4,26,21,53,58,4,26,27,59,58,4,27,21,53,59,4,24,23,55,56,4,23,28,60,55,4,28,24,56,60,4,28,29,61,60,4,29,24,56,61,4,25,24,56,57,4,29,25,57,61,4,29,30,62,61,4,30,25,57,62,4,26,25,57,58,4,30,26,58,62,4,30,31,63,62,4,31,26,58,63,4,11,12,44,43,4,12,6,38,44,4,12,13,45,44,4,13,7,39,45,4,13,14,46,45,4,17,18,50,49,4,18,12,44,50,4,18,19,51,50,4,19,13,45,51,4,19,20,52,51,4,24,18,50,56,4,25,19,51,57,4,33,32,64,65,4,32,37,69,64,4,37,33,65,69,4,37,38,70,69,4,38,33,65,70,4,34,33,65,66,4,38,34,66,70,4,38,39,71,70,4,39,34,66,71,4,35,34,66,67,4,39,35,67,71,4,39,40,72,71,4,40,35,67,72,4,37,36,68,69,4,36,42,74,68,4,42,37,69,74,4,42,43,75,74,4,43,37,69,75,4,41,40,72,73,4,40,46,78,72,4,46,41,73,78,4,46,47,79,78,4,47,41,73,79,4,42,48,80,74,4,48,43,75,80,4,48,49,81,80,4,49,43,75,81,4,46,52,84,78,4,52,47,79,84,4,52,53,85,84,4,53,47,79,85,4,48,54,86,80,4,54,49,81,86,4,54,55,87,86,4,55,49,81,87,4,52,58,90,84,4,58,53,85,90,4,58,59,91,90,4,59,53,85,91,4,56,55,87,88,4,55,60,92,87,4,60,56,88,92,4,60,61,93,92,4,61,56,88,93,4,57,56,88,89,4,61,57,89,93,4,61,62,94,93,4,62,57,89,94,4,58,57,89,90,4,62,58,90,94,4,62,63,95,94,4,63,58,90,95,4,43,44,76,75,4,44,38,70,76,4,44,45,77,76,4,45,39,71,77,4,45,46,78,77,4,49,50,82,81,4,50,44,76,82,4,50,51,83,82,4,51,45,77,83,4,51,52,84,83,4,56,50,82,88,4,57,51,83,89,4,6,5,11,12,4,7,6,12,13,4,8,7,13,14,4,12,11,17,18,4,13,12,18,19,4,14,13,19,20,4,18,17,23,24,4,19,18,24,25,4,20,19,25,26,4,70,69,75,76,4,71,70,76,77,4,72,71,77,78,4,76,75,81,82,4,77,76,82,83,4,78,77,83,84,4,82,81,87,88,4,83,82,88,89,4,84,83,89,90])
4084 self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
4085 d=DataArrayInt([0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,197,202,207,212,217,222,227,232,237,242,247,252,257,262,267,272,277,282,287,292,297,302,307,312,317,322,327,332,337,342,347,352,357,362,367,372,377,382,387,392,397,402,407,412,417,422,427,432,437,442,447,452,457,462,467,472,477,482,487,492,497,502,507,512,517,522,527,532,537,542,547,552,557,562,567,572,577,582,587,592,597,602,607,612,617,622,627,632,637,642,647,652,657,662,667,672,677,682,687,692,697,702,707,712,717,722,727,732,737,742,747,752,757,762,767,772,777,782,787,792,797,802,807,812,817,822,827,832,837,842,847,852,857,862,867,872,877,882,887,892,897,902,907,912,917,922])
4086 self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
4087 d=DataArrayInt([1,1,0,1,0,5,1,5,1,1,5,6,1,6,1,1,2,1,1,6,2,1,6,7,1,7,2,1,3,2,1,7,3,1,7,8,1,8,3,1,5,4,1,4,10,1,10,5,1,10,11,1,11,5,1,9,8,1,8,14,1,14,9,1,14,15,1,15,9,1,10,16,1,16,11,1,16,17,1,17,11,1,14,20,1,20,15,1,20,21,1,21,15,1,16,22,1,22,17,1,22,23,1,23,17,1,20,26,1,26,21,1,26,27,1,27,21,1,24,23,1,23,28,1,28,24,1,28,29,1,29,24,1,25,24,1,29,25,1,29,30,1,30,25,1,26,25,1,30,26,1,30,31,1,31,26,1,11,12,1,12,6,1,12,13,1,13,7,1,13,14,1,17,18,1,18,12,1,18,19,1,19,13,1,19,20,1,24,18,1,25,19,1,65,64,1,64,69,1,69,65,1,69,70,1,70,65,1,66,65,1,70,66,1,70,71,1,71,66,1,67,66,1,71,67,1,71,72,1,72,67,1,69,68,1,68,74,1,74,69,1,74,75,1,75,69,1,73,72,1,72,78,1,78,73,1,78,79,1,79,73,1,74,80,1,80,75,1,80,81,1,81,75,1,78,84,1,84,79,1,84,85,1,85,79,1,80,86,1,86,81,1,86,87,1,87,81,1,84,90,1,90,85,1,90,91,1,91,85,1,88,87,1,87,92,1,92,88,1,92,93,1,93,88,1,89,88,1,93,89,1,93,94,1,94,89,1,90,89,1,94,90,1,94,95,1,95,90,1,75,76,1,76,70,1,76,77,1,77,71,1,77,78,1,81,82,1,82,76,1,82,83,1,83,77,1,83,84,1,88,82,1,89,83])
4088 self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
4089 d=DataArrayInt(129) ; d.iota() ; d*=3
4090 self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
4092 self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
4093 self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
4094 self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
4095 self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
4096 self.assertTrue(mm3D.getGroupArr(-2,"grp1").isEqualWithoutConsideringStr(DataArrayInt([0,1,5,9,12,13,14,18,22,23,30,31,33,37,38,40,42,46,50,51])))
4097 self.assertTrue(mm3D.getGroupArr(-2,"grp1_top").isEqualWithoutConsideringStr(DataArrayInt([64,65,69,73,76,77,78,82,86,87,94,95,97,101,102,104,106,110,114,115])))
4098 self.assertTrue(mm3D.getGroupArr(0,"grp0_extruded").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,24,25,26,27,28,29,48,49,50,57,58,59])))
4099 self.assertTrue(mm3D.getGroupArr(-1,"grp1_extruded").isEqualWithoutConsideringStr(DataArrayInt([48,49,53,57,60,61,62,66,70,71,78,79,81,85,86,88,90,94,98,99,112,113,117,121,124,125,126,130,134,135,142,143,145,149,150,152,154,158,162,163])))
4100 mm3D.setName("MeshExtruded")
4101 mm3D.write(fileName,0)
4104 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4105 def testMEDFileUMeshPickeling1(self):
4106 outFileName="Pyfile86.med"
4107 c=DataArrayDouble([-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ],9,2)
4108 c.setInfoOnComponents(["aa","bbb"])
4109 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
4110 m=MEDCouplingUMesh();
4111 m.setMeshDimension(2);
4113 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
4114 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
4115 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
4116 m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
4117 m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
4118 m.finishInsertingCells();
4120 m.checkConsistencyLight()
4121 m1=MEDCouplingUMesh.New();
4122 m1.setMeshDimension(1);
4123 m1.allocateCells(3);
4124 m1.insertNextCell(NORM_SEG2,2,[1,4])
4125 m1.insertNextCell(NORM_SEG2,2,[3,6])
4126 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
4127 m1.finishInsertingCells();
4129 m1.checkConsistencyLight()
4130 m2=MEDCouplingUMesh.New();
4131 m2.setMeshDimension(0);
4132 m2.allocateCells(4);
4133 m2.insertNextCell(NORM_POINT1,1,[1])
4134 m2.insertNextCell(NORM_POINT1,1,[3])
4135 m2.insertNextCell(NORM_POINT1,1,[2])
4136 m2.insertNextCell(NORM_POINT1,1,[6])
4137 m2.finishInsertingCells();
4139 m2.checkConsistencyLight()
4141 mm=MEDFileUMesh.New()
4142 self.assertTrue(mm.getUnivNameWrStatus())
4143 mm.setName("MyFirstMEDCouplingMEDmesh")
4144 mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
4148 mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
4150 mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
4151 # playing with groups
4152 g1_2=DataArrayInt.New()
4153 g1_2.setValues([1,3],2,1)
4155 g2_2=DataArrayInt.New()
4156 g2_2.setValues([1,2,3],3,1)
4158 mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
4159 g1_1=DataArrayInt.New()
4160 g1_1.setValues([0,1,2],3,1)
4162 g2_1=DataArrayInt.New()
4163 g2_1.setValues([0,2],2,1)
4165 mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
4166 g1_N=DataArrayInt.New()
4167 g1_N.setValues(list(range(8)),8,1)
4169 g2_N=DataArrayInt.New()
4170 g2_N.setValues(list(range(9)),9,1)
4172 mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
4173 mm.createGroupOnAll(0,"GrpOnAllCell")
4174 # check content of mm
4175 t=mm.getGroupArr(0,"G1",False)
4176 self.assertTrue(g1_2.isEqual(t));
4177 t=mm.getGroupArr(0,"G2",False)
4178 self.assertTrue(g2_2.isEqual(t));
4179 t=mm.getGroupArr(-1,"G1",False)
4180 self.assertTrue(g1_1.isEqual(t));
4181 t=mm.getGroupArr(-1,"G2",False)
4182 self.assertTrue(g2_1.isEqual(t));
4183 t=mm.getGroupArr(1,"G1",False)
4184 self.assertTrue(g1_N.isEqual(t));
4185 t=mm.getGroupArr(1,"G2",False)
4186 self.assertTrue(g2_N.isEqual(t));
4187 self.assertTrue(mm.existsGroup("GrpOnAllCell"));
4188 t=mm.getGroupArr(0,"GrpOnAllCell")
4190 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4191 mm2=pickle.loads(st)
4192 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4193 self.assertEqual(mm.getAxisType(),AX_CART)
4195 mm.setAxisType(AX_CYL)
4196 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4197 mm2=pickle.loads(st)
4198 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4199 self.assertEqual(mm2.getAxisType(),AX_CYL)
4202 def testMEDFileFieldsLoadSpecificEntities1(self):
4205 fileName="Pyfile87.med"
4209 m=MEDCouplingCMesh()
4210 arr=DataArrayDouble(nbNodes) ; arr.iota()
4212 m=m.buildUnstructured()
4215 fmts=MEDFileFieldMultiTS()
4216 for i in range(nbPdt):
4217 f=MEDCouplingFieldDouble(ON_NODES)
4219 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4221 f.setName(fieldName)
4222 f.setTime(float(i),i,0)
4223 fmts.appendFieldNoProfileSBT(f)
4226 mm=MEDFileUMesh() ; mm[0]=m
4227 fmts.write(fileName,2)
4228 mm.write(fileName,0)
4230 fs=MEDFileFields(fileName,False)
4231 fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
4232 fs.loadArraysIfNecessary()
4233 fs2.loadArraysIfNecessary()
4234 for i in range(nbPdt):
4235 self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4237 m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
4238 m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
4239 m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
4240 fmts=MEDFileFieldMultiTS()
4241 for i in range(nbPdt):
4242 f=MEDCouplingFieldDouble(ON_CELLS)
4244 arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
4246 f.setName(fieldName)
4247 f.setTime(float(i),i,0)
4248 fmts.appendFieldNoProfileSBT(f)
4250 mm=MEDFileUMesh() ; mm[0]=m3
4252 self.assertEqual(mm.getNonEmptyLevels(),())
4254 self.assertEqual(mm.getNonEmptyLevels(),(0,))
4255 fmts.write(fileName,2)
4256 fs=MEDFileFields(fileName,False)
4257 fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
4258 fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
4259 fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
4260 fs.loadArraysIfNecessary()
4261 fs2.loadArraysIfNecessary()
4262 fs3.loadArraysIfNecessary()
4263 fs4.loadArraysIfNecessary()
4264 for i in range(nbPdt):
4265 self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4266 self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
4267 self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
4271 def testMEDFileLotsOfTSRW1(self):
4274 fileName="Pyfile88.med"
4275 nbPdt=300 # <- perftest = 30000
4278 maxPdt=100 # <- optimum = 500
4279 m=MEDCouplingCMesh()
4280 arr=DataArrayDouble(nbNodes) ; arr.iota()
4282 m=m.buildUnstructured()
4285 nbOfField=nbPdt//maxPdt
4287 for j in range(nbOfField):
4288 fmts=MEDFileFieldMultiTS()
4289 s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
4290 for i in range(s.start, s.stop, s.step):
4291 f=MEDCouplingFieldDouble(ON_NODES)
4293 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4295 f.setName("%s_%d"%(fieldName,j))
4296 f.setTime(float(i),i,0)
4297 fmts.appendFieldNoProfileSBT(f)
4302 mm=MEDFileUMesh() ; mm[0]=m
4303 fs.write(fileName,2)
4304 mm.write(fileName,0)
4306 def appendInDict(d,key,val):
4313 allFields=GetAllFieldNames(fileName)
4315 pat=re.compile("([\d]+)([\s\S]+)$")
4316 for st in allFields:
4320 appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
4323 appendInDict(allFieldsDict,st,'')
4327 for k in allFieldsDict:
4328 if allFieldsDict[k]!=['']:
4329 allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
4332 for it in allFieldsDict[k]:
4333 fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
4338 for ii in range(nbIter):
4339 zeResu.pushBackTimeSteps(fmts2.pop())
4342 fs2.pushField(zeResu)
4344 self.assertEqual(fs2[0].getTimeSteps(), [(i, 0, float(i)) for i in range(nbPdt)])
4347 def testMEDFileMeshRearrangeFamIds1(self):
4348 """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
4349 fileName="Pyfile89.med"
4350 meshName='Maillage_2'
4352 coords=DataArrayDouble([(0.,0.,0.),(0.,0.,200.),(0.,200.,200.),(0.,200.,0.),(200.,0.,0.),(200.,0.,200.),(200.,200.,200.),(200.,200.,0.),(0.,0.,100.),(0.,100.,200.),(0.,200.,100.),(0.,100.,0.),(200.,0.,100.),(200.,100.,200.),(200.,200.,100.),(200.,100.,0.),(100.,0.,0.),(100.,0.,200.),(100.,200.,0.),(100.,200.,200.),(0.,116.87743909766768,83.12256090233232),(200.,116.87743909766768,83.12256090233232),(116.87743909766769,0.,116.87743909766769),(116.87743909766769,200.,116.87743909766769),(116.87743909766769,116.87743909766769,0.),(116.87743909766769,116.87743909766769,200.),(63.3851584383713,56.1391811199829,119.728314479261),(138.008709441123,116.039297556044,119.903790959468)])
4354 c0=DataArrayInt([14,1,26,9,8,14,17,26,1,8,14,27,26,17,22,14,26,16,20,8,14,8,0,16,11,14,16,20,11,24,14,25,20,26,27,14,22,26,24,27,14,26,16,22,24,14,8,26,22,17,14,20,9,25,26,14,19,20,25,23,14,23,6,27,25,14,19,23,10,20,14,27,22,21,24,14,27,21,14,18,14,26,9,25,17,14,13,27,25,17,14,27,18,24,21,14,22,21,15,12,14,27,20,24,18,14,23,25,27,20,14,13,27,6,25,14,23,27,6,14,14,15,16,22,12,14,27,17,13,22,14,22,27,21,13,14,24,16,22,15,14,24,18,7,21,14,12,4,15,16,14,22,12,5,13,14,8,26,16,22,14,13,27,21,14,14,20,18,10,3,14,14,27,18,23,14,14,27,6,13,14,21,22,13,12,14,25,26,17,27,14,19,9,25,20,14,26,24,20,16,14,22,24,15,21,14,9,26,1,17,14,23,27,18,20,14,20,11,18,3,14,14,18,21,7,14,19,2,9,10,14,19,23,25,6,14,18,23,20,10,14,20,26,8,9,14,22,13,5,17,14,24,11,18,20,14,21,15,7,24,14,19,20,10,9,14,20,26,27,24,14,16,8,11,20])
4355 c0i=DataArrayInt([0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135,140,145,150,155,160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255,260,265,270,275])
4356 m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
4357 m0.setConnectivity(c0,c0i)
4360 c1=DataArrayInt([3,8,20,11,3,8,9,20,3,9,2,10,3,20,9,10,3,0,8,11,3,9,8,1,3,20,10,3,3,11,20,3,3,15,21,12,3,5,12,13,3,21,13,12,3,15,12,4,3,14,6,13,3,14,13,21,3,7,14,21,3,7,21,15,3,5,22,12,3,4,12,16,3,17,1,8,3,16,8,0,3,5,17,22,3,12,22,16,3,22,17,8,3,16,22,8,3,10,2,19,3,7,18,14,3,14,23,6,3,3,10,18,3,23,19,6,3,18,23,14,3,10,19,23,3,10,23,18,3,3,18,11,3,7,24,18,3,15,4,16,3,11,16,0,3,7,15,24,3,18,24,11,3,24,15,16,3,11,24,16,3,9,19,2,3,19,25,6,3,17,5,13,3,1,17,9,3,25,13,6,3,9,25,19,3,17,13,25,3,17,25,9])
4361 c1i=DataArrayInt([0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192])
4362 m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
4363 m1.setConnectivity(c1,c1i)
4366 c2=DataArrayInt([0,8,8,1,1,9,9,2,3,10,10,2,0,11,11,3,4,12,12,5,5,13,13,6,7,14,14,6,4,15,15,7,0,16,16,4,1,17,17,5,3,18,18,7,2,19,19,6])
4367 m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4368 m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
4369 mm[-2]=m2.buildUnstructured()
4371 ref0=DataArrayInt(55) ; ref0[:]=0
4372 mm.setFamilyFieldArr(0,ref0)
4373 mm.setFamilyFieldArr(1,DataArrayInt([0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]))
4374 ref1=DataArrayInt([0,0,0,0,0,0,0,0,-6,-6,-6,-6,-6,-6,-6,-6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
4375 mm.setFamilyFieldArr(-1,ref1)
4376 ref2=DataArrayInt([0,0,-7,-7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
4377 mm.setFamilyFieldArr(-2,ref2)
4379 for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
4380 mm.setFamilyId(f,fid)
4381 for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
4382 mm.setFamiliesOnGroup(grp,fams)
4383 mm.write(fileName,2)
4385 mm=MEDFileMesh.New(fileName)
4386 grp=mm.getGroup(-1,"Groupe_1")
4387 dai=grp.computeFetchedNodeIds()
4390 mm.rearrangeFamilies() # <- the aim of the test
4391 self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
4392 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
4393 self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
4394 self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
4395 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([0,0,2,0,9,9,9,9,0,0,0,0,9,9,9,9,0,0,0,0,0,9,0,0,0,0,0,0])))
4396 allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
4397 allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
4398 self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
4399 for elt,fams in allGrps:
4400 self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
4401 self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
4402 for elt,eltId in allFams:
4403 self.assertEqual(mm.getFamilyId(elt),eltId)
4406 def testNonRegrCMeshSetFieldPfl1(self):
4407 """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
4408 ff=MEDFileField1TS()
4411 m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4415 field=MEDCouplingFieldDouble(ON_CELLS)
4417 field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4418 field.setName("Field")
4419 field.checkConsistencyLight()
4420 pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
4421 ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
4422 self.assertEqual(ff.getPfls(),())
4423 field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4424 self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4425 del ff,mm,field,field2,pfl
4426 # same with unstructured mesh
4427 ff=MEDFileField1TS()
4430 m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4433 m=m.buildUnstructured()
4435 field=MEDCouplingFieldDouble(ON_CELLS)
4437 field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4438 field.setName("Field")
4439 field.checkConsistencyLight()
4440 pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
4441 ff.setFieldProfile(field,mm,0,pfl)
4442 self.assertEqual(ff.getPfls(),())
4443 field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4444 self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4447 def testMEDFileUMeshLinearToQuadraticAndRev1(self):
4449 fileName="Pyfile90.med"
4450 fileName2="Pyfile91.med"
4451 arr=DataArrayDouble(5) ; arr.iota()
4452 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4453 m=m.buildUnstructured()
4454 d=DataArrayInt([3,7,11,15])
4457 m2=m[d.buildComplement(m.getNumberOfCells())]
4458 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
4459 m.changeSpaceDimension(3,0.)
4460 arr=DataArrayDouble(3) ; arr.iota()
4461 m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
4462 m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
4463 delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
4464 m3D=m.buildExtrudedMesh(m1D,0)
4465 m3D.sortCellsInMEDFileFrmt()
4466 m3D.setName(meshName)
4467 m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkConsistency()
4468 m1D=m2D.computeSkin() ; m1D.setName(meshName)
4469 m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
4472 mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
4473 grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
4474 grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
4475 grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
4476 grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
4477 diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
4478 vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
4479 vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
4480 mm.setGroupsAtLevel(0,[vol1,vol2])
4481 mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
4482 mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
4484 mmOut1=mm.linearToQuadratic(0,0.)
4485 mmOut1.write(fileName2,2)
4486 mmOut2=mmOut1.quadraticToLinear(0.)
4487 self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
4490 def testMEDFileMeshAddGroup1(self):
4491 m=MEDCouplingCMesh()
4492 arrX=DataArrayDouble(9) ; arrX.iota()
4493 arrY=DataArrayDouble(4) ; arrY.iota()
4494 m.setCoords(arrX,arrY)
4498 grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
4500 grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
4502 grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
4504 grp3=DataArrayInt([23]) ; grp3.setName("grp3")
4506 for grp in [grp0,grp1,grp2,grp3]:
4507 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4508 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
4510 for grp in [grp0,grp1,grp2,grp3]:
4511 grpNode=grp.deepCopy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
4512 mm.addGroup(1,grpNode)
4513 self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
4514 for grp in [grp0,grp1,grp2,grp3]:
4515 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4516 for grp in [grp0,grp1,grp2,grp3]:
4517 grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4518 self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4519 mm.normalizeFamIdsMEDFile()
4520 for grp in [grp0,grp1,grp2,grp3]:
4521 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4522 for grp in [grp0,grp1,grp2,grp3]:
4523 grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4524 self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4527 def testMEDFileJoint1(self):
4528 fileName="Pyfile92.med"
4529 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4530 coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4534 mm.setDescription("un maillage")
4535 mm.write(fileName,2)
4536 node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4537 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4538 one_step_joint=MEDFileJointOneStep()
4539 one_step_joint.pushCorrespondence(cell_correspond)
4540 one_step_joint.pushCorrespondence(node_correspond)
4541 one_joint=MEDFileJoint()
4542 one_joint.pushStep(one_step_joint)
4543 one_joint.setLocalMeshName("maa1")
4544 one_joint.setRemoteMeshName("maa1")
4545 one_joint.setDescription("joint_description")
4546 one_joint.setJointName("joint_1")
4547 one_joint.setDomainNumber(1)
4548 self.assertEqual( one_joint.getLocalMeshName(), "maa1")
4549 self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
4550 self.assertEqual( one_joint.getDescription(), "joint_description")
4551 self.assertEqual( one_joint.getJointName(), "joint_1")
4552 self.assertEqual( one_joint.getDomainNumber(), 1)
4553 joints=MEDFileJoints()
4554 joints.pushJoint(one_joint);
4555 joints.write(fileName,0)
4557 jointsR=MEDFileJoints(fileName,mm.getName())
4558 self.assertEqual( jointsR.getNumberOfJoints(), 1 )
4559 jR = jointsR.getJointAtPos(0)
4560 self.assertTrue( jR.isEqual( one_joint ))
4561 self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
4562 self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
4563 jointsR.destroyJointAtPos(0)
4566 def testMEDFileJoint2(self):
4567 fileNameWr="Pyfile93.med"
4568 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4569 coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4573 mm.setDescription("un maillage")
4574 node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
4575 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
4576 one_step_joint=MEDFileJointOneStep()
4577 two_step_joint=MEDFileJointOneStep()
4578 one_joint=MEDFileJoint()
4579 two_joint=MEDFileJoint()
4580 one_step_joint.pushCorrespondence(node_correspond)
4581 one_joint.pushStep(one_step_joint)
4582 two_step_joint.pushCorrespondence(cell_correspond)
4583 two_step_joint.pushCorrespondence(node_correspond)
4584 two_joint.pushStep(two_step_joint)
4585 one_joint.setLocalMeshName("maa1")
4586 one_joint.setRemoteMeshName("maa1")
4587 one_joint.setDescription("joint_description_1")
4588 one_joint.setJointName("joint_1")
4589 one_joint.setDomainNumber(1)
4590 two_joint.setLocalMeshName("maa1")
4591 two_joint.setRemoteMeshName("maa1")
4592 two_joint.setDescription("joint_description_2")
4593 two_joint.setJointName("joint_2")
4594 two_joint.setDomainNumber(2)
4595 joints=MEDFileJoints()
4596 joints.pushJoint(one_joint)
4597 joints.pushJoint(two_joint)
4598 mm.setJoints( joints )
4599 mm.write(fileNameWr,2)
4601 mm=MEDFileMesh.New(fileNameWr)
4602 self.assertEqual( mm.getNumberOfJoints(), 2)
4603 jointsR = mm.getJoints();
4604 self.assertEqual( jointsR.getMeshName(), mm.getName() )
4605 self.assertEqual( len( jointsR ), 2 )
4606 jointR1 = jointsR[0]
4607 jointR2 = jointsR[1]
4608 self.assertFalse( jointR1 is None )
4609 self.assertFalse( jointR2 is None )
4610 self.assertTrue( jointR1.isEqual( one_joint ))
4611 self.assertTrue( jointR2.isEqual( two_joint ))
4614 def testMEDFileJoint1(self):
4615 node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4616 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4617 cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
4618 cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
4619 joint1st_1=MEDFileJointOneStep()
4620 joint1st_1.pushCorrespondence(cell_correspond)
4621 joint1st_1.pushCorrespondence(node_correspond)
4622 joint1st_2=MEDFileJointOneStep()
4623 joint1st_2.pushCorrespondence(cell_correspond)
4624 joint1st_2.pushCorrespondence(node_correspond)
4625 joint1st_3=MEDFileJointOneStep()
4626 joint1st_3.pushCorrespondence(node_correspond)
4627 joint1st_3.pushCorrespondence(cell_correspond)
4628 joint1st_4=MEDFileJointOneStep()
4629 joint1st_4.pushCorrespondence(cell_correspond)
4630 joint1st_5=MEDFileJointOneStep()
4631 joint1st_5.pushCorrespondence(cell_correspon2)
4632 joint1st_6=MEDFileJointOneStep()
4633 joint1st_6.pushCorrespondence(cell_correspon3)
4634 self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
4635 self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
4636 self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
4637 self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
4638 self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
4639 one_joint=MEDFileJoint()
4640 one_joint.pushStep(joint1st_1)
4641 one_joint.setLocalMeshName("maa1")
4642 one_joint.setRemoteMeshName("maa2")
4643 one_joint.setDescription("joint_description")
4644 one_joint.setJointName("joint_1")
4645 one_joint.setDomainNumber(1)
4646 self.assertEqual( "maa1", one_joint.getLocalMeshName())
4647 self.assertEqual( "maa2", one_joint.getRemoteMeshName())
4648 self.assertEqual( "joint_description", one_joint.getDescription())
4649 self.assertEqual( 1, one_joint.getDomainNumber())
4650 self.assertEqual( "joint_1", one_joint.getJointName())
4653 @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
4654 def testMEDFileSafeCall0(self):
4655 """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
4656 fname="Pyfile94.med"
4657 errfname="Pyfile94.err"
4658 class StdOutRedirect(object):
4659 def __init__(self,fileName):
4662 self.stdoutOld=os.dup(2)
4663 self.fdOfSinkFile=os.open(fileName,os.O_CREAT | os.O_RDWR)
4664 fd2=os.dup2(self.fdOfSinkFile,2)
4665 self.origPyVal=sys.stderr
4666 class FlushFile(object):
4667 def __init__(self,f):
4673 return self.f.flush()
4675 return self.f.isatty()
4676 sys.stderr=FlushFile(os.fdopen(self.fdOfSinkFile,"w"))
4679 sys.stderr=self.origPyVal
4680 if sys.version_info.major >= 3:
4681 self.fdOfSinkFile.close()
4683 #os.fsync(self.fdOfSinkFile)
4685 os.dup2(self.stdoutOld,2)
4686 os.close(self.stdoutOld)
4688 # first clean file if needed
4689 if os.path.exists(fname):
4692 # second : build a file from scratch
4693 m=MEDCouplingCMesh()
4694 arr=DataArrayDouble(11) ; arr.iota()
4695 m.setCoords(arr,arr)
4700 # third : change permissions to remove write access on created file
4701 os.chmod(fname, 0o444)
4702 # four : try to append data on file -> check that it raises Exception
4703 f=MEDCouplingFieldDouble(ON_CELLS)
4706 f.setArray(DataArrayDouble(100))
4707 f.getArray()[:]=100.
4708 f.checkConsistencyLight()
4709 f1ts=MEDFileField1TS()
4710 f1ts.setFieldNoProfileSBT(f)
4712 tmp=StdOutRedirect(errfname)
4713 self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
4716 if os.path.exists(errfname):
4721 def testUnivStatus1(self):
4722 """ Non regression test to check the effectiveness of univ write status."""
4723 fname="Pyfile95.med"
4724 arr=DataArrayDouble(10) ; arr.iota()
4725 m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
4726 mm=MEDFileCMesh() ; mm.setMesh(m)
4727 mm.setUnivNameWrStatus(False) # test is here
4729 mm=MEDFileCMesh(fname)
4730 self.assertEqual(mm.getUnivName(),"")
4731 mm.setUnivNameWrStatus(True)
4733 mm=MEDFileCMesh(fname)
4734 self.assertTrue(mm.getUnivName()!="")
4737 def testEmptyMesh(self):
4738 """ MEDLoader should be able to consistently write and read an empty mesh (coords array
4740 fname = "Pyfile96.med"
4741 m = MEDCouplingUMesh('toto', 2)
4742 m.setCoords(DataArrayDouble([], 0, 2))
4743 m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
4744 mfu = MEDFileUMesh()
4745 mfu.setMeshAtLevel(0, m)
4747 mfu2 = MEDFileUMesh(fname)
4748 self.assertEqual('toto', mfu2.getName())
4749 lvl = mfu2.getNonEmptyLevels()
4750 self.assertEqual((), lvl)
4752 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4753 def testMEDFileUMeshPickeling2(self):
4754 """ Check that pickalization can be performed on a unpickalized instance. Non regression test."""
4760 arr=DataArrayDouble(nbOfNodesPerAxis) ; arr.iota() ; arr/=(nbOfNodesPerAxis-1) ; arr*=hauteur
4761 m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured() ; m.setName(name)
4762 mesh=MEDFileUMesh() ; mesh[0]=m
4763 m1=m.computeSkin() ; mesh[-1]=m1
4765 bary1=m1.computeCellCenterOfMass()[:,2]
4766 grp1=bary1.findIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
4767 grp2=bary1.findIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
4768 mesh.setGroupsAtLevel(-1,[grp1,grp2])
4770 st=pickle.dumps(mesh,2)
4772 st2=pickle.dumps(mm,2)
4773 mm2=pickle.loads(st2)
4774 self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
4777 def testMEDFileEquivalence1(self):
4778 """ First check of equivalence implementation in MEDFileMesh"""
4779 fileName="Pyfile97.med"
4782 coo=DataArrayDouble([(0,0,0),(6,0,0),(19,0,0),(36,0,0),(0,4,0),(6,4,0),(19,4,0),(36,4,0),(0,13,0),(6,13,0),(19,13,0),(36,13,0),(0,24,0),(6,24,0),(19,24,0),(36,24,0),(0,0,6),(6,0,6),(19,0,6),(36,0,6),(0,4,6),(6,4,6),(19,4,6),(36,4,6),(0,13,6),(6,13,6),(19,13,6),(36,13,6),(0,24,6),(6,24,6),(19,24,6),(36,24,6),(6,0,3),(6,2,0),(12.5,0,0),(19,0,3),(19,2,0),(6,4,3),(12.5,4,0),(19,4,3),(6,2,6),(12.5,0,6),(19,2,6),(12.5,4,6),(6,2,3),(12.5,0,3),(12.5,2,0),(19,2,3),(12.5,4,3),(12.5,2,6),(12.5,2,3)])
4783 coo.setInfoOnComponents(["X [Sans_unite]","Y [Sans_unite]","Z [Sans_unite]"])
4784 connQ4=DataArrayInt([1,17,21,5,2,18,22,6,21,5,6,22,1,32,44,33,17,40,44,32,21,37,44,40,5,33,44,37,2,35,47,36,18,42,47,35,22,39,47,42,6,36,47,39,21,37,48,43,5,38,48,37,6,39,48,38,22,43,48,39])
4785 m1=MEDCoupling1SGTUMesh(meshName,NORM_QUAD4) ; m1.setCoords(coo) ; m1.setNodalConnectivity(connQ4) ; mm[-1]=m1
4786 connH8=DataArrayInt([20,16,17,21,4,0,1,5,22,18,19,23,6,2,3,7,24,20,21,25,8,4,5,9,25,21,22,26,9,5,6,10,26,22,23,27,10,6,7,11,28,24,25,29,12,8,9,13,29,25,26,30,13,9,10,14,30,26,27,31,14,10,11,15,21,40,49,43,37,44,50,48,40,17,41,49,44,32,45,50,49,41,18,42,50,45,35,47,43,49,42,22,48,50,47,39,44,32,45,50,33,1,34,46,37,44,50,48,5,33,46,38,48,50,47,39,38,46,36,6,50,45,35,47,46,34,2,36])
4787 m0=MEDCoupling1SGTUMesh(meshName,NORM_HEXA8) ; m0.setCoords(coo) ; m0.setNodalConnectivity(connH8) ; mm[0]=m0
4788 mm.getFamilyFieldAtLevel(-1)[:]=-2
4789 mm.getFamilyFieldAtLevel(0)[:]=0
4790 mm.addFamily("HOMARD________-1",-1)
4791 mm.addFamily("HOMARD________-2",-2)
4792 mm.addFamily("HOMARD________-3",-3)
4793 mm.setFamiliesIdsOnGroup("HOMARD",[-1,-2,-3])
4795 eqName="MAILLES_A_RECOLLER_APRES_HOMARD"
4796 descEq="Cette equivalence decrit les mailles a recoller. Dans chaque correspondance, le premier numero est celui de la maille coupee ; le second numero est celui d'une des petites mailles en regard."
4797 mm.initializeEquivalences()
4798 eqs=mm.getEquivalences()
4799 eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4800 eq0.setDescription(descEq)
4801 corr=DataArrayInt([(0,3),(0,4),(0,5),(0,6),(1,7),(1,8),(1,9),(1,10),(2,11),(2,12),(2,13),(2,14)])
4802 eq0.setArray(-1,corr)
4803 self.assertEqual(eq0.getCell().size(),1)
4804 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4805 eq0.getCell().clear()
4806 self.assertEqual(eq0.getCell().size(),0)
4807 eq0.getCell().setArrayForType(NORM_QUAD4,corr)
4808 self.assertEqual(eq0.getCell().size(),1)
4809 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4810 mm.killEquivalences()
4811 mm.initializeEquivalences()
4812 eqs=mm.getEquivalences()
4813 eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4814 eq0.setDescription(descEq)
4816 c.setArrayForType(NORM_QUAD4,corr)
4817 self.assertEqual(eq0.getCell().size(),1)
4818 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4820 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4821 self.assertEqual(mm2.getEquivalences().size(),1)
4822 self.assertTrue(mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4).isEqual(corr))
4823 mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=2
4824 self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
4825 mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=0
4826 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4827 mm.write(fileName,2)
4829 mm3=MEDFileMesh.New(fileName)
4830 self.assertTrue(mm.isEqual(mm3,1e-12)[0])
4833 def testMEDFileForFamiliesPlayer1(self):
4834 """Non regression bug EDF11911. For serial killers using same family name to store both cells and nodes ! Only sky is the limit."""
4835 fileName="Pyfile98.med"
4837 magicSt="%s%%04i"%(MEDFileMesh.GetMagicFamilyStr())
4838 arr=DataArrayDouble(4) ; arr.iota()
4839 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4840 m=m.buildUnstructured()
4843 mm.setName(meshName)
4844 mm.setFamilyId("FAMILLE_ZERO",0)
4845 mm.getFamilyFieldAtLevel(0)[-3:]=-4
4846 mm.setFamilyId("RIDF%s"%(magicSt%0),-4)
4847 mm.setGroupsOnFamily("RIDF%s"%(magicSt%0),["RID"])
4848 d=DataArrayInt(16) ; d[:]=0 ; d[[1,2,4,5]]=3
4849 mm.setFamilyFieldArr(1,d)
4850 mm.setFamilyId("RIDF%s"%(magicSt%1),3)
4851 mm.setGroupsOnFamily("RIDF%s"%(magicSt%1),["RID"])
4852 self.assertEqual(mm.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4853 self.assertEqual(mm.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF")) # <- the aim of test is here !
4854 self.assertEqual(mm.getFamiliesIdsOnGroup("RID"),(-4,3))
4855 mm.write(fileName,2)
4856 # now read such funny file !
4857 mm2=MEDFileMesh.New(fileName) # <- normaly mdump of Pyfile98.med must contain only RID and FAMILLE_ZERO families.
4858 self.assertTrue(mm.isEqual(mm2,1e-16))
4859 self.assertEqual(mm2.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4860 self.assertEqual(mm2.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF"))
4861 self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too !
4864 def testCartesianizer1(self):
4865 """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """
4867 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
4868 mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts()
4869 d0=DataArrayInt(16) ; d0[:]=0
4870 d1=DataArrayInt(9) ; d1[:]=0
4871 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4872 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4873 ref0=mm.getCoords().getHiddenCppPointer()
4874 ref1=mm[0].getNodalConnectivity().getHiddenCppPointer()
4875 self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer())
4876 ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer()
4877 ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer()
4878 self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
4879 mm.setAxisType(AX_CYL) #<- important
4880 mm2=mm.cartesianize() # the trigger
4881 self.assertEqual(mm2.getAxisType(),AX_CART)
4882 mm.setAxisType(AX_CART) # this is here only to avoid complaints
4883 self.assertTrue(isinstance(mm2,MEDFileUMesh))
4884 self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
4885 self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important
4886 self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important
4887 self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer())
4888 self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
4889 self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important
4890 self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important
4891 self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important
4892 self.assertEqual(mm2.getName(),mm.getName())
4893 self.assertEqual(mm2.getDescription(),mm.getDescription())
4894 self.assertEqual(mm2.getTime(),mm.getTime())
4895 self.assertEqual(mm2.getTime(),mm.getTime())
4896 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4897 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4898 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4899 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4900 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4901 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4902 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4903 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4905 mm.setAxisType(AX_CART)
4906 mm2=mm.cartesianize() # the trigger
4907 self.assertEqual(mm2.getAxisType(),AX_CART)
4908 self.assertTrue(isinstance(mm2,MEDFileUMesh))
4909 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4910 # CurveLinearMesh non cart
4911 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear()
4912 mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
4913 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4914 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4915 ref0=mm.getMesh().getCoords().getHiddenCppPointer()
4916 mm2=mm.cartesianize() # the trigger
4917 self.assertEqual(mm2.getAxisType(),AX_CART)
4918 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4919 self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
4920 self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important
4921 self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important
4922 self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
4923 self.assertEqual(mm2.getName(),mm.getName())
4924 self.assertEqual(mm2.getDescription(),mm.getDescription())
4925 self.assertEqual(mm2.getTime(),mm.getTime())
4926 self.assertEqual(mm2.getTime(),mm.getTime())
4927 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4928 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4929 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4930 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4931 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4932 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4933 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4934 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4935 # CurveLinearMesh cart
4936 mm.setAxisType(AX_CART)
4937 mm2=mm.cartesianize() # the trigger
4938 self.assertEqual(mm2.getAxisType(),AX_CART)
4939 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4940 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4942 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4943 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
4944 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
4945 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
4946 mm2=mm.cartesianize() # the trigger
4947 self.assertEqual(mm2.getAxisType(),AX_CART)
4948 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
4949 self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
4950 self.assertEqual(mm2.getName(),mm.getName())
4951 self.assertEqual(mm2.getDescription(),mm.getDescription())
4952 self.assertEqual(mm2.getTime(),mm.getTime())
4953 self.assertEqual(mm2.getTime(),mm.getTime())
4954 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
4955 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
4956 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
4957 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
4958 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
4959 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
4960 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
4961 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
4963 mm.setAxisType(AX_CART)
4964 mm2=mm.cartesianize() # the trigger
4965 self.assertEqual(mm2.getAxisType(),AX_CART)
4966 self.assertTrue(isinstance(mm2,MEDFileCMesh))
4967 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
4970 def testCheckCoherency(self):
4971 m2 = MEDCouplingUMesh("2d", 2)
4972 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
4973 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
4974 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
4975 mum = MEDFileUMesh()
4976 mum.setMeshAtLevel(0, m2)
4977 mum.setMeshAtLevel(-1, m1)
4978 mum.checkConsistency()
4979 mum2 = mum.deepCopy()
4982 arr = DataArrayInt([2]*4)
4983 mum.setFamilyFieldArr(1, arr); arr.reAlloc(35);
4984 self.assertRaises(InterpKernelException, mum.checkConsistency)
4985 mum=mum2; mum2=mum.deepCopy();
4986 arr = DataArrayInt([2]*4)
4987 mum.setRenumFieldArr(1, arr); arr.reAlloc(35);
4988 self.assertRaises(InterpKernelException, mum.checkConsistency)
4989 mum=mum2; mum2=mum.deepCopy();
4990 mum.setRenumFieldArr(1, DataArrayInt([2]*4))
4991 self.assertRaises(InterpKernelException, mum.checkConsistency)
4992 mum=mum2; mum2=mum.deepCopy();
4993 arr = DataArrayAsciiChar(['tutu x']*4)
4994 mum.setNameFieldAtLevel(1, arr); arr.reAlloc(35);
4995 self.assertRaises(InterpKernelException, mum.checkConsistency)
4998 mum=mum2; mum2=mum.deepCopy();
4999 arr = DataArrayInt([2]*2)
5000 mum.setFamilyFieldArr(0, arr); arr.reAlloc(35);
5001 self.assertRaises(InterpKernelException, mum.checkConsistency)
5002 mum=mum2; mum2=mum.deepCopy();
5003 arr = DataArrayInt([2]*2)
5004 mum.setRenumFieldArr(0, arr); arr.reAlloc(35);
5005 self.assertRaises(InterpKernelException, mum.checkConsistency)
5006 mum=mum2; mum2=mum.deepCopy();
5007 mum.setRenumFieldArr(0, DataArrayInt([2]*2))
5008 self.assertRaises(InterpKernelException, mum.checkConsistency)
5009 mum=mum2; mum2=mum.deepCopy();
5010 arr = DataArrayAsciiChar(['tutu x']*2)
5011 mum.setNameFieldAtLevel(0, arr); arr.reAlloc(35);
5012 self.assertRaises(InterpKernelException, mum.checkConsistency)
5015 mum=mum2; mum2=mum.deepCopy();
5016 arr = DataArrayInt([2]*5)
5017 mum.setFamilyFieldArr(-1, arr); arr.reAlloc(35);
5018 self.assertRaises(InterpKernelException, mum.checkConsistency)
5019 mum=mum2; mum2=mum.deepCopy();
5020 arr = DataArrayInt([2]*5)
5021 mum.setRenumFieldArr(-1, arr); arr.reAlloc(35);
5022 self.assertRaises(InterpKernelException, mum.checkConsistency)
5023 mum=mum2; mum2=mum.deepCopy();
5024 mum.setRenumFieldArr(-1, DataArrayInt([2]*5))
5025 self.assertRaises(InterpKernelException, mum.checkConsistency)
5026 mum=mum2; mum2=mum.deepCopy();
5027 arr = DataArrayAsciiChar(['tutu x']*5)
5028 mum.setNameFieldAtLevel(-1, arr); arr.reAlloc(35);
5029 self.assertRaises(InterpKernelException, mum.checkConsistency)
5031 def testCheckSMESHConsistency(self):
5032 m2 = MEDCouplingUMesh("2d", 2)
5033 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5034 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5035 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5036 mum = MEDFileUMesh()
5037 mum.setMeshAtLevel(0, m2)
5038 mum.setMeshAtLevel(-1, m1)
5039 mum.checkConsistency()
5040 mum.checkSMESHConsistency()
5041 n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5042 n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5043 mum.setRenumFieldArr(0, n2)
5044 mum.setRenumFieldArr(-1, n1)
5045 self.assertRaises(InterpKernelException, mum.checkSMESHConsistency)
5046 mum.setRenumFieldArr(-1, n1+100)
5047 mum.checkSMESHConsistency()
5050 def testClearNodeAndCellNumbers(self):
5051 m2 = MEDCouplingUMesh("2d", 2)
5052 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5053 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5054 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5055 mum = MEDFileUMesh()
5056 mum.setMeshAtLevel(0, m2)
5057 mum.setMeshAtLevel(-1, m1)
5058 mum.checkConsistency()
5059 n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5060 n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5061 mum.setRenumFieldArr(0, n2)
5062 mum.setRenumFieldArr(-1, n1)
5063 mum.clearNodeAndCellNumbers()
5064 mum.checkSMESHConsistency()
5067 def testCMeshSetFamilyFieldArrNull(self):
5069 fname="Pyfile99.med"
5070 arrX=DataArrayDouble([0,1,2,3])
5071 arrY=DataArrayDouble([0,1,2])
5072 m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m.setName(meshName)
5073 mm=MEDFileCMesh() ; mm.setMesh(m)
5074 famCellIds=DataArrayInt([0,-2,-2,-1,-2,0])
5075 famNodeIds=DataArrayInt([0,0,0,3,4,1,2,7,2,1,0,0])
5076 mm.setFamilyFieldArr(0,famCellIds)
5077 mm.setFamilyFieldArr(1,famNodeIds)
5079 mm=MEDFileMesh.New(fname)
5080 self.assertTrue(mm.getFamilyFieldAtLevel(0) is not None)
5081 self.assertTrue(mm.getFamilyFieldAtLevel(1) is not None)
5082 mm.setFamilyFieldArr(0,None)#<- bug was here
5083 mm.setFamilyFieldArr(1,None)#<- bug was here
5084 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
5085 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
5087 self.assertTrue(mm3.getFamilyFieldAtLevel(0) is None)
5088 self.assertTrue(mm3.getFamilyFieldAtLevel(1) is None)
5090 mm2=MEDFileMesh.New(fname)
5091 self.assertTrue(mm2.getFamilyFieldAtLevel(0) is None)
5092 self.assertTrue(mm2.getFamilyFieldAtLevel(1) is None)
5095 def testAppendFieldProfileOnIntField(self):
5096 fname="Pyfile100.med"
5097 arrX=DataArrayDouble([0,1,2,3])
5098 arrY=DataArrayDouble([0,1,2])
5099 mesh=MEDCouplingCMesh() ; mesh.setCoords(arrX,arrY) ; mesh.setName("Mesh")
5103 fmts=MEDFileIntFieldMultiTS()
5105 pfl=DataArrayInt([1,3,5]) ; pfl.setName(pflName)
5106 f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(mesh)
5107 fieldName="FieldOnCell"
5108 f.setTime(1.2,1,1) ; f.setName(fieldName)
5109 arr=DataArrayInt([101,102,103]) ; f.setArray(arr)
5110 fmts.appendFieldProfile(f,mm,0,pfl)
5115 mm=MEDFileMesh.New(fname)
5116 fmts=MEDFileAnyTypeFieldMultiTS.New(fname)
5117 self.assertTrue(isinstance(fmts,MEDFileIntFieldMultiTS))
5118 self.assertEqual(fmts.getName(),fieldName)
5119 self.assertEqual(len(fmts),1)
5121 ftest,pfltest=f1ts.getFieldWithProfile(ON_CELLS,0,mm)
5122 self.assertEqual(pfltest.getName(),pflName)
5123 self.assertEqual(ftest.getName(),fieldName)
5124 self.assertTrue(ftest.isEqualWithoutConsideringStr(arr))
5125 ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
5126 self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr))
5127 self.assertEqual(ftest2.getTime(),f.getTime())
5128 self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr))
5131 def testMEDFileFieldEasyField1(self):
5132 """Check for all spatial discretization of field (cells,nodes,elno,gauss) for double field that all is OK. Here no profile and only top level is considered."""
5133 ## Basic test on cells on top level
5134 fname="Pyfile101.med"
5137 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5138 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5140 m.insertNextCell(NORM_TRI3,[0,1,2])
5141 m.insertNextCell(NORM_TRI3,[3,4,5])
5142 m.insertNextCell(NORM_TRI3,[6,7,8])
5143 m.insertNextCell(NORM_TRI3,[9,10,11])
5144 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5145 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5148 arr0=DataArrayDouble([10,11,12,13,100,101])
5149 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5150 f.setName(fieldName) ; f.setTime(2.,6,7)
5152 ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5154 arr2=arr0+1000 ; f.setArray(arr2)
5155 f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f)
5159 mm=MEDFileMesh.New(fname)
5160 f1ts=MEDFileField1TS(fname,fieldName,6,7)
5161 ftst0=f1ts.field(mm)
5162 self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12))
5163 f1ts=MEDFileField1TS(fname,fieldName,8,9)
5164 ftst1=f1ts.field(mm)
5165 self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12))
5166 fmts=MEDFileFieldMultiTS(fname,fieldName)
5167 self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12))
5168 ## Basic test on nodes on top level
5169 f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5170 f2.setName(fieldName)
5172 ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5174 mm=MEDFileMesh.New(fname)
5175 f1ts=MEDFileField1TS(fname,fieldName,23,24)
5176 self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12))
5177 fmts=MEDFileFieldMultiTS(fname,fieldName)
5178 self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12))
5180 f3=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
5181 f3.setName(fieldName) ; f3.checkConsistencyLight()
5182 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5184 mm=MEDFileMesh.New(fname)
5185 f1ts=MEDFileField1TS(fname,fieldName,2,3)
5186 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5188 f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5189 f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,1.],[0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5],[0.2,0.3,0.1,0.05,0.35])
5190 f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5)
5191 arr4=DataArrayDouble([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
5192 f4.checkConsistencyLight()
5193 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5195 mm=MEDFileMesh.New(fname)
5196 f1ts=MEDFileField1TS(fname,fieldName,4,5)
5197 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5200 def testMEDFileFieldEasyField2(self):
5201 """Same thantestMEDFileFieldEasyField1 except that here intfields are considered.
5202 Check for all spatial discretization of field (cells,nodes,elno,gauss) for int field that all is OK. Here no profile and only top level is considered."""
5203 ## Basic test on cells on top level
5204 fname="Pyfile102.med"
5207 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5208 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5210 m.insertNextCell(NORM_TRI3,[0,1,2])
5211 m.insertNextCell(NORM_TRI3,[3,4,5])
5212 m.insertNextCell(NORM_TRI3,[6,7,8])
5213 m.insertNextCell(NORM_TRI3,[9,10,11])
5214 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5215 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5218 arr0=DataArrayInt([10,11,12,13,100,101])
5219 f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5220 f.setName(fieldName) ; f.setTime(2.,6,7)
5222 ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5224 arr2=arr0+1000 ; f.setArray(arr2)
5225 f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f)
5229 mm=MEDFileMesh.New(fname)
5230 f1ts=MEDFileIntField1TS(fname,fieldName,6,7)
5231 ftst0=f1ts.field(mm)
5232 self.assertTrue(f0.isEqual(ftst0,1e-12,0))
5233 f1ts=MEDFileIntField1TS(fname,fieldName,8,9)
5234 ftst1=f1ts.field(mm)
5235 self.assertTrue(f1.isEqual(ftst1,1e-12,0))
5236 fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5237 self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,0))
5238 ## Basic test on nodes on top level
5239 f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5240 f2.setName(fieldName)
5242 ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5244 mm=MEDFileMesh.New(fname)
5245 f1ts=MEDFileIntField1TS(fname,fieldName,23,24)
5246 self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,0))
5247 fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5248 self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,0))
5250 f3=MEDCouplingFieldInt(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
5251 f3.setName(fieldName) ; f3.checkConsistencyLight()
5252 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5254 mm=MEDFileMesh.New(fname)
5255 f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5256 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5258 f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5259 f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,1.],[0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5],[0.2,0.3,0.1,0.05,0.35])
5260 f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5)
5261 arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
5262 f4.checkConsistencyLight()
5263 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5265 mm=MEDFileMesh.New(fname)
5266 f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5267 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5270 def testMEDFileFieldEasyField3(self):
5271 """Here a multi level mesh. And field on cells lying on different level of this mesh. Show how "field" method deal with that. Here on field double are considered."""
5272 fname="Pyfile103.med"
5275 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5276 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5278 m.insertNextCell(NORM_TRI3,[0,1,2])
5279 m.insertNextCell(NORM_TRI3,[3,4,5])
5280 m.insertNextCell(NORM_TRI3,[6,7,8])
5281 m.insertNextCell(NORM_TRI3,[9,10,11])
5282 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5283 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5285 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5287 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5288 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5292 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5293 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5295 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2)
5296 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5297 # here f1 lying on level -1 not 0 check if "field" method detect it !
5298 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5299 f1.setMesh(mm[-1]) # -1 is very important
5301 f1.checkConsistencyLight()
5303 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5305 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4)
5306 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5308 f3=MEDCouplingFieldDouble(ON_GAUSS_NE)
5309 f3.setMesh(mm[-1]) # this line is important
5310 arr3=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
5311 f3.setName(fieldName) ; f3.checkConsistencyLight()
5312 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5314 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3)
5315 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5317 f4=MEDCouplingFieldDouble(ON_GAUSS_PT)
5318 f4.setMesh(mm[-1]) # this line is important
5319 f4.setName(fieldName)
5320 f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,1.],[0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5],[0.2,0.3,0.1,0.05,0.35])
5321 f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5)
5322 arr4=DataArrayDouble([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
5323 f4.checkConsistencyLight()
5324 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5325 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5)
5326 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5329 def testMEDFileFieldEasyField4(self):
5330 """ Same than testMEDFileFieldEasyField3 but with integers"""
5331 fname="Pyfile104.med"
5334 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5335 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5337 m.insertNextCell(NORM_TRI3,[0,1,2])
5338 m.insertNextCell(NORM_TRI3,[3,4,5])
5339 m.insertNextCell(NORM_TRI3,[6,7,8])
5340 m.insertNextCell(NORM_TRI3,[9,10,11])
5341 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5342 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5344 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5346 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5347 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5351 f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5352 f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5354 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2)
5355 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5356 # here f1 lying on level -1 not 0 check if "field" method detect it !
5357 f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5358 f1.setMesh(mm[-1]) # -1 is very important
5360 f1.checkConsistencyLight()
5362 f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5364 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4)
5365 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5367 f3=MEDCouplingFieldInt(ON_GAUSS_NE)
5368 f3.setMesh(mm[-1]) # this line is important
5369 arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
5370 f3.setName(fieldName) ; f3.checkConsistencyLight()
5371 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5373 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5374 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5376 f4=MEDCouplingFieldInt(ON_GAUSS_PT)
5377 f4.setMesh(mm[-1]) # this line is important
5378 f4.setName(fieldName)
5379 f4.setGaussLocalizationOnType(NORM_TRI3,[0.,0.,1.,0.,1.,1.],[0.1,0.1, 0.2,0.2, 0.3,0.3, 0.4,0.4, 0.5,0.5],[0.2,0.3,0.1,0.05,0.35])
5380 f4.setGaussLocalizationOnType(NORM_QUAD4,[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.4, 0.6,0.7],[0.7,0.3]) ; f4.setTime(0.25,4,5)
5381 arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
5382 f4.checkConsistencyLight()
5383 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5384 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5385 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5388 def testMEDFileFieldEasyField5(self):
5389 """More and more difficult now look at how profiles are managed by "field" method."""
5390 fname="Pyfile105.med"
5393 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5394 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5396 m.insertNextCell(NORM_TRI3,[0,1,2])
5397 m.insertNextCell(NORM_TRI3,[3,4,5])
5398 m.insertNextCell(NORM_TRI3,[6,7,8])
5399 m.insertNextCell(NORM_TRI3,[9,10,11])
5400 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5401 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5404 pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl")
5405 m2=m.deepCopy()[pfl] ; m2.setName(m.getName())
5407 arr0=DataArrayDouble([10,11,12,13])
5408 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2)
5409 f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight()
5410 ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile
5413 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5414 self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5415 # more complicated -> multi level
5416 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5418 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5419 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5421 mm2[0]=m0 ; mm2[-1]=m
5423 ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl)
5425 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5426 self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5429 def testExtractPart1(self):
5430 coo=DataArrayDouble([(0,0),(1,0),(2,0),(3,0),(4,0),(0,1),(1,1),(2,1),(3,1),(4,1),(0,2),(1,2),(2,2),(3,2),(4,2)])
5432 m0=MEDCouplingUMesh(meshName,2) ; m0.setCoords(coo) ; m0.allocateCells()
5433 m0.insertNextCell(NORM_TRI3,[8,4,3])
5434 m0.insertNextCell(NORM_TRI3,[8,9,4])
5435 m0.insertNextCell(NORM_TRI3,[7,13,8])
5436 m0.insertNextCell(NORM_TRI3,[7,12,13])
5437 m0.insertNextCell(NORM_TRI3,[0,6,1])
5438 m0.insertNextCell(NORM_TRI3,[0,5,6])
5439 m0.insertNextCell(NORM_QUAD4,[1,6,7,2])
5440 m0.insertNextCell(NORM_QUAD4,[2,7,8,3])
5441 m0.insertNextCell(NORM_QUAD4,[8,13,14,9])
5442 m0.insertNextCell(NORM_QUAD4,[6,11,12,7])
5443 m0.insertNextCell(NORM_QUAD4,[5,10,11,6])
5445 m1=MEDCouplingUMesh(meshName,1) ; m1.setCoords(coo) ; m1.allocateCells()
5446 m1.insertNextCell(NORM_SEG2,[10,5])
5447 m1.insertNextCell(NORM_SEG2,[5,0])
5448 m1.insertNextCell(NORM_SEG2,[0,1])
5449 m1.insertNextCell(NORM_SEG2,[1,2])
5450 m1.insertNextCell(NORM_SEG2,[2,3])
5451 m1.insertNextCell(NORM_SEG2,[3,4])
5452 m1.insertNextCell(NORM_SEG2,[4,9])
5453 m1.insertNextCell(NORM_SEG2,[9,14])
5454 m1.insertNextCell(NORM_SEG2,[14,13])
5455 m1.insertNextCell(NORM_SEG2,[13,12])
5456 m1.insertNextCell(NORM_SEG2,[12,11])
5457 m1.insertNextCell(NORM_SEG2,[11,10])
5459 mm[0]=m0 ; mm[-1]=m1
5460 arr0=DataArrayInt([0,1,2,3,4,6,7,8,12,13])
5462 tab[0]=DataArrayInt([0,2,3,4,6,7])
5463 tab[-1]=DataArrayInt([2,3,4,5,9])
5465 self.assertTrue(mm.deduceNodeSubPartFromCellSubPart(tab).isEqual(arr0))
5469 fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5472 arr0_0=DataArrayDouble([100,101,102,103,104,105,106,107,108,109,110]) ; arr0_0.setInfoOnComponents(ic)
5473 f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*t0) ; f0.setArray(arr0_0)
5474 f0.setMesh(m0) ; f0.setName(fname0)
5475 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setTime(*t0) ; f1.setArray(DataArrayDouble([200,201,202,203,204,205,206,207,208,209,210,211]))
5476 f1.setMesh(m1) ; f1.setName(fname0) ; f1.getArray().setInfoOnComponents(ic)
5477 f2=MEDCouplingFieldDouble(ON_NODES) ; f2.setTime(*t0) ; f2.setArray(DataArrayDouble([300,301,302,303,304,305,306,307,308,309,310,311,312,313,314]))
5478 f2.setMesh(m0) ; f2.setName(fname0) ; f2.getArray().setInfoOnComponents(ic)
5479 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.setFieldNoProfileSBT(f2)
5480 fmts.pushBackTimeStep(f1ts)
5482 mmOut=mm.extractPart(tab)
5484 fsPart0=fs.extractPart(tab,mm)
5485 self.assertEqual(len(fsPart0),1)
5487 self.assertEqual(len(fmtsP),1)
5489 self.assertRaises(InterpKernelException,f1ts.field,mmOut)
5491 self.assertTrue(mmOut[0].computeCellCenterOfMass().isEqual(m0[tab[0]].computeCellCenterOfMass(),1e-12))
5492 self.assertTrue(mmOut[-1].computeCellCenterOfMass().isEqual(m1[tab[-1]].computeCellCenterOfMass(),1e-12))
5494 m0Part=m0.deepCopy()[tab[0]] ; m0Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m0Part.setName(m0.getName())
5495 self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5496 m1Part=m1.deepCopy()[tab[-1]] ; m1Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m1Part.setName(m0.getName())
5497 self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5498 self.assertTrue(mmOut[-1].isEqual(m1Part,1e-12))
5500 f0Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mmOut) ; f0Part.checkConsistencyLight()
5501 self.assertEqual(f0Part.getTypeOfField(),ON_CELLS)
5502 self.assertTrue(f0Part.getMesh().isEqual(m0Part,1e-12))
5503 arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic)
5504 self.assertTrue(f0Part.getArray().isEqual(arr0Exp,1e-12)) ; self.assertEqual(f0Part.getTime(),list(t0))
5505 f1Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,-1,mmOut) ; f1Part.checkConsistencyLight()
5506 self.assertEqual(f1Part.getTypeOfField(),ON_CELLS)
5507 self.assertTrue(f1Part.getMesh().isEqual(m1Part,1e-12))
5508 arr1Exp=DataArrayDouble([202,203,204,205,209]) ; arr1Exp.setInfoOnComponents(ic)
5509 self.assertTrue(f1Part.getArray().isEqual(arr1Exp,1e-12)) ; self.assertEqual(f1Part.getTime(),list(t0))
5511 f2Part=f1ts.getFieldOnMeshAtLevel(ON_NODES,0,mmOut) ; f2Part.checkConsistencyLight()
5512 arr2Exp=DataArrayDouble([300,301,302,303,304,306,307,308,312,313]) ; arr2Exp.setInfoOnComponents(ic)
5513 self.assertTrue(f2Part.getArray().isEqual(arr2Exp,1e-12)) ; self.assertEqual(f2Part.getTime(),list(t0))
5515 fs=MEDFileFields() ; fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5516 tss=[(16.5,3,4),(17.5,4,5),(18.5,5,6)]
5517 for i,tt in enumerate(tss):
5518 f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*tt)
5519 myarr=arr0_0+i*1000.
5521 f0.setMesh(m0) ; f0.setName(fname0) ; f0.getArray().setInfoOnComponents(ic)
5522 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; fmts.pushBackTimeStep(f1ts)
5524 fsPart1=fs.extractPart(tab,mm)
5525 self.assertEqual(len(fsPart1),1)
5527 self.assertEqual(len(fmtsP),len(tss))
5528 for i,(f1tsP,tt) in enumerate(zip(fmtsP,tss)):
5529 fPart=f1tsP.field(mmOut) ; fPart.checkConsistencyLight()
5530 self.assertEqual(fPart.getTypeOfField(),ON_CELLS)
5531 arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic) ; arr0Exp+=i*1000.
5532 self.assertTrue(fPart.getMesh().isEqual(m0Part,1e-12))
5533 self.assertTrue(fPart.getArray().isEqual(arr0Exp,1e-12))
5534 self.assertEqual(fPart.getTime(),list(tt))
5538 def testSymmetryPlusAggregationMFD1(self):
5539 """ Testing of MEDFileData::Aggregate and MEDFileUMesh::Aggregate and MEDFileUMesh::getAllDistributionOfType """
5540 fname1="Pyfile106_1.med"
5541 fname2="Pyfile106_2.med"
5542 fname3="Pyfile106_3.med"
5545 da1=DataArrayDouble([1,2,10,3,4,11,5,6,12,7,8,13],4,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5547 mm1_0=MEDCouplingUMesh(meshName,3) ; mm1_0.allocateCells()
5548 mm1_0.setCoords(da1)
5549 mm1_0.insertNextCell(NORM_TETRA4,[0,1,2,3])
5550 mm1_0.insertNextCell(NORM_TETRA4,[4,5,6,7])
5551 mm1_0.insertNextCell(NORM_PENTA6,[8,9,10,11,12,13])
5552 mm1_0.insertNextCell(NORM_PENTA6,[14,15,16,17,18,19])
5553 mm1_0.insertNextCell(NORM_PENTA6,[20,21,22,23,24,25])
5555 mm1.setFamilyFieldArr(0,DataArrayInt([1,2,3,4,5]))
5556 mm1.setRenumFieldArr(0,DataArrayInt([11,12,13,14,15]))
5558 mm1_1=MEDCouplingUMesh(meshName,2) ; mm1_1.allocateCells()
5559 mm1_1.setCoords(da1)
5560 mm1_1.insertNextCell(NORM_TRI3,[0,1,2])
5561 mm1_1.insertNextCell(NORM_TRI3,[3,4,5])
5562 mm1_1.insertNextCell(NORM_QUAD4,[6,7,8,9])
5563 mm1_1.insertNextCell(NORM_QUAD4,[10,11,12,13])
5564 mm1_1.insertNextCell(NORM_QUAD4,[14,15,16,17])
5565 mm1_1.insertNextCell(NORM_QUAD4,[18,19,20,21])
5567 mm1.setFamilyFieldArr(-1,DataArrayInt([6,7,8,9,10,11]))
5568 mm1.setRenumFieldArr(-1,DataArrayInt([16,17,18,19,20,21]))
5569 for i in range(1,10):
5570 mm1.setFamilyId("F%d"%i,i)
5571 mm1.setFamilyId("FAMILLE_ZERO",0)
5572 mm1.setFamilyId("H1",100)
5573 mm1.setFamiliesOnGroup("myGRP",["F2","F6"])
5574 mm1.setFamiliesOnGroup("myGRP1",["F2","F6"])
5575 mm1.setFamilyFieldArr(1,DataArrayInt([12,13,14,15]))
5576 mm1.setRenumFieldArr(1,DataArrayInt([22,23,24,25]))
5579 da1=DataArrayDouble([9,10,30,11,12,31,13,14,32,15,16,33,17,18,34],5,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5581 mm2_0=MEDCouplingUMesh(meshName,3) ; mm2_0.allocateCells()
5582 mm2_0.setCoords(da1)
5583 mm2_0.insertNextCell(NORM_TETRA4,[100,101,102,103])
5584 mm2_0.insertNextCell(NORM_TETRA4,[104,105,106,107])
5585 mm2_0.insertNextCell(NORM_TETRA4,[108,109,110,111])
5586 mm2_0.insertNextCell(NORM_PENTA6,[112,113,114,115,116,117])
5588 mm2.setFamilyFieldArr(0,DataArrayInt([40,41,42,43]))
5589 mm2.setRenumFieldArr(0,DataArrayInt([50,51,52,53]))
5591 mm2_1=MEDCouplingUMesh(meshName,2) ; mm2_1.allocateCells()
5592 mm2_1.setCoords(da1)
5593 mm2_1.insertNextCell(NORM_TRI3,[100,101,102])
5594 mm2_1.insertNextCell(NORM_TRI3,[103,104,105])
5595 mm2_1.insertNextCell(NORM_TRI3,[106,107,108])
5596 mm2_1.insertNextCell(NORM_QUAD4,[109,110,111,112])
5597 mm2_1.insertNextCell(NORM_QUAD4,[113,114,115,116])
5598 mm2_1.insertNextCell(NORM_QUAD4,[117,118,119,120])
5599 mm2_1.insertNextCell(NORM_QUAD4,[121,122,123,124])
5600 mm2_1.insertNextCell(NORM_QUAD4,[125,126,127,128])
5602 mm2.setFamilyFieldArr(-1,DataArrayInt([200,201,202,203,204,205,206,207]))
5603 mm2.setRenumFieldArr(-1,DataArrayInt([300,301,302,303,304,305,306,307]))
5604 for i in range(1,12):
5605 mm2.setFamilyId("G%d"%i,i+30)
5606 mm2.setFamilyId("H1",100)
5607 mm2.setFamilyId("FAMILLE_ZERO",0)
5608 mm2.setFamiliesOnGroup("myGRP",["G2","G6"])
5609 mm2.setFamiliesOnGroup("myGRP2",["G4","G7"])
5610 mm2.setFamilyFieldArr(1,DataArrayInt([112,113,114,115,116]))
5611 mm2.setRenumFieldArr(1,DataArrayInt([122,123,124,125,126]))
5613 mm=MEDFileUMesh.Aggregate([mm1,mm2])
5615 def CheckMesh(tester,mm):
5616 cooExp=DataArrayDouble([(1,2,10),(3,4,11),(5,6,12),(7,8,13),(9,10,30),(11,12,31),(13,14,32),(15,16,33),(17,18,34)]) ; cooExp.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5617 tester.assertTrue(mm.getCoords().isEqual(cooExp,1e-12))
5618 tester.assertTrue(mm[0].getNodalConnectivity().isEqual(DataArrayInt([14,0,1,2,3,14,4,5,6,7,14,104,105,106,107,14,108,109,110,111,14,112,113,114,115,16,8,9,10,11,12,13,16,14,15,16,17,18,19,16,20,21,22,23,24,25,16,116,117,118,119,120,121])))
5619 tester.assertTrue(mm[0].getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,32,39,46,53])))
5620 tester.assertTrue(mm[-1].getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,3,3,4,5,3,104,105,106,3,107,108,109,3,110,111,112,4,6,7,8,9,4,10,11,12,13,4,14,15,16,17,4,18,19,20,21,4,113,114,115,116,4,117,118,119,120,4,121,122,123,124,4,125,126,127,128,4,129,130,131,132])))
5621 tester.assertTrue(mm[-1].getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20,25,30,35,40,45,50,55,60,65])))
5622 tester.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([1,2,40,41,42,3,4,5,43])))
5623 tester.assertTrue(mm.getNumberFieldAtLevel(0).isEqual(DataArrayInt([11,12,50,51,52,13,14,15,53])))
5624 tester.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(DataArrayInt([6,7,200,201,202,8,9,10,11,203,204,205,206,207])))
5625 tester.assertTrue(mm.getNumberFieldAtLevel(-1).isEqual(DataArrayInt([16,17,300,301,302,18,19,20,21,303,304,305,306,307])))
5626 refFamIds=[("FAMILLE_ZERO",0),('F1',1),('F2',2),('F3',3),('F4',4),('F5',5),('F6',6),('F7',7),('F8',8),('F9',9),('G1',31),('G10',40),('G11',41),('G2',32),('G3',33),('G4',34),('G5',35),('G6',36),('G7',37),('G8',38),('G9',39),("H1",100)]
5627 tester.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
5628 tester.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
5629 tester.assertEqual(mm.getGroupsNames(),('myGRP','myGRP1','myGRP2'))
5630 tester.assertEqual(mm.getAllDistributionOfTypes(),[(NORM_TRI3,5),(NORM_QUAD4,9),(NORM_TETRA4,5),(NORM_PENTA6,4),(NORM_ERROR,9)])
5637 infoc=["dd [W]","eee [kA]"]
5639 fmts1=MEDFileFieldMultiTS()
5640 f1ts1=MEDFileField1TS()
5641 f1_1=MEDCouplingFieldDouble(ON_CELLS) ; f1_1.setMesh(mm1[0]) ; f1_1.setName(fieldName)
5642 arr1=DataArrayDouble([(10,110),(11,111),(12,112),(13,113),(14,114)])
5643 arr1.setInfoOnComponents(infoc)
5644 f1_1.setArray(arr1) ; f1_1.setTime(*t1) ; f1_1.setTimeUnit("ms")
5645 f1_1.checkConsistencyLight()
5646 f1ts1.setFieldNoProfileSBT(f1_1)
5648 f1_2=MEDCouplingFieldDouble(ON_CELLS) ; f1_2.setMesh(mm1[-1]) ; f1_2.setName(fieldName)
5649 arr2=DataArrayDouble([(15,115),(16,116),(17,117),(18,118),(19,119),(20,120)])
5650 arr2.setInfoOnComponents(infoc)
5651 f1_2.setArray(arr2) ; f1_2.setTime(*t1) ; f1_2.setTimeUnit("ms")
5652 f1_2.checkConsistencyLight()
5653 f1ts1.setFieldNoProfileSBT(f1_2)
5654 f1_3=MEDCouplingFieldDouble(ON_NODES) ; f1_3.setMesh(mm1[0]) ; f1_3.setName(fieldName)
5655 arr3=DataArrayDouble([(21,121),(22,122),(23,123),(24,124)])
5656 arr3.setInfoOnComponents(infoc)
5657 f1_3.setArray(arr3) ; f1_3.setTime(*t1) ; f1_3.setTimeUnit("ms")
5658 f1_3.checkConsistencyLight()
5659 f1ts1.setFieldNoProfileSBT(f1_3)
5660 fmts1.pushBackTimeStep(f1ts1)
5662 f1ts2=f1ts1.deepCopy()
5663 f1ts2.setTime(t2[1],t2[2],t2[0])
5664 f1ts2.getUndergroundDataArray()[:]+=2000
5665 fmts1.pushBackTimeStep(f1ts2)
5667 fmts2=MEDFileFieldMultiTS()
5668 f1ts3=MEDFileField1TS()
5669 f2_1=MEDCouplingFieldDouble(ON_CELLS) ; f2_1.setMesh(mm2[0]) ; f2_1.setName(fieldName)
5670 arr4=DataArrayDouble([(50,150),(51,151),(52,152),(53,153)])
5671 arr4.setInfoOnComponents(infoc)
5672 f2_1.setArray(arr4) ; f2_1.setTime(*t1) ; f2_1.setTimeUnit("ms")
5673 f2_1.checkConsistencyLight()
5674 f1ts3.setFieldNoProfileSBT(f2_1)
5675 f2_2=MEDCouplingFieldDouble(ON_CELLS) ; f2_2.setMesh(mm2[-1]) ; f2_2.setName(fieldName)
5676 arr5=DataArrayDouble([(54,154),(55,155),(56,156),(57,157),(158,158),(59,159),(60,160),(61,161)])
5677 arr5.setInfoOnComponents(infoc)
5678 f2_2.setArray(arr5) ; f2_2.setTime(*t1) ; f2_2.setTimeUnit("ms")
5679 f2_2.checkConsistencyLight()
5680 f1ts3.setFieldNoProfileSBT(f2_2)
5681 f2_3=MEDCouplingFieldDouble(ON_NODES) ; f2_3.setMesh(mm2[0]) ; f2_3.setName(fieldName)
5682 arr6=DataArrayDouble([(62,162),(63,163),(64,164),(65,165),(66,166)])
5683 arr6.setInfoOnComponents(infoc)
5684 f2_3.setArray(arr6) ; f2_3.setTime(*t1) ; f2_3.setTimeUnit("ms")
5685 f2_3.checkConsistencyLight()
5686 f1ts3.setFieldNoProfileSBT(f2_3)
5687 fmts2.pushBackTimeStep(f1ts3)
5689 f1ts4=f1ts3.deepCopy()
5690 f1ts4.setTime(t2[1],t2[2],t2[0])
5691 f1ts4.getUndergroundDataArray()[:]+=2000
5692 fmts2.pushBackTimeStep(f1ts4)
5695 mfd1.setMeshes(MEDFileMeshes())
5696 mfd1.getMeshes().pushMesh(mm1)
5697 mfd1.setFields(MEDFileFields())
5698 mfd1.getFields().pushField(fmts1)
5701 mfd2.setMeshes(MEDFileMeshes())
5702 mfd2.getMeshes().pushMesh(mm2)
5703 mfd2.setFields(MEDFileFields())
5704 mfd2.getFields().pushField(fmts2)
5706 mfd=MEDFileData.Aggregate([mfd1,mfd2])
5707 def CheckMFD(tester,mfd):
5708 tester.assertEqual(len(mfd.getMeshes()),1)
5709 tester.assertEqual(len(mfd.getFields()),1)
5710 CheckMesh(self,mfd.getMeshes()[0])
5711 tester.assertEqual(len(mfd.getFields()[0]),2)
5712 zeF1=mfd.getFields()[0][0]
5713 zeF1_1=zeF1.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5714 ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5715 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5716 ref.renumberCells(o2n)
5717 tester.assertTrue(ref.isEqual(zeF1_1,1e-12,1e-12))
5718 zeF1_2=zeF1.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5719 ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5720 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5721 ref.renumberCells(o2n)
5722 tester.assertTrue(ref.isEqual(zeF1_2,1e-12,1e-12))
5723 zeF1_3=zeF1.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5724 ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5725 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5726 ref.renumberCells(o2n)
5727 tester.assertTrue(ref.isEqual(zeF1_3,1e-12,1e-12))
5729 zeF2=mfd.getFields()[0][1]
5730 zeF2_1=zeF2.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5731 ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5732 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5733 ref.renumberCells(o2n)
5734 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5735 tester.assertTrue(ref.isEqual(zeF2_1,1e-12,1e-12))
5736 zeF2_2=zeF2.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5737 ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5738 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5739 ref.renumberCells(o2n)
5740 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5741 tester.assertTrue(ref.isEqual(zeF2_2,1e-12,1e-12))
5742 zeF2_3=zeF2.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5743 ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5744 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5745 ref.renumberCells(o2n)
5746 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5747 tester.assertTrue(ref.isEqual(zeF2_3,1e-12,1e-12))
5749 mfd1.write(fname1,2) ; mfd2.write(fname2,2)
5750 mfd=MEDFileData.Aggregate([MEDFileData(fname1),MEDFileData(fname2)])
5754 def testExtrudedMesh1(self):
5755 fname="Pyfile107.med"
5756 arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5])
5757 mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ) ; mesh3D.setName("mesh")
5758 ex=MEDCouplingMappedExtrudedMesh(mesh3D)
5761 ex2=mm.convertToExtrudedMesh()
5762 mm2=MEDFileMesh.New(fname)
5763 ex3=mm2.convertToExtrudedMesh()
5764 self.assertTrue(ex.isEqual(ex2,1e-12))
5765 self.assertTrue(ex.isEqual(ex3,1e-12))
5768 @unittest.skipUnless(LooseVersion(MEDFileVersionStr())>=LooseVersion('3.2.1'),"This test requires at least MEDFile version 3.2.1")
5769 def testWriteInto30(self):
5770 fname="Pyfile108.med"
5771 fname2="Pyfile109.med"
5772 m=MEDCouplingUMesh("mesh",1) ; m.setCoords(DataArrayDouble([0,0,1,1],2,2)) ; m.allocateCells() ; m.insertNextCell(NORM_SEG2,[1,0])
5773 mm=MEDFileUMesh() ; mm[0]=m
5774 mm.setFamilyId("FAMILLE_ZERO",0)
5777 assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==[3,0]) # checks that just written MED file has a version == 3.0.x
5778 mm2=MEDFileUMesh(fname)
5779 self.assertTrue(mm.isEqual(mm2,1e-12))
5782 assert(LooseVersion(MEDFileVersionOfFileStr(fname2)).version[:2]==list(MEDFileVersion()[:2])) # checks that MED file version of written mesh is thoose of the current MED file lib
5785 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
5786 def testPickelizationOfMEDFileObjects1(self):
5787 fname="Pyfile110.med"
5788 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)
5789 m0=MEDCouplingUMesh("Mesh",2)
5791 m0.insertNextCell(NORM_TRI3,[1,4,2])
5792 m0.insertNextCell(NORM_TRI3,[4,5,2])
5793 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
5794 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
5795 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
5796 m0.finishInsertingCells()
5798 m1=MEDCouplingUMesh(m0.getName(),1)
5800 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
5802 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
5804 m1.finishInsertingCells()
5808 m.setMeshAtLevel(0,m0)
5809 m.setMeshAtLevel(-1,m1)
5811 dt=3 ; it=2 ; tim=4.5
5812 fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
5813 fieldNode0.setName("fieldNode0")
5814 fieldNode0.setTime(tim,dt,it)
5815 pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
5816 arr=DataArrayDouble([10,11,12,13,14])
5817 fieldNode0.setArray(arr)
5818 f0=MEDFileField1TS()
5819 f0.setFieldProfile(fieldNode0,m,0,pfl0)
5820 fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
5821 fieldNode1.setName("fieldNode1")
5822 fieldNode1.setTime(tim,dt,it)
5823 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
5824 arr1=DataArrayDouble([20,21,22,23,24,25,26])
5825 fieldNode1.setArray(arr1)
5826 f1=MEDFileField1TS()
5827 f1.setFieldProfile(fieldNode1,m,-1,pfl1)
5829 mfd.setMeshes(MEDFileMeshes()) ; mfd.setFields(MEDFileFields())
5830 mfd.getMeshes().pushMesh(m)
5831 fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(f0)
5832 mfd.getFields().pushField(fmts)
5833 # first start gently
5836 self.assertEqual(len(mfd2.getMeshes()),1)
5837 self.assertEqual(len(mfd2.getFields()),1)
5838 self.assertEqual(len(mfd2.getFields()[0]),1)
5839 self.assertTrue(mfd2.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
5840 ff2=mfd2.getFields()[0][0].field(mfd2.getMeshes()[0])
5841 ff =mfd.getFields()[0][0].field(mfd.getMeshes()[0])
5842 self.assertTrue(ff2.isEqual(ff,1e-12,1e-12))
5843 # OK now end of joke -> serialization of MEDFileData
5844 st=pickle.dumps(mfd,pickle.HIGHEST_PROTOCOL)
5845 mfd3=pickle.loads(st)
5847 self.assertEqual(len(mfd3.getMeshes()),1)
5848 self.assertEqual(len(mfd3.getFields()),1)
5849 self.assertEqual(len(mfd3.getFields()[0]),1)
5850 self.assertTrue(mfd3.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
5851 ff3=mfd3.getFields()[0][0].field(mfd3.getMeshes()[0])
5852 self.assertTrue(ff3.isEqual(ff,1e-12,1e-12))
5853 # serialization of MEDFileFields
5854 st=pickle.dumps(mfd.getFields(),pickle.HIGHEST_PROTOCOL)
5855 fs4=pickle.loads(st)
5856 ff4=fs4[0][0].field(mfd3.getMeshes()[0])
5857 self.assertTrue(ff4.isEqual(ff,1e-12,1e-12))
5858 # serialization of MEDFileFieldMulitTS
5859 st=pickle.dumps(mfd.getFields()[0],pickle.HIGHEST_PROTOCOL)
5860 fmts5=pickle.loads(st)
5861 ff5=fmts5[0].field(mfd3.getMeshes()[0])
5862 self.assertTrue(ff5.isEqual(ff,1e-12,1e-12))
5863 # serialization of MEDFileField1TS
5864 st=pickle.dumps(mfd.getFields()[0][0],pickle.HIGHEST_PROTOCOL)
5865 f1ts6=pickle.loads(st)
5866 ff6=f1ts6.field(mfd3.getMeshes()[0])
5867 self.assertTrue(ff6.isEqual(ff,1e-12,1e-12))
5868 # serialization of MEDFileMeshes
5869 st=pickle.dumps(mfd.getMeshes(),pickle.HIGHEST_PROTOCOL)
5870 ms7=pickle.loads(st)
5871 self.assertEqual(len(ms7),1)
5872 self.assertTrue(ms7[0].isEqual(mfd.getMeshes()[0],1e-12))
5875 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
5876 def testPickelizationOfMEDFileObjects2(self):
5878 self.testMEDMesh6() # generates MEDFileMesh5.med file
5879 mm=MEDFileMesh.New("MEDFileMesh5.med")
5880 self.assertTrue(isinstance(mm,MEDFileCMesh))
5881 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
5882 mm2=pickle.loads(st)
5883 self.assertTrue(isinstance(mm2,MEDFileCMesh))
5884 self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12))
5886 self.testCurveLinearMesh1() # generates Pyfile55.med
5887 mm=MEDFileMesh.New("Pyfile55.med")
5888 self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh))
5889 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
5890 mm3=pickle.loads(st)
5891 self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh))
5892 self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12))
5893 self.testInt32InMEDFileFieldStar1()# generates Pyfile63.med
5894 # MEDFileIntFieldMultiTS
5895 fs4=MEDFileFields("Pyfile63.med")
5896 ms4=MEDFileMeshes("Pyfile63.med")
5897 self.assertTrue(isinstance(fs4[0],MEDFileIntFieldMultiTS))
5898 st=pickle.dumps(fs4[0],pickle.HIGHEST_PROTOCOL)
5899 fmts5=pickle.loads(st)
5900 self.assertEqual(len(fs4[0]),len(fmts5))
5901 self.assertTrue(isinstance(fmts5,MEDFileIntFieldMultiTS))
5902 self.assertTrue(fmts5[0].field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
5903 # MEDFileIntField1TS
5904 st=pickle.dumps(fs4[0][0],pickle.HIGHEST_PROTOCOL)
5905 f1ts6=pickle.loads(st)
5906 self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS))
5907 self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
5909 self.testParameters1()# generates Pyfile56.med
5910 params=MEDFileParameters("Pyfile56.med")
5911 st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL)
5912 params7=pickle.loads(st)
5913 self.assertEqual(len(params),len(params7))
5914 for i in range(len(params)):
5915 self.assertTrue(params[i].isEqual(params7[i],1e-12)[0])
5919 def testGlobalNumOnNodes1(self):
5920 """Test global number on nodes here. Used by partitionners."""
5921 fname="Pyfile112.med"
5922 arr=DataArrayDouble(5) ; arr.iota()
5923 m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
5927 self.assertTrue(not mm.getGlobalNumFieldAtLevel(1))
5928 d=DataArrayInt([7,8,9,2,0])
5930 mm.setGlobalNumFieldAtLevel(1,d)
5931 mm.checkConsistency()
5932 self.assertRaises(InterpKernelException,mm.setGlobalNumFieldAtLevel,1,d[::2])
5933 mm.checkConsistency()
5934 self.assertEqual(d.getHiddenCppPointer(),mm.getGlobalNumFieldAtLevel(1).getHiddenCppPointer())
5935 self.assertTrue(mm.getGlobalNumFieldAtLevel(1).isEqual(dRef))
5937 mm2=MEDFileMesh.New(fname)
5938 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
5939 self.assertTrue(mm2.getGlobalNumFieldAtLevel(1).isEqual(dRef))
5940 mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,10)
5941 self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
5942 mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,7)
5943 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
5946 def testPartialReadOfEntities1(self):
5947 """Test for advanced API on read to speed up read phase for users with "huge" number of time steps (more than 10 000)."""
5948 fname="Pyfile113.med"
5949 arr=DataArrayDouble(5) ; arr.iota()
5950 m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
5957 f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m) ; f1.setName(fieldName)
5958 f1.setArray(DataArrayDouble([0.,0.1,0.2,0.3,0.4]))
5960 f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m) ; f2.setName(fieldName)
5961 f2.setArray(DataArrayDouble([1.,1.1,1.2,1.3]))
5963 f1ts=MEDFileField1TS()
5964 f1ts.setFieldNoProfileSBT(f1)
5965 f1ts.setFieldNoProfileSBT(f2)
5966 self.assertEqual(set(f1ts.getTypesOfFieldAvailable()),set([ON_NODES,ON_CELLS]))
5967 f1ts_2=f1ts.deepCopy()
5968 f1ts_2.getUndergroundDataArray()[:]+=2
5969 f1ts_2.setTime(3,4,6.)
5970 fmts=MEDFileFieldMultiTS()
5971 fmts.pushBackTimeStep(f1ts)
5972 fmts.pushBackTimeStep(f1ts_2)
5977 ent=MEDFileEntities.BuildFrom([(ON_NODES,NORM_ERROR)])
5978 mm=MEDFileMesh.New(fname)
5979 fs=MEDFileFields(fname,False,ent) # the important line is here - We specify to MEDFileFields to read only nodes part to speed up read phase (by avoiding to scan all entities time geo types)
5981 self.assertEqual(len(fs),1)
5983 self.assertEqual(len(fmts),2)
5984 ff0=fmts[0] ; ff1=fmts[1]
5985 self.assertEqual(ff0.getTypesOfFieldAvailable(),[ON_NODES]) # only NODES have been loaded
5986 self.assertTrue(ff0.field(mm).isEqual(f1,1e-12,1e-12))
5987 f3=f1.deepCopy() ; f3+=2. ; f3.setTime(6.,3,4)
5988 self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
5991 def testFloat32InMEDFileFieldStar1(self):
5992 """Like testInt32InMEDFileFieldStar1 but with float32 :)"""
5993 fname="Pyfile114.med"
5994 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
5995 f1=f1.convertToFloatField()
5997 mm1=MEDFileUMesh.New()
5998 mm1.setCoords(m1.getCoords())
5999 mm1.setMeshAtLevel(0,m1)
6000 mm1.setName(m1.getName())
6002 ff1=MEDFileFloatField1TS()
6003 ff1.setFieldNoProfileSBT(f1)
6004 a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6005 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6006 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6008 ff2=MEDFileAnyTypeField1TS.New(fname)
6009 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
6010 self.assertEqual(ff2.getTime(),[0,1,2.0])
6011 self.assertTrue(isinstance(ff2,MEDFileFloatField1TS))
6012 a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6013 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6014 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6016 c=ff2.getUndergroundDataArray() ; c*=2
6017 ff2.write(fname,0) # 2 time steps in
6018 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
6019 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
6020 self.assertEqual(len(ffs1),2)
6021 self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS))
6022 a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6023 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6024 a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
6025 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6026 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
6027 a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6028 self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7))
6029 f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
6030 self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2
6031 bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6033 a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6036 self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7))
6037 nf1=MEDCouplingFieldFloat(ON_NODES)
6038 nf1.setTime(9.,10,-1)
6039 nf1.setMesh(f1.getMesh())
6040 narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
6041 nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
6042 nff1=MEDFileFloatField1TS.New()
6043 nff1.setFieldNoProfileSBT(nf1)
6044 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
6045 self.assertEqual(nff1.getTime(),[10,-1,9.0])
6048 nf2=MEDCouplingFieldFloat(ON_NODES)
6049 nf2.setTime(19.,20,-11)
6050 nf2.setMesh(f1.getMesh())
6051 narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
6052 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
6053 nff2=MEDFileFloatField1TS.New()
6054 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
6055 nff2.setFieldProfile(nf2,mm1,0,npfl)
6056 nff2.getFieldWithProfile(ON_NODES,0,mm1)
6057 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6058 self.assertTrue(b.isEqual(npfl))
6059 self.assertTrue(a.isEqual(narr2,1e-7))
6061 nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl")
6062 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6063 self.assertTrue(b.isEqual(npfl))
6064 self.assertTrue(a.isEqual(narr2,1e-7))
6066 nf3=MEDCouplingFieldDouble(ON_NODES)
6067 nf3.setName("VectorFieldOnNodesDouble")
6068 nf3.setTime(29.,30,-21)
6069 nf3.setMesh(f1.getMesh())
6070 nf3.setArray(f1.getMesh().getCoords())
6071 nff3=MEDFileField1TS.New()
6072 nff3.setFieldNoProfileSBT(nf3)
6074 fs=MEDFileFields(fname)
6075 self.assertEqual(len(fs),4)
6076 ffs=[it for it in fs]
6077 self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS))
6078 self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS))
6079 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
6080 self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS))
6082 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7))
6083 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7))
6084 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7))
6085 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7))
6086 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6088 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
6089 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6090 self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
6091 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
6092 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
6093 self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
6094 MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1)
6095 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
6097 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
6098 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6099 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
6100 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6103 def testPenta18_1(self):
6104 """EDF8478 : Test of read/write of penta18"""
6105 fname="Pyfile115.med"
6106 arr=DataArrayDouble([
6107 (0.,1.,1.),(0.,0.,1.),(1.,0.,1.),
6108 (0.,1.,0.),(0.,0.,0.),(1.,0.,0.),
6109 (0.,0.5,1.),(0.5,0.,1.),(0.5,0.5,1.),
6110 (0.,0.5,0.),(0.5,0.,0.),(0.5,0.5,0.),
6111 (0.,1.,0.5),(0.,0.,0.5),(1.,0.,0.5),
6112 (0.,0.5,0.5),(0.5,0.,0.5),(0.5,0.5,0.5)])
6113 m=MEDCouplingUMesh("mesh",3)
6116 m.insertNextCell(NORM_PENTA18,list(range(18)))
6117 m.checkConsistencyLight()
6119 f=MEDCouplingFieldDouble(ON_NODES)
6121 f.setName("FieldOnPenta18")
6122 f.setArray(DataArrayDouble(list(range(18))))
6123 f.checkConsistencyLight()
6125 m2,d,di,rd,rdi=m.buildDescendingConnectivity()
6127 f2=MEDCouplingFieldDouble(ON_NODES)
6129 f2.setName("FieldOnPenta18Sub")
6130 f2.setArray(DataArrayDouble(list(range(18))))
6131 f2.checkConsistencyLight()
6132 WriteField(fname,f2,True)
6134 self.assertTrue(f2.isEqual(f3,1e-12,1e-12))
6135 self.assertEqual(f3.getMesh().getNumberOfCells(),1)
6136 self.assertEqual(f3.getMesh().getTypeOfCell(0),NORM_PENTA18)
6141 if __name__ == "__main__":