www.mooseframework.org
NSEnergyViscousBC.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 // Navier-Stokes includes
11 #include "NS.h"
12 #include "NSEnergyViscousBC.h"
13 
14 registerMooseObject("NavierStokesApp", NSEnergyViscousBC);
15 
18 {
20  params.addRequiredCoupledVar(NS::temperature, "temperature");
21  return params;
22 }
23 
25  : NSIntegratedBC(parameters),
26  _grad_temperature(coupledGradient(NS::temperature)),
27  _thermal_conductivity(getMaterialProperty<Real>("thermal_conductivity")),
28  // Viscous stress tensor derivative computing object
29  _vst_derivs(*this),
30  // Temperature derivative computing object
31  _temp_derivs(*this)
32 {
33  // Store pointers to all variable gradients in a single vector.
34  _gradU.resize(5);
35  _gradU[0] = &_grad_rho;
36  _gradU[1] = &_grad_rho_u;
37  _gradU[2] = &_grad_rho_v;
38  _gradU[3] = &_grad_rho_w;
39  _gradU[4] = &_grad_rho_et;
40 }
41 
42 Real
44 {
45  // n . (- k*grad(T) - tau*u) v
46 
47  // Velocity vector object
49 
50  // k*grad(T)
52 
53  // tau*u
54  RealVectorValue visc_vec = _viscous_stress_tensor[_qp] * vel;
55 
56  // Add everything up, dot with normal, hit with test function.
57  return ((-thermal_vec - visc_vec) * _normals[_qp]) * _test[_i][_qp];
58 }
59 
60 Real
62 {
63  // See notes for this term, involves temperature Hessian
64  Real thermal_term = 0.0;
65 
66  for (unsigned int ell = 0; ell < LIBMESH_DIM; ++ell)
67  {
68  Real intermediate_result = 0.;
69 
70  // The temperature Hessian contribution
71  for (unsigned n = 0; n < 5; ++n)
72  intermediate_result += _temp_derivs.get_hess(/*m=*/4, n) * (*_gradU[n])[_qp](ell);
73 
74  // Hit Hessian contribution with test function
75  intermediate_result *= _phi[_j][_qp];
76 
77  // Add in the temperature gradient contribution
78  intermediate_result += _temp_derivs.get_grad(/*rhoE=*/4) * _grad_phi[_j][_qp](ell);
79 
80  // Hit the result with the normal component, accumulate in thermal_term
81  thermal_term += intermediate_result * _normals[_qp](ell);
82  }
83 
84  // Hit thermal_term with thermal conductivity
85  thermal_term *= _thermal_conductivity[_qp];
86 
87  return (-thermal_term) * _test[_i][_qp];
88 }
89 
90 Real
92 {
93  if (isNSVariable(jvar))
94  {
95  // Note: This function requires both _vst_derivs *and* _temp_derivs
96 
97  // Convenience variables
99 
100  Real rho = _rho[_qp];
101  Real phij = _phi[_j][_qp];
103 
104  // Map jvar into the variable m for our problem, regardless of
105  // how Moose has numbered things.
106  unsigned m = mapVarNumber(jvar);
107 
108  //
109  // 1.) Thermal term derivatives
110  //
111 
112  // See notes for this term, involves temperature Hessian
113  Real thermal_term = 0.;
114 
115  for (unsigned ell = 0; ell < LIBMESH_DIM; ++ell)
116  {
117  Real intermediate_result = 0.;
118 
119  // The temperature Hessian contribution
120  for (unsigned n = 0; n < 5; ++n)
121  intermediate_result += _temp_derivs.get_hess(m, n) * (*_gradU[n])[_qp](ell);
122 
123  // Hit Hessian contribution with test function
124  intermediate_result *= _phi[_j][_qp];
125 
126  // Add in the temperature gradient contribution
127  intermediate_result += _temp_derivs.get_grad(m) * _grad_phi[_j][_qp](ell);
128 
129  // Hit the result with the normal component, accumulate in thermal_term
130  thermal_term += intermediate_result * _normals[_qp](ell);
131  }
132 
133  // Hit thermal_term with thermal conductivity
134  thermal_term *= _thermal_conductivity[_qp];
135 
136  //
137  // 2.) Viscous term derivatives
138  //
139 
140  // Compute viscous term derivatives
141  Real visc_term = 0.;
142 
143  switch (m)
144  {
145  case 0: // density
146  {
147  // Loop over k and ell as in the notes...
148  for (const auto k : make_range(Moose::dim))
149  {
150  Real intermediate_value = 0.0;
151  for (unsigned int ell = 0; ell < LIBMESH_DIM; ++ell)
152  intermediate_value +=
153  (U(ell) / rho * (-tau(k, ell) * phij / rho + _vst_derivs.dtau(k, ell, m)));
154 
155  // Hit accumulated value with normal component k. We will multiply by test function at
156  // the end of this routine...
157  visc_term += intermediate_value * _normals[_qp](k);
158  } // end for k
159 
160  break;
161  } // end case 0
162 
163  case 1:
164  case 2:
165  case 3: // momentums
166  {
167  // Map m -> 0,1,2 as usual...
168  unsigned int m_local = m - 1;
169 
170  // Loop over k and ell as in the notes...
171  for (const auto k : make_range(Moose::dim))
172  {
173  Real intermediate_value = tau(k, m_local) * phij / rho;
174 
175  for (unsigned int ell = 0; ell < LIBMESH_DIM; ++ell)
176  intermediate_value += _vst_derivs.dtau(k, ell, m) * U(ell) /
177  rho; // Note: pass 'm' to dtau, it will convert it internally
178 
179  // Hit accumulated value with normal component k.
180  visc_term += intermediate_value * _normals[_qp](k);
181  } // end for k
182 
183  break;
184  } // end case 1,2,3
185 
186  case 4: // energy
187  mooseError("Shouldn't get here, this is the on-diagonal entry!");
188  break;
189 
190  default:
191  mooseError("Invalid m value.");
192  break;
193  }
194 
195  // Finally, sum up the different contributions (with appropriate
196  // sign) multiply by the test function, and return.
197  return (-thermal_term - visc_term) * _test[_i][_qp];
198  }
199  else
200  return 0.0;
201 }
const VariableTestValue & _test
bool isNSVariable(unsigned var)
unsigned int _j
This class couples together all the variables for the compressible Navier-Stokes equations to allow t...
const MooseArray< Point > & _normals
const VariableGradient & _grad_rho_w
Real get_grad(unsigned i)
The primary interfaces for computing temperature derivatives.
const VariableValue & _rho_w
virtual Real computeQpOffDiagJacobian(unsigned jvar)
const VariableValue & _w_vel
const VariableValue & _rho
unsigned int _i
static constexpr std::size_t dim
const VariableGradient & _grad_rho_u
Real dtau(unsigned k, unsigned ell, unsigned m)
The primary interface for computing viscous stress tensor derivatives.
static const std::string temperature
Definition: NS.h:57
NSTemperatureDerivs< NSEnergyViscousBC > _temp_derivs
const VariableGradient & _grad_rho_et
const VariableGradient & _grad_rho_v
const VariablePhiValue & _phi
virtual Real computeQpJacobian()
const MaterialProperty< Real > & _thermal_conductivity
const MaterialProperty< RealTensorValue > & _viscous_stress_tensor
unsigned int _qp
const VariablePhiGradient & _grad_phi
TensorValue< Real > RealTensorValue
NSViscStressTensorDerivs< NSEnergyViscousBC > _vst_derivs
virtual Real computeQpResidual()
Just like other kernels, we must overload the Residual and Jacobian contributions...
static InputParameters validParams()
std::vector< const VariableGradient * > _gradU
registerMooseObject("NavierStokesApp", NSEnergyViscousBC)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
unsigned mapVarNumber(unsigned var)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableValue & _v_vel
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
const VariableValue & _rho_u
NSEnergyViscousBC(const InputParameters &parameters)
const VariableGradient & _grad_rho
const VariableGradient & _grad_temperature
const VariableValue & _u_vel
static InputParameters validParams()
static const std::string k
Definition: NS.h:124
Real get_hess(unsigned i, unsigned j)
This class corresponds to the viscous part of the "natural" boundary condition for the energy equatio...
const VariableValue & _rho_v