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 :doc:`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 One-Dimensional Fixed Source ----------------------------- ``fixed_source_1d_reeds.py`` Reed'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.py`` Steady-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.py`` Same DT-source problem in spherical geometry (``geometry=2``) with a reflective boundary at the origin. ``fixed_source_1d_manufactured_01.py`` through ``fixed_source_1d_manufactured_05.py`` Method 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.ipynb`` Jupyter 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: :doc:`notebooks/fixed_source_1d_spatial_discretization`. One-Dimensional Criticality ---------------------------- ``critical_1d_uranium_slab.py`` Criticality (k-eigenvalue) calculation for a 1D uranium slab with a reflector using 87 energy groups. ``critical_1d_plutonium_slab.py`` Same calculation with 618-group plutonium cross sections, demonstrating a fine energy resolution k-eigenvalue problem. ``critical_1d_uranium_sphere.py`` Spherical criticality calculation (``geometry=2``, reflective at origin) with 87-group uranium cross sections. ``icsbep_suite.py`` Suite 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 with ``python examples/icsbep_suite.py path/to/library.h5``. One-Dimensional Time-Dependent -------------------------------- ``time_dependent_1d_reed.py`` Transient 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 in ``SourceData``. ``time_dependent_1d_uranium_slab.py`` Transient 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.py`` Transient 87-group uranium sphere in spherical geometry with the same DT source and decay. ``time_dependent_1d_integrators.ipynb`` Jupyter 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: :doc:`notebooks/time_dependent_1d_integrators`. One-Dimensional Hybrid ------------------------ ``hybrid_1d_reed.py`` Reed's problem solved with the collision-based hybrid method. Demonstrates the split into uncollided (fine angles) and collided (coarse angles) transport sweeps, and the ``HybridData`` indexing object constructed via ``hytools.indexing()``. ``hybrid_1d_uranium_slab.py`` 87-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 with ``hytools.coarsen_velocity()``. ``vhybrid_1d_reed.py`` Reed'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.ipynb`` Jupyter notebook comparing the collision-based hybrid method with standard S\ :sub:`N` 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: :doc:`notebooks/hybrid_1d_collided_angles`. Two-Dimensional Fixed Source ------------------------------ ``fixed_source_2d_manufactured_01.py`` through ``fixed_source_2d_manufactured_04.py`` MMS 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.ipynb`` Jupyter notebook comparing standard S\ :sub:`N` with artificial scattering (as-S\ :sub:`N`) for ray effect mitigation, using a small isotropic source in a pure absorber. Shows how to enable it with the ``sigma_as`` and ``beta_as`` fields of ``SolverData``, compares both against a fine-quadrature reference, and sweeps ``sigma_as`` to show the trade-off between removing ray effects and over-smoothing. Rendered version: :doc:`notebooks/fixed_source_2d_artificial_scattering`. Two-Dimensional Criticality ----------------------------- ``critical_2d_C5G7.py`` Seven-group C5G7 benchmark criticality calculation on a 2D square lattice. Cross sections are loaded from ``critical_2d_C5G7_xs.h5`` (generated by ``critical_2d_C5G7_xs.py``). Demonstrates ``k_criticality()`` from ``ants.critical2d``. Two-Dimensional Time-Dependent -------------------------------- ``time_dependent_2d_cylinder_01.py`` Transient 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.py`` Transient 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. Two-Dimensional Hybrid ------------------------ ``hybrid_2d_chevron_01.py`` Chevron-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.py`` Monoenergetic fissile cylinder transient solved with the hybrid method. Demonstrates the hybrid workflow for 2D problems with curved geometry. ``vhybrid_2d_chevron_01.py`` Chevron-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. Three-Dimensional Fixed Source -------------------------------- ``fixed_source_3d_kobayashi.py`` Kobayashi dog leg benchmark (Problem 3) with 50% scattering, built with ``ants.benchmarks.kobayashi``. Plots the S\ :sub:`8` 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 with ``sigma_as``. The same problem is an example in the `MC/DC `_ repository (``examples/kobayashi-dogleg``). Notes on Running Examples -------------------------- * Examples that reference ``weight_matrix_2d_chevron.npy`` require this file to exist in the working directory. The generation code is included as comments in ``time_dependent_2d_chevron_01.py``. * The C5G7 criticality example requires ``critical_2d_C5G7_xs.h5``, generated by running ``critical_2d_C5G7_xs.py`` first. * All examples produce output arrays named ``flux`` (or ``flux, keff`` for criticality). Commented-out ``np.save()`` calls at the end of each script can be uncommented to write results to disk. 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. .. toctree:: :maxdepth: 1 :glob: notebooks/*