OpenLB 1.7
Loading...
Searching...
No Matches
guoZhaoDynamics.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2016-2017 Davide Dapelo, Mathias J. Krause
4 * OpenLB 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 LB_GUOZHAO_DYNAMICS_H
29#define LB_GUOZHAO_DYNAMICS_H
30
31#include <type_traits>
32#include <functional>
33
34#include "momenta/interface.h"
35#include "interface.h"
36
37#include "core/util.h"
38#include "core/postProcessing.h"
40#include "latticeDescriptors.h"
41
42#include "momenta/interface.h"
43#include "momenta/aliases.h"
44
45#include "collision.h"
46#include "equilibrium.h"
47#include "forcing.h"
48
49namespace olb {
50
51namespace guoZhao {
52
53
54template <typename DESCRIPTOR>
57 template <typename RHO, typename U, typename USQR, typename EPSILON, typename V=RHO>
58 static V secondOrder(int iPop, const RHO& rho, const U& u, const USQR& uSqr, const EPSILON& epsilon) any_platform
59 {
60 V c_u{};
61 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
62 c_u += descriptors::c<DESCRIPTOR>(iPop,iD)*u[iD];
63 }
64 return rho
65 * descriptors::t<V,DESCRIPTOR>(iPop)
66 * ( V{1}
67 + descriptors::invCs2<V,DESCRIPTOR>() * c_u
68 + descriptors::invCs2<V,DESCRIPTOR>() * descriptors::invCs2<V,DESCRIPTOR>() * V{0.5} * c_u * c_u / epsilon
69 - descriptors::invCs2<V,DESCRIPTOR>() * V{0.5} * uSqr / epsilon)
70 - descriptors::t<V,DESCRIPTOR>(iPop);
71 }
72};
73
74template <typename DESCRIPTOR>
77 template <typename CELL, typename RHO, typename U, typename OMEGA, typename EPSILON, typename K, typename NU, typename FORCE, typename V=typename CELL::value_t>
78 static void addExternalForce(CELL& cell, const RHO& rho, const U& u, const OMEGA& omega, const EPSILON& epsilon, const K& k, const NU& nu, const FORCE& force) any_platform
79 {
80 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
81 V c_u = V();
82 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
83 c_u += descriptors::c<DESCRIPTOR>(iPop,iD)*u[iD];
84 }
85 c_u *= descriptors::invCs2<V,DESCRIPTOR>()*descriptors::invCs2<V,DESCRIPTOR>()/epsilon;
86 V forceTerm = V();
87 for (int iD=0; iD < DESCRIPTOR::d; ++iD) {
88 forceTerm +=
89 ( (epsilon*(V)descriptors::c<DESCRIPTOR>(iPop,iD)-u[iD]) * descriptors::invCs2<V,DESCRIPTOR>()/epsilon
90 + c_u * descriptors::c<DESCRIPTOR>(iPop,iD)
91 )
92 * force[iD];
93 }
94 forceTerm *= descriptors::t<V,DESCRIPTOR>(iPop);
95 forceTerm *= V(1) - omega/V(2);
96 forceTerm *= rho;
97 cell[iPop] += forceTerm;
98 }
99 }
100
102 template <typename CELL, typename U, typename EPSILON, typename K, typename NU, typename FORCE, typename BODY_F, typename V=typename CELL::value_t>
103 static void updateExternalForce(CELL& cell, const U& u, const EPSILON& epsilon, const K& k, const NU& nu, FORCE& force, BODY_F& bodyF) any_platform
104 {
105 const V uMag = util::sqrt( util::normSqr<V,DESCRIPTOR::d>(u) );
106 const V Fe = 0;//1.75/util::sqrt(150.*util::pow(epsilon,3));
107
108 // Linear Darcy term, nonlinear Forchheimer term and body force
109 for (int iDim=0; iDim <DESCRIPTOR::d; iDim++) {
110 force[iDim] = -u[iDim]*epsilon*nu/k - epsilon*Fe/util::sqrt(k)*uMag*u[iDim] + bodyF[iDim]*epsilon;
111 }
112 }
113};
114
117
118 static std::string getName() {
119 return "GuoZhaoSecondOrder";
120 }
121
122 template <typename DESCRIPTOR, typename MOMENTA>
123 struct type {
124 using MomentaF = typename MOMENTA::template type<DESCRIPTOR>;
125
126 template <typename RHO, typename U>
127 auto compute(int iPop, const RHO& rho, const U& u) any_platform {
128 assert("GuoZhaoSecondOrder::compute(int, RHO&, U&) should never be called." && false);
129 return RHO();
130 }
131
132 template <typename CELL, typename PARAMETERS, typename FEQ, typename V=typename CELL::value_t>
133 CellStatistic<V> compute(CELL& cell, PARAMETERS& parameters, FEQ& fEq) any_platform {
134 const V epsilon = cell.template getField<descriptors::EPSILON>();
135 V rho, u[DESCRIPTOR::d];
136 MomentaF().computeRhoU(cell, rho, u);
137 const V uSqr = util::normSqr<V,DESCRIPTOR::d>(u);
138 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
139 fEq[iPop] = guoZhao_equilibrium<DESCRIPTOR>::secondOrder(iPop, rho, u, uSqr, epsilon);
140 }
141 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
142 };
143 };
144};
145
146template <template <typename> typename Forced = momenta::Forced>
148 static std::string getName() {
149 return "GuoEpsilonForcing";
150 }
151
152 template <typename DESCRIPTOR, typename MOMENTA>
153 using combined_momenta = typename Forced<MOMENTA>::template type<DESCRIPTOR>;
154
155 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM>
156 using combined_equilibrium = typename EQUILIBRIUM::template type<DESCRIPTOR,Forced<MOMENTA>>;
157
158 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
160 using MomentaF = typename Forced<MOMENTA>::template type<DESCRIPTOR>;
161 using CollisionO = typename COLLISION::template type<DESCRIPTOR,Forced<MOMENTA>,EQUILIBRIUM>;
162
163 static_assert(COLLISION::parameters::template contains<descriptors::OMEGA>(),
164 "COLLISION must be parametrized using relaxation frequency OMEGA");
165
166 template <typename CELL, typename PARAMETERS, typename V=typename CELL::value_t>
167 CellStatistic<V> apply(CELL& cell, PARAMETERS& parameters) any_platform {
168 V rho, u[DESCRIPTOR::d];
169 MomentaF().computeRhoU(cell, rho, u);
170 CollisionO().apply(cell, parameters);
171 const V omega = parameters.template get<descriptors::OMEGA>();
172 const V epsilon = cell.template getField<descriptors::EPSILON>();
173 const V k = cell.template getField<descriptors::K>();
174 const V nu = cell.template getField<descriptors::NU>();
175 auto force = cell.template getField<descriptors::FORCE>();
176 auto bodyF = cell.template getField<descriptors::BODY_FORCE>();
177 guoZhao_lbm<DESCRIPTOR>::updateExternalForce(cell, u,epsilon, k, nu, force, bodyF);
178 guoZhao_lbm<DESCRIPTOR>::addExternalForce(cell, rho, u, omega, epsilon, k, nu, force);
179 return {rho, util::normSqr<V,DESCRIPTOR::d>(u)};
180 };
181 };
182
183 template <typename DESCRIPTOR, typename MOMENTA, typename EQUILIBRIUM, typename COLLISION>
184 using combined_parameters = typename COLLISION::parameters;
185};
186
187}
188
189template <typename T, typename DESCRIPTOR, typename MOMENTA=momenta::BulkTuple>
191 T, DESCRIPTOR,
192 MOMENTA,
196>;
197
198template <typename T, typename DESCRIPTOR, typename MOMENTA=momenta::BulkTuple>
200 T, DESCRIPTOR,
201 MOMENTA,
205>;
206
207
208}
209
210#endif
211
212#include "guoZhaoDynamics.cse.h"
Instantiation of Momenta tuples which define the computation and definition of momenta in a specific ...
Descriptor for all types of 2D and 3D lattices.
Interface for post-processing steps – header file.
File provides a generic interface for the computation and definition of momenta (density,...
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
Top level namespace for all of OpenLB.
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:78
Interface for post-processing steps – header file.
Return value of any collision.
Definition interface.h:43
Compute dynamics parameter OMEGA locally using Smagorinsky LES model.
Dynamics constructed as a tuple of momenta, equilibrium and collision.
Definition interface.h:182
CellStatistic< V > apply(CELL &cell, PARAMETERS &parameters) any_platform
typename COLLISION::template type< DESCRIPTOR, Forced< MOMENTA >, EQUILIBRIUM > CollisionO
typename Forced< MOMENTA >::template type< DESCRIPTOR > MomentaF
static std::string getName()
typename COLLISION::parameters combined_parameters
typename Forced< MOMENTA >::template type< DESCRIPTOR > combined_momenta
typename EQUILIBRIUM::template type< DESCRIPTOR, Forced< MOMENTA > > combined_equilibrium
typename MOMENTA::template type< DESCRIPTOR > MomentaF
CellStatistic< V > compute(CELL &cell, PARAMETERS &parameters, FEQ &fEq) any_platform
auto compute(int iPop, const RHO &rho, const U &u) any_platform
static V secondOrder(int iPop, const RHO &rho, const U &u, const USQR &uSqr, const EPSILON &epsilon) any_platform
Computation of equilibrium distribution, second order in u.
static void updateExternalForce(CELL &cell, const U &u, const EPSILON &epsilon, const K &k, const NU &nu, FORCE &force, BODY_F &bodyF) any_platform
Updates the force terms with the reaction from the porous matrix, before applying it.
static void addExternalForce(CELL &cell, const RHO &rho, const U &u, const OMEGA &omega, const EPSILON &epsilon, const K &k, const NU &nu, const FORCE &force) any_platform
Add a force term after BGK collision.
Plain wrapper for list of types.
Definition meta.h:276
Set of functions commonly used in LB computations – header file.