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:
- 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. Forl2,exprmust be a function. A callable gives a custom norm: it takesfand returns the integrand of the squared norm, e.g.lambda f: w * ufl.inner(f, f)for an L2 norm with the weightw.mesh (Mesh | None) – See
integrate().coordinates (CoordinateSystem | None) – See
integrate(). It does not weightl2.
- Raises:
TypeError – For
"l2"of anything but a function.ValueError – For an unknown kind.
- Return type:
- 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:
function (Function) – The approximation.
exact (Expr | Callable[[SpatialCoordinate], Expr]) – The exact solution, as an expression on the function’s mesh or as a callable of the mesh’s spatial coordinate.
kind (NormType | str | Callable[[Expr], Expr]) – The norm, see
NormType. Notl2.relative (bool) – Divide by the norm of the exact solution.
coordinates (CoordinateSystem | None) – See
integrate().
- Return type:
- 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.
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.
- 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.
Nonefor 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:
- 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
p0top1.The points are created on process 0, and DOLFINx distributes the cells.
- Parameters:
- Return type:
- 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)foralphain[0, 1], meshed bycreate_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:
- 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:
function (Function) – The function.
start (Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) – The first point, with as many coordinates as the mesh.
end (Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) – The last point.
num_points (int) – Number of points, including both ends.
- 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]]]