votca 2026-dev
Loading...
Searching...
No Matches
sigma_cda.cc
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#include "sigma_cda.h"
21#include "scaled_erfc.h"
22#include "votca/xtp/gw.h"
24
25namespace votca {
26namespace xtp {
27
28// Prepares the zero and imaginary frequency kappa matrices with
29// kappa(omega) = epsilon^-1(omega) - 1 needed in numerical
30// integration and for the Gaussian tail
33 opt.homo = opt_.homo;
34 opt.order = opt_.order;
35 opt.qptotal = qptotal_;
36 opt.qpmin = opt_.qpmin;
37 opt.rpamax = opt_.rpamax;
38 opt.rpamin = opt_.rpamin;
39 opt.alpha = opt_.alpha;
40 opt.quadrature_scheme = opt_.quadrature_scheme;
41 // prepare the zero frequency inverse for Gaussian tail
42 // epsilon at zero frequency is positive definite
44 InverseSPD(rpa_.calculate_epsilon_r(std::complex<double>(0.0, 0.0)));
45 kDielMxInv_zero_.diagonal().array() -= 1.0;
46 gq_.configure(opt, rpa_, kDielMxInv_zero_);
47
48 tail_terms_.assign(std::size_t(qptotal_), Eigen::VectorXd());
49 const Index offset = opt_.qpmin - opt_.rpamin;
50#pragma omp parallel for schedule(dynamic)
51 for (Index level = 0; level < qptotal_; level++) {
52 tail_terms_[std::size_t(level)] =
55 }
56}
57
58// This function is used in the calculation of the residues and
59// calculates the real part of the dielectric function for a complex
60// frequency of the kind omega = delta + i*eta. Instead of explicit
61// inversion and multiplication with and Imx vector, a linear system
62// is solved.
64 const Eigen::MatrixXd::ConstRowXpr& Imx_row, double delta,
65 double eta) const {
66 std::complex<double> delta_eta(delta, eta);
67
68 Eigen::MatrixXd DielMxInv = rpa_.calculate_epsilon_r(delta_eta);
69 Eigen::VectorXd x =
70 DielMxInv.partialPivLu().solve(Imx_row.transpose()) - Imx_row.transpose();
71 return x.dot(Imx_row.transpose());
72}
73
74// Step-function prefactor for the residues
75double Sigma_CDA::CalcResiduePrefactor(double e_f, double e_m,
76 double frequency) const {
77 double factor = 0.0;
78 double tolerance = 1e-10;
79 if (e_f < e_m && e_m < frequency) {
80 factor = 1.0;
81 } else if (e_f > e_m && e_m > frequency) {
82 factor = -1.0;
83 } else if (std::abs(e_m - frequency) < tolerance && e_f > e_m) {
84 factor = -0.5;
85 } else if (std::abs(e_m - frequency) < tolerance && e_f < e_m) {
86 factor = 0.5;
87 }
88 return factor;
89}
90
91// Calculates the contribution of residues to the correlation
92// part of the self-energy of a fixed gw_level
93double Sigma_CDA::CalcResidueContribution(double frequency,
94 Index gw_level) const {
95
96 const Eigen::VectorXd& rpa_energies = rpa_.getRPAInputEnergies();
97 Index rpatotal = rpa_energies.size();
98 Index gw_level_offset = gw_level + opt_.qpmin - opt_.rpamin;
99
100 double sigma_c = 0.0;
101 double sigma_c_tail = 0.0;
102 Index homo = opt_.homo - opt_.rpamin;
103 Index lumo = homo + 1;
104 double fermi_rpa = (rpa_energies(lumo) + rpa_energies(homo)) / 2.0;
105 const Eigen::MatrixXd& Imx = Mmn_[gw_level_offset];
106
107 for (Index i = 0; i < rpatotal; ++i) {
108 double delta = rpa_energies(i) - frequency;
109 double abs_delta = std::abs(delta);
110 double factor = CalcResiduePrefactor(fermi_rpa, rpa_energies(i), frequency);
111
112 // Only considering the terms with a abs(prefactor) > 0.
113 // The prefactor can be 1,-1,0.5,-0.5 or 0. We avoid calculating the
114 // diagonal contribution if the prefactor is 0. We want to calculate it for
115 // all the other cases.
116 if (std::abs(factor) > 1e-10) {
117 sigma_c +=
118 factor * CalcDiagContribution(Imx.row(i), abs_delta, rpa_.getEta());
119 }
120 // adds the contribution from the Gaussian tail
121 if (abs_delta > 1e-10) {
122 sigma_c_tail += CalcDiagContributionValue_tail(
123 tail_terms_[std::size_t(gw_level)](i), delta, opt_.alpha);
124 }
125 }
126 return sigma_c + sigma_c_tail;
127}
128
129// Calculates the correlation part of the self-energy for a fixed
130// gw_level and frequence by evaluating the numerical integration
131// and residue contributions
133 double frequency) const {
135 double sigma_c_residue = CalcResidueContribution(frequency, gw_level);
136 double sigma_c_integral = gq_.SigmaGQDiag(frequency, gw_level, rpa_.getEta());
137 return sigma_c_residue + sigma_c_integral;
138}
139
140// Calculates the contribuion of the tail correction to the
141// residue term
142double Sigma_CDA::CalcDiagContributionValue_tail(double row_term, double delta,
143 double alpha) const {
144
145 double erfc_factor =
146 0.5 * std::copysign(1.0, delta) * ScaledErfc(std::abs(alpha * delta));
147
148 return row_term * erfc_factor;
149}
150
151} // namespace xtp
152} // 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 CalcDiagContribution(const Eigen::MatrixXd::ConstRowXpr &Imx_row, double delta, double eta) const
Definition sigma_cda.cc:63
double CalcCorrelationDiagElement(Index gw_level, double frequency) const final
Definition sigma_cda.cc:132
ImaginaryAxisIntegration gq_
Definition sigma_cda.h:86
double CalcResidueContribution(double frequency, Index gw_level) const
Definition sigma_cda.cc:93
std::vector< Eigen::VectorXd > tail_terms_
Definition sigma_cda.h:89
double CalcDiagContributionValue_tail(double row_term, double delta, double alpha) const
Definition sigma_cda.cc:142
double CalcResiduePrefactor(double e_f, double e_m, double frequency) const
Definition sigma_cda.cc:75
void PrepareScreening() final
Definition sigma_cda.cc:31
Eigen::MatrixXd kDielMxInv_zero_
Definition sigma_cda.h:87
TCMatrix_gwbse & Mmn_
Definition sigma_base.h:207
void CountDiagEval() const
Definition sigma_base.h:221
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