% Script file to examine the convergence properties of the polynomial tests
% in polynomialGridTest as we refine the angle between elements in the
% stencil (while keeping the effective dx constant).
%
% Runs a sequence of grid sizes and ratios, stencil radii and shapes, with
% and without interpolation to examine how the error behaves.
%
% Data is summarized textually in a format suitable for inclusion in a LaTeX
% table.

% Copyright 2007 Ian M. Mitchell (mitchell@cs.ubc.ca).
% This software is used, copied and distributed under the licensing 
%   agreement contained in the file LICENSE in the top directory of 
%   the distribution.
%
% Ian Mitchell, 6/15/07

  % What grid sizes and ratios?  Note that we specify grid size for each
  % grid_ratio, so that every ratio need not use the same values for this
  % other variable.
  grid_ratios = [ 1; 2; 5 ];
  grid_sizes = 100;
  stencil_sizes = { (1:5)'; (1:5)'; (1:4)' };
  stencil_shapes = { 'circle'; 'square' };

  which_polynomial = 1;
  interpolate = 1;
  show_plots = 0;

  fprintf('\n');

  for i_ratio = 1 : length(grid_ratios)
    for i_grid = 1 : length(grid_sizes)
      for i_stencil_size = 1 : length(stencil_sizes{i_ratio})
        grid_size = 1 + (grid_sizes(i_grid) ...
                         * stencil_sizes{i_ratio}(i_stencil_size) ...
                         * [ grid_ratios(i_ratio); 1 ]);

        % To reduce clutter in the table, only show ratio when necessary.
        
        if(i_stencil_size == 1)
          fprintf('\n$1:%d$ & ', grid_ratios(i_ratio));
        else
          fprintf('\n      & ');
        end

          
        fprintf('$%d$ & $%d \\cross %d$', ...
                stencil_sizes{i_ratio}(i_stencil_size), ...
                grid_size(1), grid_size(2));

        for i_stencil_shape = 1 : length(stencil_shapes);
        
          errs = polynomialGridTest(grid_size, which_polynomial, ...
                                    stencil_sizes{i_ratio}(i_stencil_size), ...
                                    stencil_shapes{i_stencil_shape}, ...
                                    interpolate, show_plots);

          fprintf(' & %5.3f & %5.3f', errs.one, errs.inf);
        end
        % End a line of the table.
        fprintf(' \\\\')
      end
    end
  end

  fprintf('\n');
  
  % Table columns are ratio dx, grid size, stencil_size, and then L1 & Linf
  % error for each stencil_shape.
  
