1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_LINEAREIGENSYSTEMDAVIDSON_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_LINEAREIGENSYSTEMDAVIDSON_H
3#include <molpro/Profiler.h>
4#include <molpro/linalg/itsolv/CastOptions.h>
5#include <molpro/linalg/itsolv/DSpaceResetter.h>
6#include <molpro/linalg/itsolv/IterativeSolverTemplate.h>
7#include <molpro/linalg/itsolv/Logger.h>
8#include <molpro/linalg/itsolv/helper.h>
9#include <molpro/linalg/itsolv/propose_rspace.h>
10#include <molpro/linalg/itsolv/qspace_options.h>
11#include <molpro/linalg/itsolv/rspace_options.h>
12#include <molpro/linalg/itsolv/subspace/SubspaceSolverLinEig.h>
13#include <molpro/linalg/itsolv/subspace/XSpace.h>
24template<
typename value_type >
28template<
typename value_type>
45template <
class R,
class Q = R,
class P = std::map<
size_t,
typename R::value_type>>
49 using typename SolverTemplate::scalar_type;
50 using typename SolverTemplate::value_type_abs;
55 const std::shared_ptr<Logger>&
logger_ = std::make_shared<Logger>())
84 auto m_prof = prof->push(
"itsolv::end_iteration");
92 prof->start(
"end_iteration (propose_rspace)");
103 size_t end_iteration(std::vector<R>& parameters, std::vector<R>& action)
override {
107 auto wparams = std::vector<std::reference_wrapper<R>>{std::ref(parameters)};
108 auto wactions = std::vector<std::reference_wrapper<R>>{std::ref(actions)};
119 auto imag_eigval_components =
subspace_solver->imag_eigval_components();
120 if (imag_eigval_components.empty()) {
125 for (
auto&
pair : imag_eigval_components) {
130 "The following roots are complex-valued. Associated eigenvectors are the real and imaginary part "
131 "of the pairs and the imaginary parts of the eigenvalues are ",
132 imag_eigval_components);
136 void precondition(std::vector<R>& parameters, std::vector<R>& action)
const {}
141 auto eval = std::vector<scalar_type>{};
160 cout <<
"errors " << std::scientific;
162 std::copy(begin(
err), end(
err), std::ostream_iterator<scalar_type>(
cout,
", "));
164 cout <<
"eigenvalues ";
166 cout << std::fixed << std::setprecision(14);
167 std::copy(begin(
ev), end(
ev), std::ostream_iterator<scalar_type>(
cout,
", "));
168 cout << std::defaultfloat;
189 auto xspace = std::dynamic_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace);
201 if (
opt.reset_D_max_Q_size)
203 if (
opt.max_size_qspace)
205 if (
opt.min_size_qspace)
207 if (
opt.contrib_thresh)
218 auto opt = std::make_shared<LinearEigensystemDavidsonOptions>();
233 auto prof = this->
profiler()->push(
"itsolv::construct_residual");
239 const auto& imag_eigval_components =
subspace_solver->imag_eigval_components();
241 for (
size_t i = 0;
i <
roots.size(); ++
i) {
244 auto it = std::ranges::find(imag_eigval_components,
roots[
i], [](
const auto&
pair) {
return pair.first; });
246 if (
it != imag_eigval_components.end()) {
265 const auto distance = std::ranges::distance(imag_eigval_components.begin(),
it);
273 "Complex conjugate eigenvalue pair incomplete in construct_residual (this can lead to poor convergence)");
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
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
std::shared_ptr< Statistics > m_stats
accumulates statistics of operations performed by the solver
Definition IterativeSolverTemplate.h:703
One specific implementation of LinearEigensystem using Davidson's algorithm with modifications to man...
Definition LinearEigensystemDavidson.h:46
void finalize() override
Definition LinearEigensystemDavidson.h:112
int get_reset_D_maxQ_size() const
Definition LinearEigensystemDavidson.h:178
void set_min_size_qspace(std::size_t n)
Definition LinearEigensystemDavidson.h:186
size_t end_iteration(const VecRef< R > ¶meters, const VecRef< R > &action) override
Proposes new parameters for the subspace from the preconditioned residuals.
Definition LinearEigensystemDavidson.h:82
void set_reset_D_maxQ_size(size_t n)
Set the maximum size of Q space after resetting the D space.
Definition LinearEigensystemDavidson.h:177
bool nonlinear() const override
Definition LinearEigensystemDavidson.h:64
QSpaceOptions qspace_opts
Options concerning Q-space handling.
Definition LinearEigensystemDavidson.h:291
void set_hermiticity(bool hermitian) override
Definition LinearEigensystemDavidson.h:187
bool get_hermiticity() const override
Definition LinearEigensystemDavidson.h:194
bool m_resetting_in_progress
whether D space resetting is in progress
Definition LinearEigensystemDavidson.h:289
detail::DSpaceResetter< Q > m_dspace_resetter
resets D space
Definition LinearEigensystemDavidson.h:286
std::vector< scalar_type > eigenvalues() const override
Definition LinearEigensystemDavidson.h:138
std::size_t get_max_size_qspace() const
Definition LinearEigensystemDavidson.h:179
size_t end_iteration(std::vector< R > ¶meters, std::vector< R > &action) override
Definition LinearEigensystemDavidson.h:103
void precondition(std::vector< R > ¶meters, std::vector< R > &action) const
Applies the Davidson preconditioner.
Definition LinearEigensystemDavidson.h:136
void set_value_errors() override
Implementation class should overload this to set errors in the current values (e.g....
Definition LinearEigensystemDavidson.h:149
void set_max_size_qspace(std::size_t n)
Definition LinearEigensystemDavidson.h:180
size_t get_reset_D() const
Definition LinearEigensystemDavidson.h:175
std::size_t get_min_size_qspace() const
Definition LinearEigensystemDavidson.h:185
bool m_hermiticity
whether the problem is hermitian or not
Definition LinearEigensystemDavidson.h:287
void set_options(const Options &options) override
Definition LinearEigensystemDavidson.h:196
RSpaceOptions< value_type_abs > rspace_opts
Options concerning R-space handling.
Definition LinearEigensystemDavidson.h:290
void set_reset_D(size_t n)
Set the period in iterations for resetting the D space.
Definition LinearEigensystemDavidson.h:174
std::vector< scalar_type > m_last_values
The values from the previous iteration.
Definition LinearEigensystemDavidson.h:288
void report(std::ostream &cout, bool endl=true) const override
Definition LinearEigensystemDavidson.h:158
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 LinearEigensystemDavidson.h:232
virtual std::vector< scalar_type > working_set_eigenvalues() const override
Definition LinearEigensystemDavidson.h:140
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 >())
Definition LinearEigensystemDavidson.h:53
std::shared_ptr< Options > get_options() const override
Definition LinearEigensystemDavidson.h:217
size_t end_iteration(R ¶meters, R &actions) override
Definition LinearEigensystemDavidson.h:106
Interface for a specific iterative solver, it can add special member functions or variables.
Definition IterativeSolver.h:426
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
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
void read_handler_counts(std::shared_ptr< Statistics > stats, std::shared_ptr< ArrayHandlers< R, Q, P > > handlers)
Definition Statistics.h:30
const std::shared_ptr< const molpro::Options > options()
Get the Options object associated with iterative-solver.
Definition linalg_options.cpp:4
Definition scalar_traits.h:19
static std::shared_ptr< LinearEigensystemDavidsonOptions > LinearEigensystem(const std::shared_ptr< Options > &options)
Definition CastOptions.h:39
Access point for different options in iterative solvers.
Definition Options.h:20
Information about performance of IterativeSolver instance.
Definition Statistics.h:10
Definition LinearEigensystemDavidson.h:25
static const char * name
Definition LinearEigensystemDavidson.h:26