我正在尝试制作自己的 CFD 求解器,其中计算量最大的部分之一是求解压力项。更快地求解 Poisson 微分方程的一种方法是使用 multigrid method。基本的递归算法是:
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);
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
I've attempted to implement this algorithm myself 但是它非常慢并且没有给出好的结果,所以显然它做错了什么。我一直在寻找原因太久了,我认为值得看看是否有人可以帮助我。
如果我使用 2^5 x 2^5 点的网格大小,那么它可以解决它并给出合理的结果。然而,一旦我超过这个,无论执行了多少 V-Loops,它都需要指数级更长的时间来解决并且基本上会陷入某种程度的不准确性。在 2^7 x 2^7 点处,代码花费的时间太长而无法使用。
我认为我的主要问题是我的雅可比迭代实现是使用线性代数来计算每一步的更新。这通常应该很快,但是,更新矩阵 A 是一个 n*m 大小的矩阵,计算 2^7 * 2^7 大小的矩阵的点积很昂贵。由于大多数单元格只是零,我应该使用不同的方法计算结果吗?
如果有人在多重网格方法方面有任何经验,我将不胜感激!
谢谢