Commit 40a2b835 authored by Charles G Waldman's avatar Charles G Waldman
Browse files

size distributions now use rejection instead of gaussian approximation (!244)

parent 58956784
Loading
Loading
Loading
Loading
+69 −84
Changes for docs/source_docs/references/size_distributions.rst: 69 added lines, 84 removed lines.
Original line number Diff line number Diff line
@@ -109,8 +109,10 @@ The ``normal`` or Gaussian distribution is given by

   f_X(x) = \frac{d}{dx}F_X(x) = \frac{1}{\sigma \sqrt{2\pi}} \exp{\left(- \frac{(x - \mu)^2 }{  2 \sigma^2 }\right)}

where the parameter :math:`\mu` is the distribution mean, and :math:`\sigma` is the standard deviation. The inputs
used to specify the distribution are provided in the following table.
where the parameter :math:`\mu` is the distribution mean, and :math:`\sigma` is the standard deviation. The
distribution is truncated to :math:`\left[ x_\mathrm{min}, x_\mathrm{max} \right]`. The parameters describe the
distribution of the specified ``weighting``; the distribution of the other weighting is derived from it as
described below. The inputs used to specify the distribution are provided in the following table.

+---------------------+-----------------------------------------------------------------------+-------------+-----------+
|                     | Description                                                           |   Type      | Default   |
@@ -122,8 +124,8 @@ used to specify the distribution are provided in the following table.
| std                 | standard deviation of the normal random variable, :math:`X`           | Real        | N/A       |
|                     |                                                                       |             |           |
+---------------------+-----------------------------------------------------------------------+-------------+-----------+
| min                 | Minimum particle diameter. Drawn samples below ``min`` are discarded  | Real        | N/A       |
|                     | and a new sample is drawn.                                            |             |           |
| min                 | Minimum particle diameter; must be positive. Drawn samples below      | Real        | N/A       |
|                     | ``min`` are discarded and a new sample is drawn.                      |             |           |
+---------------------+-----------------------------------------------------------------------+-------------+-----------+
| max                 | Maximum particle diameter. Drawn samples above ``max`` are discarded  | Real        | N/A       |
|                     | and a new sample is drawn.                                            |             |           |
@@ -192,7 +194,7 @@ probability density function (PDF) is shifted to the right of the number-weighte

   MFIX-Exa DEM particle size distribution (open circles) generated from example inputs. The number-weighted
   density function (orange) with 1 mm mean and 0.25 mm standard deviation, and volume-weighted
   density function with ~1.17 mm mean and ~0.23 mm standard deviation are also plotted.
   density function with ~1.16 mm mean and ~0.23 mm standard deviation are also plotted.

An MFIX-Exa PIC simulation with the same settings generates approximately 82,000 parcels when ``pic.close_pack = 0.64``,
``pic.parcels_per_cell_at_pack = 32``, and the Eulerian mesh spacing :math:`\Delta x` is 3.125 mm. The parcel size distribution
@@ -210,117 +212,100 @@ recorded in the bin capturing the parcel's diameter.

   MFIX-Exa PIC parcel size distribution (open triangles) generated from example inputs. The number-weighted
   density function (orange) with 1 mm mean and 0.25 mm standard deviation, and volume-weighted density function
   (blue) with ~1.17 mm mean and ~0.23 mm standard deviation are also plotted.
   (blue) with ~1.16 mm mean and ~0.23 mm standard deviation are also plotted.

The following sections outline how MFIX-Exa computes volume-weighted normal density function parameters from
number-weighted normal density function parameters, and conversely, how number-weighted normal density function
parameters are computed from volume-weighted density function parameters.
The following sections describe how the number-weighted and volume-weighted distributions are related,
and how each is sampled.

.. rubric:: Computing volume-weighted normal density function parameters, :math:`\mu_V` and :math:`\sigma_V`, from
   number-weighted normal density function parameters, :math:`\mu_N` and :math:`\sigma_N`
.. rubric:: Relationship between the number-weighted and volume-weighted normal distributions

The volume-weighted density function, :math:`f_X^V(x)`, computed from the normally distributed number-weighted density
function, :math:`f_X^N(x)`, is normally distributed with mean, :math:`\mu_V`, and variance, :math:`\sigma_V^2`. An
expression for the volume-weighted density function is obtained by multiplying :eq:`eq_normal_dist` by :math:`x^3`
and substituting in the mean and standard deviation of the number-weighted distribution.
A normal distribution is specified for one weighting. The density of the other weighting on
:math:`\left[ x_\mathrm{min}, x_\mathrm{max} \right]` follows from the definitions of the two weightings, since
a particle of diameter :math:`x` has volume proportional to :math:`x^3`:

.. math::
   :label: eq_normal_dist_derived

   \tilde{f}_X^V(x) = \frac{x^3}{\sigma_N \sqrt{2\pi}} \exp{\left(- \frac{(x - \mu_N)^2 }{  2 \sigma_N^2 }\right)}
   f_X^V(x) = \frac{x^3 f_X^N(x)}{\int_{x_\mathrm{min}}^{x_\mathrm{max}} y^3 f_X^N(y)\,dy}
   \qquad \text{or} \qquad
   f_X^N(x) = \frac{x^{-3} f_X^V(x)}{\int_{x_\mathrm{min}}^{x_\mathrm{max}} y^{-3} f_X^V(y)\,dy}

The mean of this distribution is computed as
Neither derived distribution is a normal distribution: multiplying a Gaussian by :math:`x^3` skews it to the right,
and dividing by :math:`x^3` skews it to the left. MFIX-Exa does not approximate the derived distribution by a normal
distribution. It is sampled exactly (see below), and the mean and standard deviation reported for the derived weighting
are those of :eq:`eq_normal_dist_derived`, computed by numerical quadrature over
:math:`\left[ x_\mathrm{min}, x_\mathrm{max} \right]`. For the example above, the derived volume-weighted distribution
has mean ~1.16 mm and standard deviation ~0.23 mm.

.. math::
   :label: eq_normal_dist_FN_to_FV_mean

   \begin{aligned}
       \mu_V =& \frac{ \int_{-\infty}^{\infty} x \tilde{f}_X^V(x) dx }{\int_{-\infty}^{\infty} \tilde{f}_X^V(x) dx } \\[10pt]
             =& \frac{3\sigma_N^4 + 6\sigma_N^2\mu_N^2 + \mu_N^4}{3\sigma_N^2 \mu_N + \mu_N^3}
   \end{aligned}

and the variance is given by
The number of particles (or parcels) in an initial condition region is computed from the volume-weighted distribution
discretized into ``bins`` bins of equal width on :math:`\left[ x_\mathrm{min}, x_\mathrm{max} \right]`. The probability
of each bin is the integral of the volume-weighted density over the bin. For a volume-weighted normal distribution this
is a difference of error functions. For a number-weighted normal distribution the integral of :math:`x^3 f_X^N(x)` is
also closed-form: with :math:`z = (x - \mu)/\sigma`,

.. math::
   :label: eq_normal_dist_FN_to_FV_variance
   :label: eq_normal_dist_x3_integral

   \begin{aligned}
       \sigma^2_V =& \frac{ \int_{-\infty}^{\infty} (x - \mu_V)^2 \tilde{f}_X^V(x) dx }{\int_{-\infty}^{\infty} \tilde{f}_X^V(x) dx } \\[10pt]
                  =& \frac{3\sigma_N^4 (3\mu_N + 2b) + \sigma^2(\mu_N^3 + 6\mu_N^2 b + 3\mu_Nb^2)+\mu_N^3 b^2}{3\sigma_N^2 \mu_N + \mu_N^3}
   \end{aligned}
   \int x^3 f_X^N(x)\,dx = \left(\mu^3 + 3\mu\sigma^2\right)\Phi(z)
   - \sigma\left(3\mu^2 + 3\mu\sigma z + \sigma^2 \left(z^2 + 2\right)\right)\phi(z)

where :math:`b = (\mu_N - \mu_V)`. Because the volume-weighted distribution is normally distributed, the computed
mean and variance can be substituted directly into :eq:`eq_normal_dist`.
where :math:`\phi` and :math:`\Phi` are the standard normal density and cumulative distribution function.

.. math::

   f_X^V(x) = \frac{1}{\sigma_V \sqrt{2\pi}} \exp{\left(- \frac{(x - \mu_V)^2 }{  2 \sigma_V^2 }\right)}

.. rubric:: Computing number-weighted normal density function parameters, :math:`\mu_N` and :math:`\sigma_N`, from
   volume-weighted normal density function parameters, :math:`\mu_V` and :math:`\sigma_V`

The number-weighted density function mean and standard deviation, :math:`\mu_N` and :math:`\sigma_N`, are computed from the volume-weighted
mean and standard deviation, :math:`\mu_V` and :math:`\sigma_V`, by solving the nonlinear system of equations constructed from
:eq:`eq_normal_dist_FN_to_FV_mean` and :eq:`eq_normal_dist_FN_to_FV_variance` for :math:`\mu_N` and :math:`\sigma_N`.
.. rubric:: Sampling a normal distribution

.. math::
The number-weighted distribution is sampled when DEM particles are created, and the volume-weighted distribution is
sampled when PIC parcels are created. When the distribution to be sampled is the one specified by the user, MFIX-Exa
samples the normal distribution with mean ``m_normal_mean`` and standard deviation ``m_normal_stddev`` to return a
distribution observation.

   \begin{aligned}
     f_1(\mu_N,\sigma_N) &= \left( 3\sigma_N^4 + 6\sigma_N^2\mu_N^2 + \mu_N^4 \right) - \mu_V \left( 3\sigma_N^2 \mu_N + \mu_N^3 \right) = 0 \\
     f_2(\mu_N,\sigma_N) &= \left(3\sigma_N^4 (3\mu_N + 2b) + \sigma^2(\mu_N^3 + 6\mu_N^2 b + 3\mu_Nb^2)+\mu_N^3 b^2\right) - \sigma^2_V \left( 3\sigma_N^2 \mu_N + \mu_N^3 \right) = 0
   \end{aligned}
.. code-block::

This system is solved using the homotopy method outlined in :cite:t:`Burden10`. To ensure rapid convergence, initial guesses for
:math:`\mu_N` and :math:`\sigma_N` are calculated from the density function created by dividing :eq:`eq_normal_dist` by :math:`x^3`
and substituting in the mean and standard deviation of the volume-weighted distribution, :math:`\mu_V` and :math:`\sigma_V`.
   amrex::Real observation;

.. math::
   :label: eq_normal_dist_FV_to_FN_initial_expression
   do { observation = amrex::RandomNormal(m_normal_mean, m_normal_stddev, a_engine); }
   while (!(m_min <= observation && observation <= m_max));

   \tilde{f}_X^N(x) = \frac{1}{x^3\sigma_V \sqrt{2\pi}} \exp{\left(- \frac{(x - \mu_V)^2 }{  2 \sigma_V^2 }\right)}
   return observation;

The function ``amrex::RandomNormal``  returns one pseudo-random real number (double). The sample is discarded and the distribution
is sampled again until the value satisfies :math:`\mathrm{xmin} \le x` and :math:`x \le \mathrm{xmax}`.

:math:`\tilde{f}_X^N(x)`, shown in :numref:`fig_normal-dist-pdf-approx_FN`, is not the number-weighted density function,
but an approximation to it. The mean and variance are calculated by numerically integrating :math:`\tilde{f}_X^N(x)`
over the interval :math:`x \in \left[ x_\mathrm{min}, x_\mathrm{max} \right]` where :math:`x_{min}` and :math:`x_{mid}`
are found by setting the derivative of :eq:`eq_normal_dist_FV_to_FN_initial_expression` to zero and computing the roots.
:math:`x_\mathrm{max}` is chosen to mirror :math:`x_\mathrm{min}` across the midpoint.
When the distribution to be sampled is the derived one, :eq:`eq_normal_dist_derived` is sampled by rejection
sampling. A candidate :math:`x` is drawn uniformly from :math:`\left[ x_\mathrm{min}, x_\mathrm{max} \right]` and
accepted with probability :math:`g(x)/g_\mathrm{max}`, where

.. math::
   :label: eq_normal_dist_FV_to_FN_discrete_values

   \begin{aligned}
     x_{\mathrm{min}} \; =& \; \left( \mu_V - \sqrt{\mu_V^2 -12\sigma_V^2}\right)/2 \\
     x_{\mathrm{mid}} \; =& \; \left(\mu_V + \sqrt{\mu_V^2 -12\sigma_V^2}\right)/2 \\
     x_{\mathrm{max}} \; =& \; 2x_{\mathrm{mid}} - x_{\mathrm{min}}
   \end{aligned}

.. _fig_normal-dist-pdf-approx_FN:

.. figure:: ./images/normal-dist-pdf-approx_FN.png
   :width: 95%
   :align: center
   :alt: approximate number-weighted pdf
   g(x) = x^{\pm 3} \exp{\left(- \frac{(x - \mu)^2 }{  2 \sigma^2 }\right)}

   The number-weighted normal distribution function approximated by dividing the volume-weighted
   distribution function by x\ :sup:`3`. The approximate mean and variance are computed by numerically
   integrating this function from x\ :sub:`min` to x\ :sub:`max`.
is the unnormalized derived density (:math:`x^{3}` when a number-weighted distribution is specified, :math:`x^{-3}`
when a volume-weighted distribution is specified) and :math:`g_\mathrm{max}` is its maximum on
:math:`\left[ x_\mathrm{min}, x_\mathrm{max} \right]`. Accepted candidates are distributed exactly according to
:eq:`eq_normal_dist_derived`.

.. rubric:: Sampling a normal distribution
.. code-block::

MFIX-Exa samples the normal distribution with mean ``m_mean`` and standard deviation ``m_stddev`` to return an
distribution observation.
   amrex::Real observation, g;

.. code-block::
   do {
     observation = m_min + (m_max - m_min)*amrex::Random(a_engine);

   amrex::Real observation;
     amrex::Real const z = (observation - m_normal_mean)/m_normal_stddev;
     amrex::Real const x3 = observation*observation*observation;

   do { observation = amrex::RandomNormal(m_mean, m_stddev, a_engine); }
   while (!(m_min <= observation && observation <= m_max));
     g = std::exp(-0.5*z*z) * (m_is_number_weighted ? x3 : 1./x3);
   }
   while (amrex::Random(a_engine)*m_gmax > g);

   return observation;

The function ``amrex::RandomNormal``  returns one pseudo-random real number (double). The sample is discarded and the distribution
is sampled again until the value satisfies :math:`\mathrm{xmin} \le x` and :math:`x \le \mathrm{xmax}`.
The function ``amrex::Random`` returns one pseudo-random real number (double) from a uniform distribution between
0.0 and 1.0. :math:`g_\mathrm{max}` is computed once when the distribution is defined, as the largest value of
:math:`g` at the interval endpoints and at the interior stationary point of :math:`g`, if there is one:
:math:`x^{3} \exp(\cdot)` has its maximum at :math:`x = \left(\mu + \sqrt{\mu^2 + 12\sigma^2}\right)/2`;
:math:`x^{-3} \exp(\cdot)` has a local maximum at :math:`x = \left(\mu + \sqrt{\mu^2 - 12\sigma^2}\right)/2`
when :math:`\mu^2 \ge 12\sigma^2`, and is decreasing otherwise. The fraction of candidates accepted depends on the
inputs (about 40% for the example above) and affects only the cost of generating the initial particles.


``log-normal`` distribution