iterative-solver 0.0
 
Loading...
Searching...
No Matches
molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P > Class Template Reference

Solves a system of linear equation, A x = b. More...

#include <LinearEquationsDavidson.h>

Inheritance diagram for molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >:
Collaboration diagram for molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >:

Detailed Description

template<class R, class Q = R, class P = std::map<size_t, typename R::value_type>>
class molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >

Solves a system of linear equation, A x = b.

The equations are solved using a Krylov subspace projection method with the P and D space. This is the same approach as LinearEigenvalue.

Residual

The residual is scaled down by the norm of the RHS vector so that thresholds are consistent.

Value

The value of solution i is $\chi_{ii}=\langle b_i|x_i\rangle$, the diagonal element of the susceptibility (second-order property) when the equations are for first-order perturbed wavefunctions. The value error used with the value convergence threshold is the absolute change in $\chi_{ii}$ since the previous iteration, without the scaling applied to the residual. With the augmented Hessian it is instead the change in the subspace eigenvalue.

Preconditioner

Augmented Hessian

Public Types

using SolverTemplate = IterativeSolverTemplate< LinearEquations, R, Q, P >
 
- Public Types inherited from molpro::linalg::itsolv::DavidsonCommon< Solver, R, Q, P >
using SolverTemplate = IterativeSolverTemplate< Solver, R, Q, P >
 

Public Member Functions

 LinearEquationsDavidson (const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers, const std::shared_ptr< Logger > &logger_=std::make_shared< Logger >())
 
void add_equations (const CVecRef< R > &rhs) override
 
void add_equations (const R &rhs) override
 
void add_equations (const std::vector< R > &rhs) override
 
CVecRef< Q > rhs () const override
 
void set_augmented_hessian (const value_type_abs parameter)
 Set value of augmented hessian parameter. If 0, than augmented Hessian is not used.
 
value_type_abs get_augmented_hessian () const
 
void set_options (const Options &options) override
 
std::shared_ptr< Options > get_options () const override
 
void report (std::ostream &cout, bool endl=true) const override
 
- Public Member Functions inherited from molpro::linalg::itsolv::DavidsonCommon< Solver, R, Q, P >
bool nonlinear () const override
 
size_t end_iteration (const VecRef< R > &parameters, const VecRef< R > &action) override
 Proposes new parameters for the subspace from the preconditioned residuals.
 
size_t end_iteration (std::vector< R > &parameters, std::vector< R > &action) override
 Proposes new parameters for the subspace from the preconditioned residuals.
 
size_t end_iteration (R &parameters, R &actions) override
 Proposes new parameters for the subspace from the preconditioned residuals.
 
void set_norm_thresh (value_type_abs thresh)
 Set threshold on the norm of parameters that should be considered null.
 
value_type_abs get_norm_thresh () const
 
void set_svd_thresh (value_type_abs thresh)
 
value_type_abs get_svd_thresh () const
 
void set_reset_D (size_t n)
 Set the period in iterations for resetting the D space, 0 for never.
 
size_t get_reset_D () const
 
void set_reset_D_maxQ_size (size_t n)
 Set the maximum size of Q space after resetting the D space.
 
size_t get_reset_D_maxQ_size () const
 
void set_max_size_qspace (std::size_t n)
 
std::size_t get_max_size_qspace () const
 
void set_min_size_qspace (std::size_t n)
 Set the minimum size of Q space when it is truncated, which must not exceed the maximum size.
 
std::size_t get_min_size_qspace () const
 
void set_hermiticity (bool hermitian) override
 
bool get_hermiticity () const override
 
- Public Member Functions inherited from molpro::linalg::itsolv::IterativeSolverTemplate< Solver, R, Q, P >
 IterativeSolverTemplate ()=delete
 
 IterativeSolverTemplate (const IterativeSolverTemplate< Solver, R, Q, P > &)=delete
 
 IterativeSolverTemplate (IterativeSolverTemplate< Solver, R, Q, P > &&) noexcept=default
 
IterativeSolverTemplate< Solver, R, Q, P > & operator= (const IterativeSolverTemplate< Solver, R, Q, P > &)=delete
 
IterativeSolverTemplate< Solver, R, Q, P > & operator= (IterativeSolverTemplate< Solver, R, Q, P > &&) noexcept=default
 
void set_logger (std::shared_ptr< Logger > logger) override
 
Logger & logger () override
 
int add_vector (const VecRef< R > &parameters, const VecRef< R > &actions) override
 
int add_vector (const VecRef< R > &parameters, const VecRef< R > &actions, const VecRef< R > &metric_actions) override
 
bool supports_metric (MetricKind kind) const override
 
void set_metric (MetricKind kind, MetricStorage storage=MetricStorage::Stored, fapply_metric_type apply_metric={}) override
 
MetricKind metric_kind () const override
 
void set_check_metric (bool check) override
 
bool get_check_metric () const override
 
MetricStorage metric_storage () const override
 
int add_vector (std::vector< R > &parameters, std::vector< R > &actions) override
 
int add_vector (R &parameters, R &actions, value_type value=0) override
 
size_t add_p (const CVecRef< P > &pparams, const array::Span< value_type > &pp_action_matrix, const VecRef< R > &parameters, const VecRef< R > &actions, fapply_on_p_type apply_p) override
 
size_t add_p (const CVecRef< P > &pparams, const array::Span< value_type > &pp_action_matrix, const VecRef< R > &parameters, const VecRef< R > &actions, fapply_on_p_type apply_p, const PSpaceMetric &metric) override
 
void clearP () override
 
void solution (const std::vector< int > &roots, const VecRef< R > &parameters, const VecRef< R > &residual) override
 
void solution (const std::vector< int > &roots, std::vector< R > &parameters, std::vector< R > &residual) override
 
void solution (R &parameters, R &residual) override
 
void solution_params (const std::vector< int > &roots, std::vector< R > &parameters) override
 
void solution_params (const std::vector< int > &roots, const VecRef< R > &parameters) override
 
void solution_params (R &parameters) override
 
std::vector< size_t > suggest_p (const CVecRef< R > &solution, const CVecRef< R > &residual, size_t max_number, value_type_abs threshold) override
 
const std::vector< int > & working_set () const override
 
size_t n_roots () const override
 
void set_n_roots (size_t roots) override
 
void set_options (const Options &options) override
 
std::shared_ptr< Options > get_options () const override
 
const std::vector< value_type_abs > & errors () const override
 
const Statistics & statistics () const override
 
void report (std::ostream &cout, bool endl=true) const override
 
void iteration_report () const
 
void summary_report () const
 
void report () const override
 
void set_convergence_threshold (value_type_abs thresh) override
 
value_type_abs convergence_threshold () const override
 
void set_convergence_threshold_value (value_type_abs thresh) override
 
value_type_abs convergence_threshold_value () const override
 
void set_verbosity (Verbosity v) override
 
void set_verbosity (int v) override
 
Verbosity get_verbosity () const override
 
void set_max_iter (int n) override
 
int get_max_iter () const override
 
void set_max_p (int n) override
 
int get_max_p () const override
 
void set_p_threshold (value_type_abs threshold) override
 
value_type_abs get_p_threshold () const override
 
const subspace::Dimensions & dimensions () const override
 Access dimensions of the subspace.
 
scalar_type value () const override
 
void set_profiler (molpro::profiler::Profiler &profiler) override
 
void set_profiler (std::shared_ptr< molpro::profiler::Profiler > profiler) override
 
const std::shared_ptr< molpro::profiler::Profiler > & profiler () const override
 
std::vector< scalar_type > current_values () const
 The values reported in the iteration events: eigenvalues of eigensystems, the function value otherwise.
 
bool solve (const VecRef< R > &parameters, const VecRef< R > &actions, const Problem< R > &problem, bool generate_initial_guess=false) override
 
bool solve (const VecRef< R > &parameters, const VecRef< R > &actions, const VecRef< R > &metric_actions, const Problem< R > &problem, bool generate_initial_guess=false) override
 
bool solve (R &parameters, R &actions, const Problem< R > &problem, bool generate_initial_guess=false) override
 
bool solve (std::vector< R > &parameters, std::vector< R > &actions, const Problem< R > &problem, bool generate_initial_guess=false) override
 
bool test_problem (const Problem< R > &problem, R &v0, R &v1, int verbosity, value_type_abs threshold) const override
 

Protected Member Functions

void prepare_solve (const Problem< R > &problem, const VecRef< R > &actions) override
 Adds the right-hand sides provided by problem.
 
std::vector< value_type > values () const override
 The values chi_ii = <b_i|x_i> of the current solutions, or with the augmented Hessian the subspace eigenvalues.
 
void construct_residual (const std::vector< int > &roots, const CVecRef< R > &params, const VecRef< R > &actions, const detail::MetricSolutions< R, Q > &metric_solutions) override
 Constructs residual for given roots provided their parameters and actions.
 
- Protected Member Functions inherited from molpro::linalg::itsolv::DavidsonCommon< Solver, R, Q, P >
 DavidsonCommon (const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers, const std::shared_ptr< Logger > &logger, bool hermiticity)
 
void set_davidson_options (const Options &options, const DavidsonOptions &opt)
 Sets the general options and those of the Davidson solvers, after checking them.
 
template<class SolverOptions >
std::shared_ptr< SolverOptions > get_davidson_options () const
 Returns the general options and those of the Davidson solvers in an options object of type SolverOptions.
 
void assign_max_size_qspace (std::size_t n)
 Sets the maximum size of the Q space, without checking it, and lowers that after a D-space reset to it.
 
void set_value_errors () override
 Implementation class should overload this to set errors in the current values (e.g. change in eigenvalues)
 
- Protected Member Functions inherited from molpro::linalg::itsolv::IterativeSolverTemplate< Solver, R, Q, P >
bool solve_impl (const VecRef< R > &parameters, const VecRef< R > &actions, const VecRef< R > &metric_actions, const Problem< R > &problem, bool generate_initial_guess)
 Implements both overloads of solve(), with empty metric_actions for a problem without a metric.
 
void solution_impl (const std::vector< int > &roots, const VecRef< R > &parameters, const VecRef< R > &residual, const VecRef< R > &scratch)
 Implements solution()
 
template<typename ConstructResidual >
void solution_impl (const std::vector< int > &roots, const VecRef< R > &parameters, const VecRef< R > &residual, const VecRef< R > &scratch, ConstructResidual &&construct_residual_with)
 Implements solution(), with the residuals constructed by the given function in place of construct_residual(), which takes the same arguments.
 
void construct_solutions (const std::vector< int > &rows, const subspace::Matrix< value_type > &solutions, const VecRef< R > &parameters)
 Constructs the subspace vectors with the coefficients in the given rows of solutions.
 
void construct_actions (const std::vector< int > &rows, const subspace::Matrix< value_type > &solutions, const VecRef< R > &actions)
 Constructs the actions on the subspace vectors with the coefficients in the given rows of solutions.
 
 IterativeSolverTemplate (std::shared_ptr< subspace::IXSpace< R, Q, P > > xspace, std::shared_ptr< subspace::ISubspaceSolver< R, Q, P > > solver, std::shared_ptr< ArrayHandlers< R, Q, P > > handlers, std::shared_ptr< Statistics > stats, std::shared_ptr< Logger > logger)
 
virtual ~IterativeSolverTemplate ()
 
bool test_metric (const Problem< R > &problem, R &v0, R &v1, int verbosity, value_type_abs threshold) const
 Tests that the metric of a problem is Hermitian, <u|M v> = <M u|v>, and, if its kind says so, positive (semi)definite, on the first two test parameters.
 
virtual void combine_errors ()
 Implementation class can overload this to combine the errors of solutions, once those of all are known.
 
virtual void compute_errors (const std::vector< int > &roots, const CVecRef< R > &params, const CVecRef< R > &residuals, const std::vector< value_type_abs > &solution_norms, std::vector< value_type_abs > &errors)
 Computes the errors of roots, given their parameters and residuals; by default the norms of the residuals.
 
virtual void solution_with_errors (const std::vector< int > &roots, const VecRef< R > &parameters, const VecRef< R > &residual, const VecRef< R > &scratch, const std::vector< value_type_abs > &solution_norms, std::vector< value_type_abs > &errors)
 Constructs the parameters and residuals of roots, as solution_impl() does, and computes their errors, as compute_errors() does.
 
virtual bool linearEigensystem () const
 
size_t add_p_impl (const CVecRef< P > &pparams, const array::Span< value_type > &pp_action_matrix, const array::Span< value_type > &pp_metric_matrix, const VecRef< R > &parameters, const VecRef< R > &actions, fapply_on_p_type apply_p)
 Implements add_p(), with an empty pp_metric_matrix for a problem without a metric.
 
void check_pspace_metric (MetricKind kind, const CVecRef< P > &pparams, const array::Span< value_type > &pp_metric_matrix) const
 Throws if the metric matrix in the P space is not given for a metric of this kind, or, unless checks are off, shows that the metric does not have the properties of its kind; checked before the P space is added.
 
void check_metric_change (MetricKind kind, MetricStorage storage) const
 Throws if set_metric() with these arguments is not possible, apart from the function applying the metric.
 
void check_metric_positive ()
 For a positive (semi)definite metric, throws if the metric matrix shows that it is not, unless checks are off.
 
size_t n_added_vectors (const VecRef< R > &parameters) const
 The number of the given parameters that add_vector() takes up: no more than there are in the working set.
 
int add_vector_impl (const VecRef< R > &parameters, const VecRef< R > &actions, const VecRef< R > &metric_actions)
 Implements add_vector()
 
size_t solve_and_generate_working_set (const VecRef< R > &parameters, const VecRef< R > &action, const VecRef< R > &scratch={})
 Solves the subspace problems and selects the working set of roots, returning their parameters and residual in parameters and action.
 
template<typename TTT >
void check_consistent_number_of_roots_and_solutions (const std::vector< TTT > &roots, const size_t nparams)
 
bool end_iteration_needed () override
 
void finalize () override
 
bool verbosity_at_least (Verbosity v) const
 Whether output of verbosity v is printed in solve(); everything is printed if no verbosity was set.
 
void generate_initial_guess_from_diagonals (const VecRef< R > &parameters, const Q &diagonals)
 Fills parameters with unit vectors at the positions of the lowest diagonal elements.
 
std::vector< P > select_pspace (const Q &diagonals)
 Selects the P space from the lowest diagonal elements, subject to max_p and p_threshold.
 
std::pair< std::vector< value_type >, std::vector< value_type > > pspace_problem_matrices (const std::vector< P > &pspace, const Problem< R > &problem, const bool metric, const bool store_metric_actions) const
 Adds the P space to the subspace using the P-space kernel provided by problem; returns the working-set size.
 
size_t initialise_pspace (const std::vector< P > &pspace, const Problem< R > &problem, std::pair< std::vector< value_type >, std::vector< value_type > > &matrices, const VecRef< R > &parameters, const VecRef< R > &actions)
 Adds the P space to the subspace with the matrices of pspace_problem_matrices(); returns the working-set size.
 

Additional Inherited Members

- Static Protected Member Functions inherited from molpro::linalg::itsolv::DavidsonCommon< Solver, R, Q, P >
static void check_qspace_size_limits (std::size_t min_size, std::size_t max_size)
 Throws std::invalid_argument if the minimum size of the Q space exceeds its maximum size.
 
- Protected Attributes inherited from molpro::linalg::itsolv::DavidsonCommon< Solver, R, Q, P >
RSpaceOptions< value_type_abs > rspace_opts
 Options concerning R-space handling.
 
QSpaceOptions qspace_opts
 Options concerning Q-space handling.
 
detail::DSpaceResetter< Q > m_dspace_resetter
 resets D space
 
bool m_hermiticity = false
 whether the problem is hermitian or not
 
std::vector< value_type > m_last_values
 the values from the previous iteration
 
bool m_resetting_in_progress = false
 whether D space resetting is in progress
 
- Protected Attributes inherited from molpro::linalg::itsolv::IterativeSolverTemplate< Solver, R, Q, P >
std::shared_ptr< ArrayHandlers< R, Q, P > > m_handlers
 Array handlers.
 
std::shared_ptr< subspace::IXSpace< R, Q, P > > m_xspace
 manages the subspace and associated data
 
std::shared_ptr< subspace::ISubspaceSolver< R, Q, P > > m_subspace_solver
 solves the subspace problem
 
std::vector< value_type_abs > m_errors
 errors from the most recent solution
 
std::vector< value_type_abs > m_value_errors
 value errors from the most recent solution
 
std::vector< int > m_working_set
 indices of roots in the working set
 
size_t m_nroots {0}
 number of roots the solver is searching for
 
value_type_abs m_convergence_threshold {1.0e-8}
 residual norms less than this mark a converged solution
 
value_type_abs m_convergence_threshold_value
 value changes less than this mark a converged solution
 
std::shared_ptr< Statistics > m_stats
 accumulates statistics of operations performed by the solver
 
std::shared_ptr< Logger > m_logger
 logger
 
fapply_on_p_type m_apply_p = {}
 function that evaluates effect of action on the P space projection
 
std::optional< Verbosity > m_verbosity = {}
 how much output to print in solve()
 
int m_max_iter = 100
 maximum number of iterations in solve()
 
size_t m_max_p = 0
 maximum size of P space
 
MetricKind m_metric_kind = MetricKind::Identity
 the metric declared with set_metric()
 
MetricStorage m_metric_storage = MetricStorage::Stored
 how the actions of the metric are obtained
 
fapply_metric_type m_apply_metric = {}
 applies the metric on the fly, if its actions are not stored
 
bool m_check_metric = true
 whether the properties of the metric are checked
 
detail::MetricChecker< R, Q, P > m_metric_checker
 checks the properties of the metric
 
fapply_on_p_type m_apply_metric_p = {}
 adds the action of the metric on the P space, if its actions are stored
 
value_type_abs m_p_threshold = std::numeric_limits<value_type_abs>::max()
 threshold for selecting P space
 
bool m_end_iteration_needed = true
 whether end_iteration should be called after any preconditioner
 
bool m_solutions_outdated = false
 whether the subspace was changed since the solutions of its problem were found
 

Member Typedef Documentation

◆ SolverTemplate

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
using molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::SolverTemplate = IterativeSolverTemplate<LinearEquations, R, Q, P>

Constructor & Destructor Documentation

◆ LinearEquationsDavidson()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::LinearEquationsDavidson ( const std::shared_ptr< ArrayHandlers< R, Q, P > > &  handlers,
const std::shared_ptr< Logger > &  logger_ = std::make_shared<Logger>() 
)
inlineexplicit

Member Function Documentation

◆ add_equations() [1/3]

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::add_equations ( const CVecRef< R > &  rhs)
inlineoverride

◆ add_equations() [2/3]

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::add_equations ( const R &  rhs)
inlineoverride

◆ add_equations() [3/3]

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::add_equations ( const std::vector< R > &  rhs)
inlineoverride

◆ construct_residual()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::construct_residual ( const std::vector< int > &  roots,
const CVecRef< R > &  params,
const VecRef< R > &  actions,
const detail::MetricSolutions< R, Q > &  metric_solutions 
)
inlineoverrideprotectedvirtual

Constructs residual for given roots provided their parameters and actions.

Parameters
metric_solutionsthe actions of the metric on params if it is applied on the fly, otherwise empty

Implements molpro::linalg::itsolv::IterativeSolverTemplate< Solver, R, Q, P >.

◆ get_augmented_hessian()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
value_type_abs molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::get_augmented_hessian ( ) const
inline

◆ get_options()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
std::shared_ptr< Options > molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::get_options ( ) const
inlineoverride

◆ prepare_solve()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::prepare_solve ( const Problem< R > &  problem,
const VecRef< R > &  actions 
)
inlineoverrideprotectedvirtual

Adds the right-hand sides provided by problem.

Reimplemented from molpro::linalg::itsolv::IterativeSolverTemplate< Solver, R, Q, P >.

◆ report()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::report ( std::ostream &  cout,
bool  endl = true 
) const
inlineoverride

◆ rhs()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
CVecRef< Q > molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::rhs ( ) const
inlineoverride

◆ set_augmented_hessian()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::set_augmented_hessian ( const value_type_abs  parameter)
inline

Set value of augmented hessian parameter. If 0, than augmented Hessian is not used.

◆ set_options()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::set_options ( const Options &  options)
inlineoverride

◆ values()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
std::vector< value_type > molpro::linalg::itsolv::LinearEquationsDavidson< R, Q, P >::values ( ) const
inlineoverrideprotectedvirtual

The values chi_ii = <b_i|x_i> of the current solutions, or with the augmented Hessian the subspace eigenvalues.

Implements molpro::linalg::itsolv::DavidsonCommon< Solver, R, Q, P >.