DiFfRG
Loading...
Searching...
No Matches
integrator_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{
16 template <int d, typename NT, typename KERNEL> class IntegratorQMC
17 {
18 public:
22 using ctype = typename get_type::ctype<NT>;
23
24 template <typename... Args> class Functor
25 {
26 public:
27 static constexpr unsigned long long int number_of_integration_variables = 1;
28
29 Functor(const ctype x_extent, const ctype k, const Args &...args) : x_extent(x_extent), k(k), args(args...) {}
30
31 __host__ __device__ NT operator()(ctype *x) const
32 {
33 const ctype q = k * sqrt(x[0] * x_extent);
34 constexpr ctype S_d = S_d_prec<ctype>(d);
35 const ctype int_element = S_d // solid nd angle
36 * (powr<d - 2>(q) / 2 * powr<2>(k)) // x = p^2 / k^2 integral
37 / powr<d>(2 * (ctype)M_PI); // fourier factor
38 const ctype weight = x_extent;
39
40 return std::apply([&](auto &&...args) { return int_element * weight * KERNEL::kernel(q, k, args...); }, args);
41 }
42
43 private:
45 const ctype k;
46 std::tuple<Args...> args;
47 };
48
49 IntegratorQMC(QuadratureProvider &quadrature_provider, const std::array<uint, 1> grid_size, const ctype x_extent,
50 const JSONValue &json)
51 : IntegratorQMC(x_extent, json)
52 {
53 }
54
55 IntegratorQMC(const ctype x_extent, const double rel_tol = 1e-3, const double abs_tol = 1e-14,
56 const uint maxeval = 100000)
58 {
59 integrator.verbosity = 0;
60 integrator.epsrel = rel_tol;
61 integrator.epsabs = abs_tol;
62 integrator.maxeval = maxeval;
63 integrator.minm = 32;
64 integrator.minn = 512;
65 integrator.cudablocks = 64;
66 integrator.cudathreadsperblock = 32;
67 }
68
70 {
71 integrator.verbosity = 0;
72 integrator.epsrel = json.get_double("/integration/rel_tol");
73 integrator.epsabs = json.get_double("/integration/abs_tol");
74 integrator.maxeval = json.get_int("/integration/max_eval");
75 try {
76 integrator.minm = json.get_int("/integration/minm");
77 integrator.minn = json.get_int("/integration/minn");
78 integrator.cudablocks = json.get_int("/integration/cudablocks");
79 integrator.cudathreadsperblock = json.get_int("/integration/cudathreadsperblock");
80 } catch (const std::exception &e) {
81 spdlog::get("log")->warn("Please provide all integrator parameters in the json file. Using default values.");
82 spdlog::get("log")->warn(
83 "QMC integrator parameters: minm = 32, minn = 512, cudablocks = 64, cudathreadsperblock = 32");
84 integrator.minm = 32;
85 integrator.minn = 512;
86 integrator.cudablocks = 64;
87 integrator.cudathreadsperblock = 32;
88 }
89 }
90
101 template <typename... T> NT get(const ctype k, const T &...t) const
102 {
103 Functor<T...> functor(x_extent, k, t...);
104 integrators::result<NT> result = integrator.integrate(functor);
105
106 const NT constant = KERNEL::constant(k, t...);
107
108 return constant + result.integral;
109 }
110
121 template <typename... T> std::future<NT> request(const ctype k, const T &...t) const
122 {
123 const NT constant = KERNEL::constant(k, t...);
124
125 return std::async(std::launch::deferred, [=, this]() {
126 auto m_integrator = integrator;
127 Functor<T...> functor(x_extent, k, t...);
128 return constant + m_integrator.integrate(functor).integral;
129 });
130 }
131
132 private:
135 };
136} // namespace DiFfRG
Definition integrator_qmc.hh:25
std::tuple< Args... > args
Definition integrator_qmc.hh:46
__host__ __device__ NT operator()(ctype *x) const
Definition integrator_qmc.hh:31
Functor(const ctype x_extent, const ctype k, const Args &...args)
Definition integrator_qmc.hh:29
const ctype k
Definition integrator_qmc.hh:45
const ctype x_extent
Definition integrator_qmc.hh:44
static constexpr unsigned long long int number_of_integration_variables
Definition integrator_qmc.hh:27
Definition integrator_qmc.hh:17
const ctype x_extent
Definition integrator_qmc.hh:134
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_qmc.hh:22
IntegratorQMC(const ctype x_extent, const double rel_tol=1e-3, const double abs_tol=1e-14, const uint maxeval=100000)
Definition integrator_qmc.hh:55
NT get(const ctype k, const T &...t) const
Get the integral of the kernel.
Definition integrator_qmc.hh:101
integrators::Qmc< NT, ctype, 1, integrators::transforms::None::type > integrator
Definition integrator_qmc.hh:133
std::future< NT > request(const ctype k, const T &...t) const
Request a future for the integral of the kernel.
Definition integrator_qmc.hh:121
IntegratorQMC(const ctype x_extent, const JSONValue &json)
Definition integrator_qmc.hh:69
IntegratorQMC(QuadratureProvider &quadrature_provider, const std::array< uint, 1 > grid_size, const ctype x_extent, const JSONValue &json)
Definition integrator_qmc.hh:49
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