moltres
Loading...
Searching...
No Matches
SATauMaterial.h
Go to the documentation of this file.
1#pragma once
2
3#include "INSADTauMaterial.h"
4
5using MetaPhysicL::raw_value;
6
7template <typename T>
8class SATauMaterialTempl : public T
9{
10public:
11 static InputParameters validParams();
12
13 SATauMaterialTempl(const InputParameters & parameters);
14
15 void subdomainSetup() override;
16
17protected:
18 virtual void computeQpProperties() override;
19
20 const Real _sigma;
21 const Real _cb1;
22 const Real _cb2;
23 const Real _kappa;
24 const Real _cw1;
25 const Real _cw2;
26 const Real _cw3;
27 const Real _cv1;
28 const Real _ct1;
29 const Real _ct2;
30 const Real _ct3;
31 const Real _ct4;
32 const ADVariableValue & _mu_tilde;
33 const ADVariableGradient & _grad_mu;
34 const ADVariableValue * _visc_dot;
35 ADMaterialProperty<Real> & _tau_visc;
36 const VariableValue & _wall_dist;
37 const bool _use_ft2_term;
38
39 ADMaterialProperty<Real> & _strain_mag;
40 ADMaterialProperty<Real> & _convection_strong_residual;
41 ADMaterialProperty<Real> & _destruction_strong_residual;
42 ADMaterialProperty<Real> & _diffusion_strong_residual;
43 ADMaterialProperty<Real> & _source_strong_residual;
44 ADMaterialProperty<Real> & _time_strong_residual;
45 ADMaterialProperty<Real> & _visc_strong_residual;
46
47 using Coupleable::adCoupledDot;
48 using Coupleable::adCoupledGradient;
49 using Coupleable::adCoupledValue;
50 using Coupleable::coupledValue;
51 using T::_alpha;
52 using T::_dt;
53 using T::_grad_velocity;
54 using T::_has_transient;
55 using T::_hmax;
56 using T::_mu;
57 using T::_qp;
58 using T::_rho;
59 using T::_tau;
60 using T::_velocity;
61};
62
64
65template <typename T>
66InputParameters
68{
69 InputParameters params = T::validParams();
70 params.addClassDescription(
71 "This is the material class used to compute the stabilization parameter tau_viscosity "
72 "for the Spalart-Allmaras turbulent viscosity equation.");
73 params.addRequiredCoupledVar("mu_tilde", "Spalart-Allmaras turbulence viscosity variable");
74 params.addRequiredCoupledVar("wall_distance_var", "Wall distance aux variable name");
75 params.addParam<bool>("use_ft2_term", false, "Whether to apply the f_t2 term in the equation");
76 return params;
77}
78
79template <typename T>
80SATauMaterialTempl<T>::SATauMaterialTempl(const InputParameters & parameters)
81 : T(parameters),
82 _sigma(2.0 / 3.0),
83 _cb1(0.1355),
84 _cb2(0.622),
85 _kappa(0.41),
86 _cw1(_cb1 / _kappa / _kappa + (1 + _cb2) / _sigma),
87 _cw2(0.3),
88 _cw3(2.0),
89 _cv1(7.1),
90 _ct1(1.0),
91 _ct2(2.0),
92 _ct3(1.2),
93 _ct4(0.5),
94 _mu_tilde(adCoupledValue("mu_tilde")),
95 _grad_mu(adCoupledGradient("mu_tilde")),
96 _tau_visc(this->template declareADProperty<Real>("tau_viscosity")),
97 _wall_dist(coupledValue("wall_distance_var")),
98 _use_ft2_term(this->template getParam<bool>("use_ft2_term")),
99 _strain_mag(this->template declareADProperty<Real>("strain_mag")),
100 _convection_strong_residual(
101 this->template declareADProperty<Real>("convection_strong_residual")),
102 _destruction_strong_residual(
103 this->template declareADProperty<Real>("destruction_strong_residual")),
104 _diffusion_strong_residual(this->template declareADProperty<Real>("diffusion_strong_residual")),
105 _source_strong_residual(this->template declareADProperty<Real>("source_strong_residual")),
106 _time_strong_residual(this->template declareADProperty<Real>("time_strong_residual")),
107 _visc_strong_residual(this->template declareADProperty<Real>("visc_strong_residual"))
108{
109}
110
111template <typename T>
112void
114{
115 T::subdomainSetup();
116
117 if (_has_transient)
118 _visc_dot = &adCoupledDot("mu_tilde");
119 else
120 _visc_dot = nullptr;
121}
122
123template <typename T>
124void
126{
127 using std::sqrt, std::max, std::min, std::pow, std::exp;
128
129 T::computeQpProperties();
130
131 // Compute strain rate and vorticity magnitudes
132 _strain_mag[_qp] = 2.0 * Utility::pow<2>(_grad_velocity[_qp](0, 0)) +
133 2.0 * Utility::pow<2>(_grad_velocity[_qp](1, 1)) +
134 2.0 * Utility::pow<2>(_grad_velocity[_qp](2, 2)) +
135 Utility::pow<2>(_grad_velocity[_qp](0, 2) + _grad_velocity[_qp](2, 0)) +
136 Utility::pow<2>(_grad_velocity[_qp](0, 1) + _grad_velocity[_qp](1, 0)) +
137 Utility::pow<2>(_grad_velocity[_qp](1, 2) + _grad_velocity[_qp](2, 1));
138 _strain_mag[_qp] = sqrt(_strain_mag[_qp] + 1e-16);
139 ADReal vorticity_mag = Utility::pow<2>(_grad_velocity[_qp](0, 2) - _grad_velocity[_qp](2, 0)) +
140 Utility::pow<2>(_grad_velocity[_qp](0, 1) - _grad_velocity[_qp](1, 0)) +
141 Utility::pow<2>(_grad_velocity[_qp](1, 2) - _grad_velocity[_qp](2, 1));
142 vorticity_mag = sqrt(vorticity_mag + 1e-16);
143
144 // Compute relevant parameters for the SA equation
145 const Real d = max(_wall_dist[_qp], 1e-16); // Avoid potential division by zero
146 const ADReal chi = _mu_tilde[_qp] / _mu[_qp];
147 const ADReal fv1 = Utility::pow<3>(chi) / (Utility::pow<3>(chi) + Utility::pow<3>(_cv1));
148 const ADReal fv2 = 1.0 - chi / (1. + chi * fv1);
149 const ADReal S_tilde =
150 vorticity_mag + _mu_tilde[_qp] * fv2 / (_kappa * _kappa * d * d * _rho[_qp]);
151 const ADReal S = S_tilde + 2 * min(0.0, _strain_mag[_qp] - vorticity_mag);
152 ADReal r;
153 if (S_tilde <= 0.0) // Avoid potential division by zero
154 r = 10.;
155 else
156 r = min(_mu_tilde[_qp] / (S_tilde * _kappa * _kappa * d * d * _rho[_qp]), 10.0);
157 const ADReal g = r + _cw2 * (Utility::pow<6>(r) - r);
158 const ADReal fw =
159 g *
160 pow((1. + Utility::pow<6>(_cw3)) / (Utility::pow<6>(g) + Utility::pow<6>(_cw3)), 1.0 / 6.0);
161
162 // Compute strong forms of the SA equation
163 if (_use_ft2_term) // Whether to apply the f_t2 term in the SA equation
164 {
165 const ADReal ft2 = _ct3 * exp(-_ct4 * chi * chi);
166 _destruction_strong_residual[_qp] =
167 (_cw1 * fw - _cb1 * ft2 / _kappa / _kappa) * Utility::pow<2>(_mu_tilde[_qp] / d);
168 _source_strong_residual[_qp] = -(1 - ft2) * _rho[_qp] * _cb1 * S * _mu_tilde[_qp];
169 }
170 else
171 {
172 _destruction_strong_residual[_qp] = _cw1 * fw * Utility::pow<2>(_mu_tilde[_qp] / d);
173 _source_strong_residual[_qp] = -_rho[_qp] * _cb1 * S * _mu_tilde[_qp];
174 }
175 _convection_strong_residual[_qp] = _rho[_qp] * _velocity[_qp] * _grad_mu[_qp];
176 _diffusion_strong_residual[_qp] = -1.0 / _sigma * _cb2 * (_grad_mu[_qp] * _grad_mu[_qp]);
177 if (_has_transient)
178 _time_strong_residual[_qp] = (*_visc_dot)[_qp] * _rho[_qp];
179 _visc_strong_residual[_qp] = _has_transient ? _time_strong_residual[_qp] : 0.0;
180 _visc_strong_residual[_qp] +=
181 (_convection_strong_residual[_qp] + _destruction_strong_residual[_qp] +
182 _diffusion_strong_residual[_qp] + _source_strong_residual[_qp]);
183
184 // Compute the tau stabilization parameter for mu_tilde SUPG stabilization
185 const auto nu_visc = (_mu[_qp] + _mu_tilde[_qp]) / _rho[_qp] / _sigma;
186 const auto transient_part = _has_transient ? 4.0 / (_dt * _dt) : 0.0;
187 const auto speed = NS::computeSpeed(_velocity[_qp]);
188 _tau_visc[_qp] =
189 _alpha / sqrt(transient_part + (2.0 * speed / _hmax) * (2.0 * speed / _hmax) +
190 9.0 * (4.0 * nu_visc / (_hmax * _hmax)) * 4.0 * (nu_visc / (_hmax * _hmax)));
191
192 // Replace the nu value in the tau stabilization parameter for INS SUPG stabilization
193 const auto nu = (_mu[_qp] + _mu_tilde[_qp] * fv1) / _rho[_qp];
194 _tau[_qp] = _alpha / sqrt(transient_part + (2.0 * speed / _hmax) * (2.0 * speed / _hmax) +
195 9.0 * (4.0 * nu / (_hmax * _hmax)) * 4.0 * (nu / (_hmax * _hmax)));
196}
SATauMaterialTempl< INSADTauMaterial > SATauMaterial
Definition SATauMaterial.h:63
Definition SATauMaterial.h:9
const Real _ct4
Definition SATauMaterial.h:31
ADMaterialProperty< Real > & _convection_strong_residual
Definition SATauMaterial.h:40
ADMaterialProperty< Real > & _visc_strong_residual
Definition SATauMaterial.h:45
const Real _ct3
Definition SATauMaterial.h:30
SATauMaterialTempl(const InputParameters &parameters)
Definition SATauMaterial.h:80
const ADVariableValue * _visc_dot
Definition SATauMaterial.h:34
void subdomainSetup() override
Definition SATauMaterial.h:113
const Real _kappa
Definition SATauMaterial.h:23
static InputParameters validParams()
Definition SATauMaterial.h:67
const Real _cb2
Definition SATauMaterial.h:22
const Real _ct1
Definition SATauMaterial.h:28
const Real _cw3
Definition SATauMaterial.h:26
virtual void computeQpProperties() override
Definition SATauMaterial.h:125
const Real _cw2
Definition SATauMaterial.h:25
const VariableValue & _wall_dist
Definition SATauMaterial.h:36
ADMaterialProperty< Real > & _strain_mag
Definition SATauMaterial.h:39
ADMaterialProperty< Real > & _diffusion_strong_residual
Definition SATauMaterial.h:42
const ADVariableGradient & _grad_mu
Definition SATauMaterial.h:33
const Real _cv1
Definition SATauMaterial.h:27
const Real _cb1
Definition SATauMaterial.h:21
ADMaterialProperty< Real > & _destruction_strong_residual
Definition SATauMaterial.h:41
ADMaterialProperty< Real > & _time_strong_residual
Definition SATauMaterial.h:44
const bool _use_ft2_term
Definition SATauMaterial.h:37
const ADVariableValue & _mu_tilde
Definition SATauMaterial.h:32
const Real _sigma
Definition SATauMaterial.h:20
ADMaterialProperty< Real > & _tau_visc
Definition SATauMaterial.h:35
const Real _cw1
Definition SATauMaterial.h:24
ADMaterialProperty< Real > & _source_strong_residual
Definition SATauMaterial.h:43
const Real _ct2
Definition SATauMaterial.h:29