-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathres_flux.c
executable file
·213 lines (170 loc) · 6.64 KB
/
res_flux.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* ///////////////////////////////////////////////////////////////////// */
/*!
\file
\brief Compute the resistive MHD flux for cell-centered field.
Compute the resistive fluxes for the induction and energy equations
to update cell-centered fields.
Fluxes at zone faces by averaging the current available at cell edges.
Cell-centered fields are updated also when the CT formalism is employed.
In the induction equation, fluxes are computed by explicitly writing
the curl operator in components. In Cartesian components, for instance,
one has
\f[
\pd{\vec{B}}{t} = - \nabla\times{\vec{E}_{\rm res}} =
\pd{}{x}\left(\begin{array}{c}
0 \\ \noalign{\medskip}
\eta_z J_z \\ \noalign{\medskip}
- \eta_y J_y \end{array}\right)
+
\pd{}{y}\left(\begin{array}{c}
- \eta_z J_z \\ \noalign{\medskip}
0 \\ \noalign{\medskip}
\eta_x J_x \end{array}\right)
+
\pd{}{z}\left(\begin{array}{c}
\eta_y J_y \\ \noalign{\medskip}
-\eta_x J_x \\ \noalign{\medskip}
0 \end{array}\right)
\,,\qquad
\left(\vec{E}_{\rm res} = \tens{\eta}\cdot\vec{J}\right)
\f]
where \f$\tens{\eta}\f$ is the resistive diagonal tensor and
\f$\vec{J} = \nabla\times\vec{B}\f$ is the current density.
The corresponding contribution to the energy equation is
\f[
\pd{E}{t} = -\nabla\cdot\Big[(\tens{\eta}\cdot\vec{J})\times\vec{B}\Big]
= - \pd{}{x}\left(\eta_yJ_yB_z - \eta_zJ_zB_y\right)
- \pd{}{y}\left(\eta_zJ_zB_x - \eta_xJ_xB_z\right)
- \pd{}{z}\left(\eta_xJ_xB_y - \eta_yJ_yB_x\right)
\f]
The sign of the flux is given by writing each equation as
\f[
\pd{B_i}{t} = \nabla\cdot\vec{F}_i
\f]
(flux is positive on the right hand side).
\b References
- "The PLUTO Code for Adaptive Mesh Computations in Astrophysical
Fluid Dynamics" \n
Mignone et al, ApJS (2012) 198, 7M
\authors A. Mignone ([email protected])\n
T. Matsakos
\date July 10, 2019
*/
/* ///////////////////////////////////////////////////////////////////// */
#include "pluto.h"
/* ********************************************************************* */
void ResistiveFlux (Data_Arr V, Data_Arr curlB, double **res_flux,
double **dcoeff, int beg, int end, Grid *grid)
/*!
*
* \param [in] V 3D data array of primitive variables
* \param [out] curlB the current
* \param [out] dcoeff the diffusion coefficients evaluated at
* cell interfaces
* \param [in] beg initial index of computation
* \param [in] end final index of computation
* \param [in] grid pointer to an array of Grid structures.
*
*********************************************************************** */
{
int i, j, k, nv;
double *x1, *x2, *x3, scrh;
double eta[3], vp[NVAR], Jp[NVAR];
Data_Arr etas;
double ***Jx1, ***Jx2, ***Jx3;
double ***eta_x1, ***eta_x2, ***eta_x3;
etas = GetStaggeredEta();
Jx1 = curlB[IDIR]; eta_x1 = etas[IDIR];
Jx2 = curlB[JDIR]; eta_x2 = etas[JDIR];
Jx3 = curlB[KDIR]; eta_x3 = etas[KDIR];
x1 = grid->x[IDIR];
x2 = grid->x[JDIR];
x3 = grid->x[KDIR];
/* --------------------------------------------------------
1. Compute resistive flux for the induction and energy
equations at X1, X2 or X3 faces.
-------------------------------------------------------- */
if (g_dir == IDIR){
j = g_j; k = g_k;
x1 = grid->xr[IDIR];
for (i = beg; i <= end; i++){
/* -- interface values at (i+1/2, j, k) -- */
for (nv = 0; nv < NVAR; nv++){
vp[nv] = 0.5*(V[nv][k][j][i] + V[nv][k][j][i+1]);
}
/* ----------------------------------------------------
Compute transverse components of J at X1-faces as
arithmetic averages of the staggered arrays.
---------------------------------------------------- */
Jp[KDIR] = AVERAGE_Y(Jx3,k,j-1,i);
Jp[JDIR] = AVERAGE_Z(Jx2,k-1,j,i);
eta[KDIR] = AVERAGE_Y(eta_x3,k,j-1,i);
eta[JDIR] = AVERAGE_Z(eta_x2,k-1,j,i);
res_flux[i][BX1] = 0.0;
// res_flux[i][BX2] = eta[KDIR]*Jp[KDIR] - eta[KDIR]/(cosh(x1[i])*cosh(x1[i]));
res_flux[i][BX2] = eta[KDIR]*Jp[KDIR];
res_flux[i][BX3] = - eta[JDIR]*Jp[JDIR];
#if HAVE_ENERGY
res_flux[i][ENG] = vp[BX2]*res_flux[i][BX2] + vp[BX3]*res_flux[i][BX3];
#endif
/* -- store diffusion coefficient -- */
dcoeff[0][i] = 0.0;
dcoeff[1][i] = eta[KDIR];
dcoeff[2][i] = eta[JDIR];
}
}else if (g_dir == JDIR){
i = g_i; k = g_k;
x2 = grid->xr[JDIR];
for (j = beg; j <= end; j++){
/* -- interface values at (i, j+1/2, k) -- */
for (nv = 0; nv < NVAR; nv++) {
vp[nv] = 0.5*(V[nv][k][j][i] + V[nv][k][j+1][i]);
}
/* ----------------------------------------------------
Compute transverse components of J at X2-faces as
arithmetic averages of the staggered arrays.
---------------------------------------------------- */
Jp[KDIR] = AVERAGE_X(Jx3,k,j,i-1);
Jp[IDIR] = AVERAGE_Z(Jx1,k-1,j,i);
eta[KDIR] = AVERAGE_X(eta_x3,k,j,i-1);
eta[IDIR] = AVERAGE_Z(eta_x1,k-1,j,i);
res_flux[j][BX1] = - eta[KDIR]*Jp[KDIR];
res_flux[j][BX2] = 0.0;
res_flux[j][BX3] = eta[IDIR]*Jp[IDIR];
#if HAVE_ENERGY
res_flux[j][ENG] = vp[BX1]*res_flux[j][BX1] + vp[BX3]*res_flux[j][BX3];
#endif
/* -- store diffusion coefficient -- */
dcoeff[0][j] = eta[KDIR];
dcoeff[1][j] = 0.0;
dcoeff[2][j] = eta[IDIR];
}
}else if (g_dir == KDIR){
i = g_i; j = g_j;
x3 = grid->xr[KDIR];
for (k = beg; k <= end; k++){
/* -- interface values at (i, j, k+1/2) -- */
for (nv = 0; nv < NVAR; nv++) {
vp[nv] = 0.5*(V[nv][k][j][i] + V[nv][k+1][j][i]);
}
/* ----------------------------------------------------
Compute transverse components of J at X3-faces as
arithmetic averages of the staggered arrays.
---------------------------------------------------- */
Jp[JDIR] = AVERAGE_X(Jx2,k,j,i-1);
Jp[IDIR] = AVERAGE_Y(Jx1,k,j-1,i);
eta[JDIR] = AVERAGE_X(eta_x2,k,j,i-1);
eta[IDIR] = AVERAGE_Y(eta_x1,k,j-1,i);
res_flux[k][BX1] = eta[JDIR]*Jp[JDIR];
res_flux[k][BX2] = - eta[IDIR]*Jp[IDIR];
res_flux[k][BX3] = 0.0;
#if HAVE_ENERGY
res_flux[k][ENG] = vp[BX1]*res_flux[k][BX1] + vp[BX2]*res_flux[k][BX2];
#endif
/* -- store diffusion coefficient -- */
dcoeff[0][k] = eta[JDIR];
dcoeff[1][k] = eta[IDIR];
dcoeff[2][k] = 0.0;
}
}
}