OpenLB 1.7
Loading...
Searching...
No Matches
cell.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2006-2007 Jonas Latt
4 * 2015-2019 Mathias J. Krause, Adrian Kummerlaender
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
28#ifndef CELL_HH
29#define CELL_HH
30
31#include <algorithm>
32
33#include "cell.h"
34#include "util.h"
35#include "dynamics/lbm.h"
36
37#include "core/fieldArrayD.hh"
38
39namespace olb {
40
41
42template <typename T, typename DESCRIPTOR>
44 std::size_t iCell):
45 _iCell(iCell),
46 _block(const_cast<BlockLattice<T,DESCRIPTOR>&>(block)),
47 _populations{_block.getPopulationPointers(iCell)}
48{ }
49
50template <typename T, typename DESCRIPTOR>
52{
53 return _iCell;
54}
55
56template <typename T, typename DESCRIPTOR>
58{
59 return const_cast<ConstCell<T,DESCRIPTOR>&>(*this);
60}
61
62template <typename T, typename DESCRIPTOR>
63template <typename FIELD>
65{
67 "FIELD must be structured data field");
68 return _block.template getField<FIELD>().getPointer(_iCell);
69}
70
71template <typename T, typename DESCRIPTOR>
72template <typename FIELD>
74{
76 "FIELD must be structured data field");
77 return this->_block.template getField<FIELD>().getPointer(this->_iCell);
78}
79
80template <typename T, typename DESCRIPTOR>
81template <typename FIELD>
83{
85 "FIELD must be structured data field");
86 return _block.template getField<FIELD>()[iD][_iCell];
87}
88
89template <typename T, typename DESCRIPTOR>
91{
92 return ConstCell<T,DESCRIPTOR>(_block, _iCell + _block.getNeighborDistance(c));
93}
94
95template <typename T, typename DESCRIPTOR>
98 return Cell<T,DESCRIPTOR>(this->_block, this->_iCell + this->_block.getNeighborDistance(c));
100
101template <typename T, typename DESCRIPTOR>
103{
104 return *_populations[iPop];
105}
106
107template <typename T, typename DESCRIPTOR>
109{
110 return *this->_populations[iPop];
112
113template <typename T, typename DESCRIPTOR>
115{
116 return getCellId() == rhs.getCellId();
118
119template <typename T, typename DESCRIPTOR>
121{
122 return getCellId() != rhs.getCellId();
123}
125template <typename T, typename DESCRIPTOR>
127{
128 return getCellId() < rhs.getCellId();
129}
131template <typename T, typename DESCRIPTOR>
133{
134 return getCellId() <= rhs.getCellId();
135}
137template <typename T, typename DESCRIPTOR>
138template <typename FIELD>
141 return _block.template getField<FIELD>().get(_iCell);
142}
143
144template <typename T, typename DESCRIPTOR>
145template <typename FIELD>
147{
148 return this->_block.template getField<FIELD>().set(this->_iCell, field);
149}
150
151template <typename T, typename DESCRIPTOR>
152template <typename FIELD>
153std::enable_if_t<(DESCRIPTOR::template size<FIELD>() == 1), void>
154Cell<T,DESCRIPTOR>::setField(typename FIELD::template value_type<T> value)
156 return this->_block.template getField<FIELD>().set(this->_iCell,
158}
159
160template <typename T, typename DESCRIPTOR>
161template <typename FIELD>
162void Cell<T,DESCRIPTOR>::setFieldComponent(unsigned iD, typename FIELD::template value_type<T> value)
163{
164 this->_block.template getField<FIELD>()[iD][this->_iCell] = value;
166
167template<typename T, typename DESCRIPTOR>
170 return _block.getDynamics(_iCell);
171}
172
173template<typename T, typename DESCRIPTOR>
175{
176 return this->_block.getDynamics(this->_iCell);
177}
178
179template <typename T, typename DESCRIPTOR>
180template <typename FIELD>
183 auto field = getFieldPointer<FIELD>();
184 for (long unsigned int i=0; i < DESCRIPTOR::template size<FIELD>(); ++i) {
185 data[i] = field[i];
186 }
187}
189template<typename T, typename DESCRIPTOR>
191{
192 for (int iPop=1; iPop <= descriptors::q<DESCRIPTOR>()/2; ++iPop) {
193 std::swap(
194 operator[](iPop),
195 operator[](iPop+descriptors::q<DESCRIPTOR>()/2));
197}
199template<typename T, typename DESCRIPTOR>
201{
202 return getDynamics()->collide(*this);
203}
204
205template<typename T, typename DESCRIPTOR>
207{
208 return getDynamics()->computeRho(self());
209}
210
211template<typename T, typename DESCRIPTOR>
212void ConstCell<T,DESCRIPTOR>::computeU(T u[descriptors::d<DESCRIPTOR>()]) const
213{
214 getDynamics()->computeU(self(), u);
215}
216
217template<typename T, typename DESCRIPTOR>
218void ConstCell<T,DESCRIPTOR>::computeJ(T j[descriptors::d<DESCRIPTOR>()]) const
219{
220 getDynamics()->computeJ(self(), j);
221}
222
223template<typename T, typename DESCRIPTOR>
225{
226 T rho, u[descriptors::d<DESCRIPTOR>()];
227 getDynamics()->computeRhoU(self(), rho, u);
228 getDynamics()->computeStress(self(), rho, u, pi);
229}
230
231template<typename T, typename DESCRIPTOR>
232void ConstCell<T,DESCRIPTOR>::computeRhoU(T& rho, T u[descriptors::d<DESCRIPTOR>()]) const
233{
234 getDynamics()->computeRhoU(self(), rho, u);
235}
236
237template<typename T, typename DESCRIPTOR>
238void ConstCell<T,DESCRIPTOR>::computeFeq(T fEq[descriptors::q<DESCRIPTOR>()]) const
239{
240 T rho{};
242 computeRhoU(rho, u.data());
243 const T uSqr = norm_squared(u);
244 for (int iPop=0; iPop < descriptors::q<DESCRIPTOR>(); ++iPop) {
245 fEq[iPop] = lbm<DESCRIPTOR>::equilibrium(iPop, rho, u, uSqr);
246 }
247}
248
249template <typename T, typename DESCRIPTOR>
250void ConstCell<T,DESCRIPTOR>::computeFneq(T fNeq[descriptors::q<DESCRIPTOR>()]) const
251{
252 T rho{};
253 T u[descriptors::d<DESCRIPTOR>()] { };
254 computeRhoU(rho, u);
255 lbm<DESCRIPTOR>::computeFneq(self(), fNeq, rho, u);
256}
257
258template<typename T, typename DESCRIPTOR>
260 T& rho,
261 T u[descriptors::d<DESCRIPTOR>()],
263{
264 getDynamics()->computeAllMomenta(self(), rho, u, pi);
265}
266
267template<typename T, typename DESCRIPTOR>
269{
270 getDynamics()->defineRho(*this, rho);
271}
272
273template<typename T, typename DESCRIPTOR>
274void Cell<T,DESCRIPTOR>::defineU(const T u[descriptors::d<DESCRIPTOR>()])
275{
276 getDynamics()->defineU(*this, u);
277}
278
279template<typename T, typename DESCRIPTOR>
280void Cell<T,DESCRIPTOR>::defineRhoU(T rho, const T u[descriptors::d<DESCRIPTOR>()])
281{
282 getDynamics()->defineRhoU(*this, rho, u);
283}
284
285template<typename T, typename DESCRIPTOR>
287{
288 for (int iPop = 0; iPop < descriptors::q<DESCRIPTOR>(); ++iPop) {
289 operator[](iPop) = data[iPop];
290 }
291}
292
293template<typename T, typename DESCRIPTOR>
294void Cell<T,DESCRIPTOR>::iniEquilibrium(T rho, const T u[descriptors::d<DESCRIPTOR>()])
295{
296 getDynamics()->iniEquilibrium(*this, rho, u);
297}
298
299template<typename T, typename DESCRIPTOR>
301 T rho,
302 const T u[descriptors::d<DESCRIPTOR>()],
304{
305 getDynamics()->iniRegularized(*this, rho, u, pi);
306}
307
308
309}
310
311#endif
Definition of a LB cell – header file.
Platform-abstracted block lattice for external access and inter-block interaction.
Highest-level interface to Cell data.
Definition cell.h:148
auto getFieldPointer(FIELD field=FIELD())
Return field accessor.
Definition cell.hh:73
CellStatistic< T > collide()
Apply LB collision to the cell according to local dynamics.
Definition cell.hh:200
void setField(const FieldD< T, DESCRIPTOR, FIELD > &field)
Set value of FIELD from a vector.
Definition cell.hh:146
void definePopulations(const T *f_)
Define particle populations through the dynamics object.
Definition cell.hh:286
Dynamics< T, DESCRIPTOR > * getDynamics()
Get a pointer to the dynamics.
Definition cell.hh:174
void setFieldComponent(unsigned iD, typename FIELD::template value_type< T > value)
Definition cell.hh:162
Cell< T, DESCRIPTOR > neighbor(Vector< int, DESCRIPTOR::d > c)
Definition cell.hh:96
void defineU(const T u[descriptors::d< DESCRIPTOR >()])
Set fluid velocity on the cell.
Definition cell.hh:274
void defineRho(T rho)
Set density on the cell.
Definition cell.hh:268
void revert()
Revert ("bounce-back") the distribution functions.
Definition cell.hh:190
T & operator[](unsigned iPop)
Read-write access to distribution functions.
Definition cell.hh:108
void defineRhoU(T rho, const T u[descriptors::d< DESCRIPTOR >()])
Define fluid velocity and particle density on the cell.
Definition cell.hh:280
void iniRegularized(T rho, const T u[descriptors::d< DESCRIPTOR >()], const T pi[util::TensorVal< DESCRIPTOR >::n])
Initialize all f values with local equilibrium and non equilibrium part.
Definition cell.hh:300
void iniEquilibrium(T rho, const T u[descriptors::d< DESCRIPTOR >()])
Initialize all f values to their local equilibrium.
Definition cell.hh:294
Highest-level interface to read-only Cell data.
Definition cell.h:53
bool operator<=(ConstCell< T, DESCRIPTOR > &rhs) const
Definition cell.hh:132
bool operator!=(ConstCell< T, DESCRIPTOR > &rhs) const
Definition cell.hh:120
void computeJ(T j[descriptors::d< DESCRIPTOR >()]) const
Compute fluid momentum (j = rho * u) on the cell.
Definition cell.hh:218
bool operator<(ConstCell< T, DESCRIPTOR > &rhs) const
Definition cell.hh:126
bool operator==(ConstCell< T, DESCRIPTOR > &rhs) const
Definition cell.hh:114
ConstCell< T, DESCRIPTOR > neighbor(Vector< int, DESCRIPTOR::d > c) const
Definition cell.hh:90
void computeFeq(T fEq[descriptors::q< DESCRIPTOR >()]) const
Compute equilibrium part of cell distribution.
Definition cell.hh:238
void computeAllMomenta(T &rho, T u[descriptors::d< DESCRIPTOR >()], T pi[util::TensorVal< DESCRIPTOR >::n]) const
Compute all momenta on the celll, up to second order.
Definition cell.hh:259
T operator[](unsigned iPop) const
Read-only access to distribution functions.
Definition cell.hh:102
T computeRho() const
Compute particle density on the cell.
Definition cell.hh:206
void computeFneq(T fNeq[descriptors::q< DESCRIPTOR >()]) const
Compute non-equilibrium part of cell distribution.
Definition cell.hh:250
auto getFieldPointer(FIELD field=FIELD()) const
Return read-only field accessor.
Definition cell.hh:64
const Dynamics< T, DESCRIPTOR > * getDynamics() const
Get a pointer to the dynamics.
Definition cell.hh:168
void computeField(T *data) const
Copy FIELD content to given memory location.
Definition cell.hh:181
void computeRhoU(T &rho, T u[descriptors::d< DESCRIPTOR >()]) const
Compute fluid velocity and particle density on the cell.
Definition cell.hh:232
ConstCell(const BlockLattice< T, DESCRIPTOR > &block, std::size_t iCell)
Definition cell.hh:43
auto getFieldComponent(unsigned iD) const
Return copy of field component.
Definition cell.hh:82
void computeU(T u[descriptors::d< DESCRIPTOR >()]) const
Compute fluid velocity on the cell.
Definition cell.hh:212
auto getField(FIELD field=FIELD()) const
Return copy of descriptor-declared FIELD as a vector.
Definition cell.hh:139
std::size_t getCellId() const
Return memory ID of the currently represented cell.
Definition cell.hh:51
void computeStress(T pi[util::TensorVal< DESCRIPTOR >::n]) const
Compute components of the stress tensor on the cell.
Definition cell.hh:224
Plain old scalar vector.
Definition vector.h:47
std::integral_constant< bool, !is_tag_field< FIELD >::value > is_data_field
Top level namespace for all of OpenLB.
constexpr T norm_squared(const ScalarVector< T, D, IMPL > &a)
Squared euclidean vector norm.
Return value of any collision.
Definition interface.h:43
Interface for per-cell dynamics.
Definition interface.h:54
Collection of common computations for LBM.
Definition lbm.h:182
static void computeFneq(CELL &cell, FNEQ &fNeq, const RHO &rho, const U &u) any_platform
Computation of non-equilibrium distribution.
Definition lbm.h:271
Compute number of elements of a symmetric d-dimensional tensor.
Definition util.h:210
Set of functions commonly used in LB computations – header file.