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 /*InitDefaultsPreparse initialization at start of simulation, called from cloudy 00004 * before parser, sets initial values of quantities changed by parser */ 00005 #include "cddefines.h" 00006 #include "physconst.h" 00007 #include "phycon.h" 00008 #include "trace.h" 00009 #include "noexec.h" 00010 #include "stopcalc.h" 00011 #include "plot.h" 00012 #include "rt.h" 00013 #include "fudgec.h" 00014 #include "abund.h" 00015 #include "extinc.h" 00016 #include "h2.h" 00017 #include "hextra.h" 00018 #include "mole.h" 00019 #include "wind.h" 00020 #include "pressure.h" 00021 #include "thermal.h" 00022 #include "optimize.h" 00023 #include "punch.h" 00024 #include "dense.h" 00025 #include "hcmap.h" 00026 #include "prt.h" 00027 #include "init.h" 00028 #include "taulines.h" 00029 #include "lines_service.h" 00030 00031 /*InitDefaultsPreparse initialization at start of simulation, called from cloudy 00032 * before parser, will now be called one time per sim in grid but long term 00033 * goal is to call parser only one time in a grid. This would be called 00034 * first to set defaults that may be changed by the parser. This routine 00035 * should only set defaults for variables that change in the parser. 00036 * It does not initialize variables for the start of a calculation. That 00037 * is done by InitSimPostparse */ 00038 void InitDefaultsPreparse( void ) 00039 { 00040 long int i, 00041 ipISO, 00042 nelem; 00043 00044 DEBUG_ENTRY( "InitDefaultsPreparse()" ); 00045 00046 /* init vars before parsing commands for each sim */ 00047 00048 /* option to read in all input quantiles and NOT execute the actual model 00049 * only check on input parameters - set by calling cdNoExec */ 00050 noexec.lgNoExec = false; 00051 00052 /* constant for the extinguish command */ 00053 extinc.excolm = 0.; 00054 extinc.exleak = 0.; 00055 extinc.exlow = 1.; 00056 00057 /* parameters having to do with thermal map */ 00058 hcmap.RangeMap[0] = 10.f; 00059 hcmap.RangeMap[1] = .99e10f; 00060 /* zone where map is to be done */ 00061 hcmap.MapZone = -1; 00062 hcmap.nMapStep = 20; 00063 00064 thermal.ConstGrainTemp = 0.; 00065 thermal.lgTemperatureConstant = false; 00066 thermal.lgTemperatureConstantCommandParsed = false; 00067 thermal.ConstTemp = 0.; 00068 thermal.lgTeHigh = false; 00069 thermal.lgTeBD96 = false; 00070 thermal.lgTLaw = false; 00071 thermal.lgTeSN99 = false; 00072 /* try toe predict next zone's temperature in constant density models, 00073 * as done in ZoneStart. Turned off with no tepred command */ 00074 thermal.lgPredNextTe = true; 00075 00076 /* turbulent heating - set with hextra command */ 00077 hextra.TurbHeat = 0.; 00078 /* set true with TIME option on hextra command for time dependent sims */ 00079 hextra.lgTurbHeatVaryTime = false; 00080 /* options for for extra heating to depend on scale radius */ 00081 hextra.lgHextraDepth = false; 00082 /* options for for extra heating to depend on density */ 00083 hextra.lgHextraDensity = false; 00084 00085 /* options set by cosmic ray command */ 00086 hextra.cryden = 0.; 00087 hextra.cryden_ov_background = 0.; 00088 hextra.lg_CR_B_equipartition = false; 00089 hextra.crtemp = 0.; 00090 hextra.crpowr = 0.; 00091 hextra.cr_energydensity = 0; 00092 00093 /* this is number of electronic levels to include in the print and punch output 00094 * changed with the PRINT LINE H2 ELECTRONIC and PUNCH H2 commands 00095 * by default only include X */ 00096 h2.nElecLevelOutput = 1; 00097 00098 /* holds options for trace set with atom h2 command */ 00099 mole.nH2_TRACE = false; 00100 00101 /* option to scramble collision data */ 00102 mole.lgH2_NOISE = false; 00103 mole.lgH2_NOISECOSMIC = false; 00104 00105 /* option to turn off or on gbar collisions of the collision rate, 00106 * default is to have it on */ 00107 /* turn mole.lgColl_gbar on/off with atom h2 gbar on off */ 00108 mole.lgColl_gbar = true; 00109 00110 /* include collision rates that come from real calculations, 00111 * off with atom h2 collisions off command */ 00112 mole.lgColl_deexec_Calc = true; 00113 00114 mole.lgColl_dissoc_coll = true; 00115 00116 /* option to turn off H2 - grain collision & deexcitation, 00117 * atom h2 grain collision on/off */ 00118 mole.lgH2_grain_deexcitation = false; 00119 00120 /* option to turn off ortho-para collisions, command ATOM H2 COLLISIONS ORTHO PARA OFF */ 00121 mole.lgH2_ortho_para_coll_on = true; 00122 00123 /* which set of H2 - He collision data to use? default is Le Bourlot Meudon set, 00124 * set to ORNL with command 00125 * atom H2 He collisions ORNL */ 00126 mole.lgH2_He_ORNL = true; 00127 00128 /* use 1999 or 2007 H2 - H collision set atomic data mole H2 h */ 00129 h2.lgH2_H_coll_07 = true; 00130 00131 /* parameters to do with wind */ 00132 wind.lgWindOK = true; 00133 wind.DiskRadius = 0; 00134 wind.lgDisk = false; 00135 wind.windv0 = 0.; 00136 wind.comass = 0.; 00137 wind.windv = 0.; 00138 wind.emdot = 0.; 00139 wind.AccelAver = 0.; 00140 wind.acldr = 0.; 00141 wind.AccelGravity = 0.; 00142 wind.AccelTot = 0.; 00143 wind.AccelCont = 0.; 00144 wind.AccelLine = 0.; 00145 wind.AccelPres = 0.; 00146 wind.AccelMax = 0.; 00147 wind.fmul = 0.; 00148 wind.lgVelPos = true; 00149 00150 /* argument on ELEMENT LIMIT OFF XXX command, lowest abundance 00151 * element to include in the calculation */ 00152 dense.AbundanceLimit = 0.; 00153 00154 /* controls density fluctuations, when true variations are due to density changing, 00155 * when false are due to abundances changing if changes are on */ 00156 dense.lgDenFlucOn = true; 00157 dense.lgDenFlucRadius = true; 00158 dense.flong = 0.; 00159 dense.flcPhase = 0.; 00160 00161 /* this says keep initial density constant, 00162 * so pressure from iter to iter not really const */ 00163 dense.lgDenseInitConstant = true; 00164 00165 /* individual terms for the pressure equation of state */ 00166 /* >>chng 05 jan 01, all three are set true at start * 00167 * code default is constant density, so all this is ignored 00168 * is turned to constant pressure then these flags must be adjusted so 00169 * that we get the pressure we expect. with all true, all three 00170 * contributors to pressure will be counted - with constant gas pressure 00171 * these are turned off */ 00172 pressure.lgPres_radiation_ON = true; 00173 pressure.lgPres_magnetic_ON = true; 00174 pressure.lgPres_ram_ON = true; 00175 /* flag for constant pressure, include continuum too */ 00176 pressure.lgContRadPresOn = true; 00177 /* constant density is the default */ 00178 strcpy( dense.chDenseLaw, "CDEN" ); 00179 /* number on line is log of nT - option to specify initial pressure */ 00180 pressure.lgPressureInitialSpecified = false; 00181 /* this is log of nT product - if not present then set zero */ 00182 pressure.PressureInitialSpecified = 0; 00183 00184 /* select certain atomic data, changed with set atomic data command 00185 * this says to use Zeippen 1982 [OII] transition probabilities */ 00186 dense.lgAsChoose[ipOXYGEN][1] = false; 00187 00188 abund.lgAbnSolar = false; 00189 00190 /* the ipSolar array is a set of pointers used for reading 00191 * in abundances with the "abundances" command 00192 * the hydrogen abundance of unity is not read in */ 00193 abund.npSolar = LIMELM - 1; 00194 for( i=0; i < abund.npSolar; i++ ) 00195 { 00196 abund.ipSolar[i] = i + 2; 00197 } 00198 00199 /* option to turn off an element */ 00200 for( nelem=0; nelem < LIMELM; nelem++ ) 00201 { 00202 /* set of scale factors for changing abundances with elements command */ 00203 abund.ScaleElement[nelem] = 1.; 00204 abund.solar[nelem] = abund.SolarSave[nelem]; 00205 } 00206 00207 abund.lgAbTaON = false; 00208 00209 /* option to turn off an element */ 00210 for( nelem=0; nelem < LIMELM; nelem++ ) 00211 { 00212 /* option to have abundances from table */ 00213 abund.lgAbunTabl[nelem] = false; 00214 } 00215 00216 /* threshold for faintest heating cooling to punch with punch heating or 00217 * punch cooling commands, reset with PUNCH WEAKHEATCOOL command */ 00218 punch.WeakHeatCool = 0.05f; 00219 00220 /* set of variables used to control punch command */ 00221 punch.npunch = 0; 00222 punch.cp_npun = 0; 00223 punch.lgPunContinuum = false; 00224 punch.lgDRPLst = false; 00225 punch.lgDRHash = true; 00226 punch.lgTraceConvergeBaseHash = true; 00227 /* this is the string that will appear after each model in the punch output, 00228 * reset with the "set punch hash" command */ 00229 strcpy( punch.chHashString , " ###########################" ); 00230 /* this is the string that will be added as a prefix to filenames for punch output, 00231 * reset with the "set punch prefix" command */ 00232 strcpy( punch.chFilenamePrefix , "" ); 00233 /* punch every one continuum point, set skip punch command */ 00234 punch.ncPunchSkip = 1; 00235 /* flush file after every iteration - set punch flush */ 00236 punch.lgFLUSH = false; 00237 for( i=0; i<LIMPUN; ++i ) 00238 { 00239 punch.lgHashEndIter[i] = true; 00240 /* set false for time dependent calculations*/ 00241 punch.lg_separate_iterations[i] = true; 00242 punch.lgPunchEveryZone[i] = false; 00243 punch.nPunchEveryZone[i] = -1; 00244 } 00245 00246 /* default line width for plots is 1e3 km/s, reset with 00247 * set punch line width command */ 00248 punch.PunchLWidth = (realnum)(SPEEDLIGHT/1000.e5); 00249 00250 /* default no printing of optical depths, TooFaint is .1 */ 00251 prt.lgPrtTau = false; 00252 prt.PrtTauFnt = 0.1f; 00253 prt.lgPrtShort = false; 00254 prt.TooFaint = 1e-3f; 00255 prt.lgFaintOn = true; 00256 prt.lgFntSet = false; 00257 prt.lgPrnLineCell = false; 00258 prt.nPrnLineCell = -1000; 00259 00260 /* if true then print main block of lines as array, 00261 * set false with print lines column, will then 00262 * do a single column of lines */ 00263 prt.lgPrtLineArray = true; 00264 00265 /* when printing a column this is option to print linear rather than log */ 00266 prt.lgPrtLineLog = true; 00267 00268 /* print emergent intensities even when sphere, set with print line emergenet */ 00269 prt.lgPrtLineEmergent = false; 00270 00271 /* print ages */ 00272 prt.lgPrnAges = false; 00273 00274 /* print column densities */ 00275 prt.lgPrintColumns = true; 00276 00277 /* option to sort lines by wavelength, print sort command */ 00278 prt.lgSortLines = false; 00279 00280 prt.lgPrtMaser = false; 00281 prt.lgPrintTime = true; 00282 00283 prt.lgPrtContIndices = false; 00284 prt.lgPrtCont = false; 00285 prt.lgPrnDiff = false; 00286 prt.lgPrnPump = false; 00287 prt.lgPrnInwd = false; 00288 prt.lgPrnColl = false; 00289 prt.lgPrnHeat = false; 00290 /* >>chng 00 dec 08, these determine the standard items included in "nFnu", PvH */ 00291 prt.lgSourceReflected = true; 00292 prt.lgSourceTransmitted = false; 00293 prt.lgDiffuseInward = true; 00294 prt.lgDiffuseOutward = true; 00295 prt.lgPrtLastIt = false; 00296 prt.lgOnlyZone = false; 00297 prt.lgOnlyHead = false; 00298 prt.lgPrtStart = false; 00299 prt.nstart = 0; 00300 00301 /* turn off printing of heating agents */ 00302 prt.lgPrintHeating = false; 00303 00304 /* flag saying to print all matrix elements for ionization balance 00305 * set with PRINT ARRAYS command */ 00306 for( nelem=ipHYDROGEN; nelem<LIMELM; ++nelem ) 00307 { 00308 prt.lgPrtArry[nelem] = false; 00309 } 00310 00311 /* print line flux at earth */ 00312 prt.lgPrintFluxEarth = false; 00313 00314 /* print line surface brightness, def sr, option arcsec */ 00315 prt.lgSurfaceBrightness = false; 00316 prt.lgSurfaceBrightness_SR = true; 00317 00318 prt.nzdump = -100; 00319 00320 trace.lgSecIon = false; 00321 trace.lgTrOvrd = true; 00322 trace.lgOpacBug = false; 00323 trace.nTrConvg = 0; 00324 trace.lgTr8446 = false; 00325 trace.lgTrLevN = false; 00326 trace.lgTrGant = false; 00327 trace.lgOptcBug = false; 00328 trace.lgTrace3Bod = false; 00329 trace.lgOTSBug = false; 00330 trace.lgESOURCE = false; 00331 trace.lgTr_CO_Mole = false; 00332 trace.lgTr_H2_Mole = false; 00333 trace.lgHeatBug = false; 00334 trace.lgHeavyBug = false; 00335 trace.lgBug2nu = false; 00336 trace.lgDrBug = false; 00337 trace.lgWind = false; 00338 trace.lgPtrace = false; 00339 trace.lgDrv_cdLine = false; 00340 trace.lgDustBug = false; 00341 trace.lgComBug = false; 00342 trace.lgHeBug = false; 00343 trace.lgCarBug = false; 00344 trace.lgCalBug = false; 00345 trace.lgConBug = false; 00346 trace.lgNeBug = false; 00347 trace.lgFeBug = false; 00348 trace.lgHBug = false; 00349 trace.lgTrLine = false; 00350 trace.nznbug = 10000; 00351 trace.npsbug = 10000; 00352 trace.lgTrace = false; 00353 trace.lgPointBug = false; 00354 trace.lgNeonBug = false; 00355 trace.lgCoolTr = false; 00356 trace.lgTrDiff = false; 00357 for( ipISO=ipH_LIKE; ipISO<NISO; ++ipISO ) 00358 trace.lgIsoTraceFull[ipISO] = false; 00359 00360 /* variables used in stop ... command */ 00361 00362 /* various criteria for stopping model */ 00363 /* >>chng 04 dec 21, remove from here and init to 1e30 in zero */ 00364 /*StopCalc.tauend = 0.;*/ 00365 StopCalc.tauend = 1e30f; 00366 00367 /* >>chng 05 nov 22 - NPA. Stop calculation when fraction of oxygen frozen 00368 * out on grains ices gets too high - formation of ices */ 00369 /*StopCalc.StopDepleteFrac = 0.99f;*/ 00370 /* >>chng 05 dec 16, with revised ion solver logic, code should be able to 00371 * converge away from situation where ices have disturbed the chemistry and 00372 * net negative atomic abundances result. now we say solution not converged and 00373 * soldier on 00374 * this test should not be necessary */ 00375 StopCalc.StopDepleteFrac = 1.02f; 00376 00377 StopCalc.xMass = 0.; 00378 StopCalc.taunu = 0.; 00379 StopCalc.iptnu = -1; 00380 /* stopping AV */ 00381 StopCalc.AV_extended = 1e30f; 00382 StopCalc.AV_point = 1e30f; 00383 /* highest allowed temperature */ 00384 StopCalc.T2High = (realnum)phycon.TEMP_LIMIT_HIGH; 00385 00386 /* the floor sets a limit to the temperature in the calculation - 00387 * if te falls below this, we do a constant temperature cloud at 00388 * this temperature */ 00389 StopCalc.TeFloor = 0.; 00390 00391 /* this is in cddefines.h and is 4000 */ 00392 StopCalc.tend = (realnum)phycon.TEMP_STOP_DEFAULT; 00393 /* ending column densities */ 00394 StopCalc.HColStop = COLUMN_INIT; 00395 StopCalc.colpls = COLUMN_INIT; 00396 StopCalc.colnut = COLUMN_INIT; 00397 StopCalc.col_h2 = COLUMN_INIT; 00398 StopCalc.col_h2_nut = COLUMN_INIT; 00399 StopCalc.col_H0_ov_Tspin = COLUMN_INIT; 00400 StopCalc.col_monoxco = COLUMN_INIT; 00401 00402 /* stopping electron density */ 00403 StopCalc.StopElecDensity = -COLUMN_INIT; 00404 00405 /* stopping electron and molecular fractions */ 00406 StopCalc.StopElecFrac = -FLT_MAX; 00407 StopCalc.StopHPlusFrac = -FLT_MAX; 00408 /* stopping molecular fraction has opposite sign - want to stop when 2H_2/NH gt this */ 00409 StopCalc.StopH2MoleFrac = FLT_MAX; 00410 /* this flag says that 21cm line optical depth is the stop quantity */ 00411 StopCalc.lgStop21cm = false; 00412 /* debugging aid - stop when conv.nTotalIoniz reaches this value */ 00413 StopCalc.nTotalIonizStop = 0; 00414 /* stop when absolute value of velocity falls below this */ 00415 StopCalc.StopVelocity = 0.; 00416 /* number of stop line commands entered */ 00417 StopCalc.nstpl = 0; 00418 00419 /* initialize some variables for the optimizer */ 00420 optimize.nIterOptim = 20; 00421 optimize.ioOptim = NULL; 00422 optimize.OptGlobalErr = 0.10f; 00423 optimize.nlobs = 0; 00424 optimize.nTempObs = 0; 00425 optimize.ncobs = 0; 00426 optimize.nRangeSet = 0; 00427 strcpy( optimize.chOptRtn, "SUBP" ); 00428 00429 /* flags says what is to be matched */ 00430 optimize.lgOptLin = false; 00431 optimize.lgOptLum = false; 00432 optimize.lgOptCol = false; 00433 optimize.lgOptTemp = false; 00434 optimize.lgOptimize = false; 00435 00436 /* trace flag for optimization process */ 00437 optimize.lgTrOpt = false; 00438 00439 optimize.lgOptimFlow = false; 00440 optimize.optint = 0.; 00441 optimize.optier = 0.; 00442 # ifdef __unix 00443 optimize.lgParallel = true; 00444 # else 00445 optimize.lgParallel = false; 00446 # endif 00447 optimize.lgOptCont = false; 00448 00449 /* the fudge factors command */ 00450 fudgec.nfudge = 0; 00451 fudgec.lgFudgeUsed = false; 00452 for( i=0; i < NFUDGC; i++ ) 00453 fudgec.fudgea[i] = 0.; 00454 00455 EmLineZero( &DummyEmis ); 00456 DummyEmis.iRedisFun = 0; 00457 DummyEmis.ipFine = -1; 00458 DummyEmis.gf = 0.; 00459 DummyEmis.damp = 0.; 00460 DummyEmis.dampXvel = 0.; 00461 DummyEmis.opacity = 0.; 00462 DummyEmis.Aul = 1e-30f; 00463 DummyEmis.tran = NULL; 00464 DummyEmis.next = NULL; 00465 00466 /* parameters dealing with printer plots */ 00467 for( i=0; i < NDPLOT; i++ ) 00468 { 00469 plotCom.lgPltTrace[i] = false; 00470 } 00471 00472 /* this says what types of printer plots we will make */ 00473 for( i=0; i < NDPLOT; i++ ) 00474 { 00475 strcpy( plotCom.chPType[i], "NONE" ); 00476 } 00477 plotCom.lgPlotON = false; 00478 00479 /* following were block data logic */ 00480 rt.lgStarkON = true; 00481 00482 /* by default use Federman form of shielding function */ 00483 rt.nLineContShield = LINE_CONT_SHIELD_FEDERMAN; 00484 00485 return; 00486 }