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: 9.135 seconds, max(u): (0.000e+00, 0.000e+00, 0.000e+00) m/s, next Δt: 20 minutes
[ Info:     ... simulation initialization complete (13.128 seconds)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (3.914 seconds).
[06.94%] i: 100, t: 1.389 days, wall time: 15.524 seconds, max(u): (1.384e-01, 1.270e-01, 1.832e-03) m/s, next Δt: 20 minutes
[13.89%] i: 200, t: 2.778 days, wall time: 993.174 ms, max(u): (2.178e-01, 2.085e-01, 2.062e-03) m/s, next Δt: 20 minutes
[20.83%] i: 300, t: 4.167 days, wall time: 814.365 ms, max(u): (3.062e-01, 3.403e-01, 2.022e-03) m/s, next Δt: 20 minutes
[27.78%] i: 400, t: 5.556 days, wall time: 927.168 ms, max(u): (4.001e-01, 5.057e-01, 2.456e-03) m/s, next Δt: 20 minutes
[34.72%] i: 500, t: 6.944 days, wall time: 910.841 ms, max(u): (5.258e-01, 7.236e-01, 2.671e-03) m/s, next Δt: 20 minutes
[41.67%] i: 600, t: 8.333 days, wall time: 948.795 ms, max(u): (7.933e-01, 1.041e+00, 3.689e-03) m/s, next Δt: 20 minutes
[48.61%] i: 700, t: 9.722 days, wall time: 1.133 seconds, max(u): (1.132e+00, 1.323e+00, 5.015e-03) m/s, next Δt: 20 minutes
[55.56%] i: 800, t: 11.111 days, wall time: 906.968 ms, max(u): (1.408e+00, 1.244e+00, 5.730e-03) m/s, next Δt: 20 minutes
[62.50%] i: 900, t: 12.500 days, wall time: 2.010 seconds, max(u): (1.268e+00, 1.157e+00, 4.151e-03) m/s, next Δt: 20 minutes
[69.44%] i: 1000, t: 13.889 days, wall time: 6.130 seconds, max(u): (1.391e+00, 1.244e+00, 4.025e-03) m/s, next Δt: 20 minutes
[76.39%] i: 1100, t: 15.278 days, wall time: 7.868 seconds, max(u): (1.293e+00, 1.351e+00, 3.389e-03) m/s, next Δt: 20 minutes
[83.33%] i: 1200, t: 16.667 days, wall time: 2.953 seconds, max(u): (1.532e+00, 1.463e+00, 2.963e-03) m/s, next Δt: 20 minutes
[90.28%] i: 1300, t: 18.056 days, wall time: 893.427 ms, max(u): (1.405e+00, 1.467e+00, 2.490e-03) m/s, next Δt: 20 minutes
[97.22%] i: 1400, t: 19.444 days, wall time: 943.129 ms, max(u): (1.368e+00, 1.386e+00, 2.991e-03) m/s, next Δt: 20 minutes
[ Info: Simulation is stopping after running for 45.629 seconds.
[ Info: Simulation time 20 days equals or exceeds stop time 20 days.
[ Info: Simulation completed in 45.673 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.009384033270180225 -0.00811799056828022 -0.006876906380057335 -0.005621455144137144 -0.004372670315206051 -0.0031487729866057634 -0.0018810117617249489 -0.0006169595872052014; -0.009368067607283592 -0.008109744638204575 -0.006853338796645403 -0.005625107791274786 -0.004366787616163492 -0.0031488994136452675 -0.0018837008392438293 -0.0006241603405214846; -0.009386724792420864 -0.008129789493978024 -0.006887215655297041 -0.0056481440551579 -0.004396660253405571 -0.0031142989173531532 -0.0018901556031778455 -0.000605412176810205; -0.009356144815683365 -0.008132891729474068 -0.0068807099014520645 -0.005642095115035772 -0.0043672178871929646 -0.0031415901612490416 -0.0018747180001810193 -0.0006373777287080884; -0.00940624624490738 -0.008099095895886421 -0.006871301680803299 -0.005640027113258839 -0.004355716053396463 -0.003103425493463874 -0.0018836581148207188 -0.0006410927744582295; -0.009378298185765743 -0.008123091422021389 -0.0068786549381911755 -0.005634458735585213 -0.0043729860335588455 -0.0031275846995413303 -0.0018724511610344052 -0.0006170552805997431; -0.009362347424030304 -0.008096544072031975 -0.006874709855765104 -0.005658169277012348 -0.004375243093818426 -0.0030911224894225597 -0.0018681848887354136 -0.0006265199044719338; -0.009378144517540932 -0.008093688637018204 -0.006873409263789654 -0.005636557005345821 -0.004375721327960491 -0.0031549781560897827 -0.0018512792885303497 -0.0005930085899308324; -0.009381482377648354 -0.008121185004711151 -0.006868797820061445 -0.005614806432276964 -0.004380953032523394 -0.0031161787919700146 -0.0018802835838869214 -0.0006283426773734391; -0.009383214637637138 -0.008124570362269878 -0.006873701233416796 -0.005623778328299522 -0.004378242418169975 -0.0031333989463746548 -0.0018656909232959151 -0.0006253659958019853; -0.009366431273519993 -0.008113215677440166 -0.006857553031295538 -0.005616297014057636 -0.004406754393130541 -0.003101364942267537 -0.0018716254271566868 -0.0006179871270433068; -0.009351670742034912 -0.008131152018904686 -0.0068880836479365826 -0.005609739571809769 -0.004375289659947157 -0.003158428007736802 -0.001888813218101859 -0.0006407661712728441; -0.009358525276184082 -0.008115208707749844 -0.0068526421673595905 -0.005625427700579166 -0.004349463153630495 -0.0031548356637358665 -0.001874509733170271 -0.0006297185900621116; -0.009373902343213558 -0.008136304095387459 -0.00688551738858223 -0.00563502311706543 -0.004363407846540213 -0.003162889741361141 -0.0018583169439807534 -0.0006561033078469336; -0.009402438998222351 -0.008112861774861813 -0.0068512242287397385 -0.005650914274156094 -0.004357932135462761 -0.0031192339956760406 -0.001863922574557364 -0.0006231566658243537; -0.009365124627947807 -0.008107736706733704 -0.006875638384371996 -0.00563379330560565 -0.004368689842522144 -0.0031223094556480646 -0.0018965275958180428 -0.0006253138417378068; -0.009399905800819397 -0.008146891370415688 -0.0068819355219602585 -0.005608520936220884 -0.004381503909826279 -0.0031151401344686747 -0.0018773885676637292 -0.0006150425761006773; -0.00937403179705143 -0.008139088749885559 -0.0068640499375760555 -0.005604719743132591 -0.004392612725496292 -0.0031163468956947327 -0.0019051623530685902 -0.0006148413522168994; -0.009388001635670662 -0.00814630463719368 -0.00688392948359251 -0.005595908500254154 -0.004365450236946344 -0.003127469215542078 -0.001885464764200151 -0.0006306107388809323; -0.009342162869870663 -0.008114810101687908 -0.0069032711908221245 -0.00564882718026638 -0.004372748080641031 -0.003116986248642206 -0.0018706414848566055 -0.0006212820298969746; -0.009367560967803001 -0.00813702680170536 -0.006869161035865545 -0.005633954890072346 -0.00439369585365057 -0.0031133329030126333 -0.001877975999377668 -0.0006465483456850052; -0.009357096627354622 -0.008148834109306335 -0.0068834819830954075 -0.005625339224934578 -0.004374172538518906 -0.0031293965876102448 -0.0018366014119237661 -0.0006119172903709114; -0.0074940393678843975 -0.006246543023735285 -0.004990418907254934 -0.0037717237137258053 -0.0024816757068037987 -0.0012406500754877925 -1.6245196093223058e-5 0.0012744818814098835; -0.005410088691860437 -0.004200073424726725 -0.0029096168000251055 -0.0016573267057538033 -0.00041174929356202483 0.0008427855209447443 0.0020776863675564528 0.0033341359812766314; -0.0033472655341029167 -0.002068148460239172 -0.0008165141916833818 0.0004129335575271398 0.0016613679472357035 0.002938946709036827 0.004171549808233976 0.005401086527854204; -0.0012334480416029692 1.1490182259876747e-5 0.0012446915498003364 0.002521769143640995 0.003740578191354871 0.0050232065841555595 0.006241164170205593 0.0074729910120368; 0.0006305983988568187 0.001871081069111824 0.0031295674853026867 0.004405251704156399 0.0056133572943508625 0.00687769427895546 0.008122298866510391 0.009353607892990112; 0.0006471352535299957 0.001890727085992694 0.0031189152505248785 0.004382232204079628 0.005633171647787094 0.006868817377835512 0.008132853545248508 0.009380169212818146; 0.0006177097093313932 0.001876500085927546 0.0031083570793271065 0.004364327527582645 0.005636963993310928 0.006871132645756006 0.008119647391140461 0.009387933649122715; 0.0006466374034062028 0.0018687450792640448 0.003132544457912445 0.00437831599265337 0.0056194132193923 0.006849713157862425 0.008125508204102516 0.009361514821648598; 0.0006229050341062248 0.0018953289836645126 0.003129909047856927 0.0043890392407774925 0.0056119440123438835 0.006873176898807287 0.008130448870360851 0.009375283494591713; 0.000627932429779321 0.0018800944089889526 0.0031294028740376234 0.004379588644951582 0.0056507340632379055 0.0068751187063753605 0.008136764168739319 0.00935838371515274; 0.0006315279169939458 0.0018656470347195864 0.003159577026963234 0.004379237070679665 0.005614351015537977 0.00687265582382679 0.0081253070384264 0.009389001876115799; 0.0006453368114307523 0.0018633432919159532 0.0031278044916689396 0.00436293613165617 0.005631244741380215 0.006896061822772026 0.008126440457999706 0.009372066706418991; 0.000610189454164356 0.001861868891865015 0.003127460367977619 0.004379567690193653 0.0056433603167533875 0.0068755000829696655 0.008114909753203392 0.009365860372781754; 0.0006555861327797174 0.0018820996629074216 0.0031165184918791056 0.004404119681566954 0.005627122242003679 0.006871443707495928 0.008102205581963062 0.009379342198371887; 0.000608063128311187 0.0018776878714561462 0.0031147932168096304 0.004358173348009586 0.0056305876933038235 0.006868669763207436 0.008101552724838257 0.009381035342812538; 0.0006395686068572104 0.0018672490259632468 0.003112861653789878 0.004380004946142435 0.005637452006340027 0.006868760101497173 0.008126901462674141 0.00936403963714838; 0.0006055888370610774 0.0018711000448092818 0.0031114951707422733 0.004393944516777992 0.005636760499328375 0.006874942220747471 0.008121244609355927 0.009368374943733215; 0.0006227753474377096 0.0018828919855877757 0.0031073326244950294 0.004377077799290419 0.005654414650052786 0.006862410809844732 0.008147991262376308 0.009385868906974792; 0.0006360025727190077 0.0018691810546442866 0.0031168407294899225 0.004373765550553799 0.005636980757117271 0.006877128034830093 0.00812163483351469 0.009380122646689415; 0.0006082163890823722 0.001867719111032784 0.0031259034294635057 0.004356961231678724 0.005641428753733635 0.006880704313516617 0.008110813796520233 0.009385107085108757; 0.0006449067150242627 0.0018756147474050522 0.003100320464000106 0.004376132972538471 0.005628715269267559 0.006874520797282457 0.0080989059060812 0.009383895434439182; 0.0006507437210530043 0.0018777409568428993 0.0031215581111609936 0.004359677899628878 0.005627232138067484 0.006884608883410692 0.008140157908201218 0.009378336369991302; 0.0006212865118868649 0.001857585390098393 0.0031395237892866135 0.00438662339001894 0.005631092004477978 0.0069006672129035 0.008119686506688595 0.009370293468236923; 0.0006221791845746338 0.0018812796333804727 0.0031495830044150352 0.004379897378385067 0.00561373308300972 0.006875923369079828 0.008120102807879448 0.009356030263006687; 0.0006390204653143883 0.0018822611309587955 0.003119166474789381 0.004369379952549934 0.00562189519405365 0.006872424390166998 0.008150041103363037 0.009365232661366463; 0.000627871893811971 0.001867344486527145 0.003142404370009899 0.00435442803427577 0.005618073511868715 0.006863727699965239 0.008145228959619999 0.009359811432659626])

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-29445/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-29445/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-29445/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.40
  [98b081ad] Literate v2.21.0
  [da04e1cc] MPI v0.20.23
  [85f8d34a] NCDatasets v0.14.11
  [9e8cae18] Oceananigans v0.104.5 `..`
  [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.