Fenicsx equivalent of compute_vertex_values()

Hi all,

in Fenics, I used to be able to compute the value of a function at vertices using compute_vertex_values().

I noticed that Fenicsx allows running f.x.array, but this returns the value of the function at all degrees of freedom, as opposed to just the mesh vertices. This can be different if the function degree is greater than 1.

For a scalar function defined on a 1D domain (e.g. a radial domain), I would like to be able to use plt.plot on mesh.geometry.x and f.compute_vertex_values(), if it existed. Is there a Fenicsx equivalent of compute_vertex_values?

You can consider, as an example, this MWE:

from mpi4py import MPI

import dolfinx as d
import ufl

import matplotlib.pyplot as plt
import numpy as np

msh = d.mesh.create_interval( comm=MPI.COMM_WORLD,
                                    nx=100, points=(0, 10) )

def profile( r ):
    return 1 / ( np.exp( ( r[0] - 1) / 0.2 ) + 1. )

Pn = ufl.FiniteElement( 'CG', msh.ufl_cell(), 4 )
S = d.fem.FunctionSpace( msh, Pn )
f = d.fem.Function(S)

f.interpolate(profile)

plt.plot( msh.geometry.x[:,0], f.x.array )

Thanks!

Why not just tabulate the dof coordinates using
S.tabulate_dof_coordinates() and get a more accurate plot than a first order representation of the function?

To Get data at vertices, you should interpolate your solution in to a first order space.

You have a point. I will use your method. Thanks!