LCOV - code coverage report
Current view: top level - include/userobjects - NSPressureDerivs.h (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: 9fc4b0 Lines: 16 43 37.2 %
Date: 2025-08-14 10:14:56 Functions: 1 5 20.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             : #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 pressure
      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 NSPressureDerivs
      25             : {
      26             : public:
      27             :   NSPressureDerivs(T & x);
      28             : 
      29             :   /**
      30             :    * The primary interfaces for computing pressure 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         110 : NSPressureDerivs<T>::NSPressureDerivs(T & x) : _data(x)
      44             : {
      45             : }
      46             : 
      47             : template <class T>
      48             : Real
      49     3354624 : NSPressureDerivs<T>::get_grad(unsigned i)
      50             : {
      51             :   // Convenience vars
      52     3354624 :   const Real u = _data._u_vel[_data._qp];
      53     3354624 :   const Real v = _data._v_vel[_data._qp];
      54     3354624 :   const Real w = _data._w_vel[_data._qp];
      55             : 
      56     3354624 :   const Real vel2 = (u * u + v * v + w * w);
      57     3354624 :   const Real gam = _data._fp.gamma();
      58             : 
      59     3354624 :   switch (i)
      60             :   {
      61      838656 :     case 0: // dP/d(rho)
      62      838656 :       return 0.5 * (gam - 1.0) * vel2;
      63             : 
      64      838656 :     case 1: // dP/d(rho*u)
      65      838656 :       return (1.0 - gam) * u;
      66             : 
      67      838656 :     case 2: // dP/d(rho*v)
      68      838656 :       return (1.0 - gam) * v;
      69             : 
      70           0 :     case 3: // dP/d(rho*w)
      71           0 :       return (1.0 - gam) * w;
      72             : 
      73      838656 :     case 4: // dP/d(rho*e)
      74      838656 :       return gam - 1.;
      75             : 
      76           0 :     default:
      77           0 :       mooseError("Should not get here!");
      78             :       break;
      79             :   }
      80             : }
      81             : 
      82             : template <class T>
      83             : Real
      84           0 : NSPressureDerivs<T>::get_hess(unsigned i, unsigned j)
      85             : {
      86             :   // Convenience variables
      87           0 :   const Real U0 = _data._rho[_data._qp];
      88             : 
      89           0 :   const Real u = _data._u_vel[_data._qp];
      90           0 :   const Real v = _data._v_vel[_data._qp];
      91           0 :   const Real w = _data._w_vel[_data._qp];
      92           0 :   const Real vel2 = (u * u + v * v + w * w);
      93             : 
      94             :   // Save some typing...
      95           0 :   const Real gam = _data._fp.gamma();
      96             : 
      97             :   // A frequently-used variable
      98           0 :   const Real tmp = (1.0 - gam) / U0;
      99             : 
     100             :   // Only lower-triangle of matrix is defined, it is symmetric
     101           0 :   if (i < j)
     102             :     std::swap(i, j);
     103             : 
     104             :   // Map (i,j) into row-major storage index, 5 entries per row
     105           0 :   const unsigned int idx = 5 * i + j;
     106             : 
     107           0 :   switch (idx)
     108             :   {
     109             :     // Row 0
     110           0 :     case 0: // rho, rho derivative
     111           0 :       return tmp * vel2;
     112             : 
     113             :     // Row 1
     114           0 :     case 5: // rho*u, rho
     115           0 :       return -tmp * u;
     116             : 
     117             :     case 6: // rho*u, rho*u
     118             :       return tmp;
     119             : 
     120             :     // Row 2
     121           0 :     case 10: // rho*v, rho
     122           0 :       return -tmp * v;
     123             : 
     124             :     case 12: // rho*v, rho*v
     125             :       return tmp;
     126             : 
     127             :     // Row 3
     128           0 :     case 15: // rho*w, rho
     129           0 :       return -tmp * w;
     130             : 
     131             :     case 18: // rho*w, rho*w
     132             :       return tmp;
     133             : 
     134           0 :     case 11:
     135             :     case 16:
     136             :     case 17:
     137             :     case 20:
     138             :     case 21:
     139             :     case 22:
     140             :     case 23:
     141             :     case 24:
     142           0 :       return 0.;
     143             : 
     144           0 :     default:
     145           0 :       mooseError("Should not get here!");
     146             :       break;
     147             :   }
     148             : 
     149             :   return 0.0;
     150             : }

Generated by: LCOV version 1.14