cloudy  trunk
parse_backgrd.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 /*ParseBackgrd parse options for the BACKGROUND command - this actually enters two continua*/
4 #include "cddefines.h"
5 #include "cosmology.h"
6 #include "physconst.h"
7 #include "radius.h"
8 #include "rfield.h"
9 #include "parser.h"
10 
12 {
13  double a,
14  fac,
15  rlogl,
16  z;
17 
18  DEBUG_ENTRY( "ParseBackgrd()" );
19 
20  /* check that stack of shape and luminosity specifications
21  * is parallel, stop if not - this happens is background comes
22  * BETWEEN another set of shape and luminosity commands */
23  if( rfield.nShape != p.m_nqh )
24  {
25  fprintf( ioQQQ, " This command has come between a previous ordered pair of continuum shape and luminosity commands.\n Reorder the commands to complete each continuum specification before starting another.\n" );
26  fprintf( ioQQQ, " Sorry.\n" );
28  }
29 
30  /* diffuse x-ray background from
31  * >>refer cosmic background Ostriker and Ikeuchi ApJL 268, L63.
32  * parameter on cmnd is redshift, followed by optional J21
33  * >>refer cosmic background Ikeuchi, S.; Ostriker, J. P., 1986, ApJ 301, 522 */
34 
35  /* >>chng 02 aug 12, do not try to enter bare powerlaw, use table power law default instead */
36  {
37  // There must be a neater way than this to extract the
38  // functionality from ParseTable...
39  p.set_point(0);
40  string cmdSave = p.getRawTail();
41  p.setline("TABLE POWERLAW ");
42  ParseTable( p );
43  p.setline(cmdSave.c_str());
44  p.set_point(4);
45  }
46 
47  /* now generate equivalent of luminosity command
48  * enter phi(h), the number of h-ionizing photons/cm2 */
49 
50  strcpy( rfield.chRSpec[p.m_nqh], "SQCM" );
51  strcpy( rfield.chSpNorm[p.m_nqh], "FLUX" );
52  /* this is an isotropic radiation field */
53  rfield.lgBeamed[p.m_nqh] = false;
55 
56  /* this will be the redshift */
57  z = p.FFmtRead();
58  if( p.lgEOL() )
59  z = 0.;
60 
61  /* optional scale factor */
62  fac = p.FFmtRead();
63  if( p.lgEOL() )
64  fac = 1.0;
65 
66  /* this equation from Ostriker and Ikeuchi Ap.J.L 268, L63.
67  * this should be J_nu into 4\pi sr
68  * >>chng 96 jul 23, from ostriker to vedel, et al mnras 271, 743. */
69  rfield.totpow[p.m_nqh] = (log10(PI4*fac*1.e-21/
70  (1.+powi(5./(1.+z),4))));
71 
72  /* this is at 1 ryd for H
73  * range(nqh,1) = 1.
74  *>>chgn 96 dec 18, to H ioniz pot from 1 ryd */
75  rfield.range[p.m_nqh][0] = HIONPOT;
76 
77  ++p.m_nqh;
78  if( p.m_nqh >= LIMSPC )
79  {
80  fprintf( ioQQQ, " Too many continua entered; increase LIMSPC\n" );
82  }
83 
84  /* add fireball unless NO FIREBALL or NO CMP in */
85  if( !(p.nMatch("NO FI") || p.nMatch("NO CM") ) )
86  {
87 
88  /* put in a black body */
89  strcpy( rfield.chSpType[rfield.nShape], "BLACK" );
90  /* >>chng 03 may 23, CMB temp from 2.756 to 2.725 */
91  rfield.slope[rfield.nShape] = (CMB_TEMP*(1. + z));
92  rfield.cutoff[rfield.nShape][0] = 0.;
93  rfield.cutoff[rfield.nShape][1] = 0.;
94  strcpy( rfield.chSpNorm[p.m_nqh], "LUMI" );
95  a = log10(rfield.slope[rfield.nShape]);
96  rlogl = log10(4.*STEFAN_BOLTZ) + 4.*a;
97  strcpy( rfield.chRSpec[p.m_nqh], "SQCM" );
98  rfield.range[p.m_nqh][0] = rfield.emm;
99  rfield.range[p.m_nqh][1] = rfield.egamry;
100  rfield.totpow[p.m_nqh] = rlogl;
101 
102  /* this flag says that CMB has been set */
103  rfield.lgCMB_set = true;
104 
105  ++rfield.nShape;
106  ++p.m_nqh;
107  if( p.m_nqh >= LIMSPC )
108  {
109  fprintf( ioQQQ, " Too many continua entered; increase LIMSPC\n" );
111  }
112  }
113 
114  /* set radius to very large value if not already set */
115  /* >>chng 01 jul 24, from Radius == 0 to this, as per PvH comments */
116  if( !radius.lgRadiusKnown )
117  {
118  radius.Radius = pow(10.,radius.rdfalt);
119  }
120  return;
121 }
t_rfield::totpow
double totpow[LIMSPC]
Definition: rfield.h:300
Parser::nMatch
bool nMatch(const char *chKey) const
Definition: parser.h:135
ParseTable
void ParseTable(Parser &p)
Definition: parse_table.cpp:340
Parser::getRawTail
string getRawTail()
Definition: parser.h:220
Parser::FFmtRead
double FFmtRead(void)
Definition: parser.cpp:353
rfield
t_rfield rfield
Definition: rfield.cpp:8
ioQQQ
FILE * ioQQQ
Definition: cddefines.cpp:7
STEFAN_BOLTZ
const UNUSED double STEFAN_BOLTZ
Definition: physconst.h:210
rfield.h
HIONPOT
const UNUSED double HIONPOT
Definition: physconst.h:119
t_rfield::chSpType
char chSpType[LIMSPC][6]
Definition: rfield.h:353
LIMSPC
const int LIMSPC
Definition: rfield.h:18
PI4
const UNUSED double PI4
Definition: physconst.h:35
t_rfield::cutoff
double cutoff[LIMSPC][3]
Definition: rfield.h:302
t_rfield::slope
double slope[LIMSPC]
Definition: rfield.h:301
t_radius::lgRadiusKnown
bool lgRadiusKnown
Definition: radius.h:116
radius
t_radius radius
Definition: radius.cpp:5
EXIT_FAILURE
#define EXIT_FAILURE
Definition: cddefines.h:140
t_rfield::egamry
realnum egamry
Definition: rfield.h:52
t_rfield::chRSpec
char chRSpec[LIMSPC][5]
Definition: rfield.h:352
Parser
Definition: parser.h:31
cddefines.h
t_radius::Radius
double Radius
Definition: radius.h:25
Illuminate::SYMMETRIC
@ SYMMETRIC
Definition: rfield.h:30
t_radius::rdfalt
double rdfalt
Definition: radius.h:124
t_rfield::Illumination
Illuminate::IlluminationType Illumination[LIMSPC]
Definition: rfield.h:316
radius.h
t_rfield::lgCMB_set
bool lgCMB_set
Definition: rfield.h:124
cdEXIT
#define cdEXIT(FAIL)
Definition: cddefines.h:434
Parser::lgEOL
bool lgEOL(void) const
Definition: parser.h:98
CMB_TEMP
#define CMB_TEMP
Definition: cosmology.h:10
cosmology.h
Parser::setline
void setline(const char *const card)
Definition: parser.h:69
t_rfield::lgBeamed
bool lgBeamed[LIMSPC]
Definition: rfield.h:310
powi
double powi(double, long int)
Definition: service.cpp:604
t_rfield::range
double range[LIMSPC][2]
Definition: rfield.h:347
parser.h
physconst.h
Parser::m_nqh
long int m_nqh
Definition: parser.h:41
Parser::set_point
void set_point(long int ipnt)
Definition: parser.h:77
t_rfield::nShape
long int nShape
Definition: rfield.h:322
t_rfield::emm
realnum emm
Definition: rfield.h:49
t_rfield::chSpNorm
char chSpNorm[LIMSPC][5]
Definition: rfield.h:351
ParseBackgrd
void ParseBackgrd(Parser &p)
Definition: parse_backgrd.cpp:11
DEBUG_ENTRY
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:684