ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ReactionKernelBulk_all.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022-2023 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20// kernel generated with pystencils v1.3.3, lbmpy v1.3.3,
21// lbmpy_walberla/pystencils_walberla from waLBerla commit
22// b0842e1a493ce19ef1bbb8d2cf382fc343970a7f
23
24#pragma once
25
28
31
34
37
40
41#include <domain_decomposition/BlockDataID.h>
42
43#include <cstddef>
44#include <memory>
45#include <stdexcept>
46#include <utility>
47#include <vector>
48
49namespace walberla {
50namespace detail {
51namespace ReactionKernelBulkSelector {
52
53template <typename FloatType = double, std::size_t N = 1> struct KernelTrait {
54 using ReactionKernelBulk = pystencils::ReactionKernelBulk_1_double_precision;
55};
56
57template <> struct KernelTrait<double, 2> {
58 using ReactionKernelBulk = pystencils::ReactionKernelBulk_2_double_precision;
59};
60
61template <> struct KernelTrait<double, 3> {
62 using ReactionKernelBulk = pystencils::ReactionKernelBulk_3_double_precision;
63};
64
65template <> struct KernelTrait<double, 4> {
66 using ReactionKernelBulk = pystencils::ReactionKernelBulk_4_double_precision;
67};
68
69template <> struct KernelTrait<double, 5> {
70 using ReactionKernelBulk = pystencils::ReactionKernelBulk_5_double_precision;
71};
72
73template <> struct KernelTrait<float, 1> {
74 using ReactionKernelBulk = pystencils::ReactionKernelBulk_1_single_precision;
75};
76
77template <> struct KernelTrait<float, 2> {
78 using ReactionKernelBulk = pystencils::ReactionKernelBulk_2_single_precision;
79};
80
81template <> struct KernelTrait<float, 3> {
82 using ReactionKernelBulk = pystencils::ReactionKernelBulk_3_single_precision;
83};
84
85template <> struct KernelTrait<float, 4> {
86 using ReactionKernelBulk = pystencils::ReactionKernelBulk_4_single_precision;
87};
88
89template <> struct KernelTrait<float, 5> {
90 using ReactionKernelBulk = pystencils::ReactionKernelBulk_5_single_precision;
91};
92
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())...);
104
105 std::function<void(IBlock *)> sweep = [kernel](IBlock *b) { kernel->run(b); };
106 return sweep;
107}
108
109template <typename FloatType, class Reactant, class... Args>
110auto get_kernel_impl(const std::vector<std::shared_ptr<Reactant>> &reactants,
111 Args... args) {
112 switch (reactants.size()) {
113
114 case 1:
115 return get_kernel_impl<FloatType>(reactants, args...,
116 std::make_index_sequence<1>{});
117
118 case 2:
119 return get_kernel_impl<FloatType>(reactants, args...,
120 std::make_index_sequence<2>{});
121
122 case 3:
123 return get_kernel_impl<FloatType>(reactants, args...,
124 std::make_index_sequence<3>{});
125
126 case 4:
127 return get_kernel_impl<FloatType>(reactants, args...,
128 std::make_index_sequence<4>{});
129
130 case 5:
131 return get_kernel_impl<FloatType>(reactants, args...,
132 std::make_index_sequence<5>{});
133
134 default:
135 throw std::runtime_error("reactions of this size are not implemented!");
136 }
137}
138
139template <class Reactant, class... Args>
140auto get_kernel(const std::vector<std::shared_ptr<Reactant>> &reactants,
141 Args... args) {
142
143 const auto is_double_precision =
144 reactants[0]->get_species()->is_double_precision();
145
146 if (is_double_precision) {
147 return get_kernel_impl<double>(reactants, args...);
148 }
149
150 return get_kernel_impl<float>(reactants, args...);
151}
152
153} // namespace ReactionKernelBulkSelector
154} // namespace detail
155} // namespace walberla