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-2023 The ESPResSo project
3 * Copyright (C) 2020-2023 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.3.7+13.gdfd203a, lbmpy
22// v1.3.7+10.gd3f6236, sympy v1.12.1, lbmpy_walberla/pystencils_walberla from
23// waLBerla commit e12db9965373887d86aab4aaaf4dd7b38fa588e8
24
25/*
26 * Boundary class.
27 * Adapted from the waLBerla source file
28 * https://i10git.cs.fau.de/walberla/walberla/-/blob/e12db9965373887d86aab4aaaf4dd7b38fa588e8/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 <cassert>
43#include <functional>
44#include <memory>
45#include <vector>
46
47#if defined(__clang__)
48#pragma clang diagnostic push
49#pragma clang diagnostic ignored "-Wunused-variable"
50#pragma clang diagnostic ignored "-Wunused-parameter"
51#elif defined(__GNUC__) or defined(__GNUG__)
52#pragma GCC diagnostic push
53#pragma GCC diagnostic ignored "-Wunused-variable"
54#pragma GCC diagnostic ignored "-Wunused-parameter"
55#endif
56
57#ifdef __GNUC__
58#define RESTRICT __restrict__
59#elif _MSC_VER
60#define RESTRICT __restrict
61#else
62#define RESTRICT
63#endif
64
65#ifdef WALBERLA_BUILD_WITH_HALF_PRECISION_SUPPORT
66using walberla::half;
67#endif
68
69namespace walberla {
70namespace pystencils {
71
73public:
74 struct IndexInfo {
75 int32_t x;
76 int32_t y;
77 int32_t z;
78 IndexInfo(int32_t x_, int32_t y_, int32_t z_) : x(x_), y(y_), z(z_) {}
79 bool operator==(const IndexInfo &o) const {
80 return x == o.x && y == o.y && z == o.z;
81 }
82 };
83
85 public:
86 using CpuIndexVector = std::vector<IndexInfo>;
87
88 enum Type { ALL = 0, INNER = 1, OUTER = 2, NUM_TYPES = 3 };
89
90 IndexVectors() = default;
91 bool operator==(IndexVectors const &other) const {
92 return other.cpuVectors_ == cpuVectors_;
93 }
94
95 CpuIndexVector &indexVector(Type t) { return cpuVectors_[t]; }
97 return cpuVectors_[t].empty() ? nullptr : cpuVectors_[t].data();
98 }
99
100 void syncGPU() {}
101
102 private:
103 std::vector<CpuIndexVector> cpuVectors_{NUM_TYPES};
104 };
105
107 const std::shared_ptr<StructuredBlockForest> &blocks,
108 BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_,
109 BlockDataID rho_3ID_, BlockDataID rho_4ID_, float order_0, float order_1,
110 float order_2, float order_3, float order_4, float rate_coefficient,
111 float stoech_0, float stoech_1, float stoech_2, float stoech_3,
112 float stoech_4)
113 : rho_0ID(rho_0ID_), rho_1ID(rho_1ID_), rho_2ID(rho_2ID_),
114 rho_3ID(rho_3ID_), rho_4ID(rho_4ID_), order_0_(order_0),
115 order_1_(order_1), order_2_(order_2), order_3_(order_3),
116 order_4_(order_4), rate_coefficient_(rate_coefficient),
117 stoech_0_(stoech_0), stoech_1_(stoech_1), stoech_2_(stoech_2),
118 stoech_3_(stoech_3), stoech_4_(stoech_4) {
119 auto createIdxVector = [](IBlock *const, StructuredBlockStorage *const) {
120 return new IndexVectors();
121 };
122 indexVectorID = blocks->addStructuredBlockData<IndexVectors>(
123 createIdxVector, "IndexField_ReactionKernelIndexed_5_single_precision");
124 }
125
127 BlockDataID indexVectorID_, BlockDataID rho_0ID_, BlockDataID rho_1ID_,
128 BlockDataID rho_2ID_, BlockDataID rho_3ID_, BlockDataID rho_4ID_,
129 float order_0, float order_1, float order_2, float order_3, float order_4,
130 float rate_coefficient, float stoech_0, float stoech_1, float stoech_2,
131 float stoech_3, float stoech_4)
132 : indexVectorID(indexVectorID_), rho_0ID(rho_0ID_), rho_1ID(rho_1ID_),
133 rho_2ID(rho_2ID_), rho_3ID(rho_3ID_), rho_4ID(rho_4ID_),
134 order_0_(order_0), order_1_(order_1), order_2_(order_2),
135 order_3_(order_3), order_4_(order_4),
136 rate_coefficient_(rate_coefficient), stoech_0_(stoech_0),
137 stoech_1_(stoech_1), stoech_2_(stoech_2), stoech_3_(stoech_3),
138 stoech_4_(stoech_4) {}
139
140 void run(IBlock *block);
141
142 void operator()(IBlock *block) { run(block); }
143
144 void inner(IBlock *block);
145
146 void outer(IBlock *block);
147
148 Vector3<real_t> getForce(IBlock * /*block*/) {
149
150 WALBERLA_ABORT(
151 "Boundary condition was not generated including force calculation.")
152 return Vector3<real_t>(real_c(0.0));
153 }
154
155 std::function<void(IBlock *)> getSweep() {
156 return [this](IBlock *b) { this->run(b); };
157 }
158
159 std::function<void(IBlock *)> getInnerSweep() {
160 return [this](IBlock *b) { this->inner(b); };
161 }
162
163 std::function<void(IBlock *)> getOuterSweep() {
164 return [this](IBlock *b) { this->outer(b); };
165 }
166
167 template <typename FlagField_T>
168 void fillFromFlagField(const std::shared_ptr<StructuredBlockForest> &blocks,
169 ConstBlockDataID flagFieldID, FlagUID boundaryFlagUID,
170 FlagUID domainFlagUID) {
171 for (auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt)
172 fillFromFlagField<FlagField_T>(&*blockIt, flagFieldID, boundaryFlagUID,
173 domainFlagUID);
174 }
175
176 template <typename FlagField_T>
177 void fillFromFlagField(IBlock *block, ConstBlockDataID flagFieldID,
178 FlagUID boundaryFlagUID, FlagUID domainFlagUID) {
179 auto *indexVectors = block->getData<IndexVectors>(indexVectorID);
180 auto &indexVectorAll = indexVectors->indexVector(IndexVectors::ALL);
181 auto &indexVectorInner = indexVectors->indexVector(IndexVectors::INNER);
182 auto &indexVectorOuter = indexVectors->indexVector(IndexVectors::OUTER);
183
184 auto *flagField = block->getData<FlagField_T>(flagFieldID);
185
186 if (!(flagField->flagExists(boundaryFlagUID) and
187 flagField->flagExists(domainFlagUID)))
188 return;
189
190 auto boundaryFlag = flagField->getFlag(boundaryFlagUID);
191 auto domainFlag = flagField->getFlag(domainFlagUID);
192
193 auto inner = flagField->xyzSize();
194 inner.expand(cell_idx_t(-1));
195
196 indexVectorAll.clear();
197 indexVectorInner.clear();
198 indexVectorOuter.clear();
199
200 auto flagWithGLayers = flagField->xyzSizeWithGhostLayer();
201 for (auto it = flagField->beginWithGhostLayerXYZ(); it != flagField->end();
202 ++it) {
203
204 if (!isFlagSet(it, boundaryFlag))
205 continue;
206 if (flagWithGLayers.contains(it.x() + cell_idx_c(0),
207 it.y() + cell_idx_c(0),
208 it.z() + cell_idx_c(0)) &&
209 isFlagSet(it.neighbor(0, 0, 0, 0), domainFlag)) {
210
211 auto element = IndexInfo(it.x(), it.y(), it.z(), 0);
212
213 indexVectorAll.emplace_back(element);
214 if (inner.contains(it.x(), it.y(), it.z()))
215 indexVectorInner.emplace_back(element);
216 else
217 indexVectorOuter.emplace_back(element);
218 }
219 }
220
221 indexVectors->syncGPU();
222 }
223
224private:
225 void run_impl(IBlock *block, IndexVectors::Type type);
226
227 BlockDataID indexVectorID;
228
229public:
230 BlockDataID rho_0ID;
231 BlockDataID rho_1ID;
232 BlockDataID rho_2ID;
233 BlockDataID rho_3ID;
234 BlockDataID rho_4ID;
235 float order_0_;
236 float order_1_;
237 float order_2_;
238 float order_3_;
239 float order_4_;
246};
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_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