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