Mercurial > repos > public > sbplib
comparison +time/Timestepper.m @ 0:48b6fb693025
Initial commit.
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Thu, 17 Sep 2015 10:12:50 +0200 |
| parents | |
| children | 5205251db8c3 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:48b6fb693025 |
|---|---|
| 1 classdef Timestepper < handle | |
| 2 properties (Abstract) | |
| 3 t | |
| 4 k | |
| 5 n | |
| 6 end | |
| 7 | |
| 8 methods (Abstract) | |
| 9 [v,t] = getV(obj) | |
| 10 obj = step(obj) | |
| 11 end | |
| 12 | |
| 13 | |
| 14 methods | |
| 15 function [v,t] = stepN(obj,n,progress_bar) | |
| 16 | |
| 17 if progress_bar && n > 1500 | |
| 18 n1000 = floor(n/1000); | |
| 19 | |
| 20 s = util.replace_string('',' %d %%',0); | |
| 21 for i=1:n | |
| 22 obj.step(); | |
| 23 if mod(i,n1000) == 0 | |
| 24 s = util.replace_string(s,' %.2f %%',i/n*100); | |
| 25 end | |
| 26 end | |
| 27 s = util.replace_string(s,''); | |
| 28 else | |
| 29 for i=1:n | |
| 30 obj.step(); | |
| 31 end | |
| 32 end | |
| 33 v = obj.getV; | |
| 34 t = obj.t; | |
| 35 end | |
| 36 | |
| 37 function [v,t] = evolve(obj, tend, progress_bar) | |
| 38 default_arg('progress_bar',false) | |
| 39 if progress_bar | |
| 40 obj.evolve_with_progress(tend); | |
| 41 else | |
| 42 obj.evolve_without_progress(tend); | |
| 43 end | |
| 44 v = obj.getV; | |
| 45 t = obj.t; | |
| 46 end | |
| 47 | |
| 48 function evolve_with_progress(obj, tend) | |
| 49 dt = tend-obj.t; | |
| 50 n = floor(dt/obj.k); | |
| 51 n1000 = floor(n/1000); | |
| 52 | |
| 53 i = 0; | |
| 54 s = util.replace_string('',' %d %%',0); | |
| 55 while obj.t < tend - obj.k/100 | |
| 56 obj.step(); | |
| 57 | |
| 58 i = i + 1; | |
| 59 if mod(i,n1000) == 0 | |
| 60 s = util.replace_string(s,' %.2f %%',i/n*100); | |
| 61 end | |
| 62 end | |
| 63 | |
| 64 % if t < tend | |
| 65 % v = rk4.rungekutta_4(v, t, tend-t,F); | |
| 66 % end | |
| 67 | |
| 68 s = util.replace_string(s,''); | |
| 69 end | |
| 70 | |
| 71 function evolve_without_progress(obj, tend) | |
| 72 while obj.t < tend - obj.k/100 | |
| 73 obj.step(); | |
| 74 end | |
| 75 | |
| 76 % if t < tend | |
| 77 % v = rk4.rungekutta_4(v, t, tend-t,F); | |
| 78 % end | |
| 79 end | |
| 80 end | |
| 81 end |
