Dear all,
how to create a structured mesh on the L-shape domain ( the subset of the unit square that its upper right quadrant is removed)?
Because generate_mesh( , ) makes an unstructured mesh.
Thank you in advance.
You should consider using external meshing tools such as gmsh, which has several tutorials.
Minimal geo file with upper left quadrant removed:
//+
SetFactory("OpenCASCADE");
Rectangle(1) = {0, 0, 0, 1, 0.5, 0};
Rectangle(2) = {0.5, 0.5, 0, 0.5, 0.5, 0};
Transfinite Surface{1} = {1,2,3,4};
Transfinite Surface{2} = {5,6,7,8};
Physical Surface(1) = {1,2};
You can build custom meshes using MeshEditor:
from dolfin import *
import numpy as np
from vtkplotter.dolfin import plot
def build_mesh(vertices, cells): #build mesh from a collection of vertices and cells
editor = MeshEditor()
mesh = Mesh()
if len(cells[0]) == 3:
editor.open(mesh, 'triangle', 2, 2)
elif len(cells[0]) == 4:
editor.open(mesh, 'tetrahedron', 3, 3)
editor.init_vertices(len(vertices))
for i in range(len(vertices)):
editor.add_vertex(i,vertices[i])
editor.init_cells(len(cells))
if len(cells[0]) == 3:
for i in range(len(cells)):
editor.add_cell(i, np.array([cells[i][0], cells[i][1], cells[i][2]], dtype=np.uintp))
elif len(cells[0]) == 4:
for i in range(len(cells)):
editor.add_cell(i, np.array([cells[i][0],cells[i][1],cells[i][2],cells[i][3]], dtype=np.uintp))
editor.close()
mesh.init()
return mesh
def mesh_l_shaped():
vertices = [[-1,-1], [0,-1], [-1,0], [0,0], [1,0], [-1,1], [0,1], [1,1]]
cells = [[0,1,3], [0,2,3], [2,3,6], [2,5,6], [3,4,7], [3,6,7]]
return build_mesh(vertices, cells)
plot(mesh_l_shaped())
To get finer meshes use refine() or set the vertices and cells manually.
1 Like