cloudy  trunk
parse_cosmic_rays.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*ParseCosmicRays parse the cosmic rays command */
4 #include "cddefines.h"
5 #include "optimize.h"
6 #include "hextra.h"
7 #include "ionbal.h"
8 #include "input.h"
9 #include "parse.h"
10 #include "parser.h"
11 
12 /*ParseCosmicRays parse the cosmic rays command */
14 {
15  int npar = 0;
16  realnum a;
17  double var;
18  string ExtraPar;
19 
20  DEBUG_ENTRY( "ParseCosmicRays()" );
21 
22  /* cosmic ray density, log of rate relative to background, log of H0 rate in neutral gas,
23  * or density of rel. electrons,
24  * quantity is log unless keyword linear appears */
25  /* if no number is present FFmtRead returns zero */
26  a = (realnum)p.FFmtRead();
27  if( p.lgEOL() )
28  a = 0.;
29 
30  /* if keyword LINEAR not present, then log, and make linear */
31  if( !p.nMatch("LINE") )
32  a = (realnum)pow((realnum)10.f,a);
33  /* a is now linear scale factor, or linear density, with default of 1 if no number */
34 
35  /* default is cosmic ray ionization rate relative to galactic background, but can
36  * also give density, which was the only option originally */
37  if( p.nMatch("DENS") )
38  {
39  if( p.lgEOL() )
40  {
41  p.NoNumb("cosmic ray density");
42  }
43  hextra.cryden = a;
44 
45  /* optional power law density */
47 
48  /* option to specify a temp for non-rel electrons - but only when a density */
50  if( p.lgEOL() )
51  {
52  /* relativistic limit (Balbus and McKee) */
53  hextra.crtemp = 2.6e9;
54  }
55  else
56  {
57  var = pow((realnum)10.f,hextra.crtemp);
58  hextra.crtemp = (realnum)MIN2(var,2.6e9);
59  }
60  npar = 3;
61  ExtraPar = "DENSITY";
62  }
63  else if( p.nMatch( "RATE" ) )
64  {
65  /* this sets rate - use stored density and rate for background to set
66  * new density since code works with density */
67  ASSERT( a > 0. );
69  hextra.crtemp = 2.6e9f;
70  npar = 1;
71  ExtraPar = "RATE";
72  }
73  else if( p.nMatch( "BACKGROU" ) )
74  {
75  /* >>chng 06 may 28, require explicit BACKGROUnd to hit background for safety */
76  /* cr relative to galactic background BACK - no check on string since default */
77  /* >>chng 04 mar 10, background is now
78  * >>refer cr ion Williams, J.P., Bergin, E.A., Caseli, P., Myers, P.C., & Plume, R. 1998, ApJ, 503, 689 */
79  /* galactic background cosmic ray density to produce
80  * secondary ionization rate quoted by Tielens and Hollenbach */
81  /* hextra.cryden = 2e-9f;*/
82  /* >>chng 99 jun 24, slight change to value
83  * quoted by
84  * >>refer cosmic ray ionization rate McKee, C.M., 1999, astro-ph 9901370
85  * this will produce a total
86  * secondary ionization rate of 2.5e-17 s^-1, as tested in
87  * tsuite secondary.in. If each ionization produces 2.4 eV of heat,
88  * the background heating rate should be 9.6e-29 * n*/
89  /* >>chng 00 nov 28, changed density to 4.9e-9 to reproduce TH85a
90  * when photoionization is turned off.
91  >>refer cosmic ray ionization rate Tielens, A.G.G.M., & Hollenbach, D., 1998, ApJ, 291, 722
92  */
93  /* hextra.cryden = 7.07e-9f;*/
94  /* this value reproduces the TH cr ionization rate when the factor
95  * of 0.46 is included. This will directly go onto the h ionization rate
96  * without the factor of 0.46 there. this is necessary for the more
97  * general case where cr ionization is actually self-consistently determined
98  * from rate hot electrons injected into the plasma */
99  /*hextra.cryden = 2.25e-9f;*/
100  ASSERT( a > 0. );
102  hextra.crtemp = 2.6e9f;
103  npar = 1;
104  ExtraPar = "BACKGROUND";
105  }
106  else if( p.nMatch( "EQUI" ) )
107  {
108  /* equipartition cosmic rays, set from B */
110  /* this has to be positive for cr's to be on
111  * it will be reevaluated when B is known */
113  hextra.crtemp = 2.6e9f;
114  }
115 
116  else
117  {
118  /* no keyword found */
119  fprintf( ioQQQ, " There must be a keyword on this COSMIC RAY command.\n" );
120  fprintf( ioQQQ, " The keywords are DENSITY, RATE, BACKGROUND, and EQUIPARTITION.\n" );
122  }
123 
124  /* this is current cosmic ray density divided by background - used in
125  * a few chemical reactions */
127  /* >>chng 05 jan 05,
128  * set the cr ionization rate to very rough value, before we have enough
129  * information to evaluate it - may be needed in initial guess of H and He ionization*/
131 
132  /* vary option */
133  if( optimize.lgVarOn && ExtraPar.length() > 0 )
134  {
135  /* will be one parameter */
136  optimize.nvarxt[optimize.nparm] = npar;
137  sprintf( optimize.chVarFmt[optimize.nparm], "COSMic rays %s= %%f LOG", ExtraPar.c_str() );
138  /* log of cosmic rays rates relative to background */
139  optimize.vparm[0][optimize.nparm] = (realnum)log10(a);
140  if( npar == 3 )
141  {
142  strcat( optimize.chVarFmt[optimize.nparm], " %f %f" );
145  }
146  /* array index for where to write */
148  /* the increment in the first steps away from the original value */
149  optimize.vincr[optimize.nparm] = 0.2f;
150  ++optimize.nparm;
151  }
152 
153  return;
154 }
Parser::nMatch
bool nMatch(const char *chKey) const
Definition: parser.h:135
t_optimize::vincr
realnum vincr[LIMPAR]
Definition: optimize.h:191
Parser::FFmtRead
double FFmtRead(void)
Definition: parser.cpp:353
t_hextra::background_density
realnum background_density
Definition: hextra.h:28
ParseCosmicRays
void ParseCosmicRays(Parser &p)
Definition: parse_cosmic_rays.cpp:13
t_hextra::background_rate
realnum background_rate
Definition: hextra.h:29
t_optimize::nparm
long int nparm
Definition: optimize.h:201
t_input::nRead
long int nRead
Definition: input.h:49
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
realnum
float realnum
Definition: cddefines.h:103
t_optimize::lgVarOn
bool lgVarOn
Definition: optimize.h:203
t_hextra::crtemp
realnum crtemp
Definition: hextra.h:16
input
t_input input
Definition: input.cpp:12
ASSERT
#define ASSERT(exp)
Definition: cddefines.h:578
MIN2
#define MIN2
Definition: cddefines.h:761
parse.h
t_hextra::cryden
realnum cryden
Definition: hextra.h:14
optimize
t_optimize optimize
Definition: optimize.cpp:5
t_optimize::vparm
realnum vparm[LIMEXT][LIMPAR]
Definition: optimize.h:188
t_optimize::chVarFmt
char chVarFmt[LIMPAR][FILENAME_PATH_LENGTH_2]
Definition: optimize.h:263
EXIT_FAILURE
#define EXIT_FAILURE
Definition: cddefines.h:140
Parser::NoNumb
NORETURN void NoNumb(const char *chDesc) const
Definition: parser.cpp:233
Parser
Definition: parser.h:31
cddefines.h
hextra
t_hextra hextra
Definition: hextra.cpp:5
optimize.h
t_optimize::nvarxt
long int nvarxt[LIMPAR]
Definition: optimize.h:194
ionbal
t_ionbal ionbal
Definition: ionbal.cpp:5
cdEXIT
#define cdEXIT(FAIL)
Definition: cddefines.h:434
Parser::lgEOL
bool lgEOL(void) const
Definition: parser.h:98
ionbal.h
parser.h
t_optimize::nvfpnt
long int nvfpnt[LIMPAR]
Definition: optimize.h:195
hextra.h
t_hextra::crpowr
realnum crpowr
Definition: hextra.h:15
t_hextra::lg_CR_B_equipartition
bool lg_CR_B_equipartition
Definition: hextra.h:19
t_ionbal::CosRayIonRate
double CosRayIonRate
Definition: ionbal.h:123
input.h
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684
SMALLFLOAT
const realnum SMALLFLOAT
Definition: cpu.h:191
t_hextra::cryden_ov_background
realnum cryden_ov_background
Definition: hextra.h:25