Quinoa all test code coverage report
Current view: top level - PDE/CompFlow - CGCompFlow.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 610 682 89.4 %
Date: 2025-08-06 10:15:14 Functions: 156 352 44.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 415 802 51.7 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/PDE/CompFlow/CGCompFlow.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 single-material flow using continuous Galerkin
       9                 :            :   \details   This file implements the physics operators governing compressible
      10                 :            :     single-material flow using continuous Galerkin discretization.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : #ifndef CGCompFlow_h
      14                 :            : #define CGCompFlow_h
      15                 :            : 
      16                 :            : #include <cmath>
      17                 :            : #include <algorithm>
      18                 :            : #include <unordered_set>
      19                 :            : #include <unordered_map>
      20                 :            : 
      21                 :            : #include "DerivedData.hpp"
      22                 :            : #include "Exception.hpp"
      23                 :            : #include "Vector.hpp"
      24                 :            : #include "Mesh/Around.hpp"
      25                 :            : #include "Reconstruction.hpp"
      26                 :            : #include "Problem/FieldOutput.hpp"
      27                 :            : #include "Problem/BoxInitialization.hpp"
      28                 :            : #include "Riemann/Rusanov.hpp"
      29                 :            : #include "NodeBC.hpp"
      30                 :            : #include "EoS/EOS.hpp"
      31                 :            : #include "History.hpp"
      32                 :            : #include "Table.hpp"
      33                 :            : 
      34                 :            : namespace inciter {
      35                 :            : 
      36                 :            : extern ctr::InputDeck g_inputdeck;
      37                 :            : 
      38                 :            : namespace cg {
      39                 :            : 
      40                 :            : //! \brief CompFlow used polymorphically with tk::CGPDE
      41                 :            : //! \details The template arguments specify policies and are used to configure
      42                 :            : //!   the behavior of the class. The policies are:
      43                 :            : //!   - Physics - physics configuration, see PDE/CompFlow/Physics.h
      44                 :            : //!   - Problem - problem configuration, see PDE/CompFlow/Problems.h
      45                 :            : //! \note The default physics is Euler, set in inciter::deck::check_compflow()
      46                 :            : template< class Physics, class Problem >
      47                 :            : class CompFlow {
      48                 :            : 
      49                 :            :   private:
      50                 :            :     using ncomp_t = tk::ncomp_t;
      51                 :            :     using eq = tag::compflow;
      52                 :            :     using real = tk::real;
      53                 :            : 
      54                 :            :     static constexpr std::size_t m_ncomp = 5;
      55                 :            :     static constexpr real muscl_eps = 1.0e-9;
      56                 :            :     static constexpr real muscl_const = 1.0/3.0;
      57                 :            :     static constexpr real muscl_m1 = 1.0 - muscl_const;
      58                 :            :     static constexpr real muscl_p1 = 1.0 + muscl_const;
      59                 :            : 
      60                 :            :   public:
      61                 :            :     //! \brief Constructor
      62                 :        249 :     explicit CompFlow() :
      63                 :            :       m_physics(),
      64                 :            :       m_problem(),
      65                 :            :       m_fr(),
      66                 :            :       m_fp(),
      67                 :        249 :       m_fu()
      68                 :            :     {
      69 [ -  + ][ -  - ]:        249 :       Assert( g_inputdeck.get< tag::ncomp >() == m_ncomp,
         [ -  - ][ -  - ]
                 [ -  - ]
      70                 :            :        "Number of CompFlow PDE components must be " + std::to_string(m_ncomp) );
      71                 :            : 
      72                 :            :       // EoS initialization
      73                 :            :       const auto& matprop =
      74                 :        249 :         g_inputdeck.get< tag::material >();
      75                 :            :       const auto& matidxmap =
      76                 :        249 :         g_inputdeck.get< tag::matidxmap >();
      77                 :        249 :       auto mateos = matprop[matidxmap.get< tag::eosidx >()[0]].get<tag::eos>();
      78         [ +  - ]:        249 :       m_mat_blk.emplace_back( mateos, EqType::compflow, 0 );
      79                 :            : 
      80                 :            :       // Boundary condition configurations
      81         [ +  + ]:        506 :       for (const auto& bci : g_inputdeck.get< tag::bc >()) {
      82                 :            :         // freestream quantities
      83                 :        257 :         m_fr = bci.get< tag::density >();
      84                 :        257 :         m_fp = bci.get< tag::pressure >();
      85         [ +  - ]:        257 :         m_fu = bci.get< tag::velocity >();
      86                 :            :       }
      87                 :        249 :     }
      88                 :            : 
      89                 :            :     //! Determine nodes that lie inside the user-defined IC box and mesh blocks
      90                 :            :     //! \param[in] coord Mesh node coordinates
      91                 :            :     //! \param[in] inpoel Element node connectivity
      92                 :            :     //! \param[in,out] inbox List of nodes at which box user ICs are set for
      93                 :            :     //!    each IC box
      94                 :            :     //! \param[in] elemblkid Element ids associated with mesh block ids where
      95                 :            :     //!   user ICs are set
      96                 :            :     //! \param[in,out] nodeblkid Node ids associated to mesh block ids, where
      97                 :            :     //!   user ICs are set
      98                 :            :     //! \param[in,out] nuserblk number of mesh blocks where user ICs are set
      99                 :        722 :     void IcBoxNodes( const tk::UnsMesh::Coords& coord,
     100                 :            :       const std::vector< std::size_t >& inpoel,
     101                 :            :       const std::unordered_map< std::size_t, std::set< std::size_t > >& elemblkid,
     102                 :            :       std::vector< std::unordered_set< std::size_t > >& inbox,
     103                 :            :       std::unordered_map< std::size_t, std::set< std::size_t > >& nodeblkid,
     104                 :            :       std::size_t& nuserblk ) const
     105                 :            :     {
     106                 :        722 :       const auto& x = coord[0];
     107                 :        722 :       const auto& y = coord[1];
     108                 :        722 :       const auto& z = coord[2];
     109                 :            : 
     110                 :            :       // Detect if user has configured IC boxes
     111                 :        722 :       const auto& icbox = g_inputdeck.get<tag::ic, tag::box>();
     112         [ +  + ]:        722 :       if (!icbox.empty()) {
     113                 :          5 :         std::size_t bcnt = 0;
     114         [ +  + ]:         11 :         for (const auto& b : icbox) {   // for all boxes for this eq
     115         [ +  - ]:          6 :           inbox.emplace_back();
     116         [ +  - ]:          6 :           std::vector< tk::real > box
     117                 :          6 :             { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
     118                 :          6 :               b.template get< tag::ymin >(), b.template get< tag::ymax >(),
     119                 :          6 :               b.template get< tag::zmin >(), b.template get< tag::zmax >() };
     120                 :            : 
     121                 :            :           // Determine orientation of box
     122                 :         18 :           std::array< tk::real, 3 > b_orientn{{
     123                 :          6 :             b.template get< tag::orientation >()[0],
     124                 :          6 :             b.template get< tag::orientation >()[1],
     125                 :          6 :             b.template get< tag::orientation >()[2] }};
     126                 :          6 :           std::array< tk::real, 3 > b_centroid{{ 0.5*(box[0]+box[1]),
     127                 :          6 :             0.5*(box[2]+box[3]), 0.5*(box[4]+box[5]) }};
     128                 :            : 
     129                 :          6 :           const auto eps = std::numeric_limits< tk::real >::epsilon();
     130                 :            :           // Determine which nodes lie in the IC box
     131 [ +  - ][ +  - ]:         18 :           if ( std::any_of( begin(box), end(box), [=](auto p)
     132                 :          6 :                             { return abs(p) > eps; } ) )
     133                 :            :           {
     134                 :            :             // Transform box to reference space
     135                 :          6 :             std::array< tk::real, 3 > b_min{{box[0], box[2], box[4]}};
     136                 :          6 :             std::array< tk::real, 3 > b_max{{box[1], box[3], box[5]}};
     137                 :          6 :             tk::movePoint(b_centroid, b_min);
     138                 :          6 :             tk::movePoint(b_centroid, b_max);
     139                 :            : 
     140         [ +  + ]:       5137 :             for (ncomp_t i=0; i<x.size(); ++i) {
     141                 :       5131 :               std::array< tk::real, 3 > node{{ x[i], y[i], z[i] }};
     142                 :            :               // Transform node to reference space of box
     143                 :       5131 :               tk::movePoint(b_centroid, node);
     144                 :       5131 :               tk::rotatePoint({{-b_orientn[0], -b_orientn[1], -b_orientn[2]}},
     145                 :            :                 node);
     146         [ +  + ]:       6971 :               if ( node[0]>b_min[0] && node[0]<b_max[0] &&
     147 [ +  + ][ +  + ]:       1598 :                 node[1]>b_min[1] && node[1]<b_max[1] &&
     148 [ +  + ][ +  + ]:       6971 :                 node[2]>b_min[2] && node[2]<b_max[2] )
         [ +  + ][ +  + ]
     149                 :            :               {
     150         [ +  - ]:        759 :                 inbox[bcnt].insert( i );
     151                 :            :               }
     152                 :            :             }
     153                 :            :           }
     154                 :          6 :           ++bcnt;
     155                 :            :         }
     156                 :            :       }
     157                 :            : 
     158                 :            :       // size IC mesh blocks volume vector
     159                 :        722 :       const auto& mblks = g_inputdeck.get< tag::ic, tag::meshblock >();
     160                 :            :       // if mesh blocks have been specified for this system
     161         [ -  + ]:        722 :       if (!mblks.empty()) {
     162                 :          0 :         std::size_t idMax(0);
     163         [ -  - ]:          0 :         for (const auto& imb : mblks) {
     164                 :          0 :           idMax = std::max(idMax, imb.get< tag::blockid >());
     165                 :            :         }
     166                 :            :         // size is idMax+1 since block ids are usually 1-based
     167                 :          0 :         nuserblk = nuserblk+idMax+1;
     168                 :            :       }
     169                 :            : 
     170                 :            :       // determine node set for IC mesh blocks
     171         [ +  + ]:       1450 :       for (const auto& [blid, elset] : elemblkid) {
     172         [ +  - ]:        728 :         if (!elset.empty()) {
     173         [ +  - ]:        728 :           auto& ndset = nodeblkid[blid];
     174         [ +  + ]:     179414 :           for (auto ie : elset) {
     175 [ +  + ][ +  - ]:     893430 :             for (std::size_t i=0; i<4; ++i) ndset.insert(inpoel[4*ie+i]);
     176                 :            :           }
     177                 :            :         }
     178                 :            :       }
     179                 :        722 :     }
     180                 :            : 
     181                 :            :     //! Initalize the compressible flow equations, prepare for time integration
     182                 :            :     //! \param[in] coord Mesh node coordinates
     183                 :            :     //! \param[in,out] unk Array of unknowns
     184                 :            :     //! \param[in] t Physical time
     185                 :            :     //! \param[in] V Discrete volume of user-defined IC box
     186                 :            :     //! \param[in] inbox List of nodes at which box user ICs are set (for each
     187                 :            :     //!    box IC)
     188                 :            :     //! \param[in] nodeblkid Node ids associated to mesh block ids, where
     189                 :            :     //!   user ICs are set
     190                 :            :     //! \param[in] blkvols Vector of discrete volumes of each block where user
     191                 :            :     //!   ICs are set
     192                 :        738 :     void initialize(
     193                 :            :       const std::array< std::vector< real >, 3 >& coord,
     194                 :            :       tk::Fields& unk,
     195                 :            :       real t,
     196                 :            :       real V,
     197                 :            :       const std::vector< std::unordered_set< std::size_t > >& inbox,
     198                 :            :       const std::vector< tk::real >& blkvols,
     199                 :            :       const std::unordered_map< std::size_t, std::set< std::size_t > >&
     200                 :            :         nodeblkid ) const
     201                 :            :     {
     202 [ -  + ][ -  - ]:        738 :       Assert( coord[0].size() == unk.nunk(), "Size mismatch" );
         [ -  - ][ -  - ]
     203                 :            : 
     204                 :        738 :       const auto& x = coord[0];
     205                 :        738 :       const auto& y = coord[1];
     206                 :        738 :       const auto& z = coord[2];
     207                 :            : 
     208                 :        738 :       const auto& ic = g_inputdeck.get< tag::ic >();
     209                 :        738 :       const auto& icbox = ic.get< tag::box >();
     210                 :        738 :       const auto& mblks = ic.get< tag::meshblock >();
     211                 :            : 
     212                 :        738 :       const auto eps = 1000.0 * std::numeric_limits< tk::real >::epsilon();
     213                 :            : 
     214                 :        738 :       tk::real bgpre = ic.get< tag::pressure >();
     215                 :            : 
     216                 :        738 :       auto c_v = getmatprop< tag::cv >();
     217                 :            : 
     218                 :            :       // Set initial and boundary conditions using problem policy
     219         [ +  + ]:      66904 :       for (ncomp_t i=0; i<x.size(); ++i) {
     220         [ +  - ]:      66166 :         auto s = Problem::initialize( m_ncomp, m_mat_blk, x[i], y[i], z[i], t );
     221                 :            : 
     222                 :            :         // initialize the user-defined box IC
     223         [ +  + ]:      66166 :         if (!icbox.empty()) {
     224                 :       4640 :           std::size_t bcnt = 0;
     225         [ +  + ]:       9771 :           for (const auto& b : icbox) { // for all boxes
     226 [ +  - ][ +  - ]:       5131 :             if (inbox.size() > bcnt && inbox[bcnt].find(i) != inbox[bcnt].end())
         [ +  + ][ +  + ]
     227                 :            :             {
     228         [ +  - ]:       1518 :               std::vector< tk::real > box
     229                 :        759 :               { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
     230                 :        759 :                 b.template get< tag::ymin >(), b.template get< tag::ymax >(),
     231                 :        759 :                 b.template get< tag::zmin >(), b.template get< tag::zmax >() };
     232                 :        759 :               auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
     233         [ -  + ]:        759 :               if (V_ex < eps) V = 1.0;
     234         [ +  - ]:        759 :               initializeBox<ctr::boxList>( m_mat_blk, V_ex/V,
     235                 :            :                 V_ex, t, b, bgpre, c_v, s );
     236                 :            :             }
     237                 :       5131 :             ++bcnt;
     238                 :            :           }
     239                 :            :         }
     240                 :            : 
     241                 :            :         // initialize user-defined mesh block ICs
     242         [ -  + ]:      66166 :         for (const auto& b : mblks) { // for all blocks
     243                 :          0 :           auto blid = b.get< tag::blockid >();
     244                 :          0 :           auto V_ex = b.get< tag::volume >();
     245 [ -  - ][ -  - ]:          0 :           if (blid >= blkvols.size()) Throw("Block volume not found");
         [ -  - ][ -  - ]
     246 [ -  - ][ -  - ]:          0 :           if (nodeblkid.find(blid) != nodeblkid.end()) {
     247         [ -  - ]:          0 :             const auto& ndset = tk::cref_find(nodeblkid, blid);
     248 [ -  - ][ -  - ]:          0 :             if (ndset.find(i) != ndset.end()) {
     249         [ -  - ]:          0 :               initializeBox<ctr::meshblockList>( m_mat_blk,
     250                 :          0 :                 V_ex/blkvols[blid], V_ex, t, b, bgpre, c_v, s );
     251                 :            :             }
     252                 :            :           }
     253                 :            :         }
     254                 :            : 
     255         [ +  - ]:      66166 :         unk(i,0) = s[0]; // rho
     256         [ +  - ]:      66166 :         unk(i,1) = s[1]; // rho * u
     257         [ +  - ]:      66166 :         unk(i,2) = s[2]; // rho * v
     258         [ +  - ]:      66166 :         unk(i,3) = s[3]; // rho * w
     259         [ +  - ]:      66166 :         unk(i,4) = s[4]; // rho * e, e: total = kinetic + internal
     260                 :            :       }
     261                 :        738 :     }
     262                 :            : 
     263                 :            :     //! Query the fluid velocity
     264                 :            :     //! \param[in] u Solution vector of conserved variables
     265                 :            :     //! \param[in,out] v Velocity components
     266                 :      28461 :     void velocity( const tk::Fields& u, tk::UnsMesh::Coords& v ) const {
     267         [ +  + ]:     113844 :       for (std::size_t j=0; j<3; ++j) {
     268                 :            :         // extract momentum
     269                 :      85383 :         v[j] = u.extract_comp( 1+j );
     270 [ -  + ][ -  - ]:      85383 :         Assert( v[j].size() == u.nunk(), "Size mismatch" );
         [ -  - ][ -  - ]
     271                 :            :         // divide by density
     272         [ +  + ]:   11017068 :         for (std::size_t i=0; i<u.nunk(); ++i) v[j][i] /= u(i,0);
     273                 :            :       }
     274                 :      28461 :     }
     275                 :            : 
     276                 :            :     //! Query the sound speed
     277                 :            :     //! \param[in] U Solution vector of conserved variables
     278                 :            :     //! \param[in,out] s Speed of sound in mesh nodes
     279                 :      28461 :     void soundspeed( const tk::Fields& U, std::vector< tk::real >& s ) const {
     280                 :      28461 :       s.resize( U.nunk() );
     281         [ +  + ]:    3672356 :       for (std::size_t i=0; i<U.nunk(); ++i) {
     282         [ +  - ]:    3643895 :         auto r  = U(i,0);
     283         [ +  - ]:    3643895 :         auto ru = U(i,1);
     284         [ +  - ]:    3643895 :         auto rv = U(i,2);
     285         [ +  - ]:    3643895 :         auto rw = U(i,3);
     286         [ +  - ]:    3643895 :         auto re = U(i,4);
     287         [ +  - ]:    3643895 :         auto p = m_mat_blk[0].compute< EOS::pressure >(r, ru/r, rv/r, rw/r, re);
     288         [ +  - ]:    3643895 :         s[i] = m_mat_blk[0].compute< EOS::soundspeed >( r, p );
     289                 :            :       }
     290                 :      28461 :     }
     291                 :            : 
     292                 :            :     //! Return analytic solution (if defined by Problem) at xi, yi, zi, t
     293                 :            :     //! \param[in] xi X-coordinate
     294                 :            :     //! \param[in] yi Y-coordinate
     295                 :            :     //! \param[in] zi Z-coordinate
     296                 :            :     //! \param[in] t Physical time
     297                 :            :     //! \return Vector of analytic solution at given location and time
     298                 :            :     std::vector< real >
     299                 :      25005 :     analyticSolution( real xi, real yi, real zi, real t ) const
     300                 :      25005 :     { return Problem::analyticSolution( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
     301                 :            : 
     302                 :            :     //! Return analytic solution for conserved variables
     303                 :            :     //! \param[in] xi X-coordinate at which to evaluate the analytic solution
     304                 :            :     //! \param[in] yi Y-coordinate at which to evaluate the analytic solution
     305                 :            :     //! \param[in] zi Z-coordinate at which to evaluate the analytic solution
     306                 :            :     //! \param[in] t Physical time at which to evaluate the analytic solution
     307                 :            :     //! \return Vector of analytic solution at given location and time
     308                 :            :     std::vector< tk::real >
     309                 :     922186 :     solution( tk::real xi, tk::real yi, tk::real zi, tk::real t ) const
     310                 :     922186 :     { return Problem::initialize( m_ncomp, m_mat_blk, xi, yi, zi, t ); }
     311                 :            : 
     312                 :            :     //! \brief Compute nodal gradients of primitive variables for ALECG along
     313                 :            :     //!   chare-boundary
     314                 :            :     //! \param[in] coord Mesh node coordinates
     315                 :            :     //! \param[in] inpoel Mesh element connectivity
     316                 :            :     //! \param[in] bndel List of elements contributing to chare-boundary nodes
     317                 :            :     //! \param[in] gid Local->global node id map
     318                 :            :     //! \param[in] bid Local chare-boundary node ids (value) associated to
     319                 :            :     //!    global node ids (key)
     320                 :            :     //! \param[in] U Solution vector at recent time step
     321                 :            :     //! \param[in,out] G Nodal gradients of primitive variables
     322                 :            :     //! \details This function only computes local contributions to gradients
     323                 :            :     //!   at chare-boundary nodes. Internal node gradients are calculated as
     324                 :            :     //!   required, and do not need to be stored.
     325                 :      37026 :     void chBndGrad( const std::array< std::vector< real >, 3 >& coord,
     326                 :            :                     const std::vector< std::size_t >& inpoel,
     327                 :            :                     const std::vector< std::size_t >& bndel,
     328                 :            :                     const std::vector< std::size_t >& gid,
     329                 :            :                     const std::unordered_map< std::size_t, std::size_t >& bid,
     330                 :            :                     const tk::Fields& U,
     331                 :            :                     tk::Fields& G ) const
     332                 :            :     {
     333 [ -  + ][ -  - ]:      37026 :       Assert( U.nunk() == coord[0].size(), "Number of unknowns in solution "
         [ -  - ][ -  - ]
     334                 :            :               "vector at recent time step incorrect" );
     335                 :            : 
     336                 :            :       // compute gradients of primitive variables in points
     337                 :      37026 :       G.fill( 0.0 );
     338                 :            : 
     339                 :            :       // access node cooordinates
     340                 :      37026 :       const auto& x = coord[0];
     341                 :      37026 :       const auto& y = coord[1];
     342                 :      37026 :       const auto& z = coord[2];
     343                 :            : 
     344         [ +  + ]:    4610796 :       for (auto e : bndel) {  // elements contributing to chare boundary nodes
     345                 :            :         // access node IDs
     346                 :    4573770 :         std::size_t N[4] =
     347                 :    4573770 :           { inpoel[e*4+0], inpoel[e*4+1], inpoel[e*4+2], inpoel[e*4+3] };
     348                 :            :         // compute element Jacobi determinant, J = 6V
     349                 :    4573770 :         real bax = x[N[1]]-x[N[0]];
     350                 :    4573770 :         real bay = y[N[1]]-y[N[0]];
     351                 :    4573770 :         real baz = z[N[1]]-z[N[0]];
     352                 :    4573770 :         real cax = x[N[2]]-x[N[0]];
     353                 :    4573770 :         real cay = y[N[2]]-y[N[0]];
     354                 :    4573770 :         real caz = z[N[2]]-z[N[0]];
     355                 :    4573770 :         real dax = x[N[3]]-x[N[0]];
     356                 :    4573770 :         real day = y[N[3]]-y[N[0]];
     357                 :    4573770 :         real daz = z[N[3]]-z[N[0]];
     358                 :    4573770 :         auto J = tk::triple( bax, bay, baz, cax, cay, caz, dax, day, daz );
     359 [ -  + ][ -  - ]:    4573770 :         ErrChk( J > 0, "Element Jacobian non-positive" );
         [ -  - ][ -  - ]
     360                 :    4573770 :         auto J24 = J/24.0;
     361                 :            :         // shape function derivatives, nnode*ndim [4][3]
     362                 :            :         real g[4][3];
     363                 :    4573770 :         tk::crossdiv( cax, cay, caz, dax, day, daz, J,
     364                 :            :                       g[1][0], g[1][1], g[1][2] );
     365                 :    4573770 :         tk::crossdiv( dax, day, daz, bax, bay, baz, J,
     366                 :            :                       g[2][0], g[2][1], g[2][2] );
     367                 :    4573770 :         tk::crossdiv( bax, bay, baz, cax, cay, caz, J,
     368                 :            :                       g[3][0], g[3][1], g[3][2] );
     369         [ +  + ]:   18295080 :         for (std::size_t i=0; i<3; ++i)
     370                 :   13721310 :           g[0][i] = -g[1][i] - g[2][i] - g[3][i];
     371                 :            :         // scatter-add gradient contributions to boundary nodes
     372         [ +  + ]:   22868850 :         for (std::size_t a=0; a<4; ++a) {
     373         [ +  - ]:   18295080 :           auto i = bid.find( gid[N[a]] );
     374         [ +  + ]:   18295080 :           if (i != end(bid)) {
     375                 :            :             real u[5];
     376         [ +  + ]:   59976840 :             for (std::size_t b=0; b<4; ++b) {
     377         [ +  - ]:   47981472 :               u[0] = U(N[b],0);
     378         [ +  - ]:   47981472 :               u[1] = U(N[b],1)/u[0];
     379         [ +  - ]:   47981472 :               u[2] = U(N[b],2)/u[0];
     380         [ +  - ]:   47981472 :               u[3] = U(N[b],3)/u[0];
     381         [ +  - ]:   47981472 :               u[4] = U(N[b],4)/u[0]
     382                 :   47981472 :                      - 0.5*(u[1]*u[1] + u[2]*u[2] + u[3]*u[3]);
     383         [ +  + ]:  287888832 :               for (std::size_t c=0; c<5; ++c)
     384         [ +  + ]:  959629440 :                 for (std::size_t j=0; j<3; ++j)
     385         [ +  - ]:  719722080 :                   G(i->second,c*3+j) += J24 * g[b][j] * u[c];
     386                 :            :             }
     387                 :            :           }
     388                 :            :         }
     389                 :            :       }
     390                 :      37026 :     }
     391                 :            : 
     392                 :            :     //! Compute right hand side for ALECG
     393                 :            :     //! \param[in] t Physical time
     394                 :            :     //! \param[in] coord Mesh node coordinates
     395                 :            :     //! \param[in] inpoel Mesh element connectivity
     396                 :            :     //! \param[in] triinpoel Boundary triangle face connecitivity with local ids
     397                 :            :     //! \param[in] bid Local chare-boundary node ids (value) associated to
     398                 :            :     //!    global node ids (key)
     399                 :            :     //! \param[in] gid Local->glocal node ids
     400                 :            :     //! \param[in] lid Global->local node ids
     401                 :            :     //! \param[in] dfn Dual-face normals
     402                 :            :     //! \param[in] psup Points surrounding points
     403                 :            :     //! \param[in] esup Elements surrounding points
     404                 :            :     //! \param[in] symbctri Vector with 1 at symmetry BC boundary triangles
     405                 :            :     //! \param[in] slipwallbctri Vector with 1 at slip BC boundary triangles
     406                 :            :     //! \param[in] vol Nodal volumes
     407                 :            :     //! \param[in] edgenode Local node IDs of edges
     408                 :            :     //! \param[in] edgeid Edge ids in the order of access
     409                 :            :     //! \param[in] boxnodes Mesh node ids within user-defined IC boxes
     410                 :            :     //! \param[in] G Nodal gradients for chare-boundary nodes
     411                 :            :     //! \param[in] U Solution vector at recent time step
     412                 :            :     //! \param[in] W Mesh velocity
     413                 :            :     //! \param[in] tp Physical time for each mesh node
     414                 :            :     //! \param[in] V Total box volume
     415                 :            :     //! \param[in,out] R Right-hand side vector computed
     416                 :            :     //! \param[in,out] srcFlag Whether the energy source was added
     417                 :      37026 :     void rhs( real t,
     418                 :            :               const std::array< std::vector< real >, 3 >& coord,
     419                 :            :               const std::vector< std::size_t >& inpoel,
     420                 :            :               const std::vector< std::size_t >& triinpoel,
     421                 :            :               const std::vector< std::size_t >& gid,
     422                 :            :               const std::unordered_map< std::size_t, std::size_t >& bid,
     423                 :            :               const std::unordered_map< std::size_t, std::size_t >& lid,
     424                 :            :               const std::vector< real >& dfn,
     425                 :            :               const std::pair< std::vector< std::size_t >,
     426                 :            :                                std::vector< std::size_t > >& psup,
     427                 :            :               const std::pair< std::vector< std::size_t >,
     428                 :            :                                std::vector< std::size_t > >& esup,
     429                 :            :               const std::vector< int >& symbctri,
     430                 :            :               const std::vector< int >& slipwallbctri,
     431                 :            :               const std::vector< real >& vol,
     432                 :            :               const std::vector< std::size_t >& edgenode,
     433                 :            :               const std::vector< std::size_t >& edgeid,
     434                 :            :               const std::vector< std::unordered_set< std::size_t > >& boxnodes,
     435                 :            :               const tk::Fields& G,
     436                 :            :               const tk::Fields& U,
     437                 :            :               const tk::Fields& W,
     438                 :            :               const std::vector< tk::real >& tp,
     439                 :            :               real V,
     440                 :            :               tk::Fields& R,
     441                 :            :               std::vector< int >& srcFlag ) const
     442                 :            :     {
     443 [ -  + ][ -  - ]:      37026 :       Assert( G.nprop() == m_ncomp*3,
         [ -  - ][ -  - ]
     444                 :            :               "Number of components in gradient vector incorrect" );
     445 [ -  + ][ -  - ]:      37026 :       Assert( U.nunk() == coord[0].size(), "Number of unknowns in solution "
         [ -  - ][ -  - ]
     446                 :            :               "vector at recent time step incorrect" );
     447 [ -  + ][ -  - ]:      37026 :       Assert( R.nunk() == coord[0].size(),
         [ -  - ][ -  - ]
     448                 :            :               "Number of unknowns and/or number of components in right-hand "
     449                 :            :               "side vector incorrect" );
     450 [ -  + ][ -  - ]:      37026 :       Assert( W.nunk() == coord[0].size(), "Size mismatch " );
         [ -  - ][ -  - ]
     451                 :            : 
     452                 :            :       // compute/assemble gradients in points
     453         [ +  - ]:      74052 :       auto Grad = nodegrad( coord, inpoel, lid, bid, vol, esup, U, G );
     454                 :            : 
     455                 :            :       // zero right hand side for all components
     456 [ +  + ][ +  - ]:     222156 :       for (ncomp_t c=0; c<m_ncomp; ++c) R.fill( c, 0.0 );
     457                 :            : 
     458                 :            :       // compute domain-edge integral
     459         [ +  - ]:      37026 :       domainint( coord, gid, edgenode, edgeid, psup, dfn, U, W, Grad, R );
     460                 :            : 
     461                 :            :       // compute boundary integrals
     462         [ +  - ]:      37026 :       bndint( coord, triinpoel, symbctri, slipwallbctri, U, W, R );
     463                 :            : 
     464                 :            :       // compute external (energy) sources
     465         [ +  + ]:    3984942 :       for (auto& is : srcFlag) is = 0;   // reset energy source flag
     466         [ +  - ]:      37026 :       boxSrc( V, t, inpoel, esup, boxnodes, coord, R, srcFlag );
     467                 :            : 
     468                 :            :       // compute optional source integral
     469         [ +  - ]:      37026 :       src( coord, inpoel, t, tp, R );
     470                 :      37026 :     }
     471                 :            : 
     472                 :            :     //! Compute boundary pressure integrals (force) for rigid body motion
     473                 :            :     //! \param[in] coord Mesh node coordinates
     474                 :            :     //! \param[in] triinpoel Boundary triangle face connecitivity with local ids
     475                 :            :     //! \param[in] slipwallbctri Vector with 1 at symmetry BC boundary triangles
     476                 :            :     //! \param[in] U Solution vector at recent time step
     477                 :            :     //! \param[in] CM Center of mass
     478                 :            :     //! \param[in,out] F Force vector (appended with torque vector) computed
     479                 :          0 :     void bndPressureInt(
     480                 :            :       const std::array< std::vector< real >, 3 >& coord,
     481                 :            :       const std::vector< std::size_t >& triinpoel,
     482                 :            :       const std::vector< int >& slipwallbctri,
     483                 :            :       const tk::Fields& U,
     484                 :            :       const std::array< tk::real, 3 >& CM,
     485                 :            :       std::vector< real >& F ) const
     486                 :            :     {
     487                 :            : 
     488                 :            :       // access node coordinates
     489                 :          0 :       const auto& x = coord[0];
     490                 :          0 :       const auto& y = coord[1];
     491                 :          0 :       const auto& z = coord[2];
     492                 :            : 
     493                 :            :       // boundary integrals: compute surface integral of pressure (=force)
     494         [ -  - ]:          0 :       for (std::size_t e=0; e<triinpoel.size()/3; ++e) {
     495         [ -  - ]:          0 :         if (slipwallbctri[e]) {
     496                 :            :         // access node IDs
     497                 :          0 :         std::size_t N[3] =
     498                 :          0 :           { triinpoel[e*3+0], triinpoel[e*3+1], triinpoel[e*3+2] };
     499                 :            :         // access solution at element nodes
     500         [ -  - ]:          0 :         real rA  = U(N[0],0);
     501         [ -  - ]:          0 :         real rB  = U(N[1],0);
     502         [ -  - ]:          0 :         real rC  = U(N[2],0);
     503         [ -  - ]:          0 :         real ruA = U(N[0],1);
     504         [ -  - ]:          0 :         real ruB = U(N[1],1);
     505         [ -  - ]:          0 :         real ruC = U(N[2],1);
     506         [ -  - ]:          0 :         real rvA = U(N[0],2);
     507         [ -  - ]:          0 :         real rvB = U(N[1],2);
     508         [ -  - ]:          0 :         real rvC = U(N[2],2);
     509         [ -  - ]:          0 :         real rwA = U(N[0],3);
     510         [ -  - ]:          0 :         real rwB = U(N[1],3);
     511         [ -  - ]:          0 :         real rwC = U(N[2],3);
     512         [ -  - ]:          0 :         real reA = U(N[0],4);
     513         [ -  - ]:          0 :         real reB = U(N[1],4);
     514         [ -  - ]:          0 :         real reC = U(N[2],4);
     515                 :            :         // compute face normal
     516                 :            :         real nx, ny, nz;
     517                 :          0 :         tk::normal( x[N[0]], x[N[1]], x[N[2]],
     518                 :            :                     y[N[0]], y[N[1]], y[N[2]],
     519                 :            :                     z[N[0]], z[N[1]], z[N[2]],
     520                 :            :                     nx, ny, nz );
     521                 :            :         // compute boundary pressures
     522                 :          0 :         auto p = (
     523         [ -  - ]:          0 :           m_mat_blk[0].compute< EOS::pressure >(rA, ruA/rA, rvA/rA, rwA/rA, reA) +
     524         [ -  - ]:          0 :           m_mat_blk[0].compute< EOS::pressure >(rB, ruB/rB, rvB/rB, rwB/rB, reB) +
     525         [ -  - ]:          0 :           m_mat_blk[0].compute< EOS::pressure >(rC, ruC/rC, rvC/rC, rwC/rC, reC)
     526                 :            :           ) / 3.0;
     527                 :            :         // compute face area
     528                 :          0 :         auto Ae = tk::area( x[N[0]], x[N[1]], x[N[2]],
     529                 :            :                             y[N[0]], y[N[1]], y[N[2]],
     530                 :            :                             z[N[0]], z[N[1]], z[N[2]] );
     531                 :            :         // contribute to force vector
     532                 :          0 :         F[0] += p * Ae * nx;
     533                 :          0 :         F[1] += p * Ae * ny;
     534                 :          0 :         F[2] += p * Ae * nz;
     535                 :            : 
     536                 :            :         // contribute to torque vector
     537                 :          0 :         std::array< tk::real, 3 > rCM{{
     538                 :          0 :           (x[N[0]]+x[N[1]]+x[N[2]])/3.0 - CM[0],
     539                 :          0 :           (y[N[0]]+y[N[1]]+y[N[2]])/3.0 - CM[1],
     540                 :          0 :           (z[N[0]]+z[N[1]]+z[N[2]])/3.0 - CM[2] }};
     541                 :            : 
     542                 :          0 :         auto torque = tk::cross(rCM, {{p*Ae*nx, p*Ae*ny, p*Ae*nz}});
     543         [ -  - ]:          0 :         for (std::size_t i=0; i<3; ++i) F[i+3] += torque[i];
     544                 :            :         }
     545                 :            :       }
     546                 :          0 :     }
     547                 :            : 
     548                 :            :     //! Compute the minimum time step size (for unsteady time stepping)
     549                 :            :     //! \param[in] coord Mesh node coordinates
     550                 :            :     //! \param[in] inpoel Mesh element connectivity
     551                 :            : //    //! \param[in] t Physical time
     552                 :            :     //! \param[in] dtn Time step size at the previous time step
     553                 :            :     //! \param[in] U Solution vector at recent time step
     554                 :            :     //! \param[in] vol Nodal volume (with contributions from other chares)
     555                 :            :     //! \param[in] voln Nodal volume (with contributions from other chares) at
     556                 :            :     //!   the previous time step
     557                 :            :     //! \param[in] srcFlag Whether the energy source was added
     558                 :            :     //! \return Minimum time step size
     559                 :       6302 :     real dt( const std::array< std::vector< real >, 3 >& coord,
     560                 :            :              const std::vector< std::size_t >& inpoel,
     561                 :            :              tk::real /*t*/,
     562                 :            :              tk::real dtn,
     563                 :            :              const tk::Fields& U,
     564                 :            :              const std::vector< tk::real >& vol,
     565                 :            :              const std::vector< tk::real >& voln,
     566                 :            :              const std::vector< int >& srcFlag ) const
     567                 :            :     {
     568 [ -  + ][ -  - ]:       6302 :       Assert( U.nunk() == coord[0].size(), "Number of unknowns in solution "
         [ -  - ][ -  - ]
     569                 :            :               "vector at recent time step incorrect" );
     570                 :            : 
     571                 :            :       // energy source propagation time and velocity
     572                 :       6302 :       const auto& icbox = g_inputdeck.get< tag::ic, tag::box >();
     573                 :            : 
     574                 :       6302 :       const auto& x = coord[0];
     575                 :       6302 :       const auto& y = coord[1];
     576                 :       6302 :       const auto& z = coord[2];
     577                 :            : 
     578                 :            :       // ratio of specific heats
     579         [ +  - ]:       6302 :       auto g = getmatprop< tag::gamma >();
     580                 :            : 
     581                 :            :       // energy source propagation velocity (in all IC boxes configured)
     582                 :       6302 :       real vFront(0.0);
     583         [ +  + ]:       6302 :       if (!icbox.empty()) {
     584         [ +  + ]:        830 :         for (const auto& b : icbox) {   // for all boxes for this eq
     585                 :        420 :           const auto& initiate = b.template get< tag::initiate >();
     586         [ +  + ]:        420 :           if (initiate == ctr::InitiateType::LINEAR) {
     587                 :        400 :             vFront = std::max(vFront,
     588                 :        400 :               b.template get< tag::front_speed >());
     589                 :            :           }
     590                 :            :         }
     591                 :            :       }
     592                 :            : 
     593                 :            :       // compute the minimum dt across all elements we own
     594                 :       6302 :       real mindt = std::numeric_limits< real >::max();
     595         [ +  + ]:    3597107 :       for (std::size_t e=0; e<inpoel.size()/4; ++e) {
     596                 :    3590805 :         const std::array< std::size_t, 4 > N{{ inpoel[e*4+0], inpoel[e*4+1],
     597                 :    3590805 :                                                inpoel[e*4+2], inpoel[e*4+3] }};
     598                 :            :         // compute cubic root of element volume as the characteristic length
     599                 :            :         const std::array< real, 3 >
     600                 :    3590805 :           ba{{ x[N[1]]-x[N[0]], y[N[1]]-y[N[0]], z[N[1]]-z[N[0]] }},
     601                 :    3590805 :           ca{{ x[N[2]]-x[N[0]], y[N[2]]-y[N[0]], z[N[2]]-z[N[0]] }},
     602                 :    3590805 :           da{{ x[N[3]]-x[N[0]], y[N[3]]-y[N[0]], z[N[3]]-z[N[0]] }};
     603                 :    3590805 :         const auto L = std::cbrt( tk::triple( ba, ca, da ) / 6.0 );
     604                 :            :         // access solution at element nodes at recent time step
     605                 :            :         std::array< std::array< real, 4 >, m_ncomp > u;
     606 [ +  + ][ +  - ]:   21544830 :         for (ncomp_t c=0; c<m_ncomp; ++c) u[c] = U.extract( c, N );
     607                 :            :         // compute the maximum length of the characteristic velocity (fluid
     608                 :            :         // velocity + sound velocity) across the four element nodes
     609                 :    3590805 :         real maxvel = 0.0;
     610         [ +  + ]:   17954025 :         for (std::size_t j=0; j<4; ++j) {
     611                 :   14363220 :           auto& r  = u[0][j];    // rho
     612                 :   14363220 :           auto& ru = u[1][j];    // rho * u
     613                 :   14363220 :           auto& rv = u[2][j];    // rho * v
     614                 :   14363220 :           auto& rw = u[3][j];    // rho * w
     615                 :   14363220 :           auto& re = u[4][j];    // rho * e
     616         [ +  - ]:   14363220 :           auto p = m_mat_blk[0].compute< EOS::pressure >( r, ru/r, rv/r, rw/r,
     617                 :            :             re );
     618         [ -  + ]:   14363220 :           if (p < 0) p = 0.0;
     619         [ +  - ]:   14363220 :           auto c = m_mat_blk[0].compute< EOS::soundspeed >( r, p );
     620                 :   14363220 :           auto v = std::sqrt((ru*ru + rv*rv + rw*rw)/r/r) + c; // char. velocity
     621                 :            : 
     622 [ +  + ][ +  + ]:   14363220 :           if (srcFlag[N[j]] > 0 && std::abs(vFront) > 1e-8) {
                 [ +  + ]
     623                 :      72859 :             v = std::max(v, std::fabs(vFront));
     624                 :            :           }
     625                 :            : 
     626         [ +  + ]:   14363220 :           if (v > maxvel) maxvel = v;
     627                 :            :         }
     628                 :            :         // compute element dt for the Euler equations
     629                 :    3590805 :         auto euler_dt = L / maxvel;
     630                 :            :         // compute element dt based on the viscous force
     631                 :    3590805 :         auto viscous_dt = m_physics.viscous_dt( L, u );
     632                 :            :         // compute element dt based on thermal diffusion
     633                 :    3590805 :         auto conduct_dt = m_physics.conduct_dt( L, g, u );
     634                 :            :         // compute minimum element dt
     635                 :    3590805 :         auto elemdt = std::min( euler_dt, std::min( viscous_dt, conduct_dt ) );
     636                 :            :         // find minimum dt across all elements
     637                 :    3590805 :         mindt = std::min( elemdt, mindt );
     638                 :            :       }
     639                 :       6302 :       mindt *= g_inputdeck.get< tag::cfl >();
     640                 :            : 
     641                 :            :       // compute the minimum dt across all nodes we contribute to due to volume
     642                 :            :       // change in time
     643                 :       6302 :       auto dvcfl = g_inputdeck.get< tag::ale, tag::dvcfl >();
     644 [ +  + ][ +  + ]:       6302 :       if (dtn > 0.0 && dvcfl > 0.0) {
     645 [ -  + ][ -  - ]:        298 :         Assert( vol.size() == voln.size(), "Size mismatch" );
         [ -  - ][ -  - ]
     646         [ +  + ]:     375342 :         for (std::size_t p=0; p<vol.size(); ++p) {
     647                 :     750088 :           auto vol_dt = dtn *
     648                 :     375044 :             std::min(voln[p],vol[p]) / std::abs(voln[p]-vol[p]+1.0e-14);
     649                 :     375044 :           mindt = std::min( vol_dt, mindt );
     650                 :            :         }
     651                 :        298 :         mindt *= dvcfl;
     652                 :            :       }
     653                 :            : 
     654                 :       6302 :       return mindt;
     655                 :            :     }
     656                 :            : 
     657                 :            :     //! Compute a time step size for each mesh node (for steady time stepping)
     658                 :            :     //! \param[in] U Solution vector at recent time step
     659                 :            :     //! \param[in] vol Nodal volume (with contributions from other chares)
     660                 :            :     //! \param[in,out] dtp Time step size for each mesh node
     661                 :        200 :     void dt( uint64_t,
     662                 :            :              const std::vector< tk::real >& vol,
     663                 :            :              const tk::Fields& U,
     664                 :            :              std::vector< tk::real >& dtp ) const
     665                 :            :     {
     666         [ +  + ]:      22520 :       for (std::size_t i=0; i<U.nunk(); ++i) {
     667                 :            :         // compute cubic root of element volume as the characteristic length
     668                 :      22320 :         const auto L = std::cbrt( vol[i] );
     669                 :            :         // access solution at node p at recent time step
     670         [ +  - ]:      22320 :         const auto u = U[i];
     671                 :            :         // compute pressure
     672         [ +  - ]:      44640 :         auto p = m_mat_blk[0].compute< EOS::pressure >( u[0], u[1]/u[0],
     673                 :      22320 :           u[2]/u[0], u[3]/u[0], u[4] );
     674         [ -  + ]:      22320 :         if (p < 0) p = 0.0;
     675         [ +  - ]:      22320 :         auto c = m_mat_blk[0].compute< EOS::soundspeed >( u[0], p );
     676                 :            :         // characteristic velocity
     677                 :      22320 :         auto v = std::sqrt((u[1]*u[1] + u[2]*u[2] + u[3]*u[3])/u[0]/u[0]) + c;
     678                 :            :         // compute dt for node
     679                 :      22320 :         dtp[i] = L / v * g_inputdeck.get< tag::cfl >();
     680                 :            :       }
     681                 :        200 :     }
     682                 :            : 
     683                 :            :     //! \brief Query Dirichlet boundary condition value on a given side set for
     684                 :            :     //!    all components in this PDE system
     685                 :            :     //! \param[in] t Physical time
     686                 :            :     //! \param[in] deltat Time step size
     687                 :            :     //! \param[in] tp Physical time for each mesh node
     688                 :            :     //! \param[in] dtp Time step size for each mesh node
     689                 :            :     //! \param[in] ss Pair of side set ID and (local) node IDs on the side set
     690                 :            :     //! \param[in] coord Mesh node coordinates
     691                 :            :     //! \param[in] increment If true, evaluate the solution increment between
     692                 :            :     //!   t and t+dt for Dirichlet BCs. If false, evlauate the solution instead.
     693                 :            :     //! \return Vector of pairs of bool and boundary condition value associated
     694                 :            :     //!   to mesh node IDs at which Dirichlet boundary conditions are set. Note
     695                 :            :     //!   that if increment is true, instead of the actual boundary condition
     696                 :            :     //!   value, we return the increment between t+deltat and t, since,
     697                 :            :     //!   depending on client code and solver, that may be what the solution
     698                 :            :     //!   requires.
     699                 :            :     std::map< std::size_t, std::vector< std::pair<bool,real> > >
     700                 :      90927 :     dirbc( real t,
     701                 :            :            real deltat,
     702                 :            :            const std::vector< tk::real >& tp,
     703                 :            :            const std::vector< tk::real >& dtp,
     704                 :            :            const std::pair< const int, std::vector< std::size_t > >& ss,
     705                 :            :            const std::array< std::vector< real >, 3 >& coord,
     706                 :            :            bool increment ) const
     707                 :            :     {
     708                 :            :       using NodeBC = std::vector< std::pair< bool, real > >;
     709                 :      90927 :       std::map< std::size_t, NodeBC > bc;
     710                 :            : 
     711                 :            :       // collect sidesets across all meshes
     712                 :     181854 :       std::vector< std::size_t > ubc;
     713         [ +  + ]:     181905 :       for (const auto& ibc : g_inputdeck.get< tag::bc >()) {
     714         [ +  - ]:      90978 :         ubc.insert(ubc.end(), ibc.get< tag::dirichlet >().begin(),
     715                 :      90978 :           ibc.get< tag::dirichlet >().end());
     716                 :            :       }
     717                 :            : 
     718                 :      90927 :       const auto steady = g_inputdeck.get< tag::steady_state >();
     719         [ +  + ]:      90927 :       if (!ubc.empty()) {
     720 [ -  + ][ -  - ]:      81981 :         Assert( ubc.size() > 0, "Indexing out of Dirichlet BC eq-vector" );
         [ -  - ][ -  - ]
     721                 :      81981 :         const auto& x = coord[0];
     722                 :      81981 :         const auto& y = coord[1];
     723                 :      81981 :         const auto& z = coord[2];
     724         [ +  + ]:     573867 :         for (const auto& b : ubc)
     725         [ +  + ]:     491886 :           if (static_cast<int>(b) == ss.first)
     726         [ +  + ]:    2057907 :             for (auto n : ss.second) {
     727 [ -  + ][ -  - ]:    1975935 :               Assert( x.size() > n, "Indexing out of coordinate array" );
         [ -  - ][ -  - ]
     728         [ +  + ]:    1975935 :               if (steady) { t = tp[n]; deltat = dtp[n]; }
     729 [ -  + ][ -  - ]:    3951870 :               auto s = increment ?
         [ -  + ][ -  - ]
     730         [ -  - ]:          0 :                 solinc( m_ncomp, m_mat_blk, x[n], y[n], z[n],
     731                 :            :                         t, deltat, Problem::initialize ) :
     732         [ +  - ]:    1975935 :                 Problem::initialize( m_ncomp, m_mat_blk, x[n], y[n],
     733                 :            :                                      z[n], t+deltat );
     734 [ +  - ][ +  - ]:    3951870 :               bc[n] = {{ {true,s[0]}, {true,s[1]}, {true,s[2]}, {true,s[3]},
     735                 :    1975935 :                          {true,s[4]} }};
     736                 :            :             }
     737                 :            :       }
     738                 :     181854 :       return bc;
     739                 :            :     }
     740                 :            : 
     741                 :            :     //! Set symmetry boundary conditions at nodes
     742                 :            :     //! \param[in] U Solution vector at recent time step
     743                 :            :     //! \param[in] bnorm Face normals in boundary points, key local node id,
     744                 :            :     //!   first 3 reals of value: unit normal, outer key: side set id
     745                 :            :     //! \param[in] nodes Unique set of node ids at which to set symmetry BCs
     746                 :            :     void
     747                 :      49345 :     symbc( tk::Fields& U,
     748                 :            :            const std::array< std::vector< real >, 3 >&,
     749                 :            :            const std::unordered_map< int,
     750                 :            :              std::unordered_map< std::size_t, std::array< real, 4 > > >& bnorm,
     751                 :            :            const std::unordered_set< std::size_t >& nodes ) const
     752                 :            :     {
     753                 :            :       // collect sidesets across all meshes
     754                 :      98690 :       std::vector< std::size_t > sbc;
     755         [ +  + ]:      98714 :       for (const auto& ibc : g_inputdeck.get< tag::bc >()) {
     756         [ +  - ]:      49369 :         sbc.insert(sbc.end(), ibc.get< tag::symmetry >().begin(),
     757                 :      49369 :           ibc.get< tag::symmetry >().end());
     758                 :            :       }
     759                 :            : 
     760         [ +  + ]:      49345 :       if (sbc.size() > 0) {             // use symbcs for this system
     761         [ +  + ]:    1564907 :         for (auto p : nodes) {                 // for all symbc nodes
     762                 :            :           // for all user-def symbc sets
     763         [ +  + ]:    5947246 :           for (std::size_t s=0; s<sbc.size(); ++s) {
     764                 :            :             // find nodes & normals for side
     765         [ +  - ]:    4385750 :             auto j = bnorm.find(static_cast<int>(sbc[s]));
     766         [ +  + ]:    4385750 :             if (j != end(bnorm)) {
     767         [ +  - ]:    3557040 :               auto i = j->second.find(p);      // find normal for node
     768         [ +  + ]:    3557040 :               if (i != end(j->second)) {
     769                 :            :                 std::array< real, 3 >
     770                 :    1662800 :                   n{ i->second[0], i->second[1], i->second[2] },
     771 [ +  - ][ +  - ]:    1662800 :                   v{ U(p,1), U(p,2), U(p,3) };
                 [ +  - ]
     772                 :    1662800 :                 auto v_dot_n = tk::dot( v, n );
     773                 :            :                 // symbc: remove normal component of velocity
     774         [ +  - ]:    1662800 :                 U(p,1) -= v_dot_n * n[0];
     775         [ +  - ]:    1662800 :                 U(p,2) -= v_dot_n * n[1];
     776         [ +  - ]:    1662800 :                 U(p,3) -= v_dot_n * n[2];
     777                 :            :               }
     778                 :            :             }
     779                 :            :           }
     780                 :            :         }
     781                 :            :       }
     782                 :      49345 :     }
     783                 :            : 
     784                 :            :     //! Set farfield boundary conditions at nodes
     785                 :            :     //! \param[in] U Solution vector at recent time step
     786                 :            :     //! \param[in] bnorm Face normals in boundary points, key local node id,
     787                 :            :     //!   first 3 reals of value: unit normal, outer key: side set id
     788                 :            :     //! \param[in] nodes Unique set of node ids at which to set farfield BCs
     789                 :            :     void
     790                 :      49336 :     farfieldbc(
     791                 :            :       tk::Fields& U,
     792                 :            :       const std::array< std::vector< real >, 3 >&,
     793                 :            :       const std::unordered_map< int,
     794                 :            :         std::unordered_map< std::size_t, std::array< real, 4 > > >& bnorm,
     795                 :            :       const std::unordered_set< std::size_t >& nodes ) const
     796                 :            :     {
     797                 :            :       // collect sidesets across all meshes
     798                 :      98672 :       std::vector< std::size_t > fbc;
     799         [ +  + ]:      98687 :       for (const auto& ibc : g_inputdeck.get< tag::bc >()) {
     800         [ +  - ]:      49351 :         fbc.insert(fbc.end(), ibc.get< tag::farfield >().begin(),
     801                 :      49351 :           ibc.get< tag::farfield >().end());
     802                 :            :       }
     803                 :            : 
     804         [ +  + ]:      49336 :       if (fbc.size() > 0)               // use farbcs for this system
     805         [ +  + ]:     174276 :         for (auto p : nodes)                   // for all farfieldbc nodes
     806         [ +  + ]:    1041912 :           for (const auto& s : fbc) {// for all user-def farbc sets
     807         [ +  - ]:     868086 :             auto j = bnorm.find(static_cast<int>(s));// find nodes & normals for side
     808         [ +  + ]:     868086 :             if (j != end(bnorm)) {
     809         [ +  - ]:     866091 :               auto i = j->second.find(p);      // find normal for node
     810         [ +  + ]:     866091 :               if (i != end(j->second)) {
     811         [ +  - ]:     236791 :                 auto& r  = U(p,0);
     812         [ +  - ]:     236791 :                 auto& ru = U(p,1);
     813         [ +  - ]:     236791 :                 auto& rv = U(p,2);
     814         [ +  - ]:     236791 :                 auto& rw = U(p,3);
     815         [ +  - ]:     236791 :                 auto& re = U(p,4);
     816                 :     236791 :                 auto vn =
     817                 :     236791 :                   (ru*i->second[0] + rv*i->second[1] + rw*i->second[2]) / r;
     818                 :     236791 :                 auto a = m_mat_blk[0].compute< EOS::soundspeed >( r,
     819 [ +  - ][ +  - ]:     236791 :                   m_mat_blk[0].compute< EOS::pressure >( r, ru/r, rv/r, rw/r,
     820                 :            :                   re ) );
     821                 :     236791 :                 auto M = vn / a;
     822         [ -  + ]:     236791 :                 if (M <= -1.0) {                      // supersonic inflow
     823                 :          0 :                   r  = m_fr;
     824                 :          0 :                   ru = m_fr * m_fu[0];
     825                 :          0 :                   rv = m_fr * m_fu[1];
     826                 :          0 :                   rw = m_fr * m_fu[2];
     827         [ -  - ]:          0 :                   re = m_mat_blk[0].compute< EOS::totalenergy >( m_fr,
     828                 :          0 :                     m_fu[0], m_fu[1], m_fu[2], m_fp );
     829 [ +  - ][ +  + ]:     236791 :                 } else if (M > -1.0 && M < 0.0) {     // subsonic inflow
     830                 :      83112 :                   auto pr = m_mat_blk[0].compute< EOS::pressure >
     831         [ +  - ]:      83112 :                                                 ( r, ru/r, rv/r, rw/r, re );
     832                 :      83112 :                   r  = m_fr;
     833                 :      83112 :                   ru = m_fr * m_fu[0];
     834                 :      83112 :                   rv = m_fr * m_fu[1];
     835                 :      83112 :                   rw = m_fr * m_fu[2];
     836         [ +  - ]:      83112 :                   re = m_mat_blk[0].compute< EOS::totalenergy >( m_fr,
     837                 :      83112 :                     m_fu[0], m_fu[1], m_fu[2], pr );
     838 [ +  - ][ +  - ]:     153679 :                 } else if (M >= 0.0 && M < 1.0) {     // subsonic outflow
     839                 :     153679 :                   re = m_mat_blk[0].compute< EOS::totalenergy >( r, ru/r,
     840         [ +  - ]:     153679 :                     rv/r, rw/r, m_fp );
     841                 :            :                 }
     842                 :            :               }
     843                 :            :             }
     844                 :            :           }
     845                 :      49336 :     }
     846                 :            : 
     847                 :            :     //! Set slip wall boundary conditions at nodes
     848                 :            :     //! \param[in] U Solution vector at recent time step
     849                 :            :     //! \param[in] W Mesh velocity
     850                 :            :     //! \param[in] bnorm Face normals in boundary points, key local node id,
     851                 :            :     //!   first 3 reals of value: unit normal, outer key: side set id
     852                 :            :     //! \param[in] nodes Unique set of node ids at which to set slip BCs
     853                 :            :     void
     854                 :      49345 :     slipwallbc( tk::Fields& U,
     855                 :            :            const tk::Fields& W,
     856                 :            :            const std::array< std::vector< real >, 3 >&,
     857                 :            :            const std::unordered_map< int,
     858                 :            :              std::unordered_map< std::size_t, std::array< real, 4 > > >& bnorm,
     859                 :            :            const std::unordered_set< std::size_t >& nodes ) const
     860                 :            :     {
     861                 :            :       // collect sidesets across all meshes
     862                 :      98690 :       std::vector< std::size_t > swbc;
     863         [ +  + ]:      98714 :       for (const auto& ibc : g_inputdeck.get< tag::bc >()) {
     864         [ +  - ]:      49369 :         swbc.insert(swbc.end(), ibc.get< tag::slipwall >().begin(),
     865                 :      49369 :           ibc.get< tag::slipwall >().end());
     866                 :            :       }
     867                 :            : 
     868         [ -  + ]:      49345 :       if (swbc.size() > 0) {             // use slip bcs for this system
     869         [ -  - ]:          0 :         for (auto p : nodes) {                 // for all slipbc nodes
     870                 :            :           // for all user-def slipbc sets
     871         [ -  - ]:          0 :           for (std::size_t s=0; s<swbc.size(); ++s) {
     872                 :            :             // find nodes & normals for side
     873         [ -  - ]:          0 :             auto j = bnorm.find(static_cast<int>(swbc[s]));
     874         [ -  - ]:          0 :             if (j != end(bnorm)) {
     875         [ -  - ]:          0 :               auto i = j->second.find(p);      // find normal for node
     876         [ -  - ]:          0 :               if (i != end(j->second)) {
     877         [ -  - ]:          0 :                 auto rho = U(p,0);
     878                 :            :                 std::array< real, 3 >
     879                 :          0 :                   n{ i->second[0], i->second[1], i->second[2] },
     880 [ -  - ][ -  - ]:          0 :                   rel_mtm{ U(p,1) - rho*W(p,0), U(p,2) - rho*W(p,1),
         [ -  - ][ -  - ]
     881 [ -  - ][ -  - ]:          0 :                     U(p,3) - rho*W(p,2) };
     882                 :          0 :                 auto rel_mtm_dot_n = tk::dot( rel_mtm, n );
     883                 :            :                 // slip wall bc: remove normal component of relative momentum
     884         [ -  - ]:          0 :                 U(p,1) -= rel_mtm_dot_n * n[0];
     885         [ -  - ]:          0 :                 U(p,2) -= rel_mtm_dot_n * n[1];
     886         [ -  - ]:          0 :                 U(p,3) -= rel_mtm_dot_n * n[2];
     887                 :            :               }
     888                 :            :             }
     889                 :            :           }
     890                 :            :         }
     891                 :            :       }
     892                 :      49345 :     }
     893                 :            : 
     894                 :            :     //! Apply user defined time dependent BCs
     895                 :            :     //! \param[in] t Physical time
     896                 :            :     //! \param[in,out] U Solution vector at recent time step
     897                 :            :     //! \param[in] nodes Vector of unique sets of node ids at which to apply BCs
     898                 :            :     //! \details This function applies user defined time dependent boundary
     899                 :            :     //!   conditions on groups of side sets specified in the input file.
     900                 :            :     //!   The user specifies pressure, density, and velocity as discrete
     901                 :            :     //!   functions of time, in the control file, associated with a group of
     902                 :            :     //!   side sets. Several such groups can be specified, each with their
     903                 :            :     //!   own discrete function: p(t), rho(t), vx(t), vy(t), vz(t).
     904                 :            :     void
     905                 :      37449 :     timedepbc( tk::real t,
     906                 :            :       tk::Fields& U,
     907                 :            :       const std::vector< std::unordered_set< std::size_t > >& nodes,
     908                 :            :       const std::vector< tk::Table<5> >& timedepfn ) const
     909                 :            :     {
     910         [ +  + ]:      37870 :       for (std::size_t ib=0; ib<nodes.size(); ++ib) {
     911         [ +  + ]:       5052 :         for (auto p:nodes[ib]) {
     912                 :            :           // sample primitive vars from discrete data at time t
     913         [ +  - ]:       4631 :           auto unk = tk::sample<5>(t, timedepfn[ib]);
     914                 :            : 
     915                 :            :           // apply BCs after converting to conserved vars
     916         [ +  - ]:       4631 :           U(p,0) = unk[1];
     917         [ +  - ]:       4631 :           U(p,1) = unk[1]*unk[2];
     918         [ +  - ]:       4631 :           U(p,2) = unk[1]*unk[3];
     919         [ +  - ]:       4631 :           U(p,3) = unk[1]*unk[4];
     920 [ +  - ][ +  - ]:       4631 :           U(p,4) = m_mat_blk[0].compute< EOS::totalenergy >( unk[1], unk[2],
     921                 :            :             unk[3], unk[4], unk[0]);
     922                 :            :         }
     923                 :            :       }
     924                 :      37449 :     }
     925                 :            : 
     926                 :            :     //! Return a map that associates user-specified strings to functions
     927                 :            :     //! \return Map that associates user-specified strings to functions that
     928                 :            :     //!   compute relevant quantities to be output to file
     929                 :        802 :     std::map< std::string, tk::GetVarFn > OutVarFn() const
     930                 :        802 :     { return CompFlowOutVarFn(); }
     931                 :            : 
     932                 :            :     //! Return analytic field names to be output to file
     933                 :            :     //! \return Vector of strings labelling analytic fields output in file
     934                 :        630 :     std::vector< std::string > analyticFieldNames() const
     935                 :        630 :     { return m_problem.analyticFieldNames( m_ncomp ); }
     936                 :            : 
     937                 :            :     //! Return surface field names to be output to file
     938                 :            :     //! \return Vector of strings labelling surface fields output in file
     939                 :        802 :     std::vector< std::string > surfNames() const
     940                 :        802 :     { return CompFlowSurfNames(); }
     941                 :            : 
     942                 :            :     //! Return time history field names to be output to file
     943                 :            :     //! \return Vector of strings labelling time history fields output in file
     944                 :         22 :     std::vector< std::string > histNames() const
     945                 :         22 :     { return CompFlowHistNames(); }
     946                 :            : 
     947                 :            :     //! Return nodal surface field output going to file
     948                 :            :     std::vector< std::vector< real > >
     949                 :        802 :     surfOutput( const std::map< int, std::vector< std::size_t > >& bnd,
     950                 :            :                 const tk::Fields& U ) const
     951                 :        802 :     { return CompFlowSurfOutput( m_mat_blk, bnd, U ); }
     952                 :            : 
     953                 :            :     //! Return elemental surface field output (on triangle faces) going to file
     954                 :            :     std::vector< std::vector< real > >
     955                 :        802 :     elemSurfOutput( const std::map< int, std::vector< std::size_t > >& bface,
     956                 :            :       const std::vector< std::size_t >& triinpoel,
     957                 :            :       const tk::Fields& U ) const
     958                 :            :     {
     959                 :        802 :       return CompFlowElemSurfOutput( m_mat_blk, bface, triinpoel, U );
     960                 :            :     }
     961                 :            : 
     962                 :            :     //! Return time history field output evaluated at time history points
     963                 :            :     std::vector< std::vector< real > >
     964                 :        214 :     histOutput( const std::vector< HistData >& h,
     965                 :            :                 const std::vector< std::size_t >& inpoel,
     966                 :            :                 const tk::Fields& U ) const
     967                 :        214 :     { return CompFlowHistOutput( m_mat_blk, h, inpoel, U ); }
     968                 :            : 
     969                 :            :     //! Return names of integral variables to be output to diagnostics file
     970                 :            :     //! \return Vector of strings labelling integral variables output
     971                 :         69 :     std::vector< std::string > names() const
     972                 :         69 :     { return m_problem.names( m_ncomp ); }
     973                 :            : 
     974                 :            :   private:
     975                 :            :     const Physics m_physics;            //!< Physics policy
     976                 :            :     const Problem m_problem;            //!< Problem policy
     977                 :            :     real m_fr;                    //!< Farfield density
     978                 :            :     real m_fp;                    //!< Farfield pressure
     979                 :            :     std::vector< real > m_fu;     //!< Farfield velocity
     980                 :            :     //! EOS material block
     981                 :            :     std::vector< EOS > m_mat_blk;
     982                 :            : 
     983                 :            :     //! \brief Compute/assemble nodal gradients of primitive variables for
     984                 :            :     //!   ALECG in all points
     985                 :            :     //! \param[in] coord Mesh node coordinates
     986                 :            :     //! \param[in] inpoel Mesh element connectivity
     987                 :            :     //! \param[in] lid Global->local node ids
     988                 :            :     //! \param[in] bid Local chare-boundary node ids (value) associated to
     989                 :            :     //!    global node ids (key)
     990                 :            :     //! \param[in] vol Nodal volumes
     991                 :            :     //! \param[in] esup Elements surrounding points
     992                 :            :     //! \param[in] U Solution vector at recent time step
     993                 :            :     //! \param[in] G Nodal gradients of primitive variables in chare-boundary
     994                 :            :     //!    nodes
     995                 :            :     //! \return Gradients of primitive variables in all mesh points
     996                 :            :     tk::Fields
     997                 :      37026 :     nodegrad( const std::array< std::vector< real >, 3 >& coord,
     998                 :            :               const std::vector< std::size_t >& inpoel,
     999                 :            :               const std::unordered_map< std::size_t, std::size_t >& lid,
    1000                 :            :               const std::unordered_map< std::size_t, std::size_t >& bid,
    1001                 :            :               const std::vector< real >& vol,
    1002                 :            :               const std::pair< std::vector< std::size_t >,
    1003                 :            :                                std::vector< std::size_t > >& esup,
    1004                 :            :               const tk::Fields& U,
    1005                 :            :               const tk::Fields& G ) const
    1006                 :            :     {
    1007                 :            :       // allocate storage for nodal gradients of primitive variables
    1008                 :      37026 :       tk::Fields Grad( U.nunk(), m_ncomp*3 );
    1009         [ +  - ]:      37026 :       Grad.fill( 0.0 );
    1010                 :            : 
    1011                 :            :       // access node cooordinates
    1012                 :      37026 :       const auto& x = coord[0];
    1013                 :      37026 :       const auto& y = coord[1];
    1014                 :      37026 :       const auto& z = coord[2];
    1015                 :            : 
    1016                 :            :       // compute gradients of primitive variables in points
    1017                 :      37026 :       auto npoin = U.nunk();
    1018                 :            :       #pragma omp simd
    1019         [ +  + ]:    3984942 :       for (std::size_t p=0; p<npoin; ++p)
    1020         [ +  + ]:   50891976 :         for (auto e : tk::Around(esup,p)) {
    1021                 :            :           // access node IDs
    1022                 :   46944060 :           std::size_t N[4] =
    1023                 :   46944060 :             { inpoel[e*4+0], inpoel[e*4+1], inpoel[e*4+2], inpoel[e*4+3] };
    1024                 :            :           // compute element Jacobi determinant, J = 6V
    1025                 :   46944060 :           real bax = x[N[1]]-x[N[0]];
    1026                 :   46944060 :           real bay = y[N[1]]-y[N[0]];
    1027                 :   46944060 :           real baz = z[N[1]]-z[N[0]];
    1028                 :   46944060 :           real cax = x[N[2]]-x[N[0]];
    1029                 :   46944060 :           real cay = y[N[2]]-y[N[0]];
    1030                 :   46944060 :           real caz = z[N[2]]-z[N[0]];
    1031                 :   46944060 :           real dax = x[N[3]]-x[N[0]];
    1032                 :   46944060 :           real day = y[N[3]]-y[N[0]];
    1033                 :   46944060 :           real daz = z[N[3]]-z[N[0]];
    1034                 :   46944060 :           auto J = tk::triple( bax, bay, baz, cax, cay, caz, dax, day, daz );
    1035                 :   46944060 :           auto J24 = J/24.0;
    1036                 :            :           // shape function derivatives, nnode*ndim [4][3]
    1037                 :            :           real g[4][3];
    1038                 :   46944060 :           tk::crossdiv( cax, cay, caz, dax, day, daz, J,
    1039                 :            :                         g[1][0], g[1][1], g[1][2] );
    1040                 :   46944060 :           tk::crossdiv( dax, day, daz, bax, bay, baz, J,
    1041                 :            :                         g[2][0], g[2][1], g[2][2] );
    1042                 :   46944060 :           tk::crossdiv( bax, bay, baz, cax, cay, caz, J,
    1043                 :            :                         g[3][0], g[3][1], g[3][2] );
    1044         [ +  + ]:  187776240 :           for (std::size_t i=0; i<3; ++i)
    1045                 :  140832180 :             g[0][i] = -g[1][i] - g[2][i] - g[3][i];
    1046                 :            :           // scatter-add gradient contributions to boundary nodes
    1047                 :            :           real u[m_ncomp];
    1048         [ +  + ]:  234720300 :           for (std::size_t b=0; b<4; ++b) {
    1049         [ +  - ]:  187776240 :             u[0] = U(N[b],0);
    1050         [ +  - ]:  187776240 :             u[1] = U(N[b],1)/u[0];
    1051         [ +  - ]:  187776240 :             u[2] = U(N[b],2)/u[0];
    1052         [ +  - ]:  187776240 :             u[3] = U(N[b],3)/u[0];
    1053         [ +  - ]:  187776240 :             u[4] = U(N[b],4)/u[0]
    1054                 :  187776240 :                    - 0.5*(u[1]*u[1] + u[2]*u[2] + u[3]*u[3]);
    1055         [ +  + ]: 1126657440 :             for (std::size_t c=0; c<m_ncomp; ++c)
    1056         [ +  + ]: 3755524800 :               for (std::size_t i=0; i<3; ++i)
    1057         [ +  - ]: 2816643600 :                 Grad(p,c*3+i) += J24 * g[b][i] * u[c];
    1058                 :            :           }
    1059                 :            :         }
    1060                 :            : 
    1061                 :            :       // put in nodal gradients of chare-boundary points
    1062         [ +  + ]:    1642095 :       for (const auto& [g,b] : bid) {
    1063         [ +  - ]:    1605069 :         auto i = tk::cref_find( lid, g );
    1064         [ +  + ]:   25681104 :         for (ncomp_t c=0; c<Grad.nprop(); ++c)
    1065 [ +  - ][ +  - ]:   24076035 :           Grad(i,c) = G(b,c);
    1066                 :            :       }
    1067                 :            : 
    1068                 :            :       // divide weak result in gradients by nodal volume
    1069         [ +  + ]:    3984942 :       for (std::size_t p=0; p<npoin; ++p)
    1070         [ +  + ]:   63166656 :         for (std::size_t c=0; c<m_ncomp*3; ++c)
    1071         [ +  - ]:   59218740 :           Grad(p,c) /= vol[p];
    1072                 :            : 
    1073                 :      37026 :       return Grad;
    1074                 :            :     }
    1075                 :            : 
    1076                 :            :     //! Compute domain-edge integral for ALECG
    1077                 :            :     //! \param[in] coord Mesh node coordinates
    1078                 :            :     //! \param[in] gid Local->glocal node ids
    1079                 :            :     //! \param[in] edgenode Local node ids of edges
    1080                 :            :     //! \param[in] edgeid Local node id pair -> edge id map
    1081                 :            :     //! \param[in] psup Points surrounding points
    1082                 :            :     //! \param[in] dfn Dual-face normals
    1083                 :            :     //! \param[in] U Solution vector at recent time step
    1084                 :            :     //! \param[in] W Mesh velocity
    1085                 :            :     //! \param[in] G Nodal gradients
    1086                 :            :     //! \param[in,out] R Right-hand side vector computed
    1087                 :      37026 :     void domainint( const std::array< std::vector< real >, 3 >& coord,
    1088                 :            :                     const std::vector< std::size_t >& gid,
    1089                 :            :                     const std::vector< std::size_t >& edgenode,
    1090                 :            :                     const std::vector< std::size_t >& edgeid,
    1091                 :            :                     const std::pair< std::vector< std::size_t >,
    1092                 :            :                                      std::vector< std::size_t > >& psup,
    1093                 :            :                     const std::vector< real >& dfn,
    1094                 :            :                     const tk::Fields& U,
    1095                 :            :                     const tk::Fields& W,
    1096                 :            :                     const tk::Fields& G,
    1097                 :            :                     tk::Fields& R ) const
    1098                 :            :     {
    1099                 :            :       // domain-edge integral: compute fluxes in edges
    1100         [ +  - ]:      74052 :       std::vector< real > dflux( edgenode.size()/2 * m_ncomp );
    1101                 :            : 
    1102                 :            :       #pragma omp simd
    1103         [ +  + ]:   18850356 :       for (std::size_t e=0; e<edgenode.size()/2; ++e) {
    1104                 :   18813330 :         auto p = edgenode[e*2+0];
    1105                 :   18813330 :         auto q = edgenode[e*2+1];
    1106                 :            : 
    1107                 :            :         // compute primitive variables at edge-end points
    1108         [ +  - ]:   18813330 :         real rL  = U(p,0);
    1109         [ +  - ]:   18813330 :         real ruL = U(p,1) / rL;
    1110         [ +  - ]:   18813330 :         real rvL = U(p,2) / rL;
    1111         [ +  - ]:   18813330 :         real rwL = U(p,3) / rL;
    1112         [ +  - ]:   18813330 :         real reL = U(p,4) / rL - 0.5*(ruL*ruL + rvL*rvL + rwL*rwL);
    1113         [ +  - ]:   18813330 :         real w1L = W(p,0);
    1114         [ +  - ]:   18813330 :         real w2L = W(p,1);
    1115         [ +  - ]:   18813330 :         real w3L = W(p,2);
    1116         [ +  - ]:   18813330 :         real rR  = U(q,0);
    1117         [ +  - ]:   18813330 :         real ruR = U(q,1) / rR;
    1118         [ +  - ]:   18813330 :         real rvR = U(q,2) / rR;
    1119         [ +  - ]:   18813330 :         real rwR = U(q,3) / rR;
    1120         [ +  - ]:   18813330 :         real reR = U(q,4) / rR - 0.5*(ruR*ruR + rvR*rvR + rwR*rwR);
    1121         [ +  - ]:   18813330 :         real w1R = W(q,0);
    1122         [ +  - ]:   18813330 :         real w2R = W(q,1);
    1123         [ +  - ]:   18813330 :         real w3R = W(q,2);
    1124                 :            : 
    1125                 :            :         // compute MUSCL reconstruction in edge-end points
    1126         [ +  - ]:   18813330 :         muscl( p, q, coord, G,
    1127                 :            :                rL, ruL, rvL, rwL, reL, rR, ruR, rvR, rwR, reR );
    1128                 :            : 
    1129                 :            :         // convert back to conserved variables
    1130                 :   18813330 :         reL = (reL + 0.5*(ruL*ruL + rvL*rvL + rwL*rwL)) * rL;
    1131                 :   18813330 :         ruL *= rL;
    1132                 :   18813330 :         rvL *= rL;
    1133                 :   18813330 :         rwL *= rL;
    1134                 :   18813330 :         reR = (reR + 0.5*(ruR*ruR + rvR*rvR + rwR*rwR)) * rR;
    1135                 :   18813330 :         ruR *= rR;
    1136                 :   18813330 :         rvR *= rR;
    1137                 :   18813330 :         rwR *= rR;
    1138                 :            : 
    1139                 :            :         // evaluate pressure at edge-end points
    1140                 :   18813330 :         real pL = m_mat_blk[0].compute< EOS::pressure >( rL, ruL/rL, rvL/rL,
    1141         [ +  - ]:   18813330 :           rwL/rL, reL );
    1142                 :   18813330 :         real pR = m_mat_blk[0].compute< EOS::pressure >( rR, ruR/rR, rvR/rR,
    1143         [ +  - ]:   18813330 :           rwR/rR, reR );
    1144                 :            : 
    1145                 :            :         // compute Riemann flux using edge-end point states
    1146                 :            :         real f[m_ncomp];
    1147         [ +  - ]:   18813330 :         Rusanov::flux( m_mat_blk,
    1148                 :   18813330 :                        dfn[e*6+0], dfn[e*6+1], dfn[e*6+2],
    1149                 :   18813330 :                        dfn[e*6+3], dfn[e*6+4], dfn[e*6+5],
    1150                 :            :                        rL, ruL, rvL, rwL, reL,
    1151                 :            :                        rR, ruR, rvR, rwR, reR,
    1152                 :            :                        w1L, w2L, w3L, w1R, w2R, w3R,
    1153                 :            :                        pL, pR,
    1154                 :            :                        f[0], f[1], f[2], f[3], f[4] );
    1155                 :            :         // store flux in edges
    1156         [ +  + ]:  112879980 :         for (std::size_t c=0; c<m_ncomp; ++c) dflux[e*m_ncomp+c] = f[c];
    1157                 :            :       }
    1158                 :            : 
    1159                 :            :       // access pointer to right hand side at component
    1160                 :            :       std::array< const real*, m_ncomp > r;
    1161 [ +  + ][ +  - ]:     222156 :       for (ncomp_t c=0; c<m_ncomp; ++c) r[c] = R.cptr( c );
    1162                 :            : 
    1163                 :            :       // domain-edge integral: sum flux contributions to points
    1164         [ +  + ]:    3984942 :       for (std::size_t p=0,k=0; p<U.nunk(); ++p)
    1165         [ +  + ]:   41574576 :         for (auto q : tk::Around(psup,p)) {
    1166         [ +  + ]:   37626660 :           auto s = gid[p] > gid[q] ? -1.0 : 1.0;
    1167                 :   37626660 :           auto e = edgeid[k++];
    1168                 :            :           // the 2.0 in the following expression is so that the RHS contribution
    1169                 :            :           // conforms with Eq 12 (Waltz et al. Computers & fluids (92) 2014);
    1170                 :            :           // The 1/2 in Eq 12 is extracted from the flux function (Rusanov).
    1171                 :            :           // However, Rusanov::flux computes the flux with the 1/2. This 2
    1172                 :            :           // cancels with the 1/2 in Rusanov::flux, so that the 1/2 can be
    1173                 :            :           // extracted out and multiplied as in Eq 12
    1174         [ +  + ]:  225759960 :           for (std::size_t c=0; c<m_ncomp; ++c)
    1175         [ +  - ]:  188133300 :             R.var(r[c],p) -= 2.0*s*dflux[e*m_ncomp+c];
    1176                 :            :         }
    1177                 :            : 
    1178                 :      37026 :       tk::destroy(dflux);
    1179                 :      37026 :     }
    1180                 :            : 
    1181                 :            :     //! \brief Compute MUSCL reconstruction in edge-end points using a MUSCL
    1182                 :            :     //!    procedure with van Leer limiting
    1183                 :            :     //! \param[in] p Left node id of edge-end
    1184                 :            :     //! \param[in] q Right node id of edge-end
    1185                 :            :     //! \param[in] coord Array of nodal coordinates
    1186                 :            :     //! \param[in] G Gradient of all unknowns in mesh points
    1187                 :            :     //! \param[in,out] rL Left density
    1188                 :            :     //! \param[in,out] uL Left X velocity
    1189                 :            :     //! \param[in,out] vL Left Y velocity
    1190                 :            :     //! \param[in,out] wL Left Z velocity
    1191                 :            :     //! \param[in,out] eL Left internal energy
    1192                 :            :     //! \param[in,out] rR Right density
    1193                 :            :     //! \param[in,out] uR Right X velocity
    1194                 :            :     //! \param[in,out] vR Right Y velocity
    1195                 :            :     //! \param[in,out] wR Right Z velocity
    1196                 :            :     //! \param[in,out] eR Right internal energy
    1197                 :   18813330 :     void muscl( std::size_t p,
    1198                 :            :                 std::size_t q,
    1199                 :            :                 const tk::UnsMesh::Coords& coord,
    1200                 :            :                 const tk::Fields& G,
    1201                 :            :                 real& rL, real& uL, real& vL, real& wL, real& eL,
    1202                 :            :                 real& rR, real& uR, real& vR, real& wR, real& eR ) const
    1203                 :            :     {
    1204                 :            :       // access node coordinates
    1205                 :   18813330 :       const auto& x = coord[0];
    1206                 :   18813330 :       const auto& y = coord[1];
    1207                 :   18813330 :       const auto& z = coord[2];
    1208                 :            : 
    1209                 :            :       // edge vector
    1210                 :   18813330 :       std::array< real, 3 > vw{ x[q]-x[p], y[q]-y[p], z[q]-z[p] };
    1211                 :            : 
    1212                 :            :       real delta1[5], delta2[5], delta3[5];
    1213                 :   18813330 :       std::array< real, 5 > ls{ rL, uL, vL, wL, eL };
    1214                 :   18813330 :       std::array< real, 5 > rs{ rR, uR, vR, wR, eR };
    1215                 :   18813330 :       auto url = ls;
    1216                 :   18813330 :       auto urr = rs;
    1217                 :            : 
    1218                 :            :       // MUSCL reconstruction of edge-end-point primitive variables
    1219         [ +  + ]:  112879980 :       for (std::size_t c=0; c<5; ++c) {
    1220                 :            :         // gradients
    1221 [ +  - ][ +  - ]:   94066650 :         std::array< real, 3 > g1{ G(p,c*3+0), G(p,c*3+1), G(p,c*3+2) },
                 [ +  - ]
    1222 [ +  - ][ +  - ]:   94066650 :                               g2{ G(q,c*3+0), G(q,c*3+1), G(q,c*3+2) };
                 [ +  - ]
    1223                 :            : 
    1224                 :   94066650 :         delta2[c] = rs[c] - ls[c];
    1225                 :   94066650 :         delta1[c] = 2.0 * tk::dot(g1,vw) - delta2[c];
    1226                 :   94066650 :         delta3[c] = 2.0 * tk::dot(g2,vw) - delta2[c];
    1227                 :            : 
    1228                 :            :         // MUSCL extrapolation option 1:
    1229                 :            :         // ---------------------------------------------------------------------
    1230                 :            :         // Uncomment the following 3 blocks of code if this version is required.
    1231                 :            :         // this reconstruction is from the following paper:
    1232                 :            :         // Waltz, J., Morgan, N. R., Canfield, T. R., Charest, M. R.,
    1233                 :            :         // Risinger, L. D., & Wohlbier, J. G. (2014). A three-dimensional
    1234                 :            :         // finite element arbitrary Lagrangian–Eulerian method for shock
    1235                 :            :         // hydrodynamics on unstructured grids. Computers & Fluids, 92,
    1236                 :            :         // 172-187.
    1237                 :            : 
    1238                 :            :         //// form limiters
    1239                 :            :         //auto rcL = (delta2[c] + muscl_eps) / (delta1[c] + muscl_eps);
    1240                 :            :         //auto rcR = (delta2[c] + muscl_eps) / (delta3[c] + muscl_eps);
    1241                 :            :         //auto rLinv = (delta1[c] + muscl_eps) / (delta2[c] + muscl_eps);
    1242                 :            :         //auto rRinv = (delta3[c] + muscl_eps) / (delta2[c] + muscl_eps);
    1243                 :            : 
    1244                 :            :         //// van Leer limiter
    1245                 :            :         //// any other symmetric limiter could be used instead too
    1246                 :            :         //auto phiL = (std::abs(rcL) + rcL) / (std::abs(rcL) + 1.0);
    1247                 :            :         //auto phiR = (std::abs(rcR) + rcR) / (std::abs(rcR) + 1.0);
    1248                 :            :         //auto phi_L_inv = (std::abs(rLinv) + rLinv) / (std::abs(rLinv) + 1.0);
    1249                 :            :         //auto phi_R_inv = (std::abs(rRinv) + rRinv) / (std::abs(rRinv) + 1.0);
    1250                 :            : 
    1251                 :            :         //// update unknowns with reconstructed unknowns
    1252                 :            :         //url[c] += 0.25*(delta1[c]*muscl_m1*phiL + delta2[c]*muscl_p1*phi_L_inv);
    1253                 :            :         //urr[c] -= 0.25*(delta3[c]*muscl_m1*phiR + delta2[c]*muscl_p1*phi_R_inv);
    1254                 :            : 
    1255                 :            :         // ---------------------------------------------------------------------
    1256                 :            : 
    1257                 :            :         // MUSCL extrapolation option 2:
    1258                 :            :         // ---------------------------------------------------------------------
    1259                 :            :         // The following 2 blocks of code.
    1260                 :            :         // this reconstruction is from the following paper:
    1261                 :            :         // Luo, H., Baum, J. D., & Lohner, R. (1994). Edge-based finite element
    1262                 :            :         // scheme for the Euler equations. AIAA journal, 32(6), 1183-1190.
    1263                 :            :         // Van Leer, B. (1974). Towards the ultimate conservative difference
    1264                 :            :         // scheme. II. Monotonicity and conservation combined in a second-order
    1265                 :            :         // scheme. Journal of computational physics, 14(4), 361-370.
    1266                 :            : 
    1267                 :            :         // get Van Albada limiter
    1268                 :            :         // the following form is derived from the flux limiter phi as:
    1269                 :            :         // s = phi_inv - (1 - phi)
    1270                 :  188133300 :         auto sL = std::max(0.0, (2.0*delta1[c]*delta2[c] + muscl_eps)
    1271                 :   94066650 :           /(delta1[c]*delta1[c] + delta2[c]*delta2[c] + muscl_eps));
    1272                 :  188133300 :         auto sR = std::max(0.0, (2.0*delta3[c]*delta2[c] + muscl_eps)
    1273                 :   94066650 :           /(delta3[c]*delta3[c] + delta2[c]*delta2[c] + muscl_eps));
    1274                 :            : 
    1275                 :            :         // update unknowns with reconstructed unknowns
    1276                 :   94066650 :         url[c] += 0.25*sL*(delta1[c]*(1.0-muscl_const*sL)
    1277                 :   94066650 :           + delta2[c]*(1.0+muscl_const*sL));
    1278                 :   94066650 :         urr[c] -= 0.25*sR*(delta3[c]*(1.0-muscl_const*sR)
    1279                 :   94066650 :           + delta2[c]*(1.0+muscl_const*sR));
    1280                 :            : 
    1281                 :            :         // ---------------------------------------------------------------------
    1282                 :            :       }
    1283                 :            : 
    1284                 :            :       // force first order if the reconstructions for density or internal energy
    1285                 :            :       // would have allowed negative values
    1286 [ +  + ][ +  + ]:   18813330 :       if (ls[0] < delta1[0] || ls[4] < delta1[4]) url = ls;
                 [ +  + ]
    1287 [ +  + ][ +  + ]:   18813330 :       if (rs[0] < -delta3[0] || rs[4] < -delta3[4]) urr = rs;
                 [ +  + ]
    1288                 :            : 
    1289                 :   18813330 :       rL = url[0];
    1290                 :   18813330 :       uL = url[1];
    1291                 :   18813330 :       vL = url[2];
    1292                 :   18813330 :       wL = url[3];
    1293                 :   18813330 :       eL = url[4];
    1294                 :            : 
    1295                 :   18813330 :       rR = urr[0];
    1296                 :   18813330 :       uR = urr[1];
    1297                 :   18813330 :       vR = urr[2];
    1298                 :   18813330 :       wR = urr[3];
    1299                 :   18813330 :       eR = urr[4];
    1300                 :   18813330 :     }
    1301                 :            : 
    1302                 :            :     //! Compute boundary integrals for ALECG
    1303                 :            :     //! \param[in] coord Mesh node coordinates
    1304                 :            :     //! \param[in] triinpoel Boundary triangle face connecitivity with local ids
    1305                 :            :     //! \param[in] symbctri Vector with 1 at symmetry BC boundary triangles
    1306                 :            :     //! \param[in] slipwallbctri Vector with 1 at slip wall BC boundary triangles
    1307                 :            :     //! \param[in] U Solution vector at recent time step
    1308                 :            :     //! \param[in] W Mesh velocity
    1309                 :            :     //! \param[in,out] R Right-hand side vector computed
    1310                 :      37026 :     void bndint( const std::array< std::vector< real >, 3 >& coord,
    1311                 :            :                  const std::vector< std::size_t >& triinpoel,
    1312                 :            :                  const std::vector< int >& symbctri,
    1313                 :            :                  const std::vector< int >& slipwallbctri,
    1314                 :            :                  const tk::Fields& U,
    1315                 :            :                  const tk::Fields& W,
    1316                 :            :                  tk::Fields& R ) const
    1317                 :            :     {
    1318                 :            : 
    1319                 :            :       // access node coordinates
    1320                 :      37026 :       const auto& x = coord[0];
    1321                 :      37026 :       const auto& y = coord[1];
    1322                 :      37026 :       const auto& z = coord[2];
    1323                 :            : 
    1324                 :            :       // boundary integrals: compute fluxes in edges
    1325         [ +  - ]:      74052 :       std::vector< real > bflux( triinpoel.size() * m_ncomp * 2 );
    1326                 :            : 
    1327                 :            :       #pragma omp simd
    1328         [ +  + ]:    3847092 :       for (std::size_t e=0; e<triinpoel.size()/3; ++e) {
    1329                 :            :         // access node IDs
    1330                 :    3810066 :         std::size_t N[3] =
    1331                 :    3810066 :           { triinpoel[e*3+0], triinpoel[e*3+1], triinpoel[e*3+2] };
    1332                 :            :         // access solution at element nodes
    1333         [ +  - ]:    3810066 :         real rA  = U(N[0],0);
    1334         [ +  - ]:    3810066 :         real rB  = U(N[1],0);
    1335         [ +  - ]:    3810066 :         real rC  = U(N[2],0);
    1336         [ +  - ]:    3810066 :         real ruA = U(N[0],1);
    1337         [ +  - ]:    3810066 :         real ruB = U(N[1],1);
    1338         [ +  - ]:    3810066 :         real ruC = U(N[2],1);
    1339         [ +  - ]:    3810066 :         real rvA = U(N[0],2);
    1340         [ +  - ]:    3810066 :         real rvB = U(N[1],2);
    1341         [ +  - ]:    3810066 :         real rvC = U(N[2],2);
    1342         [ +  - ]:    3810066 :         real rwA = U(N[0],3);
    1343         [ +  - ]:    3810066 :         real rwB = U(N[1],3);
    1344         [ +  - ]:    3810066 :         real rwC = U(N[2],3);
    1345         [ +  - ]:    3810066 :         real reA = U(N[0],4);
    1346         [ +  - ]:    3810066 :         real reB = U(N[1],4);
    1347         [ +  - ]:    3810066 :         real reC = U(N[2],4);
    1348         [ +  - ]:    3810066 :         real w1A = W(N[0],0);
    1349         [ +  - ]:    3810066 :         real w2A = W(N[0],1);
    1350         [ +  - ]:    3810066 :         real w3A = W(N[0],2);
    1351         [ +  - ]:    3810066 :         real w1B = W(N[1],0);
    1352         [ +  - ]:    3810066 :         real w2B = W(N[1],1);
    1353         [ +  - ]:    3810066 :         real w3B = W(N[1],2);
    1354         [ +  - ]:    3810066 :         real w1C = W(N[2],0);
    1355         [ +  - ]:    3810066 :         real w2C = W(N[2],1);
    1356         [ +  - ]:    3810066 :         real w3C = W(N[2],2);
    1357                 :            :         // compute face normal
    1358                 :            :         real nx, ny, nz;
    1359                 :    3810066 :         tk::normal( x[N[0]], x[N[1]], x[N[2]],
    1360                 :            :                     y[N[0]], y[N[1]], y[N[2]],
    1361                 :            :                     z[N[0]], z[N[1]], z[N[2]],
    1362                 :            :                     nx, ny, nz );
    1363                 :            :         // compute boundary flux
    1364                 :            :         real f[m_ncomp][3];
    1365                 :            :         real p, vn;
    1366                 :    3810066 :         int sym = symbctri[e];
    1367                 :    3810066 :         int slip = slipwallbctri[e];
    1368         [ +  - ]:    3810066 :         p = m_mat_blk[0].compute< EOS::pressure >( rA, ruA/rA, rvA/rA, rwA/rA,
    1369                 :            :           reA );
    1370 [ +  + ][ +  - ]:    3810066 :         vn = (sym || slip) ? 0.0 : (nx*(ruA/rA-w1A) + ny*(rvA/rA-w2A) + nz*(rwA/rA-w3A));
    1371                 :    3810066 :         f[0][0] = rA*vn;
    1372                 :    3810066 :         f[1][0] = ruA*vn + p*nx;
    1373                 :    3810066 :         f[2][0] = rvA*vn + p*ny;
    1374                 :    3810066 :         f[3][0] = rwA*vn + p*nz;
    1375                 :    3810066 :         f[4][0] = reA*vn + p*((nx*ruA + ny*rvA + nz*rwA)/rA);
    1376         [ +  - ]:    3810066 :         p = m_mat_blk[0].compute< EOS::pressure >( rB, ruB/rB, rvB/rB, rwB/rB,
    1377                 :            :           reB );
    1378 [ +  + ][ +  - ]:    3810066 :         vn = (sym || slip) ? 0.0 : (nx*(ruB/rB-w1B) + ny*(rvB/rB-w2B) + nz*(rwB/rB-w3B));
    1379                 :    3810066 :         f[0][1] = rB*vn;
    1380                 :    3810066 :         f[1][1] = ruB*vn + p*nx;
    1381                 :    3810066 :         f[2][1] = rvB*vn + p*ny;
    1382                 :    3810066 :         f[3][1] = rwB*vn + p*nz;
    1383                 :    3810066 :         f[4][1] = reB*vn + p*((nx*ruB + ny*rvB + nz*rwB)/rB);
    1384         [ +  - ]:    3810066 :         p = m_mat_blk[0].compute< EOS::pressure >( rC, ruC/rC, rvC/rC, rwC/rC,
    1385                 :            :           reC );
    1386 [ +  + ][ +  - ]:    3810066 :         vn = (sym || slip) ? 0.0 : (nx*(ruC/rC-w1C) + ny*(rvC/rC-w2C) + nz*(rwC/rC-w3C));
    1387                 :    3810066 :         f[0][2] = rC*vn;
    1388                 :    3810066 :         f[1][2] = ruC*vn + p*nx;
    1389                 :    3810066 :         f[2][2] = rvC*vn + p*ny;
    1390                 :    3810066 :         f[3][2] = rwC*vn + p*nz;
    1391                 :    3810066 :         f[4][2] = reC*vn + p*((nx*ruC + ny*rvC + nz*rwC)/rC);
    1392                 :            :         // compute face area
    1393                 :    3810066 :         auto A6 = tk::area( x[N[0]], x[N[1]], x[N[2]],
    1394                 :            :                             y[N[0]], y[N[1]], y[N[2]],
    1395                 :            :                             z[N[0]], z[N[1]], z[N[2]] ) / 6.0;
    1396                 :    3810066 :         auto A24 = A6/4.0;
    1397                 :            :         // store flux in boundary elements
    1398         [ +  + ]:   22860396 :         for (std::size_t c=0; c<m_ncomp; ++c) {
    1399                 :   19050330 :           auto eb = (e*m_ncomp+c)*6;
    1400                 :   19050330 :           auto Bab = A24 * (f[c][0] + f[c][1]);
    1401                 :   19050330 :           bflux[eb+0] = Bab + A6 * f[c][0];
    1402                 :   19050330 :           bflux[eb+1] = Bab;
    1403                 :   19050330 :           Bab = A24 * (f[c][1] + f[c][2]);
    1404                 :   19050330 :           bflux[eb+2] = Bab + A6 * f[c][1];
    1405                 :   19050330 :           bflux[eb+3] = Bab;
    1406                 :   19050330 :           Bab = A24 * (f[c][2] + f[c][0]);
    1407                 :   19050330 :           bflux[eb+4] = Bab + A6 * f[c][2];
    1408                 :   19050330 :           bflux[eb+5] = Bab;
    1409                 :            :         }
    1410                 :            :       }
    1411                 :            : 
    1412                 :            :       // access pointer to right hand side at component
    1413                 :            :       std::array< const real*, m_ncomp > r;
    1414 [ +  + ][ +  - ]:     222156 :       for (ncomp_t c=0; c<m_ncomp; ++c) r[c] = R.cptr( c );
    1415                 :            : 
    1416                 :            :       // boundary integrals: sum flux contributions to points
    1417         [ +  + ]:    3847092 :       for (std::size_t e=0; e<triinpoel.size()/3; ++e)
    1418         [ +  + ]:   22860396 :         for (std::size_t c=0; c<m_ncomp; ++c) {
    1419                 :   19050330 :           auto eb = (e*m_ncomp+c)*6;
    1420         [ +  - ]:   19050330 :           R.var(r[c],triinpoel[e*3+0]) -= bflux[eb+0] + bflux[eb+5];
    1421         [ +  - ]:   19050330 :           R.var(r[c],triinpoel[e*3+1]) -= bflux[eb+1] + bflux[eb+2];
    1422         [ +  - ]:   19050330 :           R.var(r[c],triinpoel[e*3+2]) -= bflux[eb+3] + bflux[eb+4];
    1423                 :            :         }
    1424                 :            : 
    1425                 :      37026 :       tk::destroy(bflux);
    1426                 :      37026 :     }
    1427                 :            : 
    1428                 :            :     //! Compute optional source integral
    1429                 :            :     //! \param[in] coord Mesh node coordinates
    1430                 :            :     //! \param[in] inpoel Mesh element connectivity
    1431                 :            :     //! \param[in] t Physical time
    1432                 :            :     //! \param[in] tp Physical time for each mesh node
    1433                 :            :     //! \param[in,out] R Right-hand side vector computed
    1434                 :      37026 :     void src( const std::array< std::vector< real >, 3 >& coord,
    1435                 :            :               const std::vector< std::size_t >& inpoel,
    1436                 :            :               real t,
    1437                 :            :               const std::vector< tk::real >& tp,
    1438                 :            :               tk::Fields& R ) const
    1439                 :            :     {
    1440                 :            :       // access node coordinates
    1441                 :      37026 :       const auto& x = coord[0];
    1442                 :      37026 :       const auto& y = coord[1];
    1443                 :      37026 :       const auto& z = coord[2];
    1444                 :            : 
    1445                 :            :       // access pointer to right hand side at component
    1446                 :            :       std::array< const real*, m_ncomp > r;
    1447 [ +  + ][ +  - ]:     222156 :       for (ncomp_t c=0; c<m_ncomp; ++c) r[c] = R.cptr( c );
    1448                 :            : 
    1449                 :            :       // source integral
    1450         [ +  + ]:   11773041 :       for (std::size_t e=0; e<inpoel.size()/4; ++e) {
    1451                 :   11736015 :         std::size_t N[4] =
    1452                 :   11736015 :           { inpoel[e*4+0], inpoel[e*4+1], inpoel[e*4+2], inpoel[e*4+3] };
    1453                 :            :         // compute element Jacobi determinant, J = 6V
    1454                 :   11736015 :         auto J24 = tk::triple(
    1455                 :   11736015 :           x[N[1]]-x[N[0]], y[N[1]]-y[N[0]], z[N[1]]-z[N[0]],
    1456                 :   11736015 :           x[N[2]]-x[N[0]], y[N[2]]-y[N[0]], z[N[2]]-z[N[0]],
    1457                 :   11736015 :           x[N[3]]-x[N[0]], y[N[3]]-y[N[0]], z[N[3]]-z[N[0]] ) / 24.0;
    1458                 :            :         // sum source contributions to nodes
    1459         [ +  + ]:   58680075 :         for (std::size_t a=0; a<4; ++a) {
    1460         [ +  - ]:   93888120 :           std::vector< real > s(m_ncomp);
    1461         [ +  + ]:   46944060 :           if (g_inputdeck.get< tag::steady_state >()) t = tp[N[a]];
    1462         [ +  - ]:   46944060 :           Problem::src( 1, m_mat_blk, x[N[a]], y[N[a]], z[N[a]], t, s );
    1463         [ +  + ]:  281664360 :           for (std::size_t c=0; c<m_ncomp; ++c)
    1464         [ +  - ]:  234720300 :             R.var(r[c],N[a]) += J24 * s[c];
    1465                 :            :         }
    1466                 :            :       }
    1467                 :      37026 :     }
    1468                 :            : 
    1469                 :            :     //! Compute sources corresponding to a propagating front in user-defined box
    1470                 :            :     //! \param[in] V Total box volume
    1471                 :            :     //! \param[in] t Physical time
    1472                 :            :     //! \param[in] inpoel Element point connectivity
    1473                 :            :     //! \param[in] esup Elements surrounding points
    1474                 :            :     //! \param[in] boxnodes Mesh node ids within user-defined boxes
    1475                 :            :     //! \param[in] coord Mesh node coordinates
    1476                 :            :     //! \param[in] R Right-hand side vector
    1477                 :            :     //! \param[in,out] engSrcAdded Whether the energy source was added
    1478                 :            :     //! \details This function adds the energy source corresponding to a
    1479                 :            :     //!   spherical wave-front growing at a user-specified velocity, within a
    1480                 :            :     //!   user-configured box initial condition, configured by the user.
    1481                 :            :     //!   Example (SI) units of the quantities involved:
    1482                 :            :     //!    * internal energy content (energy per unit volume): J/m^3
    1483                 :            :     //!    * specific energy (internal energy per unit mass): J/kg
    1484                 :      37026 :     void boxSrc( real V,
    1485                 :            :                  real t,
    1486                 :            :                  const std::vector< std::size_t >& inpoel,
    1487                 :            :                  const std::pair< std::vector< std::size_t >,
    1488                 :            :                                   std::vector< std::size_t > >& esup,
    1489                 :            :                  const std::vector< std::unordered_set< std::size_t > >& boxnodes,
    1490                 :            :                  const std::array< std::vector< real >, 3 >& coord,
    1491                 :            :                  tk::Fields& R,
    1492                 :            :                  std::vector< int >& engSrcAdded ) const
    1493                 :            :     {
    1494                 :      37026 :       const auto& icbox = g_inputdeck.get< tag::ic, tag::box >();
    1495                 :            : 
    1496                 :            :       // if nodes exist in box (on this partition)
    1497 [ +  + ][ +  - ]:      37026 :       if (!icbox.empty() && !boxnodes.empty()) {
                 [ +  + ]
    1498                 :       1230 :         std::size_t bcnt = 0;
    1499                 :            :         // for all boxes
    1500         [ +  + ]:       2490 :         for (const auto& b : icbox) {
    1501                 :            :           // if linear initialize is set up (energy-pill)
    1502         [ +  + ]:       1260 :           if (b.template get< tag::initiate >() == ctr::InitiateType::LINEAR) {
    1503                 :            : 
    1504         [ +  - ]:       2400 :           std::vector< tk::real > box
    1505                 :       1200 :            { b.template get< tag::xmin >(), b.template get< tag::xmax >(),
    1506                 :       1200 :              b.template get< tag::ymin >(), b.template get< tag::ymax >(),
    1507                 :       1200 :              b.template get< tag::zmin >(), b.template get< tag::zmax >() };
    1508                 :            : 
    1509                 :       1200 :           auto boxenc = b.template get< tag::energy_content >();
    1510 [ -  + ][ -  - ]:       1200 :           Assert( boxenc > 0.0, "Box energy content must be nonzero" );
         [ -  - ][ -  - ]
    1511                 :       1200 :           const auto& x0_front = b.template get< tag::point >();
    1512 [ -  + ][ -  - ]:       1200 :           Assert(x0_front.size()==3, "Incorrectly sized front initial location");
         [ -  - ][ -  - ]
    1513                 :            : 
    1514                 :       1200 :           auto V_ex = (box[1]-box[0]) * (box[3]-box[2]) * (box[5]-box[4]);
    1515                 :            : 
    1516                 :            :           // determine times at which sourcing is initialized and terminated
    1517                 :       1200 :           auto vFront = b.template get< tag::front_speed >();
    1518                 :       1200 :           auto wFront = b.template get< tag::front_width >();
    1519                 :       1200 :           auto tInit = b.template get< tag::init_time >();
    1520                 :            : 
    1521                 :       1200 :           const auto& x = coord[0];
    1522                 :       1200 :           const auto& y = coord[1];
    1523                 :       1200 :           const auto& z = coord[2];
    1524                 :            : 
    1525         [ +  - ]:       1200 :           if (t >= tInit) {
    1526                 :            :             // current radius of front
    1527                 :       1200 :             tk::real rFront = vFront * (t-tInit);
    1528                 :            : 
    1529                 :            :             // arbitrary shape form
    1530                 :       1200 :             auto amplE = boxenc * vFront / wFront;
    1531                 :       1200 :             amplE *= V_ex / V;
    1532                 :            : 
    1533         [ +  + ]:      81600 :             for (auto p : boxnodes[bcnt]) {
    1534                 :      80400 :               std::array< tk::real, 3 > node{{ x[p], y[p], z[p] }};
    1535                 :            : 
    1536                 :      80400 :               auto r_e = std::sqrt(
    1537                 :      80400 :                 (node[0]-x0_front[0])*(node[0]-x0_front[0]) +
    1538                 :      80400 :                 (node[1]-x0_front[1])*(node[1]-x0_front[1]) +
    1539                 :      80400 :                 (node[2]-x0_front[2])*(node[2]-x0_front[2]) );
    1540                 :            : 
    1541                 :            :               // if mesh node lies within spherical shell add sources
    1542 [ +  + ][ +  + ]:      80400 :               if (r_e >= rFront && r_e <= rFront+wFront) {
    1543                 :            :                 // arbitrary shape form
    1544                 :       5318 :                 auto S = amplE;
    1545         [ +  + ]:      76303 :                 for (auto e : tk::Around(esup,p)) {
    1546                 :            :                   // access node IDs
    1547                 :      70985 :                   std::size_t N[4] =
    1548                 :      70985 :                     {inpoel[e*4+0], inpoel[e*4+1], inpoel[e*4+2], inpoel[e*4+3]};
    1549                 :            :                   // compute element Jacobi determinant, J = 6V
    1550                 :      70985 :                   real bax = x[N[1]]-x[N[0]];
    1551                 :      70985 :                   real bay = y[N[1]]-y[N[0]];
    1552                 :      70985 :                   real baz = z[N[1]]-z[N[0]];
    1553                 :      70985 :                   real cax = x[N[2]]-x[N[0]];
    1554                 :      70985 :                   real cay = y[N[2]]-y[N[0]];
    1555                 :      70985 :                   real caz = z[N[2]]-z[N[0]];
    1556                 :      70985 :                   real dax = x[N[3]]-x[N[0]];
    1557                 :      70985 :                   real day = y[N[3]]-y[N[0]];
    1558                 :      70985 :                   real daz = z[N[3]]-z[N[0]];
    1559                 :            :                   auto J =
    1560                 :      70985 :                     tk::triple( bax, bay, baz, cax, cay, caz, dax, day, daz );
    1561                 :      70985 :                   auto J24 = J/24.0;
    1562                 :            :                   // Add the source term to the rhs
    1563         [ +  - ]:      70985 :                   R(p,4) += J24 * S;
    1564                 :      70985 :                   engSrcAdded[p] = 1;
    1565                 :            :                 }
    1566                 :            :               }
    1567                 :            :             }
    1568                 :            :           }
    1569                 :            : 
    1570                 :            :           }
    1571                 :       1260 :           ++bcnt;
    1572                 :            :         }
    1573                 :            :       }
    1574                 :      37026 :     }
    1575                 :            : 
    1576                 :            : };
    1577                 :            : 
    1578                 :            : } // cg::
    1579                 :            : 
    1580                 :            : } // inciter::
    1581                 :            : 
    1582                 :            : #endif // CGCompFlow_h

Generated by: LCOV version 1.14