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