DiFfRG
Loading...
Searching...
No Matches
integrator_2Dpx0_cpu.hh
Go to the documentation of this file.
1#pragma once
2
3// standard library
4#include <future>
5
6// external libraries
7#include <tbb/tbb.h>
8
9// DiFfRG
11
12namespace DiFfRG
13{
24 template <typename NT, typename KERNEL> class Integrator2Dpx0TBB
25 {
26 public:
30 using ctype = typename get_type::ctype<NT>;
31
41 Integrator2Dpx0TBB(QuadratureProvider &quadrature_provider, const std::array<uint, 3> grid_sizes,
42 const ctype x_extent, const ctype x0_extent, const JSONValue &)
43 : Integrator2Dpx0TBB(quadrature_provider, grid_sizes, x_extent, x0_extent)
44 {
45 }
46
56 Integrator2Dpx0TBB(QuadratureProvider &quadrature_provider, std::array<uint, 3> grid_sizes, const ctype x_extent,
57 const ctype x0_extent, const uint max_block_size = 0)
59 x_quadrature_p(quadrature_provider.get_points<ctype>(grid_sizes[0])),
60 x_quadrature_w(quadrature_provider.get_weights<ctype>(grid_sizes[0])),
61 ang_quadrature_p(quadrature_provider.get_points<ctype>(grid_sizes[1])),
62 ang_quadrature_w(quadrature_provider.get_weights<ctype>(grid_sizes[1])),
63 x0_quadrature_p(quadrature_provider.get_points<ctype>(grid_sizes[2])),
64 x0_quadrature_w(quadrature_provider.get_weights<ctype>(grid_sizes[2]))
65 {
66 (void)max_block_size;
67 }
68
78 template <typename... T> NT get(const ctype k, const T &...t) const
79 {
80 constexpr ctype S_2d = 2 * (ctype)M_PI;
81 using std::sqrt;
82
83 const auto constant = KERNEL::constant(k, t...);
84 return constant +
85 tbb::parallel_reduce(
86 tbb::blocked_range3d<uint, uint, uint>(0, grid_sizes[0], 0, grid_sizes[1], 0, grid_sizes[2]), NT(0.),
87 [&](const tbb::blocked_range3d<uint, uint, uint> &r, NT value) -> NT {
88 for (uint idx_x = r.pages().begin(); idx_x != r.pages().end(); ++idx_x) {
89 const ctype q = k * sqrt(x_quadrature_p[idx_x] * x_extent);
90 const ctype int_element = (1 / (ctype)2 * powr<2>(k)) // x = q^2 / k^2 integral
91 * (k) // x0 = q0 / k integral
92 * S_2d * (1 / (ctype)2) // S_2 and divide out the cos integral
93 / powr<3>(2 * (ctype)M_PI); // fourier factor
94 for (uint idx_y = r.rows().begin(); idx_y != r.rows().end(); ++idx_y) {
95 const ctype cos = 2 * (ang_quadrature_p[idx_y] - (ctype)0.5);
96 for (uint idx_z = r.cols().begin(); idx_z != r.cols().end(); ++idx_z) {
97 const ctype q0 = k * x0_quadrature_p[idx_z] * x0_extent;
98 const ctype weight = x0_quadrature_w[idx_z] * x0_extent * 2 * ang_quadrature_w[idx_y] *
99 x_quadrature_w[idx_x] * x_extent;
100 value += int_element * weight *
101 (KERNEL::kernel(q, cos, q0, k, t...) + KERNEL::kernel(q, cos, -q0, k, t...));
102 }
103 }
104 }
105 return value;
106 },
107 [&](NT x, NT y) -> NT { return x + y; });
108 }
109
120 template <typename... T> std::future<NT> request(const ctype k, const T &...t) const
121 {
122 return std::async(std::launch::deferred, [=, this]() { return get(k, t...); });
123 }
124
125 private:
126 const std::array<uint, 3> grid_sizes;
127
130
131 const std::vector<ctype> &x_quadrature_p;
132 const std::vector<ctype> &x_quadrature_w;
133 const std::vector<ctype> &ang_quadrature_p;
134 const std::vector<ctype> &ang_quadrature_w;
135 const std::vector<ctype> &x0_quadrature_p;
136 const std::vector<ctype> &x0_quadrature_w;
137 };
138} // namespace DiFfRG
Integrator for 2+1D integrals over p, x0 and an angle using TBB. Calculates.
Definition integrator_2Dpx0_cpu.hh:25
Integrator2Dpx0TBB(QuadratureProvider &quadrature_provider, std::array< uint, 3 > grid_sizes, const ctype x_extent, const ctype x0_extent, const uint max_block_size=0)
Construct a new Integrator2Dpx0TBB object.
Definition integrator_2Dpx0_cpu.hh:56
const std::vector< ctype > & ang_quadrature_w
Definition integrator_2Dpx0_cpu.hh:134
NT get(const ctype k, const T &...t) const
Get the integral of the kernel.
Definition integrator_2Dpx0_cpu.hh:78
const ctype x_extent
Definition integrator_2Dpx0_cpu.hh:128
Integrator2Dpx0TBB(QuadratureProvider &quadrature_provider, const std::array< uint, 3 > grid_sizes, const ctype x_extent, const ctype x0_extent, const JSONValue &)
Construct a new Integrator2Dpx0TBB object.
Definition integrator_2Dpx0_cpu.hh:41
std::future< NT > request(const ctype k, const T &...t) const
Request a future for the integral of the kernel.
Definition integrator_2Dpx0_cpu.hh:120
const ctype x0_extent
Definition integrator_2Dpx0_cpu.hh:129
const std::array< uint, 3 > grid_sizes
Definition integrator_2Dpx0_cpu.hh:126
const std::vector< ctype > & x_quadrature_p
Definition integrator_2Dpx0_cpu.hh:131
const std::vector< ctype > & x0_quadrature_p
Definition integrator_2Dpx0_cpu.hh:135
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_2Dpx0_cpu.hh:30
const std::vector< ctype > & x0_quadrature_w
Definition integrator_2Dpx0_cpu.hh:136
const std::vector< ctype > & ang_quadrature_p
Definition integrator_2Dpx0_cpu.hh:133
const std::vector< ctype > & x_quadrature_w
Definition integrator_2Dpx0_cpu.hh:132
A wrapper around the boost json value class.
Definition json.hh:19
A class that provides quadrature points and weights, in host and device memory. The quadrature points...
Definition quadrature_provider.hh:139
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