pymor.analyticalproblems.functions¶
Module Contents¶
Classes¶
Interface for |
|
A constant |
|
Wrapper making an arbitrary Python function between |
|
Turns a Python expression given as a string into a |
|
Define a 2D |
|
Empirically interpolated |
|
Interface for |
|
Interface for |
- class pymor.analyticalproblems.functions.Function[source]¶
Bases:
pymor.parameters.base.ParametricObjectInterface for
Parameterdependent analytical functions.Every
Functionis a map of the formf(μ): Ω ⊆ R^d -> R^(shape_range)
The returned values are
NumPy arraysof 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.- abstract evaluate(self, x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- class pymor.analyticalproblems.functions.ConstantFunction(value=np.array(1.0), dim_domain=1, name=None)[source]¶
Bases:
FunctionA constant
FunctionDefined 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.
- evaluate(self, x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- class pymor.analyticalproblems.functions.GenericFunction(mapping, dim_domain=1, shape_range=(), parameters={}, name=None)[source]¶
Bases:
FunctionWrapper making an arbitrary Python function between
NumPy arraysa properFunction.Note that a
GenericFunctioncan only bepickledif the function it is wrapping can be pickled (cf.dumps_function). For this reason, it is usually preferable to useExpressionFunctioninstead ofGenericFunction.Parameters
- mapping
The function to wrap. If
parametersisNone, the function is of the formmapping(x). Ifparametersis 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
Parametersthe mapping accepts.- name
The name of the function.
- evaluate(self, x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- class pymor.analyticalproblems.functions.ExpressionFunction(expression, dim_domain=1, parameters={}, values={}, variable='x', name=None)[source]¶
Bases:
GenericFunctionTurns a Python expression given as a string into a
Function.Some
NumPyarithmetic functions like ‘sin’, ‘log’, ‘min’ are supported. For a full list see thefunctionsclass attribute.Warning
evalis 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
Parametersthe expression accepts.- values
Dictionary of additional constants that can be used in
expressionwith their corresponding value.- variable
Name of the input variable in the given expression.
- name
The name of the function.
- class pymor.analyticalproblems.functions.LincombFunction(functions, coefficients, name=None)[source]¶
Bases:
FunctionA
Functionrepresenting a linear combination ofFunctions.The linear coefficients can be provided either as scalars or as
ParameterFunctionals.Parameters
- functions
List of
Functionswhose 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.
- evaluate_coefficients(self, mu)[source]¶
Compute the linear coefficients for given
parameter valuesmu.
- evaluate(self, x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- class pymor.analyticalproblems.functions.ProductFunction(functions, name=None)[source]¶
Bases:
FunctionA
Functionrepresenting a product ofFunctions.Parameters
- functions
List of
Functionswhose product is formed.- name
Name of the function.
- evaluate(self, x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- class pymor.analyticalproblems.functions.BitmapFunction(filename, bounding_box=None, range=None)[source]¶
Bases:
FunctionDefine a 2D
Functionvia 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].
- evaluate(self, x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- 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:
LincombFunctionEmpirically interpolated
Function.Instantiated by
interpolate_function.Parameters
- function
The
Functionto interpolate.- interpolation_points
NumPy arraycontaining the coordinates at which the function is interpolated. TypicallyX[dofs]whereXis the array of evaluation points used for snapshot data generation anddofsis returned byei_greedy.- interpolation_matrix
The interpolation matrix corresponding to the selected interpolation basis vectors and
interpolation_pointsas returned bypymor.algorithms.ei.ei_greedy.- triangular
Whether or not
interpolation_matrixis lower triangular with unit diagonal.- snapshot_mus
List of
parameter valuesfor which the snapshot data forpymor.algorithms.ei.ei_greedyhas 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_muswith the i-th row ofsnapshot_coefficientsas coefficients. Returned byei_greedyasdata['coefficients'].- evaluation_points
Optional
NumPy arrayof 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 arrayof evaluations of the interpolation basis atevaluation_points. Corresponds to thebasisreturn value ofei_greedy.
- class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunctionFunctional(interpolated_function, index)[source]¶
Bases:
pymor.parameters.functionals.ParameterFunctionalInterface for
Parameterfunctionals.A parameter functional is simply a function mapping
Parametersto a number.- evaluate(self, mu=None)[source]¶
Evaluate the functional for given
parameter valuesmu.
- class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunctionBasisFunction(interpolated_function, index)[source]¶
Bases:
FunctionInterface for
Parameterdependent analytical functions.Every
Functionis a map of the formf(μ): Ω ⊆ R^d -> R^(shape_range)
The returned values are
NumPy arraysof 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.- evaluate(self, x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.