% This script solves u_t = F(u,t)  using a pseudospectral method.
%==========================================================================
%
% In "run_oneway.m" set parameters
%   t0, tf, dtplot, x0, x1, ord, pltord, epsilon, ltrunc
% Initial condition u0 set in "uzero.m"
% Equation set in "f.m"
% Output in "plot_oneway.m"
%==========================================================================

clear all;

%% Set time parameters
%%
t0 = 0;             % initial time
tf = 1.0;             % final time

lt = 200;
% dtplot = 0.025; % time between solution plots
dtplot = (tf-t0)/lt;
tspan = t0:dtplot:tf;
lt = length(tspan);

%% Set space parameters
%%
x0 = 0;             % left endpoint
x1 = 2*pi;          % right endpoint
ord = 16;            % n = 2^ord  space grid points
pltord = 8;         % use 2^pltord points for surface plots

xlength = x1-x0;        
nord = 2^ord;
dx = xlength/nord;
x = x0+dx*(0:(nord-1));
lx = length(x);
k = make_k(lx);

%% Set viscosity parameters
%%
epsilon = dx;               % coefficient of numerical viscosity
%epsilon = 0;               % no numerical viscosity applied
ltrunc = round(sqrt(lx));   % viscosity applied to wavenumbers k > ltrunc

%% Define initial condition  u0 = u(x,0)
%%
u0 = uzero(x,lx);

%% Solve the equation
%%
%    options = odeset('AbsTol', 1.0e-6, 'RelTol', 1.0e-6);
%    [t, u] = ode45 (@f, [t0 tf], u0, options);
[t, u] = ode45(@f,tspan,u0,[],k,lx,ltrunc,epsilon);

%% Plot the solution
%%
plot_oneway(t,x,u,k,t0,tf,lt,x0,x1,lx,ord,pltord)