Here is what I have been able to do with the codes you provide in your site:
import pygmsh
resolution = 0.01
# Channel parameters
L = 2
H = 2
# Initialize empty geometry using the build in kernel in GMSH
geometry = pygmsh.geo.Geometry()
# Fetch model we would like to add data to
model = geometry.__enter__()
# Add points with finer resolution on left side
points = [model.add_point((0 , 0, 0), mesh_size=5*resolution),
model.add_point((L/2, 0, 0), mesh_size=5*resolution),
model.add_point((L/2, H, 0), mesh_size=5*resolution),
model.add_point((0 , H, 0), mesh_size=5*resolution),
model.add_point((L , 0, 0), mesh_size=5*resolution),
model.add_point((L , H, 0), mesh_size=5*resolution)]
channel_lines_1 = [model.add_line(points[0], points[1]),
model.add_line(points[1], points[2]),
model.add_line(points[2], points[3]),
model.add_line(points[3], points[0])]
channel_lines_2 = [model.add_line(points[1], points[4]),
model.add_line(points[4], points[5]),
model.add_line(points[5], points[2]),
model.add_line(points[2], points[1])]
# Create the first line loop and plane surface for meshing
channel_loop_1 = model.add_curve_loop(channel_lines_1)
plane_surface_1 = model.add_plane_surface(channel_loop_1)
# Create the second line loop and plane surface for meshing
channel_loop_2 = model.add_curve_loop(channel_lines_2)
plane_surface_2 = model.add_plane_surface(channel_loop_2)
# Call gmsh kernel before add physical entities
model.synchronize()
model.add_physical([plane_surface_1], "Volume_1")
model.add_physical([plane_surface_2], "Volume_2")
model.add_physical([channel_lines_1[3]], "Inflow")
model.add_physical([channel_lines_2[1]], "Outflow")
geometry.generate_mesh(dim=2)
import gmsh
gmsh.write("mesh.msh")
gmsh.clear()
geometry.__exit__()
import meshio
import numpy as np
msh = meshio.read("mesh.msh")
line_cells = []
for cell in msh.cells:
if cell.type == "triangle":
triangle_cells = cell.data
elif cell.type == "line":
if len(line_cells) == 0:
line_cells = cell.data
else:
line_cells = np.vstack([line_cells, cell.data])
line_data = []
for key in msh.cell_data_dict["gmsh:physical"].keys():
if key == "line":
if len(line_data) == 0:
line_data = msh.cell_data_dict["gmsh:physical"][key]
else:
line_data = np.vstack([line_data, msh.cell_data_dict["gmsh:physical"][key]])
elif key == "triangle":
triangle_data = msh.cell_data_dict["gmsh:physical"][key]
triangle_mesh = meshio.Mesh(points=msh.points[:,:2], cells={"triangle": triangle_cells})
line_mesh =meshio.Mesh(points=msh.points,
cells=[("line", line_cells)],
cell_data={"name_to_read":[line_data]})
meshio.write("mesh.xdmf", triangle_mesh)
meshio.xdmf.write("mf.xdmf", line_mesh)
from dolfin import *
mesh = Mesh()
with XDMFFile("mesh.xdmf") as infile:
infile.read(mesh)
mvc = MeshValueCollection("size_t", mesh, 2)
with XDMFFile("mf.xdmf") as infile:
infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
Now I got this error:
*** -------------------------------------------------------------------------
*** Error: Unable to find entity in map.
*** Reason: Error reading MeshValueCollection.
*** Where: This error was encountered inside HDF5File.cpp.
*** Process: 0
Also, I probably have not been able to mark my subdomains to call later.