votca 2026-dev
Loading...
Searching...
No Matches
bse_operator_kernels.h
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#pragma once
21#ifndef VOTCA_XTP_BSE_OPERATOR_KERNELS_H
22#define VOTCA_XTP_BSE_OPERATOR_KERNELS_H
23
24// Local VOTCA includes
25#include "eigen.h"
26#include "threecenter.h"
27
28namespace votca {
29namespace xtp {
30
41
46inline Eigen::MatrixXd ApplyBSEExchange(
47 const TCMatrix_gwbse& Mout, const BSEWindow& out, const TCMatrix_gwbse& Min,
48 const BSEWindow& in, const Eigen::MatrixXd& x, double prefactor) {
49 const Index auxsize = Min.auxsize();
50 const Index k = x.cols();
51 // B = sum_v2 M_in[v2]_c^T x_v2, accumulated per thread
52 Eigen::MatrixXd B = Eigen::MatrixXd::Zero(auxsize, k);
53#pragma omp parallel
54 {
55 Eigen::MatrixXd B_thread = Eigen::MatrixXd::Zero(auxsize, k);
56#pragma omp for schedule(dynamic)
57 for (Index v2 = 0; v2 < in.vtotal; ++v2) {
58 B_thread.noalias() +=
59 Min[v2 + in.vmin].middleRows(in.cmin, in.ctotal).transpose() *
60 x.middleRows(v2 * in.ctotal, in.ctotal);
61 }
62#pragma omp critical
63 B += B_thread;
64 }
65 Eigen::MatrixXd y(out.size(), k);
66#pragma omp parallel for schedule(dynamic)
67 for (Index v1 = 0; v1 < out.vtotal; ++v1) {
68 y.middleRows(v1 * out.ctotal, out.ctotal).noalias() =
69 prefactor * Mout[v1 + out.vmin].middleRows(out.cmin, out.ctotal) * B;
70 }
71 return y;
72}
73
79inline Eigen::MatrixXd ApplyBSEQuasiparticle(const Eigen::MatrixXd& Hqp,
80 Index vtotal, Index ctotal,
81 const Eigen::MatrixXd& x,
82 double prefactor) {
83 const Eigen::MatrixXd Hvv = Hqp.topLeftCorner(vtotal, vtotal);
84 const Eigen::MatrixXd Hcc = Hqp.block(vtotal, vtotal, ctotal, ctotal);
85 Eigen::MatrixXd y(x.rows(), x.cols());
86 // all columns at once for Hcc: x as ctotal x (vtotal * k)
87 Eigen::Map<const Eigen::MatrixXd> X_all(x.data(), ctotal, vtotal * x.cols());
88 Eigen::Map<Eigen::MatrixXd> Y_all(y.data(), ctotal, vtotal * x.cols());
89 Y_all.noalias() = prefactor * Hcc * X_all;
90 for (Index col = 0; col < x.cols(); ++col) {
91 Eigen::Map<const Eigen::MatrixXd> X(x.col(col).data(), ctotal, vtotal);
92 Eigen::Map<Eigen::MatrixXd> Y(y.col(col).data(), ctotal, vtotal);
93 Y.noalias() -= prefactor * X * Hvv;
94 }
95 return y;
96}
97
98} // namespace xtp
99} // namespace votca
100
101#endif // VOTCA_XTP_BSE_OPERATOR_KERNELS_H
Eigen::MatrixXd ApplyBSEExchange(const TCMatrix_gwbse &Mout, const BSEWindow &out, const TCMatrix_gwbse &Min, const BSEWindow &in, const Eigen::MatrixXd &x, double prefactor)
Eigen::MatrixXd ApplyBSEQuasiparticle(const Eigen::MatrixXd &Hqp, Index vtotal, Index ctotal, const Eigen::MatrixXd &x, double prefactor)
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26