How to create mesh based on cell size instead of resolution


I would like to create a mesh based on cell size (specify mesh.hmin ) instead of setting resolution.
(For example, using UnitSquareMesh function.)
Is there a simple way of doing that in FEniCS ?

I checked the following question but it is suggested to use Gmsh, which I would like to avoid for now.


The unit square mesh (UnitSquareMesh(N,N)is defined as a rectangle from [0,1]\times[0,1] divided into N segments in each direction. This means that the diagonal (hmin) would be h = \sqrt{\frac{2}{N^2}}.
Therefore, you can make an easy conversion script from h to N, which you use as input to the mesh initializer.

For general meshes, the recommended approach is to use gmsh (python API or GUI) or the wrapper pygmsh as the FEniCS module mshr is no longer maintained.

1 Like

Thank you for the answer. Very helpful.