Mercurial > repos > public > sbplib
comparison +rv/+time/rungekuttaRV.m @ 1033:037f203b9bf5 feature/burgers1d
Merge with branch feature/advectioRV to utilize the +rv package
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 17 Jan 2019 10:44:12 +0100 |
parents | 2d7c1333bd6c |
children | 010bb2677230 |
comparison
equal
deleted
inserted
replaced
854:18162a0a5bb5 | 1033:037f203b9bf5 |
---|---|
1 % Takes one time step of size dt using the rungekutta method | |
2 % starting from v 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, DvDt, coeffs) | |
7 % Move one stage outside to avoid branching for updating the | |
8 % residual inside the loop. | |
9 k = zeros(length(v), coeffs.s); | |
10 k(:,1) = F(v,t,RV.evaluate(v,DvDt(v))); | |
11 | |
12 % Compute the intermediate stages k | |
13 for i = 2:coeffs.s | |
14 u = v; | |
15 for j = 1:i-1 | |
16 u = u + dt*coeffs.a(i,j)*k(:,j); | |
17 end | |
18 %RV.update(0.5*(u+v),(u-v)/(coeffs.c(i)*dt)); % Crank-Nicholson for time discretization | |
19 k(:,i) = F(u,t+coeffs.c(i)*dt, RV.evaluate(u,DvDt(u))); | |
20 end | |
21 | |
22 % Compute the updated solution as a linear combination | |
23 % of the intermediate stages. | |
24 u = v; | |
25 for i = 1:coeffs.s | |
26 u = u + dt*coeffs.b(i)*k(:,i); | |
27 end | |
28 %RV.update(0.5*(u+v),(u-v)/dt); % Crank-Nicholson for time discretization | |
29 v = u; | |
30 end |