Open mapengfei-nwpu opened 3 years ago
from dolfin import *
mesh = UnitCubeMesh.create(1,1,1,CellType.Type.hexahedron)
# define left face
class Left(SubDomain):
def inside(self, x, on_boundary):
return abs(x[0] - 0.0) < DOLFIN_EPS and on_boundary
left = Left()
boundaries = MeshFunction('size_t', mesh, mesh.topology().dim()-1)
subdomains = MeshFunction('size_t', mesh, mesh.topology().dim())
# marking boundary
boundaries.set_all(0)
left.mark(boundaries, 1)
xdmf = XDMFFile(mesh.mpi_comm(), "file.xdmf")
xdmf.write(mesh)
xdmf.write(subdomains)
xdmf = XDMFFile(mesh.mpi_comm(), "boundaries.xdmf")
xdmf.write(boundaries)
xdmf.close()
mesh = Mesh()
xdmf = XDMFFile(mesh.mpi_comm(), "file.xdmf")
xdmf.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("file.xdmf") as infile:
infile.read(mvc, "f")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
xdmf.close()
mvc2 = MeshValueCollection("size_t", mesh, 1)
with XDMFFile("boundaries.xdmf") as infile:
infile.read(mvc2, "f")
mf2 = cpp.mesh.MeshFunctionSizet(mesh, mvc2)