src/test/mpi-restriction.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
#define BGHOSTS 2

int main (int argc, char * argv[])
{
  origin (-0.6, -0.6, -0.6);
  init_grid (1);
  int depth = argc > 1 ? atoi(argv[1]) : 4;
  refine (level < depth - 2 ||
	  level <= depth*(1. - sqrt(sq(x) + sq(y) + sq(z))));
  
  scalar s[];
  foreach()
    s[] = 1;
  boundary ({s});

  output_cells (stdout);

  // check boundary conditions on leaves
  foreach()
    foreach_neighbor()
      assert (s[] == 1.);

  // check boundary conditions on levels
  scalar s1[];
  for (int l = 0; l <= depth(); l++) {
    foreach_level (l)
      s1[] = 2;
    boundary_level ({s1}, l);
    foreach_level_or_leaf (l)
      foreach_neighbor(1) // fixme: shoud work with foreach_neighbor()
        assert (s1[] == 2.);
  }
  
  // check restriction
  for (int l = 0; l < depth; l++)
    foreach_coarse_level (l) {
      fprintf (stderr, "res %g %g %g %g %d\n", x, y, z, s[], level);
      assert (s[] == 1.);
    }

  // check face traversal
  foreach_face() {
    fprintf (stderr, "face %g %g %g %g\n", x, y, z, s[] - s[-1]);
    assert (s[] == s[-1]);
  }
}