DiFfRG
Loading...
Searching...
No Matches
integrator_4D_2ang_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{
25 template <typename NT, typename KERNEL> class Integrator4D2AngTBB
26 {
27 public:
31 using ctype = typename get_type::ctype<NT>;
32
33 Integrator4D2AngTBB(QuadratureProvider &quadrature_provider, const std::array<uint, 3> grid_sizes,
34 const ctype x_extent, const JSONValue &)
35 : Integrator4D2AngTBB(quadrature_provider, grid_sizes, x_extent)
36 {
37 }
38
39 Integrator4D2AngTBB(QuadratureProvider &quadrature_provider, std::array<uint, 3> grid_sizes, const ctype x_extent,
40 const uint max_block_size = 0)
42 x_quadrature_p(quadrature_provider.get_points<ctype>(grid_sizes[0])),
43 x_quadrature_w(quadrature_provider.get_weights<ctype>(grid_sizes[0])),
44 ang_quadrature_p1(quadrature_provider.get_points<ctype>(grid_sizes[1])),
45 ang_quadrature_w1(quadrature_provider.get_weights<ctype>(grid_sizes[1])),
46 ang_quadrature_p2(quadrature_provider.get_points<ctype>(grid_sizes[2])),
47 ang_quadrature_w2(quadrature_provider.get_weights<ctype>(grid_sizes[2]))
48 {
49 (void)max_block_size;
50 }
51
62 template <typename... T> NT get(const ctype k, const T &...t) const
63 {
64 using std::sqrt;
65
66 const auto constant = KERNEL::constant(k, t...);
67 return constant +
68 tbb::parallel_reduce(
69 tbb::blocked_range3d<uint, uint, uint>(0, grid_sizes[0], 0, grid_sizes[1], 0, grid_sizes[2]), NT(0),
70 [&](const tbb::blocked_range3d<uint, uint, uint> &r, NT value) -> NT {
71 for (uint idx_x = r.pages().begin(); idx_x != r.pages().end(); ++idx_x) {
72 const ctype q = k * sqrt(x_quadrature_p[idx_x] * x_extent);
73 for (uint idx_y = r.rows().begin(); idx_y != r.rows().end(); ++idx_y) {
74 const ctype cos1 = 2 * (ang_quadrature_p1[idx_y] - (ctype)0.5);
75 const ctype int_element = 2 * (ctype)M_PI *
76 (powr<2>(q) * (ctype)0.5 * powr<2>(k)) // x = p^2 / k^2 integral
77 * sqrt(1. - powr<2>(cos1)) // cos1 integral jacobian
78 / powr<4>(2 * (ctype)M_PI); // fourier factor
79 for (uint idx_z = r.cols().begin(); idx_z != r.cols().end(); ++idx_z) {
80 const ctype cos2 = 2 * (ang_quadrature_p2[idx_z] - (ctype)0.5);
81 const ctype weight = 2 * ang_quadrature_w2[idx_z] // cos2 weight
82 * 2 * ang_quadrature_w1[idx_y] // cos1 weight
83 * x_quadrature_w[idx_x] * x_extent; // x weight
84 value += int_element * weight * KERNEL::kernel(q, cos1, cos2, k, t...);
85 }
86 }
87 }
88 return value;
89 },
90 [&](NT x, NT y) -> NT { return x + y; });
91 }
92
103 template <typename... T> std::future<NT> request(const ctype k, const T &...t) const
104 {
105 return std::async(std::launch::deferred, [=, this]() { return get(k, t...); });
106 }
107
108 private:
109 const std::array<uint, 3> grid_sizes;
110
112
113 const std::vector<ctype> &x_quadrature_p;
114 const std::vector<ctype> &x_quadrature_w;
115 const std::vector<ctype> &ang_quadrature_p1;
116 const std::vector<ctype> &ang_quadrature_w1;
117 const std::vector<ctype> &ang_quadrature_p2;
118 const std::vector<ctype> &ang_quadrature_w2;
119 };
120} // namespace DiFfRG
Integrator for the integration of a 4D function with two angles with CUDA. Calculates.
Definition integrator_4D_2ang_cpu.hh:26
const std::vector< ctype > & ang_quadrature_p2
Definition integrator_4D_2ang_cpu.hh:117
Integrator4D2AngTBB(QuadratureProvider &quadrature_provider, std::array< uint, 3 > grid_sizes, const ctype x_extent, const uint max_block_size=0)
Definition integrator_4D_2ang_cpu.hh:39
const std::vector< ctype > & ang_quadrature_w2
Definition integrator_4D_2ang_cpu.hh:118
Integrator4D2AngTBB(QuadratureProvider &quadrature_provider, const std::array< uint, 3 > grid_sizes, const ctype x_extent, const JSONValue &)
Definition integrator_4D_2ang_cpu.hh:33
const std::vector< ctype > & x_quadrature_w
Definition integrator_4D_2ang_cpu.hh:114
std::future< NT > request(const ctype k, const T &...t) const
Request a future for the integral of the kernel.
Definition integrator_4D_2ang_cpu.hh:103
const std::array< uint, 3 > grid_sizes
Definition integrator_4D_2ang_cpu.hh:109
const ctype x_extent
Definition integrator_4D_2ang_cpu.hh:111
typename get_type::ctype< NT > ctype
Numerical type to be used for integration tasks e.g. the argument or possible jacobians.
Definition integrator_4D_2ang_cpu.hh:31
const std::vector< ctype > & ang_quadrature_p1
Definition integrator_4D_2ang_cpu.hh:115
NT get(const ctype k, const T &...t) const
Get the integral of the kernel.
Definition integrator_4D_2ang_cpu.hh:62
const std::vector< ctype > & ang_quadrature_w1
Definition integrator_4D_2ang_cpu.hh:116
const std::vector< ctype > & x_quadrature_p
Definition integrator_4D_2ang_cpu.hh:113
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