Mercurial > repos > public > sbplib
changeset 80:14bf01b7a068
Changed noname.animate and noname.Discretization to use a opt struct for timestepper options.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 25 Nov 2015 18:33:49 +0100 |
parents | 4cd77c7bdcaf |
children | 9c0192cf099f 3c39dd714fb6 |
files | +noname/Discretization.m +noname/animate.m default_field.m |
diffstat | 3 files changed, 41 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
diff -r 4cd77c7bdcaf -r 14bf01b7a068 +noname/Discretization.m --- a/+noname/Discretization.m Wed Nov 25 18:32:29 2015 +0100 +++ b/+noname/Discretization.m Wed Nov 25 18:33:49 2015 +0100 @@ -23,11 +23,12 @@ % Calculates a timestep for the discretization and a given timestepping method. % Can take order, differnt types of scaling in h, or other parameters in Discr into - % account. + % account. opt is a struct that among other things may contain % method -- time stepping method for which to give a timestep. % cfl -- [optioanal] a cfl constant to use to calculate the timetep. % if skipped getTimestep should use a precomputed value. - k = getTimestep(obj, method, cfl) + % k -- timestep to use + k = getTimestep(obj, opt) % getTimeSnapshot returns a struct which represents the solution in ts at current time. % if ts is empty or 0 a representation of the initial conditions be returned.
diff -r 4cd77c7bdcaf -r 14bf01b7a068 +noname/animate.m --- a/+noname/animate.m Wed Nov 25 18:32:29 2015 +0100 +++ b/+noname/animate.m Wed Nov 25 18:33:49 2015 +0100 @@ -4,15 +4,12 @@ % animate('',discr,tend) % animate('my_mov',discr,tend,time_mod,time_method) -function hand = animate(dirname,discretization,Tend, time_modifier,time_method) - makemovies = ~strcmp(dirname,''); - if makemovies - dirname = ['mov/' dirname]; - end +function hand = animate(discretization, time_modifier, Tend, dirname, opt) + default_arg('time_modifier',1); + default_arg('Tend', Inf); + default_arg('dirname',''); + default_arg('opt', []); - default_arg('Tend',Inf); - default_arg('time_modifier',1); - default_arg('time_method',[]); if time_modifier < 0 do_pause = true; @@ -21,24 +18,37 @@ do_pause = false; end + makemovies = ~strcmp(dirname,''); + if makemovies + dirname = ['mov/' dirname]; + end fprintf('Animating: %s\n',discretization.name); - fprintf('Tend : %.2f\n',Tend); fprintf('order : %d\n',discretization.order); fprintf('m : %d\n',size(discretization)); - fprintf('Creating time discretization'); - tic - ts = discretization.getTimestepper(time_method); - fprintf(' - done %fs\n', toc()) + + 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 @@ -57,15 +67,15 @@ if do_pause pause end - end - sol = discretization.getTimeSnapshot(0); - update(sol); + update(start_solution); - fprintf('Using time step k = %.6f\n',ts.k) - fprintf('System size: %d\n',size(discretization)) + fprintf('Using time step k = %.6f\n',ts.k); + fprintf('System size: %d\n',size(discretization)); % waitforbuttonpress - anim.animate(@G,0,Tend,time_modifier) + + anim.animate(@G, Tstart, Tend, time_modifier); + % str = util.replace_string(str,''); % if makemovies
diff -r 4cd77c7bdcaf -r 14bf01b7a068 default_field.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/default_field.m Wed Nov 25 18:33:49 2015 +0100 @@ -0,0 +1,7 @@ +function default_field(s, f, val) + if isfield(s,f) + return + end + s.(f) = val; + assignin('caller', inputname(1),s); +end \ No newline at end of file