Evaluation of UFL expression at mesh points

Please note that Dx(f, 1) is not uniquely defined at vertices (when f is a CG 1 function). Thus there is ambiguity in what the value should be at a vertex.

What you can do if you insist of evaluating the expression at the vertices, is that you:

  1. Interpolate the ufl expression into an appropriate space, as for instance shown here: dolfinx/test_interpolation.py at c9f3c459a75f02abcf255a9dd05185350eb1edde · FEniCS/dolfinx · GitHub
  2. Use the point evaluation function for the vertices, as shown here: Implementation — FEniCSx tutorial

However, note that you can send in the cells you want to use the dolfinx.Expression at, which you can reduce to a subset of cells spanning all the unique vertices, reducing the size of the output array from cells * num_vertices_per_cell=3*num_cells in your example above, to 3*subset_of_cells, which will depend on which cells you choose to cover all vertices.