function fd3d_poisson_test ( )

%*****************************************************************************80
%
%% fd3d_poisson_test() tests fd3d_poisson();
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 December 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../fd3d_poisson' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'fd3d_poisson_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  fd3d_poisson() is a simple Poisson equation solver\n' );
  fprintf ( 1, '  for a 3d rectangular block region.\n' );

  nx = 5;
  ny = 5;
  nz = 5;

  xmin = 0.0;
  xmax = 1.0;
  ymin = 0.0;
  ymax = 1.0;
  zmin = 0.0;
  zmax = 1.0;

  [ U, X, Y, Z ] = fd3d_poisson ( nx, ny, nz, xmin, xmax, ymin, ymax, zmin, ...
    zmax, @f, @g );
%
%  Compute the RMS error.
%
  err = 0.0;
  for i = 1 : nz
    for j = 1 : ny
      for k = 1 : nx
        err = err + ( U(i,j,k) - exact(X(i,j,k),Y(i,j,k),Z(i,j,k)) )^2;
      end
    end
  end
  err = sqrt ( err / nx / ny / nz );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Using a %d by %d by %d grid\n', nx, ny, nz );
  fprintf ( 1, '  The RMS error was %g\n', err );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'fd3d_poisson_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../fd3d_poisson' );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

function value = f ( x, y, z )

%*****************************************************************************80
%
%% f evaluates the right hand side of the Poisson equation.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 December 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X, Y, Z, the arguments.
%
%  Output:
%
%    real VALUE, the value of F(X,Y,Z).
%
  value = ...
    + 16.0 *        sin ( x.^2 + y.^2 ) ...
    + 16.0 * x.^2 * cos ( x.^2 + y.^2 ) ...
    + 16.0 * y.^2 * cos ( x.^2 + y.^2 ) ...
    + y.^2 .* sin ( y .* z ) ...
    + z.^2 .* sin ( y .* z );

  return
end
function value = g ( x, y, z )

%*****************************************************************************80
%
%% g evaluates the boundary conditions.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 December 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X, Y, Z, the arguments.
%
%  Output:
%
%    real VALUE, the value of G(X,Y,Z).
%
  value = exact ( x, y, z );

  return
end
function value = exact ( x, y, z )

%*****************************************************************************80
%
%% exact evaluates the exact solution.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 December 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real X, Y, Z, the arguments.
%
%  Output:
%
%    real VALUE, the value of the exact solution.
%
  value = 4.0 * cos ( x.^2 + y.^2 ) + sin ( y .* z );

  return
end
