/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
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:
36 int predict_size(const NT T, const NT typical_E = 1., const int step = 2);
37
47 MatsubaraQuadrature(const NT T, const NT typical_E = 1., const int step = 2, const int min_size = 0,
48 const int max_size = 256, const int vacuum_quad_size = 48, const int precision_factor = 1);
49
51
61 void reinit(const NT T, const NT typical_E = 1., const int step = 2, const int min_size = 0,
62 const int max_size = 256, const int vacuum_quad_size = 48, const int precision_factor = 1);
63
67 size_t size() const;
68
72 NT get_T() const;
73
77 NT get_typical_E() const;
78
86 template <typename F> auto sum(const F &f) const
87 {
88 auto sum = T * f(static_cast<NT>(0));
89 for (int i = 0; i < m_size; ++i)
90 sum += host_weights[i] * (f(host_nodes[i]) + f(-host_nodes[i]));
91 return sum;
92 }
93
94 template <typename MemorySpace> Kokkos::View<const NT *, MemorySpace> nodes() const
95 {
96 if constexpr (std::is_same_v<MemorySpace, Kokkos::DefaultExecutionSpace::memory_space>) {
97 return device_nodes;
98 } else if constexpr (std::is_same_v<MemorySpace, Kokkos::DefaultHostExecutionSpace::memory_space>) {
99 return host_nodes;
100 } else {
101 throw std::runtime_error("Invalid memory space");
102 }
103 }
104
105 template <typename MemorySpace> Kokkos::View<const NT *, MemorySpace> weights() const
106 {
107 if constexpr (std::is_same_v<MemorySpace, Kokkos::DefaultExecutionSpace::memory_space>) {
108 return device_weights;
109 } else if constexpr (std::is_same_v<MemorySpace, Kokkos::DefaultHostExecutionSpace::memory_space>) {
110 return host_weights;
111 } else {
112 throw std::runtime_error("Invalid memory space");
113 }
114 }
115
116 private:
118
119 Kokkos::View<NT *, GPU_memory> device_nodes;
120 Kokkos::View<NT *, GPU_memory> device_weights;
121
122 Kokkos::View<NT *, CPU_memory> host_nodes;
123 Kokkos::View<NT *, CPU_memory> host_weights;
124
129
130 void write_data(const std::vector<NT> &x, const std::vector<NT> &w);
131
135 void reinit_0();
136
139 };
140} // 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:128
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.
MatsubaraQuadrature(const NT T, const NT typical_E=1., const int step=2, const int min_size=0, const int max_size=256, const int vacuum_quad_size=48, const int 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:86
Kokkos::View< NT *, CPU_memory > host_weights
Definition matsubara.hh:123
void write_data(const std::vector< NT > &x, const std::vector< NT > &w)
NT get_T() const
Get the temperature of the quadrature rule.
Kokkos::View< const NT *, MemorySpace > nodes() const
Definition matsubara.hh:94
size_t size() const
Get the size of the quadrature rule.
int precision_factor
Definition matsubara.hh:138
NT T
Definition matsubara.hh:117
Kokkos::View< NT *, GPU_memory > device_weights
Definition matsubara.hh:120
int vacuum_quad_size
Definition matsubara.hh:137
void reinit_0()
Construct a quadrature rule for T=0.
Kokkos::View< NT *, GPU_memory > device_nodes
Definition matsubara.hh:119
Kokkos::View< NT *, CPU_memory > host_nodes
Definition matsubara.hh:122
Kokkos::View< const NT *, MemorySpace > weights() const
Definition matsubara.hh:105
void reinit(const NT T, const NT typical_E=1., const int step=2, const int min_size=0, const int max_size=256, const int vacuum_quad_size=48, const int precision_factor=1)
Update the quadrature rule with new parameters.
NT typical_E
Definition matsubara.hh:117
NT get_typical_E() const
Get the typical energy scale of the quadrature rule.
Definition complex_math.hh:10