DiFfRG
Loading...
Searching...
No Matches
integrator_angle_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 <qmc/qmc.hpp>
8
9// DiFfRG
13
14namespace DiFfRG
15{
26 template <int d, typename NT, typename KERNEL> class IntegratorAngleQMC
27 {
28 public:
32 using ctype = typename get_type::ctype<NT>;
33
34 template <typename... Args> class Functor
35 {
36 public:
37 static constexpr unsigned long long int number_of_integration_variables = 2;
38
39 Functor(const ctype x_extent, const ctype k, const Args &...args) : x_extent(x_extent), k(k), args(args...) {}
40
41 __host__ __device__ NT operator()(ctype *x) const
42 {
43 const ctype q = k * sqrt(x[0] * x_extent);
44 const ctype cos = 2 * (x[1] - (ctype)0.5);
45 const ctype weight = 2 * x_extent;
46 constexpr ctype S_d = S_d_prec<ctype>(d);
47 const ctype int_element = S_d // solid nd angle
48 * (powr<d - 2>(q) / (ctype)2 * powr<2>(k)) // x = p^2 / k^2 integral
49 * (1 / (ctype)2) // divide the cos integral out
50 / powr<d>(2 * (ctype)M_PI); // fourier factor
51
52 return std::apply([&](auto &&...args) { return int_element * weight * KERNEL::kernel(q, cos, k, args...); },
53 args);
54 }
55
56 private:
58 const ctype k;
59 std::tuple<Args...> args;
60 };
61
62 IntegratorAngleQMC(QuadratureProvider &quadrature_provider, const std::array<uint, 2> grid_size,
63 const ctype x_extent, const JSONValue &json)
65 {
66 }
67
68 IntegratorAngleQMC(const ctype x_extent, const double rel_tol = 1e-3, const double abs_tol = 1e-14,
69 const uint maxeval = 100000)
71 {
72 integrator.verbosity = 0;
73 integrator.epsrel = rel_tol;
74 integrator.epsabs = abs_tol;
75 integrator.maxeval = maxeval;
76 integrator.minm = 32;
77 integrator.minn = 512;
78 integrator.cudablocks = 64;
79 integrator.cudathreadsperblock = 32;
80 }
81
83 {
84 integrator.verbosity = 0;
85 integrator.epsrel = json.get_double("/integration/rel_tol");
86 integrator.epsabs = json.get_double("/integration/abs_tol");
87 integrator.maxeval = json.get_int("/integration/max_eval");
88 try {
89 integrator.minm = json.get_int("/integration/minm");
90 integrator.minn = json.get_int("/integration/minn");
91 integrator.cudablocks = json.get_int("/integration/cudablocks");
92 integrator.cudathreadsperblock = json.get_int("/integration/cudathreadsperblock");
93 } catch (const std::exception &e) {
94 spdlog::get("log")->warn("Please provide all integrator parameters in the json file. Using default values.");
95 spdlog::get("log")->warn(
96 "QMC integrator parameters: minm = 32, minn = 512, cudablocks = 64, cudathreadsperblock = 32");
97 integrator.minm = 32;
98 integrator.minn = 512;
99 integrator.cudablocks = 64;
100 integrator.cudathreadsperblock = 32;
101 }
102 }
103
114 template <typename... T> NT get(const ctype k, const T &...t) const
115 {
116 Functor<T...> functor(x_extent, k, t...);
117 integrators::result<NT> result = integrator.integrate(functor);
118
119 const NT constant = KERNEL::constant(k, t...);
120
121 return constant + result.integral;
122 }
123
134 template <typename... T> std::future<NT> request(const ctype k, const T &...t) const
135 {
136 const NT constant = KERNEL::constant(k, t...);
137
138 return std::async(std::launch::deferred, [=, this]() {
139 auto m_integrator = integrator;
140 Functor<T...> functor(x_extent, k, t...);
141 return constant + m_integrator.integrate(functor).integral;
142 });
143 }
144
145 private:
148 };
149} // namespace DiFfRG
Definition integrator_angle_qmc.hh:35
std::tuple< Args... > args
Definition integrator_angle_qmc.hh:59
Functor(const ctype x_extent, const ctype k, const Args &...args)
Definition integrator_angle_qmc.hh:39
const ctype x_extent
Definition integrator_angle_qmc.hh:57
__host__ __device__ NT operator()(ctype *x) const
Definition integrator_angle_qmc.hh:41
const ctype k
Definition integrator_angle_qmc.hh:58
static constexpr unsigned long long int number_of_integration_variables
Definition integrator_angle_qmc.hh:37
GPU integrator for the integration of a function with one angle with quasi-Monte-Carlo....
Definition integrator_angle_qmc.hh:27
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_angle_qmc.hh:32
const ctype x_extent
Definition integrator_angle_qmc.hh:147
NT get(const ctype k, const T &...t) const
Get the integral of the kernel.
Definition integrator_angle_qmc.hh:114
IntegratorAngleQMC(const ctype x_extent, const JSONValue &json)
Definition integrator_angle_qmc.hh:82
IntegratorAngleQMC(QuadratureProvider &quadrature_provider, const std::array< uint, 2 > grid_size, const ctype x_extent, const JSONValue &json)
Definition integrator_angle_qmc.hh:62
IntegratorAngleQMC(const ctype x_extent, const double rel_tol=1e-3, const double abs_tol=1e-14, const uint maxeval=100000)
Definition integrator_angle_qmc.hh:68
std::future< NT > request(const ctype k, const T &...t) const
Request a future for the integral of the kernel.
Definition integrator_angle_qmc.hh:134
integrators::Qmc< NT, ctype, 2, integrators::transforms::None::type > integrator
Definition integrator_angle_qmc.hh:146
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
constexpr __forceinline__ __host__ __device__ double S_d(NT d)
Surface of a d-dimensional sphere.
Definition math.hh:91
consteval NT S_d_prec(uint d)
Surface of a d-dimensional sphere (precompiled)
Definition math.hh:104
unsigned int uint
Definition utils.hh:22
Definition qmc.hpp:70
T integral
Definition qmc.hpp:71