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.Methods
Attributes
-
visualize
(U, **kwargs)[source]¶ Visualize a solution
VectorArray
U.Parameters
- U
- The
VectorArray
fromsolution_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 linearFunctional
, and u_0 the initial data. The massOperator
M is assumed to be linear, time-independent andParameter
-independent.Parameters
- T
- The final time T.
- initial_data
- The initial data
u_0
. Either aVectorArray
of length 1 or (for theParameter
-dependent case) a vector-likeOperator
(i.e. a linearOperator
withsource.dim == 1
) which applied toNumpyVectorArray(np.array([1]))
will yield the initial data for a givenParameter
. - operator
- The
Operator
L. - rhs
- The
Functional
F. - mass
- The mass
Operator
M
. IfNone
, the identity is assumed. - time_stepper
- The
time-stepper
to be used bysolve
. - 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. Ifestimator
is notNone
, anestimate(U, mu)
method is added to the discretization which will callestimator.estimate(U, mu, self)
. - visualizer
- A visualizer for the problem. This can be any object with
a
visualize(U, discretization, ...)
method. Ifvisualizer
is notNone
, avisualize(U, *args, **kwargs)
method is added to the discretization which forwards its arguments to the visualizer’svisualize
method. - cache_region
None
or name of theCacheRegion
to use.- name
- Name of the discretization.
Methods
Attributes
-
T
¶ The final time T.
-
initial_data
¶ The intial data u_0 given by a vector-like
Operator
. The same asoperators['initial_data']
.
-
rhs
¶ The
Functional
F. The same asoperators['rhs']
.
-
mass
¶ The mass operator M. The same as
operators['mass']
.
-
time_stepper
¶ The provided
time-stepper
.
-
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. Ifestimator
is notNone
, anestimate(U, mu)
method is added to the discretization which will callestimator.estimate(U, mu, self)
. - visualizer
- A visualizer for the problem. This can be any object with
a
visualize(U, discretization, ...)
method. Ifvisualizer
is notNone
, avisualize(U, *args, **kwargs)
method is added to the discretization which forwards its arguments to the visualizer’svisualize
method. - cache_region
None
or name of theCacheRegion
to use.- name
- Name of the discretization.
Methods
Attributes
-
rhs
¶ The
Functional
F. The same asoperators['rhs']
.
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 theOperators
it contains. Furthermore, discretizatoins can besolved
for a givenParameter
resulting in a solutionVectorArray
.Methods
Attributes
-
solution_space
¶ VectorSpaceInterface
of theVectorArrays
returned bysolve
.
-
linear
¶ True
if the discretization describes a linear problem.
-
operators
¶ Dictionary of all
Operators
contained in the discretization (seeGenericRBReductor
for a usage example).
-
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
.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
fromsolution_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 frompymor.tools.mpi
to allow an MPI distributed usage of theDiscretization
. The underlying implementation needs to be MPI aware. In particular, the discretization’ssolve
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 localDiscretization
on each rank.- operators
- Dictionary of all
Operators
contained in the discretization, wrapped for use on rank 0. Usempi_wrap_discretization
to automatically wrap all operators of a given MPI-awareDiscretization
. - products
- See
operators
. - pickle_local_spaces
- See
MPIOperator
. - space_type
- See
MPIOperator
.
Methods
Attributes
-
class
pymor.discretizations.mpi.
MPIVisualizer
(d_obj_id)[source]¶
-
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 globalDiscretization
on rank 0.Given MPI distributed local
Discretizations
referred to by theObjectId
local_discretizations
, return a newDiscretization
which manages these distributed discretizations from rank 0. This is done by first wrapping allOperators
of theDiscretization
usingmpi_wrap_operator
.Alternatively,
local_discretizations
can be a callable (with no arguments) which is then called on each rank to instantiate the localDiscretizations
.When
use_with
isFalse
, anMPIDiscretization
is instantiated with the wrapped operators. A call tosolve
will then use an MPI parallel call to thesolve
methods of the wrapped localDiscretizations
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
isTrue
,with_
is called on the localDiscretization
on rank 0, to obtain a newDiscretization
with the wrapped MPIOperators
. This is mainly useful when the local discretizations are genericDiscretizations
as inpymor.discretizations.basic
andsolve
is implemented directly in pyMOR via operations on the containedOperators
.Parameters
- local_discretizations
ObjectId
of the localDiscretizations
on each rank or a callable generating theDiscretizations
.- use_with
- See above.
- with_apply2
- See
MPIOperator
. - pickle_local_spaces
- See
MPIOperator
. - space_type
- See
MPIOperator
.