41#include <domain_decomposition/BlockDataID.h>
51namespace ReactionKernelBulkSelector {
53template <
typename FloatType =
double, std::
size_t N = 1>
struct KernelTrait {
54 using ReactionKernelBulk = pystencils::ReactionKernelBulk_1_double_precision;
57template <>
struct KernelTrait<double, 2> {
58 using ReactionKernelBulk = pystencils::ReactionKernelBulk_2_double_precision;
61template <>
struct KernelTrait<double, 3> {
62 using ReactionKernelBulk = pystencils::ReactionKernelBulk_3_double_precision;
65template <>
struct KernelTrait<double, 4> {
66 using ReactionKernelBulk = pystencils::ReactionKernelBulk_4_double_precision;
69template <>
struct KernelTrait<double, 5> {
70 using ReactionKernelBulk = pystencils::ReactionKernelBulk_5_double_precision;
73template <>
struct KernelTrait<float, 1> {
74 using ReactionKernelBulk = pystencils::ReactionKernelBulk_1_single_precision;
77template <>
struct KernelTrait<float, 2> {
78 using ReactionKernelBulk = pystencils::ReactionKernelBulk_2_single_precision;
81template <>
struct KernelTrait<float, 3> {
82 using ReactionKernelBulk = pystencils::ReactionKernelBulk_3_single_precision;
85template <>
struct KernelTrait<float, 4> {
86 using ReactionKernelBulk = pystencils::ReactionKernelBulk_4_single_precision;
89template <>
struct KernelTrait<float, 5> {
90 using ReactionKernelBulk = pystencils::ReactionKernelBulk_5_single_precision;
93template <
typename FloatType,
class Reactant, std::size_t... ints>
94auto get_kernel_impl(
const std::vector<std::shared_ptr<Reactant>> &reactants,
95 const double coefficient,
96 std::index_sequence<ints...> int_seq) {
97 auto kernel = std::make_shared<
98 typename KernelTrait<FloatType, int_seq.size()>::ReactionKernelBulk>(
99 walberla::BlockDataID(
100 reactants[ints]->get_species()->get_density_id())...,
101 numeric_cast<FloatType>(reactants[ints]->get_order())...,
102 numeric_cast<FloatType>(coefficient),
103 numeric_cast<FloatType>(reactants[ints]->get_stoech_coeff())...);
105 std::function<void(IBlock *)> sweep = [kernel](IBlock *b) { kernel->run(b); };
109template <
typename FloatType,
class Reactant,
class... Args>
110auto get_kernel_impl(
const std::vector<std::shared_ptr<Reactant>> &reactants,
112 switch (reactants.size()) {
115 return get_kernel_impl<FloatType>(reactants, args...,
116 std::make_index_sequence<1>{});
119 return get_kernel_impl<FloatType>(reactants, args...,
120 std::make_index_sequence<2>{});
123 return get_kernel_impl<FloatType>(reactants, args...,
124 std::make_index_sequence<3>{});
127 return get_kernel_impl<FloatType>(reactants, args...,
128 std::make_index_sequence<4>{});
131 return get_kernel_impl<FloatType>(reactants, args...,
132 std::make_index_sequence<5>{});
135 throw std::runtime_error(
"reactions of this size are not implemented!");
139template <
class Reactant,
class... Args>
140auto get_kernel(
const std::vector<std::shared_ptr<Reactant>> &reactants,
143 const auto is_double_precision =
144 reactants[0]->get_species()->is_double_precision();
146 if (is_double_precision) {
147 return get_kernel_impl<double>(reactants, args...);
150 return get_kernel_impl<float>(reactants, args...);
\file PackInfoPdfDoublePrecision.cpp \author pystencils