OpenLB 1.8.1
Loading...
Searching...
No Matches
dynamics.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, Mathias J. Krause
4 * 2021 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
25#ifndef LB_LEGACY_DYNAMICS_H
26#define LB_LEGACY_DYNAMICS_H
27
28#include "dynamics/interface.h"
29
30namespace olb {
31
32namespace legacy {
33
34template <typename T, typename DESCRIPTOR, typename MOMENTA>
35struct BasicDynamics : public dynamics::CustomCollision<T,DESCRIPTOR,MOMENTA> {
36 void computeEquilibrium(ConstCell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override {
37 for ( int iPop = 0; iPop < DESCRIPTOR::q; iPop++ ) {
38 fEq[iPop] = equilibrium<DESCRIPTOR>::secondOrder(iPop, rho, u);
39 }
40 };
41
42 std::type_index id() override {
44 }
45
47 throw std::bad_function_call();
48 }
49
50};
51
52template<typename T, typename DESCRIPTOR, typename MOMENTA=momenta::BulkTuple>
53class BGKdynamics : public BasicDynamics<T,DESCRIPTOR,MOMENTA> {
54public:
55 BGKdynamics(T omega);
58
59 virtual T getOmega() const {
60 return _omega;
61 }
62
63private:
64 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
65
66 T _omega;
67};
68
69template<typename T, typename DESCRIPTOR, typename MOMENTA>
71 : BasicDynamics<T,DESCRIPTOR,MOMENTA>(),
72 _omega(omega)
73{ }
74
75template<typename T, typename DESCRIPTOR, typename MOMENTA>
77{
78 T rho, u[DESCRIPTOR::d];
79 MomentaF().computeRhoU(cell, rho, u);
80 T uSqr = lbm<DESCRIPTOR>::bgkCollision(cell, rho, u, _omega);
81 return {rho, uSqr};
82}
83
84template<typename T, typename DESCRIPTOR>
85class NoLatticeDynamics : public Dynamics<T,DESCRIPTOR> {
86public:
88 NoLatticeDynamics(T rho = T(1) );
90 void computeEquilibrium(ConstCell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override any_platform;
94 T computeRho(ConstCell<T,DESCRIPTOR>& cell) const override;
96 void computeU (
98 T u[DESCRIPTOR::d] ) const override;
100 void computeJ (
102 T j[DESCRIPTOR::d] ) const override;
104 void computeStress (
106 T rho, const T u[DESCRIPTOR::d],
107 T pi[util::TensorVal<DESCRIPTOR >::n] ) const override;
108 void computeRhoU (
110 T& rho, T u[DESCRIPTOR::d]) const override;
111 void computeAllMomenta (
113 T& rho, T u[DESCRIPTOR::d],
114 T pi[util::TensorVal<DESCRIPTOR >::n] ) const override;
116 void defineRho(Cell<T,DESCRIPTOR>& cell, T rho) override;
118 void defineU(Cell<T,DESCRIPTOR>& cell,
119 const T u[DESCRIPTOR::d]) override;
121 void defineRhoU (
122 Cell<T,DESCRIPTOR>& cell,
123 T rho, const T u[DESCRIPTOR::d]) override;
125 void defineAllMomenta (
126 Cell<T,DESCRIPTOR>& cell,
127 T rho, const T u[DESCRIPTOR::d],
128 const T pi[util::TensorVal<DESCRIPTOR >::n] ) override;
129
130 std::type_index id() override {
131 return typeid(NoLatticeDynamics<T,DESCRIPTOR>);
132 }
133
135 throw std::bad_function_call();
136 }
137
138private:
140 T _rho;
141};
142
146template<typename T, typename DESCRIPTOR>
147class OffDynamics : public NoLatticeDynamics<T,DESCRIPTOR> {
148public:
150 OffDynamics(const T _location[DESCRIPTOR::d]);
152 OffDynamics(const T _location[DESCRIPTOR::d], T _distances[DESCRIPTOR::q]);
154 T computeRho(ConstCell<T,DESCRIPTOR>& cell) const override;
156 void computeU(ConstCell<T,DESCRIPTOR>& cell, T u[DESCRIPTOR::d] ) const override;
158 void setBoundaryIntersection(int iPop, T distance);
160 bool getBoundaryIntersection(int iPop, T intersection[DESCRIPTOR::d]);
162 void defineRho(Cell<T,DESCRIPTOR>& cell, T rho) override;
164 void defineRho(int iPop, T rho);
166 void defineU(Cell<T,DESCRIPTOR>& cell, const T u[DESCRIPTOR::d]) override;
168 void defineU(const T u[DESCRIPTOR::d]);
170 void defineU(int iPop, const T u[DESCRIPTOR::d]);
172 T getVelocityCoefficient(int iPop);
173
174 std::type_index id() override {
175 return typeid(OffDynamics<T,DESCRIPTOR>);
176 }
177
178
179private:
180 T _rho;
181 T _u[DESCRIPTOR::q][DESCRIPTOR::d];
182 T location[DESCRIPTOR::d];
183 T distances[DESCRIPTOR::q];
184 T boundaryIntersection[DESCRIPTOR::q][DESCRIPTOR::d];
185 T velocityCoefficient[DESCRIPTOR::q];
186};
187
189
190template<typename T, typename DESCRIPTOR>
192{
193 this->getName() = "NoLatticeDynamics";
194}
195
196template<typename T, typename DESCRIPTOR>
197void NoLatticeDynamics<T,DESCRIPTOR>::computeEquilibrium(ConstCell<T,DESCRIPTOR>& cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const
198{
199 return T();
200}
201
202template<typename T, typename DESCRIPTOR>
206
207template<typename T, typename DESCRIPTOR>
212
213template<typename T, typename DESCRIPTOR>
216 T u[DESCRIPTOR::d]) const
217{
218 for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
219 u[iD] = T();
220 }
221}
222
223template<typename T, typename DESCRIPTOR>
226 T j[DESCRIPTOR::d]) const
227{
228 for (int iD=0; iD<DESCRIPTOR::d; ++iD) {
229 j[iD] = T();
230 }
231}
232
233template<typename T, typename DESCRIPTOR>
236 T rho, const T u[DESCRIPTOR::d],
238{
239 for (int iPi=0; iPi<util::TensorVal<DESCRIPTOR >::n; ++iPi) {
240 pi[iPi] = T();//std::numeric_limits<T>::signaling_NaN();
241 }
242}
243
244template<typename T, typename DESCRIPTOR>
247 T& rho, T u[DESCRIPTOR::d]) const
248{
249 rho = computeRho(cell);
250 computeU(cell, u);
251}
252
253template<typename T, typename DESCRIPTOR>
256 T& rho, T u[DESCRIPTOR::d],
258{
259 computeRhoU(cell, rho, u);
260 computeStress(cell, rho, u, pi);
261}
262
263template<typename T, typename DESCRIPTOR>
266
267template<typename T, typename DESCRIPTOR>
269 Cell<T,DESCRIPTOR>& cell,
270 const T u[DESCRIPTOR::d])
271{ }
272
273template<typename T, typename DESCRIPTOR>
275 Cell<T,DESCRIPTOR>& cell,
276 T rho, const T u[DESCRIPTOR::d])
277{ }
278
279template<typename T, typename DESCRIPTOR>
281 Cell<T,DESCRIPTOR>& cell,
282 T rho, const T u[DESCRIPTOR::d],
284{ }
285
287
288template<typename T, typename DESCRIPTOR>
289OffDynamics<T,DESCRIPTOR>::OffDynamics(const T _location[DESCRIPTOR::d])
290{
291 this->getName() = "OffDynamics";
292 typedef DESCRIPTOR L;
293 for (int iD = 0; iD < L::d; iD++) {
294 location[iD] = _location[iD];
295 }
296 for (int iPop = 0; iPop < L::q; iPop++) {
297 distances[iPop] = -1;
298 velocityCoefficient[iPop] = 0;
299 for (int iD = 0; iD < L::d; iD++) {
300 boundaryIntersection[iPop][iD] = _location[iD];
301 _u[iPop][iD] = T();
302 }
303 }
304 _rho=T(1);
305}
306
307template<typename T, typename DESCRIPTOR>
308OffDynamics<T,DESCRIPTOR>::OffDynamics(const T _location[DESCRIPTOR::d], T _distances[DESCRIPTOR::q])
309{
310 this->getName() = "OffDynamics";
311 typedef DESCRIPTOR L;
312 for (int iD = 0; iD < L::d; iD++) {
313 location[iD] = _location[iD];
314 }
315 for (int iPop = 0; iPop < L::q; iPop++) {
316 distances[iPop] = _distances[iPop];
317 velocityCoefficient[iPop] = 0;
318 for (int iD = 0; iD < L::d; iD++) {
319 boundaryIntersection[iPop][iD] = _location[iD] - _distances[iPop]*descriptors::c<L>(iPop,iD);
320 _u[iPop][iD] = T();
321 }
322 }
323 _rho=T(1);
324}
325
326template<typename T, typename DESCRIPTOR>
328{
329 /*typedef DESCRIPTOR L;
330 T rhoTmp = T();
331 T counter = T();
332 int counter2 = int();
333 for (int iPop = 0; iPop < L::q; iPop++) {
334 if (distances[iPop] != -1) {
335 rhoTmp += (cell[iPop] + descriptors::t<T,L>(iPop))*descriptors::t<T,L>(iPop);
336 counter += descriptors::t<T,L>(iPop);
337 counter2++;
338 }
339 }
340 //if (rhoTmp/counter + 1<0.1999) std::cout << rhoTmp/counter2 + 1 <<std::endl;
341 //if (rhoTmp/counter + 1>1.001) std::cout << rhoTmp/counter2 + 1 <<std::endl;
342 return rhoTmp/counter/counter;*/
343 return _rho;
344}
345
346template<typename T, typename DESCRIPTOR>
348{
349 typedef DESCRIPTOR L;
350 for (int iD = 0; iD < L::d; iD++) {
351 u[iD] = T();
352 }
353 int counter = 0;
354 for (int iPop = 0; iPop < L::q; iPop++) {
355 if ( !util::nearZero(distances[iPop]+1) ) {
356 for (int iD = 0; iD < L::d; iD++) {
357 u[iD] += _u[iPop][iD];
358 }
359 counter++;
360 }
361 }
362 if (counter!=0) {
363 for (int iD = 0; iD < L::d; iD++) {
364 u[iD] /= counter;
365 }
366 }
367 return;
368}
369
370template<typename T, typename DESCRIPTOR>
372{
375 typedef DESCRIPTOR L;
376 distances[iPop] = distance;
377 for (int iD = 0; iD < L::d; iD++) {
378 boundaryIntersection[iPop][iD] = location[iD] - distance*descriptors::c<L>(iPop,iD);
379 }
380}
381
382template<typename T, typename DESCRIPTOR>
383bool OffDynamics<T,DESCRIPTOR>::getBoundaryIntersection(int iPop, T intersection[DESCRIPTOR::d])
384{
385 typedef DESCRIPTOR L;
386 if ( !util::nearZero(distances[iPop]+1) ) {
387 for (int iD = 0; iD < L::d; iD++) {
388 intersection[iD] = boundaryIntersection[iPop][iD];
389 }
390 return true;
391 }
392 return false;
393}
394
395template<typename T, typename DESCRIPTOR>
397{
398 _rho=rho;
399}
400
401template<typename T, typename DESCRIPTOR>
403{
404 _rho=rho;
405}
406
407template<typename T, typename DESCRIPTOR>
409 Cell<T,DESCRIPTOR>& cell,
410 const T u[DESCRIPTOR::d])
411{
412 defineU(u);
413}
414
415template<typename T, typename DESCRIPTOR>
416void OffDynamics<T,DESCRIPTOR>::defineU(const T u[DESCRIPTOR::d])
417{
418 typedef DESCRIPTOR L;
419 for (int iPop = 0; iPop < L::q; iPop++) {
420 if ( !util::nearZero(distances[iPop]+1) ) {
421 defineU(iPop, u);
422 }
423 }
424}
425
427
431template<typename T, typename DESCRIPTOR>
433 int iPop, const T u[DESCRIPTOR::d])
434{
435 OLB_PRECONDITION(distances[iPop] != -1)
436 typedef DESCRIPTOR L;
437 velocityCoefficient[iPop] = 0;
438 // scalar product of c(iPop) and u
439 for (int sum = 0; sum < L::d; sum++) { // +/- problem because of first stream than postprocess
440 velocityCoefficient[iPop] -= descriptors::c<L>(iPop,sum)*u[sum];
441 }
442 // compute summand for boundary condition
443 velocityCoefficient[iPop] *= 2*descriptors::invCs2<T,L>() * descriptors::t<T,L>(iPop);
444
445 for (int iD = 0; iD < L::d; iD++) {
446 _u[iPop][iD] = u[iD];
447 }
448}
449
450template<typename T, typename DESCRIPTOR>
452{
453 return velocityCoefficient[iPop];
454}
455
456}
457
458}
459
460#endif
Highest-level interface to read-only Cell data.
Definition interface.h:36
virtual T getOmega() const
Definition dynamics.h:59
CellStatistic< T > collide(Cell< T, DESCRIPTOR > &cell) override
Collision step.
Definition dynamics.h:76
CellStatistic< T > collide(Cell< T, DESCRIPTOR > &cell) override
Collision step.
Definition dynamics.h:203
std::type_index id() override
Expose unique type-identifier for RTTI.
Definition dynamics.h:130
void computeEquilibrium(ConstCell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override any_platform
Yields 0;.
Definition dynamics.h:197
void defineAllMomenta(Cell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], const T pi[util::TensorVal< DESCRIPTOR >::n]) override
Does nothing.
Definition dynamics.h:280
void computeAllMomenta(ConstCell< T, DESCRIPTOR > &cell, T &rho, T u[DESCRIPTOR::d], T pi[util::TensorVal< DESCRIPTOR >::n]) const override
Compute all momenta up to second order.
Definition dynamics.h:254
void computeJ(ConstCell< T, DESCRIPTOR > &cell, T j[DESCRIPTOR::d]) const override
Yields 0;.
Definition dynamics.h:224
void defineRho(Cell< T, DESCRIPTOR > &cell, T rho) override
Does nothing.
Definition dynamics.h:264
void computeRhoU(ConstCell< T, DESCRIPTOR > &cell, T &rho, T u[DESCRIPTOR::d]) const override
Compute fluid velocity and particle density.
Definition dynamics.h:245
NoLatticeDynamics(T rho=T(1))
You may fix a fictitious density value on no dynamics node via this constructor.
Definition dynamics.h:191
void computeStress(ConstCell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], T pi[util::TensorVal< DESCRIPTOR >::n]) const override
Yields NaN.
Definition dynamics.h:234
T computeRho(ConstCell< T, DESCRIPTOR > &cell) const override
Yields 1;.
Definition dynamics.h:208
void defineRhoU(Cell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d]) override
Does nothing.
Definition dynamics.h:274
void computeU(ConstCell< T, DESCRIPTOR > &cell, T u[DESCRIPTOR::d]) const override
Yields 0;.
Definition dynamics.h:214
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
Definition dynamics.h:134
void defineU(Cell< T, DESCRIPTOR > &cell, const T u[DESCRIPTOR::d]) override
Does nothing.
Definition dynamics.h:268
Dynamics for offLattice boundary conditions OffDynamics are basically NoLatticeDynamics with the addi...
Definition dynamics.h:147
OffDynamics(const T _location[DESCRIPTOR::d])
Constructor.
Definition dynamics.h:289
T getVelocityCoefficient(int iPop)
Get VelocitySummand for Bouzidi-Boundary Condition.
Definition dynamics.h:451
void defineRho(Cell< T, DESCRIPTOR > &cell, T rho) override
Set particle density on the cell.
Definition dynamics.h:396
void computeU(ConstCell< T, DESCRIPTOR > &cell, T u[DESCRIPTOR::d]) const override
Returns an average of the locally stored u.
Definition dynamics.h:347
std::type_index id() override
Expose unique type-identifier for RTTI.
Definition dynamics.h:174
T computeRho(ConstCell< T, DESCRIPTOR > &cell) const override
Returns local stored rho which is updated if the bc is used as velocity!=0 condition.
Definition dynamics.h:327
void defineU(Cell< T, DESCRIPTOR > &cell, const T u[DESCRIPTOR::d]) override
Set fluid velocity on the cell.
Definition dynamics.h:408
void setBoundaryIntersection(int iPop, T distance)
Set Intersection of the link and the boundary.
Definition dynamics.h:371
bool getBoundaryIntersection(int iPop, T intersection[DESCRIPTOR::d])
Get Intersection of the link and the boundary.
Definition dynamics.h:383
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
bool nearZero(T a) any_platform
return true if a is close to zero
Definition util.h:402
Top level namespace for all of OpenLB.
std::string getName(OperatorScope scope)
Returns human-readable name of scope.
dynamics::Tuple< T, DESCRIPTOR, MOMENTA, std::conditional_t<(DESCRIPTOR::d==3 &&DESCRIPTOR::q==7)||(DESCRIPTOR::d==2 &&DESCRIPTOR::q==5), equilibria::FirstOrder, equilibria::SecondOrder >, collision::BGK > BGKdynamics
Common BGK collision step.
Definition dynamics.h:90
#define OLB_PRECONDITION(COND)
Definition olbDebug.h:46
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77
Dynamic access interface for FIELD-valued parameters.
Return value of any collision.
Definition interface.h:45
Interface for per-cell dynamics.
Definition interface.h:56
virtual std::string getName() const
Return human-readable name.
Definition interface.h:65
CellStatistic< V > collide(CELL &cell, PARAMETERS &parameters) any_platform
Apply purely-local collision step to a generic CELL.
Definition interface.h:360
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 bgkCollision(CELL &cell, const RHO &rho, const VELOCITY &u, const OMEGA &omega) any_platform
BGK collision step.
Definition lbm.h:372
void computeEquilibrium(ConstCell< T, DESCRIPTOR > &cell, T rho, const T u[DESCRIPTOR::d], T fEq[DESCRIPTOR::q]) const override
Return iPop equilibrium for given first and second momenta.
Definition dynamics.h:36
AbstractParameters< T, DESCRIPTOR > & getParameters(BlockLattice< T, DESCRIPTOR > &block) override
Parameters access for legacy post processors.
Definition dynamics.h:46
std::type_index id() override
Expose unique type-identifier for RTTI.
Definition dynamics.h:42
Compute number of elements of a symmetric d-dimensional tensor.
Definition util.h:216