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