cloudy  trunk
parse_constant.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 /*ParseConstant parse parameters from the 'constant ...' command */
4 #include "cddefines.h"
5 #include "physconst.h"
6 #include "optimize.h"
7 #include "thermal.h"
8 #include "dense.h"
9 #include "pressure.h"
10 #include "phycon.h"
11 #include "input.h"
12 #include "parse.h"
13 #include "parser.h"
14 
16 {
17  DEBUG_ENTRY( "ParseConstant()" );
18 
19  if( p.nMatch("GRAI") && p.nMatch("TEMP") )
20  {
21  /* constant grain temperature command */
23 
24  /* if linear option is not on the line, convert to exponent if <= 10 */
25  if( !p.nMatch("LINE") )
26  {
27  if( thermal.ConstGrainTemp <= 10. )
29  }
30 
31  if( p.lgEOL() )
32  {
33  p.NoNumb("grain temperature");
34  }
35  }
36 
37  else if( p.nMatch("TEMP") )
38  {
39  /* a constant temperature model */
42 
43  /* this is an option to specify the temperature in different units
44  * keV, eV now supported */
45  realnum convert_to_Kelvin = 1;
46  if( p.nMatch(" EV ") )
47  {
48  convert_to_Kelvin = (realnum)EVDEGK;
49  }
50  else if( p.nMatch(" KEV") )
51  {
52  convert_to_Kelvin = (realnum)(EVDEGK * 1000.);
53  }
54 
55  /* this is the "force" temperature. same var used in force temp
56  * command, but lgTSetOn is not set so then allowed to vary
57  * so constant temperature requires both lgTSetOn true and ConstTemp > 0 */
59  if( p.lgEOL() )
60  p.NoNumb("temperature");
61 
62  /* if linear option is not on the line and T<=10, assume number is log */
63  if( p.nMatch(" LOG") || (thermal.ConstTemp <= 10. && !p.nMatch("LINE")) )
64  {
65  if( thermal.ConstTemp > log10(BIGFLOAT) )
66  {
67  fprintf(ioQQQ," PROBLEM temperature entered as a log but is too large "\
68  "for this processor. I am interpreting it as the linear temperature.\n");
69  }
70  else
72  }
73  /* do units conversion here */
74  thermal.ConstTemp *= convert_to_Kelvin;
75 
76  /* check temperature bounds */
78  {
80  fprintf( ioQQQ, " PROBLEM Te too low, reset to %g K.\n",
82  }
84  {
86  fprintf( ioQQQ, " PROBLEM Te too high, reset to %g K.\n",
88  }
89 
90  /* set the real electron temperature to the forced value */
91  TempChange( thermal.ConstTemp, false );
92 
93  /* vary option */
94  if( optimize.lgVarOn )
95  {
96  /* no luminosity options on vary */
98  // the keyword LOG is not used above, but is checked elsewhere
99  strcpy( optimize.chVarFmt[optimize.nparm], "CONSTANT TEMP %f LOG" );
100 
101  /* pointer to where to write */
103 
104  /* log of temp will be pointer */
106  optimize.vincr[optimize.nparm] = 0.1f;
107  optimize.varang[optimize.nparm][0] = (realnum)log10(1.00001*phycon.TEMP_LIMIT_LOW);
109  ++optimize.nparm;
110  }
111  }
112 
113  else if( p.nMatch("DENS") )
114  {
115  /* constant density */
116  strcpy( dense.chDenseLaw, "CDEN" );
117  /* turn off radiation pressure */
120  pressure.lgPres_ram_ON = false;
121  }
122 
123  else if( p.nMatch("PRES") )
124  {
125  /* constant pressure */
126  strcpy( dense.chDenseLaw, "CPRE" );
127 
128  /* >>chng 06 jun 20, add reset option, to reset density to keep
129  * initial pressure itself constant from iteration to iteration,
130  * rather than initial density */
131  if( p.nMatch("RESE") )
132  {
133  /* this says not to keep initial density constant,
134  * reset it to keep pressure const */
135  dense.lgDenseInitConstant = false;
136  }
137  else
138  {
139  /* this is default, says keep initial density constant,
140  * so pressure from iter to iter not really const */
141  dense.lgDenseInitConstant = true;
142  }
143 
144  if( p.nMatch("TIME") )
145  {
146  // pressure varies as a function of time
147  /* this says not to keep initial density constant,
148  * reset it to keep pressure const */
149  dense.lgDenseInitConstant = false;
150  dense.lgPressureVaryTime = true;
151 
152  // required number is timescale for time variation
155  {
156  // need two numbers
157  fprintf(ioQQQ," PROBLEM the constant pressure time command requires"
158  " a positive timescale.\n");
160  }
161  // optional number is index for time variation
163  // pressure will be initial pressure - pressure.PresTotlInit - multiplied by
164  // (time / time scale ) ^ index
165  if( p.lgEOL() )
166  {
167  // need two numbers
168  fprintf(ioQQQ," PROBLEM the constant pressure time command requires"
169  " two numbers, the timescale for the variation and an index.\n");
171  }
172  }
173 
174  if( p.nMatch(" GAS") )
175  {
176  /* constant gas pressure (no radiation)
177  * turn off radiation pressure */
179 
180  /* turn off incident continuum */
181  pressure.lgContRadPresOn = false;
182 
183  /* turn off magnetic and ram pressure */
185  pressure.lgPres_ram_ON = false;
186 
187  /* optional number is power law index */
189  }
190 
191  else
192  {
193  /* constant total pressure, gas+rad+incident continuum
194  * turn on radiation pressure */
197  pressure.lgPres_ram_ON = true;
198 
199  /* option to turn off continuum pressure */
200  if( p.nMatch("NO CO") )
201  {
202  pressure.lgContRadPresOn = false;
203  }
204  else
205  {
206  pressure.lgContRadPresOn = true;
207  }
208 
209  /* option to not abort when too much radiation pressure, no abort */
210  if( p.nMatch("NO AB") )
211  {
212  pressure.lgRadPresAbortOK = false;
213  }
214  else
215  {
216  pressure.lgRadPresAbortOK = true;
217  }
218  /* there is no optional power law option for constant total pressure */
219  pressure.PresPowerlaw = 0.;
220 
221  /* option to set pressure */
222  if( p.nMatch(" SET") )
223  {
224  /* number on line is log of nT - option to specify initial pressure */
226  /* this is log of nT product - if not present then set zero */
228  if( p.lgEOL() )
229  p.NoNumb("initial pressure" );
230  else
231  /* pressure in nkT units */
233  BOLTZMANN;
234  }
235  else
237  }
238 
239  /* vary option */
241  {
242  /* no options on vary */
244  // the keyword LOG is not used above, but is checked elsewhere
245  strcpy( optimize.chVarFmt[optimize.nparm], "CONSTANT PRESSURE SET %f LOG" );
247  strcat( optimize.chVarFmt[optimize.nparm], " RESET" );
249  strcat( optimize.chVarFmt[optimize.nparm], " NO CONTINUUM" );
251  strcat( optimize.chVarFmt[optimize.nparm], " NO ABORT" );
252 
253  /* pointer to where to write */
255 
256  /* log of temp will be pointer */
258  optimize.vincr[optimize.nparm] = 0.1f;
259  ++optimize.nparm;
260  }
261  }
262 
263  else
264  {
265  /* no keys were recognized */
266  fprintf( ioQQQ, " The keyword should be TEMPerature, DENSity, GAS or PRESsure, sorry.\n" );
268  }
269  return;
270 }
thermal.h
Parser::nMatch
bool nMatch(const char *chKey) const
Definition: parser.h:135
t_optimize::vincr
realnum vincr[LIMPAR]
Definition: optimize.h:191
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
t_optimize::nparm
long int nparm
Definition: optimize.h:201
t_input::nRead
long int nRead
Definition: input.h:49
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
TempChange
void TempChange(double TempNew, bool lgForceUpdate)
Definition: temp_change.cpp:51
realnum
float realnum
Definition: cddefines.h:103
t_pressure::lgPres_magnetic_ON
bool lgPres_magnetic_ON
Definition: pressure.h:131
EVDEGK
const UNUSED double EVDEGK
Definition: physconst.h:186
t_optimize::lgVarOn
bool lgVarOn
Definition: optimize.h:203
phycon
t_phycon phycon
Definition: phycon.cpp:6
t_dense::lgDenseInitConstant
bool lgDenseInitConstant
Definition: dense.h:162
t_phycon::TEMP_LIMIT_LOW
const double TEMP_LIMIT_LOW
Definition: phycon.h:111
input
t_input input
Definition: input.cpp:12
t_thermal::lgTemperatureConstant
bool lgTemperatureConstant
Definition: thermal.h:32
t_dense::lgPressureVaryTime
bool lgPressureVaryTime
Definition: dense.h:165
parse.h
t_pressure::lgPres_ram_ON
bool lgPres_ram_ON
Definition: pressure.h:132
optimize
t_optimize optimize
Definition: optimize.cpp:5
t_optimize::vparm
realnum vparm[LIMEXT][LIMPAR]
Definition: optimize.h:188
t_optimize::chVarFmt
char chVarFmt[LIMPAR][FILENAME_PATH_LENGTH_2]
Definition: optimize.h:263
EXIT_FAILURE
#define EXIT_FAILURE
Definition: cddefines.h:140
Parser::NoNumb
NORETURN void NoNumb(const char *chDesc) const
Definition: parser.cpp:233
t_pressure::lgRadPresAbortOK
bool lgRadPresAbortOK
Definition: pressure.h:161
Parser
Definition: parser.h:31
dense.h
t_thermal::ConstTemp
realnum ConstTemp
Definition: thermal.h:44
cddefines.h
thermal
t_thermal thermal
Definition: thermal.cpp:5
t_thermal::ConstGrainTemp
realnum ConstGrainTemp
Definition: thermal.h:47
optimize.h
t_optimize::nvarxt
long int nvarxt[LIMPAR]
Definition: optimize.h:194
t_pressure::PressureInitialSpecified
double PressureInitialSpecified
Definition: pressure.h:98
pressure.h
t_pressure::lgContRadPresOn
bool lgContRadPresOn
Definition: pressure.h:105
cdEXIT
#define cdEXIT(FAIL)
Definition: cddefines.h:434
Parser::lgEOL
bool lgEOL(void) const
Definition: parser.h:98
BIGFLOAT
const UNUSED realnum BIGFLOAT
Definition: cpu.h:189
t_pressure::lgPres_radiation_ON
bool lgPres_radiation_ON
Definition: pressure.h:130
t_optimize::varang
realnum varang[LIMPAR][2]
Definition: optimize.h:198
t_dense::PressureVaryTimeIndex
double PressureVaryTimeIndex
Definition: dense.h:170
parser.h
physconst.h
t_optimize::nvfpnt
long int nvfpnt[LIMPAR]
Definition: optimize.h:195
t_pressure::PresPowerlaw
realnum PresPowerlaw
Definition: pressure.h:76
t_thermal::lgTemperatureConstantCommandParsed
bool lgTemperatureConstantCommandParsed
Definition: thermal.h:38
t_dense::PressureVaryTimeTimescale
double PressureVaryTimeTimescale
Definition: dense.h:168
pressure
t_pressure pressure
Definition: pressure.cpp:5
phycon.h
t_phycon::TEMP_LIMIT_HIGH
const double TEMP_LIMIT_HIGH
Definition: phycon.h:113
t_pressure::lgPressureInitialSpecified
bool lgPressureInitialSpecified
Definition: pressure.h:96
BOLTZMANN
const UNUSED double BOLTZMANN
Definition: physconst.h:97
input.h
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684
ParseConstant
void ParseConstant(Parser &p)
Definition: parse_constant.cpp:15
SMALLFLOAT
const realnum SMALLFLOAT
Definition: cpu.h:191