forked from csc-training/hpc-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevolve.c
More file actions
25 lines (20 loc) · 669 Bytes
/
evolve.c
File metadata and controls
25 lines (20 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <string.h>
void evolve(double *u, double *u_previous, int nx, int ny,
double a, double dt, double dx2, double dy2)
{
int i, j;
int ij, ip, im, jp, jm;
for (i=1; i < nx-1; i++)
for (j=1; j < ny-1; j++) {
// Linearisation for 2D array
ij = j + i*nx;
ip = j + (i+1)*nx;
im = j + (i-1)*nx;
jp = (j + 1) + i*nx;
jm = (j - 1) + i*nx;
u[ij] = u_previous[ij] + a * dt * (
(u_previous[ip] - 2*u_previous[ij] + u_previous[im]) / dx2 +
(u_previous[jp] - 2*u_previous[ij] + u_previous[jm]) / dy2 );
}
memcpy(u_previous, u, nx*ny*sizeof(double));
}