A stratified turbulence example

using Oceananigans
using TurbulentWords
using CairoMakie

We construct a simulation with a word and run it.

simulation = word_to_simulation("hello", dynamics=:buoyancy_driven, pad_to_square=true)
simulation.stop_time = 0.8

model = simulation.model
b = model.tracers.b
outputs = (; b)
filename = "hello_buoyancy"
simulation.output_writers[:fields] = JLD2OutputWriter(model, outputs,
                                                      schedule = TimeInterval(0.02),
                                                      filename = filename * ".jld2",
                                                      overwrite_existing = true)


run!(simulation)
[ Info: Initializing simulation...
[ Info: Iteration: 0, time: 0.0, wall time: 5.659 seconds, Δt: 0.011000000000000001
[ Info:     ... simulation initialization complete (4.847 seconds)
[ Info: Executing initial time step...
[ Info:     ... initial time step complete (4.946 seconds).
[ Info: Iteration: 10, time: 0.1, wall time: 10.166 seconds, Δt: 0.011000000000000001
[ Info: Iteration: 20, time: 0.191, wall time: 5.839 seconds, Δt: 0.011000000000000001
[ Info: Iteration: 30, time: 0.29100000000000004, wall time: 6.124 seconds, Δt: 0.011000000000000001
[ Info: Iteration: 40, time: 0.391, wall time: 6.192 seconds, Δt: 0.011000000000000001
[ Info: Iteration: 50, time: 0.491, wall time: 5.861 seconds, Δt: NaN
[ Info: Iteration: 60, time: NaN, wall time: 5.540 seconds, Δt: NaN
[ Info: Iteration: 70, time: NaN, wall time: 5.544 seconds, Δt: NaN
[ Info: Iteration: 80, time: NaN, wall time: 5.536 seconds, Δt: NaN
[ Info: Iteration: 90, time: NaN, wall time: 5.564 seconds, Δt: NaN
[ Info: time = NaN, iteration = 100: NaN found in field u. Stopping simulation.
[ Info: Iteration: 100, time: NaN, wall time: 5.531 seconds, Δt: NaN

Now we load the saved output

bt = FieldTimeSeries(filename * ".jld2", "b")
times = bt.times
0.0:0.02:0.48

and make a movie

fig = Figure(size = (600, 600))
ax = Axis(fig[1, 1])
hidedecorations!(ax)
hidespines!(ax)
n = Observable(1)

bn = @lift bt[$n]

blim = 0.8
heatmap!(ax, bn; colormap = :balance, colorrange = (-blim, blim))

stillframes = 20
framerate = 32
movingframes = length(times)

record(fig, filename * ".mp4"; framerate) do io
    [recordframe!(io) for _ = 1:stillframes]

    for nn in 1:movingframes
        n[] = nn
        recordframe!(io)
    end

    for nn in movingframes:-1:1
        n[] = nn
        recordframe!(io)
    end

    [recordframe!(io) for _ = 1:stillframes]
end
"hello_buoyancy.mp4"


This page was generated using Literate.jl.