pymor.analyticalproblems.functions
¶
Module Contents¶
- class pymor.analyticalproblems.functions.BitmapFunction(filename, bounding_box=None, range=None)[source]¶
Bases:
Function
Define a 2D
Function
via a grayscale image.Parameters
- filename
Path of the image representing the function.
- bounding_box
Lower left and upper right coordinates of the domain of the function.
- range
A pixel of value p is mapped to
(p / 255.) * range[1] + range[0]
.
Methods
Evaluate the function for given argument
x
andparameter values
mu
.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
x
andparameter values
mu
.
- class pymor.analyticalproblems.functions.ConstantFunction(value=np.array(1.0), dim_domain=1, name=None)[source]¶
Bases:
Function
A constant
Function
Defined as
f: R^d -> R^shape(c), f(x) = c
Parameters
- value
The constant c.
- dim_domain
The dimension d.
- name
The name of the function.
Methods
Evaluate the function for given argument
x
andparameter values
mu
.Convert to ufl expression over dolfin mesh.
- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
x
andparameter values
mu
.
- to_fenics(mesh)[source]¶
Convert to ufl expression over dolfin mesh.
Parameters
- mesh
The dolfin mesh object.
Returns
- coeffs
NumPy array
of shapeself.shape_range
where each entry is an ufl expression.- params
Dict mapping parameter names to lists of dolfin
Constants
which are used in the ufl expressions for the corresponding parameter values.
- class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunction(function, interpolation_points, interpolation_matrix, triangular, snapshot_mus, snapshot_coefficients, evaluation_points=None, basis_evaluations=None, name=None)[source]¶
Bases:
LincombFunction
Empirically interpolated
Function
.Instantiated by
interpolate_function
.Parameters
- function
The
Function
to interpolate.- interpolation_points
NumPy array
containing the coordinates at which the function is interpolated. TypicallyX[dofs]
whereX
is the array of evaluation points used for snapshot data generation anddofs
is returned byei_greedy
.- interpolation_matrix
The interpolation matrix corresponding to the selected interpolation basis vectors and
interpolation_points
as returned bypymor.algorithms.ei.ei_greedy
.- triangular
Whether or not
interpolation_matrix
is lower triangular with unit diagonal.- snapshot_mus
List of
parameter values
for which the snapshot data forpymor.algorithms.ei.ei_greedy
has been computed.- snapshot_coefficients
Matrix of linear coefficients s.t. the i-th interpolation basis vector is given by a linear combination of the functions corresponding to
snapshot_mus
with the i-th row ofsnapshot_coefficients
as coefficients. Returned byei_greedy
asdata['coefficients']
.- evaluation_points
Optional
NumPy array
of coordinates at which the function has been evaluated to obtain the snapshot data. If the same evaluation points are used to evaluateEmpiricalInterpolatedFunction
, then re-evaluation of the snapshot data at the evaluation points can be avoided, when this argument is specified together withbasis_evaluations
.- basis_evaluations
Optional
NumPy array
of evaluations of the interpolation basis atevaluation_points
. Corresponds to thebasis
return value ofei_greedy
.
- class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunctionBasisFunction(interpolated_function, index)[source]¶
Bases:
Function
Interface for
Parameter
dependent analytical functions.Every
Function
is a map of the formf(μ): Ω ⊆ R^d -> R^(shape_range)
The returned values are
NumPy arrays
of arbitrary (but fixed) shape. Note that NumPy distinguishes between one-dimensional arrays of length 1 (with shape(1,)
) and zero-dimensional scalar arrays (with shape()
). In pyMOR, we usually expect scalar-valued functions to haveshape_range == ()
.While the function might raise an error if it is evaluated for an argument not in the domain Ω, the exact behavior is left undefined.
Functions are vectorized in the sense, that if
x.ndim == k
, thenf(x, μ)[i0, i1, ..., i(k-2)] == f(x[i0, i1, ..., i(k-2)], μ).
In particular,
f(x, μ).shape == x.shape[:-1] + shape_range
.Methods
Evaluate the function for given argument
x
andparameter values
mu
.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
x
andparameter values
mu
.
- class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunctionFunctional(interpolated_function, index)[source]¶
Bases:
pymor.parameters.functionals.ParameterFunctional
Interface for
Parameter
functionals.A parameter functional is simply a function mapping
Parameters
to a number.Methods
Evaluate the functional for given
parameter values
mu
.- evaluate(mu=None)[source]¶
Evaluate the functional for given
parameter values
mu
.
- class pymor.analyticalproblems.functions.ExpressionFunction(expression, dim_domain=1, parameters={}, values={}, variable='x', name=None)[source]¶
Bases:
GenericFunction
Turns a Python expression given as a string into a
Function
.Some
NumPy
arithmetic functions like ‘sin’, ‘log’, ‘min’ are supported. For a full list see thefunctions
class attribute.Warning
eval
is used to evaluate the given expression. Using this class with expression strings from untrusted sources will cause mayhem and destruction!Parameters
- expression
A Python expression of one variable and the
parameters
, given as astr
.- dim_domain
The dimension of the domain.
- parameters
The
Parameters
the expression accepts.- values
Dictionary of additional constants that can be used in
expression
with their corresponding value.- variable
Name of the input variable in the given expression.
- name
The name of the function.
Methods
Convert to ufl expression over dolfin mesh.
- to_fenics(mesh)[source]¶
Convert to ufl expression over dolfin mesh.
Parameters
- mesh
The dolfin mesh object.
Returns
- coeffs
NumPy array
of shapeself.shape_range
where each entry is an ufl expression.- params
Dict mapping parameter names to lists of dolfin
Constants
which are used in the ufl expressions for the corresponding parameter values.
- class pymor.analyticalproblems.functions.Function[source]¶
Bases:
pymor.parameters.base.ParametricObject
Interface for
Parameter
dependent analytical functions.Every
Function
is a map of the formf(μ): Ω ⊆ R^d -> R^(shape_range)
The returned values are
NumPy arrays
of arbitrary (but fixed) shape. Note that NumPy distinguishes between one-dimensional arrays of length 1 (with shape(1,)
) and zero-dimensional scalar arrays (with shape()
). In pyMOR, we usually expect scalar-valued functions to haveshape_range == ()
.While the function might raise an error if it is evaluated for an argument not in the domain Ω, the exact behavior is left undefined.
Functions are vectorized in the sense, that if
x.ndim == k
, thenf(x, μ)[i0, i1, ..., i(k-2)] == f(x[i0, i1, ..., i(k-2)], μ).
In particular,
f(x, μ).shape == x.shape[:-1] + shape_range
.Methods
Evaluate the function for given argument
x
andparameter values
mu
.- abstract evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
x
andparameter values
mu
.
- class pymor.analyticalproblems.functions.GenericFunction(mapping, dim_domain=1, shape_range=(), parameters={}, name=None)[source]¶
Bases:
Function
Wrapper making an arbitrary Python function between
NumPy arrays
a properFunction
.Note that a
GenericFunction
can only bepickled
if the function it is wrapping can be pickled (cf.dumps_function
). For this reason, it is usually preferable to useExpressionFunction
instead ofGenericFunction
.Parameters
- mapping
The function to wrap. If
parameters
isNone
, the function is of the formmapping(x)
. Ifparameters
is notNone
, the function has to have the signaturemapping(x, mu)
. Moreover, the function is expected to be vectorized, i.e.:mapping(x).shape == x.shape[:-1] + shape_range.
- dim_domain
The dimension of the domain.
- shape_range
The shape of the values returned by the mapping.
- parameters
The
Parameters
the mapping accepts.- name
The name of the function.
Methods
Evaluate the function for given argument
x
andparameter values
mu
.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
x
andparameter values
mu
.
- class pymor.analyticalproblems.functions.LincombFunction(functions, coefficients, name=None)[source]¶
Bases:
Function
A
Function
representing a linear combination ofFunctions
.The linear coefficients can be provided either as scalars or as
ParameterFunctionals
.Parameters
- functions
List of
Functions
whose linear combination is formed.- coefficients
A list of linear coefficients. A linear coefficient can either be a fixed number or a
ParameterFunctional
.- name
Name of the function.
Methods
Evaluate the function for given argument
x
andparameter values
mu
.Compute the linear coefficients for given
parameter values
mu
.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
x
andparameter values
mu
.
- evaluate_coefficients(mu)[source]¶
Compute the linear coefficients for given
parameter values
mu
.
- class pymor.analyticalproblems.functions.ProductFunction(functions, name=None)[source]¶
Bases:
Function
A
Function
representing a product ofFunctions
.Parameters
- functions
List of
Functions
whose product is formed.- name
Name of the function.
Methods
Evaluate the function for given argument
x
andparameter values
mu
.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
x
andparameter values
mu
.