/home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/quadrature/matsubara.hh Source File#

DiFfRG: /home/runner/work/DiFfRG_current/DiFfRG_current/DiFfRG/include/DiFfRG/common/quadrature/matsubara.hh Source File
DiFfRG
Discretization Framework for functional Renormalization Group flows
matsubara.hh
Go to the documentation of this file.
1#pragma once
2
3// DiFfRG
6
7// C++ standard library
8#include <vector>
9
10namespace DiFfRG
11{
24 template <typename NT> class MatsubaraQuadrature
25 {
26 public:
39 static int predict_size(const NT T, const NT typical_E = 1., const double precision_factor = 1.,
40 const int step = 2);
41
57 MatsubaraQuadrature(const NT T, const NT typical_E = 1., const int step = 2, const int min_size = 8,
58 const int max_size = 128, const int vacuum_quad_size = 64, const double precision_factor = 1);
59
61
77 void reinit(const NT T, const NT typical_E = 1., const int step = 2, const int min_size = 8,
78 const int max_size = 128, const int vacuum_quad_size = 64, const double precision_factor = 1);
79
92 void reinit_with_size(const int size, const NT T, const NT typical_E = 1.);
93
100 static int modes_below(const NT T, const NT freq_cutoff);
101
122 void reinit_exact_sum(const NT T, const NT freq_cutoff);
123
157 void reinit_finite_interval(const NT cutoff, const Kokkos::View<const NT *, CPU_memory> gl_nodes,
158 const Kokkos::View<const NT *, CPU_memory> gl_weights);
159
163 size_t size() const;
164
169 size_t sum_size() const;
170
174 NT get_T() const;
175
179 NT get_typical_E() const;
180
188 template <typename F> auto sum(const F &f) const
189 {
190 auto sum = T * f(static_cast<NT>(0));
191 for (int i = 0; i < m_size; ++i)
192 sum += host_weights[i] * (f(host_nodes[i]) + f(-host_nodes[i]));
193 return sum;
194 }
195
199 template <typename MemorySpace> Kokkos::View<const NT *, MemorySpace> nodes() const
200 {
201 return Kokkos::subview(raw_nodes<MemorySpace>(), Kokkos::make_pair(size_t(0), size_t(m_size)));
202 }
203
204 template <typename MemorySpace> Kokkos::View<const NT *, MemorySpace> weights() const
205 {
206 return Kokkos::subview(raw_weights<MemorySpace>(), Kokkos::make_pair(size_t(0), size_t(m_size)));
207 }
208
221 template <typename MemorySpace> Kokkos::View<const NT *, MemorySpace> sum_nodes() const
222 {
223 return Kokkos::subview(raw_nodes<MemorySpace>(), Kokkos::make_pair(size_t(0), sum_size()));
224 }
225
226 template <typename MemorySpace> Kokkos::View<const NT *, MemorySpace> sum_weights() const
227 {
228 return Kokkos::subview(raw_weights<MemorySpace>(), Kokkos::make_pair(size_t(0), sum_size()));
229 }
230
231 private:
232 template <typename MemorySpace> Kokkos::View<const NT *, MemorySpace> raw_nodes() const
233 {
234 if constexpr (std::is_same_v<MemorySpace, Kokkos::DefaultExecutionSpace::memory_space>) {
235 return device_nodes;
236 } else if constexpr (std::is_same_v<MemorySpace, Kokkos::DefaultHostExecutionSpace::memory_space>) {
237 return host_nodes;
238 } else {
239 throw std::runtime_error("Invalid memory space");
240 }
241 }
242
243 template <typename MemorySpace> Kokkos::View<const NT *, MemorySpace> raw_weights() const
244 {
245 if constexpr (std::is_same_v<MemorySpace, Kokkos::DefaultExecutionSpace::memory_space>) {
246 return device_weights;
247 } else if constexpr (std::is_same_v<MemorySpace, Kokkos::DefaultHostExecutionSpace::memory_space>) {
248 return host_weights;
249 } else {
250 throw std::runtime_error("Invalid memory space");
251 }
252 }
253
255
256 Kokkos::View<NT *, GPU_memory> device_nodes;
257 Kokkos::View<NT *, GPU_memory> device_weights;
258
259 Kokkos::View<NT *, CPU_memory> host_nodes;
260 Kokkos::View<NT *, CPU_memory> host_weights;
261
266
271
275 void reinit_0();
276
280 void write_data(const std::vector<NT> &x, const std::vector<NT> &w);
281
284 };
285} // namespace DiFfRG
A quadrature rule for (bosonic) Matsubara frequencies, based on the method of Monien [1]....
Definition matsubara.hh:25
int m_size
The number of nodes in the quadrature rule.
Definition matsubara.hh:265
Kokkos::View< const NT *, MemorySpace > raw_weights() const
Definition matsubara.hh:243
static int modes_below(const NT T, const NT freq_cutoff)
Number of positive Matsubara modes strictly inside a frequency cutoff.
Kokkos::View< const NT *, MemorySpace > sum_weights() const
Definition matsubara.hh:226
MatsubaraQuadrature(const NT T, const NT typical_E=1., const int step=2, const int min_size=8, const int max_size=128, const int vacuum_quad_size=64, const double precision_factor=1)
Create a new quadrature rule for Matsubara frequencies.
auto sum(const F &f) const
Compute a matsubara sum of a given function.
Definition matsubara.hh:188
Kokkos::View< NT *, CPU_memory > host_weights
Definition matsubara.hh:260
void write_data(const std::vector< NT > &x, const std::vector< NT > &w)
Store x/w plus the appended zero mode; see sum_nodes(). x and w have m_size entries.
void reinit_exact_sum(const NT T, const NT freq_cutoff)
Build the EXACT Matsubara sum for a summand of finite extent in the frequency.
size_t sum_size() const
Size of the node list returned by sum_nodes()/sum_weights(): size() plus the zero mode,...
NT get_T() const
Get the temperature of the quadrature rule.
Kokkos::View< const NT *, MemorySpace > nodes() const
The positive-frequency nodes, without the zero mode. Length size().
Definition matsubara.hh:199
size_t size() const
Get the size of the quadrature rule, NOT counting the zero mode.
double precision_factor
Definition matsubara.hh:283
NT T
Definition matsubara.hh:254
Kokkos::View< NT *, GPU_memory > device_weights
Definition matsubara.hh:257
void build_monien()
Construct the Monien rule for the current m_size and T.
Kokkos::View< const NT *, MemorySpace > raw_nodes() const
Definition matsubara.hh:232
int vacuum_quad_size
Definition matsubara.hh:282
void reinit_0()
Construct a quadrature rule for T=0.
void reinit(const NT T, const NT typical_E=1., const int step=2, const int min_size=8, const int max_size=128, const int vacuum_quad_size=64, const double precision_factor=1)
Update the quadrature rule with new parameters.
Kokkos::View< NT *, GPU_memory > device_nodes
Definition matsubara.hh:256
Kokkos::View< NT *, CPU_memory > host_nodes
Definition matsubara.hh:259
void reinit_finite_interval(const NT cutoff, const Kokkos::View< const NT *, CPU_memory > gl_nodes, const Kokkos::View< const NT *, CPU_memory > gl_weights)
Gauss-Legendre over the FINITE interval the summand actually lives on.
Kokkos::View< const NT *, MemorySpace > sum_nodes() const
Node list for a device-side sum: the positive frequencies followed by the zero mode.
Definition matsubara.hh:221
Kokkos::View< const NT *, MemorySpace > weights() const
Definition matsubara.hh:204
NT typical_E
Definition matsubara.hh:254
static int predict_size(const NT T, const NT typical_E=1., const double precision_factor=1., const int step=2)
Nodes the Monien rule needs to reach past typical_E at this temperature.
void reinit_with_size(const int size, const NT T, const NT typical_E=1.)
Build a rule with an explicitly prescribed number of nodes, bypassing predict_size().
NT get_typical_E() const
Get the typical energy scale of the quadrature rule.
Definition complex_math.hh:10