Number of elements in a mesh

Dear all,

I have constructed this mesh in FEnics and I would like to compute the number of elements in the mesh (the mesh characteristics in general), I appreciate any help regarding this issue.

Here is my code:

from fenics import *
from mshr import *

domain = Rectangle(Point(0.0,0.0),Point(1,0.5))

mesh = generate_mesh(domain, 50)

Hi,

You can check number of elements using following function

mesh.num_cells()

If you run your code in parallel, you need to sum size of all parts of mesh on each core, so you need to use

MPI.sum(MPI.comm_world, mesh.num_cells())

Similarly, for maximum and minimum elements size you may use

mesh.hmax())
mesh.hmin())

More about these and other mesh functions can be seen here.

mesh.num_cells() works

Thank youuu :slight_smile: