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 , find the maximum flux over all volume elements:
Then the weight-window lower bound for volume element and group is
where is the relative error of the tally and is the error tolerance. The factor of normalizes the peak-flux voxel to a lower bound of ; MAGIC is intended to be iterated so the weight windows refine over successive forward runs (Cooper & Larsen 2001)cooper-2001.
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
| Aspect | Total | Per-group |
|---|---|---|
| Source arrays | `total_result`, `total_rel_error` | `result`, `rel_error` |
| Lower bounds per voxel | 1 | 1 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:]`) |
Parameters
| Parameter | Default | Meaning |
|---|---|---|
| tolerance τ | 0.5 | Relative error above which a bound is nulled. |
| null_value | 0.0 | Value assigned to nulled elements. |
Worked example
Consider a tally with four volume elements and total fluxes and relative errors all below the default tolerance of .
Find the group maximum: .
Compute the scale factor: .
The lower bounds are .
If the tolerance were tightened to , the element with error would
be nulled to null_value instead.
Alias-table source sampling
The MeshSourceSampler uses a Walker/Vose alias table to draw particle
birth voxels in time per sample after an construction step.
Alias-table construction
Given a discrete probability mass function over bins:
- Normalize so that .
- Scale each probability by , giving .
- Partition bins into “small” () and “large” ().
- Pair a small bin with a large bin :
- Set .
- Set .
- Reduce the large bin’s surplus: .
- Drain any remaining bins with .
Sampling
To draw one index:
Generate .
Pick column .
Return if ; otherwise return .
Mesh source sampling modes
| Mode | Sampling PDF | Birth weight |
|---|---|---|
| Analog | ∝ flux × volume | 1.0 |
| Uniform | ∝ volume | analog_pdf / uniform_pdf |
| User | ∝ user_density × volume | analog_pdf / user_pdf |
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 , the normalization divides by zero and
Error::ZeroMaxFluxis returned. - MAGIC rejects non-finite flux or error values:
NaNor infinite entries in the input arrays produceError::NonFiniteTallyrather than poisoned lower bounds. - Mesh source sampling rejects negative values: negative
total_resultoruser_pdfentries produceError::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 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.
Related work beyond Nucleide
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:
WeightWindowsandWeightWindowGenerator(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
MeshSourceSampleris voxel-level and energy-integrated.