iterative-solver 0.0
 
Loading...
Searching...
No Matches
SubspaceSolverOptSD.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_SUBSPACESOLVEROPTSD_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_SUBSPACESOLVEROPTSD_H
3#include <molpro/linalg/itsolv/subspace/ISubspaceSolver.h>
4#include <molpro/linalg/itsolv/subspace/IXSpace.h>
5#include <molpro/linalg/itsolv/subspace/Matrix.h>
6#include <molpro/linalg/itsolv/Logger.h>
7
8#include <memory>
9
11
15template <class RT, class QT, class PT>
16class SubspaceSolverOptSD : public ISubspaceSolver<RT, QT, PT> {
17public:
23
24 explicit SubspaceSolverOptSD(std::shared_ptr<Logger> logger) : m_logger(std::move(logger)) {}
25
26 void solve(IXSpace<R, Q, P>& xspace, const size_t nroots_max) override {
27 m_logger->trace("SubspaceSolverOptSD::solve");
28 assert(xspace.data.end() != xspace.data.find(EqnData::value));
29 auto values = xspace.data[EqnData::value];
30 assert(xspace.size() == values.size());
31
32 auto kH = xspace.data[EqnData::H];
33 auto kS = xspace.data[EqnData::S];
34 auto kValue = xspace.data[EqnData::value];
35 m_logger->data_dump("S = ", kS);
36 m_logger->data_dump<15>("H = ", kH);
37 m_logger->data_dump<15>("value = ", kValue);
38 auto kDim = kH.rows();
39 // int kVerbosity = m_logger->max_trace_level == Logger::Info ? 3 : 0;
41 if (kDim == 0) {
42 m_errors.clear();
43 return;
44 }
45 m_solutions.slice().fill(0);
46 m_solutions(0, 0) = 1;
47 m_errors.assign(1, std::abs(kH(0, 0)));
48 m_logger->data_dump("solution = ", m_solutions);
49 }
50
51public:
53 void set_error(int root, value_type_abs error) override { m_errors.at(root) = error; }
54 void set_error(const std::vector<int>& roots, const std::vector<value_type_abs>& errors) override {
55 for (size_t i = 0; i < roots.size(); ++i)
57 }
58
59 const Matrix<value_type>& solutions() const override { return m_solutions; }
60 const std::vector<value_type>& eigenvalues() const override {
61 throw std::logic_error("eigenvalues() not available in non-linear method");
62 }
63 const std::vector<value_type_abs>& errors() const override { return m_errors; }
64
66 size_t size() const override { return m_solutions.rows(); }
67
68 void set_logger(std::shared_ptr<Logger> logger) override { m_logger = std::move(logger); }
69
70protected:
72 std::vector<value_type_abs> m_errors;
73 std::shared_ptr<Logger> m_logger{};
74
75public:
78};
79
80} // namespace molpro::linalg::itsolv::subspace
81
82#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_SUBSPACESOLVEROPTSD_H
Full subspace.
Definition IXSpace.h:19
SubspaceData< value_type > data
Equation data in the subspace.
Definition IXSpace.h:28
size_t size() const
Number of vectors forming the subspace.
Definition IXSpace.h:31
Matrix container that allows simple data access, slicing, copying and resizing without loosing data.
Definition Matrix.h:32
Slice slice(coord_type upper_left, coord_type bottom_right)
Access a rectangular slice of the matrix.
Definition Matrix.h:101
void resize(const coord_type &dims)
Resize the matrix. The old data is preserved and any new rows/cols are zeroed.
Definition Matrix.h:130
index_type rows() const
Definition Matrix.h:169
Solves subspace problem for minimisation using the Steepest Descent algorithm.
Definition SubspaceSolverOptSD.h:16
typename ISubspaceSolver< RT, QT, PT >::Q Q
Definition SubspaceSolverOptSD.h:21
void set_logger(std::shared_ptr< Logger > logger) override
Definition SubspaceSolverOptSD.h:68
std::shared_ptr< Logger > m_logger
Definition SubspaceSolverOptSD.h:73
void set_error(const std::vector< int > &roots, const std::vector< value_type_abs > &errors) override
Update errors for a group of roots.
Definition SubspaceSolverOptSD.h:54
typename ISubspaceSolver< RT, QT, PT >::P P
Definition SubspaceSolverOptSD.h:22
void set_error(int root, value_type_abs error) override
Set error value for solution root
Definition SubspaceSolverOptSD.h:53
const std::vector< value_type_abs > & errors() const override
Access errors corresponding to each solution.
Definition SubspaceSolverOptSD.h:63
value_type_abs m_svd_solver_threshold
threshold to select null space during SVD in eigenproblem, rescaled from double to the working precis...
Definition SubspaceSolverOptSD.h:77
typename ISubspaceSolver< RT, QT, PT >::value_type_abs value_type_abs
Definition SubspaceSolverOptSD.h:19
typename ISubspaceSolver< RT, QT, PT >::value_type value_type
Definition SubspaceSolverOptSD.h:18
void solve(IXSpace< R, Q, P > &xspace, const size_t nroots_max) override
Solve the subspace problem.
Definition SubspaceSolverOptSD.h:26
typename ISubspaceSolver< RT, QT, PT >::R R
Definition SubspaceSolverOptSD.h:20
SubspaceSolverOptSD(std::shared_ptr< Logger > logger)
Definition SubspaceSolverOptSD.h:24
Matrix< value_type > m_solutions
solution matrix with row vectors
Definition SubspaceSolverOptSD.h:71
size_t size() const override
Number of solutions.
Definition SubspaceSolverOptSD.h:66
std::vector< value_type_abs > m_errors
errors in subspace solutions
Definition SubspaceSolverOptSD.h:72
const Matrix< value_type > & solutions() const override
Access solutions from the last solve() call.
Definition SubspaceSolverOptSD.h:59
const std::vector< value_type > & eigenvalues() const override
Access eigenvalues from the last solve() call.
Definition SubspaceSolverOptSD.h:60
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
Manages solution of the subspace problem and storage of those solutions.
Definition ISubspaceSolver.h:21
typename array::ArrayHandler< R, R >::value_type value_type
Definition ISubspaceSolver.h:25
typename array::ArrayHandler< R, R >::value_type_abs value_type_abs
Definition ISubspaceSolver.h:26
PT P
Definition ISubspaceSolver.h:24
QT Q
Definition ISubspaceSolver.h:23
RT R
Definition ISubspaceSolver.h:22