How to build a mesh whose element sizes varies without using Gmsh?

Dear all,

I have read the Fenics tutorial carefully. Now I want to build a square mesh whose element sizes are very small at the left-bottom corner while the element sizes at other places are very large. I know we can achieve this using Gmsh. However, can we achieve this only using Fenics commands?

Thank you very much in advance for your kind help.

Best regards

You can provide a sequence of geometric points and their connecting topology to dolfinx.mesh.create_mesh. There’s an example here. You’d need to provide the points and cells which satisfy your needs. I believe @dokken may have a separate tutorial for creating meshes too.

To add to Nate’s comment, see:

@RR_rr do you want your mesh to be structured or unstructured? Could you make a simple sketch of a coarse version of this mesh?

1 Like

Thank you for your reply. I want my mesh to be unstructured.
I displayed my code to generate my mesh here. As can be seen, I used “generate_mesh()” to create my mesh. But the element sizes are basically the same. I focus on the left-bottom corner of the mesh (i.e. regions close to the quarter circle), so I want to make the element sizes around the quarter circle smaller. And I want to make the element sizes at other places larger (to decrease the computational cost). Can we achieve this without using Gmsh?

I am now reading the links that you shared. Thank you again.

Best regards.

from __future__ import print_function
from fenics import *
import matplotlib.pyplot as plt
import numpy as np
from mshr import *

N = 30

length = 10.0
width = 10.0
p0 = Point(np.array([0.0, 0.0]))
p1 = Point(np.array([length, width]))
r = 2
obj = Circle(Point(0, 0), r)
domain = Rectangle(p0, p1) - obj
mesh = generate_mesh(domain, N)

print( "number of cells:", mesh.num_cells() )


For that you need a mesh tool. This could be Gmsh, pygmsh, open cascade, cgal or similar:

You could Also simply store the mesh generated with mshr as xdmf and load it into dolfinx.

I understand now. Thank you very much.

Best regards.