4 #define USE_PR_GRADIENT YES
6 #ifdef FINITE_DIFFERENCE
7 #define USE_PR_GRADIENT NO
9 #define USE_PR_GRADIENT YES
15 int beg,
int end,
double dt,
Grid *grid)
45 double dtdx, dtdV,
scrh;
46 double *x1, *x1p, *dx1, *dV1;
47 double *x2, *x2p, *dx2, *dV2;
48 double *x3, *x3p, *dx3, *dV3;
49 double **flux, **rhs, *p, *v;
52 static double **fA, *h;
54 #if GEOMETRY != CARTESIAN
91 #if USE_PR_GRADIENT == NO
92 for (i = beg - 1; i <= end; i++) flux[i][
MXn] += p[i];
95 #if GEOMETRY == CARTESIAN
118 for (i = beg; i <= end; i++) {
126 NVAR_LOOP(nv) rhs[
i][nv] = -dtdx*(flux[
i][nv] - flux[i-1][nv]);
127 #if USE_PR_GRADIENT == YES
128 rhs[
i][
MX1] -= dtdx*(p[
i] - p[i-1]);
136 #if (BODY_FORCE & VECTOR)
139 #if DIMENSIONS == 1 && COMPONENTS > 1
148 rhs[i][ENG] += dt*0.5*(flux[i][
RHO] + flux[i-1][
RHO])*g[
IDIR];
149 #if DIMENSIONS == 1 && COMPONENTS > 1
150 rhs[
i][ENG] += dt*(EXPAND(0.0, + vc[
RHO]*vc[
VX2]*g[
JDIR],
167 for (j = beg; j <= end; j++) {
175 NVAR_LOOP(nv) rhs[
j][nv] = -dtdx*(flux[
j][nv] - flux[j-1][nv]);
176 #if USE_PR_GRADIENT == YES
177 rhs[
j][
MX2] -= dtdx*(p[
j] - p[j-1]);
185 #if (BODY_FORCE & VECTOR)
188 #if DIMENSIONS == 2 && COMPONENTS == 3
192 rhs[
j][ENG] += dt*0.5*(flux[
j][
RHO] + flux[j-1][
RHO])*g[
JDIR];
193 #if DIMENSIONS == 2 && COMPONENTS == 3
213 for (k = beg; k <= end; k++) {
221 NVAR_LOOP(nv) rhs[
k][nv] = -dtdx*(flux[
k][nv] - flux[k-1][nv]);
222 #if USE_PR_GRADIENT == YES
223 rhs[
k][
MX3] -= dtdx*(p[
k] - p[k-1]);
231 #if (BODY_FORCE & VECTOR)
235 rhs[
k][ENG] += dt*0.5*(flux[
k][
RHO] + flux[k-1][
RHO])*g[
KDIR];
241 #elif GEOMETRY == CYLINDRICAL
252 double vB,
vel2, lor2, wt, mphi,
B2;
263 for (i = beg - 1; i <= end; i++){
267 EXPAND(fA[i][
iMR] = flux[i][
iMR]*R; ,
271 EXPAND(fA[i][
iBR] = flux[i][
iBR]*R; ,
276 fA[i][ENG] = flux[i][ENG]*R;
295 for (i = beg; i <= end; i++){
306 EXPAND(rhs[i][
iMR] = - dtdV*(fA[i][
iMR] - fA[i-1][
iMR]); ,
307 rhs[
i][
iMZ] = - dtdV*(fA[
i][
iMZ] - fA[i-1][
iMZ]); ,
310 rhs[i][
iMR] -= dtdx*(p[i] - p[i-1]);
313 EXPAND(rhs[i][
iBR] = - dtdV*(fA[i][
iBR] - fA[i-1][
iBR]); ,
314 rhs[
i][
iBZ] = - dtdV*(fA[
i][
iBZ] - fA[i-1][
iBZ]); ,
317 rhs[i][
iBR] = - dtdx*(flux[i][
iBR] - flux[i-1][
iBR]);
322 rhs[
i][ENG] = -dtdV*(fA[
i][ENG] - fA[i-1][ENG]);
324 NSCL_LOOP(nv) rhs[
i][nv] = -dtdV*(fA[
i][nv] - fA[i-1][nv]);
338 lor2 = 1.0/(1.0 -
vel2);
340 vB = EXPAND(v[VX1]*v[
BX1], + v[VX2]*v[
BX2], + v[VX3]*v[
BX3]);
341 B2 = EXPAND(v[BX1]*v[BX1], + v[BX2]*v[BX2], + v[BX3]*v[BX3]);
342 wt = v[
RHO]*h[
i]*lor2 +
B2;
345 wt = v[
RHO]*h[
i]*lor2;
360 #if (BODY_FORCE & VECTOR)
364 rhs[
i][ENG] += dt*0.5*(flux[
i][
RHO] + flux[i-1][
RHO])*g[
g_dir];
380 for (j = beg; j <= end; j++){
388 NVAR_LOOP(nv) rhs[
j][nv] = -dtdx*(flux[
j][nv] - flux[j-1][nv]);
389 #if USE_PR_GRADIENT == YES
390 rhs[
j][
iMZ] += - dtdx*(p[
j] - p[j-1]);
398 #if (BODY_FORCE & VECTOR)
402 rhs[
j][ENG] += dt*0.5*(flux[
j][
RHO] + flux[j-1][
RHO])*g[
JDIR];
409 #elif GEOMETRY == POLAR
420 double vB,
vel2, g_2, wt, mphi,
B2;
431 for (i = beg - 1; i <= end; i++) {
435 EXPAND(fA[i][
iMR] = flux[i][
iMR]*R; ,
439 EXPAND(fA[i][
iBR] = flux[i][
iBR]*R; ,
444 fA[i][ENG] = flux[i][ENG]*R;
465 for (i = beg; i <= end; i++) {
476 EXPAND(rhs[i][
iMR] = - dtdV*(fA[i][
iMR] - fA[i-1][
iMR])
477 - dtdx*(p[i] - p[i-1]); ,
481 EXPAND(rhs[i][
iBR] = -dtdV*(fA[i][
iBR] - fA[i-1][
iBR]); ,
485 rhs[i][
iBR] = -dtdx*(flux[i][
iBR] - flux[i-1][
iBR]);
490 rhs[
i][ENG] = -dtdV*(fA[
i][ENG] - fA[i-1][ENG]);
493 NSCL_LOOP(nv) rhs[
i][nv] = -dtdV*(fA[
i][nv] - fA[i-1][nv]);
506 vB = EXPAND(v[VX1]*v[
BX1], + v[VX2]*v[
BX2], + v[VX3]*v[
BX3]);
507 B2 = EXPAND(v[BX1]*v[BX1], + v[BX2]*v[BX2], + v[BX3]*v[BX3]);
508 wt = v[
RHO]*h[
i]/g_2 +
B2;
511 wt = v[
RHO]*h[
i]/g_2;
525 #if (BODY_FORCE & VECTOR)
529 rhs[
i][ENG] += dt*0.5*(flux[
i][
RHO] + flux[i-1][
RHO])*g[
JDIR];
546 for (j = beg; j <= end; j++){
554 NVAR_LOOP(nv) rhs[
j][nv] = -dtdx*(flux[
j][nv] - flux[j-1][nv]);
555 rhs[
j][
iMPHI] -= dtdx*(p[
j] - p[j-1]);
562 #if (BODY_FORCE & VECTOR)
566 rhs[
j][ENG] += dt*0.5*(flux[
j][
RHO] + flux[j-1][
RHO])*g[
JDIR];
584 for (k = beg; k <= end; k++){
592 NVAR_LOOP(nv) rhs[
k][nv] = -dtdx*(flux[
k][nv] - flux[k-1][nv]);
593 rhs[
k][
iMZ] -= dtdx*(p[
k] - p[k-1]);
600 #if (BODY_FORCE & VECTOR)
604 rhs[
k][ENG] += dt*0.5*(flux[
k][
RHO] + flux[k-1][
RHO])*g[
KDIR];
610 #elif GEOMETRY == SPHERICAL
621 double s, s2, ct, s_1;
622 double vB,
vel2, lor2, wt,
B2;
623 double mth = 0.0, mphi = 0.0;
633 th = x2[
j]; s = sin(th);
635 for (i = beg - 1; i <= end; i++){
641 EXPAND(fA[i][
iMR] = flux[i][
iMR]*r2; ,
645 EXPAND(fA[i][
iBR] = flux[i][
iBR]*r2; ,
650 fA[i][ENG] = flux[i][ENG]*r2;
671 for (i = beg; i <= end; i++) {
683 rhs[i][
iMR] = - dtdV*(fA[i][
iMR] - fA[i-1][
iMR])
684 - dtdx*(p[i] - p[i-1]); ,
690 rhs[i][
iBR] = -dtdV*(fA[i][
iBR] - fA[i-1][
iBR]); ,
695 rhs[i][
iBR] = -dtdx*(flux[i][
iBR] - flux[i-1][
iBR]);
700 rhs[
i][ENG] = -dtdV*(fA[
i][ENG] - fA[i-1][ENG]);
704 NSCL_LOOP(nv) rhs[
i][nv] = -dtdV*(fA[
i][nv] - fA[i-1][nv]);
714 lor2 = 1.0/(1.0 -
vel2);
716 vB = EXPAND(v[VX1]*v[
BX1], + v[VX2]*v[
BX2], + v[VX3]*v[
BX3]);
717 B2 = EXPAND(v[BX1]*v[BX1], + v[BX2]*v[BX2], + v[BX3]*v[BX3]);
718 wt = v[
RHO]*h[
i]*lor2 +
B2;
723 wt = v[
RHO]*h[i]*lor2;
729 Sm = EXPAND( 0.0, + mth*v[
iVTH], + mphi*v[
iVPHI]);
731 Sm += EXPAND( 0.0, - (v[
iBTH]/lor2 + vB*v[iVTH])*v[
iBTH],
734 rhs[
i][
iMR] += dt*Sm*r_1;
740 #if (BODY_FORCE & VECTOR)
744 rhs[
i][ENG] += dt*0.5*(flux[
i][
RHO] + flux[i-1][
RHO])*g[
IDIR];
759 for (j = beg - 1; j <= end; j++){
764 EXPAND(fA[j][
iMR] = flux[j][
iMR]*s; ,
768 EXPAND(fA[j][
iBR] = flux[j][
iBR]*s; ,
773 fA[j][ENG] = flux[j][ENG]*s;
791 r_1 = 0.5*(x1p[
i]*x1p[
i] - x1p[i-1]*x1p[i-1])/dV1[i];
796 for (j = beg; j <= end; j++){
798 dtdV = dt/dV2[
j]*r_1;
799 dtdx = dt/dx2[
j]*r_1;
810 rhs[j][
iMR] = - dtdV*(fA[j][
iMR] - fA[j-1][
iMR]); ,
812 - dtdx*(p[j] - p[j-1]); ,
817 rhs[j][
iBR] = -dtdV*(fA[j][
iBR] - fA[j-1][
iBR]); ,
827 rhs[
j][ENG] = -dtdV*(fA[
j][ENG] - fA[j-1][ENG]);
830 NSCL_LOOP(nv) rhs[
j][nv] = -dtdV*(fA[
j][nv] - fA[j-1][nv]);
839 lor2 = 1.0/(1.0 -
vel2);
841 vB = EXPAND(v[VX1]*v[
BX1], + v[VX2]*v[
BX2], + v[VX3]*v[
BX3]);
842 B2 = EXPAND(v[BX1]*v[BX1], + v[BX2]*v[BX2], + v[BX3]*v[BX3]);
843 wt = v[
RHO]*h[
j]*lor2 +
B2;
848 wt = v[
RHO]*h[j]*lor2;
854 Sm = EXPAND( 0.0, - mth*v[
iVR], + ct*mphi*v[
iVPHI]);
856 Sm += EXPAND( 0.0, + (v[
iBTH]/lor2 + vB*v[
iVTH])*v[
iBR],
859 rhs[
j][
iMTH] += dt*Sm*r_1;
865 #if (BODY_FORCE & VECTOR)
869 rhs[
j][ENG] += dt*0.5*(flux[
j][
RHO] + flux[j-1][
RHO])*g[
JDIR];
885 r_1 = 0.5*(x1p[
i]*x1p[
i] - x1p[i-1]*x1p[i-1])/dV1[i];
886 scrh = dt*r_1*dx2[
j]/dV2[
j];
888 for (k = beg; k <= end; k++) {
896 NVAR_LOOP(nv) rhs[
k][nv] = -dtdx*(flux[
k][nv] - flux[k-1][nv]);
897 rhs[
k][
iMPHI] -= dtdx*(p[
k] - p[k-1]);
904 #if (BODY_FORCE & VECTOR)
908 rhs[
k][ENG] += dt*0.5*(flux[
k][
RHO] + flux[k-1][
RHO])*g[
KDIR];
921 #if DIVB_CONTROL == EIGHT_WAVES
922 for (i = beg; i <= end; i++) {
923 EXPAND(rhs[i][
MX1] += dt*state->
src[i][
MX1]; ,
927 EXPAND(rhs[i][
BX1] += dt*state->
src[i][
BX1]; ,
931 rhs[
i][ENG] += dt*state->
src[
i][ENG];
941 #if (defined GLM_MHD) && (GLM_EXTENDED == YES)
942 print1 (
"! RightHandSide(): Extended GLM source terms not defined for RMHD\n");
950 #if INTERNAL_BOUNDARY == YES
963 for (i = beg-1; i <= end; i++) {
967 #if GEOMETRY == POLAR || GEOMETRY == SPHERICAL
969 cl /= fabs(grid[
IDIR].xgc[
g_i]);
971 #if GEOMETRY == SPHERICAL
double ** v
Cell-centered primitive varables at the base time level, v[i] = .
double ** vh
Primitive state at n+1/2 (only for one step method)
double ** flux
upwind flux computed with the Riemann solver
void print1(const char *fmt,...)
double ** rhs
Conservative right hand side.
void Enthalpy(double **v, real *h, int beg, int end)
double * cmax
Maximum signal velocity for hyperbolic eqns.
double inv_dta
Inverse of advection (hyperbolic) time step, .
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
int g_dir
Specifies the current sweep or direction of integration.
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
void RightHandSide(const State_1D *state, Time_Step *Dts, int beg, int end, double dt, Grid *grid)
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
double * r_1
Geometrical factor 1/r.
#define ARRAY_1D(nx, type)
long int NMAX_POINT
Maximum number of points among the three directions, boundaries excluded.
void InternalBoundaryReset(const State_1D *, Time_Step *, int, int, Grid *)
void BodyForceVector(double *, double *, double, double, double)
double * ct
Geometrical factor cot(theta).
double * press
Upwind pressure term computed with the Riemann solver.
#define ARRAY_2D(nx, ny, type)
double * inv_dxi
inverse of the distance between the center of two cells, inv_dxi = .
#define QUIT_PLUTO(e_code)
void AdvectFlux(const State_1D *state, int beg, int end, Grid *grid)
double * A
Right interface area, A[i] = .