Add ability to set TCRs manually - #4106
Open
GiudGiud wants to merge 3 commits into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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