Join two interval meshes into one

You can create your mesh with mesh editor, where you can control the number if elements in each region. See:


from dolfin import *
import numpy

mesh   = Mesh()
editor = MeshEditor()

A = 0
B = 0.75
C = 1
N_AB = 10 # Number of cells in AB
N_BC = 15 # Number of cells in BC

vertices_a = numpy.linspace(A, B, N_AB+1)
vertices_b = numpy.linspace(B, C, N_BC+1)[1:]
vertices = numpy.hstack([vertices_a, vertices_b])

topological_dim = 1
geometrical_dim = 1




num_local_vertices = N_AB + N_BC + 1
num_local_cells    = N_AB + N_BC

num_global_vertices = num_local_vertices
num_global_cells    = num_local_cells

editor.open(mesh, "interval" , 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
for i, vertex in enumerate(vertices):
    editor.add_vertex(i, numpy.array([vertex], dtype='float'))
# Add cells
for i in range(num_local_cells):
    editor.add_cell(i, numpy.array([i, i+1], dtype='uint'))

# Close editor
editor.close()

outfile = File("mesh.pvd") << mesh