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: 0 bytes (file not yet created)

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: 8.846 seconds, max(u): (0.000e+00, 0.000e+00, 0.000e+00) m/s, next Δt: 20 minutes
[ Info:     ... simulation initialization complete (11.845 seconds)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (3.741 seconds).
[06.94%] i: 100, t: 1.389 days, wall time: 14.114 seconds, max(u): (1.204e-01, 1.179e-01, 1.644e-03) m/s, next Δt: 20 minutes
[13.89%] i: 200, t: 2.778 days, wall time: 814.045 ms, max(u): (2.083e-01, 1.844e-01, 1.952e-03) m/s, next Δt: 20 minutes
[20.83%] i: 300, t: 4.167 days, wall time: 1.051 seconds, max(u): (2.719e-01, 2.481e-01, 1.822e-03) m/s, next Δt: 20 minutes
[27.78%] i: 400, t: 5.556 days, wall time: 804.493 ms, max(u): (3.449e-01, 3.300e-01, 1.896e-03) m/s, next Δt: 20 minutes
[34.72%] i: 500, t: 6.944 days, wall time: 796.151 ms, max(u): (4.358e-01, 4.602e-01, 2.174e-03) m/s, next Δt: 20 minutes
[41.67%] i: 600, t: 8.333 days, wall time: 805.710 ms, max(u): (5.448e-01, 6.796e-01, 2.785e-03) m/s, next Δt: 20 minutes
[48.61%] i: 700, t: 9.722 days, wall time: 2.480 seconds, max(u): (7.621e-01, 1.066e+00, 3.918e-03) m/s, next Δt: 20 minutes
[55.56%] i: 800, t: 11.111 days, wall time: 1.378 seconds, max(u): (1.227e+00, 1.172e+00, 4.593e-03) m/s, next Δt: 20 minutes
[62.50%] i: 900, t: 12.500 days, wall time: 770.327 ms, max(u): (1.374e+00, 1.149e+00, 4.735e-03) m/s, next Δt: 20 minutes
[69.44%] i: 1000, t: 13.889 days, wall time: 780.588 ms, max(u): (1.372e+00, 1.105e+00, 4.152e-03) m/s, next Δt: 20 minutes
[76.39%] i: 1100, t: 15.278 days, wall time: 786.226 ms, max(u): (1.376e+00, 9.938e-01, 3.142e-03) m/s, next Δt: 20 minutes
[83.33%] i: 1200, t: 16.667 days, wall time: 800.488 ms, max(u): (1.272e+00, 9.718e-01, 2.741e-03) m/s, next Δt: 20 minutes
[90.28%] i: 1300, t: 18.056 days, wall time: 805.345 ms, max(u): (1.309e+00, 1.020e+00, 3.837e-03) m/s, next Δt: 20 minutes
[97.22%] i: 1400, t: 19.444 days, wall time: 783.121 ms, max(u): (1.299e+00, 1.191e+00, 3.211e-03) m/s, next Δt: 20 minutes
[ Info: Simulation is stopping after running for 29.559 seconds.
[ Info: Simulation time 20 days equals or exceeds stop time 20 days.
[ Info: Simulation completed in 29.578 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.009364916011691093 -0.008097426034510136 -0.006887848488986492 -0.0056357854045927525 -0.004370504524558783 -0.0031002704054117203 -0.0018449976341798902 -0.0006384592270478606; -0.009387497790157795 -0.008118280209600925 -0.006882953457534313 -0.005625077523291111 -0.004370126407593489 -0.003138671163469553 -0.0018981907051056623 -0.0006060113664716482; -0.00937520619481802 -0.008144755847752094 -0.006852341815829277 -0.005634730216115713 -0.0043571945279836655 -0.0031030180398374796 -0.0018605521181598306 -0.0006293315091170371; -0.009358862414956093 -0.008130528032779694 -0.006895275320857763 -0.005627891514450312 -0.004384305793792009 -0.003117814427241683 -0.0018802746199071407 -0.0006227371632121503; -0.009386429563164711 -0.008104303851723671 -0.006868068594485521 -0.005605159793049097 -0.004373450297862291 -0.003122831229120493 -0.0018660909263417125 -0.0006289511220529675; -0.009376517497003078 -0.00813429243862629 -0.006882564164698124 -0.0056421710178256035 -0.0043906569480896 -0.0031342681031674147 -0.0018969913944602013 -0.00064858328551054; -0.009393026120960712 -0.008114015683531761 -0.006866376847028732 -0.00560351787135005 -0.004374413751065731 -0.003131505800411105 -0.0019079738995060325 -0.0006116392323747277; -0.009371019899845123 -0.008119513280689716 -0.006875650491565466 -0.005624133162200451 -0.004385027568787336 -0.0030999404843896627 -0.0018944957992061973 -0.0006352149648591876; -0.00936941895633936 -0.008148612454533577 -0.006867134012281895 -0.005628005135804415 -0.004369194153696299 -0.003117560874670744 -0.0019037813181057572 -0.0006344995927065611; -0.009392231702804565 -0.008126060478389263 -0.006879194639623165 -0.005622934550046921 -0.004383513238281012 -0.00312754581682384 -0.001896839588880539 -0.0006252999301068485; -0.009373635053634644 -0.008117533288896084 -0.006870917975902557 -0.005649599712342024 -0.004384596366435289 -0.0031442472245544195 -0.0018494337564334273 -0.0006268814322538674; -0.009391684085130692 -0.008135225623846054 -0.006870294455438852 -0.005634167697280645 -0.004382964223623276 -0.003125986782833934 -0.0018843833822757006 -0.0006331207696348429; -0.009374700486660004 -0.008100499399006367 -0.006845713127404451 -0.005620642565190792 -0.004383380990475416 -0.0031528302934020758 -0.0018632248975336552 -0.0006205267854966223; -0.009382117539644241 -0.00808799546211958 -0.006867039483040571 -0.005640774965286255 -0.004381455946713686 -0.003090039361268282 -0.0018506976775825024 -0.0006390613853000104; -0.009371278807520866 -0.008148455992341042 -0.0068915607407689095 -0.005614763591438532 -0.004362370353192091 -0.0031135682947933674 -0.0018749050796031952 -0.0006307692965492606; -0.009388146921992302 -0.008112812414765358 -0.006869591306895018 -0.005624055862426758 -0.004358249716460705 -0.0031360487919300795 -0.0018839517142623663 -0.0006305251736193895; -0.009373340755701065 -0.008119439706206322 -0.0068946960382163525 -0.005642698612064123 -0.004368861671537161 -0.003131962614133954 -0.0018864031881093979 -0.0006024686153978109; -0.00936000794172287 -0.008124065585434437 -0.0068657067604362965 -0.005645712837576866 -0.004400528036057949 -0.003117126179859042 -0.0018501017475500703 -0.0006255489424802363; -0.009351812303066254 -0.008129787631332874 -0.006868994329124689 -0.005642575211822987 -0.004349255934357643 -0.0031009300146251917 -0.0018578021554276347 -0.000654077623039484; -0.009377707727253437 -0.008131694979965687 -0.006886134389787912 -0.005633351858705282 -0.0043813856318593025 -0.0031185555271804333 -0.001870828797109425 -0.00063086993759498; -0.009384958073496819 -0.008122707717120647 -0.006851399317383766 -0.005610175896435976 -0.00437328452244401 -0.0031334569212049246 -0.0018644965020939708 -0.000637889199424535; -0.009395236149430275 -0.008136625401675701 -0.006872227881103754 -0.005635168869048357 -0.004389983601868153 -0.003132577519863844 -0.0018630173290148377 -0.0006072354153729975; -0.007499626372009516 -0.006262576673179865 -0.004976546857506037 -0.0037309513427317142 -0.0024642932694405317 -0.0012359400279819965 -3.7402046473289374e-6 0.00124113739002496; -0.005422955844551325 -0.004170265980064869 -0.0029211160726845264 -0.001663804636336863 -0.00041790830437093973 0.000815175415482372 0.0020931954495608807 0.0033240800257772207; -0.0033249882981181145 -0.0020774654112756252 -0.0008333656587637961 0.00038159199175424874 0.0016941300127655268 0.002903819316998124 0.004174340516328812 0.005410616286098957; -0.0012491615489125252 1.1753977560147177e-6 0.0012422879226505756 0.002500489354133606 0.003747043199837208 0.005019805394113064 0.006254174746572971 0.007518714293837547; 0.0006303584668785334 0.0018635684391483665 0.003113063983619213 0.00436859717592597 0.005642090458422899 0.006857977714389563 0.008168495260179043 0.009354595094919205; 0.0006420153076760471 0.0018925175536423922 0.0031071517150849104 0.004385922569781542 0.00563059002161026 0.006897789891809225 0.008101788349449635 0.009369609877467155; 0.000600117607973516 0.0018736369675025344 0.003103130729869008 0.00437126774340868 0.005632766056805849 0.006880840752273798 0.008142085745930672 0.00936049036681652; 0.0006314940401352942 0.0018743154359981418 0.0031007779762148857 0.004375859163701534 0.0055875214748084545 0.0068438430316746235 0.008110035210847855 0.009370469488203526; 0.0006161072524264455 0.0018887151964008808 0.00309864548034966 0.004372203256934881 0.005623271688818932 0.006873759441077709 0.008110619150102139 0.009381821379065514; 0.0006344763096421957 0.0018558602314442396 0.0031179438810795546 0.004384404048323631 0.005665376782417297 0.006912711542099714 0.008114177733659744 0.009393777698278427; 0.0005969516350887716 0.0018768049776554108 0.003110454883426428 0.004373917356133461 0.0056176502257585526 0.006882145069539547 0.008106682449579239 0.009375549852848053; 0.0006402219878509641 0.0018900883151218295 0.003142026485875249 0.004349799361079931 0.005612033419311047 0.006860463880002499 0.008132388815283775 0.009416908957064152; 0.0006177527830004692 0.0018505712505429983 0.0031276647932827473 0.004367219749838114 0.0056258379481732845 0.0068888673558831215 0.008124937303364277 0.009372706525027752; 0.000639615987893194 0.0018540403107181191 0.003142409725114703 0.004380423109978437 0.005614049732685089 0.0068525453098118305 0.008114960975944996 0.009374561719596386; 0.0006420131539925933 0.001891373423859477 0.0031075940933078527 0.004379482474178076 0.005632931366562843 0.006883978843688965 0.00811807531863451 0.009363194927573204; 0.0006238312926143408 0.001863562036305666 0.0031382667366415262 0.004406108986586332 0.0055872052907943726 0.006867649499326944 0.008111824281513691 0.009403403848409653; 0.0006290911114774644 0.0018700590590015054 0.003143459092825651 0.004358467645943165 0.005632313899695873 0.00688311317935586 0.008138357661664486 0.009360580705106258; 0.0005955054075457156 0.0018629352562129498 0.003133603371679783 0.0043820892460644245 0.005631016567349434 0.006890643388032913 0.008134854026138783 0.009375713765621185; 0.0006205157260410488 0.0018695445032790303 0.003098334651440382 0.004409146495163441 0.005621637217700481 0.00687711825594306 0.008137219585478306 0.009400784969329834; 0.0006213480373844504 0.0018789208261296153 0.0031361468136310577 0.004358984064310789 0.005633958615362644 0.0068819173611700535 0.008124551735818386 0.009383338503539562; 0.0006174167501740158 0.0019076289609074593 0.0031207536812871695 0.0043926904909312725 0.005650006700307131 0.006875375285744667 0.008135958574712276 0.009356185793876648; 0.0006171966670081019 0.001863816287368536 0.003090672893449664 0.004370627924799919 0.005616161972284317 0.006892588920891285 0.008128708228468895 0.009363705292344093; 0.0006064155022613704 0.001876539085060358 0.003101509064435959 0.0043662237003445625 0.005633171182125807 0.006865364499390125 0.008128601126372814 0.009366671554744244; 0.00064811174524948 0.0018876376561820507 0.003109211102128029 0.004356807097792625 0.005650743842124939 0.006887008901685476 0.008106792345643044 0.009390613995492458; 0.0006251352024264634 0.0018727672286331654 0.003102746093645692 0.004404332954436541 0.0056230840273201466 0.0068882484920322895 0.008128286339342594 0.009366245940327644; 0.0006181058706715703 0.0018782609840855002 0.00315292552113533 0.004379163030534983 0.005611733999103308 0.006875614169985056 0.008124787360429764 0.00939343124628067])

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.4
Commit 01a2eadb047 (2026-01-06 16:56 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-28714/docs/
  JULIA_VERSION = 1.12.4
  JULIA_LOAD_PATH = @:@v#.#:@stdlib
  JULIA_VERSION_ENZYME = 1.10.10
  JULIA_PYTHONCALL_EXE = /var/lib/buildkite-agent/Oceananigans.jl-28714/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-28714/docs/Project.toml`
  [79e6a3ab] Adapt v4.4.0
  [052768ef] CUDA v5.9.6
  [13f3f980] CairoMakie v0.15.8
  [e30172f5] Documenter v1.16.1
  [daee34ce] DocumenterCitations v1.4.1
  [033835bb] JLD2 v0.6.3
  [63c18a36] KernelAbstractions v0.9.39
  [98b081ad] Literate v2.21.0
  [da04e1cc] MPI v0.20.23
  [85f8d34a] NCDatasets v0.14.10
  [9e8cae18] Oceananigans v0.104.1 `..`
  [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.1

This page was generated using Literate.jl.