LCOV - code coverage report
Current view: top level - src/kernels - NSSUPGEnergy.C (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 40 41 97.6 %
Date: 2025-08-14 10:14:56 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          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             : #include "NSSUPGEnergy.h"
      11             : 
      12             : // FluidProperties includes
      13             : #include "IdealGasFluidProperties.h"
      14             : 
      15             : registerMooseObject("NavierStokesApp", NSSUPGEnergy);
      16             : 
      17             : InputParameters
      18          41 : NSSUPGEnergy::validParams()
      19             : {
      20          41 :   InputParameters params = NSSUPGBase::validParams();
      21          41 :   params.addClassDescription(
      22             :       "Compute residual and Jacobian terms form the SUPG terms in the energy equation.");
      23          41 :   return params;
      24           0 : }
      25             : 
      26          22 : NSSUPGEnergy::NSSUPGEnergy(const InputParameters & parameters) : NSSUPGBase(parameters) {}
      27             : 
      28             : Real
      29     5483520 : NSSUPGEnergy::computeQpResidual()
      30             : {
      31             :   // See "Component SUPG contributions" section of notes for details.
      32             : 
      33             :   // Values to be summed up and returned
      34             :   Real mass_term = 0.0;
      35             :   Real mom_term = 0.0;
      36             :   Real energy_term = 0.0;
      37             : 
      38             :   // Ratio of specific heats
      39     5483520 :   const Real gam = _fp.gamma();
      40             : 
      41             :   // Velocity vector
      42     5483520 :   RealVectorValue vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
      43             : 
      44             :   // Velocity vector magnitude squared
      45             :   Real velmag2 = vel.norm_sq();
      46             : 
      47             :   // Velocity vector, dotted with the test function gradient
      48     5483520 :   Real U_grad_phi = vel * _grad_test[_i][_qp];
      49             : 
      50             :   // Vector object of momentum equation strong residuals
      51             :   RealVectorValue Ru(
      52     5483520 :       _strong_residuals[_qp][1], _strong_residuals[_qp][2], _strong_residuals[_qp][3]);
      53             : 
      54             :   // 1.) The mass-residual term:
      55     5483520 :   Real mass_coeff = (0.5 * (gam - 1.0) * velmag2 - _specific_total_enthalpy[_qp]) * U_grad_phi;
      56             : 
      57     5483520 :   mass_term = _tauc[_qp] * mass_coeff * _strong_residuals[_qp][0];
      58             : 
      59             :   // 2.) The momentum-residual term:
      60     5483520 :   Real mom_term1 = _specific_total_enthalpy[_qp] * (_grad_test[_i][_qp] * Ru);
      61     5483520 :   Real mom_term2 = (1.0 - gam) * U_grad_phi * (vel * Ru);
      62             : 
      63     5483520 :   mom_term = _taum[_qp] * (mom_term1 + mom_term2);
      64             : 
      65             :   // 3.) The energy-residual term:
      66     5483520 :   energy_term = _taue[_qp] * gam * U_grad_phi * _strong_residuals[_qp][4];
      67             : 
      68             :   // For printing purposes only
      69     5483520 :   Real result = mass_term + mom_term + energy_term;
      70             :   // Moose::out << "result[" << _qp << "]=" << result << std::endl;
      71             : 
      72     5483520 :   return result;
      73             : }
      74             : 
      75             : Real
      76     3354624 : NSSUPGEnergy::computeQpJacobian()
      77             : {
      78             :   // This is the energy equation, so pass the on-diagonal variable number.
      79     3354624 :   return computeJacobianHelper(_rho_et_var_number);
      80             : }
      81             : 
      82             : Real
      83    10063872 : NSSUPGEnergy::computeQpOffDiagJacobian(unsigned int jvar)
      84             : {
      85    10063872 :   return computeJacobianHelper(jvar);
      86             : }
      87             : 
      88             : Real
      89    13418496 : NSSUPGEnergy::computeJacobianHelper(unsigned var)
      90             : {
      91    13418496 :   if (isNSVariable(var))
      92             :   {
      93             :     // Convert the Moose numbering to canonical NS variable numbering.
      94    13418496 :     unsigned mapped_var_number = mapVarNumber(var);
      95             : 
      96             :     // Convenience vars
      97             : 
      98             :     // Velocity vector
      99    13418496 :     RealVectorValue vel(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
     100             : 
     101             :     // Velocity vector magnitude squared
     102             :     Real velmag2 = vel.norm_sq();
     103             : 
     104             :     // Ratio of specific heats
     105    13418496 :     const Real gam = _fp.gamma();
     106             : 
     107             :     // Shortcuts for shape function gradients at current qp.
     108    13418496 :     RealVectorValue grad_test_i = _grad_test[_i][_qp];
     109    13418496 :     RealVectorValue grad_phi_j = _grad_phi[_j][_qp];
     110             : 
     111             :     // ...
     112             : 
     113             :     // 1.) taum- and taue-proportional terms present for any variable:
     114             : 
     115             :     //
     116             :     // Art. Diffusion matrix for taum-proportional term = (diag(H) + (1-gam)*S) * A_{ell}
     117             :     //
     118             :     RealTensorValue mom_mat;
     119    13418496 :     mom_mat(0, 0) = mom_mat(1, 1) = mom_mat(2, 2) = _specific_total_enthalpy[_qp]; // (diag(H)
     120    13418496 :     mom_mat += (1. - gam) * _calC[_qp][0] * _calC[_qp][0].transpose();             //  + (1-gam)*S)
     121    13418496 :     mom_mat = mom_mat * _calA[_qp][mapped_var_number];                             // * A_{ell}
     122    13418496 :     Real mom_term = _taum[_qp] * grad_test_i * (mom_mat * grad_phi_j);
     123             : 
     124             :     //
     125             :     // Art. Diffusion matrix for taue-proportinal term = gam * E_{ell},
     126             :     // where E_{ell} = C_k * E_{k ell} for any k, summation over k *not* implied.
     127             :     //
     128    13418496 :     RealTensorValue ene_mat = gam * _calC[_qp][0] * _calE[_qp][0][mapped_var_number];
     129    13418496 :     Real ene_term = _taue[_qp] * grad_test_i * (ene_mat * grad_phi_j);
     130             : 
     131             :     // 2.) Terms only present if the variable is one of the momentums
     132             :     Real mass_term = 0.;
     133             : 
     134    13418496 :     switch (mapped_var_number)
     135             :     {
     136     6709248 :       case 1:
     137             :       case 2:
     138             :       case 3:
     139             :       {
     140             :         // Variable for zero-based indexing into local matrices and vectors.
     141             :         unsigned m_local = mapped_var_number - 1;
     142             : 
     143             :         //
     144             :         // Art. Diffusion matrix for tauc-proportional term = (0.5*(gam-1.)*velmag2 - H)*C_m
     145             :         //
     146             :         RealTensorValue mass_mat =
     147     6709248 :             (0.5 * (gam - 1.) * velmag2 - _specific_total_enthalpy[_qp]) * _calC[_qp][m_local];
     148     6709248 :         mass_term = _tauc[_qp] * grad_test_i * (mass_mat * grad_phi_j);
     149             : 
     150             :         // Don't even need to break, no other cases to fall through to...
     151             :         break;
     152             :       }
     153             :     }
     154             : 
     155             :     // Sum up values and return
     156    13418496 :     return mass_term + mom_term + ene_term;
     157             :   }
     158             :   else
     159             :     return 0.0;
     160             : }

Generated by: LCOV version 1.14