cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ionbal.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 #include "cddefines.h"
4 #include "ionbal.h"
5 #include "dense.h"
6 #include "warnings.h"
7 
9 
11 {
12  /* these will save bound electron recoil information data */
13  ipCompRecoil =
14  (long**)MALLOC(sizeof(long*)*(unsigned)LIMELM );
16  (double**)MALLOC(sizeof(double*)*(unsigned)LIMELM );
18  (double**)MALLOC(sizeof(double*)*(unsigned)LIMELM );
20  (double**)MALLOC(sizeof(double*)*(unsigned)LIMELM );
22  (double**)MALLOC(sizeof(double*)*(unsigned)LIMELM );
24  (double****)MALLOC(sizeof(double***)*(unsigned)LIMELM );
26  (double***)MALLOC(sizeof(double**)*(unsigned)LIMELM );
28  (double**)MALLOC(sizeof(double*)*(unsigned)LIMELM );
30  (double**)MALLOC(sizeof(double*)*(unsigned)LIMELM );
31  UTA_heat_rate =
32  (double**)MALLOC(sizeof(double*)*(unsigned)LIMELM );
33  /* space for ionization recombination arrays */
34  RateIoniz = (double ***)MALLOC(sizeof(double **)*(unsigned)LIMELM );
35  RateRecomTot = (double **)MALLOC(sizeof(double *)*(unsigned)LIMELM );
36  RateRecomIso = (double **)MALLOC(sizeof(double *)*(unsigned)LIMELM );
37  RR_rate_coef_used = (double **)MALLOC(sizeof(double *)*(unsigned)LIMELM );
38  RR_Verner_rate_coef = (double **)MALLOC(sizeof(double *)*(unsigned)LIMELM );
39 
40  /* rate coefficients [cm3 s-1] for Badnell DR recombination */
41  DR_Badnell_rate_coef = (double **)MALLOC(sizeof(double *)*(unsigned)LIMELM );
42  RR_Badnell_rate_coef = (double **)MALLOC(sizeof(double *)*(unsigned)LIMELM );
43  CX_recomb_rate_used = (double **)MALLOC(sizeof(double *)*(unsigned)LIMELM );
44 
46 
47  /* create arrays for ions */
48  for( long nelem=0; nelem<LIMELM; ++nelem )
49  {
50  DR_Badnell_rate_coef[nelem] = (double *)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
51  RR_Badnell_rate_coef[nelem] = (double *)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
52  CX_recomb_rate_used[nelem] = (double *)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
53 
54  RateIoniz[nelem] = (double **)MALLOC(sizeof(double *)*(unsigned)(nelem+1) );
55  RateRecomTot[nelem] = (double *)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
56 
57  for( long ion=0; ion<nelem+1; ++ion )
58  {
59  RateIoniz[nelem][ion] = (double *)MALLOC(sizeof(double )*(unsigned)(nelem+2) );
60  for( long ion2=0; ion2<nelem+2; ++ion2 )
61  RateIoniz[nelem][ion][ion2] = 0.;
62  }
63 
64  RR_rate_coef_used[nelem] = (double *)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
65  RR_Verner_rate_coef[nelem] = (double *)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
66  UTA_ionize_rate[nelem] =
67  (double*)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
68  UTA_heat_rate[nelem] =
69  (double*)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
70  ipCompRecoil[nelem] =
71  (long*)MALLOC(sizeof(long)*(unsigned)(nelem+1) );
72  CompRecoilIonRate[nelem] =
73  (double*)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
74  CompRecoilIonRateSave[nelem] =
75  (double*)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
76  CompRecoilHeatRate[nelem] =
77  (double*)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
78  CompRecoilHeatRateSave[nelem] =
79  (double*)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
80  PhotoRate_Shell[nelem] =
81  (double***)MALLOC(sizeof(double**)*(unsigned)(nelem+1) );
82  CollIonRate_Ground[nelem] =
83  (double**)MALLOC(sizeof(double*)*(unsigned)(nelem+1) );
84  ExcitationGround[nelem] =
85  (double*)MALLOC(sizeof(double)*(unsigned)(nelem+1) );
86  RateRecomIso[nelem] = (double *)MALLOC(sizeof(double)*(unsigned)(NISO) );
87  for( long ipISO=0; ipISO<NISO; ++ipISO )
88  {
89  RateRecomIso[nelem][ipISO] = 0.;
90  }
91 
92  for( long ion=0; ion<nelem+1; ++ion )
93  {
94  /* >>chng 03 aug 09, set these to impossible values */
95  RateRecomTot[nelem][ion] = -1.;
96  UTA_ionize_rate[nelem][ion] = -1.;
97  UTA_heat_rate[nelem][ion] = -1.;
98  ipCompRecoil[nelem][ion] = -99;
99  CompRecoilIonRate[nelem][ion] = -1.;
100  CompRecoilIonRateSave[nelem][ion] = -1.;
101  CompRecoilHeatRate[nelem][ion] = -1.;
102  CompRecoilHeatRateSave[nelem][ion] = -1.;
103 
104  /* finish mallocing space */
105  PhotoRate_Shell[nelem][ion] =
106  (double**)MALLOC(sizeof(double*)*(unsigned)NSHELLS );
107  CollIonRate_Ground[nelem][ion] =
108  (double*)MALLOC(sizeof(double)*(unsigned)2 );
109  for( long ns=0; ns<NSHELLS; ++ns )
110  {
111  PhotoRate_Shell[nelem][ion][ns] =
112  (double*)MALLOC(sizeof(double)*(unsigned)3 );
113  }
114 
115  /* now set to impossible values */
116  ipCompRecoil[nelem][ion] = -100000;
117  DR_Badnell_rate_coef[nelem][ion] = 0.;
118  RR_Badnell_rate_coef[nelem][ion] = 0.;
119  }
120 
121  set_NaN( RR_rate_coef_used[nelem], nelem+1 );
122  set_NaN( RR_Verner_rate_coef[nelem], nelem+1 );
123  set_NaN( CX_recomb_rate_used[nelem], nelem+1 );
124 
125  DR_Badnell_suppress_fact.reserve( nelem, nelem+1 );
126  }
127 
129 }
130 
132 {
133  /* now zero out these arrays */
134  for( long nelem=0; nelem< LIMELM; ++nelem )
135  {
136  for( long ion=0; ion<nelem+1; ++ion )
137  {
138 
139  CompRecoilHeatRate[nelem][ion] = 0.;
140  CompRecoilIonRate[nelem][ion] = 0.;
141  UTA_ionize_rate[nelem][ion] = 0.;
142  UTA_heat_rate[nelem][ion] = 0.;
143  CollIonRate_Ground[nelem][ion][0] = 0.;
144  CollIonRate_Ground[nelem][ion][1] = 0.;
145  ExcitationGround[nelem][ion] = 0.;
146  RateRecomTot[nelem][ion] = 0.;
147  for( long ns=0; ns < NSHELLS; ++ns )
148  {
149  /* must be zero since ion routines use these when
150  * not yet defined */
151  PhotoRate_Shell[nelem][ion][ns][0] = 0.;
152  PhotoRate_Shell[nelem][ion][ns][1] = 0.;
153  PhotoRate_Shell[nelem][ion][ns][2] = 0.;
154  }
155  }
156  }
157 
158  /* limits for highest and lowest stages of ionization in TrimStage */
159  lgTrimhiOn = true;
160  trimhi = 1e-6;
161  lgTrimloOn = true;
162  trimlo = 1e-10;
163  lgNewTrim = false;
164 
165  lgPhotoIoniz_On = true;
166  lgCompRecoil = true;
167 
168  lgDRsup = true;
169 
170  lgNoCota = false;
171  for( long nelem = 0; nelem < LIMELM; ++nelem )
172  {
173  CotaRate[nelem] = 0.;
174  }
175  ilt = 0;
176  iltln = 0;
177  ilthn = 0;
178  ihthn = 0;
179  ifail = 0;
180  lgGrainIonRecom = true;
181 
182  /* option to print recombination coefficient then exit */
183  lgRecom_Badnell_print = false;
184  guess_noise = 0.;
185 
186 }
187 
189 {
190  char chLine[INPUT_LINE_LENGTH];
191 
192  if( ionbal.CompHeating_Max > 0.05 )
193  {
194  sprintf( chLine,
195  " !Bound Compton heating reached %.2f%% of the local heating.",
196  ionbal.CompHeating_Max*100. );
197  w.bangin(chLine);
198  }
199  else if( ionbal.CompHeating_Max > 0.01 )
200  {
201  sprintf( chLine,
202  " Bound Compton heating reached %.2f%% of the local heating.",
203  ionbal.CompHeating_Max*100. );
204  w.notein(chLine);
205  }
206 
207  /* say if 3-body recombination coefficient function outside range of validity
208  * tripped if te/z**2 < 100 or approx 10**13: => effect >50% of radiative
209  * other integers defined in source for da */
210  if( ionbal.ifail > 0 && ionbal.ifail <= 10 )
211  {
212  sprintf( chLine,
213  " 3 body recombination coefficient outside range %ld", ionbal.ifail );
214  w.notein(chLine);
215  }
216  else if( ionbal.ifail > 10 )
217  {
218  sprintf( chLine,
219  " C-3 body recombination coefficient outside range %ld", ionbal.ifail );
220  w.caunin(chLine);
221  }
222 }
223 
224 double t_ionbal::RateIonizTot( long nelem, long ion ) const
225 {
226  double sum = 0.;
227 
228  for( long ion_to=ion+1; ion_to<=dense.IonHigh[nelem]; ion_to++ )
229  sum += RateIoniz[nelem][ion][ion_to];
230 
231  return sum;
232 }
double ** DR_Badnell_rate_coef
Definition: ionbal.h:200
double ** RR_Badnell_rate_coef
Definition: ionbal.h:200
bool lgTrimhiOn
Definition: ionbal.h:90
bool lgNewTrim
Definition: ionbal.h:96
double ** UTA_heat_rate
Definition: ionbal.h:176
double ** CompRecoilIonRate
Definition: ionbal.h:162
double ** CompRecoilHeatRate
Definition: ionbal.h:168
void set_NaN(sys_float &x)
Definition: cpu.cpp:906
double ** RR_Verner_rate_coef
Definition: ionbal.h:213
const int NISO
Definition: cddefines.h:311
long int ilthn
Definition: ionbal.h:242
long int IonHigh[LIMELM+1]
Definition: dense.h:130
bool lgPhotoIoniz_On
Definition: ionbal.h:117
double ** CompRecoilIonRateSave
Definition: ionbal.h:165
double trimhi
Definition: ionbal.h:83
bool lgRecom_Badnell_print
Definition: ionbal.h:207
void comment(t_warnings &)
Definition: ionbal.cpp:188
t_dense dense
Definition: global.cpp:15
double ** ExcitationGround
Definition: ionbal.h:124
double ** RateRecomIso
Definition: ionbal.h:197
double CompHeating_Max
Definition: ionbal.h:186
long int ifail
Definition: ionbal.h:242
double ** RateRecomTot
Definition: ionbal.h:194
#define MALLOC(exp)
Definition: cddefines.h:554
t_ionbal ionbal
Definition: ionbal.cpp:8
realnum guess_noise
Definition: ionbal.h:229
#define NSHELLS
Definition: ionbal.h:61
double ** UTA_ionize_rate
Definition: ionbal.h:174
const int INPUT_LINE_LENGTH
Definition: cddefines.h:301
void zero()
Definition: ionbal.cpp:131
double ** CompRecoilHeatRateSave
Definition: ionbal.h:171
double **** PhotoRate_Shell
Definition: ionbal.h:112
double *** CollIonRate_Ground
Definition: ionbal.h:121
int lgGrainIonRecom
Definition: ionbal.h:226
void alloc()
Definition: ionbal.cpp:10
double ** CX_recomb_rate_used
Definition: ionbal.h:200
void reserve(size_type i1)
const int LIMELM
Definition: cddefines.h:308
double *** RateIoniz
Definition: ionbal.h:180
multi_arr< double, 2 > DR_Badnell_suppress_fact
Definition: ionbal.h:204
bool lgCompRecoil
Definition: ionbal.h:153
double RateIonizTot(long nelem, long ion) const
Definition: ionbal.cpp:224
double trimlo
Definition: ionbal.h:83
bool lgNoCota
Definition: ionbal.h:236
bool lgTrimloOn
Definition: ionbal.h:93
void notein(const char *chLine)
Definition: warnings.cpp:50
long int ilt
Definition: ionbal.h:242
void bangin(const char *chLine)
Definition: warnings.cpp:73
bool lgDRsup
Definition: ionbal.h:232
long int ihthn
Definition: ionbal.h:242
realnum CotaRate[LIMELM]
Definition: ionbal.h:239
void caunin(const char *chLine)
Definition: warnings.cpp:96
long int iltln
Definition: ionbal.h:242
double ** RR_rate_coef_used
Definition: ionbal.h:210
long int ** ipCompRecoil
Definition: ionbal.h:159