view +noname/animate.m @ 87:0a29a60e0b21

In Curve: Rearranged for speed. arc_length_fun is now a property of Curve. If it is not supplied, it is computed via the derivative and spline fitting. Switching to the arc length parameterization is much faster now. The new stuff can be tested with testArcLength.m (which should be deleted after that).
author Martin Almquist <martin.almquist@it.uu.se>
date Sun, 29 Nov 2015 22:23:09 +0100
parents 14bf01b7a068
children b7f40a0c6476
line wrap: on
line source

% animate(dirname,discretization,Tend, time_modifier,time_method)
%
% Example:
%      animate('',discr,tend)
%      animate('my_mov',discr,tend,time_mod,time_method)

function hand = animate(discretization, time_modifier, Tend, dirname, opt)
    default_arg('time_modifier',1);
    default_arg('Tend', Inf);
    default_arg('dirname','');
    default_arg('opt', []);


    if time_modifier < 0
        do_pause = true;
        time_modifier = -time_modifier;
    else
        do_pause = false;
    end

    makemovies = ~strcmp(dirname,'');
    if makemovies
        dirname = ['mov/' dirname];
    end

    fprintf('Animating: %s\n',discretization.name);
    fprintf('order    : %d\n',discretization.order);
    fprintf('m        : %d\n',size(discretization));


    ts = discretization.getTimestepper(opt);

    if numel(Tend) == 2
        Tstart = Tend(1);
        Tend = Tend(2);


        fprintf('Evolving to starting time: ');
        ts.evolve(Tstart,'true');
        fprintf(' - Done\n');
        start_solution = discretization.getTimeSnapshot(ts);
    else
        Tstart = 0;
        start_solution = discretization.getTimeSnapshot(0);
    end

    [update, figure_handle] = discretization.setupPlot('animation');
    if makemovies
        save_frame = anim.setup_fig_mov(figure_handle,dirname);
    end

    % Initialize loop
    str = '';
    % Loop function
    function next_t = G(next_t)
        ts.evolve(next_t);
        sol = discretization.getTimeSnapshot(ts);
        update(sol);
        drawnow
        % waitforbuttonpress
        if makemovies
            save_frame();
        end
        % pause(0.1)
        str = util.replace_string(str,'t = %.5f',ts.t);

        if do_pause
            pause
        end
    end
    update(start_solution);

    fprintf('Using time step k = %.6f\n',ts.k);
    fprintf('System size: %d\n',size(discretization));
    % waitforbuttonpress

    anim.animate(@G, Tstart, Tend, time_modifier);

    % str = util.replace_string(str,'');

    % if makemovies
        % fprintf('Generating movies...\n')
        % system(sprintf('bash make_movie.sh %s',dirname));
    % end
end