正在加载图片...
880 Chapter 19.Partial Differential Equations void rstrct(double **uc,double **uf,int nc) Half-weighting restriction.nc is the coarse-grid dimension.The fine-grid solution is input in uf [1..2*nc-1][1..2*nc-1],the coarse-grid solution is returned in uc [1..nc][1..nc]. int ic,iif,jc,jf,ncc=2*nc-1; for (jf=3,jc=2;jc<nc;jc++,jf+=2) Interior points for(1if=3,1c=2;ic<nc;1c++,11f+=2)[ uc[1c][jc]=0.5*uf[iif][f]+0.125*(uf[i1f+1][jf]+uf[1if-1][jf] +uf [iif][if+1]+uf[iif][if-1]); for(jc=1,1c=1;1c<=nc;1c++,jc+=2)[ Boundary points. uc[ic][1]=uf[jc][1]; uc [ic][nc]=uf [jc][ncc]: granted for 19881992 for(jc=1,1c=1;ic<=nc;1c++,jc+=2){ uc[1][ic]=uf[1][jc]; 1600 9 uc [ne][ic]=uf [ncc][jc]; 2 NUMERICAL RECIPES I void interp(double **uf,double **uc,int nf) (Nort server Coarse-to-fine prolongation by bilinear interpolation.nf is the fine-grid dimension.The coarse- to make grid solution is input as uc [1..nc][1..nc],where nc nf/2+1.The fine-grid solution is returned in uf [1..nf][1..nf]. int ic,iif,jc,jf,nci nc=nf/2+1; for (jc=1,jf=1;jc<=nc;jc++,jf+=2) Do elements that are copies. 9 for (ic=1;ic<=nc;ic++)uf[2*ic-1][jf]=uc[ic][jc]; for (jf=1;jf<=nf;jf+=2) Do odd-numbered columns,interpolat- for (iif=2;iif<nf;iif+=2) ing vertically. IENTIFIC uf[iif][if]=0.5*(uf [iif+1][if]+uf[iif-1][if]); for (jf=2;jf<nf;jf+=2) Do even-numbered columns,interpolat- for (iif=1;iif <nf;iif++) ing horizontally. uf[iif][if]=0.5*(uf [iif][if+1]+uf [iif][if-1]); 1992 COMPUTING(ISBN void addint(double **uf,double **uc,double **res,int nf) Does coarse-to-fine interpolation and adds result to uf.nf is the fine-grid dimension.The 021 coarse-grid solution is input as uc [1..nc][1..nc],where nc nf/2+1.The fine-grid solu- tion is returned in uf [1..nf][1..nf].res [1..nf][1..nf]is used for temporary storage. Numerical Recipes 43108 void interp(double **uf,double **uc,int nf); int i,j; (outside interp(res,uc,nf); for (j=1;j<=nf;j++) North Software. for (i=1;i<=nf;i++) uf [i][j]+res[i][j]; void slvsml(double *u,double **rhs) Solution of the model problem on the coarsest grid,where h=.The right-hand side is input in rhs [1..3][1..3]and the solution is returned in u[1..3][1..3]. void fill0(double **u,int n); double h=0.5; f1110(u,3);880 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). void rstrct(double **uc, double **uf, int nc) Half-weighting restriction. nc is the coarse-grid dimension. The fine-grid solution is input in uf[1..2*nc-1][1..2*nc-1], the coarse-grid solution is returned in uc[1..nc][1..nc]. { int ic,iif,jc,jf,ncc=2*nc-1; for (jf=3,jc=2;jc<nc;jc++,jf+=2) { Interior points. for (iif=3,ic=2;ic<nc;ic++,iif+=2) { uc[ic][jc]=0.5*uf[iif][jf]+0.125*(uf[iif+1][jf]+uf[iif-1][jf] +uf[iif][jf+1]+uf[iif][jf-1]); } } for (jc=1,ic=1;ic<=nc;ic++,jc+=2) { Boundary points. uc[ic][1]=uf[jc][1]; uc[ic][nc]=uf[jc][ncc]; } for (jc=1,ic=1;ic<=nc;ic++,jc+=2) { uc[1][ic]=uf[1][jc]; uc[nc][ic]=uf[ncc][jc]; } } void interp(double **uf, double **uc, int nf) Coarse-to-fine prolongation by bilinear interpolation. nf is the fine-grid dimension. The coarse￾grid solution is input as uc[1..nc][1..nc], where nc = nf/2+1. The fine-grid solution is returned in uf[1..nf][1..nf]. { int ic,iif,jc,jf,nc; nc=nf/2+1; for (jc=1,jf=1;jc<=nc;jc++,jf+=2) Do elements that are copies. for (ic=1;ic<=nc;ic++) uf[2*ic-1][jf]=uc[ic][jc]; for (jf=1;jf<=nf;jf+=2) Do odd-numbered columns, interpolat￾for (iif=2;iif<nf;iif+=2) ing vertically. uf[iif][jf]=0.5*(uf[iif+1][jf]+uf[iif-1][jf]); for (jf=2;jf<nf;jf+=2) Do even-numbered columns, interpolat￾for (iif=1;iif <= nf;iif++) ing horizontally. uf[iif][jf]=0.5*(uf[iif][jf+1]+uf[iif][jf-1]); } void addint(double **uf, double **uc, double **res, int nf) Does coarse-to-fine interpolation and adds result to uf. nf is the fine-grid dimension. The coarse-grid solution is input as uc[1..nc][1..nc], where nc = nf/2+1. The fine-grid solu￾tion is returned in uf[1..nf][1..nf]. res[1..nf][1..nf] is used for temporary storage. { void interp(double **uf, double **uc, int nf); int i,j; interp(res,uc,nf); for (j=1;j<=nf;j++) for (i=1;i<=nf;i++) uf[i][j] += res[i][j]; } void slvsml(double **u, double **rhs) Solution of the model problem on the coarsest grid, where h = 1 2 . The right-hand side is input in rhs[1..3][1..3] and the solution is returned in u[1..3][1..3]. { void fill0(double **u, int n); double h=0.5; fill0(u,3);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有