Skip to content

Commit

Permalink
brought tests up to date with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jtramm committed Jul 1, 2024
2 parents 6348358 + 391450c commit 4c2c1ba
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 61 deletions.
17 changes: 13 additions & 4 deletions docs/source/methods/eigenvalue.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ in :ref:`fission-bank-algorithms`.
Source Convergence Issues
-------------------------

.. _methods-shannon-entropy:

Diagnosing Convergence with Shannon Entropy
-------------------------------------------

As discussed earlier, it is necessary to converge both :math:`k_{eff}` and the
source distribution before any tallies can begin. Moreover, the convergence rate
of the source distribution is in general slower than that of
:math:`k_{eff}`. One should thus examine not only the convergence of
:math:`k_{eff}` but also the convergence of the source distribution in order to
make decisions on when to start active batches.
of the source distribution is in general slower than that of :math:`k_{eff}`.
One should thus examine not only the convergence of :math:`k_{eff}` but also the
convergence of the source distribution in order to make decisions on when to
start active batches.

However, the representation of the source distribution makes it a bit more
difficult to analyze its convergence. Since :math:`k_{eff}` is a scalar
Expand Down Expand Up @@ -108,6 +110,13 @@ at plots of :math:`k_{eff}` and the Shannon entropy. A number of methods have
been proposed (see e.g. [Romano]_, [Ueki]_), but each of these is not without
problems.

Shannon entropy is calculated differently for the random ray solver, as
described :ref:`in the random ray theory section
<methods-shannon-entropy-random-ray>`. Additionally, as the Shannon entropy only
serves as a diagnostic tool for convergence of the fission source distribution,
there is currently no diagnostic to determine if the scattering source
distribution in random ray is converged.

---------------------------
Uniform Fission Site Method
---------------------------
Expand Down
58 changes: 54 additions & 4 deletions docs/source/methods/random_ray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Random Ray
What is Random Ray?
-------------------

`Random ray <Tramm-2017a>`_ is a stochastic transport method, closely related to
`Random ray <Tramm-2017a_>`_ is a stochastic transport method, closely related to
the deterministic Method of Characteristics (MOC) [Askew-1972]_. Rather than
each ray representing a single neutron as in Monte Carlo, it represents a
characteristic line through the simulation geometry upon which the transport
Expand Down Expand Up @@ -82,7 +82,7 @@ Random Ray Numerical Derivation

In this section, we will derive the numerical basis for the random ray solver
mode in OpenMC. The derivation of random ray is also discussed in several papers
(`1 <Tramm-2017a>`_, `2 <Tramm-2017b>`_, `3 <Tramm-2018>`_), and some of those
(`1 <Tramm-2017a_>`_, `2 <Tramm-2017b_>`_, `3 <Tramm-2018_>`_), and some of those
derivations are reproduced here verbatim. Several extensions are also made to
add clarity, particularly on the topic of OpenMC's treatment of cell volumes in
the random ray solver.
Expand Down Expand Up @@ -411,6 +411,8 @@ which when partially simplified becomes:
Note that there are now four (seemingly identical) volume terms in this equation.

.. _methods-volume-dilemma:

~~~~~~~~~~~~~~
Volume Dilemma
~~~~~~~~~~~~~~
Expand All @@ -426,7 +428,7 @@ of terms. Mathematically, such cancellation allows us to arrive at the following
This derivation appears mathematically sound at first glance but unfortunately
raises a serious issue as discussed in more depth by `Tramm et al.
<Tramm-2020>`_ and `Cosgrove and Tramm <Cosgrove-2023>`_. Namely, the second
<Tramm-2020_>`_ and `Cosgrove and Tramm <Cosgrove-2023_>`_. Namely, the second
term:

.. math::
Expand Down Expand Up @@ -605,7 +607,7 @@ guess can be made by taking the isotropic source from the FSR the ray was
sampled in, direct usage of this quantity would result in significant bias and
error being imparted on the simulation.

Thus, an `on-the-fly approximation method <Tramm-2017a>`_ was developed (known
Thus, an `on-the-fly approximation method <Tramm-2017a_>`_ was developed (known
as the "dead zone"), where the first several mean free paths of a ray are
considered to be "inactive" or "read only". In this sense, the angular flux is
solved for using the MOC equation, but the ray does not "tally" any scalar flux
Expand Down Expand Up @@ -738,13 +740,16 @@ scalar flux value for the FSR).
global::volume[fsr] += s;
}

.. _methods_random_tallies:

------------------------
How are Tallies Handled?
------------------------

Most tallies, filters, and scores that you would expect to work with a
multigroup solver like random ray should work. For example, you can define 3D
mesh tallies with energy filters and flux, fission, and nu-fission scores, etc.

There are some restrictions though. For starters, it is assumed that all filter
mesh boundaries will conform to physical surface boundaries (or lattice
boundaries) in the simulation geometry. It is acceptable for multiple cells
Expand All @@ -754,6 +759,51 @@ behavior if a single simulation cell is able to score to multiple filter mesh
cells. In the future, the capability to fully support mesh tallies may be added
to OpenMC, but for now this restriction needs to be respected.

Flux tallies are handled slightly differently than in Monte Carlo. By default,
in MC, flux tallies are reported in units of tracklength (cm), so must be
manually normalized by volume by the user to produce an estimate of flux in
units of cm\ :sup:`-2`\. Alternatively, MC flux tallies can be normalized via a
separated volume calculation process as discussed in the :ref:`Volume
Calculation Section<usersguide_volume>`. In random ray, as the volumes are
computed on-the-fly as part of the transport process, the flux tallies can
easily be reported either in units of flux (cm\ :sup:`-2`\) or tracklength (cm).
By default, the unnormalized flux values (units of cm) will be reported. If the
user wishes to received volume normalized flux tallies, then an option for this
is available, as described in the :ref:`User Guide<usersguide_flux_norm>`.

.. _methods-shannon-entropy-random-ray:

-----------------------------
Shannon Entropy in Random Ray
-----------------------------

As :math:`k_{eff}` is updated at each generation, the fission source at each FSR
is used to compute the Shannon entropy. This follows the :ref:`same procedure
for computing Shannon entropy in continuous-energy or multigroup Monte Carlo
simulations <methods-shannon-entropy>`, except that fission sources at FSRs are
considered, rather than fission sites of user-defined regular meshes. Thus, the
volume-weighted fission rate is considered instead, and the fraction of fission
sources is adjusted such that:

.. math::
:label: fraction-source-random-ray
S_i = \frac{\text{Fission source in FSR $i \times$ Volume of FSR
$i$}}{\text{Total fission source}} = \frac{Q_{i} V_{i}}{\sum_{i=1}^{i=N}
Q_{i} V_{i}}
The Shannon entropy is then computed normally as

.. math::
:label: shannon-entropy-random-ray
H = - \sum_{i=1}^N S_i \log_2 S_i
where :math:`N` is the number of FSRs. FSRs with no fission source (or,
occassionally, negative fission source, :ref:`due to the volume estimator
problem <methods-volume-dilemma>`) are skipped to avoid taking an undefined
logarithm in :eq:`shannon-entropy-random-ray`.

.. _usersguide_fixed_source_methods:

------------
Expand Down
32 changes: 32 additions & 0 deletions docs/source/usersguide/random_ray.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ solver::
settings.batches = 1200
settings.inactive = 600

---------------
Shannon Entropy
---------------

Similar to Monte Carlo, :ref:`Shannon entropy
<methods-shannon-entropy-random-ray>` can be used to gauge whether the fission
source has fully developed. The Shannon entropy is calculated automatically
after each batch and is printed to the statepoint file. Unlike Monte Carlo, an
entropy mesh does not need to be defined, as the Shannon entropy is calculated
over FSRs using a volume-weighted approach.

-------------------------------
Inactive Ray Length (Dead Zone)
-------------------------------
Expand Down Expand Up @@ -319,6 +330,8 @@ of a two-dimensional 2x2 reflective pincell lattice:

In the future, automated subdivision of FSRs via mesh overlay may be supported.

.. _usersguide_flux_norm:

-------
Tallies
-------
Expand Down Expand Up @@ -356,6 +369,25 @@ Note that there is no difference between the analog, tracklength, and collision
estimators in random ray mode as individual particles are not being simulated.
Tracklength-style tally estimation is inherent to the random ray method.

As discussed in the random ray theory section on :ref:`Random Ray
Tallies<methods_random_tallies>`, by default flux tallies in the random ray mode
are not normalized by the spatial tally volumes such that flux tallies are in
units of cm. While the volume information is readily available as a byproduct of
random ray integration, the flux value is reported in unnormalized units of cm
so that the user will be able to compare "apples to apples" with the default
flux tallies from the Monte Carlo solver (also reported by default in units of
cm). If volume normalized flux tallies (in units of cm\ :sup:`-2`) are desired,
then the user can set the ``volume_normalized_flux_tallies`` field in the
:attr:`openmc.Settings.random_ray` dictionary to ``True``. An example is given
below:

::

settings.random_ray['volume_normalized_flux_tallies'] = True

Note that MC mode flux tallies can also be normalized by volume, as discussed in
the :ref:`Volume Calculation Section<usersguide_volume>` of the user guide.

--------
Plotting
--------
Expand Down
5 changes: 5 additions & 0 deletions include/openmc/random_ray/flat_source_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class FlatSourceDomain {
void all_reduce_replicated_source_regions();
void convert_external_sources();
void count_external_source_regions();
double compute_fixed_source_normalization_factor() const;

//----------------------------------------------------------------------------
// Static Data members
static bool volume_normalized_flux_tallies_;

//----------------------------------------------------------------------------
// Public Data members
Expand Down
12 changes: 12 additions & 0 deletions openmc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ class Settings:
:ray_source:
Starting ray distribution (must be uniform in space and angle) as
specified by a :class:`openmc.SourceBase` object.
:volume_normalized_flux_tallies:
Whether to normalize flux tallies by volume (bool). The default
is 'False'. When enabled, flux tallies will be reported in units of
cm/cm^3. When disabled, flux tallies will be reported in units
of cm (i.e., total distance traveled by neutrons in the spatial
tally region).
.. versionadded:: 0.15.0
resonance_scattering : dict
Expand Down Expand Up @@ -1084,6 +1090,8 @@ def random_ray(self, random_ray: dict):
random_ray[key], 0.0, True)
elif key == 'ray_source':
cv.check_type('random ray source', random_ray[key], SourceBase)
elif key == 'volume_normalized_flux_tallies':
cv.check_type('volume normalized flux tallies', random_ray[key], bool)
else:
raise ValueError(f'Unable to set random ray to "{key}" which is '
'unsupported by OpenMC')
Expand Down Expand Up @@ -1877,6 +1885,10 @@ def _random_ray_from_xml_element(self, root):
elif child.tag == 'source':
source = SourceBase.from_xml_element(child)
self.random_ray['ray_source'] = source
elif child.tag == 'volume_normalized_flux_tallies':
self.random_ray['volume_normalized_flux_tallies'] = (
child.text in ('true', '1')
)

def to_xml_element(self, mesh_memo=None):
"""Create a 'settings' element to be written to an XML file.
Expand Down
2 changes: 1 addition & 1 deletion src/eigenvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void shannon_entropy()
double H = 0.0;
for (auto p_i : p) {
if (p_i > 0.0) {
H -= p_i * std::log(p_i) / std::log(2.0);
H -= p_i * std::log2(p_i);
}
}

Expand Down
Loading

0 comments on commit 4c2c1ba

Please sign in to comment.