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 T::_alpha;
48 using T::_dt;
49 using T::_has_transient;
50 using T::_hmax;
51 using T::_mu;
52 using T::_qp;
53 using T::_rho;
54 using T::_velocity;
55 using T::_grad_velocity;
56 using T::_tau;
57 using Coupleable::adCoupledValue;
58 using Coupleable::adCoupledGradient;
59 using Coupleable::coupledValue;
60 using Coupleable::adCoupledDot;
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(this->template
101 declareADProperty<Real>("convection_strong_residual")),
102 _destruction_strong_residual(this->template
103 declareADProperty<Real>("destruction_strong_residual")),
104 _diffusion_strong_residual(this->template
105 declareADProperty<Real>("diffusion_strong_residual")),
106 _source_strong_residual(this->template
107 declareADProperty<Real>("source_strong_residual")),
108 _time_strong_residual(this->template
109 declareADProperty<Real>("time_strong_residual")),
110 _visc_strong_residual(this->template
111 declareADProperty<Real>("visc_strong_residual"))
112{
113}
114
115template <typename T>
116void
118{
119 T::subdomainSetup();
120
121 if (_has_transient)
122 _visc_dot = & adCoupledDot("mu_tilde");
123 else
124 _visc_dot = nullptr;
125}
126
127template <typename T>
128void
130{
131 T::computeQpProperties();
132
133 // Compute strain rate and vorticity magnitudes
134 _strain_mag[_qp] = 2.0 * Utility::pow<2>(_grad_velocity[_qp](0, 0)) +
135 2.0 * Utility::pow<2>(_grad_velocity[_qp](1, 1)) +
136 2.0 * Utility::pow<2>(_grad_velocity[_qp](2, 2)) +
137 Utility::pow<2>(_grad_velocity[_qp](0, 2) + _grad_velocity[_qp](2, 0)) +
138 Utility::pow<2>(_grad_velocity[_qp](0, 1) + _grad_velocity[_qp](1, 0)) +
139 Utility::pow<2>(_grad_velocity[_qp](1, 2) + _grad_velocity[_qp](2, 1));
140 _strain_mag[_qp] = std::sqrt(_strain_mag[_qp] + 1e-16);
141 ADReal vorticity_mag =
142 Utility::pow<2>(_grad_velocity[_qp](0, 2) - _grad_velocity[_qp](2, 0)) +
143 Utility::pow<2>(_grad_velocity[_qp](0, 1) - _grad_velocity[_qp](1, 0)) +
144 Utility::pow<2>(_grad_velocity[_qp](1, 2) - _grad_velocity[_qp](2, 1));
145 vorticity_mag = std::sqrt(vorticity_mag + 1e-16);
146
147 // Compute relevant parameters for the SA equation
148 const Real d = std::max(_wall_dist[_qp], 1e-16); // Avoid potential division by zero
149 const ADReal chi = _mu_tilde[_qp] / _mu[_qp];
150 const ADReal fv1 = Utility::pow<3>(chi) / (Utility::pow<3>(chi) + Utility::pow<3>(_cv1));
151 const ADReal fv2 = 1.0 - chi / (1. + chi * fv1);
152 const ADReal S_tilde =
153 vorticity_mag + _mu_tilde[_qp] * fv2 / (_kappa * _kappa * d * d * _rho[_qp]);
154 const ADReal S = S_tilde + 2 * std::min(0.0, _strain_mag[_qp] - vorticity_mag);
155 ADReal r;
156 if (S_tilde <= 0.0) // Avoid potential division by zero
157 r = 10.;
158 else
159 r = std::min(_mu_tilde[_qp] / (S_tilde * _kappa * _kappa * d * d * _rho[_qp]), 10.0);
160 const ADReal g = r + _cw2 * (Utility::pow<6>(r) - r);
161 const ADReal fw = g * std::pow((1. + Utility::pow<6>(_cw3)) /
162 (Utility::pow<6>(g) + Utility::pow<6>(_cw3)),
163 1.0 / 6.0);
164
165 // Compute strong forms of the SA equation
166 if (_use_ft2_term) // Whether to apply the f_t2 term in the SA equation
167 {
168 const ADReal ft2 = _ct3 * std::exp(-_ct4 * chi * chi);
169 _destruction_strong_residual[_qp] =
170 (_cw1 * fw - _cb1 * ft2 / _kappa / _kappa) * Utility::pow<2>(_mu_tilde[_qp] / d);
171 _source_strong_residual[_qp] = -(1 - ft2) * _rho[_qp] * _cb1 * S * _mu_tilde[_qp];
172 }
173 else
174 {
175 _destruction_strong_residual[_qp] = _cw1 * fw * Utility::pow<2>(_mu_tilde[_qp] / d);
176 _source_strong_residual[_qp] = -_rho[_qp] * _cb1 * S * _mu_tilde[_qp];
177 }
178 _convection_strong_residual[_qp] = _rho[_qp] * _velocity[_qp] * _grad_mu[_qp];
179 _diffusion_strong_residual[_qp] = -1.0 / _sigma * _cb2 * (_grad_mu[_qp] * _grad_mu[_qp]);
180 if (_has_transient)
181 _time_strong_residual[_qp] = (*_visc_dot)[_qp] * _rho[_qp];
182 _visc_strong_residual[_qp] = _has_transient ? _time_strong_residual[_qp] : 0.0;
183 _visc_strong_residual[_qp] += (_convection_strong_residual[_qp] +
184 _destruction_strong_residual[_qp] +
185 _diffusion_strong_residual[_qp] +
186 _source_strong_residual[_qp]);
187
188 // Compute the tau stabilization parameter for mu_tilde SUPG stabilization
189 const auto nu_visc = (_mu[_qp] + _mu_tilde[_qp]) / _rho[_qp] / _sigma;
190 const auto transient_part = _has_transient ? 4.0 / (_dt * _dt) : 0.0;
191 const auto speed = NS::computeSpeed(_velocity[_qp]);
192 _tau_visc[_qp] = _alpha / std::sqrt(transient_part +
193 (2.0 * speed / _hmax) * (2.0 * speed / _hmax) +
194 9.0 * (4.0 * nu_visc / (_hmax * _hmax)) *
195 4.0 * (nu_visc / (_hmax * _hmax)));
196
197 // Replace the nu value in the tau stabilization parameter for INS SUPG stabilization
198 const auto nu = (_mu[_qp] + _mu_tilde[_qp] * fv1) / _rho[_qp];
199 _tau[_qp] = _alpha / std::sqrt(transient_part +
200 (2.0 * speed / _hmax) * (2.0 * speed / _hmax) +
201 9.0 * (4.0 * nu / (_hmax * _hmax)) *
202 4.0 * (nu / (_hmax * _hmax)));
203}
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:117
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:129
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