pymor.operators package

Submodules

basic module


class pymor.operators.basic.OperatorBase[source]

Bases: pymor.operators.interfaces.OperatorInterface

Base class for Operators providing some default implementations.

When implementing a new operator, it is usually advisable to derive from this class.


class pymor.operators.basic.ProjectedOperator(operator, range_basis, source_basis, product=None, solver_options=None)[source]

Bases: pymor.operators.basic.OperatorBase

Generic Operator representing the projection of an Operator to a subspace.

This operator is implemented as the concatenation of the linear combination with source_basis, application of the original operator and projection onto range_basis. As such, this operator can be used to obtain a reduced basis projection of any given Operator. However, no offline/online decomposition is performed, so this operator is mainly useful for testing before implementing offline/online decomposition for a specific application.

This operator is instantiated in pymor.algorithms.projection.project as a default implementation for parametric or nonlinear operators.

Parameters

operator
The Operator to project.
source_basis
See pymor.algorithms.projection.project.
range_basis
See pymor.algorithms.projection.project.
product
See pymor.algorithms.projection.project.

block module


class pymor.operators.block.BlockDiagonalOperator(blocks)[source]

Bases: pymor.operators.block.BlockOperator

Block diagonal Operator of arbitrary Operators.

This is a specialization of BlockOperator for the block diagonal case.


class pymor.operators.block.BlockOperator(blocks)[source]

Bases: pymor.operators.basic.OperatorBase

A matrix of arbitrary Operators.

This operator can be applied to a compatible BlockVectorArrays.

Parameters

blocks
Two-dimensional array-like where each entry is an Operator or None.
classmethod hstack(operators)[source]

Horizontal stacking of Operators.

Parameters

operators
An iterable where each item is an Operator or None.
classmethod vstack(operators)[source]

Vertical stacking of Operators.

Parameters

operators
An iterable where each item is an Operator or None.

cg module

This module provides some operators for continuous finite element discretizations.


class pymor.operators.cg.AdvectionOperatorP1(grid, boundary_info, advection_function=None, advection_constant=None, dirichlet_clear_columns=False, dirichlet_clear_diag=False, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Linear advection Operator for linear finite elements.

The operator is of the form

(Lu)(x) = c ∇ ⋅ [ v(x) u(x) ]

The function v is vector-valued. The current implementation works in one and two dimensions, but can be trivially extended to arbitrary dimensions.

Parameters

grid
The Grid for which to assemble the operator.
boundary_info
BoundaryInfo for the treatment of Dirichlet boundary conditions.
advection_function
The Function v(x) with shape_range = (grid.dim, ). If None, constant one is assumed.
advection_constant
The constant c. If None, c is set to one.
dirichlet_clear_columns
If True, set columns of the system matrix corresponding to Dirichlet boundary DOFs to zero to obtain a symmetric system matrix. Otherwise, only the rows will be set to zero.
dirichlet_clear_diag
If True, also set diagonal entries corresponding to Dirichlet boundary DOFs to zero. Otherwise they are set to one.
name
Name of the operator.

class pymor.operators.cg.AdvectionOperatorQ1(grid, boundary_info, advection_function=None, advection_constant=None, dirichlet_clear_columns=False, dirichlet_clear_diag=False, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Linear advection Operator for bilinear finite elements.

The operator is of the form

(Lu)(x) = c ∇ ⋅ [ v(x) u(x) ]

The function v has to be vector-valued. The current implementation works in two dimensions, but can be trivially extended to arbitrary dimensions.

Parameters

grid
The Grid for which to assemble the operator.
boundary_info
BoundaryInfo for the treatment of Dirichlet boundary conditions.
advection_function
The Function v(x) with shape_range = (grid.dim, ). If None, constant one is assumed.
advection_constant
The constant c. If None, c is set to one.
dirichlet_clear_columns
If True, set columns of the system matrix corresponding to Dirichlet boundary DOFs to zero to obtain a symmetric system matrix. Otherwise, only the rows will be set to zero.
dirichlet_clear_diag
If True, also set diagonal entries corresponding to Dirichlet boundary DOFs to zero. Otherwise they are set to one.
name
Name of the operator.

pymor.operators.cg.CGVectorSpace(grid, id_='STATE')[source]

class pymor.operators.cg.DiffusionOperatorP1(grid, boundary_info, diffusion_function=None, diffusion_constant=None, dirichlet_clear_columns=False, dirichlet_clear_diag=False, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Diffusion Operator for linear finite elements.

The operator is of the form

(Lu)(x) = c ∇ ⋅ [ d(x) ∇ u(x) ]

The function d can be scalar- or matrix-valued. The current implementation works in one and two dimensions, but can be trivially extended to arbitrary dimensions.

Parameters

grid
The Grid for which to assemble the operator.
boundary_info
BoundaryInfo for the treatment of Dirichlet boundary conditions.
diffusion_function
The Function d(x) with shape_range == () or shape_range = (grid.dim, grid.dim). If None, constant one is assumed.
diffusion_constant
The constant c. If None, c is set to one.
dirichlet_clear_columns
If True, set columns of the system matrix corresponding to Dirichlet boundary DOFs to zero to obtain a symmetric system matrix. Otherwise, only the rows will be set to zero.
dirichlet_clear_diag
If True, also set diagonal entries corresponding to Dirichlet boundary DOFs to zero. Otherwise they are set to one.
name
Name of the operator.

class pymor.operators.cg.DiffusionOperatorQ1(grid, boundary_info, diffusion_function=None, diffusion_constant=None, dirichlet_clear_columns=False, dirichlet_clear_diag=False, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Diffusion Operator for bilinear finite elements.

The operator is of the form

(Lu)(x) = c ∇ ⋅ [ d(x) ∇ u(x) ]

The function d can be scalar- or matrix-valued. The current implementation works in two dimensions, but can be trivially extended to arbitrary dimensions.

Parameters

grid
The Grid for which to assemble the operator.
boundary_info
BoundaryInfo for the treatment of Dirichlet boundary conditions.
diffusion_function
The Function d(x) with shape_range == () or shape_range = (grid.dim, grid.dim). If None, constant one is assumed.
diffusion_constant
The constant c. If None, c is set to one.
dirichlet_clear_columns
If True, set columns of the system matrix corresponding to Dirichlet boundary DOFs to zero to obtain a symmetric system matrix. Otherwise, only the rows will be set to zero.
dirichlet_clear_diag
If True, also set diagonal entries corresponding to Dirichlet boundary DOFs to zero. Otherwise they are set to one.
name
Name of the operator.

class pymor.operators.cg.InterpolationOperator(grid, function)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Vector-like Lagrange interpolation Operator for continuous finite element spaces.

Parameters

grid
The Grid on which to interpolate.
function
The Function to interpolate.

class pymor.operators.cg.L2ProductFunctionalP1(grid, function, boundary_info=None, dirichlet_data=None, neumann_data=None, robin_data=None, order=2, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Linear finite element Functional representing the inner product with an L2-Function.

Boundary treatment can be performed by providing boundary_info and dirichlet_data, in which case the DOFs corresponding to Dirichlet boundaries are set to the values provided by dirichlet_data. Neumann boundaries are handled by providing a neumann_data function, Robin boundaries by providing a robin_data tuple.

The current implementation works in one and two dimensions, but can be trivially extended to arbitrary dimensions.

Parameters

grid
Grid for which to assemble the functional.
function
The Function with which to take the inner product.
boundary_info
BoundaryInfo determining the Dirichlet and Neumann boundaries or None. If None, no boundary treatment is performed.
dirichlet_data
Function providing the Dirichlet boundary values. If None, constant-zero boundary is assumed.
neumann_data
Function providing the Neumann boundary values. If None, constant-zero is assumed.
robin_data
Tuple of two Functions providing the Robin parameter and boundary values, see RobinBoundaryOperator. If None, constant-zero for both functions is assumed.
order
Order of the Gauss quadrature to use for numerical integration.
name
The name of the functional.

class pymor.operators.cg.L2ProductFunctionalQ1(grid, function, boundary_info=None, dirichlet_data=None, neumann_data=None, robin_data=None, order=2, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Bilinear finite element Functional representing the inner product with an L2-Function.

Boundary treatment can be performed by providing boundary_info and dirichlet_data, in which case the DOFs corresponding to Dirichlet boundaries are set to the values provided by dirichlet_data. Neumann boundaries are handled by providing a neumann_data function, Robin boundaries by providing a robin_data tuple.

The current implementation works in two dimensions, but can be trivially extended to arbitrary dimensions.

Parameters

grid
Grid for which to assemble the functional.
function
The Function with which to take the inner product.
boundary_info
BoundaryInfo determining the Dirichlet boundaries or None. If None, no boundary treatment is performed.
dirichlet_data
Function providing the Dirichlet boundary values. If None, constant-zero boundary is assumed.
neumann_data
Function providing the Neumann boundary values. If None, constant-zero is assumed.
robin_data
Tuple of two Functions providing the Robin parameter and boundary values, see RobinBoundaryOperator. If None, constant-zero for both functions is assumed.
order
Order of the Gauss quadrature to use for numerical integration.
name
The name of the functional.

class pymor.operators.cg.L2ProductP1(grid, boundary_info, dirichlet_clear_rows=True, dirichlet_clear_columns=False, dirichlet_clear_diag=False, coefficient_function=None, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Operator representing the L2-product between linear finite element functions.

The current implementation works in one and two dimensions, but can be trivially extended to arbitrary dimensions.

Parameters

grid
The Grid for which to assemble the product.
boundary_info
BoundaryInfo for the treatment of Dirichlet boundary conditions.
dirichlet_clear_rows
If True, set the rows of the system matrix corresponding to Dirichlet boundary DOFs to zero.
dirichlet_clear_columns
If True, set columns of the system matrix corresponding to Dirichlet boundary DOFs to zero.
dirichlet_clear_diag
If True, also set diagonal entries corresponding to Dirichlet boundary DOFs to zero. Otherwise, if either dirichlet_clear_rows or dirichlet_clear_columns is True, the diagonal entries are set to one.
coefficient_function
Coefficient Function for product with shape_range == (). If None, constant one is assumed.
name
The name of the product.

class pymor.operators.cg.L2ProductQ1(grid, boundary_info, dirichlet_clear_rows=True, dirichlet_clear_columns=False, dirichlet_clear_diag=False, coefficient_function=None, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Operator representing the L2-product between bilinear finite element functions.

The current implementation works in two dimensions, but can be trivially extended to arbitrary dimensions.

Parameters

grid
The Grid for which to assemble the product.
boundary_info
BoundaryInfo for the treatment of Dirichlet boundary conditions.
dirichlet_clear_rows
If True, set the rows of the system matrix corresponding to Dirichlet boundary DOFs to zero.
dirichlet_clear_columns
If True, set columns of the system matrix corresponding to Dirichlet boundary DOFs to zero.
dirichlet_clear_diag
If True, also set diagonal entries corresponding to Dirichlet boundary DOFs to zero. Otherwise, if either dirichlet_clear_rows or dirichlet_clear_columns is True, the diagonal entries are set to one.
coefficient_function
Coefficient Function for product with shape_range == (). If None, constant one is assumed.
name
The name of the product.

class pymor.operators.cg.RobinBoundaryOperator(grid, boundary_info, robin_data=None, order=2, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Robin boundary Operator for linear finite elements.

The operator represents the contribution of Robin boundary conditions to the stiffness matrix, where the boundary condition is supposed to be given in the form

-[ d(x) ∇u(x) ] ⋅ n(x) = c(x) (u(x) - g(x))

d and n are the diffusion function (see DiffusionOperatorP1) and the unit outer normal in x, while c is the (scalar) Robin parameter function and g is the (also scalar) Robin boundary value function.

Parameters

grid
The Grid over which to assemble the operator.
boundary_info
BoundaryInfo for the treatment of Dirichlet boundary conditions.
robin_data
Tuple providing two Functions that represent the Robin parameter and boundary value function. If None, the resulting operator is zero.
name
Name of the operator.

constructions module

Module containing some constructions to obtain new operators from old ones.


class pymor.operators.constructions.AdjointOperator(operator, source_product=None, range_product=None, name=None, with_apply_inverse=True, solver_options=None)[source]

Bases: pymor.operators.basic.OperatorBase

Represents the adjoint of a given linear Operator.

For a linear Operator op the adjoint op^* of op is given by:

(op^*(v), u)_s = (v, op(u))_r,

where ( , )_s and ( , )_r denote the inner products on the source and range space of op. If two products are given by P_s and P_r, then:

op^*(v) = P_s^(-1) o op.T o P_r,

Thus, if ( , )_s and ( , )_r are the Euclidean inner products, op^*v is simply given by applycation of the :attr:transpose <pymor.operators.interface.OperatorInterface.T>` Operator.

Parameters

operator
The Operator of which the adjoint is formed.
source_product
If not None, inner product Operator for the source VectorSpaceInterface w.r.t. which to take the adjoint.
range_product
If not None, inner product Operator for the range VectorSpaceInterface w.r.t. which to take the adjoint.
name
If not None, name of the operator.
with_apply_inverse
If True, provide own apply_inverse and apply_inverse_transpose implementations by calling these methods on the given operator. (Is set to False in the default implementation of and apply_inverse_transpose.)
solver_options
When with_apply_inverse is False, the solver_options to use for the apply_inverse default implementation.

class pymor.operators.constructions.AffineOperator(operator, name=None)[source]

Bases: pymor.operators.constructions.ProxyOperator

Decompose an affine Operator into affine_shift and linear_part.


class pymor.operators.constructions.ComponentProjection(components, source, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Operator representing the projection of a VectorArray on some of its components.

Parameters

components
List or 1D NumPy array of the indices of the vector components that ar to be extracted by the operator.
source
Source VectorSpaceInterface of the operator.
name
Name of the operator.

class pymor.operators.constructions.Concatenation(second, first, solver_options=None, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Operator representing the concatenation of two Operators.

Parameters

second
The Operator which is applied as second operator.
first
The Operator which is applied as first operator.
name
Name of the operator.

class pymor.operators.constructions.ConstantOperator(value, source, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

A constant Operator always returning the same vector.

Parameters

value
A VectorArray of length 1 containing the vector which is returned by the operator.
source
Source VectorSpaceInterface of the operator.
name
Name of the operator.

class pymor.operators.constructions.FixedParameterOperator(operator, mu=None, name=None)[source]

Bases: pymor.operators.constructions.ProxyOperator

Makes an Operator Parameter-independent by setting a fixed Parameter.

Parameters

operator
The Operator to wrap.
mu
The fixed Parameter that will be fed to the apply method of operator.

class pymor.operators.constructions.IdentityOperator(space, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

The identity Operator.

In other words:

op.apply(U) == U

Parameters

space
The VectorSpaceInterface the operator acts on.
name
Name of the operator.

class pymor.operators.constructions.InducedNorm(product, raise_negative, tol, name)[source]

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

Instantiated by induced_norm. Do not use directly.


class pymor.operators.constructions.InverseOperator(operator, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Represents the inverse of a given Operator.

Parameters

operator
The Operator of which the inverse is formed.
name
If not None, name of the operator.

class pymor.operators.constructions.InverseTransposeOperator(operator, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Represents the inverse transpose of a given Operator.

Parameters

operator
The Operator of which the inverse transpose is formed.
name
If not None, name of the operator.

class pymor.operators.constructions.LincombOperator(operators, coefficients, solver_options=None, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Linear combination of arbitrary Operators.

This Operator represents a (possibly Parameter dependent) linear combination of a given list of Operators.

Parameters

operators
List of Operators 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 operator.
evaluate_coefficients(mu)[source]

Compute the linear coefficients for a given Parameter.

Parameters

mu
Parameter for which to compute the linear coefficients.

Returns

List of linear coefficients.


class pymor.operators.constructions.LinearOperator(operator, name=None)[source]

Bases: pymor.operators.constructions.ProxyOperator

Mark the wrapped Operator to be linear.


class pymor.operators.constructions.ProxyOperator(operator, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Forwards all interface calls to given Operator.

Mainly useful as base class for other Operator implementations.

Parameters

operator
The Operator to wrap.
name
Name of the wrapping operator.

class pymor.operators.constructions.SelectionOperator(operators, parameter_functional, boundaries, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

An Operator selected from a list of Operators.

operators[i] is used if parameter_functional(mu) is less or equal than boundaries[i] and greater than boundaries[i-1]:

-infty ------- boundaries[i] ---------- boundaries[i+1] ------- infty
                    |                        |
--- operators[i] ---|---- operators[i+1] ----|---- operators[i+2]
                    |                        |

Parameters

operators
List of Operators from which one Operator is selected based on the given Parameter.
parameter_functional
The ParameterFunctional used for the selection of one Operator.
boundaries
The interval boundaries as defined above.
name
Name of the operator.

class pymor.operators.constructions.VectorArrayOperator(array, transposed=False, space_id=None, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Wraps a VectorArray as an Operator.

If transposed is False, the operator maps from NumpyVectorSpace(len(array)) to array.space by forming linear combinations of the vectors in the array with given coefficient arrays.

If transposed == True, the operator maps from array.space to NumpyVectorSpace(len(array)) by forming the inner products of the argument with the vectors in the given array.

Parameters

array
The VectorArray which is to be treated as an operator.
transposed
See description above.
name
The name of the operator.

class pymor.operators.constructions.VectorFunctional(vector, product=None, name=None)[source]

Bases: pymor.operators.constructions.VectorArrayOperator

Wrap a vector as a linear Functional.

Given a vector v of dimension d, this class represents the functional

f: R^d ----> R^1
    u  |---> (u, v)

where ( , ) denotes the inner product given by product.

In particular, if product is None

VectorFunctional(vector).as_source_array() == vector.

If product is not none, we obtain

VectorFunctional(vector).as_source_array() == product.apply(vector).

Parameters

vector
VectorArray of length 1 containing the vector v.
product
Operator representing the scalar product to use.
name
Name of the operator.

class pymor.operators.constructions.VectorOperator(vector, name=None)[source]

Bases: pymor.operators.constructions.VectorArrayOperator

Wrap a vector as a vector-like Operator.

Given a vector v of dimension d, this class represents the operator

op: R^1 ----> R^d
     x  |---> x⋅v

In particular:

VectorOperator(vector).as_range_array() == vector

Parameters

vector
VectorArray of length 1 containing the vector v.
name
Name of the operator.

class pymor.operators.constructions.ZeroOperator(source, range, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

The Operator which maps every vector to zero.

Parameters

source
Source VectorSpaceInterface of the operator.
range
Range VectorSpaceInterface of the operator.
name
Name of the operator.

pymor.operators.constructions.induced_norm(product, raise_negative=True, tol=1e-10, name=None)[source]

Obtain induced norm of an inner product.

The norm of the vectors in a VectorArray U is calculated by calling

product.pairwise_apply2(U, U, mu=mu).

In addition, negative norm squares of absolute value smaller than tol are clipped to 0. If raise_negative is True, a ValueError exception is raised if there are negative norm squares of absolute value larger than tol.

Parameters

product
The inner product Operator for which the norm is to be calculated.
raise_negative
If True, raise an exception if calculated norm is negative.
tol
See above.
name
optional, if None product’s name is used

Returns

norm
A function norm(U, mu=None) taking a VectorArray U as input together with the Parameter mu which is passed to the product.

Defaults

raise_negative, tol (see pymor.core.defaults)

ei module


class pymor.operators.ei.EmpiricalInterpolatedOperator(operator, interpolation_dofs, collateral_basis, triangular, solver_options=None, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Interpolate an Operator using Empirical Operator Interpolation.

Let L be an Operator, 0 <= c_1, ..., c_M < L.range.dim indices of interpolation DOFs and let b_1, ..., b_M in R^(L.range.dim) be collateral basis vectors. If moreover ψ_j(U) denotes the j-th component of U, the empirical interpolation L_EI of L w.r.t. the given data is given by

|                M
|   L_EI(U, μ) = ∑ b_i⋅λ_i     such that
|               i=1
|
|   ψ_(c_i)(L_EI(U, μ)) = ψ_(c_i)(L(U, μ))   for i=0,...,M

Since the original operator only has to be evaluated at the given interpolation DOFs, EmpiricalInterpolatedOperator calls restricted to obtain a restricted version of the operator which is used to quickly obtain the required evaluations. If the restricted method, is not implemented, the full operator will be evaluated (which will lead to the same result, but without any speedup).

The interpolation DOFs and the collateral basis can be generated using the algorithms provided in the pymor.algorithms.ei module.

Parameters

operator
The Operator to interpolate.
interpolation_dofs
List or 1D NumPy array of the interpolation DOFs c_1, ..., c_M.
collateral_basis
VectorArray containing the collateral basis b_1, ..., b_M.
triangular
If True, assume that ψ_(c_i)(b_j) = 0 for i < j, which means that the interpolation matrix is triangular.
name
Name of the operator.

class pymor.operators.ei.ProjectedEmpiciralInterpolatedOperator(restricted_operator, interpolation_matrix, source_basis_dofs, projected_collateral_basis, triangular, source_id, solver_options=None, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

A projected EmpiricalInterpolatedOperator.

fv module

This module provides some operators for finite volume discretizations.


class pymor.operators.fv.DiffusionOperator(grid, boundary_info, diffusion_function=None, diffusion_constant=None, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Finite Volume Diffusion Operator.

The operator is of the form

(Lu)(x) = c ∇ ⋅ [ d(x) ∇ u(x) ]

Parameters

grid
The Grid over which to assemble the operator.
boundary_info
BoundaryInfo for the treatment of Dirichlet boundary conditions.
diffusion_function
The scalar-valued Function d(x). If None, constant one is assumed.
diffusion_constant
The constant c. If None, c is set to one.
name
Name of the operator.

class pymor.operators.fv.EngquistOsherFlux(flux, flux_derivative, gausspoints=5, intervals=1)[source]

Bases: pymor.operators.fv.NumericalConvectiveFluxInterface

Engquist-Osher numerical flux.

If f is the analytical flux, and f' its derivative, the Engquist-Osher flux is given by:

F(U_in, U_out, normal, vol) = vol * [c^+(U_in, normal)  +  c^-(U_out, normal)]

                                   U_in
c^+(U_in, normal)  = f(0)⋅normal +  ∫   max(f'(s)⋅normal, 0) ds
                                   s=0

                                  U_out
c^-(U_out, normal) =                ∫   min(f'(s)⋅normal, 0) ds
                                   s=0

Parameters

flux
Function defining the analytical flux f.
flux_derivative
Function defining the analytical flux derivative f'.
gausspoints
Number of Gauss quadrature points to be used for integration.
intervals
Number of subintervals to be used for integration.

pymor.operators.fv.FVVectorSpace(grid, id_='STATE')[source]

class pymor.operators.fv.L2Product(grid, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Operator representing the L2-product between finite volume functions.

Parameters

grid
The Grid for which to assemble the product.
name
The name of the product.

class pymor.operators.fv.L2ProductFunctional(grid, function=None, boundary_info=None, dirichlet_data=None, diffusion_function=None, diffusion_constant=None, neumann_data=None, order=1, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Finite volume Functional representing the inner product with an L2-Function.

Additionally, boundary conditions can be enforced by providing dirichlet_data and neumann_data functions.

Parameters

grid
Grid for which to assemble the functional.
function
The Function with which to take the inner product or None.
boundary_info
BoundaryInfo determining the Dirichlet and Neumann boundaries or None. If None, no boundary treatment is performed.
dirichlet_data
Function providing the Dirichlet boundary values. If None, constant-zero boundary is assumed.
diffusion_function
See DiffusionOperator. Has to be specified in case dirichlet_data is given.
diffusion_constant
See DiffusionOperator. Has to be specified in case dirichlet_data is given.
neumann_data
Function providing the Neumann boundary values. If None, constant-zero is assumed.
order
Order of the Gauss quadrature to use for numerical integration.
name
The name of the functional.

class pymor.operators.fv.LaxFriedrichsFlux(flux, lxf_lambda=1.0)[source]

Bases: pymor.operators.fv.NumericalConvectiveFluxInterface

Lax-Friedrichs numerical flux.

If f is the analytical flux, the Lax-Friedrichs flux F is given by:

F(U_in, U_out, normal, vol) = vol * [normal⋅(f(U_in) + f(U_out))/2 + (U_in - U_out)/(2*λ)]

Parameters

flux
Function defining the analytical flux f.
lxf_lambda
The stabilization parameter λ.

class pymor.operators.fv.LinearAdvectionLaxFriedrichs(grid, boundary_info, velocity_field, lxf_lambda=1.0, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Linear advection finite Volume Operator using Lax-Friedrichs flux.

The operator is of the form

L(u, mu)(x) = ∇ ⋅ (v(x, mu)⋅u(x))

See LaxFriedrichsFlux for the definition of the Lax-Friedrichs flux.

Parameters

grid
Grid over which to assemble the operator.
boundary_info
BoundaryInfo determining the Dirichlet and Neumann boundaries.
velocity_field
Function defining the velocity field v.
lxf_lambda
The stabilization parameter λ.
name
The name of the operator.

class pymor.operators.fv.NonlinearAdvectionOperator(grid, boundary_info, numerical_flux, dirichlet_data=None, solver_options=None, space_id='STATE', name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Nonlinear finite volume advection Operator.

The operator is of the form

L(u, mu)(x) = ∇ ⋅ f(u(x), mu)

Parameters

grid
Grid for which to evaluate the operator.
boundary_info
BoundaryInfo determining the Dirichlet and Neumann boundaries.
numerical_flux
The NumericalConvectiveFlux to use.
dirichlet_data
Function providing the Dirichlet boundary values. If None, constant-zero boundary is assumed.
name
The name of the operator.

class pymor.operators.fv.NonlinearReactionOperator(grid, reaction_function, reaction_function_derivative=None, space_id='STATE', name=None)[source]

Bases: pymor.operators.basic.OperatorBase


class pymor.operators.fv.NumericalConvectiveFluxInterface[source]

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

Interface for numerical convective fluxes for finite volume schemes.

Numerical fluxes defined by this interfaces are functions of the form F(U_inner, U_outer, unit_outer_normal, edge_volume, mu).

The flux evaluation is vectorized and happens in two stages:
  1. evaluate_stage1 receives a NumPy array U of all values which appear as U_inner or U_outer for all edges the flux shall be evaluated at and returns a tuple of NumPy arrays each of the same length as U.

  2. evaluate_stage2 receives the reordered stage1_data for each edge as well as the unit outer normal and the volume of the edges.

    stage1_data is given as follows: If R_l is l-th entry of the tuple returned by evaluate_stage1, the l-th entry D_l of of the stage1_data tuple has the shape (num_edges, 2) + R_l.shape[1:]. If for edge k the values U_inner and U_outer are the i-th and j-th value in the U array provided to evaluate_stage1, we have

    D_l[k, 0] == R_l[i],    D_l[k, 1] == R_l[j].
    

    evaluate_stage2 returns a NumPy array of the flux evaluations for each edge.


class pymor.operators.fv.ReactionOperator(grid, reaction_coefficient, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Finite Volume reaction Operator.

The operator is of the form

L(u, mu)(x) = c(x, mu)⋅u(x)

Parameters

grid
The Grid for which to assemble the operator.
reaction_coefficient
The function ‘c’
name
The name of the operator.

class pymor.operators.fv.SimplifiedEngquistOsherFlux(flux, flux_derivative)[source]

Bases: pymor.operators.fv.NumericalConvectiveFluxInterface

Engquist-Osher numerical flux. Simplified Implementation for special case.

For the definition of the Engquist-Osher flux see EngquistOsherFlux. This class provides a faster and more accurate implementation for the special case that f(0) == 0 and the derivative of f only changes sign at 0.

Parameters

flux
Function defining the analytical flux f.
flux_derivative
Function defining the analytical flux derivative f'.

pymor.operators.fv.jacobian_options(delta=1e-07)[source]

pymor.operators.fv.nonlinear_advection_engquist_osher_operator(grid, boundary_info, flux, flux_derivative, gausspoints=5, intervals=1, dirichlet_data=None, solver_options=None, name=None)[source]

Instantiate a NonlinearAdvectionOperator using EngquistOsherFlux.


pymor.operators.fv.nonlinear_advection_lax_friedrichs_operator(grid, boundary_info, flux, lxf_lambda=1.0, dirichlet_data=None, solver_options=None, name=None)[source]

Instantiate a NonlinearAdvectionOperator using LaxFriedrichsFlux.


pymor.operators.fv.nonlinear_advection_simplified_engquist_osher_operator(grid, boundary_info, flux, flux_derivative, dirichlet_data=None, solver_options=None, name=None)[source]

Instantiate a NonlinearAdvectionOperator using SimplifiedEngquistOsherFlux.

interfaces module


class pymor.operators.interfaces.OperatorInterface[source]

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

Interface for Parameter dependent discrete operators.

An operator in pyMOR is simply a mapping which for any given Parameter maps vectors from its source VectorSpaceInterface to vectors in its range VectorSpaceInterface.

Note that there is no special distinction between functionals and operators in pyMOR. A functional is simply an operator with NumpyVectorSpace (1) as its range VectorSpaceInterface.

solver_options

If not None, a dict which can contain the following keys:

‘inverse’:solver options used for apply_inverse
‘inverse_transpose’:solver options used for apply_inverse_transpose
‘jacobian’:solver options for the operators returned by jacobian (has no effect for linear operators)

If solver_options is None or a dict entry is missing or None, default options are used. The interpretation of the given solver options is up to the operator at hand. In general, values in solver_options should either be strings (indicating a solver type) or dicts of options, usually with an entry 'type' which specifies the solver type to use and further items which configure this solver.

linear

True if the operator is linear.

source

The source VectorSpaceInterface.

range

The range VectorSpaceInterface.

T

The transpose operator, i.e.

self.T.apply(V, mu) == self.apply_transpose(V, mu)

for all V, mu.

__add__(other)[source]

Sum of two operators.

__mul__(other)[source]

Product of operator by a scalar.

__radd__(other)[source]

Sum of two operators.

apply(U, mu=None)[source]

Apply the operator to a VectorArray.

Parameters

U
VectorArray of vectors to which the operator is applied.
mu
The Parameter for which to evaluate the operator.

Returns

VectorArray of the operator evaluations.

apply2(V, U, mu=None)[source]

Treat the operator as a 2-form by computing V.dot(self.apply(U)).

If the operator is a linear operator given by multiplication with a matrix M, then apply2 is given as:

op.apply2(V, U) = V^T*M*U.

Parameters

V
VectorArray of the left arguments V.
U
VectorArray of the right right arguments U.
mu
The Parameter for which to evaluate the operator.

Returns

A NumPy array with shape (len(V), len(U)) containing the 2-form evaluations.

apply_inverse(V, mu=None, least_squares=False)[source]

Apply the inverse operator.

Parameters

V
VectorArray of vectors to which the inverse operator is applied.
mu
The Parameter for which to evaluate the inverse operator.
least_squares

If True, solve the least squares problem:

u = argmin ||op(u) - v||_2.

Since for an invertible operator the least squares solution agrees with the result of the application of the inverse operator, setting this option should, in general, have no effect on the result for those operators. However, note that when no appropriate solver_options are set for the operator, most implementations will choose a least squares solver by default which may be undesirable.

Returns

VectorArray of the inverse operator evaluations.

Raises

InversionError
The operator could not be inverted.
apply_inverse_transpose(U, mu=None, least_squares=False)[source]

Apply the inverse transpose operator.

Parameters

U
VectorArray of vectors to which the inverse transpose operator is applied.
mu
The Parameter for which to evaluate the inverse transpose operator.
least_squares

If True, solve the least squares problem:

v = argmin ||op*(v) - u||_2.

Since for an invertible operator the least squares solution agrees with the result of the application of the inverse operator, setting this option should, in general, have no effect on the result for those operators. However, note that when no appropriate solver_options are set for the operator, most operator implementations will choose a least squares solver by default which may be undesirable.

Returns

VectorArray of the inverse transpose operator evaluations.

Raises

InversionError
The operator could not be inverted.
apply_transpose(V, mu=None)[source]

Apply the transpose operator.

For any given linear Operator op, Parameter mu and VectorArrays U, V in the source resp. range we have:

op.apply_transpose(V, mu).dot(U) == V.dot(op.apply(U, mu))

Thus, when op is represented by a matrix M, apply_transpose is given by left-multplication of M with V.

Parameters

V
VectorArray of vectors to which the transpose operator is applied.
mu
The Parameter for which to apply the transpose operator.

Returns

VectorArray of the transpose operator evaluations.

as_range_array(mu=None)[source]

Return a VectorArray representation of the operator in its range space.

In the case of a linear operator with NumpyVectorSpace as source, this method returns for every Parameter mu a VectorArray V in the operator’s range, such that

V.lincomb(U.data) == self.apply(U, mu)

for all VectorArrays U.

Parameters

mu
The Parameter for which to return the VectorArray representation.

Returns

V
The VectorArray defined above.
as_source_array(mu=None)[source]

Return a VectorArray representation of the operator in its source space.

In the case of a linear operator with NumpyVectorSpace as range, this method returns for every Parameter mu a VectorArray V in the operator’s source, such that

self.range.make_array(V.dot(U)) == self.apply(U, mu)

for all VectorArrays U.

Parameters

mu
The Parameter for which to return the VectorArray representation.

Returns

V
The VectorArray defined above.
as_vector(mu=None, *, space=None)[source]

Return a vector representation of a linear functional or vector operator.

Depending on the operator’s source and range, this method is equivalent to calling as_range_array or as_source_array respectively. The resulting VectorArray is required to have length 1.

Note that in case both source and range are one-dimensional NumpyVectorSpaces but with different ids, it is impossible to determine which space to choose. In this case, the desired space has to be specified via the space parameter.

Parameters

mu
The Parameter for which to return the vector representation.
space
See above.

Returns

V
VectorArray of length 1 containing the vector representation.
assemble(mu=None)[source]

Assemble the operator for a given parameter.

The result of the method strongly depends on the given operator. For instance, a matrix-based operator will assemble its matrix, a LincombOperator will try to form the linear combination of its operators, whereas an arbitrary operator might simply return a FixedParameterOperator. The only assured property of the assembled operator is that it no longer depends on a Parameter.

Parameters

mu
The Parameter for which to assemble the operator.

Returns

Parameter-independent, assembled Operator.

assemble_lincomb(operators, coefficients, solver_options=None, name=None)[source]

Try to assemble a linear combination of the given operators.

This method is called in the assemble method of LincombOperator on the first of its operator. If an assembly of the given linear combination is possible, e.g. the linear combination of the system matrices of the operators can be formed, then the assembled operator is returned. Otherwise, the method returns None to indicate that assembly is not possible.

Parameters

operators
List of Operators whose linear combination is formed.
coefficients
List of the corresponding linear coefficients.
solver_options
solver_options for the assembled operator.
name
Name of the assembled operator.

Returns

The assembled Operator if assembly is possible, otherwise None.

jacobian(U, mu=None)[source]

Return the operator’s Jacobian as a new Operator.

Parameters

U
Length 1 VectorArray containing the vector for which to compute the Jacobian.
mu
The Parameter for which to compute the Jacobian.

Returns

Linear Operator representing the Jacobian.

pairwise_apply2(V, U, mu=None)[source]

Treat the operator as a 2-form by computing V.dot(self.apply(U)).

Same as OperatorInterface.apply2, except that vectors from V and U are applied in pairs.

Parameters

V
VectorArray of the left arguments V.
U
VectorArray of the right right arguments U.
mu
The Parameter for which to evaluate the operator.

Returns

A NumPy array with shape (len(V),) == (len(U),) containing the 2-form evaluations.

restricted(dofs)[source]

Restrict the operator range to a given set of degrees of freedom.

This method returns a restricted version restricted_op of the operator along with an array source_dofs such that for any VectorArray U in self.source the following is true:

self.apply(U, mu).components(dofs)
    == restricted_op.apply(NumpyVectorArray(U.components(source_dofs)), mu))

Such an operator is mainly useful for empirical interpolation where the evaluation of the original operator only needs to be known for few selected degrees of freedom. If the operator has a small stencil, only few source_dofs will be needed to evaluate the restricted operator which can make its evaluation very fast compared to evaluating the original operator.

Parameters

dofs
One-dimensional NumPy array of degrees of freedom in the operator range to which to restrict.

Returns

restricted_op
The restricted operator as defined above. The operator will have NumpyVectorSpace (len(source_dofs)) as source and NumpyVectorSpace (len(dofs)) as range.
source_dofs
One-dimensional NumPy array of source degrees of freedom as defined above.

mpi module


class pymor.operators.mpi.MPIOperator(obj_id, with_apply2=False, pickle_local_spaces=True, space_type=<class 'pymor.vectorarrays.mpi.MPIVectorSpace'>)[source]

Bases: pymor.operators.basic.OperatorBase

MPI distributed Operator.

Given a single-rank implementation of an Operator, this wrapper class uses the event loop from pymor.tools.mpi to allow an MPI distributed usage of the Operator.

Instances of MPIOperator can be used on rank 0 like any other (non-distributed) Operator.

Note, however, that the underlying Operator implementation needs to be MPI aware. For instance, the operator’s apply method has to perform the necessary MPI communication to obtain all DOFs hosted on other MPI ranks which are required for the local operator evaluation.

Instead of instantiating MPIOperator directly, it is usually preferable to use mpi_wrap_operator instead.

Parameters

obj_id
ObjectId of the local Operators on each rank.
with_apply2
Set to True if the operator implementation has its own MPI aware implementation of apply2 and pairwise_apply2. Otherwise, the default implementations using apply and dot will be used.
pickle_local_spaces
If pickle_local_spaces is False, a unique identifier is computed for each local source/range VectorSpaceInterface, which is then transferred to rank 0 instead of the true VectorSpaceInterface. This allows the useage of MPIVectorArray even when the local VectorSpaces are not picklable.
space_type
This class will be used to wrap the local VectorArrays returned by the local operators into an MPI distributed VectorArray managed from rank 0. By default, MPIVectorSpace will be used, other options are MPIVectorSpaceAutoComm and MPIVectorSpaceNoComm.

pymor.operators.mpi.mpi_wrap_operator(obj_id, with_apply2=False, pickle_local_spaces=True, space_type=<class 'pymor.vectorarrays.mpi.MPIVectorSpace'>)[source]

Wrap MPI distributed local Operators to a global Operator on rank 0.

Given MPI distributed local Operators referred to by the ObjectId obj_id, return a new Operator which manages these distributed operators from rank 0. This is done by instantiating MPIOperator. Additionally, the structure of the wrapped operators is preserved. E.g. LincombOperators will be wrapped as a LincombOperator of MPIOperators.

Parameters

See : class:MPIOperator.

Returns

The wrapped Operator.

numpy module

This module provides the following NumPy based Operators:


class pymor.operators.numpy.NumpyGenericOperator(mapping, transpose_mapping=None, dim_source=1, dim_range=1, linear=False, parameter_type=None, source_id=None, range_id=None, solver_options=None, name=None)[source]

Bases: pymor.operators.basic.OperatorBase

Wraps an arbitrary Python function between NumPy arrays as a an Operator.

Parameters

mapping

The function to wrap. If parameter_type is None, the function is of the form mapping(U) and is expected to be vectorized. In particular:

mapping(U).shape == U.shape[:-1] + (dim_range,).

If parameter_type is not None, the function has to have the signature mapping(U, mu).

transpose_mapping

The transpsoe function to wrap. If parameter_type is None, the function is of the form transpose_mapping(U) and is expected to be vectorized. In particular:

transpose_mapping(U).shape == U.shape[:-1] + (dim_source,).

If parameter_type is not None, the function has to have the signature transpose_mapping(U, mu).

dim_source
Dimension of the operator’s source.
dim_range
Dimension of the operator’s range.
linear
Set to True if the provided mapping and transpose_mapping are linear.
parameter_type
The ParameterType of the Parameters the mapping accepts.
name
Name of the operator.

class pymor.operators.numpy.NumpyMatrixBasedOperator[source]

Bases: pymor.operators.basic.OperatorBase

Base class for operators which assemble into a NumpyMatrixOperator.

sparse

True if the operator assembles into a sparse matrix, False if the operator assembles into a dense matrix, None if unknown.

assemble(mu=None)[source]

Assembles the operator for a given Parameter.

Parameters

mu
The Parameter for which to assemble the operator.

Returns

The assembled parameter independent Operator.

export_matrix(filename, matrix_name=None, output_format='matlab', mu=None)[source]

Save the matrix of the operator to a file.

Parameters

filename
Name of output file.
matrix_name
The name, the output matrix is given. (Comment field is used in case of Matrix Market output_format.) If None, the Operator‘s name is used.
output_format
Output file format. Either matlab or matrixmarket.
mu
The Parameter to assemble the to be exported matrix for.

class pymor.operators.numpy.NumpyMatrixOperator(matrix, source_id=None, range_id=None, solver_options=None, name=None)[source]

Bases: pymor.operators.numpy.NumpyMatrixBasedOperator

Wraps a 2D NumPy array as an Operator.

Parameters

matrix
The NumPy array which is to be wrapped.
name
Name of the operator.
apply_inverse(V, mu=None, least_squares=False, check_finite=True, default_sparse_solver_backend='scipy')[source]

Apply the inverse operator.

Parameters

V
VectorArray of vectors to which the inverse operator is applied.
mu
The Parameter for which to evaluate the inverse operator.
least_squares

If True, solve the least squares problem:

u = argmin ||op(u) - v||_2.

Since for an invertible operator the least squares solution agrees with the result of the application of the inverse operator, setting this option should, in general, have no effect on the result for those operators. However, note that when no appropriate solver_options are set for the operator, most implementations will choose a least squares solver by default which may be undesirable.

check_finite
Test if solution only containes finite values.
default_solver
Default sparse solver backend to use (scipy, pyamg, generic).

Returns

VectorArray of the inverse operator evaluations.

Raises

InversionError
The operator could not be inverted.

Defaults

check_finite, default_sparse_solver_backend (see pymor.core.defaults)