# get geometry type try : geotypename,geotype = med.MEDmeshEntityInfo(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_CELL, it ) except RuntimeError as ex : print("ERROR : get geo type ...\n%s" % ex) doCleanup(fid, -1) # how many cells of type geotype ? try : nelt, chgt3, trsf3 = med.MEDmeshnEntity(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_CELL, geotype, med.MED_CONNECTIVITY, med.MED_NODAL) except RuntimeError as ex : print("ERROR : number of cell of type geotype ...\n%s" % ex) doCleanup(fid, -1) # read cells connectivity in the mesh connectivity = med.MEDINT([0] * nelt * (geotype % 100)) try : med.MEDmeshElementConnectivityRd(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_CELL, geotype, med.MED_NODAL, med.MED_FULL_INTERLACE, connectivity) except RuntimeError as ex : print("ERROR : cell connectivity ...\n%s" % ex) doCleanup(fid, -1) # ... we know that the family number of nodes and elements is 0, a real code would check ... # close MED file doCleanup(fid, 0)
# max size of meshname : med.MED_NAME_SIZE+1 meshname = "2D unstructured mesh" spacedim = 2 meshdim = 2 # max size of axisname and unitname : 2*med.MED_SNAME_SIZE+1 # 12345678901234561234567890123456 axisname = "x y " unitname = "cm cm " # ten nodes with two of them shared by the two polygons coordinates = med.MEDFLOAT([ 0.5, 0., 1.5, 0., 0., 0.5, 1., 0.5, 2., 0.5, 0., 1., 1., 1., 2., 1., 0.5, 2., 1.5, 2. ]) nnodes = 10 indexsize = 3 index = med.MEDINT([1, 7, 13]) # connectivity : 2 hexagons connectivity = med.MEDINT([1, 4, 7, 9, 6, 3, 2, 5, 8, 10, 7, 4]) # MED file creation try: fid = med.MEDfileOpen("UsesCase_MEDmesh_13.med", med.MED_ACC_CREAT) except RuntimeError as ex: print("ERROR : file creation ...\n%s" % ex) sys.exit(-1) # write a comment in the file try: med.MEDfileCommentWr(fid, "A 2D unstructured mesh : 12, 12 polygons") except RuntimeError as ex: print("ERROR : write file description ...\n%s" % ex)
med.MED_NODAL) except RuntimeError as ex: print("ERROR : number of MED_QUAD4 ...\n%s" % ex) doCleanup(fid, -1) # read mesh nodes coordinates coordinates = med.MEDFLOAT([0.] * nnodes * spacedim) try: med.MEDmeshNodeCoordinateRd(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_FULL_INTERLACE, coordinates) except RuntimeError as ex: print("ERROR : nodes coordinates ...\n%s" % ex) doCleanup(fid, -1) # read cells connectivity in the mesh triaconnectivity = med.MEDINT([0] * ntria3 * 3) try: med.MEDmeshElementConnectivityRd(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_CELL, med.MED_TRIA3, med.MED_NODAL, med.MED_FULL_INTERLACE, triaconnectivity) except RuntimeError as ex: print("ERROR : MED_TRIA3 connectivity ...\n%s" % ex) doCleanup(fid, -1) quadconnectivity = med.MEDINT([0] * nquad4 * 4) try: med.MEDmeshElementConnectivityRd(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_CELL, med.MED_QUAD4, med.MED_NODAL, med.MED_FULL_INTERLACE, quadconnectivity)
# max size of meshname : med.MED_NAME_SIZE+1 meshname = "2D unstructured mesh" spacedim = 2 meshdim = 2 # max size of axisname and unitname : 2*med.MED_SNAME_SIZE+1 # 12345678901234561234567890123456 axisname = "x y " unitname = "cm cm " coordinates = med.MEDFLOAT([ 2., 1., 7., 1., 12., 1., 17., 1., 22., 1., 2., 6., 7., 6., 12., 6., 17., 6., 22., 6., 2., 11., 7., 11., 12., 11., 17., 11., 22., 11. ]) nnodes = 15 triaconnectivity = med.MEDINT([ 1, 7, 6, 2, 7, 1, 3, 7, 2, 8, 7, 3, 13, 7, 8, 12, 7, 13, 11, 7, 12, 6, 7, 11 ]) ntria3 = 8 quadconnectivity = med.MEDINT( [3, 4, 9, 8, 4, 5, 10, 9, 15, 14, 9, 10, 13, 8, 9, 14]) nquad4 = 4 # MED file creation try: fid = med.MEDfileOpen("UsesCase_MEDmesh_1.med", med.MED_ACC_CREAT) except RuntimeError as ex: print("ERROR : file creation ...\n%s" % ex) sys.exit(-1) # write a comment in the file try:
try: med.MEDmeshNodeCoordinateRd(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_FULL_INTERLACE, coordinates) except RuntimeError as ex: print("ERROR : nodes coordinates ...\n%s" % ex) doCleanup(fid, -1) for i in range(0, nnodes * spacedim): sys.stdout.write(str(coordinates[i])) if (i + 1 != nnodes * spacedim): sys.stdout.write(" - ") else: print("") # read polyhedron connectivity faceindex = med.MEDINT([0] * faceindexsize) nodeindex = med.MEDINT([0] * nodeindexsize) connectivity = med.MEDINT([0] * connectivitysize) try: med.MEDmeshPolyhedronRd(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_CELL, med.MED_NODAL, faceindex, nodeindex, connectivity) except RuntimeError as ex: print("ERROR : read polyhedron connectivity ...\n%s" % ex) doCleanup(fid, -1) for i in range(0, npoly): print(">> MED_POLYHEDRON %s :" % str(i + 1)) print("---- Face Index ----- : [") ind1 = faceindex[i] - 1
# 12345678901234561234567890123456 axisname = "x y " unitname = "cm cm " cooXaxis = med.MEDFLOAT([1., 2., 3., 4., 5.]) cooYaxis = med.MEDFLOAT([1., 2., 3.]) nquad4 = 8 # max size of cellsname : 8*med.MED_SNAME_SIZE+1 # 12345678901234561234567890123456123456789012345612345678901234561234567890123456123456789012345612345678901234561234567890123456 cellsnames = med.MEDCHAR( "CELL_1 CELL_2 CELL_3 CELL_4 CELL_5 CELL_6 CELL_7 CELL_8 " ) # max size of familyname : med.MED_NAME_SIZE+1 familyname = "CART_GRID_QUAD_FAMILY" # max size of groupname : med.MED_LNAME_SIZE+1 groupname = med.MEDCHAR("CART_GRID_GROUP") familynumbers = med.MEDINT([-1, -1, -1, -1, -1, -1, -1, -1]) # MED file creation try: fid = med.MEDfileOpen("UsesCase_MEDmesh_4.med", med.MED_ACC_CREAT) except RuntimeError as ex: print("ERROR : file creation ...\n%s" % ex) sys.exit(-1) # create the structured mesh in the MED file try: med.MEDmeshCr(fid, meshname, spacedim, meshdim, med.MED_STRUCTURED_MESH, "A 2D structured mesh", "", med.MED_SORT_DTIT, med.MED_CARTESIAN, axisname, unitname) except RuntimeError as ex: print("ERROR : mesh creation ...\n%s" % ex)
connectivitysize, chgt, trsf = med.MEDmeshnEntity( fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_CELL, med.MED_POLYGON, med.MED_CONNECTIVITY, med.MED_NODAL) except RuntimeError as ex: print("ERROR : read connectivity size ...\n%s" % ex) doCleanup(fid, -1) # read mesh nodes coordinates coordinates = med.MEDFLOAT([0.] * nnodes * spacedim) try: med.MEDmeshNodeCoordinateRd(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_FULL_INTERLACE, coordinates) except RuntimeError as ex: print("ERROR : nodes coordinates ...\n%s" % ex) doCleanup(fid, -1) # read polygons connectivity index = med.MEDINT([0] * indexsize) connectivity = med.MEDINT([0] * connectivitysize) try: med.MEDmeshPolygonRd(fid, meshname, med.MED_NO_DT, med.MED_NO_IT, med.MED_CELL, med.MED_NODAL, index, connectivity) except RuntimeError as ex: print("ERROR : read polygon connectivity ...\n%s" % ex) doCleanup(fid, -1) # ... we know that the family number of nodes and elements is 0, a real code would check ... # close MED file doCleanup(fid, 0)
connectivity = med.MEDINT([ # - Poly 1 1, 2, 9, 3, 10, # - Face 1 1, 12, 5, 6, 11, 2, # - Face 2 2, 11, 6, 3, 9, # - Face 3 3, 6, 5, # - Face 4 3, 5, 10, # - Face 5 1, 10, 5, 12, # - Face 6 # - Poly 2 3, 13, 7, 8, 15, 4, # - Face 1 3, 4, 10, # - Face 2 4, 15, 8, 16, 5, 10, # - Face 3 3, 6, 14, 7, 13, # - Face 4 5, 16, 8, 7, 14, 6, # - Face 5 3, 10, 5, # - Face 6 3, 5, 6 # - Face 7 ])