1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2020 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 cooMem = 100 * 2 * 8
2260 nodalMem = 5 * 81 * MEDCouplingSizeOfIDs()//8
2261 indexMem = 82 * MEDCouplingSizeOfIDs()//8
2262 meshMem = cooMem + nodalMem + indexMem
2263 self.assertIn(m.getHeapMemorySize(), list(range(meshMem - 100, meshMem + 100 + 4 * strMulFac)))
2264 delta = (m.getHeapMemorySize()-meshMem)//3 # std::string::capacity behaves differently
2265 self.assertIn(f.getHeapMemorySize(), list(range(meshMem + 81*8 - (100 + 3*delta), meshMem + 81*8 + (100+3*delta) + 8 * strMulFac)))
2268 mm.setMeshAtLevel(0,m)
2269 self.assertIn(mm.getHeapMemorySize(), list(range(meshMem + 81*(MEDCouplingSizeOfIDs()//8) - (100+3*delta), meshMem + 81*(MEDCouplingSizeOfIDs()//8) + (100+3*delta) + 10 * strMulFac)))
2270 ff=MEDFileField1TS()
2271 ff.setFieldNoProfileSBT(f)
2272 self.assertIn(ff.getHeapMemorySize(), list(range(771 - 40, 871 + 21 + (4 + 1) * strMulFac)))
2274 fff=MEDFileFieldMultiTS()
2275 fff.appendFieldNoProfileSBT(f)
2276 self.assertIn(fff.getHeapMemorySize(), list(range(815 - 50, 915 + 30 + (6 + 2) * strMulFac)))
2278 fff.appendFieldNoProfileSBT(f)
2279 self.assertIn(fff.getHeapMemorySize(), list(range(1594 - 90, 1794 + 50 + (10 + 1) * strMulFac)))
2280 self.assertIn(fff[0, -1].getHeapMemorySize(), list(range(771 - 40, 871 + 20 + (4 + 1) * strMulFac)))
2283 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2284 fff.appendFieldProfile(f2,mm,0,pfl)
2285 self.assertIn(fff.getHeapMemorySize(), range(2348 - 130, 2608 + 400 + (10 + 2) * strMulFac))
2286 self.assertIn(fff.getProfile("pfl").getHeapMemorySize(), list(range(50 *(MEDCouplingSizeOfIDs()//8) - 10, 50 *(MEDCouplingSizeOfIDs()//8) + 10 + 2 * strMulFac)))
2287 self.assertIn(fff[1, -1].getHeapMemorySize(), range(538 + (50 *(MEDCouplingSizeOfIDs()//8)) - 50, 900 + (50 *(MEDCouplingSizeOfIDs()//8)) + 30 + 4 * strMulFac))
2290 def internalCurveLinearMesh1(self):
2291 fname="Pyfile55.med"
2292 mesh=MEDCouplingCurveLinearMesh();
2293 mesh.setTime(2.3,4,5);
2294 mesh.setTimeUnit("us");
2295 mesh.setName("Example of Cuve linear mesh");
2296 mesh.setDescription("buildCLMesh");
2297 a1=DataArrayDouble(3*20,1);
2298 a1.iota(7.) ; a1.rearrange(3);
2300 mesh.setNodeGridStructure([4,5]);
2301 mesh.checkConsistencyLight();
2303 m=MEDFileCurveLinearMesh()
2305 d=DataArrayInt(20) ; d.iota(4)
2306 m.setFamilyFieldArr(1,d)
2307 d3=DataArrayInt(20) ; d3.iota(400)
2308 m.setRenumFieldArr(1,d3)
2309 d2=DataArrayInt(12) ; d2.iota(40)
2310 m.setFamilyFieldArr(0,d2)
2311 d4=DataArrayInt(21) ; d4.iota(4000)
2312 self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2314 m.setRenumFieldArr(1,d4)
2317 m1=MEDFileCurveLinearMesh(fname)
2319 self.assertTrue(mm.isEqual(mesh,1e-12))
2320 self.assertEqual(mm.getSpaceDimension(),3)
2321 self.assertEqual(mm.getSpaceDimensionOnNodeStruct(),2)
2323 m1=MEDFileMesh.New(fname)
2324 self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2325 self.assertTrue(isinstance(m1.getUnivName(),str))
2326 self.assertTrue(len(m1.getUnivName())!=0)
2327 self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2331 def testCurveLinearMesh1(self):
2332 self.internalCurveLinearMesh1()
2335 def testParameters1(self):
2336 self.internalParameters1()
2338 def internalParameters1(self):
2339 fname="Pyfile56.med"
2340 m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2341 mm=MEDFileCMesh() ; mm.setMesh(m)
2342 ms=MEDFileMeshes() ; ms.pushMesh(mm)
2344 p=MEDFileParameters()
2345 data.setParams(p) ; data.setMeshes(ms)
2346 pts=MEDFileParameterMultiTS()
2347 pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2348 pts.appendValue(1,2,3.4,567.89)
2349 pts.appendValue(2,3,5.6,999.123)
2350 pts2=pts.deepCopy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2351 p.pushParam(pts) ; p.pushParam(pts2)
2353 p2=MEDFileParameters(fname)
2354 self.assertTrue(p.isEqual(p2,1e-14)[0])
2355 self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2357 pts4=pts2.deepCopy()
2358 pts3=pts2.deepCopy()
2359 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2360 pts2.eraseTimeStepIds([0])
2361 self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2363 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2364 self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2365 self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2366 self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2367 self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2369 self.assertTrue(p.isEqual(p2,1e-14)[0])
2370 self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2371 self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2372 self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2373 self.assertEqual(p.getParamsNames(),('A','B'))
2374 ptsr=MEDFileParameterMultiTS(fname,"B")
2375 self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2376 ptsr=MEDFileParameterMultiTS(fname)
2377 self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2378 p1tsr=MEDFileParameterDouble1TS(fname)
2379 self.assertEqual(p1tsr.getName(),"A")
2380 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2381 p1tsr=MEDFileParameterDouble1TS(fname,"B")
2382 self.assertEqual(p1tsr.getName(),"B")
2383 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2384 p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2385 self.assertEqual(p1tsr.getName(),"B")
2386 self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2387 data2=MEDFileData(fname)
2388 self.assertEqual(2,data2.getNumberOfParams())
2389 self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2393 def testNamesOnCellAndNodesInMeshes1(self):
2394 fname="Pyfile58.med"
2395 fname2="Pyfile59.med"
2396 m=MEDLoaderDataForTest.build3DSurfMesh_1()
2397 m1=m.buildDescendingConnectivity()[0]
2398 m1.sortCellsInMEDFileFrmt()
2401 mm.setMeshAtLevel(0,m)
2402 mm.setMeshAtLevel(-1,m1)
2403 namesCellL0=DataArrayAsciiChar(6,16)
2404 namesCellL0[:] = ["CellL0#%.3d " % (i) for i in range(6)]
2405 mm.setNameFieldAtLevel(0,namesCellL0)
2406 namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.subArray(2)])
2407 namesCellL1[:] = ["CellLM1#%.3d " % (i) for i in range(16)]
2408 mm.setNameFieldAtLevel(-1,namesCellL1)
2409 namesNodes=namesCellL1.subArray(4,16)
2410 namesNodes[:] = ["Node#%.3d " % (i) for i in range(12)]
2411 mm.setNameFieldAtLevel(1,namesNodes)
2414 mmr=MEDFileMesh.New(fname)
2415 self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
2416 self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d " % (i) for i in range(16)])))
2417 self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(12)])))
2418 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2419 mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2420 self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2421 mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2422 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2424 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2425 # remove names on nodes
2426 mmCpy.setNameFieldAtLevel(1,None)
2427 self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2428 mm.setNameFieldAtLevel(1,None)
2429 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2430 mm.setNameFieldAtLevel(-1,None)
2432 mmr=MEDFileMesh.New(fname)
2433 self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2434 self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
2435 self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2437 c=MEDCouplingCMesh()
2438 arr=DataArrayDouble([0.,1.1,2.3])
2439 c.setCoords(arr,arr)
2443 cc.setNameFieldAtLevel(0, DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)]))
2444 cc.setNameFieldAtLevel(1, DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)]))
2446 ccr=MEDFileMesh.New(fname2)
2447 self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)])))
2448 self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)])))
2449 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2450 ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2451 self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2452 ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2453 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2455 self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2459 def testToExportInExamples1(self):
2460 m=MEDCouplingCMesh()
2461 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2462 m.setCoords(arr,arr)
2463 m=m.buildUnstructured() ; m.setName("mesh")
2464 grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2465 grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2468 mm.setMeshAtLevel(0,m)
2469 mm.setMeshAtLevel(-1,m2)
2470 mm.setGroupsAtLevel(0,[grp1,grp2])
2471 mm.write("example.med",2)
2473 m0=mm.getMeshAtLevel(0)
2474 m1=mm.getMeshAtLevel(-1)
2475 grp1=mm.getGroupArr(0,"grp1")
2476 grp2=mm.getGroupArr(0,"grp2")
2478 whichGrp=DataArrayInt(m0.getNumberOfCells())
2479 whichGrp.fillWithValue(-1)
2480 for grpId,grp in enumerate(grps):
2483 a,b,bI,c,cI=m0.buildDescendingConnectivity()
2484 e,f=a.areCellsIncludedIn(m1,2)
2486 c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2487 self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2488 c2.transformWithIndArr(whichGrp)
2489 splitOfM1=len(grps)*[None]
2490 for grpId,grp in enumerate(grps):
2491 tmp=c2.findIdsEqual(grpId)
2492 splitOfM1[grpId]=tmp
2494 splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2495 splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2499 def testBugCorrection1(self):
2502 self.assertEqual(fs[0],None)
2503 self.assertEqual(3,len(fs))
2507 def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2508 f1Name="Pyfile60.med"
2509 f2Name="Pyfile61.med"
2510 d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2512 d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2514 # reading and compare
2515 d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2516 for mn in d1.getMeshes().getMeshesNames():
2517 m1=d1.getMeshes()[mn]
2518 m2=d2.getMeshes()[mn]
2519 for lev in m1.getNonEmptyLevels():
2520 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2521 for grpName in grpsNames:
2522 self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2526 for fieldn in d1.getFields().getFieldsNames():
2527 f1=d1.getFields()[fieldn]
2528 f2=d2.getFields()[fieldn]
2529 for it,order,tim in f1.getTimeSteps():
2532 if len(f1t.getPflsReallyUsed())!=0:
2534 for lev in f1t.getNonEmptyLevels()[1]:
2535 arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2536 arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2537 self.assertTrue(pfl1.isEqual(pfl2))
2538 self.assertTrue(arr1.isEqual(arr2,1e-10))
2543 for lev in f1t.getNonEmptyLevels()[1]:
2544 f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2545 f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2546 self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2554 def testNonRegBugNormalizeFamIdsMEDFile1(self):
2555 m=MEDCouplingCMesh()
2556 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2557 m.setCoords(arr,arr,arr)
2558 m=m.buildUnstructured()
2559 m2=m.buildDescendingConnectivity()[0]
2561 g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2562 g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2563 g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2564 g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2565 g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2566 g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2568 mm.setMeshAtLevel(0,m)
2569 mm.setGroupsAtLevel(0,[g1,g2])
2570 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2571 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2572 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2573 mm.normalizeFamIdsMEDFile()
2574 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2575 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2576 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2577 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2578 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2579 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2580 for g in mm.getGroupsOnSpecifiedLev(0):
2581 for f in mm.getFamiliesIdsOnGroup(g):
2582 self.assertTrue(f<0)
2587 mm.setMeshAtLevel(0,m)
2588 mm.setMeshAtLevel(-1,m2)
2589 mm.setGroupsAtLevel(0,[g1,g2])
2590 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2591 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2592 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
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 mm.normalizeFamIdsMEDFile()
2598 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2599 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2600 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2601 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2602 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2603 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2604 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2605 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2606 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2607 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2608 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2609 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2611 for g in mm.getGroupsOnSpecifiedLev(lev):
2612 for f in mm.getFamiliesIdsOnGroup(g):
2613 self.assertTrue(f<0)
2619 mm.setMeshAtLevel(0,m)
2620 mm.setMeshAtLevel(-1,m2)
2621 mm.setGroupsAtLevel(0,[g1,g2])
2622 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2623 mm.setGroupsAtLevel(1,[g1Node,g2Node])
2624 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2625 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2626 s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2627 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2628 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2629 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2630 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2631 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2632 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2633 mm.normalizeFamIdsMEDFile()
2634 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2635 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2636 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2637 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2638 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2639 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2640 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2641 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2642 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2643 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2644 self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2645 self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2646 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2647 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2648 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2649 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2650 self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2651 self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2653 for g in mm.getGroupsOnSpecifiedLev(lev):
2654 for f in mm.getFamiliesIdsOnGroup(g):
2655 self.assertTrue(f<0)
2659 for g in mm.getGroupsOnSpecifiedLev(1):
2660 for f in mm.getFamiliesIdsOnGroup(g):
2661 self.assertTrue(f>0)
2667 def testNonRegressionMantis22212ChangeGrpName(self):
2668 fileName="Pyfile62.med"
2669 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2670 m=MEDFileUMesh.New()
2671 m.setCoords(m2.getCoords())
2672 m.setMeshAtLevel(0,m2)
2673 m.setMeshAtLevel(-1,m1)
2674 m.setMeshAtLevel(-2,m0)
2675 m.setFamilyFieldArr(0,f2)
2676 m.setFamilyFieldArr(-1,f1)
2677 m.setFamilyFieldArr(-2,f0)
2678 m.setFamilyFieldArr(1,p)
2680 for i in range(nbOfFams):
2681 m.addFamily(fns[i],fids[i])
2684 for i in range(nbOfGrps):
2685 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2687 m.setName(m2.getName())
2688 m.setDescription(m2.getDescription())
2691 mm0=MEDFileMesh.New(fileName)
2692 mm1=MEDFileMesh.New(fileName)
2693 groupNamesIni=GetMeshGroupsNames(fileName,"ma")
2694 for name in groupNamesIni:
2695 mm1.changeGroupName(name,name+'N')
2697 mm1.write(fileName,2)
2700 mm2=MEDFileMesh.New(fileName)
2701 for name in groupNamesIni:
2702 for lev in mm0.getGrpNonEmptyLevelsExt(name):
2703 arr0=mm0.getGroupArr(lev,name)
2704 arr2=mm2.getGroupArr(lev,name+'N')
2705 arr0.setName(name+'N')
2706 self.assertTrue(arr0.isEqual(arr2))
2712 def testInt32InMEDFileFieldStar1(self):
2713 self.internalInt32InMEDFileFieldStar1()
2715 def internalInt32InMEDFileFieldStar1(self):
2716 fname="Pyfile63.med"
2717 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2718 f1=f1.convertToIntField()
2720 mm1=MEDFileUMesh.New()
2721 mm1.setCoords(m1.getCoords())
2722 mm1.setMeshAtLevel(0,m1)
2723 mm1.setName(m1.getName())
2725 ff1=MEDFileIntField1TS()
2726 ff1.setFieldNoProfileSBT(f1)
2727 a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2728 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2729 self.assertTrue(a.isEqual(f1,1e-12,0))
2731 a,b=ff1.getUndergroundDataArrayExt()
2732 self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
2733 self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
2734 ff2=MEDFileAnyTypeField1TS.New(fname)
2735 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2736 self.assertEqual(ff2.getTime(),[0,1,2.0])
2737 self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2738 a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2739 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2740 self.assertTrue(a.isEqual(f1,1e-12,0))
2742 c=ff2.getUndergroundDataArray() ; c*=2
2743 ff2.write(fname,0) # 2 time steps in
2744 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2745 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2746 self.assertEqual(len(ffs1),2)
2747 self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2748 a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2749 self.assertTrue(a.isEqual(f1,1e-12,0))
2750 a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
2751 self.assertTrue(a.isEqual(f1,1e-12,0))
2752 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2753 a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2754 self.assertTrue(a.getArray().isEqual(2*f1.getArray()))
2755 f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
2756 self.assertTrue(a.isEqual(f1,1e-12,0)) ; f1.getArray()[:]/=2
2757 bc=DataArrayInt32(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2759 a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2762 self.assertTrue(bc.isEqual(3*f1.getArray()))
2763 nf1=MEDCouplingFieldInt(ON_NODES)
2764 nf1.setTime(9.,10,-1)
2765 nf1.setMesh(f1.getMesh())
2766 narr=DataArrayInt32(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
2767 nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
2768 nff1=MEDFileIntField1TS.New()
2769 nff1.setFieldNoProfileSBT(nf1)
2770 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2771 self.assertEqual(nff1.getTime(),[10,-1,9.0])
2774 nf2=MEDCouplingFieldInt(ON_NODES)
2775 nf2.setTime(19.,20,-11)
2776 nf2.setMesh(f1.getMesh())
2777 narr2=DataArrayInt32(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
2778 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
2779 nff2=MEDFileIntField1TS.New()
2780 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
2781 nff2.setFieldProfile(nf2,mm1,0,npfl)
2782 nff2.getFieldWithProfile(ON_NODES,0,mm1)
2783 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2784 self.assertTrue(b.isEqual(npfl))
2785 self.assertTrue(a.isEqual(narr2))
2787 nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
2788 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
2789 self.assertTrue(b.isEqual(npfl))
2790 self.assertTrue(a.isEqual(narr2))
2792 nf3=MEDCouplingFieldDouble(ON_NODES)
2793 nf3.setName("VectorFieldOnNodesDouble")
2794 nf3.setTime(29.,30,-21)
2795 nf3.setMesh(f1.getMesh())
2796 nf3.setArray(f1.getMesh().getCoords())
2797 nff3=MEDFileField1TS.New()
2798 nff3.setFieldNoProfileSBT(nf3)
2800 fs=MEDFileFields(fname)
2801 self.assertEqual(len(fs),4)
2802 ffs=[it for it in fs]
2803 self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
2804 self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
2805 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
2806 self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
2808 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray()))
2809 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray()))
2810 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
2811 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
2812 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2814 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
2815 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
2816 self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
2817 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
2818 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
2819 self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
2820 MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
2821 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
2823 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
2824 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2825 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
2826 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
2830 def testMEDFileFields1(self):
2831 fname="Pyfile64.med"
2832 f1=MEDCouplingFieldDouble(ON_NODES)
2833 f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
2834 c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
2835 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
2837 arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=list(range(12)) ; arr[:,1]=2*arr[:,0]
2839 f1.setName("Field1")
2840 ff1=MEDFileField1TS.New()
2841 ff1.setFieldNoProfileSBT(f1)
2842 self.assertEqual(ff1.getDtUnit(),"us")
2844 f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2845 f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2847 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2848 ff1s=MEDFileFieldMultiTS(fname,"Field1")
2849 ff1s.setName("Field2")
2851 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
2852 f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2853 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
2854 self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
2855 self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
2856 f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
2857 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
2858 self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
2861 # Multi time steps and multi fields management without Globals (profiles, locs) aspects
2863 def testMEDFileFields2(self):
2864 fname="Pyfile65.med"
2865 # to check that all is initialize
2866 MEDFileField1TS().__str__()
2867 MEDFileFieldMultiTS().__str__()
2868 # building a mesh containing 4 tri3 + 5 quad4
2869 tri=MEDCouplingUMesh("tri",2)
2870 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2871 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2872 tris = [tri.deepCopy() for i in range(4)]
2873 for i,elt in enumerate(tris): elt.translate([i,0])
2874 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2875 quad=MEDCouplingUMesh("quad",2)
2876 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2877 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2878 quads = [quad.deepCopy() for i in range(5)]
2879 for i,elt in enumerate(quads): elt.translate([5+i,0])
2880 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2881 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2882 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2884 fmts0_0=MEDFileFieldMultiTS()
2885 fmts0_1=MEDFileFieldMultiTS()
2888 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2889 d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2890 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2891 f.setTime(float(i+1)+0.1,i+1,-i-1)
2892 fmts0_0.appendFieldNoProfileSBT(f)
2893 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
2894 self.assertEqual(fmts0_1.getName(),name1)
2895 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2896 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2898 # components names have been modified to generate errors
2899 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
2900 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
2901 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
2902 f1ts.setInfo(['aa [bb]','eee [dd]'])
2903 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
2905 # add a mismatch of nb of compos
2907 fmts0_2=fmts0_0.deepCopy()
2908 fmts0_3=fmts0_0.deepCopy()
2909 fmts0_4=fmts0_0.deepCopy()
2910 fmts0_5=fmts0_0.shallowCpy()
2911 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)
2913 self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
2914 del fmts0_3[[1.1,(6,-6),9]]
2915 self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
2916 fmts0_6=fmts0_4[[1.1,(6,-6),8]]
2917 self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
2918 self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
2919 fmts0_7=fmts0_4[::-3]
2920 self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
2921 self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
2924 fs0.pushField(fmts0_0)
2925 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2926 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2927 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2928 self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
2930 fs0=MEDFileFields(fname)
2931 self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
2932 fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
2933 self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2934 del fs1[["2ndField",3]]
2935 self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
2936 fs2=fs0[[0,"4thField"]]
2937 self.assertTrue(isinstance(fs2,MEDFileFields))
2938 self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
2940 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
2943 # Multi time steps and multi fields management with Globals (profiles, locs) aspects
2945 def testMEDFileFields3(self):
2946 fname="Pyfile66.med"
2947 # building a mesh containing 4 tri3 + 5 quad4
2948 tri=MEDCouplingUMesh("tri",2)
2949 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
2950 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
2951 tris = [tri.deepCopy() for i in range(4)]
2952 for i,elt in enumerate(tris): elt.translate([i,0])
2953 tris=MEDCouplingUMesh.MergeUMeshes(tris)
2954 quad=MEDCouplingUMesh("quad",2)
2955 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
2956 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
2957 quads = [quad.deepCopy() for i in range(5)]
2958 for i,elt in enumerate(quads): elt.translate([5+i,0])
2959 quads=MEDCouplingUMesh.MergeUMeshes(quads)
2960 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
2961 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
2963 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
2965 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
2966 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
2967 fmts0_0=MEDFileFieldMultiTS()
2968 fmts0_1=MEDFileFieldMultiTS()
2971 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2972 d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
2973 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
2974 f.setTime(float(i+1)+0.1,i+1,-i-1)
2975 fmts0_0.appendFieldProfile(f,mm,0,pfl)
2976 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
2977 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
2978 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
2981 self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
2982 self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
2983 fmts0_0.zipPflsNames()
2984 self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
2985 self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
2986 fmts0_2=fmts0_0.deepCopy()
2987 fmts0_3=fmts0_0.deepCopy()
2988 fmts0_4=fmts0_0.deepCopy()
2990 fs0.pushField(fmts0_0)
2991 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
2992 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
2993 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
2994 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
2996 fmts0_5=MEDFileFieldMultiTS()
2998 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
2999 d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
3000 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3001 f.setTime(float(i+1)+0.1,i+1,-i-1)
3002 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
3004 fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
3005 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
3006 fs0.checkGlobsCoherency()
3011 def testSplitComponents1(self):
3012 fname="Pyfile67.med"
3013 # building a mesh containing 4 tri3 + 5 quad4
3014 tri=MEDCouplingUMesh("tri",2)
3015 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3016 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3017 tris = [tri.deepCopy() for i in range(4)]
3018 for i,elt in enumerate(tris): elt.translate([i,0])
3019 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3020 quad=MEDCouplingUMesh("quad",2)
3021 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3022 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3023 quads = [quad.deepCopy() for i in range(5)]
3024 for i,elt in enumerate(quads): elt.translate([5+i,0])
3025 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3026 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3027 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3029 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3031 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3032 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
3034 fmts0_1=MEDFileFieldMultiTS()
3036 infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
3039 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
3040 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3041 f.setTime(float(i+1)+0.1,i+1,-i-1)
3042 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
3043 self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
3045 fs.pushField(fmts0_1)
3046 self.assertEqual(1,len(fs))
3047 l=fmts0_1.splitComponents()
3048 self.assertEqual(3,len(l))
3049 for elt in l: self.assertEqual(10,len(elt))
3050 for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
3052 elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
3055 self.assertEqual(4,len(fs))
3056 for elt in fs: self.assertEqual(10,len(elt))
3057 self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
3058 self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
3060 fs.write(fname,0) ; del fs
3062 fs1=MEDFileFields(fname)
3063 self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
3064 self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
3065 self.assertEqual(4,len(fs1))
3067 for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
3068 f1ts=fs1[fieldName][i]
3069 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
3070 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
3071 self.assertTrue(d.isEqual(f.getArray(),1e-13))
3073 f1ts=fs1["1stField"][i]
3074 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
3075 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
3076 self.assertTrue(d.isEqual(f.getArray(),1e-13))
3081 def testMEDFileFieldConvertTo1(self):
3082 fname="Pyfile68.med"
3083 # building a mesh containing 4 tri3 + 5 quad4
3084 tri=MEDCouplingUMesh("tri",2)
3085 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3086 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3087 tris = [tri.deepCopy() for i in range(4)]
3088 for i,elt in enumerate(tris): elt.translate([i,0])
3089 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3090 quad=MEDCouplingUMesh("quad",2)
3091 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3092 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3093 quads = [quad.deepCopy() for i in range(5)]
3094 for i,elt in enumerate(quads): elt.translate([5+i,0])
3095 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3096 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3097 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3098 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3100 ff0=MEDFileField1TS()
3101 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")
3102 f0.checkConsistencyLight()
3103 ff0.setFieldNoProfileSBT(f0)
3105 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
3106 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3108 ff0i=ff0.convertToInt()
3109 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3110 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3112 ff1=ff0i.convertToDouble()
3113 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3114 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3116 del arr,f0,ff0,ff1,ff0i,fspExp
3117 ff0=MEDFileField1TS()
3118 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")
3119 f0.checkConsistencyLight()
3120 pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
3121 ff0.setFieldProfile(f0,mm,0,pfl)
3122 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
3123 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3125 ff0i=ff0.convertToInt()
3126 self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
3127 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3128 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3130 ff1=ff0i.convertToDouble()
3131 self.assertTrue(isinstance(ff1,MEDFileField1TS))
3132 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3133 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3135 ff0=MEDFileFieldMultiTS()
3136 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)
3137 f0.checkConsistencyLight()
3138 ff0.appendFieldProfile(f0,mm,0,pfl)
3139 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)
3140 f0.checkConsistencyLight()
3141 ff0.appendFieldProfile(f0,mm,0,pfl)
3142 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)
3143 f0.checkConsistencyLight()
3144 ff0.appendFieldProfile(f0,mm,0,pfl)
3145 ff1=ff0.convertToInt()
3146 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3147 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3148 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3149 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3150 arr=ff1.getUndergroundDataArray(dt,it)
3151 arr.isEqualWithoutConsideringStr(DataArrayInt32.Range(delt,delt+7,1))
3153 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3158 ff1=ff1.convertToDouble()
3159 self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
3160 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3161 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3162 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3163 arr=ff1.getUndergroundDataArray(dt,it)
3164 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
3166 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3168 ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
3169 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3170 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3171 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3172 self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
3173 arr=ff1.getUndergroundDataArray(dt,it)
3174 arr.isEqualWithoutConsideringStr(DataArrayInt32.Range(delt,delt+7,1))
3176 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
3180 def testMEDFileFieldPartialLoading(self):
3181 fname="Pyfile69.med"
3183 a=DataArrayInt() ; aa=a.getHeapMemorySize()
3185 strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
3186 # building a mesh containing 30 tri3 + 40 quad4
3187 tri=MEDCouplingUMesh("tri",2)
3188 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3189 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3190 tris = [tri.deepCopy() for i in range(30)]
3191 for i,elt in enumerate(tris): elt.translate([i,0])
3192 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3193 quad=MEDCouplingUMesh("quad",2)
3194 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3195 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3196 quads = [quad.deepCopy() for i in range(40)]
3197 for i,elt in enumerate(quads): elt.translate([40+i,0])
3198 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3199 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3200 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3201 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3203 ff0=MEDFileField1TS()
3204 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")
3205 f0.checkConsistencyLight()
3206 ff0.setFieldNoProfileSBT(f0)
3209 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
3210 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3212 ff0=MEDFileField1TS()
3213 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")
3214 f0.checkConsistencyLight()
3215 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
3216 ff0.setFieldProfile(f0,mm,0,pfl)
3217 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
3218 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3221 ff0=MEDFileField1TS(fname,False)
3222 self.assertEqual(ff0.getName(),"FieldCell")
3223 self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
3224 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
3225 heap_memory_ref=ff0.getHeapMemorySize()
3226 self.assertIn(heap_memory_ref, list(range(182, 540 + 2 * strMulFac)))
3228 arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
3229 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3230 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
3232 ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
3233 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
3234 heap_memory_ref=ff0.getHeapMemorySize()
3235 self.assertIn(heap_memory_ref, list(range(350, 700 + 6 * strMulFac)))
3237 arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
3238 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3239 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3241 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3242 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3243 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3244 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3246 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3247 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3248 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3249 ff0.loadArraysIfNecessary() ##
3250 self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
3251 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3252 heap_memory_ref=ff0.getHeapMemorySize()
3253 self.assertIn(heap_memory_ref, list(range(1100, 1600 + 2 * strMulFac)))
3255 hmd=ff0.getHeapMemorySize()-heap_memory_ref
3256 self.assertEqual(hmd,-800) # -50*8*2
3258 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
3260 ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
3261 heap_memory_ref=ff0.getHeapMemorySize()
3262 self.assertIn(heap_memory_ref, list(range(299, 670 + 6 * strMulFac)))
3264 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3265 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3267 fieldName="FieldCellMultiTS"
3268 ff0=MEDFileFieldMultiTS()
3270 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)
3271 f0.setTime(float(t)+0.1,t,100+t)
3272 f0.checkConsistencyLight()
3273 ff0.appendFieldNoProfileSBT(f0)
3277 ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
3278 heap_memory_ref=ff0.getHeapMemorySize()
3279 self.assertIn(heap_memory_ref, range(5536, 9212 + (80 + 26 + 1) * strMulFac))
3281 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
3284 ffs=MEDFileFields(fname,False)
3285 heap_memory_ref=ffs.getHeapMemorySize()
3286 self.assertIn(heap_memory_ref, range(5335, 10331 + (80 + 50 + len(ffs)) * strMulFac))
3288 self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
3292 def testMEDFileMeshReadSelector1(self):
3293 mrs=MEDFileMeshReadSelector()
3294 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3295 mrs.__str__() ; mrs.__repr__()
3297 mrs=MEDFileMeshReadSelector(0)
3298 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())
3299 mrs=MEDFileMeshReadSelector(1)
3300 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3301 mrs=MEDFileMeshReadSelector(2)
3302 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3303 mrs=MEDFileMeshReadSelector(3)
3304 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3305 mrs=MEDFileMeshReadSelector(4)
3306 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3307 mrs=MEDFileMeshReadSelector(5)
3308 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3309 mrs=MEDFileMeshReadSelector(6)
3310 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3311 mrs=MEDFileMeshReadSelector(7)
3312 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3313 mrs=MEDFileMeshReadSelector(8)
3314 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3315 mrs=MEDFileMeshReadSelector(9)
3316 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3317 mrs=MEDFileMeshReadSelector(10)
3318 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3319 mrs=MEDFileMeshReadSelector(11)
3320 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3321 mrs=MEDFileMeshReadSelector(12)
3322 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3323 mrs=MEDFileMeshReadSelector(13)
3324 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3325 mrs=MEDFileMeshReadSelector(14)
3326 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3327 mrs=MEDFileMeshReadSelector(15)
3328 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3329 mrs=MEDFileMeshReadSelector(16)
3330 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3331 mrs=MEDFileMeshReadSelector(17)
3332 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3333 mrs=MEDFileMeshReadSelector(18)
3334 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3335 mrs=MEDFileMeshReadSelector(19)
3336 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3337 mrs=MEDFileMeshReadSelector(20)
3338 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3339 mrs=MEDFileMeshReadSelector(21)
3340 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3341 mrs=MEDFileMeshReadSelector(22)
3342 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3343 mrs=MEDFileMeshReadSelector(23)
3344 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3345 mrs=MEDFileMeshReadSelector(24)
3346 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3347 mrs=MEDFileMeshReadSelector(25)
3348 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3349 mrs=MEDFileMeshReadSelector(26)
3350 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3351 mrs=MEDFileMeshReadSelector(27)
3352 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3353 mrs=MEDFileMeshReadSelector(28)
3354 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3355 mrs=MEDFileMeshReadSelector(29)
3356 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3357 mrs=MEDFileMeshReadSelector(30)
3358 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3359 mrs=MEDFileMeshReadSelector(31)
3360 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3361 mrs=MEDFileMeshReadSelector(32)
3362 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3363 mrs=MEDFileMeshReadSelector(33)
3364 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3365 mrs=MEDFileMeshReadSelector(34)
3366 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3367 mrs=MEDFileMeshReadSelector(35)
3368 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3369 mrs=MEDFileMeshReadSelector(36)
3370 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3371 mrs=MEDFileMeshReadSelector(37)
3372 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3373 mrs=MEDFileMeshReadSelector(38)
3374 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3375 mrs=MEDFileMeshReadSelector(39)
3376 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3377 mrs=MEDFileMeshReadSelector(40)
3378 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3379 mrs=MEDFileMeshReadSelector(41)
3380 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3381 mrs=MEDFileMeshReadSelector(42)
3382 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3383 mrs=MEDFileMeshReadSelector(43)
3384 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3385 mrs=MEDFileMeshReadSelector(44)
3386 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3387 mrs=MEDFileMeshReadSelector(45)
3388 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3389 mrs=MEDFileMeshReadSelector(46)
3390 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3391 mrs=MEDFileMeshReadSelector(47)
3392 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3393 mrs=MEDFileMeshReadSelector(48)
3394 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3395 mrs=MEDFileMeshReadSelector(49)
3396 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3397 mrs=MEDFileMeshReadSelector(50)
3398 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3399 mrs=MEDFileMeshReadSelector(51)
3400 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3401 mrs=MEDFileMeshReadSelector(52)
3402 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3403 mrs=MEDFileMeshReadSelector(53)
3404 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3405 mrs=MEDFileMeshReadSelector(54)
3406 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3407 mrs=MEDFileMeshReadSelector(55)
3408 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3409 mrs=MEDFileMeshReadSelector(56)
3410 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3411 mrs=MEDFileMeshReadSelector(57)
3412 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3413 mrs=MEDFileMeshReadSelector(58)
3414 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3415 mrs=MEDFileMeshReadSelector(59)
3416 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3417 mrs=MEDFileMeshReadSelector(60)
3418 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3419 mrs=MEDFileMeshReadSelector(61)
3420 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3421 mrs=MEDFileMeshReadSelector(62)
3422 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3423 mrs=MEDFileMeshReadSelector(63)
3424 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3426 mrs=MEDFileMeshReadSelector(63)
3427 mrs.setCellFamilyFieldReading(False)
3428 self.assertEqual(mrs.getCode(),62)
3429 mrs.setCellFamilyFieldReading(True)
3430 self.assertEqual(mrs.getCode(),63)
3431 mrs.setNodeFamilyFieldReading(False)
3432 self.assertEqual(mrs.getCode(),61)
3433 mrs.setNodeFamilyFieldReading(True)
3434 self.assertEqual(mrs.getCode(),63)
3435 mrs.setCellNameFieldReading(False)
3436 self.assertEqual(mrs.getCode(),59)
3437 mrs.setCellNameFieldReading(True)
3438 self.assertEqual(mrs.getCode(),63)
3439 mrs.setNodeNameFieldReading(False)
3440 self.assertEqual(mrs.getCode(),55)
3441 mrs.setNodeNameFieldReading(True)
3442 self.assertEqual(mrs.getCode(),63)
3443 mrs.setCellNumFieldReading(False)
3444 self.assertEqual(mrs.getCode(),47)
3445 mrs.setCellNumFieldReading(True)
3446 self.assertEqual(mrs.getCode(),63)
3447 mrs.setNodeNumFieldReading(False)
3448 self.assertEqual(mrs.getCode(),31)
3449 mrs.setNodeNumFieldReading(True)
3450 self.assertEqual(mrs.getCode(),63)
3454 def testPartialReadOfMeshes(self):
3455 fname="Pyfile70.med"
3456 # building a mesh containing 4 tri3 + 5 quad4
3457 tri=MEDCouplingUMesh("tri",2)
3458 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3459 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3460 tris = [tri.deepCopy() for i in range(4)]
3461 for i,elt in enumerate(tris): elt.translate([i,0])
3462 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3463 quad=MEDCouplingUMesh("quad",2)
3464 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3465 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3466 quads = [quad.deepCopy() for i in range(5)]
3467 for i,elt in enumerate(quads): elt.translate([5+i,0])
3468 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3469 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3470 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3471 m1=m.buildDescendingConnectivity()[0]
3472 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3474 grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3475 grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3476 mm.setGroupsAtLevel(0,[grp0,grp1])
3477 grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3478 grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3479 mm.setGroupsAtLevel(-1,[grp2,grp3])
3480 grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3481 grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3482 mm.setGroupsAtLevel(1,[grp4,grp5])
3483 mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3484 mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3485 mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3489 mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3490 b4_ref_heap_mem=mm.getHeapMemorySize()
3491 mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
3492 mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
3493 ref_heap_mem=mm.getHeapMemorySize()
3494 # check the gain of memory using 1GTUMesh instead of UMesh
3495 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
3497 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3498 self.assertEqual(len(mm.getGroupsNames()),0)
3499 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3500 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3501 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3502 self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3503 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3504 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3505 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3506 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3507 delta1=ref_heap_mem-mm.getHeapMemorySize()
3508 self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3510 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3511 self.assertEqual(len(mm.getGroupsNames()),6)
3512 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3513 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3514 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3515 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3516 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3517 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3518 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3519 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3520 delta2=ref_heap_mem-mm.getHeapMemorySize()
3521 self.assertTrue(delta2<delta1)
3522 self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3524 mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3525 self.assertEqual(len(mm.getGroupsNames()),6)
3526 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3527 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3528 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3529 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3530 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3531 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3532 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3533 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3534 delta3=ref_heap_mem-mm.getHeapMemorySize()
3535 self.assertTrue(delta3<delta2)
3536 self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3538 mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3539 self.assertEqual(len(mm.getGroupsNames()),6)
3540 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3541 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3542 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3543 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3544 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3545 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3546 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3547 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3548 delta4=ref_heap_mem-mm.getHeapMemorySize()
3549 self.assertTrue(delta4<delta3)
3550 self.assertTrue(delta4>=32*4*2)
3552 mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3553 self.assertEqual(len(mm.getGroupsNames()),6)
3554 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3555 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3556 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3557 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3558 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3559 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3560 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3561 self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3562 delta5=ref_heap_mem-mm.getHeapMemorySize()
3563 self.assertTrue(delta5<delta4)
3564 self.assertEqual(delta5,0)
3567 # this test checks that setFieldProfile perform a check of the array length
3568 # compared to the profile length. This test also checks that mesh attribute of field
3569 # is not used by setFieldProfile (because across this test mesh is equal to None)
3571 def testCheckCompatibilityPfl1(self):
3572 # building a mesh containing 4 tri3 + 5 quad4
3573 tri=MEDCouplingUMesh("tri",2)
3574 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3575 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3576 tris = [tri.deepCopy() for i in range(4)]
3577 for i,elt in enumerate(tris): elt.translate([i,0])
3578 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3579 quad=MEDCouplingUMesh("quad",2)
3580 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3581 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3582 quads = [quad.deepCopy() for i in range(5)]
3583 for i,elt in enumerate(quads): elt.translate([5+i,0])
3584 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3585 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3586 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3587 m1=m.buildDescendingConnectivity()[0]
3588 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3590 f1ts=MEDFileField1TS()
3591 f=MEDCouplingFieldDouble(ON_NODES)
3592 vals=DataArrayDouble(7) ; vals.iota(1000)
3594 f.setName("anonymous") # f has no mesh it is not a bug
3595 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3596 f1ts.setFieldProfile(f,mm,0,pfl)
3598 f1ts=MEDFileField1TS()
3599 f=MEDCouplingFieldDouble(ON_NODES)
3600 vals=DataArrayDouble(8) ; vals.iota(1000)
3602 f.setName("anonymous") # f has no mesh it is not a bug
3603 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3604 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3606 f1ts=MEDFileField1TS()
3607 f=MEDCouplingFieldDouble(ON_CELLS)
3608 vals=DataArrayDouble(7) ; vals.iota(1000)
3610 f.setName("anonymous") # f has no mesh it is not a bug
3611 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3612 f1ts.setFieldProfile(f,mm,0,pfl)
3613 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3615 f1ts=MEDFileField1TS()
3616 f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3617 vals=DataArrayDouble(27) ; vals.iota(1000)
3619 f.setName("anonymous") # f has no mesh it is not a bug
3620 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3622 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])
3623 f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3624 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])
3626 f1ts.setFieldProfile(f,mm,0,pfl)
3627 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3628 vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3629 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3630 vals=DataArrayDouble(27) ; vals.iota(1000)
3631 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3633 f1ts=MEDFileField1TS()
3634 f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3635 vals=DataArrayDouble(25) ; vals.iota(1000)
3637 f.setName("anonymous") # f has no mesh it is not a bug
3638 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3639 f1ts.setFieldProfile(f,mm,0,pfl)
3640 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3641 vals2=DataArrayDouble(26) ; vals2.iota(1050)
3643 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3644 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3646 f1ts=MEDFileField1TS()
3647 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3648 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3650 f1ts.setFieldProfile(f,mm,0,pfl)
3654 def testWRMeshWithNoCells(self):
3655 fname="Pyfile71.med"
3656 a=DataArrayDouble(4) ; a.iota()
3657 c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
3658 m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
3660 m.setMeshAtLevel(0,m00)
3661 m.setRenumFieldArr(1,DataArrayInt(list(range(10,26))))
3662 m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
3666 m=MEDFileMesh.New(fname)
3667 self.assertEqual((),m.getNonEmptyLevels())
3668 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))
3669 self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(list(range(10,26)))))
3670 self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
3674 def testWRQPolyg1(self):
3675 fname="Pyfile72.med"
3676 m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
3677 m.insertNextCell([0,2,1,3])
3678 m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
3680 ms = [m.deepCopy() for i in range(4)]
3681 for i,elt in enumerate(ms):
3682 elt.translate([float(i)*1.5,0.])
3684 m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3685 m0.convertAllToPoly()
3687 ms = [m.deepCopy() for i in range(5)]
3688 for i,elt in enumerate(ms):
3689 elt.translate([float(i)*1.5,1.5])
3691 m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3692 m1.convertAllToPoly()
3693 m1.convertLinearCellsToQuadratic()
3695 m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
3698 mm.setMeshAtLevel(0,m)
3699 grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
3700 grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
3701 grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
3702 mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3707 mm_read=MEDFileUMesh(fname)
3708 self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
3709 self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
3710 self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
3711 self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
3713 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
3715 arr0=DataArrayDouble(9) ; arr0.iota()
3716 arr1=DataArrayDouble(9) ; arr1.iota(100)
3717 arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
3718 f.setArray(arr) ; f.checkConsistencyLight()
3720 ff=MEDFileField1TS()
3721 ff.setFieldNoProfileSBT(f)
3724 ff_read=MEDFileField1TS(fname)
3725 f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
3726 self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
3730 def testLoadIfNecessaryOnFromScratchFields0(self):
3732 This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
3734 fname="Pyfile77.med"
3735 coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
3736 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
3738 m.insertNextCell(NORM_QUAD4,[0,5,3,2])
3739 m.insertNextCell(NORM_QUAD4,[4,2,3,1])
3740 m.finishInsertingCells()
3742 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3743 ms=MEDFileMeshes() ; ms.pushMesh(mm)
3747 ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
3748 f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
3750 f0.setName("myELNOField")
3751 arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
3752 f0.setArray(arrs[0])
3753 ff0.appendFieldNoProfileSBT(f0)
3756 arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
3757 f0.setArray(arrs[1])
3758 ff0.appendFieldNoProfileSBT(f0)
3761 arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
3762 f0.setArray(arrs[2])
3763 ff0.appendFieldNoProfileSBT(f0)
3766 arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
3767 f0.setArray(arrs[3])
3768 ff0.appendFieldNoProfileSBT(f0)
3770 for i,arr in enumerate(arrs):
3771 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3772 fs[0][i].loadArraysIfNecessary()
3773 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3775 fs.loadArraysIfNecessary()
3776 for i,arr in enumerate(arrs):
3777 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3779 fs[0].loadArraysIfNecessary()
3780 for i,arr in enumerate(arrs):
3781 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
3786 def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
3787 """ 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.
3789 fname="Pyfile78.med"
3790 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)
3791 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3792 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
3794 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
3795 m0.insertNextCell(NORM_TETRA4,elt)
3797 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
3798 m0.insertNextCell(NORM_PYRA5,elt)
3800 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
3801 m0.insertNextCell(NORM_PENTA6,elt)
3803 m0.checkConsistency()
3804 m1=MEDCouplingUMesh(); m1.setName("mesh")
3805 m1.setMeshDimension(2);
3806 m1.allocateCells(5);
3807 m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3808 m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3809 m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3810 m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3811 m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3812 m1.setCoords(coords);
3813 m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
3815 m3.insertNextCell(NORM_POINT1,[2])
3816 m3.insertNextCell(NORM_POINT1,[3])
3817 m3.insertNextCell(NORM_POINT1,[4])
3818 m3.insertNextCell(NORM_POINT1,[5])
3821 mm.setMeshAtLevel(0,m0)
3822 mm.setMeshAtLevel(-1,m1)
3823 mm.setMeshAtLevel(-3,m3)
3825 #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
3826 mm=MEDFileMesh.New(fname)
3828 fmts=MEDFileFieldMultiTS()
3829 f1ts=MEDFileField1TS()
3830 for lev in mm.getNonEmptyLevels():
3831 for gt in mm.getGeoTypesAtLevel(lev):
3832 p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
3833 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
3834 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
3835 f.setArray(arr) ; f.setName("f0")
3836 f1ts.setFieldNoProfileSBT(f)
3839 self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
3840 for lev in [0,-1,-3]:
3841 mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
3843 fmts.pushBackTimeStep(f1ts)
3847 #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
3848 fs=MEDFileFields(fname)
3849 self.assertEqual(len(fs),1)
3850 self.assertEqual(len(fs[0]),1)
3852 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),'','')])])
3853 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))
3857 def testMEDFileUMeshSetName(self):
3858 """ 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.
3859 This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
3861 fname="Pyfile79.med"
3862 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
3864 m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
3865 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)
3866 m0.allocateCells(5);
3867 m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
3868 m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
3869 m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
3870 m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
3871 m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
3872 m0.setCoords(coords);
3873 mm.setMeshAtLevel(0,m0)
3874 m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
3876 m2.insertNextCell(NORM_POINT1,[2])
3877 m2.insertNextCell(NORM_POINT1,[3])
3878 m2.insertNextCell(NORM_POINT1,[4])
3879 m2.insertNextCell(NORM_POINT1,[5])
3880 mm.setMeshAtLevel(-2,m2)
3881 self.assertEqual(mm.getName(),"")
3882 self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
3883 mm.forceComputationOfParts()
3884 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
3886 self.assertEqual(mm.getName(),"abc")
3887 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
3888 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
3889 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
3890 self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
3894 def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
3895 fileName="Pyfile80.med"
3896 m=MEDCouplingCMesh() ; m.setName("cmesh")
3897 arr=DataArrayDouble(6) ; arr.iota()
3898 m.setCoords(arr,arr)
3899 nbCells=m.getNumberOfCells()
3900 self.assertEqual(25,nbCells)
3901 f=MEDCouplingFieldDouble(ON_CELLS)
3902 f.setName("FieldOnCell") ; f.setMesh(m)
3903 arr=DataArrayDouble(nbCells) ; arr.iota()
3907 fmts=MEDFileFieldMultiTS()
3909 for i in range(nbCells):
3910 t=(float(i)+0.1,i+1,-i-2)
3912 arr2=DataArrayDouble(nbCells)
3913 perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
3916 f1ts=MEDFileField1TS()
3917 f1ts.setFieldNoProfileSBT(f)
3918 fmts.pushBackTimeStep(f1ts)
3920 fmts.unloadArraysWithoutDataLoss()
3921 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))
3922 fs=MEDFileFields() ; fs.pushField(fmts)
3923 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))
3924 fs.unloadArraysWithoutDataLoss()
3925 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))
3927 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))
3928 f1ts.unloadArraysWithoutDataLoss()
3929 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))
3930 mm.write(fileName,2)
3931 fs.write(fileName,0)
3932 del m,fmts,mm,f,f1ts
3934 mm=MEDFileMesh.New(fileName)
3935 fmts=MEDFileFieldMultiTS(fileName)
3936 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 fmts.unloadArraysWithoutDataLoss()
3938 self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
3939 fmts.loadArraysIfNecessary()
3940 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))
3942 fs=MEDFileFields(fileName)
3943 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 fs.unloadArraysWithoutDataLoss()
3945 self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
3946 fs.loadArraysIfNecessary()
3947 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))
3949 f1ts=MEDFileField1TS(fileName)
3950 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))
3951 f1ts.unloadArraysWithoutDataLoss()
3952 self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
3953 f1ts.loadArraysIfNecessary()
3954 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))
3958 def testMEDFileUMeshLoadPart1(self):
3959 """ 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
3960 memory of the returned instance.
3962 fileName="Pyfile81.med"
3963 arr=DataArrayDouble(6) ; arr.iota()
3964 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
3965 m=m.buildUnstructured()
3967 m.changeSpaceDimension(3,0.)
3968 infos=["aa [b]","cc [de]","gg [klm]"]
3969 m.getCoords().setInfoOnComponents(infos)
3970 m.checkConsistency()
3972 mm.setMeshAtLevel(0,m)
3973 m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh")
3974 m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
3975 mm.setMeshAtLevel(-1,m1)
3976 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])
3977 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])
3978 namesCellL0=DataArrayAsciiChar(25,16)
3979 namesCellL0[:] = ["Cell#%.3d " % (i) for i in range(25)]
3980 renumM1=DataArrayInt([3,4,0,2,1])
3981 famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
3982 mm.setRenumFieldArr(0,renum0)
3983 mm.setFamilyFieldArr(0,famField0)
3984 mm.setNameFieldAtLevel(0,namesCellL0)
3985 mm.setRenumFieldArr(-1,renumM1)
3986 mm.setFamilyFieldArr(-1,famFieldM1)
3987 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])
3988 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])
3989 namesNodes=DataArrayAsciiChar(36,16)
3990 namesNodes[:] = ["Node#%.3d " % (i) for i in range(36)]
3991 mm.setRenumFieldArr(1,renum1)
3992 mm.setFamilyFieldArr(1,famField1)
3993 mm.setNameFieldAtLevel(1,namesNodes)
3994 mm.setFamilyId("Fam7",77)
3995 mm.setFamilyId("Fam8",88)
3996 mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
3997 mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
3998 mm.write(fileName,2)
4000 mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
4001 self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
4002 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])))
4003 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)
4004 self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
4005 self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
4006 self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
4007 self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
4008 self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
4009 self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
4010 self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
4012 mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
4013 self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
4014 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])))
4015 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)
4016 self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
4017 self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
4018 self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
4019 self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
4020 self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
4021 self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
4022 self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
4024 mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
4025 self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
4026 self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
4027 self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
4028 self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
4029 self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
4030 self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
4031 self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
4032 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])))
4033 self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
4034 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)
4035 self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
4036 self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
4037 self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
4038 self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
4042 def testMEDFileFieldsLoadPart1(self):
4043 """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
4045 fileName="Pyfile82.med"
4047 compos=["aa [kg]","bbb [m/s]"]
4048 arr=DataArrayDouble(6) ; arr.iota()
4049 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4050 m=m.buildUnstructured()
4052 m.changeSpaceDimension(3,0.)
4053 infos=["aa [b]","cc [de]","gg [klm]"]
4054 m.getCoords().setInfoOnComponents(infos)
4055 m.checkConsistency()
4056 f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4058 arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4059 arr[:,0]=list(range(25))
4060 arr[:,1]=list(range(100,125))
4062 WriteField(fileName,f,True)
4063 f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4064 f.setName("FieldNode")
4065 arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4066 arr[:,0]=list(range(200,236))
4067 arr[:,1]=list(range(300,336))
4069 f.checkConsistencyLight()
4070 WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4073 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
4075 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4076 self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
4079 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
4081 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4083 fs[0][0].loadArrays()
4084 arr = DataArrayDouble(12, 2) ; arr[:, 0] = list(range(3, 15)) ; arr[:, 1] = list(range(103, 115))
4085 arr.setInfoOnComponents(compos)
4086 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4087 fs[1][0].loadArrays()
4088 arr = DataArrayDouble(21, 2) ; arr[:, 0] = list(range(203, 224)) ; arr[:, 1] = list(range(303, 324))
4089 arr.setInfoOnComponents(compos)
4090 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4094 def testMEDFileWithoutCells1(self):
4095 fileName="Pyfile83.med"
4096 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4097 coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
4101 mm.write(fileName,2)
4103 mm=MEDFileMesh.New(fileName)
4104 self.assertEqual(mm.getName(),"mesh")
4105 self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
4109 def testZipCoordsWithLoadPart1(self):
4110 """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
4112 fileName="Pyfile84.med"
4114 compos=["aa [kg]","bbb [m/s]"]
4115 arr=DataArrayDouble(6) ; arr.iota()
4116 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4117 m=m.buildUnstructured()
4119 m.changeSpaceDimension(3,0.)
4120 infos=["aa [b]","cc [de]","gg [klm]"]
4121 m.getCoords().setInfoOnComponents(infos)
4122 m.checkConsistency()
4123 f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4125 arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4126 arr[:,0]=list(range(25))
4127 arr[:,1]=list(range(100,125))
4129 WriteField(fileName,f,True)
4130 f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4131 f.setName("FieldNode")
4132 arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4133 arr[:,0]=list(range(200,236))
4134 arr[:,1]=list(range(300,336))
4136 f.checkConsistencyLight()
4137 WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4140 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
4142 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4143 self.assertEqual(spd.getSlice(),slice(4,6,1))
4144 spd=mm.getPartDefAtLevel(1)
4145 self.assertEqual(spd.getSlice(),slice(4,14,1))
4146 self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4147 mm.zipCoords() # <- The important line is here !
4148 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4149 self.assertEqual(spd.getSlice(),slice(4,6,1))
4150 spd=mm.getPartDefAtLevel(1)
4151 self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4152 self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
4153 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4154 fs[0][0].loadArrays()
4155 arr=DataArrayDouble([(4,104),(5,105)])
4156 arr.setInfoOnComponents(compos)
4157 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4158 fs[1][0].loadArrays()
4159 arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
4160 arr.setInfoOnComponents(compos)
4161 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4165 def testMEDFileCMeshSetGroupsAtLevel(self):
4166 """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
4168 m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
4170 mm=MEDFileCMesh() ; mm.setMesh(m)
4171 grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
4172 mm.setGroupsAtLevel(0,[grp])
4173 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
4177 def testMEDFileUMeshBuildExtrudedMesh1(self):
4178 """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
4179 fileName="Pyfile85.med"
4182 meshName3DOut="Mesh3D"
4184 d1=DataArrayInt([0,4,20,24])
4185 d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
4187 a=DataArrayDouble(6) ; a.iota()
4188 m=MEDCouplingCMesh() ; m.setCoords(a,a)
4189 m=m.buildUnstructured()
4190 d1c=d1.buildComplement(m.getNumberOfCells())
4191 m=m[d1c] ; m.zipCoords()
4192 m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
4194 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
4195 m.setName(meshName2D)
4196 mMinus1,a,b,c,d=m.buildDescendingConnectivity()
4197 e=d.deltaShiftIndex().findIdsEqual(1)
4200 mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
4201 grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
4202 mm.setGroupsAtLevel(0,[grp0])
4203 grp1=e ; grp1.setName("grp1")
4204 mm.setGroupsAtLevel(-1,[grp1])
4205 mm.write(fileName,2)
4207 a=DataArrayDouble(3) ; a.iota()
4208 tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
4209 tmp.setName(meshName1D)
4210 tmp.changeSpaceDimension(3)
4211 tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
4213 mm1D.setMeshAtLevel(0,tmp)
4214 mm1D.write(fileName,0)
4216 mm2D=MEDFileMesh.New(fileName,meshName2D)
4217 mm1D=MEDFileMesh.New(fileName,meshName1D)
4218 m1D=mm1D.getMeshAtLevel(0)
4219 mm3D=mm2D.buildExtrudedMesh(m1D,0)
4221 self.assertEqual(mm3D.getName(),mm2D.getName())
4222 self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
4223 self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
4224 self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
4225 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
4226 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
4227 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
4228 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
4229 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
4230 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
4231 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.)])
4232 self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
4233 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])
4234 self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
4235 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])
4236 self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
4237 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])
4238 self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
4239 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])
4240 self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
4241 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])
4242 self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
4243 d=DataArrayInt(129) ; d.iota() ; d*=3
4244 self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
4246 self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
4247 self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
4248 self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
4249 self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
4250 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])))
4251 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])))
4252 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])))
4253 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])))
4254 mm3D.setName("MeshExtruded")
4255 mm3D.write(fileName,0)
4258 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4260 def testMEDFileUMeshPickeling1(self):
4261 outFileName="Pyfile86.med"
4262 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)
4263 c.setInfoOnComponents(["aa","bbb"])
4264 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
4265 m=MEDCouplingUMesh();
4266 m.setMeshDimension(2);
4268 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
4269 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
4270 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
4271 m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
4272 m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
4273 m.finishInsertingCells();
4275 m.checkConsistencyLight()
4276 m1=MEDCouplingUMesh.New();
4277 m1.setMeshDimension(1);
4278 m1.allocateCells(3);
4279 m1.insertNextCell(NORM_SEG2,2,[1,4])
4280 m1.insertNextCell(NORM_SEG2,2,[3,6])
4281 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
4282 m1.finishInsertingCells();
4284 m1.checkConsistencyLight()
4285 m2=MEDCouplingUMesh.New();
4286 m2.setMeshDimension(0);
4287 m2.allocateCells(4);
4288 m2.insertNextCell(NORM_POINT1,1,[1])
4289 m2.insertNextCell(NORM_POINT1,1,[3])
4290 m2.insertNextCell(NORM_POINT1,1,[2])
4291 m2.insertNextCell(NORM_POINT1,1,[6])
4292 m2.finishInsertingCells();
4294 m2.checkConsistencyLight()
4296 mm=MEDFileUMesh.New()
4297 self.assertTrue(mm.getUnivNameWrStatus())
4298 mm.setName("MyFirstMEDCouplingMEDmesh")
4299 mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
4303 mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
4305 mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
4306 # playing with groups
4307 g1_2=DataArrayInt.New()
4308 g1_2.setValues([1,3],2,1)
4310 g2_2=DataArrayInt.New()
4311 g2_2.setValues([1,2,3],3,1)
4313 mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
4314 g1_1=DataArrayInt.New()
4315 g1_1.setValues([0,1,2],3,1)
4317 g2_1=DataArrayInt.New()
4318 g2_1.setValues([0,2],2,1)
4320 mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
4321 g1_N=DataArrayInt.New()
4322 g1_N.setValues(list(range(8)),8,1)
4324 g2_N=DataArrayInt.New()
4325 g2_N.setValues(list(range(9)),9,1)
4327 mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
4328 mm.createGroupOnAll(0,"GrpOnAllCell")
4329 # check content of mm
4330 t=mm.getGroupArr(0,"G1",False)
4331 self.assertTrue(g1_2.isEqual(t));
4332 t=mm.getGroupArr(0,"G2",False)
4333 self.assertTrue(g2_2.isEqual(t));
4334 t=mm.getGroupArr(-1,"G1",False)
4335 self.assertTrue(g1_1.isEqual(t));
4336 t=mm.getGroupArr(-1,"G2",False)
4337 self.assertTrue(g2_1.isEqual(t));
4338 t=mm.getGroupArr(1,"G1",False)
4339 self.assertTrue(g1_N.isEqual(t));
4340 t=mm.getGroupArr(1,"G2",False)
4341 self.assertTrue(g2_N.isEqual(t));
4342 self.assertTrue(mm.existsGroup("GrpOnAllCell"));
4343 t=mm.getGroupArr(0,"GrpOnAllCell")
4345 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4346 mm2=pickle.loads(st)
4347 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4348 self.assertEqual(mm.getAxisType(),AX_CART)
4350 mm.setAxisType(AX_CYL)
4351 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4352 mm2=pickle.loads(st)
4353 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4354 self.assertEqual(mm2.getAxisType(),AX_CYL)
4358 def testMEDFileFieldsLoadSpecificEntities1(self):
4361 fileName="Pyfile87.med"
4365 m=MEDCouplingCMesh()
4366 arr=DataArrayDouble(nbNodes) ; arr.iota()
4368 m=m.buildUnstructured()
4371 fmts=MEDFileFieldMultiTS()
4372 for i in range(nbPdt):
4373 f=MEDCouplingFieldDouble(ON_NODES)
4375 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4377 f.setName(fieldName)
4378 f.setTime(float(i),i,0)
4379 fmts.appendFieldNoProfileSBT(f)
4382 mm=MEDFileUMesh() ; mm[0]=m
4383 fmts.write(fileName,2)
4384 mm.write(fileName,0)
4386 fs=MEDFileFields(fileName,False)
4387 fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
4388 fs.loadArraysIfNecessary()
4389 fs2.loadArraysIfNecessary()
4390 for i in range(nbPdt):
4391 self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4393 m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
4394 m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
4395 m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
4396 fmts=MEDFileFieldMultiTS()
4397 for i in range(nbPdt):
4398 f=MEDCouplingFieldDouble(ON_CELLS)
4400 arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
4402 f.setName(fieldName)
4403 f.setTime(float(i),i,0)
4404 fmts.appendFieldNoProfileSBT(f)
4406 mm=MEDFileUMesh() ; mm[0]=m3
4408 self.assertEqual(mm.getNonEmptyLevels(),())
4410 self.assertEqual(mm.getNonEmptyLevels(),(0,))
4411 fmts.write(fileName,2)
4412 fs=MEDFileFields(fileName,False)
4413 fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
4414 fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
4415 fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
4416 fs.loadArraysIfNecessary()
4417 fs2.loadArraysIfNecessary()
4418 fs3.loadArraysIfNecessary()
4419 fs4.loadArraysIfNecessary()
4420 for i in range(nbPdt):
4421 self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4422 self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
4423 self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
4428 def testMEDFileLotsOfTSRW1(self):
4431 fileName="Pyfile88.med"
4432 nbPdt=300 # <- perftest = 30000
4435 maxPdt=100 # <- optimum = 500
4436 m=MEDCouplingCMesh()
4437 arr=DataArrayDouble(nbNodes) ; arr.iota()
4439 m=m.buildUnstructured()
4442 nbOfField=nbPdt//maxPdt
4444 for j in range(nbOfField):
4445 fmts=MEDFileFieldMultiTS()
4446 s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
4447 for i in range(s.start, s.stop, s.step):
4448 f=MEDCouplingFieldDouble(ON_NODES)
4450 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4452 f.setName("%s_%d"%(fieldName,j))
4453 f.setTime(float(i),i,0)
4454 fmts.appendFieldNoProfileSBT(f)
4459 mm=MEDFileUMesh() ; mm[0]=m
4460 fs.write(fileName,2)
4461 mm.write(fileName,0)
4463 def appendInDict(d,key,val):
4470 allFields=GetAllFieldNames(fileName)
4472 pat=re.compile("([\d]+)([\s\S]+)$")
4473 for st in allFields:
4477 appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
4480 appendInDict(allFieldsDict,st,'')
4484 for k in allFieldsDict:
4485 if allFieldsDict[k]!=['']:
4486 allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
4489 for it in allFieldsDict[k]:
4490 fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
4495 for ii in range(nbIter):
4496 zeResu.pushBackTimeSteps(fmts2.pop())
4499 fs2.pushField(zeResu)
4501 self.assertEqual(fs2[0].getTimeSteps(), [(i, 0, float(i)) for i in range(nbPdt)])
4505 def testMEDFileMeshRearrangeFamIds1(self):
4506 """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
4507 fileName="Pyfile89.med"
4508 meshName='Maillage_2'
4510 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)])
4512 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])
4513 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])
4514 m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
4515 m0.setConnectivity(c0,c0i)
4518 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])
4519 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])
4520 m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
4521 m1.setConnectivity(c1,c1i)
4524 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])
4525 m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4526 m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
4527 mm[-2]=m2.buildUnstructured()
4529 ref0=DataArrayInt(55) ; ref0[:]=0
4530 mm.setFamilyFieldArr(0,ref0)
4531 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]))
4532 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])
4533 mm.setFamilyFieldArr(-1,ref1)
4534 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])
4535 mm.setFamilyFieldArr(-2,ref2)
4537 for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
4538 mm.setFamilyId(f,fid)
4539 for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
4540 mm.setFamiliesOnGroup(grp,fams)
4541 mm.write(fileName,2)
4543 mm=MEDFileMesh.New(fileName)
4544 grp=mm.getGroup(-1,"Groupe_1")
4545 dai=grp.computeFetchedNodeIds()
4548 mm.rearrangeFamilies() # <- the aim of the test
4549 self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
4550 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
4551 self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
4552 self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
4553 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])))
4554 allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
4555 allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
4556 self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
4557 for elt,fams in allGrps:
4558 self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
4559 self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
4560 for elt,eltId in allFams:
4561 self.assertEqual(mm.getFamilyId(elt),eltId)
4565 def testNonRegrCMeshSetFieldPfl1(self):
4566 """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
4567 ff=MEDFileField1TS()
4570 m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4574 field=MEDCouplingFieldDouble(ON_CELLS)
4576 field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4577 field.setName("Field")
4578 field.checkConsistencyLight()
4579 pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
4580 ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
4581 self.assertEqual(ff.getPfls(),())
4582 field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4583 self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4584 del ff,mm,field,field2,pfl
4585 # same with unstructured mesh
4586 ff=MEDFileField1TS()
4589 m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4592 m=m.buildUnstructured()
4594 field=MEDCouplingFieldDouble(ON_CELLS)
4596 field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4597 field.setName("Field")
4598 field.checkConsistencyLight()
4599 pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
4600 ff.setFieldProfile(field,mm,0,pfl)
4601 self.assertEqual(ff.getPfls(),())
4602 field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4603 self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4607 def testMEDFileUMeshLinearToQuadraticAndRev1(self):
4609 fileName="Pyfile90.med"
4610 fileName2="Pyfile91.med"
4611 arr=DataArrayDouble(5) ; arr.iota()
4612 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4613 m=m.buildUnstructured()
4614 d=DataArrayInt([3,7,11,15])
4617 m2=m[d.buildComplement(m.getNumberOfCells())]
4618 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
4619 m.changeSpaceDimension(3,0.)
4620 arr=DataArrayDouble(3) ; arr.iota()
4621 m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
4622 m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
4623 delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
4624 m3D=m.buildExtrudedMesh(m1D,0)
4625 m3D.sortCellsInMEDFileFrmt()
4626 m3D.setName(meshName)
4627 m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkConsistency()
4628 m1D=m2D.computeSkin() ; m1D.setName(meshName)
4629 m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
4632 mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
4633 grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
4634 grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
4635 grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
4636 grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
4637 diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
4638 vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
4639 vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
4640 mm.setGroupsAtLevel(0,[vol1,vol2])
4641 mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
4642 mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
4644 mmOut1=mm.linearToQuadratic(0,0.)
4645 mmOut1.write(fileName2,2)
4646 mmOut2=mmOut1.quadraticToLinear(0.)
4647 self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
4651 def testMEDFileMeshAddGroup1(self):
4652 m=MEDCouplingCMesh()
4653 arrX=DataArrayDouble(9) ; arrX.iota()
4654 arrY=DataArrayDouble(4) ; arrY.iota()
4655 m.setCoords(arrX,arrY)
4659 grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
4661 grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
4663 grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
4665 grp3=DataArrayInt([23]) ; grp3.setName("grp3")
4667 for grp in [grp0,grp1,grp2,grp3]:
4668 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4669 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
4671 for grp in [grp0,grp1,grp2,grp3]:
4672 grpNode=grp.deepCopy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
4673 mm.addGroup(1,grpNode)
4674 self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
4675 for grp in [grp0,grp1,grp2,grp3]:
4676 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4677 for grp in [grp0,grp1,grp2,grp3]:
4678 grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4679 self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4680 mm.normalizeFamIdsMEDFile()
4681 for grp in [grp0,grp1,grp2,grp3]:
4682 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4683 for grp in [grp0,grp1,grp2,grp3]:
4684 grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4685 self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4689 def testMEDFileJoint1(self):
4690 fileName="Pyfile92.med"
4691 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4692 coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4696 mm.setDescription("un maillage")
4697 mm.write(fileName,2)
4698 node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4699 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4700 one_step_joint=MEDFileJointOneStep()
4701 one_step_joint.pushCorrespondence(cell_correspond)
4702 one_step_joint.pushCorrespondence(node_correspond)
4703 one_joint=MEDFileJoint()
4704 one_joint.pushStep(one_step_joint)
4705 one_joint.setLocalMeshName("maa1")
4706 one_joint.setRemoteMeshName("maa1")
4707 one_joint.setDescription("joint_description")
4708 one_joint.setJointName("joint_1")
4709 one_joint.setDomainNumber(1)
4710 self.assertEqual( one_joint.getLocalMeshName(), "maa1")
4711 self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
4712 self.assertEqual( one_joint.getDescription(), "joint_description")
4713 self.assertEqual( one_joint.getJointName(), "joint_1")
4714 self.assertEqual( one_joint.getDomainNumber(), 1)
4715 joints=MEDFileJoints()
4716 joints.pushJoint(one_joint);
4717 joints.write(fileName,0)
4719 jointsR=MEDFileJoints(fileName,mm.getName())
4720 self.assertEqual( jointsR.getNumberOfJoints(), 1 )
4721 jR = jointsR.getJointAtPos(0)
4722 self.assertTrue( jR.isEqual( one_joint ))
4723 self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
4724 self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
4725 jointsR.destroyJointAtPos(0)
4729 def testMEDFileJoint2(self):
4730 fileNameWr="Pyfile93.med"
4731 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4732 coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4736 mm.setDescription("un maillage")
4737 node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
4738 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
4739 one_step_joint=MEDFileJointOneStep()
4740 two_step_joint=MEDFileJointOneStep()
4741 one_joint=MEDFileJoint()
4742 two_joint=MEDFileJoint()
4743 one_step_joint.pushCorrespondence(node_correspond)
4744 one_joint.pushStep(one_step_joint)
4745 two_step_joint.pushCorrespondence(cell_correspond)
4746 two_step_joint.pushCorrespondence(node_correspond)
4747 two_joint.pushStep(two_step_joint)
4748 one_joint.setLocalMeshName("maa1")
4749 one_joint.setRemoteMeshName("maa1")
4750 one_joint.setDescription("joint_description_1")
4751 one_joint.setJointName("joint_1")
4752 one_joint.setDomainNumber(1)
4753 two_joint.setLocalMeshName("maa1")
4754 two_joint.setRemoteMeshName("maa1")
4755 two_joint.setDescription("joint_description_2")
4756 two_joint.setJointName("joint_2")
4757 two_joint.setDomainNumber(2)
4758 joints=MEDFileJoints()
4759 joints.pushJoint(one_joint)
4760 joints.pushJoint(two_joint)
4761 mm.setJoints( joints )
4762 mm.write(fileNameWr,2)
4764 mm=MEDFileMesh.New(fileNameWr)
4765 self.assertEqual( mm.getNumberOfJoints(), 2)
4766 jointsR = mm.getJoints();
4767 self.assertEqual( jointsR.getMeshName(), mm.getName() )
4768 self.assertEqual( len( jointsR ), 2 )
4769 jointR1 = jointsR[0]
4770 jointR2 = jointsR[1]
4771 self.assertFalse( jointR1 is None )
4772 self.assertFalse( jointR2 is None )
4773 self.assertTrue( jointR1.isEqual( one_joint ))
4774 self.assertTrue( jointR2.isEqual( two_joint ))
4778 def testMEDFileJoint1(self):
4779 node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4780 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4781 cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
4782 cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
4783 joint1st_1=MEDFileJointOneStep()
4784 joint1st_1.pushCorrespondence(cell_correspond)
4785 joint1st_1.pushCorrespondence(node_correspond)
4786 joint1st_2=MEDFileJointOneStep()
4787 joint1st_2.pushCorrespondence(cell_correspond)
4788 joint1st_2.pushCorrespondence(node_correspond)
4789 joint1st_3=MEDFileJointOneStep()
4790 joint1st_3.pushCorrespondence(node_correspond)
4791 joint1st_3.pushCorrespondence(cell_correspond)
4792 joint1st_4=MEDFileJointOneStep()
4793 joint1st_4.pushCorrespondence(cell_correspond)
4794 joint1st_5=MEDFileJointOneStep()
4795 joint1st_5.pushCorrespondence(cell_correspon2)
4796 joint1st_6=MEDFileJointOneStep()
4797 joint1st_6.pushCorrespondence(cell_correspon3)
4798 self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
4799 self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
4800 self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
4801 self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
4802 self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
4803 one_joint=MEDFileJoint()
4804 one_joint.pushStep(joint1st_1)
4805 one_joint.setLocalMeshName("maa1")
4806 one_joint.setRemoteMeshName("maa2")
4807 one_joint.setDescription("joint_description")
4808 one_joint.setJointName("joint_1")
4809 one_joint.setDomainNumber(1)
4810 self.assertEqual( "maa1", one_joint.getLocalMeshName())
4811 self.assertEqual( "maa2", one_joint.getRemoteMeshName())
4812 self.assertEqual( "joint_description", one_joint.getDescription())
4813 self.assertEqual( 1, one_joint.getDomainNumber())
4814 self.assertEqual( "joint_1", one_joint.getJointName())
4817 @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
4819 def testMEDFileSafeCall0(self):
4820 """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
4821 fname="Pyfile94.med"
4822 errfname="Pyfile94.err"
4825 # first clean file if needed
4826 if os.path.exists(fname):
4829 # second : build a file from scratch
4830 m=MEDCouplingCMesh()
4831 arr=DataArrayDouble(11) ; arr.iota()
4832 m.setCoords(arr,arr)
4837 # third : change permissions to remove write access on created file
4838 os.chmod(fname, 0o444)
4839 # four : try to append data on file -> check that it raises Exception
4840 f=MEDCouplingFieldDouble(ON_CELLS)
4843 f.setArray(DataArrayDouble(100))
4844 f.getArray()[:]=100.
4845 f.checkConsistencyLight()
4846 f1ts=MEDFileField1TS()
4847 f1ts.setFieldNoProfileSBT(f)
4849 tmp=StdOutRedirect(errfname)
4850 self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
4853 if os.path.exists(errfname):
4859 def testUnivStatus1(self):
4860 """ Non regression test to check the effectiveness of univ write status."""
4861 fname="Pyfile95.med"
4862 arr=DataArrayDouble(10) ; arr.iota()
4863 m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
4864 mm=MEDFileCMesh() ; mm.setMesh(m)
4865 mm.setUnivNameWrStatus(False) # test is here
4867 mm=MEDFileCMesh(fname)
4868 self.assertEqual(mm.getUnivName(),"")
4869 mm.setUnivNameWrStatus(True)
4871 mm=MEDFileCMesh(fname)
4872 self.assertTrue(mm.getUnivName()!="")
4876 def testEmptyMesh(self):
4877 """ MEDLoader should be able to consistently write and read an empty mesh (coords array
4879 fname = "Pyfile96.med"
4880 m = MEDCouplingUMesh('toto', 2)
4881 m.setCoords(DataArrayDouble([], 0, 2))
4882 m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
4883 mfu = MEDFileUMesh()
4884 mfu.setMeshAtLevel(0, m)
4886 mfu2 = MEDFileUMesh(fname)
4887 self.assertEqual('toto', mfu2.getName())
4888 lvl = mfu2.getNonEmptyLevels()
4889 self.assertEqual((), lvl)
4891 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4892 def testMEDFileUMeshPickeling2(self):
4893 """ Check that pickalization can be performed on a unpickalized instance. Non regression test."""
4899 arr=DataArrayDouble(nbOfNodesPerAxis) ; arr.iota() ; arr/=(nbOfNodesPerAxis-1) ; arr*=hauteur
4900 m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured() ; m.setName(name)
4901 mesh=MEDFileUMesh() ; mesh[0]=m
4902 m1=m.computeSkin() ; mesh[-1]=m1
4904 bary1=m1.computeCellCenterOfMass()[:,2]
4905 grp1=bary1.findIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
4906 grp2=bary1.findIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
4907 mesh.setGroupsAtLevel(-1,[grp1,grp2])
4909 st=pickle.dumps(mesh,2)
4911 st2=pickle.dumps(mm,2)
4912 mm2=pickle.loads(st2)
4913 self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
4917 def testMEDFileEquivalence1(self):
4918 """ First check of equivalence implementation in MEDFileMesh"""
4919 fileName="Pyfile97.med"
4922 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)])
4923 coo.setInfoOnComponents(["X [Sans_unite]","Y [Sans_unite]","Z [Sans_unite]"])
4924 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])
4925 m1=MEDCoupling1SGTUMesh(meshName,NORM_QUAD4) ; m1.setCoords(coo) ; m1.setNodalConnectivity(connQ4) ; mm[-1]=m1
4926 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])
4927 m0=MEDCoupling1SGTUMesh(meshName,NORM_HEXA8) ; m0.setCoords(coo) ; m0.setNodalConnectivity(connH8) ; mm[0]=m0
4928 mm.getFamilyFieldAtLevel(-1)[:]=-2
4929 mm.getFamilyFieldAtLevel(0)[:]=0
4930 mm.addFamily("HOMARD________-1",-1)
4931 mm.addFamily("HOMARD________-2",-2)
4932 mm.addFamily("HOMARD________-3",-3)
4933 mm.setFamiliesIdsOnGroup("HOMARD",[-1,-2,-3])
4935 eqName="MAILLES_A_RECOLLER_APRES_HOMARD"
4936 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."
4937 mm.initializeEquivalences()
4938 eqs=mm.getEquivalences()
4939 eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4940 eq0.setDescription(descEq)
4941 corr=DataArrayInt32([(0,3),(0,4),(0,5),(0,6),(1,7),(1,8),(1,9),(1,10),(2,11),(2,12),(2,13),(2,14)])
4942 eq0.setArray(-1,corr)
4943 self.assertEqual(eq0.getCell().size(),1)
4944 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4945 eq0.getCell().clear()
4946 self.assertEqual(eq0.getCell().size(),0)
4947 eq0.getCell().setArrayForType(NORM_QUAD4,corr)
4948 self.assertEqual(eq0.getCell().size(),1)
4949 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4950 mm.killEquivalences()
4951 mm.initializeEquivalences()
4952 eqs=mm.getEquivalences()
4953 eq0=eqs.appendEmptyEquivalenceWithName(eqName)
4954 eq0.setDescription(descEq)
4956 c.setArrayForType(NORM_QUAD4,corr)
4957 self.assertEqual(eq0.getCell().size(),1)
4958 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
4960 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4961 self.assertEqual(mm2.getEquivalences().size(),1)
4962 self.assertTrue(mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4).isEqual(corr))
4963 mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=2
4964 self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
4965 mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=0
4966 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4967 mm.write(fileName,2)
4969 mm3=MEDFileMesh.New(fileName)
4970 self.assertTrue(mm.isEqual(mm3,1e-12)[0])
4974 def testMEDFileForFamiliesPlayer1(self):
4975 """Non regression bug EDF11911. For serial killers using same family name to store both cells and nodes ! Only sky is the limit."""
4976 fileName="Pyfile98.med"
4978 magicSt="%s%%04i"%(MEDFileMesh.GetMagicFamilyStr())
4979 arr=DataArrayDouble(4) ; arr.iota()
4980 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4981 m=m.buildUnstructured()
4984 mm.setName(meshName)
4985 mm.setFamilyId("FAMILLE_ZERO",0)
4986 mm.getFamilyFieldAtLevel(0)[-3:]=-4
4987 mm.setFamilyId("RIDF%s"%(magicSt%0),-4)
4988 mm.setGroupsOnFamily("RIDF%s"%(magicSt%0),["RID"])
4989 d=DataArrayInt(16) ; d[:]=0 ; d[[1,2,4,5]]=3
4990 mm.setFamilyFieldArr(1,d)
4991 mm.setFamilyId("RIDF%s"%(magicSt%1),3)
4992 mm.setGroupsOnFamily("RIDF%s"%(magicSt%1),["RID"])
4993 self.assertEqual(mm.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
4994 self.assertEqual(mm.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF")) # <- the aim of test is here !
4995 self.assertEqual(mm.getFamiliesIdsOnGroup("RID"),(-4,3))
4996 mm.write(fileName,2)
4997 # now read such funny file !
4998 mm2=MEDFileMesh.New(fileName) # <- normally mdump of Pyfile98.med must contain only RID and FAMILLE_ZERO families.
4999 self.assertTrue(mm.isEqual(mm2,1e-16))
5000 self.assertEqual(mm2.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
5001 self.assertEqual(mm2.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF"))
5002 self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too !
5006 def testCartesianizer1(self):
5007 """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """
5009 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
5010 mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts()
5011 d0=DataArrayInt(16) ; d0[:]=0
5012 d1=DataArrayInt(9) ; d1[:]=0
5013 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5014 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5015 ref0=mm.getCoords().getHiddenCppPointer()
5016 ref1=mm[0].getNodalConnectivity().getHiddenCppPointer()
5017 self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer())
5018 ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer()
5019 ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer()
5020 self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
5021 mm.setAxisType(AX_CYL) #<- important
5022 mm2=mm.cartesianize() # the trigger
5023 self.assertEqual(mm2.getAxisType(),AX_CART)
5024 mm.setAxisType(AX_CART) # this is here only to avoid complaints
5025 self.assertTrue(isinstance(mm2,MEDFileUMesh))
5026 self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
5027 self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important
5028 self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important
5029 self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer())
5030 self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
5031 self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important
5032 self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important
5033 self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important
5034 self.assertEqual(mm2.getName(),mm.getName())
5035 self.assertEqual(mm2.getDescription(),mm.getDescription())
5036 self.assertEqual(mm2.getTime(),mm.getTime())
5037 self.assertEqual(mm2.getTime(),mm.getTime())
5038 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5039 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5040 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5041 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5042 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5043 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5044 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5045 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5047 mm.setAxisType(AX_CART)
5048 mm2=mm.cartesianize() # the trigger
5049 self.assertEqual(mm2.getAxisType(),AX_CART)
5050 self.assertTrue(isinstance(mm2,MEDFileUMesh))
5051 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5052 # CurveLinearMesh non cart
5053 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear()
5054 mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
5055 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5056 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5057 ref0=mm.getMesh().getCoords().getHiddenCppPointer()
5058 mm2=mm.cartesianize() # the trigger
5059 self.assertEqual(mm2.getAxisType(),AX_CART)
5060 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5061 self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
5062 self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important
5063 self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important
5064 self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
5065 self.assertEqual(mm2.getName(),mm.getName())
5066 self.assertEqual(mm2.getDescription(),mm.getDescription())
5067 self.assertEqual(mm2.getTime(),mm.getTime())
5068 self.assertEqual(mm2.getTime(),mm.getTime())
5069 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5070 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5071 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5072 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5073 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5074 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5075 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5076 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5077 # CurveLinearMesh cart
5078 mm.setAxisType(AX_CART)
5079 mm2=mm.cartesianize() # the trigger
5080 self.assertEqual(mm2.getAxisType(),AX_CART)
5081 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5082 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5084 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
5085 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
5086 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5087 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5088 mm2=mm.cartesianize() # the trigger
5089 self.assertEqual(mm2.getAxisType(),AX_CART)
5090 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5091 self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
5092 self.assertEqual(mm2.getName(),mm.getName())
5093 self.assertEqual(mm2.getDescription(),mm.getDescription())
5094 self.assertEqual(mm2.getTime(),mm.getTime())
5095 self.assertEqual(mm2.getTime(),mm.getTime())
5096 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5097 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5098 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5099 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5100 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5101 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5102 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5103 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5105 mm.setAxisType(AX_CART)
5106 mm2=mm.cartesianize() # the trigger
5107 self.assertEqual(mm2.getAxisType(),AX_CART)
5108 self.assertTrue(isinstance(mm2,MEDFileCMesh))
5109 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5113 def testCheckCoherency(self):
5114 m2 = MEDCouplingUMesh("2d", 2)
5115 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5116 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5117 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5118 mum = MEDFileUMesh()
5119 mum.setMeshAtLevel(0, m2)
5120 mum.setMeshAtLevel(-1, m1)
5121 mum.checkConsistency()
5122 mum2 = mum.deepCopy()
5125 arr = DataArrayInt([2]*4)
5126 mum.setFamilyFieldArr(1, arr); arr.reAlloc(35);
5127 self.assertRaises(InterpKernelException, mum.checkConsistency)
5128 mum=mum2; mum2=mum.deepCopy();
5129 arr = DataArrayInt([2]*4)
5130 mum.setRenumFieldArr(1, arr); arr.reAlloc(35);
5131 self.assertRaises(InterpKernelException, mum.checkConsistency)
5132 mum=mum2; mum2=mum.deepCopy();
5133 mum.setRenumFieldArr(1, DataArrayInt([2]*4))
5134 self.assertRaises(InterpKernelException, mum.checkConsistency)
5135 mum=mum2; mum2=mum.deepCopy();
5136 arr = DataArrayAsciiChar(['tutu x']*4)
5137 mum.setNameFieldAtLevel(1, arr); arr.reAlloc(35);
5138 self.assertRaises(InterpKernelException, mum.checkConsistency)
5141 mum=mum2; mum2=mum.deepCopy();
5142 arr = DataArrayInt([2]*2)
5143 mum.setFamilyFieldArr(0, arr); arr.reAlloc(35);
5144 self.assertRaises(InterpKernelException, mum.checkConsistency)
5145 mum=mum2; mum2=mum.deepCopy();
5146 arr = DataArrayInt([2]*2)
5147 mum.setRenumFieldArr(0, arr); arr.reAlloc(35);
5148 self.assertRaises(InterpKernelException, mum.checkConsistency)
5149 mum=mum2; mum2=mum.deepCopy();
5150 mum.setRenumFieldArr(0, DataArrayInt([2]*2))
5151 self.assertRaises(InterpKernelException, mum.checkConsistency)
5152 mum=mum2; mum2=mum.deepCopy();
5153 arr = DataArrayAsciiChar(['tutu x']*2)
5154 mum.setNameFieldAtLevel(0, arr); arr.reAlloc(35);
5155 self.assertRaises(InterpKernelException, mum.checkConsistency)
5158 mum=mum2; mum2=mum.deepCopy();
5159 arr = DataArrayInt([2]*5)
5160 mum.setFamilyFieldArr(-1, arr); arr.reAlloc(35);
5161 self.assertRaises(InterpKernelException, mum.checkConsistency)
5162 mum=mum2; mum2=mum.deepCopy();
5163 arr = DataArrayInt([2]*5)
5164 mum.setRenumFieldArr(-1, arr); arr.reAlloc(35);
5165 self.assertRaises(InterpKernelException, mum.checkConsistency)
5166 mum=mum2; mum2=mum.deepCopy();
5167 mum.setRenumFieldArr(-1, DataArrayInt([2]*5))
5168 self.assertRaises(InterpKernelException, mum.checkConsistency)
5169 mum=mum2; mum2=mum.deepCopy();
5170 arr = DataArrayAsciiChar(['tutu x']*5)
5171 mum.setNameFieldAtLevel(-1, arr); arr.reAlloc(35);
5172 self.assertRaises(InterpKernelException, mum.checkConsistency)
5175 def testCheckSMESHConsistency(self):
5176 m2 = MEDCouplingUMesh("2d", 2)
5177 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5178 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5179 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5180 mum = MEDFileUMesh()
5181 mum.setMeshAtLevel(0, m2)
5182 mum.setMeshAtLevel(-1, m1)
5183 mum.checkConsistency()
5184 mum.checkSMESHConsistency()
5185 n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5186 n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5187 mum.setRenumFieldArr(0, n2)
5188 mum.setRenumFieldArr(-1, n1)
5189 self.assertRaises(InterpKernelException, mum.checkSMESHConsistency)
5190 mum.setRenumFieldArr(-1, n1+100)
5191 mum.checkSMESHConsistency()
5195 def testClearNodeAndCellNumbers(self):
5196 m2 = MEDCouplingUMesh("2d", 2)
5197 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5198 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5199 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5200 mum = MEDFileUMesh()
5201 mum.setMeshAtLevel(0, m2)
5202 mum.setMeshAtLevel(-1, m1)
5203 mum.checkConsistency()
5204 n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5205 n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5206 mum.setRenumFieldArr(0, n2)
5207 mum.setRenumFieldArr(-1, n1)
5208 mum.clearNodeAndCellNumbers()
5209 mum.checkSMESHConsistency()
5213 def testCMeshSetFamilyFieldArrNull(self):
5215 fname="Pyfile99.med"
5216 arrX=DataArrayDouble([0,1,2,3])
5217 arrY=DataArrayDouble([0,1,2])
5218 m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m.setName(meshName)
5219 mm=MEDFileCMesh() ; mm.setMesh(m)
5220 famCellIds=DataArrayInt([0,-2,-2,-1,-2,0])
5221 famNodeIds=DataArrayInt([0,0,0,3,4,1,2,7,2,1,0,0])
5222 mm.setFamilyFieldArr(0,famCellIds)
5223 mm.setFamilyFieldArr(1,famNodeIds)
5225 mm=MEDFileMesh.New(fname)
5226 self.assertTrue(mm.getFamilyFieldAtLevel(0) is not None)
5227 self.assertTrue(mm.getFamilyFieldAtLevel(1) is not None)
5228 mm.setFamilyFieldArr(0,None)#<- bug was here
5229 mm.setFamilyFieldArr(1,None)#<- bug was here
5230 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
5231 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
5233 self.assertTrue(mm3.getFamilyFieldAtLevel(0) is None)
5234 self.assertTrue(mm3.getFamilyFieldAtLevel(1) is None)
5236 mm2=MEDFileMesh.New(fname)
5237 self.assertTrue(mm2.getFamilyFieldAtLevel(0) is None)
5238 self.assertTrue(mm2.getFamilyFieldAtLevel(1) is None)
5242 def testAppendFieldProfileOnIntField(self):
5243 fname="Pyfile100.med"
5244 arrX=DataArrayDouble([0,1,2,3])
5245 arrY=DataArrayDouble([0,1,2])
5246 mesh=MEDCouplingCMesh() ; mesh.setCoords(arrX,arrY) ; mesh.setName("Mesh")
5250 fmts=MEDFileIntFieldMultiTS()
5252 pfl=DataArrayInt([1,3,5]) ; pfl.setName(pflName)
5253 f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(mesh)
5254 fieldName="FieldOnCell"
5255 f.setTime(1.2,1,1) ; f.setName(fieldName)
5256 arr=DataArrayInt32([101,102,103]) ; f.setArray(arr)
5257 fmts.appendFieldProfile(f,mm,0,pfl)
5262 mm=MEDFileMesh.New(fname)
5263 fmts=MEDFileAnyTypeFieldMultiTS.New(fname)
5264 self.assertTrue(isinstance(fmts,MEDFileIntFieldMultiTS))
5265 self.assertEqual(fmts.getName(),fieldName)
5266 self.assertEqual(len(fmts),1)
5268 ftest,pfltest=f1ts.getFieldWithProfile(ON_CELLS,0,mm)
5269 self.assertEqual(pfltest.getName(),pflName)
5270 self.assertEqual(ftest.getName(),fieldName)
5271 self.assertTrue(ftest.isEqualWithoutConsideringStr(arr))
5272 ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
5273 self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr))
5274 self.assertEqual(ftest2.getTime(),f.getTime())
5275 self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr))
5279 def testMEDFileFieldEasyField1(self):
5280 """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."""
5281 ## Basic test on cells on top level
5282 fname="Pyfile101.med"
5285 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5286 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5288 m.insertNextCell(NORM_TRI3,[0,1,2])
5289 m.insertNextCell(NORM_TRI3,[3,4,5])
5290 m.insertNextCell(NORM_TRI3,[6,7,8])
5291 m.insertNextCell(NORM_TRI3,[9,10,11])
5292 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5293 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5296 arr0=DataArrayDouble([10,11,12,13,100,101])
5297 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5298 f.setName(fieldName) ; f.setTime(2.,6,7)
5300 ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5302 arr2=arr0+1000 ; f.setArray(arr2)
5303 f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f)
5307 mm=MEDFileMesh.New(fname)
5308 f1ts=MEDFileField1TS(fname,fieldName,6,7)
5309 ftst0=f1ts.field(mm)
5310 self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12))
5311 f1ts=MEDFileField1TS(fname,fieldName,8,9)
5312 ftst1=f1ts.field(mm)
5313 self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12))
5314 fmts=MEDFileFieldMultiTS(fname,fieldName)
5315 self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12))
5316 ## Basic test on nodes on top level
5317 f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5318 f2.setName(fieldName)
5320 ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5322 mm=MEDFileMesh.New(fname)
5323 f1ts=MEDFileField1TS(fname,fieldName,23,24)
5324 self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12))
5325 fmts=MEDFileFieldMultiTS(fname,fieldName)
5326 self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12))
5328 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)
5329 f3.setName(fieldName) ; f3.checkConsistencyLight()
5330 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5332 mm=MEDFileMesh.New(fname)
5333 f1ts=MEDFileField1TS(fname,fieldName,2,3)
5334 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5336 f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5337 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])
5338 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)
5339 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)
5340 f4.checkConsistencyLight()
5341 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5343 mm=MEDFileMesh.New(fname)
5344 f1ts=MEDFileField1TS(fname,fieldName,4,5)
5345 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5349 def testMEDFileFieldEasyField2(self):
5350 """Same thantestMEDFileFieldEasyField1 except that here intfields are considered.
5351 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."""
5352 ## Basic test on cells on top level
5353 fname="Pyfile102.med"
5356 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5357 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5359 m.insertNextCell(NORM_TRI3,[0,1,2])
5360 m.insertNextCell(NORM_TRI3,[3,4,5])
5361 m.insertNextCell(NORM_TRI3,[6,7,8])
5362 m.insertNextCell(NORM_TRI3,[9,10,11])
5363 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5364 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5367 arr0=DataArrayInt32([10,11,12,13,100,101])
5368 f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5369 f.setName(fieldName) ; f.setTime(2.,6,7)
5371 ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5373 arr2=arr0+1000 ; f.setArray(arr2)
5374 f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f)
5378 mm=MEDFileMesh.New(fname)
5379 f1ts=MEDFileIntField1TS(fname,fieldName,6,7)
5380 ftst0=f1ts.field(mm)
5381 self.assertTrue(f0.isEqual(ftst0,1e-12,0))
5382 f1ts=MEDFileIntField1TS(fname,fieldName,8,9)
5383 ftst1=f1ts.field(mm)
5384 self.assertTrue(f1.isEqual(ftst1,1e-12,0))
5385 fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5386 self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,0))
5387 ## Basic test on nodes on top level
5388 f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt32([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5389 f2.setName(fieldName)
5391 ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5393 mm=MEDFileMesh.New(fname)
5394 f1ts=MEDFileIntField1TS(fname,fieldName,23,24)
5395 self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,0))
5396 fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5397 self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,0))
5399 f3=MEDCouplingFieldInt(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayInt32([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)
5400 f3.setName(fieldName) ; f3.checkConsistencyLight()
5401 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5403 mm=MEDFileMesh.New(fname)
5404 f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5405 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5407 f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5408 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])
5409 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)
5410 arr4=DataArrayInt32([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)
5411 f4.checkConsistencyLight()
5412 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5414 mm=MEDFileMesh.New(fname)
5415 f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5416 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5420 def testMEDFileFieldEasyField3(self):
5421 """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."""
5422 fname="Pyfile103.med"
5425 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5426 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5428 m.insertNextCell(NORM_TRI3,[0,1,2])
5429 m.insertNextCell(NORM_TRI3,[3,4,5])
5430 m.insertNextCell(NORM_TRI3,[6,7,8])
5431 m.insertNextCell(NORM_TRI3,[9,10,11])
5432 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5433 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5435 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5437 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5438 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5442 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5443 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5445 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2)
5446 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5447 # here f1 lying on level -1 not 0 check if "field" method detect it !
5448 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5449 f1.setMesh(mm[-1]) # -1 is very important
5451 f1.checkConsistencyLight()
5453 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5455 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4)
5456 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5458 f3=MEDCouplingFieldDouble(ON_GAUSS_NE)
5459 f3.setMesh(mm[-1]) # this line is important
5460 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)
5461 f3.setName(fieldName) ; f3.checkConsistencyLight()
5462 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5464 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3)
5465 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5467 f4=MEDCouplingFieldDouble(ON_GAUSS_PT)
5468 f4.setMesh(mm[-1]) # this line is important
5469 f4.setName(fieldName)
5470 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])
5471 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)
5472 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)
5473 f4.checkConsistencyLight()
5474 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5475 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5)
5476 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5480 def testMEDFileFieldEasyField4(self):
5481 """ Same than testMEDFileFieldEasyField3 but with integers"""
5482 fname="Pyfile104.med"
5485 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5486 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5488 m.insertNextCell(NORM_TRI3,[0,1,2])
5489 m.insertNextCell(NORM_TRI3,[3,4,5])
5490 m.insertNextCell(NORM_TRI3,[6,7,8])
5491 m.insertNextCell(NORM_TRI3,[9,10,11])
5492 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5493 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5495 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5497 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5498 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5502 f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt32([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5503 f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5505 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2)
5506 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5507 # here f1 lying on level -1 not 0 check if "field" method detect it !
5508 f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt32([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5509 f1.setMesh(mm[-1]) # -1 is very important
5511 f1.checkConsistencyLight()
5513 f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5515 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4)
5516 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5518 f3=MEDCouplingFieldInt(ON_GAUSS_NE)
5519 f3.setMesh(mm[-1]) # this line is important
5520 arr3=DataArrayInt32([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)
5521 f3.setName(fieldName) ; f3.checkConsistencyLight()
5522 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5524 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5525 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5527 f4=MEDCouplingFieldInt(ON_GAUSS_PT)
5528 f4.setMesh(mm[-1]) # this line is important
5529 f4.setName(fieldName)
5530 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])
5531 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)
5532 arr4=DataArrayInt32([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)
5533 f4.checkConsistencyLight()
5534 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5535 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5536 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5540 def testMEDFileFieldEasyField5(self):
5541 """More and more difficult now look at how profiles are managed by "field" method."""
5542 fname="Pyfile105.med"
5545 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5546 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5548 m.insertNextCell(NORM_TRI3,[0,1,2])
5549 m.insertNextCell(NORM_TRI3,[3,4,5])
5550 m.insertNextCell(NORM_TRI3,[6,7,8])
5551 m.insertNextCell(NORM_TRI3,[9,10,11])
5552 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5553 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5556 pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl")
5557 m2=m.deepCopy()[pfl] ; m2.setName(m.getName())
5559 arr0=DataArrayDouble([10,11,12,13])
5560 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2)
5561 f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight()
5562 ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile
5565 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5566 self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5567 # more complicated -> multi level
5568 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5570 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5571 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5573 mm2[0]=m0 ; mm2[-1]=m
5575 ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl)
5577 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5578 self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5582 def testExtractPart1(self):
5583 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)])
5585 m0=MEDCouplingUMesh(meshName,2) ; m0.setCoords(coo) ; m0.allocateCells()
5586 m0.insertNextCell(NORM_TRI3,[8,4,3])
5587 m0.insertNextCell(NORM_TRI3,[8,9,4])
5588 m0.insertNextCell(NORM_TRI3,[7,13,8])
5589 m0.insertNextCell(NORM_TRI3,[7,12,13])
5590 m0.insertNextCell(NORM_TRI3,[0,6,1])
5591 m0.insertNextCell(NORM_TRI3,[0,5,6])
5592 m0.insertNextCell(NORM_QUAD4,[1,6,7,2])
5593 m0.insertNextCell(NORM_QUAD4,[2,7,8,3])
5594 m0.insertNextCell(NORM_QUAD4,[8,13,14,9])
5595 m0.insertNextCell(NORM_QUAD4,[6,11,12,7])
5596 m0.insertNextCell(NORM_QUAD4,[5,10,11,6])
5598 m1=MEDCouplingUMesh(meshName,1) ; m1.setCoords(coo) ; m1.allocateCells()
5599 m1.insertNextCell(NORM_SEG2,[10,5])
5600 m1.insertNextCell(NORM_SEG2,[5,0])
5601 m1.insertNextCell(NORM_SEG2,[0,1])
5602 m1.insertNextCell(NORM_SEG2,[1,2])
5603 m1.insertNextCell(NORM_SEG2,[2,3])
5604 m1.insertNextCell(NORM_SEG2,[3,4])
5605 m1.insertNextCell(NORM_SEG2,[4,9])
5606 m1.insertNextCell(NORM_SEG2,[9,14])
5607 m1.insertNextCell(NORM_SEG2,[14,13])
5608 m1.insertNextCell(NORM_SEG2,[13,12])
5609 m1.insertNextCell(NORM_SEG2,[12,11])
5610 m1.insertNextCell(NORM_SEG2,[11,10])
5612 mm[0]=m0 ; mm[-1]=m1
5613 arr0=DataArrayInt([0,1,2,3,4,6,7,8,12,13])
5615 tab[0]=DataArrayInt([0,2,3,4,6,7])
5616 tab[-1]=DataArrayInt([2,3,4,5,9])
5618 self.assertTrue(mm.deduceNodeSubPartFromCellSubPart(tab).isEqual(arr0))
5622 fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5625 arr0_0=DataArrayDouble([100,101,102,103,104,105,106,107,108,109,110]) ; arr0_0.setInfoOnComponents(ic)
5626 f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*t0) ; f0.setArray(arr0_0)
5627 f0.setMesh(m0) ; f0.setName(fname0)
5628 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setTime(*t0) ; f1.setArray(DataArrayDouble([200,201,202,203,204,205,206,207,208,209,210,211]))
5629 f1.setMesh(m1) ; f1.setName(fname0) ; f1.getArray().setInfoOnComponents(ic)
5630 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]))
5631 f2.setMesh(m0) ; f2.setName(fname0) ; f2.getArray().setInfoOnComponents(ic)
5632 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.setFieldNoProfileSBT(f2)
5633 fmts.pushBackTimeStep(f1ts)
5635 mmOut=mm.extractPart(tab)
5637 fsPart0=fs.extractPart(tab,mm)
5638 self.assertEqual(len(fsPart0),1)
5640 self.assertEqual(len(fmtsP),1)
5642 self.assertRaises(InterpKernelException,f1ts.field,mmOut)
5644 self.assertTrue(mmOut[0].computeCellCenterOfMass().isEqual(m0[tab[0]].computeCellCenterOfMass(),1e-12))
5645 self.assertTrue(mmOut[-1].computeCellCenterOfMass().isEqual(m1[tab[-1]].computeCellCenterOfMass(),1e-12))
5647 m0Part=m0.deepCopy()[tab[0]] ; m0Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m0Part.setName(m0.getName())
5648 self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5649 m1Part=m1.deepCopy()[tab[-1]] ; m1Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m1Part.setName(m0.getName())
5650 self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5651 self.assertTrue(mmOut[-1].isEqual(m1Part,1e-12))
5653 f0Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mmOut) ; f0Part.checkConsistencyLight()
5654 self.assertEqual(f0Part.getTypeOfField(),ON_CELLS)
5655 self.assertTrue(f0Part.getMesh().isEqual(m0Part,1e-12))
5656 arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic)
5657 self.assertTrue(f0Part.getArray().isEqual(arr0Exp,1e-12)) ; self.assertEqual(f0Part.getTime(),list(t0))
5658 f1Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,-1,mmOut) ; f1Part.checkConsistencyLight()
5659 self.assertEqual(f1Part.getTypeOfField(),ON_CELLS)
5660 self.assertTrue(f1Part.getMesh().isEqual(m1Part,1e-12))
5661 arr1Exp=DataArrayDouble([202,203,204,205,209]) ; arr1Exp.setInfoOnComponents(ic)
5662 self.assertTrue(f1Part.getArray().isEqual(arr1Exp,1e-12)) ; self.assertEqual(f1Part.getTime(),list(t0))
5664 f2Part=f1ts.getFieldOnMeshAtLevel(ON_NODES,0,mmOut) ; f2Part.checkConsistencyLight()
5665 arr2Exp=DataArrayDouble([300,301,302,303,304,306,307,308,312,313]) ; arr2Exp.setInfoOnComponents(ic)
5666 self.assertTrue(f2Part.getArray().isEqual(arr2Exp,1e-12)) ; self.assertEqual(f2Part.getTime(),list(t0))
5668 fs=MEDFileFields() ; fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5669 tss=[(16.5,3,4),(17.5,4,5),(18.5,5,6)]
5670 for i,tt in enumerate(tss):
5671 f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*tt)
5672 myarr=arr0_0+i*1000.
5674 f0.setMesh(m0) ; f0.setName(fname0) ; f0.getArray().setInfoOnComponents(ic)
5675 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; fmts.pushBackTimeStep(f1ts)
5677 fsPart1=fs.extractPart(tab,mm)
5678 self.assertEqual(len(fsPart1),1)
5680 self.assertEqual(len(fmtsP),len(tss))
5681 for i,(f1tsP,tt) in enumerate(zip(fmtsP,tss)):
5682 fPart=f1tsP.field(mmOut) ; fPart.checkConsistencyLight()
5683 self.assertEqual(fPart.getTypeOfField(),ON_CELLS)
5684 arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic) ; arr0Exp+=i*1000.
5685 self.assertTrue(fPart.getMesh().isEqual(m0Part,1e-12))
5686 self.assertTrue(fPart.getArray().isEqual(arr0Exp,1e-12))
5687 self.assertEqual(fPart.getTime(),list(tt))
5692 def testSymmetryPlusAggregationMFD1(self):
5693 """ Testing of MEDFileData::Aggregate and MEDFileUMesh::Aggregate and MEDFileUMesh::getAllDistributionOfType """
5694 fname1="Pyfile106_1.med"
5695 fname2="Pyfile106_2.med"
5696 fname3="Pyfile106_3.med"
5699 da1=DataArrayDouble([1,2,10,3,4,11,5,6,12,7,8,13],4,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5701 mm1_0=MEDCouplingUMesh(meshName,3) ; mm1_0.allocateCells()
5702 mm1_0.setCoords(da1)
5703 mm1_0.insertNextCell(NORM_TETRA4,[0,1,2,3])
5704 mm1_0.insertNextCell(NORM_TETRA4,[4,5,6,7])
5705 mm1_0.insertNextCell(NORM_PENTA6,[8,9,10,11,12,13])
5706 mm1_0.insertNextCell(NORM_PENTA6,[14,15,16,17,18,19])
5707 mm1_0.insertNextCell(NORM_PENTA6,[20,21,22,23,24,25])
5709 mm1.setFamilyFieldArr(0,DataArrayInt([1,2,3,4,5]))
5710 mm1.setRenumFieldArr(0,DataArrayInt([11,12,13,14,15]))
5712 mm1_1=MEDCouplingUMesh(meshName,2) ; mm1_1.allocateCells()
5713 mm1_1.setCoords(da1)
5714 mm1_1.insertNextCell(NORM_TRI3,[0,1,2])
5715 mm1_1.insertNextCell(NORM_TRI3,[3,4,5])
5716 mm1_1.insertNextCell(NORM_QUAD4,[6,7,8,9])
5717 mm1_1.insertNextCell(NORM_QUAD4,[10,11,12,13])
5718 mm1_1.insertNextCell(NORM_QUAD4,[14,15,16,17])
5719 mm1_1.insertNextCell(NORM_QUAD4,[18,19,20,21])
5721 mm1.setFamilyFieldArr(-1,DataArrayInt([6,7,8,9,10,11]))
5722 mm1.setRenumFieldArr(-1,DataArrayInt([16,17,18,19,20,21]))
5723 for i in range(1,10):
5724 mm1.setFamilyId("F%d"%i,i)
5725 mm1.setFamilyId("FAMILLE_ZERO",0)
5726 mm1.setFamilyId("H1",100)
5727 mm1.setFamiliesOnGroup("myGRP",["F2","F6"])
5728 mm1.setFamiliesOnGroup("myGRP1",["F2","F6"])
5729 mm1.setFamilyFieldArr(1,DataArrayInt([12,13,14,15]))
5730 mm1.setRenumFieldArr(1,DataArrayInt([22,23,24,25]))
5733 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]"])
5735 mm2_0=MEDCouplingUMesh(meshName,3) ; mm2_0.allocateCells()
5736 mm2_0.setCoords(da1)
5737 mm2_0.insertNextCell(NORM_TETRA4,[100,101,102,103])
5738 mm2_0.insertNextCell(NORM_TETRA4,[104,105,106,107])
5739 mm2_0.insertNextCell(NORM_TETRA4,[108,109,110,111])
5740 mm2_0.insertNextCell(NORM_PENTA6,[112,113,114,115,116,117])
5742 mm2.setFamilyFieldArr(0,DataArrayInt([40,41,42,43]))
5743 mm2.setRenumFieldArr(0,DataArrayInt([50,51,52,53]))
5745 mm2_1=MEDCouplingUMesh(meshName,2) ; mm2_1.allocateCells()
5746 mm2_1.setCoords(da1)
5747 mm2_1.insertNextCell(NORM_TRI3,[100,101,102])
5748 mm2_1.insertNextCell(NORM_TRI3,[103,104,105])
5749 mm2_1.insertNextCell(NORM_TRI3,[106,107,108])
5750 mm2_1.insertNextCell(NORM_QUAD4,[109,110,111,112])
5751 mm2_1.insertNextCell(NORM_QUAD4,[113,114,115,116])
5752 mm2_1.insertNextCell(NORM_QUAD4,[117,118,119,120])
5753 mm2_1.insertNextCell(NORM_QUAD4,[121,122,123,124])
5754 mm2_1.insertNextCell(NORM_QUAD4,[125,126,127,128])
5756 mm2.setFamilyFieldArr(-1,DataArrayInt([200,201,202,203,204,205,206,207]))
5757 mm2.setRenumFieldArr(-1,DataArrayInt([300,301,302,303,304,305,306,307]))
5758 for i in range(1,12):
5759 mm2.setFamilyId("G%d"%i,i+30)
5760 mm2.setFamilyId("H1",100)
5761 mm2.setFamilyId("FAMILLE_ZERO",0)
5762 mm2.setFamiliesOnGroup("myGRP",["G2","G6"])
5763 mm2.setFamiliesOnGroup("myGRP2",["G4","G7"])
5764 mm2.setFamilyFieldArr(1,DataArrayInt([112,113,114,115,116]))
5765 mm2.setRenumFieldArr(1,DataArrayInt([122,123,124,125,126]))
5767 mm=MEDFileUMesh.Aggregate([mm1,mm2])
5769 def CheckMesh(tester,mm):
5770 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]"])
5771 tester.assertTrue(mm.getCoords().isEqual(cooExp,1e-12))
5772 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])))
5773 tester.assertTrue(mm[0].getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,32,39,46,53])))
5774 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])))
5775 tester.assertTrue(mm[-1].getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20,25,30,35,40,45,50,55,60,65])))
5776 tester.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([1,2,40,41,42,3,4,5,43])))
5777 tester.assertTrue(mm.getNumberFieldAtLevel(0).isEqual(DataArrayInt([11,12,50,51,52,13,14,15,53])))
5778 tester.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(DataArrayInt([6,7,200,201,202,8,9,10,11,203,204,205,206,207])))
5779 tester.assertTrue(mm.getNumberFieldAtLevel(-1).isEqual(DataArrayInt([16,17,300,301,302,18,19,20,21,303,304,305,306,307])))
5780 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)]
5781 tester.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
5782 tester.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
5783 tester.assertEqual(mm.getGroupsNames(),('myGRP','myGRP1','myGRP2'))
5784 tester.assertEqual(mm.getAllDistributionOfTypes(),[(NORM_TRI3,5),(NORM_QUAD4,9),(NORM_TETRA4,5),(NORM_PENTA6,4),(NORM_ERROR,9)])
5791 infoc=["dd [W]","eee [kA]"]
5793 fmts1=MEDFileFieldMultiTS()
5794 f1ts1=MEDFileField1TS()
5795 f1_1=MEDCouplingFieldDouble(ON_CELLS) ; f1_1.setMesh(mm1[0]) ; f1_1.setName(fieldName)
5796 arr1=DataArrayDouble([(10,110),(11,111),(12,112),(13,113),(14,114)])
5797 arr1.setInfoOnComponents(infoc)
5798 f1_1.setArray(arr1) ; f1_1.setTime(*t1) ; f1_1.setTimeUnit("ms")
5799 f1_1.checkConsistencyLight()
5800 f1ts1.setFieldNoProfileSBT(f1_1)
5802 f1_2=MEDCouplingFieldDouble(ON_CELLS) ; f1_2.setMesh(mm1[-1]) ; f1_2.setName(fieldName)
5803 arr2=DataArrayDouble([(15,115),(16,116),(17,117),(18,118),(19,119),(20,120)])
5804 arr2.setInfoOnComponents(infoc)
5805 f1_2.setArray(arr2) ; f1_2.setTime(*t1) ; f1_2.setTimeUnit("ms")
5806 f1_2.checkConsistencyLight()
5807 f1ts1.setFieldNoProfileSBT(f1_2)
5808 f1_3=MEDCouplingFieldDouble(ON_NODES) ; f1_3.setMesh(mm1[0]) ; f1_3.setName(fieldName)
5809 arr3=DataArrayDouble([(21,121),(22,122),(23,123),(24,124)])
5810 arr3.setInfoOnComponents(infoc)
5811 f1_3.setArray(arr3) ; f1_3.setTime(*t1) ; f1_3.setTimeUnit("ms")
5812 f1_3.checkConsistencyLight()
5813 f1ts1.setFieldNoProfileSBT(f1_3)
5814 fmts1.pushBackTimeStep(f1ts1)
5816 f1ts2=f1ts1.deepCopy()
5817 f1ts2.setTime(t2[1],t2[2],t2[0])
5818 f1ts2.getUndergroundDataArray()[:]+=2000
5819 fmts1.pushBackTimeStep(f1ts2)
5821 fmts2=MEDFileFieldMultiTS()
5822 f1ts3=MEDFileField1TS()
5823 f2_1=MEDCouplingFieldDouble(ON_CELLS) ; f2_1.setMesh(mm2[0]) ; f2_1.setName(fieldName)
5824 arr4=DataArrayDouble([(50,150),(51,151),(52,152),(53,153)])
5825 arr4.setInfoOnComponents(infoc)
5826 f2_1.setArray(arr4) ; f2_1.setTime(*t1) ; f2_1.setTimeUnit("ms")
5827 f2_1.checkConsistencyLight()
5828 f1ts3.setFieldNoProfileSBT(f2_1)
5829 f2_2=MEDCouplingFieldDouble(ON_CELLS) ; f2_2.setMesh(mm2[-1]) ; f2_2.setName(fieldName)
5830 arr5=DataArrayDouble([(54,154),(55,155),(56,156),(57,157),(158,158),(59,159),(60,160),(61,161)])
5831 arr5.setInfoOnComponents(infoc)
5832 f2_2.setArray(arr5) ; f2_2.setTime(*t1) ; f2_2.setTimeUnit("ms")
5833 f2_2.checkConsistencyLight()
5834 f1ts3.setFieldNoProfileSBT(f2_2)
5835 f2_3=MEDCouplingFieldDouble(ON_NODES) ; f2_3.setMesh(mm2[0]) ; f2_3.setName(fieldName)
5836 arr6=DataArrayDouble([(62,162),(63,163),(64,164),(65,165),(66,166)])
5837 arr6.setInfoOnComponents(infoc)
5838 f2_3.setArray(arr6) ; f2_3.setTime(*t1) ; f2_3.setTimeUnit("ms")
5839 f2_3.checkConsistencyLight()
5840 f1ts3.setFieldNoProfileSBT(f2_3)
5841 fmts2.pushBackTimeStep(f1ts3)
5843 f1ts4=f1ts3.deepCopy()
5844 f1ts4.setTime(t2[1],t2[2],t2[0])
5845 f1ts4.getUndergroundDataArray()[:]+=2000
5846 fmts2.pushBackTimeStep(f1ts4)
5849 mfd1.setMeshes(MEDFileMeshes())
5850 mfd1.getMeshes().pushMesh(mm1)
5851 mfd1.setFields(MEDFileFields())
5852 mfd1.getFields().pushField(fmts1)
5855 mfd2.setMeshes(MEDFileMeshes())
5856 mfd2.getMeshes().pushMesh(mm2)
5857 mfd2.setFields(MEDFileFields())
5858 mfd2.getFields().pushField(fmts2)
5860 mfd=MEDFileData.Aggregate([mfd1,mfd2])
5861 def CheckMFD(tester,mfd):
5862 tester.assertEqual(len(mfd.getMeshes()),1)
5863 tester.assertEqual(len(mfd.getFields()),1)
5864 CheckMesh(self,mfd.getMeshes()[0])
5865 tester.assertEqual(len(mfd.getFields()[0]),2)
5866 zeF1=mfd.getFields()[0][0]
5867 zeF1_1=zeF1.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5868 ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5869 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5870 ref.renumberCells(o2n)
5871 tester.assertTrue(ref.isEqual(zeF1_1,1e-12,1e-12))
5872 zeF1_2=zeF1.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5873 ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5874 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5875 ref.renumberCells(o2n)
5876 tester.assertTrue(ref.isEqual(zeF1_2,1e-12,1e-12))
5877 zeF1_3=zeF1.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5878 ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5879 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5880 ref.renumberCells(o2n)
5881 tester.assertTrue(ref.isEqual(zeF1_3,1e-12,1e-12))
5883 zeF2=mfd.getFields()[0][1]
5884 zeF2_1=zeF2.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
5885 ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
5886 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5887 ref.renumberCells(o2n)
5888 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5889 tester.assertTrue(ref.isEqual(zeF2_1,1e-12,1e-12))
5890 zeF2_2=zeF2.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
5891 ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
5892 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5893 ref.renumberCells(o2n)
5894 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5895 tester.assertTrue(ref.isEqual(zeF2_2,1e-12,1e-12))
5896 zeF2_3=zeF2.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
5897 ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
5898 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
5899 ref.renumberCells(o2n)
5900 ref.setTime(*t2) ; ref.getArray()[:]+=2000
5901 tester.assertTrue(ref.isEqual(zeF2_3,1e-12,1e-12))
5903 mfd1.write(fname1,2) ; mfd2.write(fname2,2)
5904 mfd=MEDFileData.Aggregate([MEDFileData(fname1),MEDFileData(fname2)])
5909 def testAggregateWithGroups(self):
5910 """ Testing MEDFileUMesh::Aggretate when groups are present. """
5911 def generate(grp_name, offset):
5912 coo = DataArrayDouble([0., 1., 2.])
5914 m = MEDCouplingCMesh("toto")
5915 m.setCoords(coo, coo)
5916 m = m.buildUnstructured()
5917 mu = MEDFileUMesh.New()
5918 mu.setMeshAtLevel(0, m)
5919 g = DataArrayInt([0])
5921 g2 = DataArrayInt([1])
5922 g2.setName("common") # make a common group for all meshes being merged
5923 mu.setGroupsAtLevel(0, [g, g2])
5926 m1 = generate("A", 0.)
5927 m2 = generate("B", 2.)
5928 mm = MEDFileUMesh.Aggregate([m1,m2])
5930 self.assertEqual(mm.getFamilyFieldAtLevel(0).getValues(), [-2, -3, -1, -1, -4, -5, -1, -1])
5931 self.assertEqual(mm.getNumberFieldAtLevel(0), None)
5932 refFamIds=[('Family_-1',-1),('Family_-2',-2),('Family_-3',-3), ('Family_-4',-4), ('Family_-5',-5)]
5933 self.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
5934 self.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
5935 self.assertEqual(mm.getGroupsNames(),('A','B', 'common'))
5936 self.assertEqual(mm.getGroupArr(0, 'A').getValues(), [0])
5937 self.assertEqual(mm.getGroupArr(0, 'B').getValues(), [4])
5938 self.assertEqual(mm.getGroupArr(0, 'common').getValues(), [1,5])
5943 def testExtrudedMesh1(self):
5944 fname="Pyfile107.med"
5945 arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5])
5946 mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ) ; mesh3D.setName("mesh")
5947 ex=MEDCouplingMappedExtrudedMesh(mesh3D)
5950 ex2=mm.convertToExtrudedMesh()
5951 mm2=MEDFileMesh.New(fname)
5952 ex3=mm2.convertToExtrudedMesh()
5953 self.assertTrue(ex.isEqual(ex2,1e-12))
5954 self.assertTrue(ex.isEqual(ex3,1e-12))
5957 @unittest.skipUnless(LooseVersion(MEDFileVersionStr())>=LooseVersion('3.2.1'),"This test requires at least MEDFile version 3.2.1")
5959 def testWriteInto30(self):
5960 fname="Pyfile108.med"
5961 fname2="Pyfile109.med"
5962 m=MEDCouplingUMesh("mesh",1) ; m.setCoords(DataArrayDouble([0,0,1,1],2,2)) ; m.allocateCells() ; m.insertNextCell(NORM_SEG2,[1,0])
5963 mm=MEDFileUMesh() ; mm[0]=m
5964 mm.setFamilyId("FAMILLE_ZERO",0)
5967 assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==[3,3]) # checks that just written MED file has a version == 3.0.x
5968 mm2=MEDFileUMesh(fname)
5969 self.assertTrue(mm.isEqual(mm2,1e-12))
5972 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
5975 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
5977 def testPickelizationOfMEDFileObjects1(self):
5978 fname="Pyfile110.med"
5979 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)
5980 m0=MEDCouplingUMesh("Mesh",2)
5982 m0.insertNextCell(NORM_TRI3,[1,4,2])
5983 m0.insertNextCell(NORM_TRI3,[4,5,2])
5984 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
5985 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
5986 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
5987 m0.finishInsertingCells()
5989 m1=MEDCouplingUMesh(m0.getName(),1)
5991 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
5993 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
5995 m1.finishInsertingCells()
5999 m.setMeshAtLevel(0,m0)
6000 m.setMeshAtLevel(-1,m1)
6002 dt=3 ; it=2 ; tim=4.5
6003 fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
6004 fieldNode0.setName("fieldNode0")
6005 fieldNode0.setTime(tim,dt,it)
6006 pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
6007 arr=DataArrayDouble([10,11,12,13,14])
6008 fieldNode0.setArray(arr)
6009 f0=MEDFileField1TS()
6010 f0.setFieldProfile(fieldNode0,m,0,pfl0)
6011 fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
6012 fieldNode1.setName("fieldNode1")
6013 fieldNode1.setTime(tim,dt,it)
6014 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
6015 arr1=DataArrayDouble([20,21,22,23,24,25,26])
6016 fieldNode1.setArray(arr1)
6017 f1=MEDFileField1TS()
6018 f1.setFieldProfile(fieldNode1,m,-1,pfl1)
6020 mfd.setMeshes(MEDFileMeshes()) ; mfd.setFields(MEDFileFields())
6021 mfd.getMeshes().pushMesh(m)
6022 fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(f0)
6023 mfd.getFields().pushField(fmts)
6024 # first start gently
6027 self.assertEqual(len(mfd2.getMeshes()),1)
6028 self.assertEqual(len(mfd2.getFields()),1)
6029 self.assertEqual(len(mfd2.getFields()[0]),1)
6030 self.assertTrue(mfd2.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
6031 ff2=mfd2.getFields()[0][0].field(mfd2.getMeshes()[0])
6032 ff =mfd.getFields()[0][0].field(mfd.getMeshes()[0])
6033 self.assertTrue(ff2.isEqual(ff,1e-12,1e-12))
6034 # OK now end of joke -> serialization of MEDFileData
6035 st=pickle.dumps(mfd,pickle.HIGHEST_PROTOCOL)
6036 mfd3=pickle.loads(st)
6038 self.assertEqual(len(mfd3.getMeshes()),1)
6039 self.assertEqual(len(mfd3.getFields()),1)
6040 self.assertEqual(len(mfd3.getFields()[0]),1)
6041 self.assertTrue(mfd3.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
6042 ff3=mfd3.getFields()[0][0].field(mfd3.getMeshes()[0])
6043 self.assertTrue(ff3.isEqual(ff,1e-12,1e-12))
6044 # serialization of MEDFileFields
6045 st=pickle.dumps(mfd.getFields(),pickle.HIGHEST_PROTOCOL)
6046 fs4=pickle.loads(st)
6047 ff4=fs4[0][0].field(mfd3.getMeshes()[0])
6048 self.assertTrue(ff4.isEqual(ff,1e-12,1e-12))
6049 # serialization of MEDFileFieldMulitTS
6050 st=pickle.dumps(mfd.getFields()[0],pickle.HIGHEST_PROTOCOL)
6051 fmts5=pickle.loads(st)
6052 ff5=fmts5[0].field(mfd3.getMeshes()[0])
6053 self.assertTrue(ff5.isEqual(ff,1e-12,1e-12))
6054 # serialization of MEDFileField1TS
6055 st=pickle.dumps(mfd.getFields()[0][0],pickle.HIGHEST_PROTOCOL)
6056 f1ts6=pickle.loads(st)
6057 ff6=f1ts6.field(mfd3.getMeshes()[0])
6058 self.assertTrue(ff6.isEqual(ff,1e-12,1e-12))
6059 # serialization of MEDFileMeshes
6060 st=pickle.dumps(mfd.getMeshes(),pickle.HIGHEST_PROTOCOL)
6061 ms7=pickle.loads(st)
6062 self.assertEqual(len(ms7),1)
6063 self.assertTrue(ms7[0].isEqual(mfd.getMeshes()[0],1e-12))
6066 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
6068 def testPickelizationOfMEDFileObjects2(self):
6070 self.internalMEDMesh6() # generates MEDFileMesh5.med file
6071 mm=MEDFileMesh.New("MEDFileMesh5.med")
6072 self.assertTrue(isinstance(mm,MEDFileCMesh))
6073 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
6074 mm2=pickle.loads(st)
6075 self.assertTrue(isinstance(mm2,MEDFileCMesh))
6076 self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12))
6078 self.internalCurveLinearMesh1() # generates Pyfile55.med
6079 mm=MEDFileMesh.New("Pyfile55.med")
6080 self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh))
6081 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
6082 mm3=pickle.loads(st)
6083 self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh))
6084 self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12))
6085 self.internalInt32InMEDFileFieldStar1()# generates Pyfile63.med
6086 # MEDFileIntFieldMultiTS
6087 fs4=MEDFileFields("Pyfile63.med")
6088 ms4=MEDFileMeshes("Pyfile63.med")
6089 self.assertTrue(isinstance(fs4[0],MEDFileIntFieldMultiTS))
6090 st=pickle.dumps(fs4[0],pickle.HIGHEST_PROTOCOL)
6091 fmts5=pickle.loads(st)
6092 self.assertEqual(len(fs4[0]),len(fmts5))
6093 self.assertTrue(isinstance(fmts5,MEDFileIntFieldMultiTS))
6094 self.assertTrue(fmts5[0].field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
6095 # MEDFileIntField1TS
6096 st=pickle.dumps(fs4[0][0],pickle.HIGHEST_PROTOCOL)
6097 f1ts6=pickle.loads(st)
6098 self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS))
6099 self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
6101 self.internalParameters1()# generates Pyfile56.med
6102 params=MEDFileParameters("Pyfile56.med")
6103 st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL)
6104 params7=pickle.loads(st)
6105 self.assertEqual(len(params),len(params7))
6106 for i in range(len(params)):
6107 self.assertTrue(params[i].isEqual(params7[i],1e-12)[0])
6112 def testGlobalNumOnNodes1(self):
6113 """Test global number on nodes here. Used by partitionners."""
6114 fname="Pyfile112.med"
6115 arr=DataArrayDouble(5) ; arr.iota()
6116 m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
6120 self.assertTrue(not mm.getGlobalNumFieldAtLevel(1))
6121 d=DataArrayInt([7,8,9,2,0])
6123 mm.setGlobalNumFieldAtLevel(1,d)
6124 mm.checkConsistency()
6125 self.assertRaises(InterpKernelException,mm.setGlobalNumFieldAtLevel,1,d[::2])
6126 mm.checkConsistency()
6127 self.assertEqual(d.getHiddenCppPointer(),mm.getGlobalNumFieldAtLevel(1).getHiddenCppPointer())
6128 self.assertTrue(mm.getGlobalNumFieldAtLevel(1).isEqual(dRef))
6130 mm2=MEDFileMesh.New(fname)
6131 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
6132 self.assertTrue(mm2.getGlobalNumFieldAtLevel(1).isEqual(dRef))
6133 mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,10)
6134 self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
6135 mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,7)
6136 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
6140 def testPartialReadOfEntities1(self):
6141 """Test for advanced API on read to speed up read phase for users with "huge" number of time steps (more than 10 000)."""
6142 fname="Pyfile113.med"
6143 arr=DataArrayDouble(5) ; arr.iota()
6144 m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
6151 f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m) ; f1.setName(fieldName)
6152 f1.setArray(DataArrayDouble([0.,0.1,0.2,0.3,0.4]))
6154 f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m) ; f2.setName(fieldName)
6155 f2.setArray(DataArrayDouble([1.,1.1,1.2,1.3]))
6157 f1ts=MEDFileField1TS()
6158 f1ts.setFieldNoProfileSBT(f1)
6159 f1ts.setFieldNoProfileSBT(f2)
6160 self.assertEqual(set(f1ts.getTypesOfFieldAvailable()),set([ON_NODES,ON_CELLS]))
6161 f1ts_2=f1ts.deepCopy()
6162 f1ts_2.getUndergroundDataArray()[:]+=2
6163 f1ts_2.setTime(3,4,6.)
6164 fmts=MEDFileFieldMultiTS()
6165 fmts.pushBackTimeStep(f1ts)
6166 fmts.pushBackTimeStep(f1ts_2)
6171 ent=MEDFileEntities.BuildFrom([(ON_NODES,NORM_ERROR)])
6172 mm=MEDFileMesh.New(fname)
6173 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)
6175 self.assertEqual(len(fs),1)
6177 self.assertEqual(len(fmts),2)
6178 ff0=fmts[0] ; ff1=fmts[1]
6179 self.assertEqual(ff0.getTypesOfFieldAvailable(),[ON_NODES]) # only NODES have been loaded
6180 self.assertTrue(ff0.field(mm).isEqual(f1,1e-12,1e-12))
6181 f3=f1.deepCopy() ; f3+=2. ; f3.setTime(6.,3,4)
6182 self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
6186 def testFloat32InMEDFileFieldStar1(self):
6187 """Like testInt32InMEDFileFieldStar1 but with float32 :)"""
6188 fname="Pyfile114.med"
6189 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
6190 f1=f1.convertToFloatField()
6192 mm1=MEDFileUMesh.New()
6193 mm1.setCoords(m1.getCoords())
6194 mm1.setMeshAtLevel(0,m1)
6195 mm1.setName(m1.getName())
6197 ff1=MEDFileFloatField1TS()
6198 ff1.setFieldNoProfileSBT(f1)
6199 a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6200 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6201 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6203 a,b=ff1.getUndergroundDataArrayExt()
6204 self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
6205 self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
6206 ff2=MEDFileAnyTypeField1TS.New(fname)
6207 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
6208 self.assertEqual(ff2.getTime(),[0,1,2.0])
6209 self.assertTrue(isinstance(ff2,MEDFileFloatField1TS))
6210 a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6211 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6212 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6214 c=ff2.getUndergroundDataArray() ; c*=2
6215 ff2.write(fname,0) # 2 time steps in
6216 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
6217 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
6218 self.assertEqual(len(ffs1),2)
6219 self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS))
6220 a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6221 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6222 a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
6223 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6224 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
6225 a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6226 self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7))
6227 f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
6228 self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2
6229 bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6231 a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6234 self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7))
6235 nf1=MEDCouplingFieldFloat(ON_NODES)
6236 nf1.setTime(9.,10,-1)
6237 nf1.setMesh(f1.getMesh())
6238 narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
6239 nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
6240 nff1=MEDFileFloatField1TS.New()
6241 nff1.setFieldNoProfileSBT(nf1)
6242 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
6243 self.assertEqual(nff1.getTime(),[10,-1,9.0])
6246 nf2=MEDCouplingFieldFloat(ON_NODES)
6247 nf2.setTime(19.,20,-11)
6248 nf2.setMesh(f1.getMesh())
6249 narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
6250 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
6251 nff2=MEDFileFloatField1TS.New()
6252 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
6253 nff2.setFieldProfile(nf2,mm1,0,npfl)
6254 nff2.getFieldWithProfile(ON_NODES,0,mm1)
6255 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6256 self.assertTrue(b.isEqual(npfl))
6257 self.assertTrue(a.isEqual(narr2,1e-7))
6259 nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl")
6260 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6261 self.assertTrue(b.isEqual(npfl))
6262 self.assertTrue(a.isEqual(narr2,1e-7))
6264 nf3=MEDCouplingFieldDouble(ON_NODES)
6265 nf3.setName("VectorFieldOnNodesDouble")
6266 nf3.setTime(29.,30,-21)
6267 nf3.setMesh(f1.getMesh())
6268 nf3.setArray(f1.getMesh().getCoords())
6269 nff3=MEDFileField1TS.New()
6270 nff3.setFieldNoProfileSBT(nf3)
6272 fs=MEDFileFields(fname)
6273 self.assertEqual(len(fs),4)
6274 ffs=[it for it in fs]
6275 self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS))
6276 self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS))
6277 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
6278 self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS))
6280 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7))
6281 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7))
6282 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7))
6283 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7))
6284 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6286 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
6287 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6288 self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
6289 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
6290 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
6291 self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
6292 MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1)
6293 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
6295 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
6296 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6297 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
6298 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6302 def testPenta18_1(self):
6303 """EDF8478 : Test of read/write of penta18"""
6304 fname="Pyfile115.med"
6305 arr=DataArrayDouble([
6306 (0.,1.,1.),(0.,0.,1.),(1.,0.,1.),
6307 (0.,1.,0.),(0.,0.,0.),(1.,0.,0.),
6308 (0.,0.5,1.),(0.5,0.,1.),(0.5,0.5,1.),
6309 (0.,0.5,0.),(0.5,0.,0.),(0.5,0.5,0.),
6310 (0.,1.,0.5),(0.,0.,0.5),(1.,0.,0.5),
6311 (0.,0.5,0.5),(0.5,0.,0.5),(0.5,0.5,0.5)])
6312 m=MEDCouplingUMesh("mesh",3)
6315 m.insertNextCell(NORM_PENTA18,list(range(18)))
6316 m.checkConsistencyLight()
6318 f=MEDCouplingFieldDouble(ON_NODES)
6320 f.setName("FieldOnPenta18")
6321 f.setArray(DataArrayDouble(list(range(18))))
6322 f.checkConsistencyLight()
6324 m2,d,di,rd,rdi=m.buildDescendingConnectivity()
6326 f2=MEDCouplingFieldDouble(ON_NODES)
6328 f2.setName("FieldOnPenta18Sub")
6329 f2.setArray(DataArrayDouble(list(range(18))))
6330 f2.checkConsistencyLight()
6331 WriteField(fname,f2,True)
6333 self.assertTrue(f2.isEqual(f3,1e-12,1e-12))
6334 self.assertEqual(f3.getMesh().getNumberOfCells(),1)
6335 self.assertEqual(f3.getMesh().getTypeOfCell(0),NORM_PENTA18)
6339 def testFieldsLinearToQuadratic(self):
6340 fname="Pyfile117.med"
6341 arr=DataArrayDouble([0,1])
6342 m=MEDCouplingCMesh();
6343 m.setCoords(arr,arr,arr)
6344 m=m.buildUnstructured()
6346 m2.translate([2,0,0])
6347 m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6351 mmq=mm.linearToQuadratic(0)
6352 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6353 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6355 f=MEDCouplingFieldDouble(ON_NODES)
6359 arr=DataArrayDouble(m3.getNumberOfNodes())
6362 f1ts=MEDFileField1TS()
6363 f1ts.setFieldNoProfileSBT(f)
6364 fmts=MEDFileFieldMultiTS()
6365 fmts.pushBackTimeStep(f1ts)
6366 f1ts_2=f1ts.deepCopy()
6367 f1ts_2.setTime(3,4,5.)
6368 f1ts_2.getUndergroundDataArray()[:]*=2.
6369 fmts.pushBackTimeStep(f1ts_2)
6372 fs2=fs.linearToQuadratic(mms,mmsq)
6373 self.myTester1(fs2,mmsq[0])
6374 # A small Write/Read and test again
6375 mms.write(fname,2) ; fs.write(fname,0)
6376 mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6377 mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6378 fs2=fs.linearToQuadratic(mms,mmqs)
6379 self.myTester1(fs2,mmqs[0])
6382 def myTester1(self,fs2,mmq):
6383 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)
6384 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])
6385 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])
6386 fToTest=fs2[0][0].field(mmq)
6387 self.assertEqual(fToTest.getTime(),[3.,1,2])
6388 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6389 self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6390 self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6391 self.assertTrue(fToTest.getArray().isEqual(dataExp2,1e-12))
6392 # testing 2nd timestep
6393 fToTest=fs2[0][1].field(mmq)
6394 self.assertEqual(fToTest.getTime(),[5.,3,4])
6395 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6396 self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6397 self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6398 self.assertTrue(fToTest.getArray().isEqual(2*dataExp2,1e-12))
6402 def testFieldsLinearToQuadratic2(self):
6403 """Same than testFieldsLinearToQuadratic but with profile on NODES"""
6404 GeneratePyfile18(self)
6405 fname="Pyfile118.med"
6406 arr=DataArrayDouble([0,1])
6407 m=MEDCouplingCMesh();
6408 m.setCoords(arr,arr,arr)
6409 m=m.buildUnstructured()
6411 m2.translate([2,0,0])
6412 m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6414 # add a point for fun
6415 m3.setCoords(DataArrayDouble.Aggregate(m3.getCoords(),DataArrayDouble([1.5,1.5,1.5],1,3)))
6419 mmq=mm.linearToQuadratic(0)
6420 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6421 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6423 f=MEDCouplingFieldDouble(ON_NODES)
6427 arr=DataArrayDouble(8) ; arr.iota()
6430 f1ts=MEDFileField1TS()
6431 pfl=DataArrayInt([8,9,10,11,12,13,14,15]) ; pfl.setName("pfl")
6432 f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 8 nodes of cell #1
6433 f1ts_2=f1ts.deepCopy()
6434 f1ts_2.setTime(3,4,5.)
6435 f1ts_2.getUndergroundDataArray()[:]*=4.
6436 fmts=MEDFileFieldMultiTS()
6437 fmts.pushBackTimeStep(f1ts)
6438 fmts.pushBackTimeStep(f1ts_2)
6441 fs2=fs.linearToQuadratic(mms,mmsq)
6442 mms.write(fname,2) ; fs.write(fname,0)
6444 self.myTester2(fs2,mmq)
6446 mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6447 mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6448 fs2=fs.linearToQuadratic(mms,mmqs)
6449 self.myTester2(fs2,mmq)
6450 ## More vicious add single node 16
6453 mmq=mm.linearToQuadratic(0)
6454 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6455 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6457 f=MEDCouplingFieldDouble(ON_NODES)
6461 arr=DataArrayDouble(9) ; arr.iota()
6464 f1ts=MEDFileField1TS()
6465 pfl=DataArrayInt([8,9,10,11,12,13,14,15,16]) ; pfl.setName("pfl")
6466 f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 9 nodes of cell #1 + orphan node
6467 fmts=MEDFileFieldMultiTS()
6468 fmts.pushBackTimeStep(f1ts)
6471 fs2=fs.linearToQuadratic(mms,mmsq)
6473 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")
6474 f1tsToTest=fs2[0][0]
6475 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])
6476 assert(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6477 assert(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6478 assert(f1tsToTest.getFieldSplitedByType()==[(40,[(1,(0,21),'pfl_NODE','')])])
6481 def myTester2(self,fs2,mmq):
6482 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")
6483 f1tsToTest=fs2[0][0]
6484 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])
6485 self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6486 self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6487 self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6488 fToTest=fs2[0][0].field(mmq)
6489 self.assertEqual(fToTest.getTime(),[3.,1,2])
6490 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6491 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])))
6492 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))
6493 self.assertTrue(fToTest.getArray().isEqual(exp1,1e-12))
6495 f1tsToTest=fs2[0][1]
6496 self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6497 self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(4*exp1,1e-12))
6498 self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6499 fToTest=fs2[0][1].field(mmq)
6500 self.assertEqual(fToTest.getTime(),[5.,3,4])
6501 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6502 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])))
6503 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))
6504 self.assertTrue(fToTest.getArray().isEqual(4*exp1,1e-12))
6509 def testSetFieldProfileFlatly1(self):
6510 """ 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
6512 arr=DataArrayDouble(10) ; arr.iota()
6513 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
6514 m=m.buildUnstructured()
6517 m=MEDCouplingUMesh.MergeUMeshes(m2,m)
6521 f=MEDCouplingFieldDouble(ON_CELLS)
6523 arr=DataArrayDouble(m.getNumberOfCells())
6527 pfl=DataArrayInt(m.getNumberOfCells()) ; pfl.iota() ; pfl.setName("pfl")
6529 refSp=[(3,[(0,(0,162),'','')]),(4,[(0,(162,243),'','')])]
6530 refSp1=[(3,[(0,(0,162),'pfl_NORM_TRI3','')]),(4,[(0,(162,243),'pfl_NORM_QUAD4','')])]
6532 f1ts=MEDFileField1TS()
6533 f1ts.setFieldProfile(f,mm,0,pfl)
6534 self.assertEqual(f1ts.getPfls(),()) # here setFieldProfile has detected useless pfl -> no pfl
6535 self.assertEqual(f1ts.getFieldSplitedByType(),refSp)
6536 self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
6538 f1ts=MEDFileField1TS()
6539 f1ts.setFieldProfileFlatly(f,mm,0,pfl) # no optimization attempt. Create pfl unconditionally
6540 self.assertEqual(f1ts.getPfls(),("%s_NORM_TRI3"%pfl.getName(),"%s_NORM_QUAD4"%pfl.getName()))
6541 self.assertEqual(f1ts.getFieldSplitedByType(),refSp1)
6542 self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
6543 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3").isIota(162))
6544 self.assertTrue(f1ts.getProfile("pfl_NORM_QUAD4").isIota(81))
6548 def testRmGroupAtSpeLevelAndMultiLevGrpCreation(self):
6549 """ Here multi level groups are created"""
6550 arr=DataArrayDouble(11) ; arr.iota()
6551 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
6552 m=m.buildUnstructured()
6554 m1=m.buildDescendingConnectivity()[0]
6559 grp0_0=DataArrayInt([0,1,2,6]) ; grp0_0.setName(grpName)
6560 grp0_1=DataArrayInt([0,1,2,7]) ; grp0_1.setName(grpName)
6561 grp1=DataArrayInt([1,2,3,5,6]) ; grp1.setName("grp1")
6562 grp2=DataArrayInt([2,3,5,8]) ; grp2.setName("grp2")
6563 ################ ajouter un groupe sur plusieurs niveau
6565 mm.addGroup(-1,grp2)
6566 mm.addGroup(0,grp0_0)
6567 mm.addGroup(-1,grp0_1)
6568 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
6569 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6570 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6571 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6572 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6573 self.assertRaises(InterpKernelException,mm.addGroup,-1,grp0_1) # raise
6574 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6575 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6576 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6577 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6578 mm.removeGroupAtLevel(0,grpName)
6579 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(-1,))
6580 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6581 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6582 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6583 mm.removeGroupAtLevel(-1,grpName)
6584 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),())
6585 self.assertRaises(InterpKernelException,mm.removeGroupAtLevel,-2,grpName)
6586 mm.addGroup(-1,grp0_1)
6587 mm.addGroup(0,grp0_0)
6588 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
6589 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6590 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6591 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6592 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6596 def testYutaka(self):
6597 """ 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...
6598 Then rearrange method removes unused entites by putting 0 on them -> Previously group has been modified by rearrange. Should not !"""
6600 m=MEDCouplingCMesh()
6601 arr=DataArrayDouble(4) ; arr.iota()
6602 m.setCoords(arr,arr,arr)
6603 m=m.buildUnstructured()
6606 m=m.buildUnstructured()
6607 m1=m.buildDescendingConnectivity()[0]
6613 grp0=DataArrayInt([0,1,2]) ; grp0.setName("grp0")
6615 grp1=DataArrayInt([3,4,5,6]) ; grp1.setName("grp1")
6617 grp2=DataArrayInt([7,8,9]) ; grp2.setName("grp2")
6619 grp3=DataArrayInt.Range(0,m1.getNumberOfCells(),1) ; grp3.setName("grp3")
6620 mm.addGroup(-1,grp3)
6621 self.assertNotIn(0,mm.getFamiliesIdsOnGroup("grp3")) # bug was here !
6622 grp4=DataArrayInt([3,5,8,10]) ; grp4.setName("grp4")
6623 mm.addNodeGroup(grp4)
6624 mm.rearrangeFamilies()
6625 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp0"),(0,))
6626 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp1"),(0,))
6627 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp2"),(0,))
6628 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp3"),(-1,))
6629 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp4"),(1,))
6631 for grp in [grp0,grp1,grp2,grp3,grp4]:
6632 self.assertTrue(mm.getGroupArr(mm.getGrpNonEmptyLevelsExt(grp.getName())[0],grp.getName()).isEqual(grp))
6637 def testContxtMger1TS(self):
6638 fname="Pyfile119.med"
6639 coo=DataArrayDouble(1000) ; coo.iota()
6640 m=MEDCouplingUMesh.Build0DMeshFromCoords(coo)
6642 WriteMesh(fname,m,True)
6643 f=MEDCouplingFieldDouble(ON_CELLS)
6646 arr=DataArrayDouble(m.getNumberOfCells())
6648 f.checkConsistencyLight()
6651 f.setTime(float(i),i,0)
6652 WriteFieldUsingAlreadyWrittenMesh(fname,f)
6655 mm=MEDFileMesh.New(fname)
6656 fmts=MEDFileFieldMultiTS(fname,False)
6657 refSize=fmts.getHeapMemorySize()
6663 self.assertIn(fmts.getHeapMemorySize(),range(refSize,refSize+refSize//10))
6666 def testZipFamilies1(self):
6668 MEDFileMesh.zipFamilies tries to reduce family partitions under groups.
6671 arr=DataArrayDouble(10) ; arr.iota()
6672 m=MEDCouplingCMesh()
6673 m.setCoords(arr,arr)
6674 m=m.buildUnstructured()
6679 for i in range(m.getNumberOfCells()):
6680 d = DataArrayInt([i])
6681 d.setName("grp%d"%i)
6685 grp_all = DataArrayInt.Range(0,m.getNumberOfCells(),1)
6686 grp_all.setName("grp_all")
6687 mm.addGroup(0,grp_all)
6688 for i in range(m.getNumberOfCells()):
6689 mm.removeGroup("grp{}".format(i))
6692 mm.zipFamilies() # the method to test
6694 self.assertEqual(mm.getGroupsNames(),("grp_all",))
6695 self.assertEqual(len(mm.getFamiliesNames()),1)
6696 self.assertTrue(mm.getGroupArr(0,"grp_all").isEqualWithoutConsideringStr(DataArrayInt.Range(0,81,1)))
6699 def testZipFamilies2(self):
6701 MEDFileMesh.zipFamilies tries to reduce family partitions under groups.
6704 arr=DataArrayDouble(21) ; arr.iota()
6705 m=MEDCouplingCMesh()
6707 m=m.buildUnstructured()
6712 # 1 and 3 to be merged
6713 # 2 and 5 to be merged
6714 mm.setFamilyFieldArr(0,DataArrayInt([-1,-1,-2,-3,-8, 0,-7,-7,-1,0, -6,-2,-5,-5,-2, -2,-2,-5,-4,-3]))
6715 for i in range(1,9):
6716 mm.setFamilyId("Fam_{}".format(i),-i)
6717 mm.setFamiliesOnGroup("grp0",["Fam_1","Fam_3","Fam_6"])
6718 mm.setFamiliesOnGroup("grp1",["Fam_1","Fam_2","Fam_3","Fam_5","Fam_6"])
6719 mm.setFamiliesOnGroup("grp2",["Fam_2","Fam_5","Fam_6","Fam_7"])
6721 grp0=DataArrayInt([0,1,3,8,10,19])
6722 grp1=DataArrayInt([0,1,2,3,8,10,11,12,13,14,15,16,17,19])
6723 grp2=DataArrayInt([2,6,7,10,11,12,13,14,15,16,17])
6724 self.assertTrue(mm.getGroupArr(0,"grp0").isEqualWithoutConsideringStr(grp0))
6725 self.assertTrue(mm.getGroupArr(0,"grp1").isEqualWithoutConsideringStr(grp1))
6726 self.assertTrue(mm.getGroupArr(0,"grp2").isEqualWithoutConsideringStr(grp2))
6727 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2'))
6729 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2'))
6730 self.assertTrue(mm.getGroupArr(0,"grp0").isEqualWithoutConsideringStr(grp0))
6731 self.assertTrue(mm.getGroupArr(0,"grp1").isEqualWithoutConsideringStr(grp1))
6732 self.assertTrue(mm.getGroupArr(0,"grp2").isEqualWithoutConsideringStr(grp2))
6733 self.assertEqual(mm.getFamiliesNames(),('Fam_1','Fam_2','Fam_6','Fam_7'))
6736 def testMeshConvertFromMEDFileGeoType(self):
6737 self.assertEqual(MEDFileMesh.ConvertFromMEDFileGeoType(320),NORM_HEXA20)
6741 if __name__ == "__main__":