Mercurial > repos > public > sbplib
diff +time/+rk/General.m @ 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 | 10c5eda235b7 |
line wrap: on
line diff
--- 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