ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ReactionKernelIndexed_4_double_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.3, lbmpy v1.3.3,
22// lbmpy_walberla/pystencils_walberla from waLBerla commit
23// b0842e1a493ce19ef1bbb8d2cf382fc343970a7f
24
25/*
26 * Boundary class.
27 * Adapted from the waLBerla source file
28 * https://i10git.cs.fau.de/walberla/walberla/-/blob/fb076cd18daa6e2f24448349d1fffb974c845269/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
64#endif
65
66namespace walberla {
67namespace pystencils {
68
70public:
71 struct IndexInfo {
72 int32_t x;
73 int32_t y;
74 int32_t z;
75 IndexInfo(int32_t x_, int32_t y_, int32_t z_) : x(x_), y(y_), z(z_) {}
76 bool operator==(const IndexInfo &o) const {
77 return x == o.x && y == o.y && z == o.z;
78 }
79 };
80
82 public:
83 using CpuIndexVector = std::vector<IndexInfo>;
84
85 enum Type { ALL = 0, INNER = 1, OUTER = 2, NUM_TYPES = 3 };
86
87 IndexVectors() = default;
88 bool operator==(IndexVectors const &other) const {
89 return other.cpuVectors_ == cpuVectors_;
90 }
91
92 CpuIndexVector &indexVector(Type t) { return cpuVectors_[t]; }
93 IndexInfo *pointerCpu(Type t) { return cpuVectors_[t].data(); }
94
95 void syncGPU() {}
96
97 private:
98 std::vector<CpuIndexVector> cpuVectors_{NUM_TYPES};
99 };
100
102 const std::shared_ptr<StructuredBlockForest> &blocks,
103 BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_,
104 BlockDataID rho_3ID_, double order_0, double order_1, double order_2,
105 double order_3, double rate_coefficient, double stoech_0, double stoech_1,
106 double stoech_2, double stoech_3)
107 : rho_0ID(rho_0ID_), rho_1ID(rho_1ID_), rho_2ID(rho_2ID_),
108 rho_3ID(rho_3ID_), order_0_(order_0), order_1_(order_1),
109 order_2_(order_2), order_3_(order_3),
110 rate_coefficient_(rate_coefficient), stoech_0_(stoech_0),
111 stoech_1_(stoech_1), stoech_2_(stoech_2), stoech_3_(stoech_3) {
112 auto createIdxVector = [](IBlock *const, StructuredBlockStorage *const) {
113 return new IndexVectors();
114 };
115 indexVectorID = blocks->addStructuredBlockData<IndexVectors>(
116 createIdxVector, "IndexField_ReactionKernelIndexed_4_double_precision");
117 };
118
120 BlockDataID indexVectorID_, BlockDataID rho_0ID_, BlockDataID rho_1ID_,
121 BlockDataID rho_2ID_, BlockDataID rho_3ID_, double order_0,
122 double order_1, double order_2, double order_3, double rate_coefficient,
123 double stoech_0, double stoech_1, double stoech_2, double stoech_3)
124 : indexVectorID(indexVectorID_), rho_0ID(rho_0ID_), rho_1ID(rho_1ID_),
125 rho_2ID(rho_2ID_), rho_3ID(rho_3ID_), order_0_(order_0),
126 order_1_(order_1), order_2_(order_2), order_3_(order_3),
127 rate_coefficient_(rate_coefficient), stoech_0_(stoech_0),
128 stoech_1_(stoech_1), stoech_2_(stoech_2), stoech_3_(stoech_3){};
129
130 void run(IBlock *block);
131
132 void operator()(IBlock *block) { run(block); }
133
134 void inner(IBlock *block);
135
136 void outer(IBlock *block);
137
138 std::function<void(IBlock *)> getSweep() {
139 return [this](IBlock *b) { this->run(b); };
140 }
141
142 std::function<void(IBlock *)> getInnerSweep() {
143 return [this](IBlock *b) { this->inner(b); };
144 }
145
146 std::function<void(IBlock *)> getOuterSweep() {
147 return [this](IBlock *b) { this->outer(b); };
148 }
149
150 template <typename FlagField_T>
151 void fillFromFlagField(const std::shared_ptr<StructuredBlockForest> &blocks,
152 ConstBlockDataID flagFieldID, FlagUID boundaryFlagUID,
153 FlagUID domainFlagUID) {
154 for (auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt)
155 fillFromFlagField<FlagField_T>(&*blockIt, flagFieldID, boundaryFlagUID,
156 domainFlagUID);
157 }
158
159 template <typename FlagField_T>
160 void fillFromFlagField(IBlock *block, ConstBlockDataID flagFieldID,
161 FlagUID boundaryFlagUID, FlagUID domainFlagUID) {
162 auto *indexVectors = block->getData<IndexVectors>(indexVectorID);
163 auto &indexVectorAll = indexVectors->indexVector(IndexVectors::ALL);
164 auto &indexVectorInner = indexVectors->indexVector(IndexVectors::INNER);
165 auto &indexVectorOuter = indexVectors->indexVector(IndexVectors::OUTER);
166
167 auto *flagField = block->getData<FlagField_T>(flagFieldID);
168
169 assert(flagField->flagExists(boundaryFlagUID) and
170 flagField->flagExists(domainFlagUID));
171
172 auto boundaryFlag = flagField->getFlag(boundaryFlagUID);
173 auto domainFlag = flagField->getFlag(domainFlagUID);
174
175 auto inner = flagField->xyzSize();
176 inner.expand(cell_idx_t(-1));
177
178 indexVectorAll.clear();
179 indexVectorInner.clear();
180 indexVectorOuter.clear();
181
182 auto flagWithGLayers = flagField->xyzSizeWithGhostLayer();
183 for (auto it = flagField->beginWithGhostLayerXYZ(); it != flagField->end();
184 ++it) {
185
186 if (!isFlagSet(it, boundaryFlag))
187 continue;
188 if (flagWithGLayers.contains(it.x() + cell_idx_c(0),
189 it.y() + cell_idx_c(0),
190 it.z() + cell_idx_c(0)) &&
191 isFlagSet(it.neighbor(0, 0, 0, 0), domainFlag)) {
192
193 auto element = IndexInfo(it.x(), it.y(), it.z(), 0);
194
195 indexVectorAll.push_back(element);
196 if (inner.contains(it.x(), it.y(), it.z()))
197 indexVectorInner.push_back(element);
198 else
199 indexVectorOuter.push_back(element);
200 }
201 }
202
203 indexVectors->syncGPU();
204 }
205
206private:
207 void run_impl(IBlock *block, IndexVectors::Type type);
208
209 BlockDataID indexVectorID;
210
211public:
212 BlockDataID rho_0ID;
213 BlockDataID rho_1ID;
214 BlockDataID rho_2ID;
215 BlockDataID rho_3ID;
216 double order_0_;
217 double order_1_;
218 double order_2_;
219 double order_3_;
221 double stoech_0_;
222 double stoech_1_;
223 double stoech_2_;
224 double stoech_3_;
225};
226
227} // namespace pystencils
228} // namespace walberla
ReactionKernelIndexed_4_double_precision(const std::shared_ptr< StructuredBlockForest > &blocks, BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_, BlockDataID rho_3ID_, double order_0, double order_1, double order_2, double order_3, double rate_coefficient, double stoech_0, double stoech_1, double stoech_2, double stoech_3)
void fillFromFlagField(IBlock *block, ConstBlockDataID flagFieldID, FlagUID boundaryFlagUID, FlagUID domainFlagUID)
void fillFromFlagField(const std::shared_ptr< StructuredBlockForest > &blocks, ConstBlockDataID flagFieldID, FlagUID boundaryFlagUID, FlagUID domainFlagUID)
ReactionKernelIndexed_4_double_precision(BlockDataID indexVectorID_, BlockDataID rho_0ID_, BlockDataID rho_1ID_, BlockDataID rho_2ID_, BlockDataID rho_3ID_, double order_0, double order_1, double order_2, double order_3, double rate_coefficient, double stoech_0, double stoech_1, double stoech_2, double stoech_3)
static double * block(double *p, std::size_t index, std::size_t size)
Definition elc.cpp:172
\file PackInfoPdfDoublePrecision.cpp \author pystencils