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 "FVPDE.hpp" 21 : : #include "Factory.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() > >; 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() > >; 35 : : 36 : : //! \brief Factory for PDEs using finite volume discretization storing 37 : : //! keys associated to their constructors 38 : : using FVFactory = 39 : : std::map< ctr::PDEKey, std::function< FVPDE() > >; 40 : : 41 : : //! \brief Function object for registering a partial differential equation 42 : : //! into the partial differential equation factory 43 : : //! \details This functor is repeatedly called by MPL's cartesian_product, 44 : : //! sweeping all combinations of the partial differential equation 45 : : //! policies. The purpose of template template is to simplify client code 46 : : //! as that will not have to specify the template arguments of the 47 : : //! template argument (the policies of Eq), since we can figure it out 48 : : //! here. See also http://stackoverflow.com/a/214900. The template 49 : : //! argument Eq specifies a "child" class that is used polymorphically 50 : : //! with a "base" class modeling a concept defined in the base. The base 51 : : //! is given by the template argument PDE. The template argument Factory 52 : : //! specifies which factory to store the registered and configured child 53 : : //1 PDE. 54 : : template< template< class, class > class Eq, class Factory, class PDE > 55 : : struct registerPDE { 56 : : //! Need to store the reference to factory we are registering into 57 : : Factory& factory; 58 : : //! Need to store which differential equation we are registering 59 : : const ctr::PDEType type; 60 : : //! Constructor, also count number of unique equation types registered 61 : : //! \param[in,out] f Factory into which to register PDE 62 : : //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h 63 : : //! \param[in] eqTypes Equation type counters 64 : 15897 : explicit registerPDE( Factory& f, 65 : : ctr::PDEType t, 66 : : std::set< ctr::PDEType >& eqTypes ) : 67 : 15897 : factory( f ), type( t ) { eqTypes.insert( t ); } 68 : : //! \brief Function call operator called with tk::cartesian_product for 69 : : //! each unique sequence of policy combinations 70 : 177138 : template< typename U > void operator()( brigand::type_<U> ) { 71 : : // Get problem policy: first type of brigand::list U 72 : : using Physics = typename brigand::front< U >; 73 : : // Get problem policy: last type of brigand::list U 74 : : using Problem = typename brigand::back< U >; 75 : : // Build differential equation key 76 [ + - ]: 177138 : ctr::PDEKey key{{ type, Physics::type(), Problem::type() }}; 77 : : // Register equation (with policies given by brigand::list U) into factory 78 [ + - ]: 177138 : tk::recordModelLate< PDE, Eq< Physics, Problem > >( factory, key ); 79 : 177138 : } 80 : : }; 81 : : 82 : : //! Wrapper of registerPDE specialized for registering CG PDEs 83 : : //! \details The sole reason for this functor is to simplify client-code 84 : : //! calling registerPDE specialized to CG PDEs 85 : : template< template< class, class > class Eq > 86 : : struct registerCG : registerPDE< Eq, CGFactory, CGPDE > { 87 : : //! Delegate constructor to base and specialize to CG 88 : : //! \param[in] f Factory to register to 89 : : //! \param[in] eqtypes Counters for equation types in factory 90 : : //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h 91 : 4542 : explicit registerCG( CGFactory& f, 92 : : std::set< ctr::PDEType >& eqtypes, 93 : : ctr::PDEType t ) : 94 : 4542 : registerPDE< Eq, CGFactory, CGPDE >( f, t, eqtypes ) {} 95 : : }; 96 : : 97 : : //! Wrapper of registerPDE specialized for registering DG PDEs 98 : : //! \details The sole reason for this functor is to simplify client-code 99 : : //! calling registerPDE specialized to DG PDEs 100 : : template< template< class, class > class Eq > 101 : : struct registerDG : registerPDE< Eq, DGFactory, DGPDE > { 102 : : //! Delegate constructor to base and specialize to CG 103 : : //! \param[in] f Factory to register to 104 : : //! \param[in] eqtypes Counters for equation types in factory 105 : : //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h 106 : 9084 : explicit registerDG( DGFactory& f, 107 : : std::set< ctr::PDEType >& eqtypes, 108 : : ctr::PDEType t ) : 109 : 9084 : registerPDE< Eq, DGFactory, DGPDE >( f, t, eqtypes ) {} 110 : : }; 111 : : 112 : : //! Wrapper of registerPDE specialized for registering FV PDEs 113 : : //! \details The sole reason for this functor is to simplify client-code 114 : : //! calling registerPDE specialized to FV PDEs 115 : : template< template< class, class > class Eq > 116 : : struct registerFV : registerPDE< Eq, FVFactory, FVPDE > { 117 : : //! Delegate constructor to base and specialize to FV 118 : : //! \param[in] f Factory to register to 119 : : //! \param[in] eqtypes Counters for equation types in factory 120 : : //! \param[in] t Enum selecting PDE type, Control/Inciter/Options/PDE.h 121 : 2271 : explicit registerFV( FVFactory& f, 122 : : std::set< ctr::PDEType >& eqtypes, 123 : : ctr::PDEType t ) : 124 : 2271 : registerPDE< Eq, FVFactory, FVPDE >( f, t, eqtypes ) {} 125 : : }; 126 : : 127 : : } // inciter:: 128 : : 129 : : #endif // PDEFactory_h