foreach_boundary (top) {
// find the corresponding x,y,z at the bottom boundary
// if x - shift < X0, we need to apply left,right periodic bc
double x_interp = X0 + fmod((x - shift - X0 + L0), L0);
double y_interp = Y0 + Delta/2;
// u.x[0,1] = interpolate(u.x, x_interp, y_interp, z);
u.y[0,1] = interpolate(u_temp.y, x_interp, y_interp, z);
// u.z[0,1] = interpolate(u.z, x_interp, y_interp, z);
uf.y[] = 0.5*(u.y[] + u.y[0,1]);
uf.y[0,1] = interpolate(u_temp.y, x_interp, Y0 + Delta, z);
// check interpolate value
if (fabs(uf.y[]) > 1e6 || fabs(uf.y[0,1]) > 1e6) {
fprintf(stderr, "Top: x,y,z,uf.y[],uf.y[0,1]:%g,%g,%g,%g,%g\n", x,y,z,uf.y[],uf.y[0,1]);
}
}
foreach_boundary (bottom) {
// find the corresponding x,y,z at the top boundary
// if x + shift > X0 + Lx, we need to apply left,right periodic bc
double x_edge = X0 + fmod((x + shift - X0 + L0), L0);
double y_edge = Y0 + L0 - Delta/2; // y center at the top cell
// u.x[0,-1] = interpolate(u.x, x_edge, y_edge, z);
u.y[0,-1] = interpolate(u_temp.y, x_edge, y_edge, z);
// u.z[0,-1] = interpolate(u.z, x_edge, y_edge, z);
uf.y[] = 0.5*(u.y[] + u.y[0,-1]);
uf.y[0,-1] = interpolate(u_temp.y, x_edge, Y0 + L0 - Delta, z);
// check interpolate value
if (fabs(uf.y[]) > 1e6 || fabs(uf.y[0,-1]) > 1e6) {
fprintf(stderr, "Bottom: dt,x_edge,x,y,z,uf.y[],uf.y[0,-1],u.y[],u.y[0,-1]:%g,%g,%g,%g,%g,%g,%g,%g,%g\n", dt,x_edge,x,y,z,uf.y[],uf.y[0,-1],u.y[],u.y[0,-1]);
}
}
}