"""
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
# Run with 2^14 = 16384 grid points
# This provides good resolution for capturing nonlinear dynamics
main_cpu(2^14; animation=false)
Notes on Performance:
N = 2^14 requires significant computation (several FFTs per time step × thousands of time steps)2^12 for faster testing