I am having some trouble creating a DirichletBC from a facetfunction from a HDF5 file.
I have created a small script to demonstrate the issue: the first DirichletBC is created but the second one returns an error.
*** Error: Unable to create Dirichlet boundary condition.
*** Reason: User MeshFunction and FunctionSpace meshes are different.
my fenics is version 2019.1.0
import dolfin as df
def create_dirichletBC(mesh, meshfunc):
V = df.FunctionSpace(mesh, "CG", 1)
bc = df.DirichletBC(V, 0, meshfunc, 1)
def create_mesh():
mesh = df.UnitSquareMesh(3,3)
meshfunc = df.MeshFunction("size_t", mesh, 1)
return mesh, meshfunc
def mesh_to_file(mesh, meshfunc):
with df.HDF5File(df.MPI.comm_world, "mesh.h5", "w") as f:
f.write(mesh, "mesh")
f.write(meshfunc, "facet_markers")
def load_mesh():
with df.HDF5File(df.MPI.comm_world, "mesh.h5", "r") as f:
mesh = df.Mesh()
f.read(mesh, "mesh", True)
facetfunc = df.MeshFunction("size_t", mesh, 1)
f.read(facetfunc, "facet_markers")
return mesh, meshfunc
if __name__ == "__main__":
print("Dolfin version is {}".format(df.__version__))
mesh, meshfunc = create_mesh()
print("Creating DirichletBC when mesh created in script")
create_dirichletBC(mesh, meshfunc)
mesh_to_file(mesh, meshfunc)
mesh, meshfunc = load_mesh()
print("Creating DirichletBC when mesh loaded from file")
create_dirichletBC(mesh, meshfunc)