Mercurial > repos > public > sbplib
comparison +noname/animate.m @ 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 | 1edee9e1ea41 |
| children | b7f40a0c6476 |
comparison
equal
deleted
inserted
replaced
| 79:4cd77c7bdcaf | 80:14bf01b7a068 |
|---|---|
| 2 % | 2 % |
| 3 % Example: | 3 % Example: |
| 4 % animate('',discr,tend) | 4 % animate('',discr,tend) |
| 5 % animate('my_mov',discr,tend,time_mod,time_method) | 5 % animate('my_mov',discr,tend,time_mod,time_method) |
| 6 | 6 |
| 7 function hand = animate(dirname,discretization,Tend, time_modifier,time_method) | 7 function hand = animate(discretization, time_modifier, Tend, dirname, opt) |
| 8 makemovies = ~strcmp(dirname,''); | 8 default_arg('time_modifier',1); |
| 9 if makemovies | 9 default_arg('Tend', Inf); |
| 10 dirname = ['mov/' dirname]; | 10 default_arg('dirname',''); |
| 11 end | 11 default_arg('opt', []); |
| 12 | 12 |
| 13 default_arg('Tend',Inf); | |
| 14 default_arg('time_modifier',1); | |
| 15 default_arg('time_method',[]); | |
| 16 | 13 |
| 17 if time_modifier < 0 | 14 if time_modifier < 0 |
| 18 do_pause = true; | 15 do_pause = true; |
| 19 time_modifier = -time_modifier; | 16 time_modifier = -time_modifier; |
| 20 else | 17 else |
| 21 do_pause = false; | 18 do_pause = false; |
| 22 end | 19 end |
| 23 | 20 |
| 21 makemovies = ~strcmp(dirname,''); | |
| 22 if makemovies | |
| 23 dirname = ['mov/' dirname]; | |
| 24 end | |
| 24 | 25 |
| 25 fprintf('Animating: %s\n',discretization.name); | 26 fprintf('Animating: %s\n',discretization.name); |
| 26 fprintf('Tend : %.2f\n',Tend); | |
| 27 fprintf('order : %d\n',discretization.order); | 27 fprintf('order : %d\n',discretization.order); |
| 28 fprintf('m : %d\n',size(discretization)); | 28 fprintf('m : %d\n',size(discretization)); |
| 29 | 29 |
| 30 fprintf('Creating time discretization'); | 30 |
| 31 tic | 31 ts = discretization.getTimestepper(opt); |
| 32 ts = discretization.getTimestepper(time_method); | 32 |
| 33 fprintf(' - done %fs\n', toc()) | 33 if numel(Tend) == 2 |
| 34 Tstart = Tend(1); | |
| 35 Tend = Tend(2); | |
| 36 | |
| 37 | |
| 38 fprintf('Evolving to starting time: '); | |
| 39 ts.evolve(Tstart,'true'); | |
| 40 fprintf(' - Done\n'); | |
| 41 start_solution = discretization.getTimeSnapshot(ts); | |
| 42 else | |
| 43 Tstart = 0; | |
| 44 start_solution = discretization.getTimeSnapshot(0); | |
| 45 end | |
| 34 | 46 |
| 35 [update, figure_handle] = discretization.setupPlot('animation'); | 47 [update, figure_handle] = discretization.setupPlot('animation'); |
| 36 | |
| 37 if makemovies | 48 if makemovies |
| 38 save_frame = anim.setup_fig_mov(figure_handle,dirname); | 49 save_frame = anim.setup_fig_mov(figure_handle,dirname); |
| 39 end | 50 end |
| 40 | |
| 41 | 51 |
| 42 % Initialize loop | 52 % Initialize loop |
| 43 str = ''; | 53 str = ''; |
| 44 % Loop function | 54 % Loop function |
| 45 function next_t = G(next_t) | 55 function next_t = G(next_t) |
| 55 str = util.replace_string(str,'t = %.5f',ts.t); | 65 str = util.replace_string(str,'t = %.5f',ts.t); |
| 56 | 66 |
| 57 if do_pause | 67 if do_pause |
| 58 pause | 68 pause |
| 59 end | 69 end |
| 70 end | |
| 71 update(start_solution); | |
| 60 | 72 |
| 61 end | 73 fprintf('Using time step k = %.6f\n',ts.k); |
| 62 sol = discretization.getTimeSnapshot(0); | 74 fprintf('System size: %d\n',size(discretization)); |
| 63 update(sol); | 75 % waitforbuttonpress |
| 64 | 76 |
| 65 fprintf('Using time step k = %.6f\n',ts.k) | 77 anim.animate(@G, Tstart, Tend, time_modifier); |
| 66 fprintf('System size: %d\n',size(discretization)) | 78 |
| 67 % waitforbuttonpress | |
| 68 anim.animate(@G,0,Tend,time_modifier) | |
| 69 % str = util.replace_string(str,''); | 79 % str = util.replace_string(str,''); |
| 70 | 80 |
| 71 % if makemovies | 81 % if makemovies |
| 72 % fprintf('Generating movies...\n') | 82 % fprintf('Generating movies...\n') |
| 73 % system(sprintf('bash make_movie.sh %s',dirname)); | 83 % system(sprintf('bash make_movie.sh %s',dirname)); |
