正在加载图片...
878 Chapter 19. Partial Differential Equations ③ ⑤ ⑨ © © 4-grid ⑨⑤ ncycle =1 自间 E E http://www.nr read able files ⑨ © ⑤ 83 granted for ③ ⑨ ⑤ © §③ ⑤ 1100 9 ⊙ © 4-grid 872 ncycle =2 自自 自 自 E E (Nort server Figure 19.6.2.Structure of cycles for the full multigrid(FMG)method.This method starts on the coarsest grid,interpolates,and then refines (by "V's"),the solution onto grids of increasing fineness. Americ University Press. make one paper computer, THE ART you can use fr=Rfh.This prescription is not always safe for inhomogeneous boundary conditions.In that case it is better to discretize f on each coarse grid. Progra Note that the FMG algorithm produces the solution on all levels.It can therefore be combined with techniques like Richardson extrapolation. We now give a routine mglin that implements the Full Multigrid Algorithm 6 %州 for a linear equation,the model problem(19.0.6).It uses red-black Gauss-Seidel as the smoothing operator,bilinear interpolation for P,and half-weighting for R.To change the routine to handle another linear problem,all you need do is modify the OF SCIENTIFIC COMPUTING (ISBN functions relax,resid,and slvsml appropriately.A feature of the routine is the dynamical allocation of storage for variables defined on the various grids. 、 1988-18920 10-621 #include "nrutil.h" #define NPRE 1 Number of relaxation sweeps before... Numerical Recipes #define NPOST 1 ..and after the coarse-grid correction is com- #define NGMAX 15 puted. (outside 膜 void mglin(double **u,int n,int ncycle) oftware. Full Multigrid Algorithm for solution of linear elliptic equation,here the model problem(19.0.6) On input u[1..n][1..n]contains the right-hand side p,while on output it returns the solution. The dimension n must be of the form 2+1 for some integer j.(j is actually the number of grid levels used in the solution,called ng below.)ncycle is the number of V-cycles to be B used at each level. void addint(double **uf,double **uc,double **res,int nf); void copy(double **aout,double **ain,int n); void fill0(double **u,int n); void interp(double **uf,double **uc,int nf); void relax(double **u,double +*rhs,int n); void resid(double **res,double *u,double **rhs,int n); void rstrct(double **uc,double **uf,int nc); void slvsml(double **u,double **rhs);878 Chapter 19. Partial Differential Equations Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). 4-grid ncycle = 1 4-grid ncycle = 2 S S S S S S S S S S S E E S S S S S E E E S S S S S E E S S S E S S S S S E E S S S S E S S S S S E S S S E E S S S S S S S S E Figure 19.6.2. Structure of cycles for the full multigrid (FMG) method. This method starts on the coarsest grid, interpolates, and then refines (by “V’s”), the solution onto grids of increasing fineness. you can use fH = Rfh. This prescription is not always safe for inhomogeneous boundary conditions. In that case it is better to discretize f on each coarse grid. Note that the FMG algorithm produces the solution on all levels. It can therefore be combined with techniques like Richardson extrapolation. We now give a routine mglin that implements the Full Multigrid Algorithm for a linear equation, the model problem (19.0.6). It uses red-black Gauss-Seidel as the smoothing operator, bilinear interpolation for P, and half-weighting for R. To change the routine to handle another linear problem, all you need do is modify the functions relax, resid, and slvsml appropriately. A feature of the routine is the dynamical allocation of storage for variables defined on the various grids. #include "nrutil.h" #define NPRE 1 Number of relaxation sweeps before ... #define NPOST 1 ... and after the coarse-grid correction is com- #define NGMAX 15 puted. void mglin(double **u, int n, int ncycle) Full Multigrid Algorithm for solution of linear elliptic equation, here the model problem (19.0.6). On input u[1..n][1..n] contains the right-hand side ρ, while on output it returns the solution. The dimension n must be of the form 2j + 1 for some integer j. (j is actually the number of grid levels used in the solution, called ng below.) ncycle is the number of V-cycles to be used at each level. { void addint(double **uf, double **uc, double **res, int nf); void copy(double **aout, double **ain, int n); void fill0(double **u, int n); void interp(double **uf, double **uc, int nf); void relax(double **u, double **rhs, int n); void resid(double **res, double **u, double **rhs, int n); void rstrct(double **uc, double **uf, int nc); void slvsml(double **u, double **rhs);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有