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