Mercurial > repos > public > sbplib
comparison +time/Timestepper.m @ 3:5205251db8c3
Added some smartness to evolve with progress.`
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 18 Sep 2015 13:30:19 +0200 |
parents | 48b6fb693025 |
children | b18d3d201a71 |
comparison
equal
deleted
inserted
replaced
2:bce9e28c1e26 | 3:5205251db8c3 |
---|---|
44 v = obj.getV; | 44 v = obj.getV; |
45 t = obj.t; | 45 t = obj.t; |
46 end | 46 end |
47 | 47 |
48 function evolve_with_progress(obj, tend) | 48 function evolve_with_progress(obj, tend) |
49 FRAME_RATE = 20; | |
50 | |
49 dt = tend-obj.t; | 51 dt = tend-obj.t; |
50 n = floor(dt/obj.k); | |
51 n1000 = floor(n/1000); | |
52 | 52 |
53 i = 0; | 53 steps_to_update = 1; |
54 steps_since_update = 0; | |
55 last_update = tic(); | |
54 s = util.replace_string('',' %d %%',0); | 56 s = util.replace_string('',' %d %%',0); |
55 while obj.t < tend - obj.k/100 | 57 while obj.t < tend - obj.k/100 |
56 obj.step(); | 58 obj.step(); |
57 | 59 |
58 i = i + 1; | 60 steps_since_update = steps_since_update + 1; |
59 if mod(i,n1000) == 0 | 61 |
60 s = util.replace_string(s,' %.2f %%',i/n*100); | 62 if steps_since_update >= steps_to_update |
63 s = util.replace_string(s,' %.2f %%',obj.t/tend*100); | |
64 | |
65 time_since_update = toc(last_update); | |
66 time_error = time_since_update - 1/FRAME_RATE; | |
67 time_per_step = time_since_update/steps_since_update; | |
68 | |
69 steps_to_update = max(steps_to_update - 0.9*time_error/time_per_step ,1); | |
70 | |
71 steps_since_update = 0; | |
72 last_update = tic(); | |
61 end | 73 end |
62 end | 74 end |
63 | 75 |
64 % if t < tend | 76 % if t < tend |
65 % v = rk4.rungekutta_4(v, t, tend-t,F); | 77 % v = rk4.rungekutta_4(v, t, tend-t,F); |