pymor.models.basic
¶
Module Contents¶
Classes¶
Generic class for models of stationary problems. 

Generic class for models of instationary problems. 
 class pymor.models.basic.StationaryModel(operator, rhs, output_functional=None, products=None, error_estimator=None, visualizer=None, name=None)[source]¶
Bases:
pymor.models.interface.Model
Generic class for models of stationary problems.
This class describes discrete problems given by the equation:
L(u(μ), μ) = F(μ)
with a vectorlike righthand side F and a (possibly nonlinear) operator L.
Note that even when solving a variational formulation where F is a functional and not a vector, F has to be specified as a vectorlike
Operator
(mapping scalars to vectors). This ensures that in the complex case both L and F are antilinear in the test variable.Parameters
 operator
The
Operator
L. rhs
The vector F. Either a
VectorArray
of length 1 or a vectorlikeOperator
. output_functional
Operator
mapping a given solution to the model output. In many applications, this will be aFunctional
, i.e. anOperator
mapping to scalars. This is not required, however. products
A dict of inner product
Operators
defined on the discrete space the problem is posed on. For each product with key'x'
a corresponding attributex_product
, as well as a norm methodx_norm
is added to the model. error_estimator
An error estimator for the problem. This can be any object with an
estimate_error(U, mu, m)
method. Iferror_estimator
is notNone
, anestimate_error(U, mu)
method is added to the model which will callerror_estimator.estimate_error(U, mu, self)
. visualizer
A visualizer for the problem. This can be any object with a
visualize(U, m, ...)
method. Ifvisualizer
is notNone
, avisualize(U, *args, **kwargs)
method is added to the model which forwards its arguments to the visualizer’svisualize
method. name
Name of the model.
 _compute_solution(self, mu=None, **kwargs)[source]¶
Compute the model’s solution for
parameter values
mu
.This method is called by the default implementation of
compute
inpymor.models.interface.Model
.Parameters
 mu
Parameter values
for which to compute the solution. kwargs
Additional keyword arguments to customize how the solution is computed or to select additional data to be returned.
Returns
VectorArray
with the computed solution or a dict which at least must contain the key'solution'
.
 _compute_solution_d_mu_single_direction(self, parameter, index, solution, mu)[source]¶
Compute the partial derivative of the solution w.r.t. a parameter index
Parameters
 parameter
parameter for which to compute the sensitivity
 index
parameter index for which to compute the sensitivity
 solution
Internal model state for the given
Parameter value
. mu
Parameter value
for which to solve
Returns
The sensitivity of the solution as a
VectorArray
.
 _compute_output_d_mu(self, solution, mu, return_array=False, use_adjoint=None)[source]¶
Compute the gradient of the output functional w.r.t. the parameters.
Parameters
 solution
Internal model state for the given
Parameter value
 mu
Parameter value
for which to compute the gradient return_array
if
True
, return the output gradient as aNumPy array
. Otherwise, return a dict of gradients for eachParameter
. use_adjoint
if
None
use standard approach, ifTrue
, use the adjoint solution for a more efficient way of computing the gradient. See Section 1.6.2 in [HPUU08] for more details. So far, the adjoint approach is only valid for linear models.
Returns
The gradient as a
NumPy array
or a dict ofNumPy arrays
.
 deaffinize(self, arg)[source]¶
Build
Model
with linear solution space.For many
Models
the solution manifold is contained in an affine subspace of thesolution_space
, e.g. the affine space of functions with certain fixed boundary values. Most MOR techniques, however, construct linear approximation spaces, which are not fully contained in this affine subspace, even if these spaces are created using snapshot vectors from the subspace. Depending on the FOM, neglecting the affine structure of the solution space may lead to bad approximations or even an illposed ROM. A standard approach to circumvent this issue is to replace the FOM with an equivalentModel
with linear solution space. This method can be used to obtain such aModel
.Given a vector
u_0
from the affine solution space, the returnedStationaryModel
is equivalent to solving:L(u(μ) + u_0, μ) = F(μ)
When
operator
is linear, the affine shift is moved to the righthand side to obtain:L(u(μ), μ) = F(μ)  L(u_0, μ)
Solutions of the original
Model
can be obtained by addingu_0
to the solutions of the deaffinizedModel
.The
output_functional
is adapted accordingly to yield the same output for givenparameter values
.Parameters
 arg
Either a
VectorArray
of length 1 containing the vectoru_0
. Alternatively,parameter values
can be provided, for which the model issolved
to obtainu_0
.
Returns
The deaffinized
Model
.
 class pymor.models.basic.InstationaryModel(T, initial_data, operator, rhs, mass=None, time_stepper=None, num_values=None, output_functional=None, products=None, error_estimator=None, visualizer=None, name=None)[source]¶
Bases:
pymor.models.interface.Model
Generic class for models 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 vectorlikeOperator
, and u_0 the initial data. The massOperator
M is assumed to be linear.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 givenparameter values
. operator
The
Operator
L. rhs
The righthand side 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. output_functional
Operator
mapping a given solution to the model output. In many applications, this will be aFunctional
, i.e. anOperator
mapping to scalars. This is not required, however. products
A dict of product
Operators
defined on the discrete space the problem is posed on. For each product with key'x'
a corresponding attributex_product
, as well as a norm methodx_norm
is added to the model. error_estimator
An error estimator for the problem. This can be any object with an
estimate_error(U, mu, m)
method. Iferror_estimator
is notNone
, anestimate_error(U, mu)
method is added to the model which will callerror_estimator.estimate_error(U, mu, self)
. visualizer
A visualizer for the problem. This can be any object with a
visualize(U, m, ...)
method. Ifvisualizer
is notNone
, avisualize(U, *args, **kwargs)
method is added to the model which forwards its arguments to the visualizer’svisualize
method. name
Name of the model.
 _compute_solution(self, mu=None, **kwargs)[source]¶
Compute the model’s solution for
parameter values
mu
.This method is called by the default implementation of
compute
inpymor.models.interface.Model
.Parameters
 mu
Parameter values
for which to compute the solution. kwargs
Additional keyword arguments to customize how the solution is computed or to select additional data to be returned.
Returns
VectorArray
with the computed solution or a dict which at least must contain the key'solution'
.