cloudy  trunk
parse_fluc.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2013 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 /*ParseFluc parse the fluctuations command, which affects either density or abundances */
4 #include "cddefines.h"
5 #include "dense.h"
6 #include "parser.h"
7 
8 void ParseFluc(Parser &p )
9 {
10  double flmax,
11  flmin,
12  period,
13  temp;
14 
15  DEBUG_ENTRY( "ParseFluc()" );
16 
17  /* rapid density fluctuations
18  * first parameter is log of period, 2 is log den max, 3 log Nmin */
19  if( p.nMatch("ABUN") )
20  {
21  /* abundances varied, not density */
22  dense.lgDenFlucOn = false;
23  }
24  else
25  {
26  /* density is varied */
27  dense.lgDenFlucOn = true;
28  }
29 
30  /* optional keyword COLUMN makes sin over column density rather than radius */
31  if( p.nMatch("COLU") )
32  {
33  /* found key, not fluc over radius, over col den instead */
34  dense.lgDenFlucRadius = false;
35  }
36  else
37  {
38  /* no key, use default of radius */
39  dense.lgDenFlucRadius = true;
40  }
41 
42  /* 1st number log of period in centimeters */
43  period = pow(10.,p.FFmtRead());
44  dense.flong = (realnum)(6.2831853/period);
45  temp = p.FFmtRead();
46 
47  /* check size of density - will we crash? */
48  if( temp > log10(FLT_MAX) || temp < log10(FLT_MIN) )
49  {
50  fprintf(ioQQQ,
51  " DISASTER - the log of the entered max hydrogen density is %.3f - too extreme for this processor.\n",
52  temp);
53  if( temp > 0. )
54  fprintf(ioQQQ,
55  " DISASTER - the log of the largest hydrogen density this processor can do is %.3f.\n",
56  log10(FLT_MAX) );
57  else
58  fprintf(ioQQQ,
59  " DISASTER - the log of the smallest hydrogen density this processor can do is %.3f.\n",
60  log10(FLT_MIN) );
61  fprintf(ioQQQ," Sorry.\n" );
63  }
64 
65  /* 2nd number log of max hydrogen density */
66  flmax = pow(10.,temp);
67 
68  temp = p.FFmtRead();
69 
70  /* check size of density - will we crash? */
71  if( temp > log10(FLT_MAX) || temp < log10(FLT_MIN) )
72  {
73  fprintf(ioQQQ,
74  " DISASTER - the log of the entered min hydrogen density is %.3f - too extreme for this processor.\n",
75  temp);
76  if( temp > 0. )
77  fprintf(ioQQQ,
78  " DISASTER - the log of the largest hydrogen density this processor can do is %.3f.\n",
79  log10(FLT_MAX) );
80  else
81  fprintf(ioQQQ,
82  " DISASTER - the log of the smallest hydrogen density this processor can do is %.3f.\n",
83  log10(FLT_MIN) );
84  fprintf(ioQQQ," Sorry.\n" );
86  }
87 
88  /* 3rd number log of min hydrogen density */
89  flmin = pow(10.,temp);
90 
91  if( flmax/flmin > 100. )
92  {
93  fprintf( ioQQQ, "This range of density probably will not work.\n" );
94  }
95  if( flmax > 1e15 )
96  {
97  fprintf( ioQQQ, "These parameters look funny to me. Please check Hazy.\n" );
98  }
99  if( p.lgEOL() || (flmin > flmax) )
100  {
101  fprintf( ioQQQ, "There MUST be three numbers on this line.\n" );
102  fprintf( ioQQQ, "These must be the period(cm), max, min densities, all logs, in that order.\n" );
103  if( flmin > flmax )
104  fprintf( ioQQQ, "The max density must be greater or equal than the min density.\n" );
106  }
107 
108  /* this is optional phase shift for the command */
110 
111  /* FacAbunSav = (cfirst * COS( depth*flong+flcPhase ) + csecnd) */
112  dense.cfirst = (realnum)((flmax - flmin)/2.);
113  dense.csecnd = (realnum)((flmax + flmin)/2.);
114  /* these will be added together with the first mult by sin - which goes to
115  * -1 - must not have a negative density */
117  /* >>chng 96 jul 13 moved depset to SetAbundances fac
118  * if( lgDenFlucOn ) then
119  * this is a pressure law
120  * chCPres = 'SINE'
121  * else
122  * this is the metallicity of the gas
123  * do i=3,limelm
124  * depset(i) = flmax
125  * end do
126  * endif
127  *
128  * now get density if this is density option (not abundances) */
129  if( dense.lgDenFlucOn )
130  {
131  strcpy( dense.chDenseLaw, "SINE" );
132 
133  if( dense.gas_phase[ipHYDROGEN] > 0. )
134  {
135  fprintf( ioQQQ, " PROBLEM DISASTER More than one density command was entered.\n" );
137  }
138 
139  /* depth is zero for first zone */
141 
142  if( dense.gas_phase[ipHYDROGEN] <= 0. )
143  {
144  fprintf( ioQQQ, " PROBLEM DISASTER Hydrogen density must be > 0.\n" );
146  }
147  }
148  return;
149 }
Parser::nMatch
bool nMatch(const char *chKey) const
Definition: parser.h:135
Parser::FFmtRead
double FFmtRead(void)
Definition: parser.cpp:353
t_dense::chDenseLaw
char chDenseLaw[5]
Definition: dense.h:158
dense
t_dense dense
Definition: dense.cpp:24
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
t_dense::flcPhase
realnum flcPhase
Definition: dense.h:254
realnum
float realnum
Definition: cddefines.h:103
t_dense::csecnd
realnum csecnd
Definition: dense.h:253
t_dense::gas_phase
realnum gas_phase[LIMELM]
Definition: dense.h:71
ASSERT
#define ASSERT(exp)
Definition: cddefines.h:578
ipHYDROGEN
const int ipHYDROGEN
Definition: cddefines.h:305
t_dense::flong
realnum flong
Definition: dense.h:251
EXIT_FAILURE
#define EXIT_FAILURE
Definition: cddefines.h:140
Parser
Definition: parser.h:31
dense.h
cddefines.h
ParseFluc
void ParseFluc(Parser &p)
Definition: parse_fluc.cpp:8
cdEXIT
#define cdEXIT(FAIL)
Definition: cddefines.h:434
Parser::lgEOL
bool lgEOL(void) const
Definition: parser.h:98
parser.h
t_dense::lgDenFlucRadius
bool lgDenFlucRadius
Definition: dense.h:248
t_dense::cfirst
realnum cfirst
Definition: dense.h:252
t_dense::lgDenFlucOn
bool lgDenFlucOn
Definition: dense.h:244
t_dense::SetGasPhaseDensity
void SetGasPhaseDensity(const long nelem, const realnum density)
Definition: dense.cpp:86
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684