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