Mercurial > repos > public > sbplib
diff +time/+rk/rungekuttaRV.m @ 846:c6fcee3fcf1b feature/burgers1d
Add generalized RungeKutta and RungeKuttaRV class which extracts its coefficients from a butcher tableau, specified on the scheme.
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 20 Sep 2018 17:51:19 +0200 |
parents | |
children | 1c6f1595bb94 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+time/+rk/rungekuttaRV.m Thu Sep 20 17:51:19 2018 +0200 @@ -0,0 +1,31 @@ +% Takes one time step of size dt using the rungekutta method +% starting from v_0 and where the function F(v,t,RV) gives the +% time derivatives. coeffs is a struct holding the RK coefficients +% for the specific method. RV is the residual viscosity which is updated +% in between the stages and after the updated solution is computed. +function v = rungekuttaRV(v, t , dt, F, RV, coeffs) + + % Move one stage outside to avoid branching for updating the + % residual inside the loop. + k = zeros(length(v), coeffs.s); + k(:,1) = F(v,t,RV.getViscosity()); + + % Compute the intermediate stages k + for i = 2:coeffs.s + u = v; + for j = 1:i-1 + u = u + dt*coeffs.a(i,j)*k(:,j); + end + RV.update(u,v,coeffs.c(i)*dt); + k(:,i) = F(u,t+coeffs.c(i)*dt, RV.getViscosity()); + end + + % Compute the updated solution as a linear combination + % of the intermediate stages. + u = v; + for i = 1:coeffs.s + u = u + dt*coeffs.b(i)*k(:,i); + end + RV.update(u,v,dt); + v = u; +end