Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/PDE/EoS/EOS.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 Polymorphic variant-style implementation for equations of state,
9 : : where children implement specific EOS functions.
10 : : */
11 : : // *****************************************************************************
12 : : #ifndef EOS_h
13 : : #define EOS_h
14 : :
15 : : #include <variant>
16 : :
17 : : #include "PUPUtil.hpp"
18 : : #include "Inciter/Options/Material.hpp"
19 : : #include "EoS/StiffenedGas.hpp"
20 : : #include "EoS/JWL.hpp"
21 : : #include "EoS/SmallShearSolid.hpp"
22 : :
23 : : namespace inciter {
24 : :
25 : : //! Equation types
26 : : enum class EqType : uint8_t { compflow
27 : : , multimat
28 : : };
29 : :
30 : : //! Base class for generic forwarding interface to eos types
31 : : class EOS {
32 : :
33 : : private:
34 : : //! Variant type listing all eos types modeling the same concept
35 : : std::variant< StiffenedGas
36 : : , JWL
37 : : , SmallShearSolid
38 : : > m_material;
39 : :
40 : : public:
41 : : //! Empty constructor for Charm++
42 : : explicit EOS() {}
43 : :
44 : : //! Constructor
45 : : explicit EOS( ctr::MaterialType mattype, EqType eq, std::size_t k );
46 : :
47 : : //! Entry method tags for specific EOS classes to use with compute()
48 : : struct density {};
49 : : struct pressure {};
50 : : struct soundspeed {};
51 : : struct totalenergy {};
52 : : struct temperature {};
53 : : struct min_eff_pressure {};
54 : : struct refDensity {};
55 : : struct refPressure {};
56 : : //! Call EOS function
57 : : //! \tparam Fn Function tag identifying the function to call
58 : : //! \tparam Args Types of arguments to pass to function
59 : : //! \param[in] args Arguments to member function to be called
60 : : //! \details This function issues a call to a member function of the
61 : : //! EOS vector and is thus equivalent to mat_blk[imat].Fn(...).
62 : : template< typename Fn, typename... Args >
63 : 471983472 : tk::real compute( Args&&... args ) const {
64 : 943966944 : return std::visit( [&]( const auto& m )-> tk::real {
65 : : if constexpr( std::is_same_v< Fn, density > )
66 : 2196200 : return m.density( std::forward< Args >( args )... );
67 : :
68 : : else if constexpr( std::is_same_v< Fn, pressure > )
69 [ - - ][ - - ]: 172621291 : return m.pressure( std::forward< Args >( args )... );
[ + - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ + - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ + - ]
70 : :
71 : : else if constexpr( std::is_same_v< Fn, soundspeed > )
72 [ - - ][ - - ]: 173158725 : return m.soundspeed( std::forward< Args >( args )... );
[ + - ][ + - ]
[ - - ][ + - ]
[ + - ][ - - ]
[ + - ][ - - ]
[ - - ][ + - ]
73 : :
74 : : else if constexpr( std::is_same_v< Fn, totalenergy > )
75 [ - - ][ - - ]: 15352658 : return m.totalenergy( std::forward< Args >( args )... );
[ + - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ + - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ + - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ + - ]
76 : :
77 : : else if constexpr( std::is_same_v< Fn, temperature > )
78 [ - - ][ - - ]: 2568604 : return m.temperature( std::forward< Args >( args )... );
[ + - ]
79 : :
80 : : else if constexpr( std::is_same_v< Fn, min_eff_pressure > )
81 : 106085994 : return m.min_eff_pressure( std::forward< Args >( args )... );
82 : :
83 : : else if constexpr( std::is_same_v< Fn, refDensity > )
84 : : return m.refDensity( std::forward< Args >( args )... );
85 : :
86 : : else if constexpr( std::is_same_v< Fn, refPressure > )
87 : : return m.refPressure( std::forward< Args >( args )... );
88 [ + - ]: 943966944 : }, m_material );
89 : : }
90 : :
91 : : //! Entry method tags for specific EOS classes to use with computeTensor()
92 : : struct CauchyStress {};
93 : : //! Call EOS function returning a tensor
94 : : //! \tparam Fn Function tag identifying the function to call
95 : : //! \tparam Args Types of arguments to pass to function
96 : : //! \param[in] args Arguments to member function to be called
97 : : //! \details This function issues a call to a member function of the
98 : : //! EOS vector and is thus equivalent to mat_blk[imat].Fn(...).
99 : : template< typename Fn, typename... Args >
100 : 102548 : std::array< std::array< tk::real, 3 >, 3 > computeTensor( Args&&... args )
101 : : const {
102 : 205096 : return std::visit( [&]( const auto& m )->
103 : : std::array< std::array< tk::real, 3 >, 3 > {
104 : : if constexpr( std::is_same_v< Fn, CauchyStress > )
105 : 102548 : return m.CauchyStress( std::forward< Args >( args )... );
106 : :
107 [ + - ]: 205096 : }, m_material );
108 : : }
109 : :
110 : : /** @name Charm++ pack/unpack serializer member functions */
111 : : ///@{
112 : : //! \brief Pack/Unpack serialize member function
113 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
114 : : void pup( PUP::er &p ) {
115 : : p | m_material;
116 : : }
117 : : //! \brief Pack/Unpack serialize operator|
118 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
119 : : //! \param[in,out] s EOS object reference
120 : : friend void operator|( PUP::er& p, EOS& s ) { s.pup(p); }
121 : : //@}
122 : : };
123 : :
124 : : } // inciter::
125 : :
126 : : #endif // EOS_h
|