[multigrid] resid routine
Heimdall
06-07-2008, 05:04 AM
Hello,
I'm writing a multigrid solver for the following equation :
u - mu*Laplacian(u) = f
(in 2D)
I don't understand why in the routine resid() the residual is set to zero on the boundaries.
I mean, r = Lu-f, and L is a derivative and no matter what is the order it depends of surrounding points right ? so that makes r not 0 on the boundary during the iterative process ?
On the other side, if I have Dirichlet boundary conditions, I set the exact value on these boundaries, and so there the equation is perfectly satisfied and residual is zero.
Which one is correct and why ?
What is to do for the residual on a boundary with neumann condition ? Do I have to calculate it or set it to 0 ?
Thanks a lot
Saul Teukolsky
06-08-2008, 03:51 PM
You can always arrange for the residual to be zero on the boundaries. The discussion after eqn. 20.4.15 in the 3rd edition (eqn 19.4.15 in the second edition) shows how to change inhomogeneous b.c.'s into homogeneous b.c.'s. (The discussion is for transform methods, but the same scheme works in general). With homogeneous b.c.'s, you can write down the boundary condition (eg u=0) on the boundary, then regard that as a known term, take it over to the right-hand side, and only solve in the interior. For Neumann conditions, u'=0, write this down by finite differencing, eg u_{-1}-u_1=0, and eliminate u_{-1} from the equations.
Saul Teukolsky
Heimdall
06-09-2008, 03:01 PM
With homogeneous b.c.'s, you can write down the boundary condition (eg u=0) on the boundary, then regard that as a known term, take it over to the right-hand side, and only solve in the interior.
All right, I understand that I can always treat inhomogeneous BCs like homogenous ones. But Why then the residual is zero on the boundary ? (sorry if you said it but I don't understand).
Example :
let's say that I have homogeneous dirichlet condition at j=0, my equation then if I write the residual r(i,0) I have :
r(i,0) = f(i,0) - u(i,0) + mu/dx^2*(u(i-1)-2u(i,0)+u(i+1,0))+ mu/dy2*(u(i,-1)-2u(i,0)+u(i,1))
What about the point u(i,-1) ?
Saul Teukolsky
06-09-2008, 04:50 PM
Suppose the boundary is at i=0. You don't need to solve the equation at i=0, since you know u=0 there. So the smallest value of i you need to solve for is at i=1. This equations refers to u(i-1), i.e. u(0). But this is known (zero in this case). You can think of it as being on the right-hand side. The matrix representing the differential operator never operates on u(0).
Saul Teukolsky
Heimdall
06-10-2008, 12:09 AM
The matrix representing the differential operator never operates on u(0).
Ok so you mean that since we know the value u(0) there is no residual there because we just don't solve these points on the boundary.
But in multigrid, saying that the residual is 0 on the boundary of the fine grid means that the equation error has homogeneous dirichlet conditions ? I don't find it very intuitive. And again, each residual will be zero on the boundary so that each equation error will have dirichlet condition ?