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 : #pragma once 11 : 12 : // FluidProperties includes 13 : #include "IdealGasFluidProperties.h" 14 : 15 : /** 16 : * Class outside the Moose hierarchy that contains common 17 : * functionality for computing derivatives of the temperature 18 : * variable. 19 : * 20 : * This class is templated so that it can be used by either 21 : * a Kernel object or a BC object. 22 : */ 23 : template <class T> 24 : class NSTemperatureDerivs 25 : { 26 : public: 27 : NSTemperatureDerivs(T & x); 28 : 29 : /** 30 : * The primary interfaces for computing temperature derivatives. 31 : * Requires access to protected values from the _data reference. 32 : * The indices input to these functions are in terms of the 33 : * "canonical" variable numbering. 34 : */ 35 : Real get_grad(unsigned i); 36 : Real get_hess(unsigned i, unsigned j); 37 : 38 : private: 39 : T & _data; 40 : }; 41 : 42 : template <class T> 43 0 : NSTemperatureDerivs<T>::NSTemperatureDerivs(T & x) : _data(x) 44 : { 45 : } 46 : 47 : template <class T> 48 : Real 49 0 : NSTemperatureDerivs<T>::get_grad(unsigned i) 50 : { 51 : // Convenience vars 52 0 : const Real U0 = _data._rho[_data._qp]; 53 0 : const Real U1 = _data._rho_u[_data._qp]; 54 0 : const Real U2 = _data._rho_v[_data._qp]; 55 0 : const Real U3 = _data._rho_w[_data._qp]; 56 0 : const Real U4 = _data._rho_et[_data._qp]; 57 : 58 0 : const Real rho2 = U0 * U0; 59 0 : const Real mom2 = U1 * U1 + U2 * U2 + U3 * U3; 60 0 : const Real tmp = -1.0 / rho2 / _data._fp.cv(); 61 : 62 0 : switch (i) 63 : { 64 0 : case 0: // dT/d(rho) 65 0 : return (U4 - (mom2 / U0)) * tmp; 66 : 67 0 : case 1: // dT/d(rho*u) 68 0 : return U1 * tmp; 69 : 70 0 : case 2: // dT/d(rho*v) 71 0 : return U2 * tmp; 72 : 73 0 : case 3: // dT/d(rho*w) 74 0 : return U3 * tmp; 75 : 76 0 : case 4: // dT/d(rho*e) 77 0 : return -U0 * tmp; 78 : 79 0 : default: 80 0 : mooseError("Should not get here!"); 81 : break; 82 : } 83 : } 84 : 85 : template <class T> 86 : Real 87 0 : NSTemperatureDerivs<T>::get_hess(unsigned i, unsigned j) 88 : { 89 : // Convenience vars 90 0 : const Real U0 = _data._rho[_data._qp]; 91 0 : const Real U1 = _data._rho_u[_data._qp]; 92 0 : const Real U2 = _data._rho_v[_data._qp]; 93 0 : const Real U3 = _data._rho_w[_data._qp]; 94 0 : const Real U4 = _data._rho_et[_data._qp]; 95 : 96 0 : const Real rho2 = U0 * U0; 97 0 : const Real rho3 = rho2 * U0; 98 0 : const Real rho4 = rho3 * U0; 99 0 : const Real mom2 = U1 * U1 + U2 * U2 + U3 * U3; 100 : 101 0 : const Real cv = _data._fp.cv(); 102 0 : const Real tmp = -1.0 / rho2 / cv; 103 : 104 : // Only lower-triangle of matrix is defined, it is symmetric 105 0 : if (i < j) 106 : std::swap(i, j); 107 : 108 : // Map (i,j) into row-major storage index, 5 entries per row 109 0 : unsigned idx = 5 * i + j; 110 : 111 0 : switch (idx) 112 : { 113 : // Row 0 114 0 : case 0: // rho, rho derivative 115 0 : return 2.0 * U4 / rho3 / cv - 3.0 * mom2 / rho4 / cv; 116 : 117 : // Row 1 118 0 : case 5: // rho*u, rho 119 0 : return 2.0 * U1 / rho3 / cv; 120 : 121 : case 6: // rho*u, rho*u 122 : return tmp; 123 : 124 : // Row 2 125 0 : case 10: // rho*v, rho 126 0 : return 2.0 * U2 / rho3 / cv; 127 : 128 : case 12: // rho*v, rho*v 129 : return tmp; 130 : 131 : // Row 3 132 0 : case 15: // rho*w, rho 133 0 : return 2.0 * U3 / rho3 / cv; 134 : 135 : case 18: // rho*w, rho*w 136 : return tmp; 137 : 138 : // Row 4 139 : case 20: // rho*e, rho 140 : return tmp; 141 : 142 0 : case 11: 143 : case 16: 144 : case 17: 145 : case 21: 146 : case 22: 147 : case 23: 148 : case 24: 149 0 : return 0.0; 150 : 151 0 : default: 152 0 : mooseError("Should not get here!"); 153 : break; 154 : } 155 : 156 : return 0.0; 157 : }