OpenLB 1.7
Loading...
Searching...
No Matches
forcing.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_FORCING_H
25#define DYNAMICS_FORCING_H
26
27#include "lbm.h"
28#include "descriptorField.h"
30
31namespace olb {
32
34namespace forcing {
35
37template <template <typename> typename Forced = momenta::Forced>
38struct Guo {
39 static std::string getName() {
40 return "GuoForcing";
41 }
42
43 template <typename DESCRIPTOR, typename MOMENTA>
44 using combined_momenta = typename Forced<MOMENTA>::template type<DESCRIPTOR>;
45
46 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
47 using combined_equilibrium = typename EQUILIBRIUM::template type<DESCRIPTOR,Forced<MOMENTA>>;
48
49 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
51 using MomentaF = typename Forced<MOMENTA>::template type<DESCRIPTOR>;
52 using CollisionO = typename COLLISION::template type<DESCRIPTOR,Forced<MOMENTA>,EQUILIBRIUM>;
53
54 static_assert(COLLISION::parameters::template contains<descriptors::OMEGA>(),
55 "COLLISION must be parametrized using relaxation frequency OMEGA");
56
57 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
58 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
59 V rho, u[DESCRIPTOR::d];
60 MomentaF().computeRhoU(cell, rho, u);
61 CollisionO().apply(cell, parameters);
62 const V omega = parameters.template get<descriptors::OMEGA>();
63 const auto force = cell.template getField<descriptors::FORCE>();
64 lbm<DESCRIPTOR>::addExternalForce(cell, rho, u, omega, force);
65 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
66 };
67 };
68
69 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
70 using combined_parameters = typename COLLISION::parameters;
71};
72
74//template <template <typename> typename Sourced = momenta::Sourced>
75struct AdeGuo {
76 static std::string getName() {
77 return "AdeGuoForcing";
78 }
79
80 template <typename DESCRIPTOR, typename MOMENTA>
81 using combined_momenta = typename MOMENTA::template type<DESCRIPTOR>;
82
83 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
84 using combined_equilibrium = typename EQUILIBRIUM::template type<DESCRIPTOR,MOMENTA>;
85
86 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
88 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
89 using CollisionO = typename COLLISION::template type<DESCRIPTOR,MOMENTA,EQUILIBRIUM>;
90
91 static_assert(COLLISION::parameters::template contains<descriptors::OMEGA>(),
92 "COLLISION must be parametrized using relaxation frequency OMEGA");
93
94 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
95 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
96 const auto u = cell.template getField<descriptors::VELOCITY>();
97 const V rho = MomentaF().computeRho(cell);
98 CollisionO().apply(cell, parameters);
99 const V omega = parameters.template get<descriptors::OMEGA>();
100 const auto source = cell.template getField<descriptors::SOURCE>();
101 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
102 V sourceTerm{};
103 sourceTerm = source;
104 sourceTerm *= descriptors::t<V,DESCRIPTOR>(iPop);
105 sourceTerm *= (V{1} - omega * V{0.5});
106 cell[iPop] += sourceTerm;
107 }
108 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
109 };
110 };
111
112 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
113 using combined_parameters = typename COLLISION::parameters;
114};
115
117template <template <typename> typename Forced = momenta::Identity>
118struct MCGuo {
119 static std::string getName() {
120 return "MultiComponentGuoForcing";
121 }
122 template <typename DESCRIPTOR, typename MOMENTA>
123 using combined_momenta = typename Forced<MOMENTA>::template type<DESCRIPTOR>;
124 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
125 using combined_equilibrium = typename EQUILIBRIUM::template type<DESCRIPTOR,Forced<MOMENTA>>;
126 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
128 using MomentaF = typename Forced<MOMENTA>::template type<DESCRIPTOR>;
129 using CollisionO = typename COLLISION::template type<DESCRIPTOR,Forced<MOMENTA>,EQUILIBRIUM>;
130 static_assert(COLLISION::parameters::template contains<descriptors::OMEGA>(),
131 "COLLISION must be parametrized using relaxation frequency OMEGA");
132 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
133 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
134 V rho, u[DESCRIPTOR::d];
135 MomentaF().computeRhoU(cell, rho, u);
136 CollisionO().apply(cell, parameters);
137 const V omega = parameters.template get<descriptors::OMEGA>();
138 const auto force = cell.template getField<descriptors::FORCE>();
139 lbm<DESCRIPTOR>::addExternalForce(cell, rho, u, omega, force);
140 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
141 };
142 };
143 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
144 using combined_parameters = typename COLLISION::parameters;
145};
146
149 static std::string getName() {
150 return "KupershtokhForcing";
151 }
152
153 template <typename DESCRIPTOR, typename MOMENTA>
154 using combined_momenta = typename momenta::Forced<MOMENTA>::template type<DESCRIPTOR>;
155
156 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
157 using combined_equilibrium = typename EQUILIBRIUM::template type<DESCRIPTOR,MOMENTA>;
158
159 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
161 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
163 using CollisionO = typename COLLISION::template type<DESCRIPTOR,MOMENTA,EQUILIBRIUM>;
164
165 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
166 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
167 V u[DESCRIPTOR::d];
168 MomentaF().computeU(cell, u);
169 const auto statistic = CollisionO().apply(cell, parameters);
170 const auto force = cell.template getField<descriptors::FORCE>();
171 V uPlusDeltaU[DESCRIPTOR::d];
172 for (int iVel=0; iVel < DESCRIPTOR::d; ++iVel) {
173 uPlusDeltaU[iVel] = u[iVel] + force[iVel];
174 }
175 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
176 cell[iPop] += EquilibriumF().compute(iPop, statistic.rho, uPlusDeltaU)
177 - EquilibriumF().compute(iPop, statistic.rho, u);
178 }
179 return statistic;
180 };
181 };
182
183 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
184 using combined_parameters = typename COLLISION::parameters;
185};
186
188class ShanChen {
189private:
190 template <typename EQUILIBRIUM>
191 struct VelocityShiftedEquilibrium {
192 static std::string getName() {
193 return "ShanChen<" + EQUILIBRIUM::getName() + ">";
194 }
195
196 template <typename DESCRIPTOR, typename MOMENTA>
197 struct type {
198 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
199 using EquilibriumF = typename EQUILIBRIUM::template type<DESCRIPTOR,MOMENTA>;
200
201 template <typename RHO, typename U>
202 auto compute(int iPop, const RHO& rho, const U& u) any_platform {
203 return EquilibriumF().compute(iPop, rho, u);
204 }
205
206 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
207 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
208 V rho, u[DESCRIPTOR::d], uSqr{};
209 MomentaF().computeRhoU(cell, rho, u);
210 const auto force = cell.template getFieldPointer<descriptors::FORCE>();
211 for (int iVel=0; iVel<DESCRIPTOR::d; ++iVel) {
212 u[iVel] += force[iVel] / parameters.template get<descriptors::OMEGA>();
213 uSqr += u[iVel] * u[iVel];
214 }
215 for (unsigned iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
216 fEq[iPop] = EquilibriumF().compute(iPop, rho, u);
217 }
218 return {rho, uSqr};
219 };
220 };
221 };
222
223public:
224 static std::string getName() {
225 return "ShanChenForcing";
226 }
227
228 template <typename DESCRIPTOR, typename MOMENTA>
229 using combined_momenta = typename momenta::Forced<MOMENTA>::template type<DESCRIPTOR>;
230
231 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
232 using combined_equilibrium = typename VelocityShiftedEquilibrium<EQUILIBRIUM>::template type<DESCRIPTOR,MOMENTA>;
233
234 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
237 using CollisionO = typename COLLISION::template type<DESCRIPTOR,MOMENTA,VelocityShiftedEquilibrium<EQUILIBRIUM>>;
238
239 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
240 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
241 V rho, u[DESCRIPTOR::d] { };
242 MomentaF().computeRhoU(cell, rho, u);
243 CollisionO().apply(cell, parameters);
244 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
245 };
246 };
247
248 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
249 using combined_parameters = typename COLLISION::parameters;
250};
251
253 static std::string getName() {
254 return "LinearVelocityForcing";
255 }
256
257 template <typename DESCRIPTOR, typename MOMENTA>
258 using combined_momenta = typename MOMENTA::template type<DESCRIPTOR>;
259
260 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
261 using combined_equilibrium = typename EQUILIBRIUM::template type<DESCRIPTOR,MOMENTA>;
262
263 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
265 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
266 using CollisionO = typename COLLISION::template type<DESCRIPTOR,MOMENTA,EQUILIBRIUM>;
267
268 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
269 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) {
270 V rho, u[DESCRIPTOR::d], pi[util::TensorVal<DESCRIPTOR >::n];
271 MomentaF().computeAllMomenta(cell, rho, u, pi);
272 auto force = cell.template getFieldPointer<descriptors::FORCE>();
273 int nDim = DESCRIPTOR::d;
274 V forceSave[nDim];
275 // adds a+Bu to force, where
276 // d=2: a1=v[0], a2=v[1], B11=v[2], B12=v[3], B21=v[4], B22=v[5]
277 // d=2: a1=v[0], a2=v[1], a3=v[2], B11=v[3], B12=v[4], B13=v[5], B21=v[6], B22=v[7], B23=v[8], B31=v[9], B32=v[10], B33=v[11]
278 auto v = cell.template getFieldPointer<descriptors::V12>();
279 for (int iDim=0; iDim<nDim; ++iDim) {
280 forceSave[iDim] = force[iDim];
281 force[iDim] += v[iDim];
282 for (int jDim=0; jDim<nDim; ++jDim) {
283 force[iDim] += v[jDim + iDim*nDim + nDim]*u[jDim];
284 }
285 }
286 for (int iVel=0; iVel<nDim; ++iVel) {
287 u[iVel] += force[iVel] / V{2.};
288 }
289
290 auto statistics = CollisionO().apply(cell, parameters);
291 V newOmega = parameters.template get<descriptors::OMEGA>();
292 lbm<DESCRIPTOR>::addExternalForce(cell, rho, u, newOmega, force);
293 // Writing back to froce fector
294 for (int iVel=0; iVel<nDim; ++iVel) {
295 force[iVel] = forceSave[iVel];
296 }
297 return statistics;
298 };
299 };
300
301 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
302 using combined_parameters = typename COLLISION::parameters;
303};
304
305}
306
307}
308
309#endif
Dynamics combination rule implementing the forcing scheme by Shan and Chen.
Definition forcing.h:188
static std::string getName()
Definition forcing.h:224
typename VelocityShiftedEquilibrium< EQUILIBRIUM >::template type< DESCRIPTOR, MOMENTA > combined_equilibrium
Definition forcing.h:232
typename COLLISION::parameters combined_parameters
Definition forcing.h:249
typename momenta::Forced< MOMENTA >::template type< DESCRIPTOR > combined_momenta
Definition forcing.h:229
Interface for post-processing steps – header file.
MOMENTA Identity
Definition interface.h:315
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
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Definition forcing.h:88
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
Definition forcing.h:95
typename COLLISION::template type< DESCRIPTOR, MOMENTA, EQUILIBRIUM > CollisionO
Definition forcing.h:89
Dynamics combination rule implementing the forcing scheme by Guo et al.
Definition forcing.h:75
static std::string getName()
Definition forcing.h:76
typename MOMENTA::template type< DESCRIPTOR > combined_momenta
Definition forcing.h:81
typename EQUILIBRIUM::template type< DESCRIPTOR, MOMENTA > combined_equilibrium
Definition forcing.h:84
typename COLLISION::parameters combined_parameters
Definition forcing.h:113
typename Forced< MOMENTA >::template type< DESCRIPTOR > MomentaF
Definition forcing.h:51
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
Definition forcing.h:58
typename COLLISION::template type< DESCRIPTOR, Forced< MOMENTA >, EQUILIBRIUM > CollisionO
Definition forcing.h:52
Dynamics combination rule implementing the forcing scheme by Guo et al.
Definition forcing.h:38
static std::string getName()
Definition forcing.h:39
typename Forced< MOMENTA >::template type< DESCRIPTOR > combined_momenta
Definition forcing.h:44
typename EQUILIBRIUM::template type< DESCRIPTOR, Forced< MOMENTA > > combined_equilibrium
Definition forcing.h:47
typename COLLISION::parameters combined_parameters
Definition forcing.h:70
combined_equilibrium< DESCRIPTOR, MOMENTA, EQUILIBRIUM > EquilibriumF
Definition forcing.h:162
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
Definition forcing.h:166
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Definition forcing.h:161
typename COLLISION::template type< DESCRIPTOR, MOMENTA, EQUILIBRIUM > CollisionO
Definition forcing.h:163
Dynamics combination rule implementing the forcing scheme by Kupershtokh et al.
Definition forcing.h:148
typename momenta::Forced< MOMENTA >::template type< DESCRIPTOR > combined_momenta
Definition forcing.h:154
typename COLLISION::parameters combined_parameters
Definition forcing.h:184
static std::string getName()
Definition forcing.h:149
typename EQUILIBRIUM::template type< DESCRIPTOR, MOMENTA > combined_equilibrium
Definition forcing.h:157
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters)
Definition forcing.h:269
typename COLLISION::template type< DESCRIPTOR, MOMENTA, EQUILIBRIUM > CollisionO
Definition forcing.h:266
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Definition forcing.h:265
typename EQUILIBRIUM::template type< DESCRIPTOR, MOMENTA > combined_equilibrium
Definition forcing.h:261
static std::string getName()
Definition forcing.h:253
typename MOMENTA::template type< DESCRIPTOR > combined_momenta
Definition forcing.h:258
typename COLLISION::parameters combined_parameters
Definition forcing.h:302
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
Definition forcing.h:133
typename COLLISION::template type< DESCRIPTOR, Forced< MOMENTA >, EQUILIBRIUM > CollisionO
Definition forcing.h:129
typename Forced< MOMENTA >::template type< DESCRIPTOR > MomentaF
Definition forcing.h:128
Dynamics combination rule implementing the forcing scheme by Guo et al. with barycentric velocity.
Definition forcing.h:118
typename EQUILIBRIUM::template type< DESCRIPTOR, Forced< MOMENTA > > combined_equilibrium
Definition forcing.h:125
typename COLLISION::parameters combined_parameters
Definition forcing.h:144
static std::string getName()
Definition forcing.h:119
typename Forced< MOMENTA >::template type< DESCRIPTOR > combined_momenta
Definition forcing.h:123
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Definition forcing.h:198
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
Definition forcing.h:207
typename EQUILIBRIUM::template type< DESCRIPTOR, MOMENTA > EquilibriumF
Definition forcing.h:199
auto compute(int iPop, const RHO &rho, const U &u) any_platform
Definition forcing.h:202
typename COLLISION::template type< DESCRIPTOR, MOMENTA, VelocityShiftedEquilibrium< EQUILIBRIUM > > CollisionO
Definition forcing.h:237
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
Definition forcing.h:240
combined_momenta< DESCRIPTOR, MOMENTA > MomentaF
Definition forcing.h:236
static void addExternalForce(CELL &cell, const RHO &rho, const U &u, const OMEGA &omega, const FORCE &force) any_platform
Add a force term after BGK collision.
Definition lbm.h:463
Compute number of elements of a symmetric d-dimensional tensor.
Definition util.h:210