Evaluation of Quantities of Interest

After solving a PDE system, the solution is available in the form of finite element functions. Besides visualizing the solution (see Output), evaluating certain quantities of interest is usually desired, such as the value of the solution at particular points, averages of the solution, fluxes, solution norms, or more complex quantities like von Mises equivalent stress in solid mechanics or lift and drag in fluid mechanics.

Pointwise evaluations

FE functions support the evaluation of values and derivatives by global position or by local position for a given cell. Note that evaluation by global position involves a search for the cell containing the position, is therefore extremely expensive on large meshes, and should be avoided in production code.

auto uVal   = u.value(GlobalPosition<Grid>({0.1,0.2}));
auto uDeriv = u.derivative(cell,LocalPosition<Grid>({0.02,0.02}));

For a function with \( m \) components per shape function, a vector of type Dune::FieldVector<Scalar,components> is returned as value, even if the function is scalar. The derivative is always taken with respect to the global world coordinates and has type Dune::FieldMatrix<Scalar,components,dimworld>. In the scalar two-dimensional example above, uVal is therefore a Dune::FieldVector<double,1> (access its entry with uVal[0]), and uDeriv is a Dune::FieldMatrix<double,1,2>.

Norms and integrals

Kaskade 7 provides norm functors in fem/norms.hh and integration functions in fem/integration.hh. For a scalar or vector-valued FE function u,

#include "fem/norms.hh"
#include "fem/integration.hh"

double l2  = L2Norm()(component<0>(u));
double h1  = H1Norm()(component<0>(u));
double sem = H1SemiNorm()(component<0>(u));
double vol = integral(component<0>(u))[0];       // integral over the domain

The norm functors compute \(|u|{L^2}\), \(|u|{H^1}\), and the \(H^1\)-seminorm \(|\nabla u|_{L^2}\), respectively. The free function integral integrates a finite element function or a function view over the domain. Boundary integrals are available via integrateOverBoundary and boundaryL2Norm.

For error control, the norms are often evaluated on the difference of two functions. A FunctionView can be used to form such expressions without storing an additional FE function.

Function views

Function views provide a lightweight way to evaluate transformed FE functions without assembling a new finite element function. Examples in fem/functionviews.hh are AbsSquare, Gradient, and Difference. A view is evaluated on a cell and a local coordinate, or through an evaluator, just like an FE function. Typical uses are error norms, flux computations, and postprocessing.

#include "fem/functionviews.hh"

// |grad u|^2 as a function view
FunctionViews::GradientAbsSquare<decltype(component<0>(u))> gradSq(component<0>(u));
double energy = integral(gradSq);

For evaluating a user-defined expression on each cell, use makeFunctionView (from fem/fetransfer.hh) with the finite element space and a lambda taking an evaluator:

auto flux = makeFunctionView(h1Space,[&](auto const& evaluator)
{
  auto x = evaluator.cell().geometry().center();
  return Dune::FieldVector<double,1>(x[0]*component<0>(u).value(evaluator)[0]);
});

Page last modified: 2026-11-10