generated from bssw-tutorial/hello-numerical-world
-
Notifications
You must be signed in to change notification settings - Fork 8
/
upwind15.C
27 lines (24 loc) · 833 Bytes
/
upwind15.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "heat.H"
bool
update_solution_upwind15(int n, Double *curr, Double const *last,
Double alpha, Double dx, Double dt,
Double bc_0, Double bc_1)
{
Double const f2 = 1.0/24;
Double const f1 = 1.0/6;
Double const f0 = 1.0/4;
Double const k = alpha * alpha * dt / (dx * dx);
Double const k2 = k*k;
int i;
curr[0 ] = bc_0;
curr[1 ] = last[1 ] + k * (last[0 ] - 2 * last[1 ] + last[2 ]);
curr[n-2] = last[n-2] + k * (last[n-3] - 2 * last[n-2] + last[n-1]);
curr[n-1] = bc_1;
for (i = 2; i < n-2; i++)
curr[i] = f2*(12*k2 -2*k )*last[i-2]
+f2*(12*k2 -2*k )*last[i+2]
-f1*(12*k2 -8*k )*last[i-1]
-f1*(12*k2 -8*k )*last[i+1]
+f0*(12*k2 -10*k +4)*last[i ];
return true;
}