00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <math.h>
00013
00014
00015
00016
00017
00018
00019 void green(double *bz0,
00020 double *Bx, double *By, double *Bz,
00021 int nx, int ny, int nz,
00022 int verb)
00023 {
00024 double *x, *y, *z, *Pot0;
00025 double zoff, dummy1, h, r, rx, ry, rz;
00026
00027 int nynz, nxnynz;
00028 int i, i2, ix, iy, iz, ix1, iy1;
00029
00030 if (verb) {printf("Vectormagnetogram loaded\n"); fflush(stdout);}
00031
00032 h = 1.0;
00033 nynz = ny * nz;
00034 nxnynz = nx * ny * nz;
00035 zoff = 0.5;
00036 {printf("1\n"); fflush(stdout);}
00037
00038 x = (double *) calloc(nx, sizeof(double));
00039 y = (double *) calloc(ny, sizeof(double));
00040 z = (double *) calloc(nz, sizeof(double));
00041 Pot0 = (double *) calloc(nxnynz, sizeof(double));
00042 {printf("2\n"); fflush(stdout);}
00043
00044
00045
00046
00047 for (ix = 0; ix < nx; ix++) {x[ix] = ix * 1.0;}
00048 for (iy = 0; iy < ny; iy++) {y[iy] = iy * 1.0;}
00049 for (iz = 0; iz < nz; iz++) {z[iz] = zoff + iz * 1.0;}
00050 {printf("3\n"); fflush(stdout);}
00051
00052
00053 #ifdef _OPENMP
00054 #pragma omp parallel for private (i,ix,iy,iz,dummy1,ix1,iy1,rx,ry,rz,r,i2)
00055 #endif
00056 for (ix = 0; ix < nx; ix++) {
00057 if (verb) {printf("percent finished = %lf\n", 100.0 * ix / nx); fflush(stdout);}
00058 for (iy = 0; iy < ny; iy++)
00059 for (iz = 0; iz < nz; iz++) {
00060 i = ix * nynz + iy*nz + iz;
00061 dummy1 = 0.0;
00062 for (ix1 = 0; ix1 < nx; ix1++)
00063 for (iy1 = 0; iy1 < ny; iy1++) {
00064 i2 = ny * ix1 + iy1;
00065 rx = x[ix] - x[ix1];
00066 ry = y[iy] - y[iy1];
00067 rz = z[iz];
00068 r = sqrt(rx * rx + ry * ry + rz * rz);
00069 dummy1 = dummy1 - bz0[i2] / r;
00070 }
00071 Pot0[i] = dummy1 / 2.0 / M_PI;
00072 }
00073 }
00074 {printf("4\n"); fflush(stdout);}
00075
00076
00077 #ifdef _OPENMP
00078 #pragma omp parallel for private (i,ix,iy,iz)
00079 #endif
00080 for (ix = 0; ix < nx; ix++)
00081 for (iy = 0; iy < ny; iy++)
00082 for (iz = 0; iz < nz; iz++)
00083 {
00084 i = ix * nynz + iy * nz + iz;
00085 Bx[i] = GRADX(Pot0,i);
00086 By[i] = GRADY(Pot0,i);
00087 Bz[i] = GRADZ(Pot0,i);
00088 }
00089
00090
00091
00092
00093
00094 {printf("5\n"); fflush(stdout);}
00095
00096 free(x); free(y); free(z); free(Pot0);
00097 {printf("6\n"); fflush(stdout);}
00098 if (verb) printf("Potential field done\n");
00099 }