OpenLB 1.8.1
Loading...
Searching...
No Matches
collisionMRT.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_COLLISION_MRT_H
25#define DYNAMICS_COLLISION_MRT_H
26
27#include "mrt.h"
28#include "descriptor/fields.h"
30
32
33namespace olb {
34
35namespace collision {
36
37struct MRT {
39
40 static std::string getName() {
41 return "MRT";
42 }
43
44 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
45 struct type {
46 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
47 using EquilibriumF = typename EQUILIBRIUM::template type<DESCRIPTOR,MOMENTA>;
48
49 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
50 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) {
51 const V omega = parameters.template get<descriptors::OMEGA>();
52
53 V rt[DESCRIPTOR::q] { }; // relaxation times vector.
54 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
55 rt[iPop] = descriptors::s<V,DESCRIPTOR>(iPop);
56 }
57 for (int iPop=0; iPop < descriptors::shearIndexes<DESCRIPTOR>(); ++iPop) {
59 }
60 V invM_S[DESCRIPTOR::q][DESCRIPTOR::q] { }; // relaxation times matrix
61 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
62 for (int jPop = 0; jPop < DESCRIPTOR::q; ++jPop) {
63 invM_S[iPop][jPop] = V{};
64 for (int kPop = 0; kPop < DESCRIPTOR::q; ++kPop) {
65 if (kPop == jPop) {
66 invM_S[iPop][jPop] += descriptors::invM<V,DESCRIPTOR>(iPop,kPop) * rt[kPop];
67 }
68 }
69 }
70 }
71
72 V rho, u[DESCRIPTOR::d];
73 MomentaF().computeRhoU(cell, rho, u);
74 V uSqr = mrt<DESCRIPTOR>::mrtCollision(cell, rho, u, invM_S);
75
76 return {rho, uSqr};
77 };
78 };
79};
80
81}
82
83namespace forcing {
84
86
90 static std::string getName() {
91 return "LaddVerbergForcing";
92 }
93
94 template <typename DESCRIPTOR, typename MOMENTA>
95 using combined_momenta = typename MOMENTA::template type<DESCRIPTOR>;
96
97 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
98 using combined_equilibrium = typename EQUILIBRIUM::template type<DESCRIPTOR,MOMENTA>;
99
100 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
102 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
103 using CollisionO = typename COLLISION::template type<DESCRIPTOR,MOMENTA,EQUILIBRIUM>;
104
105 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
106 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) {
107 V rho, u[DESCRIPTOR::d];
108 MomentaF().computeRhoU(cell, rho, u);
109 const auto statistic = CollisionO().apply(cell, parameters);
110 const V omega = parameters.template get<descriptors::OMEGA>();
111 // While this duplication can be resolved using CSE it should be extracted into a helper
112 V rt[DESCRIPTOR::q] { }; // relaxation times vector.
113 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
114 rt[iPop] = descriptors::s<V,DESCRIPTOR>(iPop);
115 }
116 for (int iPop=0; iPop < descriptors::shearIndexes<DESCRIPTOR>(); ++iPop) {
118 }
119 V invM_S[DESCRIPTOR::q][DESCRIPTOR::q]; // relaxation times matrix
120 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
121 for (int jPop = 0; jPop < DESCRIPTOR::q; ++jPop) {
122 invM_S[iPop][jPop] = V{};
123 for (int kPop = 0; kPop < DESCRIPTOR::q; ++kPop) {
124 if (kPop == jPop) {
125 invM_S[iPop][jPop] += descriptors::invM<V,DESCRIPTOR>(iPop,kPop) * rt[kPop];
126 }
127 }
128 }
129 }
130 const auto force = cell.template getField<descriptors::FORCE>();
131 mrt<DESCRIPTOR>::addExternalForce(cell, rho, u, invM_S, force);
132 return statistic;
133 };
134 };
135
136 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
137 using combined_parameters = typename COLLISION::parameters;
138};
139
140}
141
142}
143
144#endif
Helper functions for the implementation of LB dynamics.
Interface for post-processing steps – header file.
constexpr T s(unsigned iPop, tag::MRT)
Definition mrt.h:410
constexpr int shearViscIndexes(unsigned iPop, tag::MRT)
Definition mrt.h:446
constexpr T invM(unsigned iPop, unsigned jPop, tag::MRT)
Definition mrt.h:398
Top level namespace for all of OpenLB.
Return value of any collision.
Definition interface.h:45
typename EQUILIBRIUM::template type< DESCRIPTOR, MOMENTA > EquilibriumF
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters)
typename meta::list< descriptors::OMEGA > parameters
static std::string getName()
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters)
typename COLLISION::template type< DESCRIPTOR, MOMENTA, EQUILIBRIUM > CollisionO
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Dynamics combination rule implementing the forcing scheme by Ladd and Verberg.
typename EQUILIBRIUM::template type< DESCRIPTOR, MOMENTA > combined_equilibrium
typename MOMENTA::template type< DESCRIPTOR > combined_momenta
static std::string getName()
typename COLLISION::parameters combined_parameters
Plain wrapper for list of types.
Definition meta.h:276
static V mrtCollision(CELL &cell, const RHO &rho, const U &u, const INVM_S &invM_S)
MRT collision step.
Definition mrt.h:88
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