Example

In this example we shall observe the disintegration of a heap of water using the water-waves system as well as a second-order small-steepness model.

More advanced examples can be found in the package's examples and notebooks section.

Set up the initial-value problem

First we define parameters of our problem.

using WaterWaves1D

param = (
    # Physical parameters. Variables are non-dimensionalized as in Lannes, The water waves problem, isbn:978-0-8218-9470-5
    μ  = 1,     # shallow-water dimensionless parameter
    ϵ  = 1/4,   # nonlinearity dimensionless parameter
    # Numerical parameters
    N  = 2^10,  # number of collocation points
    L  = 10,    # half-length of the numerical tank (-L,L)
    T  = 5,     # final time of computation
    dt = 0.01,  # timestep
                );
(μ = 1, ϵ = 0.25, N = 1024, L = 10, T = 5, dt = 0.01)

Now we define initial data solver (the "heap of water"). The function Init may take either functions, or vectors (values at collocation points) as arguments.

z(x) = exp.(-abs.(x).^4); # surface deformation
v(x) = zero(x);     # zero initial velocity
init = Init(z,v);         # generate the initial data with correct type
Initial data: user-defined

Then we build the different models to compare (see WaterWaves and WWn).

WW_model=WaterWaves(param) # The water waves system
WW2_model=WWn(param;n=2,dealias=1,δ=1/10) # The quadratic model (WW2)
Spectral model of order 2.
├─Shallowness parameter μ=1, nonlinearity parameter ϵ=0.25, scaling parameter ν=1 (shallow water case).
├─Rectifier with strength δ=0.1 and order m=-1.
└─Dealiasing with Orszag's rule adapted to power 2 nonlinearity. No Krasny filter. 
Discretized with 1024 collocation points on [-10.0, 10.0].

Finally we set up initial-value problems. Optionally, one may specify a time solver to Problem, by default the standard explicit fourth order Runge Kutta method is used.

WW_problem=Problem(WW_model, init, param) ;
WW2_problem=Problem(WW2_model, init, param) ;
Initial-value problem with...
├─Model: WW2.
├─Initial data: user-defined.
├─Solver: RK4.
└─Grid of times: 501 computed times on [0, 5.0] (timestep dt=0.01), among which 501 will be stored.

Solve the initial-value problem

Solving the initial-value problems is as easy as solve!.

solve!([WW_problem WW2_problem];verbose=false);

Generate graphics

Plot solutions at final time.

using Plots
plot([WW_problem, WW2_problem])
Example block output

Generate an animation.

@gif for t in LinRange(0,param.T,100)
    plot([WW_problem, WW2_problem], T = t)
    ylims!(-0.5, 1)
end
Example block output

See the plot recipes for many more plotting possibilities.