function temple9200_particle_1d_advection_reaction
%TEMPLE9200_PARTICLE_1D_ADVECTION_REACTION
%   A 1d example of an advection-reaction problem with a
%   variable advection velocity field, and a bi-stable
%   reaction term. The reaction term steepens gradients,
%   while the advection term flattens them (for the given
%   initial conditions). The solution is approximated
%   using characteristic particles. This example shows
%   how the moving particles eventually fail to resolve
%   the solution, if no particle management is applied.

% 01/2015 by Benjamin Seibold
%            http://www.math.temple.edu/~seibold/

%-----------------------------------------------------------------------
% Problem parameters
tf = 3; % final time
nt = 300; % number of time steps
u = @(x) sin(2*pi*x); % advection velocity field
g = @(f) -6*(f-1).*f.*(f+1); % reaction term
f = @(x) sin(pi*x); % initial conditions
np = 1e3; % number of particles
%-----------------------------------------------------------------------
px = linspace(-1,1,np); % create particles
pf = f(px); % evaluate initial conditions on particles
dt = tf/nt; % time step
for t = linspace(0,tf,nt+1) % time loop
    % Plotting
    clf
    plot(px,pf,'k.-')
    xlabel('x'), ylabel('\phi')
    title(sprintf('Advection-reaction problem at t = %0.2f',t))
    pause(1e-3)
    
    % Update particle positions and function values (using forward Euler)
    px = px+dt*u(px);
    pf = pf+dt*g(pf);
end
