35 const Eigen::VectorXd& gwaenergies,
57 use(
Mmn_[m_level].bottomRows(n_unocc));
64 const Index skip = std::min(
Mmn_.ExcludedHoles(), n_occ);
68 [&weights, skip](
Index m, Eigen::VectorXd& w) { weights(m + skip, w); },
77 const double freq2 = frequency * frequency;
79 Eigen::MatrixXd result =
81 const Eigen::ArrayXd deltaE =
84 denom = 4 * deltaE / (deltaE.square() + freq2);
86 Eigen::ArrayXd deltEf = deltaE - frequency;
87 Eigen::ArrayXd sum = deltEf / (deltEf.square() + eta2);
88 deltEf = deltaE + frequency;
89 sum += deltEf / (deltEf.square() + eta2);
93 result.diagonal().array() += 1.0;
94 if (
Mmn_.HasAdditionalResponse()) {
95 result +=
Mmn_.AdditionalResponse(imag, frequency);
97 if (
Mmn_.AdditionalPoleCount() > 0) {
99 const Eigen::ArrayXd& W =
Mmn_.AdditionalPoleEnergies().array();
102 w = 4 * W / (W.square() + freq2);
104 w = 2 * ((W - frequency) / ((W - frequency).square() + eta2) +
105 (W + frequency) / ((W + frequency).square() + eta2));
107 const Eigen::MatrixXd C =
Mmn_.AdditionalPoleVectors();
108 result.noalias() += C * w.matrix().asDiagonal() * C.transpose();
117 if (
Mmn_.HasAdditionalResponse()) {
118 throw std::runtime_error(
119 "RPA: an additional response (inactive_screening with the "
120 "plasmon-pole model) is only available at the plasmon-pole fitting "
121 "points, not for complex frequencies (sigma_integrator cda).");
124 const double sigma_1 = std::pow(frequency.imag() +
eta_, 2);
125 const double sigma_2 = std::pow(frequency.imag() -
eta_, 2);
126 Eigen::MatrixXd result =
128 const Eigen::ArrayXd deltaE =
130 const Eigen::ArrayXd deltaEm = frequency.real() - deltaE;
131 const Eigen::ArrayXd deltaEp = frequency.real() + deltaE;
133 chi = -2.0 * (deltaEm * (deltaEm.abs2() + sigma_1).inverse() -
134 deltaEp * (deltaEp.abs2() + sigma_2).inverse());
136 if (
Mmn_.AdditionalPoleCount() > 0) {
137 const Eigen::ArrayXd W =
Mmn_.AdditionalPoleEnergies().array();
138 const Eigen::ArrayXd deltaEm = frequency.real() - W;
139 const Eigen::ArrayXd deltaEp = frequency.real() + W;
140 const Eigen::VectorXd chi =
141 -2.0 * (deltaEm * (deltaEm.square() + sigma_1).inverse() -
142 deltaEp * (deltaEp.square() + sigma_2).inverse());
143 const Eigen::MatrixXd C =
Mmn_.AdditionalPoleVectors();
144 result.noalias() += C * chi.asDiagonal() * C.transpose();
146 result.diagonal().array() += 1.0;
154 const Index rpasize = AmB.size();
160 Eigen::MatrixXd& C = ApB;
161 C.applyOnTheLeft(AmB.cwiseSqrt().asDiagonal());
162 C.applyOnTheRight(AmB.cwiseSqrt().asDiagonal());
167 sol.
omega = Eigen::VectorXd::Zero(es.
values.size());
172 std::ostringstream oss;
173 oss <<
TimeStamp() <<
" RKS H2p poles (first 20, eV): ";
174 const Index nprint = std::min<Index>(20, sol.
omega.size());
175 for (
Index i = 0; i < nprint; ++i) {
176 oss << std::fixed << std::setprecision(6)
178 if (i + 1 < nprint) {
186 <<
" Lowest neutral excitation energy (eV): "
197 sol.
XpY = Eigen::MatrixXd(rpasize, rpasize);
199 Eigen::VectorXd AmB_sqrt = AmB.cwiseSqrt();
200 Eigen::VectorXd Omega_sqrt_inv = sol.
omega.cwiseSqrt().cwiseInverse();
201 for (
int s = 0; s < rpasize; s++) {
203 Omega_sqrt_inv(s) * AmB_sqrt.cwiseProduct(es.
vectors.col(s));
214 const Index skip = std::min(
Mmn_.ExcludedHoles(), n_occ);
215 const Index rpasize = (n_occ - skip) * n_unocc;
216 const Index npoles =
Mmn_.AdditionalPoleCount();
218 Eigen::VectorXd AmB = Eigen::VectorXd::Zero(rpasize + npoles);
219 for (
Index v = skip; v < n_occ; v++) {
221 AmB.segment(i, n_unocc) =
224 AmB.tail(npoles) =
Mmn_.AdditionalPoleEnergies();
232 const Index skip = std::min(
Mmn_.ExcludedHoles(), n_occ);
233 const Index rpasize = (n_occ - skip) * n_unocc;
234 const Index npoles =
Mmn_.AdditionalPoleCount();
236 Eigen::MatrixXd ApB =
237 Eigen::MatrixXd::Zero(rpasize + npoles, rpasize + npoles);
238#pragma omp parallel for schedule(guided)
239 for (
Index v2 = skip; v2 < n_occ; v2++) {
241 const Eigen::MatrixXd Mmn_v2T =
242 Mmn_[v2].middleRows(n_occ, n_unocc).transpose();
243 for (
Index v1 = v2; v1 < n_occ; v1++) {
246 ApB.block(i1, i2, n_unocc, n_unocc) =
247 2 * 2 *
Mmn_[v1].middleRows(n_occ, n_unocc) * Mmn_v2T;
252 const Eigen::MatrixXd C =
Mmn_.AdditionalPoleVectors();
253 ApB.bottomRightCorner(npoles, npoles) = 4 * C.transpose() * C;
254#pragma omp parallel for schedule(dynamic)
255 for (
Index v = skip; v < n_occ; v++) {
256 ApB.block(rpasize, vc.
I(v, 0), npoles, n_unocc) =
257 4 * C.transpose() *
Mmn_[v].middleRows(n_occ, n_unocc).transpose();
266 <<
TimeStamp() <<
" Diagonalizing two-particle Hamiltonian "
270 <<
TimeStamp() <<
" Diagonalization done " << std::flush;
271 double minCoeff = es.
values.minCoeff();
272 if (minCoeff <= 0.0) {
274 <<
TimeStamp() <<
" Detected non-positive eigenvalue: " << minCoeff
276 throw std::runtime_error(
"Detected non-positive eigenvalue.");
Eigen::MatrixXd Calculate_H2p_ApB() const
void ShiftUncorrectedEnergies(const Eigen::VectorXd &dftenergies, Index qpmin, Index gwsize)
Eigen::MatrixXd ResponseSum(const WeightedGram::WeightsFn &weights) const
OutOfWindowShift out_of_window_
Eigen::VectorXd energies_
void VisitHoleVirtualRows(Index m_level, const WeightedGram::RowsVisitor &use) const
Eigen::MatrixXd calculate_epsilon(double frequency) const
Eigen::MatrixXd calculate_epsilon_r(double frequency) const
const TCMatrix_gwbse & Mmn_
SymmetricEigenSystem Diagonalize_H2p_C(const Eigen::MatrixXd &C) const
Eigen::VectorXd Calculate_H2p_AmB() const
rpa_eigensolution Diagonalize_H2p() const
void UpdateRPAInputEnergies(const Eigen::VectorXd &dftenergies, const Eigen::VectorXd &gwaenergies, Index qpmin)
Timestamp returns the current time as a string Example: cout << TimeStamp().
std::function< void(Index m, Eigen::VectorXd &w)> WeightsFn
Writes the weights of block m; their number is the number of rows.
std::function< void(const Eigen::Ref< const Eigen::MatrixXd > &)> RowsVisitor
Calls use(R_m); R_m may be a block of stored data or a temporary.
static Eigen::MatrixXd Compute(Index nblocks, Index ncols, const WeightsFn &weights, const RowsFn &rows)
This class transforms a pair of indices v,c into a compound index I, via I=ctotal*v+c the fast dimens...
Index I(Index v, Index c) const
#define XTP_LOG(level, log)
Charge transport classes.
SymmetricEigenSystem SymmetricEigen(const Eigen::MatrixXd &A, bool vectors=true)
With vectors = false only the eigenvalues are computed.
Provides a means for comparing floating point numbers.