comparison +time/Timestepper.m @ 16:f7975c054bc3

Improved progress indication for stepN
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 22 Sep 2015 14:25:59 +0200
parents b18d3d201a71
children 54055b32d516
comparison
equal deleted inserted replaced
15:16bad7c459da 16:f7975c054bc3
13 13
14 methods 14 methods
15 function [v,t] = stepN(obj,n,progress_bar) 15 function [v,t] = stepN(obj,n,progress_bar)
16 default_arg('progress_bar',false); 16 default_arg('progress_bar',false);
17 17
18 if progress_bar && n > 1500 18 if ~progress_bar
19 n1000 = floor(n/1000); 19 obj.stepN_without_progress(n);
20 else
21 obj.stepN_with_progress(n);
22 end
20 23
21 s = util.replace_string('',' %d %%',0); 24 v = obj.getV;
22 for i=1:n 25 t = obj.t;
23 obj.step(); 26 end
24 if mod(i,n1000) == 0 27
28 function stepN_without_progress(obj, n)
29 for i=1:n
30 obj.step();
31 end
32 end
33
34 function stepN_with_progress(obj, n)
35 FRAME_RATE = 20;
36
37 steps_to_update = 1;
38 steps_since_update = 0;
39 last_update = tic();
40 s = util.replace_string('',' %d %%',0);
41 for i=1:n
42 obj.step();
43
44 steps_since_update = steps_since_update + 1;
45
46 if steps_since_update >= steps_to_update
25 s = util.replace_string(s,' %.2f %%',i/n*100); 47 s = util.replace_string(s,' %.2f %%',i/n*100);
26 end 48
49 time_since_update = toc(last_update);
50 time_error = time_since_update - 1/FRAME_RATE;
51 time_per_step = time_since_update/steps_since_update;
52
53 steps_to_update = max(steps_to_update - 0.9*time_error/time_per_step ,1);
54
55 steps_since_update = 0;
56 last_update = tic();
27 end 57 end
28 s = util.replace_string(s,''); 58 end
59
60 s = util.replace_string(s,'');
61 end
62
63 function [v,t] = evolve(obj, tend, progress_bar)
64 default_arg('progress_bar',false)
65 if ~progress_bar
66 obj.evolve_without_progress(tend);
29 else 67 else
30 for i=1:n 68 obj.evolve_with_progress(tend);
31 obj.step();
32 end
33 end 69 end
34 v = obj.getV; 70 v = obj.getV;
35 t = obj.t; 71 t = obj.t;
36 end 72 end
37 73
38 function [v,t] = evolve(obj, tend, progress_bar) 74 function evolve_without_progress(obj, tend)
39 default_arg('progress_bar',false) 75 while obj.t < tend - obj.k/100
40 if progress_bar 76 obj.step();
41 obj.evolve_with_progress(tend);
42 else
43 obj.evolve_without_progress(tend);
44 end 77 end
45 v = obj.getV;
46 t = obj.t;
47 end 78 end
48 79
49 function evolve_with_progress(obj, tend) 80 function evolve_with_progress(obj, tend)
50 FRAME_RATE = 20; 81 FRAME_RATE = 20;
51
52 dt = tend-obj.t;
53 82
54 steps_to_update = 1; 83 steps_to_update = 1;
55 steps_since_update = 0; 84 steps_since_update = 0;
56 last_update = tic(); 85 last_update = tic();
57 s = util.replace_string('',' %d %%',0); 86 s = util.replace_string('',' %d %%',0);
72 steps_since_update = 0; 101 steps_since_update = 0;
73 last_update = tic(); 102 last_update = tic();
74 end 103 end
75 end 104 end
76 105
77 % if t < tend
78 % v = rk4.rungekutta_4(v, t, tend-t,F);
79 % end
80
81 s = util.replace_string(s,''); 106 s = util.replace_string(s,'');
82 end 107 end
83 108
84 function evolve_without_progress(obj, tend)
85 while obj.t < tend - obj.k/100
86 obj.step();
87 end
88 109
89 % if t < tend
90 % v = rk4.rungekutta_4(v, t, tend-t,F);
91 % end
92 end
93 end 110 end
94 end 111 end