4.3 Animation Creation

"""
Create animated visualization of the wave evolution

Shows two subplots:
1. Physical space: η(x,t) - surface elevation
2. Fourier space: log(|η̂(k,t)|) - energy spectrum

Parameters:
- mesh: spatial grid
- times: time stepping info
- model: the model (for labeling)
- data: solution data [η̂, φ̂] at all times
"""
function create_animation(mesh, times, model, data)
    
    prog = Progress(times.Nt, 1)

    hr = zeros(Float64, mesh.N)  # Real space elevation
    ur = zeros(Float64, mesh.N)  # Real space velocity

    anim = @animate for l in 1:size(data)[end]

        # Create 2×1 subplot layout
        pl = plot(layout=(2, 1))

        # Transform to physical space
        hr .= real(ifft(view(data, :, 1, l)))
        ur .= real(ifft(view(data, :, 2, l)))

        # Top plot: Physical space elevation
        plot!(pl[1,1], mesh.x, hr;
              ylims=(-0.6, 1),
              title="Physical Space: Surface Elevation",
              label=model.label)

        # Bottom plot: Fourier space spectrum
        plot!(pl[2,1], fftshift(mesh.k),
              log10.(1e-18 .+ abs.(fftshift(fft(hr))));
              ylims=(-20, 5),
              title="Fourier Space: Energy Spectrum",
              label=model.label)

        next!(prog)

    end when mod(l, 100) == 0  # Sample every 100 time steps

    gif(anim, "anim_" * model.label * ".gif", fps=15)

end


CC BY-NC-SA 4.0 Pierre Navaro