ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ReactionKernelIndexed_4_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_, float order_0, float order_1, float order_2,
112 float order_3, float rate_coefficient, float stoech_0, float stoech_1,
113 float stoech_2, float stoech_3)
114 : rho_0ID(rho_0ID_), rho_1ID(rho_1ID_), rho_2ID(rho_2ID_),
115 rho_3ID(rho_3ID_), order_0_(order_0), order_1_(order_1),
116 order_2_(order_2), order_3_(order_3),
117 rate_coefficient_(rate_coefficient), stoech_0_(stoech_0),
118 stoech_1_(stoech_1), stoech_2_(stoech_2), stoech_3_(stoech_3) {
119 auto createIdxVector = [](IBlock *const, StructuredBlockStorage *const) {
120 return new IndexVectors();
121 };
122 indexVectorID = blocks->addStructuredBlockData<IndexVectors>(
123 createIdxVector, "IndexField_ReactionKernelIndexed_4_single_precision");
124 }
125
127 BlockDataID indexVectorID_, BlockDataID rho_0ID_, BlockDataID rho_1ID_,
128 BlockDataID rho_2ID_, BlockDataID rho_3ID_, float order_0, float order_1,
129 float order_2, float order_3, float rate_coefficient, float stoech_0,
130 float stoech_1, float stoech_2, float stoech_3)
131 : indexVectorID(indexVectorID_), rho_0ID(rho_0ID_), rho_1ID(rho_1ID_),
132 rho_2ID(rho_2ID_), rho_3ID(rho_3ID_), order_0_(order_0),
133 order_1_(order_1), order_2_(order_2), order_3_(order_3),
134 rate_coefficient_(rate_coefficient), stoech_0_(stoech_0),
135 stoech_1_(stoech_1), stoech_2_(stoech_2), stoech_3_(stoech_3) {}
136
137 void run(IBlock *block);
138
139 void operator()(IBlock *block) { run(block); }
140
141 void inner(IBlock *block);
142
143 void outer(IBlock *block);
144
145 Vector3<double> getForce(IBlock * /*block*/) {
146
147 WALBERLA_ABORT(
148 "Boundary condition was not generated including force calculation.")
149 return Vector3<double>(double_c(0.0));
150 }
151
152 std::function<void(IBlock *)> getSweep() {
153 return [this](IBlock *b) { this->run(b); };
154 }
155
156 std::function<void(IBlock *)> getInnerSweep() {
157 return [this](IBlock *b) { this->inner(b); };
158 }
159
160 std::function<void(IBlock *)> getOuterSweep() {
161 return [this](IBlock *b) { this->outer(b); };
162 }
163
164 template <typename FlagField_T>
165 void fillFromFlagField(const std::shared_ptr<StructuredBlockForest> &blocks,
166 ConstBlockDataID flagFieldID, FlagUID boundaryFlagUID,
167 FlagUID domainFlagUID) {
168 for (auto &block : *blocks)
169 fillFromFlagField<FlagField_T>(&block, flagFieldID, boundaryFlagUID,
170 domainFlagUID);
171 }
172
173 template <typename FlagField_T>
174 void fillFromFlagField(IBlock *block, ConstBlockDataID flagFieldID,
175 FlagUID boundaryFlagUID, FlagUID domainFlagUID) {
176 auto *indexVectors = block->getData<IndexVectors>(indexVectorID);
177 auto &indexVectorAll = indexVectors->indexVector(IndexVectors::ALL);
178 auto &indexVectorInner = indexVectors->indexVector(IndexVectors::INNER);
179 auto &indexVectorOuter = indexVectors->indexVector(IndexVectors::OUTER);
180
181 auto *flagField = block->getData<FlagField_T>(flagFieldID);
182
183 if (!(flagField->flagExists(boundaryFlagUID) and
184 flagField->flagExists(domainFlagUID)))
185 return;
186
187 auto boundaryFlag = flagField->getFlag(boundaryFlagUID);
188 auto domainFlag = flagField->getFlag(domainFlagUID);
189
190 auto inner = flagField->xyzSize();
191 inner.expand(cell_idx_t(-1));
192
193 indexVectorAll.clear();
194 indexVectorInner.clear();
195 indexVectorOuter.clear();
196
197 auto flagWithGLayers = flagField->xyzSizeWithGhostLayer();
198 for (auto it = flagField->beginWithGhostLayerXYZ(); it != flagField->end();
199 ++it) {
200
201 if (!isFlagSet(it, boundaryFlag))
202 continue;
203 if (flagWithGLayers.contains(it.x() + cell_idx_c(0),
204 it.y() + cell_idx_c(0),
205 it.z() + cell_idx_c(0)) &&
206 isFlagSet(it.neighbor(0, 0, 0, 0), domainFlag)) {
207
208 auto element = IndexInfo(it.x(), it.y(), it.z(), 0);
209
210 indexVectorAll.emplace_back(element);
211 if (inner.contains(it.x(), it.y(), it.z()))
212 indexVectorInner.emplace_back(element);
213 else
214 indexVectorOuter.emplace_back(element);
215 }
216 }
217
218 indexVectors->syncGPU();
219 }
220
221private:
222 void run_impl(IBlock *block, IndexVectors::Type type);
223
224 BlockDataID indexVectorID;
225
226public:
227 BlockDataID rho_0ID;
228 BlockDataID rho_1ID;
229 BlockDataID rho_2ID;
230 BlockDataID rho_3ID;
231 float order_0_;
232 float order_1_;
233 float order_2_;
234 float order_3_;
240};
241
242#if defined(__clang__)
243#pragma clang diagnostic pop
244#elif defined(__GNUC__) or defined(__GNUG__)
245#pragma GCC diagnostic pop
246#endif
247
248} // namespace pystencils
249} // 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_4_single_precision(BlockDataID indexVectorID_, BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_, BlockDataID rho_3ID_, float order_0, float order_1, float order_2, float order_3, float rate_coefficient, float stoech_0, float stoech_1, float stoech_2, float stoech_3)
ReactionKernelIndexed_4_single_precision(const std::shared_ptr< StructuredBlockForest > &blocks, BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_, BlockDataID rho_3ID_, float order_0, float order_1, float order_2, float order_3, float rate_coefficient, float stoech_0, float stoech_1, float stoech_2, float stoech_3)
static double * block(double *p, std::size_t index, std::size_t size)
Definition elc.cpp:176
\file PackInfoPdfDoublePrecision.cpp \author pystencils