1.7. Examples#
The examples/ directory contains runnable scripts demonstrating the full range of
problem types and solver modules. Each example uses the DataTypes-based API
(MaterialData, SourceData, GeometryData, etc.) described in Standard Inputs.
All examples import from the ants package and the relevant solver module, for example:
import ants
from ants.datatypes import MaterialData, SourceData, GeometryData, SolverData
from ants.fixed1d import fixed_source
1.7.1. One-Dimensional Fixed Source#
fixed_source_1d_reeds.pyReed’s monoenergetic problem — a standard verification benchmark with four material regions (scatter, vacuum, absorber, source). Demonstrates steady-state fixed-source solution and scalar flux reconstruction from the angular output.
fixed_source_1d_uranium_slab.pySteady-state fixed-source problem in a 1D uranium slab with a deuterium-tritium (DT) boundary source. Uses 87 energy groups retrieved via
ants.materials().fixed_source_1d_uranium_sphere.pySame DT-source problem in spherical geometry (
geometry=2) with a reflective boundary at the origin.fixed_source_1d_manufactured_01.pythroughfixed_source_1d_manufactured_05.pyMethod of manufactured solutions (MMS) verification problems for the 1D fixed-source solver. Each problem applies a known analytic solution to generate consistent cross sections and sources, then checks that the numerical solution matches. Problems range from pure absorption to multi-material scattering with angle-dependent sources.
fixed_source_1d_spatial_discretization.ipynbJupyter notebook comparing step, diamond and step characteristic differencing (
GeometryData(space_disc=...)). Measures order of accuracy with a manufactured solution, then shows the positivity and accuracy trade-off on a coarse-mesh Reed’s problem, including the scattering reaction rate. Rendered version: Spatial Discretization: Step, Diamond and Step Characteristic.
1.7.2. One-Dimensional Criticality#
critical_1d_uranium_slab.pyCriticality (k-eigenvalue) calculation for a 1D uranium slab with a reflector using 87 energy groups.
critical_1d_plutonium_slab.pySame calculation with 618-group plutonium cross sections, demonstrating a fine energy resolution k-eigenvalue problem.
critical_1d_uranium_sphere.pySpherical criticality calculation (
geometry=2, reflective at origin) with 87-group uranium cross sections.icsbep_suite.pySuite of ICSBEP fast metal sphere benchmarks (Jezebel, Godiva, Flattop, …) built from an HDF5 library with
ants.run_suite(), varying the number of angles and spatial cells and comparing k-effective to the benchmark values. Run withpython examples/icsbep_suite.py path/to/library.h5.
1.7.3. One-Dimensional Time-Dependent#
time_dependent_1d_reed.pyTransient version of Reed’s monoenergetic benchmark using the backward Euler (BDF1) time integrator. Demonstrates how to wrap a steady-state source with
ants.external1d.time_dependence_constant()and pass an initial flux inSourceData.time_dependent_1d_uranium_slab.pyTransient 87-group uranium slab with a time-decaying DT boundary source. Uses
ants.boundary1d.time_dependence_decay_02()to construct the time-dependent boundary array.time_dependent_1d_uranium_sphere.pyTransient 87-group uranium sphere in spherical geometry with the same DT source and decay.
time_dependent_1d_integrators.ipynbJupyter notebook comparing the BDF1, Crank-Nicolson, BDF2 and TR-BDF2 time integrators. Covers the inputs each one expects, measures order of accuracy with a manufactured solution, and runs a stiff Reed’s problem transient with a large time step that shows Crank-Nicolson oscillating. Tracks the scattering reaction rate over time. Rendered version: Time Integrators: BDF1, Crank-Nicolson, BDF2 and TR-BDF2.
1.7.4. One-Dimensional Hybrid#
hybrid_1d_reed.pyReed’s problem solved with the collision-based hybrid method. Demonstrates the split into uncollided (fine angles) and collided (coarse angles) transport sweeps, and the
HybridDataindexing object constructed viahytools.indexing().hybrid_1d_uranium_slab.py87-group uranium slab transient using the hybrid method with 43 coarse energy groups. Shows how to coarsen cross sections with
hytools.coarsen_materials()and velocity withhytools.coarsen_velocity().vhybrid_1d_reed.pyReed’s problem solved with the vectorized hybrid method (
vhybrid1d). Unlike the standard hybrid, the coarse resolution is specified as per-step integer arrays (vgroups_c,vangles_c), enabling adaptive accuracy across time steps.hybrid_1d_collided_angles.ipynbJupyter notebook comparing the collision-based hybrid method with standard SN on a transient Reed’s problem. Shows that accuracy is set by the uncollided quadrature, sweeps the number of collided angles against cost and error, and plots the scattering reaction rate over time. Rendered version: The Collision-Based Hybrid Method.
1.7.5. Two-Dimensional Fixed Source#
fixed_source_2d_manufactured_01.pythroughfixed_source_2d_manufactured_04.pyMMS verification problems for the 2D fixed-source solver. Each script computes the numerical solution and plots a three-panel comparison of the numerical flux, the exact analytic flux, and the absolute error. Demonstrates use of
ants.boundary2d.manufactured_ss_*()functions to generate angle-dependent boundary conditions consistent with the chosen manufactured solution.fixed_source_2d_artificial_scattering.ipynbJupyter notebook comparing standard SN with artificial scattering (as-SN) for ray effect mitigation, using a small isotropic source in a pure absorber. Shows how to enable it with the
sigma_asandbeta_asfields ofSolverData, compares both against a fine-quadrature reference, and sweepssigma_asto show the trade-off between removing ray effects and over-smoothing. Rendered version: Artificial Scattering for Ray Effect Mitigation.
1.7.6. Two-Dimensional Criticality#
critical_2d_C5G7.pySeven-group C5G7 benchmark criticality calculation on a 2D square lattice. Cross sections are loaded from
critical_2d_C5G7_xs.h5(generated bycritical_2d_C5G7_xs.py). Demonstratesk_criticality()fromants.critical2d.
1.7.7. Two-Dimensional Time-Dependent#
time_dependent_2d_cylinder_01.pyTransient monoenergetic problem with a fissile cylinder embedded in a void. The curved cylinder boundary is represented on the Cartesian grid via a stochastic weight matrix computed with
ants.weight_matrix2d(). A boundary source at x = 0 decays in time.time_dependent_2d_chevron_01.pyTransient 87-group multigroup problem on a chevron geometry (triangular uranium fuel regions in an HDPE moderator). Uses the TR-BDF2 time integrator and a pre-computed weight matrix (
weight_matrix_2d_chevron.npy). A decaying DT boundary source enters from y = 0.
1.7.8. Two-Dimensional Hybrid#
hybrid_2d_chevron_01.pyChevron-geometry transient solved with the collision-based hybrid method: 87 uncollided groups and 43 collided groups, 8 uncollided angles and 4 collided angles. Uses TR-BDF2 time integration.
hybrid_2d_cylinder_01.pyMonoenergetic fissile cylinder transient solved with the hybrid method. Demonstrates the hybrid workflow for 2D problems with curved geometry.
vhybrid_2d_chevron_01.pyChevron-geometry transient solved with the vectorized hybrid method. Per-step coarse group and angle counts (
vgroups_c,vangles_c) allow the angular and energy resolution to vary adaptively across time steps.
1.7.9. Three-Dimensional Fixed Source#
fixed_source_3d_kobayashi.pyKobayashi dog leg benchmark (Problem 3) with 50% scattering, built with
ants.benchmarks.kobayashi. Plots the S8 flux against the Monte Carlo reference along the three lines of the benchmark, which shows the ray effects far down the duct. Artificial scattering can be turned on withsigma_as. The same problem is an example in the MC/DC repository (examples/kobayashi-dogleg).
1.7.10. Notes on Running Examples#
Examples that reference
weight_matrix_2d_chevron.npyrequire this file to exist in the working directory. The generation code is included as comments intime_dependent_2d_chevron_01.py.The C5G7 criticality example requires
critical_2d_C5G7_xs.h5, generated by runningcritical_2d_C5G7_xs.pyfirst.All examples produce output arrays named
flux(orflux, kefffor criticality). Commented-outnp.save()calls at the end of each script can be uncommented to write results to disk.
1.7.11. Example Notebooks#
Notebooks in examples/ are rendered here with their saved outputs. They are
not run during the documentation build, so rerun a notebook and save it after
changing it.