https://mooseframework.inl.gov
Loading...
Searching...
No Matches
INSFEFluidEnergyKernel.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
11
14 MDFluidEnergyKernel,
15 "02/01/2024 00:00",
17
20{
22 params.addClassDescription("Adds advection, diffusion, and heat source terms to energy equation, "
23 "potentially with stabilization");
24 params.addParam<bool>("conservative_form", false, "if conservative form is used");
25 params.addCoupledVar("porosity_elem", "Element averaged porosity");
26 params.addCoupledVar("power_density", "volumetric heat source");
27 params.addCoupledVar("pke_power_var", "Normalized power from PKE");
28 params.addParam<FunctionName>("power_shape_function", "Function that defines power profile");
29
30 return params;
31}
32
35 _conservative_form(getParam<bool>("conservative_form")),
36 _k_elem(getMaterialProperty<Real>("k_fluid_elem")),
37 _cp(getMaterialProperty<Real>("cp_fluid")),
38 _has_porosity_elem(isParamValid("porosity_elem")),
39 _porosity_elem(_has_porosity_elem ? coupledValue("porosity_elem")
40 : (_has_porosity ? coupledValue("porosity") : _zero)),
41 _has_qv(isParamValid("power_density")),
42 _qv(_has_qv ? coupledValue("power_density") : _zero),
43 _has_pke(isParamValid("pke_power_var")),
44 _pke_qv(_has_pke ? coupledScalarValue("pke_power_var") : _zero),
45 _power_shape_function(
46 isParamValid("power_shape_function") ? &getFunction("power_shape_function") : NULL)
47{
48 // Input sanity check: cannot have both 'power_density' and 'pke_power_var'
49 if (_has_qv && _has_pke)
51 "'power_density' and 'pke_power_var' cannot be both provided in 'INSFEFluidEnergyKernel'.");
52
53 if (_has_pke && (_power_shape_function == NULL))
54 mooseError("'power_shape_function' is required if 'pke_power_var' is provided in "
55 "'INSFEFluidEnergyKernel'.");
56}
57
58Real
60{
61 Real porosity = _has_porosity ? _porosity[_qp] : 1.0;
62 Real porosity_elem = (_has_porosity_elem || _has_porosity) ? _porosity_elem[_qp] : 1.0;
63 RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
64 Real enthalpy = _eos.h_from_p_T(_pressure[_qp], _u[_qp]);
65
66 // Residual weak form terms: convection + diffusion + volumetric heat
67 Real convective_part = _conservative_form
68 ? -_rho[_qp] * enthalpy * vec_vel * _grad_test[_i][_qp]
69 : _rho[_qp] * _cp[_qp] * vec_vel * _grad_u[_qp] * _test[_i][_qp];
70
71 // heat source, one of the two terms, or both two terms will be zero
72 Real heat_source_part = -_qv[_qp] * _test[_i][_qp];
73 if (_has_pke)
74 heat_source_part +=
76
77 Real diffusion_part = porosity_elem * _k_elem[_qp] * _grad_u[_qp] * _grad_test[_i][_qp];
78
79 // Residual strong form terms for SUPG contributions
80 Real transient_supg = _bTransient ? porosity * _rho[_qp] * _cp[_qp] * _u_dot[_qp] : 0;
81 Real convection_supg = _rho[_qp] * _cp[_qp] * vec_vel * _grad_u[_qp];
82 Real heat_source_supg = -_qv[_qp];
83 if (_has_pke)
84 heat_source_supg += -_pke_qv[0] * _power_shape_function->value(_t, _q_point[_qp]);
85
86 Real diffusion_supg = -porosity_elem * _k_elem[_qp] * _second_u[_qp].tr();
87
88 // assemble residuals
89 Real normal_part = convective_part + heat_source_part + diffusion_part;
90 Real supg_part = (transient_supg + convection_supg + heat_source_supg + diffusion_supg) *
92
93 return normal_part + supg_part;
94}
95
96Real
98{
99 Real porosity = _has_porosity ? _porosity[_qp] : 1.0;
100 Real porosity_elem = (_has_porosity_elem || _has_porosity) ? _porosity_elem[_qp] : 1.0;
101 Real rho, drho_dp, drho_dT;
102 _eos.rho_from_p_T(_pressure[_qp], _u[_qp], rho, drho_dp, drho_dT);
103 Real enthalpy = _eos.h_from_p_T(_pressure[_qp], _u[_qp]);
104 RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
105
106 // convection part
107 Real convection_part = _conservative_form
108 ? -(_rho[_qp] * _cp[_qp] + enthalpy * drho_dT) * vec_vel *
109 _phi[_j][_qp] * _grad_test[_i][_qp]
110 : _cp[_qp] * vec_vel *
111 (drho_dT * _grad_u[_qp] + _rho[_qp] * _grad_phi[_j][_qp]) *
112 _test[_i][_qp];
113
114 // diffusion part
115 Real diffusion_part = porosity_elem * _k_elem[_qp] * _grad_phi[_j][_qp] * _grad_test[_i][_qp];
116
117 Real normal_part = convection_part + diffusion_part;
118
119 // SUPG contributions (only transient and convection part, ignore diffusion part)
120 Real transient_supg =
121 _bTransient ? porosity * _rho[_qp] * _cp[_qp] * _du_dot_du[_qp] * _phi[_j][_qp] : 0;
122 Real convection_supg = _rho[_qp] * _cp[_qp] * vec_vel * _grad_phi[_j][_qp];
123 Real supg_part =
124 _taue[_qp] * _vel_elem * _grad_test[_i][_qp] * (transient_supg + convection_supg);
125
126 // Assembly total residuals
127 return normal_part + supg_part;
128}
129
130Real
132{
133 unsigned m = this->mapVarNumber(jvar);
134
135 RealVectorValue vec_vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
136 Real enthalpy = _eos.h_from_p_T(_pressure[_qp], _u[_qp]);
137
138 Real jac = 0.;
139 switch (m)
140 {
141 case 1:
142 case 2:
143 case 3:
144 // convection weak form part
146 jac -= _rho[_qp] * _phi[_j][_qp] * enthalpy * _grad_test[_i][_qp](m - 1);
147 else
148 jac += _rho[_qp] * _cp[_qp] * _phi[_j][_qp] * _grad_u[_qp](m - 1) * _test[_i][_qp];
149 // convection supg part
150 jac += _rho[_qp] * _cp[_qp] * _phi[_j][_qp] * _grad_u[_qp](m - 1) * _taue[_qp] * _vel_elem *
151 _grad_test[_i][_qp];
152 break;
153
154 default:
155 jac = 0.0;
156 }
157
158 return jac;
159}
const double rho
registerMooseObjectRenamed("NavierStokesApp", MDFluidEnergyKernel, "02/01/2024 00:00", INSFEFluidEnergyKernel)
registerMooseObject("NavierStokesApp", INSFEFluidEnergyKernel)
virtual Real value(Real t, const Point &p) const
The spatial part of the 3D energy conservation for fluid flow.
static InputParameters validParams()
const VariableValue & _qv
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
const VariableValue & _porosity_elem
virtual Real computeQpJacobian() override
virtual Real computeQpResidual() override
const Function * _power_shape_function
const MaterialProperty< Real > & _k_elem
bool _has_pke
volumetric heat source
const MaterialProperty< Real > & _cp
INSFEFluidEnergyKernel(const InputParameters &parameters)
const VariableValue & _pke_qv
const VariableValue & _w_vel
const VariableValue & _u_vel
const VariableValue & _v_vel
const SinglePhaseFluidProperties & _eos
const VariableValue & _porosity
const MaterialProperty< Real > & _rho
const VariableSecond & _second_u
unsigned int mapVarNumber(unsigned int var) const
Helper function for mapping Moose variable numberings into the "canonical" numbering for the porous m...
const VariableValue & _pressure
Base class for stabilization kernels.
const MaterialProperty< Real > & _taue
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
const MooseArray< Point > & _q_point
unsigned int _j
unsigned int _i
const VariableGradient & _grad_u
const VariablePhiValue & _phi
const VariableTestValue & _test
const VariablePhiGradient & _grad_phi
const VariableTestGradient & _grad_test
const VariableValue & _u
void mooseError(Args &&... args) const
Real & _t