Post-processing#

Post-processing of DOLFINx functions: integrals, norms, lines and ranges.

Integrals, norms and errors#

sumfem.post_processing.integrate(expr, mesh=None, coordinates=None)[source]#

The integral of an integrand over its whole mesh, on every process.

Parameters:
  • expr (Expr | float) – A scalar integrand of DOLFINx functions, constants and the mesh’s coordinates, e.g. the square of an error.

  • mesh (Mesh | None) – The mesh, needed when the integrand does not name one, such as a number to measure the mesh’s volume.

  • coordinates (CoordinateSystem | None) – The coordinate system of the mesh, which weights the integral and writes its vectors, e.g. that of the domain the mesh belongs to. Cartesian by default.

Return type:

float

sumfem.post_processing.norm(expr, kind=NormType.L2, mesh=None, coordinates=None)[source]#

A norm of an expression over its whole mesh, on every process.

Parameters:
  • expr (Expr) – A scalar, vector or tensor expression, e.g. an error.

  • kind (NormType | str | Callable[[Expr], Expr]) – Which norm, see NormType. For l2, expr must be a function. A callable gives a custom norm: it takes f and returns the integrand of the squared norm, e.g. lambda f: w * ufl.inner(f, f) for an L2 norm with the weight w.

  • mesh (Mesh | None) – See integrate().

  • coordinates (CoordinateSystem | None) – See integrate(). It does not weight l2.

Raises:
Return type:

float

sumfem.post_processing.error(function, exact, kind=NormType.L2, relative=False, coordinates=None)[source]#

The error of a function against an exact solution, in a norm().

Parameters:
Return type:

float

class sumfem.post_processing.NormType(*values)[source]#

The kind of a norm(). Plain strings with these values work too.

l2 = 'l2'#

The Euclidean norm of the degrees of freedom of a function.

L2 = 'L2'#

sqrt((f, f)).

H1 = 'H1'#

sqrt((f, f) + (grad f, grad f)).

H10 = 'H10'#

The seminorm sqrt((grad f, grad f)).

Hdiv = 'Hdiv'#

sqrt((f, f) + (div f, div f)), for vectors.

Hcurl = 'Hcurl'#

sqrt((f, f) + (curl f, curl f)), for vectors.

sumfem.post_processing.Squared#

the square of the integrand of a quantity f.

Type:

A custom norm

alias of Callable[[Expr], Expr]

Evaluation#

sumfem.post_processing.evaluate_at_points(function, points)[source]#

Evaluate a function at points, each on the process that owns it.

dolfinx.geometry.determine_point_ownership() gives each point in the mesh one owning process, also on the boundary between processes. Points outside the mesh are evaluated nowhere. Collective.

Parameters:
Returns:

The indices of the points evaluated on this process, increasing, and the values there, of shape (len(indices), value size).

Return type:

tuple[ndarray[tuple[Any, …], dtype[int32]], ndarray[tuple[Any, …], dtype[float64]]]

sumfem.post_processing.function_range(function, entities=None, dim=None)[source]#

The global minimum and maximum of the values of a scalar function.

These are the extreme values of the degrees of freedom, which bound the function for Lagrange elements of degree one or zero.

Parameters:
  • function (Function) – The function.

  • entities (ndarray[tuple[Any, ...], dtype[int32]] | None) – Local indices of mesh entities whose degrees of freedom bound the range, e.g. the cells of a subdomain or the facets of a surface. None for the whole mesh.

  • dim (int | None) – Topological dimension of the entities. Defaults to the cells.

Raises:

ValueError – For a function with several components.

Return type:

tuple[float, float]

sumfem.post_processing.create_line(p0, p1, num_points, comm=<mpi4py.MPI.Intracomm object>)[source]#

A mesh of interval cells on the line segment from p0 to p1.

The points are created on process 0, and DOLFINx distributes the cells.

Parameters:
Return type:

Mesh

sumfem.post_processing.interpolate_to_line(expr, p0, p1, num_points, element)[source]#

Interpolate an expression into a function on a line segment.

The line is L(alpha) = p0 + alpha (p1 - p0) for alpha in [0, 1], meshed by create_line(). The expression is first interpolated into a space of the element on its own mesh, and then moved to the line by non-matching interpolation.

Parameters:
  • expr (Expr) – A UFL expression on a single mesh.

  • p0 (ndarray[tuple[Any, ...], dtype[floating]]) – The first point of the line.

  • p1 (ndarray[tuple[Any, ...], dtype[floating]]) – The last point of the line.

  • num_points (int) – Number of points on the line, including both ends.

  • element (ElementMetaData) – The element of the function on the line, and of the intermediate space on the expression’s mesh.

Returns:

The function on the line mesh.

Raises:

ValueError – If the expression is not on a single mesh.

Return type:

Function

sumfem.post_processing.evaluate_over_line(function, start, end, num_points)[source]#

Evaluate a function at equidistant points on a line segment.

Each point is evaluated on the process that owns it, see evaluate_at_points(). Collective.

Parameters:
Returns:

The points on this process, of shape (n, 3), and the values there, of shape (n, value size).

Return type:

tuple[ndarray[tuple[Any, …], dtype[float64]], ndarray[tuple[Any, …], dtype[float64]]]