OpenLB 1.8.1
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 "descriptor/fields.h"
29
30namespace olb {
31
32template<typename T> struct CellStatistic;
33
34namespace equilibria {
35
36struct None {
38
39 static std::string getName() {
40 return "None";
41 }
42
43 template <typename DESCRIPTOR, typename MOMENTA>
44 struct type {
45 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
46
47 template <typename CELL, typename RHO, typename U, typename FEQ, typename V=typename CELL::value_t>
48 CellStatistic<V> compute(CELL& cell, RHO& rho, U& u, FEQ& fEq) any_platform {
49 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
50 fEq[iPop] = V{0};
51 }
52 return {0, 0};
53 };
54
55 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
56 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
57 V rho, u[DESCRIPTOR::d];
58 MomentaF().computeRhoU(cell, rho, u);
59 return compute(cell, rho, u, fEq);
60 };
61 };
62};
63
66
67 static std::string getName() {
68 return "ZerothOrder";
69 }
70
71 template <typename DESCRIPTOR, typename MOMENTA>
72 struct type {
73 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
74
75 template <typename CELL, typename RHO, typename U, typename FEQ, typename V=typename CELL::value_t>
76 CellStatistic<V> compute(CELL& cell, RHO& rho, U& u, FEQ& fEq) any_platform {
77 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
78 fEq[iPop] = descriptors::t<V,DESCRIPTOR>(iPop) * rho - descriptors::t<V,DESCRIPTOR>(iPop);
79 }
80 return {rho, 0};
81 };
82
83 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
84 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
85 V rho, u[DESCRIPTOR::d];
86 MomentaF().computeRhoU(cell, rho, u);
87 return compute(cell, rho, u, fEq);
88 };
89 };
90};
91
94
95 static std::string getName() {
96 return "CahnHilliardZerothOrder";
97 }
98
99 template <typename DESCRIPTOR, typename MOMENTA>
100 struct type {
101 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
102
103 template <typename CELL, typename RHO, typename U, typename FEQ, typename V=typename CELL::value_t>
104 CellStatistic<V> compute(CELL& cell, RHO& rho, U& u, FEQ& fEq) any_platform {
105 const auto mu = cell.template getField<descriptors::CHEM_POTENTIAL>();
107 for (int iPop=1; iPop < DESCRIPTOR::q; ++iPop) {
109 }
110 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
111 }
112
113 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
114 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
115 V rho, u[DESCRIPTOR::d];
116 MomentaF().computeRhoU(cell, rho, u);
117 return compute(cell, rho, u, fEq);
118 };
119 };
120};
121
124
125 static std::string getName() {
126 return "FirstOrder";
127 }
128
129 template <typename DESCRIPTOR, typename MOMENTA>
130 struct type {
131 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
132
133 template <typename CELL, typename RHO, typename U, typename FEQ, typename V=typename CELL::value_t>
134 CellStatistic<V> compute(CELL& cell, RHO& rho, U& u, FEQ& fEq) any_platform {
135 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
136 fEq[iPop] = equilibrium<DESCRIPTOR>::firstOrder(iPop, rho, u);
137 }
138 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
139 };
140
141 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
142 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
143 V rho, u[DESCRIPTOR::d];
144 MomentaF().computeRhoU(cell, rho, u);
145 return compute(cell, rho, u, fEq);
146 };
147 };
148};
149
152
153 static std::string getName() {
154 return "SecondOrder";
155 }
156
157 template <typename DESCRIPTOR, typename MOMENTA>
158 struct type {
159 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
160
161 template <typename CELL, typename RHO, typename U, typename FEQ, typename V=typename CELL::value_t>
162 CellStatistic<V> compute(CELL& cell, RHO& rho, U& u, FEQ& fEq) any_platform {
163 const V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
164 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
165 fEq[iPop] = equilibrium<DESCRIPTOR>::secondOrder(iPop, rho, u, uSqr);
166 }
167 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
168 };
169
170 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
171 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
172 V rho, u[DESCRIPTOR::d];
173 MomentaF().computeRhoU(cell, rho, u);
174 return compute(cell, rho, u, fEq);
175 };
176 };
177};
178
181
182 static std::string getName() {
183 return "ThirdOrder";
184 }
185
186 template <typename DESCRIPTOR, typename MOMENTA>
187 struct type {
188 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
189
190 template <typename CELL, typename RHO, typename U, typename FEQ, typename V=typename CELL::value_t>
191 CellStatistic<V> compute(CELL& cell, RHO& rho, U& u, FEQ& fEq) any_platform {
192 const V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
193 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
194 fEq[iPop] = equilibrium<DESCRIPTOR>::thirdOrder(iPop, rho, u, uSqr);
195 }
196 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
197 };
198
199 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
200 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
201 V rho, u[DESCRIPTOR::d];
202 MomentaF().computeRhoU(cell, rho, u);
203 return compute(cell, rho, u, fEq);
204 };
205 };
206};
207
210
211 static std::string getName() {
212 return "Incompressible";
213 }
214
215 template <typename DESCRIPTOR, typename MOMENTA>
216 struct type {
217 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
218
219 template <typename CELL, typename RHO, typename J, typename FEQ, typename V=typename CELL::value_t>
220 CellStatistic<V> compute(CELL& cell, RHO& rho, J& j, FEQ& fEq) any_platform {
221 const V pressure = rho / descriptors::invCs2<V,DESCRIPTOR>();
222 const V jSqr = util::normSqr<V,DESCRIPTOR::d>(j);
223 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
224 fEq[iPop] = equilibrium<DESCRIPTOR>::incompressible(iPop, j, jSqr, pressure);
225 }
226 return {rho, jSqr / (rho*rho)};
227 };
228
229 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
230 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
231 V rho, j[DESCRIPTOR::d];
232 MomentaF().computeRhoJ(cell, rho, j);
233 return compute(cell, rho, j, fEq);
234 };
235 };
236};
237
240
241 static std::string getName() {
242 return "Multi-Phase-Incompressible";
243 }
244
245 template <typename DESCRIPTOR, typename MOMENTA>
246 struct type {
247 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
248
249 template <typename CELL, typename P, typename U, typename FEQ, typename V=typename CELL::value_t>
250 CellStatistic<V> compute(CELL& cell, P& p, U& u, FEQ& fEq) any_platform {
251 const auto rho = cell.template getField<descriptors::RHO>();
252 const V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
253 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
254 fEq[iPop] = equilibrium<DESCRIPTOR>::mpincompressible(iPop, rho, u, uSqr, p);
255 }
256 return {rho, uSqr};
257 };
258
259 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
260 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
261 V p, u[DESCRIPTOR::d];
262 MomentaF().computeRhoU(cell, p, u);
263 return compute(cell, p, u, fEq);
264 };
265 };
266};
267
268struct P1 {
270
271 static std::string getName() {
272 return "P1";
273 }
274
275 template <typename DESCRIPTOR, typename MOMENTA>
276 struct type {
277 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
278
279 template <typename CELL, typename RHO, typename J, typename FEQ, typename V=typename CELL::value_t>
280 CellStatistic<V> compute(CELL& cell, RHO& rho, J& j, FEQ& fEq) any_platform {
281 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
282 fEq[iPop] = equilibrium<DESCRIPTOR>::P1(iPop, rho, j);
283 }
284 return {rho, 0};
285 };
286
287 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
288 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
289 V rho, j[DESCRIPTOR::d];
290 MomentaF().computeRhoJ(cell, rho, j);
291 return compute(cell, rho, j, fEq);
292 };
293 };
294};
295
296struct Chopard {
298
300
301 static std::string getName() {
302 return "Chopard";
303 }
304
305 template <typename DESCRIPTOR, typename MOMENTA>
306 struct type {
307 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
308
309 template <typename CELL, typename RHO, typename U, typename FEQ, typename VS2, typename V=typename CELL::value_t>
310 CellStatistic<V> compute(CELL& cell, RHO& rho, U& u, FEQ& fEq, VS2 vs2 = V{1} / descriptors::invCs2<V,DESCRIPTOR>()) any_platform {
311 const V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
312 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
313 if (iPop==0) {
314 return rho * (V{1} - vs2 * descriptors::invCs2<V,DESCRIPTOR>()*(V{1}-descriptors::t<V,DESCRIPTOR>(0))
317 }
318 else {
319 V c_u{};
320 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
321 c_u += descriptors::c<DESCRIPTOR>(iPop,iD)*u[iD];
322 }
324 * (vs2 + c_u
325 + descriptors::invCs2<V,DESCRIPTOR>() / V{2} * c_u*c_u
326 - uSqr / V{2})
328 }
329 }
330 return {rho, uSqr};
331 };
332
333 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
334 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
335 V rho, u[DESCRIPTOR::d];
336 MomentaF().computeRhoU(cell, rho, u);
337 const V vs2 = parameters.template get<SPEED_OF_SOUND>();
338 const V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
339 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
340 if (iPop==0) {
341 return rho * (V{1} - vs2 * descriptors::invCs2<V,DESCRIPTOR>()*(V{1}-descriptors::t<V,DESCRIPTOR>(0))
344 }
345 else {
346 V c_u{};
347 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
348 c_u += descriptors::c<DESCRIPTOR>(iPop,iD)*u[iD];
349 }
351 * (vs2 + c_u
352 + descriptors::invCs2<V,DESCRIPTOR>() / V{2} * c_u*c_u
353 - uSqr / V{2})
355 }
356 }
357 return {rho, uSqr};
358 };
359 };
360};
361
362}
363
364}
365
366#endif
constexpr T invCs2() any_platform
Definition functions.h:107
constexpr T t(unsigned iPop, tag::CUM) any_platform
Definition cum.h:108
constexpr int c(unsigned iPop, unsigned iDim) any_platform
Definition functions.h:83
auto normSqr(const ARRAY_LIKE &u) any_platform
Compute norm square of a d-dimensional vector.
Definition util.h:145
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77
Return value of any collision.
Definition interface.h:45
Base of a field whose size is defined by [C_0,C_1,C_2]^T * [1,D,Q].
Definition fields.h:52
CellStatistic< V > compute(CELL &cell, RHO &rho, U &u, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
CellStatistic< V > compute(CELL &cell, RHO &rho, U &u, FEQ &fEq, VS2 vs2=V{1}/descriptors::invCs2< V, DESCRIPTOR >()) any_platform
static std::string getName()
CellStatistic< V > compute(CELL &cell, RHO &rho, U &u, FEQ &fEq) any_platform
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
static std::string getName()
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > compute(CELL &cell, RHO &rho, J &j, FEQ &fEq) any_platform
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
static std::string getName()
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
CellStatistic< V > compute(CELL &cell, P &p, U &u, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Definition equilibrium.h:45
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
Definition equilibrium.h:56
CellStatistic< V > compute(CELL &cell, RHO &rho, U &u, FEQ &fEq) any_platform
Definition equilibrium.h:48
static std::string getName()
Definition equilibrium.h:39
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > compute(CELL &cell, RHO &rho, J &j, FEQ &fEq) any_platform
static std::string getName()
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > compute(CELL &cell, RHO &rho, U &u, FEQ &fEq) any_platform
static std::string getName()
CellStatistic< V > compute(CELL &cell, RHO &rho, U &u, FEQ &fEq) any_platform
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
static std::string getName()
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
Definition equilibrium.h:84
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Definition equilibrium.h:73
CellStatistic< V > compute(CELL &cell, RHO &rho, U &u, FEQ &fEq) any_platform
Definition equilibrium.h:76
static std::string getName()
Definition equilibrium.h:67
static V incompressible(int iPop, const J &j, const JSQR &jSqr, const PRESSURE &pressure) any_platform
Definition lbm.h:146
static V thirdOrder(int iPop, const RHO &rho, const U &u, const USQR &uSqr) any_platform
Computation of equilibrium distribution, third order in u.
Definition lbm.h:75
static V P1(int iPop, const RHO &rho, const U &u) any_platform
Definition lbm.h:134
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 mpincompressible(int iPop, const RHO &rho, const U &u, const USQR &uSqr, const PRESSURE &pressure) any_platform
Definition lbm.h:167
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