MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
lbsrctermsgs.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#include "IO/context.h"
8#include "UTIL/debug.h"
9#include "UTIL/parallelfor.h"
10#include "lbsolverdxqy.h"
11#include "lbsrcterm.h"
12#include "lbsrctermcontroller.h"
13
14namespace maia::lb {
15
16//---LbSrcTerm_smagorinsky--------------------------------------------------
17//-declaration
22template <MInt nDim, MInt nDist, class SysEqn, MBool bubble = false>
23class LbSrcTerm_smagorinsky : public LbSrcTerm<nDim, nDist, SysEqn> {
24 protected:
26 MFloat m_Cs = 0.1;
27 const MFloat m_deltaX = 1.0;
28
29 void readProperties() override;
30
31 public:
32 // static const LbRegSrcTerm<nDim, nDist, LbSrcTerm_smagorinsky<nDim, nDist, SysEqn>> reg;
33
35
36 void init() override{/*NOT USED*/};
37 void apply_preCollision() override;
38 void apply_postCollision() override{/*NOT USED*/};
39 void apply_postPropagation() override{/*NOT USED*/};
40};
41
42//-definiton
43template <MInt nDim, MInt nDist, class SysEqn, MBool bubble>
45 TRACE();
46 const MInt solverId = m_solver->m_solverId;
47 if(Context::propertyExists("smagorinskyConstant")) {
48 m_Cs = Context::getSolverProperty<MFloat>("smagorinskyConstant", solverId, AT_);
49 }
50}
51
52template <MInt nDim, MInt nDist, class SysEqn, MBool bubble>
54 TRACE();
55 LbSolverDxQy<nDim, nDist, SysEqn>* const s = m_solver; // alias for readability
56
57 s->m_nu = s->m_Ma * LBCS / s->m_Re * s->m_referenceLength;
58 maia::parallelFor<false>(0, s->m_currentMaxNoCells, [=](MInt index) {
59 const MInt pCellId = s->m_activeCellList[index];
60 const MInt lvlDiff = s->maxLevel() - s->a_level(pCellId);
61 if((globalTimeStep - 1) % IPOW2(lvlDiff) != 0) return;
62 // TODO labels:LB daniell: This is critical for setting a_oldNu ?! But without
63 // test case 3D_LB-FV_Euler-Euler_bubble_sphere fails
64 s->a_nu(pCellId) = s->m_nu;
65 // Ref: Hou, Sterling, Chen, and Doolen 1994
66 // Also worth reading: Siebler, Krafczyk, Freudiger, and Geier 2011
67 constexpr MInt nDimSqr = nDim * nDim;
68 MFloat c[nDimSqr]{};
69 const MFloat rho = s->a_variable(pCellId, s->PV->RHO);
70#ifndef WAR_NVHPC_PSTL
71 const MFloat* const u = &s->a_variable(pCellId, s->PV->U);
72 const MFloat* const dist = &s->a_oldDistribution(pCellId, 0);
73 s->sysEqn().calcMomentumFlux(rho, u, dist, c);
74#else
75 MFloat u[nDim] = {F0};
76 MFloat dist[nDist] = {F0};
77 for(MInt d = 0; d < nDim; d++) {
78 u[d] = s->a_variable(pCellId, d);
79 }
80 for(MInt d = 0; d < nDist; d++) {
81 dist[d] = s->a_oldDistribution(pCellId, d);
82 }
83 s->sysEqn().calcMomentumFlux(rho, u, dist, c);
84#endif
85 const MFloat Q = sqrt(2.0 * std::inner_product(&c[0], &c[nDimSqr], &c[0], .0));
86 MFloat nu_BIT = 0.0;
87 if constexpr(bubble) {
88 if(s->m_isEELiquid) {
89 // BIT (bubble induced turbulence) see Mohammadi 19 / Sato 81 / Milelli 01
90 const MFloat u_d = sqrt(POW2(s->a_uOtherPhase(pCellId, 0) - u[0]) + POW2(s->a_uOtherPhase(pCellId, 1) - u[1])
91 + POW2(s->a_uOtherPhase(pCellId, 2) - u[2]));
92 nu_BIT = m_Cs * s->a_alphaGasLim(pCellId) * u_d;
93 }
94 }
95 // The stress tensor S_mean depends on tau and tau depends on S_mean.
96 // This leads to a quadratic equation, that is solved by this.
97 MFloat tauBase = F1B2 + 3.0 * (s->m_nu + nu_BIT) * FFPOW2(s->maxLevel() - s->a_level(pCellId));
98 const MFloat tau = F1B2
99 * (tauBase
100 + sqrt(tauBase * tauBase
101 + 2.0 * m_Cs * m_Cs * m_deltaX * m_deltaX * (F1BCSsq * F1BCSsq) * Q
102 * FPOW2(s->maxLevel() - s->a_level(pCellId))));
103
104 // eddy viscosity
105 if constexpr(bubble) {
106 if(s->m_cells.saveOldNu()) {
107 s->a_oldNu(pCellId) = s->a_nu(pCellId);
108 }
109 }
110 s->a_nu(pCellId) = (2.0 * tau - 1.0) * CSsq * FPOW2(s->maxLevel() - s->a_level(pCellId)) / 2.0;
111 if constexpr(bubble) {
112 if(s->m_isEELiquid) {
113 if(s->m_cells.saveOldNu()) {
114 s->a_oldNuT(pCellId) = s->a_nuT(pCellId);
115 }
116 s->a_nuT(pCellId) = s->a_nu(pCellId) - s->m_nu - nu_BIT;
117 }
118 }
119 });
120}
121
122//-registration for LbSrcTermFactory class
123static const LbRegSrcTerm<LbSrcTerm_smagorinsky<2, 9, LbSysEqnIncompressible<2, 9>, false>>
124 reg_Smagorinskyd2q9("LB_SRC_SMAGORINSKY");
125static const LbRegSrcTerm<LbSrcTerm_smagorinsky<3, 19, LbSysEqnIncompressible<3, 19>, false>>
126 reg_Smagorinskyd3q19("LB_SRC_SMAGORINSKY");
127static const LbRegSrcTerm<LbSrcTerm_smagorinsky<3, 27, LbSysEqnIncompressible<3, 27>, false>>
128 reg_Smagorinskyd3q27("LB_SRC_SMAGORINSKY");
129
130static const LbRegSrcTerm<LbSrcTerm_smagorinsky<2, 9, LbSysEqnIncompressible<2, 9>, true>>
131 reg_SmagorinskydBubble2q9("LB_SRC_SMAGORINSKY_BUBBLE");
132static const LbRegSrcTerm<LbSrcTerm_smagorinsky<3, 19, LbSysEqnIncompressible<3, 19>, true>>
133 reg_SmagorinskydBubble3q19("LB_SRC_SMAGORINSKY_BUBBLE");
134static const LbRegSrcTerm<LbSrcTerm_smagorinsky<3, 27, LbSysEqnIncompressible<3, 27>, true>>
135 reg_SmagorinskydBubble3q27("LB_SRC_SMAGORINSKY_BUBBLE");
136
137static const LbRegSrcTerm<LbSrcTerm_smagorinsky<2, 9, LbSysEqnCompressible<2, 9>, false>>
138 reg_Smagorinskyd2q9C("LB_SRC_SMAGORINSKY");
139static const LbRegSrcTerm<LbSrcTerm_smagorinsky<3, 19, LbSysEqnCompressible<3, 19>, false>>
140 reg_Smagorinskyd3q19C("LB_SRC_SMAGORINSKY");
141static const LbRegSrcTerm<LbSrcTerm_smagorinsky<3, 27, LbSysEqnCompressible<3, 27>, false>>
142 reg_Smagorinskyd3q27C("LB_SRC_SMAGORINSKY");
143
144static const LbRegSrcTerm<LbSrcTerm_smagorinsky<2, 9, LbSysEqnCompressible<2, 9>, true>>
145 reg_SmagorinskydBubble2q9C("LB_SRC_SMAGORINSKY_BUBBLE");
146static const LbRegSrcTerm<LbSrcTerm_smagorinsky<3, 19, LbSysEqnCompressible<3, 19>, true>>
147 reg_SmagorinskydBubble3q19C("LB_SRC_SMAGORINSKY_BUBBLE");
148static const LbRegSrcTerm<LbSrcTerm_smagorinsky<3, 27, LbSysEqnCompressible<3, 27>, true>>
149 reg_SmagorinskydBubble3q27C("LB_SRC_SMAGORINSKY_BUBBLE");
150
151} // namespace maia::lb
static MBool propertyExists(const MString &name, MInt solver=m_noSolvers)
This function checks if a property exists in general.
Definition: context.cpp:494
This class represents all LB models.
Definition: lbsolverdxqy.h:29
constexpr SysEqn sysEqn() const
Definition: lbsolverdxqy.h:194
Class to handle sub-grid scale model (Smagorinsky)
LbSrcTerm_smagorinsky(LbSolverDxQy< nDim, nDist, SysEqn > *p_solver)
MFloat m_Cs
Smagorinsky constant.
LbSolverDxQy< nDim, nDist, SysEqn > * m_solver
void apply_postPropagation() override
const MFloat m_deltaX
Filter width.
Abstract class for lb source terms.
Definition: lbsrcterm.h:22
constexpr Real POW2(const Real x)
Definition: functions.h:119
constexpr MFloat FPOW2(MInt x)
constexpr MFloat FFPOW2(MInt x)
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52
MFloat dist(const Point< DIM > &p, const Point< DIM > &q)
Definition: pointbox.h:54