view +noname/convergence.m @ 577:e45c9b56d50d feature/grids

Add an Empty grid class The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution. In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 07 Sep 2017 09:16:12 +0200
parents 3e1d8051e68e
children
line wrap: on
line source

% Reference is either a key or a function handle
function [q, e, h, runtime] = convergence(filename, errorFunc, reference, name, order, m, T)
    default_arg('errorFunc', @scheme.error1d);

    sf = SolutionFile(filename);


    % Generate convergence, error, and efficiency plots for each search key with more than one entry.
    for i = 1:length(m)
        key.name = name;
        key.order = order;
        key.m = m(i);
        key.T = T;

        entry = sf.get(key);

        [e(i),h(i)] = errorForEntry(key, entry, errorFunc, reference,T);
        runtime(i) = entry.runtime;

    end
    q = convergence(e,h);
end

function [e, h] = errorForEntry(key,entry, errorFunc, reference,T)
    v_repr = entry.repr;
    discr = entry.discr;

    % Get the solution to be compared
    v = v_repr.v;

    % Get the reference solution vector
    if isa(reference,'function_handle');
        x = v_repr.grid.points();
        v_ref = reference(x,T);
    else
        % Downsample the reference solution
        v_ref = reference.grid.restrictFunc(reference.v, v_repr.grid);
    end

    e = errorFunc(discr,v, v_ref);
    h = discr.h;
end