cloudy  trunk
 All Data Structures 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-2008 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 
14 void ParseConstant(char *chCard )
15 {
16  bool lgEOL;
17  long int i;
18 
19  DEBUG_ENTRY( "ParseConstant()" );
20 
21  if( nMatch("GRAI",chCard) && nMatch("TEMP",chCard) )
22  {
23  /* constant grain temperature command */
24  i = 5;
26 
27  /* if linear option is not on the line, convert to exponent if <= 10 */
28  if( !nMatch("LINE",chCard) )
29  {
30  if( thermal.ConstGrainTemp <= 10. )
32  }
33 
34  if( lgEOL )
35  {
36  NoNumb(chCard);
37  }
38  }
39 
40  else if( nMatch("TEMP",chCard) )
41  {
42  /* a constant temperature model */
45 
46  /* this is an option to specify the temperature in different units
47  * keV, eV now supported */
48  realnum convert_to_Kelvin = 1;
49  if( nMatch(" EV ",chCard) )
50  {
51  convert_to_Kelvin = (realnum)EVDEGK;
52  }
53  else if( nMatch(" KEV",chCard) )
54  {
55  convert_to_Kelvin = (realnum)(EVDEGK * 1000.);
56  }
57 
58  i = 5;
59  /* this is the "force" temperature. same var used in force temp
60  * command, but lgTSetOn is not set so then allowed to vary
61  * so constant temperature requires both lgTSetOn true and ConstTemp > 0 */
62  thermal.ConstTemp = (realnum)FFmtRead(chCard,&i,INPUT_LINE_LENGTH,&lgEOL);
63  if( lgEOL )
64  NoNumb(chCard);
65 
66  /* if linear option is not on the line and T<=10, assume number is log */
67  if( !nMatch("LINE",chCard) )
68  {
69  if( thermal.ConstTemp <= 10. )
71  }
72  /* do units conversion here */
73  thermal.ConstTemp *= convert_to_Kelvin;
74 
75  /* check that temperature is not less than 3K */
76  if( thermal.ConstTemp < 3. )
77  {
78  fprintf( ioQQQ, " PROBLEM TE<3K, reset to 3K.\n" );
79  thermal.ConstTemp = 3.;
80  }
81 
82  /* bail if temperature is too high */
83  /* >>chng 06 feb 14, can cannot do a temperature of 1e10 - gaunt factors overrun
84  * energy array. temp must be less than 1e10
85  * >>chng 06 feb 27, change 1e10 to phycon.TEMP_LIMIT_HIGH - which is the same */
87  {
88  fprintf( ioQQQ, " The constant temperature (%.3e K) is > %.3e K, Cloudy cannot handle this temperature.\n",
91  fprintf( ioQQQ, " The upper temperature limit is %.3e K.\n" ,
93  fprintf( ioQQQ, " Sorry.\n" );
94  cdEXIT(EXIT_FAILURE);
95  }
96 
97  /* set the real electron temperature to the forced value */
98  TempChange(thermal.ConstTemp , false);
99 
100  /* vary option */
101  if( optimize.lgVarOn )
102  {
103  /* no luminosity options on vary */
105  strcpy( optimize.chVarFmt[optimize.nparm], "CONStant TEMP %f" );
106 
107  /* pointer to where to write */
109 
110  /* log of temp will be pointer */
111  optimize.vparm[0][optimize.nparm] = (realnum)log10(phycon.te);
112  optimize.vincr[optimize.nparm] = 0.1f;
113  ++optimize.nparm;
114  }
115  }
116 
117  else if( nMatch("DENS",chCard) )
118  {
119  /* constant density */
120  strcpy( dense.chDenseLaw, "CDEN" );
121  /* turn off radiation pressure */
124  pressure.lgPres_ram_ON = false;
125  }
126 
127  else if( nMatch("PRES",chCard) )
128  {
129  /* constant pressure */
130  strcpy( dense.chDenseLaw, "CPRE" );
131 
132  /* >>chng 06 jun 20, add reset option, to reset density to keep
133  * initial pressure itself constant from iteration to iteration,
134  * rather than initial density */
135  if( nMatch("RESE",chCard) )
136  {
137  /* this says not to keep initial density constant,
138  * reset it to keep pressure const */
139  dense.lgDenseInitConstant = false;
140  }
141  else
142  {
143  /* this is default, says keep initial density constant,
144  * so pressure from iter to iter not really const */
145  dense.lgDenseInitConstant = true;
146  }
147 
148  if( nMatch(" GAS",chCard) )
149  {
150  /* constant gas pressure (no radiation)
151  * turn off radiation pressure */
153 
154  /* turn off incident continuum */
155  pressure.lgContRadPresOn = false;
156 
157  /* turn off magnetic and ram pressure */
159  pressure.lgPres_ram_ON = false;
160 
161  /* optional second number is power law index */
162  i = 4;
164  }
165 
166  else
167  {
168  /* constant total pressure, gas+rad+incident continuum
169  * turn on radiation pressure */
172  pressure.lgPres_ram_ON = true;
173 
174  /* option to turn off continuum pressure */
175  if( nMatch("O CO",chCard) )
176  {
177  pressure.lgContRadPresOn = false;
178  }
179  else
180  {
181  pressure.lgContRadPresOn = true;
182  }
183 
184  /* option to not abort when too much radiation pressure, no abort */
185  if( nMatch("O AB",chCard) )
186  {
187  pressure.lgRadPresAbortOK = false;
188  }
189  else
190  {
191  pressure.lgRadPresAbortOK = true;
192  }
193  /* there is no optional power law option for constant total pressure */
194  pressure.PresPowerlaw = 0.;
195 
196  /* option to set pressure */
197  if( nMatch(" SET",chCard) )
198  {
199  /* number on line is log of nT - option to specify initial pressure */
201  /* this is log of nT product - if not present then set zero */
202  i = 5;
204  if( lgEOL )
205  NoNumb( chCard );
206  else
207  /* pressure in nkT units */
209  BOLTZMANN;
210  }
211  else
213  }
214 
215  /* vary option */
217  {
218  /* no options on vary */
220  strcpy( optimize.chVarFmt[optimize.nparm], "CONStant PRESsure SET %f" );
221 
222  /* pointer to where to write */
224 
225  /* log of temp will be pointer */
227  optimize.vincr[optimize.nparm] = 0.1f;
228  ++optimize.nparm;
229  }
230  }
231 
232  else
233  {
234  /* no keys were recognized */
235  fprintf( ioQQQ, " The keyword should be TEMPerature, DENSity, GAS or PRESsure, sorry.\n" );
236  cdEXIT(EXIT_FAILURE);
237  }
238  return;
239 }

Generated for cloudy by doxygen 1.8.1.2