PLUTO
fluxes.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Compute the MHD flux.
5 
6  Compute the flux of the conservative MHD equations in the direction
7  given by ::g_dir.
8  This function defines the component of the hyperbolic flux tensor
9  of the standard MHD equations.\n
10  In what follows:
11  - \c VXn, \c MXn, \c BXn are the velocity, momentum and magnetic field
12  components in the direction given by ::g_dir (normal, \c "n")
13  - \c VXt, \c MXt, \c BXt and \c VXb, \c MXb, \c BXb are the transverse
14  components (tangent \c "t" and bi-tangent \c "b").
15 
16  \author A. Mignone (mignone@ph.unito.it)
17  \date Jan 16, 2014
18 */
19 /* ///////////////////////////////////////////////////////////////////// */
20 #include "pluto.h"
21 
22 /* ********************************************************************* */
23 void Flux (double **ucons, double **wprim, double *a2, double **bck,
24  double **fx, double *p, int beg, int end)
25 
26 /*!
27  * \param [in] ucons 1D array of conserved quantities
28  * \param [in] wprim 1D array of primitive quantities
29  * \param [in] a2 1D array of sound speeds
30  * \param [in] bck 1D array of background field values
31  * \param [out] fx 1D array of fluxes (total pressure excluded)
32  * \param [out] p 1D array of pressure values
33  * \param [in] beg initial index of computation
34  * \param [in] end final index of computation
35  *
36  * \return This function has no return value.
37  *********************************************************************** */
38 {
39  int nv, i;
40  double vB, ptot;
41  double bt1, bt2, bt3;
42  double *w, *u;
43 
44  for (i = beg; i <= end; i++) {
45 
46  w = wprim[i];
47  u = ucons[i];
48 
49  ptot = 0.5*(EXPAND(w[BX1]*w[BX1] , + w[BX2]*w[BX2], + w[BX3]*w[BX3]));
50 
51  #if HAVE_ENERGY
52  ptot += w[PRS];
53  #elif EOS == BAROTROPIC
54  ptot += BAROTROPIC_PR(w[RHO]);
55  #elif EOS == ISOTHERMAL
56  ptot += a2[i]*w[RHO];
57  #else
58  print ("! Flux(): not defined for this EoS\n");
59  QUIT_PLUTO(1);
60  #endif
61 
62  vB = EXPAND(w[VX1]*w[BX1] , + w[VX2]*w[BX2], + w[VX3]*w[BX3]);
63 
64  #if BACKGROUND_FIELD == YES
65  ptot += EXPAND(bck[i][BX1]*w[BX1], + bck[i][BX2]*w[BX2], + bck[i][BX3]*w[BX3]);
66 
67  EXPAND(bt1 = w[BXn] + bck[i][BXn]; ,
68  bt2 = w[BXt] + bck[i][BXt]; ,
69  bt3 = w[BXb] + bck[i][BXb];)
70 
71  fx[i][RHO] = u[MXn];
72  EXPAND(fx[i][MX1] = w[VXn]*u[MX1] - bt1*w[BX1] - w[BXn]*bck[i][BX1]; ,
73  fx[i][MX2] = w[VXn]*u[MX2] - bt1*w[BX2] - w[BXn]*bck[i][BX2]; ,
74  fx[i][MX3] = w[VXn]*u[MX3] - bt1*w[BX3] - w[BXn]*bck[i][BX3]; )
75 
76  EXPAND(fx[i][BXn] = 0.0; ,
77  fx[i][BXt] = w[VXn]*bt2 - bt1*w[VXt]; ,
78  fx[i][BXb] = w[VXn]*bt3 - bt1*w[VXb]; )
79  #if HAVE_ENERGY
80  fx[i][ENG] = (u[ENG] + ptot)*w[VXn] - bt1*vB;
81  #endif
82  #else
83  fx[i][RHO] = u[MXn];
84  EXPAND(fx[i][MX1] = w[VXn]*u[MX1] - w[BXn]*w[BX1]; ,
85  fx[i][MX2] = w[VXn]*u[MX2] - w[BXn]*w[BX2]; ,
86  fx[i][MX3] = w[VXn]*u[MX3] - w[BXn]*w[BX3]; )
87 
88  EXPAND(fx[i][BXn] = 0.0; ,
89  fx[i][BXt] = w[VXn]*w[BXt] - w[BXn]*w[VXt]; ,
90  fx[i][BXb] = w[VXn]*w[BXb] - w[BXn]*w[VXb]; )
91  #if HAVE_ENERGY
92  fx[i][ENG] = (u[ENG] + ptot)*w[VXn] - w[BXn]*vB;
93  #endif
94  #endif
95 
96  p[i] = ptot;
97 
98  #ifdef GLM_MHD
99  fx[i][BXn] = w[PSI_GLM];
100  fx[i][PSI_GLM] = glm_ch*glm_ch*w[BXn];
101  #endif
102  }
103 }
#define MX3
Definition: mod_defs.h:22
#define MX1
Definition: mod_defs.h:20
#define VX2
Definition: mod_defs.h:29
void Flux(double **u, double **w, double *a2, double **fx, double *p, int beg, int end)
Definition: fluxes.c:23
#define RHO
Definition: mod_defs.h:19
#define PSI_GLM
Definition: mod_defs.h:34
#define VX1
Definition: mod_defs.h:28
int VXb
Definition: globals.h:73
int BXn
Definition: globals.h:75
#define MX2
Definition: mod_defs.h:21
int VXt
Definition: globals.h:73
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
int MXn
Definition: globals.h:74
int VXn
Definition: globals.h:73
#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 VX3
Definition: mod_defs.h:30
#define BX2
Definition: mod_defs.h:26
double glm_ch
The propagation speed of divergence error.
Definition: glm.c:21
int BXt
Definition: globals.h:75
int BXb
Definition: globals.h:75
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define HAVE_ENERGY
Definition: pluto.h:395