Quinoa all test code coverage report
Current view: top level - PDE - PDEFactory.hpp (source / functions) Hit Total Coverage
Commit: Quinoa_v0.3-957-gb4f0efae0 Lines: 10 10 100.0 %
Date: 2021-11-11 18:25:50 Functions: 61 61 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 4 50.0 %

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/PDE/PDEFactory.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     Differential equations factory
       9                 :            :   \details   This file declares the type for a differential equations factory.
      10                 :            : */
      11                 :            : // *****************************************************************************
      12                 :            : #ifndef PDEFactory_h
      13                 :            : #define PDEFactory_h
      14                 :            : 
      15                 :            : #include <map>
      16                 :            : #include <set>
      17                 :            : 
      18                 :            : #include "CGPDE.hpp"
      19                 :            : #include "DGPDE.hpp"
      20                 :            : #include "Factory.hpp"
      21                 :            : #include "SystemComponents.hpp"
      22                 :            : #include "Inciter/Options/PDE.hpp"
      23                 :            : 
      24                 :            : namespace inciter {
      25                 :            : 
      26                 :            : //! \brief Factory for PDEs using continuous Galerkin discretization storing
      27                 :            : //!   keys associated to their constructors
      28                 :            : using CGFactory =
      29                 :            :   std::map< ctr::PDEKey, std::function< CGPDE(const tk::ctr::ncomp_t&) > >;
      30                 :            : 
      31                 :            : //! \brief Factory for PDEs using discontinuous Galerkin discretization storing
      32                 :            : //!   keys associated to their constructors
      33                 :            : using DGFactory =
      34                 :            :   std::map< ctr::PDEKey, std::function< DGPDE(const tk::ctr::ncomp_t&) > >;
      35                 :            : 
      36                 :            : //! \brief Function object for registering a partial differential equation
      37                 :            : //!   into the partial differential equation factory
      38                 :            : //! \details This functor is repeatedly called by MPL's cartesian_product,
      39                 :            : //!   sweeping all combinations of the partial differential equation
      40                 :            : //!   policies. The purpose of template template is to simplify client code
      41                 :            : //!   as that will not have to specify the template arguments of the
      42                 :            : //!   template argument (the policies of Eq), since we can figure it out
      43                 :            : //!   here. See also http://stackoverflow.com/a/214900. The template
      44                 :            : //!   argument Eq specifies a "child" class that is used polymorphically
      45                 :            : //!   with a "base" class modeling a concept defined in the base. The base
      46                 :            : //!   is given by the template argument PDE. The template argument Factory
      47                 :            : //!   specifies which factory to store the registered and configured child
      48                 :            : //1   PDE.
      49                 :            : template< template< class, class > class Eq, class Factory, class PDE >
      50                 :            : struct registerPDE {
      51                 :            :   //! Need to store the reference to factory we are registering into
      52                 :            :   Factory& factory;
      53                 :            :   //! Need to store which differential equation we are registering
      54                 :            :   const ctr::PDEType type;
      55                 :            :   //! Constructor, also count number of unique equation types registered
      56                 :            :   //! \param[in,out] f Factory into which to register PDE
      57                 :            :   //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h
      58                 :            :   //! \param[in] eqTypes Equation type counters
      59                 :       7825 :   explicit registerPDE( Factory& f,
      60                 :            :                         ctr::PDEType t,
      61                 :            :                         std::set< ctr::PDEType >& eqTypes ) :
      62                 :       7825 :     factory( f ), type( t ) { eqTypes.insert( t ); }
      63                 :            :   //! \brief Function call operator called with tk::cartesian_product for
      64                 :            :   //!   each unique sequence of policy combinations
      65                 :      79815 :   template< typename U > void operator()( brigand::type_<U> ) {
      66                 :            :     // Get problem policy: first type of brigand::list U
      67                 :            :     using Physics = typename brigand::front< U >;
      68                 :            :     // Get problem policy: last type of brigand::list U
      69                 :            :     using Problem = typename brigand::back< U >;
      70                 :            :     // Build differential equation key
      71         [ +  - ]:      79815 :     ctr::PDEKey key{{ type, Physics::type(), Problem::type() }};
      72                 :            :     // Register equation (with policies given by brigand::list U) into factory
      73                 :            :     tk::recordModelLate< PDE, Eq< Physics, Problem > >
      74         [ +  - ]:      79815 :                        ( factory, key, static_cast<tk::ctr::ncomp_t>(0) );
      75                 :      79815 :   }
      76                 :            : };
      77                 :            : 
      78                 :            : //! Wrapper of registerPDE specialized for registering CG PDEs
      79                 :            : //! \details The sole reason for this functor is to simplify client-code
      80                 :            : //!   calling registerPDE specialized to CG PDEs
      81                 :            : template< template< class, class > class Eq >
      82                 :            : struct registerCG : registerPDE< Eq, CGFactory, CGPDE > {
      83                 :            :   //! Delegate constructor to base and specialize to CG
      84                 :            :   //! \param[in] f Factory to register to
      85                 :            :   //! \param[in] eqtypes Counters for equation types in factory
      86                 :            :   //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h
      87                 :       3130 :   explicit registerCG( CGFactory& f,
      88                 :            :                        std::set< ctr::PDEType >& eqtypes,
      89                 :            :                        ctr::PDEType t ) :
      90                 :       3130 :     registerPDE< Eq, CGFactory, CGPDE >( f, t, eqtypes ) {}
      91                 :            : };
      92                 :            : 
      93                 :            : //! Wrapper of registerPDE specialized for registering DG PDEs
      94                 :            : //! \details The sole reason for this functor is to simplify client-code
      95                 :            : //!   calling registerPDE specialized to DG PDEs
      96                 :            : template< template< class, class > class Eq >
      97                 :            : struct registerDG : registerPDE< Eq, DGFactory, DGPDE > {
      98                 :            :   //! Delegate constructor to base and specialize to CG
      99                 :            :   //! \param[in] f Factory to register to
     100                 :            :   //! \param[in] eqtypes Counters for equation types in factory
     101                 :            :   //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h
     102                 :       4695 :   explicit registerDG( DGFactory& f,
     103                 :            :                        std::set< ctr::PDEType >& eqtypes,
     104                 :            :                        ctr::PDEType t ) :
     105                 :       4695 :     registerPDE< Eq, DGFactory, DGPDE >( f, t, eqtypes ) {}
     106                 :            : };
     107                 :            : 
     108                 :            : } // inciter::
     109                 :            : 
     110                 :            : #endif // PDEFactory_h

Generated by: LCOV version 1.14