function dudt = allen_cahn_deriv ( t, u, x )

%*****************************************************************************80
%
%% allen_cahn_deriv returns the right hand side of the allen-cahn ODE.
%
%  Discussion:
%
%    This version of the equation has the form:
%
%      du/dt = nu * uxx - u * (u^2-1) / (2*xi)
%
%    uxx is the second derivative of u with respect to x;
%    nu is a positive diffusion coefficient;
%    xi is a positive parameter called the interface thickness.
%
%    Zero Neumann boundary conditions are assumed, and so we
%    set dudt(1) = dudt(2) and dudt(nx) = dudt(nx-1).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    03 May 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Costica Morosanu, Silvio Paval,
%    On the numerical approximation of a nonlinear reaction-diffusion
%    equation with non-homogeneous Neumann boundary conditions.  Case 1D,
%    ROMAI Journal,
%    Volume 15, Number 2, pages 43-60, 2019.
%
%    Jian Zhang, Qiang Du,
%    Numerical studies of discrete approximations to the Allen-Cahn
%    equation in the sharp interface limit,
%    SIAM Journal on Scientific Computing,
%    Volume 31, Number 4, pages 3042-3063, 2009.
%
%  Input:
%
%    real T, the current time.
%
%    real U(*): the current state values.
%
%    real X(*): the node coordinates.
%
%  Output:
%
%    real DUDT(*), the time derivatives of the current state values.
%
  [ nu, xi, t0, tstop, xmin, xmax ] = allen_cahn_parameters ( );

  uxx = laplacian_interval ( u, x );

  dudt = nu * uxx - u .* ( u.^2 - 1.0 ) / ( 2.0 * xi^2 );
%
%  Apply boundary conditions.
%
  dudt(1) = dudt(2);
  dudt(end) = dudt(end-1);
%
%  MATLAB needs column vector output.
%
  dudt = dudt(:);

  return
end

