cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
init_coreload.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 /*InitCoreload one time initialization of core load, called from cdDrive, this sets
4 * minimum set of values needed for the code to start - called after
5 * input lines have been read in and checked for VARY or GRID - so
6 * known whether single or multiple sims will be run */
7 #include "cddefines.h"
8 #include "init.h"
9 #include "parse.h"
10 #include "struc.h"
11 #include "atmdat.h"
12 #include "hcmap.h"
13 #include "h2.h"
14 #include "hextra.h"
15 #include "heavy.h"
16 #include "ionbal.h"
17 #include "iso.h"
18 #include "taulines.h"
19 #include "cosmology.h"
20 #include "broke.h"
21 #include "dense.h"
22 #include "optimize.h"
23 
24 // //////////////////////////////////////////////////////////////////////////
25 //
26 //
27 // NB DO NOT ADD VARIABLES TO THIS FILE! THE GOAL IS TO REMOVE THIS FILE
28 // initialization of variables done one time per coreload should be done in
29 // a constructor for the data
30 //
31 //
32 // //////////////////////////////////////////////////////////////////////////
33 
34 /*InitCoreload one time initialization of core load, called from cdDrive, this sets
35 * minimum set of values needed for the code to start - called after
36 * input lines have been read in and checked for VARY or GRID - so
37 * known whether single or multiple sims will be run */
38 void InitCoreload( void )
39 {
40  static int nCalled=0;
41  long int nelem;
42 
43  DEBUG_ENTRY( "InitCoreload()" );
44 
45  /* return if already called */
46  if( nCalled )
47  return;
48 
49  ++nCalled;
50 
51  hcmap.lgMapOK = true;
52  hcmap.lgMapDone = false;
53 
54  /* will be reset to positive number when map actually done */
55  hcmap.nMapAlloc = 0;
56  hcmap.nmap = 0;
57  hcmap.lgMapBeingDone = false;
58 
59  /* name of output file from optimization run */
60  strncpy( chOptimFileName , "optimal.in" , sizeof( chOptimFileName ) );
61 
62  /* number of electrons in valence shell that can Compton recoil ionize */
63  long int nCom[LIMELM] =
64  {
65  1 , 2 , /* K 1s shell */
66  1 , 2 , /* L 2s shell */
67  1 , 2 , 3 , 4 , 5 , 6 , /* L 2p shell */
68  1 , 2 , /* M 3s shell */
69  1 , 2 , 3 , 4 , 5 , 6 , /* M 3p shell */
70  1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , /* M 3d shell */
71  1 , 2 , /* N 4s shell */
72  1 , 2 /* N 4p shell */
73  };
74 
75  for( nelem=ipHYDROGEN; nelem<LIMELM; ++nelem )
76  {
77  ionbal.nCompRecoilElec[nelem] = nCom[nelem];
78  }
79 
80  /* list of shells, 1 to 7 */
81  strcpy( Heavy.chShell[0], "1s" );
82  strcpy( Heavy.chShell[1], "2s" );
83  strcpy( Heavy.chShell[2], "2p" );
84  strcpy( Heavy.chShell[3], "3s" );
85  strcpy( Heavy.chShell[4], "3p" );
86  strcpy( Heavy.chShell[5], "3d" );
87  strcpy( Heavy.chShell[6], "4s" );
88 
89  /* variables for H-like sequence */
90  /* default number of levels for hydrogen iso sequence */
91  for( nelem=ipHYDROGEN; nelem < LIMELM; ++nelem )
92  {
94  iso_sp[ipH_LIKE][nelem].nCollapsed_max = 2;
95  }
96 
97  /* add more collapsed levels for these abundant elements. Tests
98  * show collapsed levels have very little impact on time */
107  iso_sp[ipH_LIKE][LIMELM-1].nCollapsed_max = 5;
108 
109  /* H and He are special cases since very high resolution, S/N
110  * optical / IR data are common
111  */
114 
117 
118  /* variables for He-like sequence */
119  /* "he-like" hydrogen (H-) is treated elsewhere */
123 
124  for( nelem=ipHELIUM; nelem < LIMELM; ++nelem )
125  {
126  /* put at least three resolved and 1 collapsed in every element for he-like
127  * An n shell for He has twice the number of resolved levels due to singlet/triplet */
129  iso_sp[ipHE_LIKE][nelem].nCollapsed_max = 2;
130  }
131 
132  /* And n=5 for these because they are most abundant */
149  /* also set this, for exercising any possible issues with highest charge models */
150  iso_sp[ipHE_LIKE][LIMELM-1].n_HighestResolved_max = 5;
151  iso_sp[ipHE_LIKE][LIMELM-1].nCollapsed_max = 5;
152 
153  /* He I is very special case - we want to do a good job, lots of levels */
156 
157  iso_ctrl.chISO[ipH_LIKE] = "H-like ";
158  iso_ctrl.chISO[ipHE_LIKE] = "He-like";
159 
160  max_num_levels = 0;
161  for( long ipISO = ipH_LIKE; ipISO < NISO; ipISO++ )
162  {
163  for( nelem=ipISO; nelem < LIMELM; nelem++ )
164  {
165  /* set this to LONG_MAX, reduce to actual number later,
166  * then verify number of levels is not increased after initial coreload */
167  iso_sp[ipISO][nelem].numLevels_malloc = LONG_MAX;
168  iso_update_num_levels( ipISO, nelem );
169  }
170  }
171 
172  lgStatesAdded = false;
173  lgLinesAdded = false;
174 
175  /* turn element on if this is first call to this routine,
176  * but do not reset otherwise since would clobber how elements were set up */
177  for( nelem=0; nelem < LIMELM; nelem++ )
178  {
179  /* never turn on element if turned off on first iteration */
180  dense.lgElmtOn[nelem] = true;
181  /* no elements yet explicitly turned off */
182  dense.lgElmtSetOff[nelem] = false;
183 
184  /* option to set ionization with element ioniz cmnd,
185  * default (false) is to solve for ionization */
186  dense.lgSetIoniz[nelem] = false;
187 
188  // are we using Chianti for this ion?
189  for( int ion=0; ion<=nelem+1; ++ion )
190  {
191  dense.lgIonChiantiOn[nelem][ion] = false;
192  dense.lgIonStoutOn[nelem][ion] = false;
193  dense.maxWN[nelem][ion] = 0.;
194  }
195  }
196 
197  //set all sources to blank and false.
198  //Sources will be added from masterlist files in species.cpp
199  for( int nelem=ipHYDROGEN; nelem<LIMELM; ++nelem )
200  {
201  for( int ion=0; ion<nelem+2; ++ion )
202  {
203  strcpy(atmdat.chdBaseSources[nelem][ion]," ");
204  atmdat.lgdBaseSourceExists[nelem][ion] = false;
205  }
206  }
207 
209  for( int nelem = 0; nelem < LIMELM; nelem++)
210  {
211  vector<long> row;
212  for(int ion = 0; ion < nelem+1; ion++)
213  {
214  row.push_back(-1);
215  }
216  atmdat.ipSpecIon.push_back(row);
217  }
218 
219  /* smallest density to permit in any ion - if smaller then set to zero */
222 
223  /* default cosmic ray background */
224  /* >>chng 99 jun 24, slight change to value
225  * quoted by
226  * >>refer cosmic ray ionization rate McKee, C.M., 1999, astro-ph 9901370
227  * this will produce a total
228  * secondary ionization rate of 2.5e-17 s^-1, as tested in
229  * test suite cosmicray.in. If each ionization produces 2.4 eV of heat,
230  * the background heating rate should be 9.6e-29 * n*/
231  /* >>chng 04 jan 26, update cosmic ray ionization rate for H0 to
232  * >>refer cosmic ray ionization Williams, J.P., Bergin, E.A., Caselli, P.,
233  * >>refercon Myers, P.C., & Plume, R. 1998, ApJ, 503, 689,
234  * H0 ionization rate of 2.5e-17 s-1 and a H2 ionization rate twice this
235  * >>chng 04 mar 15, comment said 2.5e-17 which is correct, but code produce 8e-17,
236  * fix back to correct value
237  */
238  /* NB - the rate is derived from the density. these two are related by the secondary
239  * ionization efficiency problem. background_rate is only here to provide the relationship
240  * for predominantly neutral gas. the background_density is the real rate.
241  hextra.background_density = 1.99e-9f;*/
242  /* >>chng 05 apr 16, to get proper ionization rate in ism_set_cr_rate, where
243  * H is forced to be fully atomic, no molecules, density from 1.99 to 2.15 */
244  /* >>chng 02 apr 05, update to
245  * >>refer cosmic ray ionization Indriolo, N., Geballe, T., Oka, T., & McCall, B.J. 2007, ApJ, 671, 1736
246  */
247  hextra.background_density = 2.15e-9f*7.9f;
248  hextra.background_rate = 2.5e-17f*7.9f;
249 
250  for( long i=0; i < LIMPAR; ++i )
251  optimize.lgOptimizeAsLinear[i] = false;
252 
253  /* limit on ionization we check for zoning and prtcomment */
254  struc.dr_ionfrac_limit = 1e-3f;
255 
256  SaveFilesInit();
257 
258  diatoms_init();
259 
260  /* initialize cosmological information */
263  cosmology.redshift_step = 0.f;
264  cosmology.omega_baryon = 0.04592f;
265  cosmology.omega_rad = 8.23e-5f;
266  cosmology.omega_lambda = 0.7299177f;
267  cosmology.omega_matter = 0.27f;
268  cosmology.omega_k = 0.f;
269  /* the Hubble parameter in 100 km/s/Mpc */
270  cosmology.h = 0.71f;
271  /* the Hubble parameter in km/s/Mpc */
272  cosmology.H_0 = 100.f*cosmology.h;
273  cosmology.lgDo = false;
274 
275  // the code is ok at startup; only init here so that code remains broken
276  // in a grid if any single model announces broken
277  broke.lgBroke = false;
278  broke.lgFixit = false;
279  broke.lgCheckit = false;
280  broke.lgPrintFixits = false;
281 
282  return;
283 }
t_atmdat atmdat
Definition: atmdat.cpp:6
bool lgMapOK
Definition: hcmap.h:30
realnum h
Definition: cosmology.h:38
long int numLevels_malloc
Definition: iso.h:533
long int nCompRecoilElec[LIMELM]
Definition: ionbal.h:184
const int ipMAGNESIUM
Definition: cddefines.h:360
realnum dr_ionfrac_limit
Definition: struc.h:84
const int ipHE_LIKE
Definition: iso.h:65
t_struc struc
Definition: struc.cpp:6
t_Heavy Heavy
Definition: heavy.cpp:5
const realnum SMALLFLOAT
Definition: cpu.h:246
t_isoCTRL iso_ctrl
Definition: iso.cpp:9
const int NISO
Definition: cddefines.h:311
realnum redshift_step
Definition: cosmology.h:26
const int ipOXYGEN
Definition: cddefines.h:356
bool lgBroke
Definition: broke.h:30
realnum redshift_start
Definition: cosmology.h:26
long int nCollapsed_max
Definition: iso.h:518
t_hextra hextra
Definition: hextra.cpp:5
bool lgElmtSetOff[LIMELM]
Definition: dense.h:164
bool lgSetIoniz[LIMELM]
Definition: dense.h:167
bool lgDo
Definition: cosmology.h:44
realnum H_0
Definition: cosmology.h:38
const int ipSULPHUR
Definition: cddefines.h:364
t_dense dense
Definition: global.cpp:15
t_iso_sp iso_sp[NISO][LIMELM]
Definition: iso.cpp:11
long int max_num_levels
Definition: iso.cpp:13
bool lgIonStoutOn[LIMELM][LIMELM+1]
Definition: dense.h:143
bool lgLinesAdded
Definition: taulines.cpp:12
bool lgIonChiantiOn[LIMELM][LIMELM+1]
Definition: dense.h:140
t_ionbal ionbal
Definition: ionbal.cpp:8
bool lgdBaseSourceExists[LIMELM][LIMELM+1]
Definition: atmdat.h:452
realnum background_rate
Definition: hextra.h:39
const int ipIRON
Definition: cddefines.h:374
void iso_update_num_levels(long ipISO, long nelem)
long int n_HighestResolved_max
Definition: iso.h:536
bool lgMapDone
Definition: hcmap.h:36
realnum redshift_current
Definition: cosmology.h:26
char chdBaseSources[LIMELM][LIMELM+1][10]
Definition: atmdat.h:451
const char * chISO[NISO]
Definition: iso.h:348
bool lgPrintFixits
Definition: broke.h:34
bool lgFixit
Definition: broke.h:33
const int ipNEON
Definition: cddefines.h:358
t_broke broke
Definition: broke.cpp:10
bool lgMapBeingDone
Definition: hcmap.h:33
const long LIMPAR
Definition: optimize.h:61
t_optimize optimize
Definition: optimize.cpp:6
long int nmap
Definition: hcmap.h:39
bool lgElmtOn[LIMELM]
Definition: dense.h:160
realnum omega_baryon
Definition: cosmology.h:31
const int ipSILICON
Definition: cddefines.h:362
bool lgOptimizeAsLinear[LIMPAR]
Definition: optimize.h:184
realnum omega_lambda
Definition: cosmology.h:31
realnum omega_k
Definition: cosmology.h:31
const int ipNITROGEN
Definition: cddefines.h:355
const int ipH_LIKE
Definition: iso.h:64
const int LIMELM
Definition: cddefines.h:308
vector< vector< long > > ipSpecIon
Definition: atmdat.h:455
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:723
t_cosmology cosmology
Definition: cosmology.cpp:8
const int ipHELIUM
Definition: cddefines.h:350
realnum omega_rad
Definition: cosmology.h:31
void InitCoreload(void)
#define MAX2(a, b)
Definition: cddefines.h:824
char chShell[7][3]
Definition: heavy.h:31
const int ipCARBON
Definition: cddefines.h:354
double maxWN[LIMELM][LIMELM+1]
Definition: dense.h:146
bool lgStatesAdded
Definition: taulines.cpp:11
long int numLevels_max
Definition: iso.h:524
t_hcmap hcmap
Definition: hcmap.cpp:23
void diatoms_init(void)
Definition: h2.cpp:159
const int ipHYDROGEN
Definition: cddefines.h:349
realnum omega_matter
Definition: cosmology.h:31
realnum background_density
Definition: hextra.h:38
char chOptimFileName[INPUT_LINE_LENGTH]
Definition: optimize.cpp:7
long int nMapAlloc
Definition: hcmap.h:53
void SaveFilesInit(void)
double density_low_limit
Definition: dense.h:208
bool lgCheckit
Definition: broke.h:37