1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_DSPACERESETTER_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_DSPACERESETTER_H
3#include <molpro/linalg/itsolv/IterativeSolver.h>
4#include <molpro/linalg/itsolv/propose_rspace.h>
5#include <molpro/linalg/itsolv/qspace_options.h>
6#include <molpro/linalg/itsolv/subspace/Dimensions.h>
7#include <molpro/linalg/itsolv/subspace/IXSpace.h>
8#include <molpro/linalg/itsolv/subspace/QSpace.h>
9#include <molpro/linalg/itsolv/subspace/gram_schmidt.h>
10#include <molpro/linalg/itsolv/subspace/util.h>
11#include <molpro/linalg/itsolv/util.h>
18template <
class R,
class Q,
class P,
typename value_type>
21 logger.
trace(
"resize_qspace()");
36template <
class R,
class Q>
39 logger.
trace(
"max_overlap_with_R()");
46 auto ov = std::vector<typename array::ArrayHandler<R, Q>::value_type_abs>{};
48 ov.push_back(std::abs(overlap(
i,
j)));
49 auto it_max = std::max_element(
ov.begin(),
ov.end());
52 ", with overlap = " + std::to_string(*
it_max));
76 std::size_t
m_nreset = std::numeric_limits<std::size_t>::max();
78 std::numeric_limits<std::size_t>::max();
96 template <
class R,
class P,
typename value_type,
typename value_type_abs>
100 logger.
trace(
"DSpaceResetter::run()");
105 logger.
debug(
"constructing solutions");
118 for (
size_t i = 0;
i <
nC; ++
i)
120 auto roots = std::vector<int>(
nC);
129 for (
size_t i = 0;
i <
nR; ++
i) {
Enhances various operations between pairs of arrays and allows dynamic code injection with uniform in...
Definition ArrayHandler.h:163
Class, containing a collection of array handlers used in IterativeSolver Provides a Builder sub-class...
Definition ArrayHandlers.h:25
void debug(std::string_view message, Ts &&...args) const
Definition Logger.h:500
void trace(std::string_view message, Ts &&...args) const
Definition Logger.h:495
Resets D space constructing full solutions as the new working set, removing instabilities from Q spac...
Definition DSpaceResetter.h:74
std::size_t m_max_Qsize_after_reset
maximum size of Q space after reset
Definition DSpaceResetter.h:77
DSpaceResetter(std::size_t nreset, std::size_t max_Qsize)
Definition DSpaceResetter.h:83
auto get_nreset() const
Definition DSpaceResetter.h:91
bool do_reset(size_t iter, const subspace::Dimensions &dims)
Whether reset operation should be run.
Definition DSpaceResetter.h:86
std::list< Q > solution_params
all current solutions that will be moved to the Q space
Definition DSpaceResetter.h:79
void set_max_Qsize(size_t i)
Definition DSpaceResetter.h:92
std::vector< int > run(const VecRef< R > &rparams, subspace::IXSpace< R, Q, P > &xspace, const subspace::Matrix< value_type > &solutions, const value_type_abs norm_thresh, const value_type_abs svd_thresh, ArrayHandlers< R, Q, P > &handlers, Logger &logger)
Run the reset operation.
Definition DSpaceResetter.h:97
std::size_t m_nreset
reset D space every n iterations
Definition DSpaceResetter.h:76
void set_nreset(size_t i)
Definition DSpaceResetter.h:90
auto get_max_Qsize() const
Definition DSpaceResetter.h:93
Full subspace.
Definition IXSpace.h:19
SubspaceData< value_type > data
Equation data in the subspace.
Definition IXSpace.h:28
virtual CVecRef< Q > cparamsq() const =0
virtual void eraseq(size_t i)=0
Removes parameter i from Q subspace.
virtual CVecRef< Q > cparamsd() const =0
virtual const Dimensions & dimensions() const =0
virtual void update_dspace(VecRef< Q > ¶ms, VecRef< Q > &actions)=0
Updates D space with the new parameters.
Matrix container that allows simple data access, slicing, copying and resizing without loosing data.
Definition Matrix.h:32
auto construct_projected_solution(const subspace::Matrix< value_type > &solutions, const subspace::Dimensions &dims, const std::vector< std::size_t > &remove_qspace, Logger &logger)
Projects solution from the full subspace on to Q_{delete} and current D space.
Definition propose_rspace.h:60
auto construct_projected_solutions_overlap(const subspace::Matrix< value_type > &solutions_proj, const subspace::Matrix< value_type > &overlap, const subspace::Dimensions &dims, const std::vector< std::size_t > &remove_qspace, Logger &logger)
Constructs overlap matrix for projected solutions.
Definition propose_rspace.h:93
auto remove_null_projected_solutions(const subspace::Matrix< value_type > &solutions_proj, const subspace::Matrix< value_type > &overlap_proj, const value_type_abs svd_thresh, Logger &logger)
Transforms to a stable subspace of projected solutions via SVD.
Definition propose_rspace.h:176
void remove_null_norm_and_normalise(subspace::Matrix< value_type > ¶meters, subspace::Matrix< value_type > &overlap, const value_type_abs norm_thresh, Logger &logger)
Removes parameters with norm less than threshold and normalises the rest.
Definition propose_rspace.h:137
Definition helper-dispatch.h:140
auto max_overlap_with_R(const CVecRef< R > &rparams, const CVecRef< Q > &qparams, array::ArrayHandler< R, Q > &handler, Logger &logger)
Returns list of Q indices with maximum overlap to R parameters, sorted in descending order.
Definition DSpaceResetter.h:37
void resize_qspace(subspace::IXSpace< R, Q, P > &xspace, const subspace::Matrix< value_type > &solutions, std::size_t max_size, Logger &logger)
Removes Q parameters that have smallest contribution to any solution until Q space size is within lim...
Definition DSpaceResetter.h:19
std::vector< std::size_t > limit_qspace_size(const subspace::Dimensions &dims, const QSpaceOptions &opts, const subspace::Matrix< value_type > &solutions, Logger &logger)
Ensures that size Q space is within limit by proposing Q parameters for deletion.
Definition propose_rspace.h:326
auto overlap(const CVecRef< R > &left, const CVecRef< Q > &right, array::ArrayHandler< Z, W > &handler) -> std::enable_if_t< detail::Z_and_W_are_one_of_R_and_Q< R, Q, Z, W >, Matrix< typename array::ArrayHandler< Z, W >::value_type > >
Calculates overlap matrix between left and right vectors.
Definition util.h:52
Q construct_zeroed_copy(const R ¶m, array::ArrayHandler< Q, R > &handler)
Copy R parameter to Q and zero it. This ensures same size and distribution of the copy.
Definition util.h:48
void construct_solutions(const VecRef< R > ¶ms, const std::vector< int > &roots, const subspace::Matrix< value_type > &solutions, const CVecRef< P > &pparams, const CVecRef< Q > &qparams, const CVecRef< Q > &dparams, size_t oP, size_t oQ, size_t oD, array::ArrayHandler< R, R > &handler_rr, array::ArrayHandler< R, P > &handler_rp, array::ArrayHandler< R, Q > &handler_rq)
Construct solutions.
Definition util.h:70
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
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
Definition Dimensions.h:9
size_t nD
Definition Dimensions.h:14
size_t nQ
Definition Dimensions.h:13
size_t nP
Definition Dimensions.h:12