API Reference
Complete API documentation for TimestepperTestCases.jl.
TimestepperTestCases.Diffusivity — Method
Diffusivity(case, t, var)Compute the effective numerical diffusivity from variance dissipation diagnostics.
Diffusivity(case, t, var)
Arguments
case: Case dictionary containing dissipation and gradient fieldst: Time indexvar: Variable symbol (e.g.,:bfor buoyancy)
Returns
KernelFunctionOperationrepresenting the numerical diffusivity field
The diffusivity is computed as κ = -0.5 * (Ax + Az) / Gz, where Ax and Az are the advective dissipation rates and Gz is the vertical gradient squared. This provides a local measure of numerical mixing, as described in the paper.
TimestepperTestCases.KineticEnergy — Method
KineticEnergy(case, i)Compute the volume-averaged kinetic energy at time index i.
KineticEnergy(case, i)
Arguments
case: Case dictionary containing velocity and volume fieldsi: Time index
Returns
- Volume-averaged kinetic energy [m²/s²]:
(u² + v² + w²) / V
Kinetic energy is computed using volume-weighted velocity components at their respective grid locations (u at Face-Center-Center, v at Center-Face-Center, w at Center-Center-Face).
TimestepperTestCases.MeanKineticEnergy — Method
MeanKineticEnergy(case, i)Compute the volume-averaged mean kinetic energy (zonally averaged) at time index i.
MeanKineticEnergy(case, i)
Arguments
case: Case dictionary containing velocity and volume fieldsi: Time index
Returns
- Volume-averaged mean kinetic energy [m²/s²]
Mean kinetic energy is computed from zonally averaged velocity components, representing the energy in the mean flow rather than eddy kinetic energy.
TimestepperTestCases.buoyancy_flux — Method
buoyancy_flux(i, j, grid, clock, model_fields, p)Compute the surface buoyancy flux forcing.
buoyancy_flux(i, j, grid, clock, model_fields, p)
Arguments
i, j: Grid indicesgrid: Grid objectclock: Simulation clockmodel_fields: Model fieldsp: Parameters named tuple containingQᵇ(flux magnitude),y_shutoff(shutoff location), andLy(domain length)
Returns
- Surface buoyancy flux [m²/s³] following a cosine profile, zero beyond
y_shutoff
The flux profile is Qᵇ * cos(3π * y / Ly) for y < y_shutoff, providing differential heating/cooling that drives meridional circulation.
TimestepperTestCases.buoyancy_relaxation — Method
buoyancy_relaxation(i, j, k, grid, clock, model_fields, p)Compute the buoyancy relaxation forcing in the sponge layer.
buoyancy_relaxation(i, j, k, grid, clock, model_fields, p)
Arguments
i, j, k: Grid indicesgrid: Grid objectclock: Simulation clockmodel_fields: Model fieldsp: Parameters named tuple containing relaxation parameters
Returns
- Buoyancy relaxation rate [m/s³] that restores buoyancy toward the initial profile in the sponge layer
This forcing relaxes buoyancy toward the initial exponential profile in the northern sponge region, with strength controlled by mask(y, p) / λt where λt is the relaxation timescale.
TimestepperTestCases.calculate_z★_diagnostics — Method
calculate_z★_diagnostics(b::Field, vol)Calculate the re-sorted height field z★ from buoyancy and volume fields.
calculate_z★_diagnostics(b, vol)
Arguments
b: Buoyancy fieldvol: Volume field
Returns
z★field representing the height each fluid parcel would occupy after adiabatic re-sorting
The re-sorted height is computed by sorting the buoyancy field and computing cumulative volume distribution, providing a reference state for potential energy calculations.
TimestepperTestCases.channel_simulation — Method
channel_simulation(; momentum_advection, tracer_advection, closure, zstar, restart_file, arch, bottom_height, timestepper, grid, initial_file, testcase)Set up and run the idealized re-entrant channel flow simulation.
channel_simulation(
;
momentum_advection,
tracer_advection,
closure,
zstar,
restart_file,
arch,
bottom_height,
timestepper,
grid,
initial_file,
testcase
)
Keyword Arguments
momentum_advection: Momentum advection scheme (default:WENOVectorInvariant())tracer_advection: Tracer advection scheme (default: 7th-order WENO)closure: Turbulence closure (default:CATKEVerticalDiffusivity)zstar: Whether to use z-star vertical coordinates (default:true)restart_file: Optional restart file path (default:nothing)arch: Architecture to run on (default:CPU())bottom_height: Optional bottom height function (default:nothingfor flat bottom)timestepper: Timestepper symbol (default::SplitRungeKutta)grid: Grid to use (default:default_grid(...))initial_file: Optional initial condition file (default:"tIni_80y_90L.bin")testcase: Test case identifier string (default:"0")
Returns
Simulationobject after running to completion
This function sets up the idealized re-entrant channel test case described in the paper. The configuration consists of a 1000 km × 2000 km × 3 km periodic channel forced by sinusoidal wind stress and variable surface heat flux. Buoyancy is restored at the northern boundary to maintain an equilibrated state.
The simulation includes a spin-up phase followed by a long integration (40 years) with time-averaged outputs. This test case demonstrates how numerical mixing interacts with explicit physical mixing in an equilibrated configuration, as shown in the paper.
TimestepperTestCases.compute_rpe_density — Method
compute_rpe_density(case::Dict)Compute reference potential energy (RPE) and available potential energy (APE) time series from a case dictionary.
compute_rpe_density(case)
Arguments
case: Dictionary containing:b(buoyancy FieldTimeSeries) and:VCCC(volume FieldTimeSeries)
Returns
- Named tuple with
rpeandapearrays containing volume-averaged RPE and APE at each time step
RPE represents the minimum potential energy achievable by adiabatic re-sorting of the density field, while APE is the difference between actual and reference potential energy. These diagnostics are used to quantify irreversible mixing, as described in the paper.
TimestepperTestCases.compute_rpe_density — Method
compute_rpe_density(b::Field, vol)Compute RPE and APE density fields from buoyancy and volume fields.
compute_rpe_density(b, vol)
Arguments
b: Buoyancy fieldvol: Volume field
Returns
- Named tuple with
ze(re-sorted height),εe(RPE density), andαe(APE density) fields
This function computes the re-sorted height z★ by sorting buoyancy and computing the cumulative volume distribution. RPE density is ρ * z★ and APE density is ρ * (z - z★), where ρ is computed from buoyancy using the linear equation of state.
TimestepperTestCases.compute_rpe_density_two — Method
compute_rpe_density_two(case::Dict)Compute RPE and APE time series using buoyancy directly (without volume weighting).
compute_rpe_density_two(case)
Arguments
case: Dictionary containing:b(buoyancy FieldTimeSeries) and:VCCC(volume FieldTimeSeries)
Returns
- Named tuple with
rpeandapearrays
This variant computes RPE/APE using the buoyancy field directly, suitable for cases where buoyancy is already volume-weighted or when using different volume conventions.
TimestepperTestCases.compute_tracer_dissipation! — Method
compute_tracer_dissipation!(sim)Compute the time rate of change of tracer variance (dissipation) for tracers b and c.
compute_tracer_dissipation!(sim)
Arguments
sim: TheSimulationobject containing the model with tracersbandc
Returns
nothing(modifiessim.model.auxiliary_fieldsin place)
This function computes the dissipation rate of tracer variance, defined as Δtc² = (c² - c⁻²) / Δt where c⁻ is the tracer value from the previous time step. The results are stored in sim.model.auxiliary_fields.Δtc² and sim.model.auxiliary_fields.Δtb².
This diagnostic is used to quantify numerical mixing introduced by the time discretization, as described in the paper's appendix.
TimestepperTestCases.default_closure — Method
default_closure()Return the default turbulence closure for the channel simulation.
default_closure()
Returns
CATKEVerticalDiffusivityclosure with default parameters
This closure uses the CATKE (Convective Adjustment and TKE) parameterization for vertical mixing, which is appropriate for equilibrated channel flows with mesoscale forcing.
TimestepperTestCases.default_grid — Method
default_grid(arch, zstar, bottom_height)Construct the default grid for the channel simulation.
default_grid(arch, zstar, bottom_height)
Arguments
arch: Architecture to use (CPU()orGPU())zstar: Whether to use z-star vertical coordinatesbottom_height: Optional bottom height function(x, y) -> z, ornothingfor flat bottom
Returns
RectilinearGridorImmersedBoundaryGridwith 200×400×90 grid points
The grid spans 1000 km zonally (periodic), 2000 km meridionally (bounded), and uses 90 non-uniform vertical layers with finer spacing near the surface and bottom.
TimestepperTestCases.hasclosure — Method
hasclosure(closure, ClosureType)Check if a closure or tuple of closures contains a specific closure type.
hasclosure(closure, ClosureType)
Arguments
closure: A single closure or tuple of closuresClosureType: The closure type to check for
Returns
trueifclosureis of typeClosureTypeor contains it in a tuple,falseotherwise
This helper function is used to determine if CATKE or other specific closures are present in the closure configuration.
TimestepperTestCases.idealized_coast — Method
idealized_coast(timestepper::Symbol; arch, forced, lowres, free_surface)Set up and run the idealized coastal baroclinic adjustment test case simulation.
idealized_coast(
timestepper;
arch,
forced,
lowres,
free_surface
)
Arguments
timestepper: Symbol indicating the timestepper (:QuasiAdamsBashforth2or:SplitRungeKutta3)
Keyword Arguments
arch: Architecture to run on (default:CPU())forced: Whether to apply wind forcing (default:true)lowres: Whether to use low resolution (default:false)free_surface: Free surface formulation (default:SplitExplicitFreeSurfacewith CFL=0.7)
Returns
Simulationobject configured but not yet run
This function sets up the idealized coastal baroclinic adjustment test case described in the paper. The configuration features a rectangular domain with a linearly sloping bathymetry and initial meridional salinity gradient that drives baroclinic instabilities. The test case demonstrates how numerical mixing can suppress submesoscale variability, as shown in the paper.
The simulation runs for 40 days and outputs velocity, temperature, salinity, buoyancy, and variance dissipation diagnostics.
TimestepperTestCases.idealized_coast_timestep — Method
idealized_coast_timestep(::Val{timestepper})Return the recommended time step for the idealized coast test case given a timestepper.
idealized_coast_timestep(_)
Arguments
timestepper: Symbol indicating the timestepper (:QuasiAdamsBashforth2or:SplitRungeKutta3)
Returns
- Recommended time step [s] for the given timestepper
Time steps are chosen to match computational cost between AB2 and RK schemes.
TimestepperTestCases.initial_buoyancy — Method
initial_buoyancy(z, p)Compute the initial buoyancy profile as a function of depth.
initial_buoyancy(z, p)
Arguments
z: Vertical position [m]p: Parameters named tuple containingΔB(surface buoyancy gradient),h(decay scale), andLz(domain depth)
Returns
- Initial buoyancy [m/s²] following an exponential profile
The profile follows ΔB * (exp(z/h) - exp(-Lz/h)) / (1 - exp(-Lz/h)), which provides a stable stratification that decays exponentially with depth.
TimestepperTestCases.internal_tide — Method
internal_tide(timestepper::Symbol; free_surface, tracer_advection)Set up and run the internal tide test case simulation.
internal_tide(timestepper; free_surface, tracer_advection)
Arguments
timestepper: Symbol indicating the timestepper (:QuasiAdamsBashforth2,:SplitRungeKutta3, or:SplitRungeKutta4)
Keyword Arguments
free_surface: Free surface formulation (default:SplitExplicitFreeSurfacewith 60 substeps)tracer_advection: Tracer advection scheme (default: 7th-order WENO)
Returns
Simulationobject after running to completion
This function sets up the internal tide test case described in the paper, which simulates tidal flow over a Gaussian seamount. The domain is initially stratified and forced by an oscillatory tidal forcing. The simulation runs for 40 days and outputs velocity, buoyancy, tracer fields, and dissipation diagnostics.
The test case isolates the role of time discretization in numerical mixing, as spatial advection plays a secondary role in this mostly linear configuration.
TimestepperTestCases.internal_tide_grid — Method
internal_tide_grid()Construct the grid for the internal tide test case with a Gaussian seamount.
internal_tide_grid()
Returns
ImmersedBoundaryGridwith periodic horizontal boundaries and a Gaussian seamount bottom
The grid spans from -L to L horizontally (periodic) and from -H to 0 vertically (bounded). A Gaussian seamount of height h₀ and width width is imposed using an immersed boundary method. The grid parameters are taken from internal_tide_parameters().
TimestepperTestCases.internal_tide_parameters — Method
internal_tide_parameters()Return a named tuple containing the default parameters for the internal tide test case.
internal_tide_parameters()
Returns
Nx: Number of grid points in the horizontal (x) directionNz: Number of grid points in the vertical (z) directionH: Domain depth [m]L: Domain half-length [m]h₀: Seamount height [m]width: Seamount width [m]T₂: Tidal period [s]ω₂: Tidal frequency [rad/s]ϵ: Excursion parameter (dimensionless)U₂: Characteristic tidal velocity [m/s]f: Coriolis parameter [s⁻¹]A₂: Tidal forcing amplitude [m/s²]Nᵢ²: Initial stratification [s⁻²]
These parameters define a 2-kilometer deep domain with a Gaussian seamount that interacts with an oscillatory tidal forcing, as described in the paper.
TimestepperTestCases.internal_tide_timestep — Method
internal_tide_timestep(::Val{timestepper})Return the recommended time step for the internal tide test case given a timestepper.
internal_tide_timestep(_)
Arguments
timestepper: Symbol indicating the timestepper (:QuasiAdamsBashforth2,:SplitRungeKutta3, or:SplitRungeKutta4)
Returns
- Recommended time step [s] for the given timestepper
The time steps are chosen to match computational cost between AB2 and RK schemes while maintaining stability, as described in the paper.
TimestepperTestCases.load_channel — Method
load_channel(folder, case_number; arch)Load and process channel simulation output data.
load_channel(folder, case_number; arch)
Arguments
folder: Directory containing the simulation output filescase_number: Case identifier stringarch: Architecture to load data on (default:CPU())
Returns
- Dictionary containing velocity, buoyancy, volume, and energy diagnostics
This function loads channel simulation snapshots and computes kinetic energy, mean kinetic energy, and potential energy diagnostics for equilibrated channel flow analysis.
TimestepperTestCases.load_idealized_coast — Method
load_idealized_coast(folder, closure, suffix, timestepper)Load and process idealized coast simulation output data.
load_idealized_coast(folder, closure, suffix, timestepper)
Arguments
folder: Directory containing the simulation output filesclosure: Closure name string (e.g.,"CATKE")suffix: Filename suffix string (e.g.,"split_free_surface_")timestepper: Timestepper name string (e.g.,"SplitRungeKutta3")
Returns
- Dictionary containing velocity, tracer, dissipation, and energy diagnostics
Similar to load_internal_tide, but includes additional fields for temperature and salinity dissipation diagnostics, as well as three-dimensional volume fields.
TimestepperTestCases.load_internal_tide — Method
load_internal_tide(folder, timestepper, free_surface)Load and process internal tide simulation output data.
load_internal_tide(folder, timestepper, free_surface)
Arguments
folder: Directory containing the simulation output filestimestepper: Timestepper name string (e.g.,"SplitRungeKutta3")free_surface: Free surface type string (e.g.,"split_free_surface_DFB")
Returns
- Dictionary containing:
:u,:w,:b,:η: Velocity, buoyancy, and free surface FieldTimeSeries:VCCC,:VFCC,:VCCF: Volume FieldTimeSeries at different grid locations:Abx,:Abz: Advective buoyancy dissipation in x and z directions:Gbx,:Gbz: Buoyancy gradient squared in x and z directions:abx,:abz,:abt: Volume-averaged dissipation rates:gbx,:gbz,:gbt: Volume-averaged gradient squared:κb: Effective numerical diffusivity:KE,:MKE: Kinetic energy and mean kinetic energy time series:η2: Free surface variance time series:RPE,:APE: Reference and available potential energy time series
This function loads simulation output, computes volume fields accounting for free surface variations, and calculates various diagnostics used for analyzing numerical mixing.
TimestepperTestCases.mask — Method
mask(y, p)Compute the sponge layer mask function for buoyancy relaxation.
mask(y, p)
Arguments
y: Meridional position [m]p: Parameters named tuple containingLy(domain length) andLsponge(sponge layer width)
Returns
- Mask value between 0 and 1, increasing linearly from 0 at
y = Ly - Lspongeto 1 aty = Ly
This function creates a sponge layer mask used for buoyancy restoring at the northern boundary.
TimestepperTestCases.print_progress — Method
print_progress(sim)Print simulation progress information including completion percentage, iteration number, simulation time, wall clock time, maximum velocity components, and next time step.
print_progress(sim)
Arguments
sim: TheSimulationobject to print progress for.
Returns
nothing
This callback function is typically added to simulations using add_callback! to monitor progress during long-running simulations.
TimestepperTestCases.simulation_Δt — Method
simulation_Δt(::Val{timestepper})Return the recommended time step for the channel simulation given a timestepper.
simulation_Δt(_)
Arguments
timestepper: Symbol indicating the timestepper (:QuasiAdamsBashforth2,:SplitRungeKutta3, or:SplitRungeKutta6)
Returns
- Recommended time step [s] for the given timestepper
Time steps are chosen to match computational cost between different timesteppers.
TimestepperTestCases.tidal_forcing — Method
tidal_forcing(x, z, t, p)Compute the tidal forcing amplitude at position (x, z) and time t.
tidal_forcing(x, z, t, p)
Arguments
x: Horizontal position [m]z: Vertical position [m]t: Time [s]p: Parameters named tuple containingA₂(forcing amplitude) andω₂(tidal frequency)
Returns
- Forcing amplitude [m/s²] as a function of time only:
A₂ * sin(ω₂ * t)
This function implements a simple oscillatory tidal forcing that varies sinusoidally in time with amplitude A₂ and frequency ω₂.
TimestepperTestCases.u_stress — Method
u_stress(i, j, grid, clock, model_fields, p)Compute the zonal wind stress at the surface.
u_stress(i, j, grid, clock, model_fields, p)
Arguments
i, j: Grid indicesgrid: Grid objectclock: Simulation clockmodel_fields: Model fieldsp: Parameters named tuple containingτ(stress magnitude) andLy(domain length)
Returns
- Zonal wind stress [m²/s²] following a sine profile:
-τ * sin(π * y / Ly)
This implements a sinusoidal wind stress profile that drives zonal flow, with maximum stress at the domain center and zero at the boundaries.
TimestepperTestCases.wind_stress — Method
wind_stress(i, j, grid, clock, fields, p)Compute the wind stress forcing at grid point (i, j).
wind_stress(i, j, grid, clock, fields, p)
Arguments
i, j: Grid indicesgrid: Grid objectclock: Simulation clockfields: Model fieldsp: Parameters named tuple containingτ₀(stress amplitude) andf(frequency)
Returns
- Wind stress [m²/s²] that activates after 4 days:
τ₀ * sin(f * t)ift > 4 days, else0
This function implements a time-dependent wind stress that begins after a 4-day spin-up period and oscillates with frequency f and amplitude τ₀.
TimestepperTestCases.BuoyancyVarianceDissipationComputations.BuoyancyVarianceDissipation — Method
(ϵ::BuoyancyVarianceDissipation)(model)Compute buoyancy variance dissipation and update flux caches for the next time step.
BuoyancyVarianceDissipation(grid; Uⁿ⁻¹, Uⁿ)
Arguments
model: TheHydrostaticFreeSurfaceModelcontaining temperature and salinity tracers
Returns
nothing(modifiesϵin place)
This function is called as a simulation callback to compute the advective dissipation of buoyancy variance at each time step. It first computes dissipation from previously cached fluxes, then updates the flux caches for the next time step.
The model must have :T and :S tracers to compute buoyancy.
TimestepperTestCases.BuoyancyVarianceDissipationComputations.c_grid_vector — Method
c_grid_vector(grid)Create a named tuple of C-grid vector fields (x, y, z components at face locations).
c_grid_vector(grid)
Arguments
grid: Grid on which to create the fields
Returns
- Named tuple with
x,y,zfields at XFace, YFace, and ZFace locations respectively
This helper function creates the vector fields needed to store advective fluxes and dissipation rates at their proper staggered grid locations.
TimestepperTestCases.BuoyancyVarianceDissipationComputations.cache_fluxes! — Method
cache_fluxes!(dissipation, model)Cache advective fluxes and update velocity fields for dissipation computation.
cache_fluxes!(dissipation, model)
Arguments
dissipation:BuoyancyVarianceDissipationobjectmodel: The model containing velocities and tracers
Returns
nothing(modifiesdissipationin place)
This function updates the velocity fields (Uⁿ, Uⁿ⁻¹) and caches the advective buoyancy fluxes (Fⁿ, Fⁿ⁻¹) needed for computing dissipation at the next time step. The caching procedure depends on the timestepper type and stage.
TimestepperTestCases.BuoyancyVarianceDissipationComputations.compute_dissipation! — Method
compute_dissipation!(dissipation, model)Compute the numerical dissipation of buoyancy variance from previously calculated advective fluxes.
compute_dissipation!(dissipation, model)
Arguments
dissipation:BuoyancyVarianceDissipationobject containing cached fluxesmodel: The model containing tracers and timestepper information
Returns
nothing(modifiesdissipation.advective_productionin place)
The dissipation is computed using the formulation:
A = 2 * δc★ * F - U δc² # For advective dissipationwhere F is the flux associated with advection, U is the advecting velocity, c★ and c² are functions of the buoyancy field.
For multi-stage timesteppers, the fluxes and velocities must account for the substepping procedure. For AB2: F = 1.5 Fⁿ - 0.5 Fⁿ⁻¹ and U = 1.5 Uⁿ - 0.5 Uⁿ⁻¹. For RK schemes, the fluxes from the appropriate substep are used.
This method is adapted from the exact variance budget methodology described in the paper's appendix.
TimestepperTestCases.BuoyancyVarianceDissipationComputations.finally_cache_fluxes! — Method
finally_cache_fluxes!(dissipation, model)Cache advective buoyancy fluxes from temperature and salinity tracers.
finally_cache_fluxes!(dissipation, model)
Arguments
dissipation:BuoyancyVarianceDissipationobjectmodel: The model containing tracers and advection scheme
Returns
nothing(modifiesdissipation.advective_fluxesin place)
This function computes the advective fluxes of buoyancy by combining temperature and salinity fluxes using the linear equation of state. The fluxes are computed at face locations and cached for use in dissipation computation.
TimestepperTestCases.BuoyancyVarianceDissipationComputations.flatten_dissipation_fields — Method
flatten_dissipation_fields(t::BuoyancyVarianceDissipation)Flatten the dissipation fields into a named tuple for output.
flatten_dissipation_fields(t)
Arguments
t:BuoyancyVarianceDissipationobject
Returns
- Named tuple containing
Abx,Aby,Abzfields representing advective buoyancy dissipation in the x, y, and z directions respectively
This function extracts the dissipation fields from the internal C-grid vector structure into a flat named tuple suitable for use as simulation outputs.
TimestepperTestCases.BuoyancyVarianceDissipationComputations.flux_parameters — Method
flux_parameters(grid)Compute kernel parameters for flux computation based on grid topology.
flux_parameters(grid)
Arguments
grid: Grid object
Returns
KernelParametersobject with appropriate index ranges for flux computation
This function determines the correct index ranges for computing fluxes at face locations, accounting for flat (1D/2D) dimensions in the grid topology.