问题:
function vnew=mgVcycle(vold,f,alpha1,alpha2,omega,Nmin,N,smoother)
这是 V-cycle 实现,代码的核心部分。您应该基于递归实现来实现您的实现。
在此例程中,您将首先在当前级别上进行松弛,该级别具有 NxN 个内部点,然后递归调用下一个级别,具有 (N-1)/2 x (N-1)/2 个内部点,然后是粗网格校正和另一种放松。
vold 是 V 周期之前的当前电平的近似值,而 vnew 是 V 周期之后的新近似值。f 是当前级别的右侧(请记住,在除最精细之外的所有级别上,这是残差向量)。
alpha1 和 alpha2 是放松前后的次数。Omega 是加权 Jacobi 松弛的权重。
如果 N <= Nmin 您将直接求解(使用 Matlab 的 v=A\f)。smoother=1 表示加权 Jacobi,smoother=2 表示 Gauss-Seidel。
伪代码
以下是我对伪代码的解释:
if smoother == 1
Do weighted jacobi alpha1 times on A, vold, f, omega to get vnew
if length(vnew) == (N-1)/2 %coarse grid
Do weighted jacobi alpha 2 times on A,vold,f,omega to get vnew
else
create restriction matrix
f2h = restriction matrix * error
find V2h = by running mgVcycle with error
elseif smoother == 2
Do gauss alpha 1 times on A, vold, f to get vnew
if length(vnew) == (N-1)/2 %coarse grid
Do gauss alpha 2 times on A,vold,f to get vnew
else
create restriction matrix
f2h = restriction matrix * error
find V2h = by running mgVcycle with error
end
end
任何帮助将不胜感激!