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

One specific implementation of LinearEigensystem using Davidson's algorithm with modifications to manage near linear dependencies, and consequent numerical noise, in candidate expansion vectors. More...

#include <LinearEigensystemDavidson.h>

Inheritance diagram for molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >:
Collaboration diagram for molpro::linalg::itsolv::LinearEigensystemDavidson< 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::LinearEigensystemDavidson< R, Q, P >

One specific implementation of LinearEigensystem using Davidson's algorithm with modifications to manage near linear dependencies, and consequent numerical noise, in candidate expansion vectors.

TODO add more documentation and examples

Template Parameters
R
Q
P

Public Types

using SolverTemplate = IterativeSolverTemplate< LinearEigensystem, R, Q, P >
 

Public Member Functions

 LinearEigensystemDavidson (const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers=std::make_shared< molpro::linalg::itsolv::ArrayHandlers< R, Q, P > >(), const std::shared_ptr< Logger > &logger_=std::make_shared< Logger >())
 
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
 
size_t end_iteration (R &parameters, R &actions) override
 
void finalize () override
 
void precondition (std::vector< R > &parameters, std::vector< R > &action) const
 Applies the Davidson preconditioner.
 
std::vector< scalar_type > eigenvalues () const override
 
virtual std::vector< scalar_type > working_set_eigenvalues () const override
 
void set_value_errors () override
 Implementation class should overload this to set errors in the current values (e.g. change in eigenvalues)
 
void report (std::ostream &cout, bool endl=true) const override
 
void set_reset_D (size_t n)
 Set the period in iterations for resetting the D space.
 
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.
 
int get_reset_D_maxQ_size () const
 
std::size_t get_max_size_qspace () const
 
void set_max_size_qspace (std::size_t n)
 
std::size_t get_min_size_qspace () const
 
void set_min_size_qspace (std::size_t n)
 
void set_hermiticity (bool hermitian) override
 
bool get_hermiticity () const override
 
void set_options (const Options &options) override
 
std::shared_ptr< Options > get_options () 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 (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
 
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
 
const std::shared_ptr< molpro::profiler::Profiler > & profiler () const override
 
bool solve (const VecRef< R > &parameters, const VecRef< R > &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 construct_residual (const std::vector< int > &roots, const CVecRef< R > &params, const VecRef< R > &actions) override
 Constructs residual for given roots provided their parameters and actions.
 
- Protected Member Functions inherited from molpro::linalg::itsolv::IterativeSolverTemplate< Solver, R, Q, P >
 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 ()
 
virtual bool linearEigensystem () const
 
size_t solve_and_generate_working_set (const VecRef< R > &parameters, const VecRef< R > &action)
 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
 

Protected Attributes

detail::DSpaceResetter< Q > m_dspace_resetter
 resets D space
 
bool m_hermiticity = false
 whether the problem is hermitian or not
 
std::vector< scalar_type > m_last_values
 The values from the previous iteration.
 
bool m_resetting_in_progress = false
 whether D space resetting is in progress
 
RSpaceOptions< value_type_abs > rspace_opts
 Options concerning R-space handling.
 
QSpaceOptions qspace_opts
 Options concerning Q-space handling.
 
- 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
 
bool m_normalise_solution = false
 whether to normalise the solutions
 
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
 
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
 

Member Typedef Documentation

◆ SolverTemplate

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

Constructor & Destructor Documentation

◆ LinearEigensystemDavidson()

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

Member Function Documentation

◆ construct_residual()

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

Constructs residual for given roots provided their parameters and actions.

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

◆ eigenvalues()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
std::vector< scalar_type > molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::eigenvalues ( ) const
inlineoverride

◆ end_iteration() [1/3]

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
size_t molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::end_iteration ( const VecRef< R > &  parameters,
const VecRef< R > &  action 
)
inlineoverride

Proposes new parameters for the subspace from the preconditioned residuals.

After add_vector solves the subspace problem it returns the new solution and residual. The residual should be preconditioned, i.e. using Davidson method, to accelerate convergence. The updated residual is used in this function to propose new Q space parameters orthonormal to the old space. They are returned in parameters so that corresponding actions can be calculated and used in add_vector in the next iteration.

Every n_reset_D iterations the D space has to be reset. If working set does not cover all solutions than resetting is done over multiple iterations. During this time, there are no deletions from the Q space. This is done by temporarily increasing maximum allowed size of Q space.

Parameters
parametersoutput new parameters for the subspace.
residualpreconditioned residuals.
Returns
number of significant parameters to calculate the action for

◆ end_iteration() [2/3]

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
size_t molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::end_iteration ( R &  parameters,
R &  actions 
)
inlineoverride

◆ end_iteration() [3/3]

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
size_t molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::end_iteration ( std::vector< R > &  parameters,
std::vector< R > &  action 
)
inlineoverride

◆ finalize()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::finalize ( )
inlineoverride

◆ get_hermiticity()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
bool molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::get_hermiticity ( ) const
inlineoverride

◆ get_max_size_qspace()

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

◆ get_min_size_qspace()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
std::size_t molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::get_min_size_qspace ( ) 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::LinearEigensystemDavidson< R, Q, P >::get_options ( ) const
inlineoverride

◆ get_reset_D()

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

◆ get_reset_D_maxQ_size()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
int molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::get_reset_D_maxQ_size ( ) const
inline

◆ nonlinear()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
bool molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::nonlinear ( ) const
inlineoverride

◆ precondition()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::precondition ( std::vector< R > &  parameters,
std::vector< R > &  action 
) const
inline

Applies the Davidson preconditioner.

◆ report()

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

◆ set_hermiticity()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::set_hermiticity ( bool  hermitian)
inlineoverride

◆ set_max_size_qspace()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::set_max_size_qspace ( std::size_t  n)
inline

◆ set_min_size_qspace()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::set_min_size_qspace ( std::size_t  n)
inline

◆ set_options()

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

◆ set_reset_D()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::set_reset_D ( size_t  n)
inline

Set the period in iterations for resetting the D space.

◆ set_reset_D_maxQ_size()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::set_reset_D_maxQ_size ( size_t  n)
inline

Set the maximum size of Q space after resetting the D space.

◆ set_value_errors()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
void molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::set_value_errors ( )
inlineoverridevirtual

Implementation class should overload this to set errors in the current values (e.g. change in eigenvalues)

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

◆ working_set_eigenvalues()

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
virtual std::vector< scalar_type > molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::working_set_eigenvalues ( ) const
inlineoverridevirtual

Member Data Documentation

◆ m_dspace_resetter

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
detail::DSpaceResetter<Q> molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::m_dspace_resetter
protected

resets D space

◆ m_hermiticity

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
bool molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::m_hermiticity = false
protected

whether the problem is hermitian or not

◆ m_last_values

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
std::vector<scalar_type> molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::m_last_values
protected

The values from the previous iteration.

◆ m_resetting_in_progress

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
bool molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::m_resetting_in_progress = false
protected

whether D space resetting is in progress

◆ qspace_opts

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
QSpaceOptions molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::qspace_opts
protected

Options concerning Q-space handling.

◆ rspace_opts

template<class R , class Q = R, class P = std::map<size_t, typename R::value_type>>
RSpaceOptions<value_type_abs> molpro::linalg::itsolv::LinearEigensystemDavidson< R, Q, P >::rspace_opts
protected

Options concerning R-space handling.