ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ReactionKernelIndexed_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.7+13.gdfd203a, lbmpy
21// v1.3.7+10.gd3f6236, sympy v1.12.1, lbmpy_walberla/pystencils_walberla from
22// waLBerla commit e12db9965373887d86aab4aaaf4dd7b38fa588e8
23
24#pragma once
25
28
31
34
37
40
41#if defined(__CUDACC__)
42
45
48
51
54
57
58#endif
59
60#include <domain_decomposition/BlockDataID.h>
61
62#include <cstddef>
63#include <memory>
64#include <stdexcept>
65#include <utility>
66#include <vector>
67
68namespace walberla {
69namespace detail {
70namespace ReactionKernelIndexedSelector {
71
72template <typename FloatType = double, std::size_t N = 1> struct KernelTrait {
73 using ReactionKernelIndexed =
74 pystencils::ReactionKernelIndexed_1_double_precision;
75};
76
77template <> struct KernelTrait<double, 2> {
78 using ReactionKernelIndexed =
79 pystencils::ReactionKernelIndexed_2_double_precision;
80};
81
82template <> struct KernelTrait<double, 3> {
83 using ReactionKernelIndexed =
84 pystencils::ReactionKernelIndexed_3_double_precision;
85};
86
87template <> struct KernelTrait<double, 4> {
88 using ReactionKernelIndexed =
89 pystencils::ReactionKernelIndexed_4_double_precision;
90};
91
92template <> struct KernelTrait<double, 5> {
93 using ReactionKernelIndexed =
94 pystencils::ReactionKernelIndexed_5_double_precision;
95};
96
97template <> struct KernelTrait<float, 1> {
98 using ReactionKernelIndexed =
99 pystencils::ReactionKernelIndexed_1_single_precision;
100};
101
102template <> struct KernelTrait<float, 2> {
103 using ReactionKernelIndexed =
104 pystencils::ReactionKernelIndexed_2_single_precision;
105};
106
107template <> struct KernelTrait<float, 3> {
108 using ReactionKernelIndexed =
109 pystencils::ReactionKernelIndexed_3_single_precision;
110};
111
112template <> struct KernelTrait<float, 4> {
113 using ReactionKernelIndexed =
114 pystencils::ReactionKernelIndexed_4_single_precision;
115};
116
117template <> struct KernelTrait<float, 5> {
118 using ReactionKernelIndexed =
119 pystencils::ReactionKernelIndexed_5_single_precision;
120};
121
122template <typename FloatType, class Reactant, std::size_t... ints>
123auto get_kernel_impl(const std::vector<std::shared_ptr<Reactant>> &reactants,
124 const double coefficient, const BlockDataID &indexFieldID,
125 std::index_sequence<ints...> int_seq) {
126 auto kernel = std::make_shared<
127 typename KernelTrait<FloatType, int_seq.size()>::ReactionKernelIndexed>(
129 walberla::BlockDataID(
130 reactants[ints]->get_species()->get_density_id())...,
131 numeric_cast<FloatType>(reactants[ints]->get_order())...,
133 numeric_cast<FloatType>(reactants[ints]->get_stoech_coeff())...);
134
135 std::function<void(IBlock *)> sweep = [kernel](IBlock *b) { kernel->run(b); };
136 return sweep;
137}
138
139template <typename FloatType, class Reactant, class... Args>
140auto get_kernel_impl(const std::vector<std::shared_ptr<Reactant>> &reactants,
141 Args... args) {
142 switch (reactants.size()) {
143
144 case 1:
146 std::make_index_sequence<1>{});
147
148 case 2:
150 std::make_index_sequence<2>{});
151
152 case 3:
154 std::make_index_sequence<3>{});
155
156 case 4:
158 std::make_index_sequence<4>{});
159
160 case 5:
162 std::make_index_sequence<5>{});
163
164 default:
165 throw std::runtime_error("reactions of this size are not implemented!");
166 }
167}
168
169template <class Reactant, class... Args>
170auto get_kernel(const std::vector<std::shared_ptr<Reactant>> &reactants,
171 Args... args) {
172
173 const auto is_double_precision =
174 reactants[0]->get_species()->is_double_precision();
175
176 if (is_double_precision) {
178 }
179
181}
182
183#if defined(__CUDACC__)
184
185template <typename FloatType = double, std::size_t N = 1>
186struct KernelTraitGPU {
188 pystencils::ReactionKernelIndexed_1_double_precision_CUDA;
189};
190
191template <> struct KernelTraitGPU<double, 2> {
193 pystencils::ReactionKernelIndexed_2_double_precision_CUDA;
194};
195
196template <> struct KernelTraitGPU<double, 3> {
198 pystencils::ReactionKernelIndexed_3_double_precision_CUDA;
199};
200
201template <> struct KernelTraitGPU<double, 4> {
203 pystencils::ReactionKernelIndexed_4_double_precision_CUDA;
204};
205
206template <> struct KernelTraitGPU<double, 5> {
208 pystencils::ReactionKernelIndexed_5_double_precision_CUDA;
209};
210
211template <> struct KernelTraitGPU<float, 1> {
213 pystencils::ReactionKernelIndexed_1_single_precision_CUDA;
214};
215
216template <> struct KernelTraitGPU<float, 2> {
218 pystencils::ReactionKernelIndexed_2_single_precision_CUDA;
219};
220
221template <> struct KernelTraitGPU<float, 3> {
223 pystencils::ReactionKernelIndexed_3_single_precision_CUDA;
224};
225
226template <> struct KernelTraitGPU<float, 4> {
228 pystencils::ReactionKernelIndexed_4_single_precision_CUDA;
229};
230
231template <> struct KernelTraitGPU<float, 5> {
233 pystencils::ReactionKernelIndexed_5_single_precision_CUDA;
234};
235
236template <typename FloatType, class Reactant, std::size_t... ints>
238 const std::vector<std::shared_ptr<Reactant>> &reactants,
239 const double coefficient, const BlockDataID &indexFieldID,
240 std::index_sequence<ints...> int_seq) {
241 auto kernel = std::make_shared<typename KernelTraitGPU<
242 FloatType, int_seq.size()>::ReactionKernelIndexedGPU>(
244 walberla::BlockDataID(
245 reactants[ints]->get_species()->get_density_id())...,
246 numeric_cast<FloatType>(reactants[ints]->get_order())...,
248 numeric_cast<FloatType>(reactants[ints]->get_stoech_coeff())...);
249
250 std::function<void(IBlock *)> sweep = [kernel](IBlock *b) { kernel->run(b); };
251 return sweep;
252}
253
254template <typename FloatType, class Reactant, class... Args>
256 const std::vector<std::shared_ptr<Reactant>> &reactants, Args... args) {
257 switch (reactants.size()) {
258
259 case 1:
261 std::make_index_sequence<1>{});
262
263 case 2:
265 std::make_index_sequence<2>{});
266
267 case 3:
269 std::make_index_sequence<3>{});
270
271 case 4:
273 std::make_index_sequence<4>{});
274
275 case 5:
277 std::make_index_sequence<5>{});
278
279 default:
280 throw std::runtime_error("reactions of this size are not implemented!");
281 }
282}
283
284template <class Reactant, class... Args>
285auto get_kernel_gpu(const std::vector<std::shared_ptr<Reactant>> &reactants,
286 Args... args) {
287
288 const auto is_double_precision =
289 reactants[0]->get_species()->is_double_precision();
290
291 if (is_double_precision) {
293 }
294
296}
297
298#endif
299
300} // namespace ReactionKernelIndexedSelector
301} // namespace detail
302} // namespace walberla
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
\file PackInfoPdfDoublePrecision.cpp \author pystencils