OpenLB 1.7
Loading...
Searching...
No Matches
dualLbHelpers.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2014 Mathias J. Krause
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
30#ifndef DUAL_LB_HELPERS_H
31#define DUAL_LB_HELPERS_H
32
34#include "dynamics/lbm.h"
35//#include "core/cell.h"
36//#include "core/util.h"
37//#include "utilities/vectorHelpers.h"
38
39
40namespace olb {
41
43namespace opti {
44
45// Forward declarations
46template<typename T, typename DESCRIPTOR> struct dualLbDynamicsHelpers;
47template<typename T, typename DESCRIPTOR> struct dualLbExternalHelpers;
48template<typename T, typename DESCRIPTOR> struct dualLbLatticeHelpers;
49
51template<typename T, typename DESCRIPTOR>
53
54 static T equilibrium(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
55 {
57 ::equilibrium(iPop, jPop, rho, u);
58 }
59
60 static T equilibrium2(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
61 {
63 ::equilibrium2(iPop, jPop, rho, u);
64 }
65 /*
66 static T incEquilibrium(int iPop, const T j[DESCRIPTOR::d], const T jSqr, const T pressure) {
67 return lbm<DESCRIPTOR>
68 ::incEquilibrium(iPop, j, jSqr, pressure);
69 }
70
71 static void computeFneq ( ConstCell<T,DESCRIPTOR>& cell,
72 T fNeq[DESCRIPTOR::q], T rho, const T u[DESCRIPTOR::d] )
73 {
74 lbm<DESCRIPTOR>
75 ::computeFneq(&cell[0], fNeq, rho, u);
76 }
77
78 static T bgkCollision(Cell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d], T omega)
79 {
80 return lbm<DESCRIPTOR>
81 ::bgkCollision(&cell[0], rho, u, omega);
82 }
83
84 static T incBgkCollision(Cell<T,DESCRIPTOR>& cell, T pressure, const T j[DESCRIPTOR::d], T omega)
85 {
86 return lbm<DESCRIPTOR>
87 ::incBgkCollision(&cell[0], pressure, j, omega);
88 }
89
90 static T constRhoBgkCollision(Cell<T,DESCRIPTOR>& cell,
91 T rho, const T u[DESCRIPTOR::d], T ratioRho, T omega)
92 {
93 return lbm<DESCRIPTOR>
94 ::constRhoBgkCollision(&cell[0], rho, u, ratioRho, omega);
95 }
96
97 static T computeRho(ConstCell<T,DESCRIPTOR>& cell) {
98 return lbm<DESCRIPTOR>
99 ::computeRho(&cell[0]);
100 }
101
102 static void computeJ(ConstCell<T,DESCRIPTOR>& cell, T j[DESCRIPTOR::d] ) {
103 lbm<DESCRIPTOR>
104 ::computeJ(&cell[0], j);
105 }
106 */
107 static void computeRhoU(ConstCell<T,DESCRIPTOR>& cell, T& rho, T u[DESCRIPTOR::d])
108 {
110 ::computeRhoU(&cell[0], rho, u);
111 }
112
113 static void computeRhoJ(ConstCell<T,DESCRIPTOR>& cell, T& rho, T j[DESCRIPTOR::d])
114 {
116 ::computeRhoJ(&cell[0], rho, j);
117 }
118 /*
119 static void computeStress(ConstCell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d],
120 T pi[util::TensorVal<DESCRIPTOR >::n] )
121 {
122 lbm<DESCRIPTOR>
123 ::computeStress(&cell[0], rho, u, pi);
124 }
125
126 static void computeAllMomenta(ConstCell<T,DESCRIPTOR>& cell, T& rho, T u[DESCRIPTOR::d],
127 T pi[util::TensorVal<DESCRIPTOR >::n] )
128 {
129 lbm<DESCRIPTOR>
130 ::computeAllMomenta(&cell[0], rho, u, pi);
131 }
132
133 static void modifyVelocity(Cell<T,DESCRIPTOR>& cell, const T newU[DESCRIPTOR::d]) {
134 lbm<DESCRIPTOR>
135 ::modifyVelocity(&cell[0], newU);
136 }
137
138 static void addExternalForce(Cell<T,DESCRIPTOR>& cell, const T u[DESCRIPTOR::d], T omega, T amplitude=(T)1)
139 {
140 lbExternalHelpers<T,DESCRIPTOR>::addExternalForce(cell, u, omega, amplitude);
141 }
142 */
143}; // struct lbHelpers
144
145
147template<typename T, typename DESCRIPTOR>
150 static T equilibrium(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
151 {
152 T eq = olb::equilibrium<DESCRIPTOR>::template secondOrder(iPop, rho, u) + descriptors::t<T,DESCRIPTOR>(iPop);
153 T sum = T();
154 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
155 sum += (u[iD] - descriptors::c<DESCRIPTOR>(jPop,iD))*(u[iD] - descriptors::c<DESCRIPTOR>(iPop,iD));
156 } //std::cout<<u[0]<<std::endl;
157 return (descriptors::invCs2<T,DESCRIPTOR>()*sum + T(1))/rho*eq;
158 }
159
161 static T equilibrium2(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
162 {
163 T u_c = T();
164 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
165 u_c += u[iD]*descriptors::c<DESCRIPTOR>(iPop,iD);
166 }
167 T sum = T();
168 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
169 sum += (u[iD]*u[iD] + 2.*descriptors::c<DESCRIPTOR>(jPop,iD)*(descriptors::c<DESCRIPTOR>(iPop,iD)-u[iD]) )
170 * descriptors::invCs2<T,DESCRIPTOR>()*0.5
171 + (u_c*descriptors::c<DESCRIPTOR>(iPop,iD)*(2.*descriptors::c<DESCRIPTOR>(jPop,iD)-u[iD]))
172 * descriptors::invCs2<T,DESCRIPTOR>()*descriptors::invCs2<T,DESCRIPTOR>()*0.5;
173 }
174 return descriptors::t<T,DESCRIPTOR>(iPop)*(1.+sum);
175 }
176
177 /*
178 static T incEquilibrium( int iPop, const T j[DESCRIPTOR::d],
179 const T jSqr, const T pressure )
180 {
181 T c_j = T();
182 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
183 c_j += descriptors::c<DESCRIPTOR>(iPop,iD)*j[iD];
184 }
185 T rho = (T)1 + pressure*descriptors::invCs2<T,DESCRIPTOR>();
186 return descriptors::t<T,DESCRIPTOR>(iPop) * ( rho +
187 descriptors::invCs2<T,DESCRIPTOR>() * c_j +
188 descriptors::invCs2<T,DESCRIPTOR>() * descriptors::invCs2<T,DESCRIPTOR>()/(T)2 * c_j*c_j -
189 descriptors::invCs2<T,DESCRIPTOR>()/(T)2 * jSqr
190 ) - descriptors::t<T,DESCRIPTOR>(iPop);
191 }
192
193 static void computeFneq(T const* cell, T fNeq[DESCRIPTOR::q], T rho, const T u[DESCRIPTOR::d]) {
194 const T uSqr = util::normSqr<T,DESCRIPTOR::d>(u);
195 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
196 fNeq[iPop] = cell[iPop] - equilibrium(iPop, rho, u, uSqr);
197 }
198 }
199
201 static T bgkCollision(T* cell, T rho, const T u[DESCRIPTOR::d], T omega) {
202 const T uSqr = util::normSqr<T,DESCRIPTOR::d>(u);
203 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
204 cell[iPop] *= (T)1-omega;
205 cell[iPop] += omega * lbm<DESCRIPTOR>::equilibrium (
206 iPop, rho, u, uSqr );
207 }
208 return uSqr;
209 }
210
212 static T incBgkCollision(T* cell, T pressure, const T j[DESCRIPTOR::d], T omega) {
213 const T jSqr = util::normSqr<T,DESCRIPTOR::d>(j);
214 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
215 cell[iPop] *= (T)1-omega;
216 cell[iPop] += omega * lbm<DESCRIPTOR>::incEquilibrium (
217 iPop, j, jSqr, pressure );
218 }
219 return jSqr;
220 }
221
223 static T constRhoBgkCollision(T* cell, T rho, const T u[DESCRIPTOR::d], T ratioRho, T omega) {
224 const T uSqr = util::normSqr<T,DESCRIPTOR::d>(u);
225 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
226 T feq = lbm<DESCRIPTOR>::equilibrium(iPop, rho, u, uSqr );
227 cell[iPop] =
228 ratioRho*(feq+descriptors::t<T,DESCRIPTOR>(iPop))-descriptors::t<T,DESCRIPTOR>(iPop) +
229 ((T)1-omega)*(cell[iPop]-feq);
230 }
231 return uSqr;
232 }
233
235 static T computeRho(T const* cell) {
236 T rho = T();
237 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
238 rho += cell[iPop];
239 }
240 rho += (T)1;
241 return rho;
242 }
243
245 static void computeJ(T const* cell, T j[DESCRIPTOR::d]) {
246 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
247 j[iD] = T();
248 }
249 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
250 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
251 j[iD] += cell[iPop]*descriptors::c<DESCRIPTOR>(iPop,iD);
252 }
253 }
254 }
255 */
257 static void computeRhoU(T const* cell, T& rho, T u[DESCRIPTOR::d])
258 {
259
260 rho = T();
261 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
262 u[iD] = T();
263 }
264 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
265 rho += cell[iPop];
266 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
267 u[iD] += cell[iPop]*descriptors::c<DESCRIPTOR>(iPop,iD);
268 }
269 }
270 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
271 u[iD] /= rho;
272 }
273 }
274
276 static void computeRhoJ(T const* cell, T& rho, T j[DESCRIPTOR::d])
277 {
278
279 lbm<DESCRIPTOR>::computeRhoJ(&cell[0], rho, j);
280 rho-=T(1);
281 }
282 /*
284 static void computeStress(T const* cell, T rho, const T u[DESCRIPTOR::d],
285 T pi[util::TensorVal<DESCRIPTOR>::n] )
286 {
287 int iPi = 0;
288 for (int iAlpha=0; iAlpha < DESCRIPTOR::d; ++iAlpha) {
289 for (int iBeta=iAlpha; iBeta < DESCRIPTOR::d; ++iBeta) {
290 pi[iPi] = T();
291 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
292 pi[iPi] += descriptors::c<DESCRIPTOR>(iPop,iAlpha) *
293 descriptors::c<DESCRIPTOR>(iPop,iBeta) * cell[iPop];
294 }
295 // stripe off equilibrium contribution
296 pi[iPi] -= rho*u[iAlpha]*u[iBeta];
297 if (iAlpha==iBeta) {
298 pi[iPi] -= 1./descriptors::invCs2<T,DESCRIPTOR>()*(rho-(T)1);
299 }
300 ++iPi;
301 }
302 }
303 }
304
306 static void computeAllMomenta(T const* cell, T& rho, T u[DESCRIPTOR::d],
307 T pi[util::TensorVal<DESCRIPTOR>::n] )
308 {
309 computeRhoU(cell, rho, u);
310 computeStress(cell, rho, u, pi);
311 }
312
313 static void modifyVelocity(T* cell, const T newU[DESCRIPTOR::d]) {
314 T rho, oldU[DESCRIPTOR::d];
315 computeRhoU(cell, rho, oldU);
316 const T oldUSqr = util::normSqr<T,DESCRIPTOR::d>(oldU);
317 const T newUSqr = util::normSqr<T,DESCRIPTOR::d>(newU);
318 for (int iPop=0; iPop<DESCRIPTOR::q; ++iPop) {
319 cell[iPop] = cell[iPop]
320 - equilibrium(iPop, rho, oldU, oldUSqr)
321 + equilibrium(iPop, rho, newU, newUSqr);
322 }
323 }*/
324
325}; // struct lbHelpers
326
328template<typename T, typename DESCRIPTOR>
330 /*
332 static void addExternalForce(Cell<T,DESCRIPTOR>& cell, const T u[DESCRIPTOR::d], T omega, T amplitude) {
333 static const int forceBeginsAt = DESCRIPTOR::template index<descriptors::FORCE>();
334 T* force = cell.template getFieldPointer<descriptors::FORCE>();
335 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
336 T c_u = T();
337 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
338 c_u += descriptors::c<DESCRIPTOR>(iPop,iD)*u[iD];
339 }
340 c_u *= descriptors::invCs2<T,DESCRIPTOR>() * descriptors::invCs2<T,DESCRIPTOR>();
341 T forceTerm = T();
342 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
343 forceTerm +=
344 ( (descriptors::c<DESCRIPTOR>(iPop,iD)-u[iD]) * descriptors::invCs2<T,DESCRIPTOR>()
345 + c_u * descriptors::c<DESCRIPTOR>(iPop,iD)
346 )
347 * force[iD];
348 }
349 forceTerm *= descriptors::t<T,DESCRIPTOR>(iPop);
350 forceTerm *= 1-omega/(T)2;
351 forceTerm *= amplitude;
352 cell[iPop] += forceTerm;
353 }
354 }*/
355}; // struct externalFieldHelpers
356
358template<typename T, typename DESCRIPTOR>
360};
361
363template<typename T, typename DESCRIPTOR, int direction, int orientation>
365 /*
366 static void computeStress (
367 ConstCell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d],
368 T pi[util::TensorVal<DESCRIPTOR >::n] )
369 {
370 typedef DESCRIPTOR L;
371 const T uSqr = util::normSqr<T,L::d>(u);
372
373 std::vector<int> const& onWallIndices = util::subIndex<L, direction, 0>();
374 std::vector<int> const& normalIndices = util::subIndex<L, direction, orientation>();
375
376 T fNeq[DESCRIPTOR::q];
377 for (unsigned fIndex=0; fIndex<onWallIndices.size(); ++fIndex) {
378 int iPop = onWallIndices[fIndex];
379 fNeq[iPop] =
380 cell[iPop] -
381 lbm<DESCRIPTOR>::equilibrium(iPop, rho, u, uSqr);
382 }
383 for (unsigned fIndex=0; fIndex<normalIndices.size(); ++fIndex) {
384 int iPop = normalIndices[fIndex];
385 if (iPop == 0) {
386 fNeq[iPop] = T(); // fNeq[0] will not be used anyway
387 }
388 else {
389 fNeq[iPop] =
390 cell[iPop] -
391 lbm<DESCRIPTOR>::equilibrium(iPop, rho, u, uSqr);
392 }
393 }
394
395 int iPi = 0;
396 for (int iAlpha=0; iAlpha<L::d; ++iAlpha) {
397 for (int iBeta=iAlpha; iBeta<L::d; ++iBeta) {
398 pi[iPi] = T();
399 for (unsigned fIndex=0; fIndex<onWallIndices.size(); ++fIndex)
400 {
401 const int iPop = onWallIndices[fIndex];
402 pi[iPi] +=
403 descriptors::c<L>(iPop)[iAlpha]*descriptors::c<L>(iPop)[iBeta]*fNeq[iPop];
404 }
405 for (unsigned fIndex=0; fIndex<normalIndices.size(); ++fIndex)
406 {
407 const int iPop = normalIndices[fIndex];
408 pi[iPi] += (T)2 * descriptors::c<L>(iPop)[iAlpha]*descriptors::c<L>(iPop)[iBeta]*
409 fNeq[iPop];
410 }
411 ++iPi;
412 }
413 }
414 }
415 */
416}; // struct boundaryHelpers
417
418
419} // namespace opti
420
421} // namespace olb
422
423// The specialized code is directly included. That is because we never want
424// it to be precompiled so that in both the precompiled and the
425// "include-everything" version, the compiler can apply all the
426// optimizations it wants.
427//#include "lbHelpersD2Q9.h"
428//#include "lbHelpersD3Q9.h"
429
430#endif
Highest-level interface to read-only Cell data.
Definition cell.h:53
Top level namespace for all of OpenLB.
Optimization Code.
static void computeRhoJ(CELL &cell, RHO &rho, J &j) any_platform
Computation of hydrodynamic variables.
Definition lbm.h:211
All boundary helper functions are inside this structure.
All helper functions are inside this structure.
static T equilibrium(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
Computation of adjoint equilibrium distribution operator dEq_i/dF_j -> Mathias J. Krause.
static void computeRhoJ(T const *cell, T &rho, T j[DESCRIPTOR::d])
Computation of hydrodynamic variables.
static T equilibrium2(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
Computation of adjoint equilibrium distribution operator dEq_i/dF_j (discrete approach) -> Geng Liu.
static void computeRhoU(T const *cell, T &rho, T u[DESCRIPTOR::d])
Computation of hydrodynamic variables.
Helper functions for dynamics that access external field.
This structure forwards the calls to the appropriate helper class.
static T equilibrium2(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
static void computeRhoJ(ConstCell< T, DESCRIPTOR > &cell, T &rho, T j[DESCRIPTOR::d])
static T equilibrium(int iPop, int jPop, T rho, const T u[DESCRIPTOR::d])
static void computeRhoU(ConstCell< T, DESCRIPTOR > &cell, T &rho, T u[DESCRIPTOR::d])
Helper functions with full-lattice access.