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