pymor.models.interface¶
Module Contents¶
- class pymor.models.interface.Model(dim_input=0, products=None, error_estimator=None, visualizer=None, name=None)[source]¶
Bases:
pymor.core.cache.CacheableObject,pymor.parameters.base.ParametricObjectInterface for model objects.
A model object defines a discrete problem via its
classand theOperatorsit contains. Furthermore, models can besolvedfor givenparameter valuesresulting in a solutionVectorArray.- solution_space[source]¶
VectorSpaceof the solutionVectorArraysreturned bysolve.
Methods
Compute the solution of the model and associated quantities.
Estimate the error for the computed internal state.
Estimate the error for the computed output.
Return the model output for given
parameter valuesmu.Compute the gradient w.r.t. the parameter of the output functional.
Solve the discrete problem for the
parameter valuesmu.Solve for the partial derivative of the solution w.r.t. a parameter index
Visualize a
VectorArrayU of the model'ssolution_space.- compute(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, output_error_estimate_return_vector=False, *, mu=None, input=None, **kwargs)[source]¶
Compute the solution of the model and associated quantities.
This method computes the output of the model, its internal state, and various associated quantities for given
parameter valuesmu.Note
The default implementation defers the actual computations to the methods
_compute_solution,_compute_output,_compute_solution_error_estimateand_compute_output_error_estimate. The call to_compute_solutioniscached. In addition,Modelimplementors may implement_computeto simultaneously compute multiple values in an optimized way. The corresponding_compute_XXXmethods 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, eitherTrueto 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.- output_error_estimate_return_vector
If
True, return the output estimate as aNumPy array, where each component corresponds to the respective component of theoutput_functional. Otherwise, return the Euclidean norm of all components.- mu
Parameter valuesfor which to compute the values.- input
The model input. Either a
NumPy arrayof shape(self.dim_input,), aFunctionwithdim_domain == 1andshape_range == (self.dim_input,)mapping time to input, or astrexpression withtas variable that can be used to instantiate anExpressionFunctionof this type. Can beNoneifself.dim_input == 0.- kwargs
Further keyword arguments to select further quantities that should be returned or to customize how the values are computed.
Returns
A dict with the computed values.
- estimate_error(mu=None, input=None, **kwargs)[source]¶
Estimate the error for the computed internal state.
For given
parameter valuesmuthis 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 valuesfor which to estimate the error.- input
The model input. Either a
NumPy arrayof shape(self.dim_input,), aFunctionwithdim_domain == 1andshape_range == (self.dim_input,)mapping time to input, or astrexpression withtas variable that can be used to instantiate anExpressionFunctionof this type. Can beNoneifself.dim_input == 0.- kwargs
Additional keyword arguments passed to
computethat might affect how the error estimate (or the solution) is computed.
Returns
The estimated error.
- estimate_output_error(mu=None, input=None, return_vector=False, **kwargs)[source]¶
Estimate the error for the computed output.
For given
parameter valuesmuthis 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 valuesfor which to estimate the error.- input
The model input. Either a
NumPy arrayof shape(self.dim_input,), aFunctionwithdim_domain == 1andshape_range == (self.dim_input,)mapping time to input, or astrexpression withtas variable that can be used to instantiate anExpressionFunctionof this type. Can beNoneifself.dim_input == 0.- return_vector
If
True, return the output estimate as aNumPy array, where each component corresponds to the respective component of theoutput_functional. Otherwise, return the Euclidean norm of all components.- kwargs
Additional keyword arguments passed to
computethat might affect how the error estimate (or the output) is computed.
Returns
The estimated error.
- output(mu=None, input=None, return_error_estimate=False, return_error_estimate_vector=False, **kwargs)[source]¶
Return the model output for given
parameter valuesmu.This method is a convenience wrapper around
compute.Parameters
- mu
Parameter valuesfor which to compute the output.- input
The model input. Either a
NumPy arrayof shape(self.dim_input,), aFunctionwithdim_domain == 1andshape_range == (self.dim_input,)mapping time to input, or astrexpression withtas variable that can be used to instantiate anExpressionFunctionof this type. Can beNoneifself.dim_input == 0.- return_error_estimate
If
True, also return an error estimate for the computed output.- return_error_estimate_vector
If
True, return the output estimate as aNumPy array, where each component corresponds to the respective component of theoutput_functional. Otherwise, return the Euclidean norm of all components.- kwargs
Additional keyword arguments passed to
computethat 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_estimateisTrue, the estimate is returned as second value.
- output_d_mu(mu=None, input=None, return_array=False, **kwargs)[source]¶
Compute the gradient w.r.t. the parameter of the output functional.
Parameters
- mu
Parameter valuefor which to compute the gradient- input
The model input. Either a
NumPy arrayof shape(self.dim_input,), aFunctionwithdim_domain == 1andshape_range == (self.dim_input,)mapping time to input, or astrexpression withtas variable that can be used to instantiate anExpressionFunctionof this type. Can beNoneifself.dim_input == 0.- 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 arrayor a dict ofNumPy arrays.
- solve(mu=None, input=None, return_error_estimate=False, **kwargs)[source]¶
Solve the discrete problem for the
parameter valuesmu.This method returns a
VectorArraywith a internal state representation of the model’s solution for givenparameter values. It is a convenience wrapper aroundcompute.The result may be
cachedin case caching has been activated for the given model.Parameters
- mu
Parameter valuesfor which to solve.- input
The model input. Either a
NumPy arrayof shape(self.dim_input,), aFunctionwithdim_domain == 1andshape_range == (self.dim_input,)mapping time to input, or astrexpression withtas variable that can be used to instantiate anExpressionFunctionof this type. Can beNoneifself.dim_input == 0.- return_error_estimate
If
True, also return an error estimate for the computed solution.- kwargs
Additional keyword arguments passed to
computethat might affect how the solution is computed.
Returns
The solution
VectorArray. Whenreturn_error_estimateisTrue, the estimate is returned as second value.
- solve_d_mu(parameter, index, mu=None, input=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 valuefor which to solve- input
The model input. Either a
NumPy arrayof shape(self.dim_input,), aFunctionwithdim_domain == 1andshape_range == (self.dim_input,)mapping time to input, or astrexpression withtas variable that can be used to instantiate anExpressionFunctionof this type. Can beNoneifself.dim_input == 0.
Returns
The sensitivity of the solution as a
VectorArray.
- visualize(U, **kwargs)[source]¶
Visualize a
VectorArrayU of the model’ssolution_space.Parameters
- U
The
VectorArrayfromsolution_spacethat shall be visualized.- kwargs
Additional keyword arguments to customize the visualization. See the docstring of
self.visualizer.visualize.