No squared mesh

Hi, can i make mesh like that with mesh functions in fenics?

Please note that you have not specified if you are using legacy fenics or fenicsx.
As it seems like you already have the triangulation for this grid, you could simply read it in manually in DOLFINx, as show in Mesh generation — FEniCS Tutorial @ Sorbonne

1 Like

Consider submesh. But this will not be optimal unless you redistribute the cells.

import dolfinx
from mpi4py import MPI
import numpy as np

n_ele = 16
if n_ele % 2:
    raise NotImplementedError("n_ele must be even")

mesh = dolfinx.mesh.create_unit_square(
    MPI.COMM_WORLD, n_ele, n_ele,
    diagonal=dolfinx.mesh.DiagonalType.left_right)

tol = 1e-9
discard_cells = dolfinx.mesh.locate_entities(
    mesh, mesh.topology.dim,
    lambda x: (x[0] >= 0.5 - tol) & (x[1] <= 0.5 + tol))
keep_cells = np.arange(mesh.topology.index_map(mesh.topology.dim).size_local,
                       dtype=np.int32)
keep_cells = np.setdiff1d(keep_cells, discard_cells)

mesh, _, _, _ = dolfinx.mesh.create_submesh(
    mesh, mesh.topology.dim, keep_cells)

1 Like