https://mooseframework.inl.gov
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 
10 #include "INSFEFluidEnergyKernel.h"
11 
13 registerMooseObjectRenamed("NavierStokesApp",
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 
34  : INSFEFluidKernelStabilization(parameters),
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)
50  mooseError(
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 
58 Real
60 {
62  Real porosity_elem = (_has_porosity_elem || _has_porosity) ? _porosity_elem[_qp] : 1.0;
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 
96 Real
98 {
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 
130 Real
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
145  if (_conservative_form)
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 SinglePhaseFluidProperties & _eos
const VariableValue & _pke_qv
const VariableSecond & _second_u
const VariableGradient & _grad_u
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const VariableValue & _w_vel
const VariablePhiGradient & _grad_phi
const MaterialProperty< Real > & _k_elem
static InputParameters validParams()
const VariableValue & _qv
const MaterialProperty< Real > & _taue
registerMooseObject("NavierStokesApp", INSFEFluidEnergyKernel)
virtual Real computeQpResidual() override
static const std::string porosity
Definition: NS.h:104
const VariableTestValue & _test
const VariableValue & _pressure
Real & _t
registerMooseObjectRenamed("NavierStokesApp", MDFluidEnergyKernel, "02/01/2024 00:00", INSFEFluidEnergyKernel)
const MaterialProperty< Real > & _cp
unsigned int _i
const VariableValue & _porosity
const Function * _power_shape_function
Base class for stabilization kernels.
void addCoupledVar(const std::string &name, const std::string &doc_string)
const VariableValue & _u_vel
The spatial part of the 3D energy conservation for fluid flow.
unsigned int _j
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableTestGradient & _grad_test
virtual Real computeQpJacobian() override
void mooseError(Args &&... args) const
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
void addClassDescription(const std::string &doc_string)
const MaterialProperty< Real > & _rho
const VariableValue & _porosity_elem
unsigned int mapVarNumber(unsigned int var) const
Helper function for mapping Moose variable numberings into the "canonical" numbering for the porous m...
bool _has_pke
volumetric heat source
virtual Real value(Real t, const Point &p) const
INSFEFluidEnergyKernel(const InputParameters &parameters)
const VariableValue & _v_vel
const VariablePhiValue & _phi
const MooseArray< Point > & _q_point
const VariableValue & _u
unsigned int _qp