pymor.analyticalproblems.functions¶
Module Contents¶
- class pymor.analyticalproblems.functions.BitmapFunction(bitmap, bounding_box=None)[source]¶
Bases:
FunctionDefine a piecewise constant 2D
Functionvia a bitmap array.Parameters
- bitmap
2d
NumPy arrayof the discrete function values.- bounding_box
Lower left and upper right coordinates of the domain of the function.
Methods
Evaluate the function for given argument
xandparameter valuesmu.Create a
BitmapFunctionfrom a grayscale image file.Create a random
BitmapFunctionwith uniform distribution of values.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- classmethod from_file(filename, bounding_box=None, range=None)[source]¶
Create a
BitmapFunctionfrom a grayscale image file.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].
- classmethod random(shape=(1, 1), bounding_box=((0.0, 0.0), (1.0, 1.0)), range=(0.0, 1.0))[source]¶
Create a random
BitmapFunctionwith uniform distribution of values.Parameters
- bounding_box
Lower left and upper right coordinates of the domain of the function.
- range
Tuple of minimum and maximum function values.
- class pymor.analyticalproblems.functions.ConstantFunction(value=np.array(1.0), dim_domain=1, name=None)[source]¶
Bases:
FunctionA 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
xandparameter valuesmu.Convert to ufl expression over dolfin mesh.
- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- to_fenics(mesh)[source]¶
Convert to ufl expression over dolfin mesh.
Parameters
- mesh
The dolfin mesh object.
Returns
- coeffs
NumPy arrayof shapeself.shape_rangewhere each entry is an ufl expression.- params
Dict mapping parameter names to lists of dolfin
Constantswhich 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:
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.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.Methods
Evaluate the function for given argument
xandparameter valuesmu.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- 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.Methods
Evaluate the functional for given
parameter valuesmu.- evaluate(mu=None)[source]¶
Evaluate the functional for given
parameter valuesmu.
- class pymor.analyticalproblems.functions.ExpressionFunction(expression, dim_domain=1, parameters={}, values={}, variable='x', name=None)[source]¶
Bases:
SymbolicExpressionFunctionTurns 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.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.Methods
Evaluate the function for given argument
xandparameter valuesmu.Convert to ufl expression over dolfin mesh.
- abstract evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- abstract to_fenics(mesh)[source]¶
Convert to ufl expression over dolfin mesh.
Parameters
- mesh
The dolfin mesh object.
Returns
- coeffs
NumPy arrayof shapeself.shape_rangewhere each entry is an ufl expression.- params
Dict mapping parameter names to lists of dolfin
Constantswhich are used in the ufl expressions for the corresponding parameter values.
- 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.
Methods
Evaluate the function for given argument
xandparameter valuesmu.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- 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.
Methods
Evaluate the function for given argument
xandparameter valuesmu.Compute the linear coefficients for given
parameter valuesmu.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- evaluate_coefficients(mu)[source]¶
Compute the linear coefficients for given
parameter 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.
Methods
Evaluate the function for given argument
xandparameter valuesmu.- evaluate(x, mu=None)[source]¶
Evaluate the function for given argument
xandparameter valuesmu.
- class pymor.analyticalproblems.functions.SymbolicExpressionFunction(expression_obj, dim_domain=1, variable='x', name=None)[source]¶
Bases:
GenericFunctionTurns a symbolic expression into a
Function.Parameters
- expression
- dim_domain
The dimension of the domain.
- 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 arrayof shapeself.shape_rangewhere each entry is an ufl expression.- params
Dict mapping parameter names to lists of dolfin
Constantswhich are used in the ufl expressions for the corresponding parameter values.