L-shape mesh generation with right element

The link above showed how to make it for a single cell. In this post I’ve now added a simple L-shape mesh with “left” diagonals.

import matplotlib.pyplot as plt
from dolfin import *
import numpy
# Create mesh object and open editor
mesh = Mesh()
editor = MeshEditor()
topological_dim = 2
geometrical_dim = 2
num_local_vertices = 8
num_global_vertices = num_local_vertices  # True if run in serial
num_local_cells = 6
num_global_cells = num_local_cells
editor.open(mesh, "triangle", topological_dim, geometrical_dim)
editor.init_vertices_global(num_local_vertices, num_global_vertices)
editor.init_cells_global(num_local_cells, num_global_cells)

# Add vertices
editor.add_vertex(0, numpy.array([0.0, 0.0], dtype='float'))
editor.add_vertex(1, numpy.array([1.0, 0.0], dtype='float'))
editor.add_vertex(2, numpy.array([0.0, 1.0], dtype='float'))
editor.add_vertex(3, numpy.array([1.0, 1.0], dtype='float'))
editor.add_vertex(4, numpy.array([0.0, 2.0], dtype='float'))
editor.add_vertex(5, numpy.array([1.0, 2.0], dtype='float'))
editor.add_vertex(6, numpy.array([3.0, 0.0], dtype='float'))
editor.add_vertex(7, numpy.array([3.0, 1.0], dtype='float'))
# Add cell
editor.add_cell(0, numpy.array([0, 1, 2], dtype='uint'))
editor.add_cell(1, numpy.array([1, 2, 3], dtype='uint'))
editor.add_cell(2, numpy.array([2, 3, 4], dtype='uint'))
editor.add_cell(3, numpy.array([3, 4, 5], dtype='uint'))
editor.add_cell(4, numpy.array([1, 6, 3], dtype='uint'))
editor.add_cell(5, numpy.array([6, 7, 3], dtype='uint'))
# Close editor
editor.close()

plot(mesh, color="r")
plt.savefig("mesh.png")
1 Like