Mercurial > repos > public > sbplib
changeset 993:44e7e497c3b7 feature/timesteppers
Make time.rk.General accept a butcher tableau instead of a string to choose method. String variant implemented as a static method
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 09 Jan 2019 11:14:16 +0100 |
parents | bbd165cc585c |
children | 2f89959fb9f0 |
files | +time/+rk/General.m +time/+rk/butcherTableauFromStr.m |
diffstat | 2 files changed, 22 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
diff -r bbd165cc585c -r 44e7e497c3b7 +time/+rk/General.m --- a/+time/+rk/General.m Wed Jan 09 10:59:38 2019 +0100 +++ b/+time/+rk/General.m Wed Jan 09 11:14:16 2019 +0100 @@ -13,10 +13,10 @@ methods - % Timesteps v_t = F(v,t), using the specified RK method from t = t0 with - % timestep dt and initial conditions v = v0 - function obj = General(F, dt, t0, v0, method, discreteData) - default_arg('method',"rk4"); + % Timesteps v_t = F(v,t), using the specified ButcherTableau + % from t = t0 with timestep dt and initial conditions v(0) = v0 + function obj = General(F, dt, t0, v0, bt, discreteData) + assertType(bt, 'time.rk.ButcherTableau') default_arg('discreteData', []); obj.F = F; obj.dt = dt; @@ -24,10 +24,8 @@ obj.v = v0; obj.n = 0; - % Extract the coefficients for the specified method - % used for the RK updates from the Butcher tableua. - [s,a,b,c] = time.rk.butcherTableauFromStr(method); - obj.coeffs = struct('s',s,'a',a,'b',b,'c',c); + assert(bt.isExplicit()) + obj.coeffs = struct('s',bt.nStages,'a',bt.a(:,1:end-1),'b',bt.b,'c',bt.c); if isempty(discreteData) obj.scheme = @(v,t,n) time.rk.rungekutta(v, t, dt, F, obj.coeffs); @@ -78,4 +76,19 @@ weights = repmat(b', N, 1); end end -end \ No newline at end of file + + methods(Static) + % TBD: Function name + function ts = methodFromStr(F, dt, t0, v0, methodStr, discreteData) + default_arg('discreteData', []); + + try + bt = time.rk.ButcherTableau.(method); + catch + error('Runge-Kutta method ''%s'' is not implemented', methodStr) + end + + ts = time.rk.General(F, dt, t0, v0, bt, discreteData); + end + end +end
diff -r bbd165cc585c -r 44e7e497c3b7 +time/+rk/butcherTableauFromStr.m --- a/+time/+rk/butcherTableauFromStr.m Wed Jan 09 10:59:38 2019 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -% Returns the coefficients used in a RK method as defined by a Butcher Tableau. -% -% @param method - string specifying which Runge-Kutta method to be used. -% @return s - number of stages -% @return a - coefficents for intermediate stages -% @return b - weights for summing stages -% @return c - time step coefficents for intermediate stages -function [s,a,b,c] = butcherTableauFromStr(method) - try - bt = time.rk.ButcherTableau.(method); - catch - error('Runge-Kutta method %s is not implemented', method) - end - - assert(bt.isExplicit()); - - s = bt.nStages(); - a = bt.a(:,1:end-1); - b = bt.b; - c = bt.c; -end