Skip to content

Commit aaaf41d

Browse files
Use Makie extension in Kelvin-Helmholtz example (#4569)
* simplifications + use makieext * fix docs * more using makie ext * simplify color limits * Update VarianceDissipationComputations.jl * Update TimeSteppers.jl * Update VarianceDissipationComputations.jl * Apply suggestions from code review Co-authored-by: Simone Silvestri <[email protected]> --------- Co-authored-by: Simone Silvestri <[email protected]>
1 parent b0d8a2a commit aaaf41d

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

examples/kelvin_helmholtz_instability.jl

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ model = NonhydrostaticModel(; grid,
145145
buoyancy = BuoyancyTracer(),
146146
tracers = :b)
147147

148-
# We have included a "pinch" of viscosity and diffusivity in anticipation of what will follow furtherdown:
148+
# We have included a "pinch" of viscosity and diffusivity in anticipation of what will follow further down:
149149
# viscosity and diffusivity will ensure numerical stability when we evolve the unstable mode to the point
150150
# it becomes nonlinear.
151151

@@ -251,7 +251,7 @@ function estimate_growth_rate(simulation, energy, ω, b; convergence_criterion=1
251251
σ = []
252252
power_method_data = []
253253
compute!(ω)
254-
push!(power_method_data, (ω=collect(interior(ω, :, 1, :)), b=collect(interior(b, :, 1, :)), σ=deepcopy(σ)))
254+
push!(power_method_data, (ω=deepcopy(ω), b=deepcopy(b), σ=deepcopy(σ)))
255255

256256
while convergence(σ) > convergence_criterion
257257
compute!(energy)
@@ -265,7 +265,7 @@ function estimate_growth_rate(simulation, energy, ω, b; convergence_criterion=1
265265

266266
compute!(ω)
267267
rescale!(simulation.model, energy)
268-
push!(power_method_data, (ω=collect(interior(ω, :, 1, :)), b=collect(interior(b, :, 1, :)), σ=deepcopy(σ)))
268+
push!(power_method_data, (ω=deepcopy(ω), b=deepcopy(b), σ=deepcopy(σ)))
269269
end
270270

271271
return σ, power_method_data
@@ -281,9 +281,6 @@ b = model.tracers.b
281281

282282
perturbation_vorticity = Field(∂z(u) - ∂x(w))
283283

284-
xω, yω, zω = nodes(perturbation_vorticity)
285-
xb, yb, zb = nodes(b)
286-
287284
# # Rev your engines...
288285
#
289286
# We initialize the power iteration with random noise and rescale to have a `target_kinetic_energy`
@@ -307,7 +304,7 @@ n = Observable(1)
307304

308305
fig = Figure(size=(800, 600))
309306

310-
kwargs = (xlabel="x", ylabel="z", limits = ((xω[1], xω[end]), (zω[1], zω[end])), aspect=1,)
307+
kwargs = (xlabel="x", ylabel="z", limits = ((-5, 5), (-5, 5)), aspect=1)
311308

312309
ω_title(t) = t === nothing ? @sprintf("vorticity") : @sprintf("vorticity at t = %.2f", t)
313310
b_title(t) = t === nothing ? @sprintf("buoyancy") : @sprintf("buoyancy at t = %.2f", t)
@@ -321,13 +318,13 @@ bₙ = @lift power_method_data[$n].b
321318

322319
σₙ = @lift [(i-1, i==1 ? NaN : growth_rates[i-1]) for i in 1:$n]
323320

324-
ω_lims = @lift (-maximum(abs, power_method_data[$n].ω) - 1e-16, maximum(abs, power_method_data[$n].ω) + 1e-16)
325-
b_lims = @lift (-maximum(abs, power_method_data[$n].b) - 1e-16, maximum(abs, power_method_data[$n].b) + 1e-16)
321+
ω_lims = @lift (-maximum(abs, power_method_data[$n].ω), maximum(abs, power_method_data[$n].ω))
322+
b_lims = @lift (-maximum(abs, power_method_data[$n].b), maximum(abs, power_method_data[$n].b))
326323

327-
hm_ω = heatmap!(ax_ω, xω, zω, ωₙ; colorrange = ω_lims, colormap = :balance)
324+
hm_ω = heatmap!(ax_ω, ωₙ; colorrange = ω_lims, colormap = :balance)
328325
Colorbar(fig[2, 2], hm_ω)
329326

330-
hm_b = heatmap!(ax_b, xb, zb, bₙ; colorrange = b_lims, colormap = :balance)
327+
hm_b = heatmap!(ax_b, bₙ; colorrange = b_lims, colormap = :balance)
331328
Colorbar(fig[2, 4], hm_b)
332329

333330
eigentitle(σ, t) = length(σ) > 0 ? @sprintf("Iteration #%i; growth rate %.2e", length(σ), σ[end]) : @sprintf("Initial perturbation fields")
@@ -345,7 +342,7 @@ scatter!(ax_σ, σₙ; color = :blue)
345342
frames = 1:length(power_method_data)
346343

347344
record(fig, "powermethod.mp4", frames, framerate=1) do i
348-
n[] = i
345+
n[] = i
349346
end
350347

351348
nothing #hide
@@ -410,12 +407,12 @@ t_final = times[end]
410407

411408
n = Observable(1)
412409

413-
ωₙ = @lift interior(ω_timeseries, :, 1, :, $n)
414-
bₙ = @lift interior(b_timeseries, :, 1, :, $n)
410+
ωₙ = @lift ω_timeseries[$n]
411+
bₙ = @lift b_timeseries[$n]
415412

416413
fig = Figure(size=(800, 600))
417414

418-
kwargs = (xlabel="x", ylabel="z", limits = ((xω[1], xω[end]), (zω[1], zω[end])), aspect=1,)
415+
kwargs = (xlabel="x", ylabel="z", limits = ((-5, 5), (-5, 5)), aspect=1)
419416

420417
title = @lift @sprintf("t = %.2f", times[$n])
421418

@@ -430,13 +427,13 @@ ax_KE = Axis(fig[3, :];
430427

431428
fig[1, :] = Label(fig, title, fontsize=24, tellwidth=false)
432429

433-
ω_lims = @lift (-maximum(abs, interior(ω_timeseries, :, 1, :, $n)) - 1e-16, maximum(abs, interior(ω_timeseries, :, 1, :, $n)) + 1e-16)
434-
b_lims = @lift (-maximum(abs, interior(b_timeseries, :, 1, :, $n)) - 1e-16, maximum(abs, interior(b_timeseries, :, 1, :, $n)) + 1e-16)
430+
ω_lims = @lift (-maximum(abs, ω_timeseries[$n]), maximum(abs, ω_timeseries[$n]))
431+
b_lims = @lift (-maximum(abs, b_timeseries[$n]), maximum(abs, b_timeseries[$n]))
435432

436-
hm_ω = heatmap!(ax_ω, xω, zω, ωₙ; colorrange = ω_lims, colormap = :balance)
433+
hm_ω = heatmap!(ax_ω, ωₙ; colorrange = ω_lims, colormap = :balance)
437434
Colorbar(fig[2, 2], hm_ω)
438435

439-
hm_b = heatmap!(ax_b, xb, zb, bₙ; colorrange = b_lims, colormap = :balance)
436+
hm_b = heatmap!(ax_b, bₙ; colorrange = b_lims, colormap = :balance)
440437
Colorbar(fig[2, 4], hm_b)
441438

442439
tₙ = @lift times[1:$n]
@@ -469,12 +466,12 @@ nothing #hide
469466
# And then the same for total vorticity & buoyancy of the fluid.
470467
n = Observable(1)
471468

472-
Ωₙ = @lift interior(Ω_timeseries, :, 1, :, $n)
473-
Bₙ = @lift interior(B_timeseries, :, 1, :, $n)
469+
Ωₙ = @lift Ω_timeseries[$n]
470+
Bₙ = @lift B_timeseries[$n]
474471

475472
fig = Figure(size=(800, 600))
476473

477-
kwargs = (xlabel="x", ylabel="z", limits = ((xω[1], xω[end]), (zω[1], zω[end])), aspect=1,)
474+
kwargs = (xlabel="x", ylabel="z", limits = ((-5, 5), (-5, 5)), aspect=1)
478475

479476
title = @lift @sprintf("t = %.2f", times[$n])
480477

@@ -489,10 +486,10 @@ ax_KE = Axis(fig[3, :];
489486

490487
fig[1, :] = Label(fig, title, fontsize=24, tellwidth=false)
491488

492-
hm_Ω = heatmap!(ax_Ω, xω, zω, Ωₙ; colorrange = (-1, 1), colormap = :balance)
489+
hm_Ω = heatmap!(ax_Ω, Ωₙ; colorrange = (-1, 1), colormap = :balance)
493490
Colorbar(fig[2, 2], hm_Ω)
494491

495-
hm_B = heatmap!(ax_B, xb, zb, Bₙ; colorrange = (-0.05, 0.05), colormap = :balance)
492+
hm_B = heatmap!(ax_B, Bₙ; colorrange = (-0.05, 0.05), colormap = :balance)
496493
Colorbar(fig[2, 4], hm_B)
497494

498495
tₙ = @lift times[1:$n]

src/Models/VarianceDissipationComputations/VarianceDissipationComputations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using Oceananigans.Fields
1010
using Oceananigans.Fields: Field, VelocityFields
1111
using Oceananigans.Operators
1212
using Oceananigans.BoundaryConditions
13-
using Oceananigans.TimeSteppers: QuasiAdamsBashforth2TimeStepper,
13+
using Oceananigans.TimeSteppers: QuasiAdamsBashforth2TimeStepper,
1414
RungeKutta3TimeStepper,
1515
SplitRungeKutta3TimeStepper
1616

@@ -80,7 +80,7 @@ Keyword Arguments
8080
- `Uⁿ`: The velocity field at the current time step. Default: `VelocityFields(grid)`.
8181
8282
!!! compat "Time stepper compatibility"
83-
At the moment, the variance dissipation diagnostic is supported only for a [`QuasiAdamsBashforth2TimeStepper`](@ref)
83+
At the moment, the variance dissipation diagnostic is supported only for a [`QuasiAdamsBashforth2TimeStepper`](@ref)
8484
and a [`SplitRungeKutta3TimeStepper`](@ref).
8585
"""
8686
function VarianceDissipation(tracer_name, grid;

0 commit comments

Comments
 (0)