Convergence test with gmsh: python API vs. gmsh native

Dear community.

I would like to run a fenicsx simulation on a family of gmsh meshes, with decreasing mesh size, in order to perform a convergence test. I have two options:

  1. Creating a mesh in the python API of gmsh, like explained here and here. This works well, however one can not inspect the mesh easily. One can export the mesh and check it in the gmsh UI or in paraview, but these are extra steps, that one has to perform.

  2. Creating a mesh in gmsh, using .geo files. This works well, the gmsh UI can immediately show the result and the interplay between the .geo scripts and the visualization is very user friendly. E.g. one can create points, define a surface and read the implicitely defined identification tag (that every geometric entity has) using the UI. But: after importing the mesh to python, it can not be refined. I can not perform convergence tests like this.

How do the experts here handle this? Whats the best way to do it?

Note that you can use gmsh.fltk.run() to make the gui display a mesh with GMSH, see: Gmsh 4.12.2

3 Likes

A related question:

Is it preferred to refine a mesh (created by gmsh or by dolfinx) inside a python script or to create a family of meshes with decreasing element size and importing them one by one?

I tried to implement the first case based on the documentation:

from dolfinx import mesh, MPI
from mpi4py import MPI

msh = mesh.create_rectangle(comm=MPI.COMM_WORLD,
                            points=((0.0, 0.0), (1.0, 1.0)), n=(32, 32),
                            cell_type=mesh.CellType.triangle)

# refine mesh uniformly
refined_mesh = mesh.refine(msh, redistribute=True)

However I get an error message:

RuntimeError: Edges must be initialised

How does one initialize the edges?

mesh.topology.create_entities(1)

This depends on your geometry. If the boundary of the geometry is accurately represented on the coarse grid, i would refine it using dolfinx. However, it there are large curvatures, meaning that the coarse and finer grids would look significantly different, i would use Gmsh.

1 Like

Thank you very much for your answer!