forked from markcmiller86/hello-numerical-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdufrank.C
25 lines (21 loc) · 850 Bytes
/
dufrank.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
#include "heat.H"
bool // false if unstable, true otherwise
update_solution_dufrank(
int n, // number of samples
Number *uk, // new array of u(x,k) to compute/return
Number const *uk1, // array u(x,k-1) computed @ -1 time index ago
Number const *uk2, // array u(x,k-2) computed @ -2 time index ago
Number alpha, // thermal diffusivity
Number dx, Number dt, // spacing in space, x, and time, t.
Number bc0, Number bc1) // boundary conditions @ x=0 & x=Lx
{
Number r = alpha * dt / (dx * dx);
Number q = 1 / (1+r);
// FTCS update algorithm
for (int i = 1; i < n-1; i++)
uk[i] = q * (1-r) * uk2[i] + q * r * (uk1[i+1] + uk1[i-1]);
// enforce boundary conditions
uk[0 ] = bc0;
uk[n-1] = bc1;
return true;
}