pomerol  2.1
Misc.hpp
Go to the documentation of this file.
1 //
2 // This file is part of pomerol, an exact diagonalization library aimed at
3 // solving condensed matter models of interacting fermions.
4 //
5 // Copyright (C) 2016-2024 A. Antipov, I. Krivenko and contributors
6 //
7 // This Source Code Form is subject to the terms of the Mozilla Public
8 // License, v. 2.0. If a copy of the MPL was not distributed with this
9 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
15 
16 #ifndef POMEROL_INCLUDE_POMEROL_MISC_HPP
17 #define POMEROL_INCLUDE_POMEROL_MISC_HPP
18 
19 #include <pomerol/Version.hpp>
20 
21 #include <libcommute/algebra_ids.hpp>
22 #include <libcommute/loperator/loperator.hpp>
23 #include <libcommute/loperator/state_vector.hpp>
24 
25 #ifndef DOXYGEN_SKIP
26 #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
27 #endif
28 #include <Eigen/Core>
29 #include <Eigen/Sparse>
30 
31 #ifdef POMEROL_USE_OPENMP
32 #include <omp.h>
33 #endif
34 
35 #if __cplusplus >= 201402L
36 #define POMEROL_DEPRECATED [[deprecated]]
37 #else
38 #define POMEROL_DEPRECATED
39 #endif
40 
41 #include <array>
42 #include <complex>
43 #include <cstddef>
44 #include <iostream>
45 #include <type_traits>
46 
48 namespace Pomerol {
49 
52 
53 #ifndef DOXYGEN_SKIP
54 #define MSG_PREFIX __FILE__ << ":" << __LINE__ << ": "
55 #endif
56 #ifndef NDEBUG
57 #define DEBUG(MSG) std::cout << MSG_PREFIX << MSG << '\n'
59 #else
60 #define DEBUG(MSG)
61 #endif
62 #define INFO(MSG) std::cout << MSG << '\n'
64 #define INFO_NONEWLINE(MSG) std::cout << MSG
66 #define ERROR(MSG) std::cerr << MSG_PREFIX << MSG << '\n'
68 
70 using RealType = double;
72 using ComplexType = std::complex<double>;
73 
75 using ParticleIndex = unsigned int;
76 
78 using QuantumState = libcommute::sv_index_type;
79 
81 using ComplexMatrixType =
82  Eigen::Matrix<ComplexType, Eigen::Dynamic, Eigen::Dynamic, Eigen::AutoAlign | Eigen::RowMajor>;
83 
86 template <bool Complex> using MelemType = typename std::conditional<Complex, ComplexType, RealType>::type;
87 
90 template <typename ScalarType>
91 using LOperatorType = libcommute::loperator<ScalarType, libcommute::fermion, libcommute::boson>;
92 
95 template <bool Complex>
96 using LOperatorTypeRC = libcommute::loperator<MelemType<Complex>, libcommute::fermion, libcommute::boson>;
97 
100 template <bool Complex>
101 using MatrixType =
102  Eigen::Matrix<MelemType<Complex>, Eigen::Dynamic, Eigen::Dynamic, Eigen::AutoAlign | Eigen::RowMajor>;
103 
105 using ComplexVectorType = Eigen::Matrix<ComplexType, Eigen::Dynamic, 1, Eigen::AutoAlign>;
107 using RealVectorType = Eigen::Matrix<RealType, Eigen::Dynamic, 1, Eigen::AutoAlign>;
108 
111 template <bool Complex> using VectorType = Eigen::Matrix<MelemType<Complex>, Eigen::Dynamic, 1, Eigen::AutoAlign>;
112 
115 template <bool Complex> using ColMajorMatrixType = Eigen::SparseMatrix<MelemType<Complex>, Eigen::ColMajor>;
118 template <bool Complex> using RowMajorMatrixType = Eigen::SparseMatrix<MelemType<Complex>, Eigen::RowMajor>;
119 
121 static ComplexType const I = ComplexType(0.0, 1.0); // 'static' to prevent linking problems
122 
124 struct Permutation3 {
126  std::array<std::size_t, 3> const perm;
128  int const sign;
129  bool operator==(Permutation3 const& rhs) const;
130  bool operator!=(Permutation3 const& rhs) const;
131 
136  friend std::ostream& operator<<(std::ostream& os, Permutation3 const& p);
137 };
139 extern std::array<Permutation3, 6> const permutations3;
140 
142 struct Permutation4 {
144  std::array<std::size_t, 4> const perm;
146  int const sign;
147  bool operator==(Permutation4 const& rhs) const;
148  bool operator!=(Permutation4 const& rhs) const;
149 
154  friend std::ostream& operator<<(std::ostream& os, Permutation4 const& p);
155 };
157 extern std::array<Permutation4, 24> const permutations4;
158 
160 enum Channel : int {
161  PP,
162  PH,
164 };
165 std::ostream& operator<<(std::ostream& os, Channel channel);
166 
173 std::size_t hash_binned_real(double x, double bin_size);
174 
176 
177 } // namespace Pomerol
178 
179 #endif // #ifndef POMEROL_INCLUDE_POMEROL_MISC_HPP
Pomerol::ComplexMatrixType
Eigen::Matrix< ComplexType, Eigen::Dynamic, Eigen::Dynamic, Eigen::AutoAlign|Eigen::RowMajor > ComplexMatrixType
Dense complex matrix.
Definition: Misc.hpp:82
Pomerol::permutations3
const std::array< Permutation3, 6 > permutations3
An array of all 3! = 6 permutations of 3 elements.
Pomerol::QuantumState
libcommute::sv_index_type QuantumState
Index of a many-body state.
Definition: Misc.hpp:78
Pomerol::operator<<
std::ostream & operator<<(std::ostream &os, Channel channel)
Pomerol::Permutation4::perm
const std::array< std::size_t, 4 > perm
A permuted list of integers (0, 1, 2, 3)
Definition: Misc.hpp:144
Pomerol::LOperatorType
libcommute::loperator< ScalarType, libcommute::fermion, libcommute::boson > LOperatorType
Definition: Misc.hpp:91
Pomerol::MatrixType
Eigen::Matrix< MelemType< Complex >, Eigen::Dynamic, Eigen::Dynamic, Eigen::AutoAlign|Eigen::RowMajor > MatrixType
Definition: Misc.hpp:102
Pomerol::Permutation3::operator==
bool operator==(Permutation3 const &rhs) const
Pomerol::LOperatorTypeRC
libcommute::loperator< MelemType< Complex >, libcommute::fermion, libcommute::boson > LOperatorTypeRC
Definition: Misc.hpp:96
Pomerol::I
static const ComplexType I
Imaginary unit .
Definition: Misc.hpp:121
Pomerol::RowMajorMatrixType
Eigen::SparseMatrix< MelemType< Complex >, Eigen::RowMajor > RowMajorMatrixType
Definition: Misc.hpp:118
Pomerol::hash_binned_real
std::size_t hash_binned_real(double x, double bin_size)
Pomerol::Permutation3::sign
const int sign
Signature of the permutation.
Definition: Misc.hpp:128
Pomerol::RealVectorType
Eigen::Matrix< RealType, Eigen::Dynamic, 1, Eigen::AutoAlign > RealVectorType
Dense real vector.
Definition: Misc.hpp:107
Pomerol::Channel
Channel
Channel, in which a susceptibility function is defined.
Definition: Misc.hpp:160
Pomerol::VectorType
Eigen::Matrix< MelemType< Complex >, Eigen::Dynamic, 1, Eigen::AutoAlign > VectorType
Definition: Misc.hpp:111
Pomerol::xPH
@ xPH
Crossed particle-hole channel.
Definition: Misc.hpp:163
Pomerol::ComplexType
std::complex< double > ComplexType
Complex floating point type.
Definition: Misc.hpp:72
Pomerol::RealType
double RealType
Real floating point type.
Definition: Misc.hpp:70
Pomerol::Permutation4::operator==
bool operator==(Permutation4 const &rhs) const
Pomerol::Permutation4::sign
const int sign
Signature of the permutation.
Definition: Misc.hpp:146
Pomerol::ColMajorMatrixType
Eigen::SparseMatrix< MelemType< Complex >, Eigen::ColMajor > ColMajorMatrixType
Definition: Misc.hpp:115
Pomerol::Permutation3::perm
const std::array< std::size_t, 3 > perm
A permuted list of integers (0, 1, 2)
Definition: Misc.hpp:126
Pomerol::PH
@ PH
Particle-hole channel.
Definition: Misc.hpp:162
Pomerol::Permutation3
Permutation of 3 elements.
Definition: Misc.hpp:124
Pomerol::Permutation4::operator<<
friend std::ostream & operator<<(std::ostream &os, Permutation4 const &p)
Pomerol::Permutation3::operator!=
bool operator!=(Permutation3 const &rhs) const
Pomerol::ComplexVectorType
Eigen::Matrix< ComplexType, Eigen::Dynamic, 1, Eigen::AutoAlign > ComplexVectorType
Dense complex vector.
Definition: Misc.hpp:105
Pomerol::Permutation3::operator<<
friend std::ostream & operator<<(std::ostream &os, Permutation3 const &p)
Pomerol::MelemType
typename std::conditional< Complex, ComplexType, RealType >::type MelemType
Definition: Misc.hpp:86
Pomerol::ParticleIndex
unsigned int ParticleIndex
Index of a single particle degree of freedom.
Definition: Misc.hpp:75
Pomerol::permutations4
const std::array< Permutation4, 24 > permutations4
An array of all 4! = 24 permutations of 4 elements.
Pomerol::Permutation4::operator!=
bool operator!=(Permutation4 const &rhs) const
Pomerol
The main namespace of the library.
Definition: ChaseIndices.hpp:26
Pomerol::PP
@ PP
Particle-particle channel.
Definition: Misc.hpp:161
Version.hpp
Pomerol version information.
Pomerol::Permutation4
Permutation of 4 elements.
Definition: Misc.hpp:142