Quinoa all test code coverage report
Current view: top level - PDE/Riemann - AUSM.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 99 99 100.0 %
Date: 2024-05-15 17:17:09 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 38 60 63.3 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/PDE/Riemann/AUSM.hpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     Advection Upstream Splitting Method (AUSM+) Riemann flux function
       9                 :            :   \details   This file implements the Advection Upstream Splitting Method (AUSM)
      10                 :            :              Riemann solver, with the all-speed corrections.
      11                 :            :              Ref. Liou, M. S. (2006). A sequel to AUSM, Part II: AUSM+-up for
      12                 :            :              all speeds. Journal of computational physics, 214(1), 137-170.
      13                 :            : */
      14                 :            : // *****************************************************************************
      15                 :            : #ifndef AUSM_h
      16                 :            : #define AUSM_h
      17                 :            : 
      18                 :            : #include <vector>
      19                 :            : 
      20                 :            : #include "Fields.hpp"
      21                 :            : #include "FunctionPrototypes.hpp"
      22                 :            : #include "Inciter/Options/Flux.hpp"
      23                 :            : #include "EoS/EOS.hpp"
      24                 :            : #include "MultiMat/MultiMatIndexing.hpp"
      25                 :            : 
      26                 :            : namespace inciter {
      27                 :            : 
      28                 :            : //! AUSM+up approximate Riemann solver
      29                 :            : struct AUSM {
      30                 :            : 
      31                 :            :   //! AUSM+up approximate Riemann solver flux function
      32                 :            :   //! \param[in] fn Face/Surface normal
      33                 :            :   //! \param[in] u Left and right unknown/state vector
      34                 :            :   //! \return Riemann flux solution according to AUSM+up, appended by Riemann
      35                 :            :   //!   velocities and volume-fractions.
      36                 :            :   //! \note The function signature must follow tk::RiemannFluxFn
      37                 :            :   static tk::RiemannFluxFn::result_type
      38                 :    8054891 :   flux( const std::vector< EOS >& mat_blk,
      39                 :            :         const std::array< tk::real, 3 >& fn,
      40                 :            :         const std::array< std::vector< tk::real >, 2 >& u,
      41                 :            :         const std::vector< std::array< tk::real, 3 > >& = {} )
      42                 :            :   {
      43                 :    8054891 :     auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
      44                 :            : 
      45                 :    8054891 :     auto ncomp = u[0].size()-(3+nmat);
      46         [ +  - ]:    8054891 :     std::vector< tk::real > flx( ncomp, 0 );
      47                 :            : 
      48                 :            :     // Primitive variables
      49                 :    8054891 :     tk::real rhol(0.0), rhor(0.0);
      50         [ +  + ]:   26859739 :     for (std::size_t k=0; k<nmat; ++k)
      51                 :            :     {
      52                 :   18804848 :       rhol += u[0][densityIdx(nmat, k)];
      53                 :   18804848 :       rhor += u[1][densityIdx(nmat, k)];
      54                 :            :     }
      55                 :            : 
      56                 :    8054891 :     tk::real pl(0.0), pr(0.0), amatl(0.0), amatr(0.0);
      57 [ +  - ][ +  - ]:   16109782 :     std::vector< tk::real > al_l(nmat, 0.0), al_r(nmat, 0.0),
      58 [ +  - ][ +  - ]:   16109782 :                             hml(nmat, 0.0), hmr(nmat, 0.0),
      59 [ +  - ][ +  - ]:   16109782 :                             pml(nmat, 0.0), pmr(nmat, 0.0),
      60         [ +  - ]:   16109782 :                             arhom12(nmat, 0.0),
      61         [ +  - ]:   16109782 :                             amat12(nmat, 0.0);
      62         [ +  + ]:   26859739 :     for (std::size_t k=0; k<nmat; ++k)
      63                 :            :     {
      64                 :   18804848 :       al_l[k] = u[0][volfracIdx(nmat, k)];
      65                 :   18804848 :       pml[k] = u[0][ncomp+pressureIdx(nmat, k)];
      66                 :   18804848 :       pl += pml[k];
      67                 :   18804848 :       hml[k] = u[0][energyIdx(nmat, k)] + pml[k];
      68         [ +  - ]:   37609696 :       amatl = mat_blk[k].compute< EOS::soundspeed >(
      69                 :   18804848 :         u[0][densityIdx(nmat, k)], pml[k], al_l[k], k );
      70                 :            : 
      71                 :   18804848 :       al_r[k] = u[1][volfracIdx(nmat, k)];
      72                 :   18804848 :       pmr[k] = u[1][ncomp+pressureIdx(nmat, k)];
      73                 :   18804848 :       pr += pmr[k];
      74                 :   18804848 :       hmr[k] = u[1][energyIdx(nmat, k)] + pmr[k];
      75         [ +  - ]:   37609696 :       amatr = mat_blk[k].compute< EOS::soundspeed >(
      76                 :   18804848 :         u[1][densityIdx(nmat, k)], pmr[k], al_r[k], k );
      77                 :            : 
      78                 :            :       // Average states for mixture speed of sound
      79                 :   18804848 :       arhom12[k] = 0.5*(u[0][densityIdx(nmat, k)] + u[1][densityIdx(nmat, k)]);
      80                 :   18804848 :       amat12[k] = 0.5*(amatl+amatr);
      81                 :            :     }
      82                 :            : 
      83                 :    8054891 :     auto rho12 = 0.5*(rhol+rhor);
      84                 :            : 
      85                 :            :     // mixture speed of sound
      86                 :    8054891 :     tk::real ac12(0.0);
      87         [ +  + ]:   26859739 :     for (std::size_t k=0; k<nmat; ++k)
      88                 :            :     {
      89                 :   18804848 :       ac12 += (arhom12[k]*amat12[k]*amat12[k]);
      90                 :            :     }
      91                 :    8054891 :     ac12 = std::sqrt( ac12/rho12 );
      92                 :            : 
      93                 :            :     // Independently limited velocities for advection
      94                 :    8054891 :     auto ul = u[0][ncomp+velocityIdx(nmat, 0)];
      95                 :    8054891 :     auto vl = u[0][ncomp+velocityIdx(nmat, 1)];
      96                 :    8054891 :     auto wl = u[0][ncomp+velocityIdx(nmat, 2)];
      97                 :    8054891 :     auto ur = u[1][ncomp+velocityIdx(nmat, 0)];
      98                 :    8054891 :     auto vr = u[1][ncomp+velocityIdx(nmat, 1)];
      99                 :    8054891 :     auto wr = u[1][ncomp+velocityIdx(nmat, 2)];
     100                 :            : 
     101                 :            :     // Face-normal velocities from advective velocities
     102                 :    8054891 :     auto vnl = ul*fn[0] + vl*fn[1] + wl*fn[2];
     103                 :    8054891 :     auto vnr = ur*fn[0] + vr*fn[1] + wr*fn[2];
     104                 :            : 
     105                 :            :     // Mach numbers
     106                 :    8054891 :     auto ml = vnl/ac12;
     107                 :    8054891 :     auto mr = vnr/ac12;
     108                 :            : 
     109                 :            :     // All-speed parameters
     110                 :            :     // These parameters control the amount of all-speed diffusion necessary for
     111                 :            :     // low-Mach flows. Setting k_u and k_p to zero does not add any all-speed
     112                 :            :     // diffusion, whereas setting k_u and k_p to 1 adds maximum recommended
     113                 :            :     // all-speed diffusion. See "Liou, M. S. (2006). A sequel to AUSM, Part II:
     114                 :            :     // AUSM+-up for all speeds. Journal of computational physics, 214(1),
     115                 :            :     // 137-170" for more mathematical explanation. k_u is the velocity diffusion
     116                 :            :     // term and k_p is the pressure diffusion term. These two terms reduce
     117                 :            :     // pressure-velocity decoupling (chequerboarding/odd-even oscillations).
     118                 :    8054891 :     tk::real k_u(1.0), k_p(1.0), f_a(1.0);
     119                 :            : 
     120                 :            :     // Split Mach polynomials
     121                 :    8054891 :     auto msl = splitmach_ausm( f_a, ml );
     122                 :    8054891 :     auto msr = splitmach_ausm( f_a, mr );
     123                 :            : 
     124                 :            :     // Riemann Mach number
     125                 :    8054891 :     auto m0 = 1.0 - (0.5*(vnl*vnl + vnr*vnr)/(ac12*ac12));
     126                 :    8054891 :     auto mp = -k_p* std::max(m0, 0.0) * (pr-pl) / (f_a*rho12*ac12*ac12);
     127                 :    8054891 :     auto m12 = msl[0] + msr[1] + mp;
     128                 :    8054891 :     auto vriem = ac12 * m12;
     129                 :            : 
     130                 :            :     // Riemann pressure
     131                 :    8054891 :     auto pu = -k_u* msl[2] * msr[3] * f_a * rho12 * ac12 * (vnr-vnl);
     132                 :    8054891 :     auto p12 = msl[2]*pl + msr[3]*pr + pu;
     133                 :            : 
     134                 :            :     // Flux vector splitting
     135                 :    8054891 :     auto l_plus = 0.5 * (vriem + std::fabs(vriem));
     136                 :    8054891 :     auto l_minus = 0.5 * (vriem - std::fabs(vriem));
     137                 :            : 
     138                 :            :     // Conservative fluxes
     139         [ +  + ]:   26859739 :     for (std::size_t k=0; k<nmat; ++k)
     140                 :            :     {
     141                 :   18804848 :       flx[volfracIdx(nmat, k)] = l_plus*al_l[k] + l_minus*al_r[k];
     142                 :   37609696 :       flx[densityIdx(nmat, k)] = l_plus*u[0][densityIdx(nmat, k)]
     143                 :   18804848 :                               + l_minus*u[1][densityIdx(nmat, k)];
     144                 :   18804848 :       flx[energyIdx(nmat, k)] = l_plus*hml[k] + l_minus*hmr[k];
     145                 :            :     }
     146                 :            : 
     147         [ +  + ]:   32219564 :     for (std::size_t idir=0; idir<3; ++idir)
     148                 :            :     {
     149                 :   48329346 :     flx[momentumIdx(nmat, idir)] = l_plus*u[0][momentumIdx(nmat, idir)]
     150                 :   24164673 :                                  + l_minus*u[1][momentumIdx(nmat, idir)]
     151                 :   24164673 :                                  + p12*fn[idir];
     152                 :            :     }
     153                 :            : 
     154                 :    8054891 :     l_plus = l_plus/( std::fabs(vriem) + 1.0e-12 );
     155                 :    8054891 :     l_minus = l_minus/( std::fabs(vriem) + 1.0e-12 );
     156                 :            : 
     157                 :            :     // Store Riemann-advected partial pressures
     158         [ +  + ]:    8054891 :     if (std::fabs(l_plus) > 1.0e-10)
     159                 :            :     {
     160         [ +  + ]:    9042021 :       for (std::size_t k=0; k<nmat; ++k)
     161         [ +  - ]:    6366443 :         flx.push_back( pml[k] );
     162                 :            :     }
     163         [ +  + ]:    5379313 :     else if (std::fabs(l_minus) > 1.0e-10)
     164                 :            :     {
     165         [ +  + ]:    9088208 :       for (std::size_t k=0; k<nmat; ++k)
     166         [ +  - ]:    6407151 :         flx.push_back( pmr[k] );
     167                 :            :     }
     168                 :            :     else
     169                 :            :     {
     170         [ +  + ]:    8729510 :       for (std::size_t k=0; k<nmat; ++k)
     171         [ +  - ]:    6031254 :         flx.push_back( 0.5*(pml[k] + pmr[k]) );
     172                 :            :     }
     173                 :            : 
     174                 :            :     // Store Riemann velocity
     175         [ +  - ]:    8054891 :     flx.push_back( vriem );
     176                 :            : 
     177 [ -  + ][ -  - ]:    8054891 :     Assert( flx.size() == (3*nmat+3+nmat+1), "Size of multi-material flux "
         [ -  - ][ -  - ]
     178                 :            :             "vector incorrect" );
     179                 :            : 
     180                 :   16109782 :     return flx;
     181                 :            :   }
     182                 :            : 
     183                 :            :   //! Flux type accessor
     184                 :            :   //! \return Flux type
     185                 :            :   static ctr::FluxType type() noexcept { return ctr::FluxType::AUSM; }
     186                 :            : 
     187                 :            :   private:
     188                 :            : 
     189                 :            :   //! Split Mach polynomials for AUSM+ flux
     190                 :            :   //! \param[in] fa All-speed parameter
     191                 :            :   //! \param[in] mach Local Mach numner
     192                 :            :   //! \return Values of the positive and negative split Mach and pressure
     193                 :            :   //!   polynomials.
     194                 :            :   //! \details This function returns a vector with positive and negative Mach
     195                 :            :   //!   and pressure polynomials, as:
     196                 :            :   //!   ms[0] = M_4(+),
     197                 :            :   //!   ms[1] = M_4(-),
     198                 :            :   //!   ms[2] = P_5(+), and
     199                 :            :   //!   ms[3] = P_5(-).
     200                 :            :   //!   For more details, ref. Liou, M. S. (2006). A sequel to AUSM, Part II:
     201                 :            :   //!   AUSM+-up for all speeds. J. Comp. Phys., 214(1), 137-170.
     202                 :   16109782 :   static std::array< tk::real, 4 > splitmach_ausm( tk::real fa,
     203                 :            :                                                    tk::real mach )
     204                 :            :   {
     205                 :            :     std::array< tk::real, 4 > ms;
     206                 :            : 
     207                 :            :     std::array< tk::real, 3 > msplus, msminus;
     208                 :            :     tk::real psplus, psminus;
     209                 :            : 
     210                 :   16109782 :     msplus[0] = 0.5*(mach + std::fabs(mach));
     211                 :   16109782 :     msminus[0]= 0.5*(mach - std::fabs(mach));
     212                 :            : 
     213                 :   16109782 :     msplus[1] = +0.25*(mach + 1.0)*(mach + 1.0);
     214                 :   16109782 :     msminus[1]= -0.25*(mach - 1.0)*(mach - 1.0);
     215                 :            : 
     216                 :   16109782 :     auto alph_fa = (3.0/16.0) * (-4.0 + 5.0*fa*fa);
     217                 :            : 
     218         [ +  + ]:   16109782 :     if (std::fabs(mach) >= 1.0)
     219                 :            :     {
     220                 :        609 :         msplus[2] = msplus[0];
     221                 :        609 :         msminus[2]= msminus[0];
     222                 :        609 :         psplus    = msplus[0]/mach;
     223                 :        609 :         psminus   = msminus[0]/mach;
     224                 :            :     }
     225                 :            :     else
     226                 :            :     {
     227                 :   16109173 :         msplus[2] = msplus[1]* (1.0 - 2.0*msminus[1]);
     228                 :   16109173 :         msminus[2]= msminus[1]* (1.0 + 2.0*msplus[1]);
     229                 :   16109173 :         psplus    = msplus[1]*
     230                 :   16109173 :                     ((+2.0 - mach) - (16.0 * alph_fa)*mach*msminus[1]);
     231                 :   16109173 :         psminus   = msminus[1]*
     232                 :   16109173 :                     ((-2.0 - mach) + (16.0 * alph_fa)*mach*msplus[1]);
     233                 :            :     }
     234                 :            : 
     235                 :   16109782 :     ms[0] = msplus[2];
     236                 :   16109782 :     ms[1] = msminus[2];
     237                 :   16109782 :     ms[2] = psplus;
     238                 :   16109782 :     ms[3] = psminus;
     239                 :            : 
     240                 :   16109782 :     return ms;
     241                 :            :   }
     242                 :            : };
     243                 :            : 
     244                 :            : } // inciter::
     245                 :            : 
     246                 :            : #endif // AUSM_h

Generated by: LCOV version 1.14