PLUTO
mean_mol_weight.c
Go to the documentation of this file.
1 /* ///////////////////////////////////////////////////////////////////// */
2 /*!
3  \file
4  \brief Compute the mean molecular weight.
5 
6  Compute and return the mean molecular weight as a function of the gas
7  composition under non-equilibrium conditions.
8  The mean molecular weight is usually needed to compute the temperature
9  or mass density from the particle number density:
10  \f[
11  T = \frac{p}{n_{\rm tot}k_B} = \frac{p}{\rho}\frac{m_u\mu}{k_B}
12  \,,\qquad
13  \rho = \mu m_u n_{\rm tot}
14  \f]
15  where \f$ m_u \f$ is the atomic mass unit while
16  \f$ n_{\rm tot} \f$ is the number density of all particles.
17  The Mean molecular weight is defined as the average mass of a particle of
18  gas in terms of the atomic mass unit and it is expressed by the weighted
19  sum of the mass of particles in atomic mass unit divided by total number
20  of particles (see book by Ryan & Norton [Eq. 1.7])
21  \f[
22  \mu = \frac{\DS\sum_k N_k \frac{m_k}{m_u}}{\DS\sum_k N_k}
23  \f]
24  where
25  - \f$ N_k \f$ is the number of particles in the gas of element k and it
26  can be related to mass fraction \f$X_k\f$ as
27  \f$\DS \frac{N_k}{V} = n_k = \frac{\rho}{m_u}\frac{X_k}{A_k}\f$, where
28  \f$A_k\f$ is the atomic mass number.
29  - \f$ m_k \f$ is the mass of each particle of element k.
30 
31  \b H2_COOL: to compute \f$\mu\f$ we proceed as follows:
32  -# using standard solar composition \f$ X_{\odot},\, Y_{\odot},\, Z_{\odot}\f$
33  we derive
34  \f[
35  \frac{N_{He}}{N_H} = \frac{Y_{\odot}}{A_{He}}\frac{A_H}{X_\odot}
36  ,\,\qquad
37  \frac{N_Z}{N_H} = \frac{Z_{\odot}}{A_{Z}}\frac{A_H}{X_\odot}
38  \f]
39  -# The weighted sum of the mass of particles in the numerator of \f$\mu\f$
40  is given by
41  \f[
42  \sum_k N_k \frac{m_k}{m_u} = N_H \frac{m_H}{m_u}
43  + N_{He}\frac{m_{He}}{m_u}
44  + N_Z \frac{m_Z}{m_u}
45  \f]
46  Note that since mass of electron is negligible, so is its contribution to
47  the previous summation.
48  -# For the denominator we have
49  \f[
50  \sum_k N_k = N_{HI} + N_{HII} + N_{H2} + N_e + N_{He} + N_Z
51  + \frac{A_ZN_Z}{2}
52  \f]
53  where two sources of electrons considered here: \f$ N_e \f$ electrons
54  corresponding to \f$ N_{HII} \f$ protons due to ionization of hydrogen and
55  \f$ A_ZN_Z/2 \f$ number of electrons due to metals.
56  Note that now the electrons contribute to the total number of particles
57  and cannot be neglected.
58  -# Next define the total number of hydrogen,
59  \f$ N_H = N_{HI} + N_{HII} + 2N_{H2} \f$ as the sum of number of atomic
60  hydrogen (HI), ionized hydrogen (HII, or protons) and twice the number
61  of molecular hydrogen (H2) and the corresponding number fractions:
62  \f[
63  f_{HI} = \frac{N_{HI}}{N_H},\quad
64  f_{HII} = \frac{N_{HII}}{N_H},\quad
65  f_{H2} = \frac{N_{H2}}{N_H},\quad
66  \f]
67  so that \f$ f_{HI} + 2f_{H2} + f_{HII} = 1 \f$.
68 
69  Putting it all together:
70  \f[
71  \mu = \frac{A_H + A_{He}f_{He} + A_Zf_Z}
72  {f_{HI} + f_{H2} + 2f_{HII} + f_{He} + f_Z + A_Z f_Z/2}
73  \f]
74  where
75  - \f$A_{He}, A_Z \f$ are atomic mass numbers of helium and metals respectively.
76  - \f$f_{He} = N_{He}/N_H\f$ is the fixed number fraction of helium with
77  respect to hydrogen;
78  - \f$f_Z = N_Z/N_H\f$ is the fixed number fraction of metals with respect to
79  hydrogen.
80 
81 
82  \b MINEq: please see Eq. [12] of Tesileanu (2008)
83 
84  \b SNEq: the derivation is similar to H2_COOL with \f$ f_{H2} = 0\f$ yielding
85  \f[
86  \mu = \frac{A_H + A_{He}f_{He} + A_Zf_Z}
87  {2 - f_{HI} + f_{He} + 2f_Z}
88  \f]
89  where one electron from metals is assumed.
90 
91  \b No \b Chemistry: in case where chemical reaction are not incuded,
92  the mean molecular weight is computed from the mass fractions assuming
93  a fully ionized gas:
94  \f[
95  \mu = \frac{A_H + A_{He}f_{He} + A_Zf_Z}{2 + f_{He} + f_Z(1 + A_Z/2)}
96  \f]
97 
98 
99  \b References
100  - "Stellar Evolution and Nucleosynthesis"
101  Sean G. Ryan and Andrew J. Norton.
102  The University of Chicago Press
103  - "Simulating radiative astrophysical flows with the PLUTO code:
104  a non-equilibrium, multi-species cooling function",
105  Tesileanu, Mignone \& Massaglia, A\&A (2008) 488, 429
106 
107  \authors A. Mignone (mignone@ph.unito.it)\n
108  B. Vaidya
109 
110  \date Aug 11, 2015
111 */
112 /* ///////////////////////////////////////////////////////////////////// */
113 #include "pluto.h"
114 //#if (COOLING == SNEq) || (COOLING == MINEq) || (COOLING == H2_COOL)
115 #if (COOLING == MINEq)
116  #include "cooling_defs.h"
117 #endif
118 
119 /* ********************************************************************* */
120 double MeanMolecularWeight(double *v)
121 /*!
122  *
123  * Return the mean molecular weight.
124  *
125  * \param [in] v array of primitive variables (including ions)
126  *
127  *********************************************************************** */
128 {
129  int nv;
130  double mu;
131 
132 #if COOLING == NO
133 
135  (2.0 + FRAC_He + FRAC_Z*(1.0 + CONST_AZ*0.5));
136 
137 #elif COOLING == TABULATED
138 
140  (2.0 + FRAC_He + FRAC_Z*(1.0 + CONST_AZ*0.5));
141 
142 #elif COOLING == SNEq
143 
145  (2.0 + FRAC_He + 2.0*FRAC_Z - v[X_HI]);
146 
147 /*
148  return ( (CONST_AH + frac_He*CONST_AHe + frac_Z*CONST_AZ) /
149  (2.0 + frac_He + 2.0*frac_Z - v[X_HI]));
150 */
151 
152 #elif COOLING == H2_COOL
153 
154  double munum, muden;
155 
156  NIONS_LOOP(nv){
157  v[nv] = MAX(v[nv], 0.0);
158  v[nv] = MIN(v[nv], 1.0);
159  }
160 
161  v[X_H2] = MIN(v[X_H2], 0.5);
162 
163  double fn = v[X_HI];
164  double gn = v[X_H2];
165  double hn = v[X_HII];
166 
168  (fn + gn + 2*hn + FRAC_He + FRAC_Z + 0.5*CONST_AZ*FRAC_Z);
169 
170 /*
171  double N_H = (H_MASS_FRAC/CONST_AH);
172  double N_He = (He_MASS_FRAC/CONST_AHe);
173  double N_Z = ((1.0 - H_MASS_FRAC - He_MASS_FRAC)/CONST_AZ);
174 
175  double fracHe = N_He/N_H;
176  double fracZ = N_Z/N_H;
177 
178  double fn = v[X_HI];
179  double gn = v[X_H2];
180  double hn = v[X_HII];
181 
182  munum = 1.0 + CONST_AHe*(fracHe) + CONST_AZ*(fracZ);
183  muden = fn + gn + 2*hn + fracHe + fracZ + 0.5*CONST_AZ*(fracZ);
184 
185  return munum/muden;
186 */
187 #elif COOLING == MINEq
188 
189  double mmw1, mmw2;
190  int i, j;
191 
192  mmw1 = mmw2 = 0.0;
193  for (i = 0; i < NIONS; i++) {
194  if (v[NFLX+i] < 0.0) v[NFLX+i] = 0.0;
195  if (v[NFLX+i] > 1.0) v[NFLX+i] = 1.0;
197  CoolCoeffs.dmuD_dX[i] = elem_ab[elem_part[i]] *rad_rec_z[i];
198  mmw1 += CoolCoeffs.dmuN_dX[i]*v[NFLX+i]; /* Numerator part of mu */
199  mmw2 += CoolCoeffs.dmuD_dX[i]*v[NFLX+i]; /* Denominator part of mu */
200  }
201 
202 /* -- Add contributions from ionized H -- */
203 
205  CoolCoeffs.dmuD_dX[0] += -2.0*elem_ab[el_H];
206 
207  mmw1 += elem_mass[0]*elem_ab[el_H]*(1.0 - v[X_HI]);
208  mmw2 += elem_ab[el_H]*(1.0 - v[X_HI])*2.;
209 
210  CoolCoeffs.muN = mmw1;
211  CoolCoeffs.muD = mmw2;
212 
213  if (mmw1 != mmw1) {
214  print(">>> Error! MMW1 NaN! %ld\n",g_stepNumber);
215  for (i = 0; i < NIONS; i++) {
216  print ("%d %10.4e\n",i,v[NFLX+i]);
217  }
218  QUIT_PLUTO(1);
219  }
220  if (mmw2 != mmw2) {
221  print(">>> Error! MMW2 NaN!\n");
222  for (i = 0; i < NIONS; i++) {
223  print ("%d %10.4e\n",i,v[NFLX+i]);
224  }
225  QUIT_PLUTO(1);
226  }
227 
228  mu = mmw1/mmw2;
229 
230 #endif
231 
232  return mu;
233 }
#define MAX(a, b)
Definition: macros.h:101
#define NIONS_LOOP(n)
Definition: pluto.h:614
#define CONST_AH
Definition: pluto.h:250
#define FRAC_Z
Definition: pluto.h:556
const double elem_ab[8]
Definition: radiat.c:9
const double rad_rec_z[31]
Definition: radiat.c:24
COOL_COEFF CoolCoeffs
Definition: radiat.c:38
double MeanMolecularWeight(double *v)
const double elem_mass[8]
Definition: radiat.c:14
#define MIN(a, b)
Definition: macros.h:104
long int g_stepNumber
Gives the current integration step number.
Definition: globals.h:97
#define X_HII
Definition: cooling.h:31
#define NFLX
Definition: mod_defs.h:32
double dmuN_dX[NIONS]
Definition: cooling_defs.h:53
#define NIONS
Definition: cooling.h:28
#define CONST_AZ
Mean atomic weight of heavy elements.
Definition: pluto.h:252
int j
Definition: analysis.c:2
Definition: cooling.h:110
const int elem_part[31]
Definition: radiat.c:16
void print(const char *fmt,...)
Definition: amrPluto.cpp:497
double dmuD_dX[NIONS]
Definition: cooling_defs.h:54
PLUTO main header file.
int i
Definition: analysis.c:2
#define X_H2
Definition: cooling.h:30
#define CONST_AHe
Atomic weight of Helium.
Definition: pluto.h:251
#define FRAC_He
Definition: pluto.h:555
#define QUIT_PLUTO(e_code)
Definition: macros.h:125
#define el_H
Definition: cooling_defs.h:71