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.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 ReactionKernelIndexedSelector {
52
53template <typename FloatType = double, std::size_t N = 1> struct KernelTrait {
54 using ReactionKernelIndexed =
55 pystencils::ReactionKernelIndexed_1_double_precision;
56};
57
58template <> struct KernelTrait<double, 2> {
59 using ReactionKernelIndexed =
60 pystencils::ReactionKernelIndexed_2_double_precision;
61};
62
63template <> struct KernelTrait<double, 3> {
64 using ReactionKernelIndexed =
65 pystencils::ReactionKernelIndexed_3_double_precision;
66};
67
68template <> struct KernelTrait<double, 4> {
69 using ReactionKernelIndexed =
70 pystencils::ReactionKernelIndexed_4_double_precision;
71};
72
73template <> struct KernelTrait<double, 5> {
74 using ReactionKernelIndexed =
75 pystencils::ReactionKernelIndexed_5_double_precision;
76};
77
78template <> struct KernelTrait<float, 1> {
79 using ReactionKernelIndexed =
80 pystencils::ReactionKernelIndexed_1_single_precision;
81};
82
83template <> struct KernelTrait<float, 2> {
84 using ReactionKernelIndexed =
85 pystencils::ReactionKernelIndexed_2_single_precision;
86};
87
88template <> struct KernelTrait<float, 3> {
89 using ReactionKernelIndexed =
90 pystencils::ReactionKernelIndexed_3_single_precision;
91};
92
93template <> struct KernelTrait<float, 4> {
94 using ReactionKernelIndexed =
95 pystencils::ReactionKernelIndexed_4_single_precision;
96};
97
98template <> struct KernelTrait<float, 5> {
99 using ReactionKernelIndexed =
100 pystencils::ReactionKernelIndexed_5_single_precision;
101};
102
103template <typename FloatType, class Reactant, std::size_t... ints>
104auto get_kernel_impl(const std::vector<std::shared_ptr<Reactant>> &reactants,
105 const double coefficient, const BlockDataID &indexFieldID,
106 std::index_sequence<ints...> int_seq) {
107 auto kernel = std::make_shared<
108 typename KernelTrait<FloatType, int_seq.size()>::ReactionKernelIndexed>(
109 indexFieldID,
110 walberla::BlockDataID(
111 reactants[ints]->get_species()->get_density_id())...,
112 numeric_cast<FloatType>(reactants[ints]->get_order())...,
113 numeric_cast<FloatType>(coefficient),
114 numeric_cast<FloatType>(reactants[ints]->get_stoech_coeff())...);
115
116 std::function<void(IBlock *)> sweep = [kernel](IBlock *b) { kernel->run(b); };
117 return sweep;
118}
119
120template <typename FloatType, class Reactant, class... Args>
121auto get_kernel_impl(const std::vector<std::shared_ptr<Reactant>> &reactants,
122 Args... args) {
123 switch (reactants.size()) {
124
125 case 1:
126 return get_kernel_impl<FloatType>(reactants, args...,
127 std::make_index_sequence<1>{});
128
129 case 2:
130 return get_kernel_impl<FloatType>(reactants, args...,
131 std::make_index_sequence<2>{});
132
133 case 3:
134 return get_kernel_impl<FloatType>(reactants, args...,
135 std::make_index_sequence<3>{});
136
137 case 4:
138 return get_kernel_impl<FloatType>(reactants, args...,
139 std::make_index_sequence<4>{});
140
141 case 5:
142 return get_kernel_impl<FloatType>(reactants, args...,
143 std::make_index_sequence<5>{});
144
145 default:
146 throw std::runtime_error("reactions of this size are not implemented!");
147 }
148}
149
150template <class Reactant, class... Args>
151auto get_kernel(const std::vector<std::shared_ptr<Reactant>> &reactants,
152 Args... args) {
153
154 const auto is_double_precision =
155 reactants[0]->get_species()->is_double_precision();
156
157 if (is_double_precision) {
158 return get_kernel_impl<double>(reactants, args...);
159 }
160
161 return get_kernel_impl<float>(reactants, args...);
162}
163
164} // namespace ReactionKernelIndexedSelector
165} // namespace detail
166} // namespace walberla
\file PackInfoPdfDoublePrecision.cpp \author pystencils