From cef713b91e633f5f37bf165cba51145e7befba0e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 5 Dec 2018 08:35:08 -0600 Subject: [PATCH] Make sure fission neutron energy is resampled if > max energy Also fix two other bugs, one where openmc.capi.find_material crashes if a material is void, and one where OpenMC doesn't compile if omp.h is missing (can happen on macOS). --- openmc/capi/core.py | 2 +- src/physics.cpp | 6 ++++-- src/settings.cpp | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/openmc/capi/core.py b/openmc/capi/core.py index bedde6e162..88c2b45a38 100644 --- a/openmc/capi/core.py +++ b/openmc/capi/core.py @@ -121,7 +121,7 @@ def find_material(xyz): _dll.openmc_find_cell((c_double*3)(*xyz), index, instance) mats = openmc.capi.Cell(index=index.value).fill - if isinstance(mats, openmc.capi.Material): + if isinstance(mats, (openmc.capi.Material, type(None))): return mats else: return mats[instance.value] diff --git a/src/physics.cpp b/src/physics.cpp index 43fc2871b4..4d8c01cf35 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -1057,7 +1057,8 @@ void sample_fission_neutron(int i_nuclide, const Reaction* rx, double E_in, Bank rx->products_[group].sample(E_in, site->E, mu); // resample if energy is greater than maximum neutron energy - constexpr int neutron = static_cast(ParticleType::neutron); + // TODO: off-by-one + constexpr int neutron = static_cast(ParticleType::neutron) - 1; if (site->E < data::energy_max[neutron]) break; // check for large number of resamples @@ -1082,7 +1083,8 @@ void sample_fission_neutron(int i_nuclide, const Reaction* rx, double E_in, Bank rx->products_[0].sample(E_in, site->E, mu); // resample if energy is greater than maximum neutron energy - constexpr int neutron = static_cast(ParticleType::neutron); + // TODO: off-by-one + constexpr int neutron = static_cast(ParticleType::neutron) - 1; if (site->E < data::energy_max[neutron]) break; // check for large number of resamples diff --git a/src/settings.cpp b/src/settings.cpp index 303a35ddd9..261536813c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -5,7 +5,9 @@ #include #include +#ifdef _OPENMP #include +#endif #include "openmc/capi.h" #include "openmc/constants.h"