function hw7 ( initial_condition )

%*****************************************************************************80
%
%% hw7 solves the Burgers equation using a parabolic method.
%
%  Discussion:
%
%    We consider BCV, the Burgers conservative viscid equation:
%
%      du/dt = -1/2 d u^2/dx + nu d2u/dx^2
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    16 July 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    function value = initial_condition ( x ): sets the initial condition.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hw7:\n' );
  fprintf ( 1, '  Solve the Burgers equation using a parabolic method.\n' );

  xmin = -1.0;
  xmax = +1.0;
  nx = 81;
  x = linspace ( xmin, xmax, nx );
  dx = ( xmax - xmin ) / ( nx - 1 );

  tmin = 0.0;
  tmax = 2.0;
  nt = 201;
  t = linspace ( tmin, tmax, nt );
  dt = ( tmax - tmin ) / ( nt - 1 );

  nu = 0.01;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  BCV viscosity is %g\n', nu );

  IM1 = [ nx-1, 1:nx-2 ];
  I   = [ 1:nx-1 ];
  IP1 = [ 2:nx-1, 1 ];

  c = zeros ( nt, 1 );

  for k = 1 : nt

    if ( k == 1 )
      un = initial_condition ( x );
    else
      uo = un;
      un(I) = uo(I) ...
        - 0.25 * dt / dx * ( uo(IP1).^2 - uo(IM1).^2 ) ...
        + ( nu * dt / dx^2 ) * ( uo(IM1) - 2.0 * uo(I) + uo(IP1) );
      un(nx) = un(1);
    end
%
%  Plot the computed solution.
%
    clf ( );
    plot ( x, un, 'b-', 'linewidth', 3 );
    grid ( 'on' );
    xlabel ( '<--- x --->' );
    ylabel ( '<--- u(x,t) -->' );
    label = sprintf ( 'BCV Parabolic: k = %3d, t = %4.1f', k, t(k) );
    title ( label );
    axis ( [ xmin, xmax, 0.0, 1.1 ] );
    pause ( 0.1 );

    c(k) = sum ( un(I) * dx );

  end

  filename = 'hw7.png';
  print ( '-dpng', filename );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Last velocity plot saved as "%s"\n', filename );
%
%  Plot the integral of velocity, which should be conserved.
%
  clf ( );
  plot ( t, c, 'b-', [tmin,tmax], [c(1), c(1) ], 'r--', 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<--- t --->' );
  ylabel ( '<--- \int(u dx) -->' );
  title ( 'BCV Parabolic: conservation of \int(u dx)' );
  emax = 1.1 * max ( e );
  axis ( [ tmin, tmax, 0.0, emax ] );
  filename = 'hw7_conservation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Conservation plot saved as "%s"\n', filename );

  return
end

