cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
age_check.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2017 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*AgeCheck check various timescales after calculation complete to confirm time steady OK */
4 #include "cddefines.h"
5 #include "physconst.h"
6 #include "prt.h"
7 #include "mole.h"
8 #include "struc.h"
9 #include "warnings.h"
10 #include "dense.h"
11 #include "timesc.h"
12 
13 void AgeCheck(void)
14 {
15  char chLine[INPUT_LINE_LENGTH];
16  long int i,
17  limit;
18  double hold,
19  tlong,
20  tsound;
21 
22  DEBUG_ENTRY( "AgeCheck()" );
23 
24  /* cloud age of zero means that age command turned off
25  * negative cloud age means was not set */
26 
27  /* remember longest timescale */
28  tlong = 0.;
29 
30  limit = MAX2(1,nzone-1);
31  ASSERT( limit < struc.nzlim );
32 
33  /* thermal equilibrium timescales */
34  timesc.calc_therm_timesc( limit );
35 
36 
37  /* NZLIM is the size of the struc vectors - should be dynamic
38  limit = MIN2( limit , NZLIM-1 );*/
39 
40  for( i=0; i < limit; i++ )
41  {
44  struc.DenParticles[i]*BOLTZMANN*1.5*struc.testr[i]/struc.coolstr[i]);
47  struc.DenParticles[i]*BOLTZMANN*1.5*struc.testr[i]/struc.coolstr[i]);
48  /*>>chng 99 feb 01, had div by heating, changed to cooling so constant
49  * temperature models are more realistic */
50  }
51 
52  tlong = MAX2(tlong,timesc.time_therm_long);
53  if( prt.lgPrnAges )
54  {
55  sprintf( chLine, " AGE: longest thermal timescale= %.2es.",
57  notein(chLine);
58  }
59 
60  tlong = MAX2(tlong,timesc.TimeH21cm);
61  if( prt.lgPrnAges )
62  {
63  sprintf( chLine, " AGE: 21 cm equilibrium timescale= %.2es.",
64  timesc.TimeH21cm );
65  notein(chLine);
66  }
67 
69  {
70  sprintf( chLine, " C-AGE: Thermal equilibrium timescale, %.2es, longer than age",
72  caunin(chLine);
73  }
74 
75  /* check soundt travel time if constant pressure */
76  if( strcmp(dense.chDenseLaw,"CPRE") == 0 )
77  {
78  tsound = timesc.sound;
79  if( prt.lgPrnAges )
80  {
81  sprintf( chLine, " AGE: sound travel time= %.2es.",
82  tsound );
83  notein(chLine);
84  }
85 
86  if( timesc.CloudAgeSet > 0. && tsound > timesc.CloudAgeSet )
87  {
88  sprintf( chLine, " C-AGE: Sound travel time longer than age in constant pressure model = %.2es",
90  caunin(chLine);
91  }
92  }
93 
94  else
95  {
96  /* do not check if not constant pressure */
97  tsound = 0.;
98  }
99  tlong = MAX2(tlong,tsound);
100 
101  /* molecule formation timescale */
102  /* >>chng 04 sep 17, - if species are negligible will set to negative number
103  * to retain value but not include in timescales */
104  if( findspecieslocal("H2")->xFracLim < 1e-2 )
105  {
108  }
109  tlong = MAX2( tlong , timesc.time_H2_Dest_longest );
110  tlong = MAX2( tlong , timesc.time_H2_Form_longest );
111 
112  if( findspecieslocal("CO")->xFracLim < 1e-2 )
113  {
114  timesc.BigCOMoleForm *= -1.;
115  }
116  tlong = MAX2( tlong , timesc.BigCOMoleForm );
117 
118  /* >>chng 97 jan 03, don't print if zero */
120  {
121  sprintf( chLine, " AGE: longest H2 destruction timescale= %.2es.",
123  notein(chLine);
124  }
125 
127  {
128  sprintf( chLine, " AGE: longest H2 formation timescale= %.2es.",
130  notein(chLine);
131  }
132 
134  {
135  sprintf( chLine, " C-AGE: H2 destruction timescale longer than age, = %.2es",
137  caunin(chLine);
138  }
139 
141  {
142  sprintf( chLine, " C-AGE: H2 formation timescale longer than age, = %.2es",
144  caunin(chLine);
145  }
146 
147  if( prt.lgPrnAges && timesc.BigCOMoleForm > 0. )
148  {
149  sprintf( chLine, " AGE: longest CO formation timescale= %.2es.",
151  notein(chLine);
152  }
153 
155  {
156  sprintf( chLine, " C-AGE: CO formation timescale longer than age, = %.2es",
158  caunin(chLine);
159  }
160 
161  /* hydrogen recombination timescale */
164  for( i=0; i < limit; i++ )
165  {
166  if( struc.ednstr[i]>SMALLFLOAT )
167  {
168  hold = struc.ednstr[i]*2.90e-10*pow(struc.testr[i],(realnum)-0.77f);
171  }
172  }
173 
174  tlong = MAX2(tlong,timesc.time_Hrecom_long);
175  if( prt.lgPrnAges )
176  {
177  sprintf( chLine, " AGE: longest H recombination timescale= %.2es.",
179  notein(chLine);
180  }
181 
183  {
184  sprintf( chLine, " C-AGE: Hydrogen recombination timescale longer than age, = %.2es",
186  caunin(chLine);
187  }
188 
189  /* give age in various units, depending on order of magnitude */
190  if( timesc.CloudAgeSet < 0. )
191  {
192  /* CloudAgeSet initially set to -1, if still the case then age not set */
193  if( tlong < 3600. )
194  {
195  /* less than one day, give only seconds */
196  sprintf( chLine, " !AGE: Cloud age was not set. Longest timescale was %.2e s.",
197  tlong );
198  bangin(chLine);
199  }
200 
201  else if( tlong < 8.64e4 )
202  {
203  /* less than one day, give seconds and hours */
204  sprintf( chLine, " !AGE: Cloud age was not set. Longest timescale was %.2e s = %.2e hours.",
205  tlong, tlong/3600. );
206  bangin(chLine);
207  }
208 
209  else if( tlong < 3e7/12. )
210  {
211  /* less than one month, give seconds and days */
212  sprintf( chLine, " !AGE: Cloud age was not set. Longest timescale was %.2e s = %.2e days.",
213  tlong, tlong/86400. );
214  bangin(chLine);
215  }
216 
217  else if( tlong < 3e7 )
218  {
219  /* less than one year, give seconds and months */
220  sprintf( chLine, " !AGE: Cloud age was not set. Longest timescale was %.2e s = %.2e months.",
221  tlong, (tlong/3.15569e7)*12. );
222  bangin(chLine);
223  }
224 
225  else
226  {
227  /* more than one year, give seconds and years */
228  sprintf( chLine, " !AGE: Cloud age was not set. Longest timescale was %.2e s = %.2e years.",
229  tlong, tlong/3.15569e7 );
230  bangin(chLine);
231  }
232  }
233 
234  else
235  {
236  /* age set, and passed tests, still say longest */
237  if( tlong < 3e7 )
238  {
239  /* less than one year, give only seconds */
240  sprintf( chLine, " AGE: Cloud age was %.2es, Longest timescale was %.2e s.",
241  timesc.CloudAgeSet, tlong );
242  notein(chLine);
243  }
244 
245  else
246  {
247  /* more than one year, give seconds and years */
248  sprintf( chLine, " AGE: Cloud age was %.2e s. Longest timescale was %.2e s = %.2e years.",
249  timesc.CloudAgeSet, tlong, tlong/3.15569e7 );
250  notein(chLine);
251  }
252  }
253  return;
254 }
void bangin(const char *chLine)
Definition: warnings.h:90
double time_Hrecom_short
Definition: timesc.h:36
void calc_therm_timesc(long izone)
Definition: timesc.cpp:26
t_struc struc
Definition: struc.cpp:6
const realnum SMALLFLOAT
Definition: cpu.h:246
realnum * ednstr
Definition: struc.h:25
double time_therm_short
Definition: timesc.h:29
double TimeH21cm
Definition: timesc.h:64
molezone * findspecieslocal(const char buf[])
long int nzone
Definition: cddefines.cpp:14
#define MIN2(a, b)
Definition: cddefines.h:807
double * coolstr
Definition: struc.h:78
t_dense dense
Definition: global.cpp:15
double BigCOMoleForm
Definition: timesc.h:48
double time_H2_Dest_longest
Definition: timesc.h:48
void AgeCheck(void)
Definition: age_check.cpp:13
float realnum
Definition: cddefines.h:124
const int INPUT_LINE_LENGTH
Definition: cddefines.h:301
realnum CloudAgeSet
Definition: timesc.h:43
void notein(const char *chLine)
Definition: warnings.h:82
realnum * DenParticles
Definition: struc.h:25
t_timesc timesc
Definition: timesc.cpp:7
t_prt prt
Definition: prt.cpp:14
double time_Hrecom_long
Definition: timesc.h:36
long int nzlim
Definition: struc.h:19
#define ASSERT(exp)
Definition: cddefines.h:617
double sound
Definition: timesc.h:40
char chDenseLaw[5]
Definition: dense.h:176
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:729
bool lgPrnAges
Definition: prt.h:164
#define MAX2(a, b)
Definition: cddefines.h:828
double pow(double x, int i)
Definition: cddefines.h:782
realnum * testr
Definition: struc.h:25
double time_H2_Form_longest
Definition: timesc.h:48
double time_therm_long
Definition: timesc.h:29
void caunin(const char *chLine)
Definition: warnings.h:98