This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Vertex, edge and cell count discrepancy?

+1 vote

Dear all,

I am trying to get the correct number of cells, vertices, and edges in a 2D mesh, but I am getting weird answers.

Take for instance this code:

import dolfin
import mshr

# set a domain
rect = mshr.Rectangle(dolfin.Point(0.0, 0.0), dolfin.Point(1.0, 1.0))

# mesh it
m = mshr.generate_mesh(rect, 2)

# dump mesh
dolfin.File("/Users/sensei/Downloads/a.pvd") << m

# get information
ncells = [  m.num_vertices(), m.num_edges(), m.num_faces(), m.num_facets(), m.num_cells() ]

print(ncells)

You can see the mesh in the attached image. The problem is the output:

[9, 0, 8, 0, 8]

I expected to find 9 vertices, 16 edges, and 8 cells.

Am I missing something obvious?

Thanks!

asked May 12, 2017 by senseiwa FEniCS User (2,620 points)

have you called m.init()?

Thanks that did the trick. I never had the necessity of faces, and never saw that function.

Cheers!

Cool cool. Dolfin only initialises the entities of a mesh required for FEM assembly. It can get memory intensive.

1 Answer

0 votes
 
Best answer

Be sure to initialise the mesh

mesh.init()

since DOLFIN doesn't initialise entities unless they're necessary in a FEM formulation.

answered May 12, 2017 by nate FEniCS Expert (17,050 points)
selected May 24, 2017 by johannr
...