Line data Source code
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 : // Navier-Stokes includes 11 : #include "NS.h" 12 : #include "NSEnergyThermalFlux.h" 13 : 14 : registerMooseObject("NavierStokesApp", NSEnergyThermalFlux); 15 : 16 : InputParameters 17 0 : NSEnergyThermalFlux::validParams() 18 : { 19 0 : InputParameters params = NSKernel::validParams(); 20 0 : params.addClassDescription("This class is responsible for computing residuals and Jacobian terms " 21 : "for the k * grad(T) * grad(phi) term in the Navier-Stokes energy " 22 : "equation."); 23 0 : params.addRequiredCoupledVar(NS::temperature, "temperature"); 24 0 : return params; 25 0 : } 26 : 27 0 : NSEnergyThermalFlux::NSEnergyThermalFlux(const InputParameters & parameters) 28 : : NSKernel(parameters), 29 0 : _grad_temp(coupledGradient(NS::temperature)), 30 0 : _thermal_conductivity(getMaterialProperty<Real>("thermal_conductivity")), 31 : // Temperature derivative computing object 32 0 : _temp_derivs(*this) 33 : { 34 : // Store pointers to all variable gradients in a single vector. 35 0 : _gradU.resize(5); 36 0 : _gradU[0] = &_grad_rho; 37 0 : _gradU[1] = &_grad_rho_u; 38 0 : _gradU[2] = &_grad_rho_v; 39 0 : _gradU[3] = &_grad_rho_w; 40 0 : _gradU[4] = &_grad_rho_et; 41 0 : } 42 : 43 : Real 44 0 : NSEnergyThermalFlux::computeQpResidual() 45 : { 46 : // k * grad(T) * grad(phi) 47 0 : return _thermal_conductivity[_qp] * (_grad_temp[_qp] * _grad_test[_i][_qp]); 48 : } 49 : 50 : Real 51 0 : NSEnergyThermalFlux::computeQpJacobian() 52 : { 53 : // The "on-diagonal" Jacobian for the energy equation 54 : // corresponds to variable number 4. 55 0 : return computeJacobianHelper_value(/*var_number=*/4); 56 : } 57 : 58 : Real 59 0 : NSEnergyThermalFlux::computeQpOffDiagJacobian(unsigned int jvar) 60 : { 61 0 : if (isNSVariable(jvar)) 62 0 : return computeJacobianHelper_value(mapVarNumber(jvar)); 63 : else 64 : return 0.0; 65 : } 66 : 67 : Real 68 0 : NSEnergyThermalFlux::computeJacobianHelper_value(unsigned var_number) 69 : { 70 : // The value to return 71 : Real result = 0.0; 72 : 73 : // I used "ell" here as the loop counter since it matches the 74 : // "\ell" used in my LaTeX notes. 75 0 : for (unsigned int ell = 0; ell < 3; ++ell) 76 : { 77 : // Accumulate the first dot product term 78 0 : Real intermediate_result = _temp_derivs.get_grad(var_number) * _grad_phi[_j][_qp](ell); 79 : 80 : // Now accumulate the Hessian term 81 : Real hess_term = 0.0; 82 0 : for (unsigned n = 0; n < 5; ++n) 83 : { 84 : // hess_term += get_hess(m,n) * gradU[n](ell); // ideally... but you can't have a 85 : // vector<VariableGradient&> :-( 86 0 : hess_term += _temp_derivs.get_hess(var_number, n) * 87 0 : (*_gradU[n])[_qp](ell); // dereference pointer to get value 88 : } 89 : 90 : // Accumulate the second dot product term 91 0 : intermediate_result += hess_term * _phi[_j][_qp]; 92 : 93 : // Hit intermediate_result with the test function, accumulate in the final value 94 0 : result += intermediate_result * _grad_test[_i][_qp](ell); 95 : } 96 : 97 : // Return result, don't forget to multiply by "k"! 98 0 : return _thermal_conductivity[_qp] * result; 99 : }