OpenLB 1.7
Loading...
Searching...
No Matches
rtlbmDynamics.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2017-2019 Albert Mink, Christopher McHardy
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
28#ifndef RTLBM_DYNAMICS_HH
29#define RTLBM_DYNAMICS_HH
30
31#include "rtlbmDynamics.h"
32#include "rtlbmDescriptors.h"
33#include "lbm.h"
34
35namespace olb {
36
37
38
39//==================================================================//
40//============= BGK Model for Advection diffusion anisotropic ===//
41//==================================================================//
42
43template<typename T, typename DESCRIPTOR, typename MOMENTA>
45(T latticeAbsorption, T latticeScattering, std::array<std::array<T,DESCRIPTOR::q>, DESCRIPTOR::q>& anisoMatrix)
46 : legacy::BasicDynamics<T, DESCRIPTOR, MOMENTA>(), _absorption(latticeAbsorption), _scattering(latticeScattering), _anisoMatrix(anisoMatrix)
47{
48 this->getName() = "RTLBMdynamicsMcHardy";
49}
50
51template<typename T, typename DESCRIPTOR, typename MOMENTA>
52T RTLBMdynamicsMcHardy<T, DESCRIPTOR, MOMENTA>::computeEquilibrium( int iPop, T rho, const T u[DESCRIPTOR::d], T uSqr ) const
53{
54 return rho*descriptors::t<T,DESCRIPTOR>(iPop) - descriptors::t<T,DESCRIPTOR>(iPop);
55}
56
57
58template<typename T, typename DESCRIPTOR, typename MOMENTA>
60{
61 std::array<double, DESCRIPTOR::q> feq = {};
62 for ( int iPop = 0; iPop < DESCRIPTOR::q; ++iPop ) {
63 for ( int jPop = 0; jPop < DESCRIPTOR::q; ++jPop ) {
64 feq[iPop] += (cell[jPop] + descriptors::t<T,DESCRIPTOR>(jPop)) * _anisoMatrix[jPop][iPop];
65 }
66 feq[iPop] *= descriptors::t<T,DESCRIPTOR>(iPop);
67 }
68 // execute collision
69 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
70 cell[iPop] = (cell[iPop]+descriptors::t<T,DESCRIPTOR>(iPop))
71 - descriptors::norm_c<T,DESCRIPTOR>(iPop)*(_absorption+_scattering) * ( (cell[iPop]+descriptors::t<T,DESCRIPTOR>(iPop))- feq[iPop] )
72 - _absorption*descriptors::norm_c<T,DESCRIPTOR>(iPop) *(cell[iPop]+descriptors::t<T,DESCRIPTOR>(iPop))
73 - descriptors::t<T,DESCRIPTOR>(iPop);
74 }
75 T temperature = lbm<DESCRIPTOR>::computeRho(cell);
76 statistics.incrementStats( temperature, T() );
77}
78
79template<typename T, typename DESCRIPTOR, typename MOMENTA>
84
85template<typename T, typename DESCRIPTOR, typename MOMENTA>
89
90//==================================================================================//
91template<typename T, typename DESCRIPTOR, typename MOMENTA>
93(T latticeAbsorption, T latticeScattering, std::array<std::array<T,DESCRIPTOR::q>, DESCRIPTOR::q>& anisoMatrix)
94 : legacy::BasicDynamics<T, DESCRIPTOR, MOMENTA>(), _absorption(latticeAbsorption), _scattering(latticeScattering), _anisoMatrix(anisoMatrix)
95{
96 this->getName() = "RTLBMdynamicsMcHardyRK";
97}
98
99template<typename T, typename DESCRIPTOR, typename MOMENTA>
100T RTLBMdynamicsMcHardyRK<T, DESCRIPTOR, MOMENTA>::computeEquilibrium( int iPop, T rho, const T u[DESCRIPTOR::d], T uSqr ) const
101{
102 return rho*descriptors::t<T,DESCRIPTOR>(iPop) - descriptors::t<T,DESCRIPTOR>(iPop);
103}
104
105template<typename T, typename DESCRIPTOR, typename MOMENTA>
107{
108 feq.fill( T() );
109 for ( int iPop = 0; iPop < DESCRIPTOR::q; ++iPop ) {
110 for ( int jPop = 0; jPop < DESCRIPTOR::q; ++jPop ) {
111 feq[iPop] += cell[jPop] * _anisoMatrix[jPop][iPop];
112 }
113 feq[iPop] *= descriptors::t<T,DESCRIPTOR>(iPop);
114 }
115}
116
117template<typename T, typename DESCRIPTOR, typename MOMENTA>
118std::array<T,DESCRIPTOR::q> RTLBMdynamicsMcHardyRK<T,DESCRIPTOR,MOMENTA>::doCollision(Cell<T,DESCRIPTOR>& cell, std::array<T,DESCRIPTOR::q>& feq)
119{
120 std::array<T,DESCRIPTOR::q> k;
121 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
122 k[iPop] = - descriptors::norm_c<T,DESCRIPTOR>(iPop)*(_absorption+_scattering) * (cell[iPop])
123 + descriptors::norm_c<T,DESCRIPTOR>(iPop)*_scattering * feq[iPop];
124 }
125 return k;
126}
127
128template<typename T, typename DESCRIPTOR, typename MOMENTA>
130{
131 std::array<T,DESCRIPTOR::q> feq;
132 std::array<T,DESCRIPTOR::q> f_pre_collision;
133 // separate cell and precollision f_i
134 for ( int iPop = 0; iPop < DESCRIPTOR::q; ++iPop ) {
135 f_pre_collision[iPop] = cell[iPop] + descriptors::t<T,DESCRIPTOR>(iPop);
136 }
137
138 // shift only first collision und equilibrium and then at the very end
139 for ( int iPop = 0; iPop < DESCRIPTOR::q; ++iPop ) {
140 cell[iPop] += descriptors::t<T,DESCRIPTOR>(iPop);
141 }
142 computeEquilibriumAniso(cell,feq);
143 std::array<T,DESCRIPTOR::q> k1 = doCollision(cell,feq);
144 // update cell
145 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
146 cell[iPop] = f_pre_collision[iPop] + 0.5*k1[iPop];
147 }
148
149 computeEquilibriumAniso(cell,feq);
150 std::array<T,DESCRIPTOR::q> k2 = doCollision(cell,feq);
151 // update cell
152 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
153 cell[iPop] = f_pre_collision[iPop] + 0.5*k2[iPop];
154 }
155
156 computeEquilibriumAniso(cell,feq);
157 std::array<T,DESCRIPTOR::q> k3 = doCollision(cell,feq);
158 // update cell
159 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
160 cell[iPop] = f_pre_collision[iPop] + k3[iPop];
161 }
162
163 computeEquilibriumAniso(cell,feq);
164 std::array<T,DESCRIPTOR::q> k4 = doCollision(cell,feq);
165 // update cell
166 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
167 cell[iPop] = f_pre_collision[iPop] + 1/6.*(k1[iPop] + 2*k2[iPop] + 2*k3[iPop] + k4[iPop])
168 - descriptors::t<T,DESCRIPTOR>(iPop); // back shift for OpenLB
169 }
170 T temperature = lbm<DESCRIPTOR>::computeRho(cell);
171 statistics.incrementStats( temperature, T() );
172}
173
174template<typename T, typename DESCRIPTOR, typename MOMENTA>
179
180template<typename T, typename DESCRIPTOR, typename MOMENTA>
184
185
186} // namespace olb
187
188
189#endif
190
Highest-level interface to Cell data.
Definition cell.h:148
void incrementStats(T rho, T uSqr)
CellStatistic< T > collide(Cell< T, DESCRIPTOR > &cell, LatticeStatistics< T > &statistics) override
Collision step.
T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d], T uSqr) const override
Compute equilibrium distribution function.
void setOmega(T omega)
Set local relaxation parameter of the dynamics.
RTLBMdynamicsMcHardyRK(T latticeAbsorption, T latticeScattering, std::array< std::array< T, DESCRIPTOR::q >, DESCRIPTOR::q > &anisoMatrix)
Constructor.
T getOmega() const
Get local relaxation parameter of the dynamics.
RTLBMdynamicsMcHardy(T latticeAbsorption, T latticeScattering, std::array< std::array< T, DESCRIPTOR::q >, DESCRIPTOR::q > &anisoMatrix)
Constructor.
CellStatistic< T > collide(Cell< T, DESCRIPTOR > &cell, LatticeStatistics< T > &statistics) override
Collision step.
T getOmega() const
Get local relaxation parameter of the dynamics.
T computeEquilibrium(int iPop, T rho, const T u[DESCRIPTOR::d], T uSqr) const override
Compute equilibrium distribution function.
void setOmega(T omega)
Set local relaxation parameter of the dynamics.
Top level namespace for all of OpenLB.
– header file
A collection of radiative transport dynamics classes – header file.
Return value of any collision.
Definition interface.h:43
virtual std::string getName() const
Return human-readable name.
Definition interface.h:63
static V computeRho(CELL &cell) any_platform
Computation of density.
Definition lbm.h:185