Baroclinic adjustment

In this example, we simulate the evolution and equilibration of a baroclinically unstable front.

Install dependencies

First let's make sure we have all required packages installed.

using Pkg
pkg"add Oceananigans, CairoMakie"
using Oceananigans
using Oceananigans.Units

Grid

We use a three-dimensional channel that is periodic in the x direction:

Lx = 1000kilometers # east-west extent [m]
Ly = 1000kilometers # north-south extent [m]
Lz = 1kilometers    # depth [m]

grid = RectilinearGrid(size = (48, 48, 8),
                       x = (0, Lx),
                       y = (-Ly/2, Ly/2),
                       z = (-Lz, 0),
                       topology = (Periodic, Bounded, Bounded))
48×48×8 RectilinearGrid{Float64, Periodic, Bounded, Bounded} on CPU with 3×3×3 halo
├── Periodic x ∈ [0.0, 1.0e6)          regularly spaced with Δx=20833.3
├── Bounded  y ∈ [-500000.0, 500000.0] regularly spaced with Δy=20833.3
└── Bounded  z ∈ [-1000.0, 0.0]        regularly spaced with Δz=125.0

Model

We built a HydrostaticFreeSurfaceModel with an ImplicitFreeSurface solver. Regarding Coriolis, we use a beta-plane centered at 45° South.

model = HydrostaticFreeSurfaceModel(; grid,
                                    coriolis = BetaPlane(latitude = -45),
                                    buoyancy = BuoyancyTracer(),
                                    tracers = :b,
                                    momentum_advection = WENO(),
                                    tracer_advection = WENO())
HydrostaticFreeSurfaceModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
├── grid: 48×48×8 RectilinearGrid{Float64, Periodic, Bounded, Bounded} on CPU with 3×3×3 halo
├── timestepper: QuasiAdamsBashforth2TimeStepper
├── tracers: b
├── closure: Nothing
├── buoyancy: BuoyancyTracer with ĝ = NegativeZDirection()
├── free surface: ImplicitFreeSurface with gravitational acceleration 9.80665 m s⁻²
│   └── solver: FFTImplicitFreeSurfaceSolver
├── advection scheme: 
│   ├── momentum: WENO{3, Float64, Float32}(order=5)
│   └── b: WENO{3, Float64, Float32}(order=5)
├── vertical_coordinate: ZCoordinate
└── coriolis: BetaPlane{Float64}

We start our simulation from rest with a baroclinically unstable buoyancy distribution. We use ramp(y, Δy), defined below, to specify a front with width Δy and horizontal buoyancy gradient . We impose the front on top of a vertical buoyancy gradient and a bit of noise.

"""
    ramp(y, Δy)

Linear ramp from 0 to 1 between -Δy/2 and +Δy/2.

For example:
```
            y < -Δy/2 => ramp = 0
    -Δy/2 < y < -Δy/2 => ramp = y / Δy
            y >  Δy/2 => ramp = 1
```
"""
ramp(y, Δy) = min(max(0, y/Δy + 1/2), 1)

N² = 1e-5 # [s⁻²] buoyancy frequency / stratification
M² = 1e-7 # [s⁻²] horizontal buoyancy gradient

Δy = 100kilometers # width of the region of the front
Δb = Δy * M²       # buoyancy jump associated with the front
ϵb = 1e-2 * Δb     # noise amplitude

bᵢ(x, y, z) = N² * z + Δb * ramp(y, Δy) + ϵb * randn()

set!(model, b=bᵢ)

Let's visualize the initial buoyancy distribution.

using CairoMakie
set_theme!(Theme(fontsize = 20))

# Build coordinates with units of kilometers
x, y, z = 1e-3 .* nodes(grid, (Center(), Center(), Center()))

b = model.tracers.b

fig, ax, hm = heatmap(view(b, 1, :, :),
                      colormap = :deep,
                      axis = (xlabel = "y [km]",
                              ylabel = "z [km]",
                              title = "b(x=0, y, z, t=0)",
                              titlesize = 24))

Colorbar(fig[1, 2], hm, label = "[m s⁻²]")

fig

Simulation

Now let's build a Simulation.

simulation = Simulation(model, Δt=20minutes, stop_time=20days)
Simulation of HydrostaticFreeSurfaceModel{CPU, RectilinearGrid}(time = 0 seconds, iteration = 0)
├── Next time step: 20 minutes
├── run_wall_time: 0 seconds
├── run_wall_time / iteration: NaN days
├── stop_time: 20 days
├── stop_iteration: Inf
├── wall_time_limit: Inf
├── minimum_relative_step: 0.0
├── callbacks: OrderedDict with 4 entries:
│   ├── stop_time_exceeded => Callback of stop_time_exceeded on IterationInterval(1)
│   ├── stop_iteration_exceeded => Callback of stop_iteration_exceeded on IterationInterval(1)
│   ├── wall_time_limit_exceeded => Callback of wall_time_limit_exceeded on IterationInterval(1)
│   └── nan_checker => Callback of NaNChecker for u on IterationInterval(100)
└── output_writers: OrderedDict with no entries

We add a TimeStepWizard callback to adapt the simulation's time-step,

conjure_time_step_wizard!(simulation, IterationInterval(20), cfl=0.2, max_Δt=20minutes)

Also, we add a callback to print a message about how the simulation is going,

using Printf

wall_clock = Ref(time_ns())

function print_progress(sim)
    u, v, w = model.velocities
    progress = 100 * (time(sim) / sim.stop_time)
    elapsed = (time_ns() - wall_clock[]) / 1e9

    @printf("[%05.2f%%] i: %d, t: %s, wall time: %s, max(u): (%6.3e, %6.3e, %6.3e) m/s, next Δt: %s\n",
            progress, iteration(sim), prettytime(sim), prettytime(elapsed),
            maximum(abs, u), maximum(abs, v), maximum(abs, w), prettytime(sim.Δt))

    wall_clock[] = time_ns()

    return nothing
end

add_callback!(simulation, print_progress, IterationInterval(100))

Diagnostics/Output

Here, we save the buoyancy, $b$, at the edges of our domain as well as the zonal ($x$) average of buoyancy.

u, v, w = model.velocities
ζ = ∂x(v) - ∂y(u)
B = Average(b, dims=1)
U = Average(u, dims=1)
V = Average(v, dims=1)

filename = "baroclinic_adjustment"
save_fields_interval = 0.5day

slicers = (east = (grid.Nx, :, :),
           north = (:, grid.Ny, :),
           bottom = (:, :, 1),
           top = (:, :, grid.Nz))

for side in keys(slicers)
    indices = slicers[side]

    simulation.output_writers[side] = JLD2Writer(model, (; b, ζ);
                                                 filename = filename * "_$(side)_slice",
                                                 schedule = TimeInterval(save_fields_interval),
                                                 overwrite_existing = true,
                                                 indices)
end

simulation.output_writers[:zonal] = JLD2Writer(model, (; b=B, u=U, v=V);
                                               filename = filename * "_zonal_average",
                                               schedule = TimeInterval(save_fields_interval),
                                               overwrite_existing = true)
JLD2Writer scheduled on TimeInterval(12 hours):
├── filepath: baroclinic_adjustment_zonal_average.jld2
├── 3 outputs: (b, u, v)
├── array_type: Array{Float32}
├── including: [:grid, :coriolis, :buoyancy, :closure]
├── file_splitting: NoFileSplitting
└── file size: 32.6 KiB

Now we're ready to run.

@info "Running the simulation..."

run!(simulation)

@info "Simulation completed in " * prettytime(simulation.run_wall_time)
[ Info: Running the simulation...
[ Info: Initializing simulation...
[00.00%] i: 0, t: 0 seconds, wall time: 19.135 seconds, max(u): (0.000e+00, 0.000e+00, 0.000e+00) m/s, next Δt: 20 minutes
[ Info:     ... simulation initialization complete (10.084 seconds)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (2.736 seconds).
[06.94%] i: 100, t: 1.389 days, wall time: 7.757 seconds, max(u): (1.215e-01, 1.247e-01, 1.712e-03) m/s, next Δt: 20 minutes
[13.89%] i: 200, t: 2.778 days, wall time: 826.875 ms, max(u): (2.188e-01, 1.927e-01, 1.916e-03) m/s, next Δt: 20 minutes
[20.83%] i: 300, t: 4.167 days, wall time: 817.980 ms, max(u): (3.132e-01, 2.965e-01, 1.848e-03) m/s, next Δt: 20 minutes
[27.78%] i: 400, t: 5.556 days, wall time: 991.784 ms, max(u): (3.788e-01, 3.917e-01, 1.911e-03) m/s, next Δt: 20 minutes
[34.72%] i: 500, t: 6.944 days, wall time: 844.097 ms, max(u): (4.697e-01, 4.851e-01, 2.088e-03) m/s, next Δt: 20 minutes
[41.67%] i: 600, t: 8.333 days, wall time: 837.048 ms, max(u): (6.070e-01, 8.350e-01, 2.956e-03) m/s, next Δt: 20 minutes
[48.61%] i: 700, t: 9.722 days, wall time: 1.039 seconds, max(u): (1.015e+00, 1.108e+00, 3.700e-03) m/s, next Δt: 20 minutes
[55.56%] i: 800, t: 11.111 days, wall time: 854.896 ms, max(u): (1.293e+00, 1.151e+00, 4.397e-03) m/s, next Δt: 20 minutes
[62.50%] i: 900, t: 12.500 days, wall time: 842.287 ms, max(u): (1.369e+00, 1.189e+00, 3.838e-03) m/s, next Δt: 20 minutes
[69.44%] i: 1000, t: 13.889 days, wall time: 904.483 ms, max(u): (1.319e+00, 1.191e+00, 4.255e-03) m/s, next Δt: 20 minutes
[76.39%] i: 1100, t: 15.278 days, wall time: 918.614 ms, max(u): (1.430e+00, 1.304e+00, 4.415e-03) m/s, next Δt: 20 minutes
[83.33%] i: 1200, t: 16.667 days, wall time: 891.106 ms, max(u): (1.463e+00, 1.206e+00, 3.352e-03) m/s, next Δt: 20 minutes
[90.28%] i: 1300, t: 18.056 days, wall time: 909.478 ms, max(u): (1.410e+00, 1.188e+00, 2.872e-03) m/s, next Δt: 20 minutes
[97.22%] i: 1400, t: 19.444 days, wall time: 802.054 ms, max(u): (1.350e+00, 1.310e+00, 2.577e-03) m/s, next Δt: 20 minutes
[ Info: Simulation is stopping after running for 25.444 seconds.
[ Info: Simulation time 20 days equals or exceeds stop time 20 days.
[ Info: Simulation completed in 25.467 seconds

Visualization

All that's left is to make a pretty movie. Actually, we make two visualizations here. First, we illustrate how to make a 3D visualization with Makie's Axis3 and Makie.surface. Then we make a movie in 2D. We use CairoMakie in this example, but note that using GLMakie is more convenient on a system with OpenGL, as figures will be displayed on the screen.

using CairoMakie

Three-dimensional visualization

We load the saved buoyancy output on the top, north, and east surface as FieldTimeSerieses.

filename = "baroclinic_adjustment"

sides = keys(slicers)

slice_filenames = NamedTuple(side => filename * "_$(side)_slice.jld2" for side in sides)

b_timeserieses = (east   = FieldTimeSeries(slice_filenames.east, "b"),
                  north  = FieldTimeSeries(slice_filenames.north, "b"),
                  top    = FieldTimeSeries(slice_filenames.top, "b"))

B_timeseries = FieldTimeSeries(filename * "_zonal_average.jld2", "b")

times = B_timeseries.times
grid = B_timeseries.grid
48×48×8 RectilinearGrid{Float64, Periodic, Bounded, Bounded} on CPU with 3×3×3 halo
├── Periodic x ∈ [0.0, 1.0e6)          regularly spaced with Δx=20833.3
├── Bounded  y ∈ [-500000.0, 500000.0] regularly spaced with Δy=20833.3
└── Bounded  z ∈ [-1000.0, 0.0]        regularly spaced with Δz=125.0

We build the coordinates. We rescale horizontal coordinates to kilometers.

xb, yb, zb = nodes(b_timeserieses.east)

xb = xb ./ 1e3 # convert m -> km
yb = yb ./ 1e3 # convert m -> km

Nx, Ny, Nz = size(grid)

x_xz = repeat(x, 1, Nz)
y_xz_north = y[end] * ones(Nx, Nz)
z_xz = repeat(reshape(z, 1, Nz), Nx, 1)

x_yz_east = x[end] * ones(Ny, Nz)
y_yz = repeat(y, 1, Nz)
z_yz = repeat(reshape(z, 1, Nz), grid.Ny, 1)

x_xy = x
y_xy = y
z_xy_top = z[end] * ones(grid.Nx, grid.Ny)

Then we create a 3D axis. We use zonal_slice_displacement to control where the plot of the instantaneous zonal average flow is located.

fig = Figure(size = (1600, 800))

zonal_slice_displacement = 1.2

ax = Axis3(fig[2, 1],
           aspect=(1, 1, 1/5),
           xlabel = "x (km)",
           ylabel = "y (km)",
           zlabel = "z (m)",
           xlabeloffset = 100,
           ylabeloffset = 100,
           zlabeloffset = 100,
           limits = ((x[1], zonal_slice_displacement * x[end]), (y[1], y[end]), (z[1], z[end])),
           elevation = 0.45,
           azimuth = 6.8,
           xspinesvisible = false,
           zgridvisible = false,
           protrusions = 40,
           perspectiveness = 0.7)
Axis3 with 12 plots:
 ┣━ Poly{Tuple{GeometryBasics.Polygon{2, Float64}}}
 ┣━ Poly{Tuple{GeometryBasics.Polygon{2, Float64}}}
 ┣━ Poly{Tuple{GeometryBasics.Polygon{2, Float64}}}
 ┣━ LineSegments{Tuple{Base.ReinterpretArray{Point{3, Float64}, 1, Tuple{Point{3, Float64}, Point{3, Float64}}, Vector{Tuple{Point{3, Float64}, Point{3, Float64}}}, false}}}
 ┣━ LineSegments{Tuple{Base.ReinterpretArray{Point{3, Float64}, 1, Tuple{Point{3, Float64}, Point{3, Float64}}, Vector{Tuple{Point{3, Float64}, Point{3, Float64}}}, false}}}
 ┣━ LineSegments{Tuple{Vector{Point{3, Float64}}}}
 ┣━ LineSegments{Tuple{Base.ReinterpretArray{Point{3, Float64}, 1, Tuple{Point{3, Float64}, Point{3, Float64}}, Vector{Tuple{Point{3, Float64}, Point{3, Float64}}}, false}}}
 ┣━ LineSegments{Tuple{Base.ReinterpretArray{Point{3, Float64}, 1, Tuple{Point{3, Float64}, Point{3, Float64}}, Vector{Tuple{Point{3, Float64}, Point{3, Float64}}}, false}}}
 ┣━ LineSegments{Tuple{Vector{Point{3, Float64}}}}
 ┣━ LineSegments{Tuple{Base.ReinterpretArray{Point{3, Float64}, 1, Tuple{Point{3, Float64}, Point{3, Float64}}, Vector{Tuple{Point{3, Float64}, Point{3, Float64}}}, false}}}
 ┣━ LineSegments{Tuple{Base.ReinterpretArray{Point{3, Float64}, 1, Tuple{Point{3, Float64}, Point{3, Float64}}, Vector{Tuple{Point{3, Float64}, Point{3, Float64}}}, false}}}
 ┗━ LineSegments{Tuple{Vector{Point{3, Float64}}}}

We use data from the final savepoint for the 3D plot. Note that this plot can easily be animated by using Makie's Observable. To dive into Observables, check out Makie.jl's Documentation.

n = length(times)
41

Now let's make a 3D plot of the buoyancy and in front of it we'll use the zonally-averaged output to plot the instantaneous zonal-average of the buoyancy.

b_slices = (east   = interior(b_timeserieses.east[n], 1, :, :),
            north  = interior(b_timeserieses.north[n], :, 1, :),
            top    = interior(b_timeserieses.top[n], :, :, 1))

# Zonally-averaged buoyancy
B = interior(B_timeseries[n], 1, :, :)

clims = 1.1 .* extrema(b_timeserieses.top[n][:])

kwargs = (colorrange=clims, colormap=:deep, shading=NoShading)

surface!(ax, x_yz_east, y_yz, z_yz;  color = b_slices.east, kwargs...)
surface!(ax, x_xz, y_xz_north, z_xz; color = b_slices.north, kwargs...)
surface!(ax, x_xy, y_xy, z_xy_top;   color = b_slices.top, kwargs...)

sf = surface!(ax, zonal_slice_displacement .* x_yz_east, y_yz, z_yz; color = B, kwargs...)

contour!(ax, y, z, B; transformation = (:yz, zonal_slice_displacement * x[end]),
         levels = 15, linewidth = 2, color = :black)

Colorbar(fig[2, 2], sf, label = "m s⁻²", height = Relative(0.4), tellheight=false)

title = "Buoyancy at t = " * string(round(times[n] / day, digits=1)) * " days"
fig[1, 1:2] = Label(fig, title; fontsize = 24, tellwidth = false, padding = (0, 0, -120, 0))

rowgap!(fig.layout, 1, Relative(-0.2))
colgap!(fig.layout, 1, Relative(-0.1))

save("baroclinic_adjustment_3d.png", fig)

Two-dimensional movie

We make a 2D movie that shows buoyancy $b$ and vertical vorticity $ζ$ at the surface, as well as the zonally-averaged zonal and meridional velocities $U$ and $V$ in the $(y, z)$ plane. First we load the FieldTimeSeries and extract the additional coordinates we'll need for plotting

ζ_timeseries = FieldTimeSeries(slice_filenames.top, "ζ")
U_timeseries = FieldTimeSeries(filename * "_zonal_average.jld2", "u")
B_timeseries = FieldTimeSeries(filename * "_zonal_average.jld2", "b")
V_timeseries = FieldTimeSeries(filename * "_zonal_average.jld2", "v")

xζ, yζ, zζ = nodes(ζ_timeseries)
yv = ynodes(V_timeseries)

xζ = xζ ./ 1e3 # convert m -> km
yζ = yζ ./ 1e3 # convert m -> km
yv = yv ./ 1e3 # convert m -> km
-500.0:20.833333333333332:500.0

Next, we set up a plot with 4 panels. The top panels are large and square, while the bottom panels get a reduced aspect ratio through rowsize!.

fig = Figure(size=(1800, 1000))

axb = Axis(fig[1, 2], xlabel="x (km)", ylabel="y (km)", aspect=1)
axζ = Axis(fig[1, 3], xlabel="x (km)", ylabel="y (km)", aspect=1, yaxisposition=:right)

axu = Axis(fig[2, 2], xlabel="y (km)", ylabel="z (m)")
axv = Axis(fig[2, 3], xlabel="y (km)", ylabel="z (m)", yaxisposition=:right)

rowsize!(fig.layout, 2, Relative(0.3))

To prepare a plot for animation, we index the timeseries with an Observable,

n = Observable(1)

b_top = @lift interior(b_timeserieses.top[$n], :, :, 1)
ζ_top = @lift interior(ζ_timeseries[$n], :, :, 1)
U = @lift interior(U_timeseries[$n], 1, :, :)
V = @lift interior(V_timeseries[$n], 1, :, :)
B = @lift interior(B_timeseries[$n], 1, :, :)
Observable([-0.00935235433280468 -0.008096328936517239 -0.00685178441926837 -0.005629586987197399 -0.00436416594311595 -0.0031199692748486996 -0.0018887423211708665 -0.0006098277517594397; -0.009388642385601997 -0.008127131499350071 -0.006867558229714632 -0.005598770920187235 -0.004367569927126169 -0.0031195892952382565 -0.0018765948479995131 -0.0006119671743363142; -0.009379399940371513 -0.008121373131871223 -0.006855282001197338 -0.005596792791038752 -0.004361727740615606 -0.003127811476588249 -0.001875899382866919 -0.0006439030403271317; -0.009400802664458752 -0.008124219253659248 -0.00688088359311223 -0.005608111619949341 -0.004365066532045603 -0.0031386397313326597 -0.0018604060169309378 -0.0006326526636257768; -0.009359205141663551 -0.008121209219098091 -0.006880458910018206 -0.005610412918031216 -0.004364849999547005 -0.003101615235209465 -0.0018732682801783085 -0.0006369000184349716; -0.00937295239418745 -0.008115975186228752 -0.006864399649202824 -0.005654050037264824 -0.0043912529945373535 -0.0031323395669460297 -0.0018672478618100286 -0.0006105193169787526; -0.009355848655104637 -0.008110755123198032 -0.006880039814859629 -0.005646686535328627 -0.004373449832201004 -0.0031292035710066557 -0.001870003528892994 -0.0006309792515821755; -0.009389430284500122 -0.008135301992297173 -0.006865986157208681 -0.00561288557946682 -0.004384265746921301 -0.003096239874139428 -0.0018879093695431948 -0.0006291699246503413; -0.0094003239646554 -0.00812551286071539 -0.006871346849948168 -0.005638552829623222 -0.004349449183791876 -0.003129224991425872 -0.001855848473496735 -0.0006243569660000503; -0.009379038587212563 -0.008126188069581985 -0.006890400312840939 -0.005606832914054394 -0.004376087803393602 -0.0031471329275518656 -0.0018648785771802068 -0.000620026548858732; -0.009385980665683746 -0.008116962388157845 -0.0068130940198898315 -0.005634730216115713 -0.004381714388728142 -0.00310389488004148 -0.0018660080386325717 -0.0006193858571350574; -0.009375308640301228 -0.008111166767776012 -0.006905829533934593 -0.005637722089886665 -0.004363683983683586 -0.0031158733181655407 -0.0018903615418821573 -0.0006340323016047478; -0.009399753995239735 -0.008110207505524158 -0.006890381220728159 -0.005620080977678299 -0.004400686826556921 -0.0031577753834426403 -0.0018912297673523426 -0.0006468617939390242; -0.00936916097998619 -0.008120949380099773 -0.0068659232929348946 -0.005609151441603899 -0.00437361653894186 -0.0031108513940125704 -0.0018907921621575952 -0.0006288766744546592; -0.009371642023324966 -0.008086943067610264 -0.00687313312664628 -0.005645738914608955 -0.004364481661468744 -0.0031329840421676636 -0.0018533034017309546 -0.0006175596499815583; -0.009345130994915962 -0.008127325214445591 -0.006902346387505531 -0.005625956691801548 -0.004386511631309986 -0.003121843794360757 -0.001859116367995739 -0.0006227761623449624; -0.009397976100444794 -0.008128014393150806 -0.006850156467407942 -0.005632421933114529 -0.004387631546705961 -0.0031238440424203873 -0.001900868839584291 -0.0006032087840139866; -0.009372119791805744 -0.008115509524941444 -0.006858237087726593 -0.005634021013975143 -0.004351197276264429 -0.0031187934800982475 -0.001867287908680737 -0.0006416813121177256; -0.009362894110381603 -0.008148238994181156 -0.006884163245558739 -0.005623809061944485 -0.004371613264083862 -0.0031233844347298145 -0.001867389539256692 -0.0006003855378367007; -0.009363912977278233 -0.008130272850394249 -0.006883249152451754 -0.005609589628875256 -0.004376523196697235 -0.00311832781881094 -0.0018628654070198536 -0.0006386089371517301; -0.009372246451675892 -0.008140825666487217 -0.006873533129692078 -0.005618200171738863 -0.004379559773951769 -0.003133854828774929 -0.0018610130064189434 -0.0006436502444557846; -0.009383952245116234 -0.008093450218439102 -0.00687228562310338 -0.005620885174721479 -0.0043795364908874035 -0.0031239576637744904 -0.0018867431208491325 -0.0006284228875301778; -0.007504100911319256 -0.006226410623639822 -0.005016158800572157 -0.0037519093602895737 -0.0025074610020965338 -0.0012388909235596657 -7.118922553672746e-7 0.0012733598705381155; -0.005406467709690332 -0.004150354769080877 -0.0029241235461086035 -0.001690674340352416 -0.0004160540411248803 0.0008469533058814704 0.002091512316837907 0.003335139947012067; -0.0033550311345607042 -0.0020864519756287336 -0.0008342534420080483 0.0004319723811931908 0.0016425007488578558 0.002904584864154458 0.004163710400462151 0.005414723418653011; -0.0012372914934530854 -1.0276985449308995e-5 0.0012637956533581018 0.002516570733860135 0.003728387411683798 0.004997728858143091 0.0062493737787008286 0.007515279576182365; 0.0006468320498242974 0.0018602743512019515 0.0031369845382869244 0.0043764966540038586 0.005595996975898743 0.0068759918212890625 0.008134257048368454 0.009374640882015228; 0.0006150311091914773 0.001874776789918542 0.003130317199975252 0.004373783711344004 0.005647579673677683 0.006879577413201332 0.008116157725453377 0.009359242394566536; 0.000648965360596776 0.0018715143669396639 0.003132173325866461 0.004399712197482586 0.005643568933010101 0.00687633128836751 0.008101695217192173 0.009367265738546848; 0.0006153834983706474 0.0018653884762898088 0.0031434674747288227 0.004359231796115637 0.005623104982078075 0.00687182554975152 0.008108624257147312 0.009381198324263096; 0.0006006393232382834 0.0018851833883672953 0.00311642955057323 0.004392862785607576 0.005632265005260706 0.006873057223856449 0.008108249865472317 0.009361165575683117; 0.0006467349012382329 0.001873280038125813 0.0031151408329606056 0.004370914306491613 0.005617762915790081 0.0068914140574634075 0.00812752079218626 0.009387381374835968; 0.0006272525642998517 0.0018772640032693744 0.003134453669190407 0.004360394086688757 0.0056619360111653805 0.006863140966743231 0.008147139102220535 0.009385624900460243; 0.0006480194278992712 0.0018614833243191242 0.0031363433226943016 0.0043846056796610355 0.005608799867331982 0.006878772284835577 0.008105394430458546 0.009386800229549408; 0.0006076786085031927 0.0018647133838385344 0.0031406802590936422 0.004386923275887966 0.005630057770758867 0.006882664281874895 0.008133823983371258 0.009389007464051247; 0.0006144784274511039 0.0019208549056202173 0.003126951167359948 0.0043428982608020306 0.005637474823743105 0.006850233301520348 0.008114080876111984 0.009381328709423542; 0.0006120403413660824 0.0018945938209071755 0.003117319429293275 0.00437310803681612 0.005639129318296909 0.006895237136632204 0.008137790486216545 0.009371435269713402; 0.0006512756226584315 0.0018988926894962788 0.003121722489595413 0.004358088597655296 0.0056261178106069565 0.006885496433824301 0.008120552636682987 0.00935126468539238; 0.0006257438217289746 0.0018842356512323022 0.0031477001029998064 0.0043509164825081825 0.005642985459417105 0.00686571653932333 0.008140617050230503 0.009363597258925438; 0.0006138837779872119 0.0018701618537306786 0.003137059509754181 0.004399923142045736 0.005595667287707329 0.0068831657990813255 0.008122623898088932 0.009362929500639439; 0.0006291708559729159 0.001894318382255733 0.0031254240311682224 0.004387165419757366 0.005640639923512936 0.006873058620840311 0.008148237131536007 0.009356673806905746; 0.0006362809799611568 0.0018622683128342032 0.0031204684637486935 0.00438885111361742 0.005619713570922613 0.0068707033060491085 0.00814293697476387 0.009373029693961143; 0.0006620496860705316 0.0018720575608313084 0.0031222237739712 0.004380382131785154 0.005630156956613064 0.006871960591524839 0.00815062876790762 0.009367348626255989; 0.0005940542905591428 0.001863699872046709 0.0031272065825760365 0.00438134977594018 0.005633040796965361 0.00687457574531436 0.00813144352287054 0.009374825283885002; 0.0006460123113356531 0.0018683813977986574 0.0031177913770079613 0.004342841450124979 0.0056603942066431046 0.00686737522482872 0.008132281713187695 0.009384779259562492; 0.0006300848908722401 0.0018948278157040477 0.0031127806287258863 0.00437404029071331 0.005633164197206497 0.0068629649467766285 0.008129793219268322 0.009390251711010933; 0.0006120409816503525 0.0018462197622284293 0.003135248087346554 0.004396206699311733 0.005646924488246441 0.006872906815260649 0.008134091272950172 0.009393745101988316; 0.0006210306892171502 0.001883156830444932 0.0031276345252990723 0.00438050739467144 0.005638363305479288 0.006869527976959944 0.008111413568258286 0.009377525188028812])

and then build our plot:

hm = heatmap!(axb, xb, yb, b_top, colorrange=(0, Δb), colormap=:thermal)
Colorbar(fig[1, 1], hm, flipaxis=false, label="Surface b(x, y) (m s⁻²)")

hm = heatmap!(axζ, xζ, yζ, ζ_top, colorrange=(-5e-5, 5e-5), colormap=:balance)
Colorbar(fig[1, 4], hm, label="Surface ζ(x, y) (s⁻¹)")

hm = heatmap!(axu, yb, zb, U; colorrange=(-5e-1, 5e-1), colormap=:balance)
Colorbar(fig[2, 1], hm, flipaxis=false, label="Zonally-averaged U(y, z) (m s⁻¹)")
contour!(axu, yb, zb, B; levels=15, color=:black)

hm = heatmap!(axv, yv, zb, V; colorrange=(-1e-1, 1e-1), colormap=:balance)
Colorbar(fig[2, 4], hm, label="Zonally-averaged V(y, z) (m s⁻¹)")
contour!(axv, yb, zb, B; levels=15, color=:black)

Finally, we're ready to record the movie.

frames = 1:length(times)

record(fig, filename * ".mp4", frames, framerate=8) do i
    n[] = i
end


Julia version and environment information

This example was executed with the following version of Julia:

using InteractiveUtils: versioninfo
versioninfo()
Julia Version 1.12.2
Commit ca9b6662be4 (2025-11-20 16:25 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 128 × AMD EPYC 9374F 32-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, znver4)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 128 virtual cores)
Environment:
  LD_LIBRARY_PATH = 
  JULIA_PKG_SERVER_REGISTRY_PREFERENCE = eager
  JULIA_DEPOT_PATH = /var/lib/buildkite-agent/.julia-oceananigans
  JULIA_PROJECT = /var/lib/buildkite-agent/Oceananigans.jl-27802/docs/
  JULIA_VERSION = 1.12.2
  JULIA_LOAD_PATH = @:@v#.#:@stdlib
  JULIA_VERSION_ENZYME = 1.10.10
  JULIA_PYTHONCALL_EXE = /var/lib/buildkite-agent/Oceananigans.jl-27802/docs/.CondaPkg/.pixi/envs/default/bin/python
  JULIA_DEBUG = Literate

These were the top-level packages installed in the environment:

import Pkg
Pkg.status()
Status `~/Oceananigans.jl-27802/docs/Project.toml`
  [79e6a3ab] Adapt v4.4.0
  [052768ef] CUDA v5.9.5
  [13f3f980] CairoMakie v0.15.8
  [e30172f5] Documenter v1.16.1
  [daee34ce] DocumenterCitations v1.4.1
  [033835bb] JLD2 v0.6.3
  [98b081ad] Literate v2.21.0
  [da04e1cc] MPI v0.20.23
  [85f8d34a] NCDatasets v0.14.10
  [9e8cae18] Oceananigans v0.103.1 `~/Oceananigans.jl-27802`
  [f27b6e38] Polynomials v4.1.0
  [6038ab10] Rotations v1.7.1
  [d496a93d] SeawaterPolynomials v0.3.10
  [09ab397b] StructArrays v0.7.2
  [bdfc003b] TimesDates v0.3.3
  [2e0b0046] XESMF v0.1.6
  [b77e0a4c] InteractiveUtils v1.11.0
  [37e2e46d] LinearAlgebra v1.12.0
  [44cfe95a] Pkg v1.12.0

This page was generated using Literate.jl.