votca 2024.2-dev
Loading...
Searching...
No Matches
bseoperator_btda.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#ifndef VOTCA_XTP_BSEOPERATOR_BTDA_H
19#define VOTCA_XTP_BSEOPERATOR_BTDA_H
20
21// Local VOTCA includes
22#include "bse_operator.h"
23#include "eigen.h"
24
25namespace votca {
26namespace xtp {
27
28template <typename MatrixReplacementA, typename MatrixReplacementB>
29class HamiltonianOperator;
30}
31} // namespace votca
32namespace Eigen {
33namespace internal {
34
35template <typename MatrixReplacementA, typename MatrixReplacementB>
36struct traits<
37 votca::xtp::HamiltonianOperator<MatrixReplacementA, MatrixReplacementB>>
38 : public Eigen::internal::traits<Eigen::MatrixXd> {};
39} // namespace internal
40} // namespace Eigen
41
42namespace votca {
43namespace xtp {
44template <typename MatrixReplacementA, typename MatrixReplacementB>
46 : public Eigen::EigenBase<
47 HamiltonianOperator<MatrixReplacementA, MatrixReplacementB>> {
48 public:
49 // Required typedefs, constants, and method:
50 using Scalar = double;
51 using RealScalar = double;
53 enum {
54 ColsAtCompileTime = Eigen::Dynamic,
55 MaxColsAtCompileTime = Eigen::Dynamic,
56 IsRowMajor = false
57 };
58
59 HamiltonianOperator(const MatrixReplacementA& A, const MatrixReplacementB& B)
60 : A_(A), B_(B) {
61 size_ = 2 * A.cols();
63 };
64
65 Eigen::Index rows() const { return this->size_; }
66 Eigen::Index cols() const { return this->size_; }
67
68 template <typename Vtype>
69 Eigen::Product<HamiltonianOperator, Vtype, Eigen::AliasFreeProduct> operator*(
70 const Eigen::MatrixBase<Vtype>& x) const {
71 return Eigen::Product<HamiltonianOperator, Vtype, Eigen::AliasFreeProduct>(
72 *this, x.derived());
73 }
74
75 Eigen::VectorXd diagonal() const { return diag_; }
76
77 const MatrixReplacementA& A_;
78 const MatrixReplacementB& B_;
79
80 private:
81 Eigen::VectorXd get_diagonal() const {
82 Eigen::VectorXd diag = Eigen::VectorXd::Zero(size_);
83 Index half = size_ / 2;
84 diag.head(half) = A_.diagonal();
85 diag.tail(half) = -diag.head(half);
86 return diag;
87 }
88
90 Eigen::VectorXd diag_;
91};
92} // namespace xtp
93} // namespace votca
94
95namespace Eigen {
96namespace internal {
97
98// replacement of the mat*mat operation
99template <typename Mtype, typename MatrixReplacementA,
100 typename MatrixReplacementB>
101struct generic_product_impl<
102 votca::xtp::HamiltonianOperator<MatrixReplacementA, MatrixReplacementB>,
103 Mtype, DenseShape, DenseShape, GemmProduct>
104 : generic_product_impl_base<
105 votca::xtp::HamiltonianOperator<MatrixReplacementA,
106 MatrixReplacementB>,
107 Mtype,
108 generic_product_impl<votca::xtp::HamiltonianOperator<
109 MatrixReplacementA, MatrixReplacementB>,
110 Mtype>> {
111
112 typedef typename Product<
114 Mtype>::Scalar Scalar;
115
116 template <typename Dest>
117 static void scaleAndAddTo(Dest& dst,
119 MatrixReplacementA, MatrixReplacementB>& op,
120 const Mtype& m, const Scalar& alpha) {
121 // returns dst = alpha * op * v
122 // alpha must be 1 here
123 assert(alpha == Scalar(1) && "scaling is not implemented");
124 EIGEN_ONLY_USED_FOR_DEBUG(alpha);
125
126 Index half = op.rows() / 2;
136 const Map<const MatrixXd> m_reshaped(m.data(), m.rows() / 2, m.cols() * 2);
137 {
138 const MatrixXd temp = op.A_ * m_reshaped;
139 const Map<const MatrixXd> temp_unshaped(temp.data(), m.rows(), m.cols());
140 dst.topRows(half) = temp_unshaped.topRows(half);
141 dst.bottomRows(half) = -temp_unshaped.bottomRows(half);
142 }
143 {
144 const MatrixXd temp = op.B_ * m_reshaped;
145 const Map<const MatrixXd> temp_unshaped(temp.data(), m.rows(), m.cols());
146 dst.topRows(half) += temp_unshaped.bottomRows(half);
147 dst.bottomRows(half) -= temp_unshaped.topRows(half);
148 }
149 }
150};
151} // namespace internal
152} // namespace Eigen
153
154#endif // VOTCA_XTP_BSEOPERATOR_BTDA_H
const MatrixReplacementA & A_
const MatrixReplacementB & B_
Eigen::Product< HamiltonianOperator, Vtype, Eigen::AliasFreeProduct > operator*(const Eigen::MatrixBase< Vtype > &x) const
Eigen::VectorXd diagonal() const
HamiltonianOperator(const MatrixReplacementA &A, const MatrixReplacementB &B)
Eigen::VectorXd get_diagonal() const
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26
static void scaleAndAddTo(Dest &dst, const votca::xtp::HamiltonianOperator< MatrixReplacementA, MatrixReplacementB > &op, const Mtype &m, const Scalar &alpha)