Can dolfinx read a GMSH file containing 1D mesh of an ellipse?

Noet that you should use Physical Tags when using GMSH, i.e.

SetFactory("OpenCASCADE");
Ellipse(1) = {0, 0, 0, 5, 2.5, 0, 2*Pi};
Physical Curve(1) = {1};

Then, in turn, when using meshio, you should use the script from
https://jorgensd.github.io/dolfinx-tutorial/chapter3/subdomains.html?highlight=meshio#read-in-msh-files-with-dolfinx
and then you have the full pipeline:

from dolfinx import io
from mpi4py import MPI
import meshio


def create_mesh(mesh, cell_type, prune_z=False):
    cells = mesh.get_cells_type(cell_type)
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    points = mesh.points[:, :2] if prune_z else mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={
                           "name_to_read": [cell_data]})
    return out_mesh


mesh = meshio.read("ellipse.msh")
meshio.write("ellipse.xdmf", create_mesh(mesh, "line", True))


# Define parameters
meshfile = "ellipse.xdmf"

# Read the mesh
with io.XDMFFile(MPI.COMM_WORLD, meshfile, "r") as file:
    domain = file.read_mesh(name='Grid')

print(domain.topology.cell_type, domain.topology.index_map(
    domain.topology.dim).size_local, domain.geometry.dim)

which returns

CellType.interval 22 2
1 Like