votca 2026-dev
Loading...
Searching...
No Matches
sigma_cda_uks.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2026 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#include "sigma_cda_uks.h"
21#include "scaled_erfc.h"
22#include "votca/xtp/gw.h"
23
24#include <algorithm>
25#include <iostream>
26#include <limits>
27
28namespace votca {
29namespace xtp {
30
31namespace {
32
33constexpr double kResidueFactorTol = 1e-10;
34constexpr double kCdaWarnMinDelta = 1e-4; // Ha
35constexpr double kCdaWarnKappa = 1e3;
36constexpr double kTiny = 1e-14;
37
38const char* SpinName(TCMatrix::SpinChannel spin) {
39 return (spin == TCMatrix::SpinChannel::Alpha) ? "alpha" : "beta";
40}
41
42} // namespace
43
46 opt.homo = opt_.homo;
47 opt.order = opt_.order;
48 opt.qptotal = qptotal_;
49 opt.qpmin = opt_.qpmin;
50 opt.rpamax = opt_.rpamax;
51 opt.rpamin = opt_.rpamin;
52 opt.alpha = opt_.alpha;
53 opt.quadrature_scheme = opt_.quadrature_scheme;
54
55 // epsilon at zero frequency is positive definite
57 InverseSPD(rpa_.calculate_epsilon_r(std::complex<double>(0.0, 0.0)));
58 kDielMxInv_zero_.diagonal().array() -= 1.0;
59 gq_.configure(opt, rpa_, kDielMxInv_zero_);
60
61 tail_terms_.assign(std::size_t(qptotal_), Eigen::VectorXd());
62 const Index offset = opt_.qpmin - opt_.rpamin;
63#pragma omp parallel for schedule(dynamic)
64 for (Index level = 0; level < qptotal_; level++) {
65 tail_terms_[std::size_t(level)] =
68 }
69}
70
72 const Eigen::MatrixXd::ConstRowXpr& Imx_row, double delta,
73 double eta) const {
74 std::complex<double> delta_eta(delta, eta);
75
76 Eigen::MatrixXd DielMxInv = rpa_.calculate_epsilon_r(delta_eta);
77 Eigen::VectorXd x =
78 DielMxInv.partialPivLu().solve(Imx_row.transpose()) - Imx_row.transpose();
79
80 return x.dot(Imx_row.transpose());
81}
82
83double Sigma_CDA_UKS::CalcResiduePrefactor(double e_f, double e_m,
84 double frequency) const {
85 double factor = 0.0;
86 double tolerance = 1e-10;
87 if (e_f < e_m && e_m < frequency) {
88 factor = 1.0;
89 } else if (e_f > e_m && e_m > frequency) {
90 factor = -1.0;
91 } else if (std::abs(e_m - frequency) < tolerance && e_f > e_m) {
92 factor = -0.5;
93 } else if (std::abs(e_m - frequency) < tolerance && e_f < e_m) {
94 factor = 0.5;
95 }
96 return factor;
97}
98
100 Index gw_level) const {
101 const Eigen::VectorXd& rpa_energies = getSpinRPAInputEnergies();
102 Index rpatotal = rpa_energies.size();
103 Index gw_level_offset = gw_level + opt_.qpmin - opt_.rpamin;
104
105 double sigma_c = 0.0;
106 double sigma_c_tail = 0.0;
107 Index homo = opt_.homo - opt_.rpamin;
108 Index lumo = homo + 1;
109 double fermi_rpa = (rpa_energies(lumo) + rpa_energies(homo)) / 2.0;
110
111 double min_abs_delta = std::numeric_limits<double>::infinity();
112 double sum_abs_contributions = 0.0;
113 double sum_signed_contributions = 0.0;
114
115 const Eigen::MatrixXd& Imx = Mmn_[gw_level_offset];
116
117 for (Index i = 0; i < rpatotal; ++i) {
118 double delta = rpa_energies(i) - frequency;
119 double abs_delta = std::abs(delta);
120 min_abs_delta = std::min(min_abs_delta, abs_delta);
121
122 double factor = CalcResiduePrefactor(fermi_rpa, rpa_energies(i), frequency);
123
124 if (std::abs(factor) > kResidueFactorTol) {
125 double diag = CalcDiagContribution(Imx.row(i), abs_delta, rpa_.getEta());
126 double contribution = factor * diag;
127 sigma_c += contribution;
128
129 sum_abs_contributions += std::abs(contribution);
130 sum_signed_contributions += contribution;
131 }
132
133 if (abs_delta > kResidueFactorTol) {
134 double tail = CalcDiagContributionValue_tail(
135 tail_terms_[std::size_t(gw_level)](i), delta, opt_.alpha);
136 sigma_c_tail += tail;
137 }
138 }
139
140 double kappa =
141 sum_abs_contributions / (std::abs(sum_signed_contributions) + kTiny);
142
143 if (min_abs_delta < kCdaWarnMinDelta || kappa > kCdaWarnKappa) {
144 std::cout << "\nWarning: CDA may be unreliable for " << SpinName(spin_)
145 << " GW level " << (gw_level + opt_.qpmin)
146 << " at omega = " << frequency
147 << " Ha: min |e_m - omega| = " << min_abs_delta
148 << " Ha, cancellation metric = " << kappa << std::flush;
149 }
150
151 return sigma_c + sigma_c_tail;
152}
153
155 double frequency) const {
156 double sigma_c_residue = CalcResidueContribution(frequency, gw_level);
157 double sigma_c_integral = gq_.SigmaGQDiag(frequency, gw_level, rpa_.getEta());
158 return sigma_c_residue + sigma_c_integral;
159}
160
162 double delta,
163 double alpha) const {
164 double erfc_factor =
165 0.5 * std::copysign(1.0, delta) * ScaledErfc(std::abs(alpha * delta));
166
167 return row_term * erfc_factor;
168}
169
170} // namespace xtp
171} // namespace votca
static Eigen::VectorXd RowQuadraticForms(const Eigen::MatrixXd &M, const Eigen::MatrixXd &K)
q(i) = M.row(i) K M.row(i)^T for all rows of M.
double CalcCorrelationDiagElement(Index gw_level, double frequency) const final
double CalcResiduePrefactor(double e_f, double e_m, double frequency) const
double CalcResidueContribution(double frequency, Index gw_level) const
ImaginaryAxisIntegration gq_
Eigen::MatrixXd kDielMxInv_zero_
std::vector< Eigen::VectorXd > tail_terms_
double CalcDiagContribution(const Eigen::MatrixXd::ConstRowXpr &Imx_row, double delta, double eta) const
double CalcDiagContributionValue_tail(double row_term, double delta, double alpha) const
const Eigen::VectorXd & getSpinRPAInputEnergies() const
TCMatrix::SpinChannel spin_
Charge transport classes.
Definition ERIs.h:28
double ScaledErfc(double x)
Definition scaled_erfc.h:33
Eigen::MatrixXd InverseSPD(const Eigen::MatrixXd &A)
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26