Quinoa all test code coverage report
Current view: top level - PDE - PDEStack.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 24 25 96.0 %
Date: 2024-11-22 08:51:48 Functions: 18 20 90.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 52 21.2 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/PDE/PDEStack.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 PDEStack, which implements various
      10                 :            :     functionality related to registering and instantiating partial differential
      11                 :            :     equation types. Registration and instantiation use a partial differential
      12                 :            :     equation factory, which is a std::map (an associative container),
      13                 :            :     associating unique partial differential equation keys to their constructor
      14                 :            :     calls. For more details, see the in-code documentation of the constructor.
      15                 :            : */
      16                 :            : // *****************************************************************************
      17                 :            : #ifndef PDEStack_h
      18                 :            : #define PDEStack_h
      19                 :            : 
      20                 :            : #include <map>
      21                 :            : #include <set>
      22                 :            : #include <string>
      23                 :            : #include <vector>
      24                 :            : #include <iostream>
      25                 :            : 
      26                 :            : #include "NoWarning/back.hpp"
      27                 :            : #include "NoWarning/front.hpp"
      28                 :            : 
      29                 :            : #include "Tags.hpp"
      30                 :            : #include "Types.hpp"
      31                 :            : #include "Exception.hpp"
      32                 :            : #include "Factory.hpp"
      33                 :            : #include "CGPDE.hpp"
      34                 :            : #include "DGPDE.hpp"
      35                 :            : #include "FVPDE.hpp"
      36                 :            : #include "PDEFactory.hpp"
      37                 :            : #include "Inciter/InputDeck/InputDeck.hpp"
      38                 :            : 
      39                 :            : namespace inciter {
      40                 :            : 
      41                 :            : extern ctr::InputDeck g_inputdeck;
      42                 :            : 
      43                 :            : //! \brief Partial differential equations stack
      44                 :            : class PDEStack {
      45                 :            : 
      46                 :            :   private:
      47                 :            :     using ncomp_t = tk::ncomp_t;
      48                 :            : 
      49                 :            :   public:
      50                 :            :     //! Constructor: register partial differential equations into factory
      51                 :            :     explicit PDEStack();
      52                 :            : 
      53                 :            :     //! Instantiate selected PDEs using continuous Galerkin discretization
      54                 :            :     std::vector< CGPDE > selectedCG() const;
      55                 :            : 
      56                 :            :     //! Instantiate selected PDEs using discontinuous Galerkin discretization
      57                 :            :     std::vector< DGPDE > selectedDG() const;
      58                 :            : 
      59                 :            :     //! Instantiate selected PDEs using finite volume discretization
      60                 :            :     std::vector< FVPDE > selectedFV() const;
      61                 :            : 
      62                 :            :     //! Constant accessor to CGPDE factory
      63                 :            :     //! \return Constant reference to the CGPDE factory
      64                 :        189 :     const CGFactory& cgfactory() const { return m_cgfactory; }
      65                 :            : 
      66                 :            :     //! Constant accessor to DGPDE factory
      67                 :            :     //! \return Constant reference to the DGPDE factory
      68                 :        189 :     const DGFactory& dgfactory() const { return m_dgfactory; }
      69                 :            : 
      70                 :            :     //! Constant accessor to FVPDE factory
      71                 :            :     //! \return Constant reference to the FVPDE factory
      72                 :        189 :     const FVFactory& fvfactory() const { return m_fvfactory; }
      73                 :            : 
      74                 :            :     //! Return info on selected partial differential equations
      75                 :            :     std::vector< std::vector< std::pair< std::string, std::string > > > info()
      76                 :            :     const;
      77                 :            : 
      78                 :            :     //! Return number of unique equation types registered into the CG factory
      79                 :            :     //! \return The number of unique equation types registered into the CG
      80                 :            :     //!   factory the factory
      81                 :        189 :     std::size_t cgntypes() const { return m_cgEqTypes.size(); }
      82                 :            : 
      83                 :            :     //! Return number of unique equation types registered into the DG factory
      84                 :            :     //! \return The number of unique equation types registered into the DG
      85                 :            :     //!   factory the factory
      86                 :        189 :     std::size_t dgntypes() const { return m_dgEqTypes.size(); }
      87                 :            : 
      88                 :            :     //! Return number of unique equation types registered into the FV factory
      89                 :            :     //! \return The number of unique equation types registered into the FV
      90                 :            :     //!   factory the factory
      91                 :        189 :     std::size_t fvntypes() const { return m_fvEqTypes.size(); }
      92                 :            : 
      93                 :            :   private:
      94                 :            :     //! \brief Instantiate a partial differential equation
      95                 :            :     //! \details The template argument, EqTag, is used to find the given
      96                 :            :     //!   partial differential equation in the input deck, the hierarchical data
      97                 :            :     //!   filled during control file parsing, containing user input. The
      98                 :            :     //!   template argument Factory specifies which factory we search in. The
      99                 :            :     //!   template argument PDE specifies the "base" PDE type that the
     100                 :            :     //!   instantiated "child" PDE class object is used polymorphically with.
     101                 :            :     //! \param[in] f Factory in which to search PDE in
     102                 :            :     //! \param[in] eq The unique partial differential equation key whose object
     103                 :            :     //!   to instantiate.
     104                 :            :     //! \param[in,out] cnt Counter, a std::map, that counts all instantiated
     105                 :            :     //!   partial differential equations by type.
     106                 :            :     template< class EqTag, class Factory, class PDE >
     107                 :        784 :     PDE createPDE( const Factory& f,
     108                 :            :                    ctr::PDEType eq,
     109                 :            :                    std::map< ctr::PDEType, ncomp_t >& cnt ) const
     110                 :            :     {
     111                 :        784 :       auto c = ++cnt[ eq ];   // count eqs
     112                 :        784 :       --c;                    // used to index vectors starting with 0
     113                 :        784 :       const auto& nc = g_inputdeck.get< tag::ncomp >();
     114         [ +  - ]:        784 :       if ( nc ) {
     115                 :            :         // re-create key and search for it
     116                 :        784 :         auto prob = g_inputdeck.get< EqTag, tag::problem >();
     117                 :            :         // if more than one mesh, set problem type for all additional meshes
     118                 :            :         // as user-defined
     119 [ +  - ][ +  + ]:        784 :         if (cnt[eq] > 1) prob = ctr::ProblemType::USER_DEFINED;
     120         [ +  - ]:        784 :         ctr::PDEKey key{{ eq,
     121                 :            :           g_inputdeck.get< EqTag, tag::physics >(), prob }};
     122         [ +  - ]:        784 :         const auto it = f.find( key );
     123 [ -  + ][ -  - ]:        784 :         Assert( it != end( f ),
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
         [ -  - ][ -  - ]
                 [ -  - ]
     124                 :            :                 "Can't find PDE with key('" +
     125                 :            :                   ctr::PDE().name( key.get< tag::pde >() ) + "', '" +
     126                 :            :                   ctr::Physics().name( key.get< tag::physics >() ) + "', '" +
     127                 :            :                   ctr::Problem().name( key.get< tag::problem >() ) +
     128                 :            :                   + "') in factory" );
     129                 :            :         // Associate equation system index (value) to all variable offsets
     130 [ +  + ][ +  - ]:       4557 :         for (ncomp_t i=0; i<nc; ++i) g_inputdeck.get<tag::sys>()[i] = c;
     131                 :            :         // instantiate and return PDE object
     132         [ +  - ]:       1568 :         return it->second();
     133 [ -  - ][ -  - ]:          0 :       } else Throw ( "Can't create PDE with zero components" );
                 [ -  - ]
     134                 :            :     }
     135                 :            : 
     136                 :            :     //! Wrapper of createPDE specialized for registering CG PDEs
     137                 :            :     //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h
     138                 :            :     //! \param[in,out] cnt Counter, a std::map, that counts all instantiated
     139                 :            :     //!   partial differential equations by type.
     140                 :            :     //! \details The sole reason for this function is to simplify client-code
     141                 :            :     //!   calling createPDE specialized to CG PDEs
     142                 :            :     template< class EqTag >
     143                 :        326 :     CGPDE createCG( ctr::PDEType t, std::map< ctr::PDEType, ncomp_t >& cnt )
     144                 :            :     const {
     145                 :        326 :       return createPDE< EqTag, CGFactory, CGPDE >( m_cgfactory, t, cnt );
     146                 :            :     }
     147                 :            : 
     148                 :            :     //! Wrapper of createPDE specialized for registering DG PDEs
     149                 :            :     //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h
     150                 :            :     //! \param[in,out] cnt Counter, a std::map, that counts all instantiated
     151                 :            :     //!   partial differential equations by type.
     152                 :            :     //! \details The sole reason for this function is to simplify client-code
     153                 :            :     //!   calling createPDE specialized to DG PDEs
     154                 :            :     template< class EqTag >
     155                 :        377 :     DGPDE createDG( ctr::PDEType t, std::map< ctr::PDEType, ncomp_t >& cnt )
     156                 :            :     const {
     157                 :        377 :       return createPDE< EqTag, DGFactory, DGPDE >( m_dgfactory, t, cnt );
     158                 :            :     }
     159                 :            : 
     160                 :            :     //! Wrapper of createPDE specialized for registering FV PDEs
     161                 :            :     //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h
     162                 :            :     //! \param[in,out] cnt Counter, a std::map, that counts all instantiated
     163                 :            :     //!   partial differential equations by type.
     164                 :            :     //! \details The sole reason for this function is to simplify client-code
     165                 :            :     //!   calling createPDE specialized to FV PDEs
     166                 :            :     template< class EqTag >
     167                 :         81 :     FVPDE createFV( ctr::PDEType t, std::map< ctr::PDEType, ncomp_t >& cnt )
     168                 :            :     const {
     169                 :         81 :       return createPDE< EqTag, FVFactory, FVPDE >( m_fvfactory, t, cnt );
     170                 :            :     }
     171                 :            : 
     172                 :            :     //! PDE factory for continuous Galerkin discretization
     173                 :            :     CGFactory m_cgfactory;
     174                 :            :     //! PDE factory for discontinuous Galerkin discretization
     175                 :            :     DGFactory m_dgfactory;
     176                 :            :     //! PDE factory for finite volume discretization
     177                 :            :     FVFactory m_fvfactory;
     178                 :            :     //! Counters for equation types registered into the CG factory
     179                 :            :     std::set< ctr::PDEType > m_cgEqTypes;
     180                 :            :     //! Counters for equation types registered into the DG factory
     181                 :            :     std::set< ctr::PDEType > m_dgEqTypes;
     182                 :            :     //! Counters for equation types registered into the FV factory
     183                 :            :     std::set< ctr::PDEType > m_fvEqTypes;
     184                 :            : };
     185                 :            : 
     186                 :            : } // inciter::
     187                 :            : 
     188                 :            : #endif // PDEStack_h

Generated by: LCOV version 1.14