#include "nr.h" namespace { void mg(const int j, Mat_IO_DP &u, Mat_I_DP &rhs, Vec_Mat_DP_p &rho, DP &trerr) { using namespace NR; const int NPRE=1,NPOST=1; const DP ALPHA=0.33; int jpost,jpre,nc,nf; DP dum=-1.0; nf=u.nrows(); nc=(nf+1)/2; Mat_DP temp(nf,nf); if (j == 0) { matadd(rhs,*rho[j],temp); slvsm2(u,temp); } else { Mat_DP v(nc,nc),ut(nc,nc),tau(nc,nc),tempc(nc,nc); for (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 (jpost=0;jpost>= 1) ng++; if ((n-1) != (1 << ng)) nrerror("n-1 must be a power of 2 in mgfas."); Vec_Mat_DP_p rho(ng); nn=n; ngrid=ng-1; rho[ngrid]=new Mat_DP(nn,nn); copy(*rho[ngrid],u); while (nn > 3) { nn=nn/2+1; rho[--ngrid]=new Mat_DP(nn,nn); rstrct(*rho[ngrid],*rho[ngrid+1]); } nn=3; uj=new Mat_DP(nn,nn); slvsm2(*uj,*rho[0]); for (j=1;j