discrete1.main module
Utilities for building grids and basic problem parameters.
This module collects small helper functions used to build angular and energy quadratures, convert energy grids to velocities, construct time stepping grids, and build 1-D spatial material maps. The helpers are lightweight and intended for use by example scripts and tests.
Public helpers - angular_x - energy_grid - energy_velocity - gamma_time_steps - spatial1d
- discrete1.main.angular_x(angles, bc_x=[0, 0])[source]
Generate angular ordinates and normalized weights.
Uses Gauss-Legendre quadrature to compute angular ordinates (mu) and weights for the specified number of angles. If reflective boundary conditions are present (
bc_x), the ordering of ordinates and weights is adjusted so that the incoming directions correspond to the solver’s expected ordering.- Parameters:
angles (
int) – Number of angular ordinates (n).bc_x (
sequenceoftwo ints, optional) – Boundary condition indicators for left/right (default [0, 0]).
- Returns:
(angle_x, angle_w) where
angle_xis array of ordinates andangle_wis the corresponding normalized weights.- Return type:
tuple
- discrete1.main.energy_grid(grid, groups_fine, groups_coarse=None, optimize=True)[source]
Build energy grid edges and index mapping for coarse/fine grids.
The function loads predefined energy grids shipped with the package and returns the energy edges (MeV) and the array mapping problem group indices to locations within the fine grid. When
groups_coarseis provided the function also returns the coarse grid index mapping.- Parameters:
grid (
int) – Choice of stock grid (supported: 87, 361, 618).groups_fine (
int) – Number of fine groups in the problem.groups_coarse (
int, optional) – Number of coarse groups to compute an additional mapping.optimize (
bool, optional) – If True, attempt to load precomputed index mappings from packaged data; otherwise compute indices on-the-fly.
- Returns:
edges_g (
numpy.ndarray) – Energy bin edges in MeV (length grid + 1).edges_gidx_fine (
numpy.ndarray) – Integer indices mapping fine-group boundaries into the chosen energy grid.edges_gidx_coarse (
numpy.ndarray, optional) – (Only returned whengroups_coarseis not None.) Coarse group index mapping.
- discrete1.main.energy_velocity(groups, edges_g=None)[source]
Compute particle speeds (cm/s) at group centers from energy edges.
- Parameters:
groups (
int) – Number of energy groups. Used only ifedges_gis None.edges_g (
array_like, optional) – Energy group edges in MeV. If omitted, a unit vector is returned for convenience.
- Returns:
Speeds at group center energies in cm/s.
- Return type:
numpy.ndarray
- discrete1.main.gamma_time_steps(edges_t, gamma=0.5, half_step=True)[source]
Insert intermediate (gamma) time steps between existing edges.
This helper takes a time-edge array and returns a combined array that includes half-steps (or gamma-weighted sub-steps) between original edges. It’s used by time integrators that require sub-step evaluations (for example TR-BDF2).
- Parameters:
edges_t (
array_like) – Time edge array of length (n_steps + 1).gamma (
float, optional) – Fraction used to compute intermediate times (default 0.5).half_step (
bool, optional) – If True, the first intermediate step is set to the exact midpoint between the surrounding times.
- Returns:
Combined time array of length (n_steps * 2 + 1).
- Return type:
numpy.ndarray
- discrete1.main.spatial1d(layers, edges_x, labels=False, check=True)[source]
Create one-dimensional medium map.
- Parameters:
layers – list of lists where each layer is a new material. A layer is comprised of an index (int), material name (str), and the width (str) in the form [index, material, width]. The width is the starting and ending points of the material (in cm) separated by a dash. If there are multiple regions, a comma can separate them. I.E. layer = [0, “plutonium”, “0 - 2, 3 - 4”].
edges_x – Array of length I + 1 with the location of the cell edges
- Returns:
One-dimensional array of length I, identifying the locations of the materials