@dokken, thanks for the reply and tutorials!
I am trying to generate a mesh for the top-right quarter of “a plate with a hole in the center.” My attempt was based on your 2D tutorial.
This was my attempt:
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)
points = mesh.points[:,:2] if prune_z else mesh.points
out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
return out_mesh
def generate_geom():
resolution = 0.01
# Channel parameters
L = 1.0
H = 1.0
c = [0.0, 0.0, 0]
r = 0.1
# Initialize empty geometry using the build in kernel in GMSH
geometry = pg.geo.Geometry()
# Fetch model we would like to add data to
model = geometry.__enter__()
# Add circle
circle = model.add_circle(c, r, mesh_size=3*resolution)
points = [model.add_point((0, 0, 0), mesh_size=resolution),
model.add_point((L, 0, 0), mesh_size=resolution),
model.add_point((L, H, 0), mesh_size=resolution),
model.add_point((0, H, 0), mesh_size=resolution)]
# Add lines between all points creating the rectangle
rectangle_lines = [model.add_line(points[i], points[i+1])
for i in range(-1, len(points)-1)]
# Create a line loop and plane surface for meshing
rectangle_loop = model.add_curve_loop(rectangle_lines)
plane_surface = model.add_plane_surface(rectangle_loop, holes=[circle.curve_loop])
# Call gmsh kernel before add physical entities
model.synchronize()
model.add_physical([plane_surface], "Plate")
model.add_physical([rectangle_lines[0]], "left")
model.add_physical([rectangle_lines[1]], "bottom")
model.add_physical([rectangle_lines[2]], "right")
model.add_physical([rectangle_lines[3]], "top")
return model
geometry = generate_geom()
geometry.generate_mesh(dim=2)
gmsh.write("mesh.msh")
gmsh.clear()
geometry.__exit__()
mesh_from_file = meshio.read("mesh.msh")
triangle_mesh = create_mesh(mesh_from_file, "triangle", prune_z=True)
meshio.write("mesh.xdmf", triangle_mesh)
I got the following error:
Exception: Unable to recover the edge 43704 (100/148) on curve 4 (on surface 2)
Also, how can I visualize it in order to see if it is doing the right thing? And before that I think I am missing a command to define it as a mesh compatible with FEniCS, i.e., what would be the FEniCS command to define the mesh for the FE analysis?
Best