6 import medcoupling as mc
8 print("Loading a triangular mesh of a 2D square")
9 filename = "./meshSquare"
10 M=cdmath.Mesh(filename+".med")
12 #Extract groups in the mesh
13 print("Checking boundary group names")
14 boundaryFaceGroupNames=M.getNameOfFaceGroups()
15 boundaryNodeGroupNames=M.getNameOfNodeGroups()
16 print(len(boundaryFaceGroupNames), " Boundary Face Group detected : ", boundaryFaceGroupNames)
17 print(len(boundaryNodeGroupNames), " Boundary Node Group detected : ", boundaryNodeGroupNames)
19 assert(len(boundaryFaceGroupNames)==5)
20 assert(len(boundaryNodeGroupNames)==5)
22 assert boundaryFaceGroupNames[0]=="Top"
23 assert boundaryFaceGroupNames[1]=="Right"
24 assert boundaryFaceGroupNames[2]=="Left"
25 assert boundaryFaceGroupNames[3]=="Bottom"
26 assert boundaryFaceGroupNames[4]=="Boundary"
28 assert boundaryNodeGroupNames[0]=="Top"
29 assert boundaryNodeGroupNames[1]=="Right"
30 assert boundaryNodeGroupNames[2]=="Left"
31 assert boundaryNodeGroupNames[3]=="Bottom"
32 assert boundaryNodeGroupNames[4]=="Boundary"
40 radius = min(xmax-xmin,ymax-ymin)/4
41 xcentre = (xmax+xmin)/2
42 ycentre = (ymax+ymin)/2
44 nbCells = M.getNumberOfCells()
45 nbNodes = M.getNumberOfNodes()
47 # Create scalar fields
48 temperature_field_cells = cdmath.Field("Temperature", cdmath.CELLS, M, 1)
49 temperature_field_nodes = cdmath.Field("Temperature", cdmath.NODES, M, 1)
53 for i in range(nbCells):
56 distance = sqrt( (x - xcentre) * (x - xcentre) + (y - ycentre) * (y - ycentre) )
58 temperature_field_cells[i] = Tin
60 temperature_field_cells[i] = Tout
62 temperature_field_cells.writeMED(filename, False)
64 for i in range(nbNodes):
67 distance = sqrt( (x - xcentre) * (x - xcentre) + (y - ycentre) * (y - ycentre) )
69 temperature_field_nodes[i] = Tin
71 temperature_field_nodes[i] = Tout
73 temperature_field_nodes.writeMED(filename, False)
75 #### Delete mesh and still save field in a med file
76 m = mc.MEDCouplingCMesh()
77 x = mc.DataArrayDouble([0.,1.,2.])
78 y = mc.DataArrayDouble([0.,1.,2.])
80 m = m.buildUnstructured()
83 f = mc.MEDCouplingFieldDouble(mc.ON_CELLS, mc.ONE_TIME)
87 da = mc.DataArrayDouble([1,2,3,4])
92 fName = "./michael.med"
93 mc.WriteUMesh(fName, m, True)
95 # Maintenant juste les champs:
96 ff = mc.MEDFileField1TS()
97 ff.setFieldNoProfileSBT(f)
104 gc.collect() # Make sure Python interp has called mesh destructor ...
106 # Ecrit encore du champ:
110 print(da2.getValues())
113 ff = mc.MEDFileField1TS()
114 ff.setFieldNoProfileSBT(f) # le maillage n'existe plus, tant pis :-)
116 ff.write(fName, 0) # 1 append