+
+ 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.computeCellCenterOfMass()[:,2]
+ grp1=bary1.findIdsInRange(hauteur-1e-12,hauteur+1e-12) ; grp1.setName(grpName1)
+ grp2=bary1.findIdsInRange(0.-1e-12,0.+1e-12) ; grp2.setName(grpName2)
+ mesh.setGroupsAtLevel(-1,[grp1,grp2])
+
+ st=pickle.dumps(mesh,2)
+ mm=pickle.loads(st)
+ st2=pickle.dumps(mm,2)
+ mm2=pickle.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.deepCopy()
+ 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) # <- normally 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()
+ 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())
+ mm.setAxisType(AX_CYL) #<- important
+ mm2=mm.cartesianize() # the trigger
+ self.assertEqual(mm2.getAxisType(),AX_CART)
+ mm.setAxisType(AX_CART) # this is here only to avoid complaints
+ 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.setAxisType(AX_CART)
+ mm2=mm.cartesianize() # the trigger
+ self.assertEqual(mm2.getAxisType(),AX_CART)
+ 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.setAxisType(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.assertEqual(mm2.getAxisType(),AX_CART)
+ 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.setAxisType(AX_CART)
+ mm2=mm.cartesianize() # the trigger
+ self.assertEqual(mm2.getAxisType(),AX_CART)
+ 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.setAxisType(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.assertEqual(mm2.getAxisType(),AX_CART)
+ 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.setAxisType(AX_CART)
+ mm2=mm.cartesianize() # the trigger
+ self.assertEqual(mm2.getAxisType(),AX_CART)
+ self.assertTrue(isinstance(mm2,MEDFileCMesh))
+ self.assertTrue(mm.getHiddenCppPointer()==mm2.getHiddenCppPointer()) # optimization
+ pass
+
+ def testCheckCoherency(self):
+ m2 = MEDCouplingUMesh("2d", 2)
+ m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
+ m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
+ m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
+ mum = MEDFileUMesh()
+ mum.setMeshAtLevel(0, m2)
+ mum.setMeshAtLevel(-1, m1)
+ mum.checkConsistency()
+ mum2 = mum.deepCopy()
+
+ # Nodes
+ arr = DataArrayInt([2]*4)
+ mum.setFamilyFieldArr(1, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ arr = DataArrayInt([2]*4)
+ mum.setRenumFieldArr(1, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ mum.setRenumFieldArr(1, DataArrayInt([2]*4))
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ arr = DataArrayAsciiChar(['tutu x']*4)
+ mum.setNameFieldAtLevel(1, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+
+ # 2D
+ mum=mum2; mum2=mum.deepCopy();
+ arr = DataArrayInt([2]*2)
+ mum.setFamilyFieldArr(0, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ arr = DataArrayInt([2]*2)
+ mum.setRenumFieldArr(0, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ mum.setRenumFieldArr(0, DataArrayInt([2]*2))
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ arr = DataArrayAsciiChar(['tutu x']*2)
+ mum.setNameFieldAtLevel(0, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+
+ # 1D
+ mum=mum2; mum2=mum.deepCopy();
+ arr = DataArrayInt([2]*5)
+ mum.setFamilyFieldArr(-1, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ arr = DataArrayInt([2]*5)
+ mum.setRenumFieldArr(-1, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ mum.setRenumFieldArr(-1, DataArrayInt([2]*5))
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+ mum=mum2; mum2=mum.deepCopy();
+ arr = DataArrayAsciiChar(['tutu x']*5)
+ mum.setNameFieldAtLevel(-1, arr); arr.reAlloc(35);
+ self.assertRaises(InterpKernelException, mum.checkConsistency)
+
+ def testCheckSMESHConsistency(self):
+ m2 = MEDCouplingUMesh("2d", 2)
+ m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
+ m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
+ m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
+ mum = MEDFileUMesh()
+ mum.setMeshAtLevel(0, m2)
+ mum.setMeshAtLevel(-1, m1)
+ mum.checkConsistency()
+ mum.checkSMESHConsistency()
+ n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
+ n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
+ mum.setRenumFieldArr(0, n2)
+ mum.setRenumFieldArr(-1, n1)
+ self.assertRaises(InterpKernelException, mum.checkSMESHConsistency)
+ mum.setRenumFieldArr(-1, n1+100)
+ mum.checkSMESHConsistency()
+ pass
+
+ def testClearNodeAndCellNumbers(self):
+ m2 = MEDCouplingUMesh("2d", 2)
+ m2.setCoords(DataArrayDouble([(0.0, 1.0)] * 4, 4,2)) # whatever
+ m2.setConnectivity(DataArrayInt([NORM_TRI3, 0,1,2,NORM_TRI3, 1,2,3]), DataArrayInt(([0,4,8])))
+ m1 , _, _ , _, _ = m2.buildDescendingConnectivity()
+ mum = MEDFileUMesh()
+ mum.setMeshAtLevel(0, m2)
+ mum.setMeshAtLevel(-1, m1)
+ mum.checkConsistency()
+ n2 = DataArrayInt(m2.getNumberOfCells(), 1); n2.iota(1)
+ n1 = DataArrayInt(m1.getNumberOfCells(), 1); n1.iota(1)
+ mum.setRenumFieldArr(0, n2)
+ mum.setRenumFieldArr(-1, n1)
+ mum.clearNodeAndCellNumbers()
+ mum.checkSMESHConsistency()
+ pass
+
+ def testCMeshSetFamilyFieldArrNull(self):
+ meshName="mesh"
+ fname="Pyfile99.med"
+ arrX=DataArrayDouble([0,1,2,3])
+ arrY=DataArrayDouble([0,1,2])
+ m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m.setName(meshName)
+ mm=MEDFileCMesh() ; mm.setMesh(m)
+ famCellIds=DataArrayInt([0,-2,-2,-1,-2,0])
+ famNodeIds=DataArrayInt([0,0,0,3,4,1,2,7,2,1,0,0])
+ mm.setFamilyFieldArr(0,famCellIds)
+ mm.setFamilyFieldArr(1,famNodeIds)
+ mm.write(fname,2)
+ mm=MEDFileMesh.New(fname)
+ self.assertTrue(mm.getFamilyFieldAtLevel(0) is not None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(1) is not None)
+ mm.setFamilyFieldArr(0,None)#<- bug was here
+ mm.setFamilyFieldArr(1,None)#<- bug was here
+ self.assertTrue(mm.getFamilyFieldAtLevel(0) is None)
+ self.assertTrue(mm.getFamilyFieldAtLevel(1) is None)
+ mm3=mm.deepCopy()
+ self.assertTrue(mm3.getFamilyFieldAtLevel(0) is None)
+ self.assertTrue(mm3.getFamilyFieldAtLevel(1) is None)
+ mm.write(fname,2)
+ mm2=MEDFileMesh.New(fname)
+ self.assertTrue(mm2.getFamilyFieldAtLevel(0) is None)
+ self.assertTrue(mm2.getFamilyFieldAtLevel(1) is None)
+ pass
+
+ def testAppendFieldProfileOnIntField(self):
+ fname="Pyfile100.med"
+ arrX=DataArrayDouble([0,1,2,3])
+ arrY=DataArrayDouble([0,1,2])
+ mesh=MEDCouplingCMesh() ; mesh.setCoords(arrX,arrY) ; mesh.setName("Mesh")
+ mm=MEDFileCMesh()
+ mm.setMesh(mesh)
+ #
+ fmts=MEDFileIntFieldMultiTS()
+ pflName="PFL"
+ pfl=DataArrayInt([1,3,5]) ; pfl.setName(pflName)
+ f=MEDCouplingFieldInt(ON_CELLS) ; f.setMesh(mesh)
+ fieldName="FieldOnCell"
+ f.setTime(1.2,1,1) ; f.setName(fieldName)
+ arr=DataArrayInt([101,102,103]) ; f.setArray(arr)
+ fmts.appendFieldProfile(f,mm,0,pfl)
+ #
+ mm.write(fname,2)
+ fmts.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname)
+ fmts=MEDFileAnyTypeFieldMultiTS.New(fname)
+ self.assertTrue(isinstance(fmts,MEDFileIntFieldMultiTS))
+ self.assertEqual(fmts.getName(),fieldName)
+ self.assertEqual(len(fmts),1)
+ f1ts=fmts[0]
+ ftest,pfltest=f1ts.getFieldWithProfile(ON_CELLS,0,mm)
+ self.assertEqual(pfltest.getName(),pflName)
+ self.assertEqual(ftest.getName(),fieldName)
+ self.assertTrue(ftest.isEqualWithoutConsideringStr(arr))
+ ftest2=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mm)
+ self.assertTrue(ftest2.getArray().isEqualWithoutConsideringStr(arr))
+ self.assertEqual(ftest2.getTime(),f.getTime())
+ self.assertEqual(ftest2.getMesh().getNumberOfCells(),len(arr))
+ pass
+
+ def testMEDFileFieldEasyField1(self):
+ """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."""
+ ## Basic test on cells on top level
+ fname="Pyfile101.med"
+ fieldName="field1"
+ mm=MEDFileUMesh()
+ coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI3,[0,1,2])
+ m.insertNextCell(NORM_TRI3,[3,4,5])
+ m.insertNextCell(NORM_TRI3,[6,7,8])
+ m.insertNextCell(NORM_TRI3,[9,10,11])
+ m.insertNextCell(NORM_QUAD4,[100,101,102,103])
+ m.insertNextCell(NORM_QUAD4,[104,105,106,107])
+ mm[0]=m
+ mm.write(fname,2)
+ arr0=DataArrayDouble([10,11,12,13,100,101])
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
+ f.setName(fieldName) ; f.setTime(2.,6,7)
+ f0=f.deepCopy()
+ ff=MEDFileFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
+ ff.write(fname,0)
+ arr2=arr0+1000 ; f.setArray(arr2)
+ f.setTime(3.,8,9) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f)
+ ff.write(fname,0)
+ f1=f.deepCopy()
+ ##
+ mm=MEDFileMesh.New(fname)
+ f1ts=MEDFileField1TS(fname,fieldName,6,7)
+ ftst0=f1ts.field(mm)
+ self.assertTrue(f0.isEqual(ftst0,1e-12,1e-12))
+ f1ts=MEDFileField1TS(fname,fieldName,8,9)
+ ftst1=f1ts.field(mm)
+ self.assertTrue(f1.isEqual(ftst1,1e-12,1e-12))
+ fmts=MEDFileFieldMultiTS(fname,fieldName)
+ self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,1e-12))
+ ## Basic test on nodes on top level
+ f2=MEDCouplingFieldDouble(ON_NODES) ; arr2=DataArrayDouble([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
+ f2.setName(fieldName)
+ mm.write(fname,2)
+ ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname)
+ f1ts=MEDFileField1TS(fname,fieldName,23,24)
+ self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,1e-12))
+ fmts=MEDFileFieldMultiTS(fname,fieldName)
+ self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,1e-12))
+ ## Node on elements
+ 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)
+ f3.setName(fieldName) ; f3.checkConsistencyLight()
+ mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname)
+ f1ts=MEDFileField1TS(fname,fieldName,2,3)
+ self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
+ ## Gauss
+ f4=MEDCouplingFieldDouble(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
+ 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])
+ 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)
+ 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)
+ f4.checkConsistencyLight()
+ mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname)
+ f1ts=MEDFileField1TS(fname,fieldName,4,5)
+ self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
+ pass
+
+ def testMEDFileFieldEasyField2(self):
+ """Same thantestMEDFileFieldEasyField1 except that here intfields are considered.
+ 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."""
+ ## Basic test on cells on top level
+ fname="Pyfile102.med"
+ fieldName="field1"
+ mm=MEDFileUMesh()
+ coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI3,[0,1,2])
+ m.insertNextCell(NORM_TRI3,[3,4,5])
+ m.insertNextCell(NORM_TRI3,[6,7,8])
+ m.insertNextCell(NORM_TRI3,[9,10,11])
+ m.insertNextCell(NORM_QUAD4,[100,101,102,103])
+ m.insertNextCell(NORM_QUAD4,[104,105,106,107])
+ mm[0]=m
+ mm.write(fname,2)
+ arr0=DataArrayInt([10,11,12,13,100,101])
+ f=MEDCouplingFieldInt(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m)
+ f.setName(fieldName) ; f.setTime(2.,6,7)
+ f0=f.deepCopy()
+ ff=MEDFileIntFieldMultiTS() ; ff.appendFieldNoProfileSBT(f)
+ ff.write(fname,0)
+ arr2=arr0+1000 ; f.setArray(arr2)
+ f.setTime(3.,8,9) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f)
+ ff.write(fname,0)
+ f1=f.deepCopy()
+ ##
+ mm=MEDFileMesh.New(fname)
+ f1ts=MEDFileIntField1TS(fname,fieldName,6,7)
+ ftst0=f1ts.field(mm)
+ self.assertTrue(f0.isEqual(ftst0,1e-12,0))
+ f1ts=MEDFileIntField1TS(fname,fieldName,8,9)
+ ftst1=f1ts.field(mm)
+ self.assertTrue(f1.isEqual(ftst1,1e-12,0))
+ fmts=MEDFileIntFieldMultiTS(fname,fieldName)
+ self.assertTrue(f1.isEqual(fmts.field(8,9,mm),1e-12,0))
+ ## Basic test on nodes on top level
+ f2=MEDCouplingFieldInt(ON_NODES) ; arr2=DataArrayInt([200,201,202]) ; arr2.setInfoOnComponent(0,"tutu") ; f2.setArray(arr2) ; f2.setMesh(m) ; f2.setTime(22.,23,24)
+ f2.setName(fieldName)
+ mm.write(fname,2)
+ ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f2) ; ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname)
+ f1ts=MEDFileIntField1TS(fname,fieldName,23,24)
+ self.assertTrue(f2.isEqual(f1ts.field(mm),1e-12,0))
+ fmts=MEDFileIntFieldMultiTS(fname,fieldName)
+ self.assertTrue(f2.isEqual(fmts.field(23,24,mm),1e-12,0))
+ ## Node on elements
+ f3=MEDCouplingFieldInt(ON_GAUSS_NE) ; f3.setMesh(m) ; arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
+ f3.setName(fieldName) ; f3.checkConsistencyLight()
+ mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname)
+ f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
+ self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
+ ## Gauss
+ f4=MEDCouplingFieldInt(ON_GAUSS_PT) ; f4.setMesh(m) ; f4.setName(fieldName)
+ 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])
+ 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)
+ arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
+ f4.checkConsistencyLight()
+ mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname)
+ f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
+ self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
+ pass
+
+ def testMEDFileFieldEasyField3(self):
+ """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."""
+ fname="Pyfile103.med"
+ fieldName="field1"
+ mm=MEDFileUMesh()
+ coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI3,[0,1,2])
+ m.insertNextCell(NORM_TRI3,[3,4,5])
+ m.insertNextCell(NORM_TRI3,[6,7,8])
+ m.insertNextCell(NORM_TRI3,[9,10,11])
+ m.insertNextCell(NORM_QUAD4,[100,101,102,103])
+ m.insertNextCell(NORM_QUAD4,[104,105,106,107])
+ mm[-1]=m
+ m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
+ m0.allocateCells()
+ m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
+ m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
+ mm[0]=m0
+ mm.write(fname,2)
+ # start slowly
+ f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
+ f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,1,2)
+ self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
+ # here f1 lying on level -1 not 0 check if "field" method detect it !
+ f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayDouble([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
+ f1.setMesh(mm[-1]) # -1 is very important
+ f1.setTime(16.,3,4)
+ f1.checkConsistencyLight()
+ mm.write(fname,2)
+ f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,3,4)
+ self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,1e-12))
+ # nodes on elements
+ f3=MEDCouplingFieldDouble(ON_GAUSS_NE)
+ f3.setMesh(mm[-1]) # this line is important
+ 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)
+ f3.setName(fieldName) ; f3.checkConsistencyLight()
+ mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,2,3)
+ self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,1e-12))
+ # gauss
+ f4=MEDCouplingFieldDouble(ON_GAUSS_PT)
+ f4.setMesh(mm[-1]) # this line is important
+ f4.setName(fieldName)
+ 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])
+ 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)
+ 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)
+ f4.checkConsistencyLight()
+ mm.write(fname,2) ; ff=MEDFileField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,4,5)
+ self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,1e-12))
+ pass
+
+ def testMEDFileFieldEasyField4(self):
+ """ Same than testMEDFileFieldEasyField3 but with integers"""
+ fname="Pyfile104.med"
+ fieldName="field1"
+ mm=MEDFileUMesh()
+ coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI3,[0,1,2])
+ m.insertNextCell(NORM_TRI3,[3,4,5])
+ m.insertNextCell(NORM_TRI3,[6,7,8])
+ m.insertNextCell(NORM_TRI3,[9,10,11])
+ m.insertNextCell(NORM_QUAD4,[100,101,102,103])
+ m.insertNextCell(NORM_QUAD4,[104,105,106,107])
+ mm[-1]=m
+ m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
+ m0.allocateCells()
+ m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
+ m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
+ mm[0]=m0
+ mm.write(fname,2)
+ # start slowly
+ f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101)])) ; f1.setMesh(mm[0]) ; f1.setTime(4.,1,2)
+ f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,1,2)
+ self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
+ # here f1 lying on level -1 not 0 check if "field" method detect it !
+ f1=MEDCouplingFieldInt(ON_CELLS) ; f1.setName(fieldName) ; f1.setArray(DataArrayInt([(0,100),(1,101),(0,100),(1,101),(0,100),(1,101)]))
+ f1.setMesh(mm[-1]) # -1 is very important
+ f1.setTime(16.,3,4)
+ f1.checkConsistencyLight()
+ mm.write(fname,2)
+ f1ts=MEDFileIntField1TS() ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,3,4)
+ self.assertTrue(f1.isEqual(f1ts.field(mm),1e-12,0))
+ # nodes on elements
+ f3=MEDCouplingFieldInt(ON_GAUSS_NE)
+ f3.setMesh(mm[-1]) # this line is important
+ arr3=DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]) ; f3.setArray(arr3) ; f3.setTime(0.5,2,3)
+ f3.setName(fieldName) ; f3.checkConsistencyLight()
+ mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f3) ; ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,2,3)
+ self.assertTrue(f3.isEqual(f1ts.field(mm),1e-12,0))
+ # gauss
+ f4=MEDCouplingFieldInt(ON_GAUSS_PT)
+ f4.setMesh(mm[-1]) # this line is important
+ f4.setName(fieldName)
+ 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])
+ 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)
+ arr4=DataArrayInt([0,1,2,3,4 ,10,11,12,13,14, 20,21,22,23,24, 30,31,32,33,34, 45,46, 55,56]) ; arr4.setInfoOnComponent(0,"abc") ; f4.setArray(arr4)
+ f4.checkConsistencyLight()
+ mm.write(fname,2) ; ff=MEDFileIntField1TS() ; ff.setFieldNoProfileSBT(f4) ; ff.write(fname,0)
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileIntField1TS(fname,fieldName,4,5)
+ self.assertTrue(f4.isEqual(f1ts.field(mm),1e-12,0))
+ pass
+
+ def testMEDFileFieldEasyField5(self):
+ """More and more difficult now look at how profiles are managed by "field" method."""
+ fname="Pyfile105.med"
+ fieldName="field1"
+ mm=MEDFileUMesh()
+ coo=DataArrayDouble([(3,2,1),(8,7,6),(5,9,10)])
+ m=MEDCouplingUMesh("mesh",2) ; m.setCoords(coo)
+ m.allocateCells()
+ m.insertNextCell(NORM_TRI3,[0,1,2])
+ m.insertNextCell(NORM_TRI3,[3,4,5])
+ m.insertNextCell(NORM_TRI3,[6,7,8])
+ m.insertNextCell(NORM_TRI3,[9,10,11])
+ m.insertNextCell(NORM_QUAD4,[100,101,102,103])
+ m.insertNextCell(NORM_QUAD4,[104,105,106,107])
+ mm[0]=m
+ mm.write(fname,2)
+ pfl=DataArrayInt([0,2,3,5]) ; pfl.setName("pfl")
+ m2=m.deepCopy()[pfl] ; m2.setName(m.getName())
+ #
+ arr0=DataArrayDouble([10,11,12,13])
+ f=MEDCouplingFieldDouble(ON_CELLS) ; f.setArray(arr0) ; f.setMesh(m2)
+ f.setName(fieldName) ; f.setTime(2.,6,7) ; f.checkConsistencyLight()
+ ff=MEDFileFieldMultiTS() ; ff.appendFieldProfile(f,mm,0,pfl) # ff is a field on profile
+ ff.write(fname,0)
+ #
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
+ self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
+ # more complicated -> multi level
+ m0=MEDCouplingUMesh("mesh",3) ; m0.setCoords(coo)
+ m0.allocateCells()
+ m0.insertNextCell(NORM_TETRA4,[3,2,5,0])
+ m0.insertNextCell(NORM_TETRA4,[7,6,3,2])
+ mm2=MEDFileUMesh()
+ mm2[0]=m0 ; mm2[-1]=m
+ #
+ ff=MEDFileField1TS() ; ff.setFieldProfile(f,mm2,-1,pfl)
+ #
+ mm=MEDFileMesh.New(fname) ; f1ts=MEDFileField1TS(fname,fieldName,6,7)
+ self.assertTrue(f.isEqual(f1ts.field(mm),1e-12,1e-12))
+ pass
+
+ def testExtractPart1(self):
+ 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)])
+ meshName="mesh"
+ m0=MEDCouplingUMesh(meshName,2) ; m0.setCoords(coo) ; m0.allocateCells()
+ m0.insertNextCell(NORM_TRI3,[8,4,3])
+ m0.insertNextCell(NORM_TRI3,[8,9,4])
+ m0.insertNextCell(NORM_TRI3,[7,13,8])
+ m0.insertNextCell(NORM_TRI3,[7,12,13])
+ m0.insertNextCell(NORM_TRI3,[0,6,1])
+ m0.insertNextCell(NORM_TRI3,[0,5,6])
+ m0.insertNextCell(NORM_QUAD4,[1,6,7,2])
+ m0.insertNextCell(NORM_QUAD4,[2,7,8,3])
+ m0.insertNextCell(NORM_QUAD4,[8,13,14,9])
+ m0.insertNextCell(NORM_QUAD4,[6,11,12,7])
+ m0.insertNextCell(NORM_QUAD4,[5,10,11,6])
+ #
+ m1=MEDCouplingUMesh(meshName,1) ; m1.setCoords(coo) ; m1.allocateCells()
+ m1.insertNextCell(NORM_SEG2,[10,5])
+ m1.insertNextCell(NORM_SEG2,[5,0])
+ m1.insertNextCell(NORM_SEG2,[0,1])
+ m1.insertNextCell(NORM_SEG2,[1,2])
+ m1.insertNextCell(NORM_SEG2,[2,3])
+ m1.insertNextCell(NORM_SEG2,[3,4])
+ m1.insertNextCell(NORM_SEG2,[4,9])
+ m1.insertNextCell(NORM_SEG2,[9,14])
+ m1.insertNextCell(NORM_SEG2,[14,13])
+ m1.insertNextCell(NORM_SEG2,[13,12])
+ m1.insertNextCell(NORM_SEG2,[12,11])
+ m1.insertNextCell(NORM_SEG2,[11,10])
+ mm=MEDFileUMesh()
+ mm[0]=m0 ; mm[-1]=m1
+ arr0=DataArrayInt([0,1,2,3,4,6,7,8,12,13])
+ tab={} #
+ tab[0]=DataArrayInt([0,2,3,4,6,7])
+ tab[-1]=DataArrayInt([2,3,4,5,9])
+ fs=MEDFileFields()
+ self.assertTrue(mm.deduceNodeSubPartFromCellSubPart(tab).isEqual(arr0))
+ tab[1]=arr0
+ #
+ fname0="Field0"
+ fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
+ t0=(16.5,3,4)
+ ic=["toto [m]"]
+ arr0_0=DataArrayDouble([100,101,102,103,104,105,106,107,108,109,110]) ; arr0_0.setInfoOnComponents(ic)
+ f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*t0) ; f0.setArray(arr0_0)
+ f0.setMesh(m0) ; f0.setName(fname0)
+ f1=MEDCouplingFieldDouble(ON_CELLS) ; f1.setTime(*t0) ; f1.setArray(DataArrayDouble([200,201,202,203,204,205,206,207,208,209,210,211]))
+ f1.setMesh(m1) ; f1.setName(fname0) ; f1.getArray().setInfoOnComponents(ic)
+ 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]))
+ f2.setMesh(m0) ; f2.setName(fname0) ; f2.getArray().setInfoOnComponents(ic)
+ f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; f1ts.setFieldNoProfileSBT(f1) ; f1ts.setFieldNoProfileSBT(f2)
+ fmts.pushBackTimeStep(f1ts)
+ #
+ mmOut=mm.extractPart(tab)
+ #
+ fsPart0=fs.extractPart(tab,mm)
+ self.assertEqual(len(fsPart0),1)
+ fmtsP=fsPart0[0]
+ self.assertEqual(len(fmtsP),1)
+ f1ts=fmtsP[0]
+ self.assertRaises(InterpKernelException,f1ts.field,mmOut)
+ #
+ self.assertTrue(mmOut[0].computeCellCenterOfMass().isEqual(m0[tab[0]].computeCellCenterOfMass(),1e-12))
+ self.assertTrue(mmOut[-1].computeCellCenterOfMass().isEqual(m1[tab[-1]].computeCellCenterOfMass(),1e-12))
+ #
+ m0Part=m0.deepCopy()[tab[0]] ; m0Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m0Part.setName(m0.getName())
+ self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
+ m1Part=m1.deepCopy()[tab[-1]] ; m1Part.renumberNodes(tab[1].invertArrayN2O2O2N(mm.getNumberOfNodes()),len(tab[1])) ; m1Part.setName(m0.getName())
+ self.assertTrue(mmOut[0].isEqual(m0Part,1e-12))
+ self.assertTrue(mmOut[-1].isEqual(m1Part,1e-12))
+ #
+ f0Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,0,mmOut) ; f0Part.checkConsistencyLight()
+ self.assertEqual(f0Part.getTypeOfField(),ON_CELLS)
+ self.assertTrue(f0Part.getMesh().isEqual(m0Part,1e-12))
+ arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic)
+ self.assertTrue(f0Part.getArray().isEqual(arr0Exp,1e-12)) ; self.assertEqual(f0Part.getTime(),list(t0))
+ f1Part=f1ts.getFieldOnMeshAtLevel(ON_CELLS,-1,mmOut) ; f1Part.checkConsistencyLight()
+ self.assertEqual(f1Part.getTypeOfField(),ON_CELLS)
+ self.assertTrue(f1Part.getMesh().isEqual(m1Part,1e-12))
+ arr1Exp=DataArrayDouble([202,203,204,205,209]) ; arr1Exp.setInfoOnComponents(ic)
+ self.assertTrue(f1Part.getArray().isEqual(arr1Exp,1e-12)) ; self.assertEqual(f1Part.getTime(),list(t0))
+ #
+ f2Part=f1ts.getFieldOnMeshAtLevel(ON_NODES,0,mmOut) ; f2Part.checkConsistencyLight()
+ arr2Exp=DataArrayDouble([300,301,302,303,304,306,307,308,312,313]) ; arr2Exp.setInfoOnComponents(ic)
+ self.assertTrue(f2Part.getArray().isEqual(arr2Exp,1e-12)) ; self.assertEqual(f2Part.getTime(),list(t0))
+ # multisteps
+ fs=MEDFileFields() ; fmts=MEDFileFieldMultiTS() ; fs.pushField(fmts)
+ tss=[(16.5,3,4),(17.5,4,5),(18.5,5,6)]
+ for i,tt in enumerate(tss):
+ f0=MEDCouplingFieldDouble(ON_CELLS) ; f0.setTime(*tt)
+ myarr=arr0_0+i*1000.
+ f0.setArray(myarr)
+ f0.setMesh(m0) ; f0.setName(fname0) ; f0.getArray().setInfoOnComponents(ic)
+ f1ts=MEDFileField1TS() ; f1ts.setFieldNoProfileSBT(f0) ; fmts.pushBackTimeStep(f1ts)
+ pass
+ fsPart1=fs.extractPart(tab,mm)
+ self.assertEqual(len(fsPart1),1)
+ fmtsP=fsPart1[0]
+ self.assertEqual(len(fmtsP),len(tss))
+ for i,(f1tsP,tt) in enumerate(zip(fmtsP,tss)):
+ fPart=f1tsP.field(mmOut) ; fPart.checkConsistencyLight()
+ self.assertEqual(fPart.getTypeOfField(),ON_CELLS)
+ arr0Exp=DataArrayDouble([100,102,103,104,106,107]) ; arr0Exp.setInfoOnComponents(ic) ; arr0Exp+=i*1000.
+ self.assertTrue(fPart.getMesh().isEqual(m0Part,1e-12))
+ self.assertTrue(fPart.getArray().isEqual(arr0Exp,1e-12))
+ self.assertEqual(fPart.getTime(),list(tt))
+ pass
+ pass
+
+ def testSymmetryPlusAggregationMFD1(self):
+ """ Testing of MEDFileData::Aggregate and MEDFileUMesh::Aggregate and MEDFileUMesh::getAllDistributionOfType """
+ fname1="Pyfile106_1.med"
+ fname2="Pyfile106_2.med"
+ fname3="Pyfile106_3.med"
+ meshName="mesh"
+ mm1=MEDFileUMesh()
+ da1=DataArrayDouble([1,2,10,3,4,11,5,6,12,7,8,13],4,3) ; da1.setInfoOnComponents(["aa [m]","bbb [kg]","cccc [MW]"])
+ mm1.setCoords(da1)
+ mm1_0=MEDCouplingUMesh(meshName,3) ; mm1_0.allocateCells()
+ mm1_0.setCoords(da1)
+ mm1_0.insertNextCell(NORM_TETRA4,[0,1,2,3])
+ mm1_0.insertNextCell(NORM_TETRA4,[4,5,6,7])
+ mm1_0.insertNextCell(NORM_PENTA6,[8,9,10,11,12,13])
+ mm1_0.insertNextCell(NORM_PENTA6,[14,15,16,17,18,19])
+ mm1_0.insertNextCell(NORM_PENTA6,[20,21,22,23,24,25])
+ mm1[0]=mm1_0
+ mm1.setFamilyFieldArr(0,DataArrayInt([1,2,3,4,5]))
+ mm1.setRenumFieldArr(0,DataArrayInt([11,12,13,14,15]))
+ #
+ mm1_1=MEDCouplingUMesh(meshName,2) ; mm1_1.allocateCells()
+ mm1_1.setCoords(da1)
+ mm1_1.insertNextCell(NORM_TRI3,[0,1,2])
+ mm1_1.insertNextCell(NORM_TRI3,[3,4,5])
+ mm1_1.insertNextCell(NORM_QUAD4,[6,7,8,9])
+ mm1_1.insertNextCell(NORM_QUAD4,[10,11,12,13])
+ mm1_1.insertNextCell(NORM_QUAD4,[14,15,16,17])
+ mm1_1.insertNextCell(NORM_QUAD4,[18,19,20,21])
+ mm1[-1]=mm1_1
+ mm1.setFamilyFieldArr(-1,DataArrayInt([6,7,8,9,10,11]))
+ mm1.setRenumFieldArr(-1,DataArrayInt([16,17,18,19,20,21]))
+ for i in range(1,10):
+ mm1.setFamilyId("F%d"%i,i)
+ mm1.setFamilyId("FAMILLE_ZERO",0)
+ mm1.setFamilyId("H1",100)
+ mm1.setFamiliesOnGroup("myGRP",["F2","F6"])
+ mm1.setFamiliesOnGroup("myGRP1",["F2","F6"])
+ mm1.setFamilyFieldArr(1,DataArrayInt([12,13,14,15]))
+ mm1.setRenumFieldArr(1,DataArrayInt([22,23,24,25]))
+ ##############
+ mm2=MEDFileUMesh()
+ 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]"])
+ mm2.setCoords(da1)
+ mm2_0=MEDCouplingUMesh(meshName,3) ; mm2_0.allocateCells()
+ mm2_0.setCoords(da1)
+ mm2_0.insertNextCell(NORM_TETRA4,[100,101,102,103])
+ mm2_0.insertNextCell(NORM_TETRA4,[104,105,106,107])
+ mm2_0.insertNextCell(NORM_TETRA4,[108,109,110,111])
+ mm2_0.insertNextCell(NORM_PENTA6,[112,113,114,115,116,117])
+ mm2[0]=mm2_0
+ mm2.setFamilyFieldArr(0,DataArrayInt([40,41,42,43]))
+ mm2.setRenumFieldArr(0,DataArrayInt([50,51,52,53]))
+ #
+ mm2_1=MEDCouplingUMesh(meshName,2) ; mm2_1.allocateCells()
+ mm2_1.setCoords(da1)
+ mm2_1.insertNextCell(NORM_TRI3,[100,101,102])
+ mm2_1.insertNextCell(NORM_TRI3,[103,104,105])
+ mm2_1.insertNextCell(NORM_TRI3,[106,107,108])
+ mm2_1.insertNextCell(NORM_QUAD4,[109,110,111,112])
+ mm2_1.insertNextCell(NORM_QUAD4,[113,114,115,116])
+ mm2_1.insertNextCell(NORM_QUAD4,[117,118,119,120])
+ mm2_1.insertNextCell(NORM_QUAD4,[121,122,123,124])
+ mm2_1.insertNextCell(NORM_QUAD4,[125,126,127,128])
+ mm2[-1]=mm2_1
+ mm2.setFamilyFieldArr(-1,DataArrayInt([200,201,202,203,204,205,206,207]))
+ mm2.setRenumFieldArr(-1,DataArrayInt([300,301,302,303,304,305,306,307]))
+ for i in range(1,12):
+ mm2.setFamilyId("G%d"%i,i+30)
+ mm2.setFamilyId("H1",100)
+ mm2.setFamilyId("FAMILLE_ZERO",0)
+ mm2.setFamiliesOnGroup("myGRP",["G2","G6"])
+ mm2.setFamiliesOnGroup("myGRP2",["G4","G7"])
+ mm2.setFamilyFieldArr(1,DataArrayInt([112,113,114,115,116]))
+ mm2.setRenumFieldArr(1,DataArrayInt([122,123,124,125,126]))
+ #
+ mm=MEDFileUMesh.Aggregate([mm1,mm2])
+ #######
+ def CheckMesh(tester,mm):
+ 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]"])
+ tester.assertTrue(mm.getCoords().isEqual(cooExp,1e-12))
+ 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])))
+ tester.assertTrue(mm[0].getNodalConnectivityIndex().isEqual(DataArrayInt([0,5,10,15,20,25,32,39,46,53])))
+ 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])))
+ tester.assertTrue(mm[-1].getNodalConnectivityIndex().isEqual(DataArrayInt([0,4,8,12,16,20,25,30,35,40,45,50,55,60,65])))
+ tester.assertTrue(mm.getFamilyFieldAtLevel(0).isEqual(DataArrayInt([1,2,40,41,42,3,4,5,43])))
+ tester.assertTrue(mm.getNumberFieldAtLevel(0).isEqual(DataArrayInt([11,12,50,51,52,13,14,15,53])))
+ tester.assertTrue(mm.getFamilyFieldAtLevel(-1).isEqual(DataArrayInt([6,7,200,201,202,8,9,10,11,203,204,205,206,207])))
+ tester.assertTrue(mm.getNumberFieldAtLevel(-1).isEqual(DataArrayInt([16,17,300,301,302,18,19,20,21,303,304,305,306,307])))
+ 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)]
+ tester.assertEqual(set(mm.getFamiliesNames()),set([elt[0] for elt in refFamIds]))
+ tester.assertEqual(set([mm.getFamilyId(elt) for elt in mm.getFamiliesNames()]),set([elt[1] for elt in refFamIds]))
+ tester.assertEqual(mm.getGroupsNames(),('myGRP','myGRP1','myGRP2'))
+ tester.assertEqual(mm.getAllDistributionOfTypes(),[(NORM_TRI3,5),(NORM_QUAD4,9),(NORM_TETRA4,5),(NORM_PENTA6,4),(NORM_ERROR,9)])
+ pass
+ CheckMesh(self,mm)
+ ##
+ fieldName="zeField"
+ t1=(2.3,3,5)
+ t2=(5.6,7,12)
+ infoc=["dd [W]","eee [kA]"]
+ ##
+ fmts1=MEDFileFieldMultiTS()
+ f1ts1=MEDFileField1TS()
+ f1_1=MEDCouplingFieldDouble(ON_CELLS) ; f1_1.setMesh(mm1[0]) ; f1_1.setName(fieldName)
+ arr1=DataArrayDouble([(10,110),(11,111),(12,112),(13,113),(14,114)])
+ arr1.setInfoOnComponents(infoc)
+ f1_1.setArray(arr1) ; f1_1.setTime(*t1) ; f1_1.setTimeUnit("ms")
+ f1_1.checkConsistencyLight()
+ f1ts1.setFieldNoProfileSBT(f1_1)
+ #
+ f1_2=MEDCouplingFieldDouble(ON_CELLS) ; f1_2.setMesh(mm1[-1]) ; f1_2.setName(fieldName)
+ arr2=DataArrayDouble([(15,115),(16,116),(17,117),(18,118),(19,119),(20,120)])
+ arr2.setInfoOnComponents(infoc)
+ f1_2.setArray(arr2) ; f1_2.setTime(*t1) ; f1_2.setTimeUnit("ms")
+ f1_2.checkConsistencyLight()
+ f1ts1.setFieldNoProfileSBT(f1_2)
+ f1_3=MEDCouplingFieldDouble(ON_NODES) ; f1_3.setMesh(mm1[0]) ; f1_3.setName(fieldName)
+ arr3=DataArrayDouble([(21,121),(22,122),(23,123),(24,124)])
+ arr3.setInfoOnComponents(infoc)
+ f1_3.setArray(arr3) ; f1_3.setTime(*t1) ; f1_3.setTimeUnit("ms")
+ f1_3.checkConsistencyLight()
+ f1ts1.setFieldNoProfileSBT(f1_3)
+ fmts1.pushBackTimeStep(f1ts1)
+ #
+ f1ts2=f1ts1.deepCopy()
+ f1ts2.setTime(t2[1],t2[2],t2[0])
+ f1ts2.getUndergroundDataArray()[:]+=2000
+ fmts1.pushBackTimeStep(f1ts2)
+ ### fmts2
+ fmts2=MEDFileFieldMultiTS()
+ f1ts3=MEDFileField1TS()
+ f2_1=MEDCouplingFieldDouble(ON_CELLS) ; f2_1.setMesh(mm2[0]) ; f2_1.setName(fieldName)
+ arr4=DataArrayDouble([(50,150),(51,151),(52,152),(53,153)])
+ arr4.setInfoOnComponents(infoc)
+ f2_1.setArray(arr4) ; f2_1.setTime(*t1) ; f2_1.setTimeUnit("ms")
+ f2_1.checkConsistencyLight()
+ f1ts3.setFieldNoProfileSBT(f2_1)
+ f2_2=MEDCouplingFieldDouble(ON_CELLS) ; f2_2.setMesh(mm2[-1]) ; f2_2.setName(fieldName)
+ arr5=DataArrayDouble([(54,154),(55,155),(56,156),(57,157),(158,158),(59,159),(60,160),(61,161)])
+ arr5.setInfoOnComponents(infoc)
+ f2_2.setArray(arr5) ; f2_2.setTime(*t1) ; f2_2.setTimeUnit("ms")
+ f2_2.checkConsistencyLight()
+ f1ts3.setFieldNoProfileSBT(f2_2)
+ f2_3=MEDCouplingFieldDouble(ON_NODES) ; f2_3.setMesh(mm2[0]) ; f2_3.setName(fieldName)
+ arr6=DataArrayDouble([(62,162),(63,163),(64,164),(65,165),(66,166)])
+ arr6.setInfoOnComponents(infoc)
+ f2_3.setArray(arr6) ; f2_3.setTime(*t1) ; f2_3.setTimeUnit("ms")
+ f2_3.checkConsistencyLight()
+ f1ts3.setFieldNoProfileSBT(f2_3)
+ fmts2.pushBackTimeStep(f1ts3)
+ #
+ f1ts4=f1ts3.deepCopy()
+ f1ts4.setTime(t2[1],t2[2],t2[0])
+ f1ts4.getUndergroundDataArray()[:]+=2000
+ fmts2.pushBackTimeStep(f1ts4)
+ #
+ mfd1=MEDFileData()
+ mfd1.setMeshes(MEDFileMeshes())
+ mfd1.getMeshes().pushMesh(mm1)
+ mfd1.setFields(MEDFileFields())
+ mfd1.getFields().pushField(fmts1)
+ #
+ mfd2=MEDFileData()
+ mfd2.setMeshes(MEDFileMeshes())
+ mfd2.getMeshes().pushMesh(mm2)
+ mfd2.setFields(MEDFileFields())
+ mfd2.getFields().pushField(fmts2)
+ # ze Call !
+ mfd=MEDFileData.Aggregate([mfd1,mfd2])
+ def CheckMFD(tester,mfd):
+ tester.assertEqual(len(mfd.getMeshes()),1)
+ tester.assertEqual(len(mfd.getFields()),1)
+ CheckMesh(self,mfd.getMeshes()[0])
+ tester.assertEqual(len(mfd.getFields()[0]),2)
+ zeF1=mfd.getFields()[0][0]
+ zeF1_1=zeF1.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
+ ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
+ o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
+ ref.renumberCells(o2n)
+ tester.assertTrue(ref.isEqual(zeF1_1,1e-12,1e-12))
+ zeF1_2=zeF1.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
+ ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
+ o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
+ ref.renumberCells(o2n)
+ tester.assertTrue(ref.isEqual(zeF1_2,1e-12,1e-12))
+ zeF1_3=zeF1.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
+ ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
+ o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
+ ref.renumberCells(o2n)
+ tester.assertTrue(ref.isEqual(zeF1_3,1e-12,1e-12))
+ #
+ zeF2=mfd.getFields()[0][1]
+ zeF2_1=zeF2.getFieldOnMeshAtLevel(ON_CELLS,0,mfd.getMeshes()[0])
+ ref=MEDCouplingFieldDouble.MergeFields([f1_1,f2_1])
+ o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
+ ref.renumberCells(o2n)
+ ref.setTime(*t2) ; ref.getArray()[:]+=2000
+ tester.assertTrue(ref.isEqual(zeF2_1,1e-12,1e-12))
+ zeF2_2=zeF2.getFieldOnMeshAtLevel(ON_CELLS,-1,mfd.getMeshes()[0])
+ ref=MEDCouplingFieldDouble.MergeFields([f1_2,f2_2])
+ o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
+ ref.renumberCells(o2n)
+ ref.setTime(*t2) ; ref.getArray()[:]+=2000
+ tester.assertTrue(ref.isEqual(zeF2_2,1e-12,1e-12))
+ zeF2_3=zeF2.getFieldOnMeshAtLevel(ON_NODES,0,mfd.getMeshes()[0])
+ ref=MEDCouplingFieldDouble.MergeFields([f1_3,f2_3])
+ o2n=ref.getMesh().deepCopy().sortCellsInMEDFileFrmt()
+ ref.renumberCells(o2n)
+ ref.setTime(*t2) ; ref.getArray()[:]+=2000
+ tester.assertTrue(ref.isEqual(zeF2_3,1e-12,1e-12))
+ CheckMFD(self,mfd)
+ mfd1.write(fname1,2) ; mfd2.write(fname2,2)
+ mfd=MEDFileData.Aggregate([MEDFileData(fname1),MEDFileData(fname2)])
+ CheckMFD(self,mfd)
+ pass
+
+ def testExtrudedMesh1(self):
+ fname="Pyfile107.med"
+ arrX=DataArrayDouble([0,1,2,3]) ; arrY=DataArrayDouble([0,1,2,3,4]) ; arrZ=DataArrayDouble([0,1,2,3,4,5])
+ mesh3D=MEDCouplingCMesh() ; mesh3D.setCoords(arrX,arrY,arrZ) ; mesh3D.setName("mesh")
+ ex=MEDCouplingMappedExtrudedMesh(mesh3D)
+ mm=MEDFileUMesh(ex)
+ mm.write(fname,2)
+ ex2=mm.convertToExtrudedMesh()
+ mm2=MEDFileMesh.New(fname)
+ ex3=mm2.convertToExtrudedMesh()
+ self.assertTrue(ex.isEqual(ex2,1e-12))
+ self.assertTrue(ex.isEqual(ex3,1e-12))
+ pass
+
+ @unittest.skipUnless(LooseVersion(MEDFileVersionStr())>=LooseVersion('3.2.1'),"This test requires at least MEDFile version 3.2.1")
+ def testWriteInto30(self):
+ fname="Pyfile108.med"
+ fname2="Pyfile109.med"
+ m=MEDCouplingUMesh("mesh",1) ; m.setCoords(DataArrayDouble([0,0,1,1],2,2)) ; m.allocateCells() ; m.insertNextCell(NORM_SEG2,[1,0])
+ mm=MEDFileUMesh() ; mm[0]=m
+ mm.setFamilyId("FAMILLE_ZERO",0)
+ #
+ mm.write33(fname,2)
+ assert(LooseVersion(MEDFileVersionOfFileStr(fname)).version[:2]==[3,3]) # checks that just written MED file has a version == 3.0.x
+ mm2=MEDFileUMesh(fname)
+ self.assertTrue(mm.isEqual(mm2,1e-12))
+ #
+ mm.write(fname2,2)
+ 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
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def testPickelizationOfMEDFileObjects1(self):
+ fname="Pyfile110.med"
+ 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)
+ m0=MEDCouplingUMesh("Mesh",2)
+ m0.allocateCells(5)
+ m0.insertNextCell(NORM_TRI3,[1,4,2])
+ m0.insertNextCell(NORM_TRI3,[4,5,2])
+ m0.insertNextCell(NORM_QUAD4,[0,3,4,1])
+ m0.insertNextCell(NORM_QUAD4,[3,6,7,4])
+ m0.insertNextCell(NORM_QUAD4,[4,7,8,5])
+ m0.finishInsertingCells()
+ m0.setCoords(coo)
+ m1=MEDCouplingUMesh(m0.getName(),1)
+ m1.allocateCells(9)
+ conn1=[0,1,0,3,3,4,4,1,5,4,2,4,1,2,3,6,5,8]
+ for i in range(9):
+ m1.insertNextCell(NORM_SEG2,conn1[2*i:2*i+2])
+ pass
+ m1.finishInsertingCells()
+ m1.setCoords(coo)
+ #
+ m=MEDFileUMesh()
+ m.setMeshAtLevel(0,m0)
+ m.setMeshAtLevel(-1,m1)
+ #
+ dt=3 ; it=2 ; tim=4.5
+ fieldNode0=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
+ fieldNode0.setName("fieldNode0")
+ fieldNode0.setTime(tim,dt,it)
+ pfl0=DataArrayInt([0,1,2,3,4]) ; pfl0.setName("PflIdentity0") # important to keep like that
+ arr=DataArrayDouble([10,11,12,13,14])
+ fieldNode0.setArray(arr)
+ f0=MEDFileField1TS()
+ f0.setFieldProfile(fieldNode0,m,0,pfl0)
+ fieldNode1=MEDCouplingFieldDouble(ON_NODES,ONE_TIME)
+ fieldNode1.setName("fieldNode1")
+ fieldNode1.setTime(tim,dt,it)
+ pfl1=DataArrayInt([0,1,2,3,4,5,6]) ; pfl1.setName("PflIdentity1")
+ arr1=DataArrayDouble([20,21,22,23,24,25,26])
+ fieldNode1.setArray(arr1)
+ f1=MEDFileField1TS()
+ f1.setFieldProfile(fieldNode1,m,-1,pfl1)
+ mfd=MEDFileData()
+ mfd.setMeshes(MEDFileMeshes()) ; mfd.setFields(MEDFileFields())
+ mfd.getMeshes().pushMesh(m)
+ fmts=MEDFileFieldMultiTS() ; fmts.pushBackTimeStep(f0)
+ mfd.getFields().pushField(fmts)
+ # first start gently
+ d=mfd.serialize()
+ mfd2=MEDFileData(d)
+ self.assertEqual(len(mfd2.getMeshes()),1)
+ self.assertEqual(len(mfd2.getFields()),1)
+ self.assertEqual(len(mfd2.getFields()[0]),1)
+ self.assertTrue(mfd2.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
+ ff2=mfd2.getFields()[0][0].field(mfd2.getMeshes()[0])
+ ff =mfd.getFields()[0][0].field(mfd.getMeshes()[0])
+ self.assertTrue(ff2.isEqual(ff,1e-12,1e-12))
+ # OK now end of joke -> serialization of MEDFileData
+ st=pickle.dumps(mfd,pickle.HIGHEST_PROTOCOL)
+ mfd3=pickle.loads(st)
+ # check of object
+ self.assertEqual(len(mfd3.getMeshes()),1)
+ self.assertEqual(len(mfd3.getFields()),1)
+ self.assertEqual(len(mfd3.getFields()[0]),1)
+ self.assertTrue(mfd3.getMeshes()[0].isEqual(mfd.getMeshes()[0],1e-12))
+ ff3=mfd3.getFields()[0][0].field(mfd3.getMeshes()[0])
+ self.assertTrue(ff3.isEqual(ff,1e-12,1e-12))
+ # serialization of MEDFileFields
+ st=pickle.dumps(mfd.getFields(),pickle.HIGHEST_PROTOCOL)
+ fs4=pickle.loads(st)
+ ff4=fs4[0][0].field(mfd3.getMeshes()[0])
+ self.assertTrue(ff4.isEqual(ff,1e-12,1e-12))
+ # serialization of MEDFileFieldMulitTS
+ st=pickle.dumps(mfd.getFields()[0],pickle.HIGHEST_PROTOCOL)
+ fmts5=pickle.loads(st)
+ ff5=fmts5[0].field(mfd3.getMeshes()[0])
+ self.assertTrue(ff5.isEqual(ff,1e-12,1e-12))
+ # serialization of MEDFileField1TS
+ st=pickle.dumps(mfd.getFields()[0][0],pickle.HIGHEST_PROTOCOL)
+ f1ts6=pickle.loads(st)
+ ff6=f1ts6.field(mfd3.getMeshes()[0])
+ self.assertTrue(ff6.isEqual(ff,1e-12,1e-12))
+ # serialization of MEDFileMeshes
+ st=pickle.dumps(mfd.getMeshes(),pickle.HIGHEST_PROTOCOL)
+ ms7=pickle.loads(st)
+ self.assertEqual(len(ms7),1)
+ self.assertTrue(ms7[0].isEqual(mfd.getMeshes()[0],1e-12))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def testPickelizationOfMEDFileObjects2(self):
+ # CMesh
+ self.testMEDMesh6() # generates MEDFileMesh5.med file
+ mm=MEDFileMesh.New("MEDFileMesh5.med")
+ self.assertTrue(isinstance(mm,MEDFileCMesh))
+ st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
+ mm2=pickle.loads(st)
+ self.assertTrue(isinstance(mm2,MEDFileCMesh))
+ self.assertTrue(mm.getMesh().isEqual(mm2.getMesh(),1e-12))
+ # CurveLinear
+ self.testCurveLinearMesh1() # generates Pyfile55.med
+ mm=MEDFileMesh.New("Pyfile55.med")
+ self.assertTrue(isinstance(mm,MEDFileCurveLinearMesh))
+ st=pickle.dumps(mm,pickle.HIGHEST_PROTOCOL)
+ mm3=pickle.loads(st)
+ self.assertTrue(isinstance(mm3,MEDFileCurveLinearMesh))
+ self.assertTrue(mm.getMesh().isEqual(mm3.getMesh(),1e-12))
+ self.testInt32InMEDFileFieldStar1()# generates Pyfile63.med
+ # MEDFileIntFieldMultiTS
+ fs4=MEDFileFields("Pyfile63.med")
+ ms4=MEDFileMeshes("Pyfile63.med")
+ self.assertTrue(isinstance(fs4[0],MEDFileIntFieldMultiTS))
+ st=pickle.dumps(fs4[0],pickle.HIGHEST_PROTOCOL)
+ fmts5=pickle.loads(st)
+ self.assertEqual(len(fs4[0]),len(fmts5))
+ self.assertTrue(isinstance(fmts5,MEDFileIntFieldMultiTS))
+ self.assertTrue(fmts5[0].field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
+ # MEDFileIntField1TS
+ st=pickle.dumps(fs4[0][0],pickle.HIGHEST_PROTOCOL)
+ f1ts6=pickle.loads(st)
+ self.assertTrue(isinstance(f1ts6,MEDFileIntField1TS))
+ self.assertTrue(f1ts6.field(ms4[0]).isEqual((fs4[0][0]).field(ms4[0]),1e-12,0))
+ # MEDFileParameters
+ self.testParameters1()# generates Pyfile56.med
+ params=MEDFileParameters("Pyfile56.med")
+ st=pickle.dumps(params,pickle.HIGHEST_PROTOCOL)
+ params7=pickle.loads(st)
+ self.assertEqual(len(params),len(params7))
+ for i in range(len(params)):
+ self.assertTrue(params[i].isEqual(params7[i],1e-12)[0])
+ pass
+ pass
+
+ def testGlobalNumOnNodes1(self):
+ """Test global number on nodes here. Used by partitionners."""
+ fname="Pyfile112.med"
+ arr=DataArrayDouble(5) ; arr.iota()
+ m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
+ m.setName("mesh")
+ mm=MEDFileUMesh()
+ mm[0]=m
+ self.assertTrue(not mm.getGlobalNumFieldAtLevel(1))
+ d=DataArrayInt([7,8,9,2,0])
+ dRef=d.deepCopy()
+ mm.setGlobalNumFieldAtLevel(1,d)
+ mm.checkConsistency()
+ self.assertRaises(InterpKernelException,mm.setGlobalNumFieldAtLevel,1,d[::2])
+ mm.checkConsistency()
+ self.assertEqual(d.getHiddenCppPointer(),mm.getGlobalNumFieldAtLevel(1).getHiddenCppPointer())
+ self.assertTrue(mm.getGlobalNumFieldAtLevel(1).isEqual(dRef))
+ mm.write(fname,2)
+ mm2=MEDFileMesh.New(fname)
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ self.assertTrue(mm2.getGlobalNumFieldAtLevel(1).isEqual(dRef))
+ mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,10)
+ self.assertTrue(not mm.isEqual(mm2,1e-12)[0])
+ mm2.getGlobalNumFieldAtLevel(1).setIJ(0,0,7)
+ self.assertTrue(mm.isEqual(mm2,1e-12)[0])
+ pass
+
+ def testPartialReadOfEntities1(self):
+ """Test for advanced API on read to speed up read phase for users with "huge" number of time steps (more than 10 000)."""
+ fname="Pyfile113.med"
+ arr=DataArrayDouble(5) ; arr.iota()
+ m=MEDCouplingUMesh.Build1DMeshFromCoords(arr)
+ m.setName("mesh")
+ mm=MEDFileUMesh()
+ mm[0]=m
+ #
+ fieldName="Field"
+ ts1=(5.,1,2)
+ f1=MEDCouplingFieldDouble(ON_NODES) ; f1.setMesh(m) ; f1.setName(fieldName)
+ f1.setArray(DataArrayDouble([0.,0.1,0.2,0.3,0.4]))
+ f1.setTime(*ts1)
+ f2=MEDCouplingFieldDouble(ON_CELLS) ; f2.setMesh(m) ; f2.setName(fieldName)
+ f2.setArray(DataArrayDouble([1.,1.1,1.2,1.3]))
+ f2.setTime(*ts1)
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f1)
+ f1ts.setFieldNoProfileSBT(f2)
+ self.assertEqual(set(f1ts.getTypesOfFieldAvailable()),set([ON_NODES,ON_CELLS]))
+ f1ts_2=f1ts.deepCopy()
+ f1ts_2.getUndergroundDataArray()[:]+=2
+ f1ts_2.setTime(3,4,6.)
+ fmts=MEDFileFieldMultiTS()
+ fmts.pushBackTimeStep(f1ts)
+ fmts.pushBackTimeStep(f1ts_2)
+ #
+ mm.write(fname,2)
+ fmts.write(fname,0)
+ #
+ ent=MEDFileEntities.BuildFrom([(ON_NODES,NORM_ERROR)])
+ mm=MEDFileMesh.New(fname)
+ 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)
+ fs.loadArrays()
+ self.assertEqual(len(fs),1)
+ fmts=fs[0]
+ self.assertEqual(len(fmts),2)
+ ff0=fmts[0] ; ff1=fmts[1]
+ self.assertEqual(ff0.getTypesOfFieldAvailable(),[ON_NODES]) # only NODES have been loaded
+ self.assertTrue(ff0.field(mm).isEqual(f1,1e-12,1e-12))
+ f3=f1.deepCopy() ; f3+=2. ; f3.setTime(6.,3,4)
+ self.assertTrue(ff1.field(mm).isEqual(f3,1e-12,1e-12))
+ pass
+
+ def testFloat32InMEDFileFieldStar1(self):
+ """Like testInt32InMEDFileFieldStar1 but with float32 :)"""
+ fname="Pyfile114.med"
+ f1=MEDLoaderDataForTest.buildVecFieldOnCells_1();
+ f1=f1.convertToFloatField()
+ m1=f1.getMesh()
+ mm1=MEDFileUMesh.New()
+ mm1.setCoords(m1.getCoords())
+ mm1.setMeshAtLevel(0,m1)
+ mm1.setName(m1.getName())
+ mm1.write(fname,2)
+ ff1=MEDFileFloatField1TS()
+ ff1.setFieldNoProfileSBT(f1)
+ a=ff1.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
+ self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12))
+ ff1.write(fname,0)
+ a,b=ff1.getUndergroundDataArrayExt()
+ self.assertEqual(a.getHiddenCppPointer(),ff1.getUndergroundDataArray().getHiddenCppPointer())
+ self.assertEqual(b,[((3,0),(0,2)),((4,0),(2,4)),((6,0),(4,5)),((5,0),(5,6))])
+ ff2=MEDFileAnyTypeField1TS.New(fname)
+ self.assertEqual(ff2.getName(),"VectorFieldOnCells")
+ self.assertEqual(ff2.getTime(),[0,1,2.0])
+ self.assertTrue(isinstance(ff2,MEDFileFloatField1TS))
+ a=ff1.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
+ self.assertEqual(a.getArray().getInfoOnComponents(),['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12))
+ ff2.setTime(1,2,3.)
+ c=ff2.getUndergroundDataArray() ; c*=2
+ ff2.write(fname,0) # 2 time steps in
+ ffs1=MEDFileAnyTypeFieldMultiTS.New(fname,"VectorFieldOnCells")
+ self.assertEqual(ffs1.getTimeSteps(),[(0, 1, 2.0), (1, 2, 3.0)])
+ self.assertEqual(len(ffs1),2)
+ self.assertTrue(isinstance(ffs1,MEDFileFloatFieldMultiTS))
+ a=ffs1[2.].getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12))
+ a=ffs1.getFieldOnMeshAtLevel(ON_CELLS,0,1,0,mm1)
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12))
+ it=ffs1.__iter__() ; it.next() ; ff2bis=it.next()
+ a=ff2bis.getFieldOnMeshAtLevel(0,ON_CELLS,mm1)
+ self.assertTrue(a.getArray().isEqual(2*f1.getArray(),1e-7))
+ f1.setTime(3.,1,2) ; f1.getArray()[:]*=2
+ self.assertTrue(a.isEqual(f1,1e-12,1e-12)) ; f1.getArray()[:]/=2
+ bc=DataArrayFloat(6,3) ; bc[:]=0 ; bc.setInfoOnComponents(['power [MW/m^3]','density [g/cm^3]','temperature [K]'])
+ for it in ffs1:
+ a=it.getFieldOnMeshAtLevel(ON_CELLS,0,mm1)
+ bc+=a.getArray()
+ pass
+ self.assertTrue(bc.isEqual(3*f1.getArray(),1e-7))
+ nf1=MEDCouplingFieldFloat(ON_NODES)
+ nf1.setTime(9.,10,-1)
+ nf1.setMesh(f1.getMesh())
+ narr=DataArrayFloat(12,2) ; narr.setInfoOnComponents(["aa [u1]","bbbvv [ppp]"]) ; narr[:,0]=list(range(12)) ; narr[:,1]=2*narr[:,0]
+ nf1.setName("VectorFieldOnNodes") ; nf1.setArray(narr)
+ nff1=MEDFileFloatField1TS.New()
+ nff1.setFieldNoProfileSBT(nf1)
+ self.assertEqual(nff1.getInfo(),('aa [u1]','bbbvv [ppp]'))
+ self.assertEqual(nff1.getTime(),[10,-1,9.0])
+ nff1.write(fname,0)
+ #
+ nf2=MEDCouplingFieldFloat(ON_NODES)
+ nf2.setTime(19.,20,-11)
+ nf2.setMesh(f1.getMesh())
+ narr2=DataArrayFloat(8,2) ; narr.setInfoOnComponents(["aapfl [u1]","bbbvvpfl [ppp]"]) ; narr2[:,0]=list(range(8)) ; narr2[:,0]+=10 ; narr2[:,1]=3*narr2[:,0]
+ nf2.setName("VectorFieldOnNodesPfl") ; narr2.setName(nf2.getName()) ; nf2.setArray(narr2)
+ nff2=MEDFileFloatField1TS.New()
+ npfl=DataArrayInt([1,2,4,5,6,7,10,11]) ; npfl.setName("npfl")
+ nff2.setFieldProfile(nf2,mm1,0,npfl)
+ nff2.getFieldWithProfile(ON_NODES,0,mm1)
+ a,b=nff2.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
+ self.assertTrue(b.isEqual(npfl))
+ self.assertTrue(a.isEqual(narr2,1e-7))
+ nff2.write(fname,0)
+ nff2bis=MEDFileFloatField1TS(fname,"VectorFieldOnNodesPfl")
+ a,b=nff2bis.getFieldWithProfile(ON_NODES,0,mm1) ; b.setName(npfl.getName())
+ self.assertTrue(b.isEqual(npfl))
+ self.assertTrue(a.isEqual(narr2,1e-7))
+ #
+ nf3=MEDCouplingFieldDouble(ON_NODES)
+ nf3.setName("VectorFieldOnNodesDouble")
+ nf3.setTime(29.,30,-21)
+ nf3.setMesh(f1.getMesh())
+ nf3.setArray(f1.getMesh().getCoords())
+ nff3=MEDFileField1TS.New()
+ nff3.setFieldNoProfileSBT(nf3)
+ nff3.write(fname,0)
+ fs=MEDFileFields(fname)
+ self.assertEqual(len(fs),4)
+ ffs=[it for it in fs]
+ self.assertTrue(isinstance(ffs[0],MEDFileFloatFieldMultiTS))
+ self.assertTrue(isinstance(ffs[1],MEDFileFloatFieldMultiTS))
+ self.assertTrue(isinstance(ffs[2],MEDFileFieldMultiTS))
+ self.assertTrue(isinstance(ffs[3],MEDFileFloatFieldMultiTS))
+ #
+ self.assertTrue(fs["VectorFieldOnCells"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getArray(),1e-7))
+ self.assertTrue(fs["VectorFieldOnCells"][1,2].getUndergroundDataArray().isEqualWithoutConsideringStr(2*f1.getArray(),1e-7))
+ self.assertTrue(fs["VectorFieldOnNodesPfl"][0].getUndergroundDataArray().isEqualWithoutConsideringStr(narr2,1e-7))
+ self.assertTrue(fs["VectorFieldOnNodes"][9.].getUndergroundDataArray().isEqualWithoutConsideringStr(narr,1e-7))
+ self.assertTrue(fs["VectorFieldOnNodesDouble"][29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
+ #
+ nf3_read=MEDFileFieldMultiTS(fname,"VectorFieldOnNodesDouble")
+ self.assertTrue(nf3_read[29.].getUndergroundDataArray().isEqualWithoutConsideringStr(f1.getMesh().getCoords(),1e-12))
+ self.assertRaises(InterpKernelException,MEDFileFloatFieldMultiTS.New,fname,"VectorFieldOnNodesDouble")# exception because trying to read a double field with int instance
+ self.assertRaises(InterpKernelException,MEDFileFieldMultiTS.New,fname,"VectorFieldOnNodes")# exception because trying to read a int field with double instance
+ MEDFileField1TS.New(fname,"VectorFieldOnNodesDouble",30,-21)
+ self.assertRaises(InterpKernelException,MEDFileFloatField1TS.New,fname,"VectorFieldOnNodesDouble",30,-21)# exception because trying to read a double field with int instance
+ MEDFileFloatField1TS.New(fname,"VectorFieldOnNodes",10,-1)
+ self.assertRaises(InterpKernelException,MEDFileField1TS.New,fname,"VectorFieldOnNodes",10,-1)# exception because trying to read a double field with int instance
+ #
+ self.assertEqual(fs.getMeshesNames(),('3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1','3DSurfMesh_1'))
+ self.assertTrue(fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
+ self.assertEqual(fs.getMeshesNames(),('3DSurfMesh','3DSurfMesh','3DSurfMesh','3DSurfMesh'))
+ self.assertTrue(not fs.changeMeshNames([('3DSurfMesh_1','3DSurfMesh')]))
+ pass
+
+ def testPenta18_1(self):
+ """EDF8478 : Test of read/write of penta18"""
+ fname="Pyfile115.med"
+ arr=DataArrayDouble([
+ (0.,1.,1.),(0.,0.,1.),(1.,0.,1.),
+ (0.,1.,0.),(0.,0.,0.),(1.,0.,0.),
+ (0.,0.5,1.),(0.5,0.,1.),(0.5,0.5,1.),
+ (0.,0.5,0.),(0.5,0.,0.),(0.5,0.5,0.),
+ (0.,1.,0.5),(0.,0.,0.5),(1.,0.,0.5),
+ (0.,0.5,0.5),(0.5,0.,0.5),(0.5,0.5,0.5)])
+ m=MEDCouplingUMesh("mesh",3)
+ m.setCoords(arr)
+ m.allocateCells(1)
+ m.insertNextCell(NORM_PENTA18,list(range(18)))
+ m.checkConsistencyLight()
+ #
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setMesh(m)
+ f.setName("FieldOnPenta18")
+ f.setArray(DataArrayDouble(list(range(18))))
+ f.checkConsistencyLight()
+ #
+ m2,d,di,rd,rdi=m.buildDescendingConnectivity()
+ #
+ f2=MEDCouplingFieldDouble(ON_NODES)
+ f2.setMesh(m)
+ f2.setName("FieldOnPenta18Sub")
+ f2.setArray(DataArrayDouble(list(range(18))))
+ f2.checkConsistencyLight()
+ WriteField(fname,f2,True)
+ f3=ReadField(fname)
+ self.assertTrue(f2.isEqual(f3,1e-12,1e-12))
+ self.assertEqual(f3.getMesh().getNumberOfCells(),1)
+ self.assertEqual(f3.getMesh().getTypeOfCell(0),NORM_PENTA18)
+ pass
+
+ def testFieldsLinearToQuadratic(self):
+ fname="Pyfile117.med"
+ arr=DataArrayDouble([0,1])
+ m=MEDCouplingCMesh();
+ m.setCoords(arr,arr,arr)
+ m=m.buildUnstructured()
+ m2=m.deepCopy()
+ m2.translate([2,0,0])
+ m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
+ m3.setName("mesh")
+ mm=MEDFileUMesh()
+ mm[0]=m3
+ mmq=mm.linearToQuadratic(0)
+ mms=MEDFileMeshes() ; mms.pushMesh(mm)
+ mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
+ #
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setName("field")
+ f.setMesh(m3)
+ f.setTime(3.,1,2)
+ arr=DataArrayDouble(m3.getNumberOfNodes())
+ arr.iota()
+ f.setArray(arr)
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldNoProfileSBT(f)
+ fmts=MEDFileFieldMultiTS()
+ fmts.pushBackTimeStep(f1ts)
+ f1ts_2=f1ts.deepCopy()
+ f1ts_2.setTime(3,4,5.)
+ f1ts_2.getUndergroundDataArray()[:]*=2.
+ fmts.pushBackTimeStep(f1ts_2)
+ fs=MEDFileFields()
+ fs.pushField(fmts)
+ fs2=fs.linearToQuadratic(mms,mmsq)
+ self.myTester1(fs2,mmsq[0])
+ # A small Write/Read and test again
+ mms.write(fname,2) ; fs.write(fname,0)
+ mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
+ mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
+ fs2=fs.linearToQuadratic(mms,mmqs)
+ self.myTester1(fs2,mmqs[0])
+ pass
+
+ def myTester1(self,fs2,mmq):
+ 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)
+ 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])
+ 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])
+ fToTest=fs2[0][0].field(mmq)
+ self.assertEqual(fToTest.getTime(),[3.,1,2])
+ mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
+ self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
+ self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
+ self.assertTrue(fToTest.getArray().isEqual(dataExp2,1e-12))
+ # testing 2nd timestep
+ fToTest=fs2[0][1].field(mmq)
+ self.assertEqual(fToTest.getTime(),[5.,3,4])
+ mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
+ self.assertTrue(mTest.getNodalConnectivity().isEqual(dataExp1))
+ self.assertTrue(mTest.getCoords().isEqual(dataExp,1e-12))
+ self.assertTrue(fToTest.getArray().isEqual(2*dataExp2,1e-12))
+ pass
+
+ def testFieldsLinearToQuadratic2(self):
+ """Same than testFieldsLinearToQuadratic but with profile on NODES"""
+ fname="Pyfile118.med"
+ arr=DataArrayDouble([0,1])
+ m=MEDCouplingCMesh();
+ m.setCoords(arr,arr,arr)
+ m=m.buildUnstructured()
+ m2=m.deepCopy()
+ m2.translate([2,0,0])
+ m3=MEDCouplingUMesh.MergeUMeshes([m,m2])
+ m3.setName("mesh")
+ # add a point for fun
+ m3.setCoords(DataArrayDouble.Aggregate(m3.getCoords(),DataArrayDouble([1.5,1.5,1.5],1,3)))
+ #
+ mm=MEDFileUMesh()
+ mm[0]=m3
+ mmq=mm.linearToQuadratic(0)
+ mms=MEDFileMeshes() ; mms.pushMesh(mm)
+ mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
+ #
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setName("field")
+ f.setMesh(m3)
+ f.setTime(3.,1,2)
+ arr=DataArrayDouble(8) ; arr.iota()
+ arr.iota()
+ f.setArray(arr)
+ f1ts=MEDFileField1TS()
+ pfl=DataArrayInt([8,9,10,11,12,13,14,15]) ; pfl.setName("pfl")
+ f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 8 nodes of cell #1
+ f1ts_2=f1ts.deepCopy()
+ f1ts_2.setTime(3,4,5.)
+ f1ts_2.getUndergroundDataArray()[:]*=4.
+ fmts=MEDFileFieldMultiTS()
+ fmts.pushBackTimeStep(f1ts)
+ fmts.pushBackTimeStep(f1ts_2)
+ fs=MEDFileFields()
+ fs.pushField(fmts)
+ fs2=fs.linearToQuadratic(mms,mmsq)
+ mms.write(fname,2) ; fs.write(fname,0)
+ #
+ self.myTester2(fs2,mmq)
+ # Read/write
+ mms=MEDFileMeshes(fname) ; fs=MEDFileFields(fname)
+ mmq=mms[0].linearToQuadratic(0) ; mmqs=MEDFileMeshes() ; mmqs.pushMesh(mmq)
+ fs2=fs.linearToQuadratic(mms,mmqs)
+ self.myTester2(fs2,mmq)
+ ## More vicious add single node 16
+ mm=MEDFileUMesh()
+ mm[0]=m3
+ mmq=mm.linearToQuadratic(0)
+ mms=MEDFileMeshes() ; mms.pushMesh(mm)
+ mmsq=MEDFileMeshes() ; mmsq.pushMesh(mmq)
+ #
+ f=MEDCouplingFieldDouble(ON_NODES)
+ f.setName("field")
+ f.setMesh(m3)
+ f.setTime(3.,1,2)
+ arr=DataArrayDouble(9) ; arr.iota()
+ arr.iota()
+ f.setArray(arr)
+ f1ts=MEDFileField1TS()
+ pfl=DataArrayInt([8,9,10,11,12,13,14,15,16]) ; pfl.setName("pfl")
+ f1ts.setFieldProfile(f,mm,0,pfl) # f lying on 9 nodes of cell #1 + orphan node
+ fmts=MEDFileFieldMultiTS()
+ fmts.pushBackTimeStep(f1ts)
+ fs=MEDFileFields()
+ fs.pushField(fmts)
+ fs2=fs.linearToQuadratic(mms,mmsq)
+ #
+ 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")
+ f1tsToTest=fs2[0][0]
+ 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])
+ assert(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
+ assert(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
+ assert(f1tsToTest.getFieldSplitedByType()==[(40,[(1,(0,21),'pfl_NODE','')])])
+ pass
+
+ def myTester2(self,fs2,mmq):
+ 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")
+ f1tsToTest=fs2[0][0]
+ 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])
+ self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
+ self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(exp1,1e-12))
+ self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
+ fToTest=fs2[0][0].field(mmq)
+ self.assertEqual(fToTest.getTime(),[3.,1,2])
+ mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
+ 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])))
+ 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))
+ self.assertTrue(fToTest.getArray().isEqual(exp1,1e-12))
+ # 2nd Time step
+ f1tsToTest=fs2[0][1]
+ self.assertTrue(f1tsToTest.getProfile("pfl_NODE").isEqual(pflExpected))
+ self.assertTrue(f1tsToTest.getUndergroundDataArray().isEqual(4*exp1,1e-12))
+ self.assertEqual(f1tsToTest.getFieldSplitedByType(),[(NORM_ERROR,[(1,(0,20),'pfl_NODE','')])])
+ fToTest=fs2[0][1].field(mmq)
+ self.assertEqual(fToTest.getTime(),[5.,3,4])
+ mTest=MEDCoupling1SGTUMesh(fToTest.getMesh())
+ 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])))
+ 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))
+ self.assertTrue(fToTest.getArray().isEqual(4*exp1,1e-12))
+
+ pass
+
+ def testSetFieldProfileFlatly1(self):
+ """ 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
+ a profile."""
+ arr=DataArrayDouble(10) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ m2=m.deepCopy()
+ m2.simplexize(0)
+ m=MEDCouplingUMesh.MergeUMeshes(m2,m)
+ m.setName("mesh")
+ mm=MEDFileUMesh()
+ mm[0]=m
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ arr=DataArrayDouble(m.getNumberOfCells())
+ arr.iota()
+ f.setArray(arr)
+ f.setName("field")
+ pfl=DataArrayInt(m.getNumberOfCells()) ; pfl.iota() ; pfl.setName("pfl")
+ #
+ refSp=[(3,[(0,(0,162),'','')]),(4,[(0,(162,243),'','')])]
+ refSp1=[(3,[(0,(0,162),'pfl_NORM_TRI3','')]),(4,[(0,(162,243),'pfl_NORM_QUAD4','')])]
+ #
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldProfile(f,mm,0,pfl)
+ self.assertEqual(f1ts.getPfls(),()) # here setFieldProfile has detected useless pfl -> no pfl
+ self.assertEqual(f1ts.getFieldSplitedByType(),refSp)
+ self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
+ #
+ f1ts=MEDFileField1TS()
+ f1ts.setFieldProfileFlatly(f,mm,0,pfl) # no optimization attempt. Create pfl unconditionally
+ self.assertEqual(f1ts.getPfls(),("%s_NORM_TRI3"%pfl.getName(),"%s_NORM_QUAD4"%pfl.getName()))
+ self.assertEqual(f1ts.getFieldSplitedByType(),refSp1)
+ self.assertTrue(f1ts.field(mm).isEqual(f,1e-12,1e-12)) # the essential
+ self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3").isIota(162))
+ self.assertTrue(f1ts.getProfile("pfl_NORM_QUAD4").isIota(81))
+ pass
+
+ def testRmGroupAtSpeLevelAndMultiLevGrpCreation(self):
+ """ Here multi level groups are created"""
+ arr=DataArrayDouble(11) ; arr.iota()
+ m=MEDCouplingCMesh() ; m.setCoords(arr,arr)
+ m=m.buildUnstructured()
+ m.setName("mesh")
+ m1=m.buildDescendingConnectivity()[0]
+ mm=MEDFileUMesh()
+ mm[0]=m ; mm[-1]=m1
+ ################
+ grpName="grp0"
+ grp0_0=DataArrayInt([0,1,2,6]) ; grp0_0.setName(grpName)
+ grp0_1=DataArrayInt([0,1,2,7]) ; grp0_1.setName(grpName)
+ grp1=DataArrayInt([1,2,3,5,6]) ; grp1.setName("grp1")
+ grp2=DataArrayInt([2,3,5,8]) ; grp2.setName("grp2")
+ ################ ajouter un groupe sur plusieurs niveau
+ mm.addGroup(0,grp1)
+ mm.addGroup(-1,grp2)
+ mm.addGroup(0,grp0_0)
+ mm.addGroup(-1,grp0_1)
+ self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
+ self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
+ self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
+ self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
+ self.assertRaises(InterpKernelException,mm.addGroup,-1,grp0_1) # raise
+ self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
+ self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
+ self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
+ mm.removeGroupAtLevel(0,grpName)
+ self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(-1,))
+ self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
+ self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
+ mm.removeGroupAtLevel(-1,grpName)
+ self.assertEqual(mm.getGrpNonEmptyLevels(grpName),())
+ self.assertRaises(InterpKernelException,mm.removeGroupAtLevel,-2,grpName)
+ mm.addGroup(-1,grp0_1)
+ mm.addGroup(0,grp0_0)
+ self.assertEqual(mm.getGrpNonEmptyLevels(grpName),(0,-1))
+ self.assertTrue(mm.getGroupArr(0,grpName).isEqual(grp0_0))
+ self.assertTrue(mm.getGroupArr(-1,grpName).isEqual(grp0_1))
+ self.assertTrue(mm.getGroupArr(0,"grp1").isEqual(grp1))
+ self.assertTrue(mm.getGroupArr(-1,"grp2").isEqual(grp2))
+ pass
+
+ def testYutaka(self):
+ """ 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...
+ Then rearrange method removes unused entites by putting 0 on them -> Previously group has been modified by rearrange. Should not !"""
+ mn="mesh"
+ m=MEDCouplingCMesh()
+ arr=DataArrayDouble(4) ; arr.iota()
+ m.setCoords(arr,arr,arr)
+ m=m.buildUnstructured()
+ m.setName(mn)
+ #
+ m=m.buildUnstructured()
+ m1=m.buildDescendingConnectivity()[0]
+ #
+ mm=MEDFileUMesh()
+ mm[0]=m
+ mm[-1]=m1
+ #
+ grp0=DataArrayInt([0,1,2]) ; grp0.setName("grp0")
+ mm.addGroup(0,grp0)
+ grp1=DataArrayInt([3,4,5,6]) ; grp1.setName("grp1")
+ mm.addGroup(0,grp1)
+ grp2=DataArrayInt([7,8,9]) ; grp2.setName("grp2")
+ mm.addGroup(0,grp2)
+ grp3=DataArrayInt.Range(0,m1.getNumberOfCells(),1) ; grp3.setName("grp3")
+ mm.addGroup(-1,grp3)
+ self.assertNotIn(0,mm.getFamiliesIdsOnGroup("grp3")) # bug was here !
+ grp4=DataArrayInt([3,5,8,10]) ; grp4.setName("grp4")
+ mm.addNodeGroup(grp4)
+ mm.rearrangeFamilies()
+ self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp0"),(0,))
+ self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp1"),(0,))
+ self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp2"),(0,))
+ self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp3"),(-1,))
+ self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp4"),(1,))
+
+ for grp in [grp0,grp1,grp2,grp3,grp4]:
+ self.assertTrue(mm.getGroupArr(mm.getGrpNonEmptyLevelsExt(grp.getName())[0],grp.getName()).isEqual(grp))
+ pass
+ pass
+
+ def tessContxtMger1TS(self):
+ fname="Pyfile119.med"
+ coo=DataArrayDouble(1000) ; coo.iota()
+ m=MEDCouplingUMesh.Build0DMeshFromCoords(coo)
+ m.setName("mesh")
+ WriteMesh(fname,m,True)
+ f=MEDCouplingFieldDouble(ON_CELLS)
+ f.setMesh(m)
+ f.setName("Field")
+ arr=DataArrayDouble(m.getNumberOfCells())
+ f.setArray(arr)
+ f.checkConsistencyLight()
+ for i in range(10):
+ arr[:]=float(i+1)
+ f.setTime(float(i),i,0)
+ WriteFieldUsingAlreadyWrittenMesh(fname,f)
+ pass
+ #
+ mm=MEDFileMesh.New(fname)
+ fmts=MEDFileFieldMultiTS(fname,False)
+ refSize=fmts.getHeapMemorySize()
+ for f1ts in fmts:
+ with f1ts:
+ f=f1ts.field(mm)
+ pass
+ pass
+ self.assertIn(fmts.getHeapMemorySize(),range(refSize,refSize+refSize//10))
+ pass