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