1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_LINEAREQUATIONSDAVIDSON_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_LINEAREQUATIONSDAVIDSON_H
3#include <molpro/linalg/itsolv/CastOptions.h>
4#include <molpro/linalg/itsolv/DSpaceResetter.h>
5#include <molpro/linalg/itsolv/IterativeSolverTemplate.h>
6#include <molpro/linalg/itsolv/propose_rspace.h>
7#include <molpro/linalg/itsolv/qspace_options.h>
8#include <molpro/linalg/itsolv/rspace_options.h>
9#include <molpro/linalg/itsolv/subspace/SubspaceSolverLinEig.h>
10#include <molpro/linalg/itsolv/subspace/XSpace.h>
39template <
class R,
class Q = R,
class P = std::map<
size_t,
typename R::value_type>>
44 using typename SolverTemplate::value_type;
45 using typename SolverTemplate::value_type_abs;
48 const std::shared_ptr<Logger>&
logger_ = std::make_shared<Logger>())
69 auto prof = this->
profiler()->push(
"itsolv::end_iteration");
86 size_t end_iteration(std::vector<R>& parameters, std::vector<R>& action)
override {
90 auto wparams = std::vector<std::reference_wrapper<R>>{std::ref(parameters)};
91 auto wactions = std::vector<std::reference_wrapper<R>>{std::ref(actions)};
96 auto prof = this->
profiler()->push(
"itsolv::add_equations");
97 auto xspace = std::static_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace);
98 xspace->add_rhs_equations(
rhs);
106 auto xspace = std::static_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace);
107 return xspace->rhs();
137 auto xspace = std::dynamic_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace);
159 if (
opt.reset_D_max_Q_size)
161 if (
opt.max_size_qspace)
163 if (
opt.min_size_qspace)
165 if (
opt.contrib_thresh)
173 if (
opt.augmented_hessian)
178 auto opt = std::make_shared<LinearEquationsDavidsonOptions>();
194 cout <<
", errors " << std::scientific;
196 std::copy(begin(
err), end(
err), std::ostream_iterator<value_type_abs>(
cout,
", "));
197 cout << std::defaultfloat;
209 auto chi = std::vector<value_type>(std::min(solutions.rows(),
rhs.cols()), value_type{0});
210 for (
size_t i = 0;
i <
chi.size(); ++
i)
211 for (
size_t k = 0;
k < std::min(solutions.cols(),
rhs.rows()); ++
k)
229 const auto&
norm = std::dynamic_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace)->rhs_norm();
233 for (
size_t i = 0;
i < roots.size(); ++
i) {
236 if (
size_t(
ii) < eigenvalues.size()
and eigenvalues[
ii] != value_type(0))
237 this->
m_handlers->rr().axpy(-eigenvalues[
ii], params.at(
i), actions.at(
i));
Class, containing a collection of array handlers used in IterativeSolver Provides a Builder sub-class...
Definition ArrayHandlers.h:25
Implements IterativeSolver interface that is common to all solvers.
Definition IterativeSolverTemplate.h:163
std::vector< value_type_abs > m_value_errors
value errors from the most recent solution
Definition IterativeSolverTemplate.h:697
std::vector< int > m_working_set
indices of roots in the working set
Definition IterativeSolverTemplate.h:698
std::shared_ptr< subspace::IXSpace< R, Q, P > > m_xspace
manages the subspace and associated data
Definition IterativeSolverTemplate.h:694
void set_n_roots(size_t roots) override
Definition IterativeSolverTemplate.h:290
std::shared_ptr< ArrayHandlers< R, Q, P > > m_handlers
Array handlers.
Definition IterativeSolverTemplate.h:693
std::shared_ptr< subspace::ISubspaceSolver< R, Q, P > > m_subspace_solver
solves the subspace problem
Definition IterativeSolverTemplate.h:695
std::vector< value_type_abs > m_errors
errors from the most recent solution
Definition IterativeSolverTemplate.h:696
std::shared_ptr< Options > get_options() const override
Definition IterativeSolverTemplate.h:311
const std::shared_ptr< molpro::profiler::Profiler > & profiler() const override
Definition IterativeSolverTemplate.h:397
bool m_end_iteration_needed
whether end_iteration should be called after any preconditioner
Definition IterativeSolverTemplate.h:715
void report() const override
Definition IterativeSolverTemplate.h:352
bool m_normalise_solution
whether to normalise the solutions
Definition IterativeSolverTemplate.h:705
const std::vector< int > & working_set() const override
Definition IterativeSolverTemplate.h:286
std::shared_ptr< Logger > m_logger
logger
Definition IterativeSolverTemplate.h:704
void set_options(const Options &options) override
Definition IterativeSolverTemplate.h:296
bool solve(const VecRef< R > ¶meters, const VecRef< R > &actions, const Problem< R > &problem, bool generate_initial_guess=false) override
Definition IterativeSolverTemplate.h:399
std::shared_ptr< Statistics > m_stats
accumulates statistics of operations performed by the solver
Definition IterativeSolverTemplate.h:703
Solves a system of linear equation, A x = b.
Definition LinearEquationsDavidson.h:40
size_t get_reset_D() const
Definition LinearEquationsDavidson.h:119
detail::DSpaceResetter< Q > m_dspace_resetter
resets D space
Definition LinearEquationsDavidson.h:247
value_type_abs get_svd_thresh() const
Definition LinearEquationsDavidson.h:116
bool solve(const VecRef< R > ¶meters, const VecRef< R > &actions, const Problem< R > &problem, bool generate_initial_guess=false) override
Definition LinearEquationsDavidson.h:57
void add_equations(const std::vector< R > &rhs) override
Definition LinearEquationsDavidson.h:103
void set_hermiticity(bool hermitian) override
Definition LinearEquationsDavidson.h:135
size_t end_iteration(const VecRef< R > ¶meters, const VecRef< R > &action) override
Definition LinearEquationsDavidson.h:68
std::size_t get_min_size_qspace() const
Definition LinearEquationsDavidson.h:134
RSpaceOptions< value_type_abs > rspace_opts
Options concerning R-space handling.
Definition LinearEquationsDavidson.h:245
std::size_t get_max_size_qspace() const
Definition LinearEquationsDavidson.h:130
bool m_resetting_in_progress
whether D space resetting is in progress
Definition LinearEquationsDavidson.h:250
size_t end_iteration(R ¶meters, R &actions) override
Definition LinearEquationsDavidson.h:89
void set_norm_thresh(value_type_abs thresh)
Set threshold on the norm of parameters that should be considered null.
Definition LinearEquationsDavidson.h:111
void set_min_size_qspace(std::size_t n)
Definition LinearEquationsDavidson.h:131
void add_equations(const CVecRef< R > &rhs) override
Definition LinearEquationsDavidson.h:95
void set_svd_thresh(value_type_abs thresh)
Definition LinearEquationsDavidson.h:115
std::shared_ptr< Options > get_options() const override
Definition LinearEquationsDavidson.h:177
LinearEquationsDavidson(const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers, const std::shared_ptr< Logger > &logger_=std::make_shared< Logger >())
Definition LinearEquationsDavidson.h:47
void add_equations(const R &rhs) override
Definition LinearEquationsDavidson.h:102
int get_reset_D_maxQ_size() const
Definition LinearEquationsDavidson.h:122
QSpaceOptions qspace_opts
Options concerning Q-space handling.
Definition LinearEquationsDavidson.h:246
void set_max_size_qspace(std::size_t n)
Definition LinearEquationsDavidson.h:125
bool nonlinear() const override
Definition LinearEquationsDavidson.h:66
size_t end_iteration(std::vector< R > ¶meters, std::vector< R > &action) override
Definition LinearEquationsDavidson.h:86
void set_options(const Options &options) override
Definition LinearEquationsDavidson.h:154
bool m_hermiticity
whether the problem is hermitian or not
Definition LinearEquationsDavidson.h:248
void construct_residual(const std::vector< int > &roots, const CVecRef< R > ¶ms, const VecRef< R > &actions) override
Constructs residual for given roots provided their parameters and actions.
Definition LinearEquationsDavidson.h:227
std::vector< value_type > m_last_values
the values from the previous iteration
Definition LinearEquationsDavidson.h:249
CVecRef< Q > rhs() const override
Definition LinearEquationsDavidson.h:105
value_type_abs get_norm_thresh() const
Definition LinearEquationsDavidson.h:112
void set_reset_D(size_t n)
Set the period in iterations for resetting the D space.
Definition LinearEquationsDavidson.h:118
void report(std::ostream &cout, bool endl=true) const override
Definition LinearEquationsDavidson.h:192
bool get_hermiticity() const override
Definition LinearEquationsDavidson.h:142
void set_value_errors() override
Implementation class should overload this to set errors in the current values (e.g....
Definition LinearEquationsDavidson.h:216
void set_augmented_hessian(const value_type_abs parameter)
Set value of augmented hessian parameter. If 0, than augmented Hessian is not used.
Definition LinearEquationsDavidson.h:144
std::vector< value_type > values() const
The values chi_ii = <b_i|x_i> of the current solutions, or with the augmented Hessian the subspace ei...
Definition LinearEquationsDavidson.h:204
void set_reset_D_maxQ_size(size_t n)
Set the maximum size of Q space after resetting the D space.
Definition LinearEquationsDavidson.h:121
value_type_abs get_augmented_hessian() const
Definition LinearEquationsDavidson.h:149
Abstract class defining the problem-specific interface for the simplified solver interface to Iterati...
Definition IterativeSolver.h:85
virtual bool RHS(R &RHS, unsigned int instance) const
Return the inhomogeneous part of a linear equation system.
Definition IterativeSolver.h:155
Resets D space constructing full solutions as the new working set, removing instabilities from Q spac...
Definition DSpaceResetter.h:74
auto propose_rspace(IterativeSolver< R, Q, P > &solver, const VecRef< R > ¶meters, const VecRef< R > &residuals, subspace::IXSpace< R, Q, P > &xspace, subspace::ISubspaceSolver< R, Q, P > &subspace_solver, ArrayHandlers< R, Q, P > &handlers, Logger &logger, const RSpaceOptions< typename array::ArrayHandler< R, R >::value_type_abs > &r_opts, const QSpaceOptions &q_opts, molpro::profiler::Profiler &profiler)
Proposes new parameters for the subspace from the preconditioned residuals.
Definition propose_rspace.h:582
4-parameter interpolation of a 1-dimensional function given two points for which function values and ...
Definition helper.h:14
auto cwrap(ForwardIt begin, ForwardIt end)
Takes a begin and end iterators and returns a vector of references to each element.
Definition wrap.h:52
auto cwrap_arg(T &&arg, S &&... args) -> std::enable_if_t< std::conjunction_v< std::is_same< decay_t< T >, decay_t< S > >... >, CVecRef< decay_t< T > > >
Constructs a vector of const reference wrappers with provided arguments.
Definition wrap.h:149
std::unique_ptr< LinearEigensystem< R, Q, P > > create_LinearEigensystem(const LinearEigensystemOptions &options, const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers=std::make_shared< molpro::linalg::itsolv::ArrayHandlers< R, Q, P > >())
Definition SolverFactory.h:111
auto wrap(ForwardIt begin, ForwardIt end)
Takes a begin and end iterators and returns a vector of references to each element.
Definition wrap.h:32
std::vector< std::reference_wrapper< const A > > CVecRef
Definition wrap.h:14
std::vector< std::reference_wrapper< A > > VecRef
Definition wrap.h:11
T conjugate(const T &x)
Complex conjugate, staying within the scalar type; the identity for a real type.
Definition scalar_traits.h:47
const std::shared_ptr< const molpro::Options > options()
Get the Options object associated with iterative-solver.
Definition linalg_options.cpp:4
static std::shared_ptr< LinearEquationsDavidsonOptions > LinearEquations(const std::shared_ptr< Options > &options)
Definition CastOptions.h:54
Access point for different options in iterative solvers.
Definition Options.h:20
Information about performance of IterativeSolver instance.
Definition Statistics.h:10