API Reference

Mesh Construction

AgentMach.StructuredMeshType
StructuredMesh(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.

source
AgentMach.cell_centersFunction
cell_centers(mesh)

Return the tuple of vectors containing the x- and y-direction cell center coordinates.

source

Boundary Conditions

AgentMach.PeriodicBoundaryConditionsType
PeriodicBoundaryConditions(; x = true, y = true)

Describe periodic boundary conditions along the coordinate axes. Periodicity can be toggled independently for the x- and y-directions.

source
AgentMach.is_periodicFunction
is_periodic(bc, axis)

Return true when the boundary condition is periodic along the requested axis (axis = 1 for x, axis = 2 for y).

source
AgentMach.periodic_axesFunction
periodic_axes(bc)

Return the tuple (periodic_x, periodic_y) indicating which axes are periodic for the supplied boundary condition object.

source

Linear Advection

AgentMach.LinearAdvectionType
LinearAdvection(velocity)

Define the linear advection equation with a constant advection velocity represented as a 2-tuple.

source
AgentMach.LinearAdvectionProblemType
LinearAdvectionProblem(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.

source
AgentMach.meshFunction
mesh(problem)

Return the mesh associated with the PDE problem problem.

source
mesh(problem)

Return the mesh associated with the PDE problem problem.

source
AgentMach.boundary_conditionsFunction
boundary_conditions(problem)

Return the boundary-condition specification attached to problem.

source
boundary_conditions(problem)

Return the boundary-condition specification attached to problem.

source
AgentMach.pdeFunction
pde(problem)

Return the equation-of-motion descriptor stored within problem.

source
pde(problem)

Return the equation-of-motion descriptor stored within problem.

source
AgentMach.sourceMethod
source(problem)

Return the volumetric source callback associated with problem, or nothing if no source is registered.

source
AgentMach.setup_linear_advection_problemFunction
setup_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.

source
AgentMach.LinearAdvectionStateType
LinearAdvectionState(solution, workspace)

Hold the cell-centered solution field alongside scratch buffers required by the RK2 integrator.

source

Compressible Euler

AgentMach.CompressibleEulerProblemType
CompressibleEulerProblem(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.

source
AgentMach.sourceMethod
source(problem)

Return the volumetric source callback attached to problem, or nothing when no source term is registered.

source
AgentMach.limiterMethod
limiter(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.

source
AgentMach.setup_compressible_euler_problemFunction
setup_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.

source
AgentMach.primitive_variablesFunction
primitive_variables(eq, ρ, ρu, ρv, E)

Convert conserved quantities into primitive variables (ρ, u, v, p) for a compressible Euler equation set.

source
AgentMach._primitive_variables_cpuFunction
primitive_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).

source

Limiters

AgentMach.AbstractLimiterType
AbstractLimiter

Abstract 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.

source
AgentMach.MinmodLimiterType
MinmodLimiter()

Classical minmod limiter that clamps slopes to the smallest magnitude when the left/right differences agree in sign and zero otherwise.

source
AgentMach.UnlimitedLimiterType
UnlimitedLimiter()

Simple MUSCL slope with no limiting; returns the centred average of the left and right differences. Useful for smooth manufactured solutions or convergence studies.

source
AgentMach.apply_limiterFunction
apply_limiter(limiter, ΔL, ΔR)

Apply limiter to the left/right MUSCL differences ΔL and ΔR, returning the limited slope.

source

Time Integration

AgentMach.RK2WorkspaceType
RK2Workspace(k1, k2, stage)

Workspace buffers used to evaluate explicit second-order Runge-Kutta (Heun) updates without allocating temporary arrays.

source
AgentMach.solutionFunction
solution(state)

Return the primary solution array stored in state.

source
solution(state)

Return the conserved-variable tensor stored in state.

source
AgentMach.workspaceFunction
workspace(state)

Access the Runge-Kutta scratch buffers bundled with state.

source
workspace(state)

Access the Runge-Kutta scratch buffers bundled with state.

source
AgentMach.compute_rhs!Function
compute_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.

source
AgentMach.rk2_step!Function
rk2_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.

source
AgentMach.stable_timestepFunction
stable_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.

source
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.

source
AgentMach.cfl_numberFunction
cfl_number(problem, dt)

Compute the nondimensional Courant-Friedrichs-Lewy number for the provided linear advection problem and timestep length dt.

source
cfl_number(problem, state, dt)

Compute the CFL number implied by timestep dt for the compressible Euler problem problem evaluated on the state state.

source

Cell Fields

AgentMach.CellFieldType
CellField(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.

source
AgentMach.allocate_cellfieldFunction
allocate_cellfield(array_type, T, dims, n)

Allocate a CellField with n components, each created via array_type{T}(undef, dims...).

source
AgentMach.allocate_likeFunction
allocate_like(field)

Allocate a new CellField whose components mirror the array types and shapes of field.

source
allocate_like(field, T)

Allocate a new CellField with components similar to those in field but whose entries have element type T.

source
AgentMach.map_components!Function
map_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.

source

Simulation Drivers

AgentMach.run_linear_advection!Function
run_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.

source
AgentMach.run_compressible_euler!Function
run_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.

source