pymor.functions package

Submodules

basic module


class pymor.functions.basic.ConstantFunction(value=array(1.0), dim_domain=1, name=None)[source]

Bases: pymor.functions.basic.FunctionBase

A constant Function

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.

class pymor.functions.basic.ExpressionFunction(expression, dim_domain=1, shape_range=(), parameter_type=None, values=None, name=None)[source]

Bases: pymor.functions.basic.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 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 x and a parameter mu given as a string.
dim_domain
The dimension of the domain.
shape_range
The shape of the values returned by the expression.
parameter_type
The ParameterType the expression accepts.
values
Dictionary of additional constants that can be used in expression with their corresponding value.
name
The name of the function.

class pymor.functions.basic.FunctionBase[source]

Bases: pymor.functions.interfaces.FunctionInterface

Base class for Functions providing some common functionality.

__add__(other)[source]

Returns a new LincombFunction representing the sum of two functions, or of one function and a constant.

__mul__(other)[source]

Returns a new LincombFunction representing the product of a function by a scalar.

__neg__()[source]

Returns a new LincombFunction representing the function scaled by -1.

__radd__(other)

Returns a new LincombFunction representing the sum of two functions, or of one function and a constant.

__rmul__(other)

Returns a new LincombFunction representing the product of a function by a scalar.

__sub__(other)[source]

Returns a new LincombFunction representing the difference of two functions, or of one function and a constant.


class pymor.functions.basic.GenericFunction(mapping, dim_domain=1, shape_range=(), parameter_type=None, name=None)[source]

Bases: pymor.functions.basic.FunctionBase

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 parameter_type is None, the function is of the form mapping(x). If parameter_type 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
The dimension of the domain.
shape_range
The shape of the values returned by the mapping.
parameter_type
The ParameterType the mapping accepts.
name
The name of the function.

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

Bases: pymor.functions.basic.FunctionBase

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.
functions
coefficients
evaluate_coefficients(mu)[source]

Compute the linear coefficients for a given Parameter mu.

bitmap module


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

Bases: pymor.functions.basic.FunctionBase

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].

interfaces module


class pymor.functions.interfaces.FunctionInterface[source]

Bases: pymor.core.interfaces.ImmutableInterface, pymor.parameters.base.Parametric

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.

dim_domain

The dimension d > 0.

shape_range

The shape of the function values.

__call__(x, mu=None)[source]

Shorthand for evaluate.

evaluate(x, mu=None)[source]

Evaluate the function for given argument x and Parameter mu.