Mercurial > repos > public > sbplib
comparison +rv/+time/rungekuttaRV.m @ 1152:010bb2677230 feature/rv
Clean up in +rv/+time. Make the time stepping more efficient by not storing unnessecary properties in the RK-RV time steppers
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Tue, 05 Mar 2019 10:53:34 +0100 |
parents | 2d7c1333bd6c |
children |
comparison
equal
deleted
inserted
replaced
1151:03ecf18d035f | 1152:010bb2677230 |
---|---|
5 % in between the stages and after the updated solution is computed. | 5 % in between the stages and after the updated solution is computed. |
6 function v = rungekuttaRV(v, t , dt, F, RV, DvDt, coeffs) | 6 function v = rungekuttaRV(v, t , dt, F, RV, DvDt, coeffs) |
7 % Move one stage outside to avoid branching for updating the | 7 % Move one stage outside to avoid branching for updating the |
8 % residual inside the loop. | 8 % residual inside the loop. |
9 k = zeros(length(v), coeffs.s); | 9 k = zeros(length(v), coeffs.s); |
10 k(:,1) = F(v,t,RV.evaluate(v,DvDt(v))); | 10 k(:,1) = F(v,t,RV.evaluateViscosity(v,DvDt(v))); |
11 | 11 |
12 % Compute the intermediate stages k | 12 % Compute the intermediate stages k |
13 for i = 2:coeffs.s | 13 for i = 2:coeffs.s |
14 u = v; | 14 u = v; |
15 for j = 1:i-1 | 15 for j = 1:i-1 |
16 u = u + dt*coeffs.a(i,j)*k(:,j); | 16 u = u + dt*coeffs.a(i,j)*k(:,j); |
17 end | 17 end |
18 %RV.update(0.5*(u+v),(u-v)/(coeffs.c(i)*dt)); % Crank-Nicholson for time discretization | 18 k(:,i) = F(u,t+coeffs.c(i)*dt, RV.evaluateViscosity(u,DvDt(u))); |
19 k(:,i) = F(u,t+coeffs.c(i)*dt, RV.evaluate(u,DvDt(u))); | |
20 end | 19 end |
21 | 20 |
22 % Compute the updated solution as a linear combination | 21 % Compute the updated solution as a linear combination |
23 % of the intermediate stages. | 22 % of the intermediate stages. |
24 u = v; | 23 u = v; |
25 for i = 1:coeffs.s | 24 for i = 1:coeffs.s |
26 u = u + dt*coeffs.b(i)*k(:,i); | 25 u = u + dt*coeffs.b(i)*k(:,i); |
27 end | 26 end |
28 %RV.update(0.5*(u+v),(u-v)/dt); % Crank-Nicholson for time discretization | |
29 v = u; | 27 v = u; |
30 end | 28 end |