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

📄 precondition.m

📁 五点差分型多重网格方法:各种插值算子的比较)
💻 M
字号:
%PRECONDITION Precondition a vector.
%
%       Z = PRECONDITION(A, R) applies a preconditioner defined by the
%       global flag "precon_flag" to the vector R.
%

% 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
% May 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.


function z = precondition(A, r)

include_flags
include_bridge_globals

if precon_flag == NONE

   z = r;

elseif precon_flag == JACOBI

   z = r ./ spdiags(A,[0]);

elseif precon_flag == GAUSS_SEIDEL

   z = tril(A) \ r;

elseif precon_flag == MG_CYCLE_FLAG

   disp(' -- MG PRECONDITIONING -- ');
   z = mg_cycle(1,r);
   disp(' -- DONE MG PRECONDITIONING -- ');

elseif precon_flag == BLOCK_JACOBI

        % ==========================
        % This assumes that nx1, N1 are available.
        % nlines is a parameter that specifies the block size in lines
        % nlines could be a global, set-able through the
        %     Solver->Precon->Block Jacobi->nlines submenu
        % ==========================
        nlines = 4;
        blk = nlines * nx1;
        nb = ceil(N1/blk);
 
        z = zeros(size(r));
 
        for j = 1:nb
           v = [(j-1)*blk+1 : min(N1, j*blk)]';
           z(v) = A(v,v) \ r(v);
        end
        % ==========================

end

⌨️ 快捷键说明

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