votca 2026-dev
Loading...
Searching...
No Matches
bse.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20#pragma once
21#ifndef VOTCA_XTP_BSE_H
22#define VOTCA_XTP_BSE_H
23
24// Standard includes
25#include <memory>
26
27// Local VOTCA includes
28#include "logger.h"
29#include "orbitals.h"
30#include "qmstate.h"
31#include "screening_kernels.h"
32#include "threecenter.h"
33
34namespace votca {
35namespace xtp {
36class SymmetricTiles;
37struct BSE_Population;
38template <Index cqp, Index cx, Index cd, Index cd2>
39class BSE_OPERATOR;
42template <class T>
43class QMFragment;
44
45class BSE {
46
47 public:
48 // BSE(Logger& log, TCMatrix_gwbse& Mmn, const Eigen::MatrixXd& Hqp_in)
49 // : log_(log), Mmn_(Mmn), Hqp_in_(Hqp_in){};
50 BSE(Logger& log, TCMatrix_gwbse& Mmn) : log_(log), Mmn_(Mmn) {};
51
52 struct options {
53 bool useTDA;
61 Index nmax; // number of eigenvectors to calculat
63 std::string davidson_tolerance;
64 std::string davidson_update;
66 double min_print_weight; // minimium contribution for state to print it
70 };
71
72 void configure(const options& opt, const Eigen::VectorXd& RPAEnergies,
73 const Eigen::MatrixXd& Hqp_in);
74
98 void setReactionField(const Eigen::MatrixXd& R, bool include_kreac);
99
100 // <K_reac> of each singlet in es to first order, 2 (X+Y)^T K_reac (X+Y):
101 // its linear-response environment shift, whether or not K_reac is in the
102 // kernel. Needs a reaction field.
103 Eigen::VectorXd ReactionFieldExchange(const tools::EigenSystem& es,
104 bool tda) const;
105
107 const options& opt, const Eigen::VectorXd& RPAEnergies,
108 const Eigen::MatrixXd& Hqp_in, const Eigen::VectorXd& epsilon_0_inv);
109
110 void Solve_singlets(Orbitals& orb) const;
111 void Solve_triplets(Orbitals& orb) const;
112
113 Eigen::MatrixXd getHqp() const { return Hqp_; };
114
117
118 void Analyze_singlets(std::vector<QMFragment<BSE_Population>> fragments,
119 const Orbitals& orb) const;
120 void Analyze_triplets(std::vector<QMFragment<BSE_Population>> fragments,
121 const Orbitals& orb) const;
122
124
127 static void setStateMatrixMemory(double bytes) {
128 state_matrix_bytes_ = bytes;
129 }
130
131 private:
133
134 struct Interaction {
135 Eigen::VectorXd exchange_contrib;
136 Eigen::VectorXd direct_contrib;
137 Eigen::VectorXd qp_contrib;
138 };
139
141 Eigen::VectorXd direct_term;
142 Eigen::VectorXd cross_term;
143 };
144
145 static double state_matrix_bytes_;
146
153
156
157 Eigen::VectorXd epsilon_0_inv_;
158
160 Eigen::MatrixXd Hqp_;
161
162 Eigen::MatrixXd reaction_field_; // R, fill-time aux frame; empty: off
163 Eigen::MatrixXd dressing_; // (1 + R)^(1/2)
164 bool include_kreac_ = true;
165
168
171
172 void PrintWeights(const Eigen::VectorXd& weights) const;
173
174 template <typename BSE_OPERATOR>
176 BSE_OPERATOR& H, std::shared_ptr<SymmetricTiles> cache = nullptr) const;
177
178 // The screened direct terms Hd and Hd2 kept as symmetric matrices (lower
179 // triangle) for all operators of this BSE that contain them: the singlet
180 // and triplet solves and the analysis. Null if not kept. Decided from the
181 // memory budget the first time a solve needs them, then reused; dropped
182 // when the screening changes.
184 std::shared_ptr<SymmetricTiles> hd;
185 std::shared_ptr<SymmetricTiles> hd2;
186 bool hd_decided = false;
187 bool hd2_decided = false;
188 };
190 // Decides (and logs) whether Hd (and, with coupling, Hd2) are kept.
191 void DecideDirectCaches(bool coupling) const;
192 void ReleaseDirectCaches() const;
193
194 template <typename BSE_OPERATOR>
196
197 template <typename BSE_OPERATOR_ApB, typename BSE_OPERATOR_AmB>
199 BSE_OPERATOR_AmB&) const;
200
201 template <typename BSE_OPERATOR_A, typename BSE_OPERATOR_B>
203 BSE_OPERATOR_B& Bop) const;
204
205 void printFragInfo(const std::vector<QMFragment<BSE_Population>>& frags,
206 Index state) const;
207 void printWeights(Index i_bse, double weight) const;
208 void RotateIntoScreeningFrame(const Eigen::MatrixXd& U);
211 const Eigen::VectorXd& RPAInputEnergies, double energy,
212 DFTTimings& timings) const;
213 Eigen::MatrixXd DirectTermDensity(
214 const std::vector<std::pair<const Eigen::VectorXd*,
215 const Eigen::VectorXd*>>& pairs) const;
216 Eigen::MatrixXd CouplingTermDensity(const Eigen::VectorXd& Avec,
217 const Eigen::VectorXd& Bvec) const;
218 void SetupDirectInteractionOperator(const Eigen::VectorXd& DFTenergies,
219 double energy);
220
221 Eigen::MatrixXd AdjustHqpSize(const Eigen::MatrixXd& Hqp_in,
222 const Eigen::VectorXd& RPAInputEnergies);
223
225 const Orbitals& orb) const;
226 template <typename BSE_OPERATOR>
228 const Orbitals& orb,
229 const BSE_OPERATOR& H) const;
230
232 Orbitals& orb) const;
234 const Orbitals& orb) const;
235
236 std::string StateEnergiesHeader(const QMStateType& type) const;
237 std::string StateShortLabel(const QMStateType& type) const;
238 std::string StateDynamicLabel(const QMStateType& type) const;
239 double ExchangePrefactor(const QMStateType& type) const;
240};
241} // namespace xtp
242} // namespace votca
243
244#endif // VOTCA_XTP_BSE_H
void setReactionField(const Eigen::MatrixXd &R, bool include_kreac)
Screen by a static polarizable environment (embedded BSE).
Definition bse.cc:209
void Solve_singlets(Orbitals &orb) const
Definition bse.cc:368
BSE(Logger &log, TCMatrix_gwbse &Mmn)
Definition bse.h:50
Eigen::MatrixXd getHqp() const
Definition bse.h:113
static double state_matrix_bytes_
Definition bse.h:145
DirectCaches direct_caches_
Definition bse.h:189
void DecideDirectCaches(bool coupling) const
Definition bse.cc:305
void printFragInfo(const std::vector< QMFragment< BSE_Population > > &frags, Index state) const
Definition bse.cc:574
void PrintWeights(const Eigen::VectorXd &weights) const
Definition bse.cc:590
void printWeights(Index i_bse, double weight) const
std::string StateDynamicLabel(const QMStateType &type) const
Definition bse.cc:146
double dyn_tolerance_
Definition bse.h:155
void configure_with_precomputed_screening(const options &opt, const Eigen::VectorXd &RPAEnergies, const Eigen::MatrixXd &Hqp_in, const Eigen::VectorXd &epsilon_0_inv)
Definition bse.cc:81
void Analyze_singlets(std::vector< QMFragment< BSE_Population > > fragments, const Orbitals &orb) const
Definition bse.cc:606
Eigen::MatrixXd DirectTermDensity(const std::vector< std::pair< const Eigen::VectorXd *, const Eigen::VectorXd * > > &pairs) const
Definition bse.cc:835
tools::EigenSystem Solve_triplets_BTDA() const
Definition bse.cc:499
Eigen::VectorXd ReactionFieldExchange(const tools::EigenSystem &es, bool tda) const
Definition bse.cc:397
TripletOperator_TDA getTripletOperator_TDA() const
Definition bse.cc:452
void MatchDressingToRoute()
Definition bse.cc:225
SingletOperator_TDA getSingletOperator_TDA() const
Definition bse.cc:445
options opt_
Definition bse.h:132
tools::EigenSystem Solve_singlets_BTDA() const
Definition bse.cc:488
Index bse_vmax_
Definition bse.h:148
Index bse_cmin_
Definition bse.h:149
void Perturbative_DynamicalScreening(const QMStateType &type, Orbitals &orb)
Definition bse.cc:934
void Analyze_triplets(std::vector< QMFragment< BSE_Population > > fragments, const Orbitals &orb) const
Definition bse.cc:665
void SetupDirectInteractionOperator(const Eigen::VectorXd &DFTenergies, double energy)
Definition bse.cc:274
void configure(const options &opt, const Eigen::VectorXd &RPAEnergies, const Eigen::MatrixXd &Hqp_in)
Definition bse.cc:63
Eigen::MatrixXd Hqp_
Definition bse.h:160
tools::EigenSystem & GetBSEEigenSystem(const QMStateType &type, Orbitals &orb) const
Definition bse.cc:101
Eigen::VectorXd epsilon_0_inv_
Definition bse.h:157
SymmetricEigenSystem ScreenedInteraction(const Eigen::VectorXd &RPAInputEnergies, double energy, DFTTimings &timings) const
Definition bse.cc:242
void configureBSEOperator(BSE_OPERATOR &H, std::shared_ptr< SymmetricTiles > cache=nullptr) const
Definition bse.cc:291
ExpectationValues ExpectationValue_Operator(const QMStateType &type, const Orbitals &orb, const BSE_OPERATOR &H) const
Definition bse.cc:718
Interaction Analyze_eh_interaction(const QMStateType &type, const Orbitals &orb) const
Definition bse.cc:762
Index bse_ctotal_
Definition bse.h:152
static void setStateMatrixMemory(double bytes)
Definition bse.h:127
double ExchangePrefactor(const QMStateType &type) const
Definition bse.cc:157
TCMatrix_gwbse & Mmn_
Definition bse.h:159
void RotateIntoScreeningFrame(const Eigen::MatrixXd &U)
Definition bse.cc:219
Index bse_size_
Definition bse.h:150
tools::EigenSystem Solve_singlets_TDA() const
Definition bse.cc:435
Eigen::MatrixXd reaction_field_
Definition bse.h:162
bool include_kreac_
Definition bse.h:164
Index max_dyn_iter_
Definition bse.h:154
tools::EigenSystem solve_hermitian(BSE_OPERATOR &h) const
Definition bse.cc:460
tools::EigenSystem Solve_nonhermitian(BSE_OPERATOR_ApB &apb, BSE_OPERATOR_AmB &) const
void Solve_triplets(Orbitals &orb) const
Definition bse.cc:426
Logger & log_
Definition bse.h:147
void ReleaseDirectCaches() const
Definition bse.cc:303
tools::EigenSystem Solve_nonhermitian_Davidson(BSE_OPERATOR_A &Aop, BSE_OPERATOR_B &Bop) const
Definition bse.cc:511
Eigen::MatrixXd AdjustHqpSize(const Eigen::MatrixXd &Hqp_in, const Eigen::VectorXd &RPAInputEnergies)
Definition bse.cc:168
Eigen::MatrixXd CouplingTermDensity(const Eigen::VectorXd &Avec, const Eigen::VectorXd &Bvec) const
Definition bse.cc:884
Index bse_vtotal_
Definition bse.h:151
std::string StateShortLabel(const QMStateType &type) const
Definition bse.cc:136
tools::EigenSystem Solve_triplets_TDA() const
Definition bse.cc:360
Eigen::MatrixXd dressing_
Definition bse.h:163
std::string StateEnergiesHeader(const QMStateType &type) const
Definition bse.cc:125
Wall-clock accounting for the parts of a DFT run.
Definition dfttimings.h:45
Logger is used for thread-safe output of messages.
Definition logger.h:164
Container for molecular orbitals and derived one-particle data.
Definition orbitals.h:47
BSE_OPERATOR< 1, 2, 1, 0 > SingletOperator_TDA
Definition bse.h:40
BSE_OPERATOR< 1, 0, 1, 0 > TripletOperator_TDA
Definition bse.h:41
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
std::shared_ptr< SymmetricTiles > hd2
Definition bse.h:185
std::shared_ptr< SymmetricTiles > hd
Definition bse.h:184
Eigen::VectorXd direct_term
Definition bse.h:141
Eigen::VectorXd cross_term
Definition bse.h:142
Eigen::VectorXd qp_contrib
Definition bse.h:137
Eigen::VectorXd exchange_contrib
Definition bse.h:135
Eigen::VectorXd direct_contrib
Definition bse.h:136
std::string davidson_tolerance
Definition bse.h:63
std::string davidson_update
Definition bse.h:64
double min_print_weight
Definition bse.h:66
std::string davidson_correction
Definition bse.h:62