+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def testMEDFileUMeshPickeling1(self):
+ import cPickle
+ outFileName="Pyfile86.med"
+ 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)
+ c.setInfoOnComponents(["aa","bbb"])
+ targetConn=[0,3,4,1, 1,4,2, 4,5,2, 6,7,4,3, 7,8,5,4]
+ m=MEDCouplingUMesh();
+ m.setMeshDimension(2);
+ m.allocateCells(5);
+ m.insertNextCell(NORM_TRI3,3,targetConn[4:7])
+ m.insertNextCell(NORM_TRI3,3,targetConn[7:10])
+ m.insertNextCell(NORM_QUAD4,4,targetConn[0:4])
+ m.insertNextCell(NORM_POLYGON,4,targetConn[10:14])
+ m.insertNextCell(NORM_POLYGON,4,targetConn[14:18])
+ m.finishInsertingCells();
+ m.setCoords(c)
+ m.checkCoherency()
+ m1=MEDCouplingUMesh.New();
+ m1.setMeshDimension(1);
+ m1.allocateCells(3);
+ m1.insertNextCell(NORM_SEG2,2,[1,4])
+ m1.insertNextCell(NORM_SEG2,2,[3,6])
+ m1.insertNextCell(NORM_SEG3,3,[2,8,5])
+ m1.finishInsertingCells();
+ m1.setCoords(c)
+ m1.checkCoherency()
+ m2=MEDCouplingUMesh.New();
+ m2.setMeshDimension(0);
+ m2.allocateCells(4);
+ m2.insertNextCell(NORM_POINT1,1,[1])
+ m2.insertNextCell(NORM_POINT1,1,[3])
+ m2.insertNextCell(NORM_POINT1,1,[2])
+ m2.insertNextCell(NORM_POINT1,1,[6])
+ m2.finishInsertingCells();
+ m2.setCoords(c)
+ m2.checkCoherency()
+ #
+ mm=MEDFileUMesh.New()
+ self.assertTrue(mm.getUnivNameWrStatus())
+ mm.setName("MyFirstMEDCouplingMEDmesh")
+ mm.setDescription("IHopeToConvinceLastMEDMEMUsers")
+ mm.setCoords(c)
+ mm[-1]=m1;
+ mm[0]=m;
+ mm.setRenumFieldArr(0,DataArrayInt([32,41,50,56,7]))
+ mm[-2]=m2;
+ mm.setRenumFieldArr(-2,DataArrayInt([102,52,45,63]))
+ # playing with groups
+ g1_2=DataArrayInt.New()
+ g1_2.setValues([1,3],2,1)
+ g1_2.setName("G1")
+ g2_2=DataArrayInt.New()
+ g2_2.setValues([1,2,3],3,1)
+ g2_2.setName("G2")
+ mm.setGroupsAtLevel(0,[g1_2,g2_2],False)
+ g1_1=DataArrayInt.New()
+ g1_1.setValues([0,1,2],3,1)
+ g1_1.setName("G1")
+ g2_1=DataArrayInt.New()
+ g2_1.setValues([0,2],2,1)
+ g2_1.setName("G2")
+ mm.setGroupsAtLevel(-1,[g1_1,g2_1],False)
+ g1_N=DataArrayInt.New()
+ g1_N.setValues(range(8),8,1)
+ g1_N.setName("G1")
+ g2_N=DataArrayInt.New()
+ g2_N.setValues(range(9),9,1)
+ g2_N.setName("G2")
+ mm.setGroupsAtLevel(1,[g1_N,g2_N],False)
+ mm.createGroupOnAll(0,"GrpOnAllCell")
+ # check content of mm
+ t=mm.getGroupArr(0,"G1",False)
+ self.assertTrue(g1_2.isEqual(t));
+ t=mm.getGroupArr(0,"G2",False)
+ self.assertTrue(g2_2.isEqual(t));
+ t=mm.getGroupArr(-1,"G1",False)
+ self.assertTrue(g1_1.isEqual(t));
+ t=mm.getGroupArr(-1,"G2",False)
+ self.assertTrue(g2_1.isEqual(t));
+ t=mm.getGroupArr(1,"G1",False)
+ self.assertTrue(g1_N.isEqual(t));
+ t=mm.getGroupArr(1,"G2",False)
+ self.assertTrue(g2_N.isEqual(t));
+ self.assertTrue(mm.existsGroup("GrpOnAllCell"));
+ t=mm.getGroupArr(0,"GrpOnAllCell")
+ #
+ st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
+ mm2=cPickle.loads(st)
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ self.assertEqual(mm.getAxType(),AX_CART)
+ #
+ mm.setAxType(AX_CYL)
+ st=cPickle.dumps(mm,cPickle.HIGHEST_PROTOCOL)
+ mm2=cPickle.loads(st)
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ self.assertEqual(mm2.getAxType(),AX_CYL)
+ pass
+
+ def testMEDFileFieldsLoadSpecificEntities1(self):
+ nbNodes=11
+ fieldName="myField"
+ fileName="Pyfile87.med"
+ nbPdt=10
+ meshName="Mesh"
+ #
+ m=MEDCouplingCMesh()
+ arr=DataArrayDouble(nbNodes) ; arr.iota()
+ m.setCoords(arr)
+ m=m.buildUnstructured()
+ m.setName(meshName)
+ #
+ fmts=MEDFileFieldMultiTS()
+ for i in xrange(nbPdt):
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setMesh(m)
+ arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
+ f.setArray(arr)
+ f.setName(fieldName)
+ f.setTime(float(i),i,0)
+ fmts.appendFieldNoProfileSBT(f)
+ pass
+ #
+ mm=MEDFileUMesh() ; mm[0]=m
+ fmts.write(fileName,2)
+ mm.write(fileName,0)
+ #
+ fs=MEDFileFields(fileName,False)
+ fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_NODES,NORM_ERROR)],False)
+ fs.loadArraysIfNecessary()
+ fs2.loadArraysIfNecessary()
+ for i in xrange(nbPdt):
+ self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
+ pass
+ m1=MEDCouplingCMesh() ; m1.setCoords(DataArrayDouble([0,1,2,3]),DataArrayDouble([0,1])) ; m1=m1.buildUnstructured() ; m1.simplexize(0)
+ m2=MEDCouplingCMesh() ; m2.setCoords(DataArrayDouble([3,4,5]),DataArrayDouble([0,1])) ; m2=m2.buildUnstructured()
+ m3=MEDCouplingUMesh.MergeUMeshes(m1,m2) ; m3.setName(meshName)
+ fmts=MEDFileFieldMultiTS()
+ for i in xrange(nbPdt):
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m3)
+ arr=DataArrayDouble(8) ; arr.iota() ; arr*=i
+ f.setArray(arr)
+ f.setName(fieldName)
+ f.setTime(float(i),i,0)
+ fmts.appendFieldNoProfileSBT(f)
+ pass
+ mm=MEDFileUMesh() ; mm[0]=m3
+ del mm[0]
+ self.assertEqual(mm.getNonEmptyLevels(),())
+ mm[0]=m3
+ self.assertEqual(mm.getNonEmptyLevels(),(0,))
+ fmts.write(fileName,2)
+ fs=MEDFileFields(fileName,False)
+ fs2=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3)],False)
+ fs3=MEDFileFieldMultiTS.LoadSpecificEntities(fileName,fieldName,[(ON_CELLS,NORM_QUAD4)],False)
+ fs4=MEDFileFields.LoadSpecificEntities(fileName,[(ON_CELLS,NORM_TRI3),(ON_CELLS,NORM_QUAD4)],False)
+ fs.loadArraysIfNecessary()
+ fs2.loadArraysIfNecessary()
+ fs3.loadArraysIfNecessary()
+ fs4.loadArraysIfNecessary()
+ for i in xrange(nbPdt):
+ self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[:6].isEqual(fs2[fieldName][i].getUndergroundDataArray(),1e-12))
+ self.assertTrue(fs[fieldName][i].getUndergroundDataArray()[6:8].isEqual(fs3[i].getUndergroundDataArray(),1e-12))
+ self.assertTrue(fs[fieldName][i].getUndergroundDataArray().isEqual(fs4[fieldName][i].getUndergroundDataArray(),1e-12))
+ pass
+ pass
+
+ def testMEDFileLotsOfTSRW1(self):
+ nbNodes=11
+ fieldName="myField"
+ fileName="Pyfile88.med"
+ nbPdt=300 # <- perftest = 30000
+ meshName="Mesh"
+ #
+ maxPdt=100 # <- optimum = 500
+ m=MEDCouplingCMesh()
+ arr=DataArrayDouble(nbNodes) ; arr.iota()
+ m.setCoords(arr)
+ m=m.buildUnstructured()
+ m.setName(meshName)
+ #
+ nbOfField=nbPdt/maxPdt
+ fs=MEDFileFields()
+ for j in xrange(nbOfField):
+ fmts=MEDFileFieldMultiTS()
+ s=DataArray.GetSlice(slice(0,nbPdt,1),j,nbOfField)
+ for i in xrange(s.start,s.stop,s.step):
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setMesh(m)
+ arr=DataArrayDouble(nbNodes) ; arr.iota() ; arr*=i
+ f.setArray(arr)
+ f.setName("%s_%d"%(fieldName,j))
+ f.setTime(float(i),i,0)
+ fmts.appendFieldNoProfileSBT(f)
+ pass
+ fs.pushField(fmts)
+ pass
+ #
+ mm=MEDFileUMesh() ; mm[0]=m
+ fs.write(fileName,2)
+ mm.write(fileName,0)
+ ############
+ def appendInDict(d,key,val):
+ if key in d:
+ d[key].append(val)
+ else:
+ d[key]=[val]
+ pass
+ import re
+ allFields=MEDLoader.GetAllFieldNames(fileName)
+ allFieldsDict={}
+ pat=re.compile("([\d]+)([\s\S]+)$")
+ for st in allFields:
+ stRev=st[::-1]
+ m=pat.match(stRev)
+ if m:
+ appendInDict(allFieldsDict,m.group(2)[::-1],m.group(1)[::-1])
+ pass
+ else:
+ appendInDict(allFieldsDict,st,'')
+ pass
+ pass
+ fs2=MEDFileFields()
+ for k in allFieldsDict:
+ if allFieldsDict[k]!=['']:
+ allFieldsDict[k]=sorted(allFieldsDict[k],key=lambda x: int(x))
+ pass
+ fmts2=[]
+ for it in allFieldsDict[k]:
+ fmts2.append(MEDFileFieldMultiTS.LoadSpecificEntities(fileName,k+it,[(ON_NODES,NORM_ERROR)]))
+ pass
+ fmts2.reverse()
+ zeResu=fmts2.pop()
+ nbIter=len(fmts2)
+ for ii in xrange(nbIter):
+ zeResu.pushBackTimeSteps(fmts2.pop())
+ pass
+ zeResu.setName(k)
+ fs2.pushField(zeResu)
+ pass
+ self.assertEqual(fs2[0].getTimeSteps(),[(i,0,float(i)) for i in xrange(nbPdt)])
+ pass
+
+ def testMEDFileMeshRearrangeFamIds1(self):
+ """ Test for bug EDF10720. The aim of this test is the call of MEDFileMesh.rearrangeFamilies."""
+ fileName="Pyfile89.med"
+ meshName='Maillage_2'
+ mm=MEDFileUMesh()
+ 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)])
+ #
+ 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])
+ 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])
+ m0=MEDCouplingUMesh(meshName,3) ; m0.setCoords(coords)
+ m0.setConnectivity(c0,c0i)
+ mm[0]=m0
+ #
+ 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])
+ 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])
+ m1=MEDCouplingUMesh(meshName,2) ; m1.setCoords(coords)
+ m1.setConnectivity(c1,c1i)
+ mm[-1]=m1
+ #
+ 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])
+ m2=MEDCoupling1SGTUMesh(meshName,NORM_SEG2)
+ m2.setNodalConnectivity(c2) ; m2.setCoords(coords)
+ mm[-2]=m2.buildUnstructured()
+ #
+ ref0=DataArrayInt(55) ; ref0[:]=0
+ mm.setFamilyFieldArr(0,ref0)
+ 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]))
+ 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])
+ mm.setFamilyFieldArr(-1,ref1)
+ 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])
+ mm.setFamilyFieldArr(-2,ref2)
+ #
+ for f,fid in (('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2)):
+ mm.setFamilyId(f,fid)
+ for grp,fams in [('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',))]:
+ mm.setFamiliesOnGroup(grp,fams)
+ mm.write(fileName,2)
+ #
+ mm=MEDFileMesh.New(fileName)
+ grp=mm.getGroup(-1,"Groupe_1")
+ dai=grp.computeFetchedNodeIds()
+ dai.setName("TOTO")
+ mm.addGroup(1,dai)
+ mm.rearrangeFamilies() # <- the aim of the test
+ self.assertTrue(dai.isEqual(mm.getGroupArr(1,"TOTO")))
+ self.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(ref0))
+ self.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(ref1))
+ self.assertTrue(mm.getFamilyFieldAtLevel(-2).isEqual(ref2))
+ 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])))
+ allGrps=[('Groupe_1',('FAM_-6_Groupe_1',)),('Groupe_2',('FAM_-7_Groupe_2',)),('Groupe_3',('FAM_2_Groupe_3',)),('TOTO',('Family_9',))]
+ allFams=[('FAMILLE_ZERO',0),('FAM_-6_Groupe_1',-6),('FAM_-7_Groupe_2',-7),('FAM_2_Groupe_3',2),('Family_9',9)]
+ self.assertEqual(list(mm.getGroupsNames()),[elt[0] for elt in allGrps])
+ for elt,fams in allGrps:
+ self.assertEqual(mm.getFamiliesOnGroup(elt),fams)
+ self.assertEqual(list(mm.getFamiliesNames()),[elt[0] for elt in allFams])
+ for elt,eltId in allFams:
+ self.assertEqual(mm.getFamilyId(elt),eltId)
+ pass
+
+ def testNonRegrCMeshSetFieldPfl1(self):
+ """ Non regression test. For structured mesh, push a false partial field in MEDFileField1TS using setFieldProfile."""
+ ff=MEDFileField1TS()
+ meshName="mesh"
+ mm=MEDFileCMesh()
+ m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
+ m.setCoords(arr)
+ m.setName(meshName)
+ mm.setMesh(m)
+ field=MEDCouplingFieldDouble(ON_CELLS)
+ field.setMesh(m)
+ field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
+ field.setName("Field")
+ field.checkCoherency()
+ pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU") #<- false profile because defined on all cells !
+ ff.setFieldProfile(field,mm,0,pfl) # <- bug was revealed here !
+ self.assertEqual(ff.getPfls(),())
+ field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
+ self.assertTrue(field.isEqual(field2,1e-12,1e-12))
+ del ff,mm,field,field2,pfl
+ # same with unstructured mesh
+ ff=MEDFileField1TS()
+ meshName="mesh"
+ mm=MEDFileUMesh()
+ m=MEDCouplingCMesh() ; arr=DataArrayDouble(5) ; arr.iota()
+ m.setCoords(arr)
+ m.setName(meshName)
+ m=m.buildUnstructured()
+ mm[0]=m
+ field=MEDCouplingFieldDouble(ON_CELLS)
+ field.setMesh(m)
+ field.setArray(DataArrayDouble([1.2,2.3,3.4,4.5]))
+ field.setName("Field")
+ field.checkCoherency()
+ pfl=DataArrayInt([0,1,2,3]) ; pfl.setName("TUTU")
+ ff.setFieldProfile(field,mm,0,pfl)
+ self.assertEqual(ff.getPfls(),())
+ field2=ff.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
+ self.assertTrue(field.isEqual(field2,1e-12,1e-12))
+ pass
+
+ def testMEDFileUMeshLinearToQuadraticAndRev1(self):
+ meshName="mesh"
+ fileName="Pyfile90.med"
+ fileName2="Pyfile91.med"
+ arr=DataArrayDouble(5) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ d=DataArrayInt([3,7,11,15])
+ m1=m[d]
+ m1.simplexize(0)
+ m2=m[d.buildComplement(m.getNumberOfCells())]
+ m=MEDCouplingUMesh.MergeUMeshesOnSameCoords(m1,m2)
+ m.changeSpaceDimension(3,0.)
+ arr=DataArrayDouble(3) ; arr.iota()
+ m1D=MEDCouplingCMesh() ; m1D.setCoords(arr) ; m1D=m1D.buildUnstructured() ; m1D.changeSpaceDimension(3,0.)
+ m1D.setCoords(m1D.getCoords()[:,[1,2,0]])
+ delta=m.getNumberOfNodes()*(m1D.getNumberOfNodes()-1)
+ m3D=m.buildExtrudedMesh(m1D,0)
+ m3D.sortCellsInMEDFileFrmt()
+ m3D.setName(meshName)
+ m2D=m ; m2D.setCoords(m3D.getCoords()) ; m2D.shiftNodeNumbersInConn(delta) ; m2D.setName(meshName) ; m2D.checkCoherency2()
+ m1D=m2D.computeSkin() ; m1D.setName(meshName)
+ m0D=MEDCouplingUMesh.Build0DMeshFromCoords(m3D.getCoords()) ; m0D.setName(meshName) ; m0D=m0D[[2,4,10]]
+ #
+ mm=MEDFileUMesh()
+ mm[0]=m3D ; mm[-1]=m2D ; mm[-2]=m1D ; mm[-3]=m0D
+ grpEdge0=DataArrayInt([1,2,3,5]) ; grpEdge0.setName("East")
+ grpEdge1=DataArrayInt([0,1]) ; grpEdge1.setName("Corner1")
+ grpFaceSouth=DataArrayInt([0,1,8,9,10]) ; grpFaceSouth.setName("SouthFace")
+ grpFaceNorth=DataArrayInt([6,7,17,18,19]) ; grpFaceNorth.setName("NorthFace")
+ diagFace=DataArrayInt([0,1,13,15,17]) ; diagFace.setName("DiagFace")
+ vol1=DataArrayInt([20,21,23,24]) ; vol1.setName("vol1")
+ vol2=DataArrayInt([2,3,4,5,21,24]) ; vol2.setName("vol2")
+ mm.setGroupsAtLevel(0,[vol1,vol2])
+ mm.setGroupsAtLevel(-1,[grpFaceSouth,grpFaceNorth,diagFace])
+ mm.setGroupsAtLevel(-2,[grpEdge0,grpEdge1])
+ #
+ mmOut1=mm.linearToQuadratic(0,0.)
+ mmOut1.write(fileName2,2)
+ mmOut2=mmOut1.quadraticToLinear(0.)
+ self.assertTrue(mm.isEqual(mmOut2,1e-12)[0])
+ pass
+
+ def testMEDFileMeshAddGroup1(self):
+ m=MEDCouplingCMesh()
+ arrX=DataArrayDouble(9) ; arrX.iota()
+ arrY=DataArrayDouble(4) ; arrY.iota()
+ m.setCoords(arrX,arrY)
+ m.setName("mesh")
+ mm=MEDFileCMesh()
+ mm.setMesh(m)
+ grp0=DataArrayInt([3,5,6,21,22]) ; grp0.setName("grp0")
+ mm.addGroup(0,grp0)
+ grp1=DataArrayInt([3,4,5,8,18,19,22]) ; grp1.setName("grp1")
+ mm.addGroup(0,grp1)
+ grp2=DataArrayInt([0,1,2,10,11]) ; grp2.setName("grp2")
+ mm.addGroup(0,grp2)
+ grp3=DataArrayInt([23]) ; grp3.setName("grp3")
+ mm.addGroup(0,grp3)
+ for grp in [grp0,grp1,grp2,grp3]:
+ self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
+ self.assertEqual(mm.getGroupsNames(),('grp0','grp1','grp2','grp3'))
+ delta=12
+ for grp in [grp0,grp1,grp2,grp3]:
+ grpNode=grp.deepCpy() ; grpNode+=delta ; grpNode.setName("%s_node"%grp.getName())
+ mm.addGroup(1,grpNode)
+ self.assertEqual(mm.getGroupsNames(),('grp0','grp0_node','grp1','grp1_node','grp2','grp2_node','grp3','grp3_node'))
+ for grp in [grp0,grp1,grp2,grp3]:
+ self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
+ for grp in [grp0,grp1,grp2,grp3]:
+ grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
+ self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
+ mm.normalizeFamIdsMEDFile()
+ for grp in [grp0,grp1,grp2,grp3]:
+ self.assertTrue(mm.getGroupArr(0,grp.getName()).isEqual(grp))
+ for grp in [grp0,grp1,grp2,grp3]:
+ grpExp=grp+delta ; grpExp.setName("%s_node"%grp.getName())
+ self.assertTrue(mm.getGroupArr(1,"%s_node"%grp.getName()).isEqual(grpExp))
+ pass
+
+ pass
+ def testMEDFileJoint1(self):
+ fileName="Pyfile92.med"
+ coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
+ coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
+ mm=MEDFileUMesh()
+ mm.setCoords(coo)
+ mm.setName("maa1")
+ mm.setDescription("un maillage")
+ mm.write(fileName,2)
+ node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
+ cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
+ one_step_joint=MEDFileJointOneStep()
+ one_step_joint.pushCorrespondence(cell_correspond)
+ one_step_joint.pushCorrespondence(node_correspond)
+ one_joint=MEDFileJoint()
+ one_joint.pushStep(one_step_joint)
+ one_joint.setLocalMeshName("maa1")
+ one_joint.setRemoteMeshName("maa1")
+ one_joint.setDescription("joint_description")
+ one_joint.setJointName("joint_1")
+ one_joint.setDomainNumber(1)
+ self.assertEqual( one_joint.getLocalMeshName(), "maa1")
+ self.assertEqual( one_joint.getRemoteMeshName(), "maa1")
+ self.assertEqual( one_joint.getDescription(), "joint_description")
+ self.assertEqual( one_joint.getJointName(), "joint_1")
+ self.assertEqual( one_joint.getDomainNumber(), 1)
+ joints=MEDFileJoints()
+ joints.pushJoint(one_joint);
+ joints.write(fileName,0)
+ # read back
+ jointsR=MEDFileJoints(fileName,mm.getName())
+ self.assertEqual( jointsR.getNumberOfJoints(), 1 )
+ jR = jointsR.getJointAtPos(0)
+ self.assertTrue( jR.isEqual( one_joint ))
+ self.assertRaises( InterpKernelException, jointsR.getJointAtPos,1)
+ self.assertRaises( InterpKernelException, jointsR.destroyJointAtPos,1)
+ jointsR.destroyJointAtPos(0)
+
+ pass
+ def testMEDFileJoint2(self):
+ fileNameWr="Pyfile93.med"
+ coo=DataArrayDouble([(0,0,0),(1,0,0),(2,0,0)])
+ coo.setInfoOnComponents(["x [cm]","y [cm]","z [cm]"])
+ mm=MEDFileUMesh()
+ mm.setCoords(coo)
+ mm.setName("maa1")
+ mm.setDescription("un maillage")
+ node_correspond=MEDFileJointCorrespondence(DataArrayInt([13,14,15,16]))
+ cell_correspond=MEDFileJointCorrespondence(DataArrayInt([17,18]),NORM_TETRA4,NORM_PENTA6)
+ one_step_joint=MEDFileJointOneStep()
+ two_step_joint=MEDFileJointOneStep()
+ one_joint=MEDFileJoint()
+ two_joint=MEDFileJoint()
+ one_step_joint.pushCorrespondence(node_correspond)
+ one_joint.pushStep(one_step_joint)
+ two_step_joint.pushCorrespondence(cell_correspond)
+ two_step_joint.pushCorrespondence(node_correspond)
+ two_joint.pushStep(two_step_joint)
+ one_joint.setLocalMeshName("maa1")
+ one_joint.setRemoteMeshName("maa1")
+ one_joint.setDescription("joint_description_1")
+ one_joint.setJointName("joint_1")
+ one_joint.setDomainNumber(1)
+ two_joint.setLocalMeshName("maa1")
+ two_joint.setRemoteMeshName("maa1")
+ two_joint.setDescription("joint_description_2")
+ two_joint.setJointName("joint_2")
+ two_joint.setDomainNumber(2)
+ joints=MEDFileJoints()
+ joints.pushJoint(one_joint)
+ joints.pushJoint(two_joint)
+ mm.setJoints( joints )
+ mm.write(fileNameWr,2)
+ #
+ mm=MEDFileMesh.New(fileNameWr)
+ self.assertEqual( mm.getNumberOfJoints(), 2)
+ jointsR = mm.getJoints();
+ self.assertEqual( jointsR.getMeshName(), mm.getName() )
+ self.assertEqual( len( jointsR ), 2 )
+ jointR1 = jointsR[0]
+ jointR2 = jointsR[1]
+ self.assertFalse( jointR1 is None )
+ self.assertFalse( jointR2 is None )
+ self.assertTrue( jointR1.isEqual( one_joint ))
+ self.assertTrue( jointR2.isEqual( two_joint ))
+ pass
+
+ def testMEDFileJoint1(self):
+ node_correspond=MEDFileJointCorrespondence(DataArrayInt([1,2,3,4,5,6,7,8]))
+ cell_correspond=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_TRI3)
+ cell_correspon2=MEDFileJointCorrespondence(DataArrayInt([9,10,11]),NORM_TRI3,NORM_TRI3)
+ cell_correspon3=MEDFileJointCorrespondence(DataArrayInt([9,10,11,12]),NORM_TRI3,NORM_QUAD4)
+ joint1st_1=MEDFileJointOneStep()
+ joint1st_1.pushCorrespondence(cell_correspond)
+ joint1st_1.pushCorrespondence(node_correspond)
+ joint1st_2=MEDFileJointOneStep()
+ joint1st_2.pushCorrespondence(cell_correspond)
+ joint1st_2.pushCorrespondence(node_correspond)
+ joint1st_3=MEDFileJointOneStep()
+ joint1st_3.pushCorrespondence(node_correspond)
+ joint1st_3.pushCorrespondence(cell_correspond)
+ joint1st_4=MEDFileJointOneStep()
+ joint1st_4.pushCorrespondence(cell_correspond)
+ joint1st_5=MEDFileJointOneStep()
+ joint1st_5.pushCorrespondence(cell_correspon2)
+ joint1st_6=MEDFileJointOneStep()
+ joint1st_6.pushCorrespondence(cell_correspon3)
+ self.assertTrue( joint1st_1.isEqual( joint1st_2 ))
+ self.assertTrue( joint1st_1.isEqual( joint1st_3 ))
+ self.assertFalse( joint1st_1.isEqual( joint1st_4 ))
+ self.assertFalse( joint1st_4.isEqual( joint1st_5 ))
+ self.assertFalse( joint1st_4.isEqual( joint1st_6 ))
+ one_joint=MEDFileJoint()
+ one_joint.pushStep(joint1st_1)
+ one_joint.setLocalMeshName("maa1")
+ one_joint.setRemoteMeshName("maa2")
+ one_joint.setDescription("joint_description")
+ one_joint.setJointName("joint_1")
+ one_joint.setDomainNumber(1)
+ self.assertEqual( "maa1", one_joint.getLocalMeshName())
+ self.assertEqual( "maa2", one_joint.getRemoteMeshName())
+ self.assertEqual( "joint_description", one_joint.getDescription())
+ self.assertEqual( 1, one_joint.getDomainNumber())
+ self.assertEqual( "joint_1", one_joint.getJointName())
+ pass
+
+ @unittest.skipUnless('linux'==platform.system().lower(),"stderr redirection not ported on Windows ?")
+ def testMEDFileSafeCall0(self):
+ """ EDF11242 : check status of MED file calls to detect problems immediately. Sorry this test generates awful messages !"""
+ fname="Pyfile94.med"
+ errfname="Pyfile94.err"
+ class StdOutRedirect(object):
+ def __init__(self,fileName):
+ import os,sys
+ sys.stderr.flush()
+ self.stdoutOld=os.dup(2)
+ self.fdOfSinkFile=os.open(fileName,os.O_CREAT | os.O_RDWR)
+ fd2=os.dup2(self.fdOfSinkFile,2)
+ self.origPyVal=sys.stderr
+ class FlushFile(object):
+ def __init__(self,f):
+ self.f=f
+ def write(self,st):
+ self.f.write(st)
+ self.f.flush()
+ def flush(self):
+ return self.f.flush()
+ def isatty(self):
+ return self.f.isatty()
+ sys.stderr=FlushFile(os.fdopen(self.fdOfSinkFile,"w"))
+ def __del__(self):
+ import os,sys
+ sys.stderr=self.origPyVal
+ #os.fsync(self.fdOfSinkFile)
+ os.fsync(2)
+ os.dup2(self.stdoutOld,2)
+ os.close(self.stdoutOld)
+ import os
+ # first clean file if needed
+ if os.path.exists(fname):
+ os.remove(fname)
+ pass
+ # second : build a file from scratch
+ m=MEDCouplingCMesh()
+ arr=DataArrayDouble(11) ; arr.iota()
+ m.setCoords(arr,arr)
+ mm=MEDFileCMesh()
+ mm.setMesh(m)
+ mm.setName("mesh")
+ mm.write(fname,2)
+ # third : change permissions to remove write access on created file
+ os.chmod(fname,0444)
+ # four : try to append data on file -> check that it raises Exception
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setName("field")
+ f.setMesh(m)
+ f.setArray(DataArrayDouble(100))
+ f.getArray()[:]=100.
+ f.checkCoherency()
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f)
+ # redirect stderr
+ tmp=StdOutRedirect(errfname)
+ self.assertRaises(InterpKernelException,f1ts.write,fname,0) # it should raise !
+ del tmp
+ #
+ if os.path.exists(errfname):
+ os.remove(errfname)
+ #
+ pass
+
+ def testUnivStatus1(self):
+ """ Non regression test to check the effectiveness of univ write status."""
+ fname="Pyfile95.med"
+ arr=DataArrayDouble(10) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m.setName("mesh")
+ mm=MEDFileCMesh() ; mm.setMesh(m)
+ mm.setUnivNameWrStatus(False) # test is here
+ mm.write(fname,2)
+ mm=MEDFileCMesh(fname)
+ self.assertEqual(mm.getUnivName(),"")
+ mm.setUnivNameWrStatus(True)
+ mm.write(fname,2)
+ mm=MEDFileCMesh(fname)
+ self.assertTrue(mm.getUnivName()!="")
+ pass
+
+ def testEmptyMesh(self):
+ """ MEDLoader should be able to consistently write and read an empty mesh (coords array
+ with 0 tuples """
+ fname = "Pyfile96.med"
+ m = MEDCouplingUMesh('toto', 2)
+ m.setCoords(DataArrayDouble([], 0, 2))
+ m.setConnectivity(DataArrayInt([]), DataArrayInt([0]))
+ mfu = MEDFileUMesh()
+ mfu.setMeshAtLevel(0, m)
+ mfu.write(fname, 2)
+ mfu2 = MEDFileUMesh(fname)
+ self.assertEqual('toto', mfu2.getName())
+ lvl = mfu2.getNonEmptyLevels()
+ self.assertEqual((), lvl)
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def testMEDFileUMeshPickeling2(self):
+ """ Check that pickalization can be performed on a unpickalized instance. Non regression test."""
+ name="Mesh_1"
+ grpName1="HAUT"
+ grpName2="BASE"
+ hauteur=1.
+ nbOfNodesPerAxis=3
+ arr=DataArrayDouble(nbOfNodesPerAxis) ; arr.iota() ; arr/=(nbOfNodesPerAxis-1) ; arr*=hauteur
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr,arr) ; m=m.buildUnstructured() ; m.setName(name)
+ mesh=MEDFileUMesh() ; mesh[0]=m
+ m1=m.computeSkin() ; mesh[-1]=m1
+ #
+ bary1=m1.getBarycenterAndOwner()[:,2]
+ grp1=bary1.getIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
+ grp2=bary1.getIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
+ mesh.setGroupsAtLevel(-1,[grp1,grp2])
+
+ import cPickle
+ st=cPickle.dumps(mesh,2)
+ mm=cPickle.loads(st)
+ st2=cPickle.dumps(mm,2)
+ mm2=cPickle.loads(st2)
+ self.assertTrue(mesh.isEqual(mm2,1e-12)[0])
+ pass
+
+ def testMEDFileEquivalence1(self):
+ """ First check of equivalence implementation in MEDFileMesh"""
+ fileName="Pyfile97.med"
+ meshName="M_01"
+ mm=MEDFileUMesh()
+ 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)])
+ coo.setInfoOnComponents(["X [Sans_unite]","Y [Sans_unite]","Z [Sans_unite]"])
+ 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])
+ m1=MEDCoupling1SGTUMesh(meshName,NORM_QUAD4) ; m1.setCoords(coo) ; m1.setNodalConnectivity(connQ4) ; mm[-1]=m1
+ 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])
+ m0=MEDCoupling1SGTUMesh(meshName,NORM_HEXA8) ; m0.setCoords(coo) ; m0.setNodalConnectivity(connH8) ; mm[0]=m0
+ mm.getFamilyFieldAtLevel(-1)[:]=-2
+ mm.getFamilyFieldAtLevel(0)[:]=0
+ mm.addFamily("HOMARD________-1",-1)
+ mm.addFamily("HOMARD________-2",-2)
+ mm.addFamily("HOMARD________-3",-3)
+ mm.setFamiliesIdsOnGroup("HOMARD",[-1,-2,-3])
+
+ eqName="MAILLES_A_RECOLLER_APRES_HOMARD"
+ 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."
+ mm.initializeEquivalences()
+ eqs=mm.getEquivalences()
+ eq0=eqs.appendEmptyEquivalenceWithName(eqName)
+ eq0.setDescription(descEq)
+ corr=DataArrayInt([(0,3),(0,4),(0,5),(0,6),(1,7),(1,8),(1,9),(1,10),(2,11),(2,12),(2,13),(2,14)])
+ eq0.setArray(-1,corr)
+ self.assertEqual(eq0.getCell().size(),1)
+ self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
+ eq0.getCell().clear()
+ self.assertEqual(eq0.getCell().size(),0)
+ eq0.getCell().setArrayForType(NORM_QUAD4,corr)
+ self.assertEqual(eq0.getCell().size(),1)
+ self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
+ mm.killEquivalences()
+ mm.initializeEquivalences()
+ eqs=mm.getEquivalences()
+ eq0=eqs.appendEmptyEquivalenceWithName(eqName)
+ eq0.setDescription(descEq)
+ c=eq0.initCell()
+ c.setArrayForType(NORM_QUAD4,corr)
+ self.assertEqual(eq0.getCell().size(),1)
+ self.assertTrue(eq0.getCell().getArray(NORM_QUAD4).isEqual(corr))
+ mm2=mm.deepCpy()
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ self.assertEqual(mm2.getEquivalences().size(),1)
+ self.assertTrue(mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4).isEqual(corr))
+ mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=2
+ self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
+ mm2.getEquivalences().getEquivalence(0).getCell().getArray(NORM_QUAD4)[0,0]=0
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ mm.write(fileName,2)
+ #
+ mm3=MEDFileMesh.New(fileName)
+ self.assertTrue(mm.isEqual(mm3,1e-12)[0])
+ pass
+
+ def testMEDFileForFamiliesPlayer1(self):
+ """Non regression bug EDF11911. For serial killers using same family name to store both cells and nodes ! Only sky is the limit."""
+ fileName="Pyfile98.med"
+ meshName="mesh"
+ magicSt="%s%%04i"%(MEDFileMesh.GetMagicFamilyStr())
+ arr=DataArrayDouble(4) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ mm=MEDFileUMesh()
+ mm[0]=m
+ mm.setName(meshName)
+ mm.setFamilyId("FAMILLE_ZERO",0)
+ mm.getFamilyFieldAtLevel(0)[-3:]=-4
+ mm.setFamilyId("RIDF%s"%(magicSt%0),-4)
+ mm.setGroupsOnFamily("RIDF%s"%(magicSt%0),["RID"])
+ d=DataArrayInt(16) ; d[:]=0 ; d[[1,2,4,5]]=3
+ mm.setFamilyFieldArr(1,d)
+ mm.setFamilyId("RIDF%s"%(magicSt%1),3)
+ mm.setGroupsOnFamily("RIDF%s"%(magicSt%1),["RID"])
+ self.assertEqual(mm.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
+ self.assertEqual(mm.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF")) # <- the aim of test is here !
+ self.assertEqual(mm.getFamiliesIdsOnGroup("RID"),(-4,3))
+ mm.write(fileName,2)
+ # now read such funny file !
+ mm2=MEDFileMesh.New(fileName) # <- normaly mdump of Pyfile98.med must contain only RID and FAMILLE_ZERO families.
+ self.assertTrue(mm.isEqual(mm2,1e-16))
+ self.assertEqual(mm2.getFamiliesNames(),("FAMILLE_ZERO",'RIDF!/__\\!0000','RIDF!/__\\!0001'))
+ self.assertEqual(mm2.getFamiliesNamesWithFilePointOfView(),("FAMILLE_ZERO","RIDF","RIDF"))
+ self.assertEqual(mm2.getFamiliesIdsOnGroup("RID"),(-4,3))# <- very important too !
+ pass
+
+ def testCartesianizer1(self):
+ """ This test is advanced to be sure that no unnecessary copies had been made during cartesianization process. """
+ # UMesh non cart
+ arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildUnstructured()
+ mm=MEDFileUMesh() ; mm[0]=m ; mm.forceComputationOfParts() ; mm.setAxType(AX_CYL) #<- important
+ d0=DataArrayInt(16) ; d0[:]=0
+ d1=DataArrayInt(9) ; d1[:]=0
+ mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
+ mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
+ ref0=mm.getCoords().getHiddenCppPointer()
+ ref1=mm[0].getNodalConnectivity().getHiddenCppPointer()
+ self.assertEqual(ref0,mm[0].getCoords().getHiddenCppPointer())
+ ref2=mm[0].getNodalConnectivityIndex().getHiddenCppPointer()
+ ref3=mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer()
+ self.assertEqual(ref0,mm.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
+ mm2=mm.cartesianize() # the trigger
+ self.assertTrue(isinstance(mm2,MEDFileUMesh))
+ self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
+ self.assertTrue(ref0==mm.getCoords().getHiddenCppPointer()) # <- here important
+ self.assertTrue(ref0!=mm2.getCoords().getHiddenCppPointer()) # <- here important
+ self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2[0].getCoords().getHiddenCppPointer())
+ self.assertEqual(mm2.getCoords().getHiddenCppPointer(),mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getCoords().getHiddenCppPointer())
+ self.assertEqual(mm2[0].getNodalConnectivity().getHiddenCppPointer(),ref1) # <- here very important
+ self.assertEqual(mm2[0].getNodalConnectivityIndex().getHiddenCppPointer(),ref2) # <- here very important
+ self.assertEqual(mm2.getDirectUndergroundSingleGeoTypeMesh(NORM_QUAD4).getNodalConnectivity().getHiddenCppPointer(),ref3) # <- here very important
+ self.assertEqual(mm2.getName(),mm.getName())
+ self.assertEqual(mm2.getDescription(),mm.getDescription())
+ self.assertEqual(mm2.getTime(),mm.getTime())
+ self.assertEqual(mm2.getTime(),mm.getTime())
+ self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
+ self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
+ self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
+ self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
+ self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
+ self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
+ self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
+ self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
+ # UMesh cart
+ mm.setAxType(AX_CART)
+ mm2=mm.cartesianize() # the trigger
+ self.assertTrue(isinstance(mm2,MEDFileUMesh))
+ self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
+ # CurveLinearMesh non cart
+ arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr) ; m=m.buildCurveLinear()
+ mm=MEDFileCurveLinearMesh() ; mm.setMesh(m) ; mm.setAxType(AX_CYL) #<- important
+ mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
+ mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
+ ref0=mm.getMesh().getCoords().getHiddenCppPointer()
+ mm2=mm.cartesianize() # the trigger
+ self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
+ self.assertTrue(mm.getHiddenCppPointer()!=mm2.getHiddenCppPointer())
+ self.assertTrue(ref0==mm.getMesh().getCoords().getHiddenCppPointer()) # <- here important
+ self.assertTrue(ref0!=mm2.getMesh().getCoords().getHiddenCppPointer()) # <- here important
+ self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
+ self.assertEqual(mm2.getName(),mm.getName())
+ self.assertEqual(mm2.getDescription(),mm.getDescription())
+ self.assertEqual(mm2.getTime(),mm.getTime())
+ self.assertEqual(mm2.getTime(),mm.getTime())
+ self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
+ self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
+ self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
+ self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
+ self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
+ self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
+ self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
+ self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
+ # CurveLinearMesh cart
+ mm.setAxType(AX_CART)
+ mm2=mm.cartesianize() # the trigger
+ self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
+ self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
+ # CMesh non cart
+ arr=DataArrayDouble(4) ; arr.iota() ; m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ mm=MEDFileCMesh() ; mm.setMesh(m) ; mm.setAxType(AX_CYL) #<- important
+ mm.setFamilyFieldArr(0,d1) ; mm.setFamilyFieldArr(1,d0)
+ mm.setName("a") ; mm.setDescription("b") ; mm.setTime(3,4,5.) ; mm.addFamily("c",-4) ; mm.setFamiliesOnGroup("d",["c"]) ; mm.setTimeUnit("ms")
+ mm2=mm.cartesianize() # the trigger
+ self.assertTrue(isinstance(mm2,MEDFileCurveLinearMesh))
+ self.assertEqual(mm2.getMesh().getNodeGridStructure(),mm.getMesh().getNodeGridStructure())
+ self.assertEqual(mm2.getName(),mm.getName())
+ self.assertEqual(mm2.getDescription(),mm.getDescription())
+ self.assertEqual(mm2.getTime(),mm.getTime())
+ self.assertEqual(mm2.getTime(),mm.getTime())
+ self.assertEqual(mm2.getTimeUnit(),mm.getTimeUnit())
+ self.assertEqual(mm2.getGroupsNames(),mm.getGroupsNames())
+ self.assertEqual(mm2.getFamiliesNames(),mm.getFamiliesNames())
+ self.assertEqual([mm2.getFamilyId(elt) for elt in mm2.getFamiliesNames()],[mm.getFamilyId(elt2) for elt2 in mm.getFamiliesNames()])
+ self.assertEqual(mm.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer())
+ self.assertEqual(mm2.getFamilyFieldAtLevel(0).getHiddenCppPointer(),d1.getHiddenCppPointer()) # <- here very important
+ self.assertEqual(mm.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer())
+ self.assertEqual(mm2.getFamilyFieldAtLevel(1).getHiddenCppPointer(),d0.getHiddenCppPointer()) # <- here very important
+ # CMesh cart
+ mm.setAxType(AX_CART)
+ mm2=mm.cartesianize() # the trigger
+ self.assertTrue(isinstance(mm2,MEDFileCMesh))
+ self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
+ pass
+