Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3f9f0c1
Initial support for photon MGXS
paulromano Aug 3, 2026
6fe895d
Add photon MGXS regression test
paulromano Aug 9, 2026
b29af78
Use nu-scatter formalism for photon production
paulromano Aug 9, 2026
845312e
Simplify mgxs_photon test
paulromano Aug 16, 2026
6154c6b
Simplify unit tests
paulromano Aug 17, 2026
0b0d2ae
Fix slicing and condensation on photon production MGXS
paulromano Aug 23, 2026
903446c
Rename photon production matrix MGXS
paulromano Aug 27, 2026
9e79ab2
Enable multigroup photon transport in MC mode
Sep 18, 2026
58a3045
Add multigroup photon regression test
Sep 18, 2026
63c68df
Fix photon MG scoring in tally_scoring and compute multiplicity in xs…
Sep 23, 2026
5a84711
Add multigroup photon and analog nu-scatter tests
Oct 28, 2026
85b2906
Resolving conflicts
Nov 18, 2026
19cca10
Address review comments
Nov 19, 2026
5d4788d
Retain local photon CE-to-MG coverage and material guards
paulromano Nov 16, 2026
b73665a
Remove trailing whitespace in scattdata header
paulromano Nov 24, 2026
118907f
Reject multigroup nuclide density updates
paulromano Nov 24, 2026
5a54b3b
Use backslash param tags for scattering multiplicity
paulromano Nov 24, 2026
cf624f9
Clarify the analog nu-scatter weight comment
paulromano Nov 24, 2026
ebb6a8d
Make analog nu-scatter multiplicity explicit
paulromano Nov 24, 2026
aac570e
Validate the particle type in MGXS headers
paulromano Nov 24, 2026
f7c158e
Make nu scaling in tally scoring clearer
paulromano Nov 24, 2026
7110e9c
Spacing fix
paulromano Nov 24, 2026
5185b86
Move multigroup source checks into the MGXS interface
paulromano Nov 24, 2026
a4436b9
Clarify the photon multiplicity fallback comment
paulromano Nov 24, 2026
426671c
Name the photon scattering cross section explicitly
paulromano Nov 24, 2026
c8d6842
Name the photon nu-scatter cross section explicitly
paulromano Nov 24, 2026
0935736
Separate multigroup photon integration and regression tests
paulromano Nov 24, 2026
e421cc0
Simplify multigroup photon test setup and assertions
paulromano Nov 24, 2026
9ebb472
Use delta_function instead of Discrete
paulromano Nov 24, 2026
9cf2324
Normalize analog nu-scatter test line endings
paulromano Nov 24, 2026
6c14627
Reject photon MGXS in random ray mode
paulromano Nov 24, 2026
2c7b9bf
Reject photon scattering rows without production
paulromano Nov 24, 2026
1d046c8
Correct analog scatter scores for outgoing-group multiplicity
paulromano Nov 24, 2026
88442fe
Reject unsafe multigroup material updates
paulromano Nov 24, 2026
f24ebe6
Accept independent MG sources at the highest group edge
paulromano Nov 24, 2026
a61c98a
Document multigroup photon library support
paulromano Nov 24, 2026
023c78f
Remove language in settings guide about fixed source photon MG
paulromano Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions docs/source/io_formats/mgxs_library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ MGXS Library Specification
for this library it will be 'mgxs'.
- **version** (*int[2]*) -- Major and minor version of the
multi-group library file format.
- **particle_type** (*char[]*) -- Particle type for the whole
library, either ``neutron`` or ``photon``. The default is
``neutron`` when this attribute is omitted.
- **energy_groups** (*int*) -- Number of energy groups
- **delayed_groups** (*int*) -- Number of delayed groups (optional)
- **group structure** (*double[]*) -- Monotonically increasing
Expand Down Expand Up @@ -133,24 +136,22 @@ Temperature-dependent data, provided for temperature <TTT>K.
This dataset is optional. This is a 1-D vector if `representation`
is "isotropic", or a 3-D vector if `representation` is "angle"
with dimensions of [polar][azimuthal][groups].
When this data is not available, an approximation using the
group energy boundaries is used. For more information see
the particle speed subsection in the multigroup-data section
of the theory manual.
When this data is absent, OpenMC approximates neutron inverse
velocity using the group boundaries and uses :math:`1/c` for
photons. See the particle speed subsection in the multigroup-data
section of the theory manual.

**/<library name>/<TTT>K/scatter_data/**

Data specific to neutron scattering for the temperature <TTT>K
Scattering data for the temperature <TTT>K.

:Datasets: - **g_min** (*int[]* or *int[][][]*) --
Minimum (most energetic) groups with non-zero values of
the scattering matrix provided. If `scatter_shape` is
"[Order][G][G']" then `g_min` will describe the minimum values
of "G'" for each "G"; if `scatter_shape` is "[Order][G'][G]"
then `g_min` will describe the minimum values of "G" for each "G'".
These group numbers use the standard
ordering where the fastest neutron energy group is group 1 while
the slowest neutron energy group is group G.
The highest energy group is group 1 and the lowest is group G.
The dimensionality of `g_min` is:
`g_min[g]`, or `g_min[num_polar][num_azimuthal][g]`.
The former is used when `representation` is "isotropic", and the
Expand All @@ -166,14 +167,19 @@ Data specific to neutron scattering for the temperature <TTT>K
"[num_polar][num_azimuthal]" dimensions. The right-most energy
group dimension will only include the entries between `g_min` and
`g_max`.
dimension has a dimensionality of `g_min` to `g_max`.
- **multiplicity_matrix** (*double[]*) -- Flattened representation of
the scattering moment matrices. This dataset provides the code with
a scaling factor to account for neutrons being produced in (n,xn)
reactions. This is assumed isotropic and therefore is not repeated
for every Legendre moment or histogram/tabular bin. This dataset is
optional, if it is not provided no multiplication (i.e., values of
1.0) will be assumed.
The pre-flattened array is shapes consistent with `scatter_matrix`
except the "[Order]" dimension in `scatter_shape` is ignored since
this data is assumed isotropic.
In photon libraries the matrix includes secondary photon
production.
- **multiplicity_matrix** (*double[]*) -- Optional multiplicity for
each energy group transfer. It accounts for particle production in
scattering, including neutrons from (n,xn) and secondary photons.
The unflattened array has the shape of `scatter_matrix` without
the "[Order]" dimension because multiplicity is independent of the
scattering cosine.

If the dataset is absent, OpenMC uses a multiplicity of 1 for
neutrons. For photon Monte Carlo, OpenMC derives one value per
incoming group by summing the production cross sections over all
outgoing groups and dividing by the total cross section minus
absorption. A group with zero production and zero scattering uses
a multiplicity of 1. The reader rejects groups where only one of
production and scattering is positive.
2 changes: 1 addition & 1 deletion docs/source/io_formats/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ generator during generation of colors in plots.

The ``properties_file`` element has no attributes and contains the path to a
properties HDF5 file to load cell temperatures/densities and material
densities.
densities. This element is available in continuous-energy mode.

*Default*: None

Expand Down
8 changes: 4 additions & 4 deletions docs/source/usersguide/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,10 @@ transport::

settings.photon_transport = True

Atomic relaxation (the cascade of fluorescence photons and Auger electrons
emitted when an inner-shell vacancy is filled) is enabled by default whenever
photon transport is on. It can be disabled using the
:attr:`Settings.atomic_relaxation` attribute::
In continuous-energy mode, atomic relaxation (the cascade of fluorescence
photons and Auger electrons emitted when an inner-shell vacancy is filled)
is enabled by default whenever photon transport is on. To disable it, set
:attr:`Settings.atomic_relaxation` to ``False``::

settings.atomic_relaxation = False

Expand Down
6 changes: 5 additions & 1 deletion include/openmc/mgxs_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class MgxsInterface {
vector<vector<double>> get_mat_kTs();

// Get the group index corresponding to a continuous energy
int get_group_index(double E);
int get_group_index(double E) const;

// Validate the source particle type and energy before finding its group
int get_source_group_index(ParticleType particle, double E) const;

int num_energy_groups_;
int num_delayed_groups_;
Expand All @@ -63,6 +66,7 @@ class MgxsInterface {
vector<vector<double>> nuc_temps_; // all available temperatures
vector<double>
default_inverse_velocity_; // approximate default inverse-velocity data
ParticleType particle_type_ {ParticleType::neutron()};
};

namespace data {
Expand Down
9 changes: 9 additions & 0 deletions include/openmc/scattdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class ScattData {
tensor::Tensor<int> gmax; // maximum outgoing group
tensor::Tensor<double> scattxs; // Isotropic Sigma_{s,g_{in}}

//! \brief Sets a multiplicity that is the same for every outgoing group.
//!
//! Keeps the per-event weight multiplier used by sample() and get_xs()
//! consistent with the new multiplicity.
//!
//! \param gin Incoming energy group.
//! \param value Multiplicity (nu-scatter / scatter) of group gin.
void set_multiplicity(int gin, double value);

//! \brief Calculates the value of normalized f(mu).
//!
//! The value of f(mu) is normalized as in the integral of f(mu)dmu across
Expand Down
5 changes: 5 additions & 0 deletions src/cross_sections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ void read_cross_sections_xml(pugi::xml_node root)
read_ce_cross_sections_xml();
} else {
data::mg.read_header(settings::path_cross_sections);
if (settings::solver_type == SolverType::RANDOM_RAY &&
data::mg.particle_type_.is_photon()) {
fatal_error("Photon MGXS libraries are not supported by the random ray "
"solver.");
}
put_mgxs_header_data_to_globals();
}

Expand Down
22 changes: 19 additions & 3 deletions src/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Material::Material(pugi::xml_node node)
auto n = names.size();
nuclide_.reserve(n);
atom_density_ = tensor::Tensor<double>({n});
if (settings::photon_transport)
if (settings::photon_transport && settings::run_CE)
element_.reserve(n);

for (int i = 0; i < n; ++i) {
Expand Down Expand Up @@ -244,7 +244,7 @@ Material::Material(pugi::xml_node node)

// If the corresponding element hasn't been encountered yet and photon
// transport will be used, we need to add its symbol to the element_dict
if (settings::photon_transport) {
if (settings::photon_transport && settings::run_CE) {
std::string element = to_element(name);

// Make sure photon cross section data is available
Expand Down Expand Up @@ -967,6 +967,11 @@ void Material::set_id(int32_t id)

void Material::set_density(double density, const std::string& units)
{
if (!settings::run_CE) {
throw std::runtime_error {
"Setting material density is not supported in multigroup mode."};
}

assert(density >= 0.0);

if (nuclide_.empty()) {
Expand All @@ -990,7 +995,7 @@ void Material::set_density(double density, const std::string& units)
for (int i = 0; i < nuclide_.size(); ++i) {
int i_nuc = nuclide_[i];
double awr = data::nuclides[i_nuc]->awr_;
int z = settings::run_CE ? data::nuclides[i_nuc]->Z_ : 0.0;
int z = data::nuclides[i_nuc]->Z_;
density_gpcc_ += atom_density_(i) * awr * MASS_NEUTRON / N_AVOGADRO;
charge_density_ += atom_density_(i) * z;
}
Expand All @@ -1013,6 +1018,11 @@ void Material::set_density(double density, const std::string& units)
void Material::set_densities(
const vector<std::string>& name, const vector<double>& density)
{
if (!settings::run_CE) {
throw std::runtime_error {
"Setting nuclide densities is not supported in multigroup mode."};
}

auto n = name.size();
assert(n > 0);
assert(n == density.size());
Expand Down Expand Up @@ -1149,6 +1159,11 @@ void Material::import_properties_hdf5(hid_t group)

void Material::add_nuclide(const std::string& name, double density)
{
if (!settings::run_CE) {
throw std::runtime_error {
"Adding nuclides is not supported in multigroup mode."};
}

// Check if nuclide is already in material
for (int i = 0; i < nuclide_.size(); ++i) {
int i_nuc = nuclide_[i];
Expand Down Expand Up @@ -1376,6 +1391,7 @@ extern "C" int openmc_material_add_nuclide(
try {
model::materials[index]->add_nuclide(name, density);
} catch (const std::runtime_error& e) {
set_errmsg(e.what());
return OPENMC_E_DATA;
}
} else {
Expand Down
47 changes: 43 additions & 4 deletions src/mgxs_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "openmc/mgxs_interface.h"

#include <stdexcept>
#include <string>
#include <unordered_set>

Expand Down Expand Up @@ -184,13 +185,31 @@ vector<vector<double>> MgxsInterface::get_mat_kTs()

//==============================================================================

int MgxsInterface::get_group_index(double E)
int MgxsInterface::get_group_index(double E) const
{
int g =
lower_bound_index(rev_energy_bins_.begin(), rev_energy_bins_.end(), E);
return num_energy_groups_ - g - 1.;
}

int MgxsInterface::get_source_group_index(ParticleType particle, double E) const
{
if (particle != particle_type_) {
fatal_error(fmt::format(
"Source particle type '{}' does not match the '{}' MGXS library.",
particle.str(), particle_type_.str()));
}

double E_min = rev_energy_bins_.front();
double E_max = rev_energy_bins_.back();
if (E < E_min || E > E_max) {
fatal_error(fmt::format(
"Source energy {} eV is outside the MGXS group structure ({}-{} eV).", E,
E_min, E_max));
}
return get_group_index(E);
}

//==============================================================================

void MgxsInterface::read_header(const std::string& path_cross_sections)
Expand All @@ -209,6 +228,22 @@ void MgxsInterface::read_header(const std::string& path_cross_sections)
// Open file for reading
hid_t file_id = file_open(cross_sections_path_, 'r', true);

std::string particle_name {"neutron"};
if (attribute_exists(file_id, "particle_type")) {
read_attribute(file_id, "particle_type", particle_name);
}
try {
particle_type_ = ParticleType(particle_name);
} catch (const std::logic_error&) {
fatal_error(fmt::format(
"Invalid particle_type '{}' in MGXS library.", particle_name));
}
if (!particle_type_.is_neutron() && !particle_type_.is_photon()) {
fatal_error(fmt::format("Unsupported particle_type '{}' in MGXS library. "
"Expected a neutron or photon.",
particle_name));
}

ensure_exists(file_id, "energy_groups", true);
read_attribute(file_id, "energy_groups", num_energy_groups_);

Expand Down Expand Up @@ -239,6 +274,10 @@ void MgxsInterface::read_header(const std::string& path_cross_sections)

// Calculate approximate default inverse velocity data
for (int i = 0; i < energy_bins_.size() - 1; ++i) {
if (particle_type_.is_photon()) {
default_inverse_velocity_.push_back(1.0 / C_LIGHT);
continue;
}
double e_min = std::max(energy_bins_[i + 1], 1e-5);
double e_max = energy_bins_[i];
double alpha = 1.0 / (C_LIGHT * std::log(e_max / e_min));
Expand All @@ -257,9 +296,9 @@ void MgxsInterface::read_header(const std::string& path_cross_sections)
void put_mgxs_header_data_to_globals()
{
// Get the minimum and maximum energies
int neutron = ParticleType::neutron().transport_index();
data::energy_min[neutron] = data::mg.energy_bins_.back();
data::energy_max[neutron] = data::mg.energy_bins_.front();
int particle = data::mg.particle_type_.transport_index();
data::energy_min[particle] = data::mg.energy_bins_.back();
data::energy_max[particle] = data::mg.energy_bins_.front();

// Save available XS names to library list, so that when
// materials are read, the specified mgxs can be confirmed
Expand Down
6 changes: 6 additions & 0 deletions src/scattdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ void ScattData::sample_energy(int gin, int& gout, int& i_gout, uint64_t* seed)

//==============================================================================

void ScattData::set_multiplicity(int gin, double value)
{
std::fill(mult[gin].begin(), mult[gin].end(), value);
weight_mult_[gin] = value;
}

double ScattData::get_xs(
MgxsType xstype, int gin, const int* gout, const double* mu)
{
Expand Down
9 changes: 4 additions & 5 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,6 @@ void read_settings_xml(pugi::xml_node root)
// Check for photon transport
if (check_for_node(root, "photon_transport")) {
photon_transport = get_node_value_bool(root, "photon_transport");

if (!run_CE && photon_transport) {
fatal_error("Photon transport is not currently supported in "
"multigroup mode");
}
}

// Check for atomic relaxation
Expand Down Expand Up @@ -790,6 +785,10 @@ void read_settings_xml(pugi::xml_node root)

// read properties from file
if (check_for_node(root, "properties_file")) {
if (!run_CE) {
fatal_error("The properties_file setting is not supported in multigroup "
"mode.");
}
properties_file = get_node_value(root, "properties_file");
if (!file_exists(properties_file)) {
fatal_error(fmt::format("File '{}' does not exist.", properties_file));
Expand Down
13 changes: 6 additions & 7 deletions src/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,13 @@ SourceSite IndependentSource::sample(uint64_t* seed) const
if (settings::solver_type != SolverType::RANDOM_RAY) {
// Check for monoenergetic source above maximum particle energy
auto p = particle_.transport_index();
double E_max = data::energy_max[p];
auto energy_ptr = dynamic_cast<Discrete*>(energy_.get());
auto decay_spectrum = dynamic_cast<DecaySpectrum*>(energy_.get());
if (energy_ptr) {
auto energies =
tensor::Tensor<double>(energy_ptr->x().data(), energy_ptr->x().size());
if ((energies > data::energy_max[p]).any()) {
if ((energies > E_max).any()) {
fatal_error("Source energy above range of energies of at least "
"one cross section table");
}
Expand All @@ -462,9 +463,9 @@ SourceSite IndependentSource::sample(uint64_t* seed) const
E_wgt = E_wgt_temp;
}

// Resample if energy falls above maximum particle energy
if (site.E < data::energy_max[p] &&
(satisfies_energy_constraints(site.E)))
// The highest energy group includes its upper edge.
bool in_range = settings::run_CE ? site.E < E_max : site.E <= E_max;
if (in_range && satisfies_energy_constraints(site.E))
break;

++n_local_reject;
Expand Down Expand Up @@ -1855,9 +1856,7 @@ SourceSite sample_external_source(uint64_t* seed)

// If running in MG, convert site.E to group
if (!settings::run_CE) {
site.E = lower_bound_index(data::mg.rev_energy_bins_.begin(),
data::mg.rev_energy_bins_.end(), site.E);
site.E = data::mg.num_energy_groups_ - site.E - 1.;
site.E = data::mg.get_source_group_index(site.particle, site.E);
}

return site;
Expand Down
5 changes: 5 additions & 0 deletions src/summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ extern "C" int openmc_properties_export(const char* filename)

extern "C" int openmc_properties_import(const char* filename)
{
if (!settings::run_CE) {
set_errmsg("Importing properties is not supported in multigroup mode.");
return OPENMC_E_UNASSIGNED;
}

// Display output message
auto msg = fmt::format("Importing properties from {}...", filename);
write_message(msg, 5);
Expand Down
Loading
Loading