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/DavidsonCommon.h>
5#include <molpro/linalg/itsolv/IterativeSolverTemplate.h>
6#include <molpro/linalg/itsolv/subspace/SubspaceSolverLinEig.h>
7#include <molpro/linalg/itsolv/subspace/XSpace.h>
40template <
class R,
class Q = R,
class P = std::map<
size_t,
typename R::value_type>>
45 using typename SolverTemplate::value_type;
46 using typename SolverTemplate::value_type_abs;
49 const std::shared_ptr<Logger>&
logger_ = std::make_shared<Logger>())
53 auto prof = this->
profiler()->push(
"itsolv::add_equations");
54 auto xspace = std::static_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace);
55 xspace->add_rhs_equations(
rhs);
63 auto xspace = std::static_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace);
81 if (
opt.augmented_hessian)
94 cout <<
", errors " << std::scientific;
96 std::copy(begin(
err), end(
err), std::ostream_iterator<value_type_abs>(
cout,
", "));
110 std::vector<value_type>
values()
const override {
115 auto chi = std::vector<value_type>(std::min(solutions.rows(),
rhs.cols()), value_type{0});
116 for (
size_t i = 0;
i <
chi.size(); ++
i)
117 for (
size_t k = 0;
k < std::min(solutions.cols(),
rhs.rows()); ++
k)
125 assert(params.size() >= roots.size());
126 const auto& norm = std::dynamic_pointer_cast<subspace::XSpace<R, Q, P>>(this->
m_xspace)->rhs_norm();
130 for (
size_t i = 0;
i < roots.size(); ++
i) {
131 const auto ii = roots[
i];
133 if (
size_t(
ii) < eigenvalues.size()
and eigenvalues[
ii] != value_type(0))
134 this->
m_handlers->rr().axpy(-eigenvalues[
ii], params.at(
i), actions.at(
i));
135 if (norm.at(
ii) != 0) {
136 auto scal = 1 / norm[
ii];
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
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
Implements IterativeSolver interface that is common to all solvers.
Definition IterativeSolverTemplate.h:187
std::shared_ptr< subspace::IXSpace< R, Q, P > > m_xspace
manages the subspace and associated data
Definition IterativeSolverTemplate.h:1210
void set_n_roots(size_t roots) override
Definition IterativeSolverTemplate.h:318
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::vector< value_type_abs > m_errors
errors from the most recent solution
Definition IterativeSolverTemplate.h:1212
const std::shared_ptr< molpro::profiler::Profiler > & profiler() const override
Definition IterativeSolverTemplate.h:434
void report() const override
Definition IterativeSolverTemplate.h:384
Solves a system of linear equation, A x = b.
Definition LinearEquationsDavidson.h:41
void add_equations(const std::vector< R > &rhs) override
Definition LinearEquationsDavidson.h:60
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 ei...
Definition LinearEquationsDavidson.h:110
void add_equations(const CVecRef< R > &rhs) override
Definition LinearEquationsDavidson.h:52
std::shared_ptr< Options > get_options() const override
Definition LinearEquationsDavidson.h:85
LinearEquationsDavidson(const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers, const std::shared_ptr< Logger > &logger_=std::make_shared< Logger >())
Definition LinearEquationsDavidson.h:48
void add_equations(const R &rhs) override
Definition LinearEquationsDavidson.h:59
void set_options(const Options &options) override
Definition LinearEquationsDavidson.h:78
CVecRef< Q > rhs() const override
Definition LinearEquationsDavidson.h:62
void construct_residual(const std::vector< int > &roots, const CVecRef< R > ¶ms, const VecRef< R > &actions, const detail::MetricSolutions< R, Q > &metric_solutions) override
Constructs residual for given roots provided their parameters and actions.
Definition LinearEquationsDavidson.h:123
void report(std::ostream &cout, bool endl=true) const override
Definition LinearEquationsDavidson.h:91
void prepare_solve(const Problem< R > &problem, const VecRef< R > &actions) override
Adds the right-hand sides provided by problem.
Definition LinearEquationsDavidson.h:103
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:68
value_type_abs get_augmented_hessian() const
Definition LinearEquationsDavidson.h:73
Definition IterativeSolver.h:782
Abstract class defining the problem-specific interface for the simplified solver interface to Iterati...
Definition IterativeSolver.h:125
virtual bool RHS(R &RHS, unsigned int instance) const
Return the inhomogeneous part of a linear equation system.
Definition IterativeSolver.h:265
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
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
The actions of a metric applied on the fly on solutions, in R vectors or, if there are not enough of ...
Definition IterativeSolverTemplate.h:40