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) 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_H
29#define CELL_H
30
31#include <type_traits>
32
33#include "util.h"
34#include "meta.h"
35#include "utilities/aliases.h"
36
37#include "fieldArrayD.h"
38
39namespace olb {
40
41template<typename T> struct CellStatistic;
42template<typename T> class LatticeStatistics;
43template<typename T, typename DESCRIPTOR> struct Dynamics;
44template<typename T, typename DESCRIPTOR> class BlockLattice;
45template<typename T, typename DESCRIPTOR> class Cell;
46
48
52template<typename T, typename DESCRIPTOR>
53class ConstCell {
54private:
55 ConstCell<T,DESCRIPTOR>& self() const;
56
57protected:
59
61 std::size_t _iCell;
65
75
76public:
77 using value_t = T;
78 using descriptor_t = DESCRIPTOR;
79
81 std::size_t iCell);
82
84 std::size_t getCellId() const;
85
87
90 void setCellId(std::size_t iCell)
91 {
92 _iCell = iCell;
93 _populations = _block.getPopulationPointers(iCell);
94 }
95
96 bool operator==(ConstCell<T,DESCRIPTOR>& rhs) const;
97 bool operator!=(ConstCell<T,DESCRIPTOR>& rhs) const;
98 bool operator< (ConstCell<T,DESCRIPTOR>& rhs) const;
99 bool operator<=(ConstCell<T,DESCRIPTOR>& rhs) const;
100
102
104
107 T operator[](unsigned iPop) const;
108
110 template <typename FIELD>
111 auto getFieldPointer(FIELD field = FIELD()) const;
113 template <typename FIELD>
114 auto getFieldComponent(unsigned iD) const;
116 template <typename FIELD>
117 auto getField(FIELD field = FIELD()) const;
118
120 const Dynamics<T,DESCRIPTOR>* getDynamics() const;
121
123 template <typename FIELD>
124 void computeField(T* data) const;
126 T computeRho() const;
128 void computeU(T u[descriptors::d<DESCRIPTOR>()]) const;
130 void computeJ(T j[descriptors::d<DESCRIPTOR>()]) const;
134 void computeRhoU(T& rho, T u[descriptors::d<DESCRIPTOR>()]) const;
136 void computeFeq(T fEq[descriptors::q<DESCRIPTOR>()]) const;
138 void computeFneq(T fNeq[descriptors::q<DESCRIPTOR>()]) const;
141 T& rho, T u[descriptors::d<DESCRIPTOR>()],
143
144};
145
147template<typename T, typename DESCRIPTOR>
148class Cell : public ConstCell<T,DESCRIPTOR> {
149public:
151 std::size_t iCell):
152 ConstCell<T,DESCRIPTOR>(block, iCell)
153 { }
154
156
158
161 T& operator[](unsigned iPop);
162
164 template <typename FIELD>
165 auto getFieldPointer(FIELD field = FIELD());
166
168 template <typename FIELD>
169 void setField(const FieldD<T,DESCRIPTOR,FIELD>& field);
171 template <typename FIELD>
172 std::enable_if_t<(DESCRIPTOR::template size<FIELD>() == 1), void>
173 setField(typename FIELD::template value_type<T> value);
174
175 template <typename FIELD>
176 void setFieldComponent(unsigned iD, typename FIELD::template value_type<T> value);
177
180
182 void revert();
183
186
188 void defineRho(T rho);
190 void defineU(const T u[descriptors::d<DESCRIPTOR>()]);
192 void defineRhoU(T rho, const T u[descriptors::d<DESCRIPTOR>()]);
194 void definePopulations(const T* f_);
196 void iniEquilibrium(T rho, const T u[descriptors::d<DESCRIPTOR>()]);
198 void iniRegularized(T rho, const T u[descriptors::d<DESCRIPTOR>()], const T pi[util::TensorVal<DESCRIPTOR >::n]);
199
200};
201
202}
203
204#endif
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
Cell(BlockLattice< T, DESCRIPTOR > &block, std::size_t iCell)
Definition cell.h:150
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
BlockLattice< T, DESCRIPTOR > & _block
Underlying BlockLattice.
Definition cell.h:63
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
std::size_t _iCell
Memory ID of currently represented cell.
Definition cell.h:61
void setCellId(std::size_t iCell)
Jump to arbitrary cell memory ID.
Definition cell.h:90
void computeFneq(T fNeq[descriptors::q< DESCRIPTOR >()]) const
Compute non-equilibrium part of cell distribution.
Definition cell.hh:250
Vector< T *, DESCRIPTOR::q > _populations
Pointers to population values of current cell.
Definition cell.h:74
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
DESCRIPTOR descriptor_t
Definition cell.h:78
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
Top level namespace for all of OpenLB.
Return value of any collision.
Definition interface.h:43
Interface for per-cell dynamics.
Definition interface.h:54
Compute number of elements of a symmetric d-dimensional tensor.
Definition util.h:210
Set of functions commonly used in LB computations – header file.