pymor.discretizations package¶
Submodules¶
basic module¶

class
pymor.discretizations.basic.
DiscretizationBase
(operators, functionals, vector_operators, products=None, estimator=None, visualizer=None, cache_region=None, name=None)[source]¶ Bases:
pymor.discretizations.interfaces.DiscretizationInterface
Base class for
Discretizations
providing some common functionality.Methods
Attributes

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 highdimensional
Discretization
.Parameters
 U
 The solution obtained by
solve
.  mu
Parameter
for whichU
has been obtained.
Returns
The estimated error.

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=None, operator=None, rhs=None, mass=None, time_stepper=None, num_values=None, products=None, operators=None, functionals=None, vector_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 nonlinear) timedependent
Operator
, F is a timedependent linearFunctional
, and u_0 the initial data. The massOperator
M is assumed to be linear, timeindependent 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 vectorlikeOperator
(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
timestepper
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
Operators
associated with the discretization.  functionals
 A dict of (output)
Functionals
associated with the discretization.  vector_operators
 A dict of vectorlike
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 vectorlike
Operator
. The same asvector_operators['initial_data']
.

rhs
¶ The
Functional
F. The same asfunctionals['rhs']
.

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

time_stepper
¶ The provided
timestepper
.

with_
(**kwargs)[source]¶ Returns a copy with changed attributes.
The default implementation is to create a new class instance with the given keyword arguments as arguments for
__init__
. Missing arguments are obtained form instance attributes with the same name.Parameters
**kwargs
 Names of attributes to change with their new values. Each attribute name
has to be contained in
with_arguments
.
Returns
Copy of
self
with changed attributes.

class
pymor.discretizations.basic.
StationaryDiscretization
(operator=None, rhs=None, products=None, operators=None, functionals=None, vector_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 nonlinear) 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
Operators
associated with the discretization.  functionals
 A dict of (output)
Functionals
associated with the discretization.  vector_operators
 A dict of vectorlike
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 asfunctionals['rhs']
.

with_
(**kwargs)[source]¶ Returns a copy with changed attributes.
The default implementation is to create a new class instance with the given keyword arguments as arguments for
__init__
. Missing arguments are obtained form instance attributes with the same name.Parameters
**kwargs
 Names of attributes to change with their new values. Each attribute name
has to be contained in
with_arguments
.
Returns
Copy of
self
with changed attributes.
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
¶ VectorSpace
of theVectorArrays
returned bysolve
.

linear
¶ True
if the discretization describes a linear problem.

operators
¶ Dictionary of all
Operators
contained in the discretization (seepymor.reductors.basic.reduce_generic_rb
for a usage example).

functionals
¶ Same as
operators
but forFunctionals
.

vector_operators
¶ Same as operators but for
Operators
representing vectors, i.e. linearOperators
withsource.dim == 1
.

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 highdimensional
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, functionals, vector_operators, products=None, pickle_subtypes=True, array_type=<class 'pymor.vectorarrays.mpi.MPIVectorArray'>)[source]¶ Bases:
pymor.discretizations.basic.DiscretizationBase
Wrapper class for MPI distributed
Discretizations
.Given a singlerank 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 MPIawareDiscretization
.  functionals
 See
operators
.  vector_operators
 See
operators
.  products
 See
operators
.  pickle_subtypes
 If
pickle_subtypes
isFalse
, a unique identifier is computed for each localsolution_space
subtype, which is then transferred to rank 0 instead of the true subtype. This allows to useMPIVectorArray
,MPIOperator
,MPIDiscretization
even when the local subtypes are not picklable.  array_type
 This class will be used to wrap the local
VectorArrays
returned bysolve
on each rank into an MPI distributedVectorArray
managed from rank 0. By default,MPIVectorArray
will be used, other options areMPIVectorArrayAutoComm
andMPIVectorArrayNoComm
.
Methods
Attributes

class
pymor.discretizations.mpi.
MPIVisualizer
(d_obj_id)[source]¶ Bases:
pymor.core.interfaces.ImmutableInterface
Methods
MPIVisualizer
visualize
ImmutableInterface
generate_sid
,unlock
,with_
BasicInterface
disable_logging
,enable_logging
,has_interface_name
,implementor_names
,implementors
,lock
,__setattr__
Attributes
ImmutableInterface
add_with_arguments
,sid
,sid_ignore
,with_arguments
BasicInterface
locked
,logger
,logging_disabled
,name
,uid

pymor.discretizations.mpi.
mpi_wrap_discretization
(local_discretizations, use_with=False, with_apply2=False, pickle_subtypes=True, array_type=<class 'pymor.vectorarrays.mpi.MPIVectorArray'>)[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_subtypes
 See
MPIOperator
.  array_type
 See
MPIOperator
.