votca 2026-dev
Loading...
Searching...
No Matches
rpa_uks.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2021 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_RPA_UKS_H
22#define VOTCA_XTP_RPA_UKS_H
23
24#include <complex>
25#include <vector>
26
27#include "eigen.h"
28#include "logger.h"
29#include "out_of_window_shift.h"
30#include "screening_kernels.h"
32
33namespace votca {
34namespace xtp {
35
70class RPA_UKS {
71 public:
79 RPA_UKS(Logger& log, const TCMatrix_gwbse_spin& Mmn) : log_(log), Mmn_(Mmn) {}
80
95 out_of_window_ = shift;
96 }
97
98 void configure(Index homo_alpha, Index homo_beta, Index rpamin,
99 Index rpamax) {
100 homo_alpha_ = homo_alpha;
101 homo_beta_ = homo_beta;
102 rpamin_ = rpamin;
103 rpamax_ = rpamax;
105 }
106
110 double getEta() const { return eta_; }
111
113 void setTimings(DFTTimings* timings) { timings_ = timings; }
114
121 Eigen::MatrixXd calculate_epsilon_i(double frequency) const {
122 return calculate_epsilon<true>(frequency);
123 }
124
131 Eigen::MatrixXd calculate_epsilon_r(double frequency) const {
132 return calculate_epsilon<false>(frequency);
133 }
134
141 Eigen::MatrixXd calculate_epsilon_r(std::complex<double> frequency) const;
142
150 const Eigen::VectorXd& getRPAInputEnergiesAlpha() const {
151 return energies_alpha_;
152 }
153
157 const Eigen::VectorXd& getRPAInputEnergiesBeta() const {
158 return energies_beta_;
159 }
160
168 void setRPAInputEnergies(const Eigen::VectorXd& rpaenergies_alpha,
169 const Eigen::VectorXd& rpaenergies_beta) {
170 energies_alpha_ = rpaenergies_alpha;
171 energies_beta_ = rpaenergies_beta;
173 }
174
183 void UpdateRPAInputEnergies(const Eigen::VectorXd& dftenergies_alpha,
184 const Eigen::VectorXd& dftenergies_beta,
185 const Eigen::VectorXd& gwaenergies_alpha,
186 const Eigen::VectorXd& gwaenergies_beta,
187 Index qpmin);
188
240
253 Eigen::VectorXd omega;
254 Eigen::MatrixXd XpY;
256 };
257
266 const rpa_eigensolution& Diagonalize_H2p() const;
267
268 Index getHomoAlpha() const { return homo_alpha_; }
269 Index getHomoBeta() const { return homo_beta_; }
270
272 const Eigen::VectorXd*& omegas,
273 const std::vector<Eigen::VectorXd>*& modes) const;
274
275 private:
285 template <bool imag>
286 Eigen::MatrixXd calculate_epsilon(double frequency) const;
287
288 void InvalidateH2pCache();
289
301 Eigen::VectorXd Calculate_H2p_AmB() const;
302
315 Eigen::MatrixXd Calculate_H2p_ApB() const;
316
323 SymmetricEigenSystem Diagonalize_H2p_C(const Eigen::MatrixXd& C) const;
324
332 void ShiftUncorrectedEnergies(Eigen::VectorXd& energies,
333 const Eigen::VectorXd& dftenergies, Index homo,
334 Index qpmin, Index gwsize);
335
337
338 // Spin-resolved HOMO indices in the full orbital numbering
341
342 // Shared orbital window used to build the RPA quantities
345
346 // Small broadening parameter used in real-frequency expressions
347 const double eta_ = 0.0001;
348
349 // Current alpha/beta energies used in the response over [rpamin_, rpamax_]
350 Eigen::VectorXd energies_alpha_;
351 Eigen::VectorXd energies_beta_;
352
354
355 // Spin-resolved three-center integrals:
356 // Mmn_.alpha for alpha MOs, Mmn_.beta for beta MOs
359
360 // weights(beta, v, w): weights of the virtual rows of hole slice v
361 using SpinWeightsFn = std::function<void(bool, Index, Eigen::VectorXd&)>;
362 // sum over both spins and hole slices v of M_v^T diag(w_v) M_v
363 Eigen::MatrixXd ResponseSum(const SpinWeightsFn& weights) const;
364
365 mutable bool h2p_cached_ = false;
367
368 // Cached screening modes (shared across alpha/beta exact GW)
369 mutable bool screening_cached_ = false;
370 mutable Eigen::VectorXd screening_omegas_;
371 mutable std::vector<Eigen::VectorXd> screening_modes_;
372 void BuildCachedScreeningModes() const;
373};
374
375} // namespace xtp
376} // namespace votca
377
378#endif
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
void BuildCachedScreeningModes() const
Definition rpa_uks.cc:90
Eigen::VectorXd screening_omegas_
Definition rpa_uks.h:370
Eigen::VectorXd energies_beta_
Definition rpa_uks.h:351
std::function< void(bool, Index, Eigen::VectorXd &)> SpinWeightsFn
Definition rpa_uks.h:361
Eigen::MatrixXd ResponseSum(const SpinWeightsFn &weights) const
Definition rpa_uks.cc:167
const Eigen::VectorXd & getRPAInputEnergiesBeta() const
Access the current beta RPA input energies used in the response.
Definition rpa_uks.h:157
Eigen::MatrixXd calculate_epsilon_i(double frequency) const
Dielectric matrix on the imaginary frequency axis.
Definition rpa_uks.h:121
const TCMatrix_gwbse_spin & Mmn_
Definition rpa_uks.h:357
Eigen::MatrixXd calculate_epsilon(double frequency) const
Internal implementation of epsilon(w).
Definition rpa_uks.cc:207
Index getHomoBeta() const
Definition rpa_uks.h:269
Index getHomoAlpha() const
Definition rpa_uks.h:268
const double eta_
Definition rpa_uks.h:347
rpa_eigensolution h2p_solution_cache_
Definition rpa_uks.h:366
void InvalidateH2pCache()
Definition rpa_uks.cc:71
std::vector< Eigen::VectorXd > screening_modes_
Definition rpa_uks.h:371
void GetCachedScreeningModes(const Eigen::VectorXd *&omegas, const std::vector< Eigen::VectorXd > *&modes) const
Definition rpa_uks.cc:80
Eigen::VectorXd Calculate_H2p_AmB() const
Construct the diagonal AmB block of the two-particle Hamiltonian.
Definition rpa_uks.cc:324
Eigen::VectorXd energies_alpha_
Definition rpa_uks.h:350
DFTTimings * timings_
Definition rpa_uks.h:358
void setTimings(DFTTimings *timings)
Times the dielectric-matrix builds in these timings (optional).
Definition rpa_uks.h:113
double getEta() const
Small positive broadening used in the real-frequency response.
Definition rpa_uks.h:110
const Eigen::VectorXd & getRPAInputEnergiesAlpha() const
Access the current alpha RPA input energies used in the response.
Definition rpa_uks.h:150
void ShiftUncorrectedEnergies(Eigen::VectorXd &energies, const Eigen::VectorXd &dftenergies, Index homo, Index qpmin, Index gwsize)
Shift uncorrected states outside the GW window.
Definition rpa_uks.cc:161
OutOfWindowShift out_of_window_
Definition rpa_uks.h:336
void setRPAInputEnergies(const Eigen::VectorXd &rpaenergies_alpha, const Eigen::VectorXd &rpaenergies_beta)
Set alpha and beta RPA input energies directly.
Definition rpa_uks.h:168
Eigen::MatrixXd Calculate_H2p_ApB() const
Construct the ApB block of the unrestricted two-particle Hamiltonian.
Definition rpa_uks.cc:363
RPA_UKS(Logger &log, const TCMatrix_gwbse_spin &Mmn)
Definition rpa_uks.h:79
const rpa_eigensolution & Diagonalize_H2p() const
Diagonalize the unrestricted two-particle Hamiltonian.
Definition rpa_uks.cc:268
void configure(Index homo_alpha, Index homo_beta, Index rpamin, Index rpamax)
Definition rpa_uks.h:98
Eigen::MatrixXd calculate_epsilon_r(double frequency) const
Dielectric matrix on the real frequency axis.
Definition rpa_uks.h:131
SymmetricEigenSystem Diagonalize_H2p_C(const Eigen::MatrixXd &C) const
Diagonalize the symmetrized two-particle matrix C.
Definition rpa_uks.cc:459
void UpdateRPAInputEnergies(const Eigen::VectorXd &dftenergies_alpha, const Eigen::VectorXd &dftenergies_beta, const Eigen::VectorXd &gwaenergies_alpha, const Eigen::VectorXd &gwaenergies_beta, Index qpmin)
Update alpha and beta RPA input energies from DFT and GW energies.
Definition rpa_uks.cc:41
void setOutOfWindowShift(const OutOfWindowShift &shift)
Configure orbital window and spin-resolved HOMO indices.
Definition rpa_uks.h:94
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
How the RPA energies of levels outside the GW window are shifted.
Solution of the two-particle Hamiltonian in the unrestricted basis.
Definition rpa_uks.h:252