From 65f94a8d28243d174137c5e566206814099573b1 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 28 Jan 2026 23:52:06 +0200 Subject: [PATCH 1/7] warn users that tally heating photon bin without electron and positron --- src/tallies/tally.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 6eef1da9cfd..19993b25b9c 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -535,6 +535,7 @@ void Tally::set_scores(const vector& scores) bool legendre_present = false; bool cell_present = false; bool cellfrom_present = false; + bool particle_present = false; bool surface_present = false; bool meshsurface_present = false; bool non_cell_energy_present = false; @@ -555,6 +556,8 @@ void Tally::set_scores(const vector& scores) surface_present = true; } else if (filt->type() == FilterType::MESH_SURFACE) { meshsurface_present = true; + } else if (filt->type() == FilterType::PARTICLE) { + particle_present = true; } } @@ -624,8 +627,28 @@ void Tally::set_scores(const vector& scores) break; case HEATING: - if (settings::photon_transport) + if (settings::photon_transport) { estimator_ = TallyEstimator::COLLISION; + if (particle_present) { + const auto particles = get_filter().particles(); + if (contains(particles, "photon")) { + bool electron_present = contains(particles, "electron"); + bool positron_present = contains(particles, "positron"); + if (!positron_present || !electron_present) { + if (!electron_present) + warning("Tally {} contains heating score with photon bin but " + "without electron bin.", + id_); + if (!positron_present) + warning("Tally {} contains heating score with photon bin but " + "without positron bin.", + id_); + warning("Forgetting to specify charged particles in particle " + "filter when using heating score is a common gotcha."); + } + } + } + } break; case SCORE_PULSE_HEIGHT: From 4cd44bf512721cb72fc5e517ded277f66c4f6c26 Mon Sep 17 00:00:00 2001 From: GuySten Date: Thu, 29 Jan 2026 00:10:44 +0200 Subject: [PATCH 2/7] fix typo --- src/tallies/tally.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 19993b25b9c..3f4cfba9302 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -636,13 +636,15 @@ void Tally::set_scores(const vector& scores) bool positron_present = contains(particles, "positron"); if (!positron_present || !electron_present) { if (!electron_present) - warning("Tally {} contains heating score with photon bin but " - "without electron bin.", - id_); + warning(fmt::format( + "Tally {} contains heating score with photon bin but " + "without electron bin.", + id_)); if (!positron_present) - warning("Tally {} contains heating score with photon bin but " - "without positron bin.", - id_); + warning(fmt::format( + "Tally {} contains heating score with photon bin but " + "without positron bin.", + id_)); warning("Forgetting to specify charged particles in particle " "filter when using heating score is a common gotcha."); } From 39770f9f2318f7b0f47efd57471fa3503278f6db Mon Sep 17 00:00:00 2001 From: GuySten Date: Thu, 29 Jan 2026 00:13:15 +0200 Subject: [PATCH 3/7] fix typo --- src/tallies/tally.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 3f4cfba9302..f9cbd1010d8 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -630,10 +630,10 @@ void Tally::set_scores(const vector& scores) if (settings::photon_transport) { estimator_ = TallyEstimator::COLLISION; if (particle_present) { - const auto particles = get_filter().particles(); - if (contains(particles, "photon")) { - bool electron_present = contains(particles, "electron"); - bool positron_present = contains(particles, "positron"); + const auto particles = get_filter()->particles(); + if (contains(particles, ParticleType::photon)) { + bool electron_present = contains(particles, ParticleType::electron); + bool positron_present = contains(particles, ParticleType::positron); if (!positron_present || !electron_present) { if (!electron_present) warning(fmt::format( From 43cee2b04d37908f60692b419ee4454ad9319600 Mon Sep 17 00:00:00 2001 From: GuySten Date: Tue, 3 Feb 2026 09:28:44 +0200 Subject: [PATCH 4/7] fix typos --- src/tallies/tally.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 63baee0fbd1..d518e8d0f12 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -631,9 +631,11 @@ void Tally::set_scores(const vector& scores) estimator_ = TallyEstimator::COLLISION; if (particle_present) { const auto particles = get_filter()->particles(); - if (contains(particles, ParticleType::photon)) { - bool electron_present = contains(particles, ParticleType::electron); - bool positron_present = contains(particles, ParticleType::positron); + if (contains(particles, ParticleType::photon())) { + bool electron_present = + contains(particles, ParticleType::electron()); + bool positron_present = + contains(particles, ParticleType::positron()); if (!positron_present || !electron_present) { if (!electron_present) warning(fmt::format( From d847ec4119a7d6ae449992a101c9b5e732de6f44 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 18:00:38 +0200 Subject: [PATCH 5/7] improve error message according to suggestion --- src/tallies/tally.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index d518e8d0f12..2f807171910 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -637,18 +637,27 @@ void Tally::set_scores(const vector& scores) bool positron_present = contains(particles, ParticleType::positron()); if (!positron_present || !electron_present) { - if (!electron_present) - warning(fmt::format( - "Tally {} contains heating score with photon bin but " - "without electron bin.", - id_)); - if (!positron_present) - warning(fmt::format( - "Tally {} contains heating score with photon bin but " - "without positron bin.", - id_)); - warning("Forgetting to specify charged particles in particle " - "filter when using heating score is a common gotcha."); + std::string missing_bins; + if (!electron_present) { + missing_bins += "electron bin"; + if (!positron_present) + missing_bins += "and positron bin"; + } else { + missing_bins += "positron bin"; + } + std::string other_bins; + for (auto b : particles) { + if ((b != ParticleType::photon()) && + (b != ParticleType::electron()) && + (b != ParticleType::positron())) + other_bins += fmt::format("'{}', ", b.str()); + } + + warning(fmt::format( + "Tally {} contains heating score with photon bin but " + "without {}. Try adding to the particle filter: " + "openmc.ParticleFilter([{}'photon', 'electron', 'positron']) ", + id_, missing_bins, other_bins)); } } } From 27d6053a4971a3c9e517e7148b7786d345fa310e Mon Sep 17 00:00:00 2001 From: GuySten <62616591+GuySten@users.noreply.github.com> Date: Wed, 4 Feb 2026 21:50:45 +0200 Subject: [PATCH 6/7] Update src/tallies/tally.cpp Co-authored-by: Jonathan Shimwell --- src/tallies/tally.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 2f807171910..9eaccdcb012 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -641,7 +641,7 @@ void Tally::set_scores(const vector& scores) if (!electron_present) { missing_bins += "electron bin"; if (!positron_present) - missing_bins += "and positron bin"; + missing_bins += " and positron bin"; } else { missing_bins += "positron bin"; } From 246deedb8379170a725d8b3a18be57b4ac967a21 Mon Sep 17 00:00:00 2001 From: GuySten Date: Wed, 4 Feb 2026 23:20:59 +0200 Subject: [PATCH 7/7] get rid of reference to the python api in the warning --- src/tallies/tally.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/tallies/tally.cpp b/src/tallies/tally.cpp index 9eaccdcb012..465ac643493 100644 --- a/src/tallies/tally.cpp +++ b/src/tallies/tally.cpp @@ -645,19 +645,11 @@ void Tally::set_scores(const vector& scores) } else { missing_bins += "positron bin"; } - std::string other_bins; - for (auto b : particles) { - if ((b != ParticleType::photon()) && - (b != ParticleType::electron()) && - (b != ParticleType::positron())) - other_bins += fmt::format("'{}', ", b.str()); - } - warning(fmt::format( "Tally {} contains heating score with photon bin but " - "without {}. Try adding to the particle filter: " - "openmc.ParticleFilter([{}'photon', 'electron', 'positron']) ", - id_, missing_bins, other_bins)); + "without {}. A significant heating contribution might be " + "missing!", + id_, missing_bins)); } } }