struct Mgfas { Int n,ng; MatDoub *uj,*uj1; NRvector *> rho; Mgfas(MatDoub_IO &u, const Int maxcyc) : n(u.nrows()), ng(0) { Int nn=n; while (nn >>= 1) ng++; if ((n-1) != (1 << ng)) throw("n-1 must be a power of 2 in mgfas."); nn=n; Int ngrid=ng-1; rho.resize(ng); rho[ngrid]=new MatDoub(nn,nn); *rho[ngrid]=u; while (nn > 3) { nn=nn/2+1; rho[--ngrid]=new MatDoub(nn,nn); rstrct(*rho[ngrid],*rho[ngrid+1]); } nn=3; uj=new MatDoub(nn,nn); slvsm2(*uj,*rho[0]); for (Int j=1;j *> &rho, Doub &trerr) { const Int NPRE=1,NPOST=1; const Doub ALPHA=0.33; Doub dum=-1.0; Int nf=u.nrows(); Int nc=(nf+1)/2; MatDoub temp(nf,nf); if (j == 0) { matadd(rhs,*rho[j],temp); slvsm2(u,temp); } else { MatDoub v(nc,nc),ut(nc,nc),tau(nc,nc),tempc(nc,nc); for (Int jpre=0;jpre 0.0) trerr=ALPHA*anorm2(tau); mg(j-1,v,tau,rho,dum); matsub(v,ut,tempc); interp(temp,tempc); matadd(u,temp,u); for (Int jpost=0;jpost