function x_mg = mg_ns(Amat,f, domain,mg_mat,mgdata) %mg_ns GMG preconditioner for Navier-Stokes equations % x_mg = mg_ns(Amat,f, domain,mg_mat,mgdata) % input % Amat coefficient matrix % f right-hand side % domain physical domain, 1 for cavity, 3 for step % mgmat problem type, 1 for diffusion, 2 for % convection-diffusion % mgdata structure containing all GMG data % output % x_mg result of preconditioning operation % % IFISS function: HCE; 17 March 2005. % Copyright (c) 2005 D.J. Silvester, H.C. Elman, A. Ramage if domain==1, % Cavity % MG parameters tau = 1.d-8; maxit = 1; npre = 1; npost = 1; if mg_mat==1 % Apply MG to Poisson equation sweeps = 1; % See mg_solve for explanation np = sqrt(length(Amat)); nc = log2(np-1); elseif mg_mat==2, % Apply MG to convection-diffusion equation sweeps = 4; % See mg_solve for explanation nuv = sqrt(length(Amat)); nc = log2(nuv-1); else error('Multigrid solver not implemented for this matrix') end elseif domain==3, % Step tau = 1.d-8; maxit = 1; sweeps = 1; npre = 1; npost = 1; nc = mgdata(size(mgdata,2)).nc; end % MG set-up A = mgdata(nc).matrix; x_mg = zeros(length(f),1); r = f; nr0 = norm(r); if nr0==0, return; end nr = nr0; its = 0; stats = [its,nr]; % MG iterative loop flag=0; its=0; while (nr>tau*nr0)&(its