4.4 Main CPU Simulation

"""
Run complete deep water wave simulation on CPU

Parameters:
- N: number of grid points (should be power of 2 for FFT efficiency)
- animation: whether to create animated output
"""
function main_cpu(N::Int64; animation=true)
    
    # Set up simulation parameters
    param = (ϵ=1/2,           # Nonlinearity parameter (wave amplitude)
             N=N,             # Grid points
             L=10.,           # Half-width (domain is [-10, 10])
             T=5.,            # Final time
             dt=0.001)        # Time step
    
    # Initialize solver components
    mesh = Mesh(param)
    times = Times(param.dt, param.T)
    init = BellCurve(param, 2.5)  # Bell curve IC with shape parameter 2.5
    model = Matsuno(param)
    solver = RK4(param, model)
    
    # Initialize solution array: [η̂, φ̂]
    U = zeros(ComplexF64, (mesh.N, 2))
    
    # Initial elevation: apply dealiasing filter
    U[:, 1] .= model.Π⅔ .* fft(init.h)
    
    # Initial velocity: zero (no initial motion)
    U[:, 2] .= model.Π⅔ .* fft(init.u)

    dt = times.dt
    
    # Allocate storage for full solution history
    data = zeros(ComplexF64, (mesh.N, 2, times.Nt))

    # Time stepping loop
    @showprogress 1 for j in 1:times.Nt
        # Advance by one time step using RK4
        step!(solver, model, U, dt)
        
        # Store current state
        data[:, :, j] .= U
    end

    # Create visualization if requested
    if animation
        create_animation(mesh, times, model, data)
    end

end

4.4.1 Run Simulation

# Run with 2^14 = 16384 grid points
# This provides good resolution for capturing nonlinear dynamics
main_cpu(2^14; animation=false)

Notes on Performance:

4.4.2 Expected Physical Behavior

  1. Initial evolution: The bell curve starts to split into waves
  2. Dispersive spreading: Waves spread due to dispersion (different frequencies travel at different speeds)
  3. Nonlinear steepening: Large-amplitude waves develop sharper crests
  4. Energy transfer: Energy cascades to higher wavenumbers through nonlinear interactions
  5. Recurrence: In periodic domains, waves can partially or fully recur (Fermi-Pasta-Ulam effect)


CC BY-NC-SA 4.0 Pierre Navaro