1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2024 CEA, EDF
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) # EDF26299
119 self.assertTrue(medmesh.getNodeFamilyArr(famn,True).isEqualWithoutConsideringStr(DataArrayInt([])))
121 self.assertEqual([2,3,5,14,16],medmesh.getGroupArr(0,"mesh2").getValues());
122 self.assertEqual([2,3,16],medmesh.getFamilyArr(0,"Family_-3").getValues());
123 self.assertEqual([2,3,5,14,16],medmesh.getFamiliesArr(0,["Family_-5","Family_-3"]).getValues());
124 self.assertEqual([0,2,3,4,5,14,15,16],medmesh.getGroupsArr(0,["mesh2","mesh3","mesh4"],False).getValues());
125 #self.assertRaises(InterpKernelException,medmesh.getNodeFamilyArr,famn,False) # EDF26299
126 self.assertTrue(medmesh.getNodeFamilyArr(famn,False).isEqualWithoutConsideringStr(DataArrayInt([])))
129 # this tests emulates MEDMEM ( Except that it works ! ) The permutation are NOT taken into account
131 def testMEDMesh3(self):
132 outFileName="MEDFileMesh3.med"
133 c=DataArrayDouble.New()
134 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 ];
135 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
136 c.setValues(coords,9,2)
137 m=MEDCouplingUMesh.New();
138 m.setMeshDimension(2);
140 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
141 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
142 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
143 m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
144 m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
145 m.finishInsertingCells();
147 m.checkConsistencyLight()
148 m1=MEDCouplingUMesh.New();
149 m1.setMeshDimension(1);
151 m1.insertNextCell(NORM_SEG2,2,[1,4])
152 m1.insertNextCell(NORM_SEG2,2,[3,6])
153 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
154 m1.finishInsertingCells();
156 m1.checkConsistencyLight()
157 m2=MEDCouplingUMesh.New();
158 m2.setMeshDimension(0);
160 m2.insertNextCell(NORM_POINT1,1,[1])
161 m2.insertNextCell(NORM_POINT1,1,[3])
162 m2.insertNextCell(NORM_POINT1,1,[2])
163 m2.insertNextCell(NORM_POINT1,1,[6])
164 m2.finishInsertingCells();
166 m2.checkConsistencyLight()
168 mm=MEDFileUMesh.New()
169 self.assertTrue(mm.getUnivNameWrStatus())
170 mm.setName("MyFirstMEDCouplingMEDmesh")
171 mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
173 mm.setMeshAtLevel(-1,m1);
174 mm.setMeshAtLevel(0,m);
175 mm.setMeshAtLevel(-2,m2);
176 # playing with groups
177 g1_2=DataArrayInt.New()
178 g1_2.setValues([1,3],2,1)
180 g2_2=DataArrayInt.New()
181 g2_2.setValues([1,2,3],3,1)
183 mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
184 g1_1=DataArrayInt.New()
185 g1_1.setValues([0,1,2],3,1)
187 g2_1=DataArrayInt.New()
188 g2_1.setValues([0,2],2,1)
190 mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
191 g1_N=DataArrayInt.New()
192 g1_N.setValues(list(range(8)),8,1)
194 g2_N=DataArrayInt.New()
195 g2_N.setValues(list(range(9)),9,1)
197 mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
198 mm.createGroupOnAll(0,"GrpOnAllCell")
199 # check content of mm
200 t=mm.getGroupArr(0,"G1",False)
201 self.assertTrue(g1_2.isEqual(t));
202 t=mm.getGroupArr(0,"G2",False)
203 self.assertTrue(g2_2.isEqual(t));
204 t=mm.getGroupArr(-1,"G1",False)
205 self.assertTrue(g1_1.isEqual(t));
206 t=mm.getGroupArr(-1,"G2",False)
207 self.assertTrue(g2_1.isEqual(t));
208 t=mm.getGroupArr(1,"G1",False)
209 self.assertTrue(g1_N.isEqual(t));
210 t=mm.getGroupArr(1,"G2",False)
211 self.assertTrue(g2_N.isEqual(t));
212 self.assertTrue(mm.existsGroup("GrpOnAllCell"));
213 t=mm.getGroupArr(0,"GrpOnAllCell")
214 self.assertTrue(t.getValues()==list(range(5)))
217 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0]) ; del mm
218 mmCpy.write(outFileName,2);
220 mm=MEDFileMesh.New(outFileName)
222 self.assertEqual([NORM_TRI3,NORM_QUAD4,NORM_POLYGON],mm.getGeoTypesAtLevel(0))
223 self.assertEqual([NORM_SEG2,NORM_SEG3],mm.getGeoTypesAtLevel(-1))
224 self.assertEqual([NORM_POINT1],mm.getGeoTypesAtLevel(-2))
225 mm0=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POLYGON)
226 self.assertTrue(isinstance(mm0,MEDCoupling1DGTUMesh))
227 self.assertTrue(mm0.getNodalConnectivity().isEqual(DataArrayInt([6,7,4,3,7,8,5,4])))
228 self.assertTrue(mm0.getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8])))
229 lmm=mm.getDirectUndergroundSingleGeoTypeMeshes(0)
230 self.assertEqual(3,len(lmm))
231 self.assertTrue(isinstance(lmm[0],MEDCoupling1SGTUMesh))
232 self.assertTrue(isinstance(lmm[1],MEDCoupling1SGTUMesh))
233 self.assertTrue(isinstance(lmm[2],MEDCoupling1DGTUMesh))
235 self.assertTrue(mm.getUnivNameWrStatus())
236 self.assertTrue(isinstance(mm.getUnivName(),str))
237 self.assertTrue(len(mm.getUnivName())!=0)
238 mbis=mm.getMeshAtLevel(0)
239 m.setName(mm.getName()) ; m.setDescription(mm.getDescription())
240 self.assertTrue(m.isEqual(mbis,1e-12));
242 self.assertEqual(([[(3, 2), (4, 1), (5, 8)], [(1, 2), (2, 1)], [(0, 4)]], 2, 2, 9),GetUMeshGlobalInfo(outFileName,"MyFirstMEDCouplingMEDmesh"))
245 # this test is the testMEDMesh3 except that permutation is dealed here
247 def testMEDMesh4(self):
248 outFileName="MEDFileMesh4.med"
249 c=DataArrayDouble.New()
250 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 ];
251 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
252 c.setValues(coords,9,2)
253 c.setInfoOnComponent(0,"abcdef [km]")
254 c.setInfoOnComponent(1,"ghij [MW]")
255 m=MEDCouplingUMesh.New();
256 m.setMeshDimension(2);
258 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
259 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
260 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
261 m.insertNextCell(NORM_QUAD4,4,targetConn[10:14])
262 m.insertNextCell(NORM_QUAD4,4,targetConn[14:18])
263 m.finishInsertingCells();
265 m.checkConsistencyLight()
266 m1=MEDCouplingUMesh.New();
267 m1.setMeshDimension(1);
269 m1.insertNextCell(NORM_SEG2,2,[1,4])
270 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
271 m1.insertNextCell(NORM_SEG2,2,[3,6])
272 m1.finishInsertingCells();
274 m1.checkConsistencyLight()
275 m2=MEDCouplingUMesh.New();
276 m2.setMeshDimension(0);
278 m2.insertNextCell(NORM_POINT1,1,[1])
279 m2.insertNextCell(NORM_POINT1,1,[3])
280 m2.insertNextCell(NORM_POINT1,1,[2])
281 m2.insertNextCell(NORM_POINT1,1,[6])
282 m2.finishInsertingCells();
284 m2.checkConsistencyLight()
286 mm=MEDFileUMesh.New()
287 mm.setName("My2ndMEDCouplingMEDmesh")
288 mm.setDescription("ThisIsImpossibleToDoWithMEDMEM")
290 renumNode=DataArrayInt.New()
291 renumNode.setValues([10,11,12,13,14,15,16,17,18],9,1)
292 mm.setRenumFieldArr(1,renumNode)
294 mm.setMeshAtLevel(-1,m1,True);
295 mm.setMeshAtLevel(0,m,True);
296 mm.setMeshAtLevel(-2,m2,True);
297 mm.removeMeshAtLevel(-2)
298 mm.setMeshAtLevel(-2,m2,True);
299 # playing with groups
300 g1_2=DataArrayInt.New()
301 g1_2.setValues([2,3],2,1)
303 g2_2=DataArrayInt.New()
304 g2_2.setValues([2,0,3],3,1)
306 mm.setGroupsAtLevel(0,[g1_2,g2_2],True)
307 g1_1=DataArrayInt.New()
308 g1_1.setValues([0,2,1],3,1)
310 g2_1=DataArrayInt.New()
311 g2_1.setValues([0,2],2,1)
313 mm.setGroupsAtLevel(-1,[g1_1,g2_1],True)
314 g1_N=DataArrayInt.New()
315 g1_N.setValues([10,11,12,13,14,15,16,17],8,1)
317 g2_N=DataArrayInt.New()
318 g2_N.setValues([10,11,12,13,14,15,16,17,18],9,1)
320 mm.setGroupsAtLevel(1,[g1_N,g2_N],True)
321 # check content of mm
322 t=mm.getGroupArr(0,"G1",True)
323 self.assertTrue(g1_2.isEqual(t));
324 t=mm.getGroupArr(0,"G2",True)
325 self.assertTrue(g2_2.isEqual(t));
326 t=mm.getGroupArr(-1,"G1",True)
327 self.assertTrue(g1_1.isEqual(t));
328 t=mm.getGroupArr(-1,"G2",True)
329 self.assertTrue(g2_1.isEqual(t));
330 self.assertTrue(not mm.existsGroup("GrpOnAllCell"));
332 mm.write(outFileName,2);
333 mm2=MEDFileMesh.New(outFileName)
334 res=mm.isEqual(mm2,1e-12)
335 self.assertTrue(res[0])
336 l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
337 self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
338 mm2.keepFamIdsOnlyOnLevs([3],[-1])
339 for lev in mm.getGrpNonEmptyLevelsExt("G2"):
340 self.assertEqual(mm.getGroupArr(lev,"G2").getValues(),mm2.getGroupArr(lev,"G2").getValues())
342 l=list(mm2.getFamiliesOnGroup("G2")) ; l.sort()
343 self.assertEqual(['Family_-3','Family_-4','Family_-7','Family_10','Family_11'],l)
345 self.assertEqual([-7,-7,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
346 mm2.getFamilyFieldAtLevel(-1).setIJ(1,0,-8)
347 self.assertEqual([-7,-8,-6],mm2.getFamilyFieldAtLevel(-1).getValues())
348 self.assertTrue(not mm2.existsFamily("Family_-8"))
349 mm2.createGroupOnAll(-1,"GrpOnAllFace")
350 self.assertTrue(mm2.existsFamily("Family_-8"))
351 self.assertEqual(list(range(3)),mm2.getGroupArr(-1,"GrpOnAllFace").getValues())
354 #testing persistence of retrieved arrays
356 def testMEDMesh5(self):
357 GeneratePyfile18(self)
358 fileName="Pyfile18.med"
359 mname="ExampleOfMultiDimW"
360 medmesh=MEDFileUMesh.New(fileName,mname)
361 m1_0=medmesh.getLevel0Mesh(True)
362 da1=medmesh.getFamilyFieldAtLevel(0)
364 self.assertEqual(20,m1_0.getNumberOfCells())
365 self.assertEqual(20,da1.getNumberOfTuples())
368 def internalMEDMesh6(self):
369 outFileName="MEDFileMesh5.med"
372 m1=MEDCouplingCMesh.New();
373 da=DataArrayDouble.New()
374 da.setValues([0.,1.,2.],3,1)
375 da.setInfoOnComponent(0,"XX [mm]")
377 da=DataArrayDouble.New()
378 da.setValues([0.,1.2],2,1)
379 da.setInfoOnComponent(0,"YY [km]")
381 da=DataArrayDouble.New()
382 da.setValues([0.,1.3],2,1)
383 da.setInfoOnComponent(0,"ZZ [um]")
386 self.assertTrue(m[0].isEqual(m1,1e-12))
387 self.assertTrue(isinstance(m[0],MEDCouplingCMesh))
388 m.setName("myFirstCartMesh")
389 m.setDescription("mmmmpppppppp")
392 da=DataArrayInt.New()
393 da.setValues([0,0,1,0,1,2,4,3,0,1,2,2],12,1)
394 m.setFamilyFieldArr(1,da)
395 m.setFamilyId("family1",1)
396 da=m.getFamilyArr(1,"family1")
398 self.assertEqual(expected1,da.getValues())
399 self.assertTrue(m.getUnivNameWrStatus())
400 m.write(outFileName,2);
401 mm=MEDFileMesh.New(outFileName)
402 self.assertEqual([NORM_HEXA8],mm.getGeoTypesAtLevel(0))
403 self.assertTrue(isinstance(mm,MEDFileCMesh))
404 self.assertTrue(isinstance(mm.getUnivName(),str))
405 self.assertTrue(len(mm.getUnivName())!=0)
406 self.assertTrue(m.isEqual(mm,1e-12)[0])
407 self.assertEqual(expected1,mm.getFamilyArr(1,"family1").getValues())
410 m1.setTime(tt[2],tt[0],tt[1])
411 m1.setName(m.getName())
412 m1.setTimeUnit(m.getTimeUnit())
413 m1.setDescription(m.getDescription())
414 self.assertTrue(m2.isEqual(m1,1e-12));
417 def testMEDMesh6(self):
418 self.internalMEDMesh6()
422 def testMEDMesh7(self):
423 fileName="Pyfile24.med"
424 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
426 m.setCoords(m2.getCoords())
427 m.setMeshAtLevel(0,m2)
428 m.setMeshAtLevel(-1,m1)
429 m.setMeshAtLevel(-2,m0)
430 m.setFamilyFieldArr(0,f2)
431 m.setFamilyFieldArr(-1,f1)
432 m.setFamilyFieldArr(-2,f0)
433 m.setFamilyFieldArr(1,p)
434 m.setRenumFieldArr(0,n2)
435 m.setRenumFieldArr(-1,n1)
436 m.setRenumFieldArr(-2,n0)
438 for i in range(nbOfFams):
439 m.addFamily(fns[i],fids[i])
442 for i in range(nbOfGrps):
443 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
445 m.setName(m2.getName())
446 m.setDescription(m2.getDescription())
448 self.assertEqual((-1,),m.getGrpNonEmptyLevels("A2A4"))
449 self.assertEqual((),m.getGrpNonEmptyLevels("A1"))
450 self.assertEqual((-2,),m.getGrpNonEmptyLevels("AP2"))
451 self.assertEqual((-1,-2),m.getGrpsNonEmptyLevels(["A2A4","AP2"]))
452 self.assertEqual((-1,),m.getFamNonEmptyLevels('A4A3____________________________'))
453 self.assertEqual((0,),m.getFamNonEmptyLevels('MESH____DALT3___DALLE___________'))
454 self.assertEqual((0,-1,),m.getFamsNonEmptyLevels(['MESH____DALT3___DALLE___________','A4A3____________________________']))
455 self.assertEqual(('A1A2','A2A4','A3A1','A3C5','A4A3','B1C1','B2B4','B3B1','B4C3','C1C4','C2B2','C3C2','C4B3','C5A4'),m.getGroupsOnSpecifiedLev(-1))
456 self.assertEqual(('DALLE','DALQ1','DALQ2','DALT3','MESH'),m.getGroupsOnSpecifiedLev(0))
459 self.assertRaises(InterpKernelException,MEDFileField1TS,fileName)#throw because no field in file fileName
462 def funcToTestDelItem(self,ff):
466 #emulation of pointe.med file.
468 def testMEDField1(self):
469 TestMultiFieldShuffleRW1(self)
470 mm=MEDFileMesh.New("Pyfile17.med")
471 mm.write("Pyfile17_bis.med",2)
472 ff=MEDFileFieldMultiTS("Pyfile17.med")
473 tsExpected=[[1,2],[3,4],[5,6]]
474 self.assertEqual(3,len(ff))
475 for pos,f1ts in enumerate(ff):
476 self.assertEqual(tsExpected[pos],f1ts.getTime()[:2])
477 self.assertEqual(type(f1ts),MEDFileField1TS)
479 self.assertEqual("MeasureOfMesh_Extruded",ff.getName())
480 self.assertEqual([3,4],ff[1].getTime()[:-1])
481 self.assertEqual([3,4],ff[3,4].getTime()[:-1])
482 self.assertEqual([3,4],ff[0.01].getTime()[:-1])
483 ff.write("Pyfile17_bis.med",0)
485 ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
486 self.assertEqual([(1,2),(3,4),(5,6)],ts)
487 self.funcToTestDelItem(ff)
488 ts=ff.getTimeSteps() ; ts=[elt[:-1] for elt in ts]
489 self.assertEqual([(1,2)],ts)
494 def testMEDField2(self):
495 GeneratePyfile19(self)
496 mm=MEDFileMesh.New("Pyfile19.med")
497 mm.write("Pyfile19_bis.med",2)
498 ff=MEDFileFieldMultiTS.New("Pyfile19.med")
499 ff.write("Pyfile19_bis.med",0)
500 self.assertEqual([('tyty','mm'),('uiop','MW')],GetComponentsNamesOfField("Pyfile19_bis.med","VFieldOnNodes"))
505 def testMEDField3(self):
506 GeneratePyfile13(self)
507 mm=MEDFileMesh.New("Pyfile13.med")
508 mm.write("Pyfile13_bis.med",2)
509 ff=MEDFileFieldMultiTS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
510 ff.write("Pyfile13_bis.med",0)
511 ff=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint",1,5)
512 f=ff.getFieldAtLevel(ON_GAUSS_PT,0)
513 f2=ReadFieldGauss("Pyfile13.med",'2DMesh_2',0,'MyFirstFieldOnGaussPoint',1,5)
514 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
515 ff3=MEDFileField1TS.New("Pyfile13.med","MyFirstFieldOnGaussPoint")
516 f3=ff3.getFieldAtLevel(ON_GAUSS_PT,0)
517 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
518 ff4=MEDFileField1TS.New("Pyfile13.med")
519 f4=ff4.getFieldAtLevel(ON_GAUSS_PT,0)
520 self.assertTrue(f.isEqual(f4,1e-12,1e-12))
525 def testMEDField4(self):
526 GeneratePyfile14(self)
527 mm=MEDFileMesh.New("Pyfile14.med")
528 mm.write("Pyfile14_bis.med",2)
529 ff=MEDFileFieldMultiTS.New("Pyfile14.med","MyFieldOnGaussNE")
530 ff.write("Pyfile14_bis.med",0)
531 ff=MEDFileField1TS.New("Pyfile14.med","MyFieldOnGaussNE",1,5)
532 f=ff.getFieldAtLevel(ON_GAUSS_NE,0)
533 f2=ReadFieldGaussNE("Pyfile14.med",'2DMesh_2',0,"MyFieldOnGaussNE",1,5)
534 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
537 # MEDField get/set on pointe.med
539 def testMEDField5(self):
540 TestMultiFieldShuffleRW1(self)
541 ff=MEDFileField1TS.New("Pyfile17.med","MeasureOfMesh_Extruded",1,2)
542 f=ff.getFieldAtLevel(ON_CELLS,0)
543 f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
544 self.assertTrue(f.getMesh().getCoords().isEqual(f2.getMesh().getCoords(),1e-12))
545 f.getMesh().tryToShareSameCoords(f2.getMesh(),1e-12)
546 f.changeUnderlyingMesh(f2.getMesh(),22,1e-12)
547 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
548 # no with renumbering
549 f=ff.getFieldAtLevel(ON_CELLS,0,1)
550 f2=ReadFieldCell("Pyfile17.med","Extruded",0,"MeasureOfMesh_Extruded",1,2)
551 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
552 f=ff.getFieldAtLevel(ON_CELLS,0,3)
553 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
554 f=ff.getFieldAtLevel(ON_CELLS,0,2)
555 self.assertTrue(not f.isEqual(f2,1e-12,1e-12))
556 f.changeUnderlyingMesh(f2.getMesh(),12,1e-12)
557 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
560 # MEDField get/set on profiles nodes
562 def testMEDField6(self):
563 GeneratePyfile7(self)
564 ff=MEDFileFieldMultiTS.New("Pyfile7.med","VectorFieldOnNodes")
565 its=ff.getIterations()
566 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
567 f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
568 f2=ReadFieldNode("Pyfile7.med",'3DSurfMesh_1',0,"VectorFieldOnNodes",its[0][0],its[0][1])
569 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
570 GeneratePyfile19(self)
571 ff=MEDFileFieldMultiTS.New("Pyfile19.med","VFieldOnNodes")
572 its=ff.getIterations()
573 f=ff.getFieldAtLevel(ON_NODES,its[0][0],its[0][1],0)
574 f2=ReadFieldNode("Pyfile19.med",'2DMesh_1',0,"VFieldOnNodes",its[0][0],its[0][1])
575 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
576 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_CELLS,its[0][0],its[0][1],0)# request on cell and it is not on cells
577 self.assertRaises(InterpKernelException,ff.getFieldAtLevel,ON_NODES,its[0][0],its[0][1],0,1)#request renumber following mesh : it is on profile !
580 # MEDField get/set on profiles cells
582 def testMEDField7(self):
583 GeneratePyfile12(self)
584 ff=MEDFileFieldMultiTS.New("Pyfile12.med","VectorFieldOnCells")
585 its=ff.getIterations()
586 f=ff.getFieldAtLevel(ON_CELLS,its[0][0],its[0][1],0)
587 f2=ReadFieldCell("Pyfile12.med",'3DMesh_1',0,"VectorFieldOnCells",its[0][0],its[0][1])
588 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
591 #first test of assignation. No profile and types sorted by type.
593 def testMEDField8(self):
595 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
597 mm1=MEDFileUMesh.New()
598 mm1.setCoords(m1.getCoords())
599 mm1.setMeshAtLevel(0,m1)
600 mm1.setName(m1.getName())
602 ff1=MEDFileField1TS.New()
603 ff1.setFieldNoProfileSBT(f1)
605 f2=ReadFieldCell(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2]);
606 itt,orr,ti=ff1.getTime()
607 self.assertEqual(0,itt); self.assertEqual(1,orr); self.assertAlmostEqual(2.,ti,14);
608 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
610 itt,orr,ti=ff1.getTime()
611 self.assertEqual(3,itt); self.assertEqual(4,orr); self.assertAlmostEqual(2.3,ti,14);
613 ff1.copyTimeInfoFrom(f1)
614 itt,orr,ti=ff1.getTime()
615 self.assertEqual(7,itt); self.assertEqual(8,orr); self.assertAlmostEqual(5.5,ti,14);
616 da,infos=ff1.getUndergroundDataArrayExt()
617 f2.getArray().setName(da.getName())#da has the same name than f2
618 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
619 self.assertEqual([((3, 0), (0, 2)), ((4, 0), (2, 4)), ((6, 0), (4, 5)), ((5, 0), (5, 6))],infos)
622 f1=MEDLoaderDataForTest.buildVecFieldOnNodes_1();
624 mm1=MEDFileUMesh.New()
625 mm1.setCoords(m1.getCoords())
626 mm1.setMeshAtLevel(0,m1)
627 mm1.setName(m1.getName())
629 ff1=MEDFileField1TS.New()
630 ff1.setFieldNoProfileSBT(f1)
632 da=ff1.getUndergroundDataArray().setIJ(0,0,nv)
634 f2=ReadFieldNode(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
635 self.assertTrue(not f1.isEqual(f2,1e-12,1e-12))
636 f1.getArray().setIJ(0,0,nv)
637 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
640 f1=MEDLoaderDataForTest.buildVecFieldOnGaussNE_1();
642 mm1=MEDFileUMesh.New()
643 mm1.setCoords(m1.getCoords())
644 mm1.setMeshAtLevel(0,m1)
645 mm1.setName(m1.getName())
647 ff1=MEDFileField1TS.New()
648 ff1.setFieldNoProfileSBT(f1)
650 f2=ReadFieldGaussNE(fname,f1.getMesh().getName(),0,f1.getName(),f1.getTime()[1],f1.getTime()[2])
651 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
652 da,infos=ff1.getUndergroundDataArrayExt()
653 f2.getArray().setName(da.getName())#da has the same name than f2
654 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
655 self.assertEqual([((3, 0), (0, 6)), ((4, 0), (6, 14)), ((6, 0), (14, 20))],infos)
658 f1=MEDLoaderDataForTest.buildVecFieldOnGauss_2_Simpler();
659 f1InvalidCpy=f1.deepCopy()
660 f1InvalidCpy.setDiscretization(MEDCouplingFieldDiscretizationGauss())
661 f1InvalidCpy2=f1.deepCopy()
662 f1InvalidCpy2.setDiscretization(MEDCouplingFieldDiscretizationGauss())
664 mm1=MEDFileUMesh.New()
665 mm1.setCoords(m1.getCoords())
666 mm1.setMeshAtLevel(0,m1)
667 mm1.setName(m1.getName())
669 ff1=MEDFileField1TS.New()
670 self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy) # fails because no Gauss localization per cell set !*
671 f1InvalidCpy2.getDiscretization().setArrayOfDiscIds(f1.getDiscretization().getArrayOfDiscIds()) # fails because no Gauss localization set whereas gauss locid per cell given !
672 self.assertRaises(InterpKernelException,ff1.setFieldNoProfileSBT,f1InvalidCpy2)
673 ff1.setFieldNoProfileSBT(f1)
675 ff2=MEDFileField1TS.New(fname,f1.getName(),f1.getTime()[1],f1.getTime()[2])
676 f2=ff2.getFieldAtLevel(ON_GAUSS_PT,0)
677 self.assertTrue(f1.isEqual(f2,1e-12,1e-12))
678 sbt=ff2.getFieldSplitedByType2()
679 loc1=ff2.getLocalization("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5")
680 self.assertEqual("Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_5",loc1.getName())
681 self.assertEqual((-1, 1,-1,-1,1,-1,-1,0,0,-1,0,0),loc1.getRefCoords())
682 self.assertEqual(6,loc1.getNumberOfPointsInCells())
683 self.assertEqual(3,loc1.getNumberOfGaussPoints())
684 self.assertEqual(2,loc1.getDimension())
685 da,infos=ff2.getUndergroundDataArrayExt()
686 f2.getArray().setName(da.getName())#da has the same name than f2
687 self.assertTrue(da.isEqual(f2.getArray(),1e-12))
688 self.assertEqual(53,da.getNumberOfTuples())
689 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)
694 def testMEDFileData1(self):
698 m1=MEDLoaderDataForTest.build1DMesh_1()
699 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
700 mmm1=MEDFileMeshMultiTS.New() ;
701 mmm1.setOneTimeStep(mm1)
702 m2=MEDLoaderDataForTest.build2DCurveMesh_1()
703 mm2=MEDFileUMesh.New() ; mm2.setCoords(m2.getCoords()) ; mm2.setMeshAtLevel(0,m2) ; mm2.setName(m2.getName())
704 mmm2=MEDFileMeshMultiTS.New() ; mmm2.setOneTimeStep(mm2)
705 ms=MEDFileMeshes.New(); ms.setMeshAtPos(0,mm1) ; ms.setMeshAtPos(1,mm2)
707 for name,mmm in zip(["1DMesh_1","2DCurveMesh_1"],ms):
708 self.assertEqual(name,mmm.getName())
709 self.assertEqual(type(mmm),MEDFileUMesh)
711 self.assertEqual(('1DMesh_1', '2DCurveMesh_1'),d.getMeshes().getMeshesNames())
713 ff1=MEDFileFieldMultiTS.New()
714 ff21=MEDFileFieldMultiTS.New()
715 ff22=MEDFileFieldMultiTS.New()
716 f1=m1.getMeasureField(True) ; f1.setName("f1") ; f1=f1.buildNewTimeReprFromThis(ONE_TIME,False)
717 f1.getArray().setInfoOnComponent(0,"power [kW]")
718 ff1.appendFieldNoProfileSBT(f1)
719 f21=m2.getMeasureField(True) ; f21.setName("f21") ; f21=f21.buildNewTimeReprFromThis(ONE_TIME,False)
720 f21.getArray().setInfoOnComponent(0,"sta [mm]") ;
721 ff21.appendFieldNoProfileSBT(f21)
722 f22=f21.deepCopy() ; f22.setName("f22") ; f22=f22.buildNewTimeReprFromThis(ONE_TIME,False) ;
723 f22.applyFunc(2,"3*x*IVec+2*x*JVec")
724 f22.getArray().setInfoOnComponent(0,"distance [km]") ; f22.getArray().setInfoOnComponent(1,"displacement [cm]")
725 ff22.appendFieldNoProfileSBT(f22)
726 fs=MEDFileFields.New()
727 fs.pushField(ff1) ; fs.pushField(ff21) ; fs.pushField(ff22)
728 for name,fmts in zip(["f1","f21","f22"],fs):
729 self.assertEqual(name,fmts.getName())
733 fname2="Pyfile29_2.med"
736 d2=MEDFileData.New(fname2)
737 self.assertEqual(2,d2.getNumberOfMeshes())
738 self.assertEqual(3,d2.getNumberOfFields())
739 self.assertTrue(isinstance(d2.getMeshes().getMeshAtPos(0),MEDFileUMesh))
740 self.assertTrue(isinstance(d2.getMeshes()[0],MEDFileUMesh))
741 self.assertTrue(isinstance(d2.getMeshes()['2DCurveMesh_1'],MEDFileUMesh))
742 m1bis=d2.getMeshes().getMeshAtPos(0).getMeshAtLevel(0)
743 self.assertTrue(m1.isEqual(m1bis,1e-12))
744 self.assertEqual(('f1', 'f21', 'f22'),d2.getFields().getFieldsNames())
745 self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldAtPos(2).getTimeSteps())
746 self.assertEqual([(-1,-1,0.0)],d2.getFields()[2].getTimeSteps())
747 self.assertEqual([(-1,-1,0.0)],d2.getFields().getFieldWithName("f21").getTimeSteps())
748 self.assertEqual([(-1,-1,0.0)],d2.getFields()["f21"].getTimeSteps())
752 def testMEDField9(self):
753 # first test field profile WR. Full type but with some type missing
755 m1=MEDLoaderDataForTest.build2DMesh_3()
756 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
758 ff1=MEDFileField1TS.New()
759 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F1")
760 d=DataArrayDouble.New() ; d.alloc(2*9,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
761 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.
762 da=DataArrayInt.New(); da.alloc(9,1) ; da.iota(0) ; da.setName("sup1")
764 ff1.setFieldProfile(f1,mm1,0,da)
765 ff1.changePflsNames([(["sup1_NORM_QUAD4"],"ForV650")])
769 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
770 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))# profiles names cannot be contracted in pfl array name
771 self.assertTrue(vals.isEqual(d,1e-14))
773 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
774 ff3=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
775 ff2.deepCpyGlobs(ff3)
776 sbt=ff2.getFieldSplitedByType2()
777 self.assertEqual(3,sbt[0][0])#TRI3
778 self.assertEqual(0,sbt[0][1][0][0])#CELL For TRI3
779 self.assertEqual("",sbt[0][1][0][2])#no profile For TRI3
780 self.assertEqual([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],sbt[0][1][0][1].getValues())# values for TRI3
781 self.assertEqual(4,sbt[1][0])#QUAD4
782 self.assertEqual(0,sbt[1][1][0][0])#CELL For QUAD4
783 self.assertEqual("ForV650",sbt[1][1][0][2])# profile For QUAD4
784 self.assertEqual([19, 20, 21, 22, 23, 24],sbt[1][1][0][1].getValues())# values for QUAD4
785 self.assertEqual([0],ff2.getTypesOfFieldAvailable())
786 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,0,mm1) ; vals.setName("")
787 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
788 self.assertTrue(vals.isEqual(d,1e-14))
792 def testMEDField10(self):
794 m1=MEDLoaderDataForTest.build2DMesh_1()
795 m1.renumberCells([0,1,4,2,3,5],False)
796 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
798 ff1=MEDFileFieldMultiTS.New()
799 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
800 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
801 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.
802 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
804 ff1.appendFieldProfile(f1,mm1,0,da)
805 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
806 ff1.appendFieldProfile(f1,mm1,0,da)
810 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
811 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
812 self.assertTrue(vals.isEqual(e,1e-14))
813 vals,pfl=ff1.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
814 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
815 self.assertTrue(vals.isEqual(d,1e-14))
817 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
818 self.assertEqual([(-1,-1,0.0), (1,2,1.2)],ff2.getTimeSteps())
819 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,1,2,0,mm1) ; vals.setName("")
820 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
821 self.assertTrue(vals.isEqual(e,1e-14))
822 vals,pfl=ff2.getFieldWithProfile(ON_CELLS,-1,-1,0,mm1) ; vals.setName("")
823 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
824 self.assertTrue(vals.isEqual(d,1e-14))
827 # idem testMEDField9 method except that here testing profile on nodes and not on cells.
829 def testMEDField11(self):
831 m1=MEDLoaderDataForTest.build2DMesh_1()
832 m1.renumberCells([0,1,4,2,3,5],False)
833 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
835 ff1=MEDFileField1TS.New()
836 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
837 d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
838 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.
839 da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
841 ff1.setFieldProfile(f1,mm1,0,da)
842 self.assertEqual(ff1.getNonEmptyLevels(),(-1, []))
845 vals,pfl=ff1.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
846 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
847 self.assertTrue(vals.isEqual(d,1e-14))
849 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
850 vals,pfl=ff2.getFieldWithProfile(ON_NODES,0,mm1) ; vals.setName("")
851 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
852 self.assertTrue(vals.isEqual(d,1e-14))
856 def testMEDField12(self):
858 m1=MEDLoaderDataForTest.build2DMesh_1()
859 m1.renumberCells([0,1,4,2,3,5],False)
860 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
862 ff1=MEDFileFieldMultiTS.New()
863 f1=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f1.setName("F1Node")
864 d=DataArrayDouble.New() ; d.alloc(2*6,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
865 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.
866 da=DataArrayInt.New(); da.setValues([1,2,4,5,7,8],6,1) ; da.setName("sup1Node")
868 ff1.appendFieldProfile(f1,mm1,0,da)
869 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
870 ff1.appendFieldProfile(f1,mm1,0,da)
873 vals,pfl=ff1.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
874 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
875 self.assertTrue(vals.isEqual(e,1e-14))
876 vals,pfl=ff1.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
877 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
878 self.assertTrue(vals.isEqual(d,1e-14))
880 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
881 vals,pfl=ff2.getFieldWithProfile(ON_NODES,1,2,0,mm1) ; vals.setName("")
882 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
883 self.assertTrue(vals.isEqual(e,1e-14))
884 vals,pfl=ff2.getFieldWithProfile(ON_NODES,-1,-1,0,mm1) ; vals.setName("")
885 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
886 self.assertTrue(vals.isEqual(d,1e-14))
890 def testMEDField13(self):
892 m1=MEDLoaderDataForTest.build2DMesh_1()
893 m1.renumberCells([0,1,4,2,3,5],False)
895 m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
896 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
898 ff1=MEDFileField1TS.New()
899 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F3Node")
900 d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
901 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.
902 da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
904 ff1.setFieldProfile(f1,mm1,0,da)
907 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
908 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
909 self.assertTrue(vals.isEqual(d,1e-14))
911 ff2=MEDFileField1TS.New(fname,f1.getName(),-1,-1)
912 vals,pfl=ff2.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; vals.setName("")
913 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
914 self.assertTrue(vals.isEqual(d,1e-14))
918 def testMEDField14(self):
920 m1=MEDLoaderDataForTest.build2DMesh_1()
921 m1.renumberCells([0,1,4,2,3,5],False)
923 m1=m1.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) # suppression of last cell that is a polygon
924 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
926 ff1=MEDFileFieldMultiTS.New()
927 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
928 d=DataArrayDouble.New() ; d.alloc(2*11,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
929 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.
930 da=DataArrayInt.New(); da.setValues([0,2,3],3,1) ; da.setName("sup1NodeElt")
932 ff1.appendFieldProfile(f1,mm1,0,da)
933 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
934 ff1.appendFieldProfile(f1,mm1,0,da)
937 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
938 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
939 self.assertTrue(vals.isEqual(d,1e-14))
940 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
941 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
942 self.assertTrue(vals.isEqual(e,1e-14))
943 self.assertEqual([[3],[3]],ff1.getTypesOfFieldAvailable())
945 ff2=MEDFileFieldMultiTS.New(fname,f1.getName())
946 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,-1,-1,0,mm1) ; vals.setName("")
947 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
948 self.assertTrue(vals.isEqual(d,1e-14))
949 vals,pfl=ff1.getFieldWithProfile(ON_GAUSS_NE,1,2,0,mm1) ; vals.setName("")
950 self.assertTrue(pfl.isEqualWithoutConsideringStr(da))
951 self.assertTrue(vals.isEqual(e,1e-14))
953 # 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.
954 # 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
955 # 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 !
957 def testMEDField15(self):
959 m0=MEDLoaderDataForTest.build2DMesh_1()
960 m0.renumberCells([0,1,4,2,3,5],False)
962 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
963 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ;
964 ff1=MEDFileField1TS.New()
965 f1=MEDCouplingFieldDouble.New(ON_GAUSS_NE,ONE_TIME) ; f1.setName("F4Node")
966 d=DataArrayDouble.New() ; d.alloc(2*20,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
967 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.
968 da=DataArrayInt.New(); da.setValues([0,1,3,4,6],5,1) ; da.setName("sup1NodeElt")
970 ff1.setFieldProfile(f1,mm1,0,da)
971 m1=m0.buildPartOfMySelf(list(range(5)),True) ; m1.setName(tmp) ; mm1.setMeshAtLevel(0,m1) ;
974 f1=ff1.getFieldOnMeshAtLevel(ON_GAUSS_NE,m1,0)
975 f2,p1=ff1.getFieldWithProfile(ON_GAUSS_NE,0,mm1) ; f2.setName("")
976 self.assertTrue(p1.isIota(5))
977 self.assertTrue(f1.getArray().isEqual(f2,1e-12))
979 # Test for getFieldAtTopLevel method
981 def testMEDField16(self):
983 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
985 mm1=MEDFileUMesh.New()
986 mm1.setCoords(m1.getCoords())
987 mm1.setMeshAtLevel(0,m1)
988 mm1.setName(m1.getName())
989 ff1=MEDFileField1TS.New()
990 ff1.setFieldNoProfileSBT(f1)
991 m2=m1.buildDescendingConnectivity()[0]
992 m2.sortCellsInMEDFileFrmt()
993 m2.setName(m1.getName())
994 mm1.setMeshAtLevel(-1,m2)
996 f2=m2.getMeasureField(True)
997 dd=DataArrayDouble.New()
998 dd.alloc(f2.getArray().getNumberOfTuples(),3)
999 dd[:,0]=f2.getArray()
1000 dd[:,1]=2*f2.getArray()
1001 dd[:,2]=3*f2.getArray()
1002 f2=f2.buildNewTimeReprFromThis(ONE_TIME,False)
1004 f2.copyTinyStringsFrom(f1)
1005 f2.copyTinyAttrFrom(f1)
1006 ff1.setFieldNoProfileSBT(f2)
1008 # Reading Pyfile37.med
1009 ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
1010 f1bis=ff2.getFieldAtLevel(ON_CELLS,0)
1011 self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
1012 f1bis=ff2.getFieldAtLevel(ON_CELLS,-1)
1013 self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
1014 f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
1015 self.assertTrue(f1.isEqual(f1bis,1e-12,1e-12))
1017 fname="Pyfile38.med"
1019 ff1=MEDFileField1TS.New()
1020 ff1.setFieldNoProfileSBT(f2)
1022 ff2=MEDFileField1TS.New(fname,f2.getName(),0,1)
1023 f1bis=ff2.getFieldAtTopLevel(ON_CELLS)
1024 self.assertTrue(f2.isEqual(f1bis,1e-12,1e-12))
1027 # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
1029 def testMEDField17(self):
1030 fname="Pyfile39.med"
1031 m1=MEDLoaderDataForTest.build2DMesh_1()
1032 m1.renumberCells([0,1,4,2,3,5],False)
1033 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
1035 ffs=MEDFileFields.New()
1036 ff1=MEDFileFieldMultiTS.New()
1037 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
1038 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
1039 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.
1040 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
1042 ff1.appendFieldProfile(f1,mm1,0,da)
1043 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
1044 ff1.appendFieldProfile(f1,mm1,0,da)
1046 ffs.setFieldAtPos(0,ff1)
1050 ffsr=MEDFileFields.New(fname)
1051 ff3=ffsr.getFieldAtPos(0)
1052 f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
1053 self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
1056 # Non regression test to check that globals are correctly appended on MEDFileFields::setFieldAtPos
1058 def testMEDField18(self):
1059 fname="Pyfile40.med"
1060 m1=MEDLoaderDataForTest.build2DMesh_1()
1061 m1.renumberCells([0,1,4,2,3,5],False)
1062 mm1=MEDFileUMesh.New() ; mm1.setCoords(m1.getCoords()) ; mm1.setMeshAtLevel(0,m1) ; mm1.setName(m1.getName())
1064 ffs=MEDFileFields.New()
1065 ff1=MEDFileFieldMultiTS.New()
1066 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName("F2")
1067 d=DataArrayDouble.New() ; d.alloc(2*4,1) ; d.iota(7.); d.rearrange(2); d.setInfoOnComponent(0,"sigX [MPa]") ; d.setInfoOnComponent(1,"sigY [GPa]")
1068 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.
1069 da=DataArrayInt.New(); da.setValues([0,1,2,4],4,1) ; da.setName("sup2")
1071 ff1.appendFieldProfile(f1,mm1,0,da)
1072 f1.setTime(1.2,1,2) ; e=d.applyFunc("2*x") ; e.copyStringInfoFrom(d) ; f1.setArray(e) ;
1073 ff1.appendFieldProfile(f1,mm1,0,da)
1077 ffsr=MEDFileFields.New(fname)
1078 ff3=ffsr.getFieldAtPos(0)
1079 f4=ff3.getFieldAtTopLevel(ON_CELLS,1,2)
1080 self.assertTrue(f4.getArray().isEqual(f1.getArray(),1e-12))
1084 def testMEDFieldBug1(self):
1085 GeneratePyfile13(self)
1086 fname="Pyfile13.med"
1087 d=MEDFileData.New(fname)
1088 self.assertEqual(('Loc_MyFirstFieldOnGaussPoint_NORM_QUAD4_1','Loc_MyFirstFieldOnGaussPoint_NORM_TRI3_0','Loc_MyFirstFieldOnGaussPoint_NORM_TRI6_2'),d.getFields().getFieldAtPos(0).getLocs())
1092 def testMEDMesh8(self):
1093 m=MEDLoaderDataForTest.build1DMesh_1()
1094 m.convertQuadraticCellsToLinear()
1095 mm=MEDFileUMesh.New()
1096 mm.setMeshAtLevel(0,m)
1097 g1=DataArrayInt.New() ; g1.setValues([0,2],2,1) ; g1.setName("g1")
1098 g2=DataArrayInt.New() ; g2.setValues([1,3],2,1) ; g2.setName("g2")
1099 g3=DataArrayInt.New() ; g3.setValues([1,2,3],3,1) ; g3.setName("g3")
1100 mm.setGroupsAtLevel(0,[g1,g2],False)
1101 self.assertEqual(('g1','g2'),mm.getGroupsNames())
1102 self.assertEqual(('Family_-2','Family_-3'),mm.getFamiliesNames())
1103 self.assertEqual(('Family_-2',),mm.getFamiliesOnGroup('g1'))
1104 self.assertEqual(('Family_-3',),mm.getFamiliesOnGroup('g2'))
1105 mm.assignFamilyNameWithGroupName()
1106 self.assertEqual(('g1','g2'),mm.getGroupsNames())
1107 self.assertEqual(('g1','g2'),mm.getFamiliesNames())
1108 self.assertEqual(('g1',),mm.getFamiliesOnGroup('g1'))
1109 self.assertEqual(('g2',),mm.getFamiliesOnGroup('g2'))
1111 mm=MEDFileUMesh.New()
1112 mm.setMeshAtLevel(0,m)
1113 mm.setGroupsAtLevel(0,[g1,g2,g3],False)
1114 self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1115 self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1116 self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1117 self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1118 self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1119 mm.assignFamilyNameWithGroupName() # here it does nothing because no such group-family bijection found
1120 self.assertEqual(('g1','g2','g3'),mm.getGroupsNames())
1121 self.assertEqual(('Family_-2', 'Family_-4', 'Family_-5'),mm.getFamiliesNames())
1122 self.assertEqual(('Family_-2', 'Family_-4'),mm.getFamiliesOnGroup('g1'))
1123 self.assertEqual(('Family_-5',),mm.getFamiliesOnGroup('g2'))
1124 self.assertEqual(('Family_-4','Family_-5',),mm.getFamiliesOnGroup('g3'))
1125 mm.changeFamilyId(5,6)
1126 g=mm.getGroupArr(0,"g3")
1127 self.assertTrue(g.isEqual(g3));
1128 g=mm.getGroupArr(0,"g2")
1129 self.assertTrue(g.isEqual(g2));
1130 g=mm.getGroupArr(0,"g1")
1131 self.assertTrue(g.isEqual(g1));
1134 # bug detected by gauthier
1136 def testMEDLoaderMEDLoaderNSReadFieldDoubleDataInMedFile(self):
1137 fname="Pyfile41.med"
1138 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
1140 mm1=MEDFileUMesh.New()
1141 mm1.setCoords(m1.getCoords())
1142 mm1.setMeshAtLevel(0,m1)
1144 ff1=MEDFileField1TS.New()
1145 ff1.setFieldNoProfileSBT(f1)
1147 # writing mesh1 and field1, now creation of mesh2 and field2
1150 m2.translate([0.5,0.6,0.7])
1151 m2.setName("3DSurfMesh_2")
1152 f2.getArray()[:]*=2.
1153 f2.setName("VectorFieldOnCells2")
1154 mm2=MEDFileUMesh.New()
1155 mm2.setCoords(m2.getCoords())
1156 mm2.setMeshAtLevel(0,m2)
1158 ff2=MEDFileField1TS.New()
1159 ff2.setFieldNoProfileSBT(f2)
1162 f3=ReadFieldCell(fname,"3DSurfMesh_1",0,"VectorFieldOnCells",0,1)
1163 self.assertTrue(f3.isEqual(f1,1e-12,1e-12))
1164 f4=ReadFieldCell(fname,"3DSurfMesh_2",0,"VectorFieldOnCells2",0,1)
1165 self.assertTrue(f4.isEqual(f2,1e-12,1e-12))
1169 def testMEDLoaderMultiLevelCellField1(self):
1170 fname="Pyfile42.med"
1171 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1172 m=MEDFileUMesh.New()
1173 m.setCoords(m2.getCoords())
1174 m.setMeshAtLevel(0,m2)
1175 m.setMeshAtLevel(-1,m1)
1176 m.setMeshAtLevel(-2,m0)
1180 compNames1=["comp1","comp2","comp3"]
1181 ff1=MEDFileField1TS.New()
1182 da2=DataArrayDouble.New()
1183 da2.alloc(m2.getNumberOfCells()*len(compNames1),1)
1185 da2.rearrange(len(compNames1))
1186 da2.setInfoOnComponents(compNames1)
1187 f2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f2.setName(FieldName1) ; f2.setArray(da2) ; f2.setMesh(m2) ; f2.checkConsistencyLight()
1188 ff1.setFieldNoProfileSBT(f2)
1189 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0]))
1190 da0=DataArrayDouble.New()
1191 da0.alloc(m0.getNumberOfCells()*len(compNames1),1)
1193 da0.rearrange(len(compNames1))
1194 da0.setInfoOnComponents(compNames1)
1195 f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName1) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkConsistencyLight()
1196 ff1.setFieldNoProfileSBT(f0)
1197 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-2]))
1198 da1=DataArrayDouble.New()
1199 da1.alloc(m1.getNumberOfCells()*len(compNames1),1)
1201 da1.rearrange(len(compNames1))
1202 da1.setInfoOnComponents(compNames1)
1203 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName1) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkConsistencyLight()
1204 ff1.setFieldNoProfileSBT(f1)
1205 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1210 compNames2=["comp11","comp22"]
1211 ff2=MEDFileField1TS.New()
1212 da0=DataArrayDouble.New()
1213 da0.alloc(m0.getNumberOfCells()*2,1)
1216 da0.setInfoOnComponents(compNames2)
1217 f0=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0.setName(FieldName2) ; f0.setArray(da0) ; f0.setMesh(m0) ; f0.checkConsistencyLight()
1218 ff2.setFieldNoProfileSBT(f0)
1219 self.assertEqual(ff2.getNonEmptyLevels(),(0, [0]))
1220 da1=DataArrayDouble.New()
1221 da1.alloc(m1.getNumberOfCells()*len(compNames2),1)
1223 da1.rearrange(len(compNames2))
1224 da1.setInfoOnComponents(compNames2)
1225 f1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f1.setName(FieldName2) ; f1.setArray(da1) ; f1.setMesh(m1) ; f1.checkConsistencyLight()
1226 ff2.setFieldNoProfileSBT(f1)
1227 self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1231 ff1=MEDFileField1TS.New(fname,FieldName1,-1,-1)
1232 self.assertEqual(ff1.getNonEmptyLevels(),(2, [0,-1,-2]))
1233 self.assertEqual(ff1.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')]), (3, [(0, (84, 148), '', '')]), (4, [(0, (148, 212), '', '')])])
1234 ff2=MEDFileField1TS.New(fname,FieldName2,-1,-1)
1235 self.assertEqual(ff2.getNonEmptyLevels(),(1, [0,-1]))
1236 self.assertEqual(ff2.getFieldSplitedByType(),[(0, [(0, (0, 4), '', '')]), (1, [(0, (4, 84), '', '')])])
1240 def testFieldOnPflRetrieveOnMdimRelMax1(self):
1241 fname="Pyfile43.med"
1242 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
1243 m=MEDFileUMesh.New()
1244 m.setMeshAtLevel(0,m2)
1245 m.setMeshAtLevel(-1,m1)
1246 m.setMeshAtLevel(-2,m0)
1247 f=MEDFileField1TS.New()
1248 ff=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME)
1249 ff.setName("NodeFieldPfl")
1250 arr=DataArrayDouble.New() ; arr.setValues([1.,10.,100.,2.,20.,200.],2,3)
1252 pfl=DataArrayInt.New() ; pfl.setValues([2,3],2,1) ; pfl.setName("PflNode")
1253 f.setFieldProfile(ff,m,-2,pfl)
1254 tes0=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1255 self.assertEqual(ON_NODES,tes0.getTypeOfField())
1256 self.assertEqual(1,tes0.getMesh().getMeshDimension())
1257 self.assertEqual(1,tes0.getMesh().getNumberOfCells())
1258 self.assertEqual(2,tes0.getMesh().getNumberOfNodes())
1259 self.assertEqual([1,0,1],tes0.getMesh().getNodalConnectivity().getValues())
1260 self.assertEqual([0,3],tes0.getMesh().getNodalConnectivityIndex().getValues())
1261 self.assertEqual(2,tes0.getArray().getNumberOfTuples())
1262 self.assertEqual(3,tes0.getArray().getNumberOfComponents())
1263 expected1=[1.,10.,100.,2.,20.,200.]
1264 nodeCoordsWithValue1=[10.,2.5,0.]
1265 nodeCoordsWithValue2=[10.,3.75,0.]
1267 self.assertAlmostEqual(nodeCoordsWithValue1[i],tes0.getMesh().getCoordinatesOfNode(0)[i],13);
1268 self.assertAlmostEqual(nodeCoordsWithValue2[i],tes0.getMesh().getCoordinatesOfNode(1)[i],13);
1271 self.assertAlmostEqual(expected1[i],tes0.getArray().getIJ(0,i),13);
1275 tes1=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1276 self.assertEqual(ON_CELLS,tes1.getTypeOfField())# it is not a bug even if ON_NODES has been specified
1277 self.assertEqual(0,tes1.getMesh().getMeshDimension())
1278 self.assertEqual(2,tes1.getMesh().getNumberOfCells())
1279 self.assertEqual(135,tes1.getMesh().getNumberOfNodes())
1280 self.assertEqual([0,2,0,3],tes1.getMesh().getNodalConnectivity().getValues())
1281 self.assertEqual([0,2,4],tes1.getMesh().getNodalConnectivityIndex().getValues())
1282 self.assertEqual(2,tes1.getArray().getNumberOfTuples())
1283 self.assertEqual(3,tes1.getArray().getNumberOfComponents())
1285 self.assertAlmostEqual(expected1[i],tes1.getArray().getIJ(0,i),13);
1290 pfl=DataArrayInt.New() ; pfl.setValues([3,2],2,1) ; pfl.setName("PflNode")
1291 f=MEDFileField1TS.New()
1292 f.setFieldProfile(ff,m,-2,pfl)
1293 tes2=f.getFieldOnMeshAtLevel(ON_NODES,-1,m)
1294 self.assertEqual(ON_NODES,tes2.getTypeOfField())
1295 self.assertEqual(1,tes2.getMesh().getMeshDimension())
1296 self.assertEqual(1,tes2.getMesh().getNumberOfCells())
1297 self.assertEqual(2,tes2.getMesh().getNumberOfNodes())
1298 self.assertEqual([1,0,1],tes2.getMesh().getNodalConnectivity().getValues())
1299 self.assertEqual([0,3],tes2.getMesh().getNodalConnectivityIndex().getValues())
1300 self.assertEqual(2,tes2.getArray().getNumberOfTuples())
1301 self.assertEqual(3,tes2.getArray().getNumberOfComponents())
1302 expected2=[2.,20.,200.,1.,10.,100.]
1304 self.assertAlmostEqual(nodeCoordsWithValue1[i],tes2.getMesh().getCoordinatesOfNode(0)[i],13);
1305 self.assertAlmostEqual(nodeCoordsWithValue2[i],tes2.getMesh().getCoordinatesOfNode(1)[i],13);
1308 self.assertAlmostEqual(expected2[i],tes2.getArray().getIJ(0,i),13);#compare tes2 and tes3
1311 tes3=f.getFieldOnMeshAtLevel(ON_NODES,1,m)
1312 self.assertEqual(ON_CELLS,tes3.getTypeOfField())# it is not a bug even if ON_NODES has been specified
1313 self.assertEqual(0,tes3.getMesh().getMeshDimension())
1314 self.assertEqual(2,tes3.getMesh().getNumberOfCells())
1315 self.assertEqual(135,tes3.getMesh().getNumberOfNodes())
1316 self.assertEqual([0,3,0,2],tes3.getMesh().getNodalConnectivity().getValues())
1317 self.assertEqual([0,2,4],tes3.getMesh().getNodalConnectivityIndex().getValues())
1318 self.assertEqual(2,tes3.getArray().getNumberOfTuples())
1319 self.assertEqual(3,tes3.getArray().getNumberOfComponents())
1321 self.assertAlmostEqual(expected1[i],tes3.getArray().getIJ(0,i),13);
1326 def testBuildInnerBoundaryAlongM1Group1(self):
1327 fname="Pyfile44.med"
1328 m=MEDCouplingCMesh.New()
1329 m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1330 m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1331 m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1332 m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1333 m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1334 m2.setName(m.getName())
1335 grp=DataArrayInt.New([4,6,8]) ; grp.setName("Grp")
1336 grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1337 mm=MEDFileUMesh.New()
1338 mm.setMeshAtLevel(0,m)
1339 mm.setMeshAtLevel(-1,m2)
1340 mm.setGroupsAtLevel(-1,[grp,grp2])
1341 grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1342 mm.setGroupsAtLevel(1,[grpNode])
1343 ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1344 ref1=[4,9,8,14,15,4,10,9,15,16,4,11,10,16,17]
1345 ref2=[4,9,8,14,30,4,10,9,30,31,4,11,10,31,32]
1347 self.assertEqual(30,mm.getNumberOfNodes())
1348 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1349 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())
1351 nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1352 self.assertEqual([15,16,17],nodes.getValues());
1353 self.assertEqual([7,8,9],cells.getValues());
1354 self.assertEqual([12,13,14],cells2.getValues());
1355 self.assertEqual(33,mm.getNumberOfNodes())
1356 self.assertEqual([4,6,8],mm.getGroupArr(-1,"Grp").getValues())
1357 self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1358 self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1359 self.assertEqual([17,18,19],mm.getGroupArr(-1,"Grp_dup").getValues())
1360 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
1361 self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8,9]].getNodalConnectivity().getValues())#
1362 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
1363 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1364 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])
1365 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1366 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1368 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1369 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1370 refValues2=refValues[:] ; refValues2[7:10]=[1.365,1.26,1.35]
1371 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1372 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1377 def testBuildInnerBoundaryAlongM1Group2(self):
1378 fname="Pyfile45.med"
1379 m=MEDCouplingCMesh.New()
1380 m.setCoordsAt(0,DataArrayDouble.New([0.,1.1,2.3,3.6,5.,6.5]))
1381 m.setCoordsAt(1,DataArrayDouble.New([0.,1.1,2.3,3.6,5.]))
1382 m=m.buildUnstructured() ; m.setName("AnthonyDuplicate")
1383 m.getCoords().setInfoOnComponents(["X [km]","Z [mm]"])
1384 m2=m.buildDescendingConnectivity()[0][[8,11,14,20,21,22,23,24,25,26,31,32,33,34,35,36,37]]
1385 m2.setName(m.getName())
1386 grp=DataArrayInt.New([4,6]) ; grp.setName("Grp")
1387 grp2=DataArrayInt.New([9,16]) ; grp2.setName("Grp2")
1388 mm=MEDFileUMesh.New()
1389 mm.setMeshAtLevel(0,m)
1390 mm.setMeshAtLevel(-1,m2)
1391 mm.setGroupsAtLevel(-1,[grp,grp2])
1392 grpNode=DataArrayInt.New([4,21,23]) ; grpNode.setName("GrpNode")
1393 mm.setGroupsAtLevel(1,[grpNode])
1394 ref0=[4,15,14,20,21,4,16,15,21,22,4,17,16,22,23]
1395 ref1=[4,9,8,14,15,4,10,9,15,16]
1396 ref2=[4,9,8,14,30,4,10,9,30,16]
1398 self.assertEqual(30,mm.getNumberOfNodes())
1399 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[12,13,14]].getNodalConnectivity().getValues())
1400 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())
1402 nodes,cells,cells2=mm.buildInnerBoundaryAlongM1Group("Grp")
1403 self.assertEqual([15],nodes.getValues());
1404 self.assertEqual([7,8],cells.getValues());
1405 self.assertEqual([12,13],cells2.getValues());
1406 self.assertEqual(31,mm.getNumberOfNodes())
1407 self.assertEqual([4,6],mm.getGroupArr(-1,"Grp").getValues())
1408 self.assertEqual([9,16],mm.getGroupArr(-1,"Grp2").getValues())
1409 self.assertEqual([4,21,23],mm.getGroupArr(1,"GrpNode").getValues())
1410 self.assertEqual([17,18],mm.getGroupArr(-1,"Grp_dup").getValues())
1411 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
1412 self.assertEqual(ref2,mm.getMeshAtLevel(0)[[7,8]].getNodalConnectivity().getValues())#
1413 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
1414 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1415 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])
1416 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1417 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1419 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1420 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1421 refValues2=refValues[:] ; refValues2[7:9]=[1.365,1.47]
1422 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1423 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1428 def testBuildInnerBoundaryAlongM1Group3(self):
1429 """ Test buildInnerBoundaryAlongM1Group() with *non-connex* cracks """
1430 fname = "Pyfile73.med"
1431 m = MEDCouplingCMesh.New()
1432 m.setCoordsAt(0, DataArrayDouble([0.0,1.1,2.3,3.6,5.0]))
1433 m.setCoordsAt(1, DataArrayDouble([0.,1.,2.]))
1434 m = m.buildUnstructured(); m.setName("simple")
1435 m2 = m.buildDescendingConnectivity()[0]
1436 m2.setName(m.getName())
1438 # A crack in two non connected parts of the mesh:
1439 grpSeg = DataArrayInt([3,19]) ; grpSeg.setName("Grp")
1441 mm = MEDFileUMesh.New()
1442 mm.setMeshAtLevel(0,m)
1443 mm.setMeshAtLevel(-1,m2)
1444 mm.setGroupsAtLevel(-1,[grpSeg])
1445 nodes, cellsMod, cellsNotMod = mm.buildInnerBoundaryAlongM1Group("Grp")
1446 self.assertEqual([1,13],nodes.getValues());
1447 self.assertEqual([0,6],cellsMod.getValues());
1448 self.assertEqual([1,7],cellsNotMod.getValues());
1449 self.assertEqual(17,mm.getNumberOfNodes())
1450 self.assertEqual([3,19],mm.getGroupArr(-1,"Grp").getValues())
1451 self.assertEqual([22,23],mm.getGroupArr(-1,"Grp_dup").getValues())
1452 ref0=[4, 15, 0, 5, 6, 4, 8, 7, 12, 16]
1453 ref1=[4, 2, 1, 6, 7, 4, 9, 8, 13, 14]
1454 self.assertEqual(ref0,mm.getMeshAtLevel(0)[[0,6]].getNodalConnectivity().getValues())
1455 self.assertEqual(ref1,mm.getMeshAtLevel(0)[[1,7]].getNodalConnectivity().getValues())
1456 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
1457 mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith(mm.getGroup(-1,"Grp"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1459 refValues=DataArrayDouble([1.1, 1.2, 1.3, 1.4, 1.1, 1.2, 1.3, 1.4])
1460 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues) ; delta.abs()
1461 self.assertTrue(delta.getMaxValue()[0]<1e-10)
1463 mm.getCoords()[-len(nodes):]+=[0.,-0.3]
1464 self.assertRaises(InterpKernelException,mm.getGroup(-1,"Grp_dup").checkGeoEquivalWith,mm.getGroup(-1,"Grp"),12,1e-12);
1465 refValues2=refValues[:] ; refValues2[0] = 1.265; refValues2[6] = 1.105
1466 valsToTest=mm.getMeshAtLevel(0).getMeasureField(True).getArray() ; delta=(valsToTest-refValues2) ; delta.abs()
1467 self.assertTrue(delta.getMaxValue()[0]<1e-12)
1471 def testBuildInnerBoundaryAlongM1Group4(self):
1472 """ Test case where cells touch the M1 group on some nodes only and not on full edges (triangle mesh for ex)
1474 coo = DataArrayDouble([0.,0., 1.,0., 2.,0., 3.,0.,
1475 0.,1., 1.,1., 2.,1., 3.,1.,
1476 0.,2., 1.,2., 2.,2., 3.,2.], 12, 2)
1477 conn = [3,0,4,1, 3,1,4,5,
1484 connI = DataArrayInt()
1485 connI.alloc(13, 1); connI.iota(); connI *= 4
1486 m2 = MEDCouplingUMesh("2D", 2)
1488 m2.setConnectivity(DataArrayInt(conn), connI)
1489 m2.checkConsistency()
1490 m1, _, _, _, _ = m2.buildDescendingConnectivity()
1491 grpIds = DataArrayInt([9,11]); grpIds.setName("group")
1492 grpIds2 = DataArrayInt([0,1]); grpIds2.setName("group2")
1493 mfu = MEDFileUMesh()
1494 mfu.setMeshAtLevel(0, m2)
1495 mfu.setMeshAtLevel(-1, m1)
1496 mfu.setGroupsAtLevel(-1, [grpIds, grpIds2])
1497 nNod = m2.getNumberOfNodes()
1498 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1499 m2_bis = mfu.getMeshAtLevel(0)
1500 m2_bis.checkConsistency()
1501 m1_bis = mfu.getMeshAtLevel(-1)
1502 m1_bis.checkConsistency()
1503 self.assertEqual(nNod+2, mfu.getNumberOfNodes())
1504 self.assertEqual(nNod+2, m2_bis.getNumberOfNodes())
1505 self.assertEqual(nNod+2, m1_bis.getNumberOfNodes())
1506 self.assertEqual([6,7], nodesDup.getValues())
1507 self.assertEqual([2.,1., 3.,1.], m2_bis.getCoords()[nNod:].getValues())
1508 self.assertEqual(set([3,10,11]), set(cells1.getValues()))
1509 self.assertEqual(set([8,9,4,5]), set(cells2.getValues()))
1510 self.assertEqual([9,11],mfu.getGroupArr(-1,"group").getValues())
1511 self.assertEqual([23,24],mfu.getGroupArr(-1,"group_dup").getValues())
1512 self.assertEqual([0,1],mfu.getGroupArr(-1,"group2").getValues())
1513 ref0 =[3, 5, 10, 12, 3, 12, 10, 11, 3, 12, 11, 13]
1514 ref1 =[3, 2, 6, 7, 3, 2, 7, 3, 3, 1, 5, 6, 3, 1, 6, 2]
1515 self.assertEqual(ref0,mfu.getMeshAtLevel(0)[[3,10,11]].getNodalConnectivity().getValues())
1516 self.assertEqual(ref1,mfu.getMeshAtLevel(0)[[4,5,8,9]].getNodalConnectivity().getValues())
1517 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
1518 mfu.getGroup(-1,"group_dup").checkGeoEquivalWith(mfu.getGroup(-1,"group"),12,1e-12)# Grp_dup and Grp are equal considering connectivity and coordinates
1519 m_bis0 = mfu.getMeshAtLevel(-1)
1520 m_desc, _, _, _, _ = m_bis0.buildDescendingConnectivity()
1521 m_bis0.checkDeepEquivalOnSameNodesWith(mfu.getMeshAtLevel(-1), 2, 9.9999999)
1524 def testBuildInnerBoundary5(self):
1525 """ Full 3D test with tetras only. In this case a tri from the group is not duplicated because it is made only
1526 of non duplicated nodes. The tri in question is hence not part of the final new "dup" group. """
1527 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,
1528 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,
1529 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,
1530 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,
1531 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,
1532 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,
1533 400.0, 0.0, 100.02162286181577, 99.31624553977466, 99.99999998882231, 200.0, 99.31624576683302, 100.00000010178034, 0.0, 99.31624560596512, 200.0, 100.0050761312483,
1534 99.31624560612883, 0.0, 100.00507613125338, 200.0, 99.99999995813045, 100.00950673487786, 0.0, 99.99999989928207, 100.0041870621175, 301.29063354383015,
1535 100.0000000093269, 0.0, 301.29063360689975, 0.0, 100.00957769061164, 140.52853868782435, 99.99999963972768, 100.00509135751312, 297.87779091770784,
1536 97.16750463405486, 97.18018457127863], 46, 3)
1537 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,
1538 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,
1539 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,
1540 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,
1541 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,
1542 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,
1543 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,
1544 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,
1545 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,
1546 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,
1548 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,
1549 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,
1550 360, 365, 370, 375, 380, 385, 390, 395, 400, 405, 410, 415, 420, 425, 430]
1551 m3 = MEDCouplingUMesh("3D", 3)
1553 m3.setConnectivity(DataArrayInt(c0), DataArrayInt(cI0))
1554 m3.checkConsistency()
1555 m2, _, _, _, _ = m3.buildDescendingConnectivity()
1556 grpIds = DataArrayInt([36,74]); grpIds.setName("group")
1557 mfu = MEDFileUMesh()
1558 mfu.setMeshAtLevel(0, m3)
1559 mfu.setMeshAtLevel(-1, m2)
1560 grpIds3D = DataArrayInt([0,1]); grpIds3D.setName("group_3d")
1561 mfu.setGroupsAtLevel(0, [grpIds3D]) # just to check preservation of 3D group
1562 mfu.setGroupsAtLevel(-1, [grpIds])
1563 nNod = m3.getNumberOfNodes()
1564 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1565 m3_bis = mfu.getMeshAtLevel(0)
1566 m3_bis.checkConsistency()
1567 m2_bis = mfu.getMeshAtLevel(-1)
1568 m2_bis.checkConsistency()
1569 self.assertEqual(nNod+1, mfu.getNumberOfNodes())
1570 self.assertEqual(nNod+1, m3_bis.getNumberOfNodes())
1571 self.assertEqual(nNod+1, m2_bis.getNumberOfNodes())
1572 self.assertEqual([3], nodesDup.getValues())
1573 self.assertEqual(m3_bis.getCoords()[3].getValues(), m3_bis.getCoords()[nNod:].getValues())
1574 self.assertEqual(set([22]), set(cells1.getValues()))
1575 self.assertEqual(set([77]), set(cells2.getValues()))
1576 self.assertEqual([36,74],mfu.getGroupArr(-1,"group").getValues())
1577 self.assertEqual([0,1],mfu.getGroupArr(0,"group_3d").getValues())
1578 self.assertEqual([213],mfu.getGroupArr(-1,"group_dup").getValues()) # here only one cell has been duplicated
1579 m_bis0 = mfu.getMeshAtLevel(-1)
1580 m_desc, _, _, _, _ = m_bis0.buildDescendingConnectivity()
1581 m_bis0.checkDeepEquivalOnSameNodesWith(mfu.getMeshAtLevel(-1), 2, 9.9999999)
1585 def testBuildInnerBoundary6(self):
1586 """ 3D test where the crack has a funny shape with a singular point (i.e. two faces of the M1 group are only connected by one point, not a full segment)
1587 The singular point was wrongly duplicated.
1589 coo = DataArrayDouble([(-1.38778e-17,0.226,0),(-1.38778e-17,-1.38778e-17,0),(0.226,0.226,0),(0.226,-1.38778e-17,0),(0.452,0.226,0),(0.452,-1.38778e-17,0),
1590 (-1.38778e-17,0.452,0),(0.226,0.452,0),(0.452,0.452,0),(-1.38778e-17,0.226,0.25),(0.226,0.226,0.25),(0.226,-1.38778e-17,0.25),(-1.38778e-17,-1.38778e-17,0.25),
1591 (-1.38778e-17,0.226,0.779375),(0.226,0.226,0.779375),(0.226,-1.38778e-17,0.779375),(-1.38778e-17,-1.38778e-17,0.779375),(-1.38778e-17,0.226,1.30875),
1592 (0.226,0.226,1.30875),(0.226,-1.38778e-17,1.30875),(-1.38778e-17,-1.38778e-17,1.30875),(0.452,0.226,0.25),(0.452,-1.38778e-17,0.25),(0.452,0.226,0.779375),
1593 (0.452,-1.38778e-17,0.779375),(0.452,0.226,1.30875),(0.452,-1.38778e-17,1.30875),(-1.38778e-17,0.452,0.25),(0.226,0.452,0.25),(-1.38778e-17,0.452,0.779375),
1594 (0.226,0.452,0.779375),(-1.38778e-17,0.452,1.30875),(0.226,0.452,1.30875),(0.452,0.452,0.25),(0.452,0.452,0.779375),(0.452,0.452,1.30875),(0.146,0.226,0.779375),
1595 (0.146,-1.38778e-17,0.779375),(0.146,0.226,1.30875),(0.146,-1.38778e-17,1.30875),(0.146,0.452,0.779375),(0.146,0.452,1.30875)])
1596 c0 = [18, 0, 2, 3, 1, 9, 10, 11, 12, 18, 9, 10, 11, 12, 13, 36, 37, 16, 18, 13, 36, 37, 16, 17, 38, 39, 20, 18, 2, 4, 5, 3, 10, 21, 22, 11, 18, 10, 21, 22, 11, 14, 23, 24, 15,
1597 18, 14, 23, 24, 15, 18, 25, 26, 19, 18, 6, 7, 2, 0, 27, 28, 10, 9, 18, 27,
1598 28, 10, 9, 29, 40, 36, 13, 18, 29, 40, 36, 13, 31, 41, 38, 17, 18, 7, 8, 4, 2, 28, 33, 21, 10, 18, 28, 33, 21, 10, 30, 34, 23, 14, 18, 30, 34, 23, 14, 32, 35, 25, 18]
1599 cI0 = [0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108]
1600 m3 = MEDCouplingUMesh("3D", 3)
1602 m3.setConnectivity(DataArrayInt(c0), DataArrayInt(cI0))
1603 m3.checkConsistency()
1604 m2, _, _, _, _ = m3.buildDescendingConnectivity()
1605 grpIds = DataArrayInt([7,12,22,27]); grpIds.setName("group")
1606 mfu = MEDFileUMesh()
1607 mfu.setMeshAtLevel(0, m3)
1608 mfu.setMeshAtLevel(-1, m2)
1609 mfu.setGroupsAtLevel(-1, [grpIds])
1610 nNod = m3.getNumberOfNodes()
1611 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1612 m3_bis = mfu.getMeshAtLevel(0)
1613 m3_bis.checkConsistency()
1614 m2_bis = mfu.getMeshAtLevel(-1)
1615 m2_bis.checkConsistency()
1616 self.assertEqual(nNod+8, mfu.getNumberOfNodes())
1617 self.assertEqual(nNod+8, m3_bis.getNumberOfNodes())
1618 self.assertEqual(nNod+8, m2_bis.getNumberOfNodes())
1619 self.assertEqual([13, 14, 17, 18, 23, 25, 36, 38], nodesDup.getValues())
1620 self.assertEqual(m3_bis.getCoords()[nodesDup].getValues(), m3_bis.getCoords()[nNod:].getValues())
1621 self.assertEqual(set([1, 2, 4, 5]), set(cells1.getValues()))
1622 self.assertEqual(set([7, 8, 10, 11]), set(cells2.getValues()))
1623 self.assertEqual([7, 12, 22, 27],mfu.getGroupArr(-1,"group").getValues())
1624 self.assertEqual([56, 57, 58, 59],mfu.getGroupArr(-1,"group_dup").getValues()) # here only one cell has been duplicated
1625 m_desc, _, _, _, _ = m3_bis.buildDescendingConnectivity()
1626 m_desc.checkDeepEquivalOnSameNodesWith(m2_bis, 2, 9.9999)
1630 def testBuildInnerBoundary7(self):
1631 """ 3D test where the crack has another funny shape with another singular point (i.e. two faces of the M1 group are only connected by one point, not a full segment)
1632 Once the crack is inserted, the cells on either side of the crack do not necessarily form a connex spread zone. This was not properly handled either.
1634 m3 = MEDCouplingUMesh('box', 3)
1635 coo = DataArrayDouble([(5,17,0),(0,17,0),(0,12,0),(5,12,0),(15,17,0),(15,12,0),(20,12,0),(20,17,0),(20,2,0),(15,2,0),(15,-3,0),(20,-3,0),(5,-3,0),(5,2,0),(0,-3,0),(0,2,0),(5,17,10),(5,17,20),(5,17,30),(5,17,40),(0,17,10),(0,17,20),(0,17,30),(0,17,40),(0,12,10),(0,12,20),(0,12,30),(0,12,40),(5,12,10),(5,12,20),(5,12,30),(5,12,40),(15,17,10),(15,17,20),(15,17,30),(15,17,40),(15,12,10),(15,12,20),(15,12,30),(15,12,40),(20,12,10),(20,12,20),(20,12,30),(20,12,40),(20,17,10),(20,17,20),(20,17,30),(20,17,40),(20,2,10),(20,2,20),(20,2,30),(20,2,40),(15,2,10),(15,2,20),(15,2,30),(15,2,40),(15,-3,10),(15,-3,20),(15,-3,30),(15,-3,40),(20,-3,10),(20,-3,20),(20,-3,30),(20,-3,40),
1636 (5,-3,10),(5,-3,20),(5,-3,30),(5,-3,40),(5,2,10),(5,2,20),(5,2,30),(5,2,40),(0,-3,10),(0,-3,20),(0,-3,30),(0,-3,40),(0,2,10),(0,2,20),(0,2,30),(0,2,40),(20,8,0),(0,8,0),(20,8,10),(20,8,20),(20,8,30),(20,8,40),(15,8,30),(15,8,40),(5,8,30),(5,8,40),(0,8,10),(0,8,20),(0,8,30),(0,8,40)])
1638 c = DataArrayInt([31, 0, 3, 2, 1, -1, 16, 20, 24, 28, -1, 0, 16, 28, 3, -1, 3, 28, 24, 2, -1, 2, 24, 20, 1, -1, 1, 20, 16, 0, 31, 16, 28, 24, 20, -1, 17, 21, 25, 29, -1, 16, 17, 29, 28, -1, 28, 29, 25, 24, -1, 24, 25, 21, 20, -1, 20, 21, 17, 16, 31, 17, 29, 25, 21, -1, 18, 22, 26, 30, -1, 17, 18, 30, 29, -1, 29, 30, 26, 25, -1, 25, 26, 22, 21, -1, 21, 22, 18, 17, 31, 18, 30, 26, 22, -1, 19, 23, 27, 31, -1, 18, 19, 31, 30, -1, 30, 31, 27, 26, -1, 26, 27, 23, 22, -1, 22, 23, 19, 18, 31, 4, 5, 3, 0, -1, 32, 16, 28, 36, -1, 4, 32, 36, 5, -1, 5, 36, 28, 3, -1, 3, 28, 16, 0, -1, 0, 16, 32, 4, 31, 32, 36, 28, 16, -1, 33, 17, 29, 37, -1, 32, 33, 37,
1639 36, -1, 36, 37, 29, 28, -1, 28, 29, 17, 16, -1, 16, 17, 33, 32, 31, 33, 37, 29, 17, -1, 34, 18, 30, 38, -1, 33, 34, 38, 37, -1, 37, 38, 30, 29, -1, 29, 30, 18, 17, -1, 17, 18, 34, 33, 31, 34, 38, 30, 18, -1, 35, 19, 31, 39, -1, 34, 35, 39, 38, -1, 38, 39, 31, 30, -1, 30, 31, 19, 18, -1, 18, 19, 35, 34, 31, 6, 5, 4, 7, -1, 40, 44, 32, 36, -1, 6, 40, 36, 5, -1, 5, 36, 32, 4, -1, 4, 32, 44, 7, -1, 7, 44, 40, 6, 31, 40, 36, 32, 44, -1, 41, 45, 33, 37, -1, 40, 41, 37, 36, -1, 36, 37, 33, 32, -1, 32, 33, 45, 44, -1, 44, 45, 41, 40, 31, 41, 37, 33, 45, -1, 42, 46, 34, 38, -1, 41, 42, 38, 37, -1, 37, 38, 34, 33, -1, 33, 34, 46, 45, -1, 45, 46, 42, 41, 31,
1640 42, 38, 34, 46, -1, 43, 47, 35, 39, -1, 42, 43, 39, 38, -1, 38, 39, 35, 34, -1, 34, 35, 47, 46, -1, 46, 47, 43, 42, 31, 80, 9, 5, 6, -1, 82, 40, 36, 52, -1, 80, 82, 52, 9, -1, 9, 52, 36, 5, -1, 5, 36, 40, 6, -1, 6, 40, 82, 80, 31, 82, 52, 36, 40, -1, 83, 41, 37, 53, -1, 82, 83, 53, 52, -1, 52, 53, 37, 36, -1, 36, 37, 41, 40, -1, 40, 41, 83, 82, 31, 83, 53, 37, 41, -1, 84, 42, 38, 86, -1, 83, 84, 86, 53, -1, 53, 86, 38, 37, -1, 37, 38, 42, 41, -1, 41, 42, 84, 83, 31, 84, 86, 38, 42, -1, 85, 43, 39, 87, -1, 84, 85, 87, 86, -1, 86, 87, 39, 38, -1, 38, 39, 43, 42, -1, 42, 43, 85, 84, 31, 10, 9, 8, 11, -1, 56, 60, 48, 52, -1, 10, 56, 52, 9, -1, 9, 52,
1641 48, 8, -1, 8, 48, 60, 11, -1, 11, 60, 56, 10, 31, 56, 52,
1642 48, 60, -1, 57, 61, 49, 53, -1, 56, 57, 53, 52, -1, 52, 53, 49, 48, -1, 48, 49, 61, 60, -1, 60, 61, 57, 56, 31, 57, 53, 49, 61, -1, 58, 62, 50, 54, -1, 57, 58, 54, 53, -1, 53, 54, 50, 49, -1, 49, 50, 62, 61, -1, 61, 62, 58, 57, 31, 58, 54, 50, 62, -1, 59, 63, 51, 55, -1, 58, 59, 55, 54, -1, 54, 55, 51, 50, -1, 50, 51, 63, 62, -1, 62, 63, 59, 58, 31, 12, 13, 9, 10, -1, 64, 56, 52, 68, -1, 12, 64, 68, 13, -1, 13, 68, 52, 9, -1, 9, 52, 56, 10, -1, 10, 56, 64, 12, 31, 64, 68, 52, 56, -1, 65, 57, 53, 69, -1, 64, 65, 69, 68, -1, 68, 69, 53, 52, -1, 52, 53, 57, 56, -1, 56, 57, 65, 64, 31, 65, 69, 53, 57, -1, 66, 58, 54, 70, -1, 65, 66, 70, 69, -1, 69, 70,
1643 54, 53, -1, 53, 54, 58, 57, -1, 57, 58, 66, 65, 31, 66, 70, 54, 58, -1, 67, 59, 55, 71, -1, 66, 67, 71, 70, -1, 70, 71, 55, 54, -1, 54, 55, 59, 58, -1, 58, 59, 67, 66, 31, 14, 15, 13, 12, -1, 72, 64, 68, 76, -1, 14, 72, 76, 15, -1, 15, 76, 68, 13, -1, 13, 68, 64, 12, -1, 12, 64, 72, 14, 31, 72, 76, 68, 64, -1, 73, 65, 69, 77, -1, 72, 73, 77, 76, -1, 76, 77, 69, 68, -1, 68, 69, 65, 64, -1, 64, 65, 73, 72, 31, 73, 77, 69, 65, -1, 74, 66, 70, 78, -1, 73, 74, 78, 77, -1, 77, 78, 70, 69, -1, 69, 70, 66, 65, -1, 65, 66, 74, 73, 31, 74, 78, 70, 66, -1, 75, 67, 71, 79, -1, 74, 75, 79, 78, -1, 78, 79, 71, 70, -1, 70, 71, 67, 66, -1,
1644 66, 67, 75, 74, 31, 2, 3, 13, 81, -1, 24, 90, 68, 28, -1, 2, 24, 28, 3, -1, 3, 28, 68, 13, -1, 13, 68, 90, 81, -1, 81, 90, 24, 2, 31, 24, 28, 68, 90, -1, 25, 91, 69, 29, -1, 24, 25, 29, 28, -1, 28, 29, 69, 68, -1, 68, 69, 91, 90, -1, 90, 91, 25, 24, 31, 25, 29, 69, 91, -1, 26, 92, 88, 30, -1, 25, 26, 30, 29, -1, 29, 30, 88, 69, -1, 69, 88, 92, 91, -1, 91, 92, 26, 25, 31, 26, 30, 88, 92, -1, 27, 93, 89, 31, -1, 26, 27, 31, 30, -1, 30, 31, 89, 88, -1, 88, 89, 93, 92, -1, 92, 93, 27, 26, 31, 13, 3, 5, 9, -1, 68, 52, 36, 28, -1, 13, 68, 28, 3, -1, 3, 28, 36, 5, -1, 5, 36, 52, 9, -1, 9, 52, 68, 13, 31, 68, 28, 36, 52, -1, 69, 53, 37, 29, -1, 68, 69, 29,
1645 28, -1, 28, 29, 37, 36, -1, 36, 37, 53, 52, -1, 52, 53, 69, 68, 31, 69, 29, 37, 53, -1, 88, 86, 38, 30, -1, 69, 88, 30, 29, -1, 29, 30, 38, 37, -1, 37, 38, 86, 53, -1, 53, 86, 88, 69, 31, 88, 30, 38, 86, -1, 89, 87, 39, 31, -1, 88, 89, 31, 30, -1, 30, 31, 39, 38, -1, 38, 39, 87, 86, -1, 86, 87, 89, 88])
1646 cI = DataArrayInt([0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 600, 630, 660, 690, 720, 750, 780, 810, 840, 870, 900, 930, 960, 990, 1020, 1050, 1080])
1647 m3.setConnectivity(c, cI)
1648 m3.checkConsistency()
1649 m2, _, _, _, _ = m3.buildDescendingConnectivity()
1650 grpIds = DataArrayInt([2,7,12,17,95,99,103,107,129,133,137,141]); grpIds.setName("group")
1651 mfu = MEDFileUMesh()
1652 mfu.setMeshAtLevel(0, m3)
1653 mfu.setMeshAtLevel(-1, m2)
1654 mfu.setGroupsAtLevel(-1, [grpIds])
1655 nNod = m3.getNumberOfNodes()
1656 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1657 m3_bis = mfu.getMeshAtLevel(0)
1658 m3_bis.checkConsistency()
1659 m2_bis = mfu.getMeshAtLevel(-1)
1660 m2_bis.checkConsistency()
1661 self.assertEqual(nNod+22, mfu.getNumberOfNodes())
1662 self.assertEqual(nNod+22, m3_bis.getNumberOfNodes())
1663 self.assertEqual(nNod+22, m2_bis.getNumberOfNodes())
1664 self.assertEqual([0, 3, 12, 13, 16, 17, 18, 19, 28, 29, 30, 31, 64, 65, 66, 67, 68, 69, 70, 71, 88, 89], nodesDup.getValues())
1665 self.assertEqual(m3_bis.getCoords()[nodesDup].getValues(), m3_bis.getCoords()[nNod:].getValues())
1666 self.assertEqual(set([0, 1, 2, 3, 24, 25, 26, 27, 28, 29, 30, 31]), set(cells1.getValues()))
1667 self.assertEqual(set([4, 5, 6, 7, 20, 21, 22, 23, 32, 33, 34, 35]), set(cells2.getValues()))
1668 self.assertEqual([2, 7, 12, 17, 95, 99, 103, 107, 129, 133, 137, 141],mfu.getGroupArr(-1,"group").getValues())
1669 self.assertEqual([151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162],mfu.getGroupArr(-1,"group_dup").getValues()) # here only one cell has been duplicated
1670 m_desc, _, _, _, _ = m3_bis.buildDescendingConnectivity()
1671 m_desc.checkDeepEquivalOnSameNodesWith(m2_bis, 2, 9.9999)
1674 def testBuildInnerBoundary8(self):
1675 """ 3D test where the crack leaves 'naked' cells. If we call a 'close-to-crack cell' a cell which shares a face with the M1 group,
1676 a 'naked cell' is a cell that has some node duplicated, but which do not share any face with a 'close-to-crack cell'. In this case
1677 it is tricky to decide whether this cell should be renumbered or not ...
1678 Warning: on the mesh below some points have already been doubled by a previous cut.
1680 m3 = MEDCouplingUMesh('box', 3)
1681 coo = DataArrayDouble([(0,15,0),(0,5,0),(3,5,0),(5,5,0),(5,15,0),(5,20,0),(0,20,0),(15,20,0),(15,15,0),(20,15,0),(20,20,0),(20,5,0),(15,5,0),(15,0,0),(20,0,0),(5,-1.60551e-25,0),(5,3,0),(3,0,0),
1682 (3,3,0),(0,0,0),(0,3,0),(0,15,10),(0,15,20),(0,15,30),(0,15,40),(0,5,10),(0,5,20),(0,5,30),(0,5,40),(3,5,10),(3,5,20),(3,5,30),(3,5,40),(5,5,10),(5,5,20),(5,5,30),(5,5,40),(5,15,10),(5,15,20),(5,15,30),
1683 (5,15,40),(5,20,10),(5,20,20),(5,20,30),(5,20,40),(0,20,10),(0,20,20),(0,20,30),(0,20,40),(15,20,10),(15,20,20),(15,20,30),(15,20,40),(15,15,10),(15,15,20),(15,15,30),(15,15,40),(20,15,10),(20,15,20),
1684 (20,15,30),(20,15,40),(20,20,10),(20,20,20),(20,20,30),(20,20,40),(20,5,10),(20,5,20),(20,5,30),(20,5,40),(15,5,10),(15,5,20),(15,5,30),(15,5,40),(15,0,10),(15,0,20),(15,0,30),(15,0,40),(20,0,10),
1685 (20,0,20),(20,0,30),(20,0,40),(5,-1.60551e-25,10),(5,-1.60551e-25,20),(5,-1.60551e-25,30),(5,-1.60551e-25,40),(5,3,10),(5,3,20),(5,3,30),(5,3,40),(3,0,10),(3,0,20),(3,0,30),(3,0,40),(3,3,10),(3,3,20),
1686 (3,3,30),(3,3,40),(0,0,10),(0,0,20),(0,0,30),(0,0,40),(0,3,10),(0,3,20),(0,3,30),(0,3,40),(0,9,0),(3,9,0),(20,9,0),(0,9,10),(0,9,20),(0,9,30),(0,9,40),(3,9,10),(3,9,20),(3,9,30),(3,9,40),(5,9,30),
1687 (5,9,40),(20,9,10),(20,9,20),(20,9,30),(20,9,40),(15,9,30),(15,9,40),(0,15,0),(20,15,0),(0,15,10),(0,15,20),(0,15,30),(0,15,40),(5,15,30),(5,15,40),(15,15,30),(15,15,40),(20,15,10),(20,15,20),(20,15,30),
1690 c = DataArrayInt([31, 5, 4, 124, 6, -1, 41, 45, 126, 37, -1, 5, 41, 37, 4, -1, 4, 37, 126, 124, -1, 124, 126, 45, 6, -1, 6, 45, 41, 5, 31, 41, 37, 126, 45, -1, 42, 46, 127, 38, -1, 41, 42, 38, 37, -1, 37, 38, 127, 126, -1, 126, 127, 46, 45, -1, 45, 46, 42, 41, 31, 42, 38, 127, 46, -1, 43, 47, 128, 130, -1, 42, 43, 130, 38, -1, 38, 130, 128, 127, -1, 127, 128, 47, 46, -1, 46, 47, 43, 42, 31, 43, 130, 128, 47,
1691 -1, 44, 48, 129, 131, -1, 43, 44, 131, 130, -1, 130, 131, 129, 128, -1, 128, 129, 48, 47, -1, 47, 48, 44, 43, 31, 7, 8, 4, 5, -1, 49, 41, 37, 53, -1, 7, 49, 53, 8, -1, 8, 53, 37, 4, -1, 4, 37, 41, 5, -1, 5, 41, 49, 7, 31, 49, 53, 37, 41, -1, 50, 42, 38, 54, -1, 49, 50, 54, 53, -1, 53, 54, 38, 37, -1, 37, 38, 42, 41, -1, 41, 42, 50, 49, 31, 50, 54, 38, 42, -1, 51, 43, 130, 132, -1, 50, 51, 132, 54, -1, 54, 132,
1692 130, 38, -1, 38, 130, 43, 42, -1, 42, 43, 51, 50, 31, 51, 132, 130, 43, -1, 52, 44, 131, 133, -1, 51, 52, 133, 132, -1, 132, 133, 131, 130, -1, 130, 131, 44, 43, -1, 43, 44, 52, 51, 31, 125, 8, 7, 10, -1, 134, 61, 49, 53, -1, 125, 134, 53, 8, -1, 8, 53, 49, 7, -1, 7, 49, 61, 10, -1, 10, 61, 134, 125, 31, 134, 53, 49, 61, -1, 135, 62, 50, 54, -1, 134, 135, 54, 53, -1, 53, 54, 50, 49, -1, 49, 50, 62, 61, -1,
1693 61, 62, 135, 134, 31, 135, 54, 50, 62, -1, 136, 63, 51, 132, -1, 135, 136, 132, 54, -1, 54, 132, 51, 50, -1, 50, 51, 63, 62, -1, 62, 63, 136, 135, 31, 136, 132, 51, 63, -1, 137, 64, 52, 133, -1, 136, 137, 133, 132, -1, 132, 133, 52, 51, -1, 51, 52, 64, 63, -1, 63, 64, 137, 136, 31, 107, 12, 8, 9, -1, 118, 57, 53, 69, -1, 107, 118, 69, 12, -1, 12, 69, 53, 8, -1, 8, 53, 57, 9, -1, 9, 57, 118, 107, 31, 118, 69,
1694 53, 57, -1, 119, 58, 54, 70, -1, 118, 119, 70, 69, -1, 69, 70, 54, 53, -1, 53, 54, 58, 57, -1, 57, 58, 119, 118, 31, 119, 70, 54, 58, -1, 120, 59, 55, 122, -1, 119, 120, 122, 70, -1, 70, 122, 55, 54, -1, 54, 55, 59, 58, -1, 58, 59, 120, 119, 31, 120, 122, 55, 59, -1, 121, 60, 56, 123, -1, 120, 121, 123, 122, -1, 122, 123, 56, 55, -1, 55, 56, 60, 59, -1, 59, 60, 121, 120, 31, 13, 12, 11, 14, -1, 73, 77, 65, 69,
1695 -1, 13, 73, 69, 12, -1, 12, 69, 65, 11, -1, 11, 65, 77, 14, -1, 14, 77, 73, 13, 31, 73, 69, 65, 77, -1, 74, 78, 66, 70, -1, 73, 74, 70, 69, -1, 69, 70, 66, 65, -1, 65, 66, 78, 77, -1, 77, 78, 74, 73, 31, 74, 70, 66, 78, -1, 75, 79, 67, 71, -1, 74, 75, 71, 70, -1, 70, 71, 67, 66, -1, 66, 67, 79, 78, -1, 78, 79, 75, 74, 31, 75, 71, 67, 79, -1, 76, 80, 68, 72, -1, 75, 76, 72, 71, -1, 71, 72, 68, 67, -1, 67, 68, 80,
1696 79, -1, 79, 80, 76, 75, 31, 17, 18, 16, 15, -1, 89, 81, 85, 93, -1, 17, 89, 93, 18, -1, 18, 93, 85, 16, -1, 16, 85, 81, 15, -1, 15, 81, 89, 17, 31, 89, 93, 85, 81, -1, 90, 82, 86, 94, -1, 89, 90, 94, 93, -1, 93, 94, 86, 85, -1, 85, 86, 82, 81, -1, 81, 82, 90, 89, 31, 90, 94, 86, 82, -1, 91, 83, 87, 95, -1, 90, 91, 95, 94, -1, 94, 95, 87, 86, -1, 86, 87, 83, 82, -1, 82, 83, 91, 90, 31, 91, 95, 87, 83, -1, 92, 84,
1697 88, 96, -1, 91, 92, 96, 95, -1, 95, 96, 88, 87, -1, 87, 88, 84, 83, -1, 83, 84, 92, 91, 31, 19, 20, 18, 17, -1, 97, 89, 93, 101, -1, 19, 97, 101, 20, -1, 20, 101, 93, 18, -1, 18, 93, 89, 17, -1, 17, 89, 97, 19, 31, 97, 101, 93, 89, -1, 98, 90, 94, 102, -1, 97, 98, 102, 101, -1, 101, 102, 94, 93, -1, 93, 94, 90, 89, -1, 89, 90, 98, 97, 31, 98, 102, 94, 90, -1, 99, 91, 95, 103, -1, 98, 99, 103, 102, -1, 102, 103,
1698 95, 94, -1, 94, 95, 91, 90, -1, 90, 91, 99, 98, 31, 99, 103, 95, 91, -1, 100, 92, 96, 104, -1, 99, 100, 104, 103, -1, 103, 104, 96, 95, -1, 95, 96, 92, 91, -1, 91, 92, 100, 99, 31, 1, 2, 18, 20, -1, 25, 101, 93, 29, -1, 1, 25, 29, 2, -1, 2, 29, 93, 18, -1, 18, 93, 101, 20, -1, 20, 101, 25, 1, 31, 25, 29, 93, 101, -1, 26, 102, 94, 30, -1, 25, 26, 30, 29, -1, 29, 30, 94, 93, -1, 93, 94, 102, 101, -1, 101, 102,
1699 26, 25, 31, 26, 30, 94, 102, -1, 27, 103, 95, 31, -1, 26, 27, 31, 30, -1, 30, 31, 95, 94, -1, 94, 95, 103, 102, -1, 102, 103, 27, 26, 31, 27, 31, 95, 103, -1, 28, 104, 96, 32, -1, 27, 28, 32, 31, -1, 31, 32, 96, 95, -1, 95, 96, 104, 103, -1, 103, 104, 28, 27, 31, 3, 4, 8, 12, -1, 33, 69, 53, 37, -1, 3, 33, 37, 4, -1, 4, 37, 53, 8, -1, 8, 53, 69, 12, -1, 12, 69, 33, 3, 31, 33, 37, 53, 69, -1, 34, 70, 54, 38, -1,
1700 33, 34, 38, 37, -1, 37, 38, 54, 53, -1, 53, 54, 70, 69, -1, 69, 70, 34, 33, 31, 34, 38, 54, 70, -1, 116, 122, 55, 39, -1, 34, 116, 39, 38, -1, 38, 39, 55, 54, -1, 54, 55, 122, 70, -1, 70, 122, 116, 34, 31, 116, 39, 55, 122, -1, 117, 123, 56, 40, -1, 116, 117, 40, 39, -1, 39, 40, 56, 55, -1, 55, 56, 123, 122, -1, 122, 123, 117, 116, 31, 16, 18, 2, 3, -1, 85, 33, 29, 93, -1, 16, 85, 93, 18, -1, 18, 93, 29, 2,
1701 -1, 2, 29, 33, 3, -1, 3, 33, 85, 16, 31, 85, 93, 29, 33, -1, 86, 34, 30, 94, -1, 85, 86, 94, 93, -1, 93, 94, 30, 29, -1, 29, 30, 34, 33, -1, 33, 34, 86, 85, 31, 86, 94, 30, 34, -1, 87, 35, 31, 95, -1, 86, 87, 95, 94, -1, 94, 95, 31, 30, -1, 30, 31, 35, 34, -1, 34, 35, 87, 86, 31, 87, 95, 31, 35, -1, 88, 36, 32, 96, -1, 87, 88, 96, 95, -1, 95, 96, 32, 31, -1, 31, 32, 36, 35, -1, 35, 36, 88, 87, 31, 4, 3, 106,
1702 105, 0, -1, 37, 21, 108, 112, 33, -1, 3, 4, 37, 33, -1, 106, 3, 33, 112, -1, 105, 106, 112, 108, -1, 0, 105, 108, 21, -1, 4, 0, 21, 37, 31, 37, 33, 112, 108, 21, -1, 38, 22, 109, 113, 34, -1, 33, 37, 38, 34, -1, 112, 33, 34, 113, -1, 108, 112, 113, 109, -1, 21, 108, 109, 22, -1, 37, 21, 22, 38, 31, 38, 34, 113, 109, 22, -1, 39, 23, 110, 114, 116, -1, 34, 38, 39, 116, -1, 113, 34, 116, 114, -1, 109, 113, 114, 110,
1703 -1, 22, 109, 110, 23, -1, 38, 22, 23, 39, 31, 39, 116, 114, 110, 23, -1, 40, 24, 111, 115, 117, -1, 116, 39, 40, 117, -1, 114, 116, 117, 115, -1, 110, 114, 115, 111, -1, 23, 110, 111, 24, -1, 39, 23, 24, 40, 31, 16, 3, 12, 13, 15, -1, 85, 81, 73, 69, 33, -1, 3, 16, 85, 33, -1, 12, 3, 33, 69, -1, 13, 12, 69, 73, -1, 15, 13, 73, 81, -1, 16, 15, 81, 85, 31, 85, 33, 69, 73, 81, -1, 86, 82, 74, 70, 34, -1, 33, 85,
1704 86, 34, -1, 69, 33, 34, 70, -1, 73, 69, 70, 74, -1, 81, 73, 74, 82, -1, 85, 81, 82, 86, 31, 86, 34, 70, 74, 82, -1, 87, 83, 75, 71, 35, -1, 34, 86, 87, 35, -1, 70, 34, 35, 71, -1, 74, 70, 71, 75, -1, 82, 74, 75, 83, -1, 86, 82, 83, 87, 31, 87, 35, 71, 75, 83, -1, 88, 84, 76, 72, 36, -1, 35, 87, 88, 36, -1, 71, 35, 36, 72, -1, 75, 71, 72, 76, -1, 83, 75, 76, 84, -1, 87, 83, 84, 88])
1705 cI = DataArrayInt([0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 600, 630, 660, 690, 720, 750, 780, 810, 840, 870, 900, 930, 960, 990, 1020, 1050, 1080, 1110, 1140, 1170, 1200, 1237, 1274, 1311, 1348, 1385, 1422, 1459, 1496])
1706 m3.setConnectivity(c, cI)
1707 m3.checkConsistency()
1708 m2, _, _, _, _ = m3.buildDescendingConnectivity()
1709 grpIds = DataArrayInt([2,7,12,17,101,106,111,116,160,164,170,173,176,179]); grpIds.setName("group")
1710 mfu = MEDFileUMesh()
1711 mfu.setMeshAtLevel(0, m3)
1712 mfu.setMeshAtLevel(-1, m2)
1713 mfu.setGroupsAtLevel(-1, [grpIds])
1714 nNod = m3.getNumberOfNodes()
1715 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1716 m3_bis = mfu.getMeshAtLevel(0)
1717 m3_bis.checkConsistency()
1718 m2_bis = mfu.getMeshAtLevel(-1)
1719 m2_bis.checkConsistency()
1720 self.assertEqual(nNod+23, mfu.getNumberOfNodes())
1721 self.assertEqual(nNod+23, m3_bis.getNumberOfNodes())
1722 self.assertEqual(nNod+23, m2_bis.getNumberOfNodes())
1723 self.assertEqual([5, 15, 16, 35, 36, 39, 40, 41, 42, 43, 44, 81, 82, 83, 84, 85, 86, 87, 88, 116, 117, 130, 131], nodesDup.getValues())
1724 self.assertEqual(m3_bis.getCoords()[nodesDup].getValues(), m3_bis.getCoords()[nNod:].getValues())
1725 self.assertEqual(set([0, 1, 2, 3, 20, 21, 22, 23, 34, 35, 36, 37, 38, 39]), set(cells1.getValues()))
1726 self.assertEqual(set([4, 5, 6, 7, 42, 43, 44, 45, 46, 47]), set(cells2.getValues()))
1727 self.assertEqual([2, 7, 12, 17, 101, 106, 111, 116, 160, 164, 170, 173, 176, 179],mfu.getGroupArr(-1,"group").getValues())
1728 self.assertEqual([212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225],mfu.getGroupArr(-1,"group_dup").getValues()) # here only one cell has been duplicated
1729 m_desc, _, _, _, _ = m3_bis.buildDescendingConnectivity()
1730 m_desc.checkDeepEquivalOnSameNodesWith(m2_bis, 2, 9.9999)
1733 def testBuildInnerBoundary9(self):
1734 """ 3D test where the crack is performed so that two non-connex parts are found facing one single connex part on the other side
1737 m3 = MEDCouplingUMesh('box', 3)
1738 coo = DataArrayDouble([(0,4.6,0),(3,4.6,0),(5,4.6,0),(15,4.6,0),(15,0,0),(5,-1.60551e-25,0),(5,3,0),(3,0,0),(3,3.8,0),(0,0,0),(0,3.8,0),(0,4.6,10),(0,4.6,20),(3,4.6,10),(3,4.6,20),(5,4.6,10),(5,4.6,20),(15,4.6,10),(15,4.6,20),(15,0,10),(15,0,20),(5,-1.60551e-25,10),(5,-1.60551e-25,20),(5,3,10),(5,3,20),(3,0,10),(3,0,20),(3,3.8,10),(3,3.8,20),(0,0,10),(0,0,20),(0,3.8,10),(0,3.8,20),(3,3,0),(0,3,0),(3,3,10),(3,3,20),(0,3,10),(0,3,20)])
1740 c = DataArrayInt([31, 7, 33, 6, 5, -1, 25, 21, 23, 35, -1, 7, 25, 35, 33, -1, 33, 35, 23, 6, -1, 6, 23, 21, 5, -1, 5, 21, 25, 7, 31, 25, 35, 23, 21, -1, 26, 22, 24, 36, -1, 25, 26, 36, 35, -1, 35, 36, 24, 23, -1, 23, 24, 22, 21, -1, 21, 22, 26, 25, 31, 9, 34, 33, 7, -1, 29, 25, 35, 37, -1, 9, 29, 37, 34, -1, 34, 37, 35, 33, -1, 33, 35, 25, 7, -1, 7, 25, 29, 9, 31, 29, 37, 35, 25, -1, 30, 26, 36, 38, -1, 29, 30, 38, 37, -1, 37, 38, 36, 35, -1, 35, 36, 26, 25, -1, 25, 26, 30, 29, 31, 0, 1, 8, 10, -1, 11, 31, 27, 13, -1, 0, 11, 13, 1, -1, 1, 13, 27, 8, -1, 8, 27, 31, 10, -1, 10, 31, 11, 0, 31, 11, 13, 27, 31, -1, 12, 32, 28, 14, -1, 11, 12, 14, 13, -1, 13, 14, 28, 27, -1, 27, 28, 32, 31, -1, 31, 32, 12, 11, 31, 6, 8, 1, 2, -1, 23, 15, 13, 27, -1, 6, 23, 27, 8, -1, 8, 27, 13, 1, -1, 1, 13, 15, 2, -1, 2, 15, 23, 6, 31, 23, 27, 13, 15, -1, 24, 16, 14, 28, -1, 23, 24, 28, 27, -1, 27, 28, 14, 13, -1, 13, 14, 16, 15, -1, 15, 16, 24, 23, 31, 6, 2, 3, 4, 5, -1, 23, 21, 19, 17, 15, -1, 2, 6, 23, 15, -1, 3, 2, 15, 17, -1, 4, 3, 17, 19, -1, 5, 4, 19, 21, -1, 6, 5, 21, 23, 31, 23, 15, 17, 19, 21, -1, 24, 22, 20, 18, 16, -1, 15, 23, 24, 16, -1, 17, 15, 16, 18, -1, 19, 17, 18, 20, -1, 21, 19, 20, 22, -1, 23, 21, 22, 24])
1741 cI = DataArrayInt([0, 30, 60, 90, 120, 150, 180, 210, 240, 277, 314])
1742 m3.setConnectivity(c, cI)
1743 m3.checkConsistency()
1744 m2, _, _,_,_ = m3.buildDescendingConnectivity()
1745 grpIds = DataArrayInt([4,9,35,39]); grpIds.setName("group")
1746 mfu = MEDFileUMesh()
1747 mfu.setMeshAtLevel(0, m3)
1748 mfu.setMeshAtLevel(-1, m2)
1749 mfu.setGroupsAtLevel(-1, [grpIds])
1750 m2, _, _, _, _ = m3.buildDescendingConnectivity()
1751 grpIds = DataArrayInt([4,9,35,39]); grpIds.setName("group")
1752 mfu = MEDFileUMesh()
1753 mfu.setMeshAtLevel(0, m3)
1754 mfu.setMeshAtLevel(-1, m2)
1755 mfu.setGroupsAtLevel(-1, [grpIds])
1756 nNod = m3.getNumberOfNodes()
1757 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1758 m3_bis = mfu.getMeshAtLevel(0)
1759 m3_bis.checkConsistency()
1760 m2_bis = mfu.getMeshAtLevel(-1)
1761 m2_bis.checkConsistency()
1762 self.assertEqual(nNod+9, mfu.getNumberOfNodes())
1763 self.assertEqual(nNod+9, m3_bis.getNumberOfNodes())
1764 self.assertEqual(nNod+9, m2_bis.getNumberOfNodes())
1765 self.assertEqual([2, 5, 6, 15, 16, 21, 22, 23, 24], nodesDup.getValues())
1766 self.assertEqual(m3_bis.getCoords()[nodesDup].getValues(), m3_bis.getCoords()[nNod:].getValues())
1767 self.assertEqual(set([0,1,6,7]), set(cells1.getValues()))
1768 self.assertEqual(set([8,9]), set(cells2.getValues()))
1769 self.assertEqual([4,9,35,39],mfu.getGroupArr(-1,"group").getValues())
1770 self.assertEqual([49, 50, 51, 52],mfu.getGroupArr(-1,"group_dup").getValues()) # here only one cell has been duplicated
1771 m_desc, _, _, _, _ = m3_bis.buildDescendingConnectivity()
1772 m_desc.checkDeepEquivalOnSameNodesWith(m2_bis, 2, 9.9999)
1775 def testBuildInnerBoundary10(self):
1776 """ 2D tests where some cells are touching the M1 group with just a node, and are **not** neighbor
1777 with any cells touching the M1 group by a face.
1779 m2 = MEDCouplingUMesh("mesh", 2)
1780 coo = DataArrayDouble([0.0, 0.0, 1.0, 0.0, 2.0, 0.0, 3.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 1.0, 3.0, 1.0, 0.0, 2.0, 1.0, 2.0, 2.0, 2.0, 3.0, 2.0, 2.5, 0.0, 3.0, 0.5], 14, 2)
1782 c = DataArrayInt([ 3,12,2,6, 3,3,12,6, 3,13,3,6, 3,7,13,6, 4, 1, 0, 4, 5, 4, 2, 1, 5, 6, 4, 5, 4, 8, 9, 4, 6, 5, 9, 10, 4, 7, 6, 10, 11])
1783 cI = DataArrayInt([0,4,8,12,16,21,26,31,36,41])
1784 m2.setConnectivity(c, cI)
1785 m2.checkConsistency()
1786 m1, _, _, _, _ = m2.buildDescendingConnectivity()
1787 grpIds = DataArrayInt([8,14]); grpIds.setName("group")
1788 mfu = MEDFileUMesh()
1789 mfu.setMeshAtLevel(0, m2)
1790 mfu.setMeshAtLevel(-1, m1)
1791 mfu.setGroupsAtLevel(-1, [grpIds])
1792 nNod = m2.getNumberOfNodes()
1793 nodesDup, cells1, cells2 = mfu.buildInnerBoundaryAlongM1Group("group")
1794 m2_bis = mfu.getMeshAtLevel(0)
1795 m2_bis.checkConsistency()
1796 m1_bis = mfu.getMeshAtLevel(-1)
1797 m1_bis.checkConsistency()
1798 self.assertEqual(nNod+2, mfu.getNumberOfNodes())
1799 self.assertEqual(nNod+2, m2_bis.getNumberOfNodes())
1800 self.assertEqual(nNod+2, m1_bis.getNumberOfNodes())
1801 self.assertEqual([6, 7], nodesDup.getValues())
1802 self.assertEqual([2.,1., 3.,1.], m2_bis.getCoords()[nNod:].getValues())
1803 self.assertEqual(set([0,1,2,3,5]), set(cells1.getValues()))
1804 self.assertEqual(set([7,8]), set(cells2.getValues()))
1805 self.assertEqual([8,14],mfu.getGroupArr(-1,"group").getValues())
1806 self.assertEqual([22,23],mfu.getGroupArr(-1,"group_dup").getValues())
1810 def testBasicConstructors(self):
1811 GeneratePyfile18(self)
1812 fname="Pyfile18.med"
1813 TestWriteUMeshesRW1(self)
1814 m=MEDFileMesh.New(fname)
1815 m=MEDFileMesh.New(fname,"ExampleOfMultiDimW",-1,-1)
1816 m=MEDFileMesh.New(fname)
1817 m=MEDFileUMesh(fname,"ExampleOfMultiDimW",-1,-1)
1818 m=MEDFileUMesh(fname)
1820 self.internalMEDMesh6()
1821 m=MEDFileCMesh("MEDFileMesh5.med")
1822 m=MEDFileCMesh("MEDFileMesh5.med","myFirstCartMesh",-1,-1)
1824 m=MEDFileMeshMultiTS()
1825 m=MEDFileMeshMultiTS(fname)
1826 m=MEDFileMeshMultiTS(fname,"ExampleOfMultiDimW")
1828 m=MEDFileMeshes(fname)
1830 m=MEDFileField1TS(fname,"FieldOnFacesShuffle",2,7)
1831 m=MEDFileFieldMultiTS()
1832 m=MEDFileFieldMultiTS(fname,"FieldOnFacesShuffle")
1834 m=MEDFileFields(fname)
1836 m=MEDFileData(fname)
1838 m=DataArrayInt() ; m=DataArrayInt(5,2) ; m=DataArrayInt([6,5,4,3,2,1],3,2)
1839 m=DataArrayDouble() ; m=DataArrayDouble(5,2) ; m=DataArrayDouble([6,5,4,3,2,1],3,2)
1840 m=MEDCouplingUMesh("jjj",2) ; m=MEDCouplingUMesh()
1841 m=MEDCouplingCMesh()
1842 m=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
1843 m=MEDCouplingFieldTemplate(ON_NODES)
1844 m=MEDCouplingMultiFields([])
1845 m=MEDCouplingFieldOverTime([])
1848 # This is a non regression test. When a field lies partially on a mesh but fully on one of its geometric type.
1850 def testBugSemiPartialField(self):
1851 fname="Pyfile46.med"
1852 m=MEDLoaderDataForTest.build2DMesh_3()
1853 m=m[:10] ; m.setName("mesh")
1854 f=m.getMeasureField(False)
1855 f=f.buildNewTimeReprFromThis(ONE_TIME,False)
1857 f.setName("SemiPartialField")
1859 f1=f[:6] ; f1.getMesh().setName(m.getName())
1860 f2=f[6:] ; f2.getMesh().setName(m.getName())
1862 mm=MEDFileUMesh.New()
1863 mm.setMeshAtLevel(0,m)
1864 ff=MEDFileField1TS.New()
1865 ff.setFieldProfile(f1,mm,0,DataArrayInt.Range(0,6,1)) # no name on profile -> normally it is an error but in this special case
1869 ff2=MEDFileField1TS.New(fname,f.getName(),f.getTime()[1],f.getTime()[2])
1870 fread=ff2.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
1871 fread2=ff2.getFieldAtLevel(ON_CELLS,0)
1873 fread.checkConsistencyLight()
1874 fread2.checkConsistencyLight()
1875 self.assertTrue(fread.isEqual(f1,1e-12,1e-12))
1876 self.assertTrue(fread2.isEqual(f1,1e-12,1e-12))
1880 def testUnPolyze1(self):
1881 fname="Pyfile47.med"
1882 mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1883 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]
1884 self.assertEqual(ref,mm.getFamilyFieldAtLevel(1).getValues())
1885 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]]))
1887 self.assertEqual(mm.getGroupArr(0,"grp0_L0").getValues(),[0,1,2,6])
1888 self.assertEqual(mm.getGroupArr(0,"grp1_L0").getValues(),[1,3,4,5,6])
1889 self.assertEqual(mm.getGroupArr(-1,"grp0_LM1").getValues(),[1,2,3,4,5])
1890 self.assertEqual(mm.getGroupArr(-1,"grp1_LM1").getValues(),[3,4,5,6])
1891 self.assertEqual(mm.getGroupArr(-1,"grp2_LM1").getValues(),[2,6,7,8])
1892 self.assertEqual(mm.getGroupArr(1,"grp0_Node").getValues(),[0,11,15,16])
1893 self.assertEqual(mm.getGroupArr(1,"grp1_Node").getValues(),[1,2,13,14,16])
1894 self.assertEqual(mm.getFamilyFieldAtLevel(1).getValues(),ref)
1896 mm.setRenumFieldArr(0,None)
1897 mm.setFamilyFieldArr(-1,None)
1901 def testUnPolyze2(self):
1902 fname="Pyfile48.med"
1903 mfd=MEDFileData.New()
1904 mm=MEDLoaderDataForTest.buildMLMeshUnPolyze(self)
1905 meshes=MEDFileMeshes.New()
1907 mfd.setMeshes(meshes)
1908 fields=MEDFileFields.New()
1909 mfd.setFields(fields)
1910 ff=MEDFileFieldMultiTS.New()
1911 fields.pushField(ff)
1913 f0_0=MEDCouplingFieldDouble.New(ON_NODES,ONE_TIME) ; f0_0.setName("f0")
1914 f0_0.setTime(9.5,3,4)
1915 da=DataArrayDouble.New(38*2) ; da.iota(6.) ; da.rearrange(2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1917 f0_0.setMesh(mm.getMeshAtLevel(0))
1918 ff.appendFieldNoProfileSBT(f0_0)
1919 ff0=ff.getTimeStepAtPos(0)
1920 f0_1=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_1.setName("f0")
1921 f0_1.setTime(9.5,3,4)
1922 pfl=DataArrayInt.New([1,4,5,6]) ; pfl.setName("pfltest")
1923 f0_1.setMesh(mm.getMeshAtLevel(0)[pfl])
1924 da=DataArrayDouble.New([1401.,101401.,1602.,101602.,3100.,103100.,3101.,103101.],4,2) ; da.setInfoOnComponents(["Power [MW]","Density [kg/m^3]"])
1926 ff0.setFieldProfile(f0_1,mm,0,pfl)
1927 f0_2=MEDCouplingFieldDouble.New(ON_CELLS,ONE_TIME) ; f0_2.setName("f0")#provoquer error
1928 f0_2.setTime(9.5,3,4)
1929 pfl2=DataArrayInt.New([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfltestM1")
1930 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
1931 f0_2.setMesh(mm.getMeshAtLevel(-1)[pfl2])
1933 ff0.setFieldProfile(f0_2,mm,-1,pfl2)
1934 mfd.getFields().shallowCpyGlobs(ff0)
1936 mfd.unPolyzeMeshes()
1938 fmts=mfd.getFields()[0]
1939 self.assertEqual(fmts.getNumberOfTS(),1)
1940 self.assertEqual(fmts.getTimeSteps(),[(3,4,9.5)])
1941 arr,entry=fmts.getUndergroundDataArrayExt(3,4)
1942 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))])
1943 self.assertTrue(arr[38:40].isEqualWithoutConsideringStr(DataArrayDouble([300.0,100300.0,301.0,100301.0],2,2),1e-8))
1944 self.assertTrue(arr[40:43].isEqualWithoutConsideringStr(DataArrayDouble([400.0,100400.0,401.0,100401.0,402.0,100402.0],3,2),1e-8))
1945 self.assertTrue(arr[43:46].isEqualWithoutConsideringStr(DataArrayDouble([3200.0,103200.0,3201.0,103201.0,3203.0,103203.0],3,2),1e-8))
1946 self.assertTrue(arr[46:48].isEqualWithoutConsideringStr(DataArrayDouble([1401.0,101401.0,3100.0,103100.0],2,2),1e-8))
1947 self.assertTrue(arr[48:49].isEqualWithoutConsideringStr(DataArrayDouble([1602.0,101602.0],1,2),1e-8))
1948 self.assertTrue(arr[49:50].isEqualWithoutConsideringStr(DataArrayDouble([3101.0,103101.0],1,2),1e-8))
1949 self.assertEqual(('NewPfl_0','NewPfl_1','NewPfl_2'),fmts.getPflsReallyUsed())
1950 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))
1951 self.assertEqual(fmts.getProfile("NewPfl_0").getValues(),[0,1])
1952 self.assertEqual(fmts.getProfile("NewPfl_1").getValues(),[1,2])
1953 self.assertEqual(fmts.getProfile("NewPfl_2").getValues(),[2])
1954 ftest0=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,0,mfd.getMeshes()[0])
1955 self.assertTrue(ftest0.getArray().isEqualWithoutConsideringStr(DataArrayDouble([1401.,101401.,3100.,103100.,1602.,101602.,3101.,103101.],4,2),1e-8))
1956 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])
1957 self.assertEqual(ftest0.getMesh().getNodalConnectivityIndex().getValues(),[0,5,10,17,26])
1958 ftest1=fmts.getFieldOnMeshAtLevel(ON_CELLS,3,4,-1,mfd.getMeshes()[0])
1959 self.assertTrue(ftest1.getArray().isEqualWithoutConsideringStr(DataArrayDouble([300.,100300.,301.,100301.,400.,100400.,401.,100401.,402.,100402.,3200.,103200.,3201.,103201.,3203.,103203.]),1e-8))
1960 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])
1961 self.assertEqual(ftest1.getMesh().getNodalConnectivityIndex().getValues(),[0,4,8,13,18,23,29,35,43])
1967 def testGaussWriteOnPfl1(self):
1968 fname="Pyfile49.med"
1969 fname2="Pyfile50.med"
1970 coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2)
1971 mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords)
1972 mQ8.allocateCells(1)
1973 mQ8.insertNextCell(NORM_QUAD8,list(range(8)))
1974 mQ8.finishInsertingCells()
1975 mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords)
1976 mQ4.allocateCells(1)
1977 mQ4.insertNextCell(NORM_QUAD4,list(range(4)))
1978 mQ4.finishInsertingCells()
1979 mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords)
1980 mT3.allocateCells(1)
1981 mT3.insertNextCell(NORM_TRI3,list(range(3)))
1982 mT3.finishInsertingCells()
1984 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.]]
1985 ms=11*[mT3]+2*[mQ4]+7*[mQ8]
1986 ms[:]=(elt.deepCopy() for elt in ms)
1987 for m,t in zip(ms,tr):
1988 d=m.getCoords() ; d+= t
1990 m=MEDCouplingUMesh.MergeUMeshes(ms)
1992 m2=m[:13] ; m2.setName(m.getName())
1993 ### 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.
1994 ### So here 2 pfls will be created (pfl_TRI3_loc_0 and pfl_TRI3_loc_1)
1995 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
1998 da=DataArrayDouble(34) ; da.iota(3.)
2000 f.setName("fieldCellOnPflWithoutPfl")
2001 fInvalid=f.deepCopy()
2002 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])
2003 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])
2004 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])
2005 f.checkConsistencyLight()
2006 fInvalid2=fInvalid.deepCopy()
2007 fInvalid2.getDiscretization().setArrayOfDiscIds(f.getDiscretization().getArrayOfDiscIds())
2010 mm.setMeshAtLevel(0,m)
2013 f1ts=MEDFileField1TS.New()
2014 pfl=DataArrayInt(list(range(13))) ; pfl.setName("pfl")
2015 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid,mm,0,pfl) # fails because no Gauss localization per cell set !
2016 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,fInvalid2,mm,0,pfl) # fails because no Gauss localization set whereas gauss locid per cell given !
2017 f1ts.setFieldProfile(f,mm,0,pfl)
2020 self.assertEqual(f1ts.getPfls(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
2021 self.assertEqual(f1ts.getPflsReallyUsed(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1'))
2022 da1=DataArrayInt([0,1,2,3,4,5,6,7,8]) ; da1.setName("pfl_NORM_TRI3_loc_0")
2023 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_0").isEqual(da1))
2024 da1=DataArrayInt([9,10]) ; da1.setName("pfl_NORM_TRI3_loc_1")
2025 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_1").isEqual(da1))
2026 self.assertEqual(f1ts.getLocs(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
2027 self.assertEqual(f1ts.getLocsReallyUsed(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2'))
2029 dataRead=MEDFileData.New(fname)
2030 mRead=dataRead.getMeshes()[0]
2031 f1tsRead=dataRead.getFields()[0][0]
2032 f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
2033 f2=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
2034 self.assertTrue(f.isEqual(f2,1e-12,1e-12))
2035 f2_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
2036 f2_bis.checkConsistencyLight()
2037 self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12))
2039 WriteField(fname2,f,True)
2040 f2_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
2041 self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12))
2042 ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc
2043 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
2044 pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2")
2045 m2=m[pfl] ; m2.setName(m.getName())
2048 da=DataArrayDouble(35) ; da.iota(3.)
2050 f.setName("fieldCellOnPflWithoutPfl2")
2051 f.setGaussLocalizationOnCells([0,1,3],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2])
2052 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])
2053 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])
2054 f.checkConsistencyLight()
2057 mm.setMeshAtLevel(0,m)
2059 f1ts=MEDFileField1TS.New()
2060 f1ts.setFieldProfile(f,mm,0,pfl)
2061 self.assertEqual(f1ts.getPfls(),('pfl2_NORM_TRI3_loc_0','pfl2_NORM_TRI3_loc_1','pfl2_NORM_QUAD8_loc_2'))
2062 self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_0").getValues(),[1,2,6])
2063 self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_1").getValues(),[5,8,9])
2064 self.assertEqual(f1ts.getProfile("pfl2_NORM_QUAD8_loc_2").getValues(),[2,3,4,5])
2066 dataRead=MEDFileData.New(fname)
2067 mRead=dataRead.getMeshes()[0]
2068 f1tsRead=dataRead.getFields()[0][0]
2069 f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
2070 f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
2071 f3.renumberCells([0,1,3,2,4,5,6,7,8,9])
2072 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
2073 f3_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
2074 f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9])
2075 self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
2077 WriteField(fname2,f,True)
2078 f3_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
2079 f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9])
2080 self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
2081 ## Use case 3 : no pfl but creation of pfls due to gauss pts
2082 f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME)
2085 da=DataArrayDouble(60) ; da.iota(3.)
2087 f.setName("fieldCellWithoutPfl")
2088 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])
2089 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])
2090 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])
2091 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])
2092 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])
2093 f.checkConsistencyLight()
2095 mm.setMeshAtLevel(0,m)
2096 f1ts=MEDFileField1TS.New()
2097 f1ts.setFieldNoProfileSBT(f)
2098 self.assertEqual(f1ts.getPfls(),('Pfl_fieldCellWithoutPfl_NORM_TRI3_0','Pfl_fieldCellWithoutPfl_NORM_TRI3_1','Pfl_fieldCellWithoutPfl_NORM_QUAD8_3','Pfl_fieldCellWithoutPfl_NORM_QUAD8_4'))
2099 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_0").getValues(),[0,1,2,3,4,5,6,7,8])
2100 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_1").getValues(),[9,10])
2101 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_3").getValues(),[0,1,2,4,5])
2102 self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_4").getValues(),[3,6])
2106 dataRead=MEDFileData.New(fname)
2107 mRead=dataRead.getMeshes()[0]
2108 f1tsRead=dataRead.getFields()[0][0]
2109 f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead)
2110 f3.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
2111 self.assertTrue(f.isEqual(f3,1e-12,1e-12))
2112 f3_bis=ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
2113 f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
2114 self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12))
2116 WriteField(fname2,f,True)
2117 f3_ter=ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2])
2118 f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19])
2119 self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12))
2122 # Testing profile on nodes when the profile is identity but not on all nodes.
2124 def testMEDFieldPflOnNode1(self):
2125 fname="Pyfile51.med"
2126 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)
2127 m0=MEDCouplingUMesh("Mesh",2)
2129 m0.insertNextCell(NORM_TRI3,[1,4,2])
2130 m0.insertNextCell(NORM_TRI3,[4,5,2])
2131 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
2132 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
2133 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
2134 m0.finishInsertingCells()
2136 m1=MEDCouplingUMesh(m0.getName(),1)
2138 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
2140 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
2142 m1.finishInsertingCells()
2146 m.setMeshAtLevel(0,m0)
2147 m.setMeshAtLevel(-1,m1)
2149 dt=3 ; it=2 ; tim=4.5
2150 fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
2151 fieldNode0.setName("fieldNode0")
2152 fieldNode0.setTime(tim,dt,it)
2153 pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
2154 arr=DataArrayDouble([10,11,12,13,14])
2155 fieldNode0.setArray(arr)
2156 f0=MEDFileField1TS()
2157 f0.setFieldProfile(fieldNode0,m,0,pfl0)
2158 m.write(fname,2) ; f0.write(fname,0)
2159 fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
2160 fieldNode1.setName("fieldNode1")
2161 fieldNode1.setTime(tim,dt,it)
2162 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
2163 arr1=DataArrayDouble([20,21,22,23,24,25,26])
2164 fieldNode1.setArray(arr1)
2165 f1=MEDFileField1TS()
2166 f1.setFieldProfile(fieldNode1,m,-1,pfl1)
2169 ## Reading from file
2170 m=MEDFileMesh.New(fname)
2171 m0=m.getMeshAtLevel(0)
2172 m00=m0.deepCopy() ; m00=m00[[0,2]] ; m00.setName(m.getName()) ; m00.zipCoords()
2173 fieldNode0.setMesh(m00)
2174 f0=MEDFileField1TS.New(fname,fieldNode0.getName(),dt,it)
2175 ff0_1=f0.getFieldOnMeshAtLevel(ON_NODES,m0)
2176 ff0_1.checkConsistencyLight()
2177 self.assertTrue(ff0_1.isEqual(fieldNode0,1e-12,1e-12))
2178 ff0_2=f0.getFieldAtLevel(ON_NODES,0)
2179 ff0_2.checkConsistencyLight()
2180 self.assertTrue(ff0_2.isEqual(fieldNode0,1e-12,1e-12))
2181 ff0_3=f0.getFieldOnMeshAtLevel(ON_NODES,0,m)
2182 ff0_3.checkConsistencyLight()
2183 self.assertTrue(ff0_3.isEqual(fieldNode0,1e-12,1e-12))
2184 ff0_4=ReadFieldNode(fname,m.getName(),0,fieldNode0.getName(),dt,it)
2185 ff0_4.checkConsistencyLight()
2186 self.assertTrue(ff0_4.isEqual(fieldNode0,1e-12,1e-12))
2187 f1=MEDFileField1TS.New(fname,fieldNode1.getName(),dt,it)
2188 m1=m.getMeshAtLevel(-1)
2189 m10=m1.deepCopy() ; m10=m10[[0,1,2,3,4,5,6,7]] ; m10.setName(m.getName()) ; m10.zipCoords()
2190 fieldNode1.setMesh(m10)
2191 ff1_1=f1.getFieldOnMeshAtLevel(ON_NODES,m1)
2192 ff1_1.checkConsistencyLight()
2193 self.assertTrue(ff1_1.isEqual(fieldNode1,1e-12,1e-12))
2194 ff1_2=f1.getFieldAtLevel(ON_NODES,-1)
2195 ff1_2.checkConsistencyLight()
2196 self.assertTrue(ff1_2.isEqual(fieldNode1,1e-12,1e-12))
2197 ff1_3=f1.getFieldOnMeshAtLevel(ON_NODES,-1,m)
2198 ff1_3.checkConsistencyLight()
2199 self.assertTrue(ff1_3.isEqual(fieldNode1,1e-12,1e-12))
2200 ff1_4=ReadFieldNode(fname,m.getName(),-1,fieldNode1.getName(),dt,it)
2201 ff1_4.checkConsistencyLight()
2202 self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
2203 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]
2204 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]
2205 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]
2206 arr_r,pfl1_r=f1.getFieldWithProfile(ON_NODES,-1,m)
2207 arr_r.setName(fieldNode1.getArray().getName())
2208 self.assertTrue(arr_r.isEqual(fieldNode1.getArray(),1e-12))
2209 pfl1_r.setName(pfl1.getName())
2210 self.assertTrue(pfl1_r.isEqual(pfl1))
2213 # Testing profile on nodes when the profile is identity but not on all nodes.
2215 def testMEDFieldPflOnCell1(self):
2216 fname="Pyfile52.med"
2217 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)
2218 m0=MEDCouplingUMesh("Mesh",2)
2220 m0.insertNextCell(NORM_TRI3,[1,4,2])
2221 m0.insertNextCell(NORM_TRI3,[4,5,2])
2222 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
2223 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
2224 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
2225 m0.finishInsertingCells()
2227 m1=MEDCouplingUMesh(m0.getName(),1)
2229 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
2231 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
2233 m1.finishInsertingCells()
2237 m.setMeshAtLevel(0,m0)
2238 m.setMeshAtLevel(-1,m1)
2240 dt=3 ; it=2 ; tim=4.5
2241 fieldCell0=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
2242 fieldCell0.setName("fieldCell0")
2243 fieldCell0.setTime(tim,dt,it)
2244 pfl0=DataArrayInt([0,1,2]) ; pfl0.setName("PflIdentity0") # important to keep like that
2245 arr=DataArrayDouble([10,11,12])
2246 fieldCell0.setArray(arr)
2247 f0=MEDFileField1TS()
2248 f0.setFieldProfile(fieldCell0,m,0,pfl0)
2249 m.write(fname,2) ; f0.write(fname,0)
2250 fieldCell1=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME)
2251 fieldCell1.setName("fieldCell1")
2252 fieldCell1.setTime(tim,dt,it)
2253 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
2254 arr1=DataArrayDouble([20,21,22,23,24,25,26])
2255 fieldCell1.setArray(arr1)
2256 f1=MEDFileField1TS()
2257 f1.setFieldProfile(fieldCell1,m,-1,pfl1)
2260 ## Reading from file
2261 m=MEDFileMesh.New(fname)
2262 m0=m.getMeshAtLevel(0)
2263 m00=m0.deepCopy() ; m00=m00[pfl0] ; m00.setName(m.getName())
2264 fieldCell0.setMesh(m00)
2265 f0=MEDFileField1TS.New(fname,fieldCell0.getName(),dt,it)
2266 ff0_1=f0.getFieldOnMeshAtLevel(ON_CELLS,m0)
2267 ff0_1.checkConsistencyLight()
2268 self.assertTrue(ff0_1.isEqual(fieldCell0,1e-12,1e-12))
2269 ff0_2=f0.getFieldAtLevel(ON_CELLS,0)
2270 ff0_2.checkConsistencyLight()
2271 self.assertTrue(ff0_2.isEqual(fieldCell0,1e-12,1e-12))
2272 ff0_3=f0.getFieldOnMeshAtLevel(ON_CELLS,0,m)
2273 ff0_3.checkConsistencyLight()
2274 self.assertTrue(ff0_3.isEqual(fieldCell0,1e-12,1e-12))
2275 ff0_4=ReadFieldCell(fname,m.getName(),0,fieldCell0.getName(),dt,it)
2276 ff0_4.checkConsistencyLight()
2277 self.assertTrue(ff0_4.isEqual(fieldCell0,1e-12,1e-12))
2278 f1=MEDFileField1TS.New(fname,fieldCell1.getName(),dt,it)
2279 m1=m.getMeshAtLevel(-1)
2280 m10=m1.deepCopy() ; m10=m10[pfl1] ; m10.setName(m.getName())
2281 fieldCell1.setMesh(m10)
2282 ff1_1=f1.getFieldOnMeshAtLevel(ON_CELLS,m1)
2283 ff1_1.checkConsistencyLight()
2284 self.assertTrue(ff1_1.isEqual(fieldCell1,1e-12,1e-12))
2285 ff1_2=f1.getFieldAtLevel(ON_CELLS,-1)
2286 ff1_2.checkConsistencyLight()
2287 self.assertTrue(ff1_2.isEqual(fieldCell1,1e-12,1e-12))
2288 ff1_3=f1.getFieldOnMeshAtLevel(ON_CELLS,-1,m)
2289 ff1_3.checkConsistencyLight()
2290 self.assertTrue(ff1_3.isEqual(fieldCell1,1e-12,1e-12))
2291 ff1_4=ReadFieldCell(fname,m.getName(),-1,fieldCell1.getName(),dt,it)
2292 ff1_4.checkConsistencyLight()
2293 self.assertTrue(ff1_4.getMesh().isEqual(m10,1e-12))
2294 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]
2295 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]
2296 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]
2297 arr_r,pfl1_r=f1.getFieldWithProfile(ON_CELLS,-1,m)
2298 arr_r.setName(fieldCell1.getArray().getName())
2299 self.assertTrue(arr_r.isEqual(fieldCell1.getArray(),1e-12))
2300 pfl1_r.setName(pfl1.getName())
2301 self.assertTrue(pfl1_r.isEqual(pfl1))
2305 def testMEDFileUMeshZipCoords1(self):
2307 coo=DataArrayDouble(30) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2308 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])
2309 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2310 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2311 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2312 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2313 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2314 numCoo=DataArrayInt(10) ; numCoo.iota(3) ; m.setRenumFieldArr(1,numCoo)
2315 famCoo=DataArrayInt(10) ; famCoo.iota(4) ; m.setFamilyFieldArr(1,famCoo)
2316 da=DataArrayInt([20,30,40]) ; m.setRenumFieldArr(0,da) ; da=DataArrayInt([200,300,400]) ; m.setFamilyFieldArr(0,da)
2317 da=DataArrayInt([50,60]) ; m.setRenumFieldArr(-1,da) ; da=DataArrayInt([500,600]) ; m.setFamilyFieldArr(-1,da)
2318 da=DataArrayInt([70,80,90]) ; m.setRenumFieldArr(-2,da) ; da=DataArrayInt([700,800,900]) ; m.setFamilyFieldArr(-2,da)
2320 self.assertTrue(o2n.isEqual(DataArrayInt([-1,0,1,2,3,-1,4,5,6,-1])))
2321 self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt([4,5,6,7,9,10,11])))
2322 self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([5,6,7,8,10,11,12])))
2323 self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivity().isEqual(DataArrayInt([3,0,1,2,4,1,3,2,3,5,0,4,4,4,1])))
2324 self.assertTrue(m.getMeshAtLevel(0).getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,9,15])))
2325 self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivity().isEqual(DataArrayInt([1,0,4,1,5,2])))
2326 self.assertTrue(m.getMeshAtLevel(-1).getNodalConnectivityIndex().isEqual(DataArrayInt([0,3,6])))
2327 self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivity().isEqual(DataArrayInt([0,1,0,4,0,6])))
2328 self.assertTrue(m.getMeshAtLevel(-2).getNodalConnectivityIndex().isEqual(DataArrayInt([0,2,4,6])))
2332 def testMEDUMeshAddNodeGroup1(self):
2333 fname="Pyfile53.med"
2335 coo=DataArrayDouble(39) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2336 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])
2337 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2338 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2339 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2340 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2341 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2344 famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(1,famCoo)
2345 da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(0,da0)
2346 da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
2347 da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
2348 mm.setFamilyId("MyFam",2)
2349 mm.setFamilyId("MyOtherFam",3)
2350 mm.setFamilyId("MyOther-1",-1)
2351 mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
2352 mm.setFamiliesOnGroup("grpA",["MyOther-1"])
2354 self.assertTrue(mm.getNodeFamiliesArr(["MyFam","MyOtherFam"]).isEqual(DataArrayInt([1,3,4,12]))) # find family id 2 and 3 into famCoo
2356 daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
2357 mm.addNodeGroup(daTest)
2358 self.assertTrue(mm.getNodeGroupArr(daTest.getName()).isEqual(daTest)) # the node group has been pushed right before -> now read it
2359 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
2361 expect1=DataArrayInt([1,4]) ; expect1.setName("MyFam")
2362 self.assertTrue(mm.getNodeFamilyArr(expect1.getName()).isEqual(expect1))
2364 self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
2365 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
2366 for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
2367 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2369 self.assertEqual(mm.getFamiliesNames(),('Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
2370 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2371 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2372 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2373 for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
2374 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2376 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_8'))
2377 da=DataArrayInt([3,12]) ; da.setName("grp0")
2378 self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
2380 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2382 mm=MEDFileMesh.New(fname)
2383 self.assertTrue(mm.getGroupArr(1,daTest.getName()).isEqual(daTest))
2384 self.assertTrue(mm.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([6,2,6,8,2,6,5,6,6,7,7,4,8])))
2385 for lev,arr in [(0,da0),(-1,da1),(-2,da2)]:
2386 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2388 self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_4','Family_5','Family_7','Family_8','MyFam','MyOther-1','MyOtherFam'))
2389 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2390 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2391 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2392 for famName,famId in [('Family_4',4),('Family_5',5),('Family_7',7),('Family_8',8)]:
2393 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2395 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_8','MyOtherFam'))
2396 da=DataArrayInt([3,12]) ; da.setName("grp0")
2397 self.assertTrue(mm.getGroupArr(1,"grp0").isEqual(da))
2399 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2403 def testMEDUMeshAddGroup1(self):
2404 fname="Pyfile54.med"
2406 coo=DataArrayDouble(9) ; coo.iota(1.) ; coo.rearrange(3) ; coo.setInfoOnComponents(["aaa [b]","cc [dd]", "e [fff]"])
2407 m0=MEDCouplingUMesh("toto",2) ; m0.allocateCells(0)
2409 m0.insertNextCell(NORM_TRI3,[1,2,1])
2412 m0.insertNextCell(NORM_QUAD4,[1,1,2,0])
2415 m0.insertNextCell(NORM_POLYGON,[0,0,1,1,2,2])
2417 m1=MEDCouplingUMesh("toto",1) ; m1.allocateCells(0) ; m1.insertNextCell(NORM_SEG2,[1,6]) ; m1.insertNextCell(NORM_SEG2,[7,3])
2418 m2=MEDCouplingUMesh("toto",0) ; m2.allocateCells(0) ; m2.insertNextCell(NORM_POINT1,[2]) ; m2.insertNextCell(NORM_POINT1,[6]) ; m2.insertNextCell(NORM_POINT1,[8])
2419 m0.setCoords(coo) ; m.setMeshAtLevel(0,m0)
2420 m1.setCoords(coo) ; m.setMeshAtLevel(-1,m1)
2421 m2.setCoords(coo) ; m.setMeshAtLevel(-2,m2)
2424 famCoo=DataArrayInt([0,2,0,3,2,0,-1,0,0,0,0,-1,3]) ; mm.setFamilyFieldArr(0,famCoo)
2425 da0=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(1,da0)
2426 da1=DataArrayInt([0,3]) ; mm.setFamilyFieldArr(-1,da1)
2427 da2=DataArrayInt([0,0,0]) ; mm.setFamilyFieldArr(-2,da2)
2428 mm.setFamilyId("MyFam",2)
2429 mm.setFamilyId("MyOtherFam",3)
2430 mm.setFamilyId("MyOther-1",-1)
2431 mm.setFamiliesOnGroup("grp0",["MyOtherFam"])
2432 mm.setFamiliesOnGroup("grpA",["MyOther-1"])
2434 daTest=DataArrayInt([1,3,4,6,9,10,12]) ; daTest.setName("grp1")
2435 mm.addGroup(0,daTest)
2436 self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2437 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2438 for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2439 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2441 self.assertEqual(mm.getFamiliesNames(),('Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2442 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2443 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2444 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2445 for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2446 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2448 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('MyOtherFam','Family_-8'))
2449 da=DataArrayInt([3,12]) ; da.setName("grp0")
2450 self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2452 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2454 mm=MEDFileMesh.New(fname)
2455 self.assertTrue(mm.getGroupArr(0,daTest.getName()).isEqual(daTest))
2456 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-6,2,-6,-8,2,-6,-5,-6,-6,-7,-7,-4,-8])))
2457 for lev,arr in [(1,da0),(-1,da1),(-2,da2)]:
2458 self.assertTrue(mm.getFamilyFieldAtLevel(lev).isEqual(arr))
2460 self.assertEqual(mm.getFamiliesNames(),('FAMILLE_ZERO','Family_-4','Family_-5','Family_-7','Family_-8','MyFam','MyOther-1','MyOtherFam'))
2461 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grpA'))
2462 self.assertEqual(mm.getFamilyNameGivenId(3),'MyOtherFam')
2463 self.assertEqual(mm.getFamilyNameGivenId(2),'MyFam')
2464 for famName,famId in [('Family_-4',-4),('Family_-5',-5),('Family_-7',-7),('Family_-8',-8)]:
2465 self.assertEqual(mm.getFamilyNameGivenId(famId),famName)
2467 self.assertEqual(mm.getFamiliesOnGroup("grp0"),('Family_-8','MyOtherFam'))
2468 da=DataArrayInt([3,12]) ; da.setName("grp0")
2469 self.assertTrue(mm.getGroupArr(0,"grp0").isEqual(da))
2471 self.assertTrue(mm.getGroupArr(-1,"grp0").isEqual(da))
2475 def testHeapMem1(self):
2476 a=DataArrayInt() ; aa=a.getHeapMemorySize()
2478 strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
2480 m=MEDCouplingCMesh()
2481 arr=DataArrayDouble(10,1) ; arr.iota(0)
2482 m.setCoords(arr,arr)
2483 m=m.buildUnstructured()
2485 f=m.getMeasureField(False)
2486 cooMem = 100 * 2 * 8
2487 nodalMem = 5 * 81 * MEDCouplingSizeOfIDs()//8
2488 indexMem = 82 * MEDCouplingSizeOfIDs()//8
2489 meshMem = cooMem + nodalMem + indexMem
2490 self.assertIn(m.getHeapMemorySize(), list(range(meshMem - 100, meshMem + 100 + 4 * strMulFac)))
2491 delta = (m.getHeapMemorySize()-meshMem)//3 # std::string::capacity behaves differently
2492 self.assertIn(f.getHeapMemorySize(), list(range(meshMem + 81*8 - (100 + 3*delta), meshMem + 81*8 + (100+3*delta) + 8 * strMulFac)))
2495 mm.setMeshAtLevel(0,m)
2496 self.assertIn(mm.getHeapMemorySize(), list(range(meshMem + 81*(MEDCouplingSizeOfIDs()//8) - (100+3*delta), meshMem + 81*(MEDCouplingSizeOfIDs()//8) + (100+3*delta) + 10 * strMulFac)))
2497 ff=MEDFileField1TS()
2498 ff.setFieldNoProfileSBT(f)
2499 self.assertIn(ff.getHeapMemorySize(), list(range(771 - 40, 871 + 21 + (4 + 1) * strMulFac)))
2501 fff=MEDFileFieldMultiTS()
2502 fff.appendFieldNoProfileSBT(f)
2503 self.assertIn(fff.getHeapMemorySize(), list(range(815 - 50, 915 + 30 + (6 + 2) * strMulFac)))
2505 fff.appendFieldNoProfileSBT(f)
2506 self.assertIn(fff.getHeapMemorySize(), list(range(1594 - 90, 1794 + 50 + (10 + 1) * strMulFac)))
2507 self.assertIn(fff[0, -1].getHeapMemorySize(), list(range(771 - 40, 871 + 20 + (4 + 1) * strMulFac)))
2510 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
2511 fff.appendFieldProfile(f2,mm,0,pfl)
2512 self.assertIn(fff.getHeapMemorySize(), range(2348 - 130, 2608 + 400 + (10 + 2) * strMulFac))
2513 self.assertIn(fff.getProfile("pfl").getHeapMemorySize(), list(range(50 *(MEDCouplingSizeOfIDs()//8) - 10, 50 *(MEDCouplingSizeOfIDs()//8) + 10 + 2 * strMulFac)))
2514 self.assertIn(fff[1, -1].getHeapMemorySize(), range(538 + (50 *(MEDCouplingSizeOfIDs()//8)) - 50, 900 + (50 *(MEDCouplingSizeOfIDs()//8)) + 30 + 4 * strMulFac))
2517 def internalCurveLinearMesh1(self):
2518 fname="Pyfile55.med"
2519 mesh=MEDCouplingCurveLinearMesh();
2520 mesh.setTime(2.3,4,5);
2521 mesh.setTimeUnit("us");
2522 mesh.setName("Example of Cuve linear mesh");
2523 mesh.setDescription("buildCLMesh");
2524 a1=DataArrayDouble(3*20,1);
2525 a1.iota(7.) ; a1.rearrange(3);
2527 mesh.setNodeGridStructure([4,5]);
2528 mesh.checkConsistencyLight();
2530 m=MEDFileCurveLinearMesh()
2532 d=DataArrayInt(20) ; d.iota(4)
2533 m.setFamilyFieldArr(1,d)
2534 d3=DataArrayInt(20) ; d3.iota(400)
2535 m.setRenumFieldArr(1,d3)
2536 d2=DataArrayInt(12) ; d2.iota(40)
2537 m.setFamilyFieldArr(0,d2)
2538 d4=DataArrayInt(21) ; d4.iota(4000)
2539 self.assertRaises(InterpKernelException,m.setRenumFieldArr,1,d4)
2541 m.setRenumFieldArr(1,d4)
2544 m1=MEDFileCurveLinearMesh(fname)
2546 self.assertTrue(mm.isEqual(mesh,1e-12))
2547 self.assertEqual(mm.getSpaceDimension(),3)
2548 self.assertEqual(mm.getSpaceDimensionOnNodeStruct(),2)
2550 m1=MEDFileMesh.New(fname)
2551 self.assertTrue(isinstance(m1,MEDFileCurveLinearMesh))
2552 self.assertTrue(isinstance(m1.getUnivName(),str))
2553 self.assertTrue(len(m1.getUnivName())!=0)
2554 self.assertTrue(m1.getMesh().isEqual(mesh,1e-12))
2558 def testCurveLinearMesh1(self):
2559 self.internalCurveLinearMesh1()
2562 def testParameters1(self):
2563 self.internalParameters1()
2565 def internalParameters1(self):
2566 fname="Pyfile56.med"
2567 m=MEDCouplingCMesh() ; arr=DataArrayDouble([0.,1.2,3.5]) ; m.setCoords(arr,arr) ; m.setName("mesh")
2568 mm=MEDFileCMesh() ; mm.setMesh(m)
2569 ms=MEDFileMeshes() ; ms.pushMesh(mm)
2571 p=MEDFileParameters()
2572 data.setParams(p) ; data.setMeshes(ms)
2573 pts=MEDFileParameterMultiTS()
2574 pts.setName("A") ; pts.setDescription("An example of parameter") ; pts.setTimeUnit("ms")
2575 pts.appendValue(1,2,3.4,567.89)
2576 pts.appendValue(2,3,5.6,999.123)
2577 pts2=pts.deepCopy() ; pts2.setName("B") ; pts2.setDescription("A second example")
2578 p.pushParam(pts) ; p.pushParam(pts2)
2580 p2=MEDFileParameters(fname)
2581 self.assertTrue(p.isEqual(p2,1e-14)[0])
2582 self.assertAlmostEqual(p[1][1,2].getValue(),567.89,13)
2584 pts4=pts2.deepCopy()
2585 pts3=pts2.deepCopy()
2586 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2587 pts2.eraseTimeStepIds([0])
2588 self.assertTrue(not pts3.isEqual(pts2,1e-14)[0])
2590 self.assertTrue(pts3.isEqual(pts2,1e-14)[0])
2591 self.assertRaises(InterpKernelException,p[1].__getitem__,(1,2))
2592 self.assertRaises(InterpKernelException,p["B"].__getitem__,(1,2))
2593 self.assertAlmostEqual(p[0][1,2].getValue(),567.89,13)
2594 self.assertAlmostEqual(p["A"][1,2].getValue(),567.89,13)
2596 self.assertTrue(p.isEqual(p2,1e-14)[0])
2597 self.assertTrue(p2["B"].isEqual(pts,1e-14)[0])
2598 self.assertTrue(not p2["B"].isEqual(pts2,1e-14)[0])
2599 self.assertAlmostEqual(p2[0][1,2].getValue(),567.89,13)
2600 self.assertEqual(p.getParamsNames(),('A','B'))
2601 ptsr=MEDFileParameterMultiTS(fname,"B")
2602 self.assertTrue(ptsr.isEqual(pts4,1e-14)[0])
2603 ptsr=MEDFileParameterMultiTS(fname)
2604 self.assertTrue(ptsr.isEqual(pts,1e-14)[0])
2605 p1tsr=MEDFileParameterDouble1TS(fname)
2606 self.assertEqual(p1tsr.getName(),"A")
2607 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2608 p1tsr=MEDFileParameterDouble1TS(fname,"B")
2609 self.assertEqual(p1tsr.getName(),"B")
2610 self.assertAlmostEqual(p1tsr.getValue(),567.89,13)
2611 p1tsr=MEDFileParameterDouble1TS(fname,"B",2,3)
2612 self.assertEqual(p1tsr.getName(),"B")
2613 self.assertAlmostEqual(p1tsr.getValue(),999.123,13)
2614 data2=MEDFileData(fname)
2615 self.assertEqual(2,data2.getNumberOfParams())
2616 self.assertAlmostEqual(data2.getParams()["B"][1,2].getValue(),567.89,13)
2620 def testNamesOnCellAndNodesInMeshes1(self):
2621 fname="Pyfile58.med"
2622 fname2="Pyfile59.med"
2623 m=MEDLoaderDataForTest.build3DSurfMesh_1()
2624 m1=m.buildDescendingConnectivity()[0]
2625 m1.sortCellsInMEDFileFrmt()
2628 mm.setMeshAtLevel(0,m)
2629 mm.setMeshAtLevel(-1,m1)
2630 namesCellL0=DataArrayAsciiChar(6,16)
2631 namesCellL0[:] = ["CellL0#%.3d " % (i) for i in range(6)]
2632 mm.setNameFieldAtLevel(0,namesCellL0)
2633 namesCellL1=DataArrayAsciiChar.Aggregate([namesCellL0,namesCellL0,namesCellL0.subArray(2)])
2634 namesCellL1[:] = ["CellLM1#%.3d " % (i) for i in range(16)]
2635 mm.setNameFieldAtLevel(-1,namesCellL1)
2636 namesNodes=namesCellL1.subArray(4,16)
2637 namesNodes[:] = ["Node#%.3d " % (i) for i in range(12)]
2638 mm.setNameFieldAtLevel(1,namesNodes)
2641 mmr=MEDFileMesh.New(fname)
2642 self.assertTrue(mm.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
2643 self.assertTrue(mm.getNameFieldAtLevel(-1).isEqual(DataArrayAsciiChar(["CellLM1#%.3d " % (i) for i in range(16)])))
2644 self.assertTrue(mm.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(12)])))
2645 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2646 mmr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2647 self.assertTrue(not mm.isEqual(mmr,1e-12)[0])
2648 mmr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2649 self.assertTrue(mm.isEqual(mmr,1e-12)[0])
2651 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2652 # remove names on nodes
2653 mmCpy.setNameFieldAtLevel(1,None)
2654 self.assertTrue(not mm.isEqual(mmCpy,1e-12)[0])
2655 mm.setNameFieldAtLevel(1,None)
2656 self.assertTrue(mm.isEqual(mmCpy,1e-12)[0])
2657 mm.setNameFieldAtLevel(-1,None)
2659 mmr=MEDFileMesh.New(fname)
2660 self.assertEqual(mmr.getNameFieldAtLevel(1),None)
2661 self.assertTrue(mmr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["CellL0#%.3d " % (i) for i in range(6)])))
2662 self.assertEqual(mmr.getNameFieldAtLevel(-1),None)
2664 c=MEDCouplingCMesh()
2665 arr=DataArrayDouble([0.,1.1,2.3])
2666 c.setCoords(arr,arr)
2670 cc.setNameFieldAtLevel(0, DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)]))
2671 cc.setNameFieldAtLevel(1, DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)]))
2673 ccr=MEDFileMesh.New(fname2)
2674 self.assertTrue(ccr.getNameFieldAtLevel(0).isEqual(DataArrayAsciiChar(["Cell#%.3d " % (i) for i in range(4)])))
2675 self.assertTrue(ccr.getNameFieldAtLevel(1).isEqual(DataArrayAsciiChar(["Node#%.3d " % (i) for i in range(9)])))
2676 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2677 ccr.getNameFieldAtLevel(1).setIJ(0,0,'M')
2678 self.assertTrue(not cc.isEqual(ccr,1e-12)[0])
2679 ccr.getNameFieldAtLevel(1).setIJ(0,0,'N')
2680 self.assertTrue(cc.isEqual(ccr,1e-12)[0])
2682 self.assertTrue(cc.isEqual(ccCpy,1e-12)[0])
2686 def testToExportInExamples1(self):
2687 m=MEDCouplingCMesh()
2688 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2689 m.setCoords(arr,arr)
2690 m=m.buildUnstructured() ; m.setName("mesh")
2691 grp1=DataArrayInt([0,1,2,4,5,6,8,9,10,12,13,14]) ; grp1.setName("grp1")
2692 grp2=DataArrayInt([3,7,11,15]) ; grp2.setName("grp2")
2695 mm.setMeshAtLevel(0,m)
2696 mm.setMeshAtLevel(-1,m2)
2697 mm.setGroupsAtLevel(0,[grp1,grp2])
2698 mm.write("example.med",2)
2700 m0=mm.getMeshAtLevel(0)
2701 m1=mm.getMeshAtLevel(-1)
2702 grp1=mm.getGroupArr(0,"grp1")
2703 grp2=mm.getGroupArr(0,"grp2")
2705 whichGrp=DataArrayInt(m0.getNumberOfCells())
2706 whichGrp.fillWithValue(-1)
2707 for grpId,grp in enumerate(grps):
2710 a,b,bI,c,cI=m0.buildDescendingConnectivity()
2711 e,f=a.areCellsIncludedIn(m1,2)
2713 c2,c2I=MEDCouplingUMesh.ExtractFromIndexedArrays(f,c,cI)
2714 self.assertTrue(c2I.deltaShiftIndex().isUniform(1))
2715 c2.transformWithIndArr(whichGrp)
2716 splitOfM1=len(grps)*[None]
2717 for grpId,grp in enumerate(grps):
2718 tmp=c2.findIdsEqual(grpId)
2719 splitOfM1[grpId]=tmp
2721 splitOfM1[0].isEqual(DataArrayInt([0,1,2,3,6,8,10,11,12,13]))
2722 splitOfM1[1].isEqual(DataArrayInt([4,5,7,9,14,15]))
2726 def testBugCorrection1(self):
2729 self.assertEqual(fs[0],None)
2730 self.assertEqual(3,len(fs))
2734 def testCompareMEDFilesContainingOnlyFieldsOnCell1(self):
2735 f1Name="Pyfile60.med"
2736 f2Name="Pyfile61.med"
2737 d1=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2739 d2=MEDLoaderDataForTest.buildACompleteMEDDataStructureWithFieldsOnCells_1()
2741 # reading and compare
2742 d1=MEDFileData(f1Name) ; d2=MEDFileData(f2Name)
2743 for mn in d1.getMeshes().getMeshesNames():
2744 m1=d1.getMeshes()[mn]
2745 m2=d2.getMeshes()[mn]
2746 for lev in m1.getNonEmptyLevels():
2747 grpsNames=m1.getGroupsOnSpecifiedLev(lev)
2748 for grpName in grpsNames:
2749 self.assertTrue(m1.getGroupArr(lev,grpName).isEqual(m2.getGroupArr(lev,grpName))) # compare groups
2753 for fieldn in d1.getFields().getFieldsNames():
2754 f1=d1.getFields()[fieldn]
2755 f2=d2.getFields()[fieldn]
2756 for it,order,tim in f1.getTimeSteps():
2759 if len(f1t.getPflsReallyUsed())!=0:
2761 for lev in f1t.getNonEmptyLevels()[1]:
2762 arr1,pfl1=f1t.getFieldWithProfile(ON_CELLS,lev,m1)
2763 arr2,pfl2=f2t.getFieldWithProfile(ON_CELLS,lev,m2)
2764 self.assertTrue(pfl1.isEqual(pfl2))
2765 self.assertTrue(arr1.isEqual(arr2,1e-10))
2770 for lev in f1t.getNonEmptyLevels()[1]:
2771 f1mc=f1t.getFieldOnMeshAtLevel(ON_CELLS,lev,m1)
2772 f2mc=f2t.getFieldOnMeshAtLevel(ON_CELLS,lev,m2)
2773 self.assertTrue(f1mc.isEqual(f2mc,1e-10,1e-10))
2781 def testNonRegBugNormalizeFamIdsMEDFile1(self):
2782 m=MEDCouplingCMesh()
2783 arr=DataArrayDouble([0.,1.,2.,3.,4.])
2784 m.setCoords(arr,arr,arr)
2785 m=m.buildUnstructured()
2786 m2=m.buildDescendingConnectivity()[0]
2788 g1=DataArrayInt([0,1,2,3]) ; g1.setName("g1")
2789 g2=DataArrayInt([2,3,5,6]) ; g2.setName("g2")
2790 g1Face=DataArrayInt([20,21,22,23]) ; g1Face.setName("g1Face")
2791 g2Face=DataArrayInt([22,23,25,26]) ; g2Face.setName("g2Face")
2792 g1Node=DataArrayInt([10,11,12,13]) ; g1Node.setName("g1Node")
2793 g2Node=DataArrayInt([12,13,15,16]) ; g2Node.setName("g2Node")
2795 mm.setMeshAtLevel(0,m)
2796 mm.setGroupsAtLevel(0,[g1,g2])
2797 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2798 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2799 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2800 mm.normalizeFamIdsMEDFile()
2801 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2802 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2803 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2804 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2805 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2806 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2807 for g in mm.getGroupsOnSpecifiedLev(0):
2808 for f in mm.getFamiliesIdsOnGroup(g):
2809 self.assertTrue(f<0)
2814 mm.setMeshAtLevel(0,m)
2815 mm.setMeshAtLevel(-1,m2)
2816 mm.setGroupsAtLevel(0,[g1,g2])
2817 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2818 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2819 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2820 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2821 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2822 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2823 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2824 mm.normalizeFamIdsMEDFile()
2825 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2826 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2827 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2828 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2829 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2830 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2831 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2832 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2833 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2834 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2835 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2836 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2838 for g in mm.getGroupsOnSpecifiedLev(lev):
2839 for f in mm.getFamiliesIdsOnGroup(g):
2840 self.assertTrue(f<0)
2846 mm.setMeshAtLevel(0,m)
2847 mm.setMeshAtLevel(-1,m2)
2848 mm.setGroupsAtLevel(0,[g1,g2])
2849 mm.setGroupsAtLevel(-1,[g1Face,g2Face])
2850 mm.setGroupsAtLevel(1,[g1Node,g2Node])
2851 s1=set(mm.getFamiliesOnGroup("g1")) ; s2=set(mm.getFamiliesOnGroup("g2"))
2852 s3=set(mm.getFamiliesOnGroup("g1Face")) ; s4=set(mm.getFamiliesOnGroup("g2Face"))
2853 s5=set(mm.getFamiliesOnGroup("g1Node")) ; s6=set(mm.getFamiliesOnGroup("g2Node"))
2854 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2855 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2856 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2857 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2858 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2859 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2860 mm.normalizeFamIdsMEDFile()
2861 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1"),(0,))
2862 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2"),(0,))
2863 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Face"),(-1,))
2864 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Face"),(-1,))
2865 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g1Node"),(1,))
2866 self.assertEqual(mm.getGrpNonEmptyLevelsExt("g2Node"),(1,))
2867 self.assertTrue(mm.getGroupArr(0,"g1").isEqual(g1))
2868 self.assertTrue(mm.getGroupArr(0,"g2").isEqual(g2))
2869 self.assertTrue(mm.getGroupArr(-1,"g1Face").isEqual(g1Face))
2870 self.assertTrue(mm.getGroupArr(-1,"g2Face").isEqual(g2Face))
2871 self.assertTrue(mm.getGroupArr(1,"g1Node").isEqual(g1Node))
2872 self.assertTrue(mm.getGroupArr(1,"g2Node").isEqual(g2Node))
2873 self.assertEqual(s1,set(mm.getFamiliesOnGroup("g1")))
2874 self.assertEqual(s2,set(mm.getFamiliesOnGroup("g2")))
2875 self.assertEqual(s3,set(mm.getFamiliesOnGroup("g1Face")))
2876 self.assertEqual(s4,set(mm.getFamiliesOnGroup("g2Face")))
2877 self.assertEqual(s5,set(mm.getFamiliesOnGroup("g1Node")))
2878 self.assertEqual(s6,set(mm.getFamiliesOnGroup("g2Node")))
2880 for g in mm.getGroupsOnSpecifiedLev(lev):
2881 for f in mm.getFamiliesIdsOnGroup(g):
2882 self.assertTrue(f<0)
2886 for g in mm.getGroupsOnSpecifiedLev(1):
2887 for f in mm.getFamiliesIdsOnGroup(g):
2888 self.assertTrue(f>0)
2894 def testNonRegressionMantis22212ChangeGrpName(self):
2895 fileName="Pyfile62.med"
2896 m2,m1,m0,f2,f1,f0,p,n2,n1,n0,fns,fids,grpns,famIdsPerGrp=MEDLoaderDataForTest.buildMultiLevelMesh_1()
2897 m=MEDFileUMesh.New()
2898 m.setCoords(m2.getCoords())
2899 m.setMeshAtLevel(0,m2)
2900 m.setMeshAtLevel(-1,m1)
2901 m.setMeshAtLevel(-2,m0)
2902 m.setFamilyFieldArr(0,f2)
2903 m.setFamilyFieldArr(-1,f1)
2904 m.setFamilyFieldArr(-2,f0)
2905 m.setFamilyFieldArr(1,p)
2907 for i in range(nbOfFams):
2908 m.addFamily(fns[i],fids[i])
2911 for i in range(nbOfGrps):
2912 m.setFamiliesIdsOnGroup(grpns[i],famIdsPerGrp[i])
2914 m.setName(m2.getName())
2915 m.setDescription(m2.getDescription())
2918 mm0=MEDFileMesh.New(fileName)
2919 mm1=MEDFileMesh.New(fileName)
2920 groupNamesIni=GetMeshGroupsNames(fileName,"ma")
2921 for name in groupNamesIni:
2922 mm1.changeGroupName(name,name+'N')
2924 mm1.write(fileName,2)
2927 mm2=MEDFileMesh.New(fileName)
2928 for name in groupNamesIni:
2929 for lev in mm0.getGrpNonEmptyLevelsExt(name):
2930 arr0=mm0.getGroupArr(lev,name)
2931 arr2=mm2.getGroupArr(lev,name+'N')
2932 arr0.setName(name+'N')
2933 self.assertTrue(arr0.isEqual(arr2))
2939 def testInt32InMEDFileFieldStar1(self):
2940 self.internalInt32InMEDFileFieldStar1()
2942 def internalInt32InMEDFileFieldStar1(self):
2943 fname="Pyfile63.med"
2944 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
2945 f1=f1.convertToIntField()
2947 mm1=MEDFileUMesh.New()
2948 mm1.setCoords(m1.getCoords())
2949 mm1.setMeshAtLevel(0,m1)
2950 mm1.setName(m1.getName())
2952 ff1=MEDFileIntField1TS()
2953 ff1.setFieldNoProfileSBT(f1)
2954 a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2955 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2956 self.assertTrue(a.isEqual(f1,1e-12,0))
2958 a,b=ff1.getUndergroundDataArrayExt()
2959 self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
2960 self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
2961 ff2=MEDFileAnyTypeField1TS.New(fname)
2962 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
2963 self.assertEqual(ff2.getTime(),[0,1,2.0])
2964 self.assertTrue(isinstance(ff2,MEDFileIntField1TS))
2965 a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2966 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2967 self.assertTrue(a.isEqual(f1,1e-12,0))
2969 c=ff2.getUndergroundDataArray() ; c*=2
2970 ff2.write(fname,0) # 2 time steps in
2971 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
2972 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
2973 self.assertEqual(len(ffs1),2)
2974 self.assertTrue(isinstance(ffs1,MEDFileIntFieldMultiTS))
2975 a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2976 self.assertTrue(a.isEqual(f1,1e-12,0))
2977 a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
2978 self.assertTrue(a.isEqual(f1,1e-12,0))
2979 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
2980 a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
2981 self.assertTrue(a.getArray().isEqual(2*f1.getArray()))
2982 f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
2983 self.assertTrue(a.isEqual(f1,1e-12,0)) ; f1.getArray()[:]/=2
2984 bc=DataArrayInt32(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
2986 a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
2989 self.assertTrue(bc.isEqual(3*f1.getArray()))
2990 nf1=MEDCouplingFieldInt(ON_NODES)
2991 nf1.setTime(9.,10,-1)
2992 nf1.setMesh(f1.getMesh())
2993 narr=DataArrayInt32(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
2994 nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
2995 nff1=MEDFileIntField1TS.New()
2996 nff1.setFieldNoProfileSBT(nf1)
2997 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
2998 self.assertEqual(nff1.getTime(),[10,-1,9.0])
3001 nf2=MEDCouplingFieldInt(ON_NODES)
3002 nf2.setTime(19.,20,-11)
3003 nf2.setMesh(f1.getMesh())
3004 narr2=DataArrayInt32(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
3005 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
3006 nff2=MEDFileIntField1TS.New()
3007 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
3008 nff2.setFieldProfile(nf2,mm1,0,npfl)
3009 nff2.getFieldWithProfile(ON_NODES,0,mm1)
3010 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
3011 self.assertTrue(b.isEqual(npfl))
3012 self.assertTrue(a.isEqual(narr2))
3014 nff2bis=MEDFileIntField1TS(fname,"VectorFieldOnNodesPfl")
3015 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
3016 self.assertTrue(b.isEqual(npfl))
3017 self.assertTrue(a.isEqual(narr2))
3019 nf3=MEDCouplingFieldDouble(ON_NODES)
3020 nf3.setName("VectorFieldOnNodesDouble")
3021 nf3.setTime(29.,30,-21)
3022 nf3.setMesh(f1.getMesh())
3023 nf3.setArray(f1.getMesh().getCoords())
3024 nff3=MEDFileField1TS.New()
3025 nff3.setFieldNoProfileSBT(nf3)
3027 fs=MEDFileFields(fname)
3028 self.assertEqual(len(fs),4)
3029 ffs=[it for it in fs]
3030 self.assertTrue(isinstance(ffs[0],MEDFileIntFieldMultiTS))
3031 self.assertTrue(isinstance(ffs[1],MEDFileIntFieldMultiTS))
3032 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
3033 self.assertTrue(isinstance(ffs[3],MEDFileIntFieldMultiTS))
3035 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray()))
3036 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray()))
3037 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2))
3038 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr))
3039 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
3041 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
3042 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
3043 self.assertRaises(InterpKernelException,MEDFileIntFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
3044 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
3045 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
3046 self.assertRaises(InterpKernelException,MEDFileIntField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
3047 MEDFileIntField1TS.New(fname,"VectorFieldOnNodes",10,-1)
3048 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
3050 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
3051 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
3052 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
3053 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
3057 def testMEDFileFields1(self):
3058 fname="Pyfile64.med"
3059 f1=MEDCouplingFieldDouble(ON_NODES)
3060 f1.setTime(0.001,0,-1) ; f1.setTimeUnit("us")
3061 c=DataArrayDouble(12) ; c.iota(); m=MEDCouplingCMesh() ; m.setCoordsAt(0,c) ; m.setName("mesh")
3062 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.write(fname,2)
3064 arr=DataArrayDouble(12,2) ; arr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; arr[:,0]=list(range(12)) ; arr[:,1]=2*arr[:,0]
3066 f1.setName("Field1")
3067 ff1=MEDFileField1TS.New()
3068 ff1.setFieldNoProfileSBT(f1)
3069 self.assertEqual(ff1.getDtUnit(),"us")
3071 f1.setTime(1.001,1,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
3072 f1.setTime(2.001,2,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
3074 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
3075 ff1s=MEDFileFieldMultiTS(fname,"Field1")
3076 ff1s.setName("Field2")
3078 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],False))
3079 f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
3080 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1)],True))
3081 self.assertEqual(MEDFileFields(fname).partOfThisLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(1,-1)],False))
3082 self.assertEqual(MEDFileFields(fname).partOfThisNotLyingOnSpecifiedTimeSteps([(1,-1)]).getCommonIterations(),([(0,-1),(2,-1)],True))
3083 f1.setName("Field2") ; f1.setTime(3.001,3,-1) ; ff1=MEDFileField1TS.New() ; ff1.setFieldNoProfileSBT(f1) ; ff1.write(fname,0)
3084 self.assertEqual(MEDFileFields(fname).getCommonIterations(),([(0,-1),(1,-1),(2,-1),(3,-1)],False))
3085 self.assertEqual(MEDFileFields(fname)[1].getDtUnit(),"us")
3088 # Multi time steps and multi fields management without Globals (profiles, locs) aspects
3090 def testMEDFileFields2(self):
3091 fname="Pyfile65.med"
3092 # to check that all is initialize
3093 MEDFileField1TS().__str__()
3094 MEDFileFieldMultiTS().__str__()
3095 # building a mesh containing 4 tri3 + 5 quad4
3096 tri=MEDCouplingUMesh("tri",2)
3097 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3098 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3099 tris = [tri.deepCopy() for i in range(4)]
3100 for i,elt in enumerate(tris): elt.translate([i,0])
3101 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3102 quad=MEDCouplingUMesh("quad",2)
3103 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3104 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3105 quads = [quad.deepCopy() for i in range(5)]
3106 for i,elt in enumerate(quads): elt.translate([5+i,0])
3107 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3108 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3109 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3111 fmts0_0=MEDFileFieldMultiTS()
3112 fmts0_1=MEDFileFieldMultiTS()
3115 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
3116 d=DataArrayDouble(18) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
3117 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3118 f.setTime(float(i+1)+0.1,i+1,-i-1)
3119 fmts0_0.appendFieldNoProfileSBT(f)
3120 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f) ; fmts0_1.pushBackTimeStep(f1ts)
3121 self.assertEqual(fmts0_1.getName(),name1)
3122 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
3123 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
3125 # components names have been modified to generate errors
3126 d.setInfoOnComponents(['aa [bb]','eee [dd]'])
3127 self.assertRaises(InterpKernelException,fmts0_0.appendFieldNoProfileSBT,f)
3128 self.assertRaises(InterpKernelException,f1ts.setInfo,['aa [bb]'])#throw because mismatch of number of components
3129 f1ts.setInfo(['aa [bb]','eee [dd]'])
3130 self.assertRaises(InterpKernelException,fmts0_1.pushBackTimeStep,f1ts)
3132 # add a mismatch of nb of compos
3134 fmts0_2=fmts0_0.deepCopy()
3135 fmts0_3=fmts0_0.deepCopy()
3136 fmts0_4=fmts0_0.deepCopy()
3137 fmts0_5=fmts0_0.shallowCpy()
3138 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)
3140 self.assertTrue(len(fmts0_2)==5 and fmts0_2.getIterations()==[(2,-2),(4,-4),(6,-6),(8,-8),(10,-10)])
3141 del fmts0_3[[1.1,(6,-6),9]]
3142 self.assertTrue(len(fmts0_3)==7 and fmts0_3.getIterations()==[(2,-2),(3,-3),(4,-4),(5,-5),(7,-7),(8,-8),(9,-9)])
3143 fmts0_6=fmts0_4[[1.1,(6,-6),8]]
3144 self.assertTrue(isinstance(fmts0_6,MEDFileFieldMultiTS))
3145 self.assertTrue(len(fmts0_6)==3 and fmts0_6.getIterations()==[(1,-1),(6,-6),(9,-9)])
3146 fmts0_7=fmts0_4[::-3]
3147 self.assertTrue(isinstance(fmts0_7,MEDFileFieldMultiTS))
3148 self.assertTrue(len(fmts0_7)==4 and fmts0_7.getIterations()==[(10,-10),(7,-7),(4,-4),(1,-1)])
3151 fs0.pushField(fmts0_0)
3152 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
3153 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
3154 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
3155 self.assertTrue(len(fs0)==4 and fs0.getFieldsNames()==('1stField','2ndField','3rdField','4thField'))
3157 fs0=MEDFileFields(fname)
3158 self.assertEqual(fs0.getCommonIterations(),([(2,-2),(4,-4),(8,-8)],True))
3159 fs1=fs0.partOfThisLyingOnSpecifiedTimeSteps(fs0.getCommonIterations()[0])
3160 self.assertTrue(fs1.getFieldsNames()==('1stField','2ndField','3rdField','4thField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
3161 del fs1[["2ndField",3]]
3162 self.assertTrue(fs1.getFieldsNames()==('1stField','3rdField') and fs1.getCommonIterations()==([(2,-2),(4,-4),(8,-8)],False))
3163 fs2=fs0[[0,"4thField"]]
3164 self.assertTrue(isinstance(fs2,MEDFileFields))
3165 self.assertEqual(fs2.getFieldsNames(),('1stField','4thField'))
3167 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,0)
3170 # Multi time steps and multi fields management with Globals (profiles, locs) aspects
3172 def testMEDFileFields3(self):
3173 fname="Pyfile66.med"
3174 # building a mesh containing 4 tri3 + 5 quad4
3175 tri=MEDCouplingUMesh("tri",2)
3176 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3177 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3178 tris = [tri.deepCopy() for i in range(4)]
3179 for i,elt in enumerate(tris): elt.translate([i,0])
3180 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3181 quad=MEDCouplingUMesh("quad",2)
3182 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3183 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3184 quads = [quad.deepCopy() for i in range(5)]
3185 for i,elt in enumerate(quads): elt.translate([5+i,0])
3186 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3187 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3188 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3190 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3192 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3193 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
3194 fmts0_0=MEDFileFieldMultiTS()
3195 fmts0_1=MEDFileFieldMultiTS()
3198 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
3199 d=DataArrayDouble(14) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
3200 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3201 f.setTime(float(i+1)+0.1,i+1,-i-1)
3202 fmts0_0.appendFieldProfile(f,mm,0,pfl)
3203 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
3204 self.assertEqual(fmts0_0.getInfo(),('aa [bb]','ccc [ddd]'))
3205 self.assertEqual(fmts0_1.getInfo(),('aa [bb]','ccc [ddd]'))
3208 self.assertEqual(fmts0_0.getPfls(),10*('pfl_NORM_QUAD4',))
3209 self.assertEqual(fmts0_1.getPfls(),('pfl_NORM_QUAD4',))
3210 fmts0_0.zipPflsNames()
3211 self.assertEqual(fmts0_0.getPfls(),('pfl_NORM_QUAD4',))
3212 self.assertTrue(fmts0_1.getProfile("pfl_NORM_QUAD4").isEqual(fmts0_0.getProfile("pfl_NORM_QUAD4")))
3213 fmts0_2=fmts0_0.deepCopy()
3214 fmts0_3=fmts0_0.deepCopy()
3215 fmts0_4=fmts0_0.deepCopy()
3217 fs0.pushField(fmts0_0)
3218 fmts0_2.setName("2ndField") ; fs0.pushField(fmts0_2)
3219 fmts0_3.setName("3rdField") ; fs0.pushField(fmts0_3)
3220 fmts0_4.setName("4thField") ; fs0.pushField(fmts0_4)
3221 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4',))
3223 fmts0_5=MEDFileFieldMultiTS()
3225 infos1=["aa [bb]","ccc [ddd]"] ; name1="1stField"
3226 d=DataArrayDouble(16) ; d.iota(i*10) ; d.rearrange(2) ; d.setInfoOnComponents(infos1)
3227 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3228 f.setTime(float(i+1)+0.1,i+1,-i-1)
3229 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl2) ; fmts0_5.pushBackTimeStep(f1ts)
3231 fmts0_5.setName("5thField") ; fs0.pushField(fmts0_5)
3232 self.assertEqual(fs0.getPfls(),('pfl_NORM_QUAD4','pfl2_NORM_QUAD4'))
3233 fs0.checkGlobsCoherency()
3238 def testSplitComponents1(self):
3239 fname="Pyfile67.med"
3240 # building a mesh containing 4 tri3 + 5 quad4
3241 tri=MEDCouplingUMesh("tri",2)
3242 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3243 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3244 tris = [tri.deepCopy() for i in range(4)]
3245 for i,elt in enumerate(tris): elt.translate([i,0])
3246 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3247 quad=MEDCouplingUMesh("quad",2)
3248 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3249 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3250 quads = [quad.deepCopy() for i in range(5)]
3251 for i,elt in enumerate(quads): elt.translate([5+i,0])
3252 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3253 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3254 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3256 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3258 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3259 pfl2=DataArrayInt([0,1,2,3,4,5,6,8]) ; pfl2.setName("pfl2")
3261 fmts0_1=MEDFileFieldMultiTS()
3263 infos1=['aa [bb]','ccc [ddd]',"ZZZZ [MW*s]"]
3266 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
3267 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName(name1) ; f.setArray(d) ; f.setMesh(m)
3268 f.setTime(float(i+1)+0.1,i+1,-i-1)
3269 f1ts=MEDFileField1TS() ; f1ts.setFieldProfile(f,mm,0,pfl) ; fmts0_1.pushBackTimeStep(f1ts)
3270 self.assertEqual(fmts0_1.getInfo(),tuple(infos1))
3272 fs.pushField(fmts0_1)
3273 self.assertEqual(1,len(fs))
3274 l=fmts0_1.splitComponents()
3275 self.assertEqual(3,len(l))
3276 for elt in l: self.assertEqual(10,len(elt))
3277 for elt in l: self.assertTrue(isinstance(elt,MEDFileFieldMultiTS))
3279 elt.setName("%s_%s"%(elt.getName(),DataArray.GetVarNameFromInfo(elt.getInfo()[0])))
3282 self.assertEqual(4,len(fs))
3283 for elt in fs: self.assertEqual(10,len(elt))
3284 self.assertEqual(fs.getPfls(),('pfl_NORM_QUAD4',))
3285 self.assertEqual(fs.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
3287 fs.write(fname,0) ; del fs
3289 fs1=MEDFileFields(fname)
3290 self.assertEqual(fs1.getPfls(),('pfl_NORM_QUAD4',))
3291 self.assertEqual(fs1.getPflsReallyUsed(),('pfl_NORM_QUAD4',))
3292 self.assertEqual(4,len(fs1))
3294 for j,fieldName in enumerate(['1stField_aa','1stField_ccc','1stField_ZZZZ']):
3295 f1ts=fs1[fieldName][i]
3296 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
3297 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d=d[:,j] ; d.setInfoOnComponent(0,infos1[j])
3298 self.assertTrue(d.isEqual(f.getArray(),1e-13))
3300 f1ts=fs1["1stField"][i]
3301 f=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
3302 d=DataArrayDouble(21) ; d.iota(i*10) ; d.rearrange(3) ; d.setInfoOnComponents(infos1)
3303 self.assertTrue(d.isEqual(f.getArray(),1e-13))
3308 def testMEDFileFieldConvertTo1(self):
3309 fname="Pyfile68.med"
3310 # building a mesh containing 4 tri3 + 5 quad4
3311 tri=MEDCouplingUMesh("tri",2)
3312 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3313 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3314 tris = [tri.deepCopy() for i in range(4)]
3315 for i,elt in enumerate(tris): elt.translate([i,0])
3316 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3317 quad=MEDCouplingUMesh("quad",2)
3318 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3319 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3320 quads = [quad.deepCopy() for i in range(5)]
3321 for i,elt in enumerate(quads): elt.translate([5+i,0])
3322 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3323 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3324 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3325 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3327 ff0=MEDFileField1TS()
3328 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")
3329 f0.checkConsistencyLight()
3330 ff0.setFieldNoProfileSBT(f0)
3332 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,9),'','')])]
3333 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3335 ff0i=ff0.convertToInt()
3336 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3337 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3339 ff1=ff0i.convertToDouble()
3340 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3341 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3343 ff0i64=ff0.convertToInt64()
3344 self.assertEqual(ff0i64.getFieldSplitedByType(),fspExp)
3345 self.assertTrue(arr.convertToInt64Arr().isEqual(ff0i64.getUndergroundDataArray()))
3347 ff2=ff0i64.convertToDouble()
3348 self.assertTrue(ff2.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3349 self.assertEqual(ff2.getFieldSplitedByType(),fspExp)
3351 del arr,f0,ff0,ff1,ff2,ff0i,ff0i64,fspExp
3352 ff0=MEDFileField1TS()
3353 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")
3354 f0.checkConsistencyLight()
3355 pfl=DataArrayInt.Range(0,7,1) ; pfl.setName("pfl")
3356 ff0.setFieldProfile(f0,mm,0,pfl)
3357 fspExp=[(3,[(0,(0,4),'','')]),(4,[(0,(4,7),'pfl_NORM_QUAD4','')])]
3358 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3360 ff0i=ff0.convertToInt()
3361 self.assertTrue(isinstance(ff0i,MEDFileIntField1TS))
3362 self.assertEqual(ff0i.getFieldSplitedByType(),fspExp)
3363 self.assertTrue(arr.convertToIntArr().isEqual(ff0i.getUndergroundDataArray()))
3365 ff1=ff0i.convertToDouble()
3366 self.assertTrue(isinstance(ff1,MEDFileField1TS))
3367 self.assertTrue(ff1.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3368 self.assertEqual(ff1.getFieldSplitedByType(),fspExp)
3370 ff0i64=ff0.convertToInt64()
3371 self.assertTrue(isinstance(ff0i64,MEDFileInt64Field1TS))
3372 self.assertEqual(ff0i64.getFieldSplitedByType(),fspExp)
3373 self.assertTrue(arr.convertToInt64Arr().isEqual(ff0i64.getUndergroundDataArray()))
3375 ff2=ff0i64.convertToDouble()
3376 self.assertTrue(isinstance(ff2,MEDFileField1TS))
3377 self.assertTrue(ff2.getUndergroundDataArray().isEqual(ff0.getUndergroundDataArray(),1e-13))
3378 self.assertEqual(ff2.getFieldSplitedByType(),fspExp)
3380 ff0=MEDFileFieldMultiTS()
3381 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)
3382 f0.checkConsistencyLight()
3383 ff0.appendFieldProfile(f0,mm,0,pfl)
3384 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)
3385 f0.checkConsistencyLight()
3386 ff0.appendFieldProfile(f0,mm,0,pfl)
3387 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)
3388 f0.checkConsistencyLight()
3389 ff0.appendFieldProfile(f0,mm,0,pfl)
3390 ff1=ff0.convertToInt()
3391 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3392 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3393 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3394 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3395 arr=ff1.getUndergroundDataArray(dt,it)
3396 arr.isEqualWithoutConsideringStr(DataArrayInt32.Range(delt,delt+7,1))
3398 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3403 ff1=ff1.convertToDouble()
3404 self.assertTrue(isinstance(ff1,MEDFileFieldMultiTS))
3405 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3406 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3407 self.assertEqual(ff1.getFieldSplitedByType(dt,it),fspExp)
3408 arr=ff1.getUndergroundDataArray(dt,it)
3409 arr.isEqualWithoutConsideringStr(DataArrayInt.Range(delt,delt+7,1).convertToDblArr(),1e-14)
3411 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4', 'pfl_NORM_QUAD4', 'pfl_NORM_QUAD4'))
3413 ff1=MEDFileAnyTypeFieldMultiTS.New(fname,"FieldCellMTime")
3414 self.assertTrue(isinstance(ff1,MEDFileIntFieldMultiTS))
3415 self.assertEqual(ff1.getTimeSteps(),[(0,10,0.1),(1,11,1.1),(2,12,2.1)])
3416 for delt,(dt,it,t) in zip([0,100,200],ff1.getTimeSteps()):
3417 self.assertTrue(ff1.getFieldSplitedByType(dt,it),fspExp)
3418 arr=ff1.getUndergroundDataArray(dt,it)
3419 arr.isEqualWithoutConsideringStr(DataArrayInt32.Range(delt,delt+7,1))
3421 self.assertEqual(ff1.getPfls(),('pfl_NORM_QUAD4',))
3425 def testMEDFileFieldPartialLoading(self):
3426 fname="Pyfile69.med"
3428 a=DataArrayInt() ; aa=a.getHeapMemorySize()
3430 strMulFac=a.getHeapMemorySize()-aa ; del a ; del aa
3431 # building a mesh containing 30 tri3 + 40 quad4
3432 tri=MEDCouplingUMesh("tri",2)
3433 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3434 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3435 tris = [tri.deepCopy() for i in range(30)]
3436 for i,elt in enumerate(tris): elt.translate([i,0])
3437 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3438 quad=MEDCouplingUMesh("quad",2)
3439 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3440 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3441 quads = [quad.deepCopy() for i in range(40)]
3442 for i,elt in enumerate(quads): elt.translate([40+i,0])
3443 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3444 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3445 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3446 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m) ; mm.write(fname,2)
3448 ff0=MEDFileField1TS()
3449 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")
3450 f0.checkConsistencyLight()
3451 ff0.setFieldNoProfileSBT(f0)
3454 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,70),'','')])]
3455 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3457 ff0=MEDFileField1TS()
3458 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")
3459 f0.checkConsistencyLight()
3460 pfl=DataArrayInt.Range(0,50,1) ; pfl.setName("pfl")
3461 ff0.setFieldProfile(f0,mm,0,pfl)
3462 fspExp=[(3,[(0,(0,30),'','')]),(4,[(0,(30,50),'pfl_NORM_QUAD4','')])]
3463 self.assertEqual(ff0.getFieldSplitedByType(),fspExp)
3466 ff0=MEDFileField1TS(fname,False)
3467 self.assertEqual(ff0.getName(),"FieldCell")
3468 self.assertTrue(not ff0.getUndergroundDataArray().isAllocated())
3469 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),['X [km]','YY [mm]'])
3470 heap_memory_ref=ff0.getHeapMemorySize()
3471 self.assertIn(heap_memory_ref, list(range(182, 540 + 2 * strMulFac)))
3473 arr=DataArrayDouble(140) ; arr.iota() ; arr.rearrange(2)
3474 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3475 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,70*8*2)
3477 ff0=MEDFileField1TS(fname,"FieldCellPfl",False)
3478 self.assertEqual(ff0.getUndergroundDataArray().getInfoOnComponents(),["XX [pm]","YYY [hm]"])
3479 heap_memory_ref=ff0.getHeapMemorySize()
3480 self.assertIn(heap_memory_ref, list(range(350, 700 + 6 * strMulFac)))
3482 arr=DataArrayDouble(100) ; arr.iota() ; arr.rearrange(2)
3483 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3484 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3486 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3487 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3488 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3489 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3491 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3492 ff0.getUndergroundDataArray().setIJ(30,1,5.5)
3493 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3494 ff0.loadArraysIfNecessary() ##
3495 self.assertEqual(ff0.getUndergroundDataArray().getIJ(30,1),5.5)
3496 self.assertTrue(not ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3497 heap_memory_ref=ff0.getHeapMemorySize()
3498 self.assertIn(heap_memory_ref, list(range(1100, 1600 + 2 * strMulFac)))
3500 hmd=ff0.getHeapMemorySize()-heap_memory_ref
3501 self.assertEqual(hmd,-800) # -50*8*2
3503 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,0)
3505 ff0=MEDFileField1TS(fname,"FieldCellPfl",-1,-1,False)
3506 heap_memory_ref=ff0.getHeapMemorySize()
3507 self.assertIn(heap_memory_ref, list(range(299, 670 + 6 * strMulFac)))
3509 self.assertTrue(ff0.getUndergroundDataArray().isEqualWithoutConsideringStr(arr,1e-14))
3510 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,50*8*2)
3512 fieldName="FieldCellMultiTS"
3513 ff0=MEDFileFieldMultiTS()
3515 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)
3516 f0.setTime(float(t)+0.1,t,100+t)
3517 f0.checkConsistencyLight()
3518 ff0.appendFieldNoProfileSBT(f0)
3522 ff0=MEDFileAnyTypeFieldMultiTS.New(fname,fieldName,False)
3523 heap_memory_ref=ff0.getHeapMemorySize()
3524 self.assertIn(heap_memory_ref, range(5536, 9212 + (80 + 26 + 1) * strMulFac))
3526 self.assertEqual(ff0.getHeapMemorySize()-heap_memory_ref,20*70*8*2)
3529 ffs=MEDFileFields(fname,False)
3530 heap_memory_ref=ffs.getHeapMemorySize()
3531 self.assertIn(heap_memory_ref, range(5335, 10331 + (80 + 50 + len(ffs)) * strMulFac))
3533 self.assertEqual(ffs.getHeapMemorySize()-heap_memory_ref,20*70*8*2+70*8*2+50*8*2)
3537 def testMEDFileMeshReadSelector1(self):
3538 mrs=MEDFileMeshReadSelector()
3539 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3540 mrs.__str__() ; mrs.__repr__()
3542 mrs=MEDFileMeshReadSelector(0)
3543 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())
3544 mrs=MEDFileMeshReadSelector(1)
3545 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3546 mrs=MEDFileMeshReadSelector(2)
3547 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3548 mrs=MEDFileMeshReadSelector(3)
3549 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3550 mrs=MEDFileMeshReadSelector(4)
3551 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3552 mrs=MEDFileMeshReadSelector(5)
3553 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3554 mrs=MEDFileMeshReadSelector(6)
3555 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3556 mrs=MEDFileMeshReadSelector(7)
3557 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3558 mrs=MEDFileMeshReadSelector(8)
3559 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3560 mrs=MEDFileMeshReadSelector(9)
3561 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3562 mrs=MEDFileMeshReadSelector(10)
3563 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3564 mrs=MEDFileMeshReadSelector(11)
3565 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3566 mrs=MEDFileMeshReadSelector(12)
3567 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3568 mrs=MEDFileMeshReadSelector(13)
3569 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3570 mrs=MEDFileMeshReadSelector(14)
3571 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3572 mrs=MEDFileMeshReadSelector(15)
3573 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3574 mrs=MEDFileMeshReadSelector(16)
3575 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3576 mrs=MEDFileMeshReadSelector(17)
3577 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3578 mrs=MEDFileMeshReadSelector(18)
3579 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3580 mrs=MEDFileMeshReadSelector(19)
3581 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3582 mrs=MEDFileMeshReadSelector(20)
3583 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3584 mrs=MEDFileMeshReadSelector(21)
3585 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3586 mrs=MEDFileMeshReadSelector(22)
3587 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3588 mrs=MEDFileMeshReadSelector(23)
3589 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3590 mrs=MEDFileMeshReadSelector(24)
3591 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3592 mrs=MEDFileMeshReadSelector(25)
3593 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3594 mrs=MEDFileMeshReadSelector(26)
3595 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3596 mrs=MEDFileMeshReadSelector(27)
3597 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3598 mrs=MEDFileMeshReadSelector(28)
3599 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3600 mrs=MEDFileMeshReadSelector(29)
3601 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3602 mrs=MEDFileMeshReadSelector(30)
3603 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3604 mrs=MEDFileMeshReadSelector(31)
3605 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and not mrs.isNodeNumFieldReading())
3606 mrs=MEDFileMeshReadSelector(32)
3607 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3608 mrs=MEDFileMeshReadSelector(33)
3609 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3610 mrs=MEDFileMeshReadSelector(34)
3611 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3612 mrs=MEDFileMeshReadSelector(35)
3613 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3614 mrs=MEDFileMeshReadSelector(36)
3615 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3616 mrs=MEDFileMeshReadSelector(37)
3617 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3618 mrs=MEDFileMeshReadSelector(38)
3619 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3620 mrs=MEDFileMeshReadSelector(39)
3621 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3622 mrs=MEDFileMeshReadSelector(40)
3623 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3624 mrs=MEDFileMeshReadSelector(41)
3625 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3626 mrs=MEDFileMeshReadSelector(42)
3627 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3628 mrs=MEDFileMeshReadSelector(43)
3629 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3630 mrs=MEDFileMeshReadSelector(44)
3631 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3632 mrs=MEDFileMeshReadSelector(45)
3633 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3634 mrs=MEDFileMeshReadSelector(46)
3635 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3636 mrs=MEDFileMeshReadSelector(47)
3637 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and not mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3638 mrs=MEDFileMeshReadSelector(48)
3639 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3640 mrs=MEDFileMeshReadSelector(49)
3641 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3642 mrs=MEDFileMeshReadSelector(50)
3643 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3644 mrs=MEDFileMeshReadSelector(51)
3645 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3646 mrs=MEDFileMeshReadSelector(52)
3647 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3648 mrs=MEDFileMeshReadSelector(53)
3649 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3650 mrs=MEDFileMeshReadSelector(54)
3651 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3652 mrs=MEDFileMeshReadSelector(55)
3653 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and not mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3654 mrs=MEDFileMeshReadSelector(56)
3655 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3656 mrs=MEDFileMeshReadSelector(57)
3657 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3658 mrs=MEDFileMeshReadSelector(58)
3659 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3660 mrs=MEDFileMeshReadSelector(59)
3661 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and not mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3662 mrs=MEDFileMeshReadSelector(60)
3663 self.assertTrue(not mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3664 mrs=MEDFileMeshReadSelector(61)
3665 self.assertTrue(mrs.isCellFamilyFieldReading() and not mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3666 mrs=MEDFileMeshReadSelector(62)
3667 self.assertTrue(not mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3668 mrs=MEDFileMeshReadSelector(63)
3669 self.assertTrue(mrs.isCellFamilyFieldReading() and mrs.isNodeFamilyFieldReading() and mrs.isCellNameFieldReading() and mrs.isNodeNameFieldReading() and mrs.isCellNumFieldReading() and mrs.isNodeNumFieldReading())
3671 mrs=MEDFileMeshReadSelector(63)
3672 mrs.setCellFamilyFieldReading(False)
3673 self.assertEqual(mrs.getCode(),62)
3674 mrs.setCellFamilyFieldReading(True)
3675 self.assertEqual(mrs.getCode(),63)
3676 mrs.setNodeFamilyFieldReading(False)
3677 self.assertEqual(mrs.getCode(),61)
3678 mrs.setNodeFamilyFieldReading(True)
3679 self.assertEqual(mrs.getCode(),63)
3680 mrs.setCellNameFieldReading(False)
3681 self.assertEqual(mrs.getCode(),59)
3682 mrs.setCellNameFieldReading(True)
3683 self.assertEqual(mrs.getCode(),63)
3684 mrs.setNodeNameFieldReading(False)
3685 self.assertEqual(mrs.getCode(),55)
3686 mrs.setNodeNameFieldReading(True)
3687 self.assertEqual(mrs.getCode(),63)
3688 mrs.setCellNumFieldReading(False)
3689 self.assertEqual(mrs.getCode(),47)
3690 mrs.setCellNumFieldReading(True)
3691 self.assertEqual(mrs.getCode(),63)
3692 mrs.setNodeNumFieldReading(False)
3693 self.assertEqual(mrs.getCode(),31)
3694 mrs.setNodeNumFieldReading(True)
3695 self.assertEqual(mrs.getCode(),63)
3699 def testPartialReadOfMeshes(self):
3700 fname="Pyfile70.med"
3701 # building a mesh containing 4 tri3 + 5 quad4
3702 tri=MEDCouplingUMesh("tri",2)
3703 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3704 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3705 tris = [tri.deepCopy() for i in range(4)]
3706 for i,elt in enumerate(tris): elt.translate([i,0])
3707 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3708 quad=MEDCouplingUMesh("quad",2)
3709 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3710 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3711 quads = [quad.deepCopy() for i in range(5)]
3712 for i,elt in enumerate(quads): elt.translate([5+i,0])
3713 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3714 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3715 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3716 m1=m.buildDescendingConnectivity()[0]
3717 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3719 grp0=DataArrayInt([1,2,3,5,6]) ; grp0.setName("grp0")
3720 grp1=DataArrayInt([1,2,3,5,7,8]) ; grp1.setName("grp1")
3721 mm.setGroupsAtLevel(0,[grp0,grp1])
3722 grp2=DataArrayInt.Range(0,32,2) ; grp2.setName("grp2")
3723 grp3=DataArrayInt.Range(1,32,7) ; grp3.setName("grp3")
3724 mm.setGroupsAtLevel(-1,[grp2,grp3])
3725 grp4=DataArrayInt.Range(0,32,2) ; grp4.setName("grp4")
3726 grp5=DataArrayInt.Range(1,32,7) ; grp5.setName("grp5")
3727 mm.setGroupsAtLevel(1,[grp4,grp5])
3728 mm.setRenumFieldArr(0,DataArrayInt.Range(2,11,1))
3729 mm.setRenumFieldArr(-1,DataArrayInt.Range(3,35,1))
3730 mm.setRenumFieldArr(1,DataArrayInt.Range(4,36,1))
3734 mm=MEDFileMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector())
3735 b4_ref_heap_mem=mm.getHeapMemorySize()
3736 mm.getMeshAtLevel(0)## please let this line : force to move 1GTUMesh -> UMesh
3737 mm.getMeshAtLevel(-1)## please let this line : force to move 1GTUMesh -> UMesh
3738 ref_heap_mem=mm.getHeapMemorySize()
3739 # check the gain of memory using 1GTUMesh instead of UMesh
3740 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
3742 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(0))
3743 self.assertEqual(len(mm.getGroupsNames()),0)
3744 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3745 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3746 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
3747 self.assertTrue(mm.getFamilyFieldAtLevel(-1) is None)
3748 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3749 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3750 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3751 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3752 delta1=ref_heap_mem-mm.getHeapMemorySize()
3753 self.assertTrue(delta1>=4*(32+9)*3+32*4*3)
3755 mm=MEDFileMesh.New(fname,MEDFileMeshReadSelector(1))
3756 self.assertEqual(len(mm.getGroupsNames()),6)
3757 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3758 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3759 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3760 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3761 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
3762 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3763 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3764 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3765 delta2=ref_heap_mem-mm.getHeapMemorySize()
3766 self.assertTrue(delta2<delta1)
3767 self.assertTrue(delta2>=4*(32+9)*1+32*4*3)
3769 mm=MEDFileUMesh(fname,MEDFileMeshReadSelector(3))
3770 self.assertEqual(len(mm.getGroupsNames()),6)
3771 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3772 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3773 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3774 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3775 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3776 self.assertTrue(mm.getNumberFieldAtLevel(0) is None)
3777 self.assertTrue(mm.getNumberFieldAtLevel(-1) is None)
3778 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3779 delta3=ref_heap_mem-mm.getHeapMemorySize()
3780 self.assertTrue(delta3<delta2)
3781 self.assertTrue(delta3>=4*(32+9)*1+32*4*1)
3783 mm=MEDFileUMesh(fname,"mesh",-1,-1,MEDFileMeshReadSelector(19))
3784 self.assertEqual(len(mm.getGroupsNames()),6)
3785 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3786 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3787 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3788 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3789 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3790 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3791 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3792 self.assertTrue(mm.getNumberFieldAtLevel(1) is None)
3793 delta4=ref_heap_mem-mm.getHeapMemorySize()
3794 self.assertTrue(delta4<delta3)
3795 self.assertTrue(delta4>=MEDCouplingSizeOfIDs()/2*4*2)
3797 mm=MEDFileUMesh.New(fname,"mesh",-1,-1,MEDFileMeshReadSelector(51))
3798 self.assertEqual(len(mm.getGroupsNames()),6)
3799 self.assertTrue(mm.getMeshAtLevel(0).isEqual(m,1e-13))
3800 self.assertTrue(mm.getMeshAtLevel(-1).isEqual(m1,1e-13))
3801 self.assertTrue(mm.getFamilyFieldAtLevel(0)!=None)
3802 self.assertTrue(mm.getFamilyFieldAtLevel(-1)!=None)
3803 self.assertTrue(mm.getFamilyFieldAtLevel(1)!=None)
3804 self.assertTrue(mm.getNumberFieldAtLevel(0)!=None)
3805 self.assertTrue(mm.getNumberFieldAtLevel(-1)!=None)
3806 self.assertTrue(mm.getNumberFieldAtLevel(1)!=None)
3807 delta5=ref_heap_mem-mm.getHeapMemorySize()
3808 self.assertTrue(delta5<delta4)
3809 self.assertEqual(delta5,0)
3812 # this test checks that setFieldProfile perform a check of the array length
3813 # compared to the profile length. This test also checks that mesh attribute of field
3814 # is not used by setFieldProfile (because across this test mesh is equal to None)
3816 def testCheckCompatibilityPfl1(self):
3817 # building a mesh containing 4 tri3 + 5 quad4
3818 tri=MEDCouplingUMesh("tri",2)
3819 tri.allocateCells() ; tri.insertNextCell(NORM_TRI3,[0,1,2])
3820 tri.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,0.)]))
3821 tris = [tri.deepCopy() for i in range(4)]
3822 for i,elt in enumerate(tris): elt.translate([i,0])
3823 tris=MEDCouplingUMesh.MergeUMeshes(tris)
3824 quad=MEDCouplingUMesh("quad",2)
3825 quad.allocateCells() ; quad.insertNextCell(NORM_QUAD4,[0,1,2,3])
3826 quad.setCoords(DataArrayDouble([(0.,0.),(0.,1.),(1.,1.),(1.,0.)]))
3827 quads = [quad.deepCopy() for i in range(5)]
3828 for i,elt in enumerate(quads): elt.translate([5+i,0])
3829 quads=MEDCouplingUMesh.MergeUMeshes(quads)
3830 m=MEDCouplingUMesh.MergeUMeshes(tris,quads)
3831 m.setName("mesh") ; m.getCoords().setInfoOnComponents(["XX [m]","YYY [km]"])
3832 m1=m.buildDescendingConnectivity()[0]
3833 mm=MEDFileUMesh() ; mm.setMeshes([m,m1])
3835 f1ts=MEDFileField1TS()
3836 f=MEDCouplingFieldDouble(ON_NODES)
3837 vals=DataArrayDouble(7) ; vals.iota(1000)
3839 f.setName("anonymous") # f has no mesh it is not a bug
3840 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3841 f1ts.setFieldProfile(f,mm,0,pfl)
3843 f1ts=MEDFileField1TS()
3844 f=MEDCouplingFieldDouble(ON_NODES)
3845 vals=DataArrayDouble(8) ; vals.iota(1000)
3847 f.setName("anonymous") # f has no mesh it is not a bug
3848 pfl=DataArrayInt([0,1,2,3,4,5,6]) ; pfl.setName("pfl")
3849 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3851 f1ts=MEDFileField1TS()
3852 f=MEDCouplingFieldDouble(ON_CELLS)
3853 vals=DataArrayDouble(7) ; vals.iota(1000)
3855 f.setName("anonymous") # f has no mesh it is not a bug
3856 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3857 f1ts.setFieldProfile(f,mm,0,pfl)
3858 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3860 f1ts=MEDFileField1TS()
3861 f=MEDCouplingFieldDouble(ON_GAUSS_PT)
3862 vals=DataArrayDouble(27) ; vals.iota(1000)
3864 f.setName("anonymous") # f has no mesh it is not a bug
3865 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3867 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])
3868 f.setGaussLocalizationOnCells([2],[0.,0.,1.,0.,1.,1.],[0.3,0.3],[1.])
3869 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])
3871 f1ts.setFieldProfile(f,mm,0,pfl)
3872 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3873 vals=DataArrayDouble(26) ; vals.iota(1040) ; f.setArray(vals)
3874 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3875 vals=DataArrayDouble(27) ; vals.iota(1000)
3876 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3878 f1ts=MEDFileField1TS()
3879 f=MEDCouplingFieldDouble(ON_GAUSS_NE)
3880 vals=DataArrayDouble(25) ; vals.iota(1000)
3882 f.setName("anonymous") # f has no mesh it is not a bug
3883 pfl=DataArrayInt([1,2,3,5,6,7,8]) ; pfl.setName("pfl")
3884 f1ts.setFieldProfile(f,mm,0,pfl)
3885 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3886 vals2=DataArrayDouble(26) ; vals2.iota(1050)
3888 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3889 self.assertTrue(f1ts.getUndergroundDataArray().isEqual(vals,1e-10))
3891 f1ts=MEDFileField1TS()
3892 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3893 self.assertRaises(InterpKernelException,f1ts.setFieldProfile,f,mm,0,pfl)
3895 f1ts.setFieldProfile(f,mm,0,pfl)
3899 def testWRMeshWithNoCells(self):
3900 fname="Pyfile71.med"
3901 a=DataArrayDouble(4) ; a.iota()
3902 c=MEDCouplingCMesh() ; c.setCoords(a,a) ; m0=c.buildUnstructured()
3903 m00=MEDCouplingUMesh("mesh",1) ; m00.setCoords(m0.getCoords()) ; m00.allocateCells(0)
3905 m.setMeshAtLevel(0,m00)
3906 m.setRenumFieldArr(1,DataArrayInt(list(range(10,26))))
3907 m.setFamilyFieldArr(1,DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3]))
3911 m=MEDFileMesh.New(fname)
3912 self.assertEqual((),m.getNonEmptyLevels())
3913 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))
3914 self.assertTrue(m.getNumberFieldAtLevel(1).isEqual(DataArrayInt(list(range(10,26)))))
3915 self.assertTrue(m.getFamilyFieldAtLevel(1).isEqual(DataArrayInt([-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,0,-1,-3,-3,-3])))
3919 def testWRQPolyg1(self):
3920 fname="Pyfile72.med"
3921 m=MEDCoupling1SGTUMesh("mesh",NORM_QUAD4) ; m.allocateCells()
3922 m.insertNextCell([0,2,1,3])
3923 m.setCoords(DataArrayDouble([0.,0.,1.,1.,1.,0.,0.,1.],4,2))
3925 ms = [m.deepCopy() for i in range(4)]
3926 for i,elt in enumerate(ms):
3927 elt.translate([float(i)*1.5,0.])
3929 m0=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3930 m0.convertAllToPoly()
3932 ms = [m.deepCopy() for i in range(5)]
3933 for i,elt in enumerate(ms):
3934 elt.translate([float(i)*1.5,1.5])
3936 m1=MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms).buildUnstructured()
3937 m1.convertAllToPoly()
3938 m1.convertLinearCellsToQuadratic()
3940 m=MEDCouplingUMesh.MergeUMeshes(m0,m1)
3943 mm.setMeshAtLevel(0,m)
3944 grp0=DataArrayInt([0,2,3]) ; grp0.setName("grp0")
3945 grp1=DataArrayInt([4,6,7]) ; grp1.setName("grp1")
3946 grp2=DataArrayInt([0,1,2,4,5,6]) ; grp2.setName("grp2")
3947 mm.setGroupsAtLevel(0,[grp0,grp1,grp2])
3952 mm_read=MEDFileUMesh(fname)
3953 self.assertTrue(mm_read.getGroupArr(0,"grp0").isEqual(grp0))
3954 self.assertTrue(mm_read.getGroupArr(0,"grp1").isEqual(grp1))
3955 self.assertTrue(mm_read.getGroupArr(0,"grp2").isEqual(grp2))
3956 self.assertTrue(mm_read.getMeshAtLevel(0).isEqual(m,1e-12))
3958 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setName("MyFirstField")
3960 arr0=DataArrayDouble(9) ; arr0.iota()
3961 arr1=DataArrayDouble(9) ; arr1.iota(100)
3962 arr=DataArrayDouble.Meld(arr0,arr1) ; arr.setInfoOnComponents(["mm [kg]","sds [m]"])
3963 f.setArray(arr) ; f.checkConsistencyLight()
3965 ff=MEDFileField1TS()
3966 ff.setFieldNoProfileSBT(f)
3969 ff_read=MEDFileField1TS(fname)
3970 f_read=ff_read.getFieldOnMeshAtLevel(ON_CELLS,0,mm_read)
3971 self.assertTrue(f_read.isEqual(f,1e-12,1e-12))
3975 def testLoadIfNecessaryOnFromScratchFields0(self):
3977 This test checks that a call to loadArraysIfNecessary works (does nothing) on field data structure whatever its level 1TS, MTS, Fields.
3979 fname="Pyfile77.med"
3980 coords=DataArrayDouble([(0,0,0),(2,1,0),(1,0,0),(1,1,0),(2,0,0),(0,1,0)])
3981 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coords)
3983 m.insertNextCell(NORM_QUAD4,[0,5,3,2])
3984 m.insertNextCell(NORM_QUAD4,[4,2,3,1])
3985 m.finishInsertingCells()
3987 mm=MEDFileUMesh() ; mm.setMeshAtLevel(0,m)
3988 ms=MEDFileMeshes() ; ms.pushMesh(mm)
3992 ff0=MEDFileFieldMultiTS() ; fs.pushField(ff0)
3993 f0=MEDCouplingFieldDouble(ON_GAUSS_NE) ; f0.setMesh(m) ; f0.setTimeUnit("ms")
3995 f0.setName("myELNOField")
3996 arrs[0]=DataArrayDouble([7,5,3,1,5,3,1,7]) ; arrs[0].setInfoOnComponent(0,"Comp0")
3997 f0.setArray(arrs[0])
3998 ff0.appendFieldNoProfileSBT(f0)
4001 arrs[1]=DataArrayDouble([1,7,5,3,7,5,3,1]) ; arrs[1].setInfoOnComponent(0,"Comp0")
4002 f0.setArray(arrs[1])
4003 ff0.appendFieldNoProfileSBT(f0)
4006 arrs[2]=DataArrayDouble([3,1,7,5,1,7,5,3]) ; arrs[2].setInfoOnComponent(0,"Comp0")
4007 f0.setArray(arrs[2])
4008 ff0.appendFieldNoProfileSBT(f0)
4011 arrs[3]=DataArrayDouble([5,3,1,7,3,1,7,5]) ; arrs[3].setInfoOnComponent(0,"Comp0")
4012 f0.setArray(arrs[3])
4013 ff0.appendFieldNoProfileSBT(f0)
4015 for i,arr in enumerate(arrs):
4016 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
4017 fs[0][i].loadArraysIfNecessary()
4018 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
4020 fs.loadArraysIfNecessary()
4021 for i,arr in enumerate(arrs):
4022 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
4024 fs[0].loadArraysIfNecessary()
4025 for i,arr in enumerate(arrs):
4026 self.assertTrue(fs[0][i].getUndergroundDataArray().isEqual(arr,1e-12))
4031 def testField1TSSetFieldNoProfileSBTPerGeoTypes(self):
4032 """ 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.
4034 fname="Pyfile78.med"
4035 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)
4036 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
4037 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coords)
4039 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
4040 m0.insertNextCell(NORM_TETRA4,elt)
4042 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
4043 m0.insertNextCell(NORM_PYRA5,elt)
4045 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
4046 m0.insertNextCell(NORM_PENTA6,elt)
4048 m0.checkConsistency()
4049 m1=MEDCouplingUMesh(); m1.setName("mesh")
4050 m1.setMeshDimension(2);
4051 m1.allocateCells(5);
4052 m1.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
4053 m1.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
4054 m1.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
4055 m1.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
4056 m1.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
4057 m1.setCoords(coords);
4058 m3=MEDCouplingUMesh("mesh",0) ; m3.setCoords(coords)
4060 m3.insertNextCell(NORM_POINT1,[2])
4061 m3.insertNextCell(NORM_POINT1,[3])
4062 m3.insertNextCell(NORM_POINT1,[4])
4063 m3.insertNextCell(NORM_POINT1,[5])
4066 mm.setMeshAtLevel(0,m0)
4067 mm.setMeshAtLevel(-1,m1)
4068 mm.setMeshAtLevel(-3,m3)
4070 #### The file is written only with one mesh and no fields. Let's put a field on it geo types per geo types.
4071 mm=MEDFileMesh.New(fname)
4073 fmts=MEDFileFieldMultiTS()
4074 f1ts=MEDFileField1TS()
4075 for lev in mm.getNonEmptyLevels():
4076 for gt in mm.getGeoTypesAtLevel(lev):
4077 p0=mm.getDirectUndergroundSingleGeoTypeMesh(gt)
4078 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setMesh(p0)
4079 arr=DataArrayDouble(f.getNumberOfTuplesExpected()) ; arr.iota()
4080 f.setArray(arr) ; f.setName("f0")
4081 f1ts.setFieldNoProfileSBT(f)
4084 self.assertEqual(mm.getNonEmptyLevels(),(0,-1,-3))
4085 for lev in [0,-1,-3]:
4086 mm.getDirectUndergroundSingleGeoTypeMeshes(lev) # please let this line, it is for the test to emulate that
4088 fmts.pushBackTimeStep(f1ts)
4092 #### The file contains now one mesh and one cell field with all cells wathever their level ang type fetched.
4093 fs=MEDFileFields(fname)
4094 self.assertEqual(len(fs),1)
4095 self.assertEqual(len(fs[0]),1)
4097 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),'','')])])
4098 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))
4102 def testMEDFileUMeshSetName(self):
4103 """ 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.
4104 This preparation makes access to internal MEDCouplingMesh pointers whose name must be updated.
4106 fname="Pyfile79.med"
4107 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4];
4109 m0=MEDCouplingUMesh() ; m0.setMeshDimension(2) # important no name here.
4110 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)
4111 m0.allocateCells(5);
4112 m0.insertNextCell(NORM_TRI3,3,targetConn[4:7]);
4113 m0.insertNextCell(NORM_TRI3,3,targetConn[7:10]);
4114 m0.insertNextCell(NORM_QUAD4,4,targetConn[0:4]);
4115 m0.insertNextCell(NORM_QUAD4,4,targetConn[10:14]);
4116 m0.insertNextCell(NORM_QUAD4,4,targetConn[14:18]);
4117 m0.setCoords(coords);
4118 mm.setMeshAtLevel(0,m0)
4119 m2=MEDCouplingUMesh() ; m2.setMeshDimension(0) ; m2.setCoords(coords) # important no name here.
4121 m2.insertNextCell(NORM_POINT1,[2])
4122 m2.insertNextCell(NORM_POINT1,[3])
4123 m2.insertNextCell(NORM_POINT1,[4])
4124 m2.insertNextCell(NORM_POINT1,[5])
4125 mm.setMeshAtLevel(-2,m2)
4126 self.assertEqual(mm.getName(),"")
4127 self.assertEqual(mm.getMeshAtLevel(0).getName(),"")
4128 mm.forceComputationOfParts()
4129 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"")
4131 self.assertEqual(mm.getName(),"abc")
4132 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_TRI3).getName(),"abc")
4133 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getName(),"abc")
4134 self.assertEqual(mm.getDirectUndergroundSingleGeoTypeMesh(NORM_POINT1).getName(),"abc")
4135 self.assertEqual(mm.getMeshAtLevel(0).getName(),"abc")
4139 def testMEDFileFieldsUnloadArraysWithoutDataLoss1(self):
4140 fileName="Pyfile80.med"
4141 m=MEDCouplingCMesh() ; m.setName("cmesh")
4142 arr=DataArrayDouble(6) ; arr.iota()
4143 m.setCoords(arr,arr)
4144 nbCells=m.getNumberOfCells()
4145 self.assertEqual(25,nbCells)
4146 f=MEDCouplingFieldDouble(ON_CELLS)
4147 f.setName("FieldOnCell") ; f.setMesh(m)
4148 arr=DataArrayDouble(nbCells) ; arr.iota()
4152 fmts=MEDFileFieldMultiTS()
4154 for i in range(nbCells):
4155 t=(float(i)+0.1,i+1,-i-2)
4157 arr2=DataArrayDouble(nbCells)
4158 perm=DataArrayInt(nbCells) ; perm.iota(i) ; perm%=nbCells
4161 f1ts=MEDFileField1TS()
4162 f1ts.setFieldNoProfileSBT(f)
4163 fmts.pushBackTimeStep(f1ts)
4165 fmts.unloadArraysWithoutDataLoss()
4166 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))
4167 fs=MEDFileFields() ; fs.pushField(fmts)
4168 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))
4169 fs.unloadArraysWithoutDataLoss()
4170 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))
4172 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))
4173 f1ts.unloadArraysWithoutDataLoss()
4174 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))
4175 mm.write(fileName,2)
4176 fs.write(fileName,0)
4177 del m,fmts,mm,f,f1ts
4179 mm=MEDFileMesh.New(fileName)
4180 fmts=MEDFileFieldMultiTS(fileName)
4181 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))
4182 fmts.unloadArraysWithoutDataLoss()
4183 self.assertTrue(not fmts[0].getUndergroundDataArray().isAllocated())
4184 fmts.loadArraysIfNecessary()
4185 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))
4187 fs=MEDFileFields(fileName)
4188 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))
4189 fs.unloadArraysWithoutDataLoss()
4190 self.assertTrue(not fs[0][0].getUndergroundDataArray().isAllocated())
4191 fs.loadArraysIfNecessary()
4192 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))
4194 f1ts=MEDFileField1TS(fileName)
4195 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))
4196 f1ts.unloadArraysWithoutDataLoss()
4197 self.assertTrue(not f1ts.getUndergroundDataArray().isAllocated())
4198 f1ts.loadArraysIfNecessary()
4199 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))
4203 def testMEDFileUMeshLoadPart1(self):
4204 """ 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
4205 memory of the returned instance.
4207 fileName="Pyfile81.med"
4208 arr=DataArrayDouble(6) ; arr.iota()
4209 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4210 m=m.buildUnstructured()
4212 m.changeSpaceDimension(3,0.)
4213 infos=["aa [b]","cc [de]","gg [klm]"]
4214 m.getCoords().setInfoOnComponents(infos)
4215 m.checkConsistency()
4217 mm.setMeshAtLevel(0,m)
4218 m1=MEDCouplingCMesh() ; m1.setCoords(arr) ; m1.setName("Mesh")
4219 m1=m1.buildUnstructured() ; m1.setCoords(m.getCoords())
4220 mm.setMeshAtLevel(-1,m1)
4221 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])
4222 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])
4223 namesCellL0=DataArrayAsciiChar(25,16)
4224 namesCellL0[:] = ["Cell#%.3d " % (i) for i in range(25)]
4225 renumM1=DataArrayInt([3,4,0,2,1])
4226 famFieldM1=DataArrayInt([-3,-4,0,-2,-1])
4227 mm.setRenumFieldArr(0,renum0)
4228 mm.setFamilyFieldArr(0,famField0)
4229 mm.setNameFieldAtLevel(0,namesCellL0)
4230 mm.setRenumFieldArr(-1,renumM1)
4231 mm.setFamilyFieldArr(-1,famFieldM1)
4232 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])
4233 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])
4234 namesNodes=DataArrayAsciiChar(36,16)
4235 namesNodes[:] = ["Node#%.3d " % (i) for i in range(36)]
4236 mm.setRenumFieldArr(1,renum1)
4237 mm.setFamilyFieldArr(1,famField1)
4238 mm.setNameFieldAtLevel(1,namesNodes)
4239 mm.setFamilyId("Fam7",77)
4240 mm.setFamilyId("Fam8",88)
4241 mm.setGroupsOnFamily("Fam7",["Grp0","Grp1"])
4242 mm.setGroupsOnFamily("Fam8",["Grp1","Grp2"])
4243 mm.write(fileName,2)
4245 mm0=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[0,10,1])
4246 self.assertEqual(mm0.getAllGeoTypes(),[NORM_QUAD4])
4247 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])))
4248 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)
4249 self.assertTrue(mm0.getCoords().isEqual(coo,1e-12))
4250 self.assertTrue(mm0.getFamilyFieldAtLevel(0).isEqual(famField0[:10]))
4251 self.assertTrue(mm0.getNumberFieldAtLevel(0).isEqual(renum0[:10]))
4252 self.assertTrue(mm0.getNameFieldAtLevel(0).isEqual(namesCellL0[:10]))
4253 self.assertTrue(mm0.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
4254 self.assertTrue(mm0.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
4255 self.assertTrue(mm0.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
4257 mm1=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_QUAD4],[11,25,1])
4258 self.assertEqual(mm1.getAllGeoTypes(),[NORM_QUAD4])
4259 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])))
4260 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)
4261 self.assertTrue(mm1.getCoords().isEqual(coo,1e-12))
4262 self.assertTrue(mm1.getFamilyFieldAtLevel(0).isEqual(famField0[11:]))
4263 self.assertTrue(mm1.getNumberFieldAtLevel(0).isEqual(renum0[11:]))
4264 self.assertTrue(mm1.getNameFieldAtLevel(0).isEqual(namesCellL0[11:]))
4265 self.assertTrue(mm1.getFamilyFieldAtLevel(1).isEqual(famField1[13:]))
4266 self.assertTrue(mm1.getNumberFieldAtLevel(1).isEqual(renum1[13:]))
4267 self.assertTrue(mm1.getNameFieldAtLevel(1).isEqual(namesNodes[13:]))
4269 mm2=MEDFileUMesh.LoadPartOf(fileName,"Mesh",[NORM_SEG2,NORM_QUAD4],[0,5,1,1,10,1])
4270 self.assertEqual(mm2.getAllGeoTypes(),[NORM_QUAD4,NORM_SEG2])
4271 self.assertTrue(mm2.getFamilyFieldAtLevel(0).isEqual(famField0[1:10]))
4272 self.assertTrue(mm2.getNumberFieldAtLevel(0).isEqual(renum0[1:10]))
4273 self.assertTrue(mm2.getNameFieldAtLevel(0).isEqual(namesCellL0[1:10]))
4274 self.assertTrue(mm2.getFamilyFieldAtLevel(-1).isEqual(famFieldM1))
4275 self.assertTrue(mm2.getNumberFieldAtLevel(-1).isEqual(renumM1))
4276 self.assertTrue(mm2.getNameFieldAtLevel(-1) is None)
4277 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])))
4278 self.assertTrue(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_SEG2).getNodalConnectivity().isEqual(DataArrayInt([0,1,1,2,2,3,3,4,4,5])))
4279 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)
4280 self.assertTrue(mm2.getCoords().isEqual(coo,1e-12))
4281 self.assertTrue(mm2.getFamilyFieldAtLevel(1).isEqual(famField1[:18]))
4282 self.assertTrue(mm2.getNumberFieldAtLevel(1).isEqual(renum1[:18]))
4283 self.assertTrue(mm2.getNameFieldAtLevel(1).isEqual(namesNodes[:18]))
4287 def testMEDFileFieldsLoadPart1(self):
4288 """This method tests partial loading on fields on CELL. It is the same principle than those in testMEDFileUMeshLoadPart1.
4290 fileName="Pyfile82.med"
4292 compos=["aa [kg]","bbb [m/s]"]
4293 arr=DataArrayDouble(6) ; arr.iota()
4294 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4295 m=m.buildUnstructured()
4297 m.changeSpaceDimension(3,0.)
4298 infos=["aa [b]","cc [de]","gg [klm]"]
4299 m.getCoords().setInfoOnComponents(infos)
4300 m.checkConsistency()
4301 f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4303 arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4304 arr[:,0]=list(range(25))
4305 arr[:,1]=list(range(100,125))
4307 WriteField(fileName,f,True)
4308 f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4309 f.setName("FieldNode")
4310 arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4311 arr[:,0]=list(range(200,236))
4312 arr[:,1]=list(range(300,336))
4314 f.checkConsistencyLight()
4315 WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4318 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
4320 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4321 self.assertEqual(fs[1][0].getFieldSplitedByType(),[(40,[(1,(0,14),'','')])])
4324 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
4326 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4328 fs[0][0].loadArrays()
4329 arr = DataArrayDouble(12, 2) ; arr[:, 0] = list(range(3, 15)) ; arr[:, 1] = list(range(103, 115))
4330 arr.setInfoOnComponents(compos)
4331 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4332 fs[1][0].loadArrays()
4333 arr = DataArrayDouble(21, 2) ; arr[:, 0] = list(range(203, 224)) ; arr[:, 1] = list(range(303, 324))
4334 arr.setInfoOnComponents(compos)
4335 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4336 # [EDF27364] : test of LoadConnectivityOnlyPartOf
4337 mm3=MEDFileUMesh.LoadConnectivityOnlyPartOf(fileName,meshName,[NORM_QUAD4],[0,6,1])
4338 mm3.forceComputationOfParts()
4339 m3s = mm3.getDirectUndergroundSingleGeoTypeMeshes(0)
4340 self.assertEqual( len(m3s), 1 )
4342 self.assertTrue( m3s.getCoords() is None )
4343 self.assertEqual( m3s.getCellModelEnum() , NORM_QUAD4 )
4344 self.assertTrue( m3s.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])) )
4345 mm4 = MEDFileUMesh.LoadConnectivityOnlyPartOf(fileName,meshName,[NORM_QUAD4],[3,15,1])
4346 mm4.forceComputationOfParts()
4347 m4s = mm4.getDirectUndergroundSingleGeoTypeMeshes(0)
4348 self.assertEqual( len(m4s), 1 )
4350 self.assertTrue( m4s.getCoords() is None )
4351 self.assertEqual( m4s.getCellModelEnum() , NORM_QUAD4 )
4352 self.assertTrue( m4s.getNodalConnectivity().isEqual(DataArrayInt([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,13,12,18,19,14,13,19,20,15,14,20,21,16,15,21,22,17,16,22,23])) )
4356 def testMEDFileWithoutCells1(self):
4357 fileName="Pyfile83.med"
4358 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4359 coo.setInfoOnComponents(["aa [m]","bbb [s]","cccc [m/s]"])
4363 mm.write(fileName,2)
4365 mm=MEDFileMesh.New(fileName)
4366 self.assertEqual(mm.getName(),"mesh")
4367 self.assertTrue(mm.getCoords().isEqual(coo,1e-12))
4371 def testZipCoordsWithLoadPart1(self):
4372 """ Test close to Pyfile82.med except that here zipCoords on MEDFileUMesh is invoked here to see if the PartDef is correctly updated.
4374 fileName="Pyfile84.med"
4376 compos=["aa [kg]","bbb [m/s]"]
4377 arr=DataArrayDouble(6) ; arr.iota()
4378 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4379 m=m.buildUnstructured()
4381 m.changeSpaceDimension(3,0.)
4382 infos=["aa [b]","cc [de]","gg [klm]"]
4383 m.getCoords().setInfoOnComponents(infos)
4384 m.checkConsistency()
4385 f=MEDCouplingFieldDouble(ON_CELLS,ONE_TIME) ; f.setMesh(m)
4387 arr=DataArrayDouble(25,2) ; arr.setInfoOnComponents(compos)
4388 arr[:,0]=list(range(25))
4389 arr[:,1]=list(range(100,125))
4391 WriteField(fileName,f,True)
4392 f=MEDCouplingFieldDouble(ON_NODES,ONE_TIME) ; f.setMesh(m)
4393 f.setName("FieldNode")
4394 arr=DataArrayDouble(36,2) ; arr.setInfoOnComponents(compos)
4395 arr[:,0]=list(range(200,236))
4396 arr[:,1]=list(range(300,336))
4398 f.checkConsistencyLight()
4399 WriteFieldUsingAlreadyWrittenMesh(fileName,f)
4402 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1])
4404 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4405 self.assertEqual(spd.getSlice(),slice(4,6,1))
4406 spd=mm.getPartDefAtLevel(1)
4407 self.assertEqual(spd.getSlice(),slice(4,14,1))
4408 self.assertTrue(spd.getNumberOfElems()==10 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4409 mm.zipCoords() # <- The important line is here !
4410 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4411 self.assertEqual(spd.getSlice(),slice(4,6,1))
4412 spd=mm.getPartDefAtLevel(1)
4413 self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4414 self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
4415 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4416 fs[0][0].loadArrays()
4417 arr=DataArrayDouble([(4,104),(5,105)])
4418 arr.setInfoOnComponents(compos)
4419 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4420 fs[1][0].loadArrays()
4421 arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
4422 arr.setInfoOnComponents(compos)
4423 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4424 m_ref = mm[0].deepCopy()
4425 # now read it in 2 load sessions to avoid memory peak. zipCoords is no more requested here.
4427 mrs = MEDFileMeshReadSelector()
4428 mrs.setNumberOfCoordsLoadSessions(2)
4429 mm=MEDFileUMesh.LoadPartOf(fileName,meshName,[NORM_QUAD4],[4,6,1],-1,-1,mrs)
4431 spd=mm.getPartDefAtLevel(0,NORM_QUAD4)
4432 self.assertEqual(spd.getSlice(),slice(4,6,1))
4433 spd=mm.getPartDefAtLevel(1)
4434 self.assertTrue(spd.getNumberOfElems()==8 and spd.getNumberOfElems()==mm.getNumberOfNodes())
4435 self.assertTrue(spd.toDAI().isEqual(DataArrayInt([4,5,6,7,10,11,12,13])))
4436 fs=MEDFileFields.LoadPartOf(fileName,False,ms)
4437 fs[0][0].loadArrays()
4438 arr=DataArrayDouble([(4,104),(5,105)])
4439 arr.setInfoOnComponents(compos)
4440 self.assertTrue(fs[0][0].getUndergroundDataArray().isEqual(arr,1e-12))
4441 fs[1][0].loadArrays()
4442 arr=DataArrayDouble([(204,304),(205,305),(206,306),(207,307),(210,310),(211,311),(212,312),(213,313)])
4443 arr.setInfoOnComponents(compos)
4444 self.assertTrue(fs[1][0].getUndergroundDataArray().isEqual(arr,1e-12))
4445 self.assertTrue( mm[0].deepCopy().isEqual(m_ref,1e-12) )
4449 def testMEDFileCMeshSetGroupsAtLevel(self):
4450 """ Non regression test to check that setGroupsAtLevel is available with MEDFileCMesh.
4452 m=MEDCouplingCMesh() ; m.setCoords(DataArrayDouble([0,1,2,3,4]),DataArrayDouble([0,1,2,3,4]))
4454 mm=MEDFileCMesh() ; mm.setMesh(m)
4455 grp=DataArrayInt([1,3,4,5,7]) ; grp.setName("MyAssembly")
4456 mm.setGroupsAtLevel(0,[grp])
4457 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([-1,-2,-1,-2,-2,-2,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1])))
4461 def testMEDFileUMeshBuildExtrudedMesh1(self):
4462 """ New functionality of MEDFileUMesh.buildExtrudedMesh."""
4463 fileName="Pyfile85.med"
4466 meshName3DOut="Mesh3D"
4468 d1=DataArrayInt([0,4,20,24])
4469 d2=DataArrayInt([0,1,2,3,7,8,12,13,17,18,19,20])
4471 a=DataArrayDouble(6) ; a.iota()
4472 m=MEDCouplingCMesh() ; m.setCoords(a,a)
4473 m=m.buildUnstructured()
4474 d1c=d1.buildComplement(m.getNumberOfCells())
4475 m=m[d1c] ; m.zipCoords()
4476 m0=m[d2] ; m1=m[d2.buildComplement(m.getNumberOfCells())]
4478 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords([m0,m1])
4479 m.setName(meshName2D)
4480 mMinus1,a,b,c,d=m.buildDescendingConnectivity()
4481 e=d.deltaShiftIndex().findIdsEqual(1)
4484 mm.setMeshAtLevel(0,m) ; mm.setMeshAtLevel(-1,mMinus1)
4485 grp0=DataArrayInt([0,1,2,3,4,5,24,25,26]) ; grp0.setName("grp0")
4486 mm.setGroupsAtLevel(0,[grp0])
4487 grp1=e ; grp1.setName("grp1")
4488 mm.setGroupsAtLevel(-1,[grp1])
4489 mm.write(fileName,2)
4491 a=DataArrayDouble(3) ; a.iota()
4492 tmp=MEDCouplingCMesh() ; tmp.setCoords(a) ; tmp=tmp.buildUnstructured()
4493 tmp.setName(meshName1D)
4494 tmp.changeSpaceDimension(3)
4495 tmp.setCoords(tmp.getCoords()[:,[1,2,0]])
4497 mm1D.setMeshAtLevel(0,tmp)
4498 mm1D.write(fileName,0)
4500 mm2D=MEDFileMesh.New(fileName,meshName2D)
4501 mm1D=MEDFileMesh.New(fileName,meshName1D)
4502 m1D=mm1D.getMeshAtLevel(0)
4503 mm3D=mm2D.buildExtrudedMesh(m1D,0)
4505 self.assertEqual(mm3D.getName(),mm2D.getName())
4506 self.assertEqual(mm3D.getNumberOfCellsAtLevel(0),66)
4507 self.assertEqual(mm3D.getNumberOfCellsAtLevel(-1),194)
4508 self.assertEqual(mm3D.getGroupsNames(),('grp0','grp0_extruded','grp0_top','grp1','grp1_extruded','grp1_top'))
4509 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0"),(-1,))
4510 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_top"),(-1,))
4511 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp0_extruded"),(0,))
4512 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1"),(-2,))
4513 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_top"),(-2,))
4514 self.assertEqual(mm3D.getGrpNonEmptyLevels("grp1_extruded"),(-1,))
4515 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.)])
4516 self.assertTrue(mm3D.getCoords().isEqual(d,1e-12))
4517 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])
4518 self.assertTrue(mm3D[0].getNodalConnectivity().isEqual(d))
4519 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])
4520 self.assertTrue(mm3D[0].getNodalConnectivityIndex().isEqual(d))
4521 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])
4522 self.assertTrue(mm3D[-1].getNodalConnectivity().isEqual(d))
4523 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])
4524 self.assertTrue(mm3D[-1].getNodalConnectivityIndex().isEqual(d))
4525 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])
4526 self.assertTrue(mm3D[-2].getNodalConnectivity().isEqual(d))
4527 d=DataArrayInt(129) ; d.iota() ; d*=3
4528 self.assertTrue(mm3D[-2].getNodalConnectivityIndex().isEqual(d))
4530 self.assertEqual(mm3D.getGroupArr(-1,"grp0").getName(),"grp0")
4531 self.assertEqual(mm3D.getGroupArr(-2,"grp1").getName(),"grp1")
4532 self.assertTrue(mm3D.getGroupArr(-1,"grp0").isEqualWithoutConsideringStr(DataArrayInt([0,1,2,3,4,5,176,177,178])))
4533 self.assertTrue(mm3D.getGroupArr(-1,"grp0_top").isEqualWithoutConsideringStr(DataArrayInt([24,25,26,27,28,29,185,186,187])))
4534 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])))
4535 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])))
4536 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])))
4537 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])))
4538 mm3D.setName("MeshExtruded")
4539 mm3D.write(fileName,0)
4542 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
4544 def testMEDFileUMeshPickeling1(self):
4545 outFileName="Pyfile86.med"
4546 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)
4547 c.setInfoOnComponents(["aa","bbb"])
4548 targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
4549 m=MEDCouplingUMesh();
4550 m.setMeshDimension(2);
4552 m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
4553 m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
4554 m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
4555 m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
4556 m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
4557 m.finishInsertingCells();
4559 m.checkConsistencyLight()
4560 m1=MEDCouplingUMesh.New();
4561 m1.setMeshDimension(1);
4562 m1.allocateCells(3);
4563 m1.insertNextCell(NORM_SEG2,2,[1,4])
4564 m1.insertNextCell(NORM_SEG2,2,[3,6])
4565 m1.insertNextCell(NORM_SEG3,3,[2,8,5])
4566 m1.finishInsertingCells();
4568 m1.checkConsistencyLight()
4569 m2=MEDCouplingUMesh.New();
4570 m2.setMeshDimension(0);
4571 m2.allocateCells(4);
4572 m2.insertNextCell(NORM_POINT1,1,[1])
4573 m2.insertNextCell(NORM_POINT1,1,[3])
4574 m2.insertNextCell(NORM_POINT1,1,[2])
4575 m2.insertNextCell(NORM_POINT1,1,[6])
4576 m2.finishInsertingCells();
4578 m2.checkConsistencyLight()
4580 mm=MEDFileUMesh.New()
4581 self.assertTrue(mm.getUnivNameWrStatus())
4582 mm.setName("MyFirstMEDCouplingMEDmesh")
4583 mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
4587 mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
4589 mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
4590 # playing with groups
4591 g1_2=DataArrayInt.New()
4592 g1_2.setValues([1,3],2,1)
4594 g2_2=DataArrayInt.New()
4595 g2_2.setValues([1,2,3],3,1)
4597 mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
4598 g1_1=DataArrayInt.New()
4599 g1_1.setValues([0,1,2],3,1)
4601 g2_1=DataArrayInt.New()
4602 g2_1.setValues([0,2],2,1)
4604 mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
4605 g1_N=DataArrayInt.New()
4606 g1_N.setValues(list(range(8)),8,1)
4608 g2_N=DataArrayInt.New()
4609 g2_N.setValues(list(range(9)),9,1)
4611 mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
4612 mm.createGroupOnAll(0,"GrpOnAllCell")
4613 # check content of mm
4614 t=mm.getGroupArr(0,"G1",False)
4615 self.assertTrue(g1_2.isEqual(t));
4616 t=mm.getGroupArr(0,"G2",False)
4617 self.assertTrue(g2_2.isEqual(t));
4618 t=mm.getGroupArr(-1,"G1",False)
4619 self.assertTrue(g1_1.isEqual(t));
4620 t=mm.getGroupArr(-1,"G2",False)
4621 self.assertTrue(g2_1.isEqual(t));
4622 t=mm.getGroupArr(1,"G1",False)
4623 self.assertTrue(g1_N.isEqual(t));
4624 t=mm.getGroupArr(1,"G2",False)
4625 self.assertTrue(g2_N.isEqual(t));
4626 self.assertTrue(mm.existsGroup("GrpOnAllCell"));
4627 t=mm.getGroupArr(0,"GrpOnAllCell")
4629 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4630 mm2=pickle.loads(st)
4631 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4632 self.assertEqual(mm.getAxisType(),AX_CART)
4634 mm.setAxisType(AX_CYL)
4635 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
4636 mm2=pickle.loads(st)
4637 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
4638 self.assertEqual(mm2.getAxisType(),AX_CYL)
4642 def testMEDFileFieldsLoadSpecificEntities1(self):
4645 fileName="Pyfile87.med"
4649 m=MEDCouplingCMesh()
4650 arr=DataArrayDouble(nbNodes) ; arr.iota()
4652 m=m.buildUnstructured()
4655 fmts=MEDFileFieldMultiTS()
4656 for i in range(nbPdt):
4657 f=MEDCouplingFieldDouble(ON_NODES)
4659 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4661 f.setName(fieldName)
4662 f.setTime(float(i),i,0)
4663 fmts.appendFieldNoProfileSBT(f)
4666 mm=MEDFileUMesh() ; mm[0]=m
4667 fmts.write(fileName,2)
4668 mm.write(fileName,0)
4670 fs=MEDFileFields(fileName,False)
4671 fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
4672 fs.loadArraysIfNecessary()
4673 fs2.loadArraysIfNecessary()
4674 for i in range(nbPdt):
4675 self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4677 m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
4678 m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
4679 m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
4680 fmts=MEDFileFieldMultiTS()
4681 for i in range(nbPdt):
4682 f=MEDCouplingFieldDouble(ON_CELLS)
4684 arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
4686 f.setName(fieldName)
4687 f.setTime(float(i),i,0)
4688 fmts.appendFieldNoProfileSBT(f)
4690 mm=MEDFileUMesh() ; mm[0]=m3
4692 self.assertEqual(mm.getNonEmptyLevels(),())
4694 self.assertEqual(mm.getNonEmptyLevels(),(0,))
4695 fmts.write(fileName,2)
4696 fs=MEDFileFields(fileName,False)
4697 fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
4698 fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
4699 fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
4700 fs.loadArraysIfNecessary()
4701 fs2.loadArraysIfNecessary()
4702 fs3.loadArraysIfNecessary()
4703 fs4.loadArraysIfNecessary()
4704 for i in range(nbPdt):
4705 self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
4706 self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
4707 self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
4712 def testMEDFileLotsOfTSRW1(self):
4715 fileName="Pyfile88.med"
4716 nbPdt=300 # <- perftest = 30000
4719 maxPdt=100 # <- optimum = 500
4720 m=MEDCouplingCMesh()
4721 arr=DataArrayDouble(nbNodes) ; arr.iota()
4723 m=m.buildUnstructured()
4726 nbOfField=nbPdt//maxPdt
4728 for j in range(nbOfField):
4729 fmts=MEDFileFieldMultiTS()
4730 s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
4731 for i in range(s.start, s.stop, s.step):
4732 f=MEDCouplingFieldDouble(ON_NODES)
4734 arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
4736 f.setName("%s_%d"%(fieldName,j))
4737 f.setTime(float(i),i,0)
4738 fmts.appendFieldNoProfileSBT(f)
4743 mm=MEDFileUMesh() ; mm[0]=m
4744 fs.write(fileName,2)
4745 mm.write(fileName,0)
4747 def appendInDict(d,key,val):
4754 allFields=GetAllFieldNames(fileName)
4756 pat=re.compile("([\d]+)([\s\S]+)$")
4757 for st in allFields:
4761 appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
4764 appendInDict(allFieldsDict,st,'')
4768 for k in allFieldsDict:
4769 if allFieldsDict[k]!=['']:
4770 allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
4773 for it in allFieldsDict[k]:
4774 fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
4779 for ii in range(nbIter):
4780 zeResu.pushBackTimeSteps(fmts2.pop())
4783 fs2.pushField(zeResu)
4785 self.assertEqual(fs2[0].getTimeSteps(), [(i, 0, float(i)) for i in range(nbPdt)])
4789 def testMEDFileMeshRearrangeFamIds1(self):
4790 """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
4791 fileName="Pyfile89.med"
4792 meshName='Maillage_2'
4794 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)])
4796 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])
4797 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])
4798 m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
4799 m0.setConnectivity(c0,c0i)
4802 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])
4803 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])
4804 m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
4805 m1.setConnectivity(c1,c1i)
4808 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])
4809 m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
4810 m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
4811 mm[-2]=m2.buildUnstructured()
4813 ref0=DataArrayInt(55) ; ref0[:]=0
4814 mm.setFamilyFieldArr(0,ref0)
4815 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]))
4816 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])
4817 mm.setFamilyFieldArr(-1,ref1)
4818 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])
4819 mm.setFamilyFieldArr(-2,ref2)
4821 for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
4822 mm.setFamilyId(f,fid)
4823 for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
4824 mm.setFamiliesOnGroup(grp,fams)
4825 mm.write(fileName,2)
4827 mm=MEDFileMesh.New(fileName)
4828 grp=mm.getGroup(-1,"Groupe_1")
4829 dai=grp.computeFetchedNodeIds()
4832 mm.rearrangeFamilies() # <- the aim of the test
4833 self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
4834 self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
4835 self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
4836 self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
4837 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])))
4838 allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
4839 allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
4840 self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
4841 for elt,fams in allGrps:
4842 self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
4843 self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
4844 for elt,eltId in allFams:
4845 self.assertEqual(mm.getFamilyId(elt),eltId)
4849 def testNonRegrCMeshSetFieldPfl1(self):
4850 """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
4851 ff=MEDFileField1TS()
4854 m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4858 field=MEDCouplingFieldDouble(ON_CELLS)
4860 field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4861 field.setName("Field")
4862 field.checkConsistencyLight()
4863 pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
4864 ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
4865 self.assertEqual(ff.getPfls(),())
4866 field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4867 self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4868 del ff,mm,field,field2,pfl
4869 # same with unstructured mesh
4870 ff=MEDFileField1TS()
4873 m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
4876 m=m.buildUnstructured()
4878 field=MEDCouplingFieldDouble(ON_CELLS)
4880 field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
4881 field.setName("Field")
4882 field.checkConsistencyLight()
4883 pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
4884 ff.setFieldProfile(field,mm,0,pfl)
4885 self.assertEqual(ff.getPfls(),())
4886 field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
4887 self.assertTrue(field.isEqual(field2,1e-12,1e-12))
4891 def testMEDFileUMeshLinearToQuadraticAndRev1(self):
4893 fileName="Pyfile90.med"
4894 fileName2="Pyfile91.med"
4895 arr=DataArrayDouble(5) ; arr.iota()
4896 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
4897 m=m.buildUnstructured()
4898 d=DataArrayInt([3,7,11,15])
4901 m2=m[d.buildComplement(m.getNumberOfCells())]
4902 m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
4903 m.changeSpaceDimension(3,0.)
4904 arr=DataArrayDouble(3) ; arr.iota()
4905 m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
4906 m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
4907 delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
4908 m3D=m.buildExtrudedMesh(m1D,0)
4909 m3D.sortCellsInMEDFileFrmt()
4910 m3D.setName(meshName)
4911 m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkConsistency()
4912 m1D=m2D.computeSkin() ; m1D.setName(meshName)
4913 m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
4916 mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
4917 grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
4918 grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
4919 grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
4920 grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
4921 diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
4922 vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
4923 vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
4924 mm.setGroupsAtLevel(0,[vol1,vol2])
4925 mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
4926 mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
4928 mmOut1=mm.linearToQuadratic(0,0.)
4929 mmOut1.write(fileName2,2)
4930 mmOut2=mmOut1.quadraticToLinear(0.)
4931 self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
4935 def testMEDFileMeshAddGroup1(self):
4936 m=MEDCouplingCMesh()
4937 arrX=DataArrayDouble(9) ; arrX.iota()
4938 arrY=DataArrayDouble(4) ; arrY.iota()
4939 m.setCoords(arrX,arrY)
4943 grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
4945 grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
4947 grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
4949 grp3=DataArrayInt([23]) ; grp3.setName("grp3")
4951 for grp in [grp0,grp1,grp2,grp3]:
4952 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4953 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
4955 for grp in [grp0,grp1,grp2,grp3]:
4956 grpNode=grp.deepCopy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
4957 mm.addGroup(1,grpNode)
4958 self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
4959 for grp in [grp0,grp1,grp2,grp3]:
4960 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4961 for grp in [grp0,grp1,grp2,grp3]:
4962 grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4963 self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4964 mm.normalizeFamIdsMEDFile()
4965 for grp in [grp0,grp1,grp2,grp3]:
4966 self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
4967 for grp in [grp0,grp1,grp2,grp3]:
4968 grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
4969 self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
4973 def testMEDFileJoint1(self):
4974 fileName="Pyfile92.med"
4975 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
4976 coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
4980 mm.setDescription("un maillage")
4981 mm.write(fileName,2)
4982 node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
4983 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
4984 one_step_joint=MEDFileJointOneStep()
4985 one_step_joint.pushCorrespondence(cell_correspond)
4986 one_step_joint.pushCorrespondence(node_correspond)
4987 one_joint=MEDFileJoint()
4988 one_joint.pushStep(one_step_joint)
4989 one_joint.setLocalMeshName("maa1")
4990 one_joint.setRemoteMeshName("maa1")
4991 one_joint.setDescription("joint_description")
4992 one_joint.setJointName("joint_1")
4993 one_joint.setDomainNumber(1)
4994 self.assertEqual( one_joint.getLocalMeshName(), "maa1")
4995 self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
4996 self.assertEqual( one_joint.getDescription(), "joint_description")
4997 self.assertEqual( one_joint.getJointName(), "joint_1")
4998 self.assertEqual( one_joint.getDomainNumber(), 1)
4999 joints=MEDFileJoints()
5000 joints.pushJoint(one_joint);
5001 joints.write(fileName,0)
5003 jointsR=MEDFileJoints(fileName,mm.getName())
5004 self.assertEqual( jointsR.getNumberOfJoints(), 1 )
5005 jR = jointsR.getJointAtPos(0)
5006 self.assertTrue( jR.isEqual( one_joint ))
5007 self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
5008 self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
5009 jointsR.destroyJointAtPos(0)
5013 def testMEDFileJoint2(self):
5014 fileNameWr="Pyfile93.med"
5015 coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
5016 coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
5020 mm.setDescription("un maillage")
5021 node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
5022 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
5023 one_step_joint=MEDFileJointOneStep()
5024 two_step_joint=MEDFileJointOneStep()
5025 one_joint=MEDFileJoint()
5026 two_joint=MEDFileJoint()
5027 one_step_joint.pushCorrespondence(node_correspond)
5028 one_joint.pushStep(one_step_joint)
5029 two_step_joint.pushCorrespondence(cell_correspond)
5030 two_step_joint.pushCorrespondence(node_correspond)
5031 two_joint.pushStep(two_step_joint)
5032 one_joint.setLocalMeshName("maa1")
5033 one_joint.setRemoteMeshName("maa1")
5034 one_joint.setDescription("joint_description_1")
5035 one_joint.setJointName("joint_1")
5036 one_joint.setDomainNumber(1)
5037 two_joint.setLocalMeshName("maa1")
5038 two_joint.setRemoteMeshName("maa1")
5039 two_joint.setDescription("joint_description_2")
5040 two_joint.setJointName("joint_2")
5041 two_joint.setDomainNumber(2)
5042 joints=MEDFileJoints()
5043 joints.pushJoint(one_joint)
5044 joints.pushJoint(two_joint)
5045 mm.setJoints( joints )
5046 mm.write(fileNameWr,2)
5048 mm=MEDFileMesh.New(fileNameWr)
5049 self.assertEqual( mm.getNumberOfJoints(), 2)
5050 jointsR = mm.getJoints();
5051 self.assertEqual( jointsR.getMeshName(), mm.getName() )
5052 self.assertEqual( len( jointsR ), 2 )
5053 jointR1 = jointsR[0]
5054 jointR2 = jointsR[1]
5055 self.assertFalse( jointR1 is None )
5056 self.assertFalse( jointR2 is None )
5057 self.assertTrue( jointR1.isEqual( one_joint ))
5058 self.assertTrue( jointR2.isEqual( two_joint ))
5062 def testMEDFileJoint1(self):
5063 node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
5064 cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
5065 cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
5066 cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
5067 joint1st_1=MEDFileJointOneStep()
5068 joint1st_1.pushCorrespondence(cell_correspond)
5069 joint1st_1.pushCorrespondence(node_correspond)
5070 joint1st_2=MEDFileJointOneStep()
5071 joint1st_2.pushCorrespondence(cell_correspond)
5072 joint1st_2.pushCorrespondence(node_correspond)
5073 joint1st_3=MEDFileJointOneStep()
5074 joint1st_3.pushCorrespondence(node_correspond)
5075 joint1st_3.pushCorrespondence(cell_correspond)
5076 joint1st_4=MEDFileJointOneStep()
5077 joint1st_4.pushCorrespondence(cell_correspond)
5078 joint1st_5=MEDFileJointOneStep()
5079 joint1st_5.pushCorrespondence(cell_correspon2)
5080 joint1st_6=MEDFileJointOneStep()
5081 joint1st_6.pushCorrespondence(cell_correspon3)
5082 self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
5083 self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
5084 self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
5085 self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
5086 self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
5087 self.assertEqual(1,joint1st_6.getNumberOfCorrespondences())
5088 joint1st_6.clearCorrespondences()
5089 self.assertEqual(0,joint1st_6.getNumberOfCorrespondences())
5090 one_joint=MEDFileJoint()
5091 one_joint.pushStep(joint1st_1)
5092 one_joint.setLocalMeshName("maa1")
5093 one_joint.setRemoteMeshName("maa2")
5094 one_joint.setDescription("joint_description")
5095 one_joint.setJointName("joint_1")
5096 one_joint.setDomainNumber(1)
5097 self.assertEqual( "maa1", one_joint.getLocalMeshName())
5098 self.assertEqual( "maa2", one_joint.getRemoteMeshName())
5099 self.assertEqual( "joint_description", one_joint.getDescription())
5100 self.assertEqual( 1, one_joint.getDomainNumber())
5101 self.assertEqual( "joint_1", one_joint.getJointName())
5102 one_joint_copy = one_joint.deepCopy()
5103 self.assertEqual( "maa1", one_joint_copy.getLocalMeshName())
5104 self.assertEqual( "maa2", one_joint_copy.getRemoteMeshName())
5105 self.assertEqual( "joint_description", one_joint_copy.getDescription())
5106 self.assertEqual( 1, one_joint_copy.getDomainNumber())
5107 self.assertEqual( "joint_1", one_joint_copy.getJointName())
5110 @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
5112 def testMEDFileSafeCall0(self):
5113 """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
5114 fname="Pyfile94.med"
5115 errfname="Pyfile94.err"
5118 # first clean file if needed
5119 if os.path.exists(fname):
5122 # second : build a file from scratch
5123 m=MEDCouplingCMesh()
5124 arr=DataArrayDouble(11) ; arr.iota()
5125 m.setCoords(arr,arr)
5130 # third : change permissions to remove write access on created file
5131 os.chmod(fname, 0o444)
5132 # four : try to append data on file -> check that it raises Exception
5133 f=MEDCouplingFieldDouble(ON_CELLS)
5136 f.setArray(DataArrayDouble(100))
5137 f.getArray()[:]=100.
5138 f.checkConsistencyLight()
5139 f1ts=MEDFileField1TS()
5140 f1ts.setFieldNoProfileSBT(f)
5142 tmp=StdOutRedirect(errfname)
5143 self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
5146 if os.path.exists(errfname):
5152 def testUnivStatus1(self):
5153 """ Non regression test to check the effectiveness of univ write status."""
5154 fname="Pyfile95.med"
5155 arr=DataArrayDouble(10) ; arr.iota()
5156 m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
5157 mm=MEDFileCMesh() ; mm.setMesh(m)
5158 mm.setUnivNameWrStatus(False) # test is here
5160 mm=MEDFileCMesh(fname)
5161 self.assertEqual(mm.getUnivName(),"")
5162 mm.setUnivNameWrStatus(True)
5164 mm=MEDFileCMesh(fname)
5165 self.assertTrue(mm.getUnivName()!="")
5169 def testEmptyMesh(self):
5170 """ MEDLoader should be able to consistently write and read an empty mesh (coords array
5172 fname = "Pyfile96.med"
5173 m = MEDCouplingUMesh('toto', 2)
5174 m.setCoords(DataArrayDouble([], 0, 2))
5175 m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
5176 mfu = MEDFileUMesh()
5177 mfu.setMeshAtLevel(0, m)
5179 mfu2 = MEDFileUMesh(fname)
5180 self.assertEqual('toto', mfu2.getName())
5181 lvl = mfu2.getNonEmptyLevels()
5182 self.assertEqual((), lvl)
5184 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
5185 def testMEDFileUMeshPickeling2(self):
5186 """ Check that pickalization can be performed on a unpickalized instance. Non regression test."""
5192 arr=DataArrayDouble(nbOfNodesPerAxis) ; arr.iota() ; arr/=(nbOfNodesPerAxis-1) ; arr*=hauteur
5193 m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured() ; m.setName(name)
5194 mesh=MEDFileUMesh() ; mesh[0]=m
5195 m1=m.computeSkin() ; mesh[-1]=m1
5197 bary1=m1.computeCellCenterOfMass()[:,2]
5198 grp1=bary1.findIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
5199 grp2=bary1.findIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
5200 mesh.setGroupsAtLevel(-1,[grp1,grp2])
5202 st=pickle.dumps(mesh,2)
5204 st2=pickle.dumps(mm,2)
5205 mm2=pickle.loads(st2)
5206 self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
5210 def testMEDFileEquivalence1(self):
5211 """ First check of equivalence implementation in MEDFileMesh"""
5212 fileName="Pyfile97.med"
5215 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)])
5216 coo.setInfoOnComponents(["X [Sans_unite]","Y [Sans_unite]","Z [Sans_unite]"])
5217 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])
5218 m1=MEDCoupling1SGTUMesh(meshName,NORM_QUAD4) ; m1.setCoords(coo) ; m1.setNodalConnectivity(connQ4) ; mm[-1]=m1
5219 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])
5220 m0=MEDCoupling1SGTUMesh(meshName,NORM_HEXA8) ; m0.setCoords(coo) ; m0.setNodalConnectivity(connH8) ; mm[0]=m0
5221 mm.getFamilyFieldAtLevel(-1)[:]=-2
5222 mm.getFamilyFieldAtLevel(0)[:]=0
5223 mm.addFamily("HOMARD________-1",-1)
5224 mm.addFamily("HOMARD________-2",-2)
5225 mm.addFamily("HOMARD________-3",-3)
5226 mm.setFamiliesIdsOnGroup("HOMARD",[-1,-2,-3])
5228 eqName="MAILLES_A_RECOLLER_APRES_HOMARD"
5229 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."
5230 mm.initializeEquivalences()
5231 eqs=mm.getEquivalences()
5232 eq0=eqs.appendEmptyEquivalenceWithName(eqName)
5233 eq0.setDescription(descEq)
5234 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)])
5235 eq0.setArray(-1,corr)
5236 self.assertEqual(eq0.getCell().size(),1)
5237 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
5238 eq0.getCell().clear()
5239 self.assertEqual(eq0.getCell().size(),0)
5240 eq0.getCell().setArrayForType(NORM_QUAD4,corr)
5241 self.assertEqual(eq0.getCell().size(),1)
5242 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
5243 mm.killEquivalences()
5244 mm.initializeEquivalences()
5245 eqs=mm.getEquivalences()
5246 eq0=eqs.appendEmptyEquivalenceWithName(eqName)
5247 eq0.setDescription(descEq)
5249 c.setArrayForType(NORM_QUAD4,corr)
5250 self.assertEqual(eq0.getCell().size(),1)
5251 self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
5253 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
5254 self.assertEqual(mm2.getEquivalences().size(),1)
5255 self.assertTrue(mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4).isEqual(corr))
5256 mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=2
5257 self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
5258 mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=0
5259 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
5260 mm.write(fileName,2)
5262 mm3=MEDFileMesh.New(fileName)
5263 self.assertTrue(mm.isEqual(mm3,1e-12)[0])
5267 def testMEDFileForFamiliesPlayer1(self):
5268 """Non regression bug EDF11911. For serial killers using same family name to store both cells and nodes ! Only sky is the limit."""
5269 fileName="Pyfile98.med"
5271 magicSt="%s%%04i"%(MEDFileMesh.GetMagicFamilyStr())
5272 arr=DataArrayDouble(4) ; arr.iota()
5273 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
5274 m=m.buildUnstructured()
5277 mm.setName(meshName)
5278 mm.setFamilyId("FAMILLE_ZERO",0)
5279 mm.getFamilyFieldAtLevel(0)[-3:]=-4
5280 mm.setFamilyId("RIDF%s"%(magicSt%0),-4)
5281 mm.setGroupsOnFamily("RIDF%s"%(magicSt%0),["RID"])
5282 d=DataArrayInt(16) ; d[:]=0 ; d[[1,2,4,5]]=3
5283 mm.setFamilyFieldArr(1,d)
5284 mm.setFamilyId("RIDF%s"%(magicSt%1),3)
5285 mm.setGroupsOnFamily("RIDF%s"%(magicSt%1),["RID"])
5286 self.assertEqual(mm.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
5287 self.assertEqual(mm.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF")) # <- the aim of test is here !
5288 self.assertEqual(mm.getFamiliesIdsOnGroup("RID"),(-4,3))
5289 mm.write(fileName,2)
5290 # now read such funny file !
5291 mm2=MEDFileMesh.New(fileName) # <- normally mdump of Pyfile98.med must contain only RID and FAMILLE_ZERO families.
5292 self.assertTrue(mm.isEqual(mm2,1e-16))
5293 self.assertEqual(mm2.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
5294 self.assertEqual(mm2.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF"))
5295 self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too !
5299 def testCartesianizer1(self):
5300 """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """
5302 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
5303 mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts()
5304 d0=DataArrayInt(16) ; d0[:]=0
5305 d1=DataArrayInt(9) ; d1[:]=0
5306 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5307 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5308 ref0=mm.getCoords().getHiddenCppPointer()
5309 ref1=mm[0].getNodalConnectivity().getHiddenCppPointer()
5310 self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer())
5311 ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer()
5312 ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer()
5313 self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
5314 mm.setAxisType(AX_CYL) #<- important
5315 mm2=mm.cartesianize() # the trigger
5316 self.assertEqual(mm2.getAxisType(),AX_CART)
5317 mm.setAxisType(AX_CART) # this is here only to avoid complaints
5318 self.assertTrue(isinstance(mm2,MEDFileUMesh))
5319 self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
5320 self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important
5321 self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important
5322 self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer())
5323 self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
5324 self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important
5325 self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important
5326 self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important
5327 self.assertEqual(mm2.getName(),mm.getName())
5328 self.assertEqual(mm2.getDescription(),mm.getDescription())
5329 self.assertEqual(mm2.getTime(),mm.getTime())
5330 self.assertEqual(mm2.getTime(),mm.getTime())
5331 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5332 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5333 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5334 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5335 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5336 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5337 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5338 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5340 mm.setAxisType(AX_CART)
5341 mm2=mm.cartesianize() # the trigger
5342 self.assertEqual(mm2.getAxisType(),AX_CART)
5343 self.assertTrue(isinstance(mm2,MEDFileUMesh))
5344 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5345 # CurveLinearMesh non cart
5346 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear()
5347 mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
5348 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5349 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5350 ref0=mm.getMesh().getCoords().getHiddenCppPointer()
5351 mm2=mm.cartesianize() # the trigger
5352 self.assertEqual(mm2.getAxisType(),AX_CART)
5353 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5354 self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
5355 self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important
5356 self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important
5357 self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
5358 self.assertEqual(mm2.getName(),mm.getName())
5359 self.assertEqual(mm2.getDescription(),mm.getDescription())
5360 self.assertEqual(mm2.getTime(),mm.getTime())
5361 self.assertEqual(mm2.getTime(),mm.getTime())
5362 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5363 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5364 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5365 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5366 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5367 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5368 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5369 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5370 # CurveLinearMesh cart
5371 mm.setAxisType(AX_CART)
5372 mm2=mm.cartesianize() # the trigger
5373 self.assertEqual(mm2.getAxisType(),AX_CART)
5374 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5375 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5377 arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
5378 mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxisType(AX_CYL) #<- important
5379 mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
5380 mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
5381 mm2=mm.cartesianize() # the trigger
5382 self.assertEqual(mm2.getAxisType(),AX_CART)
5383 self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
5384 self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
5385 self.assertEqual(mm2.getName(),mm.getName())
5386 self.assertEqual(mm2.getDescription(),mm.getDescription())
5387 self.assertEqual(mm2.getTime(),mm.getTime())
5388 self.assertEqual(mm2.getTime(),mm.getTime())
5389 self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
5390 self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
5391 self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
5392 self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
5393 self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
5394 self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
5395 self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
5396 self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
5398 mm.setAxisType(AX_CART)
5399 mm2=mm.cartesianize() # the trigger
5400 self.assertEqual(mm2.getAxisType(),AX_CART)
5401 self.assertTrue(isinstance(mm2,MEDFileCMesh))
5402 self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
5406 def testCheckCoherency(self):
5407 m2 = MEDCouplingUMesh("2d", 2)
5408 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5409 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5410 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5411 mum = MEDFileUMesh()
5412 mum.setMeshAtLevel(0, m2)
5413 mum.setMeshAtLevel(-1, m1)
5414 mum.checkConsistency()
5415 mum2 = mum.deepCopy()
5418 arr = DataArrayInt([2]*4)
5419 mum.setFamilyFieldArr(1, arr); arr.reAlloc(35);
5420 self.assertRaises(InterpKernelException, mum.checkConsistency)
5421 mum=mum2; mum2=mum.deepCopy();
5422 arr = DataArrayInt([2]*4)
5423 mum.setRenumFieldArr(1, arr); arr.reAlloc(35);
5424 self.assertRaises(InterpKernelException, mum.checkConsistency)
5425 mum=mum2; mum2=mum.deepCopy();
5426 mum.setRenumFieldArr(1, DataArrayInt([2]*4))
5427 self.assertRaises(InterpKernelException, mum.checkConsistency)
5428 mum=mum2; mum2=mum.deepCopy();
5429 arr = DataArrayAsciiChar(['tutu x']*4)
5430 mum.setNameFieldAtLevel(1, arr); arr.reAlloc(35);
5431 self.assertRaises(InterpKernelException, mum.checkConsistency)
5434 mum=mum2; mum2=mum.deepCopy();
5435 arr = DataArrayInt([2]*2)
5436 mum.setFamilyFieldArr(0, arr); arr.reAlloc(35);
5437 self.assertRaises(InterpKernelException, mum.checkConsistency)
5438 mum=mum2; mum2=mum.deepCopy();
5439 arr = DataArrayInt([2]*2)
5440 mum.setRenumFieldArr(0, arr); arr.reAlloc(35);
5441 self.assertRaises(InterpKernelException, mum.checkConsistency)
5442 mum=mum2; mum2=mum.deepCopy();
5443 mum.setRenumFieldArr(0, DataArrayInt([2]*2))
5444 self.assertRaises(InterpKernelException, mum.checkConsistency)
5445 mum=mum2; mum2=mum.deepCopy();
5446 arr = DataArrayAsciiChar(['tutu x']*2)
5447 mum.setNameFieldAtLevel(0, arr); arr.reAlloc(35);
5448 self.assertRaises(InterpKernelException, mum.checkConsistency)
5451 mum=mum2; mum2=mum.deepCopy();
5452 arr = DataArrayInt([2]*5)
5453 mum.setFamilyFieldArr(-1, arr); arr.reAlloc(35);
5454 self.assertRaises(InterpKernelException, mum.checkConsistency)
5455 mum=mum2; mum2=mum.deepCopy();
5456 arr = DataArrayInt([2]*5)
5457 mum.setRenumFieldArr(-1, arr); arr.reAlloc(35);
5458 self.assertRaises(InterpKernelException, mum.checkConsistency)
5459 mum=mum2; mum2=mum.deepCopy();
5460 mum.setRenumFieldArr(-1, DataArrayInt([2]*5))
5461 self.assertRaises(InterpKernelException, mum.checkConsistency)
5462 mum=mum2; mum2=mum.deepCopy();
5463 arr = DataArrayAsciiChar(['tutu x']*5)
5464 mum.setNameFieldAtLevel(-1, arr); arr.reAlloc(35);
5465 self.assertRaises(InterpKernelException, mum.checkConsistency)
5468 def testCheckSMESHConsistency(self):
5469 m2 = MEDCouplingUMesh("2d", 2)
5470 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5471 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5472 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5473 mum = MEDFileUMesh()
5474 mum.setMeshAtLevel(0, m2)
5475 mum.setMeshAtLevel(-1, m1)
5476 mum.checkConsistency()
5477 mum.checkSMESHConsistency()
5478 n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5479 n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5480 mum.setRenumFieldArr(0, n2)
5481 mum.setRenumFieldArr(-1, n1)
5482 self.assertRaises(InterpKernelException, mum.checkSMESHConsistency)
5483 mum.setRenumFieldArr(-1, n1+100)
5484 mum.checkSMESHConsistency()
5488 def testClearNodeAndCellNumbers(self):
5489 m2 = MEDCouplingUMesh("2d", 2)
5490 m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
5491 m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
5492 m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
5493 mum = MEDFileUMesh()
5494 mum.setMeshAtLevel(0, m2)
5495 mum.setMeshAtLevel(-1, m1)
5496 mum.checkConsistency()
5497 n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
5498 n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
5499 mum.setRenumFieldArr(0, n2)
5500 mum.setRenumFieldArr(-1, n1)
5501 mum.clearNodeAndCellNumbers()
5502 mum.checkSMESHConsistency()
5506 def testCMeshSetFamilyFieldArrNull(self):
5508 fname="Pyfile99.med"
5509 arrX=DataArrayDouble([0,1,2,3])
5510 arrY=DataArrayDouble([0,1,2])
5511 m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m.setName(meshName)
5512 mm=MEDFileCMesh() ; mm.setMesh(m)
5513 famCellIds=DataArrayInt([0,-2,-2,-1,-2,0])
5514 famNodeIds=DataArrayInt([0,0,0,3,4,1,2,7,2,1,0,0])
5515 mm.setFamilyFieldArr(0,famCellIds)
5516 mm.setFamilyFieldArr(1,famNodeIds)
5518 mm=MEDFileMesh.New(fname)
5519 self.assertTrue(mm.getFamilyFieldAtLevel(0) is not None)
5520 self.assertTrue(mm.getFamilyFieldAtLevel(1) is not None)
5521 mm.setFamilyFieldArr(0,None)#<- bug was here
5522 mm.setFamilyFieldArr(1,None)#<- bug was here
5523 self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
5524 self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
5526 self.assertTrue(mm3.getFamilyFieldAtLevel(0) is None)
5527 self.assertTrue(mm3.getFamilyFieldAtLevel(1) is None)
5529 mm2=MEDFileMesh.New(fname)
5530 self.assertTrue(mm2.getFamilyFieldAtLevel(0) is None)
5531 self.assertTrue(mm2.getFamilyFieldAtLevel(1) is None)
5535 def testAppendFieldProfileOnIntField(self):
5536 fname="Pyfile100.med"
5537 arrX=DataArrayDouble([0,1,2,3])
5538 arrY=DataArrayDouble([0,1,2])
5539 mesh=MEDCouplingCMesh() ; mesh.setCoords(arrX,arrY) ; mesh.setName("Mesh")
5543 fmts=MEDFileIntFieldMultiTS()
5545 pfl=DataArrayInt([1,3,5]) ; pfl.setName(pflName)
5546 f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(mesh)
5547 fieldName="FieldOnCell"
5548 f.setTime(1.2,1,1) ; f.setName(fieldName)
5549 arr=DataArrayInt32([101,102,103]) ; f.setArray(arr)
5550 fmts.appendFieldProfile(f,mm,0,pfl)
5555 mm=MEDFileMesh.New(fname)
5556 fmts=MEDFileAnyTypeFieldMultiTS.New(fname)
5557 self.assertTrue(isinstance(fmts,MEDFileIntFieldMultiTS))
5558 self.assertEqual(fmts.getName(),fieldName)
5559 self.assertEqual(len(fmts),1)
5561 ftest,pfltest=f1ts.getFieldWithProfile(ON_CELLS,0,mm)
5562 self.assertEqual(pfltest.getName(),pflName)
5563 self.assertEqual(ftest.getName(),fieldName)
5564 self.assertTrue(ftest.isEqualWithoutConsideringStr(arr))
5565 ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
5566 self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr))
5567 self.assertEqual(ftest2.getTime(),f.getTime())
5568 self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr))
5572 def testMEDFileFieldEasyField1(self):
5573 """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."""
5574 ## Basic test on cells on top level
5575 fname="Pyfile101.med"
5578 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5579 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5581 m.insertNextCell(NORM_TRI3,[0,1,2])
5582 m.insertNextCell(NORM_TRI3,[3,4,5])
5583 m.insertNextCell(NORM_TRI3,[6,7,8])
5584 m.insertNextCell(NORM_TRI3,[9,10,11])
5585 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5586 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5589 arr0=DataArrayDouble([10,11,12,13,100,101])
5590 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5591 f.setName(fieldName) ; f.setTime(2.,6,7)
5593 ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5595 arr2=arr0+1000 ; f.setArray(arr2)
5596 f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f)
5600 mm=MEDFileMesh.New(fname)
5601 f1ts=MEDFileField1TS(fname,fieldName,6,7)
5602 ftst0=f1ts.field(mm)
5603 self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12))
5604 f1ts=MEDFileField1TS(fname,fieldName,8,9)
5605 ftst1=f1ts.field(mm)
5606 self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12))
5607 fmts=MEDFileFieldMultiTS(fname,fieldName)
5608 self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12))
5609 ## Basic test on nodes on top level
5610 f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5611 f2.setName(fieldName)
5613 ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5615 mm=MEDFileMesh.New(fname)
5616 f1ts=MEDFileField1TS(fname,fieldName,23,24)
5617 self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12))
5618 fmts=MEDFileFieldMultiTS(fname,fieldName)
5619 self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12))
5621 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)
5622 f3.setName(fieldName) ; f3.checkConsistencyLight()
5623 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5625 mm=MEDFileMesh.New(fname)
5626 f1ts=MEDFileField1TS(fname,fieldName,2,3)
5627 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5629 f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5630 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])
5631 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)
5632 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)
5633 f4.checkConsistencyLight()
5634 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5636 mm=MEDFileMesh.New(fname)
5637 f1ts=MEDFileField1TS(fname,fieldName,4,5)
5638 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5642 def testMEDFileFieldEasyField2(self):
5643 """Same thantestMEDFileFieldEasyField1 except that here intfields are considered.
5644 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."""
5645 ## Basic test on cells on top level
5646 fname="Pyfile102.med"
5649 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5650 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5652 m.insertNextCell(NORM_TRI3,[0,1,2])
5653 m.insertNextCell(NORM_TRI3,[3,4,5])
5654 m.insertNextCell(NORM_TRI3,[6,7,8])
5655 m.insertNextCell(NORM_TRI3,[9,10,11])
5656 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5657 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5660 arr0=DataArrayInt32([10,11,12,13,100,101])
5661 f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
5662 f.setName(fieldName) ; f.setTime(2.,6,7)
5664 ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
5666 arr2=arr0+1000 ; f.setArray(arr2)
5667 f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f)
5671 mm=MEDFileMesh.New(fname)
5672 f1ts=MEDFileIntField1TS(fname,fieldName,6,7)
5673 ftst0=f1ts.field(mm)
5674 self.assertTrue(f0.isEqual(ftst0,1e-12,0))
5675 f1ts=MEDFileIntField1TS(fname,fieldName,8,9)
5676 ftst1=f1ts.field(mm)
5677 self.assertTrue(f1.isEqual(ftst1,1e-12,0))
5678 fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5679 self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,0))
5680 ## Basic test on nodes on top level
5681 f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt32([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
5682 f2.setName(fieldName)
5684 ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
5686 mm=MEDFileMesh.New(fname)
5687 f1ts=MEDFileIntField1TS(fname,fieldName,23,24)
5688 self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,0))
5689 fmts=MEDFileIntFieldMultiTS(fname,fieldName)
5690 self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,0))
5692 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)
5693 f3.setName(fieldName) ; f3.checkConsistencyLight()
5694 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5696 mm=MEDFileMesh.New(fname)
5697 f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5698 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5700 f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
5701 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])
5702 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)
5703 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)
5704 f4.checkConsistencyLight()
5705 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5707 mm=MEDFileMesh.New(fname)
5708 f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5709 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5713 def testMEDFileFieldEasyField3(self):
5714 """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."""
5715 fname="Pyfile103.med"
5718 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5719 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5721 m.insertNextCell(NORM_TRI3,[0,1,2])
5722 m.insertNextCell(NORM_TRI3,[3,4,5])
5723 m.insertNextCell(NORM_TRI3,[6,7,8])
5724 m.insertNextCell(NORM_TRI3,[9,10,11])
5725 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5726 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5728 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5730 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5731 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5735 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5736 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5738 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2)
5739 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5740 # here f1 lying on level -1 not 0 check if "field" method detect it !
5741 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5742 f1.setMesh(mm[-1]) # -1 is very important
5744 f1.checkConsistencyLight()
5746 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5748 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4)
5749 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
5751 f3=MEDCouplingFieldDouble(ON_GAUSS_NE)
5752 f3.setMesh(mm[-1]) # this line is important
5753 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)
5754 f3.setName(fieldName) ; f3.checkConsistencyLight()
5755 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5757 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3)
5758 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
5760 f4=MEDCouplingFieldDouble(ON_GAUSS_PT)
5761 f4.setMesh(mm[-1]) # this line is important
5762 f4.setName(fieldName)
5763 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])
5764 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)
5765 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)
5766 f4.checkConsistencyLight()
5767 mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5768 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5)
5769 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
5773 def testMEDFileFieldEasyField4(self):
5774 """ Same than testMEDFileFieldEasyField3 but with integers"""
5775 fname="Pyfile104.med"
5778 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5779 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5781 m.insertNextCell(NORM_TRI3,[0,1,2])
5782 m.insertNextCell(NORM_TRI3,[3,4,5])
5783 m.insertNextCell(NORM_TRI3,[6,7,8])
5784 m.insertNextCell(NORM_TRI3,[9,10,11])
5785 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5786 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5788 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5790 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5791 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5795 f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt32([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
5796 f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5798 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2)
5799 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5800 # here f1 lying on level -1 not 0 check if "field" method detect it !
5801 f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt32([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
5802 f1.setMesh(mm[-1]) # -1 is very important
5804 f1.checkConsistencyLight()
5806 f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
5808 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4)
5809 self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
5811 f3=MEDCouplingFieldInt(ON_GAUSS_NE)
5812 f3.setMesh(mm[-1]) # this line is important
5813 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)
5814 f3.setName(fieldName) ; f3.checkConsistencyLight()
5815 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
5817 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
5818 self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
5820 f4=MEDCouplingFieldInt(ON_GAUSS_PT)
5821 f4.setMesh(mm[-1]) # this line is important
5822 f4.setName(fieldName)
5823 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])
5824 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)
5825 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)
5826 f4.checkConsistencyLight()
5827 mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
5828 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
5829 self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
5833 def testMEDFileFieldEasyField5(self):
5834 """More and more difficult now look at how profiles are managed by "field" method."""
5835 fname="Pyfile105.med"
5838 coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
5839 m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
5841 m.insertNextCell(NORM_TRI3,[0,1,2])
5842 m.insertNextCell(NORM_TRI3,[3,4,5])
5843 m.insertNextCell(NORM_TRI3,[6,7,8])
5844 m.insertNextCell(NORM_TRI3,[9,10,11])
5845 m.insertNextCell(NORM_QUAD4,[100,101,102,103])
5846 m.insertNextCell(NORM_QUAD4,[104,105,106,107])
5849 pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl")
5850 m2=m.deepCopy()[pfl] ; m2.setName(m.getName())
5852 arr0=DataArrayDouble([10,11,12,13])
5853 f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2)
5854 f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight()
5855 ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile
5858 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5859 self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5860 # more complicated -> multi level
5861 m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
5863 m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
5864 m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
5866 mm2[0]=m0 ; mm2[-1]=m
5868 ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl)
5870 mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
5871 self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
5875 def testExtractPart1(self):
5876 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)])
5878 m0=MEDCouplingUMesh(meshName,2) ; m0.setCoords(coo) ; m0.allocateCells()
5879 m0.insertNextCell(NORM_TRI3,[8,4,3])
5880 m0.insertNextCell(NORM_TRI3,[8,9,4])
5881 m0.insertNextCell(NORM_TRI3,[7,13,8])
5882 m0.insertNextCell(NORM_TRI3,[7,12,13])
5883 m0.insertNextCell(NORM_TRI3,[0,6,1])
5884 m0.insertNextCell(NORM_TRI3,[0,5,6])
5885 m0.insertNextCell(NORM_QUAD4,[1,6,7,2])
5886 m0.insertNextCell(NORM_QUAD4,[2,7,8,3])
5887 m0.insertNextCell(NORM_QUAD4,[8,13,14,9])
5888 m0.insertNextCell(NORM_QUAD4,[6,11,12,7])
5889 m0.insertNextCell(NORM_QUAD4,[5,10,11,6])
5891 m1=MEDCouplingUMesh(meshName,1) ; m1.setCoords(coo) ; m1.allocateCells()
5892 m1.insertNextCell(NORM_SEG2,[10,5])
5893 m1.insertNextCell(NORM_SEG2,[5,0])
5894 m1.insertNextCell(NORM_SEG2,[0,1])
5895 m1.insertNextCell(NORM_SEG2,[1,2])
5896 m1.insertNextCell(NORM_SEG2,[2,3])
5897 m1.insertNextCell(NORM_SEG2,[3,4])
5898 m1.insertNextCell(NORM_SEG2,[4,9])
5899 m1.insertNextCell(NORM_SEG2,[9,14])
5900 m1.insertNextCell(NORM_SEG2,[14,13])
5901 m1.insertNextCell(NORM_SEG2,[13,12])
5902 m1.insertNextCell(NORM_SEG2,[12,11])
5903 m1.insertNextCell(NORM_SEG2,[11,10])
5905 mm[0]=m0 ; mm[-1]=m1
5906 arr0=DataArrayInt([0,1,2,3,4,6,7,8,12,13])
5908 tab[0]=DataArrayInt([0,2,3,4,6,7])
5909 tab[-1]=DataArrayInt([2,3,4,5,9])
5911 self.assertTrue(mm.deduceNodeSubPartFromCellSubPart(tab).isEqual(arr0))
5915 fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5918 arr0_0=DataArrayDouble([100,101,102,103,104,105,106,107,108,109,110]) ; arr0_0.setInfoOnComponents(ic)
5919 f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*t0) ; f0.setArray(arr0_0)
5920 f0.setMesh(m0) ; f0.setName(fname0)
5921 f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setTime(*t0) ; f1.setArray(DataArrayDouble([200,201,202,203,204,205,206,207,208,209,210,211]))
5922 f1.setMesh(m1) ; f1.setName(fname0) ; f1.getArray().setInfoOnComponents(ic)
5923 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]))
5924 f2.setMesh(m0) ; f2.setName(fname0) ; f2.getArray().setInfoOnComponents(ic)
5925 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.setFieldNoProfileSBT(f2)
5926 fmts.pushBackTimeStep(f1ts)
5928 mmOut=mm.extractPart(tab)
5930 fsPart0=fs.extractPart(tab,mm)
5931 self.assertEqual(len(fsPart0),1)
5933 self.assertEqual(len(fmtsP),1)
5935 self.assertRaises(InterpKernelException,f1ts.field,mmOut)
5937 self.assertTrue(mmOut[0].computeCellCenterOfMass().isEqual(m0[tab[0]].computeCellCenterOfMass(),1e-12))
5938 self.assertTrue(mmOut[-1].computeCellCenterOfMass().isEqual(m1[tab[-1]].computeCellCenterOfMass(),1e-12))
5940 m0Part=m0.deepCopy()[tab[0]] ; m0Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m0Part.setName(m0.getName())
5941 self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5942 m1Part=m1.deepCopy()[tab[-1]] ; m1Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m1Part.setName(m0.getName())
5943 self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
5944 self.assertTrue(mmOut[-1].isEqual(m1Part,1e-12))
5946 f0Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mmOut) ; f0Part.checkConsistencyLight()
5947 self.assertEqual(f0Part.getTypeOfField(),ON_CELLS)
5948 self.assertTrue(f0Part.getMesh().isEqual(m0Part,1e-12))
5949 arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic)
5950 self.assertTrue(f0Part.getArray().isEqual(arr0Exp,1e-12)) ; self.assertEqual(f0Part.getTime(),list(t0))
5951 f1Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,-1,mmOut) ; f1Part.checkConsistencyLight()
5952 self.assertEqual(f1Part.getTypeOfField(),ON_CELLS)
5953 self.assertTrue(f1Part.getMesh().isEqual(m1Part,1e-12))
5954 arr1Exp=DataArrayDouble([202,203,204,205,209]) ; arr1Exp.setInfoOnComponents(ic)
5955 self.assertTrue(f1Part.getArray().isEqual(arr1Exp,1e-12)) ; self.assertEqual(f1Part.getTime(),list(t0))
5957 f2Part=f1ts.getFieldOnMeshAtLevel(ON_NODES,0,mmOut) ; f2Part.checkConsistencyLight()
5958 arr2Exp=DataArrayDouble([300,301,302,303,304,306,307,308,312,313]) ; arr2Exp.setInfoOnComponents(ic)
5959 self.assertTrue(f2Part.getArray().isEqual(arr2Exp,1e-12)) ; self.assertEqual(f2Part.getTime(),list(t0))
5961 fs=MEDFileFields() ; fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
5962 tss=[(16.5,3,4),(17.5,4,5),(18.5,5,6)]
5963 for i,tt in enumerate(tss):
5964 f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*tt)
5965 myarr=arr0_0+i*1000.
5967 f0.setMesh(m0) ; f0.setName(fname0) ; f0.getArray().setInfoOnComponents(ic)
5968 f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; fmts.pushBackTimeStep(f1ts)
5970 fsPart1=fs.extractPart(tab,mm)
5971 self.assertEqual(len(fsPart1),1)
5973 self.assertEqual(len(fmtsP),len(tss))
5974 for i,(f1tsP,tt) in enumerate(zip(fmtsP,tss)):
5975 fPart=f1tsP.field(mmOut) ; fPart.checkConsistencyLight()
5976 self.assertEqual(fPart.getTypeOfField(),ON_CELLS)
5977 arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic) ; arr0Exp+=i*1000.
5978 self.assertTrue(fPart.getMesh().isEqual(m0Part,1e-12))
5979 self.assertTrue(fPart.getArray().isEqual(arr0Exp,1e-12))
5980 self.assertEqual(fPart.getTime(),list(tt))
5985 def testSymmetryPlusAggregationMFD1(self):
5986 """ Testing of MEDFileData::Aggregate and MEDFileUMesh::Aggregate and MEDFileUMesh::getAllDistributionOfType """
5987 fname1="Pyfile106_1.med"
5988 fname2="Pyfile106_2.med"
5989 fname3="Pyfile106_3.med"
5992 da1=DataArrayDouble([1,2,10,3,4,11,5,6,12,7,8,13],4,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
5994 mm1_0=MEDCouplingUMesh(meshName,3) ; mm1_0.allocateCells()
5995 mm1_0.setCoords(da1)
5996 mm1_0.insertNextCell(NORM_TETRA4,[0,1,2,3])
5997 mm1_0.insertNextCell(NORM_TETRA4,[4,5,6,7])
5998 mm1_0.insertNextCell(NORM_PENTA6,[8,9,10,11,12,13])
5999 mm1_0.insertNextCell(NORM_PENTA6,[14,15,16,17,18,19])
6000 mm1_0.insertNextCell(NORM_PENTA6,[20,21,22,23,24,25])
6002 mm1.setFamilyFieldArr(0,DataArrayInt([1,2,3,4,5]))
6003 mm1.setRenumFieldArr(0,DataArrayInt([11,12,13,14,15]))
6005 mm1_1=MEDCouplingUMesh(meshName,2) ; mm1_1.allocateCells()
6006 mm1_1.setCoords(da1)
6007 mm1_1.insertNextCell(NORM_TRI3,[0,1,2])
6008 mm1_1.insertNextCell(NORM_TRI3,[3,4,5])
6009 mm1_1.insertNextCell(NORM_QUAD4,[6,7,8,9])
6010 mm1_1.insertNextCell(NORM_QUAD4,[10,11,12,13])
6011 mm1_1.insertNextCell(NORM_QUAD4,[14,15,16,17])
6012 mm1_1.insertNextCell(NORM_QUAD4,[18,19,20,21])
6014 mm1.setFamilyFieldArr(-1,DataArrayInt([6,7,8,9,10,11]))
6015 mm1.setRenumFieldArr(-1,DataArrayInt([16,17,18,19,20,21]))
6016 for i in range(1,10):
6017 mm1.setFamilyId("F%d"%i,i)
6018 mm1.setFamilyId("FAMILLE_ZERO",0)
6019 mm1.setFamilyId("H1",100)
6020 mm1.setFamiliesOnGroup("myGRP",["F2","F6"])
6021 mm1.setFamiliesOnGroup("myGRP1",["F2","F6"])
6022 mm1.setFamilyFieldArr(1,DataArrayInt([12,13,14,15]))
6023 mm1.setRenumFieldArr(1,DataArrayInt([22,23,24,25]))
6026 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]"])
6028 mm2_0=MEDCouplingUMesh(meshName,3) ; mm2_0.allocateCells()
6029 mm2_0.setCoords(da1)
6030 mm2_0.insertNextCell(NORM_TETRA4,[100,101,102,103])
6031 mm2_0.insertNextCell(NORM_TETRA4,[104,105,106,107])
6032 mm2_0.insertNextCell(NORM_TETRA4,[108,109,110,111])
6033 mm2_0.insertNextCell(NORM_PENTA6,[112,113,114,115,116,117])
6035 mm2.setFamilyFieldArr(0,DataArrayInt([40,41,42,43]))
6036 mm2.setRenumFieldArr(0,DataArrayInt([50,51,52,53]))
6038 mm2_1=MEDCouplingUMesh(meshName,2) ; mm2_1.allocateCells()
6039 mm2_1.setCoords(da1)
6040 mm2_1.insertNextCell(NORM_TRI3,[100,101,102])
6041 mm2_1.insertNextCell(NORM_TRI3,[103,104,105])
6042 mm2_1.insertNextCell(NORM_TRI3,[106,107,108])
6043 mm2_1.insertNextCell(NORM_QUAD4,[109,110,111,112])
6044 mm2_1.insertNextCell(NORM_QUAD4,[113,114,115,116])
6045 mm2_1.insertNextCell(NORM_QUAD4,[117,118,119,120])
6046 mm2_1.insertNextCell(NORM_QUAD4,[121,122,123,124])
6047 mm2_1.insertNextCell(NORM_QUAD4,[125,126,127,128])
6049 mm2.setFamilyFieldArr(-1,DataArrayInt([200,201,202,203,204,205,206,207]))
6050 mm2.setRenumFieldArr(-1,DataArrayInt([300,301,302,303,304,305,306,307]))
6051 for i in range(1,12):
6052 mm2.setFamilyId("G%d"%i,i+30)
6053 mm2.setFamilyId("H1",100)
6054 mm2.setFamilyId("FAMILLE_ZERO",0)
6055 mm2.setFamiliesOnGroup("myGRP",["G2","G6"])
6056 mm2.setFamiliesOnGroup("myGRP2",["G4","G7"])
6057 mm2.setFamilyFieldArr(1,DataArrayInt([112,113,114,115,116]))
6058 mm2.setRenumFieldArr(1,DataArrayInt([122,123,124,125,126]))
6060 mm=MEDFileUMesh.Aggregate([mm1,mm2])
6062 def CheckMesh(tester,mm):
6063 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]"])
6064 tester.assertTrue(mm.getCoords().isEqual(cooExp,1e-12))
6065 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])))
6066 tester.assertTrue(mm[0].getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,32,39,46,53])))
6067 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])))
6068 tester.assertTrue(mm[-1].getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20,25,30,35,40,45,50,55,60,65])))
6069 tester.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([1,2,40,41,42,3,4,5,43])))
6070 tester.assertTrue(mm.getNumberFieldAtLevel(0).isEqual(DataArrayInt([11,12,50,51,52,13,14,15,53])))
6071 tester.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(DataArrayInt([6,7,200,201,202,8,9,10,11,203,204,205,206,207])))
6072 tester.assertTrue(mm.getNumberFieldAtLevel(-1).isEqual(DataArrayInt([16,17,300,301,302,18,19,20,21,303,304,305,306,307])))
6073 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)]
6074 tester.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
6075 tester.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
6076 tester.assertEqual(mm.getGroupsNames(),('myGRP','myGRP1','myGRP2'))
6077 tester.assertEqual(mm.getAllDistributionOfTypes(),[(NORM_TRI3,5),(NORM_QUAD4,9),(NORM_TETRA4,5),(NORM_PENTA6,4),(NORM_ERROR,9)])
6084 infoc=["dd [W]","eee [kA]"]
6086 fmts1=MEDFileFieldMultiTS()
6087 f1ts1=MEDFileField1TS()
6088 f1_1=MEDCouplingFieldDouble(ON_CELLS) ; f1_1.setMesh(mm1[0]) ; f1_1.setName(fieldName)
6089 arr1=DataArrayDouble([(10,110),(11,111),(12,112),(13,113),(14,114)])
6090 arr1.setInfoOnComponents(infoc)
6091 f1_1.setArray(arr1) ; f1_1.setTime(*t1) ; f1_1.setTimeUnit("ms")
6092 f1_1.checkConsistencyLight()
6093 f1ts1.setFieldNoProfileSBT(f1_1)
6095 f1_2=MEDCouplingFieldDouble(ON_CELLS) ; f1_2.setMesh(mm1[-1]) ; f1_2.setName(fieldName)
6096 arr2=DataArrayDouble([(15,115),(16,116),(17,117),(18,118),(19,119),(20,120)])
6097 arr2.setInfoOnComponents(infoc)
6098 f1_2.setArray(arr2) ; f1_2.setTime(*t1) ; f1_2.setTimeUnit("ms")
6099 f1_2.checkConsistencyLight()
6100 f1ts1.setFieldNoProfileSBT(f1_2)
6101 f1_3=MEDCouplingFieldDouble(ON_NODES) ; f1_3.setMesh(mm1[0]) ; f1_3.setName(fieldName)
6102 arr3=DataArrayDouble([(21,121),(22,122),(23,123),(24,124)])
6103 arr3.setInfoOnComponents(infoc)
6104 f1_3.setArray(arr3) ; f1_3.setTime(*t1) ; f1_3.setTimeUnit("ms")
6105 f1_3.checkConsistencyLight()
6106 f1ts1.setFieldNoProfileSBT(f1_3)
6107 fmts1.pushBackTimeStep(f1ts1)
6109 f1ts2=f1ts1.deepCopy()
6110 f1ts2.setTime(t2[1],t2[2],t2[0])
6111 f1ts2.getUndergroundDataArray()[:]+=2000
6112 fmts1.pushBackTimeStep(f1ts2)
6114 fmts2=MEDFileFieldMultiTS()
6115 f1ts3=MEDFileField1TS()
6116 f2_1=MEDCouplingFieldDouble(ON_CELLS) ; f2_1.setMesh(mm2[0]) ; f2_1.setName(fieldName)
6117 arr4=DataArrayDouble([(50,150),(51,151),(52,152),(53,153)])
6118 arr4.setInfoOnComponents(infoc)
6119 f2_1.setArray(arr4) ; f2_1.setTime(*t1) ; f2_1.setTimeUnit("ms")
6120 f2_1.checkConsistencyLight()
6121 f1ts3.setFieldNoProfileSBT(f2_1)
6122 f2_2=MEDCouplingFieldDouble(ON_CELLS) ; f2_2.setMesh(mm2[-1]) ; f2_2.setName(fieldName)
6123 arr5=DataArrayDouble([(54,154),(55,155),(56,156),(57,157),(158,158),(59,159),(60,160),(61,161)])
6124 arr5.setInfoOnComponents(infoc)
6125 f2_2.setArray(arr5) ; f2_2.setTime(*t1) ; f2_2.setTimeUnit("ms")
6126 f2_2.checkConsistencyLight()
6127 f1ts3.setFieldNoProfileSBT(f2_2)
6128 f2_3=MEDCouplingFieldDouble(ON_NODES) ; f2_3.setMesh(mm2[0]) ; f2_3.setName(fieldName)
6129 arr6=DataArrayDouble([(62,162),(63,163),(64,164),(65,165),(66,166)])
6130 arr6.setInfoOnComponents(infoc)
6131 f2_3.setArray(arr6) ; f2_3.setTime(*t1) ; f2_3.setTimeUnit("ms")
6132 f2_3.checkConsistencyLight()
6133 f1ts3.setFieldNoProfileSBT(f2_3)
6134 fmts2.pushBackTimeStep(f1ts3)
6136 f1ts4=f1ts3.deepCopy()
6137 f1ts4.setTime(t2[1],t2[2],t2[0])
6138 f1ts4.getUndergroundDataArray()[:]+=2000
6139 fmts2.pushBackTimeStep(f1ts4)
6142 mfd1.setMeshes(MEDFileMeshes())
6143 mfd1.getMeshes().pushMesh(mm1)
6144 mfd1.setFields(MEDFileFields())
6145 mfd1.getFields().pushField(fmts1)
6148 mfd2.setMeshes(MEDFileMeshes())
6149 mfd2.getMeshes().pushMesh(mm2)
6150 mfd2.setFields(MEDFileFields())
6151 mfd2.getFields().pushField(fmts2)
6153 mfd=MEDFileData.Aggregate([mfd1,mfd2])
6154 def CheckMFD(tester,mfd):
6155 tester.assertEqual(len(mfd.getMeshes()),1)
6156 tester.assertEqual(len(mfd.getFields()),1)
6157 CheckMesh(self,mfd.getMeshes()[0])
6158 tester.assertEqual(len(mfd.getFields()[0]),2)
6159 zeF1=mfd.getFields()[0][0]
6160 zeF1_1=zeF1.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
6161 ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
6162 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
6163 ref.renumberCells(o2n)
6164 tester.assertTrue(ref.isEqual(zeF1_1,1e-12,1e-12))
6165 zeF1_2=zeF1.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
6166 ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
6167 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
6168 ref.renumberCells(o2n)
6169 tester.assertTrue(ref.isEqual(zeF1_2,1e-12,1e-12))
6170 zeF1_3=zeF1.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
6171 ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
6172 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
6173 ref.renumberCells(o2n)
6174 tester.assertTrue(ref.isEqual(zeF1_3,1e-12,1e-12))
6176 zeF2=mfd.getFields()[0][1]
6177 zeF2_1=zeF2.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
6178 ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
6179 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
6180 ref.renumberCells(o2n)
6181 ref.setTime(*t2) ; ref.getArray()[:]+=2000
6182 tester.assertTrue(ref.isEqual(zeF2_1,1e-12,1e-12))
6183 zeF2_2=zeF2.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
6184 ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
6185 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
6186 ref.renumberCells(o2n)
6187 ref.setTime(*t2) ; ref.getArray()[:]+=2000
6188 tester.assertTrue(ref.isEqual(zeF2_2,1e-12,1e-12))
6189 zeF2_3=zeF2.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
6190 ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
6191 o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
6192 ref.renumberCells(o2n)
6193 ref.setTime(*t2) ; ref.getArray()[:]+=2000
6194 tester.assertTrue(ref.isEqual(zeF2_3,1e-12,1e-12))
6196 mfd1.write(fname1,2) ; mfd2.write(fname2,2)
6197 mfd=MEDFileData.Aggregate([MEDFileData(fname1),MEDFileData(fname2)])
6202 def testAggregateWithGroups(self):
6203 """ Testing MEDFileUMesh::Aggretate when groups are present. """
6204 def generate(fam, fam_dict, grps, y_offset):
6205 """ Generate a 2x3 cartesian grid, with family IDs fam, family names given by the dict,
6206 and group given by grps
6208 m = MEDCouplingCMesh("toto")
6209 coo_x = DataArrayDouble([0., 1., 2.])
6210 coo_y = DataArrayDouble([0., 1., 2., 3.])
6212 m.setCoords(coo_x, coo_y)
6213 m = m.buildUnstructured()
6214 mu = MEDFileUMesh.New()
6215 mu.setMeshAtLevel(0, m)
6216 for f_nam, i in fam_dict.items():
6217 mu.setFamilyId(f_nam, i)
6218 mu.setFamilyFieldArr(0, DataArrayInt(fam))
6219 for g_nam, f_ids in grps.items():
6220 mu.setFamiliesIdsOnGroup(g_nam, f_ids)
6223 # Two meshes where either family names or family IDs will be conflicting:
6224 m1 = generate([-4,-4,-3,-1,-1,-2], {"Fam_-1": -1, "Fam_-2": -2, "Fam_-3": -3, "Fam_-4": -4 }, {"G1": [-1,-2], "G2": [-2]} ,0)
6225 m2 = generate([-4,-4,-4,-1,-1,-3], {"Woops_-1": -1, "Fam_-2": -3, "Fam_-4": -4}, {"G1": [-1,-3], "G2": [-3]} , -3)
6227 mm = MEDFileUMesh.Aggregate([m1,m2])
6229 self.assertEqual(mm.getFamilyFieldAtLevel(0).getValues(),[-4, -4, -3, -1, -1, -2, -4, -4, -4, -6, -6, -5])
6230 self.assertEqual(mm.getNumberFieldAtLevel(0), None)
6231 refFamIds=[('Fam_-1',-1),('Fam_-2',-2),('Fam_-3',-3), ('Fam_-4',-4), ('Family_-5',-5), ('Family_-6',-6)]
6232 self.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
6233 self.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
6234 self.assertEqual(mm.getGroupsNames(),('G1','G2'))
6235 self.assertEqual(mm.getGroupArr(0, 'G1').getValues(), [3,4,5,9,10,11])
6236 self.assertEqual(mm.getGroupArr(0, 'G2').getValues(), [5, 11])
6240 def testExtrudedMesh1(self):
6241 fname="Pyfile107.med"
6242 arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5])
6243 mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ) ; mesh3D.setName("mesh")
6244 ex=MEDCouplingMappedExtrudedMesh(mesh3D)
6247 ex2=mm.convertToExtrudedMesh()
6248 mm2=MEDFileMesh.New(fname)
6249 ex3=mm2.convertToExtrudedMesh()
6250 self.assertTrue(ex.isEqual(ex2,1e-12))
6251 self.assertTrue(ex.isEqual(ex3,1e-12))
6254 @unittest.skipUnless(LooseVersion(MEDFileVersionStr())>=LooseVersion('3.2.1'),"This test requires at least MEDFile version 3.2.1")
6256 def testWriteInto30(self):
6257 fname="Pyfile108.med"
6258 fname2="Pyfile109.med"
6259 m=MEDCouplingUMesh("mesh",1) ; m.setCoords(DataArrayDouble([0,0,1,1],2,2)) ; m.allocateCells() ; m.insertNextCell(NORM_SEG2,[1,0])
6260 mm=MEDFileUMesh() ; mm[0]=m
6261 mm.setFamilyId("FAMILLE_ZERO",0)
6264 assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==[3,3]) # checks that just written MED file has a version == 3.0.x
6265 mm2=MEDFileUMesh(fname)
6266 self.assertTrue(mm.isEqual(mm2,1e-12))
6269 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
6272 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
6274 def testPickelizationOfMEDFileObjects1(self):
6275 fname="Pyfile110.med"
6276 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)
6277 m0=MEDCouplingUMesh("Mesh",2)
6279 m0.insertNextCell(NORM_TRI3,[1,4,2])
6280 m0.insertNextCell(NORM_TRI3,[4,5,2])
6281 m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
6282 m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
6283 m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
6284 m0.finishInsertingCells()
6286 m1=MEDCouplingUMesh(m0.getName(),1)
6288 conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
6290 m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
6292 m1.finishInsertingCells()
6296 m.setMeshAtLevel(0,m0)
6297 m.setMeshAtLevel(-1,m1)
6299 dt=3 ; it=2 ; tim=4.5
6300 fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
6301 fieldNode0.setName("fieldNode0")
6302 fieldNode0.setTime(tim,dt,it)
6303 pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
6304 arr=DataArrayDouble([10,11,12,13,14])
6305 fieldNode0.setArray(arr)
6306 f0=MEDFileField1TS()
6307 f0.setFieldProfile(fieldNode0,m,0,pfl0)
6308 fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
6309 fieldNode1.setName("fieldNode1")
6310 fieldNode1.setTime(tim,dt,it)
6311 pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
6312 arr1=DataArrayDouble([20,21,22,23,24,25,26])
6313 fieldNode1.setArray(arr1)
6314 f1=MEDFileField1TS()
6315 f1.setFieldProfile(fieldNode1,m,-1,pfl1)
6317 mfd.setMeshes(MEDFileMeshes()) ; mfd.setFields(MEDFileFields())
6318 mfd.getMeshes().pushMesh(m)
6319 fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(f0)
6320 mfd.getFields().pushField(fmts)
6321 # first start gently
6324 self.assertEqual(len(mfd2.getMeshes()),1)
6325 self.assertEqual(len(mfd2.getFields()),1)
6326 self.assertEqual(len(mfd2.getFields()[0]),1)
6327 self.assertTrue(mfd2.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
6328 ff2=mfd2.getFields()[0][0].field(mfd2.getMeshes()[0])
6329 ff =mfd.getFields()[0][0].field(mfd.getMeshes()[0])
6330 self.assertTrue(ff2.isEqual(ff,1e-12,1e-12))
6331 # OK now end of joke -> serialization of MEDFileData
6332 st=pickle.dumps(mfd,pickle.HIGHEST_PROTOCOL)
6333 mfd3=pickle.loads(st)
6335 self.assertEqual(len(mfd3.getMeshes()),1)
6336 self.assertEqual(len(mfd3.getFields()),1)
6337 self.assertEqual(len(mfd3.getFields()[0]),1)
6338 self.assertTrue(mfd3.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
6339 ff3=mfd3.getFields()[0][0].field(mfd3.getMeshes()[0])
6340 self.assertTrue(ff3.isEqual(ff,1e-12,1e-12))
6341 # serialization of MEDFileFields
6342 st=pickle.dumps(mfd.getFields(),pickle.HIGHEST_PROTOCOL)
6343 fs4=pickle.loads(st)
6344 ff4=fs4[0][0].field(mfd3.getMeshes()[0])
6345 self.assertTrue(ff4.isEqual(ff,1e-12,1e-12))
6346 # serialization of MEDFileFieldMulitTS
6347 st=pickle.dumps(mfd.getFields()[0],pickle.HIGHEST_PROTOCOL)
6348 fmts5=pickle.loads(st)
6349 ff5=fmts5[0].field(mfd3.getMeshes()[0])
6350 self.assertTrue(ff5.isEqual(ff,1e-12,1e-12))
6351 # serialization of MEDFileField1TS
6352 st=pickle.dumps(mfd.getFields()[0][0],pickle.HIGHEST_PROTOCOL)
6353 f1ts6=pickle.loads(st)
6354 ff6=f1ts6.field(mfd3.getMeshes()[0])
6355 self.assertTrue(ff6.isEqual(ff,1e-12,1e-12))
6356 # serialization of MEDFileMeshes
6357 st=pickle.dumps(mfd.getMeshes(),pickle.HIGHEST_PROTOCOL)
6358 ms7=pickle.loads(st)
6359 self.assertEqual(len(ms7),1)
6360 self.assertTrue(ms7[0].isEqual(mfd.getMeshes()[0],1e-12))
6363 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
6365 def testPickelizationOfMEDFileObjects2(self):
6367 self.internalMEDMesh6() # generates MEDFileMesh5.med file
6368 mm=MEDFileMesh.New("MEDFileMesh5.med")
6369 self.assertTrue(isinstance(mm,MEDFileCMesh))
6370 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
6371 mm2=pickle.loads(st)
6372 self.assertTrue(isinstance(mm2,MEDFileCMesh))
6373 self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12))
6375 self.internalCurveLinearMesh1() # generates Pyfile55.med
6376 mm=MEDFileMesh.New("Pyfile55.med")
6377 self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh))
6378 st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
6379 mm3=pickle.loads(st)
6380 self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh))
6381 self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12))
6382 self.internalInt32InMEDFileFieldStar1()# generates Pyfile63.med
6383 # MEDFileIntFieldMultiTS
6384 fs4=MEDFileFields("Pyfile63.med")
6385 ms4=MEDFileMeshes("Pyfile63.med")
6386 self.assertTrue(isinstance(fs4[0],MEDFileIntFieldMultiTS))
6387 st=pickle.dumps(fs4[0],pickle.HIGHEST_PROTOCOL)
6388 fmts5=pickle.loads(st)
6389 self.assertEqual(len(fs4[0]),len(fmts5))
6390 self.assertTrue(isinstance(fmts5,MEDFileIntFieldMultiTS))
6391 self.assertTrue(fmts5[0].field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
6392 # MEDFileIntField1TS
6393 st=pickle.dumps(fs4[0][0],pickle.HIGHEST_PROTOCOL)
6394 f1ts6=pickle.loads(st)
6395 self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS))
6396 self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
6398 self.internalParameters1()# generates Pyfile56.med
6399 params=MEDFileParameters("Pyfile56.med")
6400 st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL)
6401 params7=pickle.loads(st)
6402 self.assertEqual(len(params),len(params7))
6403 for i in range(len(params)):
6404 self.assertTrue(params[i].isEqual(params7[i],1e-12)[0])
6409 def testGlobalNumOnNodes1(self):
6410 """Test global number on nodes here. Used by partitionners."""
6411 fname="Pyfile112.med"
6412 arr=DataArrayDouble(5) ; arr.iota()
6413 m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
6417 self.assertTrue(not mm.getGlobalNumFieldAtLevel(1))
6418 d=DataArrayInt([7,8,9,2,0])
6420 mm.setGlobalNumFieldAtLevel(1,d)
6421 mm.checkConsistency()
6422 self.assertRaises(InterpKernelException,mm.setGlobalNumFieldAtLevel,1,d[::2])
6423 mm.checkConsistency()
6424 self.assertEqual(d.getHiddenCppPointer(),mm.getGlobalNumFieldAtLevel(1).getHiddenCppPointer())
6425 self.assertTrue(mm.getGlobalNumFieldAtLevel(1).isEqual(dRef))
6427 mm2=MEDFileMesh.New(fname)
6428 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
6429 self.assertTrue(mm2.getGlobalNumFieldAtLevel(1).isEqual(dRef))
6430 mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,10)
6431 self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
6432 mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,7)
6433 self.assertTrue(mm.isEqual(mm2,1e-12)[0])
6437 def testPartialReadOfEntities1(self):
6438 """Test for advanced API on read to speed up read phase for users with "huge" number of time steps (more than 10 000)."""
6439 fname="Pyfile113.med"
6440 arr=DataArrayDouble(5) ; arr.iota()
6441 m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
6448 f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m) ; f1.setName(fieldName)
6449 f1.setArray(DataArrayDouble([0.,0.1,0.2,0.3,0.4]))
6451 f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m) ; f2.setName(fieldName)
6452 f2.setArray(DataArrayDouble([1.,1.1,1.2,1.3]))
6454 f1ts=MEDFileField1TS()
6455 f1ts.setFieldNoProfileSBT(f1)
6456 f1ts.setFieldNoProfileSBT(f2)
6457 self.assertEqual(set(f1ts.getTypesOfFieldAvailable()),set([ON_NODES,ON_CELLS]))
6458 f1ts_2=f1ts.deepCopy()
6459 f1ts_2.getUndergroundDataArray()[:]+=2
6460 f1ts_2.setTime(3,4,6.)
6461 fmts=MEDFileFieldMultiTS()
6462 fmts.pushBackTimeStep(f1ts)
6463 fmts.pushBackTimeStep(f1ts_2)
6468 ent=MEDFileEntities.BuildFrom([(ON_NODES,NORM_ERROR)])
6469 mm=MEDFileMesh.New(fname)
6470 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)
6472 self.assertEqual(len(fs),1)
6474 self.assertEqual(len(fmts),2)
6475 ff0=fmts[0] ; ff1=fmts[1]
6476 self.assertEqual(ff0.getTypesOfFieldAvailable(),[ON_NODES]) # only NODES have been loaded
6477 self.assertTrue(ff0.field(mm).isEqual(f1,1e-12,1e-12))
6478 f3=f1.deepCopy() ; f3+=2. ; f3.setTime(6.,3,4)
6479 self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
6483 def testFloat32InMEDFileFieldStar1(self):
6484 """Like testInt32InMEDFileFieldStar1 but with float32 :)"""
6485 fname="Pyfile114.med"
6486 f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
6487 f1=f1.convertToFloatField()
6489 mm1=MEDFileUMesh.New()
6490 mm1.setCoords(m1.getCoords())
6491 mm1.setMeshAtLevel(0,m1)
6492 mm1.setName(m1.getName())
6494 ff1=MEDFileFloatField1TS()
6495 ff1.setFieldNoProfileSBT(f1)
6496 a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6497 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6498 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6500 a,b=ff1.getUndergroundDataArrayExt()
6501 self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
6502 self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
6503 ff2=MEDFileAnyTypeField1TS.New(fname)
6504 self.assertEqual(ff2.getName(),"VectorFieldOnCells")
6505 self.assertEqual(ff2.getTime(),[0,1,2.0])
6506 self.assertTrue(isinstance(ff2,MEDFileFloatField1TS))
6507 a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6508 self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6509 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6511 c=ff2.getUndergroundDataArray() ; c*=2
6512 ff2.write(fname,0) # 2 time steps in
6513 ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
6514 self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
6515 self.assertEqual(len(ffs1),2)
6516 self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS))
6517 a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6518 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6519 a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
6520 self.assertTrue(a.isEqual(f1,1e-12,1e-12))
6521 it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
6522 a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
6523 self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7))
6524 f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
6525 self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2
6526 bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
6528 a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
6531 self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7))
6532 nf1=MEDCouplingFieldFloat(ON_NODES)
6533 nf1.setTime(9.,10,-1)
6534 nf1.setMesh(f1.getMesh())
6535 narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
6536 nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
6537 nff1=MEDFileFloatField1TS.New()
6538 nff1.setFieldNoProfileSBT(nf1)
6539 self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
6540 self.assertEqual(nff1.getTime(),[10,-1,9.0])
6543 nf2=MEDCouplingFieldFloat(ON_NODES)
6544 nf2.setTime(19.,20,-11)
6545 nf2.setMesh(f1.getMesh())
6546 narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
6547 nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
6548 nff2=MEDFileFloatField1TS.New()
6549 npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
6550 nff2.setFieldProfile(nf2,mm1,0,npfl)
6551 nff2.getFieldWithProfile(ON_NODES,0,mm1)
6552 a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6553 self.assertTrue(b.isEqual(npfl))
6554 self.assertTrue(a.isEqual(narr2,1e-7))
6556 nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl")
6557 a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
6558 self.assertTrue(b.isEqual(npfl))
6559 self.assertTrue(a.isEqual(narr2,1e-7))
6561 nf3=MEDCouplingFieldDouble(ON_NODES)
6562 nf3.setName("VectorFieldOnNodesDouble")
6563 nf3.setTime(29.,30,-21)
6564 nf3.setMesh(f1.getMesh())
6565 nf3.setArray(f1.getMesh().getCoords())
6566 nff3=MEDFileField1TS.New()
6567 nff3.setFieldNoProfileSBT(nf3)
6569 fs=MEDFileFields(fname)
6570 self.assertEqual(len(fs),4)
6571 ffs=[it for it in fs]
6572 self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS))
6573 self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS))
6574 self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
6575 self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS))
6577 self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7))
6578 self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7))
6579 self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7))
6580 self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7))
6581 self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6583 nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
6584 self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
6585 self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
6586 self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
6587 MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
6588 self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
6589 MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1)
6590 self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
6592 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
6593 self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6594 self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
6595 self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
6599 def testPenta18_1(self):
6600 """EDF8478 : Test of read/write of penta18"""
6601 fname="Pyfile115.med"
6602 arr=DataArrayDouble([
6603 (0.,1.,1.),(0.,0.,1.),(1.,0.,1.),
6604 (0.,1.,0.),(0.,0.,0.),(1.,0.,0.),
6605 (0.,0.5,1.),(0.5,0.,1.),(0.5,0.5,1.),
6606 (0.,0.5,0.),(0.5,0.,0.),(0.5,0.5,0.),
6607 (0.,1.,0.5),(0.,0.,0.5),(1.,0.,0.5),
6608 (0.,0.5,0.5),(0.5,0.,0.5),(0.5,0.5,0.5)])
6609 m=MEDCouplingUMesh("mesh",3)
6612 m.insertNextCell(NORM_PENTA18,list(range(18)))
6613 m.checkConsistencyLight()
6615 f=MEDCouplingFieldDouble(ON_NODES)
6617 f.setName("FieldOnPenta18")
6618 f.setArray(DataArrayDouble(list(range(18))))
6619 f.checkConsistencyLight()
6621 m2,d,di,rd,rdi=m.buildDescendingConnectivity()
6623 f2=MEDCouplingFieldDouble(ON_NODES)
6625 f2.setName("FieldOnPenta18Sub")
6626 f2.setArray(DataArrayDouble(list(range(18))))
6627 f2.checkConsistencyLight()
6628 WriteField(fname,f2,True)
6630 self.assertTrue(f2.isEqual(f3,1e-12,1e-12))
6631 self.assertEqual(f3.getMesh().getNumberOfCells(),1)
6632 self.assertEqual(f3.getMesh().getTypeOfCell(0),NORM_PENTA18)
6636 def testFieldsLinearToQuadratic(self):
6637 fname="Pyfile117.med"
6638 arr=DataArrayDouble([0,1])
6639 m=MEDCouplingCMesh();
6640 m.setCoords(arr,arr,arr)
6641 m=m.buildUnstructured()
6643 m2.translate([2,0,0])
6644 m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6648 mmq=mm.linearToQuadratic(0)
6649 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6650 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6652 f=MEDCouplingFieldDouble(ON_NODES)
6656 arr=DataArrayDouble(m3.getNumberOfNodes())
6659 f1ts=MEDFileField1TS()
6660 f1ts.setFieldNoProfileSBT(f)
6661 fmts=MEDFileFieldMultiTS()
6662 fmts.pushBackTimeStep(f1ts)
6663 f1ts_2=f1ts.deepCopy()
6664 f1ts_2.setTime(3,4,5.)
6665 f1ts_2.getUndergroundDataArray()[:]*=2.
6666 fmts.pushBackTimeStep(f1ts_2)
6669 fs2=fs.linearToQuadratic(mms,mmsq)
6670 self.myTester1(fs2,mmsq[0])
6671 # A small Write/Read and test again
6672 mms.write(fname,2) ; fs.write(fname,0)
6673 mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6674 mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6675 fs2=fs.linearToQuadratic(mms,mmqs)
6676 self.myTester1(fs2,mmqs[0])
6679 def myTester1(self,fs2,mmq):
6680 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)
6681 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])
6682 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])
6683 fToTest=fs2[0][0].field(mmq)
6684 self.assertEqual(fToTest.getTime(),[3.,1,2])
6685 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6686 self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6687 self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6688 self.assertTrue(fToTest.getArray().isEqual(dataExp2,1e-12))
6689 # testing 2nd timestep
6690 fToTest=fs2[0][1].field(mmq)
6691 self.assertEqual(fToTest.getTime(),[5.,3,4])
6692 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6693 self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
6694 self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
6695 self.assertTrue(fToTest.getArray().isEqual(2*dataExp2,1e-12))
6699 def testFieldsLinearToQuadratic2(self):
6700 """Same than testFieldsLinearToQuadratic but with profile on NODES"""
6701 GeneratePyfile18(self)
6702 fname="Pyfile118.med"
6703 arr=DataArrayDouble([0,1])
6704 m=MEDCouplingCMesh();
6705 m.setCoords(arr,arr,arr)
6706 m=m.buildUnstructured()
6708 m2.translate([2,0,0])
6709 m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
6711 # add a point for fun
6712 m3.setCoords(DataArrayDouble.Aggregate(m3.getCoords(),DataArrayDouble([1.5,1.5,1.5],1,3)))
6716 mmq=mm.linearToQuadratic(0)
6717 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6718 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6720 f=MEDCouplingFieldDouble(ON_NODES)
6724 arr=DataArrayDouble(8) ; arr.iota()
6727 f1ts=MEDFileField1TS()
6728 pfl=DataArrayInt([8,9,10,11,12,13,14,15]) ; pfl.setName("pfl")
6729 f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 8 nodes of cell #1
6730 f1ts_2=f1ts.deepCopy()
6731 f1ts_2.setTime(3,4,5.)
6732 f1ts_2.getUndergroundDataArray()[:]*=4.
6733 fmts=MEDFileFieldMultiTS()
6734 fmts.pushBackTimeStep(f1ts)
6735 fmts.pushBackTimeStep(f1ts_2)
6738 fs2=fs.linearToQuadratic(mms,mmsq)
6739 mms.write(fname,2) ; fs.write(fname,0)
6741 self.myTester2(fs2,mmq)
6743 mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
6744 mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
6745 fs2=fs.linearToQuadratic(mms,mmqs)
6746 self.myTester2(fs2,mmq)
6747 ## More vicious add single node 16
6750 mmq=mm.linearToQuadratic(0)
6751 mms=MEDFileMeshes() ; mms.pushMesh(mm)
6752 mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
6754 f=MEDCouplingFieldDouble(ON_NODES)
6758 arr=DataArrayDouble(9) ; arr.iota()
6761 f1ts=MEDFileField1TS()
6762 pfl=DataArrayInt([8,9,10,11,12,13,14,15,16]) ; pfl.setName("pfl")
6763 f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 9 nodes of cell #1 + orphan node
6764 fmts=MEDFileFieldMultiTS()
6765 fmts.pushBackTimeStep(f1ts)
6768 fs2=fs.linearToQuadratic(mms,mmsq)
6770 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")
6771 f1tsToTest=fs2[0][0]
6772 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])
6773 assert(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6774 assert(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6775 assert(f1tsToTest.getFieldSplitedByType()==[(40,[(1,(0,21),'pfl_NODE','')])])
6778 def myTester2(self,fs2,mmq):
6779 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")
6780 f1tsToTest=fs2[0][0]
6781 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])
6782 self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6783 self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
6784 self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6785 fToTest=fs2[0][0].field(mmq)
6786 self.assertEqual(fToTest.getTime(),[3.,1,2])
6787 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6788 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])))
6789 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))
6790 self.assertTrue(fToTest.getArray().isEqual(exp1,1e-12))
6792 f1tsToTest=fs2[0][1]
6793 self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
6794 self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(4*exp1,1e-12))
6795 self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
6796 fToTest=fs2[0][1].field(mmq)
6797 self.assertEqual(fToTest.getTime(),[5.,3,4])
6798 mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
6799 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])))
6800 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))
6801 self.assertTrue(fToTest.getArray().isEqual(4*exp1,1e-12))
6806 def testSetFieldProfileFlatly1(self):
6807 """ 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
6809 arr=DataArrayDouble(10) ; arr.iota()
6810 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
6811 m=m.buildUnstructured()
6814 m=MEDCouplingUMesh.MergeUMeshes(m2,m)
6818 f=MEDCouplingFieldDouble(ON_CELLS)
6820 arr=DataArrayDouble(m.getNumberOfCells())
6824 pfl=DataArrayInt(m.getNumberOfCells()) ; pfl.iota() ; pfl.setName("pfl")
6826 refSp=[(3,[(0,(0,162),'','')]),(4,[(0,(162,243),'','')])]
6827 refSp1=[(3,[(0,(0,162),'pfl_NORM_TRI3','')]),(4,[(0,(162,243),'pfl_NORM_QUAD4','')])]
6829 f1ts=MEDFileField1TS()
6830 f1ts.setFieldProfile(f,mm,0,pfl)
6831 self.assertEqual(f1ts.getPfls(),()) # here setFieldProfile has detected useless pfl -> no pfl
6832 self.assertEqual(f1ts.getFieldSplitedByType(),refSp)
6833 self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
6835 f1ts=MEDFileField1TS()
6836 f1ts.setFieldProfileFlatly(f,mm,0,pfl) # no optimization attempt. Create pfl unconditionally
6837 self.assertEqual(f1ts.getPfls(),("%s_NORM_TRI3"%pfl.getName(),"%s_NORM_QUAD4"%pfl.getName()))
6838 self.assertEqual(f1ts.getFieldSplitedByType(),refSp1)
6839 self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
6840 self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3").isIota(162))
6841 self.assertTrue(f1ts.getProfile("pfl_NORM_QUAD4").isIota(81))
6845 def testRmGroupAtSpeLevelAndMultiLevGrpCreation(self):
6846 """ Here multi level groups are created"""
6847 arr=DataArrayDouble(11) ; arr.iota()
6848 m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
6849 m=m.buildUnstructured()
6851 m1=m.buildDescendingConnectivity()[0]
6856 grp0_0=DataArrayInt([0,1,2,6]) ; grp0_0.setName(grpName)
6857 grp0_1=DataArrayInt([0,1,2,7]) ; grp0_1.setName(grpName)
6858 grp1=DataArrayInt([1,2,3,5,6]) ; grp1.setName("grp1")
6859 grp2=DataArrayInt([2,3,5,8]) ; grp2.setName("grp2")
6860 ################ ajouter un groupe sur plusieurs niveau
6862 mm.addGroup(-1,grp2)
6863 mm.addGroup(0,grp0_0)
6864 mm.addGroup(-1,grp0_1)
6865 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
6866 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6867 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6868 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6869 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6870 self.assertRaises(InterpKernelException,mm.addGroup,-1,grp0_1) # raise
6871 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6872 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6873 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6874 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6875 mm.removeGroupAtLevel(0,grpName)
6876 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(-1,))
6877 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6878 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6879 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6880 mm.removeGroupAtLevel(-1,grpName)
6881 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),())
6882 self.assertRaises(InterpKernelException,mm.removeGroupAtLevel,-2,grpName)
6883 mm.addGroup(-1,grp0_1)
6884 mm.addGroup(0,grp0_0)
6885 self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
6886 self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
6887 self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
6888 self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
6889 self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
6893 def testYutaka(self):
6894 """ 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...
6895 Then rearrange method removes unused entites by putting 0 on them -> Previously group has been modified by rearrange. Should not !"""
6897 m=MEDCouplingCMesh()
6898 arr=DataArrayDouble(4) ; arr.iota()
6899 m.setCoords(arr,arr,arr)
6900 m=m.buildUnstructured()
6903 m=m.buildUnstructured()
6904 m1=m.buildDescendingConnectivity()[0]
6910 grp0=DataArrayInt([0,1,2]) ; grp0.setName("grp0")
6912 grp1=DataArrayInt([3,4,5,6]) ; grp1.setName("grp1")
6914 grp2=DataArrayInt([7,8,9]) ; grp2.setName("grp2")
6916 grp3=DataArrayInt.Range(0,m1.getNumberOfCells(),1) ; grp3.setName("grp3")
6917 mm.addGroup(-1,grp3)
6918 self.assertNotIn(0,mm.getFamiliesIdsOnGroup("grp3")) # bug was here !
6919 grp4=DataArrayInt([3,5,8,10]) ; grp4.setName("grp4")
6920 mm.addNodeGroup(grp4)
6921 mm.rearrangeFamilies()
6922 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp0"),(0,))
6923 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp1"),(0,))
6924 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp2"),(0,))
6925 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp3"),(-1,))
6926 self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp4"),(1,))
6928 for grp in [grp0,grp1,grp2,grp3,grp4]:
6929 self.assertTrue(mm.getGroupArr(mm.getGrpNonEmptyLevelsExt(grp.getName())[0],grp.getName()).isEqual(grp))
6934 def testContxtMger1TS(self):
6935 fname="Pyfile119.med"
6936 coo=DataArrayDouble(1000) ; coo.iota()
6937 m=MEDCouplingUMesh.Build0DMeshFromCoords(coo)
6939 WriteMesh(fname,m,True)
6940 f=MEDCouplingFieldDouble(ON_CELLS)
6943 arr=DataArrayDouble(m.getNumberOfCells())
6945 f.checkConsistencyLight()
6948 f.setTime(float(i),i,0)
6949 WriteFieldUsingAlreadyWrittenMesh(fname,f)
6952 mm=MEDFileMesh.New(fname)
6953 fmts=MEDFileFieldMultiTS(fname,False)
6954 refSize=fmts.getHeapMemorySize()
6960 self.assertIn(fmts.getHeapMemorySize(),range(refSize,refSize+refSize//10))
6963 def testZipFamilies1(self):
6965 MEDFileMesh.zipFamilies tries to reduce family partitions under groups.
6968 arr=DataArrayDouble(10) ; arr.iota()
6969 m=MEDCouplingCMesh()
6970 m.setCoords(arr,arr)
6971 m=m.buildUnstructured()
6976 for i in range(m.getNumberOfCells()):
6977 d = DataArrayInt([i])
6978 d.setName("grp%d"%i)
6982 grp_all = DataArrayInt.Range(0,m.getNumberOfCells(),1)
6983 grp_all.setName("grp_all")
6984 mm.addGroup(0,grp_all)
6985 for i in range(m.getNumberOfCells()):
6986 mm.removeGroup("grp{}".format(i))
6989 mm.zipFamilies() # the method to test
6991 self.assertEqual(mm.getGroupsNames(),("grp_all",))
6992 self.assertEqual(len(mm.getFamiliesNames()),1)
6993 self.assertTrue(mm.getGroupArr(0,"grp_all").isEqualWithoutConsideringStr(DataArrayInt.Range(0,81,1)))
6996 def testZipFamilies2(self):
6998 MEDFileMesh.zipFamilies tries to reduce family partitions under groups.
7001 arr=DataArrayDouble(21) ; arr.iota()
7002 m=MEDCouplingCMesh()
7004 m=m.buildUnstructured()
7009 # 1 and 3 to be merged
7010 # 2 and 5 to be merged
7011 mm.setFamilyFieldArr(0,DataArrayInt([-1,-1,-2,-3,-8, 0,-7,-7,-1,0, -6,-2,-5,-5,-2, -2,-2,-5,-4,-3]))
7012 for i in range(1,9):
7013 mm.setFamilyId("Fam_{}".format(i),-i)
7014 mm.setFamiliesOnGroup("grp0",["Fam_1","Fam_3","Fam_6"])
7015 mm.setFamiliesOnGroup("grp1",["Fam_1","Fam_2","Fam_3","Fam_5","Fam_6"])
7016 mm.setFamiliesOnGroup("grp2",["Fam_2","Fam_5","Fam_6","Fam_7"])
7018 grp0=DataArrayInt([0,1,3,8,10,19])
7019 grp1=DataArrayInt([0,1,2,3,8,10,11,12,13,14,15,16,17,19])
7020 grp2=DataArrayInt([2,6,7,10,11,12,13,14,15,16,17])
7021 self.assertTrue(mm.getGroupArr(0,"grp0").isEqualWithoutConsideringStr(grp0))
7022 self.assertTrue(mm.getGroupArr(0,"grp1").isEqualWithoutConsideringStr(grp1))
7023 self.assertTrue(mm.getGroupArr(0,"grp2").isEqualWithoutConsideringStr(grp2))
7024 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2'))
7026 self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2'))
7027 self.assertTrue(mm.getGroupArr(0,"grp0").isEqualWithoutConsideringStr(grp0))
7028 self.assertTrue(mm.getGroupArr(0,"grp1").isEqualWithoutConsideringStr(grp1))
7029 self.assertTrue(mm.getGroupArr(0,"grp2").isEqualWithoutConsideringStr(grp2))
7030 self.assertEqual(mm.getFamiliesNames(),('Fam_1','Fam_2','Fam_6','Fam_7'))
7033 def testMeshConvertFromMEDFileGeoType(self):
7034 self.assertEqual(MEDFileMesh.ConvertFromMEDFileGeoType(320),NORM_HEXA20)
7035 self.assertEqual(MEDFileMesh.ConvertToMEDFileGeoType(NORM_HEXA20),320)
7038 def testFieldInt64_0(self):
7040 Small basic test with I/O of field in int64.
7042 fname="Pyfile120.med"
7043 arr = DataArrayDouble([0,1])
7044 m = MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh") ; m=m.buildUnstructured()
7045 f = MEDCouplingFieldInt64(ON_CELLS) ; f.setName("field")
7046 v = 1234567890123456
7047 f.setArray(DataArrayInt64([v]))
7051 f1ts = MEDFileInt64Field1TS()
7052 f1ts.setFieldNoProfileSBT(f)
7053 fmts = MEDFileInt64FieldMultiTS()
7054 fmts.pushBackTimeStep(f1ts)
7055 fs = MEDFileFields()
7060 mm = MEDFileMesh.New(fname)
7061 fs = MEDFileFields(fname)
7062 f = fs[0][0].field(mm)
7063 self.assertTrue( isinstance(f,MEDCouplingFieldInt64) )
7064 self.assertEqual( f.getArray().getIJ(0,0) , v )
7067 def testNonRegUMeshSubParts(self):
7069 Non regression test focuses on accordance between time stamp and active data structure in MEDFileUMeshAggregateCompute class.
7071 fname = "Pyfile121.med"
7072 m0 = MEDCouplingUMesh("mesh",1)
7073 coords = DataArrayDouble([(0,0),(1,0),(2,0)])
7074 m0.setCoords(coords)
7076 m0.insertNextCell(NORM_SEG2,[1,2])
7079 m1 = MEDCoupling1SGTUMesh(m0.getName(), NORM_POINT1)
7080 m1.setCoords(m0.getCoords())
7081 m1.setNodalConnectivity(DataArrayInt([1,2]))
7082 m1.setName(m0.getName())
7084 fni = mm.computeFetchedNodeIds() # <- This invokation of const method implies 1SGTU parts computation
7085 mm.zipCoords() # <- This call changes the coords and connectivity
7088 mm = MEDFileMesh.New(fname)
7089 mm[0].checkConsistency() # <- check that correct DS has been taken at write time into MEDFileUMeshAggregateCompute
7090 self.assertTrue( m0.isEqual(mm[0],1e-12) )
7094 def testFieldMultiTSSetInfo0(self):
7096 [EDF26665] : Test written to check correct behaviour of MEDFileFieldMultiTS.setInfo, lacking in Python wrappers
7098 fname = "Pyfile122.med"
7099 def generateAMEDFileFromScratch(fname,fieldToGenerate):
7100 arr = DataArrayDouble(10) ; arr.iota()
7101 m = MEDCouplingCMesh() ; m.setCoords(arr,arr)
7102 m = m.buildUnstructured() ; m.setName("mesh")
7103 f = MEDCouplingFieldDouble(ON_CELLS)
7105 f.setName(fieldToGenerate)
7106 arr = DataArrayDouble( f.getNumberOfMeshPlacesExpected() )
7108 WriteMesh(fname,m,True)
7110 arr[:] = float(i) + 0.1
7111 f.setTime(float(i) + 0.1, i , 0)
7112 WriteFieldUsingAlreadyWrittenMesh(fname,f)
7115 def changeCompoInMEDFile(fname, fnameTarget, fieldToModify):
7116 mfd = MEDFileData(fname)
7117 mfd.getMeshes().write(fnameTarget,2)
7118 fmtsToModify = mfd.getFields().getFieldWithName(fieldToModify)
7119 for f1ts in fmtsToModify:
7120 self.assertTrue( f1ts.getUndergroundDataArray().getInfoOnComponents() != ["Scalars"])
7121 fmtsToModify.setInfo(["Scalars"]) # <- test is here !
7122 fmtsToModify.write(fnameTarget,0)
7124 fieldToModify = "Field122"
7125 generateAMEDFileFromScratch(fname,fieldToModify)
7127 changeCompoInMEDFile(fname,fnameTarget,fieldToModify)
7129 fmts = MEDFileFieldMultiTS(fname,fieldToModify)
7131 self.assertTrue( f1ts.getUndergroundDataArray().getInfoOnComponents() == ["Scalars"])
7135 def testUMeshReduceToCells(self):
7137 [EDF27988] : test of MEDFileUMesh.reduceToCells method
7139 arr = DataArrayDouble(4) ; arr.iota()
7140 arrZ = DataArrayDouble(2) ; arrZ.iota()
7141 m = MEDCouplingCMesh() ; m.setCoords(arr,arr,arrZ)
7142 m = m.buildUnstructured()
7145 m1 = m.buildDescendingConnectivity()[0]
7146 bas1 = DataArrayInt([0,6,11,16,21,25,29,34,38])
7147 haut1 = DataArrayInt([1,7,12,17,22,26,30,35,39])
7148 lat1 = DataArrayInt([8,9,23,36])
7149 allcellsInMM = DataArrayInt.Aggregate([bas1,haut1,lat1])
7151 m1InMM = m1[allcellsInMM]
7153 bas1 = allcellsInMM.findIdForEach(bas1) ; bas1.setName("bas1")
7154 haut1 = allcellsInMM.findIdForEach(haut1) ; haut1.setName("haut1")
7155 lat1 = allcellsInMM.findIdForEach(lat1) ; lat1.setName("lat1")
7156 m2 = m1InMM.buildDescendingConnectivity()[0]
7157 lat2 = DataArrayInt( [ 14, 15, 16, 17, 34, 35, 50, 51] )
7158 allCellsInMM2 = DataArrayInt( [4, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17, 21, 22, 23, 27, 28, 29, 32, 33, 34, 35, 38, 39, 43, 44, 45, 48, 49, 50, 51, 54, 55] )
7159 lat2 = allCellsInMM2.findIdForEach(lat2) ; lat2.setName("lat2")
7160 m2InMM = m2[allCellsInMM2]
7164 bas1_id = -1 ; haut1_id = -2 ; lat1_id = -3 ; lat2_id = -4
7165 fam0 = DataArrayInt( m.getNumberOfCells() ) ; fam0.iota()
7166 mm.setFamilyFieldArr(0,fam0)
7167 fam1 = DataArrayInt( m1InMM.getNumberOfCells() ) ; fam1[:] = 0 ; fam1[bas1] = bas1_id ; fam1[haut1] = haut1_id ; fam1[lat1] = lat1_id
7168 mm.setFamilyFieldArr(-1,fam1)
7169 fam2 = DataArrayInt( m2InMM.getNumberOfCells() ) ; fam2[:] = 0 ; fam2[lat2] = lat2_id
7170 mm.setFamilyFieldArr(-2,fam2)
7171 for grp,famid in [(bas1,bas1_id),(haut1,haut1_id),(lat1,lat1_id),(lat2,lat2_id)]:
7172 mm.addFamily(grp.getName(),famid)
7173 mm.setFamiliesIdsOnGroup(grp.getName(),[famid])
7174 # ze heart of the test
7175 mmr = mm.reduceToCells(0,DataArrayInt([4]))
7177 tmp = m[4] ; tmp.zipCoords()
7178 self.assertTrue( mmr[0].isEqual(tmp,1e-12) )
7179 tmp = MEDCoupling1SGTUMesh( mmr[-1] )
7180 self.assertTrue( tmp.getCellModelEnum() == NORM_QUAD4 )
7181 self.assertTrue( tmp.getNodalConnectivity().isEqual( DataArrayInt([0, 4, 5, 1, 1, 0, 2, 3, 5, 7, 6, 4, 2, 6, 7, 3]) ) )
7182 tmp = MEDCoupling1SGTUMesh( mmr[-2] )
7183 self.assertTrue( tmp.getCellModelEnum() == NORM_SEG2 )
7184 self.assertTrue( tmp.getNodalConnectivity().isEqual( DataArrayInt([5, 4, 0, 4, 5, 1, 4, 6, 5, 7, 7, 6, 2, 6, 7, 3]) ) )
7186 self.assertTrue( mmr.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([4])) )
7187 self.assertTrue( mmr.getFamilyFieldAtLevel(-1).isEqual(DataArrayInt([-3, -1, -2, -3])) )
7188 self.assertTrue( mmr.getFamilyFieldAtLevel(-2).isEqual(DataArrayInt([0, -4, -4, 0, 0, 0, -4, -4])) )
7190 self.assertTrue( set( mm.getGroupsNames() ) == set( mmr.getGroupsNames() ) )
7191 for grp in mm.getGroupsNames():
7192 self.assertTrue( set(mm.getFamiliesIdsOnGroup(grp)) == set(mmr.getFamiliesIdsOnGroup(grp)) )
7196 if __name__ == "__main__":