1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_DAVIDSONCOMMON_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_DAVIDSONCOMMON_H
3#include <molpro/linalg/itsolv/DSpaceResetter.h>
4#include <molpro/linalg/itsolv/DavidsonOptions.h>
5#include <molpro/linalg/itsolv/IterativeSolverTemplate.h>
6#include <molpro/linalg/itsolv/Logger.h>
7#include <molpro/linalg/itsolv/Options.h>
8#include <molpro/linalg/itsolv/propose_rspace.h>
9#include <molpro/linalg/itsolv/qspace_options.h>
10#include <molpro/linalg/itsolv/rspace_options.h>
11#include <molpro/linalg/itsolv/subspace/SubspaceSolverLinEig.h>
12#include <molpro/linalg/itsolv/subspace/XSpace.h>
34template <
template <
class,
class,
class>
class Solver,
class R,
class Q,
class P>
38 using typename SolverTemplate::value_type;
39 using typename SolverTemplate::value_type_abs;
68 auto m_prof = prof->push(
"itsolv::end_iteration");
76 const auto nparam = std::min(parameters.size(),
this->n_roots());
84 prof->start(
"end_iteration (propose_rspace)");
96 size_t end_iteration(std::vector<R>& parameters, std::vector<R>& action)
override {
133 auto xspace = std::dynamic_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace);
162 if (
opt.reset_D_max_Q_size)
164 if (
opt.max_size_qspace)
166 if (
opt.min_size_qspace)
168 if (
opt.contrib_thresh)
179 template <
class SolverOptions>
181 auto opt = std::make_shared<SolverOptions>();
197 throw std::invalid_argument(
"minimum size of the Q space (" + std::to_string(
min_size) +
198 ") exceeds its maximum size (" + std::to_string(
max_size) +
")");
208 virtual std::vector<value_type>
values()
const = 0;
Class, containing a collection of array handlers used in IterativeSolver Provides a Builder sub-class...
Definition ArrayHandlers.h:25
Implementation shared by the linear Davidson solvers, LinearEigensystemDavidson and LinearEquationsDa...
Definition DavidsonCommon.h:35
DavidsonCommon(const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers, const std::shared_ptr< Logger > &logger, bool hermiticity)
Definition DavidsonCommon.h:141
void set_norm_thresh(value_type_abs thresh)
Set threshold on the norm of parameters that should be considered null.
Definition DavidsonCommon.h:105
bool nonlinear() const override
Definition DavidsonCommon.h:41
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 i...
Definition DavidsonCommon.h:201
void set_hermiticity(bool hermitian) override
Definition DavidsonCommon.h:131
detail::DSpaceResetter< Q > m_dspace_resetter
resets D space
Definition DavidsonCommon.h:222
size_t end_iteration(const VecRef< R > ¶meters, const VecRef< R > &action) override
Proposes new parameters for the subspace from the preconditioned residuals.
Definition DavidsonCommon.h:66
void set_max_size_qspace(std::size_t n)
Definition DavidsonCommon.h:119
void set_value_errors() override
Implementation class should overload this to set errors in the current values (e.g....
Definition DavidsonCommon.h:210
bool m_resetting_in_progress
whether D space resetting is in progress
Definition DavidsonCommon.h:225
value_type_abs get_norm_thresh() const
Definition DavidsonCommon.h:106
size_t end_iteration(std::vector< R > ¶meters, std::vector< R > &action) override
Proposes new parameters for the subspace from the preconditioned residuals.
Definition DavidsonCommon.h:96
void set_davidson_options(const Options &options, const DavidsonOptions &opt)
Sets the general options and those of the Davidson solvers, after checking them.
Definition DavidsonCommon.h:155
std::shared_ptr< SolverOptions > get_davidson_options() const
Returns the general options and those of the Davidson solvers in an options object of type SolverOpti...
Definition DavidsonCommon.h:180
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.
Definition DavidsonCommon.h:125
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.
Definition DavidsonCommon.h:195
size_t get_reset_D_maxQ_size() const
Definition DavidsonCommon.h:116
virtual std::vector< value_type > values() const =0
The values of the current solutions, whose changes between iterations are the value errors.
size_t end_iteration(R ¶meters, R &actions) override
Proposes new parameters for the subspace from the preconditioned residuals.
Definition DavidsonCommon.h:100
void set_reset_D(size_t n)
Set the period in iterations for resetting the D space, 0 for never.
Definition DavidsonCommon.h:112
value_type_abs get_svd_thresh() const
Definition DavidsonCommon.h:110
std::size_t get_min_size_qspace() const
Definition DavidsonCommon.h:129
QSpaceOptions qspace_opts
Options concerning Q-space handling.
Definition DavidsonCommon.h:221
std::vector< value_type > m_last_values
the values from the previous iteration
Definition DavidsonCommon.h:224
RSpaceOptions< value_type_abs > rspace_opts
Options concerning R-space handling.
Definition DavidsonCommon.h:220
void set_svd_thresh(value_type_abs thresh)
Definition DavidsonCommon.h:109
bool get_hermiticity() const override
Definition DavidsonCommon.h:138
std::size_t get_max_size_qspace() const
Definition DavidsonCommon.h:123
bool m_hermiticity
whether the problem is hermitian or not
Definition DavidsonCommon.h:223
size_t get_reset_D() const
Definition DavidsonCommon.h:113
void set_reset_D_maxQ_size(size_t n)
Set the maximum size of Q space after resetting the D space.
Definition DavidsonCommon.h:115
Implements IterativeSolver interface that is common to all solvers.
Definition IterativeSolverTemplate.h:187
std::vector< value_type_abs > m_value_errors
value errors from the most recent solution
Definition IterativeSolverTemplate.h:1213
std::vector< int > m_working_set
indices of roots in the working set
Definition IterativeSolverTemplate.h:1214
std::shared_ptr< subspace::IXSpace< R, Q, P > > m_xspace
manages the subspace and associated data
Definition IterativeSolverTemplate.h:1210
std::vector< scalar_type > current_values() const
The values reported in the iteration events: eigenvalues of eigensystems, the function value otherwis...
Definition IterativeSolverTemplate.h:437
std::shared_ptr< ArrayHandlers< R, Q, P > > m_handlers
Array handlers.
Definition IterativeSolverTemplate.h:1209
std::shared_ptr< subspace::ISubspaceSolver< R, Q, P > > m_subspace_solver
solves the subspace problem
Definition IterativeSolverTemplate.h:1211
std::shared_ptr< Options > get_options() const override
Definition IterativeSolverTemplate.h:341
bool m_solutions_outdated
whether the subspace was changed since the solutions of its problem were found
Definition IterativeSolverTemplate.h:1237
const std::shared_ptr< molpro::profiler::Profiler > & profiler() const override
Definition IterativeSolverTemplate.h:434
bool m_end_iteration_needed
whether end_iteration should be called after any preconditioner
Definition IterativeSolverTemplate.h:1236
const std::vector< int > & working_set() const override
Definition IterativeSolverTemplate.h:314
std::shared_ptr< Logger > m_logger
logger
Definition IterativeSolverTemplate.h:1220
void set_options(const Options &options) override
Definition IterativeSolverTemplate.h:324
std::shared_ptr< Statistics > m_stats
accumulates statistics of operations performed by the solver
Definition IterativeSolverTemplate.h:1219
Logger & logger() override
Definition IterativeSolverTemplate.h:210
Resets D space constructing full solutions as the new working set, removing instabilities from Q spac...
Definition DSpaceResetter.h:92
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:671
4-parameter interpolation of a 1-dimensional function given two points for which function values and ...
Definition helper.h:14
auto wrap_arg(T &&arg, S &&... args) -> std::enable_if_t< std::conjunction_v< std::is_same< decay_t< T >, decay_t< S > >... >, VecRef< decay_t< T > > >
Constructs a vector of reference wrappers with provided arguments.
Definition wrap.h:135
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< 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 DavidsonOptions.h:11
Access point for different options in iterative solvers.
Definition Options.h:20
Information about performance of IterativeSolver instance.
Definition Statistics.h:10