1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_SUBSPACESOLVERLINEIG_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_SUBSPACE_SUBSPACESOLVERLINEIG_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#include <molpro/linalg/itsolv/helper.h>
18template <
class RT,
class QT,
class PT>
30 m_logger->trace(
"SubspaceSolverLinEig::solve");
55 m_logger->trace(
"SubspaceSolverLinEig::solve_eigenvalue");
63 auto evec = std::vector<value_type>{};
90 auto [
first,
last] = std::ranges::remove_if(
94 m_logger->info(
"Complex eigenvalue pair split up due to truncation to requested number of roots");
100 m_errors.assign(
size(), std::numeric_limits<value_type_abs>::max());
103 m_logger->info(
"The following eigenvalues turned out to be complex-valued: ",
105 std::ranges::views::transform([](
const auto&
pair) {
return pair.first + 1; }));
106 m_logger->data_dump(
"imaginary parts of eigenvalues = ",
116 m_logger->trace(
"SubspaceSolverLinEig::solve_linear_equations");
123 const auto dim =
h.rows();
125 auto solution = std::vector<value_type>{};
134 m_errors.assign(
size(), std::numeric_limits<value_type_abs>::max());
142 void set_error(
const std::vector<int>& roots,
const std::vector<value_type_abs>&
errors)
override {
143 for (
size_t i = 0;
i < roots.size(); ++
i)
Full subspace.
Definition IXSpace.h:21
SubspaceData< value_type > data
Equation data in the subspace.
Definition IXSpace.h:30
virtual MetricKind metric_kind() const =0
The kind of metric declared with set_metric()
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 clear()
Clears all elements and sets dimensions to 0.
Definition Matrix.h:81
bool empty() const
Returns true if matrix is empty.
Definition Matrix.h:78
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 linear eigenvalues and system of linear equations.
Definition SubspaceSolverLinEig.h:19
value_type_abs get_augmented_hessian()
Definition SubspaceSolverLinEig.h:181
value_type_abs m_augmented_hessian
value of augmented hessian parameter. If 0, than augmented Hessian is not used
Definition SubspaceSolverLinEig.h:198
std::vector< value_type_abs > m_errors
errors in subspace solutions
Definition SubspaceSolverLinEig.h:189
std::optional< std::size_t > complex_partner(std::size_t root) const
The other member of the complex conjugate eigenvalue pair that root belongs to, if any.
Definition SubspaceSolverLinEig.h:154
typename ISubspaceSolver< RT, QT, PT >::value_type_abs value_type_abs
Definition SubspaceSolverLinEig.h:22
void set_error(const std::vector< int > &roots, const std::vector< value_type_abs > &errors) override
Update errors for a group of roots.
Definition SubspaceSolverLinEig.h:142
void set_logger(std::shared_ptr< Logger > logger) override
Definition SubspaceSolverLinEig.h:173
void set_error(int root, value_type_abs error) override
Set error value for solution root
Definition SubspaceSolverLinEig.h:141
void solve_eigenvalue(IXSpace< R, Q, P > &xspace, const size_t nroots_max)
Definition SubspaceSolverLinEig.h:54
std::map< std::size_t, std::size_t > m_complex_partners
root -> other member of its complex pair
Definition SubspaceSolverLinEig.h:187
value_type_abs m_svd_solver_threshold
threshold to select null space during SVD in eigenproblem, rescaled from double to the working precis...
Definition SubspaceSolverLinEig.h:194
std::vector< value_type > m_eigenvalues
eigenvalues
Definition SubspaceSolverLinEig.h:185
bool get_hermiticity()
Definition SubspaceSolverLinEig.h:178
typename ISubspaceSolver< RT, QT, PT >::Q Q
Definition SubspaceSolverLinEig.h:24
Matrix< value_type > m_solutions
solution matrix with row vectors
Definition SubspaceSolverLinEig.h:184
std::shared_ptr< Logger > m_logger
Definition SubspaceSolverLinEig.h:190
const std::vector< value_type > & eigenvalues() const override
Access eigenvalues from the last solve() call.
Definition SubspaceSolverLinEig.h:148
std::vector< std::pair< std::size_t, value_type > > m_imag_eigval_comps
eigenvalues
Definition SubspaceSolverLinEig.h:186
void set_augmented_hessian(value_type_abs parameter)
Set value of augmented hessian parameter. If 0, than augmented Hessian is not used.
Definition SubspaceSolverLinEig.h:180
const Matrix< value_type > & retained_solutions() const override
The solutions, followed by the complex partner of the last root if that partner was truncated away.
Definition SubspaceSolverLinEig.h:165
typename ISubspaceSolver< RT, QT, PT >::value_type value_type
Definition SubspaceSolverLinEig.h:21
typename ISubspaceSolver< RT, QT, PT >::P P
Definition SubspaceSolverLinEig.h:25
void solve(IXSpace< R, Q, P > &xspace, const size_t nroots_max) override
Solve the subspace problem.
Definition SubspaceSolverLinEig.h:29
const std::vector< std::pair< std::size_t, value_type > > & imag_eigval_components() const
Definition SubspaceSolverLinEig.h:149
void set_hermiticity(bool hermitian)
Set Hermiticity of the subspace.
Definition SubspaceSolverLinEig.h:177
const std::vector< value_type_abs > & errors() const override
Access errors corresponding to each solution.
Definition SubspaceSolverLinEig.h:168
int convert_verbosity(log::Verbosity verbosity)
Definition SubspaceSolverLinEig.h:39
SubspaceSolverLinEig(std::shared_ptr< Logger > logger)
Definition SubspaceSolverLinEig.h:27
void solve_linear_equations(IXSpace< R, Q, P > &xspace)
Definition SubspaceSolverLinEig.h:115
const Matrix< value_type > & solutions() const override
Access solutions from the last solve() call.
Definition SubspaceSolverLinEig.h:147
Matrix< value_type > m_retained_solutions
solutions and truncated partner of the last root, empty without one
Definition SubspaceSolverLinEig.h:188
typename ISubspaceSolver< RT, QT, PT >::R R
Definition SubspaceSolverLinEig.h:23
bool m_hermitian
Definition SubspaceSolverLinEig.h:196
size_t size() const override
Number of solutions.
Definition SubspaceSolverLinEig.h:171
Verbosity
Different levels of logging.
Definition Logger.h:63
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
void solve_LinearEquations(std::vector< value_type > &solution, std::vector< value_type > &eigenvalues, const std::vector< value_type > &matrix, const std::vector< value_type > &metric, const std::vector< value_type > &rhs, size_t dimension, size_t nroot, real_type_t< value_type > augmented_hessian, real_type_t< value_type > svdThreshold, int verbosity)
Definition helper-implementation.h:844
@ Identity
M = 1, i.e. no metric.
void eigenproblem(std::vector< value_type > &eigenvectors, std::vector< value_type > &eigenvalues, const std::vector< value_type > &matrix, const std::vector< value_type > &metric, size_t dimension, bool hermitian, real_type_t< value_type > svdThreshold, int verbosity, std::vector< std::pair< std::size_t, value_type > > *imag_eval_parts=nullptr, size_t nroots=std::numeric_limits< size_t >::max())
Definition helper-implementation.h:431
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