DiFfRG
Loading...
Searching...
No Matches
integrator_4D_qmc.hh
Go to the documentation of this file.
1#pragma once
2
3// standard library
4#include <future>
5
6// external libraries
7#include "BS_thread_pool.hpp"
8#include <qmc/qmc.hpp>
9
10// DiFfRG
14
15namespace DiFfRG
16{
28 template <typename NT, typename KERNEL> class Integrator4DQMC
29 {
30 public:
34 using ctype = typename get_type::ctype<NT>;
35
36 template <typename... Args> class Functor
37 {
38 public:
39 static constexpr unsigned long long int number_of_integration_variables = 4;
40
41 Functor(const ctype x_extent, const ctype k, const Args &...args) : x_extent(x_extent), k(k), args(args...) {}
42
43 __host__ __device__ NT operator()(ctype *x) const
44 {
45 const ctype q = k * sqrt(x[0] * x_extent);
46 const ctype cos1 = 2 * (x[1] - (ctype)0.5);
47 const ctype int_element = (powr<2>(q) * (ctype)0.5 * powr<2>(k)) // x = p^2 / k^2 integral
48 * sqrt(1. - powr<2>(cos1)) // cos1 integral jacobian
49 / powr<4>(2 * (ctype)M_PI); // fourier factor
50 const ctype cos2 = 2 * (x[2] - (ctype)0.5);
51 const ctype phi = 2 * (ctype)M_PI * x[3];
52 const ctype weight = 2 * (ctype)M_PI // phi weight
53 * 2 // cos2 weight
54 * 2 // cos1 weight
55 * x_extent; // x weight
56 return std::apply(
57 [&](auto &&...args) { return int_element * weight * KERNEL::kernel(q, cos1, cos2, phi, k, args...); },
58 args);
59 }
60
61 private:
63 const ctype k;
64 std::tuple<Args...> args;
65 };
66
67 Integrator4DQMC(QuadratureProvider &quadrature_provider, const std::array<uint, 4> grid_size, const ctype x_extent,
68 const JSONValue &json)
70 {
71 }
72
73 Integrator4DQMC(const ctype x_extent, const double rel_tol = 1e-3, const double abs_tol = 1e-14,
74 const uint maxeval = 100000)
75 : pool(128), x_extent(x_extent)
76 {
77 integrator.verbosity = 0;
78 integrator.epsrel = rel_tol;
79 integrator.epsabs = abs_tol;
80 integrator.maxeval = maxeval;
81 integrator.minm = 32;
82 integrator.minn = 512;
83 integrator.cudablocks = 64;
84 integrator.cudathreadsperblock = 32;
85 }
86
88 {
89 integrator.verbosity = 0;
90 integrator.epsrel = json.get_double("/integration/rel_tol");
91 integrator.epsabs = json.get_double("/integration/abs_tol");
92 integrator.maxeval = json.get_int("/integration/max_eval");
93 try {
94 integrator.minm = json.get_int("/integration/minm");
95 integrator.minn = json.get_int("/integration/minn");
96 integrator.cudablocks = json.get_int("/integration/cudablocks");
97 integrator.cudathreadsperblock = json.get_int("/integration/cudathreadsperblock");
98 } catch (const std::exception &e) {
99 spdlog::get("log")->warn("Please provide all integrator parameters in the json file. Using default values.");
100 spdlog::get("log")->warn(
101 "QMC integrator parameters: minm = 32, minn = 512, cudablocks = 64, cudathreadsperblock = 32");
102 integrator.minm = 32;
103 integrator.minn = 512;
104 integrator.cudablocks = 64;
105 integrator.cudathreadsperblock = 32;
106 }
107 }
108
119 template <typename... T> NT get(const ctype k, const T &...t) const
120 {
121 Functor<T...> functor(x_extent, k, t...);
122 integrators::result<NT> result = integrator.integrate(functor);
123
124 const NT constant = KERNEL::constant(k, t...);
125
126 return constant + result.integral;
127 }
128
139 template <typename... T> std::future<NT> request(const ctype k, const T &...t) const
140 {
141 const NT constant = KERNEL::constant(k, t...);
142
143 return pool.submit_task([=, this]() {
144 auto m_integrator = integrator;
145 Functor<T...> functor(x_extent, k, t...);
146 return constant + m_integrator.integrate(functor).integral;
147 });
148 }
149
150 private:
151 mutable BS::thread_pool<BS::tp::none> pool;
154 };
155} // namespace DiFfRG
Definition integrator_4D_qmc.hh:37
const ctype k
Definition integrator_4D_qmc.hh:63
__host__ __device__ NT operator()(ctype *x) const
Definition integrator_4D_qmc.hh:43
const ctype x_extent
Definition integrator_4D_qmc.hh:62
static constexpr unsigned long long int number_of_integration_variables
Definition integrator_4D_qmc.hh:39
Functor(const ctype x_extent, const ctype k, const Args &...args)
Definition integrator_4D_qmc.hh:41
std::tuple< Args... > args
Definition integrator_4D_qmc.hh:64
GPU integrator for the integration of a 4D function with three angles with quasi-Monte-Carlo....
Definition integrator_4D_qmc.hh:29
NT get(const ctype k, const T &...t) const
Get the integral of the kernel.
Definition integrator_4D_qmc.hh:119
Integrator4DQMC(const ctype x_extent, const JSONValue &json)
Definition integrator_4D_qmc.hh:87
BS::thread_pool< BS::tp::none > pool
Definition integrator_4D_qmc.hh:151
Integrator4DQMC(QuadratureProvider &quadrature_provider, const std::array< uint, 4 > grid_size, const ctype x_extent, const JSONValue &json)
Definition integrator_4D_qmc.hh:67
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_4D_qmc.hh:34
integrators::Qmc< NT, ctype, 4, integrators::transforms::None::type > integrator
Definition integrator_4D_qmc.hh:152
const ctype x_extent
Definition integrator_4D_qmc.hh:153
std::future< NT > request(const ctype k, const T &...t) const
Request a future for the integral of the kernel.
Definition integrator_4D_qmc.hh:139
Integrator4DQMC(const ctype x_extent, const double rel_tol=1e-3, const double abs_tol=1e-14, const uint maxeval=100000)
Definition integrator_4D_qmc.hh:73
A wrapper around the boost json value class.
Definition json.hh:19
double get_double(const std::string &key) const
Get the value of a key in the json object.
int get_int(const std::string &key) const
Get the value of a key in the json object.
A class that provides quadrature points and weights, in host and device memory. The quadrature points...
Definition quadrature_provider.hh:139
Definition qmc.hpp:1142
typename internal::_ctype< CT >::value ctype
Definition types.hh:106
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
unsigned int uint
Definition utils.hh:22
Definition qmc.hpp:70
T integral
Definition qmc.hpp:71