Branch data Line data Source code
1 : : // ***************************************************************************** 2 : : /*! 3 : : \file src/PDE/MultiMat/RiemannFactory.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 Register available Riemann solvers for multimaterial compressible 9 : : hydrodynamics into a factory 10 : : \details Register available Riemann solvers for multimaterial compressible 11 : : hydrodynamics into a factory. 12 : : */ 13 : : // ***************************************************************************** 14 : : #ifndef RiemannSolverFactory_h 15 : : #define RiemannSolverFactory_h 16 : : 17 : : #include <map> 18 : : #include <functional> 19 : : 20 : : #include "NoWarning/value_factory.hpp" 21 : : 22 : : #include "Riemann/RiemannSolver.hpp" 23 : : #include "Inciter/Options/Flux.hpp" 24 : : 25 : : namespace inciter { 26 : : 27 : : //! Factory for Riemann solvers 28 : : //! \details This factory is used to store the constructors as a 29 : : //! std::function of specific Riemann solvers that can be invoked at a 30 : : //! later time compared to the point where the map is populated. The key 31 : : //! is an enum, uniquely idenfitying a specific Riemann solver. The value 32 : : //! is std::function storing a constructor to be invoked. The type of 33 : : //! object stored in std::function is a generic (base) class constructor, 34 : : //! which provides a polymorphyic interface (overridable functions) that 35 : : //! specific (child) Riemann solvers override, yielding runtime polymorphism. 36 : : using MultiMatRiemannFactory = 37 : : std::map< ctr::FluxType, std::function< RiemannSolver() > >; 38 : : 39 : : //! Functor to register a Riemann solver into the Riemann solver factory 40 : : struct registerRiemannSolver { 41 : : //! Factory to which to register the Riemann solver 42 : : MultiMatRiemannFactory& factory; 43 : : //! Constructor 44 : : //! \param[in] f Factory 45 : 0 : explicit registerRiemannSolver( MultiMatRiemannFactory& f ) : factory( f ) {} 46 : : //! \brief Function call operator templated on the type that implements 47 : : //! a specific Riemann solver 48 : 60 : template< typename U > void operator()( brigand::type_<U> ) { 49 : : // Function object holding the (default) constructor to be called later 50 : : // without bound arguments, since all specific Riemann solvers' 51 : : // constructors are compiler-generated (default) constructors, and thus 52 : : // taking no arguments. 53 [ + - ]: 60 : std::function< U() > c = boost::value_factory< U >(); 54 : : // Associate constructor function object to flux type in factory 55 [ + - ][ + - ]: 60 : factory.emplace( U::type(), 56 : 60 : std::bind(boost::value_factory< RiemannSolver >(), std::move(c)) ); 57 : 60 : } 58 : : }; 59 : : 60 : : //! Register available Riemann solvers into a factory 61 : : MultiMatRiemannFactory multimatRiemannSolvers(); 62 : : 63 : : } // inciter:: 64 : : 65 : : #endif // RiemannSolverFactory_h