Error in mesh tutorial from Sorbonne23 workshop

I am following the tutorial on mesh generation presented at Sorbonne this year.

When trying to plot the mesh defined in the beginning of the page,

import dolfinx
import numpy as np
import ufl
from mpi4py import MPI
import pyvista

nodes = np.array([[1., 0.], [2., 0.], [3., 2.], [1, 3]])
connectivity = np.array([[0, 1, 2], [0, 2, 3]])

c_el = ufl.Mesh(ufl.VectorElement("Lagrange", ufl.triangle, 1))
domain = dolfinx.mesh.create_mesh(MPI.COMM_SELF, connectivity, nodes, c_el)

def plot_mesh(mesh: dolfinx.mesh.Mesh):
    plotter = pyvista.Plotter()

    # ugrid = pyvista.UnstructuredGrid(*dolfinx.plot.create_vtk_mesh(mesh))
    ugrid = pyvista.UnstructuredGrid(*dolfinx.plot.vtk_mesh(mesh))

    if mesh.geometry.cmap.degree > 1:
        plotter.add_mesh(ugrid, style="points", color="b", point_size=10)
        ugrid = ugrid.tessellate()
        show_edges = False
    else:
        show_edges = True
    plotter.add_mesh(ugrid, show_edges=show_edges)

    plotter.show_axes()
    plotter.view_xy()
    plotter.show()

plot_mesh(domain)

i get this error:

    if mesh.geometry.cmap.degree > 1:
       ^^^^^^^^^^^^^^^^^^
AttributeError: 'dolfinx.cpp.mesh.Geometry_float64' object has no attribute 'cmap'. Did you mean: 'cmaps'?

My fenicsx version is: 0.7.0 based on GIT commit: 2244eee852d6aa070a2bbbd76215ef78d84911e1 and i run it in a conda environment on linux.

I checked, and the current version of the dolfinx.mesh.Geometry class does really not have this ‘cmap’ attribute. How can i make this code run?

Another remark: the definition of ugrid in the code was broken. I replaced “create_vtk_mesh” with “vtk_mesh”.

The Sorbonne tutorial is written for v0.6.0.
I will update it at some point in December to work with 0.7.2.

Change mesh.geometry.cmap to mesh.geometry.cmaps[0].

Thank you for the quick reply.

The code works now, if i additionally replace plotter.show() with plotter.save_graphic("test.pdf") .

The plotter.show() is not broken itself, it works for other scripts, but not with this tutorial code somehow. Do you know why this happens?

That command is pure pyvista. I don’t know why it doesn’t work.

1 Like

Wondering in which situation that the length of a mesh.geometry.cmaps greater than 1?

When you have a mesh with a topology of more than one cell type. E.g. tets and prisms.

This has been removed in the main branch of DOLFINx, as we are looking for a different API for meshes with multiple cell types.

1 Like