pymor.algorithms package

Submodules

adaptivegreedy module


class pymor.algorithms.adaptivegreedy.AdaptiveSampleSet(parameter_space)[source]

Bases: pymor.core.interfaces.BasicInterface

An adaptive parameter sample set.

Used by adaptive_greedy.


pymor.algorithms.adaptivegreedy._estimate(mu, rd=None, d=None, rc=None, error_norm=None)[source]

Called by adaptive_greedy.


pymor.algorithms.adaptivegreedy.adaptive_greedy(discretization, reductor, parameter_space=None, initial_basis=None, use_estimator=True, error_norm=None, extension_algorithm=<function gram_schmidt_basis_extension>, target_error=None, max_extensions=None, validation_mus=0, rho=1.1, gamma=0.2, theta=0.0, visualize=False, visualize_vertex_size=80, pool=<pymor.parallel.dummy.DummyPool object>)[source]

Greedy basis generation algorithm with adaptively refined training set.

This method extends pyMOR’s default greedy greedy basis generation algorithm by adaptive refinement of the parameter training set according to [HDO11] to prevent overfitting of the reduced basis to the training set. This is achieved by estimating the reduction error on an additional validation set of parameters. If the ratio between the estimated errors on the validation set and the validation set is larger than rho, the training set is refined using standard grid refinement techniques.

[HDO11]Haasdonk, B.; Dihlmann, M. & Ohlberger, M., A training set and multiple bases generation approach for parameterized model reduction based on adaptive grids in parameter space, Math. Comput. Model. Dyn. Syst., 2011, 17, 423-442

Parameters

discretization
See greedy.
reductor
See greedy.
parameter_space
The ParameterSpace for which to compute the reduced model. If None, the parameter space of the discretization is used.
initial_basis
See greedy.
use_estimator
See greedy.
error_norm
See greedy.
extension_algorithm
See greedy.
target_error
See greedy.
max_extensions
See greedy.
validation_mus
One of the following:
  • a list of Parameters to use as validation set,
  • a positive number indicating the number of random parameters to use as validation set,
  • a non-positive number, indicating the negative number of random parameters to use as validation set in addition to the centers of the elements of the adaptive training set.
rho
Maximum allowed ratio between maximum estimated error on validation set vs. maximum estimated error on training set. If the ratio is larger, the training set is refined.
gamma
Weight of the age penalty term in the training set refinement indicators.
theta
Ratio of training set elements to select for refinement. (One element is always refined.)
visualize
If True, visualize the refinement indicators. (Only available for 2 and 3 dimensional parameter spaces.)
visualize_vertex_size
Size of the vertices in the visualization.
pool
See greedy.

Returns

Dict with the following fields

basis:The reduced basis.
reduced_discretization:The reduced Discretization obtained for the computed basis.
reconstructor:Reconstructor for reduced_discretization.
extensions:Number of greedy iterations.
max_errs:Sequence of maximum errors during the greedy run.
max_err_mus:The parameters corresponding to max_errs.
max_val_errs:Sequence of maximum errors on the validation set.
max_val_err_mus:The parameters corresponding to max_val_errs.
refinements:Number of refinements made in each extension step.
training_set_sizes:The final size of the training set in each extension step.
time:Duration of the algorithm.
reduction_data:Reduction data returned by the last reductor call.

basic module

Module containing some basic but generic linear algebra algorithms.


pymor.algorithms.basic.almost_equal(U, V, U_ind=None, V_ind=None, product=None, norm=None, rtol=1e-14, atol=1e-14)[source]

Compare U and V for almost equality.

The vectors of U and V are compared in pairs for almost equality. Two vectors u and v are considered almost equal iff

||u - v|| <= atol + ||v|| * rtol.

The norm to be used can be specified via the norm or product parameter.

If the length of U (U_ind) resp. V (V_ind) is 1, the single specified vector is compared to all vectors of the other array. Otherwise, the lengths of both indexed arrays have to agree.

Parameters

U, V
VectorArrays to be compared.
U_ind, V_ind
Indices of the vectors that are to be compared (see VectorArray).
product
If specified, use this inner product Operator to compute the norm. product and norm are mutually exclusive.
norm
If specified, must be a callable, which is used to compute the norm or, alternatively, one of the string ‘l1’, ‘l2’, ‘sup’, in which case the respective VectorArray norm methods are used. product and norm are mutually exclusive. If neither is specified, norm='l2' is assumed.
rtol
The relative tolerance.
atol
The absolute tolerance.

Defaults

rtol, atol (see pymor.core.defaults)

basisextension module

This module contains algorithms for extending a given reduced basis by a new vector.

The methods are mainly designed to be used in conjunction with the greedy algorithm. Each method is of the form

extension_algorithm(basis, U, ...)

where basis and U are VectorArrays containing the old basis and new vectors to be added. The methods return a tuple new_basis, data where new_basis holds the extended basis and data is a dict containing additional information about the extension process. The data dict at least has the key hierarchic whose value signifies if the new basis contains the old basis as its first vectors.

If the basis extension fails, e.g. because the new vector is not linearly independent from the basis, an ExtensionError exception is raised.


pymor.algorithms.basisextension.gram_schmidt_basis_extension(basis, U, product=None, copy_basis=True, copy_U=True)[source]

Extend basis using Gram-Schmidt orthonormalization.

Parameters

basis
VectorArray containing the basis to extend.
U
VectorArray containing the new basis vectors.
product
The inner product w.r.t. which to orthonormalize; if None, the Euclidean product is used.
copy_basis
If copy_basis is False, the old basis is extended in-place.
copy_U
If copy_U is False, the new basis vectors are removed from U.

Returns

new_basis
The extended basis.
extension_data

Dict containing the following fields:

hierarchic:True if new_basis contains basis as its first vectors.

Raises

ExtensionError
Gram-Schmidt orthonormalization has failed. This is the case when no vector in U is linearly independent of the basis.

pymor.algorithms.basisextension.pod_basis_extension(basis, U, count=1, copy_basis=True, product=None, orthonormalize=True)[source]

Extend basis with the first count POD modes of the defect of the projection of U onto the current basis.

Warning

The provided basis is assumed to be orthonormal w.r.t. the given inner product!

Parameters

basis
VectorArray containing the basis to extend. The basis is expected to be orthonormal w.r.t. product.
U
VectorArray containing the vectors to which the POD is applied.
count
Number of POD modes that shall be appended to the basis.
product
The inner product w.r.t. which to orthonormalize; if None, the Euclidean product is used.
copy_basis
If copy_basis is False, the old basis is extended in-place.
orthonormalize
If True, re-orthonormalize the new basis vectors obtained by the POD in order to improve numerical accuracy.

Returns

new_basis
The extended basis.
extension_data

Dict containing the following fields:

hierarchic:True if new_basis contains basis as its first vectors.

Raises

ExtensionError
POD has produced no new vectors. This is the case when no vector in U is linearly independent of the basis.

pymor.algorithms.basisextension.trivial_basis_extension(basis, U, copy_basis=True, copy_U=True)[source]

Extend basis by simply appending the new vectors.

We check if the new vectors are already contained in the basis, but we do not check for linear independence.

Parameters

basis
VectorArray containing the basis to extend.
U
VectorArray containing the new basis vectors.
copy_basis
If copy_basis is False, the old basis is extended in-place.
copy_U
If copy_U is False, the new basis vectors are removed from U.

Returns

new_basis
The extended basis.
extension_data

Dict containing the following fields:

hierarchic:True if new_basis contains basis as its first vectors.

Raises

ExtensionError
Raised when all vectors in U are already contained in the basis.

ei module

This module contains algorithms for the empirical interpolation of Operators.

The main work for generating the necessary interpolation data is handled by the ei_greedy method. The objects returned by this method can be used to instantiate an EmpiricalInterpolatedOperator.

As a convenience, the interpolate_operators method allows to perform the empirical interpolation of the Operators of a given discretization with a single function call.


pymor.algorithms.ei.deim(U, modes=None, error_norm=None, product=None)[source]

Generate data for empirical interpolation using DEIM algorithm.

Given a VectorArray U, this method generates a collateral basis and interpolation DOFs for empirical interpolation of the vectors contained in U. The returned objects can be used to instantiate an EmpiricalInterpolatedOperator (with triangular=False).

The collateral basis is determined by the first pod modes of U.

Parameters

U
A VectorArray of vectors to interpolate.
modes
Dimension of the collateral basis i.e. number of POD modes of the vectors in U.
error_norm
Norm w.r.t. which to calculate the interpolation error. If None, the Euclidean norm is used.
product
Inner product Operator used for the POD.

Returns

interpolation_dofs
NumPy array of the DOFs at which the vectors are interpolated.
collateral_basis
VectorArray containing the generated collateral basis.
data

Dict containing the following fields:

errors:Sequence of maximum approximation errors during greedy search.

pymor.algorithms.ei.ei_greedy(U, error_norm=None, atol=None, rtol=None, max_interpolation_dofs=None, projection='ei', product=None, copy=True, pool=<pymor.parallel.dummy.DummyPool object>)[source]

Generate data for empirical interpolation using EI-Greedy algorithm.

Given a VectorArray U, this method generates a collateral basis and interpolation DOFs for empirical interpolation of the vectors contained in U. The returned objects can be used to instantiate an EmpiricalInterpolatedOperator (with triangular=True).

The interpolation data is generated by a greedy search algorithm, where in each loop iteration the worst approximated vector in U is added to the collateral basis.

Parameters

U
A VectorArray of vectors to interpolate.
error_norm
Norm w.r.t. which to calculate the interpolation error. If None, the Euclidean norm is used.
atol
Stop the greedy search if the largest approximation error is below this threshold.
rtol
Stop the greedy search if the largest relative approximation error is below this threshold.
max_interpolation_dofs
Stop the greedy search if the number of interpolation DOF (= dimension of the collateral basis) reaches this value.
projection
If 'ei', compute the approximation error by comparing the given vectors by their interpolants. If 'orthogonal', compute the error by comparing with the orthogonal projection onto the span of the collateral basis.
product
If projection == 'orthogonal', the inner product which is used to perform the projection. If None, the Euclidean product is used.
copy
If False, U will be modified during executing of the algorithm.
pool
If not None, the WorkerPool to use for parallelization.

Returns

interpolation_dofs
NumPy array of the DOFs at which the vectors are evaluated.
collateral_basis
VectorArray containing the generated collateral basis.
data

Dict containing the following fields:

errors:Sequence of maximum approximation errors during greedy search.
triangularity_errors:Sequence of maximum absolute values of interoplation matrix coefficients in the upper triangle (should be near zero).

pymor.algorithms.ei.interpolate_operators(discretization, operator_names, parameter_sample, error_norm=None, atol=None, rtol=None, max_interpolation_dofs=None, projection='ei', product=None, pool=<pymor.parallel.dummy.DummyPool object>)[source]

Empirical operator interpolation using the EI-Greedy algorithm.

This is a convenience method to facilitate the use of ei_greedy. Given a Discretization, names of Operators, and a sample of Parameters, first the operators are evaluated on the solution snapshots of the discretization for the provided parameters. These evaluations are then used as input for ei_greedy. Finally the resulting interpolation data is used to create EmpiricalInterpolatedOperators and a new discretization with the interpolated operators is returned.

Note that this implementation creates one common collateral basis for all specified operators, which might not be what you want.

Parameters

discretization
The Discretization whose Operators will be interpolated.
operator_names
List of keys in the operators dict of the discretization. The corresponding Operators will be interpolated.
parameter_sample
A list of Parameters for which solution snapshots are calculated.
error_norm
See ei_greedy.
atol
See ei_greedy.
rtol
See ei_greedy.
max_interpolation_dofs
See ei_greedy.
projection
See ei_greedy.
product
See ei_greedy.
pool
If not None, the WorkerPool to use for parallelization.

Returns

ei_discretization
Discretization with Operators given by operator_names replaced by EmpiricalInterpolatedOperators.
data

Dict containing the following fields:

dofs:NumPy array of the DOFs at which the Operators have to be evaluated.
basis:VectorArray containing the generated collateral basis.
errors:Sequence of maximum approximation errors during greedy search.
triangularity_errors:Sequence of maximum absolute values of interoplation matrix coefficients in the upper triangle (should be near zero).

error module


pymor.algorithms.error.reduction_error_analysis(reduced_discretization, discretization=None, reconstructor=None, test_mus=10, basis_sizes=0, random_seed=None, estimator=True, condition=False, error_norms=(), error_norm_names=None, estimator_norm_index=0, custom=(), plot=False, plot_custom_logarithmic=True, pool=<pymor.parallel.dummy.DummyPool object>)[source]

Analyze the model reduction error.

The maximum model reduction error is estimated by solving the reduced Discretization for given random Parameters.

Parameters

reduced_discretization
The reduced Discretization.
discretization
The high-dimensional Discretization. Must be specified if error_norms are given.
reconstructor
The reconstructor for reduced_discretization. Must be specified if error_norms are given.
test_mus
Either a list of Parameters to compute the errors for, or the number of parameters which are sampled randomly from parameter_space (if given) or reduced_discretization.parameter_space.
basis_sizes
Either a list of reduced basis dimensions to consider, or the number of dimensions (which are then selected equidistantly, always including the maximum reduced space dimension). The dimensions are input for ~pymor.reductors.basic.reduce_to_subbasis to quickly obtain smaller reduced Discretizations from rb_discretization.
random_seed
If test_mus is a number, use this value as random seed for drawing the Parameters.
estimator
If True evaluate the error estimator of reduced_discretization on the test Parameters.
condition
If True, compute the condition of the reduced system matrix for the given test Parameters (can only be specified if rb_discretization is an instance of StationaryDiscretization and rb_discretization.operator is linear).
error_norms
List of norms in which to compute the model reduction error.
error_norm_names
Names of the norms given by error_norms. If None, the name attributes of the given norms are used.
estimator_norm_index
When estimator is True and error_norms are specified, this is the index of the norm in error_norms w.r.t. which to compute the effectivity of the estimator.
custom

List of custom functions which are evaluated for each test Parameter and basis size. The functions must have the signature

def custom_value(reduced_discretization, discretization=d,
                 reconstructor, mu, dim):
    pass
plot
If True, generate a plot of the computed quantities w.r.t. the basis size.
plot_custom_logarithmic
If True, use a logarithmic y-axis to plot the computed custom values.
pool
If not None, the WorkerPool to use for parallelization.

Returns

Dict with the following fields

mus:The test Parameters which have been considered.
basis_sizes:The reduced basis dimensions which have been considered.
norms:NumPy array of the norms of the high-dimensional solutions w.r.t. all given test Parameters, reduced basis dimensions and norms in error_norms. (Only present when error_norms has been specified.)
max_norms:Maxima of norms over the given test Parameters.
max_norm_mus:Parameters corresponding to max_norms.
errors:NumPy array of the norms of the model reduction errors w.r.t. all given test Parameters, reduced basis dimensions and norms in error_norms. (Only present when error_norms has been specified.)
max_errors:Maxima of errors over the given test Parameters.
max_error_mus:Parameters corresponding to max_errors.
rel_errors:errors divided by norms. (Only present when error_norms has been specified.)
max_rel_errors:Maxima of rel_errors over the given test Parameters.
max_rel_error_mus:Parameters corresponding to max_rel_errors.
error_norm_names:Names of the given error_norms. (Only present when error_norms has been specified.)
estimates:NumPy array of the model reduction error estimates w.r.t. all given test Parameters and reduced basis dimensions. (Only present when estimator is True.)
max_estimate:Maxima of estimates over the given test Parameters.
max_estimate_mus:Parameters corresponding to max_estimates.
effectivities:errors divided by estimates. (Only present when estimator is True and error_norms has been specified.)
min_effectivities:Minima of effectivities over the given test Parameters.
min_effectivity_mus:Parameters corresponding to min_effectivities.
max_effectivities:Maxima of effectivities over the given test Parameters.
max_effectivity_mus:Parameters corresponding to max_effectivities.
errors:NumPy array of the reduced system matrix conditions w.r.t. all given test Parameters and reduced basis dimensions. (Only present when conditions is True.)
max_conditions:Maxima of conditions over the given test Parameters.
max_condition_mus:Parameters corresponding to max_conditions.
custom_values:NumPy array of custom function evaluations w.r.t. all given test Parameters, reduced basis dimensions and functions in custom. (Only present when custom has been specified.)
max_custom_values:Maxima of custom_values over the given test Parameters.
max_custom_values_mus:Parameters corresponding to max_custom_values.
time:Time (in seconds) needed for the error analysis.
summary:String containing a summary of all computed quantities for the largest (last) considered basis size.
figure:The figure containing the generated plots. (Only present when plot is True.)

genericsolvers module

This module contains some iterative linear solvers which only use the Operator interface


pymor.algorithms.genericsolvers.apply_inverse(op, rhs, options=None)[source]

Solve linear equation system.

Applies the inverse of op to the vectors in rhs.

Parameters

op
The linear, non-parametric Operator to invert.
rhs
VectorArray of right-hand sides for the equation system.
options
The solver options to use. (See options.)

Returns

VectorArray of the solution vectors.


pymor.algorithms.genericsolvers.lgmres(A, b, x0=None, tol=1e-05, maxiter=1000, M=None, callback=None, inner_m=30, outer_k=3, outer_v=None, store_outer_Av=True)[source]

pymor.algorithms.genericsolvers.lsmr(A, b, damp=0.0, atol=1e-06, btol=1e-06, conlim=100000000.0, maxiter=None, show=False)[source]

pymor.algorithms.genericsolvers.lsqr(A, b, damp=0.0, atol=1e-08, btol=1e-08, conlim=100000000.0, iter_lim=None, show=False)[source]

pymor.algorithms.genericsolvers.options(default_solver='generic_lgmres', default_least_squares_solver='least_squares_generic_lsmr', generic_lgmres_tol=1e-05, generic_lgmres_maxiter=1000, generic_lgmres_inner_m=39, generic_lgmres_outer_k=3, least_squares_generic_lsmr_damp=0.0, least_squares_generic_lsmr_atol=1e-06, least_squares_generic_lsmr_btol=1e-06, least_squares_generic_lsmr_conlim=100000000.0, least_squares_generic_lsmr_maxiter=None, least_squares_generic_lsmr_show=False, least_squares_generic_lsqr_damp=0.0, least_squares_generic_lsqr_atol=1e-06, least_squares_generic_lsqr_btol=1e-06, least_squares_generic_lsqr_conlim=100000000.0, least_squares_generic_lsqr_iter_lim=None, least_squares_generic_lsqr_show=False)[source]

Returns solver_options (with default values) for arbitrary linear Operators.

Parameters

default_solver
Default solver to use (generic_lgmres, least_squares_generic_lsmr, least_squares_generic_lsqr).
default_least_squares_solver
Default solver to use for least squares problems (least_squares_generic_lsmr, least_squares_generic_lsqr).
generic_lgmres_tol
See scipy.sparse.linalg.lgmres.
generic_lgmres_maxiter
See scipy.sparse.linalg.lgmres.
generic_lgmres_inner_m
See scipy.sparse.linalg.lgmres.
generic_lgmres_outer_k
See scipy.sparse.linalg.lgmres.
least_squares_generic_lsmr_damp
See scipy.sparse.linalg.lsmr.
least_squares_generic_lsmr_atol
See scipy.sparse.linalg.lsmr.
least_squares_generic_lsmr_btol
See scipy.sparse.linalg.lsmr.
least_squares_generic_lsmr_conlim
See scipy.sparse.linalg.lsmr.
least_squares_generic_lsmr_maxiter
See scipy.sparse.linalg.lsmr.
least_squares_generic_lsmr_show
See scipy.sparse.linalg.lsmr.
least_squares_generic_lsqr_damp
See scipy.sparse.linalg.lsqr.
least_squares_generic_lsqr_atol
See scipy.sparse.linalg.lsqr.
least_squares_generic_lsqr_btol
See scipy.sparse.linalg.lsqr.
least_squares_generic_lsqr_conlim
See scipy.sparse.linalg.lsqr.
least_squares_generic_lsqr_iter_lim
See scipy.sparse.linalg.lsqr.
least_squares_generic_lsqr_show
See scipy.sparse.linalg.lsqr.

Returns

A tuple of possible values for solver_options.

Defaults

default_solver, default_least_squares_solver, generic_lgmres_tol, generic_lgmres_maxiter, generic_lgmres_inner_m, generic_lgmres_outer_k, least_squares_generic_lsmr_damp, least_squares_generic_lsmr_atol, least_squares_generic_lsmr_btol, least_squares_generic_lsmr_conlim, least_squares_generic_lsmr_maxiter, least_squares_generic_lsmr_show, least_squares_generic_lsqr_atol, least_squares_generic_lsqr_btol, least_squares_generic_lsqr_conlim, least_squares_generic_lsqr_iter_lim, least_squares_generic_lsqr_show (see pymor.core.defaults)

gram_schmidt module


pymor.algorithms.gram_schmidt.gram_schmidt(A, product=None, atol=1e-13, rtol=1e-13, offset=0, find_duplicates=True, reiterate=True, reiteration_threshold=0.1, check=True, check_tol=0.001, copy=True)[source]

Orthonormalize a VectorArray using the stabilized Gram-Schmidt algorithm.

Parameters

A
The VectorArray which is to be orthonormalized.
product
The inner product Operator w.r.t. which to orthonormalize. If None, the Euclidean product is used.
atol
Vectors of norm smaller than atol are removed from the array.
rtol
Relative tolerance used to detect linear dependent vectors (which are then removed from the array).
offset
Assume that the first offset vectors are already orthonormal and start the algorithm at the offset + 1-th vector.
reiterate
If True, orthonormalize again if the norm of the orthogonalized vector is much smaller than the norm of the original vector.
reiteration_threshold
If reiterate is True, re-orthonormalize if the ratio between the norms of the orthogonalized vector and the original vector is smaller than this value.
check
If True, check if the resulting VectorArray is really orthonormal.
check_tol
Tolerance for the check.
copy
If True, create a copy of A instead of modifying A in-place.

Returns

The orthonormalized VectorArray.

Defaults

atol, rtol, reiterate, reiteration_threshold, check, check_tol (see pymor.core.defaults)

greedy module


pymor.algorithms.greedy.greedy(discretization, reductor, samples, initial_basis=None, use_estimator=True, error_norm=None, extension_algorithm=<function gram_schmidt_basis_extension>, atol=None, rtol=None, max_extensions=None, pool=None)[source]

Greedy basis generation algorithm.

This algorithm generates a reduced basis by iteratively adding the worst approximated solution snapshot for a given training set to the reduced basis. The approximation error is computed either by directly comparing the reduced solution to the detailed solution or by using an error estimator (use_estimator == True). The reduction and basis extension steps are performed by calling the methods provided by the reductor and extension_algorithm arguments.

Parameters

discretization
The Discretization to reduce.
reductor
Reductor for reducing the given Discretization. This has to be a function of the form reductor(discretization, basis, extends=None). The method has to return a tuple (reduced_discretization, reconstructor, reduction_data). In case the last basis extension was hierarchic (see extension_algorithm), the extends argument is set to (last_reduced_discretization, last_reconstructor, last_reduction_data) which can be used by the reductor to speed up the reduction process. For an example see reduce_coercive.
samples
The set of Parameter samples on which to perform the greedy search.
initial_basis
The initial reduced basis at the start of the algorithm. If None, an empty basis is used as initial basis.
use_estimator
If True, use reduced_discretization.estimate() to estimate the errors on the sample set. Otherwise discretization.solve() is called to compute the exact model reduction error.
error_norm
If use_estimator == False, use this function to calculate the norm of the error. If None, the Euclidean norm is used.
extension_algorithm
The extension algorithm to be used to extend the current reduced basis with the maximum error snapshot. This has to be a function of the form extension_algorithm(old_basis, new_vector), which returns a tuple (new_basis, extension_data), where extension_data is a dict at least containing the key hierarchic. hierarchic should be set to True if new_basis contains old_basis as its first vectors.
atol
If not None, stop the algorithm if the maximum (estimated) error on the sample set drops below this value.
rtol
If not None, stop the algorithm if the maximum (estimated) relative error on the sample set drops below this value.
max_extensions
If not None, stop the algorithm after max_extensions extension steps.
pool
If not None, the WorkerPool to use for parallelization.

Returns

Dict with the following fields

basis:The reduced basis.
reduced_discretization:The reduced Discretization obtained for the computed basis.
reconstructor:Reconstructor for reduced_discretization.
max_errs:Sequence of maximum errors during the greedy run.
max_err_mus:The parameters corresponding to max_errs.
extensions:Number of performed basis extensions.
time:Total runtime of the algorithm.
reduction_data:The reduction_data returned by the last reductor call.

image module


pymor.algorithms.image.estimate_image(operators=(), vectors=(), domain=None, extends=False, orthonormalize=True, product=None, riesz_representatives=False)[source]

Estimate the image of given Operators for all mu.

Let operators be a list of Operators with common source and range, and let vectors be a list of VectorArrays or vector-like Operators in the range of these operators. Given a VectorArray domain of vectors in the source of the operators, this algorithms determines a VectorArray image of range vectors such that the linear span of image contains:

  • op.apply(U, mu=mu) for all operators op in operators, for all possible Parameters mu and for all VectorArrays U contained in the linear span of domain,
  • U for all VectorArrays in vectors,
  • v.as_vector(mu) for all Operators in vectors and all possible Parameters mu.

The algorithm will try to choose image as small as possible. However, no optimality is guaranteed.

Parameters

operators
See above.
vectors
See above.
domain
See above. If None, an empty domain VectorArray is assumed.
extends
For some operators, e.g. EmpiricalInterpolatedOperator, as well as for all elements of vectors, image is estimated independently from the choice of domain. If extends is True, such operators are ignored. (This is useful in case these vectors have already been obtained by earlier calls to this function.)
orthonormalize
Compute an orthonormal basis for the linear span of image using the gram_schmidt algorithm.
product
Inner product Operator w.r.t. which to orthonormalize.
riesz_representatives
If True, compute Riesz representatives of the vectors in image before orthonormalizing (useful for dual norm computation when the range of the operators is a dual space).

Returns

The VectorArray image.

Raises

ImageCollectionError
Is raised when for a given Operator no image estimate is possible.

pymor.algorithms.image.estimate_image_hierarchical(operators=(), vectors=(), domain=None, extends=None, orthonormalize=True, product=None, riesz_representatives=False)[source]

Estimate the image of given Operators for all mu.

This is an extended version of estimate_image, which calls estimate_image individually for each vector of domain.

As a result, the vectors in the returned image VectorArray will be ordered by the domain vector they correspond to (starting with vectors which correspond to the functionals and to Operators for which the image is estimated independently from domain).

This function also returns an image_dims list, such that the first image_dims[i+1] vectors of image correspond to the first i vectors of domain (the first image_dims[0] vectors correspond to vectors and to Operators with fixed image estimate).

Parameters

operators
See estimate_image.
vectors
See estimate_image.
domain
See estimate_image.
extends
When additional vectors have been appended to the domain VectorArray after estimate_image_hierarchical has been called, and estimate_image_hierarchical shall be called again for the extended domain array, extends can be set to (image, image_dims), where image, image_dims are the return values of the last estimate_image_hierarchical call. The old domain vectors will then be skipped during computation and image, image_dims will be modified in-place.
orthonormalize
See estimate_image.
product
See estimate_image.
riesz_representatives
See estimate_image.

Returns

image
See above.
image_dims
See above.

Raises

ImageCollectionError
Is raised when for a given Operator no image estimate is possible.

newton module


pymor.algorithms.newton.newton(operator, rhs, initial_guess=None, mu=None, error_norm=None, least_squares=False, miniter=0, maxiter=100, rtol=-1.0, atol=-1.0, stagnation_window=3, stagnation_threshold=0.9, return_stages=False, return_residuals=False)[source]

Basic Newton algorithm.

This method solves the nonlinear equation

A(U, mu) = V

for U using the Newton method.

Parameters

operator
The Operator A. A must implement the jacobian interface method.
rhs
VectorArray of length 1 containing the vector V.
initial_guess
If None, a VectorArray of length 1 containing an initial guess for the solution U.
mu
The Parameter for which to solve the equation.
error_norm
The norm with which the norm of the residual is computed. If None, the Euclidean norm is used.
least_squares
If True, use a least squares linear solver (e.g. for residual minimization).
miniter
Minimum amount of iterations to perform.
maxiter
Fail if the iteration count reaches this value without converging.
rtol
Finish when the residual norm has been reduced by this factor relative to the norm of the initial residual.
atol
Finish when the residual norm is below this threshold.
stagnation_window
Finish when the residual norm has not been reduced by a factor of stagnation_threshold during the last stagnation_window iterations.
stagnation_threshold
See stagnation_window.
return_stages
If True, return a VectorArray of the intermediate approximations of U after each iteration.
return_residuals
If True, return a VectorArray of all residual vectors which have been computed during the Newton iterations.

Returns

U
VectorArray of length 1 containing the computed solution
data

Dict containing the following fields:

error_sequence:NumPy array containing the residual norms after each iteration.
stages:See return_stages.
residuals:See return_residuals.

Raises

NewtonError
Raised if the Netwon algorithm failed to converge.

Defaults

miniter, maxiter, rtol, atol, stagnation_window, stagnation_threshold (see pymor.core.defaults)

pod module


pymor.algorithms.pod.pod(A, modes=None, product=None, rtol=4e-08, atol=0.0, l2_mean_err=0.0, symmetrize=False, orthonormalize=True, check=True, check_tol=1e-10)[source]

Proper orthogonal decomposition of A.

Viewing the VectorArray A as a A.dim x len(A) matrix, the return value of this method is the VectorArray of left-singular vectors of the singular value decomposition of A, where the inner product on R^(dim(A)) is given by product and the inner product on R^(len(A)) is the Euclidean inner product.

Parameters

A
The VectorArray for which the POD is to be computed.
modes
If not None, only the first modes POD modes (singular vectors) are returned.
product
Inner product Operator w.r.t. which the POD is computed.
rtol
Singular values smaller than this value multiplied by the largest singular value are ignored.
atol
Singular values smaller than this value are ignored.
l2_mean_err

Do not return more modes than needed to bound the mean l2-approximation error by this value. I.e. the number of returned modes is at most

argmin_N { 1 / len(A) * sum_{n=N+1}^{infty} s_n^2 <= l2_mean_err^2 }

where s_n denotes the n-th singular value.

symmetrize
If True, symmetrize the Gramian again before proceeding.
orthonormalize
If True, orthonormalize the computed POD modes again using the gram_schmidt algorithm.
check
If True, check the computed POD modes for orthonormality.
check_tol
Tolerance for the orthonormality check.

Returns

POD
VectorArray of POD modes.
SVALS
Sequence of singular values.

Defaults

rtol, atol, l2_mean_err, symmetrize, orthonormalize, check, check_tol (see pymor.core.defaults)

timestepping module

This module provides generic time-stepping algorithms for the solution of instationary problems.

The algorithms are generic in the sense that each algorithms operates exclusively on Operators and VectorArrays. In particular, the algorithms can also be used to turn an arbitrary stationary Discretization provided by an external library into an instationary Discretization.

Currently, implementations of explicit_euler and implicit_euler time-stepping are provided. The TimeStepperInterface defines a common interface that has to be fulfilled by the time-steppers used by InstationaryDiscretization. The classes ExplicitEulerTimeStepper and ImplicitEulerTimeStepper encapsulate explicit_euler and implicit_euler to provide this interface.


class pymor.algorithms.timestepping.ExplicitEulerTimeStepper(nt)[source]

Bases: pymor.algorithms.timestepping.TimeStepperInterface

Explicit Euler time-stepper.

Solves equations of the form

M * d_t u + A(u, mu, t) = F(mu, t).

Parameters

nt
The number of time-steps the time-stepper will perform.
solve(initial_time, end_time, initial_data, operator, rhs=None, mass=None, mu=None, num_values=None)[source]

Apply time-stepper to the equation

M * d_t u + A(u, mu, t) = F(mu, t).

Parameters

initial_time
The time at which to begin time-stepping.
end_time
The time until which to perform time-stepping.
initial_data
The solution vector at initial_time.
operator
The Operator A.
rhs
The right-hand side F (either VectorArray of length 1 or Operator with range.dim == 1). If None, zero right-hand side is assumed.
mass
The Operator M. If None, the identity operator is assumed.
mu
Parameter for which operator and rhs are evaluated. The current time is added to mu with key _t.
num_values
The number of returned vectors of the solution trajectory. If None, each intermediate vector that is calculated is returned.

Returns

VectorArray containing the solution trajectory.


class pymor.algorithms.timestepping.ImplicitEulerTimeStepper(nt, solver_options='operator')[source]

Bases: pymor.algorithms.timestepping.TimeStepperInterface

Implict Euler time-stepper.

Solves equations of the form

M * d_t u + A(u, mu, t) = F(mu, t).

Parameters

nt
The number of time-steps the time-stepper will perform.
solver_options
The solver_options used to invert M + dt*A. The special values 'mass' and 'operator' are recognized, in which case the solver_options of M (resp. A) are used.
solve(initial_time, end_time, initial_data, operator, rhs=None, mass=None, mu=None, num_values=None)[source]

Apply time-stepper to the equation

M * d_t u + A(u, mu, t) = F(mu, t).

Parameters

initial_time
The time at which to begin time-stepping.
end_time
The time until which to perform time-stepping.
initial_data
The solution vector at initial_time.
operator
The Operator A.
rhs
The right-hand side F (either VectorArray of length 1 or Operator with range.dim == 1). If None, zero right-hand side is assumed.
mass
The Operator M. If None, the identity operator is assumed.
mu
Parameter for which operator and rhs are evaluated. The current time is added to mu with key _t.
num_values
The number of returned vectors of the solution trajectory. If None, each intermediate vector that is calculated is returned.

Returns

VectorArray containing the solution trajectory.


class pymor.algorithms.timestepping.TimeStepperInterface[source]

Bases: pymor.core.interfaces.ImmutableInterface

Interface for time-stepping algorithms.

Algorithms implementing this interface solve time-dependent problems of the form

M * d_t u + A(u, mu, t) = F(mu, t).

Time-steppers used by InstationaryDiscretization have to fulfill this interface.

solve(initial_time, end_time, initial_data, operator, rhs=None, mass=None, mu=None, num_values=None)[source]

Apply time-stepper to the equation

M * d_t u + A(u, mu, t) = F(mu, t).

Parameters

initial_time
The time at which to begin time-stepping.
end_time
The time until which to perform time-stepping.
initial_data
The solution vector at initial_time.
operator
The Operator A.
rhs
The right-hand side F (either VectorArray of length 1 or Operator with range.dim == 1). If None, zero right-hand side is assumed.
mass
The Operator M. If None, the identity operator is assumed.
mu
Parameter for which operator and rhs are evaluated. The current time is added to mu with key _t.
num_values
The number of returned vectors of the solution trajectory. If None, each intermediate vector that is calculated is returned.

Returns

VectorArray containing the solution trajectory.


pymor.algorithms.timestepping.explicit_euler(A, F, U0, t0, t1, nt, mu=None, num_values=None)[source]

pymor.algorithms.timestepping.implicit_euler(A, F, M, U0, t0, t1, nt, mu=None, num_values=None, solver_options='operator')[source]