-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep0.c
56 lines (46 loc) · 1.4 KB
/
step0.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "automaton.h"
#include "args.h"
void step0(inst instance, grid *g)
{
size_t n = g->n;
size_t m = g->m;
char *b = malloc(256);
double sqspeed = (g->v)*(g->v);
grid tmp, current;
new_grid(&tmp, g->n, g->m, g->v);
new_grid(¤t, g->n, g->m, g->v);
#ifdef DEBUG
printf("sqspeed: %f\nn, m = %zu %zu\n", sqspeed, n, m);
#endif
copy_grid(g, ¤t);
dump_grid("current", ¤t);
printf("\t\t\t%f\n", current.data[34+39*256].u);
for(int s = 0; s < instance.iteration; s++)
{
for(size_t i = 0; i < n; i++)
{
for(size_t j = 0; j < m; j++)
{
tmp.data[j+i*m].u = current.data[j+i*m].u + (current.data[j+i*m].v * instance.dt);
tmp.data[j+i*m].v = current.data[j+i*m].v + sqspeed * (current.data[j+((i+1) % n)*m].u + current.data[j+((n+i-1) % n)*m].u + current.data[((j+1) % m) + i*m].u + current.data[((m+j-1) % m) + i*m].u - (4 * current.data[j+i*m].u)) * instance.dt;
}
}
if(instance.alldump != NULL)
{
sprintf(b, instance.alldump, s);
dump_grid(b, &tmp);
}
// printf("%f %f -> %f %f\n", current.data[38+38*n].u, current.data[38+38*n].v, tmp.data[38+38*n].u, tmp.data[38+38*n].v);
copy_grid(&tmp, ¤t);
}
if(instance.lastdump != NULL)
{
dump_grid(instance.lastdump, ¤t);
}
free(tmp.data);
free(current.data);
free(b);
}