OpenLB 1.8.1
Loading...
Searching...
No Matches
cell.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef CORE_PLATFORM_CPU_CELL_H
25#define CORE_PLATFORM_CPU_CELL_H
26
27#include "dynamics/lbm.h"
28
29namespace olb {
30
31template <typename T, typename DESCRIPTOR, Platform PLATFORM>
33
35namespace cpu {
36
37template <typename T, typename DESCRIPTOR, Platform PLATFORM>
38class Cell;
39
41template <typename T, typename DESCRIPTOR, Platform PLATFORM>
42struct Dynamics {
43 virtual ~Dynamics() { }
44
46
48 virtual void computeU (Cell<T,DESCRIPTOR,PLATFORM>& cell, T* u) = 0;
49 virtual void computeJ (Cell<T,DESCRIPTOR,PLATFORM>& cell, T* j) = 0;
50 virtual void computeRhoU (Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u) = 0;
51 virtual void defineRho (Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho ) = 0;
52 virtual void defineU (Cell<T,DESCRIPTOR,PLATFORM>& cell, T* u) = 0;
53 virtual void defineRhoU (Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u) = 0;
54 virtual void defineAllMomenta(Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u, T* pi) = 0;
55
56 virtual void computeStress (Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u, T* pi) = 0;
57 virtual void computeAllMomenta(Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u, T* pi) = 0;
58
59 virtual void computeEquilibrium(Cell<T,DESCRIPTOR,PLATFORM>& cell, T rho, T* u, T* fEq) = 0;
60
61 virtual T getOmegaOrFallback(T fallback) = 0;
62
64 T fEq[DESCRIPTOR::q] { };
65 computeEquilibrium(cell, rho, u, fEq);
66 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
67 cell[iPop] = fEq[iPop];
68 }
69 };
70
72 T rho, T* u, T* pi) {
73 iniEquilibrium(cell, rho, u);
74 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
75 cell[iPop] += equilibrium<DESCRIPTOR>::template fromPiToFneq<T>(iPop, pi);
76 }
77 }
78
79 virtual void inverseShiftRhoU(Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u) = 0;
80
81};
82
84template <typename T, typename DESCRIPTOR, Platform PLATFORM>
85class Row {
86private:
88 CellID _iCell;
89
90public:
91 using value_t = T;
92 using descriptor_t = DESCRIPTOR;
93
94 Row():
95 _lattice(nullptr),
96 _iCell(0) { }
97
99 _lattice(&lattice),
100 _iCell(iCell) { }
101
103 return _iCell;
104 }
105
106 void setCellId(CellID iCell) {
107 _iCell = iCell;
108 }
109
110 template <typename FIELD>
111 auto getField() const {
112 return _lattice->template getField<FIELD>().getRow(_iCell);
113 }
114
115 template <typename FIELD>
117 return _lattice->template getField<FIELD>().setRow(_iCell, v);
118 }
119
120 template <typename FIELD>
122 return _lattice->template getField<FIELD>().getRowPointer(_iCell);
123 }
124
125 template <typename FIELD>
126 auto& getFieldComponent(unsigned iD) {
127 return _lattice->template getField<FIELD>()[iD][_iCell];
128 }
129
130};
131
133template <typename T, typename DESCRIPTOR, Platform PLATFORM>
134struct DYNAMICS : public descriptors::TYPED_FIELD_BASE<Dynamics<T,DESCRIPTOR,PLATFORM>*,1> { };
135
137
140template <typename T, typename DESCRIPTOR, Platform PLATFORM>
141class Cell {
142private:
144 CellID _iCell;
145
146public:
147 using value_t = T;
148 using descriptor_t = DESCRIPTOR;
149
151 _lattice(nullptr),
152 _iCell(0) { }
153
154 Cell(ConcreteBlockLattice<T,DESCRIPTOR,PLATFORM>& lattice, std::size_t iCell=0):
155 _lattice(&lattice),
156 _iCell(iCell) { }
157
159 return _iCell;
160 }
161
162 void setCellId(CellID iCell) {
163 _iCell = iCell;
164 }
165
167 _iCell = _lattice->getCellId(latticeR);
168 }
169
170 bool isPadding() const {
171 return _lattice->isPadding(_iCell);
172 }
173
174 T& operator[](unsigned iPop) {
175 return _lattice->template getField<descriptors::POPULATION>()[iPop][_iCell];
176 }
177
178 template <typename FIELD>
179 auto getField() const {
180 return _lattice->template getField<FIELD>().getRow(_iCell);
181 }
182
183 template <typename FIELD>
185 return _lattice->template getField<FIELD>().setRow(_iCell, v);
186 }
187
188 template <typename FIELD>
190 return _lattice->template getField<FIELD>().getRowPointer(_iCell);
191 }
192
193 template <typename FIELD>
194 auto& getFieldComponent(unsigned iD) {
195 return _lattice->template getField<FIELD>()[iD][_iCell];
196 }
197
199 return {*_lattice, static_cast<std::size_t>(_iCell + _lattice->getNeighborDistance(offset))};
200 }
201
205
207 return getDynamics().computeRho(*this);
208 }
209 void computeU(T* u) {
210 getDynamics().computeU(*this, u);
211 }
212 void computeJ(T* j) {
213 getDynamics().computeJ(*this, j);
214 }
215 void computeRhoU(T& rho, T* u) {
216 getDynamics().computeRhoU(*this, rho, u);
217 }
218 void computeStress(T* pi) {
219 T rho, u[DESCRIPTOR::d] { };
220 getDynamics().computeRhoU(*this, rho, u);
221 getDynamics().computeStress(*this, rho, u, pi);
222 }
223 void computeAllMomenta(T& rho, T* u, T* pi) {
224 getDynamics().computeAllMomenta(*this, rho, u, pi);
225 }
226
227 void defineRho(T& rho) {
228 getDynamics().defineRho(*this, rho);
229 }
230 void defineU(T* u) {
231 getDynamics().defineU(*this, u);
232 }
233 void defineRhoU(T rho, T* u) {
234 getDynamics().defineRhoU(*this, rho, u);
235 }
236 void defineAllMomenta(T rho, T* u, T* pi) {
237 getDynamics().defineAllMomenta(*this, rho, u, pi);
238 }
239 void definePopulations(const T* f) {
240 for (int iPop=0; iPop < descriptors::q<DESCRIPTOR>(); ++iPop) {
241 operator[](iPop) = f[iPop];
242 }
243 }
244
245 void iniEquilibrium(T rho, T* u) {
246 getDynamics().iniEquilibrium(*this, rho, u);
247 }
248 void iniRegularized(T rho, T* u, T* pi) {
249 getDynamics().iniRegularized(*this, rho, u, pi);
250 }
251 void inverseShiftRhoU(T& rho, T* u) {
252 getDynamics().inverseShiftRhoU(*this, rho, u);
253 }
254
255};
256
257template <typename T, typename DESCRIPTOR, Platform PLATFORM>
259private:
261 CellID _iCell;
262
263public:
264 using value_t = T;
265 using descriptor_t = DESCRIPTOR;
266
268 _lattice(nullptr),
269 _iCell(0) { }
270
271 PlainCell(ConcreteBlockD<T,DESCRIPTOR,PLATFORM>& lattice, std::size_t iCell=0):
272 _lattice(&lattice),
273 _iCell(iCell) { }
274
276 return _iCell;
277 }
278
279 void setCellId(CellID iCell) {
280 _iCell = iCell;
281 }
282
283 T& operator[](unsigned iPop) {
284 return _lattice->template getField<descriptors::POPULATION>()[iPop][_iCell];
285 }
286
287 template <typename FIELD>
288 auto getField() const {
289 return _lattice->template getField<FIELD>().getRow(_iCell);
290 }
291
292 template <typename FIELD>
294 return _lattice->template getField<FIELD>().setRow(_iCell, v);
295 }
296
297 template <typename FIELD>
299 return _lattice->template getField<FIELD>().getRowPointer(_iCell);
300 }
301
302 template <typename FIELD>
303 auto& getFieldComponent(unsigned iD) {
304 return _lattice->template getField<FIELD>()[iD][_iCell];
305 }
306
308 return {*_lattice, _iCell + _lattice->getNeighborDistance(offset)};
309 }
310
311};
312
313}
314
315}
316
317#endif
CellDistance getNeighborDistance(LatticeR< D > dir) const
Get 1D neighbor distance.
bool isPadding(LatticeR< D > latticeR) const
Return whether location is valid.
CellID getCellId(LatticeR< D > latticeR) const
Get 1D cell ID.
Implementation of BlockD on a concrete PLATFORM.
Definition cell.h:32
Implementation of BlockLattice on a concrete PLATFORM.
Plain old scalar vector.
Cell concept for concrete block lattices on CPU platforms.
Definition cell.h:141
auto getField() const
Definition cell.h:179
void defineAllMomenta(T rho, T *u, T *pi)
Definition cell.h:236
void setLatticeR(LatticeR< DESCRIPTOR::d > latticeR)
Definition cell.h:166
auto & getFieldComponent(unsigned iD)
Definition cell.h:194
void defineU(T *u)
Definition cell.h:230
CellID getCellId() const
Definition cell.h:158
void computeRhoU(T &rho, T *u)
Definition cell.h:215
void iniEquilibrium(T rho, T *u)
Definition cell.h:245
void setCellId(CellID iCell)
Definition cell.h:162
void computeU(T *u)
Definition cell.h:209
void computeJ(T *j)
Definition cell.h:212
Cell< T, DESCRIPTOR, PLATFORM > neighbor(LatticeR< DESCRIPTOR::d > offset)
Definition cell.h:198
auto getFieldPointer()
Definition cell.h:189
void computeAllMomenta(T &rho, T *u, T *pi)
Definition cell.h:223
void definePopulations(const T *f)
Definition cell.h:239
void defineRhoU(T rho, T *u)
Definition cell.h:233
void defineRho(T &rho)
Definition cell.h:227
Dynamics< T, DESCRIPTOR, PLATFORM > & getDynamics()
Definition cell.h:202
bool isPadding() const
Definition cell.h:170
T computeRho()
Definition cell.h:206
T & operator[](unsigned iPop)
Definition cell.h:174
void computeStress(T *pi)
Definition cell.h:218
Cell(ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > &lattice, std::size_t iCell=0)
Definition cell.h:154
void setField(const FieldD< T, DESCRIPTOR, FIELD > &v)
Definition cell.h:184
void iniRegularized(T rho, T *u, T *pi)
Definition cell.h:248
void inverseShiftRhoU(T &rho, T *u)
Definition cell.h:251
DESCRIPTOR descriptor_t
Definition cell.h:148
DESCRIPTOR descriptor_t
Definition cell.h:265
auto getField() const
Definition cell.h:288
void setField(const FieldD< T, DESCRIPTOR, FIELD > &v)
Definition cell.h:293
auto & getFieldComponent(unsigned iD)
Definition cell.h:303
Cell< T, DESCRIPTOR, PLATFORM > neighbor(LatticeR< DESCRIPTOR::d > offset)
Definition cell.h:307
void setCellId(CellID iCell)
Definition cell.h:279
T & operator[](unsigned iPop)
Definition cell.h:283
CellID getCellId() const
Definition cell.h:275
auto getFieldPointer()
Definition cell.h:298
PlainCell(ConcreteBlockD< T, DESCRIPTOR, PLATFORM > &lattice, std::size_t iCell=0)
Definition cell.h:271
Row concept for concrete non-LBM lattices on CPU platforms.
Definition cell.h:85
DESCRIPTOR descriptor_t
Definition cell.h:92
Row(ConcreteBlockD< T, DESCRIPTOR, PLATFORM > &lattice, CellID iCell=0)
Definition cell.h:98
CellID getCellId() const
Definition cell.h:102
auto & getFieldComponent(unsigned iD)
Definition cell.h:126
auto getField() const
Definition cell.h:111
void setField(const FieldD< T, DESCRIPTOR, FIELD > &v)
Definition cell.h:116
auto getFieldPointer()
Definition cell.h:121
void setCellId(CellID iCell)
Definition cell.h:106
Top level namespace for all of OpenLB.
std::uint32_t CellID
Type for sequential block-local cell indices.
Return value of any collision.
Definition interface.h:45
CPU specific field mirroring BlockDynamicsMap.
Definition cell.h:134
Virtual interface for dynamically-dispatched dynamics access on CPU targets.
Definition cell.h:42
void iniEquilibrium(Cell< T, DESCRIPTOR, PLATFORM > &cell, T rho, T *u)
Definition cell.h:63
virtual void defineRho(Cell< T, DESCRIPTOR, PLATFORM > &cell, T &rho)=0
virtual ~Dynamics()
Definition cell.h:43
virtual void inverseShiftRhoU(Cell< T, DESCRIPTOR, PLATFORM > &cell, T &rho, T *u)=0
void iniRegularized(Cell< T, DESCRIPTOR, PLATFORM > &cell, T rho, T *u, T *pi)
Definition cell.h:71
virtual void defineU(Cell< T, DESCRIPTOR, PLATFORM > &cell, T *u)=0
virtual void computeU(Cell< T, DESCRIPTOR, PLATFORM > &cell, T *u)=0
virtual void computeStress(Cell< T, DESCRIPTOR, PLATFORM > &cell, T &rho, T *u, T *pi)=0
virtual void defineRhoU(Cell< T, DESCRIPTOR, PLATFORM > &cell, T &rho, T *u)=0
virtual void computeRhoU(Cell< T, DESCRIPTOR, PLATFORM > &cell, T &rho, T *u)=0
virtual void defineAllMomenta(Cell< T, DESCRIPTOR, PLATFORM > &cell, T &rho, T *u, T *pi)=0
virtual void computeJ(Cell< T, DESCRIPTOR, PLATFORM > &cell, T *j)=0
virtual void computeAllMomenta(Cell< T, DESCRIPTOR, PLATFORM > &cell, T &rho, T *u, T *pi)=0
virtual T getOmegaOrFallback(T fallback)=0
virtual T computeRho(Cell< T, DESCRIPTOR, PLATFORM > &cell)=0
virtual CellStatistic< T > collide(Cell< T, DESCRIPTOR, PLATFORM > &cell)=0
virtual void computeEquilibrium(Cell< T, DESCRIPTOR, PLATFORM > &cell, T rho, T *u, T *fEq)=0
Base of a descriptor field of scalar TYPE.
Definition fields.h:132