Assign the normal component of the staggered magnetic field in the ghost zone-faces.
Using the div.B = 0 condition in staggered MHD, this function computes the staggered component of magnetic field lying on the zone-face parallel to the boundary specified by "side". This is preformed by solving the div.B = 0 condition for one variable only which in 2-D requires the knowledge of the other 3 components while in 3-D required the knowledge of the other 5 staggered components.
Note that this operation is performed in the outermost ghost zones only since the face value at IBEG-1 or IEND is supposed to be part of the solution and is not changed during this function. Therefore, only nghost-1 faces are assigned:
59 real dBx = 0.0, dBy = 0.0, dBz = 0.0;
62 real rp, sp, Axp, Ayp, Azp;
63 real rm, sm, Axm, Aym, Azm;
65 double ***bx, ***by, ***bz;
66 double ***
Bx, ***By, ***Bz;
72 ibeg = 0; iend =
NX1_TOT-1; di = 1;
73 jbeg = 0; jend =
NX2_TOT-1; dj = 1;
75 kbeg = 0; kend =
NX3_TOT-1; dk = 1;
77 kbeg = kend = 0, dk = 1;
80 if (side ==
X1_BEG) {ibeg =
IBEG-1; iend = 0; di = -1;}
83 if (side ==
X2_BEG) {jbeg =
JBEG-1; jend = 0; dj = -1;}
86 if (side ==
X3_BEG) {kbeg =
KBEG-1; kend = 0; dk = -1;}
89 for (k = kbeg; dk*k <= dk*kend; k += dk){
90 for (j = jbeg; dj*j <= dj*jend; j += dj){
91 for (i = ibeg; di*i <= di*iend; i += di){
94 rp = fabs(grid[
IDIR].xr[i]);
95 rm = fabs(grid[
IDIR].xl[i]);
101 #if GEOMETRY == SPHERICAL
104 sm = grid[
JDIR].
A[j - 1];
111 D_EXPAND(bxp = bx[k][j][i]; bxm = bx[
k][
j][i - 1]; ,
112 byp = by[
k][
j][
i]; bym = by[
k][j - 1][
i]; ,
113 bzp = bz[
k][
j][
i]; bzm = bz[k - 1][
j][
i];)
131 dVx = dy*dz; Axp = Axm = 1.0;
132 dVy = dx*dz; Ayp = Aym = 1.0;
133 dVz = dx*dy; Azp = Azm = 1.0;
135 #elif GEOMETRY == CYLINDRICAL
137 dVx = dy*dz; Axp = rp ; Axm = rm;
138 dVy = r*dx*dz; Ayp = 1.0; Aym = 1.0;
139 dVz = dx*dy; Azp = 1.0; Azm = 1.0;
141 #elif GEOMETRY == POLAR
143 dVx = dy*dz; Axp = rp ; Axm = rm;
144 dVy = dx*dz; Ayp = 1.0; Aym = 1.0;
145 dVz = r*dx*dy; Azp = 1.0; Azm = 1.0;
147 #elif GEOMETRY == SPHERICAL
149 dVx = dmu*dz; Axp = rp*rp; Axm = rm*rm;
150 dVy = r*dx*dz; Ayp = sp ; Aym = sm;
151 dVz = r*dx*dy; Azp = 1.0 ; Azm = 1.0;
155 D_EXPAND(dBx = dVx*(Axp*bxp - Axm*bxm); ,
156 dBy = dVy*(Ayp*byp - Aym*bym); ,
157 dBz = dVz*(Azp*bzp - Azm*bzm); )
165 bxm = (bxp*Axp + (dBy + dBz)/dVx)/Axm;
166 bx[
k][
j][i - 1] = bxm;
168 }
else if (side ==
X1_END){
170 bxp = (bxm*Axm - (dBy + dBz)/dVx)/Axp;
173 }
else if (side ==
X2_BEG){
175 bym = (byp*Ayp + (dBx + dBz)/dVy)/Aym;
176 by[
k][j - 1][
i] = bym;
178 }
else if (side ==
X2_END){
180 byp = (bym*Aym - (dBx + dBz)/dVy)/Ayp;
184 }
else if (side ==
X3_BEG){
186 bzm = (bzp*Azp + (dBx + dBy)/dVz)/Azm;
187 bz[k - 1][
j][
i] = bzm;
189 }
else if (side ==
X3_END){
191 bzp = (bzm*Azm - (dBx + dBy)/dVz)/Azp;
#define X3_BEG
Boundary region at X3 beg.
#define X1_BEG
Boundary region at X1 beg.
double **** Vs
The main four-index data array used for face-centered staggered magnetic fields.
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
double **** Vc
The main four-index data array used for cell-centered primitive variables.
#define X1_END
Boundary region at X1 end.
#define X2_END
Boundary region at X2 end.
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
long int IEND
Upper grid index of the computational domain in the the X1 direction for the local processor...
#define X3_END
Boundary region at X3 end.
D_EXPAND(tot/[n]=(double) grid[IDIR].np_int_glob;, tot/[n]=(double) grid[JDIR].np_int_glob;, tot/[n]=(double) grid[KDIR].np_int_glob;)
long int KBEG
Lower grid index of the computational domain in the the X3 direction for the local processor...
#define X2_BEG
Boundary region at X2 beg.
long int KEND
Upper grid index of the computational domain in the the X3 direction for the local processor...
long int JBEG
Lower grid index of the computational domain in the the X2 direction for the local processor...
long int JEND
Upper grid index of the computational domain in the the X2 direction for the local processor...
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
long int IBEG
Lower grid index of the computational domain in the the X1 direction for the local processor...
double * A
Right interface area, A[i] = .