API Reference
Mesh Construction
AgentMach.StructuredMesh — TypeStructuredMesh(nx, ny; lengths=(1.0, 1.0), origin=(0.0, 0.0))Create a 2D structured mesh with nx by ny cells, spanning the box defined by origin and origin .+ lengths. Cell centers are positioned halfway across each cell.
AgentMach.cell_centers — Functioncell_centers(mesh)Return the tuple of vectors containing the x- and y-direction cell center coordinates.
AgentMach.spacing — Functionspacing(mesh)Return the cell spacing (dx, dy).
AgentMach.origin — Functionorigin(mesh)Return the mesh origin.
Boundary Conditions
AgentMach.PeriodicBoundaryConditions — TypePeriodicBoundaryConditions(; x = true, y = true)Describe periodic boundary conditions along the coordinate axes. Periodicity can be toggled independently for the x- and y-directions.
AgentMach.is_periodic — Functionis_periodic(bc, axis)Return true when the boundary condition is periodic along the requested axis (axis = 1 for x, axis = 2 for y).
AgentMach.periodic_axes — Functionperiodic_axes(bc)Return the tuple (periodic_x, periodic_y) indicating which axes are periodic for the supplied boundary condition object.
Linear Advection
AgentMach.LinearAdvection — TypeLinearAdvection(velocity)Define the linear advection equation with a constant advection velocity represented as a 2-tuple.
AgentMach.LinearAdvectionProblem — TypeLinearAdvectionProblem(mesh, bc, equation, [source])Bundle the mesh, boundary conditions, and PDE description for the linear advection equation. The optional source callback receives (du, u, problem, t) and may mutate du in-place to add volumetric forcing.
AgentMach.velocity — Functionvelocity(eq)Return the constant advection velocity associated with eq.
AgentMach.mesh — Functionmesh(problem)Return the mesh associated with the PDE problem problem.
mesh(problem)Return the mesh associated with the PDE problem problem.
AgentMach.boundary_conditions — Functionboundary_conditions(problem)Return the boundary-condition specification attached to problem.
boundary_conditions(problem)Return the boundary-condition specification attached to problem.
AgentMach.pde — Functionpde(problem)Return the equation-of-motion descriptor stored within problem.
pde(problem)Return the equation-of-motion descriptor stored within problem.
AgentMach.source — Methodsource(problem)Return the volumetric source callback associated with problem, or nothing if no source is registered.
AgentMach.setup_linear_advection_problem — Functionsetup_linear_advection_problem(nx, ny; lengths=(1.0, 1.0), origin=(0.0, 0.0),
velocity=(1.0, 0.0), source=nothing)Create a linear advection problem on a structured mesh with periodic boundary conditions along both axes. Supply source with a function of (du, u, problem, t) to append volumetric forcing contributions.
AgentMach.LinearAdvectionState — TypeLinearAdvectionState(solution, workspace)Hold the cell-centered solution field alongside scratch buffers required by the RK2 integrator.
Compressible Euler
AgentMach.CompressibleEuler — TypeCompressibleEuler(; gamma=1.4)Create a 2D compressible Euler equation set with ratio of specific heats gamma.
AgentMach.CompressibleEulerProblem — TypeCompressibleEulerProblem(mesh, bc, equation, [source], [limiter])Bundle the mesh, boundary conditions, and PDE description for the 2D compressible Euler equations. The optional source callback is invoked as source(du, u, problem, t) to accumulate volumetric forcing, while the limiter controls the MUSCL slope limiting strategy.
AgentMach.source — Methodsource(problem)Return the volumetric source callback attached to problem, or nothing when no source term is registered.
AgentMach.limiter — Methodlimiter(problem)Expose the AbstractLimiter used for MUSCL slope limiting. Override this via the limiter keyword when constructing a problem to switch from the default minmod_limiter to a different strategy.
AgentMach.setup_compressible_euler_problem — Functionsetup_compressible_euler_problem(nx, ny; lengths=(1.0, 1.0), origin=(0.0, 0.0),
gamma=1.4,
boundary_conditions=PeriodicBoundaryConditions(),
source=nothing)Create a compressible Euler problem on a structured mesh with configurable boundary conditions (defaults to fully periodic). Provide a source callback with signature (du, u, problem, t) to add volumetric forcing in-place, and optionally supply an AbstractLimiter to control MUSCL slope limiting.
AgentMach.CompressibleEulerState — TypeCompressibleEulerState(solution, workspace)Hold the conserved variables for the compressible Euler system along with RK2 scratch storage.
AgentMach.primitive_variables — Functionprimitive_variables(eq, ρ, ρu, ρv, E)Convert conserved quantities into primitive variables (ρ, u, v, p) for a compressible Euler equation set.
AgentMach._primitive_variables_cpu — Functionprimitive_variables(eq, conserved; rho_out=nothing, u_out=nothing,
v_out=nothing, p_out=nothing)Convert a conserved-field array with layout (4, nx, ny) to primitive variables. Optionally provide preallocated output arrays via the keyword arguments. Returns a named tuple (rho, u, v, p).
Limiters
AgentMach.AbstractLimiter — TypeAbstractLimiterAbstract supertype for MUSCL slope limiters. To implement a custom limiter, create a subtype and define apply_limiter(limiter, ΔL, ΔR) returning the limited slope given left and right one-sided differences.
AgentMach.MinmodLimiter — TypeMinmodLimiter()Classical minmod limiter that clamps slopes to the smallest magnitude when the left/right differences agree in sign and zero otherwise.
AgentMach.UnlimitedLimiter — TypeUnlimitedLimiter()Simple MUSCL slope with no limiting; returns the centred average of the left and right differences. Useful for smooth manufactured solutions or convergence studies.
AgentMach.minmod_limiter — Constantminmod_limiterSingleton instance of MinmodLimiter that can be reused across problems without allocating a new limiter.
AgentMach.unlimited_limiter — Constantunlimited_limiterSingleton instance of UnlimitedLimiter that disables slope limiting and yields the centred MUSCL slope average.
AgentMach.apply_limiter — Functionapply_limiter(limiter, ΔL, ΔR)Apply limiter to the left/right MUSCL differences ΔL and ΔR, returning the limited slope.
Time Integration
AgentMach.RK2Workspace — TypeRK2Workspace(k1, k2, stage)Workspace buffers used to evaluate explicit second-order Runge-Kutta (Heun) updates without allocating temporary arrays.
AgentMach.solution — Functionsolution(state)Return the primary solution array stored in state.
solution(state)Return the conserved-variable tensor stored in state.
AgentMach.workspace — Functionworkspace(state)Access the Runge-Kutta scratch buffers bundled with state.
workspace(state)Access the Runge-Kutta scratch buffers bundled with state.
AgentMach.compute_rhs! — Functioncompute_rhs!(du, u, problem [, t])Populate du with the spatial derivative of u for the PDE described by problem. Linear advection problems use a second-order upwind stencil, while compressible Euler problems employ slope-limited Rusanov fluxes. When a volumetric source callback is attached to the problem, it is invoked after the flux divergence has been accumulated. The optional argument t supplies the integration time associated with the evaluation.
AgentMach.rk2_step! — Functionrk2_step!(state, problem, dt; t=0)Advance the solution stored in state by a single explicit second-order Runge-Kutta step of size dt. The optional keyword t supplies the physical time associated with the stage and is forwarded to any registered source term.
AgentMach.stable_timestep — Functionstable_timestep(problem; cfl = 0.9)Return a timestep size that satisfies cfl_number(problem, dt) <= cfl for the explicit RK2 integrator. The default cfl = 0.9 provides a modest safety margin under the ideal limit of 1.0.
stable_timestep(problem, state; cfl=0.45)Return a CFL-limited timestep estimate for the compressible Euler problem using the current state and requested cfl target.
AgentMach.cfl_number — Functioncfl_number(problem, dt)Compute the nondimensional Courant-Friedrichs-Lewy number for the provided linear advection problem and timestep length dt.
cfl_number(problem, state, dt)Compute the CFL number implied by timestep dt for the compressible Euler problem problem evaluated on the state state.
Cell Fields
AgentMach.CellField — TypeCellField(components...)Bundle one or more cell-centered arrays that share a common (nx, ny) shape. Components are stored in a structure-of-arrays layout, which keeps per-variable data contiguous for GPU and cache-friendly execution. CellField behaves like a 3D AbstractArray whose first dimension indexes the component.
AgentMach.allocate_cellfield — Functionallocate_cellfield(array_type, T, dims, n)Allocate a CellField with n components, each created via array_type{T}(undef, dims...).
AgentMach.allocate_like — Functionallocate_like(field)Allocate a new CellField whose components mirror the array types and shapes of field.
allocate_like(field, T)Allocate a new CellField with components similar to those in field but whose entries have element type T.
AgentMach.map_components! — Functionmap_components!(f, dest, inputs...)Apply f to each component array in dest, passing the corresponding components drawn from each inputs... collection. All inputs must either be CellFields with matching component counts or scalar arrays reused for every component.
AgentMach.cell_components — Functioncell_components(field)Return the tuple of component arrays stored within field.
AgentMach.component — Functioncomponent(field, i)Access the i-th component array stored inside field.
AgentMach.ncomponents — Functionncomponents(field)Return the number of component arrays bundled inside field.
AgentMach.spatial_size — Functionspatial_size(field)Return the (nx, ny) logical dimensions shared by all components.
AgentMach.backend — Functionbackend(state)Return the execution backend associated with state.
Simulation Drivers
AgentMach.run_linear_advection! — Functionrun_linear_advection!(state, problem; steps, dt=nothing, cfl_target=0.9,
log_every=0, callback=nothing, record_cfl=false,
show_timers=true)Advance a LinearAdvectionState for a fixed number of RK2 steps. Either provide dt explicitly or supply a cfl_target, which is passed to stable_timestep to infer a step size. Optional logging and callback hooks support simple drivers. Set show_timers = false to suppress the aggregated TimerOutputs summary.
The function returns a named tuple summarising integration details.
AgentMach.run_compressible_euler! — Functionrun_compressible_euler!(state, problem; steps, dt=nothing, cfl_target=0.45,
log_every=0, callback=nothing, record_cfl=false,
adapt_dt=true, show_timers=true)Advance a CompressibleEulerState for a fixed number of RK2 steps. If dt is omitted, a stable timestep is recomputed from the current state each iteration using the requested cfl_target. Set show_timers = false to suppress the aggregated TimerOutputs summary.