PLUTO
ct_stag_slopes.c
Go to the documentation of this file.
1 #include "pluto.h"
2 static double MC_LIM2 (double dp, double dm);
3 
4 /* ********************************************************************* */
5 void CT_StoreVelSlopes (EMF *emf, const State_1D *state, int beg, int end)
6 /*!
7  *
8  *
9  *
10  *********************************************************************** */
11 {
12  int i=g_i, j=g_j, k=g_k;
13 
14 /* ----------------------------------------------------
15  Allocate static memory areas
16  ---------------------------------------------------- */
17 
18  if (emf->dvx_dx == NULL){
19 
20  emf->dvx_dx = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
21  emf->dvx_dy = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
22 
23  emf->dvy_dx = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
24  emf->dvy_dy = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
25 
26  #if DIMENSIONS == 3
27  emf->dvx_dz = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
28  emf->dvy_dz = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
29 
30  emf->dvz_dx = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
31  emf->dvz_dy = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
32  emf->dvz_dz = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
33  #endif
34  }
35 
36  if (g_dir == IDIR){
37 
38  for (i = beg; i <= end; i++) {
39  emf->dvx_dx[k][j][i] = state->vp[i][VX1] - state->vm[i][VX1];
40  emf->dvy_dx[k][j][i] = state->vp[i][VX2] - state->vm[i][VX2];
41  #if DIMENSIONS == 3
42  emf->dvz_dx[k][j][i] = state->vp[i][VX3] - state->vm[i][VX3];
43  #endif
44  }
45 
46  }else if (g_dir == JDIR){
47 
48  for (j = beg; j <= end; j++) {
49  emf->dvx_dy[k][j][i] = state->vp[j][VX1] - state->vm[j][VX1];
50  emf->dvy_dy[k][j][i] = state->vp[j][VX2] - state->vm[j][VX2];
51  #if DIMENSIONS == 3
52  emf->dvz_dy[k][j][i] = state->vp[j][VX3] - state->vm[j][VX3];
53  #endif
54  }
55 
56  }else if (g_dir == KDIR){
57 
58  for (k = beg; k <= end; k++) {
59  emf->dvx_dz[k][j][i] = state->vp[k][VX1] - state->vm[k][VX1];
60  emf->dvy_dz[k][j][i] = state->vp[k][VX2] - state->vm[k][VX2];
61  #if DIMENSIONS == 3
62  emf->dvz_dz[k][j][i] = state->vp[k][VX3] - state->vm[k][VX3];
63  #endif
64  }
65  }
66 }
67 /* ********************************************************************* */
68 void CT_GetStagSlopes (const Data_Arr b, EMF *emf, Grid *grid)
69 /*!
70  * Compute slopes of staggered magnetic fields components:
71  * dBx/dy, dBx/dz,
72  * dBy/dx, dBy/dz,
73  * dBz/dx, dBz/dy,
74  *
75  * Exclude normal derivatives (i.e. dbx_dx).
76  *
77  *
78  *********************************************************************** */
79 {
80  int i,j,k;
81  double ***bx, ***by, ***bz;
82 
83  D_EXPAND(bx = b[BX1s]; ,
84  by = b[BX2s]; ,
85  bz = b[BX3s];)
86 
87  if (emf->dbx_dy == NULL){
88  emf->dbx_dy = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
89  emf->dby_dx = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
90  #if DIMENSIONS == 3
91  emf->dbx_dz = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
92  emf->dby_dz = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
93  emf->dbz_dx = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
94  emf->dbz_dy = ARRAY_3D(NX3_TOT, NX2_TOT, NX1_TOT, double);
95  #endif
96  }
97 
98  for (k = KOFFSET; k < NX3_TOT - KOFFSET; k++){
99  for (j = JOFFSET; j < NX2_TOT - JOFFSET; j++){
100  for (i = IOFFSET; i < NX1_TOT - IOFFSET; i++){
101 
102  emf->dbx_dy[k][j][i] = MC_LIM2(bx[k][j+1][i] - bx[k][j][i],
103  bx[k][j][i] - bx[k][j-1][i]);
104  emf->dby_dx[k][j][i] = MC_LIM2(by[k][j][i+1] - by[k][j][i],
105  by[k][j][i] - by[k][j][i-1]);
106  #if DIMENSIONS == 3
107  emf->dbx_dz[k][j][i] = MC_LIM2(bx[k+1][j][i] - bx[k][j][i],
108  bx[k][j][i] - bx[k-1][j][i]);
109  emf->dby_dz[k][j][i] = MC_LIM2(by[k+1][j][i] - by[k][j][i],
110  by[k][j][i] - by[k-1][j][i]);
111  emf->dbz_dx[k][j][i] = MC_LIM2(bz[k][j][i+1] - bz[k][j][i],
112  bz[k][j][i] - bz[k][j][i-1]);
113  emf->dbz_dy[k][j][i] = MC_LIM2(bz[k][j+1][i] - bz[k][j][i],
114  bz[k][j][i] - bz[k][j-1][i]);
115  #endif
116  }}}
117 }
118 
119 /* ********************************************************* */
120 double MC_LIM2 (double dp, double dm)
121 /*
122  *
123  *
124  *
125  *********************************************************** */
126 {
127  double dc, scrh;
128 
129  if (dp*dm < 0.0) return(0.0);
130 
131  dc = 0.5*(dp + dm);
132  scrh = 2.0*(fabs(dp) < fabs(dm) ? dp:dm);
133  return (fabs(dc) < fabs(scrh) ? dc:scrh);
134 }
135 
136 
static EMF emf
Definition: ct_emf.c:27
void CT_GetStagSlopes(const Data_Arr b, EMF *emf, Grid *grid)
double **** Data_Arr
Definition: pluto.h:492
#define VX2
Definition: mod_defs.h:29
tuple scrh
Definition: configure.py:200
long int NX2_TOT
Total number of zones in the X2 direction (boundaries included) for the local processor.
Definition: globals.h:57
double *** dvy_dx
Definition: ct.h:114
double *** dby_dz
Definition: ct.h:111
double *** dbz_dy
Definition: ct.h:112
#define BX3s
Definition: ct.h:29
#define ARRAY_3D(nx, ny, nz, type)
Definition: prototypes.h:172
#define VX1
Definition: mod_defs.h:28
double *** dbx_dz
Definition: ct.h:110
#define KDIR
Definition: pluto.h:195
double ** vp
prim vars at i+1/2 edge, vp[i] = vL(i+1/2)
Definition: structs.h:142
int g_i
x1 grid index when sweeping along the x2 or x3 direction.
Definition: globals.h:82
#define IDIR
Definition: pluto.h:193
int g_dir
Specifies the current sweep or direction of integration.
Definition: globals.h:86
int g_j
x2 grid index when sweeping along the x1 or x3 direction.
Definition: globals.h:83
Definition: structs.h:78
double *** dbx_dy
Definition: ct.h:110
long int NX3_TOT
Total number of zones in the X3 direction (boundaries included) for the local processor.
Definition: globals.h:59
double *** dvy_dy
Definition: ct.h:115
double *** dvy_dz
Definition: ct.h:116
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
double *** dvx_dx
Definition: ct.h:114
#define BX1s
Definition: ct.h:27
double *** dvx_dz
Definition: ct.h:116
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
double ** vm
prim vars at i-1/2 edge, vm[i] = vR(i-1/2)
Definition: structs.h:141
double *** dvz_dx
Definition: ct.h:114
PLUTO main header file.
void CT_StoreVelSlopes(EMF *emf, const State_1D *state, int beg, int end)
Definition: ct_stag_slopes.c:5
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;)
Definition: analysis.c:27
int i
Definition: analysis.c:2
double *** dvx_dy
Definition: ct.h:115
#define VX3
Definition: mod_defs.h:30
#define BX2s
Definition: ct.h:28
double *** dvz_dz
Definition: ct.h:116
#define JDIR
Definition: pluto.h:194
static double MC_LIM2(double dp, double dm)
double *** dvz_dy
Definition: ct.h:115
double *** dby_dx
Definition: ct.h:111
long int NX1_TOT
Total number of zones in the X1 direction (boundaries included) for the local processor.
Definition: globals.h:55
double *** dbz_dx
Definition: ct.h:112