Sorry for bothering you, but if I keep asking that is because I don’t see the solution in your answers.
I see that the facets are read from a file, surface.xdmf
, which is different form mesh.xdmf
. Your example shows how to generate three different files for a 3d mesh: mesh.xdmf
, surface.xdmf
and line.xdmf
.
I tried to do the same for a 1d mesh following your example, but I get an error (and this is why I read from the same file, I could not get to generate two different files):
import numpy
import meshio
import gmsh
import pygmsh
import numpy as np
resolution = 0.1
L = 1.0
geometry = pygmsh.occ.Geometry()
model = geometry.__enter__()
#add a 1d object a set of lines
points = [model.add_point( (0, 0, 0), mesh_size=resolution ),
model.add_point((np.pi/8.0, 0, 0), mesh_size=resolution),
model.add_point((L, 0, 0), mesh_size=resolution)
]
my_lines = [model.add_line( points[0], points[1] ), model.add_line( points[1], points[2] )]
model.synchronize()
model.add_physical([my_lines[0]], "line1")
model.add_physical([my_lines[1]], "line2")
model.add_physical([points[0]], "point_l")
model.add_physical([points[1]], "point_r")
geometry.generate_mesh(dim=3)
gmsh.write("mesh.msh")
model.__exit__()
def create_mesh(mesh, cell_type, prune_z=False):
cells = mesh.get_cells_type(cell_type)
cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
out_mesh = meshio.Mesh(points=mesh.points, cells={
cell_type: cells}, cell_data={"name_to_read": [cell_data]})
return out_mesh
mesh_from_file = meshio.read("mesh.msh")
#create mesh.xdmf (fail)
tetra_mesh = create_mesh(mesh_from_file, "tetra", True)
meshio.write("mesh.xdmf", tetra_mesh)
#create surface.xdmf (fail)
triangle_mesh = create_mesh(mesh_from_file, "triangle", True)
meshio.write("surface.xdmf", triangle_mesh)
#create line_mesh.xdmf (works)
line_mesh = create_mesh(mesh_from_file, "line", True)
meshio.write("line_mesh.xdmf", line_mesh)
Given that this is a one-dimensional mesh, there are no tetrahedra nor triangles, so it is no surprise that mesh.xdmf
nor surface.xdmf
can be created.
Of course, if I only generate line_mesh.xdmf
then the code above works, but I need multiple files to read everything correctly, and I do not know, nor see, how to generate multiple ones.