Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/DiffEq/Beta/MassFractionBeta.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 System of mass-fraction beta SDEs
9 : : \details This file implements the time integration of a system of stochastic
10 : : differential equations (SDEs) with linear drift and quadratic diagonal
11 : : diffusion, whose invariant is the joint [beta
12 : : distribution](http://en.wikipedia.org/wiki/Beta_distribution). The main
13 : : difference compared to the plain beta SDE (see DiffEq/Beta.h), is that in
14 : : the mass-fraction beta SDE the dependent variable, there are two
15 : : additional stochastic variables computed from the beta variables.
16 : :
17 : : In a nutshell, the equation integrated governs a set of scalars,
18 : : \f$0\!\le\!Y_\alpha\f$, \f$\alpha\!=\!1,\dots,N\f$, as
19 : :
20 : : @m_class{m-show-m}
21 : :
22 : : \f[
23 : : \mathrm{d}Y_\alpha(t) = \frac{b_\alpha}{2}\left(S_\alpha - Y_\alpha\right)
24 : : \mathrm{d}t + \sqrt{\kappa_\alpha Y_\alpha(1-Y_\alpha)}
25 : : \mathrm{d}W_\alpha(t), \qquad \alpha=1,\dots,N
26 : : \f]
27 : :
28 : : @m_class{m-hide-m}
29 : :
30 : : \f[ \begin{split}
31 : : \mathrm{d}Y_\alpha(t) = \frac{b_\alpha}{2}\left(S_\alpha - Y_\alpha\right)
32 : : \mathrm{d}t + \sqrt{\kappa_\alpha Y_\alpha(1-Y_\alpha)}
33 : : \mathrm{d}W_\alpha(t), \\ \alpha=1,\dots,N
34 : : \end{split} \f]
35 : :
36 : : with parameter vectors \f$b_\alpha > 0\f$, \f$\kappa_\alpha > 0\f$, and \f$0
37 : : < S_\alpha < 1\f$. This is the same as in DiffEq/Beta.h. Here
38 : : \f$\mathrm{d}W_\alpha(t)\f$ is an isotropic vector-valued [Wiener
39 : : process](http://en.wikipedia.org/wiki/Wiener_process) with independent
40 : : increments. The invariant distribution is the joint beta distribution. This
41 : : system of SDEs consists of N independent equations. For
42 : : more on the beta SDE, see https://doi.org/10.1080/14685248.2010.510843.
43 : :
44 : : In addition to integrating the above SDE, there are two additional functions
45 : : of \f$ Y_\alpha \f$ are computed as
46 : : \f[ \begin{aligned}
47 : : \rho(Y_\alpha) & = \frac{ \rho_{2\alpha} }{ 1 + r_\alpha Y_\alpha } \\
48 : : V(Y_\alpha) & = \frac{1}{ \rho(Y_\alpha) }
49 : : \end{aligned} \f]
50 : : These equations compute the instantaneous mixture density, \f$ \rho \f$, and
51 : : instantaneous specific volume, \f$ V_\alpha \f$, for equation \f$ \alpha \f$
52 : : in the system. These quantities are used in binary mixing of
53 : : variable-density turbulence between two fluids with constant densities, \f$
54 : : \rho_1, \f$ and \f$ \rho_2 \f$. The additional parameters, \f$ \rho_2 \f$
55 : : and \f$ r' \f$ are user input parameters and kept constant during
56 : : integration. Since we compute the above variables, \f$\rho,\f$ and \f$V\f$,
57 : : and call them mixture density and specific volume, respectively, \f$Y\f$,
58 : : governed by the beta SDE is a mass fraction, hence the name mass-fraction
59 : : beta.
60 : :
61 : : _All of this is unpublished, but will be linked in here once published_.
62 : : */
63 : : // *****************************************************************************
64 : : #ifndef MassFractionBeta_h
65 : : #define MassFractionBeta_h
66 : :
67 : : #include <vector>
68 : : #include <cmath>
69 : :
70 : : #include "InitPolicy.hpp"
71 : : #include "MassFractionBetaCoeffPolicy.hpp"
72 : : #include "RNG.hpp"
73 : : #include "Particles.hpp"
74 : :
75 : : namespace walker {
76 : :
77 : : extern ctr::InputDeck g_inputdeck;
78 : : extern std::map< tk::ctr::RawRNGType, tk::RNG > g_rng;
79 : :
80 : : //! \brief MassFractionBeta SDE used polymorphically with DiffEq
81 : : //! \details The template arguments specify policies and are used to configure
82 : : //! the behavior of the class. The policies are:
83 : : //! - Init - initialization policy, see DiffEq/InitPolicy.h
84 : : //! - Coefficients - coefficients policy, see
85 : : //! DiffEq/MassFractionBetaCoeffPolicy.h
86 : : template< class Init, class Coefficients >
87 : : class MassFractionBeta {
88 : :
89 : : private:
90 : : using ncomp_t = tk::ctr::ncomp_t;
91 : :
92 : : public:
93 : : //! \brief Constructor
94 : : //! \param[in] c Index specifying which system of mass-fraction beta SDEs
95 : : //! to construct. There can be multiple massfracbeta ... end blocks in a
96 : : //! control file. This index specifies which mass-fraction beta SDE
97 : : //! system to instantiate. The index corresponds to the order in which the
98 : : //! massfracbeta ... end blocks are given the control file.
99 : 11 : explicit MassFractionBeta( ncomp_t c ) :
100 : : m_c( c ),
101 : : m_depvar(
102 : : g_inputdeck.get< tag::param, tag::massfracbeta, tag::depvar >().at(c) ),
103 : : m_ncomp(
104 : 11 : g_inputdeck.get< tag::component >().get< tag::massfracbeta >().at(c) / 3 ),
105 : : m_offset(
106 : 11 : g_inputdeck.get< tag::component >().offset< tag::massfracbeta >(c) ),
107 : 11 : m_rng( g_rng.at( tk::ctr::raw(
108 : : g_inputdeck.get< tag::param, tag::massfracbeta, tag::rng >().at(c) ) ) ),
109 : : m_b(),
110 : : m_S(),
111 : : m_k(),
112 : : m_rho2(),
113 : : m_r(),
114 : : coeff(
115 : 11 : m_ncomp,
116 : : g_inputdeck.get< tag::param, tag::massfracbeta, tag::b >().at(c),
117 : : g_inputdeck.get< tag::param, tag::massfracbeta, tag::S >().at(c),
118 : : g_inputdeck.get< tag::param, tag::massfracbeta, tag::kappa >().at(c),
119 : : g_inputdeck.get< tag::param, tag::massfracbeta, tag::rho2 >().at(c),
120 : : g_inputdeck.get< tag::param, tag::massfracbeta, tag::r >().at(c),
121 [ - + ][ - + ]: 33 : m_b, m_S, m_k, m_rho2, m_r ) {}
[ - + ][ - + ]
[ + - ]
122 : :
123 : : //! Initalize SDE, prepare for time integration
124 : : //! \param[in] stream Thread (or more precisely stream) ID
125 : : //! \param[in,out] particles Array of particle properties
126 : : void initialize( int stream, tk::Particles& particles ) {
127 : : //! Set initial conditions using initialization policy
128 : : Init::template
129 : : init< tag::massfracbeta >
130 : 0 : ( g_inputdeck, m_rng, stream, particles, m_c, m_ncomp, m_offset );
131 : : }
132 : :
133 : : //! \brief Advance particles according to the system of mass-fraction beta
134 : : //! SDEs
135 : : //! \param[in,out] particles Array of particle properties
136 : : //! \param[in] stream Thread (or more precisely stream) ID
137 : : //! \param[in] dt Time step size
138 : 562500 : void advance( tk::Particles& particles,
139 : : int stream,
140 : : tk::real dt,
141 : : tk::real,
142 : : const std::map< tk::ctr::Product, tk::real >& )
143 : : {
144 : : // Advance particles
145 : 562500 : const auto npar = particles.nunk();
146 [ + + ]: 25487500 : for (auto p=decltype(npar){0}; p<npar; ++p) {
147 : : // Generate Gaussian random numbers with zero mean and unit variance
148 : 24925000 : std::vector< tk::real > dW( m_ncomp );
149 [ + - ]: 24925000 : m_rng.gaussian( stream, m_ncomp, dW.data() );
150 : : // Advance all m_ncomp scalars
151 [ + + ]: 149550000 : for (ncomp_t i=0; i<m_ncomp; ++i) {
152 [ + + ]: 124625000 : tk::real& Y = particles( p, i, m_offset );
153 [ + + ]: 124625000 : tk::real d = m_k[i] * Y * (1.0 - Y) * dt;
154 [ + + ]: 124625000 : d = (d > 0.0 ? std::sqrt(d) : 0.0);
155 : 124625000 : Y += 0.5*m_b[i]*(m_S[i] - Y)*dt + d*dW[i];
156 : : // Compute instantaneous values derived from updated Y
157 : 124625000 : particles( p, m_ncomp+i, m_offset ) = rho( Y, i );
158 : 124625000 : particles( p, m_ncomp*2+i, m_offset ) = vol( Y, i );
159 : : }
160 : : }
161 : 562500 : }
162 : :
163 : : private:
164 : : const ncomp_t m_c; //!< Equation system index
165 : : const char m_depvar; //!< Dependent variable
166 : : const ncomp_t m_ncomp; //!< Number of components
167 : : const ncomp_t m_offset; //!< Offset SDE operates from
168 : : const tk::RNG& m_rng; //!< Random number generator
169 : :
170 : : //! Coefficients
171 : : std::vector< kw::sde_b::info::expect::type > m_b;
172 : : std::vector< kw::sde_S::info::expect::type > m_S;
173 : : std::vector< kw::sde_kappa::info::expect::type > m_k;
174 : : std::vector< kw::sde_rho2::info::expect::type > m_rho2;
175 : : std::vector< kw::sde_r::info::expect::type > m_r;
176 : :
177 : : //! Coefficients policy
178 : : Coefficients coeff;
179 : :
180 : : //! \brief Return density for mass fraction
181 : : //! \details Functional wrapper around the dependent variable of the beta
182 : : //! SDE. This function returns the instantaneous density, rho,
183 : : //! based on the mass fraction, Y, and parameters rho2 and r'.
184 : : //! \param[in] Y Instantaneous value of the mass fraction, Y
185 : : //! \param[in] i Index specifying which (of multiple) parameters to use
186 : : //! \return Instantaneous value of the density, rho
187 : : tk::real rho( tk::real Y, ncomp_t i ) const {
188 : 124625000 : return m_rho2[i] / ( 1.0 + m_r[i] * Y );
189 : : }
190 : :
191 : : //! \brief Return specific volume for mass fraction
192 : : //! \details Functional wrapper around the dependent variable of the beta
193 : : //! SDE. This function returns the instantaneous specific volume, V,
194 : : //! based on the mass fraction, Y, and parameters rho2 and r'.
195 : : //! \param[in] Y Instantaneous value of the mass fraction, Y
196 : : //! \param[in] i Index specifying which (of multiple) parameters to use
197 : : //! \return Instantaneous value of the specific volume, V
198 : : tk::real vol( tk::real Y, ncomp_t i ) const {
199 : 124625000 : return 1.0 / rho( Y, i );
200 : : }
201 : : };
202 : :
203 : : } // walker::
204 : :
205 : : #endif // MassFractionBeta_h
|