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 : : #include "EoS/WilkinsAluminum.hpp"
23 : : #include "EoS/GodunovRomenski.hpp"
24 : : #include "EoS/ThermallyPerfectGas.hpp"
25 : :
26 : : namespace inciter {
27 : :
28 : : //! Equation types
29 : : enum class EqType : uint8_t { compflow
30 : : , multimat
31 : : , multispecies
32 : : };
33 : :
34 : : //! Base class for generic forwarding interface to eos types
35 : : class EOS {
36 : :
37 : : private:
38 : : //! Variant type listing all eos types modeling the same concept
39 : : std::variant< StiffenedGas
40 : : , JWL
41 : : , SmallShearSolid
42 : : , WilkinsAluminum
43 : : , GodunovRomenski
44 : : , ThermallyPerfectGas
45 : : > m_material;
46 : :
47 : : public:
48 : : //! Empty constructor for Charm++
49 : : explicit EOS() {}
50 : :
51 : : //! Constructor
52 : : explicit EOS( ctr::MaterialType mattype, EqType eq, std::size_t k );
53 : :
54 : : //! Entry method tags for specific EOS classes to use with compute()
55 : : struct density {};
56 : : struct pressure {};
57 : : struct pressure_coldcompr {};
58 : : struct soundspeed {};
59 : : struct shearspeed {};
60 : : struct totalenergy {};
61 : : struct temperature {};
62 : : struct min_eff_pressure {};
63 : : struct refDensity {};
64 : : struct refPressure {};
65 : : struct rho0 {};
66 : : //! Call EOS function
67 : : //! \tparam Fn Function tag identifying the function to call
68 : : //! \tparam Args Types of arguments to pass to function
69 : : //! \param[in] args Arguments to member function to be called
70 : : //! \details This function issues a call to a member function of the
71 : : //! EOS vector and is thus equivalent to mat_blk[imat].Fn(...).
72 : : template< typename Fn, typename... Args >
73 : 418802695 : tk::real compute( Args&&... args ) const {
74 : 837605390 : return std::visit( [&]( const auto& m )-> tk::real {
75 : : if constexpr( std::is_same_v< Fn, density > )
76 : 2511156 : return m.density( std::forward< Args >( args )... );
77 : :
78 : : else if constexpr( std::is_same_v< Fn, pressure > )
79 [ - - ][ - - ]: 154303111 : return m.pressure( std::forward< Args >( args )... );
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
[ + - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
80 : :
81 : : else if constexpr( std::is_same_v< Fn, pressure_coldcompr > )
82 : : return m.pressure_coldcompr( std::forward< Args >( args )... );
83 : :
84 : : else if constexpr( std::is_same_v< Fn, soundspeed > )
85 [ + - ][ - - ]: 153482455 : return m.soundspeed( std::forward< Args >( args )... );
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ + - ][ - - ]
86 : :
87 : : else if constexpr( std::is_same_v< Fn, shearspeed > )
88 : 0 : return m.shearspeed( std::forward< Args >( args )... );
89 : :
90 : : else if constexpr( std::is_same_v< Fn, totalenergy > )
91 [ + - ][ - - ]: 14053203 : return m.totalenergy( std::forward< Args >( args )... );
[ - - ][ - - ]
[ - - ][ + - ]
[ + - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
[ - - ][ - - ]
[ - - ][ - - ]
[ - - ][ + - ]
92 : :
93 : : else if constexpr( std::is_same_v< Fn, temperature > )
94 [ - - ][ - - ]: 2365840 : return m.temperature( std::forward< Args >( args )... );
[ - - ][ - - ]
[ - - ][ - - ]
95 : :
96 : : else if constexpr( std::is_same_v< Fn, min_eff_pressure > )
97 : 92086930 : return m.min_eff_pressure( std::forward< Args >( args )... );
98 : :
99 : : else if constexpr( std::is_same_v< Fn, refDensity > )
100 : : return m.refDensity( std::forward< Args >( args )... );
101 : :
102 : : else if constexpr( std::is_same_v< Fn, refPressure > )
103 : : return m.refPressure( std::forward< Args >( args )... );
104 : :
105 : : else if constexpr( std::is_same_v< Fn, rho0 > )
106 : 0 : return m.rho0( std::forward< Args >( args )... );
107 [ + - ]: 837605390 : }, m_material );
108 : : }
109 : :
110 : : //! Entry method tags for specific EOS classes to use with computeTensor()
111 : : struct CauchyStress {};
112 : : //! Call EOS function returning a tensor
113 : : //! \tparam Fn Function tag identifying the function to call
114 : : //! \tparam Args Types of arguments to pass to function
115 : : //! \param[in] args Arguments to member function to be called
116 : : //! \details This function issues a call to a member function of the
117 : : //! EOS vector and is thus equivalent to mat_blk[imat].Fn(...).
118 : : template< typename Fn, typename... Args >
119 : 0 : std::array< std::array< tk::real, 3 >, 3 > computeTensor( Args&&... args )
120 : : const {
121 : 0 : return std::visit( [&]( const auto& m )->
122 : : std::array< std::array< tk::real, 3 >, 3 > {
123 : : if constexpr( std::is_same_v< Fn, CauchyStress > )
124 : 0 : return m.CauchyStress( std::forward< Args >( args )... );
125 : :
126 [ - - ]: 0 : }, m_material );
127 : : }
128 : :
129 : : //! Entry method tags for specific EOS classes to use with set()
130 : : struct setRho0 {};
131 : : //! Call EOS function
132 : : //! \tparam Fn Function tag identifying the function to call
133 : : //! \tparam Args Types of arguments to pass to function
134 : : //! \param[in] args Arguments to member function to be called
135 : : //! \details This function issues a call to a member function of the
136 : : //! EOS vector and is thus equivalent to mat_blk[imat].Fn(...).
137 : : template< typename Fn, typename... Args >
138 : 539 : void set( Args&&... args ) {
139 : 2156 : std::visit( [&]( auto& m )-> void {
140 : : if constexpr( std::is_same_v< Fn, setRho0 > )
141 : 539 : m.setRho0( std::forward< Args >( args )... );
142 [ + - ]: 539 : }, m_material );
143 : 539 : }
144 : :
145 : : /** @name Charm++ pack/unpack serializer member functions */
146 : : ///@{
147 : : //! \brief Pack/Unpack serialize member function
148 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
149 : : void pup( PUP::er &p ) {
150 : : p | m_material;
151 : : }
152 : : //! \brief Pack/Unpack serialize operator|
153 : : //! \param[in,out] p Charm++'s PUP::er serializer object reference
154 : : //! \param[in,out] s EOS object reference
155 : : friend void operator|( PUP::er& p, EOS& s ) { s.pup(p); }
156 : : //@}
157 : : };
158 : :
159 : : } // inciter::
160 : :
161 : : #endif // EOS_h
|