Mercurial > repos > public > sbplib
diff +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 |
line wrap: on
line diff
--- a/+time/Timestepper.m Fri Sep 18 12:50:52 2015 +0200 +++ b/+time/Timestepper.m Fri Sep 18 13:30:19 2015 +0200 @@ -46,18 +46,30 @@ end function evolve_with_progress(obj, tend) + FRAME_RATE = 20; + dt = tend-obj.t; - n = floor(dt/obj.k); - n1000 = floor(n/1000); - i = 0; + steps_to_update = 1; + steps_since_update = 0; + last_update = tic(); s = util.replace_string('',' %d %%',0); while obj.t < tend - obj.k/100 obj.step(); - i = i + 1; - if mod(i,n1000) == 0 - s = util.replace_string(s,' %.2f %%',i/n*100); + steps_since_update = steps_since_update + 1; + + if steps_since_update >= steps_to_update + s = util.replace_string(s,' %.2f %%',obj.t/tend*100); + + time_since_update = toc(last_update); + time_error = time_since_update - 1/FRAME_RATE; + time_per_step = time_since_update/steps_since_update; + + steps_to_update = max(steps_to_update - 0.9*time_error/time_per_step ,1); + + steps_since_update = 0; + last_update = tic(); end end