Multigrid method: Difference between revisions

Content deleted Content added
Multigrid preconditioning: added url doi to references
m Algorithm: Correct whitespace
Line 26:
<syntaxhighlight lang="matlab">
function phi = V_Cycle(phi,f,h)
% Recursive V-Cycle Multigrid for solving the Poisson equation (\nabla^2 phi = f) on a uniform grid of spacing h
 
% Pre-Smoothing
phi = smoothing(phi,f,h);
% Compute Residual Errors
r = residual(phi,f,h);
% Restriction
rhs = restriction(r);
 
% Compute Residual Errors
eps = zeros(size(rhs));
r = residual(phi,f,h);
 
% Restriction
% stop recursion at smallest grid size, otherwise continue recursion
rhs = restriction(r);
if smallest_grid_size_is_achieved
eps = smoothing(eps,rhs,2*h);
else
eps = V_Cycle(eps,rhs,2*h);
end
% Prolongation and Correction
phi = phi + prolongation(eps);
% Post-Smoothing
phi = smoothing(phi,f,h);
end
 
eps = zeros(size(rhs));
 
% stop recursion at smallest grid size, otherwise continue recursion
if smallest_grid_size_is_achieved
eps = smoothing(eps,rhs,2*h);
else
eps = V_Cycle(eps,rhs,2*h);
end
 
% Prolongation and Correction
phi = phi + prolongation(eps);
 
% Post-Smoothing
phi = smoothing(phi,f,h);
end
</syntaxhighlight>
||
Line 59 ⟶ 58:
<syntaxhighlight lang="matlab">
function phi = F_Cycle(phi,f,h)
% Recursive F-cycle multigrid for solving the Poisson equation (\nabla^2 phi = f) on a uniform grid of spacing h
 
% Pre-smoothing
phi = smoothing(phi,f,h);
% Compute Residual Errors
r = residual(phi,f,h);
% Restriction
rhs = restriction(r);
 
% Compute Residual Errors
eps = zeros(size(rhs));
r = residual(phi,f,h);
 
% Restriction
% stop recursion at smallest grid size, otherwise continue recursion
rhs = restriction(r);
if smallest_grid_size_is_achieved
eps = smoothing(eps,rhs,2*h);
else
eps = F_Cycle(eps,rhs,2*h);
end
% Prolongation and Correction
phi = phi + prolongation(eps);
% Re-smoothing
phi = smoothing(phi,f,h);
 
eps = zeros(size(rhs));
% Compute residual errors
r = residual(phi,f,h);
% Restriction
rhs = restriction(r);
 
% stop recursion at smallest grid size, otherwise continue recursion
if smallest_grid_size_is_achieved
eps = smoothing(eps,rhs,2*h);
else else
eps = V_CycleF_Cycle(eps,rhs,2*h);
end
 
end
% Prolongation and Correction
phi = phi + prolongation(eps);
% Prolongation and Correction
 
phi = phi + prolongation(eps);
% Re-smoothing
% Post- phi = smoothing(phi,f,h);
 
phi = smoothing(phi,f,h);
% Compute residual errors
r = residual(phi,f,h);
 
% Restriction
rhs = restriction(r);
 
% stop recursion at smallest grid size, otherwise continue recursion
if smallest_grid_size_is_achieved
eps = smoothing(eps,rhs,2*h);
else
eps = V_Cycle(eps,rhs,2*h);
end
 
% Prolongation and Correction
phi = phi + prolongation(eps);
 
% Post-smoothing
phi = smoothing(phi,f,h);
end
</syntaxhighlight>
Line 110 ⟶ 109:
<syntaxhighlight lang="matlab">
function phi = W_cycle(phi,f,h)
% Recursive W-cycle multigrid for solving the Poisson equation (\nabla^2 phi = f) on a uniform grid of spacing h
 
% Pre-smoothing
phi = smoothing(phi,f,h);
 
% Compute Residual Errors
r = residual(phi,f,h);
 
% Restriction
rhs = restriction(r);
 
eps = zeros(size(rhs));
 
% stop recursion at smallest grid size, otherwise continue recursion
if smallest_grid_size_is_achieved
eps = smoothing(eps,rhs,2*h);
else
eps = W_cycle(eps,rhs,2*h);
end
 
% Prolongation and correction
phi = phi + prolongation(eps);
 
% Re-smoothing
phi = smoothing(phi,f,h);
 
% Compute residual errors
% Pre-smoothing
phi r = smoothingresidual(phi,f,h);
% Compute Residual Errors
r = residual(phi,f,h);
% Restriction
rhs = restriction(r);
 
% Restriction
eps = zeros(size(rhs));
rhs = restriction(r);
 
% stop recursion at smallest grid size, otherwise continue recursion
if smallest_grid_size_is_achieved
eps = smoothing(eps,rhs,2*h);
else else
eps = W_cycle(eps,rhs,2*h);
end
end
% Prolongation and correction
phi = phi + prolongation(eps);
% Re-smoothing
phi = smoothing(phi,f,h);
 
% Prolongation and correction
% Compute residual errors
phi = phi + prolongation(eps);
r = residual(phi,f,h);
% Restriction
rhs = restriction(r);
 
% Post-smoothing
% stop recursion at smallest grid size, otherwise continue recursion
phi = smoothing(phi,f,h);
if smallest_grid_size_is_achieved
eps = smoothing(eps,rhs,2*h);
else
eps = W_cycle(eps,rhs,2*h);
end
% Prolongation and correction
phi = phi + prolongation(eps);
% Post-smoothing
phi = smoothing(phi,f,h);
end
</syntaxhighlight>