PLUTO
res_flux.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Compute the resistive MHD flux.
5 
6  Compute the resistive fluxes for the induction and energy equations.
7  In the induction equation, fluxes are computed by explicitly writing
8  the curl operator in components. In Cartesian components, for instance,
9  one has
10  \f[
11  \pd{\vec{B}}{t} = - \nabla\times{\vec{E}_{\rm res}} =
12  \pd{}{x}\left(\begin{array}{c}
13  0 \\ \noalign{\medskip}
14  \eta_z J_z \\ \noalign{\medskip}
15  - \eta_y J_y \end{array}\right)
16  +
17  \pd{}{y}\left(\begin{array}{c}
18  - \eta_z J_z \\ \noalign{\medskip}
19  0 \\ \noalign{\medskip}
20  \eta_x J_x \end{array}\right)
21  +
22  \pd{}{z}\left(\begin{array}{c}
23  \eta_y J_y \\ \noalign{\medskip}
24  -\eta_x J_x \\ \noalign{\medskip}
25  0 \end{array}\right)
26  \,,\qquad
27  \left(\vec{E}_{\rm res} = \tens{\eta}\cdot\vec{J}\right)
28  \f]
29  where \f$\tens{\eta}\f$ is the resistive diagonal tensor and
30  \f$J = \nabla\times\vec{B}\f$ is the current density.
31  The corresponding contribution to the energy equation is
32  \f[
33  \pd{E}{t} = -\nabla\cdot\Big[(\tens{\eta}\cdot\vec{J})\times\vec{B}\Big]
34  = - \pd{}{x}\left(\eta_yJ_yB_z - \eta_zJ_zB_y\right)
35  - \pd{}{y}\left(\eta_zJ_zB_x - \eta_xJ_xB_z\right)
36  - \pd{}{z}\left(\eta_xJ_xB_y - \eta_yJ_yB_x\right)
37  \f]
38 
39  \b References
40  - "The PLUTO Code for Adaptive Mesh Computations in Astrophysical
41  Fluid Dynamics" \n
42  Mignone et al, ApJS (2012) 198, 7M
43 
44  \authors A. Mignone (mignone@ph.unito.it)\n
45  T. Matsakos
46  \date Feb 20, 2014
47 */
48 /* ///////////////////////////////////////////////////////////////////// */
49 #include "pluto.h"
50 
51 /* ********************************************************************* */
52 void ResistiveFlux (Data_Arr V, Data_Arr curlB, double **res_flux,
53  double **dcoeff, int beg, int end, Grid *grid)
54 /*!
55  * Compute resistive fluxes for the induction and energy
56  * equations. Also, compute the diffusion coefficient.
57  * Called by either ParabolicFlux or ParabolicRHS.
58  *
59  * \param [in] V 3D data array of primitive variables
60  * \param [out] res_flux the resistive fluxes
61  * \param [out] dcoeff the diffusion coefficients evaluated at
62  * cell interfaces
63  * \param [in] beg initial index of computation
64  * \param [in] end final index of computation
65  * \param [in] grid pointer to an array of Grid structures.
66  *
67  *********************************************************************** */
68 {
69  int i, j, k, nv;
70  double *x1, *x2, *x3, scrh;
71  double eta[3], vp[NVAR], Jp[NVAR];
72  Data_Arr etas;
73  double ***Jx1, ***Jx2, ***Jx3;
74  double ***eta_x1, ***eta_x2, ***eta_x3;
75 
76  #ifdef STAGGERED_MHD
77  etas = GetStaggeredEta();
78  Jx1 = curlB[IDIR]; eta_x1 = etas[IDIR];
79  Jx2 = curlB[JDIR]; eta_x2 = etas[JDIR];
80  Jx3 = curlB[KDIR]; eta_x3 = etas[KDIR];
81  #endif
82 
83  x1 = grid[IDIR].x;
84  x2 = grid[JDIR].x;
85  x3 = grid[KDIR].x;
86 
87 /* -----------------------------------------------
88  Compute resistive flux for the induction
89  and energy equations
90  ----------------------------------------------- */
91 
92  if (g_dir == IDIR){
93 
94  j = g_j; k = g_k;
95  x1 = grid[IDIR].xr;
96  for (i = beg; i <= end; i++){
97 
98  /* -- interface values at (i+1/2, j, k) -- */
99 
100  for (nv = 0; nv < NVAR; nv++){
101  vp[nv] = 0.5*(V[nv][k][j][i] + V[nv][k][j][i + 1]);
102  }
103 
104  #ifdef STAGGERED_MHD
105  EXPAND( ; ,
106  Jp[KDIR] = AVERAGE_Y(Jx3,k,j-1,i); ,
107  Jp[JDIR] = AVERAGE_Z(Jx2,k-1,j,i);)
108 
109  EXPAND( ; ,
110  eta[KDIR] = AVERAGE_Y(eta_x3,k,j-1,i); ,
111  eta[JDIR] = AVERAGE_Z(eta_x2,k-1,j,i);)
112  #else
113  for (nv = 0; nv < 3; nv++) Jp[nv] = curlB[nv][k][j][i];
114  Resistive_eta (vp, x1[i], x2[j], x3[k], Jp, eta);
115  #endif
116 
117  EXPAND( ; ,
118  res_flux[i][BX2] = - eta[KDIR]*Jp[KDIR]; ,
119  res_flux[i][BX3] = eta[JDIR]*Jp[JDIR];)
120 
121  #if HAVE_ENERGY
122  res_flux[i][ENG] = EXPAND(0.0, + vp[BX2]*res_flux[i][BX2],
123  + vp[BX3]*res_flux[i][BX3]);
124  #endif
125 
126  /* -- store diffusion coefficient -- */
127 
128  EXPAND(dcoeff[i][BX1] = 0.0; ,
129  dcoeff[i][BX2] = eta[KDIR]; ,
130  dcoeff[i][BX3] = eta[JDIR];)
131  }
132 
133  }else if (g_dir == JDIR){
134 
135  i = g_i; k = g_k;
136  x2 = grid[JDIR].xr;
137  for (j = beg; j <= end; j++){
138 
139  /* -- interface value -- */
140 
141  for (nv = 0; nv < NVAR; nv++) {
142  vp[nv] = 0.5*(V[nv][k][j][i] + V[nv][k][j + 1][i]);
143  }
144 
145  #ifdef STAGGERED_MHD
146  EXPAND(Jp[KDIR] = AVERAGE_X(Jx3,k,j,i-1); ,
147  ; ,
148  Jp[IDIR] = AVERAGE_Z(Jx1,k-1,j,i);)
149 
150  EXPAND(eta[KDIR] = AVERAGE_Y(eta_x3,k,j,i-1); ,
151  ; ,
152  eta[IDIR] = AVERAGE_Z(eta_x1,k-1,j,i);)
153  #else
154  for (nv = 0; nv < 3; nv++) Jp[nv] = curlB[nv][k][j][i];
155  Resistive_eta (vp, x1[i], x2[j], x3[k], Jp, eta);
156  #endif
157 
158  EXPAND(res_flux[j][BX1] = eta[KDIR]*Jp[KDIR]; ,
159  ; ,
160  res_flux[j][BX3] = - eta[IDIR]*Jp[IDIR];)
161 
162  #if HAVE_ENERGY
163  res_flux[j][ENG] = EXPAND( vp[BX1]*res_flux[j][BX1],
164  + 0.0,
165  + vp[BX3]*res_flux[j][BX3]);
166  #endif
167 
168  /* -- store diffusion coefficient -- */
169 
170  EXPAND(dcoeff[j][BX1] = eta[KDIR]; ,
171  dcoeff[j][BX2] = 0.0; ,
172  dcoeff[j][BX3] = eta[IDIR];)
173  }
174 
175  }else if (g_dir == KDIR){
176 
177  i = g_i; j = g_j;
178  x3 = grid[KDIR].xr;
179  for (k = beg; k <= end; k++){
180 
181  /* -- interface value -- */
182 
183  for (nv = 0; nv < NVAR; nv++) {
184  vp[nv] = 0.5*(V[nv][k][j][i] + V[nv][k + 1][j][i]);
185  }
186 
187  #ifdef STAGGERED_MHD
188  Jp[JDIR] = AVERAGE_X(Jx2,k,j,i-1);
189  Jp[IDIR] = AVERAGE_Y(Jx1,k,j-1,i);
190 
191  eta[JDIR] = AVERAGE_X(eta_x2,k,j,i-1);
192  eta[IDIR] = AVERAGE_Y(eta_x1,k,j-1,i);
193  #else
194  for (nv = 0; nv < 3; nv++) Jp[nv] = curlB[nv][k][j][i];
195  Resistive_eta (vp, x1[i], x2[j], x3[k], Jp, eta);
196  #endif
197 
198  res_flux[k][BX1] = - eta[JDIR]*Jp[JDIR];
199  res_flux[k][BX2] = eta[IDIR]*Jp[IDIR];
200 
201  #if EOS != ISOTHERMAL
202  res_flux[k][ENG] = vp[BX1]*res_flux[k][BX1] + vp[BX2]*res_flux[k][BX2];
203  #endif
204 
205  /* -- store diffusion coefficient -- */
206 
207  EXPAND(dcoeff[k][BX1] = eta[JDIR]; ,
208  dcoeff[k][BX2] = eta[IDIR]; ,
209  dcoeff[k][BX3] = 0.0;)
210  }
211  }
212 }
#define AVERAGE_Z(q, k, j, i)
Definition: macros.h:258
double **** Data_Arr
Definition: pluto.h:492
double * xr
Definition: structs.h:81
tuple scrh
Definition: configure.py:200
static double *** eta[3]
Definition: res_functions.c:94
#define KDIR
Definition: pluto.h:195
#define AVERAGE_Y(q, k, j, i)
Definition: macros.h:257
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
int j
Definition: analysis.c:2
int k
Definition: analysis.c:2
#define AVERAGE_X(q, k, j, i)
Definition: macros.h:256
double * x
Definition: structs.h:80
int g_k
x3 grid index when sweeping along the x1 or x2 direction.
Definition: globals.h:84
void Resistive_eta(double *v, double x1, double x2, double x3, double *J, double *eta)
Definition: res_eta.c:17
#define BX3
Definition: mod_defs.h:27
PLUTO main header file.
int i
Definition: analysis.c:2
#define BX1
Definition: mod_defs.h:25
#define BX2
Definition: mod_defs.h:26
#define JDIR
Definition: pluto.h:194
void ResistiveFlux(Data_Arr V, Data_Arr curlB, double **res_flux, double **dcoeff, int beg, int end, Grid *grid)
Definition: res_flux.c:52
#define NVAR
Definition: pluto.h:609
#define HAVE_ENERGY
Definition: pluto.h:395