1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2019 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,WriteInTmpDir
27 from MEDLoaderDataForTest import TestWriteUMeshesRW1,TestMultiFieldShuffleRW1,GeneratePyfile7,GeneratePyfile10,GeneratePyfile12,GeneratePyfile13,GeneratePyfile14,GeneratePyfile18,GeneratePyfile19
28 from distutils.version import LooseVersion
31 if sys.version_info.major < 3:
32 import cPickle as pickle
36 class StdOutRedirect(object):
37 def __init__(self,fileName):
40 self.stdoutOld=os.dup(2)
41 self.fdOfSinkFile=os.open(fileName,os.O_CREAT | os.O_RDWR)
42 fd2=os.dup2(self.fdOfSinkFile,2)
43 self.origPyVal=sys.stderr
44 class FlushFile(object):
53 return self.f.isatty()
57 sys.stderr=FlushFile(os.fdopen(self.fdOfSinkFile,"w"))
61 sys.stderr=self.origPyVal
63 os.dup2(self.stdoutOld,2)
64 os.close(self.stdoutOld)
66 class MEDLoaderTest3(unittest.TestCase):
68 def testMEDMesh1(self):
69 GeneratePyfile18(self)
70 fileName="Pyfile18.med"
71 mname="ExampleOfMultiDimW"
72 medmesh=MEDFileMesh.New(fileName,mname)
73 self.assertRaises(InterpKernelException,MEDFileMesh.New,fileName,"")
74 self.assertEqual((0,-1),medmesh.getNonEmptyLevels())
75 m1_0=medmesh.getLevel0Mesh(True)
76 m1_1=ReadUMeshFromFile(fileName,mname,0)
77 self.assertTrue(m1_0.isEqual(m1_1,1e-12));
78 m2_0=medmesh.getLevelM1Mesh(True)
79 m2_1=ReadUMeshFromFile(fileName,mname,-1)
80 self.assertTrue(m2_0.isEqual(m2_1,1e-12));
84 def testMEDMesh2(self):
85 GeneratePyfile10(self)
86 fileName="Pyfile10.med"
88 outFileName="MEDFileMesh1.med"
89 medmesh=MEDFileUMesh.New(fileName,mname)
90 self.assertEqual((0,),medmesh.getNonEmptyLevels())
91 m1_0=medmesh.getLevel0Mesh(True)
92 m1_1=ReadUMeshFromFile(fileName,mname,0)
93 self.assertTrue(m1_0.isEqual(m1_1,1e-12));
94 g1_0=medmesh.getGroup(0,"mesh2",True)
95 g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh2"]);
96 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
97 g1_0=medmesh.getGroup(0,"mesh3",True)
98 g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh3"]);
99 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
100 g1_0=medmesh.getGroups(0,["mesh3","mesh2"])
101 g1_1=ReadUMeshFromGroups(fileName,mname,0,["mesh3","mesh2"]);
102 g1_1.setName(g1_0.getName())
103 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
104 g1_0=medmesh.getFamily(0,"Family_-3",True)
105 g1_1=ReadUMeshFromFamilies(fileName,mname,0,["Family_-3"]);
106 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
107 g1_0=medmesh.getFamilies(0,["Family_-3","Family_-5"],True)
108 g1_1=ReadUMeshFromFamilies(fileName,mname,0,["Family_-3","Family_-5"]);
109 g1_1.setName(g1_0.getName())
110 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
111 self.assertTrue(g1_0.isEqual(g1_1,1e-12));
112 medmesh.write(outFileName,2);
113 self.assertEqual([1,2,4,13,15],medmesh.getGroupArr(0,"mesh2",True).getValues());
114 self.assertEqual([1,2,15],medmesh.getFamilyArr(0,"Family_-3",True).getValues());
115 self.assertEqual([1,2,4,13,15],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"],True).getValues());
116 self.assertEqual([18,1,2,3,4,13,14,15],medmesh.getGroupsArr(0,["mesh2","mesh4","mesh3"],True).getValues());
117 famn=medmesh.getFamilyNameGivenId(0)
118 self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,True);
120 self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues());
121 self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_-3").getValues());
122 self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"]).getValues());
123 self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
124 self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False);
127 # this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account
129 def testMEDMesh3(self):
130 outFileName="MEDFileMesh3.med"
131 c=DataArrayDouble.New()
132 coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ];
133 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
134 c.setValues(coords,9,2)
135 m=MEDCouplingUMesh.New();
136 m.setMeshDimension(2);
138 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
139 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
140 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
141 m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
142 m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
143 m.finishInsertingCells();
145 m.checkConsistencyLight()
146 m1=MEDCouplingUMesh.New();
147 m1.setMeshDimension(1);
149 m1.insertNextCell(NORM_SEG2,2,[1,4])
150 m1.insertNextCell(NORM_SEG2,2,[3,6])
151 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
152 m1.finishInsertingCells();
154 m1.checkConsistencyLight()
155 m2=MEDCouplingUMesh.New();
156 m2.setMeshDimension(0);
158 m2.insertNextCell(NORM_POINT1,1,[1])
159 m2.insertNextCell(NORM_POINT1,1,[3])
160 m2.insertNextCell(NORM_POINT1,1,[2])
161 m2.insertNextCell(NORM_POINT1,1,[6])
162 m2.finishInsertingCells();
164 m2.checkConsistencyLight()
166 mm=MEDFileUMesh.New()
167 self.assertTrue(mm.getUnivNameWrStatus())
168 mm.setName("MyFirstMEDCouplingMEDmesh")
169 mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
171 mm.setMeshAtLevel(-1,m1);
172 mm.setMeshAtLevel(0,m);
173 mm.setMeshAtLevel(-2,m2);
174 # playing with groups
175 g1_2=DataArrayInt.New()
176 g1_2.setValues([1,3],2,1)
178 g2_2=DataArrayInt.New()
179 g2_2.setValues([1,2,3],3,1)
181 mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
182 g1_1=DataArrayInt.New()
183 g1_1.setValues([0,1,2],3,1)
185 g2_1=DataArrayInt.New()
186 g2_1.setValues([0,2],2,1)
188 mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
189 g1_N=DataArrayInt.New()
190 g1_N.setValues(list(range(8)),8,1)
192 g2_N=DataArrayInt.New()
193 g2_N.setValues(list(range(9)),9,1)
195 mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
196 mm.createGroupOnAll(0,"GrpOnAllCell")
197 # check content of mm
198 t=mm.getGroupArr(0,"G1",False)
199 self.assertTrue(g1_2.isEqual(t));
200 t=mm.getGroupArr(0,"G2",False)
201 self.assertTrue(g2_2.isEqual(t));
202 t=mm.getGroupArr(-1,"G1",False)
203 self.assertTrue(g1_1.isEqual(t));
204 t=mm.getGroupArr(-1,"G2",False)
205 self.assertTrue(g2_1.isEqual(t));
206 t=mm.getGroupArr(1,"G1",False)
207 self.assertTrue(g1_N.isEqual(t));
208 t=mm.getGroupArr(1,"G2",False)
209 self.assertTrue(g2_N.isEqual(t));
210 self.assertTrue(mm.existsGroup("GrpOnAllCell"));
211 t=mm.getGroupArr(0,"GrpOnAllCell")
212 self.assertTrue(t.getValues()==list(range(5)))
215 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) ; del mm
216 mmCpy.write(outFileName,2);
218 mm=MEDFileMesh.New(outFileName)
220 self.assertEqual([NORM_TRI3,NORM_QUAD4,NORM_POLYGON],mm.getGeoTypesAtLevel(0))
221 self.assertEqual([NORM_SEG2,NORM_SEG3],mm.getGeoTypesAtLevel(-1))
222 self.assertEqual([NORM_POINT1],mm.getGeoTypesAtLevel(-2))
223 mm0=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POLYGON)
224 self.assertTrue(isinstance(mm0,MEDCoupling1DGTUMesh))
225 self.assertTrue(mm0.getNodalConnectivity().isEqual(DataArrayInt([6,7,4,3,7,8,5,4])))
226 self.assertTrue(mm0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8])))
227 lmm=mm.getDirectUndergroundSingleGeoTypeMeshes(0)
228 self.assertEqual(3,len(lmm))
229 self.assertTrue(isinstance(lmm[0],MEDCoupling1SGTUMesh))
230 self.assertTrue(isinstance(lmm[1],MEDCoupling1SGTUMesh))
231 self.assertTrue(isinstance(lmm[2],MEDCoupling1DGTUMesh))
233 self.assertTrue(mm.getUnivNameWrStatus())
234 self.assertTrue(isinstance(mm.getUnivName(),str))
235 self.assertTrue(len(mm.getUnivName())!=0)
236 mbis=mm.getMeshAtLevel(0)
237 m.setName(mm.getName()) ; m.setDescription(mm.getDescription())
238 self.assertTrue(m.isEqual(mbis,1e-12));
240 self.assertEqual(([[(3, 2), (4, 1), (5, 8)], [(1, 2), (2, 1)], [(0, 4)]], 2, 2, 9),GetUMeshGlobalInfo(outFileName,"MyFirstMEDCouplingMEDmesh"))
243 # this test is the testMEDMesh3 except that permutation is dealed here
245 def testMEDMesh4(self):
246 outFileName="MEDFileMesh4.med"
247 c=DataArrayDouble.New()
248 coords=[-0.3,-0.3, 0.2,-0.3, 0.7,-0.3, -0.3,0.2, 0.2,0.2, 0.7,0.2, -0.3,0.7, 0.2,0.7, 0.7,0.7 ];
249 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
250 c.setValues(coords,9,2)
251 c.setInfoOnComponent(0,"abcdef [km]")
252 c.setInfoOnComponent(1,"ghij [MW]")
253 m=MEDCouplingUMesh.New();
254 m.setMeshDimension(2);
256 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
257 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
258 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
259 m.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
260 m.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
261 m.finishInsertingCells();
263 m.checkConsistencyLight()
264 m1=MEDCouplingUMesh.New();
265 m1.setMeshDimension(1);
267 m1.insertNextCell(NORM_SEG2,2,[1,4])
268 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
269 m1.insertNextCell(NORM_SEG2,2,[3,6])
270 m1.finishInsertingCells();
272 m1.checkConsistencyLight()
273 m2=MEDCouplingUMesh.New();
274 m2.setMeshDimension(0);
276 m2.insertNextCell(NORM_POINT1,1,[1])
277 m2.insertNextCell(NORM_POINT1,1,[3])
278 m2.insertNextCell(NORM_POINT1,1,[2])
279 m2.insertNextCell(NORM_POINT1,1,[6])
280 m2.finishInsertingCells();
282 m2.checkConsistencyLight()
284 mm=MEDFileUMesh.New()
285 mm.setName("My2ndMEDCouplingMEDmesh")
286 mm.setDescription("ThisIsImpossibleToDoWithMEDMEM")
288 renumNode=DataArrayInt.New()
289 renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1)
290 mm.setRenumFieldArr(1,renumNode)
291 mm.setMeshAtLevel(-1,m1,True);
292 mm.setMeshAtLevel(0,m,True);
293 mm.setMeshAtLevel(-2,m2,True);
294 mm.removeMeshAtLevel(-2)
295 mm.setMeshAtLevel(-2,m2,True);
296 # playing with groups
297 g1_2=DataArrayInt.New()
298 g1_2.setValues([2,3],2,1)
300 g2_2=DataArrayInt.New()
301 g2_2.setValues([2,0,3],3,1)
303 mm.setGroupsAtLevel(0,[g1_2,g2_2],True)
304 g1_1=DataArrayInt.New()
305 g1_1.setValues([0,2,1],3,1)
307 g2_1=DataArrayInt.New()
308 g2_1.setValues([0,2],2,1)
310 mm.setGroupsAtLevel(-1,[g1_1,g2_1],True)
311 g1_N=DataArrayInt.New()
312 g1_N.setValues([10,11,12,13,14,15,16,17],8,1)
314 g2_N=DataArrayInt.New()
315 g2_N.setValues([10,11,12,13,14,15,16,17,18],9,1)
317 mm.setGroupsAtLevel(1,[g1_N,g2_N],True)
318 # check content of mm
319 t=mm.getGroupArr(0,"G1",True)
320 self.assertTrue(g1_2.isEqual(t));
321 t=mm.getGroupArr(0,"G2",True)
322 self.assertTrue(g2_2.isEqual(t));
323 t=mm.getGroupArr(-1,"G1",True)
324 self.assertTrue(g1_1.isEqual(t));
325 t=mm.getGroupArr(-1,"G2",True)
326 self.assertTrue(g2_1.isEqual(t));
327 self.assertTrue(not mm.existsGroup("GrpOnAllCell"));
329 mm.write(outFileName,2);
330 mm2=MEDFileMesh.New(outFileName)
331 res=mm.isEqual(mm2,1e-12)
332 self.assertTrue(res[0])
333 l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
334 self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
335 mm2.keepFamIdsOnlyOnLevs([3],[-1])
336 for lev in mm.getGrpNonEmptyLevelsExt("G2"):
337 self.assertEqual(mm.getGroupArr(lev,"G2").getValues(),mm2.getGroupArr(lev,"G2").getValues())
339 l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
340 self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
342 self.assertEqual([-7,-7,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
343 mm2.getFamilyFieldAtLevel(-1).setIJ(1,0,-8)
344 self.assertEqual([-7,-8,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
345 self.assertTrue(not mm2.existsFamily("Family_-8"))
346 mm2.createGroupOnAll(-1,"GrpOnAllFace")
347 self.assertTrue(mm2.existsFamily("Family_-8"))
348 self.assertEqual(list(range(3)),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
351 #testing persistence of retrieved arrays
353 def testMEDMesh5(self):
354 GeneratePyfile18(self)
355 fileName="Pyfile18.med"
356 mname="ExampleOfMultiDimW"
357 medmesh=MEDFileUMesh.New(fileName,mname)
358 m1_0=medmesh.getLevel0Mesh(True)
359 da1=medmesh.getFamilyFieldAtLevel(0)
361 self.assertEqual(20,m1_0.getNumberOfCells())
362 self.assertEqual(20,da1.getNumberOfTuples())
365 def internalMEDMesh6(self):
366 outFileName="MEDFileMesh5.med"
369 m1=MEDCouplingCMesh.New();
370 da=DataArrayDouble.New()
371 da.setValues([0.,1.,2.],3,1)
372 da.setInfoOnComponent(0,"XX [mm]")
374 da=DataArrayDouble.New()
375 da.setValues([0.,1.2],2,1)
376 da.setInfoOnComponent(0,"YY [km]")
378 da=DataArrayDouble.New()
379 da.setValues([0.,1.3],2,1)
380 da.setInfoOnComponent(0,"ZZ [um]")
383 self.assertTrue(m[0].isEqual(m1,1e-12))
384 self.assertTrue(isinstance(m[0],MEDCouplingCMesh))
385 m.setName("myFirstCartMesh")
386 m.setDescription("mmmmpppppppp")
389 da=DataArrayInt.New()
390 da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1)
391 m.setFamilyFieldArr(1,da)
392 m.setFamilyId("family1",1)
393 da=m.getFamilyArr(1,"family1")
395 self.assertEqual(expected1,da.getValues())
396 self.assertTrue(m.getUnivNameWrStatus())
397 m.write(outFileName,2);
398 mm=MEDFileMesh.New(outFileName)
399 self.assertEqual([NORM_HEXA8],mm.getGeoTypesAtLevel(0))
400 self.assertTrue(isinstance(mm,MEDFileCMesh))
401 self.assertTrue(isinstance(mm.getUnivName(),str))
402 self.assertTrue(len(mm.getUnivName())!=0)
403 self.assertTrue(m.isEqual(mm,1e-12)[0])
404 self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
407 m1.setTime(tt[2],tt[0],tt[1])
408 m1.setName(m.getName())
409 m1.setTimeUnit(m.getTimeUnit())
410 m1.setDescription(m.getDescription())
411 self.assertTrue(m2.isEqual(m1,1e-12));
414 def testMEDMesh6(self):
415 self.internalMEDMesh6()
419 def testMEDMesh7(self):
420 fileName="Pyfile24.med"
421 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
423 m.setCoords(m2.getCoords())
424 m.setMeshAtLevel(0,m2)
425 m.setMeshAtLevel(-1,m1)
426 m.setMeshAtLevel(-2,m0)
427 m.setFamilyFieldArr(0,f2)
428 m.setFamilyFieldArr(-1,f1)
429 m.setFamilyFieldArr(-2,f0)
430 m.setFamilyFieldArr(1,p)
431 m.setRenumFieldArr(0,n2)
432 m.setRenumFieldArr(-1,n1)
433 m.setRenumFieldArr(-2,n0)
435 for i in range(nbOfFams):
436 m.addFamily(fns[i],fids[i])
439 for i in range(nbOfGrps):
440 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
442 m.setName(m2.getName())
443 m.setDescription(m2.getDescription())
445 self.assertEqual((-1,),m.getGrpNonEmptyLevels("A2A4"))
446 self.assertEqual((),m.getGrpNonEmptyLevels("A1"))
447 self.assertEqual((-2,),m.getGrpNonEmptyLevels("AP2"))
448 self.assertEqual((-1,-2),m.getGrpsNonEmptyLevels(["A2A4","AP2"]))
449 self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________'))
450 self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________'))
451 self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________']))
452 self.assertEqual(('A1A2','A2A4','A3A1','A3C5','A4A3','B1C1','B2B4','B3B1','B4C3','C1C4','C2B2','C3C2','C4B3','C5A4'),m.getGroupsOnSpecifiedLev(-1))
453 self.assertEqual(('DALLE','DALQ1','DALQ2','DALT3','MESH'),m.getGroupsOnSpecifiedLev(0))
456 self.assertRaises(InterpKernelException,MEDFileField1TS,fileName)#throw because no field in file fileName
459 def funcToTestDelItem(self,ff):
463 #emulation of pointe.med file.
465 def testMEDField1(self):
466 TestMultiFieldShuffleRW1(self)
467 mm=MEDFileMesh.New("Pyfile17.med")
468 mm.write("Pyfile17_bis.med",2)
469 ff=MEDFileFieldMultiTS("Pyfile17.med")
470 tsExpected=[[1,2],[3,4],[5,6]]
471 self.assertEqual(3,len(ff))
472 for pos,f1ts in enumerate(ff):
473 self.assertEqual(tsExpected[pos],f1ts.getTime()[:2])
474 self.assertEqual(type(f1ts),MEDFileField1TS)
476 self.assertEqual("MeasureOfMesh_Extruded",ff.getName())
477 self.assertEqual([3,4],ff[1].getTime()[:-1])
478 self.assertEqual([3,4],ff[3,4].getTime()[:-1])
479 self.assertEqual([3,4],ff[0.01].getTime()[:-1])
480 ff.write("Pyfile17_bis.med",0)
482 ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
483 self.assertEqual([(1,2),(3,4),(5,6)],ts)
484 self.funcToTestDelItem(ff)
485 ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
486 self.assertEqual([(1,2)],ts)
491 def testMEDField2(self):
492 GeneratePyfile19(self)
493 mm=MEDFileMesh.New("Pyfile19.med")
494 mm.write("Pyfile19_bis.med",2)
495 ff=MEDFileFieldMultiTS.New("Pyfile19.med")
496 ff.write("Pyfile19_bis.med",0)
497 self.assertEqual([('tyty','mm'),('uiop','MW')],GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes"))
502 def testMEDField3(self):
503 GeneratePyfile13(self)
504 mm=MEDFileMesh.New("Pyfile13.med")
505 mm.write("Pyfile13_bis.med",2)
506 ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
507 ff.write("Pyfile13_bis.med",0)
508 ff=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint",1,5)
509 f=ff.getFieldAtLevel(ON_GAUSS_PT,0)
510 f2=ReadFieldGauss("Pyfile13.med",'2DMesh_2',0,'MyFirstFieldOnGaussPoint',1,5)
511 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
512 ff3=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
513 f3=ff3.getFieldAtLevel(ON_GAUSS_PT,0)
514 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
515 ff4=MEDFileField1TS.New("Pyfile13.med")
516 f4=ff4.getFieldAtLevel(ON_GAUSS_PT,0)
517 self.assertTrue(f.isEqual(f4,1e-12,1e-12))
522 def testMEDField4(self):
523 GeneratePyfile14(self)
524 mm=MEDFileMesh.New("Pyfile14.med")
525 mm.write("Pyfile14_bis.med",2)
526 ff=MEDFileFieldMultiTS.New("Pyfile14.med","MyFieldOnGaussNE")
527 ff.write("Pyfile14_bis.med",0)
528 ff=MEDFileField1TS.New("Pyfile14.med","MyFieldOnGaussNE",1,5)
529 f=ff.getFieldAtLevel(ON_GAUSS_NE,0)
530 f2=ReadFieldGaussNE("Pyfile14.med",'2DMesh_2',0,"MyFieldOnGaussNE",1,5)
531 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
534 # MEDField get/set on pointe.med
536 def testMEDField5(self):
537 TestMultiFieldShuffleRW1(self)
538 ff=MEDFileField1TS.New("Pyfile17.med","MeasureOfMesh_Extruded",1,2)
539 f=ff.getFieldAtLevel(ON_CELLS,0)
540 f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
541 self.assertTrue(f.getMesh().getCoords().isEqual(f2.getMesh().getCoords(),1e-12))
542 f.getMesh().tryToShareSameCoords(f2.getMesh(),1e-12)
543 f.changeUnderlyingMesh(f2.getMesh(),22,1e-12)
544 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
545 # no with renumbering
546 f=ff.getFieldAtLevel(ON_CELLS,0,1)
547 f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
548 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
549 f=ff.getFieldAtLevel(ON_CELLS,0,3)
550 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
551 f=ff.getFieldAtLevel(ON_CELLS,0,2)
552 self.assertTrue(not f.isEqual(f2,1e-12,1e-12))
553 f.changeUnderlyingMesh(f2.getMesh(),12,1e-12)
554 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
557 # MEDField get/set on profiles nodes
559 def testMEDField6(self):
560 GeneratePyfile7(self)
561 ff=MEDFileFieldMultiTS.New("Pyfile7.med","VectorFieldOnNodes")
562 its=ff.getIterations()
563 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
564 f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
565 f2=ReadFieldNode("Pyfile7.med",'3DSurfMesh_1',0,"VectorFieldOnNodes",its[0][0],its[0][1])
566 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
567 GeneratePyfile19(self)
568 ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes")
569 its=ff.getIterations()
570 f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
571 f2=ReadFieldNode("Pyfile19.med",'2DMesh_1',0,"VFieldOnNodes",its[0][0],its[0][1])
572 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
573 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
574 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_NODES,its[0][0],its[0][1],0,1)#request renumber following mesh : it is on profile !
577 # MEDField get/set on profiles cells
579 def testMEDField7(self):
580 GeneratePyfile12(self)
581 ff=MEDFileFieldMultiTS.New("Pyfile12.med","VectorFieldOnCells")
582 its=ff.getIterations()
583 f=ff.getFieldAtLevel(ON_CELLS,its[0][0],its[0][1],0)
584 f2=ReadFieldCell("Pyfile12.med",'3DMesh_1',0,"VectorFieldOnCells",its[0][0],its[0][1])
585 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
588 #first test of assignation. No profile and types sorted by type.
590 def testMEDField8(self):
592 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
594 mm1=MEDFileUMesh.New()
595 mm1.setCoords(m1.getCoords())
596 mm1.setMeshAtLevel(0,m1)
597 mm1.setName(m1.getName())
599 ff1=MEDFileField1TS.New()
600 ff1.setFieldNoProfileSBT(f1)
602 f2=ReadFieldCell(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]);
603 itt,orr,ti=ff1.getTime()
604 self.assertEqual(0,itt); self.assertEqual(1,orr); self.assertAlmostEqual(2.,ti,14);
605 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
607 itt,orr,ti=ff1.getTime()
608 self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14);
610 ff1.copyTimeInfoFrom(f1)
611 itt,orr,ti=ff1.getTime()
612 self.assertEqual(7,itt); self.assertEqual(8,orr); self.assertAlmostEqual(5.5,ti,14);
613 da,infos=ff1.getUndergroundDataArrayExt()
614 f2.getArray().setName(da.getName())#da has the same name than f2
615 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
616 self.assertEqual([((3, 0), (0, 2)), ((4, 0), (2, 4)), ((6, 0), (4, 5)), ((5, 0), (5, 6))],infos)
619 f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
621 mm1=MEDFileUMesh.New()
622 mm1.setCoords(m1.getCoords())
623 mm1.setMeshAtLevel(0,m1)
624 mm1.setName(m1.getName())
626 ff1=MEDFileField1TS.New()
627 ff1.setFieldNoProfileSBT(f1)
629 da=ff1.getUndergroundDataArray().setIJ(0,0,nv)
631 f2=ReadFieldNode(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
632 self.assertTrue(not f1.isEqual(f2,1e-12,1e-12))
633 f1.getArray().setIJ(0,0,nv)
634 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
637 f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
639 mm1=MEDFileUMesh.New()
640 mm1.setCoords(m1.getCoords())
641 mm1.setMeshAtLevel(0,m1)
642 mm1.setName(m1.getName())
644 ff1=MEDFileField1TS.New()
645 ff1.setFieldNoProfileSBT(f1)
647 f2=ReadFieldGaussNE(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
648 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
649 da,infos=ff1.getUndergroundDataArrayExt()
650 f2.getArray().setName(da.getName())#da has the same name than f2
651 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
652 self.assertEqual([((3, 0), (0, 6)), ((4, 0), (6, 14)), ((6, 0), (14, 20))],infos)
655 f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler();
656 f1InvalidCpy=f1.deepCopy()
657 f1InvalidCpy.setDiscretization(MEDCouplingFieldDiscretizationGauss())
658 f1InvalidCpy2=f1.deepCopy()
659 f1InvalidCpy2.setDiscretization(MEDCouplingFieldDiscretizationGauss())
661 mm1=MEDFileUMesh.New()
662 mm1.setCoords(m1.getCoords())
663 mm1.setMeshAtLevel(0,m1)
664 mm1.setName(m1.getName())
666 ff1=MEDFileField1TS.New()
667 self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy) # fails because no Gauss localization per cell set !*
668 f1InvalidCpy2.getDiscretization().setArrayOfDiscIds(f1.getDiscretization().getArrayOfDiscIds()) # fails because no Gauss localization set whereas gauss locid per cell given !
669 self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy2)
670 ff1.setFieldNoProfileSBT(f1)
672 ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2])
673 f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0)
674 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
675 sbt=ff2.getFieldSplitedByType2()
676 loc1=ff2.getLocalization("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5")
677 self.assertEqual("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5",loc1.getName())
678 self.assertEqual((-1, 1,-1,-1,1,-1,-1,0,0,-1,0,0),loc1.getRefCoords())
679 self.assertEqual(6,loc1.getNumberOfPointsInCells())
680 self.assertEqual(3,loc1.getNumberOfGaussPoints())
681 self.assertEqual(2,loc1.getDimension())
682 da,infos=ff2.getUndergroundDataArrayExt()
683 f2.getArray().setName(da.getName())#da has the same name than f2
684 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
685 self.assertEqual(53,da.getNumberOfTuples())
686 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)
691 def testMEDFileData1(self):
695 m1=MEDLoaderDataForTest.build1DMesh_1()
696 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
697 mmm1=MEDFileMeshMultiTS.New() ;
698 mmm1.setOneTimeStep(mm1)
699 m2=MEDLoaderDataForTest.build2DCurveMesh_1()
700 mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName())
701 mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2)
702 ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2)
704 for name,mmm in zip(["1DMesh_1","2DCurveMesh_1"],ms):
705 self.assertEqual(name,mmm.getName())
706 self.assertEqual(type(mmm),MEDFileUMesh)
708 self.assertEqual(('1DMesh_1', '2DCurveMesh_1'),d.getMeshes().getMeshesNames())
710 ff1=MEDFileFieldMultiTS.New()
711 ff21=MEDFileFieldMultiTS.New()
712 ff22=MEDFileFieldMultiTS.New()
713 f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False)
714 f1.getArray().setInfoOnComponent(0,"power [kW]")
715 ff1.appendFieldNoProfileSBT(f1)
716 f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False)
717 f21.getArray().setInfoOnComponent(0,"sta [mm]") ;
718 ff21.appendFieldNoProfileSBT(f21)
719 f22=f21.deepCopy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ;
720 f22.applyFunc(2,"3*x*IVec+2*x*JVec")
721 f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]")
722 ff22.appendFieldNoProfileSBT(f22)
723 fs=MEDFileFields.New()
724 fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22)
725 for name,fmts in zip(["f1","f21","f22"],fs):
726 self.assertEqual(name,fmts.getName())
730 fname2="Pyfile29_2.med"
733 d2=MEDFileData.New(fname2)
734 self.assertEqual(2,d2.getNumberOfMeshes())
735 self.assertEqual(3,d2.getNumberOfFields())
736 self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))
737 self.assertTrue(isinstance(d2.getMeshes()[0],MEDFileUMesh))
738 self.assertTrue(isinstance(d2.getMeshes()['2DCurveMesh_1'],MEDFileUMesh))
739 m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
740 self.assertTrue(m1.isEqual(m1bis,1e-12))
741 self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
742 self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
743 self.assertEqual([(-1,-1,0.0)],d2.getFields()[2].getTimeSteps())
744 self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
745 self.assertEqual([(-1,-1,0.0)],d2.getFields()["f21"].getTimeSteps())
749 def testMEDField9(self):
750 # first test field profile WR. Full type but with some type missing
752 m1=MEDLoaderDataForTest.build2DMesh_3()
753 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
755 ff1=MEDFileField1TS.New()
756 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1")
757 d=DataArrayDouble.New() ; d.alloc(2*9,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
758 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.
759 da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1")
761 ff1.setFieldProfile(f1,mm1,0,da)
762 ff1.changePflsNames([(["sup1_NORM_QUAD4"],"ForV650")])
766 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
767 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))# profiles names cannot be contracted in pfl array name
768 self.assertTrue(vals.isEqual(d,1e-14))
770 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
771 ff3=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
772 ff2.deepCpyGlobs(ff3)
773 sbt=ff2.getFieldSplitedByType2()
774 self.assertEqual(3,sbt[0][0])#TRI3
775 self.assertEqual(0,sbt[0][1][0][0])#CELL For TRI3
776 self.assertEqual("",sbt[0][1][0][2])#no profile For TRI3
777 self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],sbt[0][1][0][1].getValues())# values for TRI3
778 self.assertEqual(4,sbt[1][0])#QUAD4
779 self.assertEqual(0,sbt[1][1][0][0])#CELL For QUAD4
780 self.assertEqual("ForV650",sbt[1][1][0][2])# profile For QUAD4
781 self.assertEqual([19, 20, 21, 22, 23, 24],sbt[1][1][0][1].getValues())# values for QUAD4
782 self.assertEqual([0],ff2.getTypesOfFieldAvailable())
783 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
784 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
785 self.assertTrue(vals.isEqual(d,1e-14))
789 def testMEDField10(self):
791 m1=MEDLoaderDataForTest.build2DMesh_1()
792 m1.renumberCells([0,1,4,2,3,5],False)
793 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
795 ff1=MEDFileFieldMultiTS.New()
796 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
797 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
798 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.
799 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
801 ff1.appendFieldProfile(f1,mm1,0,da)
802 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
803 ff1.appendFieldProfile(f1,mm1,0,da)
807 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
808 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
809 self.assertTrue(vals.isEqual(e,1e-14))
810 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
811 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
812 self.assertTrue(vals.isEqual(d,1e-14))
814 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
815 self.assertEqual([(-1,-1,0.0), (1,2,1.2)],ff2.getTimeSteps())
816 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
817 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
818 self.assertTrue(vals.isEqual(e,1e-14))
819 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
820 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
821 self.assertTrue(vals.isEqual(d,1e-14))
824 # idem testMEDField9 method except that here testing profile on nodes and not on cells.
826 def testMEDField11(self):
828 m1=MEDLoaderDataForTest.build2DMesh_1()
829 m1.renumberCells([0,1,4,2,3,5],False)
830 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
832 ff1=MEDFileField1TS.New()
833 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
834 d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
835 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.
836 da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
838 ff1.setFieldProfile(f1,mm1,0,da)
839 self.assertEqual(ff1.getNonEmptyLevels(),(-1, []))
842 vals,pfl=ff1.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
843 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
844 self.assertTrue(vals.isEqual(d,1e-14))
846 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
847 vals,pfl=ff2.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
848 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
849 self.assertTrue(vals.isEqual(d,1e-14))
853 def testMEDField12(self):
855 m1=MEDLoaderDataForTest.build2DMesh_1()
856 m1.renumberCells([0,1,4,2,3,5],False)
857 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
859 ff1=MEDFileFieldMultiTS.New()
860 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
861 d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
862 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.
863 da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
865 ff1.appendFieldProfile(f1,mm1,0,da)
866 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
867 ff1.appendFieldProfile(f1,mm1,0,da)
870 vals,pfl=ff1.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
871 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
872 self.assertTrue(vals.isEqual(e,1e-14))
873 vals,pfl=ff1.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
874 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
875 self.assertTrue(vals.isEqual(d,1e-14))
877 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
878 vals,pfl=ff2.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
879 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
880 self.assertTrue(vals.isEqual(e,1e-14))
881 vals,pfl=ff2.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
882 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
883 self.assertTrue(vals.isEqual(d,1e-14))
887 def testMEDField13(self):
889 m1=MEDLoaderDataForTest.build2DMesh_1()
890 m1.renumberCells([0,1,4,2,3,5],False)
892 m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
893 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
895 ff1=MEDFileField1TS.New()
896 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F3Node")
897 d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
898 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.
899 da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
901 ff1.setFieldProfile(f1,mm1,0,da)
904 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
905 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
906 self.assertTrue(vals.isEqual(d,1e-14))
908 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
909 vals,pfl=ff2.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
910 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
911 self.assertTrue(vals.isEqual(d,1e-14))
915 def testMEDField14(self):
917 m1=MEDLoaderDataForTest.build2DMesh_1()
918 m1.renumberCells([0,1,4,2,3,5],False)
920 m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
921 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
923 ff1=MEDFileFieldMultiTS.New()
924 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
925 d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
926 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.
927 da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
929 ff1.appendFieldProfile(f1,mm1,0,da)
930 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
931 ff1.appendFieldProfile(f1,mm1,0,da)
934 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
935 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
936 self.assertTrue(vals.isEqual(d,1e-14))
937 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
938 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
939 self.assertTrue(vals.isEqual(e,1e-14))
940 self.assertEqual([[3],[3]],ff1.getTypesOfFieldAvailable())
942 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
943 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
944 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
945 self.assertTrue(vals.isEqual(d,1e-14))
946 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
947 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
948 self.assertTrue(vals.isEqual(e,1e-14))
950 # 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.
951 # 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
952 # for the necessity of the test ! The idea is too create artificially a mesh having one more fictitious cell per type and to roll back right after !
954 def testMEDField15(self):
956 m0=MEDLoaderDataForTest.build2DMesh_1()
957 m0.renumberCells([0,1,4,2,3,5],False)
959 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
960 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
961 ff1=MEDFileField1TS.New()
962 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
963 d=DataArrayDouble.New() ; d.alloc(2*20,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
964 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.
965 da=DataArrayInt.New(); da.setValues([0,1,3,4,6],5,1) ; da.setName("sup1NodeElt")
967 ff1.setFieldProfile(f1,mm1,0,da)
968 m1=m0.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
971 f1=ff1.getFieldOnMeshAtLevel(ON_GAUSS_NE,m1,0)
972 f2,p1=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; f2.setName("")
973 self.assertTrue(p1.isIota(5))
974 self.assertTrue(f1.getArray().isEqual(f2,1e-12))
976 # Test for getFieldAtTopLevel method
978 def testMEDField16(self):
980 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
982 mm1=MEDFileUMesh.New()
983 mm1.setCoords(m1.getCoords())
984 mm1.setMeshAtLevel(0,m1)
985 mm1.setName(m1.getName())
986 ff1=MEDFileField1TS.New()
987 ff1.setFieldNoProfileSBT(f1)
988 m2=m1.buildDescendingConnectivity()[0]
989 m2.sortCellsInMEDFileFrmt()
990 m2.setName(m1.getName())
991 mm1.setMeshAtLevel(-1,m2)
993 f2=m2.getMeasureField(True)
994 dd=DataArrayDouble.New()
995 dd.alloc(f2.getArray().getNumberOfTuples(),3)
996 dd[:,0]=f2.getArray()
997 dd[:,1]=2*f2.getArray()
998 dd[:,2]=3*f2.getArray()
999 f2=f2.buildNewTimeReprFromThis(ONE_TIME,False)
1001 f2.copyTinyStringsFrom(f1)
1002 f2.copyTinyAttrFrom(f1)
1003 ff1.setFieldNoProfileSBT(f2)
1005 # Reading Pyfile37.med
1006 ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
1007 f1bis=ff2.getFieldAtLevel(ON_CELLS,0)
1008 self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
1009 f1bis=ff2.getFieldAtLevel(ON_CELLS,-1)
1010 self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
1011 f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
1012 self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
1014 fname="Pyfile38.med"
1016 ff1=MEDFileField1TS.New()
1017 ff1.setFieldNoProfileSBT(f2)
1019 ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
1020 f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
1021 self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
1024 # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
1026 def testMEDField17(self):
1027 fname="Pyfile39.med"
1028 m1=MEDLoaderDataForTest.build2DMesh_1()
1029 m1.renumberCells([0,1,4,2,3,5],False)
1030 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
1032 ffs=MEDFileFields.New()
1033 ff1=MEDFileFieldMultiTS.New()
1034 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
1035 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
1036 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.
1037 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
1039 ff1.appendFieldProfile(f1,mm1,0,da)
1040 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
1041 ff1.appendFieldProfile(f1,mm1,0,da)
1043 ffs.setFieldAtPos(0,ff1)
1047 ffsr=MEDFileFields.New(fname)
1048 ff3=ffsr.getFieldAtPos(0)
1049 f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
1050 self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
1053 # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
1055 def testMEDField18(self):
1056 fname="Pyfile40.med"
1057 m1=MEDLoaderDataForTest.build2DMesh_1()
1058 m1.renumberCells([0,1,4,2,3,5],False)
1059 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
1061 ffs=MEDFileFields.New()
1062 ff1=MEDFileFieldMultiTS.New()
1063 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
1064 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
1065 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.
1066 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
1068 ff1.appendFieldProfile(f1,mm1,0,da)
1069 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
1070 ff1.appendFieldProfile(f1,mm1,0,da)
1074 ffsr=MEDFileFields.New(fname)
1075 ff3=ffsr.getFieldAtPos(0)
1076 f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
1077 self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
1081 def testMEDFieldBug1(self):
1082 GeneratePyfile13(self)
1083 fname="Pyfile13.med"
1084 d=MEDFileData.New(fname)
1085 self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs())
1089 def testMEDMesh8(self):
1090 m=MEDLoaderDataForTest.build1DMesh_1()
1091 m.convertQuadraticCellsToLinear()
1092 mm=MEDFileUMesh.New()
1093 mm.setMeshAtLevel(0,m)
1094 g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1")
1095 g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2")
1096 g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3")
1097 mm.setGroupsAtLevel(0,[g1,g2],False)
1098 self.assertEqual(('g1','g2'),mm.getGroupsNames())
1099 self.assertEqual(('Family_-2','Family_-3'),mm.getFamiliesNames())
1100 self.assertEqual(('Family_-2',),mm.getFamiliesOnGroup('g1'))
1101 self.assertEqual(('Family_-3',),mm.getFamiliesOnGroup('g2'))
1102 mm.assignFamilyNameWithGroupName()
1103 self.assertEqual(('g1','g2'),mm.getGroupsNames())
1104 self.assertEqual(('g1','g2'),mm.getFamiliesNames())
1105 self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1'))
1106 self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2'))
1108 mm=MEDFileUMesh.New()
1109 mm.setMeshAtLevel(0,m)
1110 mm.setGroupsAtLevel(0,[g1,g2,g3],False)
1111 self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1112 self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1113 self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1114 self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1115 self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1116 mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found
1117 self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1118 self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1119 self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1120 self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1121 self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1122 mm.changeFamilyId(5,6)
1123 g=mm.getGroupArr(0,"g3")
1124 self.assertTrue(g.isEqual(g3));
1125 g=mm.getGroupArr(0,"g2")
1126 self.assertTrue(g.isEqual(g2));
1127 g=mm.getGroupArr(0,"g1")
1128 self.assertTrue(g.isEqual(g1));
1131 # bug detected by gauthier
1133 def testMEDLoaderMEDLoaderNSReadFieldDoubleDataInMedFile(self):
1134 fname="Pyfile41.med"
1135 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
1137 mm1=MEDFileUMesh.New()
1138 mm1.setCoords(m1.getCoords())
1139 mm1.setMeshAtLevel(0,m1)
1141 ff1=MEDFileField1TS.New()
1142 ff1.setFieldNoProfileSBT(f1)
1144 # writing mesh1 and field1, now creation of mesh2 and field2
1147 m2.translate([0.5,0.6,0.7])
1148 m2.setName("3DSurfMesh_2")
1149 f2.getArray()[:]*=2.
1150 f2.setName("VectorFieldOnCells2")
1151 mm2=MEDFileUMesh.New()
1152 mm2.setCoords(m2.getCoords())
1153 mm2.setMeshAtLevel(0,m2)
1155 ff2=MEDFileField1TS.New()
1156 ff2.setFieldNoProfileSBT(f2)
1159 f3=ReadFieldCell(fname,"3DSurfMesh_1",0,"VectorFieldOnCells",0,1)
1160 self.assertTrue(f3.isEqual(f1,1e-12,1e-12))
1161 f4=ReadFieldCell(fname,"3DSurfMesh_2",0,"VectorFieldOnCells2",0,1)
1162 self.assertTrue(f4.isEqual(f2,1e-12,1e-12))
1166 def testMEDLoaderMultiLevelCellField1(self):
1167 fname="Pyfile42.med"
1168 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1169 m=MEDFileUMesh.New()
1170 m.setCoords(m2.getCoords())
1171 m.setMeshAtLevel(0,m2)
1172 m.setMeshAtLevel(-1,m1)
1173 m.setMeshAtLevel(-2,m0)
1177 compNames1=["comp1","comp2","comp3"]
1178 ff1=MEDFileField1TS.New()
1179 da2=DataArrayDouble.New()
1180 da2.alloc(m2.getNumberOfCells()*len(compNames1),1)
1182 da2.rearrange(len(compNames1))
1183 da2.setInfoOnComponents(compNames1)
1184 f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f2.setName(FieldName1) ; f2.setArray(da2) ; f2.setMesh(m2) ; f2.checkConsistencyLight()
1185 ff1.setFieldNoProfileSBT(f2)
1186 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0]))
1187 da0=DataArrayDouble.New()
1188 da0.alloc(m0.getNumberOfCells()*len(compNames1),1)
1190 da0.rearrange(len(compNames1))
1191 da0.setInfoOnComponents(compNames1)
1192 f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName1) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkConsistencyLight()
1193 ff1.setFieldNoProfileSBT(f0)
1194 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-2]))
1195 da1=DataArrayDouble.New()
1196 da1.alloc(m1.getNumberOfCells()*len(compNames1),1)
1198 da1.rearrange(len(compNames1))
1199 da1.setInfoOnComponents(compNames1)
1200 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName1) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkConsistencyLight()
1201 ff1.setFieldNoProfileSBT(f1)
1202 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1207 compNames2=["comp11","comp22"]
1208 ff2=MEDFileField1TS.New()
1209 da0=DataArrayDouble.New()
1210 da0.alloc(m0.getNumberOfCells()*2,1)
1213 da0.setInfoOnComponents(compNames2)
1214 f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName2) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkConsistencyLight()
1215 ff2.setFieldNoProfileSBT(f0)
1216 self.assertEqual(ff2.getNonEmptyLevels(),(0, [0]))
1217 da1=DataArrayDouble.New()
1218 da1.alloc(m1.getNumberOfCells()*len(compNames2),1)
1220 da1.rearrange(len(compNames2))
1221 da1.setInfoOnComponents(compNames2)
1222 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName2) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkConsistencyLight()
1223 ff2.setFieldNoProfileSBT(f1)
1224 self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1228 ff1=MEDFileField1TS.New(fname,FieldName1,-1,-1)
1229 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1230 self.assertEqual(ff1.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')]), (3, [(0, (84, 148), '', '')]), (4, [(0, (148, 212), '', '')])])
1231 ff2=MEDFileField1TS.New(fname,FieldName2,-1,-1)
1232 self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1233 self.assertEqual(ff2.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')])])
1237 def testFieldOnPflRetrieveOnMdimRelMax1(self):
1238 fname="Pyfile43.med"
1239 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1240 m=MEDFileUMesh.New()
1241 m.setMeshAtLevel(0,m2)
1242 m.setMeshAtLevel(-1,m1)
1243 m.setMeshAtLevel(-2,m0)
1244 f=MEDFileField1TS.New()
1245 ff=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
1246 ff.setName("NodeFieldPfl")
1247 arr=DataArrayDouble.New() ; arr.setValues([1.,10.,100.,2.,20.,200.],2,3)
1249 pfl=DataArrayInt.New() ; pfl.setValues([2,3],2,1) ; pfl.setName("PflNode")
1250 f.setFieldProfile(ff,m,-2,pfl)
1251 tes0=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1252 self.assertEqual(ON_NODES,tes0.getTypeOfField())
1253 self.assertEqual(1,tes0.getMesh().getMeshDimension())
1254 self.assertEqual(1,tes0.getMesh().getNumberOfCells())
1255 self.assertEqual(2,tes0.getMesh().getNumberOfNodes())
1256 self.assertEqual([1,0,1],tes0.getMesh().getNodalConnectivity().getValues())
1257 self.assertEqual([0,3],tes0.getMesh().getNodalConnectivityIndex().getValues())
1258 self.assertEqual(2,tes0.getArray().getNumberOfTuples())
1259 self.assertEqual(3,tes0.getArray().getNumberOfComponents())
1260 expected1=[1.,10.,100.,2.,20.,200.]
1261 nodeCoordsWithValue1=[10.,2.5,0.]
1262 nodeCoordsWithValue2=[10.,3.75,0.]
1264 self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
1265 self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
1268 self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
1272 tes1=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1273 self.assertEqual(ON_CELLS,tes1.getTypeOfField())# it is not a bug even if ON_NODES has been specified
1274 self.assertEqual(0,tes1.getMesh().getMeshDimension())
1275 self.assertEqual(2,tes1.getMesh().getNumberOfCells())
1276 self.assertEqual(135,tes1.getMesh().getNumberOfNodes())
1277 self.assertEqual([0,2,0,3],tes1.getMesh().getNodalConnectivity().getValues())
1278 self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
1279 self.assertEqual(2,tes1.getArray().getNumberOfTuples())
1280 self.assertEqual(3,tes1.getArray().getNumberOfComponents())
1282 self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
1287 pfl=DataArrayInt.New() ; pfl.setValues([3,2],2,1) ; pfl.setName("PflNode")
1288 f=MEDFileField1TS.New()
1289 f.setFieldProfile(ff,m,-2,pfl)
1290 tes2=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1291 self.assertEqual(ON_NODES,tes2.getTypeOfField())
1292 self.assertEqual(1,tes2.getMesh().getMeshDimension())
1293 self.assertEqual(1,tes2.getMesh().getNumberOfCells())
1294 self.assertEqual(2,tes2.getMesh().getNumberOfNodes())
1295 self.assertEqual([1,0,1],tes2.getMesh().getNodalConnectivity().getValues())
1296 self.assertEqual([0,3],tes2.getMesh().getNodalConnectivityIndex().getValues())
1297 self.assertEqual(2,tes2.getArray().getNumberOfTuples())
1298 self.assertEqual(3,tes2.getArray().getNumberOfComponents())
1299 expected2=[2.,20.,200.,1.,10.,100.]
1301 self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
1302 self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
1305 self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
1308 tes3=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1309 self.assertEqual(ON_CELLS,tes3.getTypeOfField())# it is not a bug even if ON_NODES has been specified
1310 self.assertEqual(0,tes3.getMesh().getMeshDimension())
1311 self.assertEqual(2,tes3.getMesh().getNumberOfCells())
1312 self.assertEqual(135,tes3.getMesh().getNumberOfNodes())
1313 self.assertEqual([0,3,0,2],tes3.getMesh().getNodalConnectivity().getValues())
1314 self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
1315 self.assertEqual(2,tes3.getArray().getNumberOfTuples())
1316 self.assertEqual(3,tes3.getArray().getNumberOfComponents())
1318 self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
1323 def testBuildInnerBoundaryAlongM1Group1(self):
1324 fname="Pyfile44.med"
1325 m=MEDCouplingCMesh.New()
1326 m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1327 m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1328 m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1329 m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1330 m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1331 m2.setName(m.getName())
1332 grp=DataArrayInt.New([4,6,8]) ; grp.setName("Grp")
1333 grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1334 mm=MEDFileUMesh.New()
1335 mm.setMeshAtLevel(0,m)
1336 mm.setMeshAtLevel(-1,m2)
1337 mm.setGroupsAtLevel(-1,[grp,grp2])
1338 grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1339 mm.setGroupsAtLevel(1,[grpNode])
1340 ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1341 ref1=[4,9,8,14,15,4,10,9,15,16,4,11,10,16,17]
1342 ref2=[4,9,8,14,30,4,10,9,30,31,4,11,10,31,32]
1344 self.assertEqual(30,mm.getNumberOfNodes())
1345 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1346 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())
1348 nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1349 self.assertEqual([15,16,17],nodes.getValues());
1350 self.assertEqual([7,8,9],cells.getValues());
1351 self.assertEqual([12,13,14],cells2.getValues());
1352 self.assertEqual(33,mm.getNumberOfNodes())
1353 self.assertEqual([4,6,8],mm.getGroupArr(-1,"Grp").getValues())
1354 self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1355 self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1356 self.assertEqual([17,18,19],mm.getGroupArr(-1,"Grp_dup").getValues())
1357 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
1358 self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())#
1359 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
1360 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1361 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])
1362 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1363 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1365 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1366 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1367 refValues2=refValues[:] ; refValues2[7:10]=[1.365,1.26,1.35]
1368 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1369 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1374 def testBuildInnerBoundaryAlongM1Group2(self):
1375 fname="Pyfile45.med"
1376 m=MEDCouplingCMesh.New()
1377 m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1378 m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1379 m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1380 m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1381 m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1382 m2.setName(m.getName())
1383 grp=DataArrayInt.New([4,6]) ; grp.setName("Grp")
1384 grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1385 mm=MEDFileUMesh.New()
1386 mm.setMeshAtLevel(0,m)
1387 mm.setMeshAtLevel(-1,m2)
1388 mm.setGroupsAtLevel(-1,[grp,grp2])
1389 grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1390 mm.setGroupsAtLevel(1,[grpNode])
1391 ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1392 ref1=[4,9,8,14,15,4,10,9,15,16]
1393 ref2=[4,9,8,14,30,4,10,9,30,16]
1395 self.assertEqual(30,mm.getNumberOfNodes())
1396 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1397 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())
1399 nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1400 self.assertEqual([15],nodes.getValues());
1401 self.assertEqual([7,8],cells.getValues());
1402 self.assertEqual([12,13],cells2.getValues());
1403 self.assertEqual(31,mm.getNumberOfNodes())
1404 self.assertEqual([4,6],mm.getGroupArr(-1,"Grp").getValues())
1405 self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1406 self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1407 self.assertEqual([17,18],mm.getGroupArr(-1,"Grp_dup").getValues())
1408 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
1409 self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())#
1410 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
1411 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1412 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])
1413 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1414 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1416 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1417 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1418 refValues2=refValues[:] ; refValues2[7:9]=[1.365,1.47]
1419 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1420 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1425 def testBuildInnerBoundaryAlongM1Group3(self):
1426 """ Test buildInnerBoundaryAlongM1Group() with *non-connex* cracks """
1427 fname = "Pyfile73.med"
1428 m = MEDCouplingCMesh.New()
1429 m.setCoordsAt(0, DataArrayDouble([0.0,1.1,2.3,3.6,5.0]))
1430 m.setCoordsAt(1, DataArrayDouble([0.,1.,2.]))
1431 m = m.buildUnstructured(); m.setName("simple")
1432 m2 = m.buildDescendingConnectivity()[0]
1433 m2.setName(m.getName())
1435 # A crack in two non connected parts of the mesh:
1436 grpSeg = DataArrayInt([3,19]) ; grpSeg.setName("Grp")
1438 mm = MEDFileUMesh.New()
1439 mm.setMeshAtLevel(0,m)
1440 mm.setMeshAtLevel(-1,m2)
1441 mm.setGroupsAtLevel(-1,[grpSeg])
1442 nodes, cellsMod, cellsNotMod = mm.buildInnerBoundaryAlongM1Group("Grp")
1443 self.assertEqual([1,13],nodes.getValues());
1444 self.assertEqual([0,6],cellsMod.getValues());
1445 self.assertEqual([1,7],cellsNotMod.getValues());
1446 self.assertEqual(17,mm.getNumberOfNodes())
1447 self.assertEqual([3,19],mm.getGroupArr(-1,"Grp").getValues())
1448 self.assertEqual([22,23],mm.getGroupArr(-1,"Grp_dup").getValues())
1449 ref0=[4, 15, 0, 5, 6, 4, 8, 7, 12, 16]
1450 ref1=[4, 2, 1, 6, 7, 4, 9, 8, 13, 14]
1451 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[0,6]].getNodalConnectivity().getValues())
1452 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[1,7]].getNodalConnectivity().getValues())
1453 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
1454 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1456 refValues=DataArrayDouble([1.1, 1.2, 1.3, 1.4, 1.1, 1.2, 1.3, 1.4])
1457 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1458 self.assertTrue(delta.getMaxValue()[0]<1e-10)
1460 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1461 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1462 refValues2=refValues[:] ; refValues2[0] = 1.265; refValues2[6] = 1.105
1463 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1464 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1468 def testBuildInnerBoundaryAlongM1Group4(self):
1469 """ Test case where cells touch the M1 group on some nodes only and not on full edges (triangle mesh for ex)
1471 coo = DataArrayDouble([0.,0., 1.,0., 2.,0., 3.,0.,
1472 0.,1., 1.,1., 2.,1., 3.,1.,
1473 0.,2., 1.,2., 2.,2., 3.,2.], 12, 2)
1474 conn = [3,0,4,1, 3,1,4,5,
1481 connI = DataArrayInt()
1482 connI.alloc(13, 1); connI.iota(); connI *= 4
1483 m2 = MEDCouplingUMesh("2D", 2)
1485 m2.setConnectivity(DataArrayInt(conn), connI)
1486 m2.checkConsistency()
1487 m1, _, _, _, _ = m2.buildDescendingConnectivity()
1488 grpIds = DataArrayInt([9,11]); grpIds.setName("group")
1489 grpIds2 = DataArrayInt([0,1]); grpIds2.setName("group2")
1490 mfu = MEDFileUMesh()
1491 mfu.setMeshAtLevel(0, m2)
1492 mfu.setMeshAtLevel(-1, m1)
1493 mfu.setGroupsAtLevel(-1, [grpIds, grpIds2])
1494 nNod = m2.getNumberOfNodes()
1495 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1496 m2_bis = mfu.getMeshAtLevel(0)
1497 m2_bis.checkConsistency()
1498 m1_bis = mfu.getMeshAtLevel(-1)
1499 m1_bis.checkConsistency()
1500 self.assertEqual(nNod+2, mfu.getNumberOfNodes())
1501 self.assertEqual(nNod+2, m2_bis.getNumberOfNodes())
1502 self.assertEqual(nNod+2, m1_bis.getNumberOfNodes())
1503 self.assertEqual([6,7], nodesDup.getValues())
1504 self.assertEqual([2.,1., 3.,1.], m2_bis.getCoords()[nNod:].getValues())
1505 self.assertEqual(set([3,10,11]), set(cells1.getValues()))
1506 self.assertEqual(set([8,9,4,5]), set(cells2.getValues()))
1507 self.assertEqual([9,11],mfu.getGroupArr(-1,"group").getValues())
1508 self.assertEqual([23,24],mfu.getGroupArr(-1,"group_dup").getValues())
1509 self.assertEqual([0,1],mfu.getGroupArr(-1,"group2").getValues())
1510 # mfu.getMeshAtLevel(0).writeVTK("/tmp/mfu_M0.vtu")
1511 ref0 =[3, 5, 10, 12, 3, 12, 10, 11, 3, 12, 11, 13]
1512 ref1 =[3, 2, 6, 7, 3, 2, 7, 3, 3, 1, 5, 6, 3, 1, 6, 2]
1513 self.assertEqual(ref0,mfu.getMeshAtLevel(0)[[3,10,11]].getNodalConnectivity().getValues())
1514 self.assertEqual(ref1,mfu.getMeshAtLevel(0)[[4,5,8,9]].getNodalConnectivity().getValues())
1515 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
1516 mfu.getGroup(-1,"group_dup").checkGeoEquivalWith(mfu.getGroup(-1,"group"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1517 m_bis0 = mfu.getMeshAtLevel(-1)
1518 m_desc, _, _, _, _ = m_bis0.buildDescendingConnectivity()
1519 m_bis0.checkDeepEquivalOnSameNodesWith(mfu.getMeshAtLevel(-1), 2, 9.9999999)
1522 def testBuildInnerBoundary5(self):
1523 """ Full 3D test with tetras only. In this case a tri from the group is not duplicated because it is made only
1524 of non duplicated nodes. The tri in question is hence not part of the final new "dup" group. """
1525 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,
1526 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,
1527 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,
1528 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,
1529 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,
1530 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,
1531 400.0, 0.0, 100.02162286181577, 99.31624553977466, 99.99999998882231, 200.0, 99.31624576683302, 100.00000010178034, 0.0, 99.31624560596512, 200.0, 100.0050761312483,
1532 99.31624560612883, 0.0, 100.00507613125338, 200.0, 99.99999995813045, 100.00950673487786, 0.0, 99.99999989928207, 100.0041870621175, 301.29063354383015,
1533 100.0000000093269, 0.0, 301.29063360689975, 0.0, 100.00957769061164, 140.52853868782435, 99.99999963972768, 100.00509135751312, 297.87779091770784,
1534 97.16750463405486, 97.18018457127863], 46, 3)
1535 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,
1536 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,
1537 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,
1538 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,
1539 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,
1540 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,
1541 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,
1542 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,
1543 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,
1544 21, 26, 33, 3, 14, 35, 45, 32, 29, 14, 29, 34, 9, 28, 14, 15, 45, 24, 40, 14, 29, 45, 28, 15, 14, 21, 24, 45, 40, 14, 24, 15, 1, 28, 14, 35, 45, 29, 30, 14, 26, 15,
1546 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,
1547 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,
1548 360, 365, 370, 375, 380, 385, 390, 395, 400, 405, 410, 415, 420, 425, 430]
1549 m3 = MEDCouplingUMesh("3D", 3)
1551 m3.setConnectivity(DataArrayInt(c0), DataArrayInt(cI0))
1552 m3.checkConsistency()
1553 m2, _, _, _, _ = m3.buildDescendingConnectivity()
1554 grpIds = DataArrayInt([36,74]); grpIds.setName("group")
1555 mfu = MEDFileUMesh()
1556 mfu.setMeshAtLevel(0, m3)
1557 mfu.setMeshAtLevel(-1, m2)
1558 grpIds3D = DataArrayInt([0,1]); grpIds3D.setName("group_3d")
1559 mfu.setGroupsAtLevel(0, [grpIds3D]) # just to check preservation of 3D group
1560 mfu.setGroupsAtLevel(-1, [grpIds])
1561 nNod = m3.getNumberOfNodes()
1562 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1563 m3_bis = mfu.getMeshAtLevel(0)
1564 m3_bis.checkConsistency()
1565 m2_bis = mfu.getMeshAtLevel(-1)
1566 m2_bis.checkConsistency()
1567 self.assertEqual(nNod+1, mfu.getNumberOfNodes())
1568 self.assertEqual(nNod+1, m3_bis.getNumberOfNodes())
1569 self.assertEqual(nNod+1, m2_bis.getNumberOfNodes())
1570 self.assertEqual([3], nodesDup.getValues())
1571 self.assertEqual(m3_bis.getCoords()[3].getValues(), m3_bis.getCoords()[nNod:].getValues())
1572 self.assertEqual(set([22]), set(cells1.getValues()))
1573 self.assertEqual(set([77]), set(cells2.getValues()))
1574 self.assertEqual([36,74],mfu.getGroupArr(-1,"group").getValues())
1575 self.assertEqual([0,1],mfu.getGroupArr(0,"group_3d").getValues())
1576 self.assertEqual([213],mfu.getGroupArr(-1,"group_dup").getValues()) # here only one cell has been duplicated
1577 m_bis0 = mfu.getMeshAtLevel(-1)
1578 m_desc, _, _, _, _ = m_bis0.buildDescendingConnectivity()
1579 m_bis0.checkDeepEquivalOnSameNodesWith(mfu.getMeshAtLevel(-1), 2, 9.9999999)
1583 def testBasicConstructors(self):
1584 GeneratePyfile18(self)
1585 fname="Pyfile18.med"
1586 TestWriteUMeshesRW1(self)
1587 m=MEDFileMesh.New(fname)
1588 m=MEDFileMesh.New(fname,"ExampleOfMultiDimW",-1,-1)
1589 m=MEDFileMesh.New(fname)
1590 m=MEDFileUMesh(fname,"ExampleOfMultiDimW",-1,-1)
1591 m=MEDFileUMesh(fname)
1593 self.internalMEDMesh6()
1594 m=MEDFileCMesh("MEDFileMesh5.med")
1595 m=MEDFileCMesh("MEDFileMesh5.med","myFirstCartMesh",-1,-1)
1597 m=MEDFileMeshMultiTS()
1598 m=MEDFileMeshMultiTS(fname)
1599 m=MEDFileMeshMultiTS(fname,"ExampleOfMultiDimW")
1601 m=MEDFileMeshes(fname)
1603 m=MEDFileField1TS(fname,"FieldOnFacesShuffle",2,7)
1604 m=MEDFileFieldMultiTS()
1605 m=MEDFileFieldMultiTS(fname,"FieldOnFacesShuffle")
1607 m=MEDFileFields(fname)
1609 m=MEDFileData(fname)
1611 m=DataArrayInt() ; m=DataArrayInt(5,2) ; m=DataArrayInt([6,5,4,3,2,1],3,2)
1612 m=DataArrayDouble() ; m=DataArrayDouble(5,2) ; m=DataArrayDouble([6,5,4,3,2,1],3,2)
1613 m=MEDCouplingUMesh("jjj",2) ; m=MEDCouplingUMesh()
1614 m=MEDCouplingCMesh()
1615 m=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1616 m=MEDCouplingFieldTemplate(ON_NODES)
1617 m=MEDCouplingMultiFields([])
1618 m=MEDCouplingFieldOverTime([])
1621 # This is a non regression test. When a field lies partially on a mesh but fully on one of its geometric type.
1623 def testBugSemiPartialField(self):
1624 fname="Pyfile46.med"
1625 m=MEDLoaderDataForTest.build2DMesh_3()
1626 m=m[:10] ; m.setName("mesh")
1627 f=m.getMeasureField(False)
1628 f=f.buildNewTimeReprFromThis(ONE_TIME,False)
1630 f.setName("SemiPartialField")
1632 f1=f[:6] ; f1.getMesh().setName(m.getName())
1633 f2=f[6:] ; f2.getMesh().setName(m.getName())
1635 mm=MEDFileUMesh.New()
1636 mm.setMeshAtLevel(0,m)
1637 ff=MEDFileField1TS.New()
1638 ff.setFieldProfile(f1,mm,0,DataArrayInt.Range(0,6,1)) # no name on profile -> normally it is an error but in this special case
1642 ff2=MEDFileField1TS.New(fname,f.getName(),f.getTime()[1],f.getTime()[2])
1643 fread=ff2.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
1644 fread2=ff2.getFieldAtLevel(ON_CELLS,0)
1646 fread.checkConsistencyLight()
1647 fread2.checkConsistencyLight()
1648 self.assertTrue(fread.isEqual(f1,1e-12,1e-12))
1649 self.assertTrue(fread2.isEqual(f1,1e-12,1e-12))
1653 def testUnPolyze1(self):
1654 fname="Pyfile47.med"
1655 mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1656 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]
1657 self.assertEqual(ref,mm.getFamilyFieldAtLevel(1).getValues())
1658 self.assertEqual(mm.unPolyze()[:3],(True,[[3,2,0],[4,3,2],[5,4,5],[14,2,9],[16,3,11],[31,2,14]],[[3,3,0],[4,3,3],[5,3,6],[14,3,9],[16,3,12],[18,1,15]]))
1660 self.assertEqual(mm.getGroupArr(0,"grp0_L0").getValues(),[0,1,2,6])
1661 self.assertEqual(mm.getGroupArr(0,"grp1_L0").getValues(),[1,3,4,5,6])
1662 self.assertEqual(mm.getGroupArr(-1,"grp0_LM1").getValues(),[1,2,3,4,5])
1663 self.assertEqual(mm.getGroupArr(-1,"grp1_LM1").getValues(),[3,4,5,6])
1664 self.assertEqual(mm.getGroupArr(-1,"grp2_LM1").getValues(),[2,6,7,8])
1665 self.assertEqual(mm.getGroupArr(1,"grp0_Node").getValues(),[0,11,15,16])
1666 self.assertEqual(mm.getGroupArr(1,"grp1_Node").getValues(),[1,2,13,14,16])
1667 self.assertEqual(mm.getFamilyFieldAtLevel(1).getValues(),ref)
1669 mm.setRenumFieldArr(0,None)
1670 mm.setFamilyFieldArr(-1,None)
1674 def testUnPolyze2(self):
1675 fname="Pyfile48.med"
1676 mfd=MEDFileData.New()
1677 mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1678 meshes=MEDFileMeshes.New()
1680 mfd.setMeshes(meshes)
1681 fields=MEDFileFields.New()
1682 mfd.setFields(fields)
1683 ff=MEDFileFieldMultiTS.New()
1684 fields.pushField(ff)
1686 f0_0=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f0_0.setName("f0")
1687 f0_0.setTime(9.5,3,4)
1688 da=DataArrayDouble.New(38*2) ; da.iota(6.) ; da.rearrange(2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1690 f0_0.setMesh(mm.getMeshAtLevel(0))
1691 ff.appendFieldNoProfileSBT(f0_0)
1692 ff0=ff.getTimeStepAtPos(0)
1693 f0_1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_1.setName("f0")
1694 f0_1.setTime(9.5,3,4)
1695 pfl=DataArrayInt.New([1,4,5,6]) ; pfl.setName("pfltest")
1696 f0_1.setMesh(mm.getMeshAtLevel(0)[pfl])
1697 da=DataArrayDouble.New([1401.,101401.,1602.,101602.,3100.,103100.,3101.,103101.],4,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1699 ff0.setFieldProfile(f0_1,mm,0,pfl)
1700 f0_2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_2.setName("f0")#provoquer error
1701 f0_2.setTime(9.5,3,4)
1702 pfl2=DataArrayInt.New([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfltestM1")
1703 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
1704 f0_2.setMesh(mm.getMeshAtLevel(-1)[pfl2])
1706 ff0.setFieldProfile(f0_2,mm,-1,pfl2)
1707 mfd.getFields().shallowCpyGlobs(ff0)
1709 mfd.unPolyzeMeshes()
1711 fmts=mfd.getFields()[0]
1712 self.assertEqual(fmts.getNumberOfTS(),1)
1713 self.assertEqual(fmts.getTimeSteps(),[(3,4,9.5)])
1714 arr,entry=fmts.getUndergroundDataArrayExt(3,4)
1715 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))])
1716 self.assertTrue(arr[38:40].isEqualWithoutConsideringStr(DataArrayDouble([300.0,100300.0,301.0,100301.0],2,2),1e-8))
1717 self.assertTrue(arr[40:43].isEqualWithoutConsideringStr(DataArrayDouble([400.0,100400.0,401.0,100401.0,402.0,100402.0],3,2),1e-8))
1718 self.assertTrue(arr[43:46].isEqualWithoutConsideringStr(DataArrayDouble([3200.0,103200.0,3201.0,103201.0,3203.0,103203.0],3,2),1e-8))
1719 self.assertTrue(arr[46:48].isEqualWithoutConsideringStr(DataArrayDouble([1401.0,101401.0,3100.0,103100.0],2,2),1e-8))
1720 self.assertTrue(arr[48:49].isEqualWithoutConsideringStr(DataArrayDouble([1602.0,101602.0],1,2),1e-8))
1721 self.assertTrue(arr[49:50].isEqualWithoutConsideringStr(DataArrayDouble([3101.0,103101.0],1,2),1e-8))
1722 self.assertEqual(('NewPfl_0','NewPfl_1','NewPfl_2'),fmts.getPflsReallyUsed())
1723 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))
1724 self.assertEqual(fmts.getProfile("NewPfl_0").getValues(),[0,1])
1725 self.assertEqual(fmts.getProfile("NewPfl_1").getValues(),[1,2])
1726 self.assertEqual(fmts.getProfile("NewPfl_2").getValues(),[2])
1727 ftest0=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,0,mfd.getMeshes()[0])
1728 self.assertTrue(ftest0.getArray().isEqualWithoutConsideringStr(DataArrayDouble([1401.,101401.,3100.,103100.,1602.,101602.,3101.,103101.],4,2),1e-8))
1729 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])
1730 self.assertEqual(ftest0.getMesh().getNodalConnectivityIndex().getValues(),[0,5,10,17,26])
1731 ftest1=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,-1,mfd.getMeshes()[0])
1732 self.assertTrue(ftest1.getArray().isEqualWithoutConsideringStr(DataArrayDouble([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.]),1e-8))
1733 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])
1734 self.assertEqual(ftest1.getMesh().getNodalConnectivityIndex().getValues(),[0,4,8,13,18,23,29,35,43])
1740 def testGaussWriteOnPfl1(self):
1741 fname="Pyfile49.med"
1742 fname2="Pyfile50.med"
1743 coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
1744 mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
1745 mQ8.allocateCells(1)
1746 mQ8.insertNextCell(NORM_QUAD8,list(range(8)))
1747 mQ8.finishInsertingCells()
1748 mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
1749 mQ4.allocateCells(1)
1750 mQ4.insertNextCell(NORM_QUAD4,list(range(4)))
1751 mQ4.finishInsertingCells()
1752 mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
1753 mT3.allocateCells(1)
1754 mT3.insertNextCell(NORM_TRI3,list(range(3)))
1755 mT3.finishInsertingCells()
1757 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.]]
1758 ms=11*[mT3]+2*[mQ4]+7*[mQ8]
1759 ms[:]=(elt.deepCopy() for elt in ms)
1760 for m,t in zip(ms,tr):
1761 d=m.getCoords() ; d+= t
1763 m=MEDCouplingUMesh.MergeUMeshes(ms)
1765 m2=m[:13] ; m2.setName(m.getName())
1766 ### 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.
1767 ### So here 2 pfls will be created (pfl_TRI3_loc_0 and pfl_TRI3_loc_1)
1768 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1771 da=DataArrayDouble(34) ; da.iota(3.)
1773 f.setName("fieldCellOnPflWithoutPfl")
1774 fInvalid=f.deepCopy()
1775 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])
1776 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])
1777 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])
1778 f.checkConsistencyLight()
1779 fInvalid2=fInvalid.deepCopy()
1780 fInvalid2.getDiscretization().setArrayOfDiscIds(f.getDiscretization().getArrayOfDiscIds())
1783 mm.setMeshAtLevel(0,m)
1786 f1ts=MEDFileField1TS.New()
1787 pfl=DataArrayInt(list(range(13))) ; pfl.setName("pfl")
1788 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set !
1789 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given !
1790 f1ts.setFieldProfile(f,mm,0,pfl)
1793 self.assertEqual(f1ts.getPfls(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1794 self.assertEqual(f1ts.getPflsReallyUsed(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
1795 da1=DataArrayInt([0,1,2,3,4,5,6,7,8]) ; da1.setName("pfl_NORM_TRI3_loc_0")
1796 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_0").isEqual(da1))
1797 da1=DataArrayInt([9,10]) ; da1.setName("pfl_NORM_TRI3_loc_1")
1798 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_1").isEqual(da1))
1799 self.assertEqual(f1ts.getLocs(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1800 self.assertEqual(f1ts.getLocsReallyUsed(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
1802 dataRead=MEDFileData.New(fname)
1803 mRead=dataRead.getMeshes()[0]
1804 f1tsRead=dataRead.getFields()[0][0]
1805 f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1806 f2=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1807 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
1808 f2_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1809 f2_bis.checkConsistencyLight()
1810 self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12))
1812 WriteField(fname2,f,True)
1813 f2_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1814 self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12))
1815 ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc
1816 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1817 pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2")
1818 m2=m[pfl] ; m2.setName(m.getName())
1821 da=DataArrayDouble(35) ; da.iota(3.)
1823 f.setName("fieldCellOnPflWithoutPfl2")
1824 f.setGaussLocalizationOnCells([0,1,3],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
1825 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])
1826 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])
1827 f.checkConsistencyLight()
1830 mm.setMeshAtLevel(0,m)
1832 f1ts=MEDFileField1TS.New()
1833 f1ts.setFieldProfile(f,mm,0,pfl)
1834 self.assertEqual(f1ts.getPfls(),('pfl2_NORM_TRI3_loc_0','pfl2_NORM_TRI3_loc_1','pfl2_NORM_QUAD8_loc_2'))
1835 self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_0").getValues(),[1,2,6])
1836 self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_1").getValues(),[5,8,9])
1837 self.assertEqual(f1ts.getProfile("pfl2_NORM_QUAD8_loc_2").getValues(),[2,3,4,5])
1839 dataRead=MEDFileData.New(fname)
1840 mRead=dataRead.getMeshes()[0]
1841 f1tsRead=dataRead.getFields()[0][0]
1842 f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1843 f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1844 f3.renumberCells([0,1,3,2,4,5,6,7,8,9])
1845 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1846 f3_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1847 f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9])
1848 self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1850 WriteField(fname2,f,True)
1851 f3_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1852 f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9])
1853 self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1854 ## Use case 3 : no pfl but creation of pfls due to gauss pts
1855 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1858 da=DataArrayDouble(60) ; da.iota(3.)
1860 f.setName("fieldCellWithoutPfl")
1861 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])
1862 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])
1863 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])
1864 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])
1865 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])
1866 f.checkConsistencyLight()
1868 mm.setMeshAtLevel(0,m)
1869 f1ts=MEDFileField1TS.New()
1870 f1ts.setFieldNoProfileSBT(f)
1871 self.assertEqual(f1ts.getPfls(),('Pfl_fieldCellWithoutPfl_NORM_TRI3_0','Pfl_fieldCellWithoutPfl_NORM_TRI3_1','Pfl_fieldCellWithoutPfl_NORM_QUAD8_3','Pfl_fieldCellWithoutPfl_NORM_QUAD8_4'))
1872 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_0").getValues(),[0,1,2,3,4,5,6,7,8])
1873 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_1").getValues(),[9,10])
1874 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_3").getValues(),[0,1,2,4,5])
1875 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_4").getValues(),[3,6])
1879 dataRead=MEDFileData.New(fname)
1880 mRead=dataRead.getMeshes()[0]
1881 f1tsRead=dataRead.getFields()[0][0]
1882 f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
1883 f3.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1884 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
1885 f3_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1886 f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1887 self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
1889 WriteField(fname2,f,True)
1890 f3_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
1891 f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
1892 self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
1895 # Testing profile on nodes when the profile is identity but not on all nodes.
1897 def testMEDFieldPflOnNode1(self):
1898 fname="Pyfile51.med"
1899 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)
1900 m0=MEDCouplingUMesh("Mesh",2)
1902 m0.insertNextCell(NORM_TRI3,[1,4,2])
1903 m0.insertNextCell(NORM_TRI3,[4,5,2])
1904 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1905 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1906 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1907 m0.finishInsertingCells()
1909 m1=MEDCouplingUMesh(m0.getName(),1)
1911 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
1913 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
1915 m1.finishInsertingCells()
1919 m.setMeshAtLevel(0,m0)
1920 m.setMeshAtLevel(-1,m1)
1922 dt=3 ; it=2 ; tim=4.5
1923 fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1924 fieldNode0.setName("fieldNode0")
1925 fieldNode0.setTime(tim,dt,it)
1926 pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
1927 arr=DataArrayDouble([10,11,12,13,14])
1928 fieldNode0.setArray(arr)
1929 f0=MEDFileField1TS()
1930 f0.setFieldProfile(fieldNode0,m,0,pfl0)
1931 m.write(fname,2) ; f0.write(fname,0)
1932 fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
1933 fieldNode1.setName("fieldNode1")
1934 fieldNode1.setTime(tim,dt,it)
1935 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
1936 arr1=DataArrayDouble([20,21,22,23,24,25,26])
1937 fieldNode1.setArray(arr1)
1938 f1=MEDFileField1TS()
1939 f1.setFieldProfile(fieldNode1,m,-1,pfl1)
1942 ## Reading from file
1943 m=MEDFileMesh.New(fname)
1944 m0=m.getMeshAtLevel(0)
1945 m00=m0.deepCopy() ; m00=m00[[0,2]] ; m00.setName(m.getName()) ; m00.zipCoords()
1946 fieldNode0.setMesh(m00)
1947 f0=MEDFileField1TS.New(fname,fieldNode0.getName(),dt,it)
1948 ff0_1=f0.getFieldOnMeshAtLevel(ON_NODES,m0)
1949 ff0_1.checkConsistencyLight()
1950 self.assertTrue(ff0_1.isEqual(fieldNode0,1e-12,1e-12))
1951 ff0_2=f0.getFieldAtLevel(ON_NODES,0)
1952 ff0_2.checkConsistencyLight()
1953 self.assertTrue(ff0_2.isEqual(fieldNode0,1e-12,1e-12))
1954 ff0_3=f0.getFieldOnMeshAtLevel(ON_NODES,0,m)
1955 ff0_3.checkConsistencyLight()
1956 self.assertTrue(ff0_3.isEqual(fieldNode0,1e-12,1e-12))
1957 ff0_4=ReadFieldNode(fname,m.getName(),0,fieldNode0.getName(),dt,it)
1958 ff0_4.checkConsistencyLight()
1959 self.assertTrue(ff0_4.isEqual(fieldNode0,1e-12,1e-12))
1960 f1=MEDFileField1TS.New(fname,fieldNode1.getName(),dt,it)
1961 m1=m.getMeshAtLevel(-1)
1962 m10=m1.deepCopy() ; m10=m10[[0,1,2,3,4,5,6,7]] ; m10.setName(m.getName()) ; m10.zipCoords()
1963 fieldNode1.setMesh(m10)
1964 ff1_1=f1.getFieldOnMeshAtLevel(ON_NODES,m1)
1965 ff1_1.checkConsistencyLight()
1966 self.assertTrue(ff1_1.isEqual(fieldNode1,1e-12,1e-12))
1967 ff1_2=f1.getFieldAtLevel(ON_NODES,-1)
1968 ff1_2.checkConsistencyLight()
1969 self.assertTrue(ff1_2.isEqual(fieldNode1,1e-12,1e-12))
1970 ff1_3=f1.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1971 ff1_3.checkConsistencyLight()
1972 self.assertTrue(ff1_3.isEqual(fieldNode1,1e-12,1e-12))
1973 ff1_4=ReadFieldNode(fname,m.getName(),-1,fieldNode1.getName(),dt,it)
1974 ff1_4.checkConsistencyLight()
1975 self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
1976 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]
1977 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]
1978 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]
1979 arr_r,pfl1_r=f1.getFieldWithProfile(ON_NODES,-1,m)
1980 arr_r.setName(fieldNode1.getArray().getName())
1981 self.assertTrue(arr_r.isEqual(fieldNode1.getArray(),1e-12))
1982 pfl1_r.setName(pfl1.getName())
1983 self.assertTrue(pfl1_r.isEqual(pfl1))
1986 # Testing profile on nodes when the profile is identity but not on all nodes.
1988 def testMEDFieldPflOnCell1(self):
1989 fname="Pyfile52.med"
1990 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)
1991 m0=MEDCouplingUMesh("Mesh",2)
1993 m0.insertNextCell(NORM_TRI3,[1,4,2])
1994 m0.insertNextCell(NORM_TRI3,[4,5,2])
1995 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
1996 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
1997 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
1998 m0.finishInsertingCells()
2000 m1=MEDCouplingUMesh(m0.getName(),1)
2002 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
2004 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
2006 m1.finishInsertingCells()
2010 m.setMeshAtLevel(0,m0)
2011 m.setMeshAtLevel(-1,m1)
2013 dt=3 ; it=2 ; tim=4.5
2014 fieldCell0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
2015 fieldCell0.setName("fieldCell0")
2016 fieldCell0.setTime(tim,dt,it)
2017 pfl0=DataArrayInt([0,1,2]) ; pfl0.setName("PflIdentity0") # important to keep like that
2018 arr=DataArrayDouble([10,11,12])
2019 fieldCell0.setArray(arr)
2020 f0=MEDFileField1TS()
2021 f0.setFieldProfile(fieldCell0,m,0,pfl0)
2022 m.write(fname,2) ; f0.write(fname,0)
2023 fieldCell1=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
2024 fieldCell1.setName("fieldCell1")
2025 fieldCell1.setTime(tim,dt,it)
2026 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
2027 arr1=DataArrayDouble([20,21,22,23,24,25,26])
2028 fieldCell1.setArray(arr1)
2029 f1=MEDFileField1TS()
2030 f1.setFieldProfile(fieldCell1,m,-1,pfl1)
2033 ## Reading from file
2034 m=MEDFileMesh.New(fname)
2035 m0=m.getMeshAtLevel(0)
2036 m00=m0.deepCopy() ; m00=m00[pfl0] ; m00.setName(m.getName())
2037 fieldCell0.setMesh(m00)
2038 f0=MEDFileField1TS.New(fname,fieldCell0.getName(),dt,it)
2039 ff0_1=f0.getFieldOnMeshAtLevel(ON_CELLS,m0)
2040 ff0_1.checkConsistencyLight()
2041 self.assertTrue(ff0_1.isEqual(fieldCell0,1e-12,1e-12))
2042 ff0_2=f0.getFieldAtLevel(ON_CELLS,0)
2043 ff0_2.checkConsistencyLight()
2044 self.assertTrue(ff0_2.isEqual(fieldCell0,1e-12,1e-12))
2045 ff0_3=f0.getFieldOnMeshAtLevel(ON_CELLS,0,m)
2046 ff0_3.checkConsistencyLight()
2047 self.assertTrue(ff0_3.isEqual(fieldCell0,1e-12,1e-12))
2048 ff0_4=ReadFieldCell(fname,m.getName(),0,fieldCell0.getName(),dt,it)
2049 ff0_4.checkConsistencyLight()
2050 self.assertTrue(ff0_4.isEqual(fieldCell0,1e-12,1e-12))
2051 f1=MEDFileField1TS.New(fname,fieldCell1.getName(),dt,it)
2052 m1=m.getMeshAtLevel(-1)
2053 m10=m1.deepCopy() ; m10=m10[pfl1] ; m10.setName(m.getName())
2054 fieldCell1.setMesh(m10)
2055 ff1_1=f1.getFieldOnMeshAtLevel(ON_CELLS,m1)
2056 ff1_1.checkConsistencyLight()
2057 self.assertTrue(ff1_1.isEqual(fieldCell1,1e-12,1e-12))
2058 ff1_2=f1.getFieldAtLevel(ON_CELLS,-1)
2059 ff1_2.checkConsistencyLight()
2060 self.assertTrue(ff1_2.isEqual(fieldCell1,1e-12,1e-12))
2061 ff1_3=f1.getFieldOnMeshAtLevel(ON_CELLS,-1,m)
2062 ff1_3.checkConsistencyLight()
2063 self.assertTrue(ff1_3.isEqual(fieldCell1,1e-12,1e-12))
2064 ff1_4=ReadFieldCell(fname,m.getName(),-1,fieldCell1.getName(),dt,it)
2065 ff1_4.checkConsistencyLight()
2066 self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
2067 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]
2068 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]
2069 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]
2070 arr_r,pfl1_r=f1.getFieldWithProfile(ON_CELLS,-1,m)
2071 arr_r.setName(fieldCell1.getArray().getName())
2072 self.assertTrue(arr_r.isEqual(fieldCell1.getArray(),1e-12))
2073 pfl1_r.setName(pfl1.getName())
2074 self.assertTrue(pfl1_r.isEqual(pfl1))
2078 def testMEDFileUMeshZipCoords1(self):
2080 coo=DataArrayDouble(30) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2081 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])
2082 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2083 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2084 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2085 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2086 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2087 numCoo=DataArrayInt(10) ; numCoo.iota(3) ; m.setRenumFieldArr(1,numCoo)
2088 famCoo=DataArrayInt(10) ; famCoo.iota(4) ; m.setFamilyFieldArr(1,famCoo)
2089 da=DataArrayInt([20,30,40]) ; m.setRenumFieldArr(0,da) ; da=DataArrayInt([200,300,400]) ; m.setFamilyFieldArr(0,da)
2090 da=DataArrayInt([50,60]) ; m.setRenumFieldArr(-1,da) ; da=DataArrayInt([500,600]) ; m.setFamilyFieldArr(-1,da)
2091 da=DataArrayInt([70,80,90]) ; m.setRenumFieldArr(-2,da) ; da=DataArrayInt([700,800,900]) ; m.setFamilyFieldArr(-2,da)
2093 self.assertTrue(o2n.isEqual(DataArrayInt([-1,0,1,2,3,-1,4,5,6,-1])))
2094 self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt([4,5,6,7,9,10,11])))
2095 self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([5,6,7,8,10,11,12])))
2096 self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,4,1,3,2,3,5,0,4,4,4,1])))
2097 self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,9,15])))
2098 self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivity().isEqual(DataArrayInt([1,0,4,1,5,2])))
2099 self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6])))
2100 self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivity().isEqual(DataArrayInt([0,1,0,4,0,6])))
2101 self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivityIndex().isEqual(DataArrayInt([0,2,4,6])))
2105 def testMEDUMeshAddNodeGroup1(self):
2106 fname="Pyfile53.med"
2108 coo=DataArrayDouble(39) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2109 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])
2110 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2111 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2112 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2113 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2114 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2117 famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(1,famCoo)
2118 da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(0,da0)
2119 da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
2120 da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
2121 mm.setFamilyId("MyFam",2)
2122 mm.setFamilyId("MyOtherFam",3)
2123 mm.setFamilyId("MyOther-1",-1)
2124 mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
2125 mm.setFamiliesOnGroup("grpA",["MyOther-1"])
2127 self.assertTrue(mm.getNodeFamiliesArr(["MyFam","MyOtherFam"]).isEqual(DataArrayInt([1,3,4,12]))) # find family id 2 and 3 into famCoo
2129 daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
2130 mm.addNodeGroup(daTest)
2131 self.assertTrue(mm.getNodeGroupArr(daTest.getName()).isEqual(daTest)) # the node group has been pushed right before -> now read it
2132 self.assertTrue(mm.getNodeGroupsArr(["grp1","grpA"]).isEqual(DataArrayInt([1,3,4,6,9,10,11,12])))#daTest+[11] because 11 is the rank of -1 (MyOther-1) in famCoo
2134 expect1=DataArrayInt([1,4]) ; expect1.setName("MyFam")
2135 self.assertTrue(mm.getNodeFamilyArr(expect1.getName()).isEqual(expect1))
2137 self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
2138 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
2139 for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
2140 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2142 self.assertEqual(mm.getFamiliesNames(),('Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
2143 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2144 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2145 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2146 for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
2147 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2149 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_8'))
2150 da=DataArrayInt([3,12]) ; da.setName("grp0")
2151 self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
2153 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2155 mm=MEDFileMesh.New(fname)
2156 self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
2157 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
2158 for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
2159 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2161 self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
2162 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2163 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2164 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2165 for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
2166 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2168 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_8','MyOtherFam'))
2169 da=DataArrayInt([3,12]) ; da.setName("grp0")
2170 self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
2172 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2176 def testMEDUMeshAddGroup1(self):
2177 fname="Pyfile54.med"
2179 coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2180 m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
2182 m0.insertNextCell(NORM_TRI3,[1,2,1])
2185 m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
2188 m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
2190 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2191 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2192 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2193 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2194 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2197 famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(0,famCoo)
2198 da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(1,da0)
2199 da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
2200 da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
2201 mm.setFamilyId("MyFam",2)
2202 mm.setFamilyId("MyOtherFam",3)
2203 mm.setFamilyId("MyOther-1",-1)
2204 mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
2205 mm.setFamiliesOnGroup("grpA",["MyOther-1"])
2207 daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
2208 mm.addGroup(0,daTest)
2209 self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2210 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2211 for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2212 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2214 self.assertEqual(mm.getFamiliesNames(),('Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2215 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2216 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2217 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2218 for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2219 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2221 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_-8'))
2222 da=DataArrayInt([3,12]) ; da.setName("grp0")
2223 self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2225 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2227 mm=MEDFileMesh.New(fname)
2228 self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2229 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2230 for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2231 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2233 self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2234 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2235 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2236 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2237 for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2238 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2240 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_-8','MyOtherFam'))
2241 da=DataArrayInt([3,12]) ; da.setName("grp0")
2242 self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2244 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2248 def testHeapMem1(self):
2249 a=DataArrayInt() ; aa=a.getHeapMemorySize()
2251 strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
2253 m=MEDCouplingCMesh()
2254 arr=DataArrayDouble(10,1) ; arr.iota(0)
2255 m.setCoords(arr,arr)
2256 m=m.buildUnstructured()
2258 f=m.getMeasureField(False)
2259 self.assertIn(m.getHeapMemorySize(), list(range(3552 - 100, 3552 + 100 + 4 * strMulFac)))
2260 self.assertIn(f.getHeapMemorySize(), list(range(4215 - 100, 4215 + 100 + 8 * strMulFac)))
2263 mm.setMeshAtLevel(0,m)
2264 self.assertIn(mm.getHeapMemorySize(), list(range(3889 - 100, 4225 + 100 + 10 * strMulFac)))
2265 ff=MEDFileField1TS()
2266 ff.setFieldNoProfileSBT(f)
2267 self.assertIn(ff.getHeapMemorySize(), list(range(771 - 40, 871 + 21 + (4 + 1) * strMulFac)))
2269 fff=MEDFileFieldMultiTS()
2270 fff.appendFieldNoProfileSBT(f)
2271 self.assertIn(fff.getHeapMemorySize(), list(range(815 - 50, 915 + 30 + (6 + 2) * strMulFac)))
2273 fff.appendFieldNoProfileSBT(f)
2274 self.assertIn(fff.getHeapMemorySize(), list(range(1594 - 90, 1794 + 50 + (10 + 1) * strMulFac)))
2275 self.assertIn(fff[0, -1].getHeapMemorySize(), list(range(771 - 40, 871 + 20 + (4 + 1) * strMulFac)))
2278 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2279 fff.appendFieldProfile(f2,mm,0,pfl)
2280 self.assertIn(fff.getHeapMemorySize(), list(range(2348 - 130, 2608 + 100 + (10 + 2) * strMulFac)))
2281 self.assertIn(fff.getProfile("pfl").getHeapMemorySize(), list(range(204 - 10, 204 + 10 + 2 * strMulFac)))
2282 self.assertIn(fff[1, -1].getHeapMemorySize(), list(range(738 - 50, 838 + 30 + 4 * strMulFac)))
2285 def internalCurveLinearMesh1(self):
2286 fname="Pyfile55.med"
2287 mesh=MEDCouplingCurveLinearMesh();
2288 mesh.setTime(2.3,4,5);
2289 mesh.setTimeUnit("us");
2290 mesh.setName("Example of Cuve linear mesh");
2291 mesh.setDescription("buildCLMesh");
2292 a1=DataArrayDouble(3*20,1);
2293 a1.iota(7.) ; a1.rearrange(3);
2295 mesh.setNodeGridStructure([4,5]);
2296 mesh.checkConsistencyLight();
2298 m=MEDFileCurveLinearMesh()
2300 d=DataArrayInt(20) ; d.iota(4)
2301 m.setFamilyFieldArr(1,d)
2302 d3=DataArrayInt(20) ; d3.iota(400)
2303 m.setRenumFieldArr(1,d3)
2304 d2=DataArrayInt(12) ; d2.iota(40)
2305 m.setFamilyFieldArr(0,d2)
2306 d4=DataArrayInt(21) ; d4.iota(4000)
2307 self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2309 m.setRenumFieldArr(1,d4)
2312 m1=MEDFileCurveLinearMesh(fname)
2314 self.assertTrue(mm.isEqual(mesh,1e-12))
2315 self.assertEqual(mm.getSpaceDimension(),3)
2316 self.assertEqual(mm.getSpaceDimensionOnNodeStruct(),2)
2318 m1=MEDFileMesh.New(fname)
2319 self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2320 self.assertTrue(isinstance(m1.getUnivName(),str))
2321 self.assertTrue(len(m1.getUnivName())!=0)
2322 self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2326 def testCurveLinearMesh1(self):
2327 self.internalCurveLinearMesh1()
2330 def testParameters1(self):
2331 self.internalParameters1()
2333 def internalParameters1(self):
2334 fname="Pyfile56.med"
2335 m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2336 mm=MEDFileCMesh() ; mm.setMesh(m)
2337 ms=MEDFileMeshes() ; ms.pushMesh(mm)
2339 p=MEDFileParameters()
2340 data.setParams(p) ; data.setMeshes(ms)
2341 pts=MEDFileParameterMultiTS()
2342 pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2343 pts.appendValue(1,2,3.4,567.89)
2344 pts.appendValue(2,3,5.6,999.123)
2345 pts2=pts.deepCopy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2346 p.pushParam(pts) ; p.pushParam(pts2)
2348 p2=MEDFileParameters(fname)
2349 self.assertTrue(p.isEqual(p2,1e-14)[0])
2350 self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2352 pts4=pts2.deepCopy()
2353 pts3=pts2.deepCopy()
2354 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2355 pts2.eraseTimeStepIds([0])
2356 self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2358 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2359 self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2360 self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2361 self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2362 self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2364 self.assertTrue(p.isEqual(p2,1e-14)[0])
2365 self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2366 self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2367 self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2368 self.assertEqual(p.getParamsNames(),('A','B'))
2369 ptsr=MEDFileParameterMultiTS(fname,"B")
2370 self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2371 ptsr=MEDFileParameterMultiTS(fname)
2372 self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2373 p1tsr=MEDFileParameterDouble1TS(fname)
2374 self.assertEqual(p1tsr.getName(),"A")
2375 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2376 p1tsr=MEDFileParameterDouble1TS(fname,"B")
2377 self.assertEqual(p1tsr.getName(),"B")
2378 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2379 p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2380 self.assertEqual(p1tsr.getName(),"B")
2381 self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2382 data2=MEDFileData(fname)
2383 self.assertEqual(2,data2.getNumberOfParams())
2384 self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2388 def testNamesOnCellAndNodesInMeshes1(self):
2389 fname="Pyfile58.med"
2390 fname2="Pyfile59.med"
2391 m=MEDLoaderDataForTest.build3DSurfMesh_1()
2392 m1=m.buildDescendingConnectivity()[0]
2393 m1.sortCellsInMEDFileFrmt()
2396 mm.setMeshAtLevel(0,m)
2397 mm.setMeshAtLevel(-1,m1)
2398 namesCellL0=DataArrayAsciiChar(6,16)
2399 namesCellL0[:] = ["CellL0#%.3d " % (i) for i in range(6)]
2400 mm.setNameFieldAtLevel(0,namesCellL0)
2401 namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.subArray(2)])
2402 namesCellL1[:] = ["CellLM1#%.3d " % (i) for i in range(16)]
2403 mm.setNameFieldAtLevel(-1,namesCellL1)
2404 namesNodes=namesCellL1.subArray(4,16)
2405 namesNodes[:] = ["Node#%.3d " % (i) for i in range(12)]
2406 mm.setNameFieldAtLevel(1,namesNodes)
2409 mmr=MEDFileMesh.New(fname)
2410 self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
2411 self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d " % (i) for i in range(16)])))
2412 self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(12)])))
2413 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2414 mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2415 self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2416 mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2417 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2419 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2420 # remove names on nodes
2421 mmCpy.setNameFieldAtLevel(1,None)
2422 self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2423 mm.setNameFieldAtLevel(1,None)
2424 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2425 mm.setNameFieldAtLevel(-1,None)
2427 mmr=MEDFileMesh.New(fname)
2428 self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2429 self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
2430 self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2432 c=MEDCouplingCMesh()
2433 arr=DataArrayDouble([0.,1.1,2.3])
2434 c.setCoords(arr,arr)
2438 cc.setNameFieldAtLevel(0, DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)]))
2439 cc.setNameFieldAtLevel(1, DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)]))
2441 ccr=MEDFileMesh.New(fname2)
2442 self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)])))
2443 self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)])))
2444 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2445 ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2446 self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2447 ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2448 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2450 self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2454 def testToExportInExamples1(self):
2455 m=MEDCouplingCMesh()
2456 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2457 m.setCoords(arr,arr)
2458 m=m.buildUnstructured() ; m.setName("mesh")
2459 grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2460 grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2463 mm.setMeshAtLevel(0,m)
2464 mm.setMeshAtLevel(-1,m2)
2465 mm.setGroupsAtLevel(0,[grp1,grp2])
2466 mm.write("example.med",2)
2468 m0=mm.getMeshAtLevel(0)
2469 m1=mm.getMeshAtLevel(-1)
2470 grp1=mm.getGroupArr(0,"grp1")
2471 grp2=mm.getGroupArr(0,"grp2")
2473 whichGrp=DataArrayInt(m0.getNumberOfCells())
2474 whichGrp.fillWithValue(-1)
2475 for grpId,grp in enumerate(grps):
2478 a,b,bI,c,cI=m0.buildDescendingConnectivity()
2479 e,f=a.areCellsIncludedIn(m1,2)
2481 c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2482 self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2483 c2.transformWithIndArr(whichGrp)
2484 splitOfM1=len(grps)*[None]
2485 for grpId,grp in enumerate(grps):
2486 tmp=c2.findIdsEqual(grpId)
2487 splitOfM1[grpId]=tmp
2489 splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2490 splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2494 def testBugCorrection1(self):
2497 self.assertEqual(fs[0],None)
2498 self.assertEqual(3,len(fs))
2502 def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2503 f1Name="Pyfile60.med"
2504 f2Name="Pyfile61.med"
2505 d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2507 d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2509 # reading and compare
2510 d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2511 for mn in d1.getMeshes().getMeshesNames():
2512 m1=d1.getMeshes()[mn]
2513 m2=d2.getMeshes()[mn]
2514 for lev in m1.getNonEmptyLevels():
2515 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2516 for grpName in grpsNames:
2517 self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2521 for fieldn in d1.getFields().getFieldsNames():
2522 f1=d1.getFields()[fieldn]
2523 f2=d2.getFields()[fieldn]
2524 for it,order,tim in f1.getTimeSteps():
2527 if len(f1t.getPflsReallyUsed())!=0:
2529 for lev in f1t.getNonEmptyLevels()[1]:
2530 arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2531 arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2532 self.assertTrue(pfl1.isEqual(pfl2))
2533 self.assertTrue(arr1.isEqual(arr2,1e-10))
2538 for lev in f1t.getNonEmptyLevels()[1]:
2539 f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2540 f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2541 self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2549 def testNonRegBugNormalizeFamIdsMEDFile1(self):
2550 m=MEDCouplingCMesh()
2551 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2552 m.setCoords(arr,arr,arr)
2553 m=m.buildUnstructured()
2554 m2=m.buildDescendingConnectivity()[0]
2556 g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2557 g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2558 g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2559 g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2560 g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2561 g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2563 mm.setMeshAtLevel(0,m)
2564 mm.setGroupsAtLevel(0,[g1,g2])
2565 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2566 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2567 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2568 mm.normalizeFamIdsMEDFile()
2569 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2570 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2571 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2572 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2573 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2574 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2575 for g in mm.getGroupsOnSpecifiedLev(0):
2576 for f in mm.getFamiliesIdsOnGroup(g):
2577 self.assertTrue(f<0)
2582 mm.setMeshAtLevel(0,m)
2583 mm.setMeshAtLevel(-1,m2)
2584 mm.setGroupsAtLevel(0,[g1,g2])
2585 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2586 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2587 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2588 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2589 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2590 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2591 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2592 mm.normalizeFamIdsMEDFile()
2593 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2594 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2595 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2596 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2597 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2598 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2599 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2600 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2601 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2602 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2603 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2604 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2606 for g in mm.getGroupsOnSpecifiedLev(lev):
2607 for f in mm.getFamiliesIdsOnGroup(g):
2608 self.assertTrue(f<0)
2614 mm.setMeshAtLevel(0,m)
2615 mm.setMeshAtLevel(-1,m2)
2616 mm.setGroupsAtLevel(0,[g1,g2])
2617 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2618 mm.setGroupsAtLevel(1,[g1Node,g2Node])
2619 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2620 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2621 s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2622 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2623 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2624 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2625 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2626 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2627 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2628 mm.normalizeFamIdsMEDFile()
2629 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2630 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2631 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2632 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2633 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2634 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2635 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2636 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2637 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2638 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2639 self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2640 self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2641 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2642 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2643 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2644 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2645 self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2646 self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2648 for g in mm.getGroupsOnSpecifiedLev(lev):
2649 for f in mm.getFamiliesIdsOnGroup(g):
2650 self.assertTrue(f<0)
2654 for g in mm.getGroupsOnSpecifiedLev(1):
2655 for f in mm.getFamiliesIdsOnGroup(g):
2656 self.assertTrue(f>0)
2662 def testNonRegressionMantis22212ChangeGrpName(self):
2663 fileName="Pyfile62.med"
2664 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2665 m=MEDFileUMesh.New()
2666 m.setCoords(m2.getCoords())
2667 m.setMeshAtLevel(0,m2)
2668 m.setMeshAtLevel(-1,m1)
2669 m.setMeshAtLevel(-2,m0)
2670 m.setFamilyFieldArr(0,f2)
2671 m.setFamilyFieldArr(-1,f1)
2672 m.setFamilyFieldArr(-2,f0)
2673 m.setFamilyFieldArr(1,p)
2675 for i in range(nbOfFams):
2676 m.addFamily(fns[i],fids[i])
2679 for i in range(nbOfGrps):
2680 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2682 m.setName(m2.getName())
2683 m.setDescription(m2.getDescription())
2686 mm0=MEDFileMesh.New(fileName)
2687 mm1=MEDFileMesh.New(fileName)
2688 groupNamesIni=GetMeshGroupsNames(fileName,"ma")
2689 for name in groupNamesIni:
2690 mm1.changeGroupName(name,name+'N')
2692 mm1.write(fileName,2)
2695 mm2=MEDFileMesh.New(fileName)
2696 for name in groupNamesIni:
2697 for lev in mm0.getGrpNonEmptyLevelsExt(name):
2698 arr0=mm0.getGroupArr(lev,name)
2699 arr2=mm2.getGroupArr(lev,name+'N')
2700 arr0.setName(name+'N')
2701 self.assertTrue(arr0.isEqual(arr2))
2707 def testInt32InMEDFileFieldStar1(self):
2708 self.internalInt32InMEDFileFieldStar1()
2710 def internalInt32InMEDFileFieldStar1(self):
2711 fname="Pyfile63.med"
2712 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2713 f1=f1.convertToIntField()
2715 mm1=MEDFileUMesh.New()
2716 mm1.setCoords(m1.getCoords())
2717 mm1.setMeshAtLevel(0,m1)
2718 mm1.setName(m1.getName())
2720 ff1=MEDFileIntField1TS()
2721 ff1.setFieldNoProfileSBT(f1)
2722 a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2723 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2724 self.assertTrue(a.isEqual(f1,1e-12,0))
2726 a,b=ff1.getUndergroundDataArrayExt()
2727 self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
2728 self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
2729 ff2=MEDFileAnyTypeField1TS.New(fname)
2730 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2731 self.assertEqual(ff2.getTime(),[0,1,2.0])
2732 self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2733 a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2734 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2735 self.assertTrue(a.isEqual(f1,1e-12,0))
2737 c=ff2.getUndergroundDataArray() ; c*=2
2738 ff2.write(fname,0) # 2 time steps in
2739 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2740 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2741 self.assertEqual(len(ffs1),2)
2742 self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2743 a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2744 self.assertTrue(a.isEqual(f1,1e-12,0))
2745 a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
2746 self.assertTrue(a.isEqual(f1,1e-12,0))
2747 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2748 a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2749 self.assertTrue(a.getArray().isEqual(2*f1.getArray()))
2750 f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
2751 self.assertTrue(a.isEqual(f1,1e-12,0)) ; f1.getArray()[:]/=2
2752 bc=DataArrayInt(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2754 a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2757 self.assertTrue(bc.isEqual(3*f1.getArray()))
2758 nf1=MEDCouplingFieldInt(ON_NODES)
2759 nf1.setTime(9.,10,-1)
2760 nf1.setMesh(f1.getMesh())
2761 narr=DataArrayInt(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
2762 nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
2763 nff1=MEDFileIntField1TS.New()
2764 nff1.setFieldNoProfileSBT(nf1)
2765 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2766 self.assertEqual(nff1.getTime(),[10,-1,9.0])
2769 nf2=MEDCouplingFieldInt(ON_NODES)
2770 nf2.setTime(19.,20,-11)
2771 nf2.setMesh(f1.getMesh())
2772 narr2=DataArrayInt(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
2773 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
2774 nff2=MEDFileIntField1TS.New()
2775 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
2776 nff2.setFieldProfile(nf2,mm1,0,npfl)
2777 nff2.getFieldWithProfile(ON_NODES,0,mm1)
2778 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2779 self.assertTrue(b.isEqual(npfl))
2780 self.assertTrue(a.isEqual(narr2))
2782 nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
2783 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2784 self.assertTrue(b.isEqual(npfl))
2785 self.assertTrue(a.isEqual(narr2))
2787 nf3=MEDCouplingFieldDouble(ON_NODES)
2788 nf3.setName("VectorFieldOnNodesDouble")
2789 nf3.setTime(29.,30,-21)
2790 nf3.setMesh(f1.getMesh())
2791 nf3.setArray(f1.getMesh().getCoords())
2792 nff3=MEDFileField1TS.New()
2793 nff3.setFieldNoProfileSBT(nf3)
2795 fs=MEDFileFields(fname)
2796 self.assertEqual(len(fs),4)
2797 ffs=[it for it in fs]
2798 self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
2799 self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
2800 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
2801 self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
2803 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray()))
2804 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray()))
2805 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
2806 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
2807 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2809 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
2810 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2811 self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
2812 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
2813 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
2814 self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
2815 MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
2816 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
2818 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
2819 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2820 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
2821 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2825 def testMEDFileFields1(self):
2826 fname="Pyfile64.med"
2827 f1=MEDCouplingFieldDouble(ON_NODES)
2828 f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
2829 c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
2830 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
2832 arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=list(range(12)) ; arr[:,1]=2*arr[:,0]
2834 f1.setName("Field1")
2835 ff1=MEDFileField1TS.New()
2836 ff1.setFieldNoProfileSBT(f1)
2837 self.assertEqual(ff1.getDtUnit(),"us")
2839 f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2840 f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2842 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2843 ff1s=MEDFileFieldMultiTS(fname,"Field1")
2844 ff1s.setName("Field2")
2846 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2847 f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2848 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
2849 self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
2850 self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
2851 f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2852 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
2853 self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
2856 # Multi time steps and multi fields management without Globals (profiles, locs) aspects
2858 def testMEDFileFields2(self):
2859 fname="Pyfile65.med"
2860 # to check that all is initialize
2861 MEDFileField1TS().__str__()
2862 MEDFileFieldMultiTS().__str__()
2863 # building a mesh containing 4 tri3 + 5 quad4
2864 tri=MEDCouplingUMesh("tri",2)
2865 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2866 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2867 tris = [tri.deepCopy() for i in range(4)]
2868 for i,elt in enumerate(tris): elt.translate([i,0])
2869 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2870 quad=MEDCouplingUMesh("quad",2)
2871 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2872 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2873 quads = [quad.deepCopy() for i in range(5)]
2874 for i,elt in enumerate(quads): elt.translate([5+i,0])
2875 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2876 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2877 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2879 fmts0_0=MEDFileFieldMultiTS()
2880 fmts0_1=MEDFileFieldMultiTS()
2883 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2884 d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2885 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2886 f.setTime(float(i+1)+0.1,i+1,-i-1)
2887 fmts0_0.appendFieldNoProfileSBT(f)
2888 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
2889 self.assertEqual(fmts0_1.getName(),name1)
2890 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2891 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2893 # components names have been modified to generate errors
2894 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
2895 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
2896 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
2897 f1ts.setInfo(['aa [bb]','eee [dd]'])
2898 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
2900 # add a mismatch of nb of compos
2902 fmts0_2=fmts0_0.deepCopy()
2903 fmts0_3=fmts0_0.deepCopy()
2904 fmts0_4=fmts0_0.deepCopy()
2905 fmts0_5=fmts0_0.shallowCpy()
2906 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)
2908 self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
2909 del fmts0_3[[1.1,(6,-6),9]]
2910 self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
2911 fmts0_6=fmts0_4[[1.1,(6,-6),8]]
2912 self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
2913 self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
2914 fmts0_7=fmts0_4[::-3]
2915 self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
2916 self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
2919 fs0.pushField(fmts0_0)
2920 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2921 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2922 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2923 self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
2925 fs0=MEDFileFields(fname)
2926 self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
2927 fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
2928 self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2929 del fs1[["2ndField",3]]
2930 self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2931 fs2=fs0[[0,"4thField"]]
2932 self.assertTrue(isinstance(fs2,MEDFileFields))
2933 self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
2935 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
2938 # Multi time steps and multi fields management with Globals (profiles, locs) aspects
2940 def testMEDFileFields3(self):
2941 fname="Pyfile66.med"
2942 # building a mesh containing 4 tri3 + 5 quad4
2943 tri=MEDCouplingUMesh("tri",2)
2944 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2945 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2946 tris = [tri.deepCopy() for i in range(4)]
2947 for i,elt in enumerate(tris): elt.translate([i,0])
2948 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2949 quad=MEDCouplingUMesh("quad",2)
2950 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2951 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2952 quads = [quad.deepCopy() for i in range(5)]
2953 for i,elt in enumerate(quads): elt.translate([5+i,0])
2954 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2955 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2956 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2958 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2960 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2961 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2962 fmts0_0=MEDFileFieldMultiTS()
2963 fmts0_1=MEDFileFieldMultiTS()
2966 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2967 d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2968 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2969 f.setTime(float(i+1)+0.1,i+1,-i-1)
2970 fmts0_0.appendFieldProfile(f,mm,0,pfl)
2971 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2972 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2973 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2976 self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
2977 self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
2978 fmts0_0.zipPflsNames()
2979 self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
2980 self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
2981 fmts0_2=fmts0_0.deepCopy()
2982 fmts0_3=fmts0_0.deepCopy()
2983 fmts0_4=fmts0_0.deepCopy()
2985 fs0.pushField(fmts0_0)
2986 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2987 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2988 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2989 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
2991 fmts0_5=MEDFileFieldMultiTS()
2993 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2994 d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2995 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2996 f.setTime(float(i+1)+0.1,i+1,-i-1)
2997 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
2999 fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
3000 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
3001 fs0.checkGlobsCoherency()
3006 def testSplitComponents1(self):
3007 fname="Pyfile67.med"
3008 # building a mesh containing 4 tri3 + 5 quad4
3009 tri=MEDCouplingUMesh("tri",2)
3010 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3011 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3012 tris = [tri.deepCopy() for i in range(4)]
3013 for i,elt in enumerate(tris): elt.translate([i,0])
3014 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3015 quad=MEDCouplingUMesh("quad",2)
3016 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3017 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3018 quads = [quad.deepCopy() for i in range(5)]
3019 for i,elt in enumerate(quads): elt.translate([5+i,0])
3020 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3021 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3022 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3024 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3026 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3027 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
3029 fmts0_1=MEDFileFieldMultiTS()
3031 infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
3034 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
3035 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3036 f.setTime(float(i+1)+0.1,i+1,-i-1)
3037 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
3038 self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
3040 fs.pushField(fmts0_1)
3041 self.assertEqual(1,len(fs))
3042 l=fmts0_1.splitComponents()
3043 self.assertEqual(3,len(l))
3044 for elt in l: self.assertEqual(10,len(elt))
3045 for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
3047 elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
3050 self.assertEqual(4,len(fs))
3051 for elt in fs: self.assertEqual(10,len(elt))
3052 self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
3053 self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
3055 fs.write(fname,0) ; del fs
3057 fs1=MEDFileFields(fname)
3058 self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
3059 self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
3060 self.assertEqual(4,len(fs1))
3062 for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
3063 f1ts=fs1[fieldName][i]
3064 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
3065 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
3066 self.assertTrue(d.isEqual(f.getArray(),1e-13))
3068 f1ts=fs1["1stField"][i]
3069 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
3070 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
3071 self.assertTrue(d.isEqual(f.getArray(),1e-13))
3076 def testMEDFileFieldConvertTo1(self):
3077 fname="Pyfile68.med"
3078 # building a mesh containing 4 tri3 + 5 quad4
3079 tri=MEDCouplingUMesh("tri",2)
3080 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3081 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3082 tris = [tri.deepCopy() for i in range(4)]
3083 for i,elt in enumerate(tris): elt.translate([i,0])
3084 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3085 quad=MEDCouplingUMesh("quad",2)
3086 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3087 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3088 quads = [quad.deepCopy() for i in range(5)]
3089 for i,elt in enumerate(quads): elt.translate([5+i,0])
3090 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3091 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3092 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3093 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3095 ff0=MEDFileField1TS()
3096 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")
3097 f0.checkConsistencyLight()
3098 ff0.setFieldNoProfileSBT(f0)
3100 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
3101 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3103 ff0i=ff0.convertToInt()
3104 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3105 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3107 ff1=ff0i.convertToDouble()
3108 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3109 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3111 del arr,f0,ff0,ff1,ff0i,fspExp
3112 ff0=MEDFileField1TS()
3113 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")
3114 f0.checkConsistencyLight()
3115 pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
3116 ff0.setFieldProfile(f0,mm,0,pfl)
3117 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
3118 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3120 ff0i=ff0.convertToInt()
3121 self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
3122 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3123 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3125 ff1=ff0i.convertToDouble()
3126 self.assertTrue(isinstance(ff1,MEDFileField1TS))
3127 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3128 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3130 ff0=MEDFileFieldMultiTS()
3131 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)
3132 f0.checkConsistencyLight()
3133 ff0.appendFieldProfile(f0,mm,0,pfl)
3134 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)
3135 f0.checkConsistencyLight()
3136 ff0.appendFieldProfile(f0,mm,0,pfl)
3137 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)
3138 f0.checkConsistencyLight()
3139 ff0.appendFieldProfile(f0,mm,0,pfl)
3140 ff1=ff0.convertToInt()
3141 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3142 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3143 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3144 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3145 arr=ff1.getUndergroundDataArray(dt,it)
3146 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
3148 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3153 ff1=ff1.convertToDouble()
3154 self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
3155 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3156 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3157 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3158 arr=ff1.getUndergroundDataArray(dt,it)
3159 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
3161 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3163 ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
3164 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3165 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3166 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3167 self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
3168 arr=ff1.getUndergroundDataArray(dt,it)
3169 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1))
3171 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
3175 def testMEDFileFieldPartialLoading(self):
3176 fname="Pyfile69.med"
3178 a=DataArrayInt() ; aa=a.getHeapMemorySize()
3180 strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
3181 # building a mesh containing 30 tri3 + 40 quad4
3182 tri=MEDCouplingUMesh("tri",2)
3183 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3184 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3185 tris = [tri.deepCopy() for i in range(30)]
3186 for i,elt in enumerate(tris): elt.translate([i,0])
3187 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3188 quad=MEDCouplingUMesh("quad",2)
3189 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3190 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3191 quads = [quad.deepCopy() for i in range(40)]
3192 for i,elt in enumerate(quads): elt.translate([40+i,0])
3193 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3194 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3195 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3196 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3198 ff0=MEDFileField1TS()
3199 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")
3200 f0.checkConsistencyLight()
3201 ff0.setFieldNoProfileSBT(f0)
3204 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
3205 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3207 ff0=MEDFileField1TS()
3208 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")
3209 f0.checkConsistencyLight()
3210 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
3211 ff0.setFieldProfile(f0,mm,0,pfl)
3212 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
3213 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3216 ff0=MEDFileField1TS(fname,False)
3217 self.assertEqual(ff0.getName(),"FieldCell")
3218 self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
3219 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
3220 heap_memory_ref=ff0.getHeapMemorySize()
3221 self.assertIn(heap_memory_ref, list(range(182, 540 + 2 * strMulFac)))
3223 arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
3224 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3225 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
3227 ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
3228 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
3229 heap_memory_ref=ff0.getHeapMemorySize()
3230 self.assertIn(heap_memory_ref, list(range(350, 600 + 6 * strMulFac)))
3232 arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
3233 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3234 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3236 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3237 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3238 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3239 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3241 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3242 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3243 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3244 ff0.loadArraysIfNecessary() ##
3245 self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
3246 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3247 heap_memory_ref=ff0.getHeapMemorySize()
3248 self.assertIn(heap_memory_ref, list(range(1100, 1400 + 2 * strMulFac)))
3250 hmd=ff0.getHeapMemorySize()-heap_memory_ref
3251 self.assertEqual(hmd,-800) # -50*8*2
3253 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
3255 ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
3256 heap_memory_ref=ff0.getHeapMemorySize()
3257 self.assertIn(heap_memory_ref, list(range(299, 620 + 6 * strMulFac)))
3259 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3260 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3262 fieldName="FieldCellMultiTS"
3263 ff0=MEDFileFieldMultiTS()
3265 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)
3266 f0.setTime(float(t)+0.1,t,100+t)
3267 f0.checkConsistencyLight()
3268 ff0.appendFieldNoProfileSBT(f0)
3272 ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
3273 heap_memory_ref=ff0.getHeapMemorySize()
3274 self.assertIn(heap_memory_ref, list(range(5536, 9212 + (80 + 26 + 1) * strMulFac)))
3276 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
3279 ffs=MEDFileFields(fname,False)
3280 heap_memory_ref=ffs.getHeapMemorySize()
3281 self.assertIn(heap_memory_ref, list(range(5335, 10031 + (80 + 50 + len(ffs)) * strMulFac)))
3283 self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
3287 def testMEDFileMeshReadSelector1(self):
3288 mrs=MEDFileMeshReadSelector()
3289 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3290 mrs.__str__() ; mrs.__repr__()
3292 mrs=MEDFileMeshReadSelector(0)
3293 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())
3294 mrs=MEDFileMeshReadSelector(1)
3295 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3296 mrs=MEDFileMeshReadSelector(2)
3297 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3298 mrs=MEDFileMeshReadSelector(3)
3299 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3300 mrs=MEDFileMeshReadSelector(4)
3301 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3302 mrs=MEDFileMeshReadSelector(5)
3303 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3304 mrs=MEDFileMeshReadSelector(6)
3305 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3306 mrs=MEDFileMeshReadSelector(7)
3307 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3308 mrs=MEDFileMeshReadSelector(8)
3309 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3310 mrs=MEDFileMeshReadSelector(9)
3311 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3312 mrs=MEDFileMeshReadSelector(10)
3313 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3314 mrs=MEDFileMeshReadSelector(11)
3315 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3316 mrs=MEDFileMeshReadSelector(12)
3317 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3318 mrs=MEDFileMeshReadSelector(13)
3319 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3320 mrs=MEDFileMeshReadSelector(14)
3321 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3322 mrs=MEDFileMeshReadSelector(15)
3323 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3324 mrs=MEDFileMeshReadSelector(16)
3325 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3326 mrs=MEDFileMeshReadSelector(17)
3327 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3328 mrs=MEDFileMeshReadSelector(18)
3329 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3330 mrs=MEDFileMeshReadSelector(19)
3331 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3332 mrs=MEDFileMeshReadSelector(20)
3333 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3334 mrs=MEDFileMeshReadSelector(21)
3335 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3336 mrs=MEDFileMeshReadSelector(22)
3337 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3338 mrs=MEDFileMeshReadSelector(23)
3339 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3340 mrs=MEDFileMeshReadSelector(24)
3341 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3342 mrs=MEDFileMeshReadSelector(25)
3343 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3344 mrs=MEDFileMeshReadSelector(26)
3345 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3346 mrs=MEDFileMeshReadSelector(27)
3347 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3348 mrs=MEDFileMeshReadSelector(28)
3349 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3350 mrs=MEDFileMeshReadSelector(29)
3351 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3352 mrs=MEDFileMeshReadSelector(30)
3353 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3354 mrs=MEDFileMeshReadSelector(31)
3355 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3356 mrs=MEDFileMeshReadSelector(32)
3357 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3358 mrs=MEDFileMeshReadSelector(33)
3359 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3360 mrs=MEDFileMeshReadSelector(34)
3361 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3362 mrs=MEDFileMeshReadSelector(35)
3363 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3364 mrs=MEDFileMeshReadSelector(36)
3365 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3366 mrs=MEDFileMeshReadSelector(37)
3367 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3368 mrs=MEDFileMeshReadSelector(38)
3369 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3370 mrs=MEDFileMeshReadSelector(39)
3371 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3372 mrs=MEDFileMeshReadSelector(40)
3373 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3374 mrs=MEDFileMeshReadSelector(41)
3375 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3376 mrs=MEDFileMeshReadSelector(42)
3377 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3378 mrs=MEDFileMeshReadSelector(43)
3379 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3380 mrs=MEDFileMeshReadSelector(44)
3381 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3382 mrs=MEDFileMeshReadSelector(45)
3383 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3384 mrs=MEDFileMeshReadSelector(46)
3385 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3386 mrs=MEDFileMeshReadSelector(47)
3387 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3388 mrs=MEDFileMeshReadSelector(48)
3389 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3390 mrs=MEDFileMeshReadSelector(49)
3391 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3392 mrs=MEDFileMeshReadSelector(50)
3393 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3394 mrs=MEDFileMeshReadSelector(51)
3395 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3396 mrs=MEDFileMeshReadSelector(52)
3397 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3398 mrs=MEDFileMeshReadSelector(53)
3399 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3400 mrs=MEDFileMeshReadSelector(54)
3401 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3402 mrs=MEDFileMeshReadSelector(55)
3403 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3404 mrs=MEDFileMeshReadSelector(56)
3405 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3406 mrs=MEDFileMeshReadSelector(57)
3407 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3408 mrs=MEDFileMeshReadSelector(58)
3409 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3410 mrs=MEDFileMeshReadSelector(59)
3411 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3412 mrs=MEDFileMeshReadSelector(60)
3413 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3414 mrs=MEDFileMeshReadSelector(61)
3415 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3416 mrs=MEDFileMeshReadSelector(62)
3417 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3418 mrs=MEDFileMeshReadSelector(63)
3419 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3421 mrs=MEDFileMeshReadSelector(63)
3422 mrs.setCellFamilyFieldReading(False)
3423 self.assertEqual(mrs.getCode(),62)
3424 mrs.setCellFamilyFieldReading(True)
3425 self.assertEqual(mrs.getCode(),63)
3426 mrs.setNodeFamilyFieldReading(False)
3427 self.assertEqual(mrs.getCode(),61)
3428 mrs.setNodeFamilyFieldReading(True)
3429 self.assertEqual(mrs.getCode(),63)
3430 mrs.setCellNameFieldReading(False)
3431 self.assertEqual(mrs.getCode(),59)
3432 mrs.setCellNameFieldReading(True)
3433 self.assertEqual(mrs.getCode(),63)
3434 mrs.setNodeNameFieldReading(False)
3435 self.assertEqual(mrs.getCode(),55)
3436 mrs.setNodeNameFieldReading(True)
3437 self.assertEqual(mrs.getCode(),63)
3438 mrs.setCellNumFieldReading(False)
3439 self.assertEqual(mrs.getCode(),47)
3440 mrs.setCellNumFieldReading(True)
3441 self.assertEqual(mrs.getCode(),63)
3442 mrs.setNodeNumFieldReading(False)
3443 self.assertEqual(mrs.getCode(),31)
3444 mrs.setNodeNumFieldReading(True)
3445 self.assertEqual(mrs.getCode(),63)
3449 def testPartialReadOfMeshes(self):
3450 fname="Pyfile70.med"
3451 # building a mesh containing 4 tri3 + 5 quad4
3452 tri=MEDCouplingUMesh("tri",2)
3453 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3454 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3455 tris = [tri.deepCopy() for i in range(4)]
3456 for i,elt in enumerate(tris): elt.translate([i,0])
3457 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3458 quad=MEDCouplingUMesh("quad",2)
3459 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3460 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3461 quads = [quad.deepCopy() for i in range(5)]
3462 for i,elt in enumerate(quads): elt.translate([5+i,0])
3463 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3464 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3465 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3466 m1=m.buildDescendingConnectivity()[0]
3467 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3469 grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3470 grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3471 mm.setGroupsAtLevel(0,[grp0,grp1])
3472 grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3473 grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3474 mm.setGroupsAtLevel(-1,[grp2,grp3])
3475 grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3476 grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3477 mm.setGroupsAtLevel(1,[grp4,grp5])
3478 mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3479 mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3480 mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3484 mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3485 b4_ref_heap_mem=mm.getHeapMemorySize()
3486 mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
3487 mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
3488 ref_heap_mem=mm.getHeapMemorySize()
3489 # check the gain of memory using 1GTUMesh instead of UMesh
3490 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
3492 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3493 self.assertEqual(len(mm.getGroupsNames()),0)
3494 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3495 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3496 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3497 self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3498 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3499 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3500 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3501 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3502 delta1=ref_heap_mem-mm.getHeapMemorySize()
3503 self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3505 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3506 self.assertEqual(len(mm.getGroupsNames()),6)
3507 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3508 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3509 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3510 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3511 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3512 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3513 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3514 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3515 delta2=ref_heap_mem-mm.getHeapMemorySize()
3516 self.assertTrue(delta2<delta1)
3517 self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3519 mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3520 self.assertEqual(len(mm.getGroupsNames()),6)
3521 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3522 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3523 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3524 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3525 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3526 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3527 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3528 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3529 delta3=ref_heap_mem-mm.getHeapMemorySize()
3530 self.assertTrue(delta3<delta2)
3531 self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3533 mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3534 self.assertEqual(len(mm.getGroupsNames()),6)
3535 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3536 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3537 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3538 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3539 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3540 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3541 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3542 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3543 delta4=ref_heap_mem-mm.getHeapMemorySize()
3544 self.assertTrue(delta4<delta3)
3545 self.assertTrue(delta4>=32*4*2)
3547 mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3548 self.assertEqual(len(mm.getGroupsNames()),6)
3549 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3550 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3551 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3552 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3553 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3554 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3555 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3556 self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3557 delta5=ref_heap_mem-mm.getHeapMemorySize()
3558 self.assertTrue(delta5<delta4)
3559 self.assertEqual(delta5,0)
3562 # this test checks that setFieldProfile perform a check of the array length
3563 # compared to the profile length. This test also checks that mesh attribute of field
3564 # is not used by setFieldProfile (because across this test mesh is equal to None)
3566 def testCheckCompatibilityPfl1(self):
3567 # building a mesh containing 4 tri3 + 5 quad4
3568 tri=MEDCouplingUMesh("tri",2)
3569 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3570 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3571 tris = [tri.deepCopy() for i in range(4)]
3572 for i,elt in enumerate(tris): elt.translate([i,0])
3573 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3574 quad=MEDCouplingUMesh("quad",2)
3575 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3576 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3577 quads = [quad.deepCopy() for i in range(5)]
3578 for i,elt in enumerate(quads): elt.translate([5+i,0])
3579 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3580 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3581 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3582 m1=m.buildDescendingConnectivity()[0]
3583 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3585 f1ts=MEDFileField1TS()
3586 f=MEDCouplingFieldDouble(ON_NODES)
3587 vals=DataArrayDouble(7) ; vals.iota(1000)
3589 f.setName("anonymous") # f has no mesh it is not a bug
3590 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3591 f1ts.setFieldProfile(f,mm,0,pfl)
3593 f1ts=MEDFileField1TS()
3594 f=MEDCouplingFieldDouble(ON_NODES)
3595 vals=DataArrayDouble(8) ; vals.iota(1000)
3597 f.setName("anonymous") # f has no mesh it is not a bug
3598 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3599 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3601 f1ts=MEDFileField1TS()
3602 f=MEDCouplingFieldDouble(ON_CELLS)
3603 vals=DataArrayDouble(7) ; vals.iota(1000)
3605 f.setName("anonymous") # f has no mesh it is not a bug
3606 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3607 f1ts.setFieldProfile(f,mm,0,pfl)
3608 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3610 f1ts=MEDFileField1TS()
3611 f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3612 vals=DataArrayDouble(27) ; vals.iota(1000)
3614 f.setName("anonymous") # f has no mesh it is not a bug
3615 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3617 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])
3618 f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3619 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])
3621 f1ts.setFieldProfile(f,mm,0,pfl)
3622 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3623 vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3624 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3625 vals=DataArrayDouble(27) ; vals.iota(1000)
3626 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3628 f1ts=MEDFileField1TS()
3629 f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3630 vals=DataArrayDouble(25) ; vals.iota(1000)
3632 f.setName("anonymous") # f has no mesh it is not a bug
3633 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3634 f1ts.setFieldProfile(f,mm,0,pfl)
3635 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3636 vals2=DataArrayDouble(26) ; vals2.iota(1050)
3638 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3639 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3641 f1ts=MEDFileField1TS()
3642 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3643 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3645 f1ts.setFieldProfile(f,mm,0,pfl)
3649 def testWRMeshWithNoCells(self):
3650 fname="Pyfile71.med"
3651 a=DataArrayDouble(4) ; a.iota()
3652 c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
3653 m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
3655 m.setMeshAtLevel(0,m00)
3656 m.setRenumFieldArr(1,DataArrayInt(list(range(10,26))))
3657 m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
3661 m=MEDFileMesh.New(fname)
3662 self.assertEqual((),m.getNonEmptyLevels())
3663 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))
3664 self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(list(range(10,26)))))
3665 self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
3669 def testWRQPolyg1(self):
3670 fname="Pyfile72.med"
3671 m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
3672 m.insertNextCell([0,2,1,3])
3673 m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
3675 ms = [m.deepCopy() for i in range(4)]
3676 for i,elt in enumerate(ms):
3677 elt.translate([float(i)*1.5,0.])
3679 m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3680 m0.convertAllToPoly()
3682 ms = [m.deepCopy() for i in range(5)]
3683 for i,elt in enumerate(ms):
3684 elt.translate([float(i)*1.5,1.5])
3686 m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3687 m1.convertAllToPoly()
3688 m1.convertLinearCellsToQuadratic()
3690 m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
3693 mm.setMeshAtLevel(0,m)
3694 grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
3695 grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
3696 grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
3697 mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3702 mm_read=MEDFileUMesh(fname)
3703 self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
3704 self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
3705 self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
3706 self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
3708 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
3710 arr0=DataArrayDouble(9) ; arr0.iota()
3711 arr1=DataArrayDouble(9) ; arr1.iota(100)
3712 arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
3713 f.setArray(arr) ; f.checkConsistencyLight()
3715 ff=MEDFileField1TS()
3716 ff.setFieldNoProfileSBT(f)
3719 ff_read=MEDFileField1TS(fname)
3720 f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
3721 self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
3725 def testLoadIfNecessaryOnFromScratchFields0(self):
3727 This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
3729 fname="Pyfile77.med"
3730 coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
3731 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
3733 m.insertNextCell(NORM_QUAD4,[0,5,3,2])
3734 m.insertNextCell(NORM_QUAD4,[4,2,3,1])
3735 m.finishInsertingCells()
3737 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3738 ms=MEDFileMeshes() ; ms.pushMesh(mm)
3742 ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
3743 f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
3745 f0.setName("myELNOField")
3746 arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
3747 f0.setArray(arrs[0])
3748 ff0.appendFieldNoProfileSBT(f0)
3751 arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
3752 f0.setArray(arrs[1])
3753 ff0.appendFieldNoProfileSBT(f0)
3756 arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
3757 f0.setArray(arrs[2])
3758 ff0.appendFieldNoProfileSBT(f0)
3761 arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
3762 f0.setArray(arrs[3])
3763 ff0.appendFieldNoProfileSBT(f0)
3765 for i,arr in enumerate(arrs):
3766 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3767 fs[0][i].loadArraysIfNecessary()
3768 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3770 fs.loadArraysIfNecessary()
3771 for i,arr in enumerate(arrs):
3772 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3774 fs[0].loadArraysIfNecessary()
3775 for i,arr in enumerate(arrs):
3776 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3781 def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
3782 """ 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.
3784 fname="Pyfile78.med"
3785 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)
3786 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3787 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
3789 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
3790 m0.insertNextCell(NORM_TETRA4,elt)
3792 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
3793 m0.insertNextCell(NORM_PYRA5,elt)
3795 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
3796 m0.insertNextCell(NORM_PENTA6,elt)
3798 m0.checkConsistency()
3799 m1=MEDCouplingUMesh(); m1.setName("mesh")
3800 m1.setMeshDimension(2);
3801 m1.allocateCells(5);
3802 m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3803 m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3804 m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3805 m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3806 m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3807 m1.setCoords(coords);
3808 m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
3810 m3.insertNextCell(NORM_POINT1,[2])
3811 m3.insertNextCell(NORM_POINT1,[3])
3812 m3.insertNextCell(NORM_POINT1,[4])
3813 m3.insertNextCell(NORM_POINT1,[5])
3816 mm.setMeshAtLevel(0,m0)
3817 mm.setMeshAtLevel(-1,m1)
3818 mm.setMeshAtLevel(-3,m3)
3820 #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
3821 mm=MEDFileMesh.New(fname)
3823 fmts=MEDFileFieldMultiTS()
3824 f1ts=MEDFileField1TS()
3825 for lev in mm.getNonEmptyLevels():
3826 for gt in mm.getGeoTypesAtLevel(lev):
3827 p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
3828 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
3829 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
3830 f.setArray(arr) ; f.setName("f0")
3831 f1ts.setFieldNoProfileSBT(f)
3834 self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
3835 for lev in [0,-1,-3]:
3836 mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
3838 fmts.pushBackTimeStep(f1ts)
3842 #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
3843 fs=MEDFileFields(fname)
3844 self.assertEqual(len(fs),1)
3845 self.assertEqual(len(fs[0]),1)
3847 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),'','')])])
3848 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))
3852 def testMEDFileUMeshSetName(self):
3853 """ This test is a small but important one for MEDReader in sauv mode. When .sauv file is loaded the conversion is performed in memory and a preparation is done then.
3854 This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
3856 fname="Pyfile79.med"
3857 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3859 m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
3860 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)
3861 m0.allocateCells(5);
3862 m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3863 m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3864 m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3865 m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3866 m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3867 m0.setCoords(coords);
3868 mm.setMeshAtLevel(0,m0)
3869 m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
3871 m2.insertNextCell(NORM_POINT1,[2])
3872 m2.insertNextCell(NORM_POINT1,[3])
3873 m2.insertNextCell(NORM_POINT1,[4])
3874 m2.insertNextCell(NORM_POINT1,[5])
3875 mm.setMeshAtLevel(-2,m2)
3876 self.assertEqual(mm.getName(),"")
3877 self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
3878 mm.forceComputationOfParts()
3879 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
3881 self.assertEqual(mm.getName(),"abc")
3882 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
3883 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
3884 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
3885 self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
3889 def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
3890 fileName="Pyfile80.med"
3891 m=MEDCouplingCMesh() ; m.setName("cmesh")
3892 arr=DataArrayDouble(6) ; arr.iota()
3893 m.setCoords(arr,arr)
3894 nbCells=m.getNumberOfCells()
3895 self.assertEqual(25,nbCells)
3896 f=MEDCouplingFieldDouble(ON_CELLS)
3897 f.setName("FieldOnCell") ; f.setMesh(m)
3898 arr=DataArrayDouble(nbCells) ; arr.iota()
3902 fmts=MEDFileFieldMultiTS()
3904 for i in range(nbCells):
3905 t=(float(i)+0.1,i+1,-i-2)
3907 arr2=DataArrayDouble(nbCells)
3908 perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
3911 f1ts=MEDFileField1TS()
3912 f1ts.setFieldNoProfileSBT(f)
3913 fmts.pushBackTimeStep(f1ts)
3915 fmts.unloadArraysWithoutDataLoss()
3916 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))
3917 fs=MEDFileFields() ; fs.pushField(fmts)
3918 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))
3919 fs.unloadArraysWithoutDataLoss()
3920 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))
3922 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))
3923 f1ts.unloadArraysWithoutDataLoss()
3924 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))
3925 mm.write(fileName,2)
3926 fs.write(fileName,0)
3927 del m,fmts,mm,f,f1ts
3929 mm=MEDFileMesh.New(fileName)
3930 fmts=MEDFileFieldMultiTS(fileName)
3931 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))
3932 fmts.unloadArraysWithoutDataLoss()
3933 self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
3934 fmts.loadArraysIfNecessary()
3935 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))
3937 fs=MEDFileFields(fileName)
3938 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))
3939 fs.unloadArraysWithoutDataLoss()
3940 self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
3941 fs.loadArraysIfNecessary()
3942 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))
3944 f1ts=MEDFileField1TS(fileName)
3945 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))
3946 f1ts.unloadArraysWithoutDataLoss()
3947 self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
3948 f1ts.loadArraysIfNecessary()
3949 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))
3953 def testMEDFileUMeshLoadPart1(self):
3954 """ This method tests MEDFileUMesh.LoadPart that loads only a part of a specified mesh in a MED file. The part is specified using a slice of cell ids. Only nodes on which cells lies are loaded to reduce at most the amount of
3955 memory of the returned instance.
3957 fileName="Pyfile81.med"
3958 arr=DataArrayDouble(6) ; arr.iota()
3959 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3960 m=m.buildUnstructured()
3962 m.changeSpaceDimension(3,0.)
3963 infos=["aa [b]","cc [de]","gg [klm]"]
3964 m.getCoords().setInfoOnComponents(infos)
3965 m.checkConsistency()
3967 mm.setMeshAtLevel(0,m)
3968 m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh")
3969 m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
3970 mm.setMeshAtLevel(-1,m1)
3971 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])
3972 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])
3973 namesCellL0=DataArrayAsciiChar(25,16)
3974 namesCellL0[:] = ["Cell#%.3d " % (i) for i in range(25)]
3975 renumM1=DataArrayInt([3,4,0,2,1])
3976 famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
3977 mm.setRenumFieldArr(0,renum0)
3978 mm.setFamilyFieldArr(0,famField0)
3979 mm.setNameFieldAtLevel(0,namesCellL0)
3980 mm.setRenumFieldArr(-1,renumM1)
3981 mm.setFamilyFieldArr(-1,famFieldM1)
3982 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])
3983 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])
3984 namesNodes=DataArrayAsciiChar(36,16)
3985 namesNodes[:] = ["Node#%.3d " % (i) for i in range(36)]
3986 mm.setRenumFieldArr(1,renum1)
3987 mm.setFamilyFieldArr(1,famField1)
3988 mm.setNameFieldAtLevel(1,namesNodes)
3989 mm.setFamilyId("Fam7",77)
3990 mm.setFamilyId("Fam8",88)
3991 mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
3992 mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
3993 mm.write(fileName,2)
3995 mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
3996 self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
3997 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])))
3998 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)
3999 self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
4000 self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
4001 self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
4002 self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
4003 self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
4004 self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
4005 self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
4007 mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
4008 self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
4009 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])))
4010 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)
4011 self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
4012 self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
4013 self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
4014 self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
4015 self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
4016 self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
4017 self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
4019 mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
4020 self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
4021 self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
4022 self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
4023 self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
4024 self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
4025 self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
4026 self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
4027 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])))
4028 self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
4029 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)
4030 self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
4031 self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
4032 self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
4033 self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
4037 def testMEDFileFieldsLoadPart1(self):
4038 """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
4040 fileName="Pyfile82.med"
4042 compos=["aa [kg]","bbb [m/s]"]
4043 arr=DataArrayDouble(6) ; arr.iota()
4044 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4045 m=m.buildUnstructured()
4047 m.changeSpaceDimension(3,0.)
4048 infos=["aa [b]","cc [de]","gg [klm]"]
4049 m.getCoords().setInfoOnComponents(infos)
4050 m.checkConsistency()
4051 f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4053 arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4054 arr[:,0]=list(range(25))
4055 arr[:,1]=list(range(100,125))
4057 WriteField(fileName,f,True)
4058 f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4059 f.setName("FieldNode")
4060 arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4061 arr[:,0]=list(range(200,236))
4062 arr[:,1]=list(range(300,336))
4064 f.checkConsistencyLight()
4065 WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4068 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
4070 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4071 self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
4074 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
4076 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4078 fs[0][0].loadArrays()
4079 arr = DataArrayDouble(12, 2) ; arr[:, 0] = list(range(3, 15)) ; arr[:, 1] = list(range(103, 115))
4080 arr.setInfoOnComponents(compos)
4081 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4082 fs[1][0].loadArrays()
4083 arr = DataArrayDouble(21, 2) ; arr[:, 0] = list(range(203, 224)) ; arr[:, 1] = list(range(303, 324))
4084 arr.setInfoOnComponents(compos)
4085 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4089 def testMEDFileWithoutCells1(self):
4090 fileName="Pyfile83.med"
4091 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4092 coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
4096 mm.write(fileName,2)
4098 mm=MEDFileMesh.New(fileName)
4099 self.assertEqual(mm.getName(),"mesh")
4100 self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
4104 def testZipCoordsWithLoadPart1(self):
4105 """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
4107 fileName="Pyfile84.med"
4109 compos=["aa [kg]","bbb [m/s]"]
4110 arr=DataArrayDouble(6) ; arr.iota()
4111 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4112 m=m.buildUnstructured()
4114 m.changeSpaceDimension(3,0.)
4115 infos=["aa [b]","cc [de]","gg [klm]"]
4116 m.getCoords().setInfoOnComponents(infos)
4117 m.checkConsistency()
4118 f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4120 arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4121 arr[:,0]=list(range(25))
4122 arr[:,1]=list(range(100,125))
4124 WriteField(fileName,f,True)
4125 f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4126 f.setName("FieldNode")
4127 arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4128 arr[:,0]=list(range(200,236))
4129 arr[:,1]=list(range(300,336))
4131 f.checkConsistencyLight()
4132 WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4135 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
4137 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4138 self.assertEqual(spd.getSlice(),slice(4,6,1))
4139 spd=mm.getPartDefAtLevel(1)
4140 self.assertEqual(spd.getSlice(),slice(4,14,1))
4141 self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4142 mm.zipCoords() # <- The important line is here !
4143 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4144 self.assertEqual(spd.getSlice(),slice(4,6,1))
4145 spd=mm.getPartDefAtLevel(1)
4146 self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4147 self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
4148 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4149 fs[0][0].loadArrays()
4150 arr=DataArrayDouble([(4,104),(5,105)])
4151 arr.setInfoOnComponents(compos)
4152 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4153 fs[1][0].loadArrays()
4154 arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
4155 arr.setInfoOnComponents(compos)
4156 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4160 def testMEDFileCMeshSetGroupsAtLevel(self):
4161 """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
4163 m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
4165 mm=MEDFileCMesh() ; mm.setMesh(m)
4166 grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
4167 mm.setGroupsAtLevel(0,[grp])
4168 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
4172 def testMEDFileUMeshBuildExtrudedMesh1(self):
4173 """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
4174 fileName="Pyfile85.med"
4177 meshName3DOut="Mesh3D"
4179 d1=DataArrayInt([0,4,20,24])
4180 d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
4182 a=DataArrayDouble(6) ; a.iota()
4183 m=MEDCouplingCMesh() ; m.setCoords(a,a)
4184 m=m.buildUnstructured()
4185 d1c=d1.buildComplement(m.getNumberOfCells())
4186 m=m[d1c] ; m.zipCoords()
4187 m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
4189 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
4190 m.setName(meshName2D)
4191 mMinus1,a,b,c,d=m.buildDescendingConnectivity()
4192 e=d.deltaShiftIndex().findIdsEqual(1)
4195 mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
4196 grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
4197 mm.setGroupsAtLevel(0,[grp0])
4198 grp1=e ; grp1.setName("grp1")
4199 mm.setGroupsAtLevel(-1,[grp1])
4200 mm.write(fileName,2)
4202 a=DataArrayDouble(3) ; a.iota()
4203 tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
4204 tmp.setName(meshName1D)
4205 tmp.changeSpaceDimension(3)
4206 tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
4208 mm1D.setMeshAtLevel(0,tmp)
4209 mm1D.write(fileName,0)
4211 mm2D=MEDFileMesh.New(fileName,meshName2D)
4212 mm1D=MEDFileMesh.New(fileName,meshName1D)
4213 m1D=mm1D.getMeshAtLevel(0)
4214 mm3D=mm2D.buildExtrudedMesh(m1D,0)
4216 self.assertEqual(mm3D.getName(),mm2D.getName())
4217 self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
4218 self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
4219 self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
4220 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
4221 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
4222 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
4223 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
4224 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
4225 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
4226 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.)])
4227 self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
4228 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])
4229 self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
4230 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])
4231 self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
4232 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])
4233 self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
4234 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])
4235 self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
4236 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])
4237 self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
4238 d=DataArrayInt(129) ; d.iota() ; d*=3
4239 self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
4241 self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
4242 self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
4243 self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
4244 self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
4245 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])))
4246 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])))
4247 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])))
4248 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])))
4249 mm3D.setName("MeshExtruded")
4250 mm3D.write(fileName,0)
4253 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4255 def testMEDFileUMeshPickeling1(self):
4256 outFileName="Pyfile86.med"
4257 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)
4258 c.setInfoOnComponents(["aa","bbb"])
4259 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
4260 m=MEDCouplingUMesh();
4261 m.setMeshDimension(2);
4263 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
4264 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
4265 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
4266 m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
4267 m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
4268 m.finishInsertingCells();
4270 m.checkConsistencyLight()
4271 m1=MEDCouplingUMesh.New();
4272 m1.setMeshDimension(1);
4273 m1.allocateCells(3);
4274 m1.insertNextCell(NORM_SEG2,2,[1,4])
4275 m1.insertNextCell(NORM_SEG2,2,[3,6])
4276 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
4277 m1.finishInsertingCells();
4279 m1.checkConsistencyLight()
4280 m2=MEDCouplingUMesh.New();
4281 m2.setMeshDimension(0);
4282 m2.allocateCells(4);
4283 m2.insertNextCell(NORM_POINT1,1,[1])
4284 m2.insertNextCell(NORM_POINT1,1,[3])
4285 m2.insertNextCell(NORM_POINT1,1,[2])
4286 m2.insertNextCell(NORM_POINT1,1,[6])
4287 m2.finishInsertingCells();
4289 m2.checkConsistencyLight()
4291 mm=MEDFileUMesh.New()
4292 self.assertTrue(mm.getUnivNameWrStatus())
4293 mm.setName("MyFirstMEDCouplingMEDmesh")
4294 mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
4298 mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
4300 mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
4301 # playing with groups
4302 g1_2=DataArrayInt.New()
4303 g1_2.setValues([1,3],2,1)
4305 g2_2=DataArrayInt.New()
4306 g2_2.setValues([1,2,3],3,1)
4308 mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
4309 g1_1=DataArrayInt.New()
4310 g1_1.setValues([0,1,2],3,1)
4312 g2_1=DataArrayInt.New()
4313 g2_1.setValues([0,2],2,1)
4315 mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
4316 g1_N=DataArrayInt.New()
4317 g1_N.setValues(list(range(8)),8,1)
4319 g2_N=DataArrayInt.New()
4320 g2_N.setValues(list(range(9)),9,1)
4322 mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
4323 mm.createGroupOnAll(0,"GrpOnAllCell")
4324 # check content of mm
4325 t=mm.getGroupArr(0,"G1",False)
4326 self.assertTrue(g1_2.isEqual(t));
4327 t=mm.getGroupArr(0,"G2",False)
4328 self.assertTrue(g2_2.isEqual(t));
4329 t=mm.getGroupArr(-1,"G1",False)
4330 self.assertTrue(g1_1.isEqual(t));
4331 t=mm.getGroupArr(-1,"G2",False)
4332 self.assertTrue(g2_1.isEqual(t));
4333 t=mm.getGroupArr(1,"G1",False)
4334 self.assertTrue(g1_N.isEqual(t));
4335 t=mm.getGroupArr(1,"G2",False)
4336 self.assertTrue(g2_N.isEqual(t));
4337 self.assertTrue(mm.existsGroup("GrpOnAllCell"));
4338 t=mm.getGroupArr(0,"GrpOnAllCell")
4340 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4341 mm2=pickle.loads(st)
4342 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4343 self.assertEqual(mm.getAxisType(),AX_CART)
4345 mm.setAxisType(AX_CYL)
4346 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4347 mm2=pickle.loads(st)
4348 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4349 self.assertEqual(mm2.getAxisType(),AX_CYL)
4353 def testMEDFileFieldsLoadSpecificEntities1(self):
4356 fileName="Pyfile87.med"
4360 m=MEDCouplingCMesh()
4361 arr=DataArrayDouble(nbNodes) ; arr.iota()
4363 m=m.buildUnstructured()
4366 fmts=MEDFileFieldMultiTS()
4367 for i in range(nbPdt):
4368 f=MEDCouplingFieldDouble(ON_NODES)
4370 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4372 f.setName(fieldName)
4373 f.setTime(float(i),i,0)
4374 fmts.appendFieldNoProfileSBT(f)
4377 mm=MEDFileUMesh() ; mm[0]=m
4378 fmts.write(fileName,2)
4379 mm.write(fileName,0)
4381 fs=MEDFileFields(fileName,False)
4382 fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
4383 fs.loadArraysIfNecessary()
4384 fs2.loadArraysIfNecessary()
4385 for i in range(nbPdt):
4386 self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4388 m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
4389 m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
4390 m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
4391 fmts=MEDFileFieldMultiTS()
4392 for i in range(nbPdt):
4393 f=MEDCouplingFieldDouble(ON_CELLS)
4395 arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
4397 f.setName(fieldName)
4398 f.setTime(float(i),i,0)
4399 fmts.appendFieldNoProfileSBT(f)
4401 mm=MEDFileUMesh() ; mm[0]=m3
4403 self.assertEqual(mm.getNonEmptyLevels(),())
4405 self.assertEqual(mm.getNonEmptyLevels(),(0,))
4406 fmts.write(fileName,2)
4407 fs=MEDFileFields(fileName,False)
4408 fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
4409 fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
4410 fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
4411 fs.loadArraysIfNecessary()
4412 fs2.loadArraysIfNecessary()
4413 fs3.loadArraysIfNecessary()
4414 fs4.loadArraysIfNecessary()
4415 for i in range(nbPdt):
4416 self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4417 self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
4418 self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
4423 def testMEDFileLotsOfTSRW1(self):
4426 fileName="Pyfile88.med"
4427 nbPdt=300 # <- perftest = 30000
4430 maxPdt=100 # <- optimum = 500
4431 m=MEDCouplingCMesh()
4432 arr=DataArrayDouble(nbNodes) ; arr.iota()
4434 m=m.buildUnstructured()
4437 nbOfField=nbPdt//maxPdt
4439 for j in range(nbOfField):
4440 fmts=MEDFileFieldMultiTS()
4441 s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
4442 for i in range(s.start, s.stop, s.step):
4443 f=MEDCouplingFieldDouble(ON_NODES)
4445 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4447 f.setName("%s_%d"%(fieldName,j))
4448 f.setTime(float(i),i,0)
4449 fmts.appendFieldNoProfileSBT(f)
4454 mm=MEDFileUMesh() ; mm[0]=m
4455 fs.write(fileName,2)
4456 mm.write(fileName,0)
4458 def appendInDict(d,key,val):
4465 allFields=GetAllFieldNames(fileName)
4467 pat=re.compile("([\d]+)([\s\S]+)$")
4468 for st in allFields:
4472 appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
4475 appendInDict(allFieldsDict,st,'')
4479 for k in allFieldsDict:
4480 if allFieldsDict[k]!=['']:
4481 allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
4484 for it in allFieldsDict[k]:
4485 fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
4490 for ii in range(nbIter):
4491 zeResu.pushBackTimeSteps(fmts2.pop())
4494 fs2.pushField(zeResu)
4496 self.assertEqual(fs2[0].getTimeSteps(), [(i, 0, float(i)) for i in range(nbPdt)])
4500 def testMEDFileMeshRearrangeFamIds1(self):
4501 """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
4502 fileName="Pyfile89.med"
4503 meshName='Maillage_2'
4505 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)])
4507 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])
4508 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])
4509 m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
4510 m0.setConnectivity(c0,c0i)
4513 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])
4514 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])
4515 m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
4516 m1.setConnectivity(c1,c1i)
4519 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])
4520 m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4521 m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
4522 mm[-2]=m2.buildUnstructured()
4524 ref0=DataArrayInt(55) ; ref0[:]=0
4525 mm.setFamilyFieldArr(0,ref0)
4526 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]))
4527 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])
4528 mm.setFamilyFieldArr(-1,ref1)
4529 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])
4530 mm.setFamilyFieldArr(-2,ref2)
4532 for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
4533 mm.setFamilyId(f,fid)
4534 for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
4535 mm.setFamiliesOnGroup(grp,fams)
4536 mm.write(fileName,2)
4538 mm=MEDFileMesh.New(fileName)
4539 grp=mm.getGroup(-1,"Groupe_1")
4540 dai=grp.computeFetchedNodeIds()
4543 mm.rearrangeFamilies() # <- the aim of the test
4544 self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
4545 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
4546 self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
4547 self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
4548 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])))
4549 allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
4550 allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
4551 self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
4552 for elt,fams in allGrps:
4553 self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
4554 self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
4555 for elt,eltId in allFams:
4556 self.assertEqual(mm.getFamilyId(elt),eltId)
4560 def testNonRegrCMeshSetFieldPfl1(self):
4561 """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
4562 ff=MEDFileField1TS()
4565 m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4569 field=MEDCouplingFieldDouble(ON_CELLS)
4571 field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4572 field.setName("Field")
4573 field.checkConsistencyLight()
4574 pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
4575 ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
4576 self.assertEqual(ff.getPfls(),())
4577 field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4578 self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4579 del ff,mm,field,field2,pfl
4580 # same with unstructured mesh
4581 ff=MEDFileField1TS()
4584 m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4587 m=m.buildUnstructured()
4589 field=MEDCouplingFieldDouble(ON_CELLS)
4591 field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4592 field.setName("Field")
4593 field.checkConsistencyLight()
4594 pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
4595 ff.setFieldProfile(field,mm,0,pfl)
4596 self.assertEqual(ff.getPfls(),())
4597 field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4598 self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4602 def testMEDFileUMeshLinearToQuadraticAndRev1(self):
4604 fileName="Pyfile90.med"
4605 fileName2="Pyfile91.med"
4606 arr=DataArrayDouble(5) ; arr.iota()
4607 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4608 m=m.buildUnstructured()
4609 d=DataArrayInt([3,7,11,15])
4612 m2=m[d.buildComplement(m.getNumberOfCells())]
4613 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
4614 m.changeSpaceDimension(3,0.)
4615 arr=DataArrayDouble(3) ; arr.iota()
4616 m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
4617 m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
4618 delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
4619 m3D=m.buildExtrudedMesh(m1D,0)
4620 m3D.sortCellsInMEDFileFrmt()
4621 m3D.setName(meshName)
4622 m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkConsistency()
4623 m1D=m2D.computeSkin() ; m1D.setName(meshName)
4624 m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
4627 mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
4628 grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
4629 grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
4630 grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
4631 grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
4632 diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
4633 vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
4634 vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
4635 mm.setGroupsAtLevel(0,[vol1,vol2])
4636 mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
4637 mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
4639 mmOut1=mm.linearToQuadratic(0,0.)
4640 mmOut1.write(fileName2,2)
4641 mmOut2=mmOut1.quadraticToLinear(0.)
4642 self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
4646 def testMEDFileMeshAddGroup1(self):
4647 m=MEDCouplingCMesh()
4648 arrX=DataArrayDouble(9) ; arrX.iota()
4649 arrY=DataArrayDouble(4) ; arrY.iota()
4650 m.setCoords(arrX,arrY)
4654 grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
4656 grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
4658 grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
4660 grp3=DataArrayInt([23]) ; grp3.setName("grp3")
4662 for grp in [grp0,grp1,grp2,grp3]:
4663 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4664 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
4666 for grp in [grp0,grp1,grp2,grp3]:
4667 grpNode=grp.deepCopy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
4668 mm.addGroup(1,grpNode)
4669 self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
4670 for grp in [grp0,grp1,grp2,grp3]:
4671 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4672 for grp in [grp0,grp1,grp2,grp3]:
4673 grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4674 self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4675 mm.normalizeFamIdsMEDFile()
4676 for grp in [grp0,grp1,grp2,grp3]:
4677 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4678 for grp in [grp0,grp1,grp2,grp3]:
4679 grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4680 self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4684 def testMEDFileJoint1(self):
4685 fileName="Pyfile92.med"
4686 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4687 coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4691 mm.setDescription("un maillage")
4692 mm.write(fileName,2)
4693 node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4694 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4695 one_step_joint=MEDFileJointOneStep()
4696 one_step_joint.pushCorrespondence(cell_correspond)
4697 one_step_joint.pushCorrespondence(node_correspond)
4698 one_joint=MEDFileJoint()
4699 one_joint.pushStep(one_step_joint)
4700 one_joint.setLocalMeshName("maa1")
4701 one_joint.setRemoteMeshName("maa1")
4702 one_joint.setDescription("joint_description")
4703 one_joint.setJointName("joint_1")
4704 one_joint.setDomainNumber(1)
4705 self.assertEqual( one_joint.getLocalMeshName(), "maa1")
4706 self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
4707 self.assertEqual( one_joint.getDescription(), "joint_description")
4708 self.assertEqual( one_joint.getJointName(), "joint_1")
4709 self.assertEqual( one_joint.getDomainNumber(), 1)
4710 joints=MEDFileJoints()
4711 joints.pushJoint(one_joint);
4712 joints.write(fileName,0)
4714 jointsR=MEDFileJoints(fileName,mm.getName())
4715 self.assertEqual( jointsR.getNumberOfJoints(), 1 )
4716 jR = jointsR.getJointAtPos(0)
4717 self.assertTrue( jR.isEqual( one_joint ))
4718 self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
4719 self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
4720 jointsR.destroyJointAtPos(0)
4724 def testMEDFileJoint2(self):
4725 fileNameWr="Pyfile93.med"
4726 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4727 coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4731 mm.setDescription("un maillage")
4732 node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
4733 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
4734 one_step_joint=MEDFileJointOneStep()
4735 two_step_joint=MEDFileJointOneStep()
4736 one_joint=MEDFileJoint()
4737 two_joint=MEDFileJoint()
4738 one_step_joint.pushCorrespondence(node_correspond)
4739 one_joint.pushStep(one_step_joint)
4740 two_step_joint.pushCorrespondence(cell_correspond)
4741 two_step_joint.pushCorrespondence(node_correspond)
4742 two_joint.pushStep(two_step_joint)
4743 one_joint.setLocalMeshName("maa1")
4744 one_joint.setRemoteMeshName("maa1")
4745 one_joint.setDescription("joint_description_1")
4746 one_joint.setJointName("joint_1")
4747 one_joint.setDomainNumber(1)
4748 two_joint.setLocalMeshName("maa1")
4749 two_joint.setRemoteMeshName("maa1")
4750 two_joint.setDescription("joint_description_2")
4751 two_joint.setJointName("joint_2")
4752 two_joint.setDomainNumber(2)
4753 joints=MEDFileJoints()
4754 joints.pushJoint(one_joint)
4755 joints.pushJoint(two_joint)
4756 mm.setJoints( joints )
4757 mm.write(fileNameWr,2)
4759 mm=MEDFileMesh.New(fileNameWr)
4760 self.assertEqual( mm.getNumberOfJoints(), 2)
4761 jointsR = mm.getJoints();
4762 self.assertEqual( jointsR.getMeshName(), mm.getName() )
4763 self.assertEqual( len( jointsR ), 2 )
4764 jointR1 = jointsR[0]
4765 jointR2 = jointsR[1]
4766 self.assertFalse( jointR1 is None )
4767 self.assertFalse( jointR2 is None )
4768 self.assertTrue( jointR1.isEqual( one_joint ))
4769 self.assertTrue( jointR2.isEqual( two_joint ))
4773 def testMEDFileJoint1(self):
4774 node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4775 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4776 cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
4777 cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
4778 joint1st_1=MEDFileJointOneStep()
4779 joint1st_1.pushCorrespondence(cell_correspond)
4780 joint1st_1.pushCorrespondence(node_correspond)
4781 joint1st_2=MEDFileJointOneStep()
4782 joint1st_2.pushCorrespondence(cell_correspond)
4783 joint1st_2.pushCorrespondence(node_correspond)
4784 joint1st_3=MEDFileJointOneStep()
4785 joint1st_3.pushCorrespondence(node_correspond)
4786 joint1st_3.pushCorrespondence(cell_correspond)
4787 joint1st_4=MEDFileJointOneStep()
4788 joint1st_4.pushCorrespondence(cell_correspond)
4789 joint1st_5=MEDFileJointOneStep()
4790 joint1st_5.pushCorrespondence(cell_correspon2)
4791 joint1st_6=MEDFileJointOneStep()
4792 joint1st_6.pushCorrespondence(cell_correspon3)
4793 self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
4794 self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
4795 self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
4796 self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
4797 self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
4798 one_joint=MEDFileJoint()
4799 one_joint.pushStep(joint1st_1)
4800 one_joint.setLocalMeshName("maa1")
4801 one_joint.setRemoteMeshName("maa2")
4802 one_joint.setDescription("joint_description")
4803 one_joint.setJointName("joint_1")
4804 one_joint.setDomainNumber(1)
4805 self.assertEqual( "maa1", one_joint.getLocalMeshName())
4806 self.assertEqual( "maa2", one_joint.getRemoteMeshName())
4807 self.assertEqual( "joint_description", one_joint.getDescription())
4808 self.assertEqual( 1, one_joint.getDomainNumber())
4809 self.assertEqual( "joint_1", one_joint.getJointName())
4812 @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
4814 def testMEDFileSafeCall0(self):
4815 """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
4816 fname="Pyfile94.med"
4817 errfname="Pyfile94.err"
4820 # first clean file if needed
4821 if os.path.exists(fname):
4824 # second : build a file from scratch
4825 m=MEDCouplingCMesh()
4826 arr=DataArrayDouble(11) ; arr.iota()
4827 m.setCoords(arr,arr)
4832 # third : change permissions to remove write access on created file
4833 os.chmod(fname, 0o444)
4834 # four : try to append data on file -> check that it raises Exception
4835 f=MEDCouplingFieldDouble(ON_CELLS)
4838 f.setArray(DataArrayDouble(100))
4839 f.getArray()[:]=100.
4840 f.checkConsistencyLight()
4841 f1ts=MEDFileField1TS()
4842 f1ts.setFieldNoProfileSBT(f)
4844 tmp=StdOutRedirect(errfname)
4845 self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
4848 if os.path.exists(errfname):
4854 def testUnivStatus1(self):
4855 """ Non regression test to check the effectiveness of univ write status."""
4856 fname="Pyfile95.med"
4857 arr=DataArrayDouble(10) ; arr.iota()
4858 m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
4859 mm=MEDFileCMesh() ; mm.setMesh(m)
4860 mm.setUnivNameWrStatus(False) # test is here
4862 mm=MEDFileCMesh(fname)
4863 self.assertEqual(mm.getUnivName(),"")
4864 mm.setUnivNameWrStatus(True)
4866 mm=MEDFileCMesh(fname)
4867 self.assertTrue(mm.getUnivName()!="")
4871 def testEmptyMesh(self):
4872 """ MEDLoader should be able to consistently write and read an empty mesh (coords array
4874 fname = "Pyfile96.med"
4875 m = MEDCouplingUMesh('toto', 2)
4876 m.setCoords(DataArrayDouble([], 0, 2))
4877 m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
4878 mfu = MEDFileUMesh()
4879 mfu.setMeshAtLevel(0, m)
4881 mfu2 = MEDFileUMesh(fname)
4882 self.assertEqual('toto', mfu2.getName())
4883 lvl = mfu2.getNonEmptyLevels()
4884 self.assertEqual((), lvl)
4886 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4887 def testMEDFileUMeshPickeling2(self):
4888 """ Check that pickalization can be performed on a unpickalized instance. Non regression test."""
4894 arr=DataArrayDouble(nbOfNodesPerAxis) ; arr.iota() ; arr/=(nbOfNodesPerAxis-1) ; arr*=hauteur
4895 m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured() ; m.setName(name)
4896 mesh=MEDFileUMesh() ; mesh[0]=m
4897 m1=m.computeSkin() ; mesh[-1]=m1
4899 bary1=m1.computeCellCenterOfMass()[:,2]
4900 grp1=bary1.findIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
4901 grp2=bary1.findIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
4902 mesh.setGroupsAtLevel(-1,[grp1,grp2])
4904 st=pickle.dumps(mesh,2)
4906 st2=pickle.dumps(mm,2)
4907 mm2=pickle.loads(st2)
4908 self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
4912 def testMEDFileEquivalence1(self):
4913 """ First check of equivalence implementation in MEDFileMesh"""
4914 fileName="Pyfile97.med"
4917 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)])
4918 coo.setInfoOnComponents(["X [Sans_unite]","Y [Sans_unite]","Z [Sans_unite]"])
4919 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])
4920 m1=MEDCoupling1SGTUMesh(meshName,NORM_QUAD4) ; m1.setCoords(coo) ; m1.setNodalConnectivity(connQ4) ; mm[-1]=m1
4921 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])
4922 m0=MEDCoupling1SGTUMesh(meshName,NORM_HEXA8) ; m0.setCoords(coo) ; m0.setNodalConnectivity(connH8) ; mm[0]=m0
4923 mm.getFamilyFieldAtLevel(-1)[:]=-2
4924 mm.getFamilyFieldAtLevel(0)[:]=0
4925 mm.addFamily("HOMARD________-1",-1)
4926 mm.addFamily("HOMARD________-2",-2)
4927 mm.addFamily("HOMARD________-3",-3)
4928 mm.setFamiliesIdsOnGroup("HOMARD",[-1,-2,-3])
4930 eqName="MAILLES_A_RECOLLER_APRES_HOMARD"
4931 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."
4932 mm.initializeEquivalences()
4933 eqs=mm.getEquivalences()
4934 eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4935 eq0.setDescription(descEq)
4936 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)])
4937 eq0.setArray(-1,corr)
4938 self.assertEqual(eq0.getCell().size(),1)
4939 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4940 eq0.getCell().clear()
4941 self.assertEqual(eq0.getCell().size(),0)
4942 eq0.getCell().setArrayForType(NORM_QUAD4,corr)
4943 self.assertEqual(eq0.getCell().size(),1)
4944 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4945 mm.killEquivalences()
4946 mm.initializeEquivalences()
4947 eqs=mm.getEquivalences()
4948 eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4949 eq0.setDescription(descEq)
4951 c.setArrayForType(NORM_QUAD4,corr)
4952 self.assertEqual(eq0.getCell().size(),1)
4953 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4955 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4956 self.assertEqual(mm2.getEquivalences().size(),1)
4957 self.assertTrue(mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4).isEqual(corr))
4958 mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=2
4959 self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
4960 mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=0
4961 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4962 mm.write(fileName,2)
4964 mm3=MEDFileMesh.New(fileName)
4965 self.assertTrue(mm.isEqual(mm3,1e-12)[0])
4969 def testMEDFileForFamiliesPlayer1(self):
4970 """Non regression bug EDF11911. For serial killers using same family name to store both cells and nodes ! Only sky is the limit."""
4971 fileName="Pyfile98.med"
4973 magicSt="%s%%04i"%(MEDFileMesh.GetMagicFamilyStr())
4974 arr=DataArrayDouble(4) ; arr.iota()
4975 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4976 m=m.buildUnstructured()
4979 mm.setName(meshName)
4980 mm.setFamilyId("FAMILLE_ZERO",0)
4981 mm.getFamilyFieldAtLevel(0)[-3:]=-4
4982 mm.setFamilyId("RIDF%s"%(magicSt%0),-4)
4983 mm.setGroupsOnFamily("RIDF%s"%(magicSt%0),["RID"])
4984 d=DataArrayInt(16) ; d[:]=0 ; d[[1,2,4,5]]=3
4985 mm.setFamilyFieldArr(1,d)
4986 mm.setFamilyId("RIDF%s"%(magicSt%1),3)
4987 mm.setGroupsOnFamily("RIDF%s"%(magicSt%1),["RID"])
4988 self.assertEqual(mm.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4989 self.assertEqual(mm.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF")) # <- the aim of test is here !
4990 self.assertEqual(mm.getFamiliesIdsOnGroup("RID"),(-4,3))
4991 mm.write(fileName,2)
4992 # now read such funny file !
4993 mm2=MEDFileMesh.New(fileName) # <- normally mdump of Pyfile98.med must contain only RID and FAMILLE_ZERO families.
4994 self.assertTrue(mm.isEqual(mm2,1e-16))
4995 self.assertEqual(mm2.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4996 self.assertEqual(mm2.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF"))
4997 self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too !
5001 def testCartesianizer1(self):
5002 """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """
5004 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
5005 mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts()
5006 d0=DataArrayInt(16) ; d0[:]=0
5007 d1=DataArrayInt(9) ; d1[:]=0
5008 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5009 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5010 ref0=mm.getCoords().getHiddenCppPointer()
5011 ref1=mm[0].getNodalConnectivity().getHiddenCppPointer()
5012 self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer())
5013 ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer()
5014 ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer()
5015 self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
5016 mm.setAxisType(AX_CYL) #<- important
5017 mm2=mm.cartesianize() # the trigger
5018 self.assertEqual(mm2.getAxisType(),AX_CART)
5019 mm.setAxisType(AX_CART) # this is here only to avoid complaints
5020 self.assertTrue(isinstance(mm2,MEDFileUMesh))
5021 self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
5022 self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important
5023 self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important
5024 self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer())
5025 self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
5026 self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important
5027 self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important
5028 self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important
5029 self.assertEqual(mm2.getName(),mm.getName())
5030 self.assertEqual(mm2.getDescription(),mm.getDescription())
5031 self.assertEqual(mm2.getTime(),mm.getTime())
5032 self.assertEqual(mm2.getTime(),mm.getTime())
5033 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5034 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5035 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5036 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5037 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5038 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5039 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5040 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5042 mm.setAxisType(AX_CART)
5043 mm2=mm.cartesianize() # the trigger
5044 self.assertEqual(mm2.getAxisType(),AX_CART)
5045 self.assertTrue(isinstance(mm2,MEDFileUMesh))
5046 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5047 # CurveLinearMesh non cart
5048 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear()
5049 mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
5050 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5051 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5052 ref0=mm.getMesh().getCoords().getHiddenCppPointer()
5053 mm2=mm.cartesianize() # the trigger
5054 self.assertEqual(mm2.getAxisType(),AX_CART)
5055 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5056 self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
5057 self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important
5058 self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important
5059 self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
5060 self.assertEqual(mm2.getName(),mm.getName())
5061 self.assertEqual(mm2.getDescription(),mm.getDescription())
5062 self.assertEqual(mm2.getTime(),mm.getTime())
5063 self.assertEqual(mm2.getTime(),mm.getTime())
5064 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5065 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5066 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5067 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5068 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5069 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5070 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5071 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5072 # CurveLinearMesh cart
5073 mm.setAxisType(AX_CART)
5074 mm2=mm.cartesianize() # the trigger
5075 self.assertEqual(mm2.getAxisType(),AX_CART)
5076 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5077 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5079 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
5080 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
5081 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5082 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5083 mm2=mm.cartesianize() # the trigger
5084 self.assertEqual(mm2.getAxisType(),AX_CART)
5085 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5086 self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
5087 self.assertEqual(mm2.getName(),mm.getName())
5088 self.assertEqual(mm2.getDescription(),mm.getDescription())
5089 self.assertEqual(mm2.getTime(),mm.getTime())
5090 self.assertEqual(mm2.getTime(),mm.getTime())
5091 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5092 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5093 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5094 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5095 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5096 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5097 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5098 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5100 mm.setAxisType(AX_CART)
5101 mm2=mm.cartesianize() # the trigger
5102 self.assertEqual(mm2.getAxisType(),AX_CART)
5103 self.assertTrue(isinstance(mm2,MEDFileCMesh))
5104 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5108 def testCheckCoherency(self):
5109 m2 = MEDCouplingUMesh("2d", 2)
5110 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5111 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5112 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5113 mum = MEDFileUMesh()
5114 mum.setMeshAtLevel(0, m2)
5115 mum.setMeshAtLevel(-1, m1)
5116 mum.checkConsistency()
5117 mum2 = mum.deepCopy()
5120 arr = DataArrayInt([2]*4)
5121 mum.setFamilyFieldArr(1, arr); arr.reAlloc(35);
5122 self.assertRaises(InterpKernelException, mum.checkConsistency)
5123 mum=mum2; mum2=mum.deepCopy();
5124 arr = DataArrayInt([2]*4)
5125 mum.setRenumFieldArr(1, arr); arr.reAlloc(35);
5126 self.assertRaises(InterpKernelException, mum.checkConsistency)
5127 mum=mum2; mum2=mum.deepCopy();
5128 mum.setRenumFieldArr(1, DataArrayInt([2]*4))
5129 self.assertRaises(InterpKernelException, mum.checkConsistency)
5130 mum=mum2; mum2=mum.deepCopy();
5131 arr = DataArrayAsciiChar(['tutu x']*4)
5132 mum.setNameFieldAtLevel(1, arr); arr.reAlloc(35);
5133 self.assertRaises(InterpKernelException, mum.checkConsistency)
5136 mum=mum2; mum2=mum.deepCopy();
5137 arr = DataArrayInt([2]*2)
5138 mum.setFamilyFieldArr(0, arr); arr.reAlloc(35);
5139 self.assertRaises(InterpKernelException, mum.checkConsistency)
5140 mum=mum2; mum2=mum.deepCopy();
5141 arr = DataArrayInt([2]*2)
5142 mum.setRenumFieldArr(0, arr); arr.reAlloc(35);
5143 self.assertRaises(InterpKernelException, mum.checkConsistency)
5144 mum=mum2; mum2=mum.deepCopy();
5145 mum.setRenumFieldArr(0, DataArrayInt([2]*2))
5146 self.assertRaises(InterpKernelException, mum.checkConsistency)
5147 mum=mum2; mum2=mum.deepCopy();
5148 arr = DataArrayAsciiChar(['tutu x']*2)
5149 mum.setNameFieldAtLevel(0, arr); arr.reAlloc(35);
5150 self.assertRaises(InterpKernelException, mum.checkConsistency)
5153 mum=mum2; mum2=mum.deepCopy();
5154 arr = DataArrayInt([2]*5)
5155 mum.setFamilyFieldArr(-1, arr); arr.reAlloc(35);
5156 self.assertRaises(InterpKernelException, mum.checkConsistency)
5157 mum=mum2; mum2=mum.deepCopy();
5158 arr = DataArrayInt([2]*5)
5159 mum.setRenumFieldArr(-1, arr); arr.reAlloc(35);
5160 self.assertRaises(InterpKernelException, mum.checkConsistency)
5161 mum=mum2; mum2=mum.deepCopy();
5162 mum.setRenumFieldArr(-1, DataArrayInt([2]*5))
5163 self.assertRaises(InterpKernelException, mum.checkConsistency)
5164 mum=mum2; mum2=mum.deepCopy();
5165 arr = DataArrayAsciiChar(['tutu x']*5)
5166 mum.setNameFieldAtLevel(-1, arr); arr.reAlloc(35);
5167 self.assertRaises(InterpKernelException, mum.checkConsistency)
5170 def testCheckSMESHConsistency(self):
5171 m2 = MEDCouplingUMesh("2d", 2)
5172 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5173 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5174 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5175 mum = MEDFileUMesh()
5176 mum.setMeshAtLevel(0, m2)
5177 mum.setMeshAtLevel(-1, m1)
5178 mum.checkConsistency()
5179 mum.checkSMESHConsistency()
5180 n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5181 n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5182 mum.setRenumFieldArr(0, n2)
5183 mum.setRenumFieldArr(-1, n1)
5184 self.assertRaises(InterpKernelException, mum.checkSMESHConsistency)
5185 mum.setRenumFieldArr(-1, n1+100)
5186 mum.checkSMESHConsistency()
5190 def testClearNodeAndCellNumbers(self):
5191 m2 = MEDCouplingUMesh("2d", 2)
5192 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5193 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5194 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5195 mum = MEDFileUMesh()
5196 mum.setMeshAtLevel(0, m2)
5197 mum.setMeshAtLevel(-1, m1)
5198 mum.checkConsistency()
5199 n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5200 n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5201 mum.setRenumFieldArr(0, n2)
5202 mum.setRenumFieldArr(-1, n1)
5203 mum.clearNodeAndCellNumbers()
5204 mum.checkSMESHConsistency()
5208 def testCMeshSetFamilyFieldArrNull(self):
5210 fname="Pyfile99.med"
5211 arrX=DataArrayDouble([0,1,2,3])
5212 arrY=DataArrayDouble([0,1,2])
5213 m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m.setName(meshName)
5214 mm=MEDFileCMesh() ; mm.setMesh(m)
5215 famCellIds=DataArrayInt([0,-2,-2,-1,-2,0])
5216 famNodeIds=DataArrayInt([0,0,0,3,4,1,2,7,2,1,0,0])
5217 mm.setFamilyFieldArr(0,famCellIds)
5218 mm.setFamilyFieldArr(1,famNodeIds)
5220 mm=MEDFileMesh.New(fname)
5221 self.assertTrue(mm.getFamilyFieldAtLevel(0) is not None)
5222 self.assertTrue(mm.getFamilyFieldAtLevel(1) is not None)
5223 mm.setFamilyFieldArr(0,None)#<- bug was here
5224 mm.setFamilyFieldArr(1,None)#<- bug was here
5225 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
5226 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
5228 self.assertTrue(mm3.getFamilyFieldAtLevel(0) is None)
5229 self.assertTrue(mm3.getFamilyFieldAtLevel(1) is None)
5231 mm2=MEDFileMesh.New(fname)
5232 self.assertTrue(mm2.getFamilyFieldAtLevel(0) is None)
5233 self.assertTrue(mm2.getFamilyFieldAtLevel(1) is None)
5237 def testAppendFieldProfileOnIntField(self):
5238 fname="Pyfile100.med"
5239 arrX=DataArrayDouble([0,1,2,3])
5240 arrY=DataArrayDouble([0,1,2])
5241 mesh=MEDCouplingCMesh() ; mesh.setCoords(arrX,arrY) ; mesh.setName("Mesh")
5245 fmts=MEDFileIntFieldMultiTS()
5247 pfl=DataArrayInt([1,3,5]) ; pfl.setName(pflName)
5248 f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(mesh)
5249 fieldName="FieldOnCell"
5250 f.setTime(1.2,1,1) ; f.setName(fieldName)
5251 arr=DataArrayInt([101,102,103]) ; f.setArray(arr)
5252 fmts.appendFieldProfile(f,mm,0,pfl)
5257 mm=MEDFileMesh.New(fname)
5258 fmts=MEDFileAnyTypeFieldMultiTS.New(fname)
5259 self.assertTrue(isinstance(fmts,MEDFileIntFieldMultiTS))
5260 self.assertEqual(fmts.getName(),fieldName)
5261 self.assertEqual(len(fmts),1)
5263 ftest,pfltest=f1ts.getFieldWithProfile(ON_CELLS,0,mm)
5264 self.assertEqual(pfltest.getName(),pflName)
5265 self.assertEqual(ftest.getName(),fieldName)
5266 self.assertTrue(ftest.isEqualWithoutConsideringStr(arr))
5267 ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
5268 self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr))
5269 self.assertEqual(ftest2.getTime(),f.getTime())
5270 self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr))
5274 def testMEDFileFieldEasyField1(self):
5275 """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."""
5276 ## Basic test on cells on top level
5277 fname="Pyfile101.med"
5280 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5281 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5283 m.insertNextCell(NORM_TRI3,[0,1,2])
5284 m.insertNextCell(NORM_TRI3,[3,4,5])
5285 m.insertNextCell(NORM_TRI3,[6,7,8])
5286 m.insertNextCell(NORM_TRI3,[9,10,11])
5287 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5288 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5291 arr0=DataArrayDouble([10,11,12,13,100,101])
5292 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5293 f.setName(fieldName) ; f.setTime(2.,6,7)
5295 ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5297 arr2=arr0+1000 ; f.setArray(arr2)
5298 f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f)
5302 mm=MEDFileMesh.New(fname)
5303 f1ts=MEDFileField1TS(fname,fieldName,6,7)
5304 ftst0=f1ts.field(mm)
5305 self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12))
5306 f1ts=MEDFileField1TS(fname,fieldName,8,9)
5307 ftst1=f1ts.field(mm)
5308 self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12))
5309 fmts=MEDFileFieldMultiTS(fname,fieldName)
5310 self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12))
5311 ## Basic test on nodes on top level
5312 f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5313 f2.setName(fieldName)
5315 ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5317 mm=MEDFileMesh.New(fname)
5318 f1ts=MEDFileField1TS(fname,fieldName,23,24)
5319 self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12))
5320 fmts=MEDFileFieldMultiTS(fname,fieldName)
5321 self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12))
5323 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)
5324 f3.setName(fieldName) ; f3.checkConsistencyLight()
5325 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5327 mm=MEDFileMesh.New(fname)
5328 f1ts=MEDFileField1TS(fname,fieldName,2,3)
5329 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5331 f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5332 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])
5333 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)
5334 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)
5335 f4.checkConsistencyLight()
5336 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5338 mm=MEDFileMesh.New(fname)
5339 f1ts=MEDFileField1TS(fname,fieldName,4,5)
5340 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5344 def testMEDFileFieldEasyField2(self):
5345 """Same thantestMEDFileFieldEasyField1 except that here intfields are considered.
5346 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."""
5347 ## Basic test on cells on top level
5348 fname="Pyfile102.med"
5351 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5352 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5354 m.insertNextCell(NORM_TRI3,[0,1,2])
5355 m.insertNextCell(NORM_TRI3,[3,4,5])
5356 m.insertNextCell(NORM_TRI3,[6,7,8])
5357 m.insertNextCell(NORM_TRI3,[9,10,11])
5358 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5359 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5362 arr0=DataArrayInt([10,11,12,13,100,101])
5363 f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5364 f.setName(fieldName) ; f.setTime(2.,6,7)
5366 ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5368 arr2=arr0+1000 ; f.setArray(arr2)
5369 f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f)
5373 mm=MEDFileMesh.New(fname)
5374 f1ts=MEDFileIntField1TS(fname,fieldName,6,7)
5375 ftst0=f1ts.field(mm)
5376 self.assertTrue(f0.isEqual(ftst0,1e-12,0))
5377 f1ts=MEDFileIntField1TS(fname,fieldName,8,9)
5378 ftst1=f1ts.field(mm)
5379 self.assertTrue(f1.isEqual(ftst1,1e-12,0))
5380 fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5381 self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,0))
5382 ## Basic test on nodes on top level
5383 f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5384 f2.setName(fieldName)
5386 ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5388 mm=MEDFileMesh.New(fname)
5389 f1ts=MEDFileIntField1TS(fname,fieldName,23,24)
5390 self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,0))
5391 fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5392 self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,0))
5394 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)
5395 f3.setName(fieldName) ; f3.checkConsistencyLight()
5396 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5398 mm=MEDFileMesh.New(fname)
5399 f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5400 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5402 f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5403 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])
5404 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)
5405 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)
5406 f4.checkConsistencyLight()
5407 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5409 mm=MEDFileMesh.New(fname)
5410 f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5411 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5415 def testMEDFileFieldEasyField3(self):
5416 """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."""
5417 fname="Pyfile103.med"
5420 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5421 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5423 m.insertNextCell(NORM_TRI3,[0,1,2])
5424 m.insertNextCell(NORM_TRI3,[3,4,5])
5425 m.insertNextCell(NORM_TRI3,[6,7,8])
5426 m.insertNextCell(NORM_TRI3,[9,10,11])
5427 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5428 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5430 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5432 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5433 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5437 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5438 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5440 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2)
5441 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5442 # here f1 lying on level -1 not 0 check if "field" method detect it !
5443 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5444 f1.setMesh(mm[-1]) # -1 is very important
5446 f1.checkConsistencyLight()
5448 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5450 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4)
5451 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5453 f3=MEDCouplingFieldDouble(ON_GAUSS_NE)
5454 f3.setMesh(mm[-1]) # this line is important
5455 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)
5456 f3.setName(fieldName) ; f3.checkConsistencyLight()
5457 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5459 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3)
5460 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5462 f4=MEDCouplingFieldDouble(ON_GAUSS_PT)
5463 f4.setMesh(mm[-1]) # this line is important
5464 f4.setName(fieldName)
5465 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])
5466 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)
5467 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)
5468 f4.checkConsistencyLight()
5469 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5470 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5)
5471 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5475 def testMEDFileFieldEasyField4(self):
5476 """ Same than testMEDFileFieldEasyField3 but with integers"""
5477 fname="Pyfile104.med"
5480 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5481 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5483 m.insertNextCell(NORM_TRI3,[0,1,2])
5484 m.insertNextCell(NORM_TRI3,[3,4,5])
5485 m.insertNextCell(NORM_TRI3,[6,7,8])
5486 m.insertNextCell(NORM_TRI3,[9,10,11])
5487 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5488 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5490 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5492 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5493 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5497 f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5498 f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5500 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2)
5501 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5502 # here f1 lying on level -1 not 0 check if "field" method detect it !
5503 f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5504 f1.setMesh(mm[-1]) # -1 is very important
5506 f1.checkConsistencyLight()
5508 f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5510 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4)
5511 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5513 f3=MEDCouplingFieldInt(ON_GAUSS_NE)
5514 f3.setMesh(mm[-1]) # this line is important
5515 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)
5516 f3.setName(fieldName) ; f3.checkConsistencyLight()
5517 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5519 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5520 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5522 f4=MEDCouplingFieldInt(ON_GAUSS_PT)
5523 f4.setMesh(mm[-1]) # this line is important
5524 f4.setName(fieldName)
5525 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])
5526 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)
5527 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)
5528 f4.checkConsistencyLight()
5529 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5530 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5531 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5535 def testMEDFileFieldEasyField5(self):
5536 """More and more difficult now look at how profiles are managed by "field" method."""
5537 fname="Pyfile105.med"
5540 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5541 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5543 m.insertNextCell(NORM_TRI3,[0,1,2])
5544 m.insertNextCell(NORM_TRI3,[3,4,5])
5545 m.insertNextCell(NORM_TRI3,[6,7,8])
5546 m.insertNextCell(NORM_TRI3,[9,10,11])
5547 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5548 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5551 pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl")
5552 m2=m.deepCopy()[pfl] ; m2.setName(m.getName())
5554 arr0=DataArrayDouble([10,11,12,13])
5555 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2)
5556 f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight()
5557 ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile
5560 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5561 self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5562 # more complicated -> multi level
5563 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5565 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5566 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5568 mm2[0]=m0 ; mm2[-1]=m
5570 ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl)
5572 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5573 self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5577 def testExtractPart1(self):
5578 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)])
5580 m0=MEDCouplingUMesh(meshName,2) ; m0.setCoords(coo) ; m0.allocateCells()
5581 m0.insertNextCell(NORM_TRI3,[8,4,3])
5582 m0.insertNextCell(NORM_TRI3,[8,9,4])
5583 m0.insertNextCell(NORM_TRI3,[7,13,8])
5584 m0.insertNextCell(NORM_TRI3,[7,12,13])
5585 m0.insertNextCell(NORM_TRI3,[0,6,1])
5586 m0.insertNextCell(NORM_TRI3,[0,5,6])
5587 m0.insertNextCell(NORM_QUAD4,[1,6,7,2])
5588 m0.insertNextCell(NORM_QUAD4,[2,7,8,3])
5589 m0.insertNextCell(NORM_QUAD4,[8,13,14,9])
5590 m0.insertNextCell(NORM_QUAD4,[6,11,12,7])
5591 m0.insertNextCell(NORM_QUAD4,[5,10,11,6])
5593 m1=MEDCouplingUMesh(meshName,1) ; m1.setCoords(coo) ; m1.allocateCells()
5594 m1.insertNextCell(NORM_SEG2,[10,5])
5595 m1.insertNextCell(NORM_SEG2,[5,0])
5596 m1.insertNextCell(NORM_SEG2,[0,1])
5597 m1.insertNextCell(NORM_SEG2,[1,2])
5598 m1.insertNextCell(NORM_SEG2,[2,3])
5599 m1.insertNextCell(NORM_SEG2,[3,4])
5600 m1.insertNextCell(NORM_SEG2,[4,9])
5601 m1.insertNextCell(NORM_SEG2,[9,14])
5602 m1.insertNextCell(NORM_SEG2,[14,13])
5603 m1.insertNextCell(NORM_SEG2,[13,12])
5604 m1.insertNextCell(NORM_SEG2,[12,11])
5605 m1.insertNextCell(NORM_SEG2,[11,10])
5607 mm[0]=m0 ; mm[-1]=m1
5608 arr0=DataArrayInt([0,1,2,3,4,6,7,8,12,13])
5610 tab[0]=DataArrayInt([0,2,3,4,6,7])
5611 tab[-1]=DataArrayInt([2,3,4,5,9])
5613 self.assertTrue(mm.deduceNodeSubPartFromCellSubPart(tab).isEqual(arr0))
5617 fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5620 arr0_0=DataArrayDouble([100,101,102,103,104,105,106,107,108,109,110]) ; arr0_0.setInfoOnComponents(ic)
5621 f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*t0) ; f0.setArray(arr0_0)
5622 f0.setMesh(m0) ; f0.setName(fname0)
5623 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setTime(*t0) ; f1.setArray(DataArrayDouble([200,201,202,203,204,205,206,207,208,209,210,211]))
5624 f1.setMesh(m1) ; f1.setName(fname0) ; f1.getArray().setInfoOnComponents(ic)
5625 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]))
5626 f2.setMesh(m0) ; f2.setName(fname0) ; f2.getArray().setInfoOnComponents(ic)
5627 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.setFieldNoProfileSBT(f2)
5628 fmts.pushBackTimeStep(f1ts)
5630 mmOut=mm.extractPart(tab)
5632 fsPart0=fs.extractPart(tab,mm)
5633 self.assertEqual(len(fsPart0),1)
5635 self.assertEqual(len(fmtsP),1)
5637 self.assertRaises(InterpKernelException,f1ts.field,mmOut)
5639 self.assertTrue(mmOut[0].computeCellCenterOfMass().isEqual(m0[tab[0]].computeCellCenterOfMass(),1e-12))
5640 self.assertTrue(mmOut[-1].computeCellCenterOfMass().isEqual(m1[tab[-1]].computeCellCenterOfMass(),1e-12))
5642 m0Part=m0.deepCopy()[tab[0]] ; m0Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m0Part.setName(m0.getName())
5643 self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5644 m1Part=m1.deepCopy()[tab[-1]] ; m1Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m1Part.setName(m0.getName())
5645 self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5646 self.assertTrue(mmOut[-1].isEqual(m1Part,1e-12))
5648 f0Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mmOut) ; f0Part.checkConsistencyLight()
5649 self.assertEqual(f0Part.getTypeOfField(),ON_CELLS)
5650 self.assertTrue(f0Part.getMesh().isEqual(m0Part,1e-12))
5651 arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic)
5652 self.assertTrue(f0Part.getArray().isEqual(arr0Exp,1e-12)) ; self.assertEqual(f0Part.getTime(),list(t0))
5653 f1Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,-1,mmOut) ; f1Part.checkConsistencyLight()
5654 self.assertEqual(f1Part.getTypeOfField(),ON_CELLS)
5655 self.assertTrue(f1Part.getMesh().isEqual(m1Part,1e-12))
5656 arr1Exp=DataArrayDouble([202,203,204,205,209]) ; arr1Exp.setInfoOnComponents(ic)
5657 self.assertTrue(f1Part.getArray().isEqual(arr1Exp,1e-12)) ; self.assertEqual(f1Part.getTime(),list(t0))
5659 f2Part=f1ts.getFieldOnMeshAtLevel(ON_NODES,0,mmOut) ; f2Part.checkConsistencyLight()
5660 arr2Exp=DataArrayDouble([300,301,302,303,304,306,307,308,312,313]) ; arr2Exp.setInfoOnComponents(ic)
5661 self.assertTrue(f2Part.getArray().isEqual(arr2Exp,1e-12)) ; self.assertEqual(f2Part.getTime(),list(t0))
5663 fs=MEDFileFields() ; fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5664 tss=[(16.5,3,4),(17.5,4,5),(18.5,5,6)]
5665 for i,tt in enumerate(tss):
5666 f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*tt)
5667 myarr=arr0_0+i*1000.
5669 f0.setMesh(m0) ; f0.setName(fname0) ; f0.getArray().setInfoOnComponents(ic)
5670 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; fmts.pushBackTimeStep(f1ts)
5672 fsPart1=fs.extractPart(tab,mm)
5673 self.assertEqual(len(fsPart1),1)
5675 self.assertEqual(len(fmtsP),len(tss))
5676 for i,(f1tsP,tt) in enumerate(zip(fmtsP,tss)):
5677 fPart=f1tsP.field(mmOut) ; fPart.checkConsistencyLight()
5678 self.assertEqual(fPart.getTypeOfField(),ON_CELLS)
5679 arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic) ; arr0Exp+=i*1000.
5680 self.assertTrue(fPart.getMesh().isEqual(m0Part,1e-12))
5681 self.assertTrue(fPart.getArray().isEqual(arr0Exp,1e-12))
5682 self.assertEqual(fPart.getTime(),list(tt))
5687 def testSymmetryPlusAggregationMFD1(self):
5688 """ Testing of MEDFileData::Aggregate and MEDFileUMesh::Aggregate and MEDFileUMesh::getAllDistributionOfType """
5689 fname1="Pyfile106_1.med"
5690 fname2="Pyfile106_2.med"
5691 fname3="Pyfile106_3.med"
5694 da1=DataArrayDouble([1,2,10,3,4,11,5,6,12,7,8,13],4,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5696 mm1_0=MEDCouplingUMesh(meshName,3) ; mm1_0.allocateCells()
5697 mm1_0.setCoords(da1)
5698 mm1_0.insertNextCell(NORM_TETRA4,[0,1,2,3])
5699 mm1_0.insertNextCell(NORM_TETRA4,[4,5,6,7])
5700 mm1_0.insertNextCell(NORM_PENTA6,[8,9,10,11,12,13])
5701 mm1_0.insertNextCell(NORM_PENTA6,[14,15,16,17,18,19])
5702 mm1_0.insertNextCell(NORM_PENTA6,[20,21,22,23,24,25])
5704 mm1.setFamilyFieldArr(0,DataArrayInt([1,2,3,4,5]))
5705 mm1.setRenumFieldArr(0,DataArrayInt([11,12,13,14,15]))
5707 mm1_1=MEDCouplingUMesh(meshName,2) ; mm1_1.allocateCells()
5708 mm1_1.setCoords(da1)
5709 mm1_1.insertNextCell(NORM_TRI3,[0,1,2])
5710 mm1_1.insertNextCell(NORM_TRI3,[3,4,5])
5711 mm1_1.insertNextCell(NORM_QUAD4,[6,7,8,9])
5712 mm1_1.insertNextCell(NORM_QUAD4,[10,11,12,13])
5713 mm1_1.insertNextCell(NORM_QUAD4,[14,15,16,17])
5714 mm1_1.insertNextCell(NORM_QUAD4,[18,19,20,21])
5716 mm1.setFamilyFieldArr(-1,DataArrayInt([6,7,8,9,10,11]))
5717 mm1.setRenumFieldArr(-1,DataArrayInt([16,17,18,19,20,21]))
5718 for i in range(1,10):
5719 mm1.setFamilyId("F%d"%i,i)
5720 mm1.setFamilyId("FAMILLE_ZERO",0)
5721 mm1.setFamilyId("H1",100)
5722 mm1.setFamiliesOnGroup("myGRP",["F2","F6"])
5723 mm1.setFamiliesOnGroup("myGRP1",["F2","F6"])
5724 mm1.setFamilyFieldArr(1,DataArrayInt([12,13,14,15]))
5725 mm1.setRenumFieldArr(1,DataArrayInt([22,23,24,25]))
5728 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]"])
5730 mm2_0=MEDCouplingUMesh(meshName,3) ; mm2_0.allocateCells()
5731 mm2_0.setCoords(da1)
5732 mm2_0.insertNextCell(NORM_TETRA4,[100,101,102,103])
5733 mm2_0.insertNextCell(NORM_TETRA4,[104,105,106,107])
5734 mm2_0.insertNextCell(NORM_TETRA4,[108,109,110,111])
5735 mm2_0.insertNextCell(NORM_PENTA6,[112,113,114,115,116,117])
5737 mm2.setFamilyFieldArr(0,DataArrayInt([40,41,42,43]))
5738 mm2.setRenumFieldArr(0,DataArrayInt([50,51,52,53]))
5740 mm2_1=MEDCouplingUMesh(meshName,2) ; mm2_1.allocateCells()
5741 mm2_1.setCoords(da1)
5742 mm2_1.insertNextCell(NORM_TRI3,[100,101,102])
5743 mm2_1.insertNextCell(NORM_TRI3,[103,104,105])
5744 mm2_1.insertNextCell(NORM_TRI3,[106,107,108])
5745 mm2_1.insertNextCell(NORM_QUAD4,[109,110,111,112])
5746 mm2_1.insertNextCell(NORM_QUAD4,[113,114,115,116])
5747 mm2_1.insertNextCell(NORM_QUAD4,[117,118,119,120])
5748 mm2_1.insertNextCell(NORM_QUAD4,[121,122,123,124])
5749 mm2_1.insertNextCell(NORM_QUAD4,[125,126,127,128])
5751 mm2.setFamilyFieldArr(-1,DataArrayInt([200,201,202,203,204,205,206,207]))
5752 mm2.setRenumFieldArr(-1,DataArrayInt([300,301,302,303,304,305,306,307]))
5753 for i in range(1,12):
5754 mm2.setFamilyId("G%d"%i,i+30)
5755 mm2.setFamilyId("H1",100)
5756 mm2.setFamilyId("FAMILLE_ZERO",0)
5757 mm2.setFamiliesOnGroup("myGRP",["G2","G6"])
5758 mm2.setFamiliesOnGroup("myGRP2",["G4","G7"])
5759 mm2.setFamilyFieldArr(1,DataArrayInt([112,113,114,115,116]))
5760 mm2.setRenumFieldArr(1,DataArrayInt([122,123,124,125,126]))
5762 mm=MEDFileUMesh.Aggregate([mm1,mm2])
5764 def CheckMesh(tester,mm):
5765 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]"])
5766 tester.assertTrue(mm.getCoords().isEqual(cooExp,1e-12))
5767 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])))
5768 tester.assertTrue(mm[0].getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,32,39,46,53])))
5769 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])))
5770 tester.assertTrue(mm[-1].getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20,25,30,35,40,45,50,55,60,65])))
5771 tester.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([1,2,40,41,42,3,4,5,43])))
5772 tester.assertTrue(mm.getNumberFieldAtLevel(0).isEqual(DataArrayInt([11,12,50,51,52,13,14,15,53])))
5773 tester.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(DataArrayInt([6,7,200,201,202,8,9,10,11,203,204,205,206,207])))
5774 tester.assertTrue(mm.getNumberFieldAtLevel(-1).isEqual(DataArrayInt([16,17,300,301,302,18,19,20,21,303,304,305,306,307])))
5775 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)]
5776 tester.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
5777 tester.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
5778 tester.assertEqual(mm.getGroupsNames(),('myGRP','myGRP1','myGRP2'))
5779 tester.assertEqual(mm.getAllDistributionOfTypes(),[(NORM_TRI3,5),(NORM_QUAD4,9),(NORM_TETRA4,5),(NORM_PENTA6,4),(NORM_ERROR,9)])
5786 infoc=["dd [W]","eee [kA]"]
5788 fmts1=MEDFileFieldMultiTS()
5789 f1ts1=MEDFileField1TS()
5790 f1_1=MEDCouplingFieldDouble(ON_CELLS) ; f1_1.setMesh(mm1[0]) ; f1_1.setName(fieldName)
5791 arr1=DataArrayDouble([(10,110),(11,111),(12,112),(13,113),(14,114)])
5792 arr1.setInfoOnComponents(infoc)
5793 f1_1.setArray(arr1) ; f1_1.setTime(*t1) ; f1_1.setTimeUnit("ms")
5794 f1_1.checkConsistencyLight()
5795 f1ts1.setFieldNoProfileSBT(f1_1)
5797 f1_2=MEDCouplingFieldDouble(ON_CELLS) ; f1_2.setMesh(mm1[-1]) ; f1_2.setName(fieldName)
5798 arr2=DataArrayDouble([(15,115),(16,116),(17,117),(18,118),(19,119),(20,120)])
5799 arr2.setInfoOnComponents(infoc)
5800 f1_2.setArray(arr2) ; f1_2.setTime(*t1) ; f1_2.setTimeUnit("ms")
5801 f1_2.checkConsistencyLight()
5802 f1ts1.setFieldNoProfileSBT(f1_2)
5803 f1_3=MEDCouplingFieldDouble(ON_NODES) ; f1_3.setMesh(mm1[0]) ; f1_3.setName(fieldName)
5804 arr3=DataArrayDouble([(21,121),(22,122),(23,123),(24,124)])
5805 arr3.setInfoOnComponents(infoc)
5806 f1_3.setArray(arr3) ; f1_3.setTime(*t1) ; f1_3.setTimeUnit("ms")
5807 f1_3.checkConsistencyLight()
5808 f1ts1.setFieldNoProfileSBT(f1_3)
5809 fmts1.pushBackTimeStep(f1ts1)
5811 f1ts2=f1ts1.deepCopy()
5812 f1ts2.setTime(t2[1],t2[2],t2[0])
5813 f1ts2.getUndergroundDataArray()[:]+=2000
5814 fmts1.pushBackTimeStep(f1ts2)
5816 fmts2=MEDFileFieldMultiTS()
5817 f1ts3=MEDFileField1TS()
5818 f2_1=MEDCouplingFieldDouble(ON_CELLS) ; f2_1.setMesh(mm2[0]) ; f2_1.setName(fieldName)
5819 arr4=DataArrayDouble([(50,150),(51,151),(52,152),(53,153)])
5820 arr4.setInfoOnComponents(infoc)
5821 f2_1.setArray(arr4) ; f2_1.setTime(*t1) ; f2_1.setTimeUnit("ms")
5822 f2_1.checkConsistencyLight()
5823 f1ts3.setFieldNoProfileSBT(f2_1)
5824 f2_2=MEDCouplingFieldDouble(ON_CELLS) ; f2_2.setMesh(mm2[-1]) ; f2_2.setName(fieldName)
5825 arr5=DataArrayDouble([(54,154),(55,155),(56,156),(57,157),(158,158),(59,159),(60,160),(61,161)])
5826 arr5.setInfoOnComponents(infoc)
5827 f2_2.setArray(arr5) ; f2_2.setTime(*t1) ; f2_2.setTimeUnit("ms")
5828 f2_2.checkConsistencyLight()
5829 f1ts3.setFieldNoProfileSBT(f2_2)
5830 f2_3=MEDCouplingFieldDouble(ON_NODES) ; f2_3.setMesh(mm2[0]) ; f2_3.setName(fieldName)
5831 arr6=DataArrayDouble([(62,162),(63,163),(64,164),(65,165),(66,166)])
5832 arr6.setInfoOnComponents(infoc)
5833 f2_3.setArray(arr6) ; f2_3.setTime(*t1) ; f2_3.setTimeUnit("ms")
5834 f2_3.checkConsistencyLight()
5835 f1ts3.setFieldNoProfileSBT(f2_3)
5836 fmts2.pushBackTimeStep(f1ts3)
5838 f1ts4=f1ts3.deepCopy()
5839 f1ts4.setTime(t2[1],t2[2],t2[0])
5840 f1ts4.getUndergroundDataArray()[:]+=2000
5841 fmts2.pushBackTimeStep(f1ts4)
5844 mfd1.setMeshes(MEDFileMeshes())
5845 mfd1.getMeshes().pushMesh(mm1)
5846 mfd1.setFields(MEDFileFields())
5847 mfd1.getFields().pushField(fmts1)
5850 mfd2.setMeshes(MEDFileMeshes())
5851 mfd2.getMeshes().pushMesh(mm2)
5852 mfd2.setFields(MEDFileFields())
5853 mfd2.getFields().pushField(fmts2)
5855 mfd=MEDFileData.Aggregate([mfd1,mfd2])
5856 def CheckMFD(tester,mfd):
5857 tester.assertEqual(len(mfd.getMeshes()),1)
5858 tester.assertEqual(len(mfd.getFields()),1)
5859 CheckMesh(self,mfd.getMeshes()[0])
5860 tester.assertEqual(len(mfd.getFields()[0]),2)
5861 zeF1=mfd.getFields()[0][0]
5862 zeF1_1=zeF1.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5863 ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5864 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5865 ref.renumberCells(o2n)
5866 tester.assertTrue(ref.isEqual(zeF1_1,1e-12,1e-12))
5867 zeF1_2=zeF1.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5868 ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5869 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5870 ref.renumberCells(o2n)
5871 tester.assertTrue(ref.isEqual(zeF1_2,1e-12,1e-12))
5872 zeF1_3=zeF1.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5873 ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5874 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5875 ref.renumberCells(o2n)
5876 tester.assertTrue(ref.isEqual(zeF1_3,1e-12,1e-12))
5878 zeF2=mfd.getFields()[0][1]
5879 zeF2_1=zeF2.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5880 ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5881 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5882 ref.renumberCells(o2n)
5883 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5884 tester.assertTrue(ref.isEqual(zeF2_1,1e-12,1e-12))
5885 zeF2_2=zeF2.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5886 ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5887 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5888 ref.renumberCells(o2n)
5889 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5890 tester.assertTrue(ref.isEqual(zeF2_2,1e-12,1e-12))
5891 zeF2_3=zeF2.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5892 ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5893 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5894 ref.renumberCells(o2n)
5895 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5896 tester.assertTrue(ref.isEqual(zeF2_3,1e-12,1e-12))
5898 mfd1.write(fname1,2) ; mfd2.write(fname2,2)
5899 mfd=MEDFileData.Aggregate([MEDFileData(fname1),MEDFileData(fname2)])
5904 def testAggregateWithGroups(self):
5905 """ Testing MEDFileUMesh::Aggretate when groups are present. """
5906 def generate(grp_name, offset):
5907 coo = DataArrayDouble([0., 1., 2.])
5909 m = MEDCouplingCMesh("toto")
5910 m.setCoords(coo, coo)
5911 m = m.buildUnstructured()
5912 mu = MEDFileUMesh.New()
5913 mu.setMeshAtLevel(0, m)
5914 g = DataArrayInt([0])
5916 mu.setGroupsAtLevel(0, [g])
5919 m1 = generate("A", 0.)
5920 m2 = generate("B", 2.)
5921 mm = MEDFileUMesh.Aggregate([m1,m2])
5923 self.assertEqual(mm.getFamilyFieldAtLevel(0).getValues(), [-2, -1, -1, -1, -3, -1, -1, -1])
5924 self.assertEqual(mm.getNumberFieldAtLevel(0), None)
5925 refFamIds=[('Family_-1',-1),('Family_-2',-2),('Family_-3',-3)]
5926 self.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
5927 self.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
5928 self.assertEqual(mm.getGroupsNames(),('A','B'))
5929 self.assertEqual(mm.getGroupArr(0, 'A').getValues(), [0])
5930 self.assertEqual(mm.getGroupArr(0, 'B').getValues(), [4])
5935 def testExtrudedMesh1(self):
5936 fname="Pyfile107.med"
5937 arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5])
5938 mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ) ; mesh3D.setName("mesh")
5939 ex=MEDCouplingMappedExtrudedMesh(mesh3D)
5942 ex2=mm.convertToExtrudedMesh()
5943 mm2=MEDFileMesh.New(fname)
5944 ex3=mm2.convertToExtrudedMesh()
5945 self.assertTrue(ex.isEqual(ex2,1e-12))
5946 self.assertTrue(ex.isEqual(ex3,1e-12))
5949 @unittest.skipUnless(LooseVersion(MEDFileVersionStr())>=LooseVersion('3.2.1'),"This test requires at least MEDFile version 3.2.1")
5951 def testWriteInto30(self):
5952 fname="Pyfile108.med"
5953 fname2="Pyfile109.med"
5954 m=MEDCouplingUMesh("mesh",1) ; m.setCoords(DataArrayDouble([0,0,1,1],2,2)) ; m.allocateCells() ; m.insertNextCell(NORM_SEG2,[1,0])
5955 mm=MEDFileUMesh() ; mm[0]=m
5956 mm.setFamilyId("FAMILLE_ZERO",0)
5959 assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==[3,3]) # checks that just written MED file has a version == 3.0.x
5960 mm2=MEDFileUMesh(fname)
5961 self.assertTrue(mm.isEqual(mm2,1e-12))
5964 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
5967 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
5969 def testPickelizationOfMEDFileObjects1(self):
5970 fname="Pyfile110.med"
5971 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)
5972 m0=MEDCouplingUMesh("Mesh",2)
5974 m0.insertNextCell(NORM_TRI3,[1,4,2])
5975 m0.insertNextCell(NORM_TRI3,[4,5,2])
5976 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
5977 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
5978 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
5979 m0.finishInsertingCells()
5981 m1=MEDCouplingUMesh(m0.getName(),1)
5983 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
5985 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
5987 m1.finishInsertingCells()
5991 m.setMeshAtLevel(0,m0)
5992 m.setMeshAtLevel(-1,m1)
5994 dt=3 ; it=2 ; tim=4.5
5995 fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
5996 fieldNode0.setName("fieldNode0")
5997 fieldNode0.setTime(tim,dt,it)
5998 pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
5999 arr=DataArrayDouble([10,11,12,13,14])
6000 fieldNode0.setArray(arr)
6001 f0=MEDFileField1TS()
6002 f0.setFieldProfile(fieldNode0,m,0,pfl0)
6003 fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
6004 fieldNode1.setName("fieldNode1")
6005 fieldNode1.setTime(tim,dt,it)
6006 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
6007 arr1=DataArrayDouble([20,21,22,23,24,25,26])
6008 fieldNode1.setArray(arr1)
6009 f1=MEDFileField1TS()
6010 f1.setFieldProfile(fieldNode1,m,-1,pfl1)
6012 mfd.setMeshes(MEDFileMeshes()) ; mfd.setFields(MEDFileFields())
6013 mfd.getMeshes().pushMesh(m)
6014 fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(f0)
6015 mfd.getFields().pushField(fmts)
6016 # first start gently
6019 self.assertEqual(len(mfd2.getMeshes()),1)
6020 self.assertEqual(len(mfd2.getFields()),1)
6021 self.assertEqual(len(mfd2.getFields()[0]),1)
6022 self.assertTrue(mfd2.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
6023 ff2=mfd2.getFields()[0][0].field(mfd2.getMeshes()[0])
6024 ff =mfd.getFields()[0][0].field(mfd.getMeshes()[0])
6025 self.assertTrue(ff2.isEqual(ff,1e-12,1e-12))
6026 # OK now end of joke -> serialization of MEDFileData
6027 st=pickle.dumps(mfd,pickle.HIGHEST_PROTOCOL)
6028 mfd3=pickle.loads(st)
6030 self.assertEqual(len(mfd3.getMeshes()),1)
6031 self.assertEqual(len(mfd3.getFields()),1)
6032 self.assertEqual(len(mfd3.getFields()[0]),1)
6033 self.assertTrue(mfd3.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
6034 ff3=mfd3.getFields()[0][0].field(mfd3.getMeshes()[0])
6035 self.assertTrue(ff3.isEqual(ff,1e-12,1e-12))
6036 # serialization of MEDFileFields
6037 st=pickle.dumps(mfd.getFields(),pickle.HIGHEST_PROTOCOL)
6038 fs4=pickle.loads(st)
6039 ff4=fs4[0][0].field(mfd3.getMeshes()[0])
6040 self.assertTrue(ff4.isEqual(ff,1e-12,1e-12))
6041 # serialization of MEDFileFieldMulitTS
6042 st=pickle.dumps(mfd.getFields()[0],pickle.HIGHEST_PROTOCOL)
6043 fmts5=pickle.loads(st)
6044 ff5=fmts5[0].field(mfd3.getMeshes()[0])
6045 self.assertTrue(ff5.isEqual(ff,1e-12,1e-12))
6046 # serialization of MEDFileField1TS
6047 st=pickle.dumps(mfd.getFields()[0][0],pickle.HIGHEST_PROTOCOL)
6048 f1ts6=pickle.loads(st)
6049 ff6=f1ts6.field(mfd3.getMeshes()[0])
6050 self.assertTrue(ff6.isEqual(ff,1e-12,1e-12))
6051 # serialization of MEDFileMeshes
6052 st=pickle.dumps(mfd.getMeshes(),pickle.HIGHEST_PROTOCOL)
6053 ms7=pickle.loads(st)
6054 self.assertEqual(len(ms7),1)
6055 self.assertTrue(ms7[0].isEqual(mfd.getMeshes()[0],1e-12))
6058 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
6060 def testPickelizationOfMEDFileObjects2(self):
6062 self.internalMEDMesh6() # generates MEDFileMesh5.med file
6063 mm=MEDFileMesh.New("MEDFileMesh5.med")
6064 self.assertTrue(isinstance(mm,MEDFileCMesh))
6065 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
6066 mm2=pickle.loads(st)
6067 self.assertTrue(isinstance(mm2,MEDFileCMesh))
6068 self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12))
6070 self.internalCurveLinearMesh1() # generates Pyfile55.med
6071 mm=MEDFileMesh.New("Pyfile55.med")
6072 self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh))
6073 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
6074 mm3=pickle.loads(st)
6075 self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh))
6076 self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12))
6077 self.internalInt32InMEDFileFieldStar1()# generates Pyfile63.med
6078 # MEDFileIntFieldMultiTS
6079 fs4=MEDFileFields("Pyfile63.med")
6080 ms4=MEDFileMeshes("Pyfile63.med")
6081 self.assertTrue(isinstance(fs4[0],MEDFileIntFieldMultiTS))
6082 st=pickle.dumps(fs4[0],pickle.HIGHEST_PROTOCOL)
6083 fmts5=pickle.loads(st)
6084 self.assertEqual(len(fs4[0]),len(fmts5))
6085 self.assertTrue(isinstance(fmts5,MEDFileIntFieldMultiTS))
6086 self.assertTrue(fmts5[0].field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
6087 # MEDFileIntField1TS
6088 st=pickle.dumps(fs4[0][0],pickle.HIGHEST_PROTOCOL)
6089 f1ts6=pickle.loads(st)
6090 self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS))
6091 self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
6093 self.internalParameters1()# generates Pyfile56.med
6094 params=MEDFileParameters("Pyfile56.med")
6095 st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL)
6096 params7=pickle.loads(st)
6097 self.assertEqual(len(params),len(params7))
6098 for i in range(len(params)):
6099 self.assertTrue(params[i].isEqual(params7[i],1e-12)[0])
6104 def testGlobalNumOnNodes1(self):
6105 """Test global number on nodes here. Used by partitionners."""
6106 fname="Pyfile112.med"
6107 arr=DataArrayDouble(5) ; arr.iota()
6108 m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
6112 self.assertTrue(not mm.getGlobalNumFieldAtLevel(1))
6113 d=DataArrayInt([7,8,9,2,0])
6115 mm.setGlobalNumFieldAtLevel(1,d)
6116 mm.checkConsistency()
6117 self.assertRaises(InterpKernelException,mm.setGlobalNumFieldAtLevel,1,d[::2])
6118 mm.checkConsistency()
6119 self.assertEqual(d.getHiddenCppPointer(),mm.getGlobalNumFieldAtLevel(1).getHiddenCppPointer())
6120 self.assertTrue(mm.getGlobalNumFieldAtLevel(1).isEqual(dRef))
6122 mm2=MEDFileMesh.New(fname)
6123 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
6124 self.assertTrue(mm2.getGlobalNumFieldAtLevel(1).isEqual(dRef))
6125 mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,10)
6126 self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
6127 mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,7)
6128 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
6132 def testPartialReadOfEntities1(self):
6133 """Test for advanced API on read to speed up read phase for users with "huge" number of time steps (more than 10 000)."""
6134 fname="Pyfile113.med"
6135 arr=DataArrayDouble(5) ; arr.iota()
6136 m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
6143 f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m) ; f1.setName(fieldName)
6144 f1.setArray(DataArrayDouble([0.,0.1,0.2,0.3,0.4]))
6146 f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m) ; f2.setName(fieldName)
6147 f2.setArray(DataArrayDouble([1.,1.1,1.2,1.3]))
6149 f1ts=MEDFileField1TS()
6150 f1ts.setFieldNoProfileSBT(f1)
6151 f1ts.setFieldNoProfileSBT(f2)
6152 self.assertEqual(set(f1ts.getTypesOfFieldAvailable()),set([ON_NODES,ON_CELLS]))
6153 f1ts_2=f1ts.deepCopy()
6154 f1ts_2.getUndergroundDataArray()[:]+=2
6155 f1ts_2.setTime(3,4,6.)
6156 fmts=MEDFileFieldMultiTS()
6157 fmts.pushBackTimeStep(f1ts)
6158 fmts.pushBackTimeStep(f1ts_2)
6163 ent=MEDFileEntities.BuildFrom([(ON_NODES,NORM_ERROR)])
6164 mm=MEDFileMesh.New(fname)
6165 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)
6167 self.assertEqual(len(fs),1)
6169 self.assertEqual(len(fmts),2)
6170 ff0=fmts[0] ; ff1=fmts[1]
6171 self.assertEqual(ff0.getTypesOfFieldAvailable(),[ON_NODES]) # only NODES have been loaded
6172 self.assertTrue(ff0.field(mm).isEqual(f1,1e-12,1e-12))
6173 f3=f1.deepCopy() ; f3+=2. ; f3.setTime(6.,3,4)
6174 self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
6178 def testFloat32InMEDFileFieldStar1(self):
6179 """Like testInt32InMEDFileFieldStar1 but with float32 :)"""
6180 fname="Pyfile114.med"
6181 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
6182 f1=f1.convertToFloatField()
6184 mm1=MEDFileUMesh.New()
6185 mm1.setCoords(m1.getCoords())
6186 mm1.setMeshAtLevel(0,m1)
6187 mm1.setName(m1.getName())
6189 ff1=MEDFileFloatField1TS()
6190 ff1.setFieldNoProfileSBT(f1)
6191 a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6192 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6193 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6195 a,b=ff1.getUndergroundDataArrayExt()
6196 self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
6197 self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
6198 ff2=MEDFileAnyTypeField1TS.New(fname)
6199 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
6200 self.assertEqual(ff2.getTime(),[0,1,2.0])
6201 self.assertTrue(isinstance(ff2,MEDFileFloatField1TS))
6202 a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6203 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6204 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6206 c=ff2.getUndergroundDataArray() ; c*=2
6207 ff2.write(fname,0) # 2 time steps in
6208 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
6209 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
6210 self.assertEqual(len(ffs1),2)
6211 self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS))
6212 a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6213 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6214 a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
6215 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6216 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
6217 a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6218 self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7))
6219 f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
6220 self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2
6221 bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6223 a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6226 self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7))
6227 nf1=MEDCouplingFieldFloat(ON_NODES)
6228 nf1.setTime(9.,10,-1)
6229 nf1.setMesh(f1.getMesh())
6230 narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
6231 nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
6232 nff1=MEDFileFloatField1TS.New()
6233 nff1.setFieldNoProfileSBT(nf1)
6234 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
6235 self.assertEqual(nff1.getTime(),[10,-1,9.0])
6238 nf2=MEDCouplingFieldFloat(ON_NODES)
6239 nf2.setTime(19.,20,-11)
6240 nf2.setMesh(f1.getMesh())
6241 narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
6242 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
6243 nff2=MEDFileFloatField1TS.New()
6244 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
6245 nff2.setFieldProfile(nf2,mm1,0,npfl)
6246 nff2.getFieldWithProfile(ON_NODES,0,mm1)
6247 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6248 self.assertTrue(b.isEqual(npfl))
6249 self.assertTrue(a.isEqual(narr2,1e-7))
6251 nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl")
6252 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6253 self.assertTrue(b.isEqual(npfl))
6254 self.assertTrue(a.isEqual(narr2,1e-7))
6256 nf3=MEDCouplingFieldDouble(ON_NODES)
6257 nf3.setName("VectorFieldOnNodesDouble")
6258 nf3.setTime(29.,30,-21)
6259 nf3.setMesh(f1.getMesh())
6260 nf3.setArray(f1.getMesh().getCoords())
6261 nff3=MEDFileField1TS.New()
6262 nff3.setFieldNoProfileSBT(nf3)
6264 fs=MEDFileFields(fname)
6265 self.assertEqual(len(fs),4)
6266 ffs=[it for it in fs]
6267 self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS))
6268 self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS))
6269 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
6270 self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS))
6272 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7))
6273 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7))
6274 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7))
6275 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7))
6276 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6278 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
6279 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6280 self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
6281 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
6282 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
6283 self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
6284 MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1)
6285 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
6287 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
6288 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6289 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
6290 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6294 def testPenta18_1(self):
6295 """EDF8478 : Test of read/write of penta18"""
6296 fname="Pyfile115.med"
6297 arr=DataArrayDouble([
6298 (0.,1.,1.),(0.,0.,1.),(1.,0.,1.),
6299 (0.,1.,0.),(0.,0.,0.),(1.,0.,0.),
6300 (0.,0.5,1.),(0.5,0.,1.),(0.5,0.5,1.),
6301 (0.,0.5,0.),(0.5,0.,0.),(0.5,0.5,0.),
6302 (0.,1.,0.5),(0.,0.,0.5),(1.,0.,0.5),
6303 (0.,0.5,0.5),(0.5,0.,0.5),(0.5,0.5,0.5)])
6304 m=MEDCouplingUMesh("mesh",3)
6307 m.insertNextCell(NORM_PENTA18,list(range(18)))
6308 m.checkConsistencyLight()
6310 f=MEDCouplingFieldDouble(ON_NODES)
6312 f.setName("FieldOnPenta18")
6313 f.setArray(DataArrayDouble(list(range(18))))
6314 f.checkConsistencyLight()
6316 m2,d,di,rd,rdi=m.buildDescendingConnectivity()
6318 f2=MEDCouplingFieldDouble(ON_NODES)
6320 f2.setName("FieldOnPenta18Sub")
6321 f2.setArray(DataArrayDouble(list(range(18))))
6322 f2.checkConsistencyLight()
6323 WriteField(fname,f2,True)
6325 self.assertTrue(f2.isEqual(f3,1e-12,1e-12))
6326 self.assertEqual(f3.getMesh().getNumberOfCells(),1)
6327 self.assertEqual(f3.getMesh().getTypeOfCell(0),NORM_PENTA18)
6331 def testFieldsLinearToQuadratic(self):
6332 fname="Pyfile117.med"
6333 arr=DataArrayDouble([0,1])
6334 m=MEDCouplingCMesh();
6335 m.setCoords(arr,arr,arr)
6336 m=m.buildUnstructured()
6338 m2.translate([2,0,0])
6339 m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6343 mmq=mm.linearToQuadratic(0)
6344 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6345 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6347 f=MEDCouplingFieldDouble(ON_NODES)
6351 arr=DataArrayDouble(m3.getNumberOfNodes())
6354 f1ts=MEDFileField1TS()
6355 f1ts.setFieldNoProfileSBT(f)
6356 fmts=MEDFileFieldMultiTS()
6357 fmts.pushBackTimeStep(f1ts)
6358 f1ts_2=f1ts.deepCopy()
6359 f1ts_2.setTime(3,4,5.)
6360 f1ts_2.getUndergroundDataArray()[:]*=2.
6361 fmts.pushBackTimeStep(f1ts_2)
6364 fs2=fs.linearToQuadratic(mms,mmsq)
6365 self.myTester1(fs2,mmsq[0])
6366 # A small Write/Read and test again
6367 mms.write(fname,2) ; fs.write(fname,0)
6368 mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6369 mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6370 fs2=fs.linearToQuadratic(mms,mmqs)
6371 self.myTester1(fs2,mmqs[0])
6374 def myTester1(self,fs2,mmq):
6375 dataExp=DataArrayDouble([0.,0.,0.,1.,0.,0.,0.,1.,0.,1.,1.,0.,0.,0.,1.,1.,0.,1.,0.,1.,1.,1.,1.,1.,2.,0.,0.,3.,0.,0.,2.,1.,0.,3.,1.,0.,2.,0.,1.,3.,0.,1.,2.,1.,1.,3.,1.,1.,0.5, 0.,0.,0.,0.5, 0.,0.5, 1.,0.,1.,0.5, 0.,0.5, 0.,1.,0.,0.5, 1.,0.5, 1.,1.,1.,0.5, 1.,1.,0.,0.5, 0.,0.,0.5, 0.,1.,0.5, 1.,1.,0.5, 2.5, 0.,0.,2.,0.5, 0.,2.5, 1.,0.,3.,0.5, 0.,2.5, 0.,1.,2.,0.5, 1.,2.5, 1.,1.,3.,0.5, 1.,3.,0.,0.5, 2.,0.,0.5, 2.,1.,0.5, 3.,1.,0.5],40,3)
6376 dataExp1=DataArrayInt([1,0,2,3,5,4,6,7,16,17,18,19,20,21,22,23,24,25,26,27,9,8,10,11,13,12,14,15,28,29,30,31,32,33,34,35,36,37,38,39])
6377 dataExp2=DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0.5,1,2.5,2,4.5,5,6.5,6,3,2,4,5,8.5,9,10.5,10,12.5,13,14.5,14,11,10,12,13])
6378 fToTest=fs2[0][0].field(mmq)
6379 self.assertEqual(fToTest.getTime(),[3.,1,2])
6380 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6381 self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6382 self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6383 self.assertTrue(fToTest.getArray().isEqual(dataExp2,1e-12))
6384 # testing 2nd timestep
6385 fToTest=fs2[0][1].field(mmq)
6386 self.assertEqual(fToTest.getTime(),[5.,3,4])
6387 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6388 self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6389 self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6390 self.assertTrue(fToTest.getArray().isEqual(2*dataExp2,1e-12))
6394 def testFieldsLinearToQuadratic2(self):
6395 """Same than testFieldsLinearToQuadratic but with profile on NODES"""
6396 GeneratePyfile18(self)
6397 fname="Pyfile118.med"
6398 arr=DataArrayDouble([0,1])
6399 m=MEDCouplingCMesh();
6400 m.setCoords(arr,arr,arr)
6401 m=m.buildUnstructured()
6403 m2.translate([2,0,0])
6404 m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6406 # add a point for fun
6407 m3.setCoords(DataArrayDouble.Aggregate(m3.getCoords(),DataArrayDouble([1.5,1.5,1.5],1,3)))
6411 mmq=mm.linearToQuadratic(0)
6412 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6413 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6415 f=MEDCouplingFieldDouble(ON_NODES)
6419 arr=DataArrayDouble(8) ; arr.iota()
6422 f1ts=MEDFileField1TS()
6423 pfl=DataArrayInt([8,9,10,11,12,13,14,15]) ; pfl.setName("pfl")
6424 f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 8 nodes of cell #1
6425 f1ts_2=f1ts.deepCopy()
6426 f1ts_2.setTime(3,4,5.)
6427 f1ts_2.getUndergroundDataArray()[:]*=4.
6428 fmts=MEDFileFieldMultiTS()
6429 fmts.pushBackTimeStep(f1ts)
6430 fmts.pushBackTimeStep(f1ts_2)
6433 fs2=fs.linearToQuadratic(mms,mmsq)
6434 mms.write(fname,2) ; fs.write(fname,0)
6436 self.myTester2(fs2,mmq)
6438 mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6439 mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6440 fs2=fs.linearToQuadratic(mms,mmqs)
6441 self.myTester2(fs2,mmq)
6442 ## More vicious add single node 16
6445 mmq=mm.linearToQuadratic(0)
6446 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6447 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6449 f=MEDCouplingFieldDouble(ON_NODES)
6453 arr=DataArrayDouble(9) ; arr.iota()
6456 f1ts=MEDFileField1TS()
6457 pfl=DataArrayInt([8,9,10,11,12,13,14,15,16]) ; pfl.setName("pfl")
6458 f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 9 nodes of cell #1 + orphan node
6459 fmts=MEDFileFieldMultiTS()
6460 fmts.pushBackTimeStep(f1ts)
6463 fs2=fs.linearToQuadratic(mms,mmsq)
6465 pflExpected=DataArrayInt([8,9,10,11,12,13,14,15,16,29,30,31,32,33,34,35,36,37,38,39,40]) ; pflExpected.setName("pfl_NODE")
6466 f1tsToTest=fs2[0][0]
6467 exp1=DataArrayDouble([0,1,2,3,4,5,6,7,8,0.5,1,2.5,2,4.5,5,6.5,6,3,2,4,5])
6468 assert(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6469 assert(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6470 assert(f1tsToTest.getFieldSplitedByType()==[(40,[(1,(0,21),'pfl_NODE','')])])
6473 def myTester2(self,fs2,mmq):
6474 pflExpected=DataArrayInt([8,9,10,11,12,13,14,15,29,30,31,32,33,34,35,36,37,38,39,40]) ; pflExpected.setName("pfl_NODE")
6475 f1tsToTest=fs2[0][0]
6476 exp1=DataArrayDouble([0,1,2,3,4,5,6,7,0.5,1,2.5,2,4.5,5,6.5,6,3,2,4,5])
6477 self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6478 self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6479 self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6480 fToTest=fs2[0][0].field(mmq)
6481 self.assertEqual(fToTest.getTime(),[3.,1,2])
6482 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6483 self.assertTrue(mTest.getNodalConnectivity().isEqual(DataArrayInt([1,0,2,3,5,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19])))
6484 self.assertTrue(mTest.getCoords().isEqual(DataArrayDouble([(2,0,0),(3,0,0),(2,1,0),(3,1,0),(2,0,1),(3,0,1),(2,1,1),(3,1,1),(2.5,0,0),(2,0.5,0),(2.5,1,0),(3,0.5,0),(2.5,0,1),(2,0.5,1),(2.5,1,1),(3,0.5,1),(3,0,0.5),(2,0,0.5),(2,1,0.5),(3,1,0.5)],20,3),1e-12))
6485 self.assertTrue(fToTest.getArray().isEqual(exp1,1e-12))
6487 f1tsToTest=fs2[0][1]
6488 self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6489 self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(4*exp1,1e-12))
6490 self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6491 fToTest=fs2[0][1].field(mmq)
6492 self.assertEqual(fToTest.getTime(),[5.,3,4])
6493 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6494 self.assertTrue(mTest.getNodalConnectivity().isEqual(DataArrayInt([1,0,2,3,5,4,6,7,8,9,10,11,12,13,14,15,16,17,18,19])))
6495 self.assertTrue(mTest.getCoords().isEqual(DataArrayDouble([(2,0,0),(3,0,0),(2,1,0),(3,1,0),(2,0,1),(3,0,1),(2,1,1),(3,1,1),(2.5,0,0),(2,0.5,0),(2.5,1,0),(3,0.5,0),(2.5,0,1),(2,0.5,1),(2.5,1,1),(3,0.5,1),(3,0,0.5),(2,0,0.5),(2,1,0.5),(3,1,0.5)],20,3),1e-12))
6496 self.assertTrue(fToTest.getArray().isEqual(4*exp1,1e-12))
6501 def testSetFieldProfileFlatly1(self):
6502 """ Sometimes for downstream code fan of profiles, profile are requested unconditionally. setFieldProfile try to reduce at most profile usage. So setFieldProfileFlatly has been added to always create
6504 arr=DataArrayDouble(10) ; arr.iota()
6505 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
6506 m=m.buildUnstructured()
6509 m=MEDCouplingUMesh.MergeUMeshes(m2,m)
6513 f=MEDCouplingFieldDouble(ON_CELLS)
6515 arr=DataArrayDouble(m.getNumberOfCells())
6519 pfl=DataArrayInt(m.getNumberOfCells()) ; pfl.iota() ; pfl.setName("pfl")
6521 refSp=[(3,[(0,(0,162),'','')]),(4,[(0,(162,243),'','')])]
6522 refSp1=[(3,[(0,(0,162),'pfl_NORM_TRI3','')]),(4,[(0,(162,243),'pfl_NORM_QUAD4','')])]
6524 f1ts=MEDFileField1TS()
6525 f1ts.setFieldProfile(f,mm,0,pfl)
6526 self.assertEqual(f1ts.getPfls(),()) # here setFieldProfile has detected useless pfl -> no pfl
6527 self.assertEqual(f1ts.getFieldSplitedByType(),refSp)
6528 self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
6530 f1ts=MEDFileField1TS()
6531 f1ts.setFieldProfileFlatly(f,mm,0,pfl) # no optimization attempt. Create pfl unconditionally
6532 self.assertEqual(f1ts.getPfls(),("%s_NORM_TRI3"%pfl.getName(),"%s_NORM_QUAD4"%pfl.getName()))
6533 self.assertEqual(f1ts.getFieldSplitedByType(),refSp1)
6534 self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
6535 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3").isIota(162))
6536 self.assertTrue(f1ts.getProfile("pfl_NORM_QUAD4").isIota(81))
6540 def testRmGroupAtSpeLevelAndMultiLevGrpCreation(self):
6541 """ Here multi level groups are created"""
6542 arr=DataArrayDouble(11) ; arr.iota()
6543 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
6544 m=m.buildUnstructured()
6546 m1=m.buildDescendingConnectivity()[0]
6551 grp0_0=DataArrayInt([0,1,2,6]) ; grp0_0.setName(grpName)
6552 grp0_1=DataArrayInt([0,1,2,7]) ; grp0_1.setName(grpName)
6553 grp1=DataArrayInt([1,2,3,5,6]) ; grp1.setName("grp1")
6554 grp2=DataArrayInt([2,3,5,8]) ; grp2.setName("grp2")
6555 ################ ajouter un groupe sur plusieurs niveau
6557 mm.addGroup(-1,grp2)
6558 mm.addGroup(0,grp0_0)
6559 mm.addGroup(-1,grp0_1)
6560 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
6561 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6562 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6563 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6564 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6565 self.assertRaises(InterpKernelException,mm.addGroup,-1,grp0_1) # raise
6566 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6567 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6568 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6569 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6570 mm.removeGroupAtLevel(0,grpName)
6571 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(-1,))
6572 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6573 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6574 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6575 mm.removeGroupAtLevel(-1,grpName)
6576 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),())
6577 self.assertRaises(InterpKernelException,mm.removeGroupAtLevel,-2,grpName)
6578 mm.addGroup(-1,grp0_1)
6579 mm.addGroup(0,grp0_0)
6580 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
6581 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6582 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6583 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6584 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6588 def testYutaka(self):
6589 """ Thank you to Yutaka Nishizawa for having report this bug. At level -1, adding a first group on all entities leads to a group lying on family 0...
6590 Then rearrange method removes unused entites by putting 0 on them -> Previously group has been modified by rearrange. Should not !"""
6592 m=MEDCouplingCMesh()
6593 arr=DataArrayDouble(4) ; arr.iota()
6594 m.setCoords(arr,arr,arr)
6595 m=m.buildUnstructured()
6598 m=m.buildUnstructured()
6599 m1=m.buildDescendingConnectivity()[0]
6605 grp0=DataArrayInt([0,1,2]) ; grp0.setName("grp0")
6607 grp1=DataArrayInt([3,4,5,6]) ; grp1.setName("grp1")
6609 grp2=DataArrayInt([7,8,9]) ; grp2.setName("grp2")
6611 grp3=DataArrayInt.Range(0,m1.getNumberOfCells(),1) ; grp3.setName("grp3")
6612 mm.addGroup(-1,grp3)
6613 self.assertNotIn(0,mm.getFamiliesIdsOnGroup("grp3")) # bug was here !
6614 grp4=DataArrayInt([3,5,8,10]) ; grp4.setName("grp4")
6615 mm.addNodeGroup(grp4)
6616 mm.rearrangeFamilies()
6617 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp0"),(0,))
6618 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp1"),(0,))
6619 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp2"),(0,))
6620 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp3"),(-1,))
6621 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp4"),(1,))
6623 for grp in [grp0,grp1,grp2,grp3,grp4]:
6624 self.assertTrue(mm.getGroupArr(mm.getGrpNonEmptyLevelsExt(grp.getName())[0],grp.getName()).isEqual(grp))
6629 def testContxtMger1TS(self):
6630 fname="Pyfile119.med"
6631 coo=DataArrayDouble(1000) ; coo.iota()
6632 m=MEDCouplingUMesh.Build0DMeshFromCoords(coo)
6634 WriteMesh(fname,m,True)
6635 f=MEDCouplingFieldDouble(ON_CELLS)
6638 arr=DataArrayDouble(m.getNumberOfCells())
6640 f.checkConsistencyLight()
6643 f.setTime(float(i),i,0)
6644 WriteFieldUsingAlreadyWrittenMesh(fname,f)
6647 mm=MEDFileMesh.New(fname)
6648 fmts=MEDFileFieldMultiTS(fname,False)
6649 refSize=fmts.getHeapMemorySize()
6655 self.assertIn(fmts.getHeapMemorySize(),range(refSize,refSize+refSize//10))
6660 if __name__ == "__main__":