sandbox/bugs/boundary_2_neumann.c

MWE: second row of ghost cells is wrong with neumann conditions

#define BGHOSTS 2

This minimum working example show that the command lines s[left] = neumann(a) followed by boundary ({s}) imposes the same value in the first and second row of ghost cells.

int main()
{
  init_grid (4);
  output_cells (stdout);

  scalar s[];

  s[left] = neumann(1.);

  foreach()
    s[] = 0.;

  boundary ({s});

  foreach()
    fprintf (stderr, "%g %g %g\n", x, y, s[]);
  foreach_boundary(left)
    for (int i = -2; i < 0; i++)
      fprintf (stderr, "%g %g %g\n", x + i*Δ, y, s[i]);
}

Outputs

In the second row of cells, the value of s should be 0.5 instead of 0.25. This comes from the definition of the neuman command in common.h:

@define neumann(x) (Delta*(x) + val(_s,0,0,0))

which does not distinguish the first and second row of ghost cells and I do not see how to do it. I didn’t find where boundary() is defined and I don’t know how to test if we are in the first or second row of ghost cells.

Second row of ghost cells is wrong

Second row of ghost cells is wrong