Quinoa all test code coverage report
Current view: top level - PDE/MultiMat - FVMultiMat.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 128 209 61.2 %
Date: 2025-04-30 15:23:38 Functions: 25 220 11.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 99 376 26.3 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/PDE/MultiMat/FVMultiMat.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-material flow using finite volumes
       9                 :            :   \details   This file implements calls to the physics operators governing
      10                 :            :     compressible multi-material flow (with velocity equilibrium) using finite
      11                 :            :     volume discretizations.
      12                 :            : */
      13                 :            : // *****************************************************************************
      14                 :            : #ifndef FVMultiMat_h
      15                 :            : #define FVMultiMat_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/MultiMatTerms.hpp"
      37                 :            : #include "Integrate/Source.hpp"
      38                 :            : #include "RiemannChoice.hpp"
      39                 :            : #include "MultiMat/MultiMatIndexing.hpp"
      40                 :            : #include "Reconstruction.hpp"
      41                 :            : #include "Limiter.hpp"
      42                 :            : #include "Problem/FieldOutput.hpp"
      43                 :            : #include "Problem/BoxInitialization.hpp"
      44                 :            : #include "MultiMat/BCFunctions.hpp"
      45                 :            : #include "MultiMat/MiscMultiMatFns.hpp"
      46                 :            : 
      47                 :            : namespace inciter {
      48                 :            : 
      49                 :            : extern ctr::InputDeck g_inputdeck;
      50                 :            : 
      51                 :            : namespace fv {
      52                 :            : 
      53                 :            : //! \brief MultiMat used polymorphically with tk::FVPDE
      54                 :            : //! \details The template arguments specify policies and are used to configure
      55                 :            : //!   the behavior of the class. The policies are:
      56                 :            : //!   - Physics - physics configuration, see PDE/MultiMat/Physics.h
      57                 :            : //!   - Problem - problem configuration, see PDE/MultiMat/Problem.h
      58                 :            : //! \note The default physics is Euler, set in inciter::deck::check_multimat()
      59                 :            : template< class Physics, class Problem >
      60                 :            : class MultiMat {
      61                 :            : 
      62                 :            :   private:
      63                 :            :     using eq = tag::multimat;
      64                 :            : 
      65                 :            :   public:
      66                 :            :     //! Constructor
      67                 :         76 :     explicit MultiMat() :
      68                 :            :       m_physics(),
      69                 :            :       m_ncomp( g_inputdeck.get< tag::ncomp >() ),
      70                 :            :       m_riemann( multimatRiemannSolver(
      71         [ +  - ]:         76 :         g_inputdeck.get< tag::flux >() ) )
      72                 :            :     {
      73                 :            :       // associate boundary condition configurations with state functions
      74 [ +  - ][ +  - ]:       1140 :       brigand::for_each< ctr::bclist::Keys >( ConfigBC( m_bc,
         [ +  - ][ +  + ]
         [ +  - ][ +  + ]
         [ +  - ][ +  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
      75                 :            :         // BC State functions
      76                 :            :         { dirichlet
      77                 :            :         , symmetry
      78                 :            :         , invalidBC         // Outlet BC not implemented
      79                 :            :         , farfield
      80                 :            :         , extrapolate
      81                 :            :         , noslipwall 
      82                 :            :         , symmetry },       // Slip equivalent to symmetry without mesh motion
      83                 :            :         // BC Gradient functions
      84                 :            :         { noOpGrad
      85                 :            :         , symmetryGrad
      86                 :            :         , noOpGrad
      87                 :            :         , noOpGrad
      88                 :            :         , noOpGrad
      89                 :            :         , noOpGrad
      90                 :            :         , symmetryGrad }
      91                 :            :         ) );
      92                 :            : 
      93                 :            :       // Inlet BC has a different structure than above BCs, so it must be 
      94                 :            :       // handled differently than with ConfigBC
      95 [ +  - ][ +  - ]:        228 :       ConfigInletBC(m_bc, inlet, zeroGrad);
         [ +  - ][ -  - ]
      96                 :            : 
      97                 :            :       // Back pressure BC has a different structure than above BCs, so it must
      98                 :            :       // be handled differently than with ConfigBC
      99 [ +  - ][ +  - ]:        152 :       ConfigBackPressureBC(m_bc, back_pressure, noOpGrad);
                 [ -  - ]
     100                 :            : 
     101                 :            :       // EoS initialization
     102         [ +  - ]:         76 :       initializeMaterialEoS( m_mat_blk );
     103                 :         76 :     }
     104                 :            : 
     105                 :            :     //! Find the number of primitive quantities required for this PDE system
     106                 :            :     //! \return The number of primitive quantities required to be stored for
     107                 :            :     //!   this PDE system
     108                 :            :     std::size_t nprim() const
     109                 :            :     {
     110                 :       9070 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     111                 :            :       // multimat needs individual material pressures and velocities currently
     112                 :       9070 :       return (nmat+3);
     113                 :            :     }
     114                 :            : 
     115                 :            :     //! Find the number of materials set up for this PDE system
     116                 :            :     //! \return The number of materials set up for this PDE system
     117                 :            :     std::size_t nmat() const
     118                 :            :     {
     119                 :          0 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     120                 :            :       return nmat;
     121                 :            :     }
     122                 :            : 
     123                 :            :     //! Determine elements that lie inside the user-defined IC box
     124                 :            :     //! \param[in] geoElem Element geometry array
     125                 :            :     //! \param[in] nielem Number of internal elements
     126                 :            :     //! \param[in,out] inbox List of nodes at which box user ICs are set for
     127                 :            :     //!    each IC box
     128                 :            :     void IcBoxElems( const tk::Fields& geoElem,
     129                 :            :       std::size_t nielem,
     130                 :            :       std::vector< std::unordered_set< std::size_t > >& inbox ) const
     131                 :            :     {
     132                 :        294 :       tk::BoxElems< eq >(geoElem, nielem, inbox);
     133                 :            :     }
     134                 :            : 
     135                 :            :     //! Initalize the compressible flow equations, prepare for time integration
     136                 :            :     //! \param[in] L Block diagonal mass matrix
     137                 :            :     //! \param[in] inpoel Element-node connectivity
     138                 :            :     //! \param[in] coord Array of nodal coordinates
     139                 :            :     //! \param[in] inbox List of elements at which box user ICs are set for
     140                 :            :     //!   each IC box
     141                 :            :     //! \param[in] elemblkid Element ids associated with mesh block ids where
     142                 :            :     //!   user ICs are set
     143                 :            :     //! \param[in,out] unk Array of unknowns
     144                 :            :     //! \param[in] t Physical time
     145                 :            :     //! \param[in] nielem Number of internal elements
     146         [ +  - ]:        294 :     void initialize( const tk::Fields& L,
     147                 :            :       const std::vector< std::size_t >& inpoel,
     148                 :            :       const tk::UnsMesh::Coords& coord,
     149                 :            :       const std::vector< std::unordered_set< std::size_t > >& inbox,
     150                 :            :       const std::unordered_map< std::size_t, std::set< std::size_t > >&
     151                 :            :         elemblkid,
     152                 :            :       tk::Fields& unk,
     153                 :            :       tk::real t,
     154                 :            :       const std::size_t nielem ) const
     155                 :            :     {
     156         [ +  - ]:        294 :       tk::initialize( m_ncomp, m_mat_blk, L, inpoel, coord,
     157                 :            :                       Problem::initialize, unk, t, nielem );
     158                 :            : 
     159                 :        294 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     160                 :            :       const auto& ic = g_inputdeck.get< tag::ic >();
     161                 :            :       const auto& icbox = ic.get< tag::box >();
     162                 :            :       const auto& icmbk = ic.get< tag::meshblock >();
     163                 :            : 
     164                 :            :       const auto& bgpre = ic.get< tag::pressure >();
     165                 :            :       const auto& bgtemp = ic.get< tag::temperature >();
     166                 :            : 
     167                 :            :       // Set initial conditions inside user-defined IC boxes and mesh blocks
     168                 :        294 :       std::vector< tk::real > s(m_ncomp, 0.0);
     169         [ +  + ]:      16466 :       for (std::size_t e=0; e<nielem; ++e) {
     170                 :            :         // inside user-defined box
     171         [ -  + ]:      16172 :         if (!icbox.empty()) {
     172                 :            :           std::size_t bcnt = 0;
     173         [ -  - ]:          0 :           for (const auto& b : icbox) {   // for all boxes
     174 [ -  - ][ -  - ]:          0 :             if (inbox.size() > bcnt && inbox[bcnt].find(e) != inbox[bcnt].end())
     175                 :            :             {
     176 [ -  - ][ -  - ]:          0 :               std::vector< tk::real > box
     177                 :            :                 { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
     178                 :            :                   b.template get< tag::ymin >(), b.template get< tag::ymax >(),
     179                 :            :                   b.template get< tag::zmin >(), b.template get< tag::zmax >() };
     180                 :          0 :               auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
     181         [ -  - ]:          0 :               for (std::size_t c=0; c<m_ncomp; ++c) {
     182                 :          0 :                 auto mark = c*rdof;
     183                 :          0 :                 s[c] = unk(e,mark);
     184                 :            :                 // set high-order DOFs to zero
     185         [ -  - ]:          0 :                 for (std::size_t i=1; i<rdof; ++i)
     186                 :          0 :                   unk(e,mark+i) = 0.0;
     187                 :            :               }
     188         [ -  - ]:          0 :               initializeBox<ctr::boxList>( m_mat_blk, V_ex, t, b, bgpre,
     189                 :            :                 bgtemp, s );
     190                 :            :               // store box-initialization in solution vector
     191         [ -  - ]:          0 :               for (std::size_t c=0; c<m_ncomp; ++c) {
     192                 :          0 :                 auto mark = c*rdof;
     193                 :          0 :                 unk(e,mark) = s[c];
     194                 :            :               }
     195                 :            :             }
     196                 :          0 :             ++bcnt;
     197                 :            :           }
     198                 :            :         }
     199                 :            : 
     200                 :            :         // inside user-specified mesh blocks
     201         [ -  + ]:      16172 :         for (const auto& b : icmbk) { // for all blocks
     202                 :          0 :           auto blid = b.get< tag::blockid >();
     203                 :          0 :           auto V_ex = b.get< tag::volume >();
     204         [ -  - ]:          0 :           if (elemblkid.find(blid) != elemblkid.end()) {
     205                 :            :             const auto& elset = tk::cref_find(elemblkid, blid);
     206         [ -  - ]:          0 :             if (elset.find(e) != elset.end()) {
     207         [ -  - ]:          0 :               initializeBox<ctr::meshblockList>( m_mat_blk, V_ex, t, b,
     208                 :            :                 bgpre, bgtemp, s );
     209                 :            :               // store initialization in solution vector
     210         [ -  - ]:          0 :               for (std::size_t c=0; c<m_ncomp; ++c) {
     211                 :          0 :                 auto mark = c*rdof;
     212                 :          0 :                 unk(e,mark) = s[c];
     213                 :            :               }
     214                 :            :             }
     215                 :            :           }
     216                 :            :         }
     217                 :            :       }
     218                 :        294 :     }
     219                 :            : 
     220                 :            :     //! Compute the left hand side block-diagonal mass matrix
     221                 :            :     //! \param[in] geoElem Element geometry array
     222                 :            :     //! \param[in,out] l Block diagonal mass matrix
     223                 :            :     void lhs( const tk::Fields& geoElem, tk::Fields& l ) const {
     224                 :        294 :       const auto nelem = geoElem.nunk();
     225 [ -  - ][ +  + ]:      52112 :       for (std::size_t e=0; e<nelem; ++e)
         [ +  + ][ +  + ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     226 [ -  - ][ +  + ]:     664538 :         for (ncomp_t c=0; c<m_ncomp; ++c)
         [ +  + ][ +  + ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     227                 :     612720 :           l(e, c) = geoElem(e,0);
     228                 :            :     }
     229                 :            : 
     230                 :            :     //! Update the primitives for this PDE system
     231                 :            :     //! \param[in] unk Array of unknowns
     232                 :            :     //! \param[in,out] prim Array of primitives
     233                 :            :     //! \param[in] nielem Number of internal elements
     234                 :            :     //! \details This function computes and stores the dofs for primitive
     235                 :            :     //!   quantities, which are required for obtaining reconstructed states used
     236                 :            :     //!   in the Riemann solver. See /PDE/Riemann/AUSM.hpp, where the
     237                 :            :     //!   normal velocity for advection is calculated from independently
     238                 :            :     //!   reconstructed velocities.
     239                 :       1562 :     void updatePrimitives( const tk::Fields& unk,
     240                 :            :                            tk::Fields& prim,
     241                 :            :                            std::size_t nielem ) const
     242                 :            :     {
     243                 :       1562 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     244                 :       1562 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     245                 :            : 
     246                 :            :       Assert( unk.nunk() == prim.nunk(), "Number of unknowns in solution "
     247                 :            :               "vector and primitive vector at recent time step incorrect" );
     248                 :            :       Assert( unk.nprop() == rdof*m_ncomp, "Number of components in solution "
     249                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     250                 :            :       Assert( prim.nprop() == rdof*nprim(), "Number of components in vector of "
     251                 :            :               "primitive quantities must equal "+ std::to_string(rdof*nprim()) );
     252                 :            : 
     253         [ +  + ]:     221894 :       for (std::size_t e=0; e<nielem; ++e)
     254                 :            :       {
     255                 :            :         // cell-average bulk density
     256                 :            :         tk::real rhob(0.0);
     257         [ +  + ]:     726696 :         for (std::size_t k=0; k<nmat; ++k)
     258                 :            :         {
     259                 :     506364 :           rhob += unk(e, densityDofIdx(nmat, k, rdof, 0));
     260                 :            :         }
     261                 :            : 
     262                 :            :         // cell-average velocity
     263                 :            :         std::array< tk::real, 3 >
     264                 :     220332 :           vel{{ unk(e, momentumDofIdx(nmat, 0, rdof, 0))/rhob,
     265                 :     220332 :                 unk(e, momentumDofIdx(nmat, 1, rdof, 0))/rhob,
     266                 :     220332 :                 unk(e, momentumDofIdx(nmat, 2, rdof, 0))/rhob }};
     267                 :            : 
     268         [ +  + ]:     881328 :         for (std::size_t idir=0; idir<3; ++idir)
     269                 :            :         {
     270                 :     660996 :           prim(e, velocityDofIdx(nmat, idir, rdof, 0)) = vel[idir];
     271         [ +  + ]:    2643984 :           for (std::size_t idof=1; idof<rdof; ++idof)
     272                 :    1982988 :             prim(e, velocityDofIdx(nmat, idir, rdof, idof)) = 0.0;
     273                 :            :         }
     274                 :            : 
     275                 :            :         // cell-average material pressure
     276         [ +  + ]:     726696 :         for (std::size_t k=0; k<nmat; ++k)
     277                 :            :         {
     278         [ +  - ]:     506364 :           tk::real arhomat = unk(e, densityDofIdx(nmat, k, rdof, 0));
     279         [ +  - ]:     506364 :           tk::real arhoemat = unk(e, energyDofIdx(nmat, k, rdof, 0));
     280                 :     506364 :           tk::real alphamat = unk(e, volfracDofIdx(nmat, k, rdof, 0));
     281 [ +  - ][ +  - ]:     506364 :           auto gmat = getDeformGrad(nmat, k, unk.extract(e));
     282         [ +  - ]:     506364 :           prim(e, pressureDofIdx(nmat, k, rdof, 0)) =
     283         [ +  - ]:     506364 :             m_mat_blk[k].compute< EOS::pressure >( arhomat, vel[0], vel[1],
     284                 :            :             vel[2], arhoemat, alphamat, k, gmat );
     285                 :     506364 :           prim(e, pressureDofIdx(nmat, k, rdof, 0)) =
     286         [ +  - ]:     506364 :             constrain_pressure( m_mat_blk,
     287                 :            :             prim(e, pressureDofIdx(nmat, k, rdof, 0)), arhomat, alphamat, k);
     288         [ +  + ]:    2025456 :           for (std::size_t idof=1; idof<rdof; ++idof)
     289                 :    1519092 :             prim(e, pressureDofIdx(nmat, k, rdof, idof)) = 0.0;
     290                 :            :         }
     291                 :            :       }
     292                 :       1562 :     }
     293                 :            : 
     294                 :            :     //! Clean up the state of trace materials for this PDE system
     295                 :            :     //! \param[in] t Physical time
     296                 :            :     //! \param[in] geoElem Element geometry array
     297                 :            :     //! \param[in,out] unk Array of unknowns
     298                 :            :     //! \param[in,out] prim Array of primitives
     299                 :            :     //! \param[in] nielem Number of internal elements
     300                 :            :     //! \details This function cleans up the state of materials present in trace
     301                 :            :     //!   quantities in each cell. Specifically, the state of materials with
     302                 :            :     //!   very low volume-fractions in a cell is replaced by the state of the
     303                 :            :     //!   material which is present in the largest quantity in that cell. This
     304                 :            :     //!   becomes necessary when shocks pass through cells which contain a very
     305                 :            :     //!   small amount of material. The state of that tiny material might
     306                 :            :     //!   become unphysical and cause solution to diverge; thus requiring such
     307                 :            :     //!   a "reset".
     308                 :       1268 :     void cleanTraceMaterial( tk::real t,
     309                 :            :                              const tk::Fields& geoElem,
     310                 :            :                              tk::Fields& unk,
     311                 :            :                              tk::Fields& prim,
     312                 :            :                              std::size_t nielem ) const
     313                 :            :     {
     314                 :            :       [[maybe_unused]] const auto rdof = g_inputdeck.get< tag::rdof >();
     315                 :       1268 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     316                 :            : 
     317                 :            :       Assert( unk.nunk() == prim.nunk(), "Number of unknowns in solution "
     318                 :            :               "vector and primitive vector at recent time step incorrect" );
     319                 :            :       Assert( unk.nprop() == rdof*m_ncomp, "Number of components in solution "
     320                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     321                 :            :       Assert( prim.nprop() == rdof*nprim(), "Number of components in vector of "
     322                 :            :               "primitive quantities must equal "+ std::to_string(rdof*nprim()) );
     323                 :            :       Assert( (g_inputdeck.get< tag::ndof >()) <= 4, "High-order "
     324                 :            :               "discretizations not set up for multimat cleanTraceMaterial()" );
     325                 :            : 
     326                 :       1268 :       auto neg_density = cleanTraceMultiMat(t, nielem, m_mat_blk, geoElem, nmat,
     327                 :            :         unk, prim);
     328                 :            : 
     329 [ -  + ][ -  - ]:       1268 :       if (neg_density) Throw("Negative partial density.");
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
     330                 :       1268 :     }
     331                 :            : 
     332                 :            :     //! Reconstruct second-order solution from first-order
     333                 :            :     //! \param[in] geoElem Element geometry array
     334                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     335                 :            :     //! \param[in] esup Elements-surrounding-nodes connectivity
     336                 :            :     //! \param[in] inpoel Element-node connectivity
     337                 :            :     //! \param[in] coord Array of nodal coordinates
     338                 :            :     //! \param[in,out] U Solution vector at recent time step
     339                 :            :     //! \param[in,out] P Vector of primitives at recent time step
     340                 :       1268 :     void reconstruct( const tk::Fields& geoElem,
     341                 :            :                       const inciter::FaceData& fd,
     342                 :            :                       const std::map< std::size_t, std::vector< std::size_t > >&
     343                 :            :                         esup,
     344                 :            :                       const std::vector< std::size_t >& inpoel,
     345                 :            :                       const tk::UnsMesh::Coords& coord,
     346                 :            :                       tk::Fields& U,
     347                 :            :                       tk::Fields& P ) const
     348                 :            :     {
     349                 :       1268 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     350                 :       1268 :       const auto nelem = fd.Esuel().size()/4;
     351                 :       1268 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     352                 :            : 
     353                 :            :       Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
     354                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     355                 :            : 
     356                 :            :       //----- reconstruction of conserved quantities -----
     357                 :            :       //--------------------------------------------------
     358                 :            :       // specify how many variables need to be reconstructed
     359                 :            :       std::vector< std::size_t > vars;
     360         [ +  + ]:       4972 :       for (std::size_t k=0; k<nmat; ++k) {
     361 [ +  - ][ +  - ]:       3704 :         vars.push_back(volfracIdx(nmat,k));
     362 [ +  - ][ -  - ]:       3704 :         vars.push_back(densityIdx(nmat,k));
     363                 :            :       }
     364                 :            : 
     365         [ +  + ]:     205428 :       for (std::size_t e=0; e<nelem; ++e)
     366                 :            :       {
     367                 :            :         // 1. solve 3x3 least-squares system
     368                 :            :         // Reconstruct second-order dofs of volume-fractions in Taylor space
     369                 :            :         // using nodal-stencils, for a good interface-normal estimate
     370         [ +  - ]:     204160 :         tk::recoLeastSqExtStencil( rdof, e, esup, inpoel, geoElem, U, vars );
     371                 :            : 
     372                 :            :         // 2. transform reconstructed derivatives to Dubiner dofs
     373         [ +  - ]:     204160 :         tk::transform_P0P1(rdof, e, inpoel, coord, U, vars);
     374                 :            :       }
     375                 :            : 
     376                 :            :       //----- reconstruction of primitive quantities -----
     377                 :            :       //--------------------------------------------------
     378                 :            :       // For multimat, conserved and primitive quantities are reconstructed
     379                 :            :       // separately.
     380                 :            :       vars.clear();
     381 [ +  + ][ +  - ]:       8776 :       for (std::size_t c=0; c<nprim(); ++c) vars.push_back(c);
     382         [ +  + ]:     205428 :       for (std::size_t e=0; e<nelem; ++e)
     383                 :            :       {
     384                 :            :         // 1.
     385                 :            :         // Reconstruct second-order dofs of volume-fractions in Taylor space
     386                 :            :         // using nodal-stencils, for a good interface-normal estimate
     387         [ +  - ]:     204160 :         tk::recoLeastSqExtStencil( rdof, e, esup, inpoel, geoElem, P, vars );
     388                 :            : 
     389                 :            :         // 2.
     390         [ +  - ]:     204160 :         tk::transform_P0P1(rdof, e, inpoel, coord, P, vars );
     391                 :            :       }
     392                 :       1268 :     }
     393                 :            : 
     394                 :            :     //! Limit second-order solution, and primitive quantities separately
     395                 :            :     //! \param[in] geoFace Face geometry array
     396                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     397                 :            :     //! \param[in] esup Elements-surrounding-nodes connectivity
     398                 :            :     //! \param[in] inpoel Element-node connectivity
     399                 :            :     //! \param[in] coord Array of nodal coordinates
     400                 :            :     //! \param[in] srcFlag Whether the energy source was added
     401                 :            :     //! \param[in,out] U Solution vector at recent time step
     402                 :            :     //! \param[in,out] P Vector of primitives at recent time step
     403                 :       1268 :     void limit( const tk::Fields& geoFace,
     404                 :            :                 const inciter::FaceData& fd,
     405                 :            :                 const std::map< std::size_t, std::vector< std::size_t > >& esup,
     406                 :            :                 const std::vector< std::size_t >& inpoel,
     407                 :            :                 const tk::UnsMesh::Coords& coord,
     408                 :            :                 const std::vector< int >& srcFlag,
     409                 :            :                 tk::Fields& U,
     410                 :            :                 tk::Fields& P ) const
     411                 :            :     {
     412                 :            :       Assert( U.nunk() == P.nunk(), "Number of unknowns in solution "
     413                 :            :               "vector and primitive vector at recent time step incorrect" );
     414                 :            : 
     415                 :       1268 :       const auto limiter = g_inputdeck.get< tag::limiter >();
     416                 :       1268 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     417                 :            :       const auto& solidx = g_inputdeck.get<
     418                 :            :         tag::matidxmap, tag::solidx >();
     419                 :            : 
     420                 :            :       // limit vectors of conserved and primitive quantities
     421         [ +  - ]:       1268 :       if (limiter == ctr::LimiterType::VERTEXBASEDP1)
     422                 :            :       {
     423                 :       1268 :         VertexBasedMultiMat_FV( esup, inpoel, fd.Esuel().size()/4,
     424                 :            :           coord, srcFlag, solidx, U, P, nmat );
     425                 :       1268 :         PositivityPreservingMultiMat_FV( inpoel, fd.Esuel().size()/4, nmat,
     426                 :       1268 :           m_mat_blk, coord, geoFace, U, P );
     427                 :            :       }
     428         [ -  - ]:          0 :       else if (limiter != ctr::LimiterType::NOLIMITER)
     429                 :            :       {
     430 [ -  - ][ -  - ]:          0 :         Throw("Limiter type not configured for multimat.");
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     431                 :            :       }
     432                 :       1268 :     }
     433                 :            : 
     434                 :            :     //! Apply CPL to the conservative variable solution for this PDE system
     435                 :            :     //! \param[in] prim Array of primitive variables
     436                 :            :     //! \param[in] geoElem Element geometry array
     437                 :            :     //! \param[in] inpoel Element-node connectivity
     438                 :            :     //! \param[in] coord Array of nodal coordinates
     439                 :            :     //! \param[in,out] unk Array of conservative variables
     440                 :            :     //! \param[in] nielem Number of internal elements
     441                 :            :     //! \details This function applies CPL to obtain consistent dofs for
     442                 :            :     //!   conservative quantities based on the limited primitive quantities.
     443                 :            :     //!   See Pandare et al. (2023). On the Design of Stable,
     444                 :            :     //!   Consistent, and Conservative High-Order Methods for Multi-Material
     445                 :            :     //!   Hydrodynamics. J Comp Phys, 112313.
     446                 :            :     void CPL( const tk::Fields& prim,
     447                 :            :       const tk::Fields& geoElem,
     448                 :            :       const std::vector< std::size_t >& inpoel,
     449                 :            :       const tk::UnsMesh::Coords& coord,
     450                 :            :       tk::Fields& unk,
     451                 :            :       std::size_t nielem ) const
     452                 :            :     {
     453                 :            :       [[maybe_unused]] const auto rdof = g_inputdeck.get< tag::rdof >();
     454                 :            :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     455                 :            : 
     456                 :            :       Assert( unk.nunk() == prim.nunk(), "Number of unknowns in solution "
     457                 :            :               "vector and primitive vector at recent time step incorrect" );
     458                 :            :       Assert( unk.nprop() == rdof*m_ncomp, "Number of components in solution "
     459                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     460                 :            :       Assert( prim.nprop() == rdof*nprim(), "Number of components in vector of "
     461                 :            :               "primitive quantities must equal "+ std::to_string(rdof*nprim()) );
     462                 :            : 
     463                 :            :       correctLimConservMultiMat(nielem, m_mat_blk, nmat, inpoel,
     464                 :            :         coord, geoElem, prim, unk);
     465                 :            :     }
     466                 :            : 
     467                 :            :     //! Compute right hand side
     468                 :            :     //! \param[in] t Physical time
     469                 :            :     //! \param[in] geoFace Face geometry array
     470                 :            :     //! \param[in] geoElem Element geometry array
     471                 :            :     //! \param[in] fd Face connectivity and boundary conditions object
     472                 :            :     //! \param[in] inpoel Element-node connectivity
     473                 :            :     //! \param[in] coord Array of nodal coordinates
     474                 :            :     //! \param[in] elemblkid Element ids associated with mesh block ids where
     475                 :            :     //!   user ICs are set
     476                 :            :     //! \param[in] U Solution vector at recent time step
     477                 :            :     //! \param[in] P Primitive vector at recent time step
     478                 :            :     //! \param[in,out] R Right-hand side vector computed
     479                 :            :     //! \param[in,out] srcFlag Whether the energy source was added
     480                 :       1268 :     void rhs( tk::real t,
     481                 :            :               const tk::Fields& geoFace,
     482                 :            :               const tk::Fields& geoElem,
     483                 :            :               const inciter::FaceData& fd,
     484                 :            :               const std::vector< std::size_t >& inpoel,
     485                 :            :               const tk::UnsMesh::Coords& coord,
     486                 :            :               const std::unordered_map< std::size_t, std::set< std::size_t > >&
     487                 :            :                 elemblkid,
     488                 :            :               const tk::Fields& U,
     489                 :            :               const tk::Fields& P,
     490                 :            :               tk::Fields& R,
     491                 :            :               std::vector< int >& srcFlag ) const
     492                 :            :     {
     493                 :       1268 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     494                 :       1268 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     495                 :       1268 :       const auto intsharp =
     496                 :            :         g_inputdeck.get< tag::multimat, tag::intsharp >();
     497                 :       1268 :       auto viscous = g_inputdeck.get< tag::multimat, tag::viscous >();
     498                 :            : 
     499                 :       1268 :       const auto nelem = fd.Esuel().size()/4;
     500                 :            : 
     501                 :            :       Assert( U.nunk() == P.nunk(), "Number of unknowns in solution "
     502                 :            :               "vector and primitive vector at recent time step incorrect" );
     503                 :            :       Assert( U.nunk() == R.nunk(), "Number of unknowns in solution "
     504                 :            :               "vector and right-hand side at recent time step incorrect" );
     505                 :            :       Assert( U.nprop() == rdof*m_ncomp, "Number of components in solution "
     506                 :            :               "vector must equal "+ std::to_string(rdof*m_ncomp) );
     507                 :            :       Assert( P.nprop() == rdof*nprim(), "Number of components in primitive "
     508                 :            :               "vector must equal "+ std::to_string(rdof*nprim()) );
     509                 :            :       Assert( fd.Inpofa().size()/3 == fd.Esuf().size()/2,
     510                 :            :               "Mismatch in inpofa size" );
     511                 :            : 
     512                 :            :       // set rhs to zero
     513                 :            :       R.fill(0.0);
     514                 :            : 
     515                 :            :       // configure a no-op lambda for prescribed velocity
     516                 :            :       auto velfn = []( ncomp_t, tk::real, tk::real, tk::real, tk::real ){
     517                 :            :         return tk::VelFn::result_type(); };
     518                 :            : 
     519                 :            :       // compute internal surface flux (including non-conservative) integrals
     520                 :       2536 :       tk::surfIntFV( nmat, m_mat_blk, t, rdof, inpoel,
     521         [ +  - ]:       1268 :                      coord, fd, geoFace, geoElem, m_riemann, velfn, U, P,
     522                 :            :                      srcFlag, R, intsharp );
     523                 :            :       // compute internal surface viscous flux integrals
     524                 :       1268 :       tk::Fields T( U.nunk(), rdof*nmat );
     525         [ -  + ]:       1268 :       if (viscous) {
     526         [ -  - ]:          0 :         computeTemperaturesFV( m_mat_blk, nmat, inpoel, coord, geoElem,
     527                 :            :                                U, P, srcFlag, T );
     528                 :            : 
     529         [ -  - ]:          0 :         tk::surfIntViscousFV( nmat, m_mat_blk, rdof, inpoel,
     530                 :            :                               coord, fd, geoFace, geoElem, U, P, T,
     531                 :            :                               srcFlag, R, intsharp );
     532                 :            :       }
     533                 :            : 
     534                 :            :       // compute boundary surface flux (including non-conservative) integrals
     535         [ +  + ]:      11412 :       for (const auto& b : m_bc) {
     536         [ +  - ]:      10144 :         tk::bndSurfIntFV( nmat, m_mat_blk, rdof, std::get<0>(b),
     537                 :            :                           fd, geoFace, geoElem, inpoel, coord, t, m_riemann,
     538                 :            :                           velfn, std::get<1>(b), U, P, srcFlag, R, intsharp );
     539         [ -  + ]:      10144 :         if (viscous)
     540         [ -  - ]:          0 :           tk::bndSurfIntViscousFV( nmat, m_mat_blk, rdof, std::get<0>(b),
     541                 :            :                                    fd, geoFace, geoElem, inpoel, coord, t,
     542                 :            :                                    std::get<1>(b), std::get<2>(b), U, P, T,
     543                 :            :                                    srcFlag, R, intsharp );
     544                 :            :       }
     545                 :            : 
     546                 :            :       // compute optional source term
     547 [ +  - ][ -  - ]:       1268 :       tk::srcIntFV( m_mat_blk, t, fd.Esuel().size()/4,
     548                 :            :                     geoElem, Problem::src, R, nmat );
     549                 :            : 
     550                 :            :       // compute finite pressure relaxation terms
     551         [ +  + ]:       1268 :       if (g_inputdeck.get< tag::multimat, tag::prelax >())
     552                 :            :       {
     553                 :       1218 :         const auto ct = g_inputdeck.get< tag::multimat,
     554                 :            :                                          tag::prelax_timescale >();
     555         [ +  - ]:       1218 :         tk::pressureRelaxationIntFV( nmat, m_mat_blk, rdof,
     556                 :            :                                      nelem, inpoel, coord, geoElem, U, P, ct,
     557                 :            :                                      R );
     558                 :            :       }
     559                 :            : 
     560                 :            :       // compute external (energy) sources
     561         [ -  - ]:          0 :       m_physics.physSrc(nmat, t, geoElem, elemblkid, R, srcFlag);
     562                 :       1268 :     }
     563                 :            : 
     564                 :            :     //! Compute the minimum time step size
     565                 :            : //    //! \param[in] fd Face connectivity and boundary conditions object
     566                 :            : //    //! \param[in] geoFace Face geometry array
     567                 :            :     //! \param[in] geoElem Element geometry array
     568                 :            :     //! \param[in] U Solution vector at recent time step
     569                 :            :     //! \param[in] P Vector of primitive quantities at recent time step
     570                 :            :     //! \param[in] nielem Number of internal elements
     571                 :            :     //! \param[in] srcFlag Whether the energy source was added
     572                 :            :     //! \param[in,out] local_dte Time step size for each element (for local
     573                 :            :     //!   time stepping)
     574                 :            :     //! \return Minimum time step size
     575                 :            :     //! \details The allowable dt is calculated by looking at the maximum
     576                 :            :     //!   wave-speed in elements surrounding each face, times the area of that
     577                 :            :     //!   face. Once the maximum of this quantity over the mesh is determined,
     578                 :            :     //!   the volume of each cell is divided by this quantity. A minimum of this
     579                 :            :     //!   ratio is found over the entire mesh, which gives the allowable dt.
     580                 :         50 :     tk::real dt( const inciter::FaceData& /*fd*/,
     581                 :            :                  const tk::Fields& /*geoFace*/,
     582                 :            :                  const tk::Fields& geoElem,
     583                 :            :                  const tk::Fields& U,
     584                 :            :                  const tk::Fields& P,
     585                 :            :                  const std::size_t nielem,
     586                 :            :                  const std::vector< int >& srcFlag,
     587                 :            :                  std::vector< tk::real >& local_dte ) const
     588                 :            :     {
     589                 :         50 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     590                 :         50 :       auto viscous = g_inputdeck.get< tag::multimat, tag::viscous >();
     591                 :            : 
     592                 :            :       // obtain dt restrictions from all physics
     593                 :         50 :       auto dt_e = timeStepSizeMultiMatFV(m_mat_blk, geoElem, nielem, nmat, U,
     594                 :            :         P, local_dte);
     595         [ -  + ]:         50 :       if (viscous)
     596         [ -  - ]:          0 :         dt_e = std::min(dt_e, timeStepSizeViscousFV(geoElem, nielem, nmat, U));
     597         [ -  + ]:         50 :       auto dt_p = m_physics.dtRestriction(geoElem, nielem, srcFlag);
     598                 :            : 
     599                 :         50 :       return std::min(dt_e, dt_p);
     600                 :            :     }
     601                 :            : 
     602                 :            :     //! Extract the velocity field at cell nodes. Currently unused.
     603                 :            :     //! \param[in] U Solution vector at recent time step
     604                 :            :     //! \param[in] N Element node indices
     605                 :            :     //! \return Array of the four values of the velocity field
     606                 :            :     std::array< std::array< tk::real, 4 >, 3 >
     607                 :            :     velocity( const tk::Fields& U,
     608                 :            :               const std::array< std::vector< tk::real >, 3 >&,
     609                 :            :               const std::array< std::size_t, 4 >& N ) const
     610                 :            :     {
     611                 :            :       const auto rdof = g_inputdeck.get< tag::rdof >();
     612                 :            :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     613                 :            : 
     614                 :            :       std::array< std::array< tk::real, 4 >, 3 > v;
     615                 :            :       v[0] = U.extract( momentumDofIdx(nmat, 0, rdof, 0), N );
     616                 :            :       v[1] = U.extract( momentumDofIdx(nmat, 1, rdof, 0), N );
     617                 :            :       v[2] = U.extract( momentumDofIdx(nmat, 2, rdof, 0), N );
     618                 :            : 
     619                 :            :       std::vector< std::array< tk::real, 4 > > ar;
     620                 :            :       ar.resize(nmat);
     621                 :            :       for (std::size_t k=0; k<nmat; ++k)
     622                 :            :         ar[k] = U.extract( densityDofIdx(nmat, k, rdof, 0), N );
     623                 :            : 
     624                 :            :       std::array< tk::real, 4 > r{{ 0.0, 0.0, 0.0, 0.0 }};
     625                 :            :       for (std::size_t i=0; i<r.size(); ++i) {
     626                 :            :         for (std::size_t k=0; k<nmat; ++k)
     627                 :            :           r[i] += ar[k][i];
     628                 :            :       }
     629                 :            : 
     630                 :            :       std::transform( r.begin(), r.end(), v[0].begin(), v[0].begin(),
     631                 :            :                       []( tk::real s, tk::real& d ){ return d /= s; } );
     632                 :            :       std::transform( r.begin(), r.end(), v[1].begin(), v[1].begin(),
     633                 :            :                       []( tk::real s, tk::real& d ){ return d /= s; } );
     634                 :            :       std::transform( r.begin(), r.end(), v[2].begin(), v[2].begin(),
     635                 :            :                       []( tk::real s, tk::real& d ){ return d /= s; } );
     636                 :            :       return v;
     637                 :            :     }
     638                 :            : 
     639                 :            :     //! Return a map that associates user-specified strings to functions
     640                 :            :     //! \return Map that associates user-specified strings to functions that
     641                 :            :     //!   compute relevant quantities to be output to file
     642                 :            :     std::map< std::string, tk::GetVarFn > OutVarFn() const
     643                 :          8 :     { return MultiMatOutVarFn(); }
     644                 :            : 
     645                 :            :     //! Return analytic field names to be output to file
     646                 :            :     //! \return Vector of strings labelling analytic fields output in file
     647                 :            :     std::vector< std::string > analyticFieldNames() const {
     648                 :          0 :       auto nmat = g_inputdeck.get< eq, tag::nmat >();
     649                 :            : 
     650                 :          0 :       return MultiMatFieldNames(nmat);
     651                 :            :     }
     652                 :            : 
     653                 :            :     //! Return surface field names to be output to file
     654                 :            :     //! \return Vector of strings labelling surface fields output in file
     655                 :            :     std::vector< std::string > surfNames() const
     656                 :          4 :     { return MultiMatSurfNames(); }
     657                 :            : 
     658                 :            :     //! Return time history field names to be output to file
     659                 :            :     //! \return Vector of strings labelling time history fields output in file
     660                 :            :     std::vector< std::string > histNames() const {
     661                 :          0 :       return MultiMatHistNames();
     662                 :            :     }
     663                 :            : 
     664                 :            :     //! Return surface field output going to file
     665                 :            :     std::vector< std::vector< tk::real > >
     666                 :            :     surfOutput( const inciter::FaceData& fd,
     667                 :            :       const tk::Fields& U,
     668                 :            :       const tk::Fields& P ) const
     669                 :            :     {
     670                 :          4 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     671                 :          4 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     672                 :            : 
     673                 :          4 :       return MultiMatSurfOutput( nmat, rdof, fd, U, P );
     674                 :            :     }
     675                 :            : 
     676                 :            :     //! Return time history field output evaluated at time history points
     677                 :            :     //! \param[in] h History point data
     678                 :            :     //! \param[in] inpoel Element-node connectivity
     679                 :            :     //! \param[in] coord Array of nodal coordinates
     680                 :            :     //! \param[in] U Array of unknowns
     681                 :            :     //! \param[in] P Array of primitive quantities
     682                 :            :     //! \return Vector of time history output of bulk flow quantities (density,
     683                 :            :     //!   velocity, total energy, pressure, and volume fraction) evaluated at 
     684                 :            :     //!   time history points
     685                 :            :     std::vector< std::vector< tk::real > >
     686                 :          0 :     histOutput( const std::vector< HistData >& h,
     687                 :            :                 const std::vector< std::size_t >& inpoel,
     688                 :            :                 const tk::UnsMesh::Coords& coord,
     689                 :            :                 const tk::Fields& U,
     690                 :            :                 const tk::Fields& P ) const
     691                 :            :     {
     692                 :          0 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     693                 :          0 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     694                 :            : 
     695                 :            :       const auto& x = coord[0];
     696                 :            :       const auto& y = coord[1];
     697                 :            :       const auto& z = coord[2];
     698                 :            : 
     699                 :          0 :       std::vector< std::vector< tk::real > > Up(h.size());
     700                 :            : 
     701                 :            :       std::size_t j = 0;
     702         [ -  - ]:          0 :       for (const auto& p : h) {
     703                 :          0 :         auto e = p.get< tag::elem >();
     704                 :          0 :         auto chp = p.get< tag::coord >();
     705                 :            : 
     706                 :            :         // Evaluate inverse Jacobian
     707                 :          0 :         std::array< std::array< tk::real, 3>, 4 > cp{{
     708                 :            :           {{ x[inpoel[4*e  ]], y[inpoel[4*e  ]], z[inpoel[4*e  ]] }},
     709                 :            :           {{ x[inpoel[4*e+1]], y[inpoel[4*e+1]], z[inpoel[4*e+1]] }},
     710                 :            :           {{ x[inpoel[4*e+2]], y[inpoel[4*e+2]], z[inpoel[4*e+2]] }},
     711                 :            :           {{ x[inpoel[4*e+3]], y[inpoel[4*e+3]], z[inpoel[4*e+3]] }} }};
     712                 :          0 :         auto J = tk::inverseJacobian( cp[0], cp[1], cp[2], cp[3] );
     713                 :            : 
     714                 :            :         // evaluate solution at history-point
     715                 :          0 :         std::array< tk::real, 3 > dc{{chp[0]-cp[0][0], chp[1]-cp[0][1],
     716         [ -  - ]:          0 :           chp[2]-cp[0][2]}};
     717         [ -  - ]:          0 :         auto B = tk::eval_basis(rdof, tk::dot(J[0],dc), tk::dot(J[1],dc),
     718                 :            :           tk::dot(J[2],dc));
     719         [ -  - ]:          0 :         auto uhp = eval_state(m_ncomp, rdof, rdof, e, U, B);
     720         [ -  - ]:          0 :         auto php = eval_state(nprim(), rdof, rdof, e, P, B);
     721                 :            : 
     722                 :            :         // store solution in history output vector
     723 [ -  - ][ -  - ]:          0 :         Up[j].resize(6+nmat, 0.0);
     724         [ -  - ]:          0 :         for (std::size_t k=0; k<nmat; ++k) {
     725                 :          0 :           Up[j][0] += uhp[densityIdx(nmat,k)];
     726                 :          0 :           Up[j][4] += uhp[energyIdx(nmat,k)];
     727                 :          0 :           Up[j][5] += php[pressureIdx(nmat,k)];
     728                 :          0 :           Up[j][6+k] = uhp[volfracIdx(nmat,k)];
     729                 :            :         }
     730         [ -  - ]:          0 :         Up[j][1] = php[velocityIdx(nmat,0)];
     731                 :          0 :         Up[j][2] = php[velocityIdx(nmat,1)];
     732                 :          0 :         Up[j][3] = php[velocityIdx(nmat,2)];
     733         [ -  - ]:          0 :         ++j;
     734                 :            :       }
     735                 :            : 
     736                 :          0 :       return Up;
     737                 :            :     }
     738                 :            : 
     739                 :            :     //! Return names of integral variables to be output to diagnostics file
     740                 :            :     //! \return Vector of strings labelling integral variables output
     741                 :            :     std::vector< std::string > names() const
     742                 :            :     {
     743                 :         20 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     744                 :         20 :       return MultiMatDiagNames(nmat);
     745                 :            :     }
     746                 :            : 
     747                 :            :     //! Return analytic solution (if defined by Problem) at xi, yi, zi, t
     748                 :            :     //! \param[in] xi X-coordinate at which to evaluate the analytic solution
     749                 :            :     //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
     750                 :            :     //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
     751                 :            :     //! \param[in] t Physical time at which to evaluate the analytic solution
     752                 :            :     //! \return Vector of analytic solution at given location and time
     753                 :            :     std::vector< tk::real >
     754                 :            :     analyticSolution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
     755                 :          0 :     { return Problem::analyticSolution( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
     756                 :            : 
     757                 :            :     //! Return analytic solution for conserved variables
     758                 :            :     //! \param[in] xi X-coordinate at which to evaluate the analytic solution
     759                 :            :     //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
     760                 :            :     //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
     761                 :            :     //! \param[in] t Physical time at which to evaluate the analytic solution
     762                 :            :     //! \return Vector of analytic solution at given location and time
     763                 :            :     std::vector< tk::real >
     764                 :            :     solution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
     765                 :          0 :     { return Problem::initialize( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
     766                 :            : 
     767                 :            :     //! Return cell-averaged specific total energy for an element
     768                 :            :     //! \param[in] e Element id for which total energy is required
     769                 :            :     //! \param[in] unk Vector of conserved quantities
     770                 :            :     //! \return Cell-averaged specific total energy for given element
     771                 :            :     tk::real sp_totalenergy(std::size_t e, const tk::Fields& unk) const
     772                 :            :     {
     773                 :          0 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     774                 :          0 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     775                 :            : 
     776                 :            :       tk::real sp_te(0.0);
     777                 :            :       // sum each material total energy
     778 [ -  - ][ -  - ]:          0 :       for (std::size_t k=0; k<nmat; ++k) {
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     779                 :          0 :         sp_te += unk(e, energyDofIdx(nmat,k,rdof,0));
     780                 :            :       }
     781                 :            :       return sp_te;
     782                 :            :     }
     783                 :            : 
     784                 :            :     //! Compute relevant sound speed for output
     785                 :            :     //! \param[in] nielem Number of internal elements
     786                 :            :     //! \param[in] U Solution vector at recent time step
     787                 :            :     //! \param[in] P Primitive vector at recent time step
     788                 :            :     //! \param[in,out] ss Sound speed vector
     789                 :          4 :     void soundspeed(
     790                 :            :       std::size_t nielem,
     791                 :            :       const tk::Fields& U,
     792                 :            :       const tk::Fields& P,
     793                 :            :       std::vector< tk::real >& ss) const
     794                 :            :     {
     795                 :            :       Assert( ss.size() == nielem, "Size of sound speed vector incorrect " );
     796                 :            : 
     797                 :          4 :       const auto ndof = g_inputdeck.get< tag::ndof >();
     798                 :          4 :       const auto rdof = g_inputdeck.get< tag::rdof >();
     799                 :          4 :       const auto use_mass_avg =
     800                 :            :         g_inputdeck.get< tag::multimat, tag::dt_sos_massavg >();
     801                 :          4 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     802                 :          4 :       std::size_t ncomp = U.nprop()/rdof;
     803                 :          4 :       std::size_t nprim = P.nprop()/rdof;
     804                 :            : 
     805 [ +  - ][ -  - ]:          4 :       std::vector< tk::real > ugp(ncomp, 0.0), pgp(nprim, 0.0);
     806                 :            : 
     807         [ +  + ]:       6068 :       for (std::size_t e=0; e<nielem; ++e) {
     808                 :            :         // basis function at centroid
     809 [ +  - ][ -  - ]:       6064 :         std::vector< tk::real > B(rdof, 0.0);
     810                 :       6064 :         B[0] = 1.0;
     811                 :            : 
     812                 :            :         // get conserved quantities
     813         [ +  - ]:       6064 :         ugp = eval_state(ncomp, rdof, ndof, e, U, B);
     814                 :            :         // get primitive quantities
     815         [ +  - ]:       6064 :         pgp = eval_state(nprim, rdof, ndof, e, P, B);
     816                 :            : 
     817                 :            :         // acoustic speed (this should be consistent with time-step calculation)
     818                 :       6064 :         ss[e] = 0.0;
     819                 :            :         tk::real mixtureDensity = 0.0;
     820         [ +  + ]:      18192 :         for (std::size_t k=0; k<nmat; ++k)
     821                 :            :         {
     822         [ -  + ]:      12128 :           if (use_mass_avg > 0)
     823                 :            :           {
     824                 :            :             // mass averaging SoS
     825         [ -  - ]:          0 :             ss[e] += ugp[densityIdx(nmat,k)]*
     826         [ -  - ]:          0 :               m_mat_blk[k].compute< EOS::soundspeed >(
     827                 :            :               ugp[densityIdx(nmat, k)], pgp[pressureIdx(nmat, k)],
     828                 :            :               ugp[volfracIdx(nmat, k)], k );
     829                 :            : 
     830                 :          0 :             mixtureDensity += ugp[densityIdx(nmat,k)];
     831                 :            :           }
     832                 :            :           else
     833                 :            :           {
     834         [ +  + ]:      12128 :             if (ugp[volfracIdx(nmat, k)] > 1.0e-04)
     835                 :            :             {
     836         [ +  - ]:      12356 :               ss[e] = std::max( ss[e], m_mat_blk[k].compute< EOS::soundspeed >(
     837                 :            :                 ugp[densityIdx(nmat, k)], pgp[pressureIdx(nmat, k)],
     838         [ +  + ]:       6178 :                 ugp[volfracIdx(nmat, k)], k ) );
     839                 :            :             }
     840                 :            :           }
     841                 :            :         }
     842         [ -  + ]:       6064 :         if (use_mass_avg > 0) ss[e] /= mixtureDensity;
     843                 :            :       }
     844                 :          4 :     }
     845                 :            : 
     846                 :            :   private:
     847                 :            :     //! Physics policy
     848                 :            :     const Physics m_physics;
     849                 :            :     //! Number of components in this PDE system
     850                 :            :     const ncomp_t m_ncomp;
     851                 :            :     //! Riemann solver
     852                 :            :     tk::RiemannFluxFn m_riemann;
     853                 :            :     //! BC configuration
     854                 :            :     BCStateFn m_bc;
     855                 :            :     //! EOS material block
     856                 :            :     std::vector< EOS > m_mat_blk;
     857                 :            : 
     858                 :            :     //! Evaluate conservative part of physical flux function for this PDE system
     859                 :            :     //! \param[in] ncomp Number of scalar components in this PDE system
     860                 :            :     //! \param[in] ugp Numerical solution at the Gauss point at which to
     861                 :            :     //!   evaluate the flux
     862                 :            :     //! \return Flux vectors for all components in this PDE system
     863                 :            :     //! \note The function signature must follow tk::FluxFn
     864                 :            :     static tk::FluxFn::result_type
     865                 :            :     flux( ncomp_t ncomp,
     866                 :            :           const std::vector< EOS >& mat_blk,
     867                 :            :           const std::vector< tk::real >& ugp,
     868                 :            :           const std::vector< std::array< tk::real, 3 > >& )
     869                 :            :     {
     870                 :            :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     871                 :            : 
     872                 :            :       return tk::fluxTerms(ncomp, nmat, mat_blk, ugp);
     873                 :            :     }
     874                 :            : 
     875                 :            :     //! \brief Boundary state function providing the left and right state of a
     876                 :            :     //!   face at Dirichlet boundaries
     877                 :            :     //! \param[in] ncomp Number of scalar components in this PDE system
     878                 :            :     //! \param[in] ul Left (domain-internal) state
     879                 :            :     //! \param[in] x X-coordinate at which to compute the states
     880                 :            :     //! \param[in] y Y-coordinate at which to compute the states
     881                 :            :     //! \param[in] z Z-coordinate at which to compute the states
     882                 :            :     //! \param[in] t Physical time
     883                 :            :     //! \return Left and right states for all scalar components in this PDE
     884                 :            :     //!   system
     885                 :            :     //! \note The function signature must follow tk::StateFn. For multimat, the
     886                 :            :     //!   left or right state is the vector of conserved quantities, followed by
     887                 :            :     //!   the vector of primitive quantities appended to it.
     888                 :            :     static tk::StateFn::result_type
     889                 :          0 :     dirichlet( ncomp_t ncomp,
     890                 :            :                const std::vector< EOS >& mat_blk,
     891                 :            :                const std::vector< tk::real >& ul, tk::real x, tk::real y,
     892                 :            :                tk::real z, tk::real t, const std::array< tk::real, 3 >& )
     893                 :            :     {
     894                 :          0 :       auto nmat = g_inputdeck.get< tag::multimat, tag::nmat >();
     895                 :            : 
     896                 :          0 :       auto ur = Problem::initialize( ncomp, mat_blk, x, y, z, t );
     897                 :            :       Assert( ur.size() == ncomp, "Incorrect size for boundary state vector" );
     898                 :            : 
     899         [ -  - ]:          0 :       ur.resize(ul.size());
     900                 :            : 
     901                 :            :       tk::real rho(0.0);
     902         [ -  - ]:          0 :       for (std::size_t k=0; k<nmat; ++k)
     903                 :          0 :         rho += ur[densityIdx(nmat, k)];
     904                 :            : 
     905                 :            :       // get primitives in boundary state
     906                 :            : 
     907                 :            :       // velocity
     908                 :          0 :       ur[ncomp+velocityIdx(nmat, 0)] = ur[momentumIdx(nmat, 0)] / rho;
     909                 :          0 :       ur[ncomp+velocityIdx(nmat, 1)] = ur[momentumIdx(nmat, 1)] / rho;
     910                 :          0 :       ur[ncomp+velocityIdx(nmat, 2)] = ur[momentumIdx(nmat, 2)] / rho;
     911                 :            : 
     912                 :            :       // material pressures
     913         [ -  - ]:          0 :       for (std::size_t k=0; k<nmat; ++k)
     914                 :            :       {
     915         [ -  - ]:          0 :         auto gk = getDeformGrad(nmat, k, ur);
     916         [ -  - ]:          0 :         ur[ncomp+pressureIdx(nmat, k)] = mat_blk[k].compute< EOS::pressure >(
     917                 :            :           ur[densityIdx(nmat, k)], ur[ncomp+velocityIdx(nmat, 0)],
     918                 :            :           ur[ncomp+velocityIdx(nmat, 1)], ur[ncomp+velocityIdx(nmat, 2)],
     919         [ -  - ]:          0 :           ur[energyIdx(nmat, k)], ur[volfracIdx(nmat, k)], k, gk );
     920                 :            :       }
     921                 :            : 
     922                 :            :       Assert( ur.size() == ncomp+nmat+3, "Incorrect size for appended "
     923                 :            :               "boundary state vector" );
     924                 :            : 
     925         [ -  - ]:          0 :       return {{ std::move(ul), std::move(ur) }};
     926                 :            :     }
     927                 :            : 
     928                 :            :     // Other boundary condition types that do not depend on "Problem" should be
     929                 :            :     // added in BCFunctions.hpp
     930                 :            : };
     931                 :            : 
     932                 :            : } // fv::
     933                 :            : 
     934                 :            : } // inciter::
     935                 :            : 
     936                 :            : #endif // FVMultiMat_h

Generated by: LCOV version 1.14