TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
matsubara_freq.hpp
Go to the documentation of this file.
1// Copyright (c) 2013-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2013-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2023 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU 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// This program 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 General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Thomas Ayral, Philipp Dumitrescu, Laura Messio, Olivier Parcollet, Nils Wentzell
19
24
25#pragma once
26
27#include "./utils.hpp"
29#include "../utility/macros.hpp"
30
31#include <compare>
32#include <complex>
33#include <iostream>
34#include <numbers>
35#include <type_traits>
36#include <utility>
37
38namespace triqs::mesh {
39
44
53 struct C2PY_IGNORE matsubara_freq {
55 using cast_t = std::complex<double>;
56
58 long n = 0;
59
61 double beta = 0.0;
62
65
70 matsubara_freq() = default;
71
80 matsubara_freq(long n_idx, double b, statistic_enum stat) : n(n_idx), beta(b), statistic(stat) {}
81
83 [[nodiscard]] long index() const { return n; }
84
86 operator cast_t() const { return std::complex<double>{0, std::numbers::pi * static_cast<double>(2 * n + statistic) / beta}; }
87
89 bool operator==(matsubara_freq const &) const = default;
90
92 std::partial_ordering operator<=>(matsubara_freq const &other) const {
93 if (beta != other.beta || statistic != other.statistic) return std::partial_ordering::unordered;
94 return n <=> other.n;
95 }
96 };
97
105 C2PY_IGNORE inline std::ostream &operator<<(std::ostream &sout, matsubara_freq const &iw) { return sout << std::complex<double>(iw); }
106
118 [[nodiscard]] C2PY_IGNORE inline matsubara_freq operator+(matsubara_freq const &iw1, matsubara_freq const &iw2) {
119 return {iw1.n + iw2.n + (iw1.statistic & iw2.statistic), iw1.beta, ((iw1.statistic ^ iw2.statistic) == 1 ? Fermion : Boson)};
120 }
121
133 [[nodiscard]] C2PY_IGNORE inline matsubara_freq operator-(matsubara_freq const &iw1, matsubara_freq const &iw2) {
134 return {iw1.n - iw2.n - (~iw1.statistic & iw2.statistic), iw1.beta, ((iw1.statistic ^ iw2.statistic) == 1 ? Fermion : Boson)};
135 }
136
146 [[nodiscard]] C2PY_IGNORE inline matsubara_freq operator-(matsubara_freq const &iw) {
147 return {-(iw.n + (iw.statistic == Fermion ? 1 : 0)), iw.beta, iw.statistic};
148 }
149
159 [[nodiscard]] C2PY_IGNORE inline auto operator/(matsubara_freq const &iw1, matsubara_freq const &iw2) {
160 return std::complex<double>{iw1} / std::complex<double>{iw2};
161 }
162
172 [[nodiscard]] C2PY_IGNORE inline auto operator*(matsubara_freq const &iw1, matsubara_freq const &iw2) {
173 return std::complex<double>{iw1} * std::complex<double>{iw2};
174 }
175
176#define IMPL_OP(OP) \
177 \
178 template <typename T> \
179 requires(not std::is_base_of_v<matsubara_freq, std::decay_t<T>>) \
180 [[nodiscard]] inline auto operator OP(matsubara_freq const &iw, T &&y) { \
181 return std::complex<double>(iw) OP std::forward<T>(y); \
182 } \
183 \
184 template <typename T> \
185 requires(not std::is_base_of_v<matsubara_freq, std::decay_t<T>>) \
186 [[nodiscard]] inline auto operator OP(T &&x, matsubara_freq const &iw) { \
187 return std::forward<T>(x) OP std::complex<double>(iw); \
188 }
189 IMPL_OP(+);
190 IMPL_OP(-);
191 IMPL_OP(*);
192 IMPL_OP(/);
193#undef IMPL_OP
194
201 [[nodiscard]] C2PY_IGNORE inline bool kronecker(matsubara_freq const &iw) { return iw.n == 0; }
202
210 [[nodiscard]] C2PY_IGNORE inline bool kronecker(matsubara_freq const &iw1, matsubara_freq const &iw2) { return iw1.n == iw2.n; }
211
213
214} // namespace triqs::mesh
k_expr<'+', L, R > operator+(L &&l, R &&r)
Lazy addition of two triqs::mesh::BzMeshPoint objects.
Definition brzone.hpp:648
k_expr_unary<'-', L > operator-(L &&l)
Lazy unary minus for triqs::mesh::BzMeshPoint objects.
Definition brzone.hpp:637
k_expr<' *', long, R > operator*(Int l, R &&r)
Lazy multiplication of a triqs::mesh::BzMeshPoint object with a scalar.
Definition brzone.hpp:670
auto operator/(matsubara_freq const &iw1, matsubara_freq const &iw2)
Divison operator for two triqs::mesh::matsubara_freq objects.
bool kronecker(matsubara_freq const &iw)
Kronecker delta function for a single Matsubara frequency.
std::ostream & operator<<(std::ostream &sout, matsubara_freq const &iw)
Write a triqs::mesh::matsubara_freq to a std::ostream.
statistic_enum
Enum to specify particle statistics.
Definition utils.hpp:163
Kronecker delta for arithmetic types, with a CLEF lazy-expression hook.
Common macros used in TRIQS.
Provides various utilities used with Meshes.
matsubara_freq()=default
Default constructor initializes the Matsubara frequency with zero index, zero inverse temperature and...
Represents a Matsubara frequency .
double beta
Inverse temperature .
matsubara_freq(long n_idx, double b, statistic_enum stat)
Construct a Matsubara frequency with a given index , inverse temperature and particle statistics.
long index() const
Get the index of the Matsubara frequency.
std::complex< double > cast_t
Value type of a Matsubara frequency.
long n
Matsubara index .
statistic_enum statistic
Particle statistics.
std::partial_ordering operator<=>(matsubara_freq const &other) const
Partial ordering by index when beta and statistic match, unordered otherwise.
bool operator==(matsubara_freq const &) const =default
Equality comparison.
matsubara_freq()=default
Default constructor initializes the Matsubara frequency with zero index, zero inverse temperature and...