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

Generated by: LCOV version 1.14