Nucleide

Variance reduction

MAGIC weight windows and alias-table source sampling in Nucleide.

Nucleide provides two variance-reduction utilities built on MCNP mesh tallies: MAGIC weight-window generation and mesh-based source sampling with alias tables.

MAGIC weight windows

MAGIC converts a forward mesh tally into weight-window lower bounds. The algorithm is simple and deterministic:

For each energy group gg, find the maximum flux over all volume elements:

Φgmax=maxvΦv,g.\Phi_g^{\max} = \max_{v} \Phi_{v,g}.

Then the weight-window lower bound for volume element vv and group gg is

wwv,g={null_valueif εv,g>τ,Φv,g2Φgmaxotherwise,\text{ww}_{v,g} = \begin{cases} \text{null\_value} & \text{if } \varepsilon_{v,g} > \tau, \\[6pt] \dfrac{\Phi_{v,g}}{2\,\Phi_g^{\max}} & \text{otherwise}, \end{cases}

where εv,g\varepsilon_{v,g} is the relative error of the tally and τ\tau is the error tolerance. The factor of 22 normalizes the peak-flux voxel to a lower bound of 0.50.5; MAGIC is intended to be iterated so the weight windows refine over successive forward runs (Cooper & Larsen 2001)cooper-2001.

Where this lives in the code

MAGIC is implemented in crates/vr-tools/src/magic.rs. The public functions are magic() for energy-integrated totals and magic_with() for explicit array selection and parameters.

Total vs. per-group mode

AspectTotalPer-group
Source arrays`total_result`, `total_rel_error``result`, `rel_error`
Lower bounds per voxel11 per energy group
Output tag`ww_n` / `ww_p``ww_n` / `ww_p`
Energy bounds tag`n_e_upper_bounds` / `p_e_upper_bounds` (single upper bound)`n_e_upper_bounds` / `p_e_upper_bounds` (`e_bounds[1:]`)
Comparison of MAGIC operating modes.

Parameters

ParameterDefaultMeaning
tolerance τ0.5Relative error above which a bound is nulled.
null_value0.0Value assigned to nulled elements.
MAGIC tuning parameters and their defaults.

Worked example

Consider a tally with four volume elements and total fluxes Φ=[1.2,3.3,1.6,1.7]\Phi = [1.2,\, 3.3,\, 1.6,\, 1.7] and relative errors all below the default tolerance of 0.50.5.

  1. Find the group maximum: Φmax=3.3\Phi^{\max} = 3.3.

  2. Compute the scale factor: 1/(2×3.3)=1/6.61 / (2 \times 3.3) = 1 / 6.6.

  3. The lower bounds are ww=[1.2/6.6,3.3/6.6,1.6/6.6,1.7/6.6]=[0.182,0.5,0.242,0.258]\text{ww} = [1.2/6.6,\, 3.3/6.6,\, 1.6/6.6,\, 1.7/6.6] = [0.182,\, 0.5,\, 0.242,\, 0.258].

If the tolerance were tightened to 0.150.15, the element with error 0.190.19 would be nulled to null_value instead.

Loading chart…

Alias-table source sampling

The MeshSourceSampler uses a Walker/Vose alias table to draw particle birth voxels in O(1)O(1) time per sample after an O(n)O(n) construction step.

Alias-table construction

Given a discrete probability mass function pip_i over nn bins:

  1. Normalize so that ipi=1\sum_i p_i = 1.
  2. Scale each probability by nn, giving npˉin \bar{p}_i.
  3. Partition bins into “small” (npˉi<1n\bar{p}_i < 1) and “large” (npˉi1n\bar{p}_i \geq 1).
  4. Pair a small bin aa with a large bin gg:
    • Set prob[a]=npˉa\text{prob}[a] = n\bar{p}_a.
    • Set alias[a]=g\text{alias}[a] = g.
    • Reduce the large bin’s surplus: npˉgnpˉg+npˉa1n\bar{p}_g \leftarrow n\bar{p}_g + n\bar{p}_a - 1.
  5. Drain any remaining bins with prob=1\text{prob} = 1.

Sampling

To draw one index:

  1. Generate r1,r2[0,1)r_1, r_2 \in [0, 1).

  2. Pick column i=nr1i = \lfloor n \, r_1 \rfloor.

  3. Return ii if r2<prob[i]r_2 < \text{prob}[i]; otherwise return alias[i]\text{alias}[i].

Mesh source sampling modes

ModeSampling PDFBirth weight
Analog∝ flux × volume1.0
Uniform∝ volumeanalog_pdf / uniform_pdf
User∝ user_density × volumeanalog_pdf / user_pdf
MeshSourceSampler bias modes.
Voxel-level only

MeshSourceSampler selects a voxel uniformly within the chosen cell. Sub-voxel or fractional-cell sampling modes are not implemented.

Assumptions and limitations

  • MAGIC requires positive flux somewhere: if every value in an energy group is 0\leq 0, the normalization divides by zero and Error::ZeroMaxFlux is returned.
  • MAGIC rejects non-finite flux or error values: NaN or infinite entries in the input arrays produce Error::NonFiniteTally rather than poisoned lower bounds.
  • Mesh source sampling rejects negative values: negative total_result or user_pdf entries produce Error::NegativeTally; zero values remain valid zero-probability bins.
  • Error comparison is strict: a relative error exactly equal to the tolerance keeps its scaled value; only errors greater than τ\tau are nulled.
  • Alias tables are exact for the given PDF: the construction reproduces the input probabilities to machine precision.
  • Voxel resolution: birth coordinates are returned as integer voxel indices; users must sample a uniform point inside the voxel themselves if sub-voxel positions are needed.

Adjacent capabilities found in PyNE, OpenMC, and the literature that Nucleide does not implement:

  • MAGIC iteration: the published method iterates — each forward run refines the windows for the next — and derives upper bounds from a fixed ratio to the lower bounds; Nucleide performs a single lower-bound pass.
  • FW-CADIS and adjoint-based global variance reduction: hybrid deterministic/Monte Carlo methods that build weight windows from an adjoint importance solve; see Wagner et al. (2014)wagner-2014.
  • Built-in generators in OpenMC: WeightWindows and WeightWindowGenerator (MAGIC-like and FW-CADIS modes, updated on the fly during transport), including an internal random-ray adjoint solver.
  • Source biasing: OpenMC supports energy/space/angle biasing of independent sources; PyNE’s mesh sampler additionally supports sub-voxel sampling modes. Nucleide’s MeshSourceSampler is voxel-level and energy-integrated.