37 const Eigen::MatrixXd& mos,
40 const Index qptotal = qpmax - qpmin + 1;
41 Eigen::MatrixXd X = Eigen::MatrixXd::Zero(qptotal, qptotal);
42 if (ncore <= 0 || qptotal <= 0) {
49 Mc.
Fill(auxbasis, dftbasis, mos);
50 Eigen::MatrixXd Z(qptotal, Mc.
auxsize());
51 for (
Index c = 0; c < ncore; ++c) {
52 for (
Index m = 0; m < qptotal; ++m) {
53 Z.row(m) = Mc[m].row(c);
55 X.selfadjointView<Eigen::Upper>().rankUpdate(Z, -1.0);
57 return X.selfadjointView<Eigen::Upper>();
76#pragma omp parallel for schedule(dynamic, 4)
96#pragma omp parallel for schedule(dynamic)
100 if (matrix.rows() != matrix.cols()) {
111 if (U.rows() != U.cols()) {
115 const Index lead_rows = std::clamp<Index>(lead, 0,
nsize());
116 const Index lead_slices = std::clamp<Index>(lead, 0,
msize());
117 full_slices = std::clamp<Index>(full_slices, 0, lead_slices);
118#pragma omp parallel for schedule(dynamic)
119 for (
Index i = 0; i < lead_slices; i++) {
123 const Index rows = (i < full_slices) ?
nsize() : lead_rows;
124 Eigen::MatrixXd rotated =
matrix_[i].topRows(rows) * U;
125 matrix_[i].topRows(rows) = rotated;
130 if (full_slices <
msize() && (lead_slices <
msize() || lead_rows <
nsize())) {
150 throw std::runtime_error(
151 "TCMatrix_gwbse: cannot dress the auxiliary index after only part of "
152 "the tensor was rotated (MultiplyRightWithAuxMatrixLeading). Rebuild "
156 throw std::runtime_error(
157 "TCMatrix_gwbse: cannot dress the auxiliary index after a non-square "
158 "MultiplyRightWithAuxMatrix. Rebuild first.");
165 const Eigen::PartialPivLU<Eigen::MatrixXd> lu(
aux_frame_);
171 throw std::runtime_error(
172 "TCMatrix_gwbse::DressAuxIndex: already dressed. Undress first.");
175 throw std::runtime_error(
176 "TCMatrix_gwbse::DressAuxIndex: S is " + std::to_string(
S.rows()) +
177 "x" + std::to_string(
S.cols()) +
", auxiliary basis has " +
193 double frequency)
const {
195 if (p.imaginary == imaginary && std::abs(p.frequency - frequency) <=
196 1
e-12 * (1.0 + std::abs(frequency))) {
198 throw std::runtime_error(
199 "TCMatrix_gwbse::AdditionalResponse: the auxiliary frame is not "
200 "known (non-square MultiplyRightWithAuxMatrix).");
208 throw std::runtime_error(
209 "TCMatrix_gwbse: an additional response (e.g. inactive_screening with "
210 "the plasmon-pole model) is set, but not at " +
211 std::string(imaginary ?
"imaginary" :
"real") +
" frequency " +
212 std::to_string(frequency) +
213 " Ha; only the plasmon-pole fitting points are supported.");
218 throw std::runtime_error(
219 "TCMatrix_gwbse::AdditionalPoleVectors: the auxiliary frame is not "
220 "known (non-square MultiplyRightWithAuxMatrix).");
229 const Eigen::MatrixXd& K)
const {
231 throw std::runtime_error(
232 "TCMatrix_gwbse::ToCurrentAuxFrame: the auxiliary index of the "
233 "three-centre integrals was multiplied by a non-square matrix, so "
234 "there is no frame to bring the kernel into. Apply it before that, "
241 throw std::runtime_error(
242 "TCMatrix_gwbse::ToCurrentAuxFrame: kernel is " +
243 std::to_string(K.rows()) +
"x" + std::to_string(K.cols()) +
244 ", auxiliary frame is " + std::to_string(
aux_frame_.rows()) +
"x" +
248 const double off_orthogonal =
252 Eigen::MatrixXd result;
253 if (off_orthogonal < 1
e-10) {
256 const Eigen::PartialPivLU<Eigen::MatrixXd> lu(
aux_frame_);
257 const Eigen::MatrixXd X = lu.solve(K);
258 result = lu.solve(Eigen::MatrixXd(X.transpose())).transpose();
269 const Eigen::MatrixXd& dft_orbitals) {
275 Fill3cMO(auxbasis, dftbasis, dft_orbitals);
278 auxoverlap.
Fill(auxbasis);
280 auxcoulomb.
Fill(auxbasis);
294 const Eigen::MatrixXd& dft_orbitals,
295 const Eigen::MatrixXd& inv_sqrt) {
299 Fill3cMO(auxbasis, dftbasis, dft_orbitals);
310 const Index window = last - first + 1;
313 assert(U.rows() == window && U.cols() == window);
321 const Eigen::MatrixXd Ut = U.transpose();
322#pragma omp parallel for schedule(dynamic)
327 auto block =
matrix_[m].middleRows(row0, window);
333 const Index chunk = std::max<Index>(
334 1, std::min<Index>(aux,
Index(8e6 /
double(rows * window + 1))));
337 for (
Index c0 = 0; c0 < aux; c0 += chunk) {
338 const Index nc = std::min(chunk, aux - c0);
339 const Index len = rows * nc;
340 X.resize(len, window);
341#pragma omp parallel for
342 for (
Index k = 0; k < window; k++) {
343 X.col(k) = Eigen::Map<const Eigen::VectorXd>(
344 matrix_[slice0 + k].col(c0).data(), len);
347#pragma omp parallel for
348 for (
Index i = 0; i < window; i++) {
349 Eigen::Map<Eigen::VectorXd>(
matrix_[slice0 + i].col(c0).data(), len) =
356 const std::vector<std::vector<Index>>& kept) {
362 for (
Index a = 0; a <
Index(kept.size()); ++a) {
363 const Index start = shell2bf[a];
366 const Index mu = start + i;
371 Index b_first = kept[a][k];
372 Index b_last = b_first;
373 while (k + 1 <
Index(kept[a].
size()) && kept[a][k + 1] == b_last + 1) {
378 const Index row = shell2bf[b_first];
379 const Index end = std::min(
381 runs_.push_back({mu, row, end - row, offset});
390 const double* src =
data_.col(
P).data();
392 std::copy(src + r.offset, src + r.offset + r.length,
395 full.triangularView<Eigen::StrictlyLower>() = full.transpose();
406 Eigen::VectorXd packed(
data_.rows());
408 for (
Index k = 0; k < r.length; ++k) {
409 const Index row = r.row + k;
410 packed(r.offset + k) =
411 (row == r.col) ? full(r.col, row) : 2.0 * full(r.col, row);
418 assert(packed.size() ==
data_.rows());
421 full.block(r.row, r.col, r.length, 1) = packed.segment(r.offset, r.length);
423 full.triangularView<Eigen::StrictlyLower>() = full.transpose();
Container to hold Basisfunctions for all atoms.
Index AOBasisSize() const
std::vector< Index > getMapToBasisFunctions() const
const AOShell & getShell(Index idx) const
void Fill(const AOBasis &aobasis) final
Index Removedfunctions() const
Eigen::MatrixXd Pseudo_InvSqrt_GWBSE(const AOOverlap &auxoverlap, double etol)
void Fill(const AOBasis &aobasis) final
std::vector< Index > col_offset_
Index size() const
Number of aux functions.
Eigen::VectorXd PackWeighted(const Eigen::MatrixXd &full) const
Eigen::MatrixXd FullMatrix(Index P) const
B_P as a full symmetric matrix, zero for the dropped pairs.
void SetupLayout(const AOBasis &dftbasis, const std::vector< std::vector< Index > > &kept)
void FillFullMatrix(Index P, Eigen::MatrixXd &full) const
Eigen::MatrixXd Unpack(const Eigen::VectorXd &packed) const
void Fill(const AOBasis &auxbasis, const AOBasis &dftbasis, const Eigen::MatrixXd &dft_orbitals)
const AOBasis * auxbasis_
static constexpr double metric_tolerance
void DressAuxIndex(const Eigen::MatrixXd &S)
Dress the auxiliary index with S: M_fill -> M_fill S.
std::vector< ResponsePoint > additional_response_
Eigen::MatrixXd AdditionalResponse(bool imaginary, double frequency) const
F^T Y F at this frequency, in the frame operator[] is in now.
void MultiplyRightWithAuxMatrixLeading(const Eigen::MatrixXd &U, Index full_slices, Index lead)
Rotate the auxiliary index of only the part of the tensor a consumer reads: all rows of slices [0,...
Eigen::MatrixXd pole_vectors_
Eigen::MatrixXd aux_frame_
Eigen::MatrixXd dressing_
const Eigen::MatrixXd * dft_orbitals_
bool AuxFrameIsOrthogonal() const
void Fill3cMO(const AOBasis &auxbasis, const AOBasis &dftbasis, const Eigen::MatrixXd &dft_orbitals)
void Initialize(Index basissize, Index mmin, Index mmax, Index nmin, Index nmax)
void MultiplyRightWithAuxMatrix(const Eigen::MatrixXd &matrix)
Eigen::MatrixXd AdditionalPoleVectors() const
The pole vectors in the frame operator[] is in now: F^T c_k.
std::vector< Eigen::MatrixXd > matrix_
void setExcludedHoles(Index k)
The first k occupied slices (levels rpamin .. rpamin+k-1) are left out of the RPA response sums,...
static Eigen::MatrixXd CoreExchange(const AOBasis &auxbasis, const AOBasis &dftbasis, const Eigen::MatrixXd &mos, Index ncore, Index qpmin, Index qpmax)
void RotateOrbitals(const Eigen::MatrixXd &U, Index first, Index last)
Change the orbital basis of levels [first, last] for QSGW: phi_i = sum_k U_ki psi_k,...
const AOBasis * dftbasis_
void MultiplyInFillFrame(const Eigen::MatrixXd &A)
Eigen::MatrixXd ToCurrentAuxFrame(const Eigen::MatrixXd &K) const
Eigen::MatrixXd inv_sqrt_
Charge transport classes.
Provides a means for comparing floating point numbers.
A response the RPA adds to its own sum over these integrals, epsilon(w) = 1 + X[M](w) + F^T Y(w) F,...