pymor.models.interface
¶
Module Contents¶
Classes¶
Interface for model objects. |
- class pymor.models.interface.Model(products=None, error_estimator=None, visualizer=None, name=None)[source]¶
Bases:
pymor.core.cache.CacheableObject
,pymor.parameters.base.ParametricObject
Interface for model objects.
A model object defines a discrete problem via its
class
and theOperators
it contains. Furthermore, models can besolved
for givenparameter values
resulting in a solutionVectorArray
.- solution_space[source]¶
VectorSpace
of the solutionVectorArrays
returned bysolve
.
- _compute(self, solution=False, output=False, solution_d_mu=False, output_d_mu=False, solution_error_estimate=False, output_error_estimate=False, output_d_mu_return_array=False, mu=None, **kwargs)[source]¶
- abstract _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_output(self, solution, mu=None, **kwargs)[source]¶
Compute the model’s output for
parameter values
mu
.This method is called by the default implementation of
compute
inpymor.models.interface.Model
. The assumption is made that the output is a derived quantity from the model’s internal state as returned my_compute_solution
. When this is not the case, the computation of the output should be implemented in_compute
.Note
The default implementation applies the
Operator
given by theoutput_functional
attribute to the givensolution
VectorArray
.Parameters
- solution
Internal model state for the given
parameter values
.- mu
Parameter values
for which to compute the output.- kwargs
Additional keyword arguments to customize how the output is computed or to select additional data to be returned.
Returns
NumPy array
with the computed output or a dict which at least must contain the key'output'
.
- abstract _compute_solution_d_mu_single_direction(self, parameter, index, solution, mu=None, **kwargs)[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_solution_d_mu(self, solution, mu=None, **kwargs)[source]¶
Compute all partial derivative of the solution w.r.t. a parameter index
Parameters
- solution
Internal model state for the given
Parameter value
.- mu
Parameter value
for which to solve
Returns
A dict of all partial sensitivities of the solution.
- _compute_output_d_mu(self, solution, mu=None, return_array=False, **kwargs)[source]¶
Compute the gradient w.r.t. the parameter of the output functional
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
.
Returns
The gradient as a
NumPy array
or a dict ofNumPy arrays
.
- _compute_solution_error_estimate(self, solution, mu=None, **kwargs)[source]¶
Compute an error estimate for the computed internal state.
This method is called by the default implementation of
compute
inpymor.models.interface.Model
. The assumption is made that the error estimate is a derived quantity from the model’s internal state as returned my_compute_solution
. When this is not the case, the computation of the error estimate should be implemented in_compute
.Note
The default implementation calls the
estimate_error
method of the object given by theerror_estimator
attribute, passingsolution
,mu
,self
and**kwargs
.Parameters
- solution
Internal model state for the given
parameter values
.- mu
Parameter values
for which to compute the error estimate.- kwargs
Additional keyword arguments to customize how the error estimate is computed or to select additional data to be returned.
Returns
The computed error estimate or a dict which at least must contain the key
'solution_error_estimate'
.
- _compute_output_error_estimate(self, solution, mu=None, **kwargs)[source]¶
Compute an error estimate for the computed model output.
This method is called by the default implementation of
compute
inpymor.models.interface.Model
. The assumption is made that the error estimate is a derived quantity from the model’s internal state as returned my_compute_solution
. When this is not the case, the computation of the error estimate should be implemented in_compute
.Note
The default implementation calls the
estimate_output_error
method of the object given by theerror_estimator
attribute, passingsolution
,mu
,self
and**kwargs
.Parameters
- solution
Internal model state for the given
parameter values
.- mu
Parameter values
for which to compute the error estimate.- kwargs
Additional keyword arguments to customize how the error estimate is computed or to select additional data to be returned.
Returns
The computed error estimate or a dict which at least must contain the key
'solution_error_estimate'
.
- compute(self, solution=False, output=False, solution_d_mu=False, output_d_mu=False, solution_error_estimate=False, output_error_estimate=False, output_d_mu_return_array=False, *, mu=None, **kwargs)[source]¶
Compute the solution of the model and associated quantities.
This methods computes the output of the model it’s internal state and various associated quantities for given
parameter values
mu
.Note
The default implementation defers the actual computations to the methods
_compute_solution
,_compute_output
,_compute_solution_error_estimate
and_compute_output_error_estimate
. The call to_compute_solution
iscached
. In addition,Model
implementors may implement_compute
to simultaneously compute multiple values in an optimized way. The corresponding_compute_XXX
methods will not be called for values already returned by_compute
.Parameters
- solution
If
True
, return the model’s internal state.- output
If
True
, return the model output.- solution_d_mu
If not
False
, eitherTrue
to return the derivative of the model’s internal state w.r.t. all parameter components or a tuple(parameter, index)
to return the derivative of a single parameter component.- output_d_mu
If
True
, return the gradient of the model output w.r.t. theParameter
.- solution_error_estimate
If
True
, return an error estimate for the computed internal state.- output_error_estimate
If
True
, return an error estimate for the computed output.- output_d_mu_return_array
if
True
, return the output gradient as aNumPy array
. Otherwise, return a dict of gradients for eachParameter
.- mu
Parameter values
for which to compute the values.- kwargs
Further keyword arguments to select further quantities that sould be returned or to customize how the values are computed.
Returns
A dict with the computed values.
- solve(self, mu=None, return_error_estimate=False, **kwargs)[source]¶
Solve the discrete problem for the
parameter values
mu
.This method returns a
VectorArray
with a internal state representation of the model’s solution for givenparameter values
. It is a convenience wrapper aroundcompute
.The result may be
cached
in case caching has been activated for the given model.Parameters
- mu
Parameter values
for which to solve.- return_error_estimate
If
True
, also return an error estimate for the computed solution.- kwargs
Additional keyword arguments passed to
compute
that might affect how the solution is computed.
Returns
The solution
VectorArray
. Whenreturn_error_estimate
isTrue
, the estimate is returned as second value.
- output(self, mu=None, return_error_estimate=False, **kwargs)[source]¶
Return the model output for given
parameter values
mu
.This method is a convenience wrapper around
compute
.Parameters
- mu
Parameter values
for which to compute the output.- return_error_estimate
If
True
, also return an error estimate for the computed output.- kwargs
Additional keyword arguments passed to
compute
that might affect how the solution is computed.
Returns
The computed model output as a 2D
NumPy array
. The dimension of axis 1 is : attr:dim_output
. (For stationary problems, axis 0 has dimension 1. For time-dependent problems, the dimension of axis 0 depends on the number of time steps.) Whenreturn_error_estimate
isTrue
, the estimate is returned as second value.
- solve_d_mu(self, parameter, index, mu=None, **kwargs)[source]¶
Solve for 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
- mu
Parameter value
for which to solve
Returns
The sensitivity of the solution as a
VectorArray
.
- output_d_mu(self, mu=None, return_array=False, **kwargs)[source]¶
Compute the gradient w.r.t. the parameter of the output functional.
Parameters
- 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
.
Returns
The gradient as a
NumPy array
or a dict ofNumPy arrays
.
- estimate_error(self, mu=None, **kwargs)[source]¶
Estimate the error for the computed internal state.
For given
parameter values
mu
this method returns an error estimate for the computed internal model state as returned bysolve
. It is a convenience wrapper aroundcompute
.The model 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
Model
.Parameters
- mu
Parameter values
for which to estimate the error.- kwargs
Additional keyword arguments passed to
compute
that might affect how the error estimate (or the solution) is computed.
Returns
The estimated error.
- estimate_output_error(self, mu=None, **kwargs)[source]¶
Estimate the error for the computed output.
For given
parameter values
mu
this method returns an error estimate for the computed model output as returned byoutput
. It is a convenience wrapper aroundcompute
.The output 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
Model
.Parameters
- mu
Parameter values
for which to estimate the error.- kwargs
Additional keyword arguments passed to
compute
that might affect how the error estimate (or the output) is computed.
Returns
The estimated error.
- visualize(self, U, **kwargs)[source]¶
Visualize a
VectorArray
U of the model’ssolution_space
.Parameters
- U
The
VectorArray
fromsolution_space
that shall be visualized.- kwargs
Additional keyword arguments to customize the visualization. See the docstring of
self.visualizer.visualize
.