function u0 = allen_cahn_initial_condition ( x )

%*****************************************************************************80
%
%% allen_cahn_initial_condition(): initial condition for the Allen-Cahn equation.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    10 November 2020
%
%  Author:
%
%    John Burkardt, Catalin Trenchea
%
%  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 X(*): points at which the initial condition is desired.
%
%  Output:
%
%    real U0(*): the initial condition values.
%
  xmin = min ( x );
  xmax = max ( x );

  x0 = linspace ( xmin, xmax, 84 );
  v0 = [ ...
    -1.40, -1.40, -1.44, -1.42, -1.42, ...
    -1.44, -1.43, -1.43, -1.42, -1.42, ...
    -1.40, -1.40, -1.25, -1.20, -1.17, ...
    -1.15, -1.10, -1.08, -1.00, -0.95, ...
    -0.90, -0.85, -0.88, -0.60,  0.00, ...
     0.50, -0.92, -0.25,  0.80, -0.70, ...
     0.58,  0.75,  0.58, -0.63, -0.59, ...
     0.69, -0.72,  0.70, -0.59, -0.50, ... 
     0.70, -0.79, -0.87, -0.88,  0.00, ...
     0.72, -0.80,  0.81,  0.00, -0.89, ...
     0.00,  0.70,  0.55,  0.68, -0.49, ...
     0.79,  0.00, -0.10, -0.80, -0.78, ...
    -0.83,  0.69, -0.80,  0.68,  0.50, ...
     0.70,  0.59,  1.00,  1.08,  1.10, ...
     1.15,  1.17,  1.20,  1.25,  1.30, ...
     1.30,  1.25,  1.24,  1.30,  1.31, ...
     1.30,  1.32,  1.30,  1.30 ];
%
%  Use a cubic spline to interpolate the data to the points x.
%
  u0 = spline ( x0, v0, x );
%
%  Guarantee boundary conditions.
%
  u0(1) = u0(2);
  u0(end) = u0(end-1);
%
%  Return as column vector.
%
  u0 = u0(:);

  return
end

