DiFfRG
Loading...
Searching...
No Matches
matsubara.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
6
7// C++ standard library
8#include <cmath>
9#include <vector>
10
11namespace DiFfRG
12{
25 template <typename NT> class MatsubaraQuadrature
26 {
27 public:
37 int predict_size(const NT T, const NT typical_E = 1., const int step = 2);
38
48 MatsubaraQuadrature(const NT T, const NT typical_E = 1., const int step = 2, const int min_size = 0,
49 const int max_size = powr<10>(2), const int vacuum_quad_size = 48,
50 const int precision_factor = 1);
51
53
63 void reinit(const NT T, const NT typical_E = 1., const int step = 2, const int min_size = 0,
64 const int max_size = powr<10>(2), const int vacuum_quad_size = 48, const int precision_factor = 1);
65
71 const std::vector<NT> &nodes() const;
72
78 const std::vector<NT> &weights() const;
79
83 int size() const;
84
88 NT get_T() const;
89
93 NT get_typical_E() const;
94
102 template <typename F> auto sum(const F &f) const
103 {
104 auto sum = T * f(static_cast<NT>(0));
105 for (int i = 0; i < m_size; ++i)
106 sum += w[i] * (f(x[i]) + f(-x[i]));
107 return sum;
108 }
109
110#ifdef USE_CUDA
116 const NT *device_nodes();
117
123 const NT *device_weights();
124#endif
125
126 private:
131 std::vector<NT> x;
132
136 std::vector<NT> w;
137
142
143#ifdef __CUDACC__
147 thrust::device_vector<NT> device_x;
148
152 thrust::device_vector<NT> device_w;
153#endif
154
159
163 void reinit_0();
164
167 };
168} // namespace DiFfRG
A quadrature rule for (bosonic) Matsubara frequencies, based on the method of Monien [1]....
Definition matsubara.hh:26
int m_size
The number of nodes in the quadrature rule.
Definition matsubara.hh:141
std::vector< NT > w
Weights of the quadrature rule.
Definition matsubara.hh:136
int predict_size(const NT T, const NT typical_E=1., const int step=2)
Calculate the number of nodes needed for a given temperature and typical energy scale.
std::vector< NT > x
Nodes of the quadrature rule.
Definition matsubara.hh:131
auto sum(const F &f) const
Compute a matsubara sum of a given function.
Definition matsubara.hh:102
int size() const
Get the size of the quadrature rule.
thrust::device_vector< NT > device_x
Device-side nodes of the quadrature rule.
Definition matsubara.hh:147
NT get_T() const
Get the temperature of the quadrature rule.
const std::vector< NT > & weights() const
Get the weights of the quadrature rule.
thrust::device_vector< NT > device_w
Device-side weights of the quadrature rule.
Definition matsubara.hh:152
MatsubaraQuadrature(const NT T, const NT typical_E=1., const int step=2, const int min_size=0, const int max_size=powr< 10 >(2), const int vacuum_quad_size=48, const int precision_factor=1)
Create a new quadrature rule for Matsubara frequencies.
void move_device_data()
Move the nodes and weights to the device, if they are not already there.
int precision_factor
Definition matsubara.hh:166
NT T
Definition matsubara.hh:127
const std::vector< NT > & nodes() const
Get the nodes of the quadrature rule.
int vacuum_quad_size
Definition matsubara.hh:165
void reinit_0()
Construct a quadrature rule for T=0.
const NT * device_nodes()
Return the device-side nodes of the quadrature rule.
NT typical_E
Definition matsubara.hh:127
void reinit(const NT T, const NT typical_E=1., const int step=2, const int min_size=0, const int max_size=powr< 10 >(2), const int vacuum_quad_size=48, const int precision_factor=1)
Update the quadrature rule with new parameters.
NT get_typical_E() const
Get the typical energy scale of the quadrature rule.
const NT * device_weights()
Return the device-side weights of the quadrature rule.
Definition complex_math.hh:14
constexpr __forceinline__ __host__ __device__ NumberType powr(const NumberType x)
A compile-time evaluatable power function for whole number exponents.
Definition math.hh:45