cloudy  trunk
 All Data Structures 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-2008 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 
11 /*ParseCosmicRays parse the cosmic rays command */
12 void ParseCosmicRays( char *chCard )
13 {
14  long int i;
15  bool lgEOL;
16  realnum a;
17  double var;
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  i = 5;
25  /* if no number is present FFmtRead returns zero */
26  a = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
27  if( lgEOL )
28  a = 0.;
29 
30  /* if keyword LINEAR not present, then log, and make linear */
31  if( !nMatch("LINE",chCard) )
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( nMatch("DENS",chCard) )
38  {
39  if( lgEOL )
40  {
41  fprintf(ioQQQ,
42  " Either the log of the cosmic ray density must appear when density given.\n");
43  NoNumb(chCard);
44  }
45  hextra.cryden = a;
46 
47  /* optional power law density */
48  hextra.crpowr = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
49 
50  /* option to specify a temp for non-rel electrons - but only when a density */
51  hextra.crtemp = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
52  if( lgEOL )
53  {
54  /* relativistic limit (Balbus and McKee) */
55  hextra.crtemp = 2.6e9;
56  }
57  else
58  {
59  var = pow((realnum)10.f,hextra.crtemp);
60  hextra.crtemp = (realnum)MIN2(var,2.6e9);
61  }
62  }
63  else if( nMatch( "RATE" , chCard ) )
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  }
71  else if( nMatch( "BACK" , chCard ) && nMatch( "GROU" , chCard ) )
72  {
73  /* >>chng 06 may 28, require explicit BACKGROUnd to hit background for safety */
74  /* cr relative to galactic background BACK - no check on string since default */
75  /* >>chng 04 mar 10, background is now
76  * >>refer cr ion Williams, J.P., Bergin, E.A., Caseli, P., Myers, P.C., & Plume, R. 1998, ApJ, 503, 689 */
77  /* galactic background cosmic ray density to produce
78  * secondary ionization rate quoted by Tielens and Hollenbach */
79  /* hextra.cryden = 2e-9f;*/
80  /* >>chng 99 jun 24, slight change to value
81  * quoted by
82  * >>refer cosmic ray ionization rate McKee, C.M., 1999, astro-ph 9901370
83  * this will produce a total
84  * secondary ionization rate of 2.5e-17 s^-1, as tested in
85  * tsuite secondary.in. If each ionization produces 2.4 eV of heat,
86  * the background heating rate should be 9.6e-29 * n*/
87  /* >>chng 00 nov 28, changed density to 4.9e-9 to reproduce TH85a
88  * when photoionization is turned off.
89  >>refer cosmic ray ionization rate Tielens, A.G.G.M., & Hollenbach, D., 1998, ApJ, 291, 722
90  */
91  /* hextra.cryden = 7.07e-9f;*/
92  /* this value reproduces the TH cr ionization rate when the factor
93  * of 0.46 is included. This will directly go onto the h ionization rate
94  * without the factor of 0.46 there. this is necessary for the more
95  * general case where cr ionization is actually self-consistently determined
96  * from rate hot electrons injected into the plasma */
97  /*hextra.cryden = 2.25e-9f;*/
98  ASSERT( a > 0. );
100  hextra.crtemp = 2.6e9f;
101  }
102  else if( nMatch( "EQUI" , chCard ) )
103  {
104  /* equipartition cosmic rays, set from B */
106  /* this has to be positive for cr's to be on
107  * it will be reevaluated when B is known */
109  hextra.crtemp = 2.6e9f;
110  }
111 
112  else
113  {
114  /* no keyword found */
115  fprintf( ioQQQ, " There must be a keyword on this COSMIC RAY command.\n" );
116  fprintf( ioQQQ, " The keywords are DENSITY, RATE, and BACKGROUND.\n" );
117  cdEXIT(EXIT_FAILURE);
118  }
119 
120  /* this is current cosmic ray density divided by background - used in
121  * a few chemical reactions */
123  /* >>chng 05 jan 05,
124  * set the cr ionization rate to very rough value, before we have enough
125  * information to evaluate it - may be needed in initial guess of H and He ionization*/
127 
128  /* vary option */
129  if( optimize.lgVarOn )
130  {
131  /* will be one parameter */
133  strcpy( optimize.chVarFmt[optimize.nparm], "COSMic rays LOG BACKGROUND=%f" );
134  /* array index for where to write */
136  /* log of cosmic rays rates relative to background */
137  optimize.vparm[0][optimize.nparm] = (realnum)log10(a);
138  /* the increment in the first steps away from the original value */
139  optimize.vincr[optimize.nparm] = 0.2f;
140  ++optimize.nparm;
141  }
142 
143  return;
144 }

Generated for cloudy by doxygen 1.8.3.1