www.mooseframework.org
NSMomentumInviscidFluxWithGradP.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 inclues
9 #include "NS.h"
11 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<NSKernel>();
17  params.addClassDescription(
18  "This class computes the inviscid flux with pressure gradient in the momentum equation.");
19  params.addRequiredCoupledVar(NS::pressure, "pressure");
20  params.addRequiredParam<unsigned int>("component", "");
21  return params;
22 }
23 
25  : NSKernel(parameters),
26  _grad_p(coupledGradient(NS::pressure)),
27  _component(getParam<unsigned int>("component")),
28  _pressure_derivs(*this)
29 {
30  // Store pointers to all variable gradients in a single vector.
31  // This is needed for computing pressure Hessian values with a small
32  // amount of code.
33  _gradU.resize(5);
34  _gradU[0] = &_grad_rho;
35  _gradU[1] = &_grad_rho_u;
36  _gradU[2] = &_grad_rho_v;
37  _gradU[3] = &_grad_rho_w;
38  _gradU[4] = &_grad_rho_E;
39 }
40 
41 Real
43 {
44  // For _component = k,
45 
46  // (rho*u) * u_k = (rho*u_k) * u <- we write it this way
47  RealVectorValue vec(_u[_qp] * _u_vel[_qp], // (U_k) * u_1
48  _u[_qp] * _v_vel[_qp], // (U_k) * u_2
49  _u[_qp] * _w_vel[_qp]); // (U_k) * u_3
50 
51  // -((rho*u_k) * u) * grad(phi) + dp/dx_k * phi
52  return -(vec * _grad_test[_i][_qp]) + _grad_p[_qp](_component) * _test[_i][_qp];
53 }
54 
55 Real
57 {
58  RealVectorValue vec(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
59 
60  // The component'th entry of the on-diagonal Jacobian value is 2*u_i without the pressure
61  // contribution.
62  vec(_component) = 2. * vec(_component);
63 
64  // The Jacobian contribution due to grad(p) for the on-diagonal
65  // variable, which is equal to _component+1.
66  Real dFdp = pressureQpJacobianHelper(_component + 1);
67 
68  return
69  // Convective terms Jacobian
70  -(vec * _grad_test[_i][_qp]) * _phi[_j][_qp]
71  // Pressure term Jacobian
72  + dFdp * _test[_i][_qp];
73 }
74 
75 Real
77 {
78  if (isNSVariable(jvar))
79  {
80 
81  // Map jvar into the numbering expected by this->compute_pressure_jacobain_value()
82  unsigned int var_number = mapVarNumber(jvar);
83 
84  // The Jacobian contribution due to differentiating the grad(p)
85  // term wrt variable var_number.
86  Real dFdp = pressureQpJacobianHelper(var_number);
87 
88  if (jvar == _rho_var_number)
89  {
90  // Derivative of inviscid flux convective terms wrt density:
91  // x-mom: (-u_1^2 , -u_1*u_2 , -u_1*u_3 ) * grad(phi_i) * phi_j
92  // y-mom: (-u_2*u_1 , -u_2^2 , -u_2*u_3 ) * grad(phi_i) * phi_j
93  // z-mom: (-u_3*u_1 , -u_3*u_2 , -u_3^2 ) * grad(phi_i) * phi_j
94 
95  // Start with the velocity vector
96  RealVectorValue vec(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
97 
98  // Scale velocity vector by -1 * vec(_component)
99  vec *= -vec(_component);
100 
101  return
102  // Convective terms Jacobian
103  -(vec * _grad_test[_i][_qp]) * _phi[_j][_qp]
104  // Pressure term Jacobian
105  + dFdp * _test[_i][_qp];
106  }
107 
108  // Handle off-diagonal derivatives wrt momentums
109  else if (jvar == _rhou_var_number || jvar == _rhov_var_number || jvar == _rhow_var_number)
110  {
111  // Start with the velocity vector
112  RealVectorValue vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
113 
114  // Map jvar into jlocal = {0,1,2}, regardless of how Moose has numbered things.
115  // Can't do a case statement here since _rhou_var_number, etc. are not constants...
116  unsigned int jlocal = 0;
117 
118  if (jvar == _rhov_var_number)
119  jlocal = 1;
120  else if (jvar == _rhow_var_number)
121  jlocal = 2;
122 
123  return
124  // Convective terms Jacobian
125  -vel(_component) * _grad_test[_i][_qp](jlocal) * _phi[_j][_qp]
126  // Pressure term Jacobian
127  + dFdp * _test[_i][_qp];
128  }
129 
130  else if (jvar == _rhoE_var_number)
131  {
132  // Pressure term Jacobian
133  return dFdp * _test[_i][_qp];
134  }
135  else
136  return 0.0;
137  }
138  else
139  return 0.0;
140 }
141 
142 Real
144 {
145  // Make sure our local gradient and Hessian data
146  // structures are up-to-date for this quadrature point
147  // this->recalculate_gradient_and_hessian();
148 
149  Real hessian_sum = 0.0;
150  for (unsigned int n = 0; n < 5; ++n)
151  hessian_sum += _pressure_derivs.get_hess(var_number, n) * (*_gradU[n])[_qp](_component);
152 
153  // Hit hessian_sum with phij, then add to dp/dU_m * dphij/dx_k, finally return the result
154  return _pressure_derivs.get_grad(var_number) * _grad_phi[_j][_qp](_component) +
155  hessian_sum * _phi[_j][_qp];
156 }
Definition: NS.h:13
This class couples together all the variables for the compressible Navier-Stokes equations to allow t...
Definition: NSKernel.h:27
const VariableValue & _w_vel
Definition: NSKernel.h:36
Real get_grad(unsigned i)
The primary interfaces for computing pressure derivatives.
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
const VariableGradient & _grad_rho_w
Definition: NSKernel.h:48
unsigned _rhov_var_number
Definition: NSKernel.h:54
unsigned _rho_var_number
Definition: NSKernel.h:52
InputParameters validParams< NSKernel >()
Definition: NSKernel.C:20
NSMomentumInviscidFluxWithGradP(const InputParameters &parameters)
const VariableGradient & _grad_rho
Definition: NSKernel.h:45
unsigned _rhow_var_number
Definition: NSKernel.h:55
bool isNSVariable(unsigned var)
Helper functions for mapping Moose variable numberings into the "canonical" numbering for the compres...
Definition: NSKernel.C:76
Real get_hess(unsigned i, unsigned j)
const VariableGradient & _grad_rho_u
Definition: NSKernel.h:46
unsigned _rhoE_var_number
Definition: NSKernel.h:56
const VariableGradient & _grad_rho_v
Definition: NSKernel.h:47
const VariableValue & _u_vel
Definition: NSKernel.h:34
const VariableValue & _v_vel
Definition: NSKernel.h:35
const std::string pressure
Definition: NS.h:24
const VariableGradient & _grad_rho_E
Definition: NSKernel.h:49
std::vector< const VariableGradient * > _gradU
NSPressureDerivs< NSMomentumInviscidFluxWithGradP > _pressure_derivs
unsigned mapVarNumber(unsigned var)
Definition: NSKernel.C:86
unsigned _rhou_var_number
Definition: NSKernel.h:53
InputParameters validParams< NSMomentumInviscidFluxWithGradP >()