Skip to content

Add ability to set TCRs manually - #4106

Open
GiudGiud wants to merge 3 commits into
openmc-dev:developfrom
GiudGiud:mgxs-transport-correction-ratios
Open

Add ability to set TCRs manually#4106
GiudGiud wants to merge 3 commits into
openmc-dev:developfrom
GiudGiud:mgxs-transport-correction-ratios

Conversation

@GiudGiud

@GiudGiud GiudGiud commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Description

Add a transport_correction_ratios attribute to openmc.mgxs.Library that
lets users supply a per-domain, per-group transport correction to apply
when the library is written to an openmc.MGXSLibrary. The ratios are a
nested dict keyed by domain type and then domain ID, with one ratio
r_g = sigma_tr,g / sigma_t,g per energy group.

Motivation is getting better results on shielding calcs for NRIC

Fixes #4107

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable) -> hopefully? how does Claude do on following the guidelines?
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

GiudGiud and others added 3 commits August 28, 2026 16:52
Add a transport_correction_ratios attribute to openmc.mgxs.Library that
lets users supply a per-domain, per-group transport correction to apply
when the library is written to an openmc.MGXSLibrary. The ratios are a
nested dict keyed by domain type and then domain ID, with one ratio
r_g = sigma_tr,g / sigma_t,g per energy group.

For each listed domain the total is replaced by the transport-corrected
value r_g * sigma_t,g and the same correction (1 - r_g) * sigma_t,g is
subtracted from the in-group P0 element of the scattering matrix, which
preserves the absorption balance. This is an alternative to the
tally-based 'P0' correction, so it requires correction=None, a
'legendre' scatter_format, and a 'total' MGXS type; domains without an
entry are left uncorrected. Both isotropic and 'angle' representations
are supported.

Add unit tests covering the setter validation/normalization and the
application logic (total, scatter diagonal, absorption balance, angle
representation, no-op without an entry, and mutual exclusivity with the
'P0' correction).

Co-Authored-By: Claude <noreply@anthropic.com>
When a 'transport' or 'nu-transport' MGXS type has been tallied,
Library.load_from_statepoint now computes the per-group transport
correction ratios r_g = sigma_tr,g / sigma_t,g for each domain and stores
them in the transport_correction_ratios attribute. The transport-corrected
total is the transport MGXS itself; the plain total is recovered from the
same MGXS's total and flux tallies. User-supplied entries are preserved and
never overwritten, and only isotropic, single-subdomain data is handled.

Because the ratios are now populated automatically alongside the standard
'P0' workflow, applying them is gated on correction being None: when
correction is 'P0' the tally-based correction is already reflected in the
total and scattering matrix, so the stored ratios are recorded but not
applied (rather than raising). check_library_for_openmc_mgxs validates the
ratios only in the case where they are applied.

Co-Authored-By: Claude <noreply@anthropic.com>
get_xsdata now derives the transport correction from the ratios stored in
transport_correction_ratios rather than relying on the tally-based total and
P0 scattering-matrix correction directly. For each domain the exported total
is set to r_g * sigma_t,g and the in-group P0 scattering diagonal is shifted
by the same amount, so the absorption balance is preserved and the stored
ratios are the single source of truth. Editing an entry after
load_from_statepoint therefore changes the correction that is applied.

The plain sigma_t needed for the correction is taken from the 'total' MGXS
when correction is None, or recovered from the 'transport'/'nu-transport'
MGXS (via _uncorrected_total_xs) when correction is 'P0'; the latter recovery
is only performed for isotropic data. When the stored ratios equal the
tally-derived sigma_tr / sigma_t (as they are after automatic population),
re-applying them reproduces the tally-based data unchanged. Validation in
check_library_for_openmc_mgxs now covers both correction modes.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to set transport correction ratios externally

1 participant