Walker test code coverage report
Current view: top level - DiffEq - DiffEqStack.hpp (source / functions) Hit Total Coverage
Commit: test_coverage.info Lines: 19 21 90.5 %
Date: 2022-09-21 13:52:12 Functions: 16 18 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 58 37.9 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/DiffEq/DiffEqStack.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     Stack of differential equations
       9                 :            :   \details   This file declares class DiffEqStack, which implements various
      10                 :            :     functionality related to registering and instantiating differential equation
      11                 :            :     types. Registration and instantiation use a differential equation factory,
      12                 :            :     which is a std::map (an associative container), associating unique
      13                 :            :     differential equation keys to their constructor calls. For more details, see
      14                 :            :     the in-code documentation of the constructor.
      15                 :            : */
      16                 :            : // *****************************************************************************
      17                 :            : #ifndef DiffEqStack_h
      18                 :            : #define DiffEqStack_h
      19                 :            : 
      20                 :            : #include <map>
      21                 :            : #include <set>
      22                 :            : #include <string>
      23                 :            : #include <vector>
      24                 :            : 
      25                 :            : #include "NoWarning/back.hpp"
      26                 :            : #include "NoWarning/front.hpp"
      27                 :            : 
      28                 :            : #include "Tags.hpp"
      29                 :            : #include "Exception.hpp"
      30                 :            : #include "DiffEq.hpp"
      31                 :            : #include "DiffEqFactory.hpp"
      32                 :            : #include "SystemComponents.hpp"
      33                 :            : #include "Walker/InputDeck/InputDeck.hpp"
      34                 :            : 
      35                 :            : namespace walker {
      36                 :            : 
      37                 :            : extern ctr::InputDeck g_inputdeck;
      38                 :            : 
      39                 :            : //! \brief Differential equations stack
      40                 :            : class DiffEqStack {
      41                 :            : 
      42                 :            :   private:
      43                 :            :     using ncomp_t = tk::ctr::ncomp_t;
      44                 :            : 
      45                 :            :   public:
      46                 :            :     //! Constructor: register differential equations into factory
      47                 :            :     explicit DiffEqStack();
      48                 :            : 
      49                 :            :     //! Instantiate selected DiffEqs
      50                 :            :     std::vector< DiffEq > selected() const;
      51                 :            : 
      52                 :            :     //! \brief Instantiate tables from which extra statistics data to be output
      53                 :            :     //!    sampled for all selected differential equations
      54                 :            :     std::pair< std::vector< std::string >, std::vector< tk::Table<1> > >
      55                 :            :     tables() const;
      56                 :            : 
      57                 :            :     //! \brief Constant accessor to differential equation factory
      58                 :            :     //! \return Constant reference to the internal differential equation factory
      59                 :            :     const DiffEqFactory& factory() const { return m_factory; }
      60                 :            : 
      61                 :            :     //! Return info on selected differential equations
      62                 :            :     std::vector< std::vector< std::pair< std::string, std::string > > > info()
      63                 :            :     const;
      64                 :            : 
      65                 :            :     //! \brief Return number of unique equation types registered
      66                 :            :     //! \return The number of unique equation types registered in the factory
      67                 :            :     std::size_t ntypes() const { return m_eqTypes.size(); }
      68                 :            : 
      69                 :            :   private:
      70                 :            :     //! \brief Instantiate a differential equation object
      71                 :            :     //! \see walker::DiffEq
      72                 :            :     //! \details Since multiple systems of equations can be configured
      73                 :            :     //!   with the same type, the map (cnt) is used to assign a counter to each
      74                 :            :     //!   type. The template argument, EqTag, is used to find the given system
      75                 :            :     //!   of differential equations in the input deck, the hierarchical data
      76                 :            :     //!   filled during control file parsing, containing user input.
      77                 :            :     //! \param[in] eq The unique differential equation system key whose object
      78                 :            :     //!   to instantiate.
      79                 :            :     //! \param[in,out] cnt Counter, a std::map, that counts all instantiated
      80                 :            :     //!   differential equations systems by type.
      81                 :            :     template< class EqTag >
      82                 :        317 :     DiffEq createDiffEq( ctr::DiffEqType eq,
      83                 :            :                          std::map< ctr::DiffEqType, ncomp_t >& cnt ) const {
      84                 :        317 :       auto c = ++cnt[ eq ];   // count eqs
      85         [ +  - ]:        317 :       --c;                    // used to index vectors starting with 0
      86         [ +  - ]:        317 :       if ( g_inputdeck.get< tag::component, EqTag >()[c] ) {
      87                 :            :         // create key and search for it
      88                 :            :         ctr::DiffEqKey key{{ eq,
      89                 :            :           g_inputdeck.get< tag::param, EqTag, tag::initpolicy >()[c],
      90                 :            :           g_inputdeck.get< tag::param, EqTag, tag::coeffpolicy >()[c] }};
      91                 :            :         const auto it = m_factory.find( key );
      92                 :            :         Assert( it != end( m_factory ),
      93                 :            :                 "Can't find eq '" + ctr::DiffEq().name( eq ) +
      94                 :            :                 "' in DiffEq factory with initialization policy '" +
      95                 :            :                 ctr::InitPolicy().name(
      96                 :            :                   g_inputdeck.get< tag::param, EqTag, tag::initpolicy >()[c] ) +
      97                 :            :                 "' and coefficient policy '" +
      98                 :            :                 ctr::CoeffPolicy().name(
      99                 :            :                   g_inputdeck.get< tag::param, EqTag, tag::coeffpolicy >()[c] )
     100                 :            :                 + "'" );
     101                 :            :         // instantiate and return diff eq object
     102                 :        317 :         return it->second( c );
     103 [ -  - ][ -  - ]:          0 :       } else Throw ( "Can't create DiffEq with zero independent variables" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     104                 :            :     }
     105                 :            : 
     106                 :            :     //! \brief Instantiate tables from a differential equation
     107                 :            :     //! \details This function is used to instantiate a vector of tk::Tables and
     108                 :            :     //!   their associated names for a system of differential equation selected
     109                 :            :     //!   by the user. Since multiple systems of equations can be configured
     110                 :            :     //!   with the same type, the map (cnt) is used to assign a counter to each
     111                 :            :     //!   type. We then find out if the coefficients policy, configured to the
     112                 :            :     //!   equation system, uses tables. If so, we return all the tables and
     113                 :            :     //!   their names associated to the different components in the system. The
     114                 :            :     //!   template argument, EqTag, is used to find the given differential
     115                 :            :     //!   equation system in the input deck, the hierarchical data filled
     116                 :            :     //!   during control file parsing, containing user input.
     117                 :            :     //! \param[in] eq The unique differential equation system key whose tables
     118                 :            :     //!   object to instantiate (if the configured coefficients policy uses
     119                 :            :     //!   tables).
     120                 :            :     //! \param[in,out] cnt Counter, a std::map, that counts all instantiated
     121                 :            :     //!   vector of tables associated to a differential equations systems by
     122                 :            :     //!   type.
     123                 :            :     template< class EqTag >
     124                 :            :     std::pair< std::vector< std::string >, std::vector< tk::Table<1> > >
     125                 :         12 :     createTables( ctr::DiffEqType eq,
     126                 :            :                   std::map< ctr::DiffEqType, ncomp_t >& cnt ) const
     127                 :            :     {
     128         [ +  - ]:         12 :       auto c = ++cnt[ eq ];   // count eqs
     129                 :            :       --c;                    // used to index vectors starting with 0
     130                 :         12 :       std::vector< tk::Table<1> > tab;
     131                 :         12 :       std::vector< std::string > nam;
     132                 :            :       const auto& ncompeq = g_inputdeck.get< tag::component, EqTag >();
     133         [ +  - ]:         12 :       if (!ncompeq.empty()) {
     134         [ +  - ]:         12 :         if ( g_inputdeck.get< tag::component, EqTag >()[c] ) {
     135                 :            :           // find out if coefficients policy uses tables and return them if so
     136         [ +  + ]:         12 :           if (g_inputdeck.get< tag::param, EqTag, tag::coeffpolicy >()[c] ==
     137                 :            :                 ctr::CoeffPolicyType::HYDROTIMESCALE)
     138                 :            :           {
     139                 :            :             const auto& hts = g_inputdeck.get< tag::param,
     140                 :            :                                                EqTag,
     141                 :            :                                                tag::hydrotimescales >().at(c);
     142         [ +  - ]:          1 :             ctr::HydroTimeScales ot;
     143                 :            :             // cppcheck-suppress useStlAlgorithm
     144 [ +  + ][ +  - ]:          6 :             for (auto t : hts) tab.push_back( ot.table(t) );
     145                 :            :             // cppcheck-suppress useStlAlgorithm
     146 [ +  + ][ +  - ]:         11 :             for (auto t : hts) nam.push_back( ot.name(t) );
     147                 :            :   
     148                 :            :             const auto& hp = g_inputdeck.get< tag::param,
     149                 :            :                                               EqTag,
     150                 :            :                                               tag::hydroproductions >().at(c);
     151         [ +  - ]:          1 :             ctr::HydroProductions op;
     152                 :            :             // cppcheck-suppress useStlAlgorithm
     153 [ +  + ][ +  - ]:          6 :             for (auto t : hp) tab.push_back( op.table(t) );
     154                 :            :             // cppcheck-suppress useStlAlgorithm
     155 [ +  + ][ +  - ]:         11 :             for (auto t : hp) nam.push_back( op.name(t) );
     156                 :            :   
     157                 :            :           }
     158 [ -  - ][ -  - ]:          0 :         } else Throw ( "DiffEq with zero independent variables" );
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
     159                 :            :       }
     160         [ +  - ]:         24 :       return { nam, tab };
     161                 :            :     }
     162                 :            : 
     163                 :            :     DiffEqFactory m_factory;                 //!< Differential equations factory
     164                 :            :     std::set< ctr::DiffEqType > m_eqTypes;   //!< Count number of equation types
     165                 :            : };
     166                 :            : 
     167                 :            : } // walker::
     168                 :            : 
     169                 :            : #endif // DiffEqStack_h

Generated by: LCOV version 1.14