pymor.analyticalproblems.functions

Classes

BitmapFunction

Define a piecewise constant 2D Function via a bitmap array.

ConstantFunction

A constant Function.

EmpiricalInterpolatedFunction

Empirically interpolated Function.

EmpiricalInterpolatedFunctionBasisFunction

EmpiricalInterpolatedFunctionFunctional

ExpressionFunction

Turns a Python expression given as a string into a Function.

Function

Interface for Parameter dependent analytical functions.

GenericFunction

Wrapper making an arbitrary Python function between NumPy arrays a proper Function.

LincombFunction

A Function representing a linear combination of Functions.

ProductFunction

A Function representing a product of Functions.

SymbolicExpressionFunction

Turns a symbolic expression into a Function.

class pymor.analyticalproblems.functions.BitmapFunction(bitmap, bounding_box=None)[source]

Bases: Function

Define a piecewise constant 2D Function via a bitmap array.

Parameters:
  • bitmap – 2d NumPy array of the discrete function values.

  • bounding_box – Lower left and upper right coordinates of the domain of the function.

classmethod from_file(filename, bounding_box=None, range=None)[source]

Create a BitmapFunction from 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 BitmapFunction with 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.

evaluate(x, mu=None)[source]

Evaluate the function for given argument x and parameter values mu.

dim_domain: int = 2[source]

The dimension d > 0.

shape_range: tuple[int, ...] = ()[source]

The shape of the function values.

class pymor.analyticalproblems.functions.ConstantFunction(value=array(1.), 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 (int) – The dimension d.

  • name – The name of the function.

evaluate(x, mu=None)[source]

Evaluate the function for given argument x and parameter values mu.

to_fenics(mesh)[source]

Convert to ufl expression over dolfin mesh.

Parameters:

mesh – The dolfin mesh object.

Returns:

  • coeffs – NumPy array of shape self.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. Typically X[dofs] where X is the array of evaluation points used for snapshot data generation and dofs is returned by ei_greedy.

  • interpolation_matrix – The interpolation matrix corresponding to the selected interpolation basis vectors and interpolation_points as returned by pymor.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 for pymor.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 of snapshot_coefficients as coefficients. Returned by ei_greedy as data['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 evaluate EmpiricalInterpolatedFunction, then re-evaluation of the snapshot data at the evaluation points can be avoided, when this argument is specified together with basis_evaluations.

  • basis_evaluations – Optional NumPy array of evaluations of the interpolation basis at evaluation_points. Corresponds to the basis return value of ei_greedy.

class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunctionBasisFunction(interpolated_function, index)[source]

Bases: Function

evaluate(x, mu=None)[source]

Evaluate the function for given argument x and parameter values mu.

class pymor.analyticalproblems.functions.EmpiricalInterpolatedFunctionFunctional(interpolated_function, index)[source]

Bases: ParameterFunctional

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: SymbolicExpressionFunction

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 the functions 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 a str.

  • dim_domain (int) – 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.

class pymor.analyticalproblems.functions.Function[source]

Bases: ParametricObject

Interface for Parameter dependent analytical functions.

Every Function is a map of the form

f(μ): Ω ⊆ 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 have shape_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, then

f(x, μ)[i0, i1, ..., i(k-2)] == f(x[i0, i1, ..., i(k-2)], μ).

In particular, f(x, μ).shape == x.shape[:-1] + shape_range.

abstractmethod evaluate(x, mu=None)[source]

Evaluate the function for given argument x and parameter values mu.

to_fenics(mesh)[source]

Convert to ufl expression over dolfin mesh.

Parameters:

mesh – The dolfin mesh object.

Returns:

  • coeffs – NumPy array of shape self.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.

dim_domain: int[source]

The dimension d > 0.

shape_range: tuple[int, ...][source]

The shape of the function values.

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 proper Function.

Note that a GenericFunction can only be pickled if the function it is wrapping can be pickled (cf. dumps_function). For this reason, it is usually preferable to use ExpressionFunction instead of GenericFunction.

Parameters:
  • mapping –

    The function to wrap. If parameters is None, the function is of the form mapping(x). If parameters is not None, the function has to have the signature mapping(x, mu). Moreover, the function is expected to be vectorized, i.e.:

    mapping(x).shape == x.shape[:-1] + shape_range.
    

  • dim_domain (int) – The dimension of the domain.

  • shape_range (tuple[int, ...]) – The shape of the values returned by the mapping.

  • parameters – The Parameters the mapping accepts.

  • name – The name of the function.

evaluate(x, mu=None)[source]

Evaluate the function for given argument x and parameter values mu.

class pymor.analyticalproblems.functions.LincombFunction(functions, coefficients, name=None)[source]

Bases: Function

A Function representing a linear combination of Functions.

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.

evaluate(x, mu=None)[source]

Evaluate the function for given argument x and parameter 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 of Functions.

Parameters:
  • functions – List of Functions whose product is formed.

  • name – Name of the function.

evaluate(x, mu=None)[source]

Evaluate the function for given argument x and parameter values mu.

class pymor.analyticalproblems.functions.SymbolicExpressionFunction(expression_obj, dim_domain=1, variable='x', name=None)[source]

Bases: GenericFunction

Turns a symbolic expression into a Function.

Parameters:
to_fenics(mesh)[source]

Convert to ufl expression over dolfin mesh.

Parameters:

mesh – The dolfin mesh object.

Returns:

  • coeffs – NumPy array of shape self.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.