MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
lbsrctermnonnewtonian.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 "enums.h"
11#include "lbsolverdxqy.h"
12#include "lbsrcterm.h"
13#include "lbsrctermcontroller.h"
14
15namespace maia::lb {
16
17//---LbSrcTerm_nonnewtonian--------------------------------------------------
18//-declaration
23template <MInt nDim, MInt nDist, class SysEqn>
24class LbSrcTerm_nonnewtonian : public LbSrcTerm<nDim, nDist, SysEqn> {
25 protected:
27
31 MFloat m_n = F0;
32 MFloat m_a = F0;
34 void readProperties() override;
35
36 public:
37 // static const LbRegSrcTerm<nDim, nDist, LbSrcTerm_nonnewtonian<nDim, nDist, SysEqn>> reg;
38
40
41 void init() override{/*NOT USED*/};
42 void apply_preCollision() override;
43 void apply_postCollision() override{/*NOT USED*/};
44 void apply_postPropagation() override{/*NOT USED*/};
45
47 MFloat powerLaw(const MFloat gamma_dot);
48 MFloat carreau(const MFloat gamma_dot);
49};
50
51//-definiton
52template <MInt nDim, MInt nDist, class SysEqn>
54 TRACE();
55 const MInt solverId = m_solver->m_solverId;
56
57 m_model = Context::getSolverProperty<MString>("nonNewtonianModel", solverId, AT_);
58
59 switch(string2enum(m_model)) {
60 case CARREAU: {
61 m_nu0 = m_solver->m_nu;
62 const MFloat nu0 = Context::getSolverProperty<MFloat>("nu0", solverId, AT_);
63 const MFloat c_nu = nu0 / m_nu0;
64
65 const MFloat nuInf = Context::getSolverProperty<MFloat>("nuInf", solverId, AT_);
66 m_nuInf = nuInf / c_nu;
67
68 const MFloat lambda = Context::getSolverProperty<MFloat>("lambda", solverId, AT_);
69
70 m_lambda = lambda * m_solver->m_referenceLength / (m_solver->m_Ma * LBCS);
71
72 m_n = Context::getSolverProperty<MFloat>("nonNewtonian_n", solverId, AT_);
73 m_a = Context::getSolverProperty<MFloat>("nonNewtonian_a", solverId, AT_);
74 m_getNuFromNonNewtonianModel = &LbSrcTerm_nonnewtonian::carreau;
75 break;
76 }
77 case POWERLAW: {
78 m_n = Context::getSolverProperty<MFloat>("nonNewtonian_n", solverId, AT_);
79
80 m_solver->m_nu = pow(m_solver->m_Ma * LBCS, F2 - m_n) / m_solver->m_Re * pow(m_solver->m_referenceLength, m_n);
81 m_nu0 = m_solver->m_nu;
82 m_getNuFromNonNewtonianModel = &LbSrcTerm_nonnewtonian::powerLaw;
83 break;
84 }
85 default: {
86 mTerm(1, AT_, "This is not an implemented model!!!");
87 }
88 }
89}
90
91template <MInt nDim, MInt nDist, class SysEqn>
93 TRACE();
94 LbSolverDxQy<nDim, nDist, SysEqn>& s = *(m_solver); // alias for readability
95
96 s.m_nu = s.m_Ma * LBCS / s.m_Re * s.m_referenceLength;
97 maia::parallelFor(0, s.m_currentMaxNoCells, [&](MInt index) {
98 const MInt pCellId = s.m_activeCellList[index];
99 const MInt lvlDiff = s.maxLevel() - s.a_level(pCellId);
100 if((globalTimeStep - 1) % IPOW2(lvlDiff) != 0) return;
101
102 constexpr MInt nDimSqr = nDim * nDim;
103 std::array<MFloat, nDimSqr> c{};
104 const MFloat rho = s.a_variable(pCellId, s.PV->RHO);
105#ifndef WAR_NVHPC_PSTL
106 const MFloat* const u = &s.a_variable(pCellId, s.PV->U);
107 const MFloat* const dist = &s.a_oldDistribution(pCellId, 0);
108 s.sysEqn().calcMomentumFlux(rho, u, dist, c.data());
109#else
110 MFloat u[nDim] = {F0};
111 MFloat dist[nDist] = {F0};
112 for(MInt d = 0; d < nDim; d++) {
113 u[d] = s.a_variable(pCellId, d);
114 }
115 for(MInt d = 0; d < nDist; d++) {
116 dist[d] = s.a_oldDistribution(pCellId, d);
117 }
118 s.sysEqn().calcMomentumFlux(rho, u, dist, c.data());
119#endif
120
121 // Compute derivative of rate-of-strain tensor
122 std::array<MFloat, nDimSqr> localS{};
123
124 MFloat nu = F0;
125 MInt noIterations = 0;
126 MBool converged = false;
127 MFloat nuOld = s.a_oldNu(pCellId);
128 const MFloat F1Brho = F1 / rho;
129 while(!converged && noIterations < 50) {
130 MFloat omega = F2 / (F6 * nuOld * FFPOW2(lvlDiff) + F1);
131 for(MInt d = 0; d < nDimSqr; d++) {
132 localS[d] = -F3B2 * omega * F1Brho * c[d];
133 }
134
135 if(nDim == 3) {
136 const MFloat volumeStrains = F1B3 * (localS[0] + localS[4] + localS[8]);
137 localS[0] -= volumeStrains;
138 localS[4] -= volumeStrains;
139 localS[8] -= volumeStrains;
140 }
141
142 // Compute second invariant of the rate-of-strain tensor
143 MFloat D = F0; // Second invariant of rate-of-strain tensor
144 for(MInt d = 0; d < nDimSqr; d++) {
145 D += localS[d] * localS[d];
146 }
147 const MFloat gamma_dot = sqrt(F2 * D);
148
149 nu = (this->*m_getNuFromNonNewtonianModel)(gamma_dot);
150
151 if(fabs(nuOld - nu) < 1e-10) converged = true;
152
153 nuOld = nu;
154 noIterations++;
155 }
156
157 s.a_nu(pCellId) = nu;
158 });
159}
160
161template <MInt nDim, MInt nDist, class SysEqn>
163 TRACE();
164
165 // Compute local viscosity
166 const MFloat exp = m_n - F1;
167 const MFloat base = gamma_dot;
168 const MFloat nu = m_nu0 * (pow(base, exp));
169
170 return nu;
171}
172
173template <MInt nDim, MInt nDist, class SysEqn>
175 TRACE();
176
177 // Compute local viscosity
178 const MFloat exp = (m_n - F1) / m_a;
179 const MFloat base = pow(m_lambda * gamma_dot, m_a) + F1;
180 const MFloat nu = m_nuInf + (m_nu0 - m_nuInf) * (pow(base, exp));
181
182 return nu;
183}
184
185//-registration for LbSrcTermFactory class
187 reg_nonNewtoniand2q9("LB_SRC_NONNEWTONIAN");
189 reg_nonNewtoniand3q19("LB_SRC_NONNEWTONIAN");
191 reg_nonNewtoniand3q27("LB_SRC_NONNEWTONIAN");
193 reg_nonNewtoniand2q9C("LB_SRC_NONNEWTONIAN");
195 reg_nonNewtoniand3q19C("LB_SRC_NONNEWTONIAN");
197 reg_nonNewtoniand3q27C("LB_SRC_NONNEWTONIAN");
198} // namespace maia::lb
This class represents all LB models.
Definition: lbsolverdxqy.h:29
constexpr SysEqn sysEqn() const
Definition: lbsolverdxqy.h:194
Class for registering a source term to the factory registry.
Class to handle non-newtonian fluids.
MFloat carreau(const MFloat gamma_dot)
LbSrcTerm_nonnewtonian(LbSolverDxQy< nDim, nDist, SysEqn > *p_solver)
MFloat(LbSrcTerm_nonnewtonian::* m_getNuFromNonNewtonianModel)(const MFloat gamma_dot)
MFloat powerLaw(const MFloat gamma_dot)
LbSolverDxQy< nDim, nDist, SysEqn > * m_solver
Abstract class for lb source terms.
Definition: lbsrcterm.h:22
MInt string2enum(MString theString)
This global function translates strings in their corresponding enum values (integer values)....
Definition: enums.cpp:20
@ POWERLAW
Definition: enums.h:263
@ CARREAU
Definition: enums.h:263
void mTerm(const MInt errorCode, const MString &location, const MString &message)
Definition: functions.cpp:29
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
void parallelFor(MInt begin, MInt end, UnaryFunction &&f)
Wrapper function for parallel for loop.
Definition: parallelfor.h:147
MFloat dist(const Point< DIM > &p, const Point< DIM > &q)
Definition: pointbox.h:54