pymor.discretizations package

Submodules

basic module


class pymor.discretizations.basic.DiscretizationBase(operators=None, products=None, estimator=None, visualizer=None, cache_region=None, name=None, **kwargs)[source]

Bases: pymor.discretizations.interfaces.DiscretizationInterface

Base class for Discretizations providing some common functionality.

visualize(U, **kwargs)[source]

Visualize a solution VectorArray U.

Parameters

U
The VectorArray from solution_space that shall be visualized.
kwargs
See docstring of self.visualizer.visualize.

class pymor.discretizations.basic.InstationaryDiscretization(T, initial_data, operator, rhs, mass=None, time_stepper=None, num_values=None, products=None, operators=None, parameter_space=None, estimator=None, visualizer=None, cache_region=None, name=None)[source]

Bases: pymor.discretizations.basic.DiscretizationBase

Generic class for discretizations of instationary problems.

This class describes instationary problems given by the equations:

M * ∂_t u(t, μ) + L(u(μ), t, μ) = F(t, μ)
                        u(0, μ) = u_0(μ)

for t in [0,T], where L is a (possibly non-linear) time-dependent Operator, F is a time-dependent linear Functional, and u_0 the initial data. The mass Operator M is assumed to be linear, time-independent and Parameter-independent.

Parameters

T
The final time T.
initial_data
The initial data u_0. Either a VectorArray of length 1 or (for the Parameter-dependent case) a vector-like Operator (i.e. a linear Operator with source.dim == 1) which applied to NumpyVectorArray(np.array([1])) will yield the initial data for a given Parameter.
operator
The Operator L.
rhs
The Functional F.
mass
The mass Operator M. If None, the identity is assumed.
time_stepper
The time-stepper to be used by solve.
num_values
The number of returned vectors of the solution trajectory. If None, each intermediate vector that is calculated is returned.
products
A dict of product Operators defined on the discrete space the problem is posed on. For each product a corresponding norm is added as a method of the discretization.
operators
A dict of additional Operators associated with the discretization.
parameter_space
The ParameterSpace for which the discrete problem is posed.
estimator
An error estimator for the problem. This can be any object with an estimate(U, mu, discretization) method. If estimator is not None, an estimate(U, mu) method is added to the discretization which will call estimator.estimate(U, mu, self).
visualizer
A visualizer for the problem. This can be any object with a visualize(U, discretization, ...) method. If visualizer is not None, a visualize(U, *args, **kwargs) method is added to the discretization which forwards its arguments to the visualizer’s visualize method.
cache_region
None or name of the CacheRegion to use.
name
Name of the discretization.
T

The final time T.

initial_data

The intial data u_0 given by a vector-like Operator. The same as operators['initial_data'].

operator

The Operator L. The same as operators['operator'].

rhs

The Functional F. The same as operators['rhs'].

mass

The mass operator M. The same as operators['mass'].

time_stepper

The provided time-stepper.

operators

Dict of all Operators appearing in the discretization.


class pymor.discretizations.basic.StationaryDiscretization(operator, rhs, products=None, operators=None, parameter_space=None, estimator=None, visualizer=None, cache_region=None, name=None)[source]

Bases: pymor.discretizations.basic.DiscretizationBase

Generic class for discretizations of stationary problems.

This class describes discrete problems given by the equation:

L(u(μ), μ) = F(μ)

with a linear functional F and a (possibly non-linear) operator L.

Parameters

operator
The Operator L.
rhs
The Functional F.
products
A dict of inner product Operators defined on the discrete space the problem is posed on. For each product a corresponding norm is added as a method of the discretization.
operators
A dict of additional Operators associated with the discretization.
parameter_space
The ParameterSpace for which the discrete problem is posed.
estimator
An error estimator for the problem. This can be any object with an estimate(U, mu, discretization) method. If estimator is not None, an estimate(U, mu) method is added to the discretization which will call estimator.estimate(U, mu, self).
visualizer
A visualizer for the problem. This can be any object with a visualize(U, discretization, ...) method. If visualizer is not None, a visualize(U, *args, **kwargs) method is added to the discretization which forwards its arguments to the visualizer’s visualize method.
cache_region
None or name of the CacheRegion to use.
name
Name of the discretization.
operator

The Operator L. The same as operators['operator'].

rhs

The Functional F. The same as operators['rhs'].

operators

Dict of all Operators appearing in the discretization.

interfaces module


class pymor.discretizations.interfaces.DiscretizationInterface[source]

Bases: pymor.core.cache.CacheableInterface, pymor.parameters.base.Parametric

Interface for discretization objects.

A discretization object defines a discrete problem via its class and the Operators it contains. Furthermore, discretizatoins can be solved for a given Parameter resulting in a solution VectorArray.

solution_space

VectorSpaceInterface of the VectorArrays returned by solve.

linear

True if the discretization describes a linear problem.

operators

Dictionary of all Operators contained in the discretization (see GenericRBReductor for a usage example).

products

Same as Operators but for inner product operators associated with the discretization.

estimate(U, mu=None)[source]

Estimate the discretization error for a given solution.

The discretization error could be the error w.r.t. the analytical solution of the given problem or the model reduction error w.r.t. a corresponding high-dimensional Discretization.

Parameters

U
The solution obtained by solve.
mu
Parameter for which U has been obtained.

Returns

The estimated error.

solve(mu=None, **kwargs)[source]

Solve the discrete problem for the Parameter mu.

The result will be cached in case caching has been activated for the given discretization.

Parameters

mu
Parameter for which to solve.

Returns

The solution given as a VectorArray.

visualize(U, **kwargs)[source]

Visualize a solution VectorArray U.

Parameters

U
The VectorArray from solution_space that shall be visualized.

mpi module


class pymor.discretizations.mpi.MPIDiscretization(obj_id, operators, products=None, pickle_local_spaces=True, space_type=<class 'pymor.vectorarrays.mpi.MPIVectorSpace'>)[source]

Bases: pymor.discretizations.basic.DiscretizationBase

Wrapper class for MPI distributed Discretizations.

Given a single-rank implementation of a Discretization, this wrapper class uses the event loop from pymor.tools.mpi to allow an MPI distributed usage of the Discretization. The underlying implementation needs to be MPI aware. In particular, the discretization’s solve method has to perform an MPI parallel solve of the discretization.

Note that this class is not intended to be instantiated directly. Instead, you should use mpi_wrap_discretization.

Parameters

obj_id
ObjectId of the local Discretization on each rank.
operators
Dictionary of all Operators contained in the discretization, wrapped for use on rank 0. Use mpi_wrap_discretization to automatically wrap all operators of a given MPI-aware Discretization.
products
See operators.
pickle_local_spaces
See MPIOperator.
space_type
See MPIOperator.

class pymor.discretizations.mpi.MPIVisualizer(d_obj_id)[source]

Bases: pymor.core.interfaces.ImmutableInterface


pymor.discretizations.mpi.mpi_wrap_discretization(local_discretizations, use_with=False, with_apply2=False, pickle_local_spaces=True, space_type=<class 'pymor.vectorarrays.mpi.MPIVectorSpace'>)[source]

Wrap MPI distributed local Discretizations to a global Discretization on rank 0.

Given MPI distributed local Discretizations referred to by the ObjectId local_discretizations, return a new Discretization which manages these distributed discretizations from rank 0. This is done by first wrapping all Operators of the Discretization using mpi_wrap_operator.

Alternatively, local_discretizations can be a callable (with no arguments) which is then called on each rank to instantiate the local Discretizations.

When use_with is False, an MPIDiscretization is instantiated with the wrapped operators. A call to solve will then use an MPI parallel call to the solve methods of the wrapped local Discretizations to obtain the solution. This is usually what you want when the actual solve is performed by an implementation in the external solver.

When use_with is True, with_ is called on the local Discretization on rank 0, to obtain a new Discretization with the wrapped MPI Operators. This is mainly useful when the local discretizations are generic Discretizations as in pymor.discretizations.basic and solve is implemented directly in pyMOR via operations on the contained Operators.

Parameters

local_discretizations
ObjectId of the local Discretizations on each rank or a callable generating the Discretizations.
use_with
See above.
with_apply2
See MPIOperator.
pickle_local_spaces
See MPIOperator.
space_type
See MPIOperator.