https://mooseframework.inl.gov
Loading...
Searching...
No Matches
INSFEMaterial.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "INSFEMaterial.h"
11#include "MooseMesh.h"
12#include "Steady.h"
13#include "libmesh/quadrature.h"
14
16registerMooseObjectRenamed("NavierStokesApp", MDFluidMaterial, "02/01/2024 00:00", INSFEMaterial);
17
20{
22
23 params.addClassDescription("Computes generic material properties related to simulation of fluid "
24 "flow");
25 params.addRequiredCoupledVar("u", "velocity in x-direction");
26 params.addCoupledVar("v", "velocity in y-direction"); // required in 2D/3D
27 params.addCoupledVar("w", "velocity in z-direction"); // required in 3D
28
29 params.addRequiredCoupledVar("temperature", "temperature");
30 params.addRequiredCoupledVar("pressure", "pressure");
31 params.addRequiredParam<UserObjectName>("eos", "The name of equation of state object to use.");
32 params.addParam<Real>("scaling_velocity", "Global scaling velocity");
33
34 params.addParam<bool>(
35 "compute_turbulence_viscosity", false, "If turbulent viscosity will be computed.");
36 params.addParam<FunctionName>("mixing_length",
37 "Prandtl mixing length to compute turbulent viscosity.");
38 params.addCoupledVar("turbulence_viscosity_var",
39 "An aux variable turbulence_viscosity will be computed from.");
40 return params;
41}
42
44 : Material(parameters),
45 _mesh_dimension(_mesh.dimension()),
46 _u_vel(coupledValue("u")),
47 _v_vel(_mesh_dimension >= 2 ? coupledValue("v") : _zero),
48 _w_vel(_mesh_dimension == 3 ? coupledValue("w") : _zero),
49 _temperature(coupledValue("temperature")),
50 _pressure(coupledValue("pressure")),
51
52 _grad_u(coupledGradient("u")),
53 _grad_v(_mesh_dimension >= 2 ? coupledGradient("v") : _grad_zero),
54 _grad_w(_mesh_dimension == 3 ? coupledGradient("w") : _grad_zero),
55
56 _viscous_stress_tensor(declareProperty<RealTensorValue>("viscous_stress_tensor")),
57 _dynamic_viscosity(declareProperty<Real>("dynamic_viscosity")),
58 _turbulence_viscosity(declareProperty<Real>("turbulence_viscosity")),
59 _inertia_resistance_coeff(declareProperty<RealTensorValue>("inertia_resistance_coeff")),
60 _viscous_resistance_coeff(declareProperty<RealTensorValue>("viscous_resistance_coeff")),
61 _k(declareProperty<Real>("k_fluid")),
62 _k_turbulence(declareProperty<Real>("k_turbulence")),
63 _k_elem(declareProperty<Real>("k_fluid_elem")),
64 _cp(declareProperty<Real>("cp_fluid")),
65 _rho(declareProperty<Real>("rho_fluid")),
66 _hsupg(declareProperty<Real>("hsupg")),
67 _tauc(declareProperty<Real>("tauc")),
68 _taum(declareProperty<Real>("taum")),
69 _taue(declareProperty<Real>("taue")),
70 _compute_visc_turbulenc(getParam<bool>("compute_turbulence_viscosity")),
71 _has_turb_visc_auxvar(isParamValid("turbulence_viscosity_var")),
72 _mixing_length(NULL),
73 _turb_visc_auxvar(_has_turb_visc_auxvar ? coupledValue("turbulence_viscosity_var") : _zero),
74 _has_scale_vel(isParamValid("scaling_velocity")),
75 _scaling_velocity(_has_scale_vel ? getParam<Real>("scaling_velocity") : 1.),
76 _eos(getUserObject<SinglePhaseFluidProperties>("eos"))
77{
79 Steady * ss = dynamic_cast<Steady *>(myExe);
80 _bSteady = (ss != NULL);
81
83 {
84 // If visc_turbulence is needed, either 'mixing_length' or 'turbulence_viscosity_var' is needed,
85 // but 'mixing_length' and 'turbulence_viscosity_var' cannot be both specified
86 if (isParamValid("mixing_length") == isParamValid("turbulence_viscosity_var"))
87 mooseError("To compute turbulence viscosity, "
88 "please provide either 'mixing_length' or 'turbulence_viscosity_var'");
89
90 // If 'turbulence_viscosity_var' is not given, 'mixing_length' is used
92 _mixing_length = &getFunction("mixing_length");
93 }
94}
95
96void
98{
99 // calculating element average velocity
100 _u_elem = 0;
101 _v_elem = 0;
102 _w_elem = 0;
103 // if(_qrule->n_points()<4) return; // only calculated element-based material properties
104 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
105 {
106 _u_elem += _u_vel[_qp] / _qrule->n_points();
107 _v_elem += _v_vel[_qp] / _qrule->n_points();
108 _w_elem += _w_vel[_qp] / _qrule->n_points();
109 }
110 _vel_mag = std::sqrt(_u_elem * _u_elem + _v_elem * _v_elem + _w_elem * _w_elem);
111
112 _k_elem_val = 0.0;
113
114 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
116
117 for (_qp = 0; _qp < _qrule->n_points(); _qp++)
119}
120
121void
123{
125
126 // Viscous Stress Tensor
127 RealTensorValue grad_vel(_grad_u[_qp], _grad_v[_qp], _grad_w[_qp]);
128
129 grad_vel += grad_vel.transpose();
130
131 // Turbulent viscosity
133 _k_turbulence[_qp] = 0.0;
135 {
138 else
139 {
140 Real strain_rate_mag = 0.0;
141 for (unsigned int i = 0; i < 3; i++)
142 for (unsigned int j = 0; j < 3; j++)
143 strain_rate_mag += 0.5 * grad_vel(i, j) * grad_vel(i, j);
144
145 Real L_mix = _mixing_length->value(_t, _q_point[_qp]);
146
147 _turbulence_viscosity[_qp] = _rho[_qp] * L_mix * L_mix * std::sqrt(strain_rate_mag);
148 }
150 }
151
152 _k_elem_val += (_k[_qp] + _k_turbulence[_qp]) / _qrule->n_points();
153
154 Real div_vel = _grad_u[_qp](0) + _grad_v[_qp](1) + _grad_w[_qp](2);
155
156 // Add diagonal terms
157 for (unsigned int i = 0; i < 3; i++)
158 grad_vel(i, i) -= 2.0 / 3.0 * div_vel;
159
161
162 // place holder which will be handled by specific closure correlations
163 _inertia_resistance_coeff[_qp] = RealTensorValue(0, 0, 0, 0, 0, 0, 0, 0, 0);
164 _viscous_resistance_coeff[_qp] = RealTensorValue(0, 0, 0, 0, 0, 0, 0, 0, 0);
165
166 // Compute stabilization parameters:
167 computeHSUPG();
168 computeTau();
169}
170
171void
173{
175 _k[_qp] = _eos.k_from_p_T(_pressure[_qp], _temperature[_qp]);
176 _cp[_qp] = _eos.cp_from_p_T(_pressure[_qp], _temperature[_qp]);
177 _rho[_qp] = _eos.rho_from_p_T(_pressure[_qp], _temperature[_qp]);
178}
179
180void
182{
183 // Just use hmin for the element!
184 _hsupg[_qp] = _current_elem->hmin();
185}
186
187void
189{
190 // element-based stabilization parameters
191 Real h2 = _hsupg[_qp] * _hsupg[_qp];
192 Real sqrt_term_supg = 4 * _vel_mag * _vel_mag / h2;
193
194 Real sqrt_term_pspg = 0.;
195 if (_has_scale_vel)
196 sqrt_term_pspg = 4 * _scaling_velocity * _scaling_velocity / h2;
197 else
198 sqrt_term_pspg = sqrt_term_supg;
199
200 if (!_bSteady)
201 {
202 sqrt_term_supg += 4. / _dt / _dt;
203 sqrt_term_pspg += 4. / _dt / _dt;
204 }
205
207 Real visc_term = 4 * vu / h2;
208
209 Real diffusivity = _k[_qp] / _rho[_qp] / _cp[_qp];
210 Real diff_term = 4 * diffusivity / h2;
211
212 _tauc[_qp] = 1. / std::sqrt(sqrt_term_pspg);
213 _taum[_qp] = 1. / std::sqrt(sqrt_term_supg + visc_term * visc_term);
214 _taue[_qp] = 1. / std::sqrt(sqrt_term_supg + diff_term * diff_term);
215}
registerMooseObject("NavierStokesApp", INSFEMaterial)
registerMooseObjectRenamed("NavierStokesApp", MDFluidMaterial, "02/01/2024 00:00", INSFEMaterial)
const Function & getFunction(const std::string &name) const
virtual Real value(Real t, const Point &p) const
Fluid materials for 3D fluid model.
bool _compute_visc_turbulenc
const Function * _mixing_length
const VariableGradient & _grad_v
MaterialProperty< Real > & _hsupg
static InputParameters validParams()
INSFEMaterial(const InputParameters &parameters)
MaterialProperty< RealTensorValue > & _viscous_resistance_coeff
const VariableGradient & _grad_w
MaterialProperty< Real > & _k
void computeFluidProperties()
MaterialProperty< RealTensorValue > & _inertia_resistance_coeff
const VariableValue & _w_vel
MaterialProperty< Real > & _cp
MaterialProperty< Real > & _tauc
MaterialProperty< Real > & _taum
bool _has_turb_visc_auxvar
virtual void computeProperties() override
MaterialProperty< Real > & _rho
MaterialProperty< Real > & _taue
virtual void computeQpProperties() override
const VariableValue & _temperature
const VariableGradient & _grad_u
const SinglePhaseFluidProperties & _eos
scaling velocity
MaterialProperty< Real > & _k_turbulence
const VariableValue & _pressure
const VariableValue & _u_vel
const VariableValue & _v_vel
MaterialProperty< Real > & _dynamic_viscosity
const VariableValue & _turb_visc_auxvar
MaterialProperty< Real > & _k_elem
MaterialProperty< Real > & _turbulence_viscosity
MaterialProperty< RealTensorValue > & _viscous_stress_tensor
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
unsigned int _qp
static InputParameters validParams()
const Elem *const & _current_elem
const QBase *const & _qrule
const MooseArray< Point > & _q_point
Executioner * getExecutioner() const
void mooseError(Args &&... args) const
bool isParamValid(const std::string &name) const
MooseApp & _app
Common class for single phase fluid properties.
Real & _dt
Real & _t