PLUTO
adv_flux.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Compute flux for passive scalars.
5 
6  Compute the interface upwind flux for passive scalars \c q obeying
7  advection equations of the form:
8  \f[ \partial_tq + v\cdot \nabla q = 0
9  \qquad\Longleftrightarrow\qquad
10  \partial_t(\rho q) + \nabla\cdot(\rho\vec{v}q) = 0
11  \f]
12  Fluxes are computed using an upwind selection rule based on the
13  density flux, already computed during a previous Riemann solver:
14  \f[
15  (\rho vq)_{i+\HALF} = \left\{\begin{array}{ll}
16  (\rho v)_{i+\HALF}q_L & \;\textrm{if}
17  \quad (\rho v)_{i+\HALF} \ge 0 \\ \noalign{\medskip}
18  (\rho v)_{i+\HALF}q_R & \; \textrm{otherwise}
19  \end{array}\right.
20  \f]
21  where \f$ (\rho v)_{i+\HALF}\f$ is the density flux computed with
22  the employed Riemann solver.
23 
24  When ionization fractions are present, we employ a technique similar
25  to the CMA (Consistent multi-fluid advection method) to normalize
26  the sum of mass fractions to one.
27 
28  The CMA can also be switched on for standard tracers (<tt>
29  #define USE_CMA YES</tt>)
30 
31  \author A. Mignone (mignone@ph.unito.it)\n
32  O. Tesileanu
33  \date 02 April, 2015
34 
35  \b Reference\n
36  "The consistent multi-fluid advection method"
37  Plewa and Muller, A&A (1999) 342, 179.
38 */
39 /* /////////////////////////////////////////////////////////////////// */
40 #include "pluto.h"
41 
42 #ifndef USE_CMA
43  #define USE_CMA NO
44 #endif
45 
46 /* ********************************************************************* */
47 void AdvectFlux (const State_1D *state, int beg, int end, Grid *grid)
48 /*!
49  *
50  * \param [in,out] state
51  * \param [in] beg initial index of computation
52  * \param [in] end final index of computation
53  *
54  * \return This function has no return value.
55  *********************************************************************** */
56 {
57  int i, nv;
58  double *ts, *flux, *vL, *vR;
59  double s, rho;
60  double phi;
61  static double *sigma, **vi;
62 
63 /* -- compute scalar's fluxes -- */
64 
65  for (i = beg; i <= end; i++){
66 
67  flux = state->flux[i];
68  vL = state->vL[i];
69  vR = state->vR[i];
70 
71  ts = flux[RHO] > 0.0 ? vL:vR;
72 
73  NSCL_LOOP(nv) flux[nv] = flux[RHO]*ts[nv];
74 
75  #if COOLING == MINEq
76 
77  /* ----- He ----- */
78 
79  phi = ts[X_HeI] + ts[X_HeII];
80  for (nv = X_HeI; nv <= X_HeII; nv++) flux[nv] /= phi;
81 
82  /* ----- C ----- */
83 
84  phi = 0.0;
85  for (nv = X_CI; nv < X_CI + C_IONS; nv++) phi += ts[nv];
86  for (nv = X_CI; nv < X_CI + C_IONS; nv++) flux[nv] /= phi;
87 
88  /* ----- N ----- */
89 
90  phi = 0.0;
91  for (nv = X_NI; nv < X_NI+N_IONS; nv++) phi += ts[nv];
92  for (nv = X_NI; nv < X_NI+N_IONS; nv++) flux[nv] /= phi;
93 
94  /* ----- O ----- */
95 
96  phi = 0.0;
97  for (nv = X_OI; nv < X_OI+O_IONS; nv++) phi += ts[nv];
98  for (nv = X_OI; nv < X_OI+O_IONS; nv++) flux[nv] /= phi;
99 
100  /* ----- Ne ----- */
101 
102  phi = 0.0;
103  for (nv = X_NeI; nv < X_NeI+Ne_IONS; nv++) phi += ts[nv];
104  for (nv = X_NeI; nv < X_NeI+Ne_IONS; nv++) flux[nv] /= phi;
105 
106  /* ----- S ----- */
107 
108  phi = 0.0;
109  for (nv = X_SI; nv < X_SI+S_IONS; nv++) phi += ts[nv];
110  for (nv = X_SI; nv < X_SI+S_IONS; nv++) flux[nv] /= phi;
111 
112  #endif
113 
114  #if COOLING == H2_COOL
115  phi = ts[X_HI] + 2.0*ts[X_H2] + ts[X_HII];
116  for (nv = X_HI; nv < X_HI + NIONS; nv++) flux[nv] /= phi;
117  #endif
118 
119  #if USE_CMA == YES /* -- only for tracers -- */
120  phi = 0.0;
121  NTRACER_LOOP(nv) phi += ts[nv];
122  NTRACER_LOOP(nv) flux[nv] /= phi;
123  #endif
124 
125  #if ENTROPY_SWITCH
126  if (flux[RHO] >= 0.0) flux[ENTR] = state->vL[i][ENTR]*flux[RHO];
127  else flux[ENTR] = state->vR[i][ENTR]*flux[RHO];
128  #endif
129  }
130 }
#define S_IONS
Definition: cooling.h:17
#define NSCL_LOOP(n)
Definition: pluto.h:616
double ** flux
upwind flux computed with the Riemann solver
Definition: structs.h:149
#define RHO
Definition: mod_defs.h:19
#define C_IONS
Definition: cooling.h:13
#define NTRACER_LOOP(n)
Definition: pluto.h:615
double ** vR
Primitive variables to the right of the interface, .
Definition: structs.h:139
#define O_IONS
Definition: cooling.h:15
Definition: cooling.h:110
#define X_HII
Definition: cooling.h:31
#define NIONS
Definition: cooling.h:28
Definition: structs.h:78
Definition: cooling.h:110
#define s
PLUTO main header file.
#define Ne_IONS
Definition: cooling.h:16
int i
Definition: analysis.c:2
#define X_H2
Definition: cooling.h:30
double ** vL
Primitive variables to the left of the interface, .
Definition: structs.h:136
void AdvectFlux(const State_1D *state, int beg, int end, Grid *grid)
Definition: adv_flux.c:47
#define N_IONS
Definition: cooling.h:14