Thanks for your quick reply!
That seems like it could potentially be an issue. However, I am loading in a MeshFunction
from file so I would have assumed there would be no need to set default values since all values should be pre-defined from the .xdmf
file?
If my assumption is incorrect, could you please point me to the syntax for assigning default values when loading a MeshFunction
from file?
My current script for loading my mesh
and MeshFunction
:
# Load mesh
mesh = Mesh()
with XDMFFile(comm, mesh_path) as infile:
infile.read(mesh)
# Load mesh function
mvc1 = MeshValueCollection("size_t", mesh, gdim)
with XDMFFile(meshfunc_filepath) as infile:
infile.read(mvc1, "name_to_read")
vols = MeshFunction("size_t", mesh, mvc1) # MeshFunction("size_t", mesh, mvc1, value=0) does not work
For additional context, I am generating my MeshFunction by converting a .gmsh
file using the function shown below (this is done in serial). Could this be the issue?
def convert_msh_to_xdmf(gmsh_mesh_filename: str, gdim: int, scaling: float = 1):
"""Converts gmsh mesh file (.msh) to .xdmf format for use in FEniCS"""
mesh = meshio.read(gmsh_mesh_filename)
assert gdim == 3
facet = "triangle"
element = "tetra"
element_data = []
facet_data = []
for cell in mesh.cells:
if cell.type == element:
element_data.append(cell.data)
elif cell.type == facet:
facet_data.append(cell.data)
element_data = np.vstack(element_data)
facet_data = np.vstack(facet_data)
points = scaling * mesh.points
for key in mesh.cell_data_dict["gmsh:physical"].keys():
if key == element:
elements = mesh.cell_data_dict["gmsh:physical"][key]
elif key == facet:
facets = mesh.cell_data_dict["gmsh:physical"][key]
element_mesh = meshio.Mesh(
points=points,
cells=[(element, element_data)],
cell_data={"name_to_read": [elements]},
)
facet_mesh = meshio.Mesh(
points=points, cells=[(facet, facet_data)], cell_data={"name_to_read": [facets]}
)
name = gmsh_mesh_filename.split(".")[0]
meshio.write(f"{name}.xdmf", element_mesh)
meshio.write(f"{name}_facets.xdmf", facet_mesh)
return len(points), len(elements)
Thanks for your help @dokken!