transportcorrection module

transportcorrection.py

Transport correction factors based on a function that finds the correction factor analytically. The transport correction relies on the slowing down theory in an infinite homogeneous medium.

Created on Mon June 09 17:10:00 2025 @author: Dan Kotlyar Last updated on Mon June 19 12:08:00 2025 @author: Jonathon Faulkner

transportcorrection.InfFlux_INCLASS(energy, sigS, sigT, src)

Solves for the infinite flux using the trapezoid rule solution to eq. 6.4

INCLASS EXAMPLE

Parameters:
  • energy (array) – energy mesh points.

  • sigS (array) – scattering cross section as a function of energy.

  • sigT (array) – total cross section as a function of energy.

  • src (array) – assumed source as a function of energy.

Returns:

flx – flux values for all the energy points

Return type:

array

transportcorrection.Plot1d(xvals, yvals, xlabel=None, ylabel=None, legend=None, fontsize=16, marker='--*', markerfill=False, markersize=6, logx=True)

Plots a 1D solution

Parameters:
  • power (bool, optional) – if power is True or not included the power distribution is plotted, otherwise not

  • xvals (np.ndarray) – x-axis values

  • yvals (np.array) – y-axis values

  • xlabel (str) – x-axis label with a default Length, meters

  • ylabel (str) – y-axis label with a default Normalized Flux

  • fontsize (float) – font size value

  • markers (str or list of strings) – markers type

  • markerfill (bool) – True if the marking filling to be included and False otherwise

  • markersize (int or float) – size of the marker with a default of 8.

transportcorrection.TRCSolver(energy: ndarray, flx: ndarray, A: float, intRule: str)

Solves for the transport correction factor.

Parameters:
  • energy (np.ndarray) – Energy points.

  • flx (np.ndarray) – Neutron flux from infFluxSolver

  • A (float) – Atomic mass number

  • intRule (str) – Either ‘trap’ or ‘simp’ for trapezoidal or Simpson’s rule for integration.

Returns:

tau – Transport correction ratio

Return type:

np.ndarray

transportcorrection._scatteringWeightGrabber(energy: ndarray, A: float, intRule: str)

Helper function - gets a matrix of weights for inscattering from groups E’ into group E.

Returns weight matrix for numerical integration.

This is used in infFluxSolver and analyticTRC

energynp.ndarray

Energy points.

Afloat

Atomic mass number

intRulestr

Either ‘trap’ or ‘simp’ for trapezoidal or Simpson’s rule for integration.

mtxW2d np.ndarray

Matrix for scattering weights based on value of A

transportcorrection._test_numerical_integration()

Helper function to test numerical integration using numericalWeights and compare as changes are made to the code.

Simpsons rule with even N should return EXACT values for the given polynomial.

transportcorrection.analyticTRC_INCLASS(energy, flx)

Calculates the transport correction factor using the trapezoid rule assuming that absorption is zero

Parameters:
  • energy (array) – energy mesh points.

  • flx (array) – assumed source as a function of energy.

  • A (float) – Atomic mass number for the colliding nuclide

Returns:

tau – transport correction coefficient

Return type:

array

transportcorrection.energyInterpolation(energy: ndarray, sigS: ndarray, sigT: ndarray, src: ndarray, energyN: int, lowerE: float, upperE: float, interpType: str = 'lin')

Create a fine energy structure for all the variables by interpolation

Parameters:
  • energy (np.ndarray) – energy mesh points.

  • sigS (np.ndarray) – scattering cross section as a function of energy.

  • sigT (np.ndarray) – total cross section as a function of energy.

  • flx (np.ndarray) – neutron flux as a function of energy.

  • energyN (int) – number of energy points.

  • lowerE (float) – lowest energy in eV

  • upperE (float) – highest energy in eV

  • interpType (str) – wanted interpolation type(options: ‘log’ and ‘lin’) default is ‘lin’

Returns:

  • energy1 (: np.ndarray) – fine energy mesh points.

  • sigS1 (: np.ndarray) – fine scattering cross section as a function of energy.

  • sigT1 (: np.ndarray) – fine total cross section as a function of energy.

  • flx1 (: np.ndarray) – fine assumed neutron flux as a function of energy.

transportcorrection.getNumericalWeights(x: ndarray, rule: str)

Takes in a vector x and returns numerical integration weights based on a given rule.

Weights are used for integrals - e.g. sum( W_row * f(x)) ~= int(f(x) dx)

This function only cares about the WEIGHTS.

So to integrate f(x) one would call this for the weights and then get f(x) from elsewhere.

Example:

test_x = np.linspace(-10,10,10) test_f = test_x**3 + 5.0*test_x**2 - 2.125*test_x**1 - 1.1521 # function f(x) trap_weights = numericalWeights(x=test_x, rule=’simp’)

integrated = np.sum(trap_weights * test_f)

print(integrated)

xarray

x points.

rulestr

Either ‘trap’ or ‘simp’ for Trapezoid Rule or ‘Composite Simpson’s rule for irregularly spaced data’

W_rowarray

Weights for integration as a 1D np.ndarray

transportcorrection.infFluxSolver(energy: ndarray, sigS: ndarray, sigT: ndarray, src: ndarray, A: float, intRule: str)

Solves for the infinite neutron flux.

Parameters:
  • energy (np.ndarray) – Energy points.

  • sigS (np.ndarray) – Scattering xs

  • sigT (np.ndarray) – Total xs

  • src (np.ndarray) – Neutron source.

  • A (float) – Atomic mass number

  • intRule (str) – Either ‘trap’ or ‘simp’ for trapezoidal or Simpson’s rule for integration.

Returns:

  • flx (np.ndarray) – Neutron flux

  • mtxW (np.ndarray) – 2D matrix showing the weights for solving

  • mtxK (np.ndarray) – 2D matrix showing the K values

  • mtxA (np.ndarray) – 2D matrix A

transportcorrection.plot_matrix(A: ndarray, black_white: bool)
Parameters:
  • A (array) – Matrix to plot/show

  • black_white (bool) – Whether to use black or white representation or plot using color.

transportcorrection.solveFluxAndTRC(dataPath: str, isotopeMass: float, energyN: int, lowerE: float, upperE: float, src: ndarray, rule: str, plotFluxMatrix: bool, plotTaus: bool)

Solves for the infinite flux and then solves for the transport correction factor for the given inputs.

Parameters:
  • dataPath (str) – Path to file containing xs csv (energy,total,scattering)

  • isotopeMass (float) – Mass (A) of isotope that scattering occurs in

  • energyN (int) – Number of energy points for energy grid.

  • lowerE (float) – Lower energy boundary

  • upperE (float) – Upper energy boundary

  • src (np.ndarray) – Neutron source (should be normalized to 1.0)

  • rule (str) – Either ‘trap’ or ‘simp’ for Trapezoid Rule or ‘Composite Simpson’s rule for irregularly spaced data’ This rule is used for numerical integration for flux and TRC.

  • plotFluxMatrix (bool) – Whether or not to show a plot of the matrix used for computing the flux. Used for validation purposes. Matrix that is plotted is matrix A.

  • plotTaus (bool) – Plots TCR as a function of energy after solving.

Returns:

  • energy1 (np.ndarray) – Energy vector used for plotting/solving TRC/flx

  • tau (np.ndarray) – Transport correction ratio

  • tau0 (np.ndarray) – Asymptotic value for TRC

  • flx (np.ndarray) – Infinite media neutron flux