cloudy trunk
Loading...
Searching...
No Matches
parse_hden.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/*ParseHDEN parse the hden command */
4#include "cddefines.h"
5#include "input.h"
6#include "dense.h"
7#include "optimize.h"
8#include "parser.h"
9#include "cosmology.h"
10
12{
13 DEBUG_ENTRY( "ParseHDEN()" );
14
15 if( dense.gas_phase[ipHYDROGEN] > 0. )
16 {
17 fprintf( ioQQQ, " PROBLEM DISASTER More than one density command was entered.\n" );
19 }
20
21 /* log of hydrogen density */
22 dense.SetGasPhaseDensity( ipHYDROGEN, (realnum)p.FFmtRead() );
23 if( p.lgEOL() )
24 {
25 fprintf( ioQQQ, " DISASTER The density MUST be entered with this command. STOP\n" );
27 }
28
29 /* check for further options */
30 if( ! p.nMatch("LINE") )
31 {
32 /* check size of density - will we crash? */
33 if( dense.gas_phase[ipHYDROGEN] > log10(FLT_MAX) ||
34 dense.gas_phase[ipHYDROGEN] < log10(FLT_MIN) )
35 {
36 fprintf(ioQQQ,
37 " DISASTER - the log of the entered hydrogen density is %.3f - too extreme for this processor.\n",
38 dense.gas_phase[ipHYDROGEN]);
39 if( dense.gas_phase[ipHYDROGEN] > 0. )
40 fprintf(ioQQQ,
41 " DISASTER - the log of the largest hydrogen density this processor can do is %.3f.\n",
42 log10(FLT_MAX) );
43 else
44 fprintf(ioQQQ,
45 " DISASTER - the log of the smallest hydrogen density this processor can do is %.3f.\n",
46 log10(FLT_MIN) );
47 fprintf(ioQQQ," Sorry.\n" );
48
50 }
51
52 dense.SetGasPhaseDensity( ipHYDROGEN, (realnum)pow((realnum)10.f,dense.gas_phase[ipHYDROGEN]) );
53 }
54
55 if( dense.gas_phase[ipHYDROGEN] > MAX_DENSITY )
56 {
57 fprintf( ioQQQ, "This density is too high. This version of Cloudy does not permit densities greater than %e cm-3.\n", MAX_DENSITY );
59 }
60
61 if( dense.gas_phase[ipHYDROGEN] <= 0. )
62 {
63 fprintf( ioQQQ, " PROBLEM DISASTER Hydrogen density must be > 0.\n" );
65 }
66
67 /* this is the linear initial density */
68 dense.den0 = dense.gas_phase[ipHYDROGEN];
69
70 /* check if exponent entered */
71 dense.DensityPower = (realnum)p.FFmtRead();
72 /* this branch when exponent was entered - do something with it */
73 if( !p.lgEOL() )
74 {
75 /* not constant density
76 * some sort of power law density distribution */
77 if( p.nMatch("COLU") )
78 {
79 /* density will depend on column density to a power
80 * number entered is col den, convert to scale radius
81 * at this point HDEN is LOG10 of hydrogen density */
82 dense.rscale = (realnum)pow(10.,p.FFmtRead());
83 if( p.lgEOL() )
84 {
85 fprintf( ioQQQ, " The column density MUST be set if the col den option is to be used.\n" );
87 }
88 strcpy( dense.chDenseLaw, "POWC" );
89 }
90 else if( p.nMatch("DEPT") )
91 {
92 /* depth option, sets scale radius, log cm */
93 dense.rscale = (realnum)pow(10.,p.FFmtRead());
94 if( p.lgEOL() )
95 {
96 fprintf( ioQQQ, " The scale depth MUST be set if the depth option is to be used.\n" );
98 }
99 strcpy( dense.chDenseLaw, "POWD" );
100 }
101 else
102 {
103 /* radius option, will be relative to inner radius */
104 strcpy( dense.chDenseLaw, "POWR" );
105 }
106 }
107
108 /* vary option */
109 if( optimize.lgVarOn )
110 {
111 /* pointer to where to write */
112 optimize.nvfpnt[optimize.nparm] = input.nRead;
113 optimize.vparm[0][optimize.nparm] = (realnum)log10(dense.gas_phase[ipHYDROGEN]);
114 optimize.vincr[optimize.nparm] = 1.;
115
116 /* these are varios options for density laws,
117 * first is constant density or pressre*/
118 if( strcmp(dense.chDenseLaw ,"CDEN") == 0 ||
119 strcmp(dense.chDenseLaw ,"CPRE") == 0 ||
120 strcmp(dense.chDenseLaw ,"WIND") == 0 ||
121 strcmp(dense.chDenseLaw ,"DYNA") == 0
122 )
123 {
124 strcpy( optimize.chVarFmt[optimize.nparm], "HDEN=%f LOG" );
125 optimize.nvarxt[optimize.nparm] = 1;
126 }
127
128 /* power law density distrution */
129 else if( strcmp(dense.chDenseLaw,"POWR") == 0 )
130 {
131 strcpy( optimize.chVarFmt[optimize.nparm], "HDEN=%f LOG, power=%f" );
132 optimize.nvarxt[optimize.nparm] = 2;
133 optimize.vparm[1][optimize.nparm] = dense.DensityPower;
134 }
135
136 /* power law with density scale depending on column density */
137 else if( strcmp(dense.chDenseLaw,"POWC") == 0 )
138 {
139 strcpy( optimize.chVarFmt[optimize.nparm], "HDEN=%f LOG, power=%f, column=%f" );
140 optimize.nvarxt[optimize.nparm] = 3;
141 optimize.vparm[1][optimize.nparm] = dense.DensityPower;
142 optimize.vparm[2][optimize.nparm] = (realnum)log10(dense.rscale);
143 }
144
145 /* power law with density scale depending on depth */
146 else if( strcmp(dense.chDenseLaw,"POWD") == 0 )
147 {
148 strcpy( optimize.chVarFmt[optimize.nparm], "HDEN=%f LOG, power=%f, depth=%f" );
149 optimize.nvarxt[optimize.nparm] = 3;
150 optimize.vparm[1][optimize.nparm] = dense.DensityPower;
151 optimize.vparm[2][optimize.nparm] = (realnum)log10(dense.rscale);
152 }
153
154 /* could not identify an option */
155 else
156 {
157 fprintf( ioQQQ, " Internal error in HDEN\n" );
159 }
160 ++optimize.nparm;
161 }
162 return;
163}
FILE * ioQQQ
Definition cddefines.cpp:7
const double MAX_DENSITY
Definition cddefines.h:269
#define EXIT_FAILURE
Definition cddefines.h:140
#define cdEXIT(FAIL)
Definition cddefines.h:434
float realnum
Definition cddefines.h:103
const int ipHYDROGEN
Definition cddefines.h:305
#define DEBUG_ENTRY(funcname)
Definition cddefines.h:684
double FFmtRead(void)
Definition parser.cpp:353
bool nMatch(const char *chKey) const
Definition parser.h:135
bool lgEOL(void) const
Definition parser.h:98
t_dense dense
Definition dense.cpp:24
t_input input
Definition input.cpp:12
t_optimize optimize
Definition optimize.cpp:5
void ParseHDEN(Parser &p)