https://mooseframework.inl.gov
NSSUPGMomentum.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 #include "NSSUPGMomentum.h"
11 
12 // FluidProperties includes
14 
15 registerMooseObject("NavierStokesApp", NSSUPGMomentum);
16 
19 {
21  params.addClassDescription(
22  "Compute residual and Jacobian terms form the SUPG terms in the momentum equation.");
23  params.addRequiredParam<unsigned int>("component", "");
24  return params;
25 }
26 
28  : NSSUPGBase(parameters), _component(getParam<unsigned>("component"))
29 {
30 }
31 
32 Real
34 {
35  // See "Component SUPG contributions" section of notes for details.
36 
37  // Values to be summed up and returned
38  Real mass_term = 0.0;
39  Real mom_term = 0.0;
40  Real energy_term = 0.0;
41 
42  // Velocity vector
44 
45  // Velocity vector magnitude squared
46  Real velmag2 = vel.norm_sq();
47 
48  // Ratio of specific heats
49  const Real gam = _fp.gamma();
50 
51  // Velocity vector, dotted with the test function gradient
52  Real U_grad_phi = vel * _grad_test[_i][_qp];
53 
54  // _component'th entry of test function gradient
55  Real dphi_dxk = _grad_test[_i][_qp](_component);
56 
57  // Vector object of momentum equation strong residuals
58  RealVectorValue Ru(
60 
61  // 1.) The mass-residual term:
62  Real mass_coeff = 0.5 * (gam - 1.0) * velmag2 * dphi_dxk - vel(_component) * U_grad_phi;
63 
64  mass_term = _tauc[_qp] * mass_coeff * _strong_residuals[_qp][0];
65  // Moose::out << "mass_term[" << _qp << "]=" << mass_term << std::endl;
66 
67  // 2.) The momentum-residual term:
68  Real mom_term1 =
69  U_grad_phi *
70  _strong_residuals[_qp][_component + 1]; // <- momentum indices are 1,2,3, _component is 0,1,2
71  Real mom_term2 = (1. - gam) * dphi_dxk * (vel * Ru);
72  Real mom_term3 = vel(_component) * (_grad_test[_i][_qp] * Ru);
73 
74  mom_term = _taum[_qp] * (mom_term1 + mom_term2 + mom_term3);
75  // Moose::out << "mom_term[" << _qp << "]=" << mom_term << std::endl;
76 
77  // 3.) The energy-residual term:
78  energy_term = _taue[_qp] * (gam - 1.0) * dphi_dxk * _strong_residuals[_qp][4];
79 
80  // For printing purposes only
81  Real result = mass_term + mom_term + energy_term;
82 
83  return result;
84 }
85 
86 Real
88 {
89  // Set variable number for the computeJacobianHelper() function based on the
90  // _component and the knowledge that this is the on-diagonal entry.
91  unsigned int var_number[3] = {_rhou_var_number, _rhov_var_number, _rhow_var_number};
92 
93  // Call the common computeJacobianHelper() function
94  return computeJacobianHelper(var_number[_component]);
95 }
96 
97 Real
99 {
100  return computeJacobianHelper(jvar);
101 }
102 
103 Real
105 {
106  if (isNSVariable(var))
107  {
108  // Convert the Moose numbering to canonical NS variable numbering.
109  unsigned mapped_var_number = mapVarNumber(var);
110 
111  // Convenience vars
112 
113  // Velocity vector
115 
116  // Velocity vector magnitude squared
117  Real velmag2 = vel.norm_sq();
118 
119  // Ratio of specific heats
120  const Real gam = _fp.gamma();
121 
122  // Shortcuts for shape function gradients at current qp.
123  RealVectorValue grad_test_i = _grad_test[_i][_qp];
124  RealVectorValue grad_phi_j = _grad_phi[_j][_qp];
125 
126  // ...
127 
128  // 1.) taum- and taue-proportional terms present for any variable:
129 
130  //
131  // Art. Diffusion matrix for taum-proportional term = ( C_k + (1-gam)*C_k^T + diag(u_k) ) *
132  // calA_{ell}
133  //
134  RealTensorValue mom_mat;
135  mom_mat(0, 0) = mom_mat(1, 1) = mom_mat(2, 2) = vel(_component); // (diag(u_k)
136  mom_mat += _calC[_qp][_component]; // + C_k
137  mom_mat += (1.0 - gam) * _calC[_qp][_component].transpose(); // + (1-gam)*C_k^T)
138  mom_mat = mom_mat * _calA[_qp][mapped_var_number]; // * calA_{ell}
139  Real mom_term =
140  _taum[_qp] * grad_test_i * (mom_mat * grad_phi_j); // taum * grad(phi_i) * (M*grad(phi_j))
141 
142  //
143  // Art. Diffusion matrix for taue-proportional term = (gam-1) * calE_km
144  //
145  RealTensorValue ene_mat = (gam - 1) * _calE[_qp][_component][mapped_var_number];
146  Real ene_term =
147  _taue[_qp] * grad_test_i * (ene_mat * grad_phi_j); // taue * grad(phi_i) * (M*grad(phi_j))
148 
149  // 2.) Terms only present if the variable is one of the momentums
150  Real mass_term = 0.0;
151 
152  switch (mapped_var_number)
153  {
154  case 1:
155  case 2:
156  case 3:
157  {
158  // Variable for zero-based indexing into local matrices and vectors.
159  unsigned m_local = mapped_var_number - 1;
160 
161  //
162  // Art. Diffusion matrix for tauc-proportional term = 0.5*(gam - 1.0)*velmag2*D_km -
163  // vel(_component)*C_m
164  //
165  RealTensorValue mass_mat;
166  mass_mat(_component, m_local) = 0.5 * (gam - 1.0) * velmag2; // 0.5*(gam - 1.0)*velmag2*D_km
167  mass_mat -= vel(_component) * _calC[_qp][m_local]; // vel(_component)*C_m
168  mass_term = _tauc[_qp] * grad_test_i *
169  (mass_mat * grad_phi_j); // tauc * grad(phi_i) * (M*grad(phi_j))
170  }
171  // Nothing else to do if we are not a momentum...
172  }
173 
174  // Sum up values and return
175  return mass_term + mom_term + ene_term;
176  }
177  else
178  return 0.0;
179 }
virtual Real computeQpOffDiagJacobian(unsigned int jvar)
const IdealGasFluidProperties & _fp
Definition: NSKernel.h:63
registerMooseObject("NavierStokesApp", NSSUPGMomentum)
const VariableValue & _w_vel
Definition: NSKernel.h:36
virtual Real computeQpJacobian()
const VariablePhiGradient & _grad_phi
unsigned _rhov_var_number
Definition: NSKernel.h:54
const MaterialProperty< std::vector< RealTensorValue > > & _calC
Definition: NSSUPGBase.h:45
void addRequiredParam(const std::string &name, const std::string &doc_string)
NSSUPGMomentum(const InputParameters &parameters)
TensorValue< Real > RealTensorValue
auto norm_sq() const -> decltype(std::norm(Real()))
unsigned _rhow_var_number
Definition: NSKernel.h:55
Compute residual and Jacobian terms form the SUPG terms in the momentum equation. ...
bool isNSVariable(unsigned var)
Helper functions for mapping Moose variable numberings into the "canonical" numbering for the compres...
Definition: NSKernel.C:79
const MaterialProperty< Real > & _taum
Definition: NSSUPGBase.h:37
static InputParameters validParams()
Definition: NSSUPGBase.C:18
unsigned int _i
Real computeJacobianHelper(unsigned int var)
virtual Real computeQpResidual()
unsigned int _j
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _component
const VariableValue & _u_vel
Definition: NSKernel.h:34
const VariableTestGradient & _grad_test
const MaterialProperty< std::vector< RealTensorValue > > & _calA
Definition: NSSUPGBase.h:42
const VariableValue & _v_vel
Definition: NSKernel.h:35
const MaterialProperty< std::vector< Real > > & _strong_residuals
Definition: NSSUPGBase.h:39
const MaterialProperty< Real > & _tauc
Definition: NSSUPGBase.h:36
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
This class acts as a base class for stabilization kernels.
Definition: NSSUPGBase.h:21
const MaterialProperty< std::vector< std::vector< RealTensorValue > > > & _calE
Definition: NSSUPGBase.h:48
unsigned mapVarNumber(unsigned var)
Definition: NSKernel.C:89
unsigned _rhou_var_number
Definition: NSKernel.h:53
const MaterialProperty< Real > & _taue
Definition: NSSUPGBase.h:38
unsigned int _qp