OpenLB 1.7
Loading...
Searching...
No Matches
collisionKBC.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 Louis Kronberg, Stephan Simonis
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 KBC_COLLISION_H
25#define KBC_COLLISION_H
26
27#include "lbm.h"
29
30namespace olb {
31
32namespace collision {
33
35struct KBC {
37
38 static std::string getName() {
39 return "KBC";
40 }
41
42 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
43 struct type {
44
45 // not using a D3Q19 lattice is a compiler error, because currently this struct implements KBC only for D3Q19
46 static_assert(DESCRIPTOR::d == 3 && DESCRIPTOR::q == 19, "KBC only implemented for D3Q19");
47
48 using EquilibriumF = typename EQUILIBRIUM::template type<DESCRIPTOR,MOMENTA>;
49 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
50
51 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
52 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
53
54 V fEq[DESCRIPTOR::q] { };
55 const auto statistic = EquilibriumF().compute(cell, parameters, fEq);
56 V rho, u[DESCRIPTOR::d];
57 MomentaF().computeRhoU(cell, rho, u);
58
59 const V omega = parameters.template get<descriptors::OMEGA>();
60
61 V df[DESCRIPTOR::q];
62 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
63 df[iPop] = cell[iPop] - fEq[iPop];
64 fEq[iPop] += descriptors::t<V,DESCRIPTOR>(iPop);
65 }
66
67 V M200 = 0 , M011 = 0;
68 V M002 = 0, M110 = 0;
69 V M020 = 0, M101 = 0;
70 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
71 V c0 = descriptors::c<DESCRIPTOR::d, DESCRIPTOR::q>(iPop, 0);
72 V c1 = descriptors::c<DESCRIPTOR::d, DESCRIPTOR::q>(iPop, 1);
73 V c2 = descriptors::c<DESCRIPTOR::d, DESCRIPTOR::q>(iPop, 2);
74
75 M200 += c0 * c0 * df[iPop];
76 M020 += c1 * c1 * df[iPop];
77 M002 += c2 * c2 * df[iPop];
78
79 M110 += c0 * c1 * df[iPop];
80 M011 += c1 * c2 * df[iPop];
81 M101 += c0 * c2 * df[iPop];
82 }
83
84
85 V Nxz = M200 - M002;
86 V Nyz = M020 - M002;
87
88 V Pxy = M110;
89 V Pxz = M101;
90 V Pyz = M011;
91
92
93 V ds[DESCRIPTOR::q] = {
94 0,
95 Nxz/3 - Nyz/6, Nyz/3 - Nxz/6, - Nxz/6 - Nyz/6,
96 Pxy/4, -Pxy/4, Pxz/4,
97 -Pxz/4, Pyz/4, -Pyz/4,
98 Nxz/3 - Nyz/6, Nyz/3 - Nxz/6, - Nxz/6 - Nyz/6,
99 Pxy/4, -Pxy/4, Pxz/4,
100 -Pxz/4, Pyz/4, -Pyz/4,
101 };
102
103
104 V dh[DESCRIPTOR::q];
105 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
106 dh[iPop] = df[iPop] - ds[iPop];
107 }
108
109 V beta = omega / 2;
110 V dsdh(0);
111 V dhdh(0);
112 for (int iPop = 0; iPop < DESCRIPTOR::q; ++iPop) {
113 dsdh += ds[iPop] * dh[iPop] / fEq[iPop];
114 dhdh += dh[iPop] * dh[iPop] / fEq[iPop];
115 }
116
117 V gamma = dhdh < 1.0e-10 ? 2.0: 1.0/beta - (2 - 1./beta) * dsdh/dhdh;
118 //V gamma = 2.0;
119
120 cell.template setField<descriptors::GAMMA>(gamma);
121 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
122 cell[iPop] -= beta * (2*ds[iPop] + gamma*dh[iPop]);
123 }
124
125 return statistic;
126 };
127 };
128};
129
130}
131}
132#endif
Interface for post-processing steps – header file.
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
Return value of any collision.
Definition interface.h:43
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
typename EQUILIBRIUM::template type< DESCRIPTOR, MOMENTA > EquilibriumF
typename MOMENTA::template type< DESCRIPTOR > MomentaF
Implementation of the KBC method. See 10.1103/PhysRevE.90.031302.
static std::string getName()
typename meta::list< descriptors::OMEGA > parameters
Plain wrapper for list of types.
Definition meta.h:276