OpenLB 1.7
Loading...
Searching...
No Matches
mrt.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2006, 2007, 2013 Jonas Latt, Mathias J. Krause, Geng Liu
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 MRT_H
31#define MRT_H
32
33#include "lbm.h"
35
36namespace olb {
37
38template<typename DESCRIPTOR>
39struct mrt {
40 static_assert(
41 std::is_same<typename DESCRIPTOR::category_tag, descriptors::tag::MRT>::value,
42 "DESCRIPTOR is tagged as MRT");
43
45 template <typename RHO, typename U, typename V=RHO>
46 static V equilibrium(int iPop, const RHO& rho, const U& u)
47 {
48 V equ{};
49 const V uSqr = util::normSqr<U,DESCRIPTOR::d>(u);
50 for (int jPop = 0; jPop < DESCRIPTOR::q; ++jPop) {
51 equ += descriptors::m<V,DESCRIPTOR>(iPop,jPop) *
53 descriptors::t<V,DESCRIPTOR>(jPop));
54 }
55 return equ;
56 }
57
59 template <typename MOMENTAEQ, typename RHO, typename U, typename V=RHO>
60 static void computeEquilibrium(MOMENTAEQ& momentaEq,
61 const RHO& rho, const U& u)
62 {
63 const V uSqr = util::normSqr<U,DESCRIPTOR::d>(u);
64 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
65 momentaEq[iPop] = V{};
66 for (int jPop = 0; jPop < DESCRIPTOR::q; ++jPop) {
67 momentaEq[iPop] += descriptors::m<V,DESCRIPTOR>(iPop,jPop) *
69 descriptors::t<V,DESCRIPTOR>(jPop));
70 }
71 }
72 }
73
74 template <typename MOMENTA, typename CELL, typename V=typename CELL::value_t>
75 static void computeMomenta(MOMENTA& momenta, CELL& cell)
76 {
77 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
78 momenta[iPop] = V{};
79 for (int jPop = 0; jPop < DESCRIPTOR::q; ++jPop) {
80 momenta[iPop] += descriptors::m<V,DESCRIPTOR>(iPop,jPop) *
81 (cell[jPop] + descriptors::t<V,DESCRIPTOR>(jPop));
82 }
83 }
84 }
85
87 template <typename CELL, typename RHO, typename U, typename INVM_S, typename V=typename CELL::value_t>
88 static V mrtCollision(CELL& cell,
89 const RHO& rho, const U& u,
90 const INVM_S& invM_S)
91 {
92 V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
93 V momenta[DESCRIPTOR::q] { };
94 V momentaEq[DESCRIPTOR::q] { };
95
96 computeMomenta(momenta, cell);
97 computeEquilibrium(momentaEq, rho, u);
98
99 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
100 V collisionTerm{};
101 for (int jPop = 0; jPop < DESCRIPTOR::q; ++jPop) {
102 collisionTerm += invM_S[iPop][jPop] * (momenta[jPop] - momentaEq[jPop]);
103 }
104 cell[iPop] -= collisionTerm;
105 }
106 return uSqr;
107 }
108
110 template <typename CELL, typename RHO, typename U, typename OMEGA, typename INVM_S_SGS, typename V=typename CELL::value_t>
111 static V mrtSGSCollision(CELL& cell,
112 const RHO& rho, const U& u,
113 const OMEGA& omega,
114 const INVM_S_SGS& invM_S_SGS)
115 {
116 V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
117 V momenta[DESCRIPTOR::q];
118 V momentaEq[DESCRIPTOR::q];
119
120 computeMomenta(momenta, cell);
121 computeEquilibrium(momentaEq, rho, u);
122
123 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
124 V collisionTerm{};
125 for (int jPop = 0; jPop < DESCRIPTOR::q; ++jPop) {
126 collisionTerm += invM_S_SGS[iPop][jPop] * (momenta[jPop] - momentaEq[jPop]);
127 }
128 cell[iPop] -= collisionTerm;
129 }
130
131 return uSqr;
132 }
133
134
137 template <typename CELL, typename RHO, typename U, typename INVM_S, typename FORCE, typename V=typename CELL::value_t>
138 static void addExternalForce(CELL& cell,
139 const RHO& rho, const U& u,
140 const INVM_S& invM_S,
141 const FORCE& force)
142 {
143 V f_u{};
144 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
145 f_u += force[iD] * u[iD];
146 }
147
148 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
149 V c_u{};
150 V c_f{};
151 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
152 c_u += descriptors::c<DESCRIPTOR>(iPop,iD)*u[iD];
153 c_f += descriptors::c<DESCRIPTOR>(iPop,iD)*force[iD];
154 }
155 V f1 = descriptors::t<V,DESCRIPTOR>(iPop)*rho*c_f*descriptors::invCs2<V,DESCRIPTOR>();
156 V f2 = descriptors::t<V,DESCRIPTOR>(iPop)*rho*(c_u*c_f*descriptors::invCs2<V,DESCRIPTOR>()-f_u)*descriptors::invCs2<V,DESCRIPTOR>();
157
158 V invMsM{};
159 for (int jPop=0; jPop < DESCRIPTOR::q; ++jPop) {
160 invMsM += invM_S[iPop][jPop]*descriptors::m<V,DESCRIPTOR>(jPop,iPop);
161 }
162 cell[iPop] += f1 + f2 - invMsM*f2*V{0.5};
163 }
164 }
165
166};
167
168}
169
170#endif
DESCRIPTORBASE for all types of 2D and 3D lattices.
Top level namespace for all of OpenLB.
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
Definition mrt.h:39
static void computeMomenta(MOMENTA &momenta, CELL &cell)
Definition mrt.h:75
static V mrtSGSCollision(CELL &cell, const RHO &rho, const U &u, const OMEGA &omega, const INVM_S_SGS &invM_S_SGS)
MRT SGS collision step.
Definition mrt.h:111
static V mrtCollision(CELL &cell, const RHO &rho, const U &u, const INVM_S &invM_S)
MRT collision step.
Definition mrt.h:88
static V equilibrium(int iPop, const RHO &rho, const U &u)
Computation of equilibrium distribution (in momenta space)
Definition mrt.h:46
static void addExternalForce(CELL &cell, const RHO &rho, const U &u, const INVM_S &invM_S, const FORCE &force)
Ladd-Verberg-I body force model for MRT A.Ladd, R.
Definition mrt.h:138
static void computeEquilibrium(MOMENTAEQ &momentaEq, const RHO &rho, const U &u)
Computation of all equilibrium distribution (in momenta space)
Definition mrt.h:60