OpenLB 1.7
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
32namespace cpu {
33
34template <typename T, typename DESCRIPTOR, Platform PLATFORM>
35class Cell;
36
38template <typename T, typename DESCRIPTOR, Platform PLATFORM>
39struct Dynamics {
40 virtual ~Dynamics() { }
41
43
45 virtual void computeU (Cell<T,DESCRIPTOR,PLATFORM>& cell, T* u) = 0;
46 virtual void computeJ (Cell<T,DESCRIPTOR,PLATFORM>& cell, T* j) = 0;
47 virtual void computeRhoU (Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u) = 0;
48 virtual void defineRho (Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho ) = 0;
49 virtual void defineU (Cell<T,DESCRIPTOR,PLATFORM>& cell, T* u) = 0;
50 virtual void defineRhoU (Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u) = 0;
51 virtual void defineAllMomenta(Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u, T* pi) = 0;
52
53 virtual void computeStress (Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u, T* pi) = 0;
54 virtual void computeAllMomenta(Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u, T* pi) = 0;
55
56 virtual T computeEquilibrium(int iPop, T rho, T* u) = 0;
57
58 virtual T getOmegaOrFallback(T fallback) = 0;
59
61 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
62 cell[iPop] = computeEquilibrium(iPop, rho, u);
63 }
64 };
65
67 T rho, T* u, T* pi) {
68 iniEquilibrium(cell, rho, u);
69 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
70 cell[iPop] += equilibrium<DESCRIPTOR>::template fromPiToFneq<T>(iPop, pi);
71 }
72 }
73
74 virtual void inverseShiftRhoU(Cell<T,DESCRIPTOR,PLATFORM>& cell, T& rho, T* u) = 0;
75
76};
77
79template <typename T, typename DESCRIPTOR, Platform PLATFORM>
80struct DYNAMICS : public descriptors::TYPED_FIELD_BASE<Dynamics<T,DESCRIPTOR,PLATFORM>*,1> { };
81
83
86template <typename T, typename DESCRIPTOR, Platform PLATFORM>
87class Cell {
88private:
90 std::size_t _iCell;
91
92public:
93 using value_t = T;
94 using descriptor_t = DESCRIPTOR;
95
97 _lattice(nullptr),
98 _iCell(0) { }
99
100 Cell(ConcreteBlockLattice<T,DESCRIPTOR,PLATFORM>& lattice, std::size_t iCell=0):
101 _lattice(&lattice),
102 _iCell(iCell) { }
103
105 return _iCell;
106 }
107
108 void setCellId(std::size_t iCell) {
109 _iCell = iCell;
110 }
111
112 T& operator[](unsigned iPop) {
113 return _lattice->template getField<descriptors::POPULATION>()[iPop][_iCell];
114 }
115
116 template <typename FIELD>
117 auto getField() const {
118 return _lattice->template getField<FIELD>().getRow(_iCell);
119 }
120
121 template <typename FIELD>
123 return _lattice->template getField<FIELD>().setRow(_iCell, v);
124 }
125
126 template <typename FIELD>
128 return _lattice->template getField<FIELD>().getRowPointer(_iCell);
129 }
130
131 template <typename FIELD>
132 auto& getFieldComponent(unsigned iD) {
133 return _lattice->template getField<FIELD>()[iD][_iCell];
134 }
135
137 return {*_lattice, _iCell + _lattice->getNeighborDistance(offset)};
138 }
139
141 return *getFieldComponent<DYNAMICS<T,DESCRIPTOR,PLATFORM>>(0);
142 }
143
145 return getDynamics().computeRho(*this);
146 }
147 void computeU(T* u) {
148 getDynamics().computeU(*this, u);
149 }
150 void computeJ(T* j) {
151 getDynamics().computeJ(*this, j);
152 }
153 void computeRhoU(T& rho, T* u) {
154 getDynamics().computeRhoU(*this, rho, u);
155 }
156 void computeStress(T* pi) {
157 T rho, u[DESCRIPTOR::d] { };
158 getDynamics().computeRhoU(*this, rho, u);
159 getDynamics().computeStress(*this, rho, u, pi);
160 }
161 void computeAllMomenta(T& rho, T* u, T* pi) {
162 getDynamics().computeAllMomenta(*this, rho, u, pi);
163 }
164
165 void defineRho(T& rho) {
166 getDynamics().defineRho(*this, rho);
167 }
168 void defineU(T* u) {
169 getDynamics().defineU(*this, u);
170 }
171 void defineRhoU(T rho, T* u) {
172 getDynamics().defineRhoU(*this, rho, u);
173 }
174 void defineAllMomenta(T rho, T* u, T* pi) {
175 getDynamics().defineAllMomenta(*this, rho, u, pi);
176 }
177 void definePopulations(const T* f) {
178 for (int iPop=0; iPop < descriptors::q<DESCRIPTOR>(); ++iPop) {
179 operator[](iPop) = f[iPop];
180 }
181 }
182
183 void iniEquilibrium(T rho, T* u) {
184 getDynamics().iniEquilibrium(*this, rho, u);
185 }
186 void iniRegularized(T rho, T* u, T* pi) {
187 getDynamics().iniRegularized(*this, rho, u, pi);
188 }
189 void inverseShiftRhoU(T& rho, T* u) {
190 getDynamics().inverseShiftRhoU(*this, rho, u);
191 }
192
193};
194
195}
196
197}
198
199#endif
CellDistance getNeighborDistance(LatticeR< D > dir) const
Get 1D neighbor distance.
Implementation of BlockLattice on a concrete PLATFORM.
Plain old scalar vector.
Definition vector.h:47
Cell concept for concrete block lattices on CPU platforms.
Definition cell.h:87
auto getField() const
Definition cell.h:117
void defineAllMomenta(T rho, T *u, T *pi)
Definition cell.h:174
auto & getFieldComponent(unsigned iD)
Definition cell.h:132
void defineU(T *u)
Definition cell.h:168
CellID getCellId() const
Definition cell.h:104
void computeRhoU(T &rho, T *u)
Definition cell.h:153
void iniEquilibrium(T rho, T *u)
Definition cell.h:183
void computeU(T *u)
Definition cell.h:147
void computeJ(T *j)
Definition cell.h:150
Cell< T, DESCRIPTOR, PLATFORM > neighbor(LatticeR< DESCRIPTOR::d > offset)
Definition cell.h:136
auto getFieldPointer()
Definition cell.h:127
void computeAllMomenta(T &rho, T *u, T *pi)
Definition cell.h:161
void definePopulations(const T *f)
Definition cell.h:177
void defineRhoU(T rho, T *u)
Definition cell.h:171
void defineRho(T &rho)
Definition cell.h:165
Dynamics< T, DESCRIPTOR, PLATFORM > & getDynamics()
Definition cell.h:140
T computeRho()
Definition cell.h:144
void setCellId(std::size_t iCell)
Definition cell.h:108
T & operator[](unsigned iPop)
Definition cell.h:112
void computeStress(T *pi)
Definition cell.h:156
Cell(ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM > &lattice, std::size_t iCell=0)
Definition cell.h:100
void setField(const FieldD< T, DESCRIPTOR, FIELD > &v)
Definition cell.h:122
void iniRegularized(T rho, T *u, T *pi)
Definition cell.h:186
void inverseShiftRhoU(T &rho, T *u)
Definition cell.h:189
DESCRIPTOR descriptor_t
Definition cell.h:94
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:43
CPU specific field mirroring BlockDynamicsMap.
Definition cell.h:80
Virtual interface for dynamically-dispatched dynamics access on CPU targets.
Definition cell.h:39
virtual T computeEquilibrium(int iPop, T rho, T *u)=0
void iniEquilibrium(Cell< T, DESCRIPTOR, PLATFORM > &cell, T rho, T *u)
Definition cell.h:60
virtual void defineRho(Cell< T, DESCRIPTOR, PLATFORM > &cell, T &rho)=0
virtual ~Dynamics()
Definition cell.h:40
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:66
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
Base of a descriptor field of scalar TYPE with dimensions A*B + B*Q + C.