Mercurial > repos > public > sbplib
comparison +rv/+time/rungekuttaRV.m @ 1012:1e437c9e5132 feature/advectionRV
Create residual viscosity package +rv and generalize the ResidualViscosity class
- Generalize residual viscosity, by passing user-defined flux and calculating the time derivative outside of the update.
- Create separate RungekuttaRV specifically using interior RV updates
- Separate the artifical dissipation operator from the scheme AdvectionRV1D so that the same scheme can be reused for creating the diff op used by the ResidualViscosity class
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Wed, 05 Dec 2018 13:44:10 +0100 |
parents | +time/+rk/rungekuttaRV.m@1c6f1595bb94 |
children | 2d7c1333bd6c |
comparison
equal
deleted
inserted
replaced
1011:e0560bc4fb7d | 1012:1e437c9e5132 |
---|---|
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, 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.getViscosity()); | |
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.getViscosity()); | |
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 |