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.7+13.gdfd203a, lbmpy
21// v1.3.7+10.gd3f6236, sympy v1.12.1, lbmpy_walberla/pystencils_walberla from
22// waLBerla commit c69cb11d6a95d32b2280544d3d9abde1fe5fdbb5
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 ReactionKernelBulkSelector {
71
72template <typename FloatType = double, std::size_t N = 1> struct KernelTrait {
73 using ReactionKernelBulk = pystencils::ReactionKernelBulk_1_double_precision;
74};
75
76template <> struct KernelTrait<double, 2> {
77 using ReactionKernelBulk = pystencils::ReactionKernelBulk_2_double_precision;
78};
79
80template <> struct KernelTrait<double, 3> {
81 using ReactionKernelBulk = pystencils::ReactionKernelBulk_3_double_precision;
82};
83
84template <> struct KernelTrait<double, 4> {
85 using ReactionKernelBulk = pystencils::ReactionKernelBulk_4_double_precision;
86};
87
88template <> struct KernelTrait<double, 5> {
89 using ReactionKernelBulk = pystencils::ReactionKernelBulk_5_double_precision;
90};
91
92template <> struct KernelTrait<float, 1> {
93 using ReactionKernelBulk = pystencils::ReactionKernelBulk_1_single_precision;
94};
95
96template <> struct KernelTrait<float, 2> {
97 using ReactionKernelBulk = pystencils::ReactionKernelBulk_2_single_precision;
98};
99
100template <> struct KernelTrait<float, 3> {
101 using ReactionKernelBulk = pystencils::ReactionKernelBulk_3_single_precision;
102};
103
104template <> struct KernelTrait<float, 4> {
105 using ReactionKernelBulk = pystencils::ReactionKernelBulk_4_single_precision;
106};
107
108template <> struct KernelTrait<float, 5> {
109 using ReactionKernelBulk = pystencils::ReactionKernelBulk_5_single_precision;
110};
111
112template <typename FloatType, class Reactant, std::size_t... ints>
113auto get_kernel_impl(const std::vector<std::shared_ptr<Reactant>> &reactants,
114 const double coefficient,
115 std::index_sequence<ints...> int_seq) {
116 auto kernel = std::make_shared<
117 typename KernelTrait<FloatType, int_seq.size()>::ReactionKernelBulk>(
118 walberla::BlockDataID(
119 reactants[ints]->get_species()->get_density_id())...,
120 numeric_cast<FloatType>(reactants[ints]->get_order())...,
122 numeric_cast<FloatType>(reactants[ints]->get_stoech_coeff())...);
123
124 std::function<void(IBlock *)> sweep = [kernel](IBlock *b) { kernel->run(b); };
125 return sweep;
126}
127
128template <typename FloatType, class Reactant, class... Args>
129auto get_kernel_impl(const std::vector<std::shared_ptr<Reactant>> &reactants,
130 Args... args) {
131 switch (reactants.size()) {
132
133 case 1:
135 std::make_index_sequence<1>{});
136
137 case 2:
139 std::make_index_sequence<2>{});
140
141 case 3:
143 std::make_index_sequence<3>{});
144
145 case 4:
147 std::make_index_sequence<4>{});
148
149 case 5:
151 std::make_index_sequence<5>{});
152
153 default:
154 throw std::runtime_error("reactions of this size are not implemented!");
155 }
156}
157
158template <class Reactant, class... Args>
159auto get_kernel(const std::vector<std::shared_ptr<Reactant>> &reactants,
160 Args... args) {
161
162 const auto is_double_precision =
163 reactants[0]->get_species()->is_double_precision();
164
165 if (is_double_precision) {
167 }
168
170}
171
172#if defined(__CUDACC__)
173
174template <typename FloatType = double, std::size_t N = 1>
175struct KernelTraitGPU {
177 pystencils::ReactionKernelBulk_1_double_precision_CUDA;
178};
179
180template <> struct KernelTraitGPU<double, 2> {
182 pystencils::ReactionKernelBulk_2_double_precision_CUDA;
183};
184
185template <> struct KernelTraitGPU<double, 3> {
187 pystencils::ReactionKernelBulk_3_double_precision_CUDA;
188};
189
190template <> struct KernelTraitGPU<double, 4> {
192 pystencils::ReactionKernelBulk_4_double_precision_CUDA;
193};
194
195template <> struct KernelTraitGPU<double, 5> {
197 pystencils::ReactionKernelBulk_5_double_precision_CUDA;
198};
199
200template <> struct KernelTraitGPU<float, 1> {
202 pystencils::ReactionKernelBulk_1_single_precision_CUDA;
203};
204
205template <> struct KernelTraitGPU<float, 2> {
207 pystencils::ReactionKernelBulk_2_single_precision_CUDA;
208};
209
210template <> struct KernelTraitGPU<float, 3> {
212 pystencils::ReactionKernelBulk_3_single_precision_CUDA;
213};
214
215template <> struct KernelTraitGPU<float, 4> {
217 pystencils::ReactionKernelBulk_4_single_precision_CUDA;
218};
219
220template <> struct KernelTraitGPU<float, 5> {
222 pystencils::ReactionKernelBulk_5_single_precision_CUDA;
223};
224
225template <typename FloatType, class Reactant, std::size_t... ints>
227 const std::vector<std::shared_ptr<Reactant>> &reactants,
228 const double coefficient, std::index_sequence<ints...> int_seq) {
229 auto kernel = std::make_shared<typename KernelTraitGPU<
230 FloatType, int_seq.size()>::ReactionKernelBulkGPU>(
231 walberla::BlockDataID(
232 reactants[ints]->get_species()->get_density_id())...,
233 numeric_cast<FloatType>(reactants[ints]->get_order())...,
235 numeric_cast<FloatType>(reactants[ints]->get_stoech_coeff())...);
236
237 std::function<void(IBlock *)> sweep = [kernel](IBlock *b) { kernel->run(b); };
238 return sweep;
239}
240
241template <typename FloatType, class Reactant, class... Args>
243 const std::vector<std::shared_ptr<Reactant>> &reactants, Args... args) {
244 switch (reactants.size()) {
245
246 case 1:
248 std::make_index_sequence<1>{});
249
250 case 2:
252 std::make_index_sequence<2>{});
253
254 case 3:
256 std::make_index_sequence<3>{});
257
258 case 4:
260 std::make_index_sequence<4>{});
261
262 case 5:
264 std::make_index_sequence<5>{});
265
266 default:
267 throw std::runtime_error("reactions of this size are not implemented!");
268 }
269}
270
271template <class Reactant, class... Args>
272auto get_kernel_gpu(const std::vector<std::shared_ptr<Reactant>> &reactants,
273 Args... args) {
274
275 const auto is_double_precision =
276 reactants[0]->get_species()->is_double_precision();
277
278 if (is_double_precision) {
280 }
281
283}
284
285#endif
286
287} // namespace ReactionKernelBulkSelector
288} // namespace detail
289} // namespace walberla
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
\file PackInfoPdfDoublePrecision.cpp \author pystencils