Quinoa all test code coverage report
Current view: top level - PDE/MultiSpecies - DGMultiSpecies.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 118 213 55.4 %
Date: 2025-05-30 09:37:40 Functions: 7 11 63.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 87 258 33.7 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/PDE/MultiSpecies/DGMultiSpecies.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     Compressible multi-species flow using discontinuous Galerkin
       9                 :            :     finite elements
      10                 :            :   \details   This file implements calls to the physics operators governing
      11                 :            :     compressible multi-species flow using discontinuous Galerkin discretization.
      12                 :            : */
      13                 :            : // *****************************************************************************
      14                 :            : #ifndef DGMultiSpecies_h
      15                 :            : #define DGMultiSpecies_h
      16                 :            : 
      17                 :            : #include <cmath>
      18                 :            : #include <algorithm>
      19                 :            : #include <unordered_set>
      20                 :            : #include <map>
      21                 :            : #include <array>
      22                 :            : 
      23                 :            : #include "Macro.hpp"
      24                 :            : #include "Exception.hpp"
      25                 :            : #include "Vector.hpp"
      26                 :            : #include "ContainerUtil.hpp"
      27                 :            : #include "UnsMesh.hpp"
      28                 :            : #include "Inciter/InputDeck/InputDeck.hpp"
      29                 :            : #include "Integrate/Basis.hpp"
      30                 :            : #include "Integrate/Quadrature.hpp"
      31                 :            : #include "Integrate/Initialize.hpp"
      32                 :            : #include "Integrate/Mass.hpp"
      33                 :            : #include "Integrate/Surface.hpp"
      34                 :            : #include "Integrate/Boundary.hpp"
      35                 :            : #include "Integrate/Volume.hpp"
      36                 :            : #include "Integrate/Source.hpp"
      37                 :            : #include "Integrate/SolidTerms.hpp"
      38                 :            : #include "RiemannChoice.hpp"
      39                 :            : #include "MultiSpecies/MultiSpeciesIndexing.hpp"
      40                 :            : #include "Reconstruction.hpp"
      41                 :            : #include "Limiter.hpp"
      42                 :            : #include "Problem/FieldOutput.hpp"
      43                 :            : #include "Problem/BoxInitialization.hpp"
      44                 :            : #include "PrefIndicator.hpp"
      45                 :            : #include "MultiSpecies/BCFunctions.hpp"
      46                 :            : #include "MultiSpecies/MiscMultiSpeciesFns.hpp"
      47                 :            : #include "EoS/GetMatProp.hpp"
      48                 :            : #include "Mixture/Mixture.hpp"
      49                 :            : 
      50                 :            : namespace inciter {
      51                 :            : 
      52                 :            : extern ctr::InputDeck g_inputdeck;
      53                 :            : 
      54                 :            : namespace dg {
      55                 :            : 
      56                 :            : //! \brief MultiSpecies used polymorphically with tk::DGPDE
      57                 :            : //! \details The template arguments specify policies and are used to configure
      58                 :            : //!   the behavior of the class. The policies are:
      59                 :            : //!   - Physics - physics configuration, see PDE/MultiSpecies/Physics.h
      60                 :            : //!   - Problem - problem configuration, see PDE/MultiSpecies/Problem.h
      61                 :            : //! \note The default physics is Euler, which is set in
      62                 :            : //!   inciter::LuaParser::storeInputDeck()
      63                 :            : template< class Physics, class Problem >
      64                 :            : class MultiSpecies {
      65                 :            : 
      66                 :            :   private:
      67                 :            :     using eq = tag::multispecies;
      68                 :            : 
      69                 :            :   public:
      70                 :            :     //! Constructor
      71                 :         24 :     explicit MultiSpecies() :
      72                 :            :       m_physics(),
      73                 :            :       m_ncomp( g_inputdeck.get< tag::ncomp >() ),
      74                 :            :       m_nprim(nprim()),
      75         [ +  - ]:         24 :       m_riemann( multispeciesRiemannSolver( g_inputdeck.get< tag::flux >() ) )
      76                 :            :     {
      77                 :            :       // associate boundary condition configurations with state functions
      78 [ +  - ][ +  - ]:        360 :       brigand::for_each< ctr::bclist::Keys >( ConfigBC( m_bc,
         [ +  - ][ +  + ]
         [ +  - ][ +  + ]
         [ +  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
      79                 :            :         // BC State functions
      80                 :            :         { dirichlet
      81                 :            :         , symmetry
      82                 :            :         , invalidBC         // Outlet BC not implemented
      83                 :            :         , farfield
      84                 :            :         , extrapolate
      85                 :            :         , noslipwall 
      86                 :            :         , symmetry },       // Slip equivalent to symmetry without mesh motion
      87                 :            :         // BC Gradient functions
      88                 :            :         { noOpGrad
      89                 :            :         , symmetryGrad
      90                 :            :         , noOpGrad
      91                 :            :         , noOpGrad
      92                 :            :         , noOpGrad
      93                 :            :         , noOpGrad
      94                 :            :         , symmetryGrad }
      95                 :            :         ) );
      96                 :            : 
      97                 :            :       // EoS initialization
      98         [ +  - ]:         24 :       initializeSpeciesEoS( m_mat_blk );
      99                 :         24 :     }
     100                 :            : 
     101                 :            :     //! Find the number of primitive quantities required for this PDE system
     102                 :            :     //! \return The number of primitive quantities required to be stored for
     103                 :            :     //!   this PDE system
     104                 :            :     std::size_t nprim() const
     105                 :            :     {
     106                 :            :       // mixture temperature
     107                 :            :       std::size_t np(1);
     108                 :            : 
     109                 :            :       return np;
     110                 :            :     }
     111                 :            : 
     112                 :            :     //! Find the number of materials set up for this PDE system
     113                 :            :     //! \return The number of materials set up for this PDE system
     114                 :            :     std::size_t nmat() const { return 1; }
     115                 :            : 
     116                 :            :     //! Assign number of DOFs per equation in the PDE system
     117                 :            :     //! \param[in,out] numEqDof Array storing number of Dofs for each PDE
     118                 :            :     //!   equation
     119                 :            :     void numEquationDofs(std::vector< std::size_t >& numEqDof) const
     120                 :            :     {
     121                 :            :       // all equation-dofs initialized to ndofs
     122         [ +  + ]:        572 :       for (std::size_t i=0; i<m_ncomp; ++i) {
     123                 :        484 :         numEqDof.push_back(g_inputdeck.get< tag::ndof >());
     124                 :            :       }
     125                 :            :     }
     126                 :            : 
     127                 :            :     //! Determine elements that lie inside the user-defined IC box
     128                 :            :     //! \param[in] geoElem Element geometry array
     129                 :            :     //! \param[in] nielem Number of internal elements
     130                 :            :     //! \param[in,out] inbox List of nodes at which box user ICs are set for
     131                 :            :     //!    each IC box
     132                 :            :     void IcBoxElems( const tk::Fields& geoElem,
     133                 :            :       std::size_t nielem,
     134                 :            :       std::vector< std::unordered_set< std::size_t > >& inbox ) const
     135                 :            :     {
     136                 :         88 :       tk::BoxElems< eq >(geoElem, nielem, inbox);
     137                 :            :     }
     138                 :            : 
     139                 :            :     //! Find how many 'stiff equations' in this PDE system
     140                 :            :     //! \return number of stiff equations. Zero for now, but will need to change
     141                 :            :     //!   as chemical non-equilibrium is added
     142                 :            :     std::size_t nstiffeq() const
     143                 :            :     {
     144                 :            :       return 0;
     145                 :            :     }
     146                 :            : 
     147                 :            :     //! Find how many 'non-stiff equations' in this PDE system
     148                 :            :     //! \return number of non-stiff equations
     149                 :            :     std::size_t nnonstiffeq() const
     150                 :            :     {
     151                 :            :       return m_ncomp-nstiffeq();
     152                 :            :     }
     153                 :            : 
     154                 :            :     //! Locate the stiff equations.
     155                 :            :     //! \param[out] stiffEqIdx list with pointers to stiff equations. Empty
     156                 :            :     //!   for now but will have to index to chemical non-equilibrium when added
     157                 :            :     void setStiffEqIdx( std::vector< std::size_t >& stiffEqIdx ) const
     158                 :            :     {
     159                 :          0 :       stiffEqIdx.resize(0);
     160                 :            :     }
     161                 :            : 
     162                 :            :     //! Locate the nonstiff equations.
     163                 :            :     //! \param[out] nonStiffEqIdx list with pointers to nonstiff equations
     164                 :            :     void setNonStiffEqIdx( std::vector< std::size_t >& nonStiffEqIdx ) const
     165                 :            :     {
     166                 :          0 :       nonStiffEqIdx.resize(0);
     167                 :            :     }
     168                 :            : 
     169                 :            :     //! Initialize the compressible flow equations, prepare for time integration
     170                 :            :     //! \param[in] L Block diagonal mass matrix
     171                 :            :     //! \param[in] inpoel Element-node connectivity
     172                 :            :     //! \param[in] coord Array of nodal coordinates
     173                 :            :     //! \param[in] inbox List of elements at which box user ICs are set for
     174                 :            :     //!   each IC box
     175                 :            :     //! \param[in] elemblkid Element ids associated with mesh block ids where
     176                 :            :     //!   user ICs are set
     177                 :            :     //! \param[in,out] unk Array of unknowns
     178                 :            :     //! \param[in] t Physical time
     179                 :            :     //! \param[in] nielem Number of internal elements
     180         [ +  - ]:         88 :     void initialize( const tk::Fields& L,
     181                 :            :       const std::vector< std::size_t >& inpoel,
     182                 :            :       const tk::UnsMesh::Coords& coord,
     183                 :            :       const std::vector< std::unordered_set< std::size_t > >& inbox,
     184                 :            :       const std::unordered_map< std::size_t, std::set< std::size_t > >&
     185                 :            :         elemblkid,
     186                 :            :       tk::Fields& unk,
     187                 :            :       tk::real t,
     188                 :            :       const std::size_t nielem ) const
     189                 :            :     {
     190         [ +  - ]:         88 :       tk::initialize( m_ncomp, m_mat_blk, L, inpoel, coord,
     191                 :            :                       Problem::initialize, unk, t, nielem );
     192                 :            : 
     193                 :         88 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     194                 :            :       const auto& ic = g_inputdeck.get< tag::ic >();
     195                 :            :       const auto& icbox = ic.get< tag::box >();
     196                 :            :       const auto& icmbk = ic.get< tag::meshblock >();
     197                 :            : 
     198                 :            :       // Set initial conditions inside user-defined IC boxes and mesh blocks
     199                 :         88 :       std::vector< tk::real > s(m_ncomp, 0.0);
     200         [ +  + ]:       9184 :       for (std::size_t e=0; e<nielem; ++e) {
     201                 :            :         // inside user-defined box
     202         [ +  - ]:       9096 :         if (!icbox.empty()) {
     203                 :            :           std::size_t bcnt = 0;
     204         [ +  + ]:      18192 :           for (const auto& b : icbox) {   // for all boxes
     205 [ +  - ][ +  + ]:      18192 :             if (inbox.size() > bcnt && inbox[bcnt].find(e) != inbox[bcnt].end())
     206                 :            :             {
     207 [ +  - ][ -  - ]:       4548 :               std::vector< tk::real > box
     208                 :            :                 { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
     209                 :            :                   b.template get< tag::ymin >(), b.template get< tag::ymax >(),
     210                 :            :                   b.template get< tag::zmin >(), b.template get< tag::zmax >() };
     211                 :       4548 :               auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
     212         [ +  + ]:      29562 :               for (std::size_t c=0; c<m_ncomp; ++c) {
     213                 :      25014 :                 auto mark = c*rdof;
     214                 :      25014 :                 s[c] = unk(e,mark);
     215                 :            :                 // set high-order DOFs to zero
     216         [ +  + ]:     100056 :                 for (std::size_t i=1; i<rdof; ++i)
     217                 :      75042 :                   unk(e,mark+i) = 0.0;
     218                 :            :               }
     219         [ +  - ]:       4548 :               initializeBox<ctr::boxList>( m_mat_blk, V_ex, t, b, s );
     220                 :            :               // store box-initialization in solution vector
     221         [ +  + ]:      29562 :               for (std::size_t c=0; c<m_ncomp; ++c) {
     222                 :      25014 :                 auto mark = c*rdof;
     223                 :      25014 :                 unk(e,mark) = s[c];
     224                 :            :               }
     225                 :            :             }
     226                 :       9096 :             ++bcnt;
     227                 :            :           }
     228                 :            :         }
     229                 :            : 
     230                 :            :         // inside user-specified mesh blocks
     231         [ -  + ]:       9096 :         if (!icmbk.empty()) {
     232         [ -  - ]:          0 :           for (const auto& b : icmbk) { // for all blocks
     233                 :          0 :             auto blid = b.get< tag::blockid >();
     234                 :          0 :             auto V_ex = b.get< tag::volume >();
     235         [ -  - ]:          0 :             if (elemblkid.find(blid) != elemblkid.end()) {
     236                 :            :               const auto& elset = tk::cref_find(elemblkid, blid);
     237         [ -  - ]:          0 :               if (elset.find(e) != elset.end()) {
     238         [ -  - ]:          0 :                 initializeBox<ctr::meshblockList>( m_mat_blk, V_ex, t, b, s );
     239                 :            :                 // store initialization in solution vector
     240         [ -  - ]:          0 :                 for (std::size_t c=0; c<m_ncomp; ++c) {
     241                 :          0 :                   auto mark = c*rdof;
     242                 :          0 :                   unk(e,mark) = s[c];
     243                 :            :                 }
     244                 :            :               }
     245                 :            :             }
     246                 :            :           }
     247                 :            :         }
     248                 :            :       }
     249                 :         88 :     }
     250                 :            : 
     251                 :            :     //! Compute density constraint for a given material. No-op
     252                 :            :     // //! \param[in] nelem Number of elements
     253                 :            :     // //! \param[in] unk Array of unknowns
     254                 :            :     //! \param[out] densityConstr Density Constraint: rho/(rho0*det(g))
     255                 :            :     void computeDensityConstr( std::size_t /*nelem*/,
     256                 :            :                                tk::Fields& /*unk*/,
     257                 :            :                                std::vector< tk::real >& densityConstr) const
     258                 :            :     {
     259                 :        176 :       densityConstr.resize(0);
     260                 :            :     }
     261                 :            : 
     262                 :            :     //! Compute the left hand side block-diagonal mass matrix
     263                 :            :     //! \param[in] geoElem Element geometry array
     264                 :            :     //! \param[in,out] l Block diagonal mass matrix
     265                 :            :     void lhs( const tk::Fields& geoElem, tk::Fields& l ) const {
     266                 :         88 :       const auto ndof = g_inputdeck.get< tag::ndof >();
     267                 :         88 :       tk::mass( m_ncomp, ndof, geoElem, l );
     268                 :            :     }
     269                 :            : 
     270                 :            :     //! Update the interface cells to first order dofs. No-op.
     271                 :            :     // //! \param[in] unk Array of unknowns
     272                 :            :     // //! \param[in] nielem Number of internal elements
     273                 :            :     // //! \param[in,out] ndofel Array of dofs
     274                 :            :     // //! \param[in,out] interface Vector of interface marker
     275                 :            :     void updateInterfaceCells( tk::Fields& /*unk*/,
     276                 :            :       std::size_t /*nielem*/,
     277                 :            :       std::vector< std::size_t >& /*ndofel*/,
     278                 :            :       std::vector< std::size_t >& /*interface*/ ) const {}
     279                 :            : 
     280                 :            :     //! Update the primitives for this PDE system.
     281                 :            :     //! \param[in] unk Array of unknowns
     282                 :            :     //! \param[in] L The left hand side block-diagonal mass matrix
     283                 :            :     //! \param[in] geoElem Element geometry array
     284                 :            :     //! \param[in,out] prim Array of primitives
     285                 :            :     //! \param[in] nielem Number of internal elements
     286                 :            :     //! \param[in] ndofel Array of dofs
     287                 :            :     //! \details This function computes and stores the dofs for primitive
     288                 :            :     //!   quantities, which are required for obtaining reconstructed states used
     289                 :            :     //!   in the Riemann solver. See for eg. /PDE/Riemann/AUSMMultiSpecies.hpp,
     290                 :            :     //!   where temperature is independently reconstructed.
     291                 :       6688 :     void updatePrimitives( const tk::Fields& unk,
     292                 :            :                            const tk::Fields& L,
     293                 :            :                            const tk::Fields& geoElem,
     294                 :            :                            tk::Fields& prim,
     295                 :            :                            std::size_t nielem,
     296                 :            :                            const std::vector< std::size_t >& ndofel ) const
     297                 :            :     {
     298                 :       6688 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     299                 :       6688 :       const auto ndof = g_inputdeck.get< tag::ndof >();
     300                 :       6688 :       auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
     301                 :            : 
     302                 :            :       Assert( unk.nunk() == prim.nunk(), "Number of unknowns in solution "
     303                 :            :               "vector and primitive vector at recent time step incorrect" );
     304                 :            :       Assert( unk.nprop() == rdof*m_ncomp, "Number of components in solution "
     305                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     306                 :            :       Assert( prim.nprop() == rdof*m_nprim, "Number of components in vector of "
     307                 :            :               "primitive quantities must equal "+ std::to_string(rdof*m_nprim) );
     308                 :            : 
     309         [ +  + ]:     697984 :       for (std::size_t e=0; e<nielem; ++e)
     310                 :            :       {
     311                 :     691296 :         std::vector< tk::real > R(m_nprim*ndof, 0.0);
     312                 :            : 
     313         [ +  - ]:     691296 :         auto ng = tk::NGvol(ndof);
     314                 :            : 
     315                 :            :         // arrays for quadrature points
     316                 :            :         std::array< std::vector< tk::real >, 3 > coordgp;
     317                 :            :         std::vector< tk::real > wgp;
     318                 :            : 
     319         [ +  - ]:     691296 :         coordgp[0].resize( ng );
     320         [ +  - ]:     691296 :         coordgp[1].resize( ng );
     321         [ +  - ]:     691296 :         coordgp[2].resize( ng );
     322         [ +  - ]:     691296 :         wgp.resize( ng );
     323                 :            : 
     324         [ +  - ]:     691296 :         tk::GaussQuadratureTet( ng, coordgp, wgp );
     325                 :            : 
     326                 :            :         // Local degree of freedom
     327                 :     691296 :         auto dof_el = ndofel[e];
     328                 :            : 
     329                 :            :         // Loop over quadrature points in element e
     330         [ +  + ]:    1382592 :         for (std::size_t igp=0; igp<ng; ++igp)
     331                 :            :         {
     332                 :            :           // Compute the basis function
     333         [ +  - ]:     691296 :           auto B = tk::eval_basis( dof_el, coordgp[0][igp], coordgp[1][igp],
     334                 :            :             coordgp[2][igp] );
     335                 :            : 
     336         [ +  - ]:     691296 :           auto w = wgp[igp] * geoElem(e, 0);
     337                 :            : 
     338         [ +  - ]:     691296 :           auto state = tk::eval_state( m_ncomp, rdof, dof_el, e, unk, B );
     339                 :            : 
     340                 :            :           // Mixture state at quadrature point
     341         [ +  - ]:     691296 :           Mixture mixgp(nspec, state, m_mat_blk);
     342                 :            : 
     343                 :            :           // Mixture density at quadrature point
     344                 :     691296 :           tk::real rhob = mixgp.get_mix_density();
     345                 :            : 
     346                 :            :           // velocity vector at quadrature point
     347                 :            :           std::array< tk::real, 3 >
     348         [ +  - ]:     691296 :             vel{ state[multispecies::momentumIdx(nspec, 0)]/rhob,
     349                 :     691296 :                  state[multispecies::momentumIdx(nspec, 1)]/rhob,
     350                 :     691296 :                  state[multispecies::momentumIdx(nspec, 2)]/rhob };
     351                 :            : 
     352 [ +  - ][ +  - ]:     691296 :           std::vector< tk::real > pri(m_nprim, 0.0);
                 [ -  - ]
     353                 :            : 
     354                 :            :           // Evaluate mixture temperature at quadrature point
     355         [ +  - ]:     691296 :           auto rhoE0 = state[multispecies::energyIdx(nspec, 0)];
     356                 :     691296 :           pri[multispecies::temperatureIdx(nspec,0)] =
     357         [ +  - ]:     691296 :             mixgp.temperature(rhob, vel[0], vel[1], vel[2], rhoE0, m_mat_blk);
     358                 :            :           // TODO: consider clipping temperature here
     359                 :            : 
     360         [ +  + ]:    1382592 :           for(std::size_t k = 0; k < m_nprim; k++)
     361                 :            :           {
     362                 :     691296 :             auto mark = k * ndof;
     363         [ +  + ]:    1382592 :             for(std::size_t idof = 0; idof < dof_el; idof++)
     364                 :     691296 :               R[mark+idof] += w * pri[k] * B[idof];
     365                 :            :           }
     366                 :            :         }
     367                 :            : 
     368                 :            :         // Update the DG solution of primitive variables
     369         [ +  + ]:    1382592 :         for(std::size_t k = 0; k < m_nprim; k++)
     370                 :            :         {
     371                 :     691296 :           auto mark = k * ndof;
     372                 :     691296 :           auto rmark = k * rdof;
     373         [ +  + ]:    1382592 :           for(std::size_t idof = 0; idof < dof_el; idof++)
     374                 :            :           {
     375                 :     691296 :             prim(e, rmark+idof) = R[mark+idof] / L(e, mark+idof);
     376                 :            :           }
     377                 :            :         }
     378                 :            :       }
     379                 :       6688 :     }
     380                 :            : 
     381                 :            :     //! Clean up the state of trace materials for this PDE system. No-op.
     382                 :            :     // //! \param[in] t Physical time
     383                 :            :     // //! \param[in] geoElem Element geometry array
     384                 :            :     // //! \param[in,out] unk Array of unknowns
     385                 :            :     // //! \param[in,out] prim Array of primitives
     386                 :            :     // //! \param[in] nielem Number of internal elements
     387                 :            :     void cleanTraceMaterial( tk::real /*t*/,
     388                 :            :                              const tk::Fields& /*geoElem*/,
     389                 :            :                              tk::Fields& /*unk*/,
     390                 :            :                              tk::Fields& /*prim*/,
     391                 :            :                              std::size_t /*nielem*/ ) const {}
     392                 :            : 
     393                 :            :     //! Reconstruct second-order solution from first-order
     394                 :            :     //! \param[in] geoElem Element geometry array
     395                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     396                 :            :     //! \param[in] esup Elements-surrounding-nodes connectivity
     397                 :            :     //! \param[in] inpoel Element-node connectivity
     398                 :            :     //! \param[in] coord Array of nodal coordinates
     399                 :            :     //! \param[in,out] U Solution vector at recent time step
     400                 :            :     //! \param[in,out] P Vector of primitives at recent time step
     401                 :            :     //! \param[in] pref Indicator for p-adaptive algorithm
     402                 :            :     //! \param[in] ndofel Vector of local number of degrees of freedome
     403                 :       6600 :     void reconstruct( tk::real,
     404                 :            :                       const tk::Fields&,
     405                 :            :                       const tk::Fields& geoElem,
     406                 :            :                       const inciter::FaceData& fd,
     407                 :            :                       const std::map< std::size_t, std::vector< std::size_t > >&
     408                 :            :                         esup,
     409                 :            :                       const std::vector< std::size_t >& inpoel,
     410                 :            :                       const tk::UnsMesh::Coords& coord,
     411                 :            :                       tk::Fields& U,
     412                 :            :                       tk::Fields& P,
     413                 :            :                       const bool pref,
     414                 :            :                       const std::vector< std::size_t >& ndofel ) const
     415                 :            :     {
     416                 :       6600 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     417                 :       6600 :       const auto ndof = g_inputdeck.get< tag::ndof >();
     418                 :            : 
     419                 :            :       bool is_p0p1(false);
     420         [ +  - ]:       6600 :       if (rdof == 4 && ndof == 1)
     421                 :            :         is_p0p1 = true;
     422                 :            : 
     423                 :       6600 :       const auto nelem = fd.Esuel().size()/4;
     424                 :            : 
     425                 :            :       Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
     426                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     427                 :            :       Assert( P.nprop() == rdof*m_nprim, "Number of components in primitive "
     428                 :            :               "vector must equal "+ std::to_string(rdof*m_nprim) );
     429                 :            : 
     430                 :            :       //----- reconstruction of conserved quantities -----
     431                 :            :       //--------------------------------------------------
     432                 :            : 
     433         [ +  + ]:     688800 :       for (std::size_t e=0; e<nelem; ++e)
     434                 :            :       {
     435                 :            :         std::vector< std::size_t > vars;
     436                 :            :         // check if element is marked as p0p1
     437 [ -  + ][ -  - ]:     682200 :         if ( (pref && ndofel[e] == 1) || is_p0p1 ) {
                 [ +  - ]
     438                 :            :           // 1. specify how many variables need to be reconstructed
     439 [ +  + ][ +  - ]:    4434300 :           for (std::size_t c=0; c<m_ncomp; ++c) vars.push_back(c);
     440                 :            : 
     441                 :            :           // 2. solve 3x3 least-squares system
     442                 :            :           // Reconstruct second-order dofs in Taylor space using nodal-stencils
     443         [ +  - ]:     682200 :           tk::recoLeastSqExtStencil( rdof, e, esup, inpoel, geoElem, U, vars );
     444                 :            : 
     445                 :            :           // 3. transform reconstructed derivatives to Dubiner dofs
     446         [ +  - ]:     682200 :           tk::transform_P0P1( rdof, e, inpoel, coord, U, vars );
     447                 :            :         }
     448                 :            :       }
     449                 :            : 
     450                 :            :       //----- reconstruction of primitive quantities -----
     451                 :            :       //--------------------------------------------------
     452                 :            :       // For multispecies, conserved and primitive quantities are reconstructed
     453                 :            :       // separately.
     454                 :            : 
     455         [ +  + ]:     688800 :       for (std::size_t e=0; e<nelem; ++e)
     456                 :            :       {
     457                 :            :         // There are two conditions that requires the reconstruction of the
     458                 :            :         // primitive variables:
     459                 :            :         //   1. p-adaptive is triggered and P0P1 scheme is applied to specific
     460                 :            :         //      elements
     461                 :            :         //   2. p-adaptive is not triggered and P0P1 scheme is applied to the
     462                 :            :         //      whole computation domain
     463 [ -  + ][ -  - ]:     682200 :         if ((pref && ndofel[e] == 1) || (!pref && is_p0p1)) {
                 [ +  - ]
     464                 :            :           std::vector< std::size_t > vars;
     465 [ +  + ][ +  - ]:    1364400 :           for (std::size_t c=0; c<m_nprim; ++c) vars.push_back(c);
     466                 :            : 
     467                 :            :           // 1.
     468                 :            :           // Reconstruct second-order dofs in Taylor space using nodal-stencils
     469         [ +  - ]:     682200 :           tk::recoLeastSqExtStencil( rdof, e, esup, inpoel, geoElem, P, vars );
     470                 :            : 
     471                 :            :           // 2.
     472         [ +  - ]:     682200 :           tk::transform_P0P1(rdof, e, inpoel, coord, P, vars);
     473                 :            :         }
     474                 :            :       }
     475                 :       6600 :     }
     476                 :            : 
     477                 :            :     //! Limit second-order solution, and primitive quantities separately
     478                 :            :     // //! \param[in] pref Indicator for p-adaptive algorithm
     479                 :            :     //! \param[in] geoFace Face geometry array
     480                 :            :     //! \param[in] geoElem Element geometry array
     481                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     482                 :            :     //! \param[in] esup Elements-surrounding-nodes connectivity
     483                 :            :     //! \param[in] inpoel Element-node connectivity
     484                 :            :     //! \param[in] coord Array of nodal coordinates
     485                 :            :     //! \param[in] ndofel Vector of local number of degrees of freedome
     486                 :            :     // //! \param[in] gid Local->global node id map
     487                 :            :     // //! \param[in] bid Local chare-boundary node ids (value) associated to
     488                 :            :     // //!   global node ids (key)
     489                 :            :     // //! \param[in] uNodalExtrm Chare-boundary nodal extrema for conservative
     490                 :            :     // //!   variables
     491                 :            :     // //! \param[in] pNodalExtrm Chare-boundary nodal extrema for primitive
     492                 :            :     // //!   variables
     493                 :            :     // //! \param[in] mtInv Inverse of Taylor mass matrix
     494                 :            :     //! \param[in,out] U Solution vector at recent time step
     495                 :            :     //! \param[in,out] P Vector of primitives at recent time step
     496                 :            :     //! \param[in,out] shockmarker Vector of shock-marker values
     497                 :       6600 :     void limit( [[maybe_unused]] tk::real,
     498                 :            :                 const bool /*pref*/,
     499                 :            :                 const tk::Fields& geoFace,
     500                 :            :                 const tk::Fields& geoElem,
     501                 :            :                 const inciter::FaceData& fd,
     502                 :            :                 const std::map< std::size_t, std::vector< std::size_t > >& esup,
     503                 :            :                 const std::vector< std::size_t >& inpoel,
     504                 :            :                 const tk::UnsMesh::Coords& coord,
     505                 :            :                 const std::vector< std::size_t >& ndofel,
     506                 :            :                 const std::vector< std::size_t >& /*gid*/,
     507                 :            :                 const std::unordered_map< std::size_t, std::size_t >& /*bid*/,
     508                 :            :                 const std::vector< std::vector<tk::real> >& /*uNodalExtrm*/,
     509                 :            :                 const std::vector< std::vector<tk::real> >& /*pNodalExtrm*/,
     510                 :            :                 const std::vector< std::vector<tk::real> >& /*mtInv*/,
     511                 :            :                 tk::Fields& U,
     512                 :            :                 tk::Fields& P,
     513                 :            :                 std::vector< std::size_t >& shockmarker ) const
     514                 :            :     {
     515                 :       6600 :       const auto limiter = g_inputdeck.get< tag::limiter >();
     516                 :       6600 :       auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
     517                 :       6600 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     518                 :            :       const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
     519                 :            : 
     520                 :            :       // limit vectors of conserved and primitive quantities
     521         [ +  - ]:       6600 :       if (limiter == ctr::LimiterType::VERTEXBASEDP1 && rdof == 4)
     522                 :            :       {
     523                 :       6600 :         VertexBasedMultiSpecies_P1( esup, inpoel, ndofel, fd.Esuel().size()/4,
     524         [ +  - ]:       6600 :           m_mat_blk, fd, geoFace, geoElem, coord, flux, solidx, U, P, nspec,
     525                 :            :           shockmarker );
     526                 :            :       }
     527         [ -  - ]:          0 :       else if (limiter == ctr::LimiterType::VERTEXBASEDP1 && rdof == 10)
     528                 :            :       {
     529                 :          0 :         VertexBasedMultiSpecies_P2( esup, inpoel, ndofel, fd.Esuel().size()/4,
     530         [ -  - ]:          0 :           m_mat_blk, fd, geoFace, geoElem, coord, flux, solidx, U, P, nspec,
     531                 :            :           shockmarker );
     532                 :            :       }
     533         [ -  - ]:          0 :       else if (limiter != ctr::LimiterType::NOLIMITER)
     534                 :            :       {
     535 [ -  - ][ -  - ]:          0 :         Throw("Limiter type not configured for multispecies.");
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     536                 :            :       }
     537                 :       6600 :     }
     538                 :            : 
     539                 :            :     //! Apply CPL to the conservative variable solution for this PDE system
     540                 :            :     //! \param[in] prim Array of primitive variables
     541                 :            :     //! \param[in] geoElem Element geometry array
     542                 :            :     //! \param[in] inpoel Element-node connectivity
     543                 :            :     //! \param[in] coord Array of nodal coordinates
     544                 :            :     //! \param[in,out] unk Array of conservative variables
     545                 :            :     //! \param[in] nielem Number of internal elements
     546                 :            :     //! \details This function applies CPL to obtain consistent dofs for
     547                 :            :     //!   conservative quantities based on the limited primitive quantities.
     548                 :            :     //!   See appendix of paper: Pandare et al. (2023). On the Design of Stable,
     549                 :            :     //!   Consistent, and Conservative High-Order Methods for Multi-Material
     550                 :            :     //!   Hydrodynamics. J Comp Phys, 112313.
     551                 :            :     void CPL( const tk::Fields& prim,
     552                 :            :       const tk::Fields& geoElem,
     553                 :            :       const std::vector< std::size_t >& inpoel,
     554                 :            :       const tk::UnsMesh::Coords& coord,
     555                 :            :       tk::Fields& unk,
     556                 :            :       std::size_t nielem ) const
     557                 :            :     {
     558                 :            :       [[maybe_unused]] const auto rdof = g_inputdeck.get< tag::rdof >();
     559                 :       6600 :       auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
     560                 :            : 
     561                 :            :       Assert( unk.nunk() == prim.nunk(), "Number of unknowns in solution "
     562                 :            :               "vector and primitive vector at recent time step incorrect" );
     563                 :            :       Assert( unk.nprop() == rdof*m_ncomp, "Number of components in solution "
     564                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     565                 :            :       Assert( prim.nprop() == rdof*m_nprim, "Number of components in vector of "
     566                 :            :               "primitive quantities must equal "+ std::to_string(rdof*m_nprim) );
     567                 :            : 
     568                 :       6600 :       correctLimConservMultiSpecies(nielem, m_mat_blk, nspec, inpoel,
     569                 :            :         coord, geoElem, prim, unk);
     570                 :            :     }
     571                 :            : 
     572                 :            :     //! Return cell-average deformation gradient tensor. No-op.
     573                 :            :     std::array< std::vector< tk::real >, 9 > cellAvgDeformGrad(
     574                 :            :       const tk::Fields&,
     575                 :            :       std::size_t ) const
     576                 :            :     { return {}; }
     577                 :            : 
     578                 :            :     //! Reset the high order solution for p-adaptive scheme
     579                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     580                 :            :     //! \param[in,out] unk Solution vector at recent time step
     581                 :            :     //! \param[in,out] prim Primitive vector at recent time step
     582                 :            :     //! \param[in] ndofel Vector of local number of degrees of freedome
     583                 :            :     //! \details This function reset the high order coefficient for p-adaptive
     584                 :            :     //!   solution polynomials. Unlike compflow class, the high order of fv
     585                 :            :     //!   solution will not be reset since p0p1 is the base scheme for
     586                 :            :     //!   multi-species p-adaptive DG method.
     587                 :          0 :     void resetAdapSol( const inciter::FaceData& fd,
     588                 :            :                        tk::Fields& unk,
     589                 :            :                        tk::Fields& prim,
     590                 :            :                        const std::vector< std::size_t >& ndofel ) const
     591                 :            :     {
     592                 :          0 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     593                 :          0 :       const auto ncomp = unk.nprop() / rdof;
     594                 :          0 :       const auto nprim = prim.nprop() / rdof;
     595                 :            : 
     596         [ -  - ]:          0 :       for(std::size_t e = 0; e < fd.Esuel().size()/4; e++)
     597                 :            :       {
     598         [ -  - ]:          0 :         if(ndofel[e] < 10)
     599                 :            :         {
     600         [ -  - ]:          0 :           for (std::size_t c=0; c<ncomp; ++c)
     601                 :            :           {
     602                 :          0 :             auto mark = c*rdof;
     603                 :          0 :             unk(e, mark+4) = 0.0;
     604                 :          0 :             unk(e, mark+5) = 0.0;
     605                 :          0 :             unk(e, mark+6) = 0.0;
     606                 :          0 :             unk(e, mark+7) = 0.0;
     607                 :          0 :             unk(e, mark+8) = 0.0;
     608                 :          0 :             unk(e, mark+9) = 0.0;
     609                 :            :           }
     610         [ -  - ]:          0 :           for (std::size_t c=0; c<nprim; ++c)
     611                 :            :           {
     612                 :          0 :             auto mark = c*rdof;
     613                 :          0 :             prim(e, mark+4) = 0.0;
     614                 :          0 :             prim(e, mark+5) = 0.0;
     615                 :          0 :             prim(e, mark+6) = 0.0;
     616                 :          0 :             prim(e, mark+7) = 0.0;
     617                 :          0 :             prim(e, mark+8) = 0.0;
     618                 :          0 :             prim(e, mark+9) = 0.0;
     619                 :            :           }
     620                 :            :         }
     621                 :            :       }
     622                 :          0 :     }
     623                 :            : 
     624                 :            :     //! Compute right hand side
     625                 :            :     //! \param[in] t Physical time
     626                 :            :     //! \param[in] pref Indicator for p-adaptive algorithm
     627                 :            :     //! \param[in] geoFace Face geometry array
     628                 :            :     //! \param[in] geoElem Element geometry array
     629                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     630                 :            :     //! \param[in] inpoel Element-node connectivity
     631                 :            :     //! \param[in] coord Array of nodal coordinates
     632                 :            :     //! \param[in] U Solution vector at recent time step
     633                 :            :     //! \param[in] P Primitive vector at recent time step
     634                 :            :     //! \param[in] ndofel Vector of local number of degrees of freedom
     635                 :            :     //! \param[in] dt Delta time
     636                 :            :     //! \param[in,out] R Right-hand side vector computed
     637                 :       6600 :     void rhs( tk::real t,
     638                 :            :               const bool pref,
     639                 :            :               const tk::Fields& geoFace,
     640                 :            :               const tk::Fields& geoElem,
     641                 :            :               const inciter::FaceData& fd,
     642                 :            :               const std::vector< std::size_t >& inpoel,
     643                 :            :               const std::vector< std::unordered_set< std::size_t > >&,
     644                 :            :               const tk::UnsMesh::Coords& coord,
     645                 :            :               const tk::Fields& U,
     646                 :            :               const tk::Fields& P,
     647                 :            :               const std::vector< std::size_t >& ndofel,
     648                 :            :               const tk::real dt,
     649                 :            :               tk::Fields& R ) const
     650                 :            :     {
     651                 :       6600 :       const auto ndof = g_inputdeck.get< tag::ndof >();
     652                 :       6600 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     653                 :            :       const auto& solidx = g_inputdeck.get< tag::matidxmap, tag::solidx >();
     654                 :            : 
     655                 :       6600 :       const auto nelem = fd.Esuel().size()/4;
     656                 :            : 
     657                 :            :       Assert( U.nunk() == P.nunk(), "Number of unknowns in solution "
     658                 :            :               "vector and primitive vector at recent time step incorrect" );
     659                 :            :       Assert( U.nunk() == R.nunk(), "Number of unknowns in solution "
     660                 :            :               "vector and right-hand side at recent time step incorrect" );
     661                 :            :       Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
     662                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     663                 :            :       Assert( P.nprop() == rdof*m_nprim, "Number of components in primitive "
     664                 :            :               "vector must equal "+ std::to_string(rdof*m_nprim) );
     665                 :            :       Assert( R.nprop() == ndof*m_ncomp, "Number of components in right-hand "
     666                 :            :               "side vector must equal "+ std::to_string(ndof*m_ncomp) );
     667                 :            :       Assert( fd.Inpofa().size()/3 == fd.Esuf().size()/2,
     668                 :            :               "Mismatch in inpofa size" );
     669                 :            : 
     670                 :            :       // set rhs to zero
     671                 :            :       R.fill(0.0);
     672                 :            : 
     673                 :            :       // empty vector for non-conservative terms. This vector is unused for
     674                 :            :       // multi-species flow since, there are no non-conservative terms
     675                 :            :       // in the system of PDEs.
     676                 :       6600 :       std::vector< std::vector< tk::real > > riemannDeriv;
     677                 :            : 
     678                 :       6600 :       std::vector< std::vector< tk::real > > vriem;
     679                 :       6600 :       std::vector< std::vector< tk::real > > riemannLoc;
     680                 :            : 
     681                 :            :       // configure a no-op lambda for prescribed velocity
     682                 :            :       auto velfn = []( ncomp_t, tk::real, tk::real, tk::real, tk::real ){
     683                 :            :         return tk::VelFn::result_type(); };
     684                 :            : 
     685                 :            :       // compute internal surface flux integrals
     686         [ +  - ]:       6600 :       tk::surfInt( pref, 1, m_mat_blk, t, ndof, rdof, inpoel, solidx,
     687         [ +  - ]:       6600 :                    coord, fd, geoFace, geoElem, m_riemann, velfn, U, P, ndofel,
     688                 :            :                    dt, R, riemannDeriv );
     689                 :            : 
     690                 :            :       // compute optional source term
     691         [ +  - ]:       6600 :       tk::srcInt( m_mat_blk, t, ndof, fd.Esuel().size()/4, inpoel,
     692                 :            :                   coord, geoElem, Problem::src, ndofel, R );
     693                 :            : 
     694         [ -  + ]:       6600 :       if(ndof > 1)
     695                 :            :         // compute volume integrals
     696 [ -  - ][ -  - ]:          0 :         tk::volInt( 1, t, m_mat_blk, ndof, rdof, nelem, inpoel, coord, geoElem,
                 [ -  - ]
     697                 :            :           flux, velfn, U, P, ndofel, R );
     698                 :            : 
     699                 :            :       // compute boundary surface flux integrals
     700         [ +  + ]:      52800 :       for (const auto& b : m_bc)
     701         [ +  - ]:      92400 :         tk::bndSurfInt( pref, 1, m_mat_blk, ndof, rdof, std::get<0>(b), fd,
     702                 :            :                         geoFace, geoElem, inpoel, coord, t, m_riemann, velfn,
     703                 :            :                         std::get<1>(b), U, P, ndofel, R, riemannDeriv );
     704                 :            : 
     705                 :            :       // compute external (energy) sources
     706                 :            :       //m_physics.physSrc(nspec, t, geoElem, {}, R, {});
     707                 :       6600 :     }
     708                 :            : 
     709                 :            :     //! Evaluate the adaptive indicator and mark the ndof for each element
     710                 :            :     //! \param[in] nunk Number of unknowns
     711                 :            :     //! \param[in] coord Array of nodal coordinates
     712                 :            :     //! \param[in] inpoel Element-node connectivity
     713                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     714                 :            :     //! \param[in] unk Array of unknowns
     715                 :            :     // //! \param[in] prim Array of primitive quantities
     716                 :            :     //! \param[in] indicator p-refinement indicator type
     717                 :            :     //! \param[in] ndof Number of degrees of freedom in the solution
     718                 :            :     //! \param[in] ndofmax Max number of degrees of freedom for p-refinement
     719                 :            :     //! \param[in] tolref Tolerance for p-refinement
     720                 :            :     //! \param[in,out] ndofel Vector of local number of degrees of freedome
     721         [ -  - ]:          0 :     void eval_ndof( std::size_t nunk,
     722                 :            :                     [[maybe_unused]] const tk::UnsMesh::Coords& coord,
     723                 :            :                     [[maybe_unused]] const std::vector< std::size_t >& inpoel,
     724                 :            :                     const inciter::FaceData& fd,
     725                 :            :                     const tk::Fields& unk,
     726                 :            :                     const tk::Fields& /*prim*/,
     727                 :            :                     inciter::ctr::PrefIndicatorType indicator,
     728                 :            :                     std::size_t ndof,
     729                 :            :                     std::size_t ndofmax,
     730                 :            :                     tk::real tolref,
     731                 :            :                     std::vector< std::size_t >& ndofel ) const
     732                 :            :     {
     733                 :            :       const auto& esuel = fd.Esuel();
     734                 :            : 
     735         [ -  - ]:          0 :       if(indicator == inciter::ctr::PrefIndicatorType::SPECTRAL_DECAY)
     736                 :          0 :         spectral_decay(1, nunk, esuel, unk, ndof, ndofmax, tolref, ndofel);
     737                 :            :       else
     738 [ -  - ][ -  - ]:          0 :         Throw( "No such adaptive indicator type" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     739                 :          0 :     }
     740                 :            : 
     741                 :            :     //! Compute the minimum time step size
     742                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     743                 :            :     //! \param[in] geoFace Face geometry array
     744                 :            :     //! \param[in] geoElem Element geometry array
     745                 :            : //    //! \param[in] ndofel Vector of local number of degrees of freedom
     746                 :            :     //! \param[in] U Solution vector at recent time step
     747                 :            :     //! \param[in] P Vector of primitive quantities at recent time step
     748                 :            :     //! \param[in] nielem Number of internal elements
     749                 :            :     //! \return Minimum time step size
     750                 :            :     //! \details The allowable dt is calculated by looking at the maximum
     751                 :            :     //!   wave-speed in elements surrounding each face, times the area of that
     752                 :            :     //!   face. Once the maximum of this quantity over the mesh is determined,
     753                 :            :     //!   the volume of each cell is divided by this quantity. A minimum of this
     754                 :            :     //!   ratio is found over the entire mesh, which gives the allowable dt.
     755                 :            :     tk::real dt( const std::array< std::vector< tk::real >, 3 >&,
     756                 :            :                  const std::vector< std::size_t >&,
     757                 :            :                  const inciter::FaceData& fd,
     758                 :            :                  const tk::Fields& geoFace,
     759                 :            :                  const tk::Fields& geoElem,
     760                 :            :                  const std::vector< std::size_t >& /*ndofel*/,
     761                 :            :                  const tk::Fields& U,
     762                 :            :                  const tk::Fields& P,
     763                 :            :                  const std::size_t nielem ) const
     764                 :            :     {
     765                 :            :       const auto ndof = g_inputdeck.get< tag::ndof >();
     766                 :            :       auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
     767                 :            : 
     768                 :            :       auto mindt = timeStepSizeMultiSpecies( m_mat_blk, fd.Esuf(), geoFace,
     769                 :            :         geoElem, nielem, nspec, U, P);
     770                 :            : 
     771                 :            :       //if (viscous)
     772                 :            :       //  mindt = std::min(mindt, timeStepSizeViscousFV(geoElem, nielem, nspec, U));
     773                 :            :       //mindt = std::min(mindt, m_physics.dtRestriction(geoElem, nielem, {}));
     774                 :            : 
     775                 :            :       tk::real dgp = 0.0;
     776                 :            :       if (ndof == 4)
     777                 :            :       {
     778                 :            :         dgp = 1.0;
     779                 :            :       }
     780                 :            :       else if (ndof == 10)
     781                 :            :       {
     782                 :            :         dgp = 2.0;
     783                 :            :       }
     784                 :            : 
     785                 :            :       // Scale smallest dt with CFL coefficient and the CFL is scaled by (2*p+1)
     786                 :            :       // where p is the order of the DG polynomial by linear stability theory.
     787                 :            :       mindt /= (2.0*dgp + 1.0);
     788                 :            :       return mindt;
     789                 :            :     }
     790                 :            : 
     791                 :            :     //! Compute stiff terms for a single element. No-op until chem sources added
     792                 :            :     // //! \param[in] e Element number
     793                 :            :     // //! \param[in] geoElem Element geometry array
     794                 :            :     // //! \param[in] inpoel Element-node connectivity
     795                 :            :     // //! \param[in] coord Array of nodal coordinates
     796                 :            :     // //! \param[in] U Solution vector at recent time step
     797                 :            :     // //! \param[in] P Primitive vector at recent time step
     798                 :            :     // //! \param[in] ndofel Vector of local number of degrees of freedom
     799                 :            :     // //! \param[in,out] R Right-hand side vector computed
     800                 :            :     void stiff_rhs( std::size_t /*e*/,
     801                 :            :                     const tk::Fields& /*geoElem*/,
     802                 :            :                     const std::vector< std::size_t >& /*inpoel*/,
     803                 :            :                     const tk::UnsMesh::Coords& /*coord*/,
     804                 :            :                     const tk::Fields& /*U*/,
     805                 :            :                     const tk::Fields& /*P*/,
     806                 :            :                     const std::vector< std::size_t >& /*ndofel*/,
     807                 :            :                     tk::Fields& /*R*/ ) const {}
     808                 :            : 
     809                 :            :     //! Extract the velocity field at cell nodes. Currently unused.
     810                 :            :     // //! \param[in] U Solution vector at recent time step
     811                 :            :     // //! \param[in] N Element node indices
     812                 :            :     //! \return Array of the four values of the velocity field
     813                 :            :     std::array< std::array< tk::real, 4 >, 3 >
     814                 :            :     velocity( const tk::Fields& /*U*/,
     815                 :            :               const std::array< std::vector< tk::real >, 3 >&,
     816                 :            :               const std::array< std::size_t, 4 >& /*N*/ ) const
     817                 :            :     {
     818                 :            :       std::array< std::array< tk::real, 4 >, 3 > v;
     819                 :            :       return v;
     820                 :            :     }
     821                 :            : 
     822                 :            :     //! Return a map that associates user-specified strings to functions
     823                 :            :     //! \return Map that associates user-specified strings to functions that
     824                 :            :     //!   compute relevant quantities to be output to file
     825                 :            :     std::map< std::string, tk::GetVarFn > OutVarFn() const
     826                 :        352 :     { return MultiSpeciesOutVarFn(); }
     827                 :            : 
     828                 :            :     //! Return analytic field names to be output to file
     829                 :            :     //! \return Vector of strings labelling analytic fields output in file
     830                 :            :     std::vector< std::string > analyticFieldNames() const {
     831                 :          0 :       auto nspec = g_inputdeck.get< eq, tag::nspec >();
     832                 :            : 
     833                 :          0 :       return MultiSpeciesFieldNames(nspec);
     834                 :            :     }
     835                 :            : 
     836                 :            :     //! Return time history field names to be output to file
     837                 :            :     //! \return Vector of strings labelling time history fields output in file
     838                 :            :     std::vector< std::string > histNames() const {
     839                 :          0 :       return MultiSpeciesHistNames();
     840                 :            :     }
     841                 :            : 
     842                 :            :     //! Return surface field output going to file
     843                 :            :     std::vector< std::vector< tk::real > >
     844                 :            :     surfOutput( const std::map< int, std::vector< std::size_t > >&,
     845                 :            :                 tk::Fields& ) const
     846                 :            :     {
     847                 :            :       std::vector< std::vector< tk::real > > s; // punt for now
     848                 :            :       return s;
     849                 :            :     }
     850                 :            : 
     851                 :            :     //! Return time history field output evaluated at time history points
     852                 :            :     //! \param[in] h History point data
     853                 :            :     //! \param[in] inpoel Element-node connectivity
     854                 :            :     //! \param[in] coord Array of nodal coordinates
     855                 :            :     //! \param[in] U Array of unknowns
     856                 :            :     //! \param[in] P Array of primitive quantities
     857                 :            :     //! \return Vector of time history output of bulk flow quantities (density,
     858                 :            :     //!   velocity, total energy, and pressure) evaluated at time history points
     859                 :            :     std::vector< std::vector< tk::real > >
     860                 :          0 :     histOutput( const std::vector< HistData >& h,
     861                 :            :                 const std::vector< std::size_t >& inpoel,
     862                 :            :                 const tk::UnsMesh::Coords& coord,
     863                 :            :                 const tk::Fields& U,
     864                 :            :                 const tk::Fields& P ) const
     865                 :            :     {
     866                 :          0 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     867                 :          0 :       auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
     868                 :            : 
     869                 :            :       const auto& x = coord[0];
     870                 :            :       const auto& y = coord[1];
     871                 :            :       const auto& z = coord[2];
     872                 :            : 
     873                 :          0 :       std::vector< std::vector< tk::real > > Up(h.size());
     874                 :            : 
     875                 :            :       std::size_t j = 0;
     876         [ -  - ]:          0 :       for (const auto& p : h) {
     877                 :          0 :         auto e = p.get< tag::elem >();
     878                 :          0 :         auto chp = p.get< tag::coord >();
     879                 :            : 
     880                 :            :         // Evaluate inverse Jacobian
     881                 :          0 :         std::array< std::array< tk::real, 3>, 4 > cp{{
     882                 :            :           {{ x[inpoel[4*e  ]], y[inpoel[4*e  ]], z[inpoel[4*e  ]] }},
     883                 :            :           {{ x[inpoel[4*e+1]], y[inpoel[4*e+1]], z[inpoel[4*e+1]] }},
     884                 :            :           {{ x[inpoel[4*e+2]], y[inpoel[4*e+2]], z[inpoel[4*e+2]] }},
     885                 :            :           {{ x[inpoel[4*e+3]], y[inpoel[4*e+3]], z[inpoel[4*e+3]] }} }};
     886                 :          0 :         auto J = tk::inverseJacobian( cp[0], cp[1], cp[2], cp[3] );
     887                 :            : 
     888                 :            :         // evaluate solution at history-point
     889                 :          0 :         std::array< tk::real, 3 > dc{{chp[0]-cp[0][0], chp[1]-cp[0][1],
     890         [ -  - ]:          0 :           chp[2]-cp[0][2]}};
     891         [ -  - ]:          0 :         auto B = tk::eval_basis(rdof, tk::dot(J[0],dc), tk::dot(J[1],dc),
     892                 :            :           tk::dot(J[2],dc));
     893         [ -  - ]:          0 :         auto uhp = eval_state(m_ncomp, rdof, rdof, e, U, B);
     894         [ -  - ]:          0 :         auto php = eval_state(m_nprim, rdof, rdof, e, P, B);
     895                 :            : 
     896                 :            :         // Mixture calculations, initialized
     897         [ -  - ]:          0 :         Mixture mix(nspec, uhp, m_mat_blk);
     898                 :            : 
     899                 :            :         // store solution in history output vector
     900 [ -  - ][ -  - ]:          0 :         Up[j].resize(6+nspec, 0.0);
     901         [ -  - ]:          0 :         Up[j][0] = mix.get_mix_density();
     902         [ -  - ]:          0 :         Up[j][1] = uhp[multispecies::momentumIdx(nspec,0)]/Up[j][0];
     903                 :          0 :         Up[j][2] = uhp[multispecies::momentumIdx(nspec,1)]/Up[j][0];
     904         [ -  - ]:          0 :         Up[j][3] = uhp[multispecies::momentumIdx(nspec,2)]/Up[j][0];
     905                 :          0 :         Up[j][4] = uhp[multispecies::energyIdx(nspec,0)];
     906         [ -  - ]:          0 :         Up[j][5] = mix.pressure( Up[j][0],
     907                 :            :           php[multispecies::temperatureIdx(nspec,0)] );
     908         [ -  - ]:          0 :         for (std::size_t k=0; k<nspec; ++k) {
     909                 :          0 :           Up[j][6+k] = uhp[multispecies::densityIdx(nspec,k)]/Up[j][0];
     910                 :            :         }
     911         [ -  - ]:          0 :         ++j;
     912                 :            :       }
     913                 :            : 
     914                 :          0 :       return Up;
     915                 :            :     }
     916                 :            : 
     917                 :            :     //! Return names of integral variables to be output to diagnostics file
     918                 :            :     //! \return Vector of strings labelling integral variables output
     919                 :            :     std::vector< std::string > names() const
     920                 :            :     {
     921                 :          6 :       auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
     922                 :          6 :       return MultiSpeciesDiagNames(nspec);
     923                 :            :     }
     924                 :            : 
     925                 :            :     //! Return analytic solution (if defined by Problem) at xi, yi, zi, t
     926                 :            :     //! \param[in] xi X-coordinate at which to evaluate the analytic solution
     927                 :            :     //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
     928                 :            :     //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
     929                 :            :     //! \param[in] t Physical time at which to evaluate the analytic solution
     930                 :            :     //! \return Vector of analytic solution at given location and time
     931                 :            :     std::vector< tk::real >
     932                 :            :     analyticSolution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
     933                 :          0 :     { return Problem::analyticSolution( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
     934                 :            : 
     935                 :            :     //! Return analytic solution for conserved variables
     936                 :            :     //! \param[in] xi X-coordinate at which to evaluate the analytic solution
     937                 :            :     //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
     938                 :            :     //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
     939                 :            :     //! \param[in] t Physical time at which to evaluate the analytic solution
     940                 :            :     //! \return Vector of analytic solution at given location and time
     941                 :            :     std::vector< tk::real >
     942                 :            :     solution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
     943                 :     227400 :     { return Problem::initialize( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
     944                 :            : 
     945                 :            :     //! Return cell-averaged specific total energy for an element
     946                 :            :     //! \param[in] e Element id for which total energy is required
     947                 :            :     //! \param[in] unk Vector of conserved quantities
     948                 :            :     //! \return Cell-averaged specific total energy for given element
     949                 :            :     tk::real sp_totalenergy(std::size_t e, const tk::Fields& unk) const
     950                 :            :     {
     951                 :     227400 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     952                 :     227400 :       auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
     953                 :            : 
     954                 :     227400 :       return unk(e, multispecies::energyDofIdx(nspec,0,rdof,0));
     955                 :            :     }
     956                 :            : 
     957                 :            :   private:
     958                 :            :     //! Physics policy
     959                 :            :     const Physics m_physics;
     960                 :            :     //! Number of components in this PDE system
     961                 :            :     const ncomp_t m_ncomp;
     962                 :            :     //! Number of primitive quantities stored in this PDE system
     963                 :            :     const ncomp_t m_nprim;
     964                 :            :     //! Riemann solver
     965                 :            :     tk::RiemannFluxFn m_riemann;
     966                 :            :     //! BC configuration
     967                 :            :     BCStateFn m_bc;
     968                 :            :     //! EOS material block
     969                 :            :     std::vector< EOS > m_mat_blk;
     970                 :            : 
     971                 :            :     //! Evaluate conservative part of physical flux function for this PDE system
     972                 :            :     //! \param[in] ncomp Number of scalar components in this PDE system
     973                 :            :     //! \param[in] ugp Numerical solution at the Gauss point at which to
     974                 :            :     //!   evaluate the flux
     975                 :            :     //! \return Flux vectors for all components in this PDE system
     976                 :            :     //! \note The function signature must follow tk::FluxFn
     977                 :            :     static tk::FluxFn::result_type
     978                 :          0 :     flux( [[maybe_unused]] ncomp_t ncomp,
     979                 :            :           const std::vector< EOS >& mat_blk,
     980                 :            :           const std::vector< tk::real >& ugp,
     981                 :            :           const std::vector< std::array< tk::real, 3 > >& )
     982                 :            :     {
     983                 :          0 :       auto nspec = g_inputdeck.get< tag::multispecies, tag::nspec >();
     984                 :            : 
     985                 :          0 :       std::vector< std::array< tk::real, 3 > > fl( ugp.size() );
     986                 :            : 
     987         [ -  - ]:          0 :       Mixture mix(nspec, ugp, mat_blk);
     988                 :          0 :       auto rhob = mix.get_mix_density();
     989                 :            : 
     990         [ -  - ]:          0 :       std::array< tk::real, 3 > u{{
     991         [ -  - ]:          0 :         ugp[multispecies::momentumIdx(nspec,0)] / rhob,
     992                 :          0 :         ugp[multispecies::momentumIdx(nspec,1)] / rhob,
     993                 :          0 :         ugp[multispecies::momentumIdx(nspec,2)] / rhob }};
     994         [ -  - ]:          0 :       auto p = mix.pressure(rhob,
     995                 :            :         ugp[ncomp+multispecies::temperatureIdx(nspec,0)]);
     996                 :            : 
     997                 :            :       // density flux
     998         [ -  - ]:          0 :       for (std::size_t k=0; k<nspec; ++k) {
     999                 :            :         auto idx = multispecies::densityIdx(nspec, k);
    1000         [ -  - ]:          0 :         for (std::size_t j=0; j<3; ++j) {
    1001                 :          0 :           fl[idx][j] = ugp[idx] * u[j];
    1002                 :            :         }
    1003                 :            :       }
    1004                 :            : 
    1005                 :            :       // momentum flux
    1006         [ -  - ]:          0 :       for (std::size_t i=0; i<3; ++i) {
    1007                 :            :         auto idx = multispecies::momentumIdx(nspec,i);
    1008         [ -  - ]:          0 :         for (std::size_t j=0; j<3; ++j) {
    1009         [ -  - ]:          0 :           fl[idx][j] = ugp[idx] * u[j];
    1010         [ -  - ]:          0 :           if (i == j) fl[idx][j] += p;
    1011                 :            :         }
    1012                 :            :       }
    1013                 :            : 
    1014                 :            :       // energy flux
    1015                 :            :       auto idx = multispecies::energyIdx(nspec,0);
    1016         [ -  - ]:          0 :       for (std::size_t j=0; j<3; ++j) {
    1017                 :          0 :         fl[idx][j] = u[j] * (ugp[idx] + p);
    1018                 :            :       }
    1019                 :            : 
    1020                 :          0 :       return fl;
    1021                 :            :     }
    1022                 :            : 
    1023                 :            :     //! \brief Boundary state function providing the left and right state of a
    1024                 :            :     //!   face at Dirichlet boundaries
    1025                 :            :     //! \param[in] ncomp Number of scalar components in this PDE system
    1026                 :            :     //! \param[in] mat_blk EOS material block
    1027                 :            :     //! \param[in] ul Left (domain-internal) state
    1028                 :            :     //! \param[in] x X-coordinate at which to compute the states
    1029                 :            :     //! \param[in] y Y-coordinate at which to compute the states
    1030                 :            :     //! \param[in] z Z-coordinate at which to compute the states
    1031                 :            :     //! \param[in] t Physical time
    1032                 :            :     //! \return Left and right states for all scalar components in this PDE
    1033                 :            :     //!   system
    1034                 :            :     //! \note The function signature must follow tk::StateFn.
    1035                 :            :     static tk::StateFn::result_type
    1036                 :       2250 :     dirichlet( ncomp_t ncomp,
    1037                 :            :                const std::vector< EOS >& mat_blk,
    1038                 :            :                const std::vector< tk::real >& ul, tk::real x, tk::real y,
    1039                 :            :                tk::real z, tk::real t, const std::array< tk::real, 3 >& )
    1040                 :            :     {
    1041                 :       2250 :       return {{ ul, Problem::initialize( ncomp, mat_blk, x, y, z, t ) }};
    1042                 :            :     }
    1043                 :            : 
    1044                 :            :     // Other boundary condition types that do not depend on "Problem" should be
    1045                 :            :     // added in BCFunctions.hpp
    1046                 :            : };
    1047                 :            : 
    1048                 :            : } // dg::
    1049                 :            : 
    1050                 :            : } // inciter::
    1051                 :            : 
    1052                 :            : #endif // DGMultiSpecies_h

Generated by: LCOV version 1.14