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.