% script: convectTest.m
% description: numically solve the convection-diffusion equation
% for solution u(x,t) using DFT in space, ERK in time
%          u_t = (D*u_x)_x + P(x)_x + Q(x) + F(x,t)
% on the domain 0 <= x <= L, t > 0 with boundary conditions
%         u(0,t) = B(t),
% and intiial conditions
%         u(x,0) = IC(x).

% programmer: t. shores
% last rev.: 2/18/16
 
% Octave and Matlab compatible file
% initialization -- set parameters of problem
% problem function parameters are defined in file convectRHS
% number of samples along x-axis -- must be power of 2:
N = 16;
% right endpoint in x-domain [0, L] of the problem:
L = 2*pi;
% time interval [0, tLast] of the problem:
tLast = 3;
% number of time steps calculated:
numSteps = 15;
% time marching method used:
mtd = 'ERK4';
% signal if solution to the problem is known:
solnFlag = false;
% calculate remaining parameters
xNodes = linspace(0,L,N+1); 
xNodes = xNodes(1:N);  % trim off right endpoint
% change uApprox to suitable array if all steps to be recorded and flag mtd
uApprox = convectIC(xNodes); % initial value of u at t = 0
hStep = tLast/numSteps; % stepsize
% run the method  to get last value -- mtd must have suitable "last value only" flag
uApprox = feval(mtd, 'convectRHS', 0, uApprox, hStep, numSteps, 0);
 % if solution is known, use L2 norm and infinity nomr to measure error
if (solnFlag)
  disp('L-norm of error at tLast:');
  disp(norm(uApprox - convectSoln(xNodes, tLast))*sqrt(hStep));
  disp('Infinity norm of error at tLast:');
  disp(norm(uApprox - convectSoln(xNodes, tLast),inf));
end 

