ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ReactionKernelIndexed_5_single_precision.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022-2025 The ESPResSo project
3 * Copyright (C) 2020-2025 The waLBerla project
4 *
5 * This file is part of ESPResSo.
6 *
7 * ESPResSo is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * ESPResSo is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21// kernel generated with pystencils v1.4+1.ge851f4e, lbmpy v1.4+1.ge9efe34,
22// sympy v1.12.1, lbmpy_walberla/pystencils_walberla from waLBerla commit
23// 007e77e077ad9d22b5eed6f3d3118240993e553c
24
25/*
26 * Boundary class.
27 * Adapted from the waLBerla source file
28 * https://i10git.cs.fau.de/walberla/walberla/-/blob/3e54d4f2336e47168ad87e3caaf7b3b082d86ca7/python/pystencils_walberla/templates/Boundary.tmpl.h
29 */
30
31#pragma once
32
33#include <core/DataTypes.h>
34
35#include <blockforest/StructuredBlockForest.h>
36#include <core/debug/Debug.h>
37#include <domain_decomposition/BlockDataID.h>
38#include <domain_decomposition/IBlock.h>
39#include <field/FlagField.h>
40#include <field/GhostLayerField.h>
41
42#include <array>
43#include <cassert>
44#include <functional>
45#include <memory>
46#include <vector>
47
48#if defined(__clang__)
49#pragma clang diagnostic push
50#pragma clang diagnostic ignored "-Wunused-variable"
51#pragma clang diagnostic ignored "-Wunused-parameter"
52#elif defined(__GNUC__) or defined(__GNUG__)
53#pragma GCC diagnostic push
54#pragma GCC diagnostic ignored "-Wunused-variable"
55#pragma GCC diagnostic ignored "-Wunused-parameter"
56#endif
57
58#ifdef __GNUC__
59#define RESTRICT __restrict__
60#elif _MSC_VER
61#define RESTRICT __restrict
62#else
63#define RESTRICT
64#endif
65
66#ifdef WALBERLA_BUILD_WITH_HALF_PRECISION_SUPPORT
67using walberla::half;
68#endif
69
70namespace walberla {
71namespace pystencils {
72
74public:
75 struct IndexInfo {
76 int32_t x;
77 int32_t y;
78 int32_t z;
79 IndexInfo(int32_t x_, int32_t y_, int32_t z_) : x(x_), y(y_), z(z_) {}
80 bool operator==(const IndexInfo &o) const {
81 return x == o.x && y == o.y && z == o.z;
82 }
83 };
84
86 public:
87 using CpuIndexVector = std::vector<IndexInfo>;
88
89 enum Type { ALL = 0, INNER = 1, OUTER = 2, NUM_TYPES = 3 };
90
91 IndexVectors() = default;
92 bool operator==(IndexVectors const &other) const {
93 return other.cpuVectors_ == cpuVectors_;
94 }
95
96 auto &indexVector(Type t) { return cpuVectors_[t]; }
97 auto const &indexVector(Type t) const { return cpuVectors_[t]; }
99 return cpuVectors_[t].empty() ? nullptr : cpuVectors_[t].data();
100 }
101
102 void syncGPU() {}
103
104 private:
105 std::vector<CpuIndexVector> cpuVectors_{NUM_TYPES};
106 };
107
109 const std::shared_ptr<StructuredBlockForest> &blocks,
110 BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_,
111 BlockDataID rho_3ID_, BlockDataID rho_4ID_, float order_0, float order_1,
112 float order_2, float order_3, float order_4, float rate_coefficient,
113 float stoech_0, float stoech_1, float stoech_2, float stoech_3,
114 float stoech_4)
115 : rho_0ID(rho_0ID_), rho_1ID(rho_1ID_), rho_2ID(rho_2ID_),
116 rho_3ID(rho_3ID_), rho_4ID(rho_4ID_), order_0_(order_0),
117 order_1_(order_1), order_2_(order_2), order_3_(order_3),
118 order_4_(order_4), rate_coefficient_(rate_coefficient),
119 stoech_0_(stoech_0), stoech_1_(stoech_1), stoech_2_(stoech_2),
120 stoech_3_(stoech_3), stoech_4_(stoech_4) {
121 auto createIdxVector = [](IBlock *const, StructuredBlockStorage *const) {
122 return new IndexVectors();
123 };
124 indexVectorID = blocks->addStructuredBlockData<IndexVectors>(
125 createIdxVector, "IndexField_ReactionKernelIndexed_5_single_precision");
126 }
127
129 BlockDataID indexVectorID_, BlockDataID rho_0ID_, BlockDataID rho_1ID_,
130 BlockDataID rho_2ID_, BlockDataID rho_3ID_, BlockDataID rho_4ID_,
131 float order_0, float order_1, float order_2, float order_3, float order_4,
132 float rate_coefficient, float stoech_0, float stoech_1, float stoech_2,
133 float stoech_3, float stoech_4)
134 : indexVectorID(indexVectorID_), rho_0ID(rho_0ID_), rho_1ID(rho_1ID_),
135 rho_2ID(rho_2ID_), rho_3ID(rho_3ID_), rho_4ID(rho_4ID_),
136 order_0_(order_0), order_1_(order_1), order_2_(order_2),
137 order_3_(order_3), order_4_(order_4),
138 rate_coefficient_(rate_coefficient), stoech_0_(stoech_0),
139 stoech_1_(stoech_1), stoech_2_(stoech_2), stoech_3_(stoech_3),
140 stoech_4_(stoech_4) {}
141
142 void run(IBlock *block);
143
144 void operator()(IBlock *block) { run(block); }
145
146 void inner(IBlock *block);
147
148 void outer(IBlock *block);
149
150 Vector3<double> getForce(IBlock * /*block*/) {
151
152 WALBERLA_ABORT(
153 "Boundary condition was not generated including force calculation.")
154 return Vector3<double>(double_c(0.0));
155 }
156
157 std::function<void(IBlock *)> getSweep() {
158 return [this](IBlock *b) { this->run(b); };
159 }
160
161 std::function<void(IBlock *)> getInnerSweep() {
162 return [this](IBlock *b) { this->inner(b); };
163 }
164
165 std::function<void(IBlock *)> getOuterSweep() {
166 return [this](IBlock *b) { this->outer(b); };
167 }
168
169 template <typename FlagField_T>
170 void fillFromFlagField(const std::shared_ptr<StructuredBlockForest> &blocks,
171 ConstBlockDataID flagFieldID, FlagUID boundaryFlagUID,
172 FlagUID domainFlagUID) {
173 for (auto &block : *blocks)
174 fillFromFlagField<FlagField_T>(&block, flagFieldID, boundaryFlagUID,
175 domainFlagUID);
176 }
177
178 template <typename FlagField_T>
179 void fillFromFlagField(IBlock *block, ConstBlockDataID flagFieldID,
180 FlagUID boundaryFlagUID, FlagUID domainFlagUID) {
181 auto *indexVectors = block->getData<IndexVectors>(indexVectorID);
182 auto &indexVectorAll = indexVectors->indexVector(IndexVectors::ALL);
183 auto &indexVectorInner = indexVectors->indexVector(IndexVectors::INNER);
184 auto &indexVectorOuter = indexVectors->indexVector(IndexVectors::OUTER);
185
186 auto *flagField = block->getData<FlagField_T>(flagFieldID);
187
188 if (!(flagField->flagExists(boundaryFlagUID) and
189 flagField->flagExists(domainFlagUID)))
190 return;
191
192 auto boundaryFlag = flagField->getFlag(boundaryFlagUID);
193 auto domainFlag = flagField->getFlag(domainFlagUID);
194
195 auto inner = flagField->xyzSize();
196 inner.expand(cell_idx_t(-1));
197
198 indexVectorAll.clear();
199 indexVectorInner.clear();
200 indexVectorOuter.clear();
201
202 auto flagWithGLayers = flagField->xyzSizeWithGhostLayer();
203 for (auto it = flagField->beginWithGhostLayerXYZ(); it != flagField->end();
204 ++it) {
205
206 if (!isFlagSet(it, boundaryFlag))
207 continue;
208 if (flagWithGLayers.contains(it.x() + cell_idx_c(0),
209 it.y() + cell_idx_c(0),
210 it.z() + cell_idx_c(0)) &&
211 isFlagSet(it.neighbor(0, 0, 0, 0), domainFlag)) {
212
213 auto element = IndexInfo(it.x(), it.y(), it.z(), 0);
214
215 indexVectorAll.emplace_back(element);
216 if (inner.contains(it.x(), it.y(), it.z()))
217 indexVectorInner.emplace_back(element);
218 else
219 indexVectorOuter.emplace_back(element);
220 }
221 }
222
223 indexVectors->syncGPU();
224 }
225
226private:
227 void run_impl(IBlock *block, IndexVectors::Type type);
228
229 BlockDataID indexVectorID;
230
231public:
232 BlockDataID rho_0ID;
233 BlockDataID rho_1ID;
234 BlockDataID rho_2ID;
235 BlockDataID rho_3ID;
236 BlockDataID rho_4ID;
237 float order_0_;
238 float order_1_;
239 float order_2_;
240 float order_3_;
241 float order_4_;
248};
249
250#if defined(__clang__)
251#pragma clang diagnostic pop
252#elif defined(__GNUC__) or defined(__GNUG__)
253#pragma GCC diagnostic pop
254#endif
255
256} // namespace pystencils
257} // namespace walberla
void fillFromFlagField(const std::shared_ptr< StructuredBlockForest > &blocks, ConstBlockDataID flagFieldID, FlagUID boundaryFlagUID, FlagUID domainFlagUID)
void fillFromFlagField(IBlock *block, ConstBlockDataID flagFieldID, FlagUID boundaryFlagUID, FlagUID domainFlagUID)
ReactionKernelIndexed_5_single_precision(BlockDataID indexVectorID_, BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_, BlockDataID rho_3ID_, BlockDataID rho_4ID_, float order_0, float order_1, float order_2, float order_3, float order_4, float rate_coefficient, float stoech_0, float stoech_1, float stoech_2, float stoech_3, float stoech_4)
ReactionKernelIndexed_5_single_precision(const std::shared_ptr< StructuredBlockForest > &blocks, BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_, BlockDataID rho_3ID_, BlockDataID rho_4ID_, float order_0, float order_1, float order_2, float order_3, float order_4, float rate_coefficient, float stoech_0, float stoech_1, float stoech_2, float stoech_3, float stoech_4)
static double * block(double *p, std::size_t index, std::size_t size)
Definition elc.cpp:176
\file PackInfoPdfDoublePrecision.cpp \author pystencils