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