comparison +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
comparison
equal deleted inserted replaced
845:1e057b0f2fed 846:c6fcee3fcf1b
1 % Takes one time step of size dt using the rungekutta method
2 % starting from v_0 and where the function F(v,t,RV) gives the
3 % time derivatives. coeffs is a struct holding the RK coefficients
4 % for the specific method. RV is the residual viscosity which is updated
5 % in between the stages and after the updated solution is computed.
6 function v = rungekuttaRV(v, t , dt, F, RV, coeffs)
7
8 % Move one stage outside to avoid branching for updating the
9 % residual inside the loop.
10 k = zeros(length(v), coeffs.s);
11 k(:,1) = F(v,t,RV.getViscosity());
12
13 % Compute the intermediate stages k
14 for i = 2:coeffs.s
15 u = v;
16 for j = 1:i-1
17 u = u + dt*coeffs.a(i,j)*k(:,j);
18 end
19 RV.update(u,v,coeffs.c(i)*dt);
20 k(:,i) = F(u,t+coeffs.c(i)*dt, RV.getViscosity());
21 end
22
23 % Compute the updated solution as a linear combination
24 % of the intermediate stages.
25 u = v;
26 for i = 1:coeffs.s
27 u = u + dt*coeffs.b(i)*k(:,i);
28 end
29 RV.update(u,v,dt);
30 v = u;
31 end