Mercurial > repos > public > sbplib
comparison +rv/+time/RungeKuttaRvInstage.m @ 1181:9ac86ccfd6a1 feature/rv
Move instage rungekutta time stepping to RungekuttaRvInstage
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 05 Jul 2019 16:51:05 +0200 |
parents | d02e5b8a0b24 |
children |
comparison
equal
deleted
inserted
replaced
1180:beecb580c5bf | 1181:9ac86ccfd6a1 |
---|---|
42 obj.v = rv.time.rungekuttaRV(obj.v, obj.t, obj.k, obj.F, obj.RV, obj.DvDt, obj.coeffs); | 42 obj.v = rv.time.rungekuttaRV(obj.v, obj.t, obj.k, obj.F, obj.RV, obj.DvDt, obj.coeffs); |
43 obj.t = obj.t + obj.k; | 43 obj.t = obj.t + obj.k; |
44 obj.n = obj.n + 1; | 44 obj.n = obj.n + 1; |
45 end | 45 end |
46 end | 46 end |
47 | |
48 % Takes one time step of size dt using the rungekutta method | |
49 % starting from v and where the function F(v,t,RV) gives the | |
50 % time derivatives. coeffs is a struct holding the RK coefficients | |
51 % for the specific method. RV is the residual viscosity which is updated | |
52 % in between the stages and after the updated solution is computed. | |
53 methods (Static) | |
54 function v = rungekuttaRV(v, t , dt, F, RV, DvDt, coeffs) | |
55 % Move one stage outside to avoid branching for updating the | |
56 % residual inside the loop. | |
57 k = zeros(length(v), coeffs.s); | |
58 k(:,1) = F(v,t,RV.evaluateViscosity(v,DvDt(v))); | |
59 | |
60 % Compute the intermediate stages k | |
61 for i = 2:coeffs.s | |
62 u = v; | |
63 for j = 1:i-1 | |
64 u = u + dt*coeffs.a(i,j)*k(:,j); | |
65 end | |
66 k(:,i) = F(u,t+coeffs.c(i)*dt, RV.evaluateViscosity(u,DvDt(u))); | |
67 end | |
68 | |
69 % Compute the updated solution as a linear combination | |
70 % of the intermediate stages. | |
71 u = v; | |
72 for i = 1:coeffs.s | |
73 u = u + dt*coeffs.b(i)*k(:,i); | |
74 end | |
75 v = u; | |
76 end | |
77 | |
78 | |
47 end | 79 end |