GQCP
Loading...
Searching...
No Matches
HoppingMatrix.hpp
Go to the documentation of this file.
1// This file is part of GQCG-GQCP.
2//
3// Copyright (C) 2017-2020 the GQCG developers
4//
5// GQCG-GQCP is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GQCG-GQCP is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GQCG-GQCP. If not, see <http://www.gnu.org/licenses/>.
17
18#pragma once
19
20
23
24
25namespace GQCP {
26
27
33template <typename _Scalar>
35public:
36 // The scalar type of the elements of the hopping matrix.
37 using Scalar = _Scalar;
38
39
40private:
41 // The matrix representation of the hopping matrix.
43
44
45public:
46 /*
47 * MARK: Constructors
48 */
49
56 H {H} {
57
58 if (!H.isHermitian()) {
59 throw std::invalid_argument("HoppingMatrix::HoppingMatrix(const SquareMatrix<Scalar>&): The given hopping matrix must be Hermitian.");
60 }
61 }
62
63
64 /*
65 * MARK: Named constructors
66 */
67
75 template <typename Z = Scalar>
76 static enable_if_t<std::is_same<Z, double>::value, HoppingMatrix<double>> Dense(std::vector<double>& triagonal_data) {
77
78 // Map the std::vector<double> into a VectorX<double> to be used into an other constructor
79 GQCP::VectorX<double> upper_triangle = Eigen::Map<Eigen::VectorXd>(triagonal_data.data(), triagonal_data.size());
81 }
82
83
92 template <typename Z = Scalar>
94 return HoppingMatrix {-1 * t * A.matrix().cast<double>()};
95 }
96
97
106 template <typename Z = Scalar>
108 // Generate the hopping (raw)matrix.
109 size_t dim = A.matrix().rows();
111
112 // Check if the dimension of the link vector matches the adjacency matrix.
113 // If the adjacency matrix corressponds to a linear system.
114 if (A.matrix()(0, dim - 1) == 0) {
115 if (link_vector.size() != dim - 1) {
116 throw std::invalid_argument("HoppingMatrix::FromLinkVector(const AdjacencyMatrix& A, std::vector<double>& link_vector): The dimension of the link vector does not match the adjacency matrix.");
117 } else {
118 for (size_t i = 0; i < dim - 1; i++) { // row index
119 H(i, i + 1) = link_vector[i];
120 H(i + 1, i) = link_vector[i];
121 }
122 }
123 }
124 // If the adjacency matrix corresponds to a cyclic system.
125 else if (A.matrix()(0, dim - 1) == 1) {
126 if (link_vector.size() != dim) {
127 throw std::invalid_argument("HoppingMatrix::FromLinkVector(const AdjacencyMatrix& A, std::vector<double>& link_vector): The dimension of the link vector does not match the adjacency matrix.");
128 } else {
129 for (size_t i = 0; i < dim - 1; i++) { // row index
130 H(i, i + 1) = link_vector[i];
131 H(i + 1, i) = link_vector[i];
132 }
133
134 H(0, dim - 1) = link_vector[dim - 1];
135 H(dim - 1, 0) = link_vector[dim - 1];
136 }
137 }
138
139 return HoppingMatrix {H};
140 }
141
142
143 /*
144 * MARK: General information
145 */
146
150 size_t numberOfLatticeSites() const { return this->matrix().dimension(); }
151
152
153 /*
154 * MARK: Access
155 */
156
160 const SquareMatrix<Scalar>& matrix() const { return this->H; }
161
165 SquareMatrix<Scalar>& matrix() { return this->H; }
166};
167
168
169} // namespace GQCP
Definition: AdjacencyMatrix.hpp:30
const SquareMatrix< size_t > & matrix() const
Definition: AdjacencyMatrix.hpp:75
Definition: HoppingMatrix.hpp:34
static enable_if_t< std::is_same< Z, double >::value, HoppingMatrix< double > > Homogeneous(const AdjacencyMatrix &A, const double t)
Definition: HoppingMatrix.hpp:93
static enable_if_t< std::is_same< Z, double >::value, HoppingMatrix< double > > FromLinkVector(const AdjacencyMatrix &A, std::vector< double > &link_vector)
Definition: HoppingMatrix.hpp:107
static enable_if_t< std::is_same< Z, double >::value, HoppingMatrix< double > > Dense(std::vector< double > &triagonal_data)
Definition: HoppingMatrix.hpp:76
const SquareMatrix< Scalar > & matrix() const
Definition: HoppingMatrix.hpp:160
_Scalar Scalar
Definition: HoppingMatrix.hpp:37
HoppingMatrix(const SquareMatrix< Scalar > &H)
Definition: HoppingMatrix.hpp:55
SquareMatrix< Scalar > & matrix()
Definition: HoppingMatrix.hpp:165
size_t numberOfLatticeSites() const
Definition: HoppingMatrix.hpp:150
Definition: Matrix.hpp:47
Definition: SquareMatrix.hpp:39
size_t dimension() const
Definition: SquareMatrix.hpp:299
bool isHermitian(const double threshold=1.0e-08) const
Definition: SquareMatrix.hpp:311
static Self SymmetricFromUpperTriangleWithoutDiagonal(const VectorX< Scalar > &v)
Definition: SquareMatrix.hpp:260
static Self Zero(const size_t dim)
Definition: SquareMatrix.hpp:289
Definition: BaseOneElectronIntegralBuffer.hpp:25
typename std::enable_if< B, T >::type enable_if_t
Definition: type_traits.hpp:37