Skip to content

Commit

Permalink
Merge branch 'transient' of https://github.com/ilhamv/openmc into tra…
Browse files Browse the repository at this point in the history
…nsient
  • Loading branch information
ilhamv committed Nov 11, 2024
2 parents 447a6b1 + cb73ddc commit a226095
Show file tree
Hide file tree
Showing 117 changed files with 1,928 additions and 473 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ jobs:

- name: Environment Variables
run: |
echo "DAGMC_ROOT=$HOME/DAGMC"
echo "OPENMC_CROSS_SECTIONS=$HOME/nndc_hdf5/cross_sections.xml" >> $GITHUB_ENV
echo "OPENMC_ENDF_DATA=$HOME/endf-b-vii.1" >> $GITHUB_ENV
Expand Down Expand Up @@ -131,6 +130,11 @@ jobs:
echo "$HOME/NJOY2016/build" >> $GITHUB_PATH
$GITHUB_WORKSPACE/tools/ci/gha-install.sh
- name: display-config
shell: bash
run: |
openmc -v
- name: cache-xs
uses: actions/cache@v4
with:
Expand Down
14 changes: 9 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ list(APPEND libopenmc_SOURCES
src/tallies/filter_meshborn.cpp
src/tallies/filter_meshsurface.cpp
src/tallies/filter_mu.cpp
src/tallies/filter_musurface.cpp
src/tallies/filter_particle.cpp
src/tallies/filter_polar.cpp
src/tallies/filter_sph_harm.cpp
Expand Down Expand Up @@ -509,6 +510,14 @@ endif()
if(OPENMC_USE_DAGMC)
target_compile_definitions(libopenmc PRIVATE DAGMC)
target_link_libraries(libopenmc dagmc-shared)

if(OPENMC_USE_UWUW)
target_compile_definitions(libopenmc PRIVATE OPENMC_UWUW)
target_link_libraries(libopenmc uwuw-shared)
endif()
elseif(OPENMC_USE_UWUW)
set(OPENMC_USE_UWUW OFF)
message(FATAL_ERROR "DAGMC must be enabled when UWUW is enabled.")
endif()

if(OPENMC_USE_LIBMESH)
Expand Down Expand Up @@ -545,11 +554,6 @@ if(OPENMC_USE_NCRYSTAL)
target_link_libraries(libopenmc NCrystal::NCrystal)
endif()

if (OPENMC_USE_UWUW)
target_compile_definitions(libopenmc PRIVATE UWUW)
target_link_libraries(libopenmc uwuw-shared)
endif()

#===============================================================================
# Log build info that this executable can report later
#===============================================================================
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/FindLIBMESH.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(DEFINED ENV{METHOD})
endif()

find_package(PkgConfig REQUIRED)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${LIBMESH_PC}")
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH True)

set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
pkg_check_modules(LIBMESH REQUIRED ${LIBMESH_PC_FILE}>=1.7.0 IMPORTED_TARGET)
pkg_get_variable(LIBMESH_PREFIX ${LIBMESH_PC_FILE} prefix)
6 changes: 3 additions & 3 deletions cmake/OpenMCConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ if(@OPENMC_USE_MCPL@)
find_package(MCPL REQUIRED)
endif()

if(@OPENMC_USE_UWUW@)
find_package(UWUW REQUIRED)
endif()
if(@OPENMC_USE_UWUW@ AND NOT ${DAGMC_BUILD_UWUW})
message(FATAL_ERROR "UWUW is enabled in OpenMC but the DAGMC installation discovered was not configured with UWUW.")
endif()
9 changes: 9 additions & 0 deletions docs/source/io_formats/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,15 @@ attributes/sub-elements:

*Default*: None

:max_source_files:
An integer value indicating the number of surface source files to be written
containing the maximum number of particles each. The surface source bank
will be cleared in simulation memory each time a surface source file is
written. By default a ``surface_source.h5`` file will be created when the
maximum number of saved particles is reached.

*Default*: 1

:mcpl:
An optional boolean which indicates if the banked particles should be
written to a file in the MCPL_-format instead of the native HDF5-based
Expand Down
39 changes: 28 additions & 11 deletions docs/source/methods/random_numbers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ Random Number Generation
In order to sample probability distributions, one must be able to produce random
numbers. The standard technique to do this is to generate numbers on the
interval :math:`[0,1)` from a deterministic sequence that has properties that
make it appear to be random, e.g. being uniformly distributed and not exhibiting
make it appear to be random, e.g., being uniformly distributed and not exhibiting
correlation between successive terms. Since the numbers produced this way are
not truly "random" in a strict sense, they are typically referred to as
pseudorandom numbers, and the techniques used to generate them are pseudorandom
number generators (PRNGs). Numbers sampled on the unit interval can then be
transformed for the purpose of sampling other continuous or discrete probability
distributions.

There are many different algorithms for pseudorandom number generation. OpenMC
currently uses `permuted congruential generator`_ (PCG), which builds on top of
the simpler linear congruential generator (LCG). Both algorithms are described
below.

------------------------------
Linear Congruential Generators
------------------------------
Expand All @@ -37,8 +42,8 @@ be generated with a method chosen at random. Some theory should be used."
Typically, :math:`M` is chosen to be a power of two as this enables :math:`x
\mod M` to be performed using the bitwise AND operator with a bit mask. The
constants for the linear congruential generator used by default in OpenMC are
:math:`g = 2806196910506780709`, :math:`c = 1`, and :math:`M = 2^{63}` (see
`L'Ecuyer`_).
:math:`g = 2806196910506780709`, :math:`c = 1`, and :math:`M = 2^{63}` (from
`L'Ecuyer <https://doi.org/10.1090/S0025-5718-99-00996-5>`_).

Skip-ahead Capability
---------------------
Expand All @@ -50,23 +55,35 @@ want to skip ahead :math:`N` random numbers and :math:`N` is large, the cost of
sampling :math:`N` random numbers to get to that position may be prohibitively
expensive. Fortunately, algorithms have been developed that allow us to skip
ahead in :math:`O(\log_2 N)` operations instead of :math:`O(N)`. One algorithm
to do so is described in a paper by Brown_. This algorithm relies on the following
to do so is described in a `paper by Brown
<https://www.osti.gov/biblio/976209>`_. This algorithm relies on the following
relationship:

.. math::
:label: lcg-skipahead
\xi_{i+k} = g^k \xi_i + c \frac{g^k - 1}{g - 1} \mod M
Note that equation :eq:`lcg-skipahead` has the same general form as equation :eq:`lcg`, so
the idea is to determine the new multiplicative and additive constants in
:math:`O(\log_2 N)` operations.
Note that equation :eq:`lcg-skipahead` has the same general form as equation
:eq:`lcg`, so the idea is to determine the new multiplicative and additive
constants in :math:`O(\log_2 N)` operations.

.. only:: html

.. rubric:: References
--------------------------------
Permuted Congruential Generators
--------------------------------

The `permuted congruential generator`_ (PCG) algorithm aims to improve upon the
LCG algorithm by permuting the output. The algorithm works on the basic
principle of first advancing the generator state using the LCG algorithm and
then applying a permutation function on the LCG state to obtain the output. This
results in increased statistical quality as measured by common statistical tests
while exhibiting a very small performance overhead relative to the LCG algorithm
and an equivalent memory footprint. For further details, see the original
technical report by `O'Neill
<https://www.pcg-random.org/pdf/hmc-cs-2014-0905.pdf>`_. OpenMC uses the
PCG-RXS-M-XS variant with a 64-bit state and 64-bit output.

.. _L'Ecuyer: https://doi.org/10.1090/S0025-5718-99-00996-5
.. _Brown: https://laws.lanl.gov/vhosts/mcnp.lanl.gov/pdf_files/anl-rn-arb-stride.pdf
.. _linear congruential generator: https://en.wikipedia.org/wiki/Linear_congruential_generator

.. _permuted congruential generator: https://en.wikipedia.org/wiki/Permuted_congruential_generator
2 changes: 2 additions & 0 deletions docs/source/pythonapi/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Constructing Tallies
openmc.EnergyFilter
openmc.EnergyoutFilter
openmc.MuFilter
openmc.MuSurfaceFilter
openmc.PolarFilter
openmc.AzimuthalFilter
openmc.DistribcellFilter
Expand Down Expand Up @@ -190,6 +191,7 @@ Post-processing
:template: myclass.rst

openmc.Particle
openmc.ParticleList
openmc.ParticleTrack
openmc.StatePoint
openmc.Summary
Expand Down
1 change: 1 addition & 0 deletions docs/source/pythonapi/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Composite Surfaces
:nosignatures:
:template: myclass.rst

openmc.model.ConicalFrustum
openmc.model.CruciformPrism
openmc.model.CylinderSector
openmc.model.HexagonalPrism
Expand Down
11 changes: 5 additions & 6 deletions docs/source/quickinstall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ packages should be installed, for example in Homebrew via:
The compiler provided by the above LLVM package should be used in place of the
one provisioned by XCode, which does not support the multithreading library used
by OpenMC. Consequently, the C++ compiler should explicitly be set before
proceeding:

.. code-block:: sh
export CXX=/opt/homebrew/opt/llvm/bin/clang++
by OpenMC. To ensure CMake picks up the correct compiler, make sure that either
the :envvar:`CXX` environment variable is set to the brew-installed ``clang++``
or that the directory containing it is on your :envvar:`PATH` environment
variable. Common locations for the brew-installed compiler are
``/opt/homebrew/opt/llvm/bin`` and ``/usr/local/opt/llvm/bin``.

After the packages have been installed, follow the instructions to build from
source below.
Expand Down
25 changes: 17 additions & 8 deletions docs/source/usersguide/geometry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ applied as universes in the OpenMC geometry file. A geometry represented
entirely by a DAGMC geometry will contain only the DAGMC universe. Using a
:class:`openmc.DAGMCUniverse` looks like the following::

dag_univ = openmc.DAGMCUniverse(filename='dagmc.h5m')
dag_univ = openmc.DAGMCUniverse('dagmc.h5m')
geometry = openmc.Geometry(dag_univ)
geometry.export_to_xml()

Expand All @@ -495,13 +495,22 @@ It is important in these cases to understand the DAGMC model's position
with respect to the CSG geometry. DAGMC geometries can be plotted with
OpenMC to verify that the model matches one's expectations.

**Note:** DAGMC geometries used in OpenMC are currently required to be clean,
meaning that all surfaces have been `imprinted and merged
<https://svalinn.github.io/DAGMC/usersguide/cubit_basics.html>`_ successfully
and that the model is `watertight
<https://svalinn.github.io/DAGMC/usersguide/tools.html#make-watertight>`_.
Future implementations of DAGMC geometry will support small volume overlaps and
un-merged surfaces.
By default, when you specify a .h5m file for a :class:`~openmc.DAGMCUniverse`
instance, it will store the absolute path to the .h5m file. If you prefer to
store the relative path, you can set the ``'resolve_paths'`` configuration
variable::

openmc.config['resolve_paths'] = False
dag_univ = openmc.DAGMCUniverse('dagmc.h5m')

.. note::
DAGMC geometries used in OpenMC are currently required to be clean,
meaning that all surfaces have been `imprinted and merged
<https://svalinn.github.io/DAGMC/usersguide/cubit_basics.html>`_ successfully
and that the model is `watertight
<https://svalinn.github.io/DAGMC/usersguide/tools.html#make-watertight>`_.
Future implementations of DAGMC geometry will support small volume overlaps and
un-merged surfaces.

Cell, Surface, and Material IDs
-------------------------------
Expand Down
11 changes: 11 additions & 0 deletions docs/source/usersguide/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,17 @@ or particles going to a cell::
.. note:: The ``cell``, ``cellfrom`` and ``cellto`` attributes cannot be
used simultaneously.

To generate more than one surface source files when the maximum number of stored
particles is reached, ``max_source_files`` is available. The surface source bank
will be cleared in simulation memory each time a surface source file is written.
As an example, to write a maximum of three surface source files:::

settings.surf_source_write = {
'surfaces_ids': [1, 2, 3],
'max_particles': 10000,
'max_source_files': 3
}

.. _compiled_source:

Compiled Sources
Expand Down
3 changes: 2 additions & 1 deletion include/openmc/lattice.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class Lattice {
//! Allocate offset table for distribcell.
void allocate_offset_table(int n_maps)
{
offsets_.resize(n_maps * universes_.size(), C_NONE);
offsets_.resize(n_maps * universes_.size());
std::fill(offsets_.begin(), offsets_.end(), C_NONE);
}

//! Populate the distribcell offset tables.
Expand Down
6 changes: 3 additions & 3 deletions include/openmc/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class Mesh {
virtual ~Mesh() = default;

// Methods
//! Perform any preparation needed to support use in mesh filters
virtual void prepare_for_tallies() {};
//! Perform any preparation needed to support point location within the mesh
virtual void prepare_for_point_location() {};

//! Update a position to the local coordinates of the mesh
virtual void local_coords(Position& r) const {};
Expand Down Expand Up @@ -737,7 +737,7 @@ class MOABMesh : public UnstructuredMesh {
// Overridden Methods

//! Perform any preparation needed to support use in mesh filters
void prepare_for_tallies() override;
void prepare_for_point_location() override;

Position sample_element(int32_t bin, uint64_t* seed) const override;

Expand Down
8 changes: 6 additions & 2 deletions include/openmc/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ struct formatter<std::array<T, 2>> {
}

template<typename FormatContext>
#if FMT_VERSION >= 110000 // Version 11.0.0 and above
auto format(const std::array<T, 2>& arr, FormatContext& ctx) const {
#else // For versions below 11.0.0
auto format(const std::array<T, 2>& arr, FormatContext& ctx)
{
#endif
return format_to(ctx.out(), "({}, {})", arr[0], arr[1]);
}
};
}
}; // namespace fmt

} // namespace fmt
8 changes: 6 additions & 2 deletions include/openmc/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,16 @@ namespace fmt {
template<>
struct formatter<openmc::Position> : formatter<std::string> {
template<typename FormatContext>
#if FMT_VERSION >= 110000 // Version 11.0.0 and above
auto format(const openmc::Position& pos, FormatContext& ctx) const {
#else // For versions below 11.0.0
auto format(const openmc::Position& pos, FormatContext& ctx)
{
#endif
return formatter<std::string>::format(
fmt::format("({}, {}, {})", pos.x, pos.y, pos.z), ctx);
}
};
}
}; // namespace fmt

} // namespace fmt

Expand Down
15 changes: 9 additions & 6 deletions include/openmc/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,18 @@ extern std::unordered_set<int>
statepoint_batch; //!< Batches when state should be written
extern std::unordered_set<int>
source_write_surf_id; //!< Surface ids where sources will be written

extern int
max_history_splits; //!< maximum number of particle splits for weight windows
extern int64_t max_surface_particles; //!< maximum number of particles to be
//!< banked on surfaces per process
extern int max_secondaries; //!< maximum number of secondaries in the bank
extern int64_t ssw_cell_id; //!< Cell id for the surface source
//!< write setting
extern SSWCellType ssw_cell_type; //!< Type of option for the cell
//!< argument of surface source write
extern int64_t ssw_max_particles; //!< maximum number of particles to be
//!< banked on surfaces per process
extern int64_t ssw_max_files; //!< maximum number of surface source files
//!< to be created
extern int64_t ssw_cell_id; //!< Cell id for the surface source
//!< write setting
extern SSWCellType ssw_cell_type; //!< Type of option for the cell
//!< argument of surface source write
extern TemperatureMethod
temperature_method; //!< method for choosing temperatures
extern double
Expand Down
1 change: 1 addition & 0 deletions include/openmc/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern "C" int n_lost_particles; //!< cumulative number of lost particles
extern "C" bool need_depletion_rx; //!< need to calculate depletion rx?
extern "C" int restart_batch; //!< batch at which a restart job resumed
extern "C" bool satisfy_triggers; //!< have tally triggers been satisfied?
extern int ssw_current_file; //!< current surface source file
extern "C" int total_gen; //!< total number of generations simulated
extern double total_weight; //!< Total source weight in a batch
extern int64_t work_per_rank; //!< number of particles per MPI rank
Expand Down
8 changes: 6 additions & 2 deletions include/openmc/state_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OPENMC_STATE_POINT_H

#include <cstdint>
#include <string>

#include <gsl/gsl-lite.hpp>

Expand Down Expand Up @@ -33,8 +34,11 @@ void load_state_point();
// values on each rank, used to create global indexing. This vector
// can be created by calling calculate_parallel_index_vector on
// source_bank.size() if such a vector is not already available.
void write_source_point(const char* filename, gsl::span<SourceSite> source_bank,
const vector<int64_t>& bank_index);
void write_h5_source_point(const char* filename,
gsl::span<SourceSite> source_bank, const vector<int64_t>& bank_index);

void write_source_point(std::string, gsl::span<SourceSite> source_bank,
const vector<int64_t>& bank_index, bool use_mcpl);

// This appends a source bank specification to an HDF5 file
// that's already open. It is used internally by write_source_point.
Expand Down
1 change: 1 addition & 0 deletions include/openmc/tallies/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum class FilterType {
MESHBORN,
MESH_SURFACE,
MU,
MUSURFACE,
PARTICLE,
POLAR,
SPHERICAL_HARMONICS,
Expand Down
Loading

0 comments on commit a226095

Please sign in to comment.