sandbox/bugs/foreach_bnd.c
This simple code shows a problem with the usage of foreach_boundary when periodic boundary condition is applied in only one direction.
#define BGHOSTS 1
#include "grid/quadtree.h"
int main()
{
= 8;
L0 periodic(top);
(1 << 2);
init_grid
printf("%s \n","----------boundary iterator for left boundary-------------");
foreach_boundary(left)
{
printf("x:%g\ty:%g \n",x,y);
}
printf("%s\n","-----------actual left boundary------------" );
foreach_face(x)
{
if(0 == x)
printf("x:%g\ty:%g \n",x,y);
}
}
Running the above piece of code gives
----------boundary iterator for left boundary-------------
:0 y:-1
x:0 y:1
x:0 y:3
x:0 y:5
x-----------actual left boundary------------
:0 y:1
x:0 y:3
x:0 y:5
x:0 y:7 x
If the foreach_boundary() iterator works correctly, the position information between splitlines should be identical. However, the foreach_boundary() iterator trys to access the ghost cell instead of the actual cell in the domain. Clearly an offset exists in the foreach_boundary() iterator and its value is related to a macro named BGHOSTS.