⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmg.m

📁 五点差分型多重网格方法:各种插值算子的比较)
💻 M
字号:
%VMG    Multigrid V-Cycle Solver
%
%       [X,RESIDS,ITS]=VMG(A,B,X0,RTOL,PRTOL,MAX_IT,MAX_TIME,MAX_MFLOP)
%       solves the system AX = B iteratively using multigrid cycles whose type
%       is defined by "cycle_flag".  The stopping criteria is given by
%       the input tolerances and limits.

% James Bordner and Faisal Saied
% Department of Computer Science
% University of Illinois at Urbana-Champaign
% 10 April 1995

% Modified for Matlab Version 6 Compatability
% Ryan McKenzie
% University of Kentucky Center for Computational Sciences
% April 2004
%
% For some reason, locally generated variables cannot be seen outside the scope of a
% particular function in version 6 unless they have a global reference. This seems to 
% only occur when the newly generated variable is passed as a parameter. I have taken
% locally generated variables throughout MGLab and "bridged" them to their destination
% routines using global references. It's an ugly fix, so maybe someone should come up
% with a more centralized solution.
%
% Removed stopping criteria and other solver information from the parameter list since
% they are all stored in global constants anyway.

function [x,resids,its] = vmg(A,b,x)

include_globals
include_bridge_globals

% gobally referencing variables from the solve routine "bridge"
b = b_in_sol_method;
A = A_in_sol_method;
x = x_in_sol_method;

r0 = b - A * x; 
r = r0;
rn0 = norm(r0);  
rn = rn0;

iter = 0;
results=update_results([],'V-Cycle',iter,rn);

bn=norm(b);
pbn = bn;
prn = rn;

% We stop on the true resid, but the test is actually performed on the precond
% resid.

while (~converged(bn,pbn,rn,prn,iter,rtol,prtol,max_it,max_time))
    cycle_start_level = 1;
    x = mg_cycle(cycle_start_level,b,x);
    r = b - A*x;
    iter = iter + 1;
    rn = norm(r);
    prn = rn;
    results=update_results(results,'V-Cycle',iter,prn);
end

its=results(:,1);
resids=results(:,4);

rho=10^(log10(resids(iter+1)/resids(2))/((iter+1)-2));
fprintf('rho = %g.\n', rho)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -