cashocs.Interpolator#
- class cashocs.Interpolator(origin_space: fenics.FunctionSpace, target_space: fenics.FunctionSpace)[source]#
Bases:
object
Efficient interpolation between two function spaces.
This is very useful, if multiple interpolations have to be carried out between the same spaces, which is made significantly faster by computing the corresponding matrix. The function spaces can even be defined on different meshes.
Notes
This class only works properly for continuous Lagrange elements and constant, discontinuous Lagrange elements.
Examples
Here, we consider interpolating from CG1 elements to CG2 elements
import fenics import cashocs mesh, _, _, _, _, _ = cashocs.regular_mesh(25) V1 = fenics.FunctionSpace(mesh, 'CG', 1) V2 = fenics.FunctionSpace(mesh, 'CG', 2) expr = fenics.Expression('sin(2*pi*x[0])', degree=1) u = fenics.interpolate(expr, V1) interp = cashocs._utils.Interpolator(V1, V2) interp.interpolate(u)
Initializes self.
- Parameters:
origin_space (fenics.FunctionSpace) – The function space whose objects shall be interpolated.
target_space (fenics.FunctionSpace) – The space into which they shall be interpolated.
Methods Summary
interpolate
(u)Interpolates function to target space.
Methods Documentation
- interpolate(u: fenics.Function) fenics.Function [source]#
Interpolates function to target space.
The function has to belong to the origin space, i.e., the first argument of __init__, and it is interpolated to the destination space, i.e., the second argument of __init__. There is no need to call set_allow_extrapolation on the function (this is done automatically due to the method).
- Parameters:
u (fenics.Function) – The function that shall be interpolated.
- Returns:
The result of the interpolation.
- Return type:
fenics.Function