OpenLB 1.7
Loading...
Searching...
No Matches
equilibrium.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 DYNAMICS_EQUILIBRIUM_H
25#define DYNAMICS_EQUILIBRIUM_H
26
27#include "lbm.h"
28#include "descriptorField.h"
30
31namespace olb {
32
33namespace equilibria {
34
35struct None {
37
38 static std::string getName() {
39 return "None";
40 }
41
42 template <typename DESCRIPTOR, typename MOMENTA>
43 struct type {
44 template <typename RHO, typename U>
45 auto compute(int iPop, const RHO& rho, const U& u) any_platform {
46 return 0;
47 }
48
49 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
50 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
51 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
52 fEq[iPop] = V{0};
53 }
54 return {0, 0};
55 };
56 };
57};
58
61
62 static std::string getName() {
63 return "ZerothOrder";
64 }
65
66 template <typename DESCRIPTOR, typename MOMENTA>
67 struct type {
68 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
69
70 template <typename RHO, typename U>
71 auto compute(int iPop, const RHO& rho, const U& u) any_platform {
72 return descriptors::t<RHO,DESCRIPTOR>(iPop) * rho - descriptors::t<RHO,DESCRIPTOR>(iPop);
73 }
74
75 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
76 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
77 const V rho = MomentaF().computeRho(cell);
78 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
79 fEq[iPop] = descriptors::t<V,DESCRIPTOR>(iPop) * rho - descriptors::t<V,DESCRIPTOR>(iPop);
80 }
81 return {rho, 0};
82 };
83 };
84};
85
86struct FirstOrder {
88
89 static std::string getName() {
90 return "FirstOrder";
91 }
92
93 template <typename DESCRIPTOR, typename MOMENTA>
94 struct type {
95 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
96
97 template <typename RHO, typename U>
98 auto compute(int iPop, const RHO& rho, const U& u) any_platform {
99 return equilibrium<DESCRIPTOR>::firstOrder(iPop, rho, u);
100 }
101
102 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
103 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
104 V rho, u[DESCRIPTOR::d];
105 MomentaF().computeRhoU(cell, rho, u);
106 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
107 fEq[iPop] = equilibrium<DESCRIPTOR>::firstOrder(iPop, rho, u);
108 }
109 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
110 };
111 };
112};
113
116
117 static std::string getName() {
118 return "SecondOrder";
119 }
120
121 template <typename DESCRIPTOR, typename MOMENTA>
122 struct type {
123 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
124
125 template <typename RHO, typename U>
126 auto compute(int iPop, const RHO& rho, const U& u) any_platform {
127 return equilibrium<DESCRIPTOR>::secondOrder(iPop, rho, u);
128 }
129
130 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
131 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
132 V rho, u[DESCRIPTOR::d];
133 MomentaF().computeRhoU(cell, rho, u);
134 const V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
135 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
136 fEq[iPop] = equilibrium<DESCRIPTOR>::secondOrder(iPop, rho, u, uSqr);
137 }
138 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
139 };
140 };
141};
142
145
146 static std::string getName() {
147 return "Incompressible";
148 }
149
150 template <typename DESCRIPTOR, typename MOMENTA>
151 struct type {
152 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
153
154 template <typename RHO, typename U, typename V=RHO>
155 auto compute(int iPop, const RHO& rho, const U& u) any_platform {
156 const V pressure = rho / descriptors::invCs2<V,DESCRIPTOR>();
157 V j[DESCRIPTOR::d] { };
158 for (unsigned iD=0; iD < DESCRIPTOR::d; ++iD) {
159 j[iD] = u[iD] * rho;
160 }
161 return equilibrium<DESCRIPTOR>::incompressible(iPop, j, pressure);
162 }
163
164 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
165 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
166 V rho, j[DESCRIPTOR::d];
167 MomentaF().computeRhoJ(cell, rho, j);
168 const V pressure = rho / descriptors::invCs2<V,DESCRIPTOR>();
169 const V jSqr = util::normSqr<V,DESCRIPTOR::d>(j);
170 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
171 fEq[iPop] = equilibrium<DESCRIPTOR>::incompressible(iPop, j, jSqr, pressure);
172 }
173 return {rho, jSqr / (rho*rho)};
174 };
175 };
176};
177
178struct P1 {
180
181 static std::string getName() {
182 return "P1";
183 }
184
185 template <typename DESCRIPTOR, typename MOMENTA>
186 struct type {
187 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
188
189 template <typename RHO, typename U>
190 auto compute(int iPop, const RHO& rho, const U& u) any_platform {
191 return equilibrium<DESCRIPTOR>::P1(iPop, rho, u);
192 }
193
194 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
195 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
196 V rho, j[DESCRIPTOR::d] { };
197 MomentaF().computeRhoJ(cell, rho, j);
198 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
199 fEq[iPop] = equilibrium<DESCRIPTOR>::P1(iPop, rho, j);
200 }
201 return {rho, 0};
202 };
203 };
204};
205
206struct Chopard {
208
210
211 static std::string getName() {
212 return "Chopard";
213 }
214
215 template <typename DESCRIPTOR, typename MOMENTA>
216 struct type {
217 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
218
219 // TODO: Use SPEED_OF_SOUND parameter
220 template <typename RHO, typename U, typename VS2, typename V=RHO>
221 auto compute(int iPop, const RHO& rho, const U& u, VS2 vs2 = V{1} / descriptors::invCs2<V,DESCRIPTOR>()) any_platform {
222 const V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
223 if (iPop==0) {
224 return rho * (V{1} - vs2 * descriptors::invCs2<V,DESCRIPTOR>()*(V{1}-descriptors::t<V,DESCRIPTOR>(0))
225 - descriptors::t<V,DESCRIPTOR>(0)/V{2}*descriptors::invCs2<V,DESCRIPTOR>()*uSqr)
226 - descriptors::t<V,DESCRIPTOR>(0);
227 }
228 else {
229 V c_u{};
230 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
231 c_u += descriptors::c<DESCRIPTOR>(iPop,iD)*u[iD];
232 }
233 return rho * descriptors::t<V,DESCRIPTOR>(iPop) * descriptors::invCs2<V,DESCRIPTOR>()
234 * (vs2 + c_u
235 + descriptors::invCs2<V,DESCRIPTOR>() / V{2} * c_u*c_u
236 - uSqr / V{2})
237 - descriptors::t<V,DESCRIPTOR>(iPop);
238 }
239 }
240
241 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
242 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
243 V rho, u[DESCRIPTOR::d] { };
244 MomentaF().computeRhoU(cell, rho, u);
245 const V vs2 = parameters.template get<SPEED_OF_SOUND>();
246 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
247 fEq[iPop] = compute(iPop, rho, u, vs2);
248 }
249 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
250 };
251 };
252};
253
254}
255
256}
257
258#endif
Interface for post-processing steps – header file.
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
Return value of any collision.
Definition interface.h:43
Base of a field whose size is defined by [C,U_1,...,U_N]^T * [1,V_1,...V_N].
typename MOMENTA::template type< DESCRIPTOR > MomentaF
auto compute(int iPop, const RHO &rho, const U &u, VS2 vs2=V{1}/descriptors::invCs2< V, DESCRIPTOR >()) any_platform
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
static std::string getName()
auto compute(int iPop, const RHO &rho, const U &u) any_platform
Definition equilibrium.h:98
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Definition equilibrium.h:95
static std::string getName()
Definition equilibrium.h:89
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
auto compute(int iPop, const RHO &rho, const U &u) any_platform
static std::string getName()
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
Definition equilibrium.h:50
auto compute(int iPop, const RHO &rho, const U &u) any_platform
Definition equilibrium.h:45
static std::string getName()
Definition equilibrium.h:38
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
auto compute(int iPop, const RHO &rho, const U &u) any_platform
static std::string getName()
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
auto compute(int iPop, const RHO &rho, const U &u) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
static std::string getName()
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
Definition equilibrium.h:76
auto compute(int iPop, const RHO &rho, const U &u) any_platform
Definition equilibrium.h:71
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Definition equilibrium.h:68
static std::string getName()
Definition equilibrium.h:62
static V incompressible(int iPop, const J &j, const JSQR &jSqr, const PRESSURE &pressure) any_platform
Definition lbm.h:87
static V P1(int iPop, const RHO &rho, const U &u) any_platform
Definition lbm.h:75
static V secondOrder(int iPop, const RHO &rho, const U &u, const USQR &uSqr) any_platform
Computation of equilibrium distribution, second order in u.
Definition lbm.h:51
static V firstOrder(int iPop, const RHO &rho, const U &u) any_platform
Computation of equilibrium distribution, first order in u.
Definition lbm.h:37
Plain wrapper for list of types.
Definition meta.h:276