00001 /* This file is part of Cloudy and is copyright (C)1978-2008 by Gary J. Ferland and 00002 * others. For conditions of distribution and use see copyright notice in license.txt */ 00003 /*ParseCosmicRays parse the cosmic rays command */ 00004 #include "cddefines.h" 00005 #include "optimize.h" 00006 #include "hextra.h" 00007 #include "ionbal.h" 00008 #include "input.h" 00009 #include "parse.h" 00010 00011 /*ParseCosmicRays parse the cosmic rays command */ 00012 void ParseCosmicRays( char *chCard ) 00013 { 00014 long int i; 00015 bool lgEOL; 00016 realnum a; 00017 double var; 00018 00019 DEBUG_ENTRY( "ParseCosmicRays()" ); 00020 00021 /* cosmic ray density, log of rate relative to background, log of H0 rate in neutral gas, 00022 * or density of rel. electrons, 00023 * quantity is log unless keyword linear appears */ 00024 i = 5; 00025 /* if no number is present FFmtRead returns zero */ 00026 a = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00027 if( lgEOL ) 00028 a = 0.; 00029 00030 /* if keyword LINEAR not present, then log, and make linear */ 00031 if( !nMatch("LINE",chCard) ) 00032 a = (realnum)pow((realnum)10.f,a); 00033 /* a is now linear scale factor, or linear density, with default of 1 if no number */ 00034 00035 /* default is cosmic ray ionization rate relative to galactic background, but can 00036 * also give density, which was the only option originally */ 00037 if( nMatch("DENS",chCard) ) 00038 { 00039 if( lgEOL ) 00040 { 00041 fprintf(ioQQQ, 00042 " Either the log of the cosmic ray density must appear when density given.\n"); 00043 NoNumb(chCard); 00044 } 00045 hextra.cryden = a; 00046 00047 /* optional power law density */ 00048 hextra.crpowr = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00049 00050 /* option to specify a temp for non-rel electrons - but only when a density */ 00051 hextra.crtemp = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL); 00052 if( lgEOL ) 00053 { 00054 /* relativistic limit (Balbus and McKee) */ 00055 hextra.crtemp = 2.6e9; 00056 } 00057 else 00058 { 00059 var = pow((realnum)10.f,hextra.crtemp); 00060 hextra.crtemp = (realnum)MIN2(var,2.6e9); 00061 } 00062 } 00063 else if( nMatch( "RATE" , chCard ) ) 00064 { 00065 /* this sets rate - use stored density and rate for background to set 00066 * new density since code works with density */ 00067 ASSERT( a > 0. ); 00068 hextra.cryden = hextra.background_density * a / hextra.background_rate; 00069 hextra.crtemp = 2.6e9f; 00070 } 00071 else if( nMatch( "BACK" , chCard ) && nMatch( "GROU" , chCard ) ) 00072 { 00073 /* >>chng 06 may 28, require explicit BACKGROUnd to hit background for safety */ 00074 /* cr relative to galactic background BACK - no check on string since default */ 00075 /* >>chng 04 mar 10, background is now 00076 * >>refer cr ion Williams, J.P., Bergin, E.A., Caseli, P., Myers, P.C., & Plume, R. 1998, ApJ, 503, 689 */ 00077 /* galactic background cosmic ray density to produce 00078 * secondary ionization rate quoted by Tielens and Hollenbach */ 00079 /* hextra.cryden = 2e-9f;*/ 00080 /* >>chng 99 jun 24, slight change to value 00081 * quoted by 00082 * >>refer cosmic ray ionization rate McKee, C.M., 1999, astro-ph 9901370 00083 * this will produce a total 00084 * secondary ionization rate of 2.5e-17 s^-1, as tested in 00085 * tsuite secondary.in. If each ionization produces 2.4 eV of heat, 00086 * the background heating rate should be 9.6e-29 * n*/ 00087 /* >>chng 00 nov 28, changed density to 4.9e-9 to reproduce TH85a 00088 * when photoionization is turned off. 00089 >>refer cosmic ray ionization rate Tielens, A.G.G.M., & Hollenbach, D., 1998, ApJ, 291, 722 00090 */ 00091 /* hextra.cryden = 7.07e-9f;*/ 00092 /* this value reproduces the TH cr ionization rate when the factor 00093 * of 0.46 is included. This will directly go onto the h ionization rate 00094 * without the factor of 0.46 there. this is necessary for the more 00095 * general case where cr ionization is actually self-consistently determined 00096 * from rate hot electrons injected into the plasma */ 00097 /*hextra.cryden = 2.25e-9f;*/ 00098 ASSERT( a > 0. ); 00099 hextra.cryden = hextra.background_density * a; 00100 hextra.crtemp = 2.6e9f; 00101 } 00102 else if( nMatch( "EQUI" , chCard ) ) 00103 { 00104 /* equipartition cosmic rays, set from B */ 00105 hextra.lg_CR_B_equipartition = true; 00106 /* this has to be positive for cr's to be on 00107 * it will be reevaluated when B is known */ 00108 hextra.cryden = SMALLFLOAT; 00109 hextra.crtemp = 2.6e9f; 00110 } 00111 00112 else 00113 { 00114 /* no keyword found */ 00115 fprintf( ioQQQ, " There must be a keyword on this COSMIC RAY command.\n" ); 00116 fprintf( ioQQQ, " The keywords are DENSITY, RATE, and BACKGROUND.\n" ); 00117 cdEXIT(EXIT_FAILURE); 00118 } 00119 00120 /* this is current cosmic ray density divided by background - used in 00121 * a few chemical reactions */ 00122 hextra.cryden_ov_background = hextra.cryden / hextra.background_density; 00123 /* >>chng 05 jan 05, 00124 * set the cr ionization rate to very rough value, before we have enough 00125 * information to evaluate it - may be needed in initial guess of H and He ionization*/ 00126 ionbal.CosRayIonRate = hextra.cryden_ov_background * 2.5e-17; 00127 00128 /* vary option */ 00129 if( optimize.lgVarOn ) 00130 { 00131 /* will be one parameter */ 00132 optimize.nvarxt[optimize.nparm] = 1; 00133 strcpy( optimize.chVarFmt[optimize.nparm], "COSMic rays LOG BACKGROUND=%f" ); 00134 /* array index for where to write */ 00135 optimize.nvfpnt[optimize.nparm] = input.nRead; 00136 /* log of cosmic rays rates relative to background */ 00137 optimize.vparm[0][optimize.nparm] = (realnum)log10(a); 00138 /* the increment in the first steps away from the original value */ 00139 optimize.vincr[optimize.nparm] = 0.2f; 00140 ++optimize.nparm; 00141 } 00142 00143 return; 00144 }