Connect 1D domains

It is quite straightforward:

from mpi4py import MPI
import ufl
import basix.ufl
import numpy as np
import dolfinx

c_el = basix.ufl.element("Lagrange", basix.CellType.interval, 1, shape=(2,))

N = 4
M = 7
L = 5
l0 = np.linspace(-1, 0, N)
l1 = np.linspace(0, 1, M)[1:]
l2 = np.linspace(0, 1, L)[1:]
nodes = np.zeros((N + M - 1 + L - 1, 2), dtype=np.float64)
nodes[:N, 0] = l0
nodes[N : N + M - 1, 1] = l1
nodes[N + M - 1 :, 0] = l2

connectivity = np.full(((N - 1 + M - 1 + L - 1), 2), -1, dtype=np.int64)
for i in range(N - 1):
    connectivity[i, 0] = i
    connectivity[i, 1] = i + 1
for j in range(N - 1, N + M - 2):
    connectivity[j, 0] = j
    connectivity[j, 1] = j + 1
connectivity[N + M - 2, 0] = N - 1
connectivity[N + M - 2, 1] = N + M - 1
for j in range(N + M - 1, N + M + L - 3):
    connectivity[j, 0] = j
    connectivity[j, 1] = j + 1

mesh = dolfinx.mesh.create_mesh(MPI.COMM_WORLD, connectivity, nodes, c_el)

with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "mesh.xdmf", "w") as xdmf:
    xdmf.write_mesh(mesh)

yielding

1 Like