warp.fem.interpolate#

warp.fem.interpolate(
integrand,
dest=None,
at=None,
dest_space=None,
quadrature=None,
dim=None,
domain=None,
fields=None,
values=None,
reduction='weighted_average',
device=None,
kernel_options=None,
temporary_store=None,
bsr_options=None,
)[source]#

Interpolates a function at a finite set of sample points and optionally assigns the result to a discrete field, raw warp array, or sparse matrix.

Interpolation can be performed either at nodes of a function space (or a restriction of), typically used to set values of a discrete field, or at arbitrary points in a domain, for instance using a quadrature formula.

Parameters:
  • integrand (Integrand | FieldLike) – Function to be interpolated: either a function with warp.fem.integrand() decorator or a field

  • dest (DiscreteField | FieldRestriction | array | BsrMatrix | None) –

    Where to store the interpolation result. Can be either

    • a DiscreteField, or restriction of a discrete field to a domain (from make_restriction());

    • a normal warp array;

    • a sparse matrix (warp.sparse.BsrMatrix). This will compute the jacooian of integrand, assuming one of the passed fields is a trial field,

      and that the result is a linear function of the trial field;

    • None, meaning the integrand will be evaluated at the interpolation sample points, but the result will be discarded.

  • at (Quadrature | SpaceRestriction | GeometryDomain | None) –

    Location of the interpolation samples. Can be either

    • a SpaceRestriction, in which case interpolation will be performed at each node of dest_space in the restriction’s domain.

    • a Quadrature, in which case interpolation will be performed at each quadrature point.

    • a GeometryDomain. In this case, interpolation will be performed:

      • at each of the domain’s nodes, if dest is a field or dest_space is provided;

      • at an arbitrary number of samples, in the domain if dim is provided;

      • at each of the domain’s elements, otherwise).

    • None, in which case it will be inferred from dest, dest_space, or the deprecated domain and quadrature arguments, when possible.

  • dest_space (FunctionSpace | None) – When interpolating at nodes, the function space that defines the degree of freedom basis. If dest is a DiscreteField, or a FieldRestriction, this will be inferred from the space of the field.

  • quadrature (Quadrature | None) – (Deprecated) Equivalent to passing a Quadrature to at. Will be removed in 1.13.

  • dim (int | None) – If dest is an array or None, and at is a GeometryDomain, the number of arbitrary samples at which to interpolate. In this case, the Sample passed to the integrand will be invalid, but the sample point index s.qp_index can be used to define custom interpolation logic.

  • domain (GeometryDomain | None) – (Deprecated) Equivalent to passing a Domain to at. Will be removed in 1.13.

  • fields (dict[str, FieldLike] | None) – Discrete fields to be passed to the integrand. Keys in the dictionary must match integrand parameters names.

  • values (dict[str, Any] | None) – Additional variable values to be passed to the integrand, can be of any type accepted by warp kernel launches. Keys in the dictionary must match integrand parameter names.

  • reduction (str) – Reduction method to be used for interpolation at nodes shared by several elements. Can be one of “weighted_average”, “mean”, “sum”, “max”, “min”, “first”. Default to “weighted_average”, meaning measure-weighted average over neighboring elements. If the interpolated field is continuous, meaning that the returned value is identical regardless of the element used for evaluation, all reduction methods should be equivalent but “first” will have the lowest computational cost.

  • device – Device on which to perform the interpolation

  • kernel_options (dict[str, Any] | None) – Overloaded options to be passed to the kernel builder (e.g, {"enable_backward": True})

  • temporary_store (TemporaryStore | None) – shared pool from which to allocate temporary arrays

  • bsr_options (dict[str, Any] | None) – Additional options to be passed to the sparse matrix construction algorithm. See warp.sparse.bsr_set_from_triplets()