This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Defines | |
#define | NGERROR -1 |
#define | NXERROR -2 |
#define | NYERROR -3 |
#define | MEMERROR -5 |
Functions | |
void | relax (real2D u, real2D rhs, real2D a, real2D b, real2D ei, real2D cc, int n1, int n2) |
int | computeng (int n1, int n2) |
int | initpressure (int n1, int n2, int ng) |
void | mginit (real2D u, real2D p, real2D a, real2D b, real2D ei, int n1, int n2, int ng) |
void | mgvcycle (int n, int nx, int ny, int npre, int npost) |
void | mgfas (real2D u, real2D p, real2D a, real2D b, real2D ei, int n1, int n2, int ng, int npre, int npost, int ncycle) |
|
|
|
|
|
|
|
|
|
Definition at line 42 of file mg.c.
00043 { 00044 int nmin, n, nn, j; 00045 00046 nmin = MIN(n1, n2); 00047 00048 j = nmin - 2; n = 1; 00049 while (j > 2) 00050 { j /= 2; n++; } 00051 00052 nn = 1; 00053 for (j = 1; j <= n; j++) 00054 nn *= 2; 00055 if((nn + 2) != nmin) 00056 return NGERROR; 00057 00058 if ((n1 - 2) % (nmin - 2) != 0) 00059 return NXERROR; 00060 if ((n2 - 2) % (nmin - 2) != 0) 00061 return NYERROR; 00062 00063 Ngrid = n; 00064 return n; 00065 } |
|
Definition at line 69 of file mg.c.
00070 { 00071 int j; 00072 int err = 0; 00073 00074 err |= ((irhs = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00075 err |= ((ires = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00076 err |= ((ip = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00077 err |= ((iap = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00078 err |= ((ic0 = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00079 err |= ((ic1 = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00080 err |= ((ic2 = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00081 err |= ((ic3 = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00082 err |= ((ic4 = (real2D *) malloc((ng + 1) * sizeof(real2D))) == NULL); 00083 00084 if ( err ) return MEMERROR; 00085 00086 err |= ((ires[ng] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00087 00088 err |= ((sxp = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00089 err |= ((syp = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00090 00091 err |= ((syu = (real2D)mymalloc(sizeof(real), n1 + 1, n2)) == NULL); 00092 err |= ((au = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00093 err |= ((cu = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00094 00095 err |= ((sxv = (real2D)mymalloc(sizeof(real), n1, n2 + 1)) == NULL); 00096 err |= ((av = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00097 err |= ((cv = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00098 00099 err |= ((rz1dr = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00100 err |= ((rz2dr = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00101 err |= ((rr1dz = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00102 err |= ((rr2dz = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00103 00104 err |= ((w1 = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00105 err |= ((w2 = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00106 err |= ((dummy = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00107 00108 n1 = n1 / 2 + 1; 00109 n2 = n2 / 2 + 1; 00110 00111 for (j = ng - 1; j >= 1; j--) { 00112 err |= ((irhs[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00113 err |= ((ires[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00114 err |= ((ip[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00115 err |= ((iap[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00116 err |= ((ic0[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00117 err |= ((ic1[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00118 err |= ((ic2[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00119 err |= ((ic3[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00120 err |= ((ic4[j] = (real2D)mymalloc(sizeof(real), n1, n2)) == NULL); 00121 00122 if ( err ) return MEMERROR; 00123 00124 n1 = n1 / 2 + 1; 00125 n2 = n2 / 2 + 1; 00126 } 00127 00128 return 0; 00129 } /* end initpressure() */ |
|
Definition at line 143 of file fas.c. References bc_scalar(), copy(), lop(), NULGRAD, real2D, and relax().
00145 { 00146 int i, j, jj, jcycle, jpre, jpost, ngrid, nfx, nfy, nn1, nn2; 00147 00148 ip[ng] = p; 00149 irho[ng] = u; 00150 ia[ng] = a; 00151 ib[ng] = b; 00152 iei[ng] = ei; 00153 icc[ng] = cc; 00154 00155 nn1 = n1 / 2 + 1; 00156 nn2 = n2 / 2 + 1; 00157 ngrid = ng - 1; 00158 00159 bc_scalar(u, n1, n2, NULGRAD); 00160 00161 rstrct(irho[ngrid], u, nn1, nn2); 00162 rstrct(icc[ngrid], cc, nn1, nn2); 00163 abfromab(ia[ngrid], ib[ngrid], iei[ngrid], 00164 ia[ngrid+1], ib[ngrid+1], nn1, nn2); 00165 while ((nn1 > 4) && (nn2 > 4)) 00166 { 00167 nn1 = nn1 / 2 + 1; 00168 nn2 = nn2 / 2 + 1; 00169 ngrid = ngrid - 1; 00170 rstrct(irho[ngrid], irho[ngrid+1], nn1, nn2); 00171 rstrct(icc[ngrid], icc[ngrid+1], nn1, nn2); 00172 abfromab(ia[ngrid], ib[ngrid], iei[ngrid], ia[ngrid+1], ib[ngrid+1], 00173 nn1, nn2); 00174 } 00175 00176 ngrid = ng; 00177 for (j = 2; j <= ngrid; j++) 00178 { 00179 nn1 = 2 * nn1 - 2; 00180 nn2 = 2 * nn2 - 2; 00181 interp(ip[j], ip[j-1], nn1, nn2); 00182 copy(irhs[j], irho[j], nn1, nn2); 00183 for (jcycle = 1; jcycle <= ncycle; jcycle++) 00184 { 00185 nfx = nn1; 00186 nfy = nn2; 00187 for (jj = j; jj >= 2; jj--) 00188 { 00189 for (jpre = 1; jpre <= npre; jpre++) 00190 { 00191 relax(ip[jj], irhs[jj], ia[jj], ib[jj], iei[jj], icc[jj], 00192 nfx, nfy); 00193 bc_scalar(ip[jj], nfx, nfy, NULGRAD); 00194 } 00195 lop(itemp[jj], ip[jj], ia[jj], ib[jj], icc[jj], nfx, nfy); 00196 bc_scalar(itemp[jj], nfx, nfy, NULGRAD); 00197 nfx = nfx / 2 + 1; 00198 nfy = nfy / 2 + 1; 00199 rstrct(itemp[jj-1], itemp[jj], nfx, nfy); 00200 rstrct(ip[jj-1], ip[jj], nfx, nfy); 00201 lop(itau[jj-1], ip[jj-1], ia[jj-1], ib[jj-1], icc[jj-1], nfx, nfy); 00202 bc_scalar(itau[jj-1], nfx, nfy, NULGRAD); 00203 matsub(itau[jj-1], itemp[jj-1], itau[jj-1], nfx, nfy); 00204 rstrct(irhs[jj-1], irhs[jj], nfx, nfy); 00205 matadd(irhs[jj-1], itau[jj-1], irhs[jj-1], nfx, nfy); 00206 } 00207 00208 slvsml(ip[1], irhs[1], 00209 ia[1], ib[1], iei[1], icc[1], nfx, nfy); 00210 00211 for (jj = 2; jj <= j; jj++) 00212 { 00213 rstrct(itemp[jj-1], ip[jj], nfx, nfy); 00214 matsub(ip[jj-1], itemp[jj-1], itemp[jj-1], nfx, nfy); 00215 nfx = 2 * nfx - 2; 00216 nfy = 2 * nfy - 2; 00217 interp(itau[jj], itemp[jj-1], nfx, nfy); 00218 matadd(ip[jj], itau[jj], ip[jj], nfx, nfy); 00219 for (jpost = 1; jpost <= npost; jpost++) 00220 { 00221 relax(ip[jj], irhs[jj], ia[jj], ib[jj], iei[jj], icc[jj], 00222 nfx, nfy); 00223 bc_scalar(ip[jj], nfx, nfy, NULGRAD); 00224 } 00225 } 00226 } 00227 } 00228 } |
|
|
|
Definition at line 222 of file mg.c.
00223 { 00224 int count; 00225 int ncx = nx/2 + 1, ncy = ny/2 + 1; 00226 00227 /* solve exactly on the coarsest grid */ 00228 if (n == COARSEST) { 00229 slvsml(ip[COARSEST], irhs[COARSEST], iap[COARSEST], 00230 ic0[COARSEST], ic1[COARSEST], ic2[COARSEST], ic3[COARSEST], 00231 ic4[COARSEST], 00232 nx, ny); 00233 return; 00234 } 00235 00236 /* do prerelaxation */ 00237 for (count = 0; count < npre; count++) { 00238 relax(ip[n], irhs[n], iap[n], 00239 ic0[n], ic1[n], ic2[n], ic3[n], ic4[n], nx, ny); 00240 bc_scalar(ip[n], nx, ny, NULGRAD2); 00241 } 00242 00243 /* compute defect */ 00244 resid(ires[n], ip[n], irhs[n], iap[n], 00245 ic0[n], ic1[n], ic2[n], ic3[n], ic4[n], 00246 nx, ny); 00247 bc_scalar(ires[n], nx, ny, NUL); 00248 00249 /* compute r.h.s. on the coarser grid using defect */ 00250 rstrct(irhs[n-1], ires[n], ncx, ncy, - 4.0); 00251 00252 /* use zero as initial guess on the coarser grid */ 00253 fill0(ip[n-1], ncx, ncy); 00254 00255 /* solve on the coarser grid */ 00256 mgvcycle(n - 1, ncx, ncy, npre + 1, npost + 1); 00257 00258 /* correct on the fine grid (use ires as temporary storage) */ 00259 addint(ip[n], ip[n-1], ires[n], iap[n], nx, ny); 00260 00261 /* do post relaxation */ 00262 for (count = 0; count < npost; count++) { 00263 relax(ip[n], irhs[n], iap[n], 00264 ic0[n], ic1[n], ic2[n], ic3[n], ic4[n], nx, ny); 00265 bc_scalar(ip[n], nx, ny, NULGRAD2); 00266 } 00267 /* 00268 sprintf(s, "ip%d", n); 00269 datbarray(ip[n], nx, ny, s); 00270 sprintf(s, "ipc%d", n); 00271 interp(ires[n], ip[n-1], nx, ny); 00272 datbarray(ires[n], nx, ny, s); 00273 sprintf(s, "iap%d", n); 00274 datbarray(iap[n], nx, ny, s); 00275 */ 00276 } |
|
Definition at line 418 of file fas.c.
00421 { 00422 real h2, h, res; 00423 int i, j, isw, jsw; 00424 00425 h = 1.0 / (n2 - 2); 00426 h2 = h * h; 00427 for (jsw = 1; jsw <= 2; jsw++) 00428 { 00429 isw = jsw; 00430 for (i = 2; i <= n1 - 1; i++, isw = 3 - isw) 00431 for (j = isw + 1; j <= n2 - 1; j += 2) 00432 if (cc[i][j] == 1.0) 00433 u[i][j] = (a[i][j] * u[i+1][j] + 00434 a[i-1][j] * u[i-1][j] + 00435 b[i][j] * u[i][j+1] + 00436 b[i][j-1] * u[i][j-1] 00437 - h2 * rhs[i][j]) 00438 * ei[i][j]; 00439 } 00440 } |