Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
atmdat.h
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2023 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #ifndef ATMDAT_H_
5 #define ATMDAT_H_
6 
7 #include "container_classes.h"
8 #include "module.h"
9 
10 /*This structure is specifically used to hold the collision data in the format given in the LEIDEN Database
11 The data is available as collision rate coefficients(cm3 s-1) over different temperatures*/
13 {
14 public:
15  /*Array of temps*/
16  vector<double> temps;
17  /*Matrix of collision rates(temp,up,lo)*/
19 
20 } ;
21 
22 /*This structure is specifically used to hold the collision data in the format given in the CHIANTI Database
23 The data is available as spline fits to the Maxwellian averaged collision strengths */
25 {
26 public:
27  /*Matrix of spline fits(hi,lo,spline index)*
28  *The first five columns gives the no of spline pts,transition type,gf value,delta E
29  *& Scaling parameter ,in the specified order*/
30  /*The transition type basically tells how the temperature and collision
31  strengths have been scaled*/
32  vector<double> collspline;
33  vector<double> SplineSecDer;
34 
35  long nSplinePts = 0L;
36  long intTranType = 0L;
37  double EnergyDiff;
38  double ScalingParam;
40 };
41 
42 /*This structure is specifically used to hold the collision data in the format given in the STOUT Database
43 The data are available as collision strengths and rates over different temperatures*/
44 struct StoutColls
45 {
46 private:
48 public:
49  /*Number of temps*/
50  long ntemps()
51  {
52  return m_ntemps;
53  }
54  /*Reset values to safe defaults*/
55  void junk()
56  {
57  m_offset = -1;
58  m_ntemps = -1;
59  lgIsRate = false;
60  }
61  // Set range of tabulated data corresponding to this level & collider
62  void setslice(long offset, long ntemps)
63  {
64  m_offset = offset;
65  m_ntemps = ntemps;
66  }
67  long offset() const
68  {
69  return m_offset;
70  }
71  /*Is this a deexcitation rate or collision strength*/
72  bool lgIsRate;
73 
74 };
75 
77 {
79  vector<double> m_temps,m_collstrs;
80  static long ilev(long ipHi, long ipLo)
81  {
82  // Can use triangular arrangement, as ipHi > ipLo
83  return (ipHi*(ipHi-1))/2+ipLo;
84  }
85 public:
86  // Allocates background data structures
87  void alloc(long nHi, long , long nCollider)
88  {
89  // Size of array is first level which *isn't* required
90  m_a.alloc(ilev(nHi+1,0),nCollider);
91  m_temps.resize(0);
92  m_collstrs.resize(0);
93  }
94  // Initializes per-collision data to safe values
95  void junk(long ipHi, long ipLo, long ipCollider)
96  {
97  m_a[ilev(ipHi,ipLo)][ipCollider].junk();
98  }
99  bool& lgIsRate(long ipHi, long ipLo, long ipCollider)
100  {
101  return m_a[ilev(ipHi,ipLo)][ipCollider].lgIsRate;
102  }
103  // Reserves space for the number of table points for this level and
104  // collider
105  void setpoints(long ipHi, long ipLo, long ipCollider,long npoints)
106  {
107  long offset = m_temps.size();
108  long length = offset+npoints;
109  // testing shows that 1200 is a reasonable initial guess for the size
110  m_temps.resize(max(length,1200));
111  m_collstrs.resize(max(length,1200));
112  m_a[ilev(ipHi,ipLo)][ipCollider].setslice(offset,npoints);
113  }
114  // Returns number of table points
115  long ntemps(long ipHi, long ipLo, long ipCollider)
116  {
117  return m_a[ilev(ipHi,ipLo)][ipCollider].ntemps();
118  }
119  // Returns pointer to temperature ordinates
120  double* temps(long ipHi, long ipLo, long ipCollider)
121  {
122  return &m_temps[m_a[ilev(ipHi,ipLo)][ipCollider].offset()];
123  }
124  // Returns pointer to collision data
125  double* collstrs(long ipHi, long ipLo, long ipCollider)
126  {
127  return &m_collstrs[m_a[ilev(ipHi,ipLo)][ipCollider].offset()];
128  }
129 };
130 
134 void LoadIsotopes ( );
135 
136 
143 double atmdat_2phot_shapefunction( double EbyE2nu, long ipISO, long nelem );
144 
148 void atmdat_readin(void);
149 
155 void atmdat_STOUT_readin( long intNS, const string& chFileName );
156 
162 void atmdat_CHIANTI_readin( long intNS, const string& chFileName );
163 
169 void atmdat_LAMDA_readin( long intNS, const string& chFileName );
170 
171 
182 void atmdat_outer_shell(
183  long int iz,
184  long int in,
185  long int *imax,
186  long int *ig0,
187  long int *ig1);
188 
192 void ChargTranEval( void );
193 
198 double ChargTranSumHeat(void);
199 
200 /*ChargTranPun save charge transfer rate coefficients */
206 void ChargTranPun( FILE* ipPnunit , char* chSave );
207 
209 double CHIANTI_Upsilon(long, long, long, long,double);
210 
216 double atmdat_dielrec_fe(long int ion, double t);
217 
220 void atmdat_H_phot_cs(void);
221 
223 void atmdat_3body(void);
224 
235 double atmdat_HS_caseB(
236  long int iHi, long int iLo, long int iZ, double TempIn,
237  double DenIn,
238  char chCase
239  );
240 
241 // arrays for Hummer & Storey 98 He1 cross sections and energies
244 
245 // arrays for TOPbase Helike cross sections and energies
249 
250 /* these are the vectors that store the original Hummer and Storey case B
251  * line data for H and He - the declaration for the interpolator follows */
252 #define NHSDIM 15
253 #define NLINEHS 300
254 #define HS_NZ 8
255 #define NHCSTE 8
256 #define NUM_HS98_DATA_POINTS 811
257 
258 struct t_atmdat : public module {
259  const char *chName() const
260  {
261  return "atmdat";
262  }
263  void zero();
264  void comment(t_warnings&) {}
279  enum {NCX=2};
280 
283 
290  inline double getIonPot( long int nelem, long int ion )
291  {
292  return EIonPot[nelem][ion];
293  }
294 
301  double CharExcIonOf[NCX][LIMELM][LIMELM+1], //(cm3 s-1)
302  CharExcRecTo[NCX][LIMELM][LIMELM+1], //(cm3 s-1)
303  HCharHeatMax,
304  HCharCoolMax,
305  HCharHeatOn;
306 
307  /* rate coefficient (cm3 s-1) for N+(3P) + H+ -> N(2D) + H+ charge transfer*/
309 
313 
315  double HIonFrac;
316 
318  double HIonFracMax;
319 
322  double HCTAlex;
323 
326  bool lgCTOn;
327 
330  double Density[2][HS_NZ][NHSDIM],
331  ElecTemp[2][HS_NZ][NHSDIM],
334 
336  long int nDensity[2][HS_NZ] , ntemp[2][HS_NZ];
338  long int ncut[2][HS_NZ];
339 
343  bool lgHCaseBOK[2][HS_NZ];
344 
346  long int nsbig;
347 
351 
357 
359  vector<realnum> CaseBWlHeI;
360 
367  const long nDefaultCollLevels;
369  const long nDefaultMolLevels;
370  // Set the constant member variables to the default values.
371 
388 
390  bool lgLamdaOn;
399 
401  bool lgStoutOn;
420  bool lgGbarOn;
421 
426 
433 
436  static const double aulThreshold;
437 
438  /* type and enum for determining what collisional ionization rate coefficient data to use.
439  * Dima: Cloudy original data from Voronov97
440  * Hybrid: Dima version scaled by the ratio of Dere07 to Dima */
441  typedef enum { DIMA, HYBRID } CollIonRC;
443 
445  string chVersion;
446 
451 
454 
457  {
458  //set all sources to blank and false.
459  //Sources will be added from masterlist files in species.cpp
460  for( int nelem=ipHYDROGEN; nelem < LIMELM; ++nelem )
461  {
462  for( int ion=0; ion < nelem+2; ++ion )
463  {
464  strcpy(chdBaseSources[nelem][ion]," ");
465  lgdBaseSourceExists[nelem][ion] = false;
466  }
467  }
468 
470  ipSpecIon.alloc(LIMELM,LIMELM);
471  ipSpecIon = -1;
472  }
473 };
474 
475 extern t_atmdat atmdat;
476 
477 class Funct
478 {
479 public:
480  virtual void operator()( long&, long&, const char*, long&) = 0;
481  virtual ~Funct() = 0;
482 };
483 
484 inline Funct::~Funct() {}
485 
486 typedef Funct* FunctPtr;
487 
488 class FunctLAMDA : public Funct
489 {
490 public:
491  explicit FunctLAMDA(void) { }
492  virtual void operator()( long& ipHi, long& ipLo, const char* chLine, long& i)
493  {
494  DEBUG_ENTRY( "FunctLAMDA()" );
495  bool lgEOL;
496  long index = (long)FFmtRead( chLine, &i, strlen(chLine), &lgEOL );
497  if( index <= 0 )
498  {
499  fprintf( ioQQQ, " PROBLEM with LAMDA readin.\n");
500  cdEXIT( EXIT_FAILURE );
501  }
502  ipHi = (long)FFmtRead( chLine, &i, strlen(chLine), &lgEOL ) - 1;
503  ipLo = (long)FFmtRead( chLine, &i, strlen(chLine), &lgEOL ) - 1;
504  return;
505  }
506 private:
507 };
508 
509 #include "h2_priv.h"
510 
511 class FunctDiatoms : public Funct
512 {
513 public:
514  explicit FunctDiatoms(const diatomics& diatom) : diatom_(diatom) { }
515  virtual void operator()( long& ipHi, long& ipLo, const char* chLine, long& i)
516  {
517  diatom_.GetIndices( ipHi, ipLo, chLine, i );
518  }
519 private:
521 };
522 
523 void ReadCollisionRateTable( CollRateCoeffArray& coll_rate_table, FILE* io, FunctPtr GetIndices, long nMolLevs, long nTemps = -1, long nTrans = -1 );
524 
525 double InterpCollRate( const CollRateCoeffArray& rate_table, const long& ipHi, const long& ipLo, const double& ftemp);
526 
527 
528 /* Form a comment for a transition obtained from an external database.
529  * The comment is the configuration of the lower and upper level */
530 inline string db_comment_tran_levels(const string& clo = "", const string& chi = "")
531 {
532  stringstream Comment;
533  if( clo.length() > 0 && chi.length() > 0 )
534  Comment << clo << " -- " << chi;
535  return Comment.str();
536 }
537 
538 #endif /* ATMDAT_H_ */
double InterpCollRate(const CollRateCoeffArray &rate_table, const long &ipHi, const long &ipLo, const double &ftemp)
Definition: atmdat.cpp:188
virtual void operator()(long &ipHi, long &ipLo, const char *chLine, long &i)
Definition: atmdat.h:515
void comment(t_warnings &)
Definition: atmdat.h:264
bool lgStoutLevelsSet
Definition: atmdat.h:414
Definition: warnings.h:11
void atmdat_CHIANTI_readin(long intNS, const string &chFileName)
Definition: atmdat_chianti.cpp:668
const char * chName() const
Definition: atmdat.h:259
char chLamdaFile[FILENAME_PATH_LENGTH]
Definition: atmdat.h:394
realnum WaveLengthCaseB[8][25][24]
Definition: atmdat.h:356
void ReadCollisionRateTable(CollRateCoeffArray &coll_rate_table, FILE *io, FunctPtr GetIndices, long nMolLevs, long nTemps=-1, long nTrans=-1)
Definition: atmdat.cpp:67
multi_arr< vector< double >, 4 > OP_Helike_Xsectn
Definition: atmdat.cpp:63
void junk()
Definition: atmdat.h:55
multi_arr< double, 3 > collrates
Definition: atmdat.h:18
double HCharHeatMax
Definition: atmdat.h:301
long ntemps(long ipHi, long ipLo, long ipCollider)
Definition: atmdat.h:115
bool lgChiantiLevelsSet
Definition: atmdat.h:387
double EIonPot[LIMELM][LIMELM]
Definition: atmdat.h:282
double HCharHeatOn
Definition: atmdat.h:301
char chStoutFile[FILENAME_PATH_LENGTH]
Definition: atmdat.h:407
#define NHSDIM
Definition: atmdat.h:252
void alloc()
Definition: container_classes.h:1078
const long nDefaultCollLevelsFe
Definition: atmdat.h:365
bool lgChiantiLvl2Hybrid
Definition: atmdat.h:375
vector< double > m_collstrs
Definition: atmdat.h:79
double ScalingParam
Definition: atmdat.h:38
bool lgStoutOn
Definition: atmdat.h:401
double getIonPot(long int nelem, long int ion)
Definition: atmdat.h:290
double CHIANTI_Upsilon(long, long, long, long, double)
Definition: species2.cpp:869
long nStoutMaxLevelsFe
Definition: atmdat.h:409
double ChargTranSumHeat(void)
Definition: atmdat_char_tran.cpp:569
long nLamdaMaxLevels
Definition: atmdat.h:396
double HCharCoolMax
Definition: atmdat.h:301
long int ncut[2][HS_NZ]
Definition: atmdat.h:338
bool lgIsRate
Definition: atmdat.h:72
long m_ntemps
Definition: atmdat.h:47
CollIonRC CIRCData
Definition: atmdat.h:442
Funct * FunctPtr
Definition: atmdat.h:486
bool lgChiantiPrint
Definition: atmdat.h:377
bool lgCollIonOn
Definition: atmdat.h:350
bool lgHCaseBOK[2][HS_NZ]
Definition: atmdat.h:343
FILE * ioQQQ
Definition: cddefines.cpp:7
long int nsbig
Definition: atmdat.h:346
bool lgGbarOn
Definition: atmdat.h:420
Definition: atmdat.h:258
Definition: h2_priv.h:72
double HIonFracMax
Definition: atmdat.h:318
multi_arr< double, 4 > HS_He1_Xsectn
Definition: atmdat.cpp:61
void GetIndices(long &ipHi, long &ipLo, const char *chLine, long &i) const
Definition: mole_h2_coll.cpp:202
const diatomics & diatom_
Definition: atmdat.h:520
FunctDiatoms(const diatomics &diatom)
Definition: atmdat.h:514
long int ntemp[2][HS_NZ]
Definition: atmdat.h:336
Definition: atmdat.h:511
Definition: atmdat.h:24
long intTranType
Definition: atmdat.h:36
#define NLINEHS
Definition: atmdat.h:253
CollIonRC
Definition: atmdat.h:441
double CharExcRecTotal[NCX]
Definition: atmdat.h:311
double CharExcIonTotal[NCX]
Definition: atmdat.h:311
virtual ~Funct()=0
Definition: atmdat.h:484
Definition: atmdat.h:477
bool lgStoutLvl2Hybrid
Definition: atmdat.h:403
virtual void operator()(long &, long &, const char *, long &)=0
bool lgdBaseSourceExists[LIMELM][LIMELM+1]
Definition: atmdat.h:450
multi_arr< long, 2 > ipSpecIon
Definition: atmdat.h:453
vector< double > m_temps
Definition: atmdat.h:79
long offset() const
Definition: atmdat.h:67
long int nDensity[2][HS_NZ]
Definition: atmdat.h:336
void setpoints(long ipHi, long ipLo, long ipCollider, long npoints)
Definition: atmdat.h:105
void setslice(long offset, long ntemps)
Definition: atmdat.h:62
double EnergyDiff
Definition: atmdat.h:37
multi_arr< double, 4 > HS_He1_Energy
Definition: atmdat.cpp:62
bool lgLamdaPrint
Definition: atmdat.h:392
static const double aulThreshold
Definition: atmdat.h:436
bool lgChiantiOn
Definition: atmdat.h:373
char chdBaseSources[LIMELM][LIMELM+1][10]
Definition: atmdat.h:448
double * temps(long ipHi, long ipLo, long ipCollider)
Definition: atmdat.h:120
bool lgCalpgmOn
Definition: atmdat.h:418
static long ilev(long ipHi, long ipLo)
Definition: atmdat.h:80
void atmdat_H_phot_cs(void)
void atmdat_LAMDA_readin(long intNS, const string &chFileName)
Definition: atmdat_lamda.cpp:28
double atmdat_dielrec_fe(long int ion, double t)
Definition: atmdat_dielrec_fe.cpp:8
char chCloudyChiantiFile[FILENAME_PATH_LENGTH]
Definition: atmdat.h:381
const long nDefaultMolLevels
Definition: atmdat.h:369
void atmdat_STOUT_readin(long intNS, const string &chFileName)
Definition: atmdat_chianti.cpp:107
long nSplinePts
Definition: atmdat.h:35
virtual void operator()(long &ipHi, long &ipLo, const char *chLine, long &i)
Definition: atmdat.h:492
const long nDefaultPhotoLevels
Definition: atmdat.h:363
double HCharExcRecTo_N0_2D
Definition: atmdat.h:308
double collstrDefault
Definition: atmdat.h:425
long nStoutMaxLevels
Definition: atmdat.h:412
Definition: atmdat.h:12
float realnum
Definition: cddefines.h:127
#define EXIT_FAILURE
Definition: cddefines.h:175
void zero()
Definition: atmdat.cpp:9
long max(int a, long b)
Definition: cddefines.h:821
#define cdEXIT(FAIL)
Definition: cddefines.h:480
string db_comment_tran_levels(const string &clo="", const string &chi="")
Definition: atmdat.h:530
double Density[2][HS_NZ][NHSDIM]
Definition: atmdat.h:330
double Emiss[2][HS_NZ][NHSDIM][NHSDIM][NLINEHS]
Definition: atmdat.h:330
double atmdat_HS_caseB(long int iHi, long int iLo, long int iZ, double TempIn, double DenIn, char chCase)
Definition: atmdat_HS_caseb.cpp:7
t_atmdat atmdat
Definition: atmdat.cpp:7
Definition: atmdat.h:44
long nChiantiMaxLevels
Definition: atmdat.h:385
Definition: atmdat.h:441
CollSplinesArray()
Definition: atmdat.h:39
void atmdat_outer_shell(long int iz, long int in, long int *imax, long int *ig0, long int *ig1)
Definition: atmdat_outer_shell.cpp:8
string chVersion
Definition: atmdat.h:445
bool lgUTAprint
Definition: atmdat.h:432
bool & lgIsRate(long ipHi, long ipLo, long ipCollider)
Definition: atmdat.h:99
#define HS_NZ
Definition: atmdat.h:254
long m_offset
Definition: atmdat.h:47
const long nDefaultPhotoLevelsFe
Definition: atmdat.h:361
void ChargTranPun(FILE *ipPnunit, char *chSave)
Definition: atmdat_char_tran.cpp:945
bool lgInnerShell_Kisielius
Definition: atmdat.h:430
const int LIMELM
Definition: cddefines.h:318
vector< double > temps
Definition: atmdat.h:16
const long nDefaultCollLevels
Definition: atmdat.h:367
t_atmdat()
Definition: atmdat.h:455
#define DEBUG_ENTRY(funcname)
Definition: cddefines.h:730
void junk(long ipHi, long ipLo, long ipCollider)
Definition: atmdat.h:95
bool lgInnerShellLine_on
Definition: atmdat.h:428
double HIonFrac
Definition: atmdat.h:315
multi_arr< StoutColls, 2 > m_a
Definition: atmdat.h:78
Definition: atmdat.h:441
double * collstrs(long ipHi, long ipLo, long ipCollider)
Definition: atmdat.h:125
const int FILENAME_PATH_LENGTH
Definition: cddefines.h:303
bool lgStoutPrint
Definition: atmdat.h:405
void atmdat_readin(void)
Definition: atmdat_readin.cpp:80
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1325
multi_arr< vector< double >, 4 > OP_Helike_Energy
Definition: atmdat.cpp:64
bool lgCTOn
Definition: atmdat.h:326
vector< realnum > CaseBWlHeI
Definition: atmdat.h:359
multi_arr< long, 4 > OP_Helike_NumPts
Definition: atmdat.cpp:65
Definition: atmdat.h:488
Definition: atmdat.h:76
long ntemps()
Definition: atmdat.h:50
double HCTAlex
Definition: atmdat.h:322
void alloc(long nHi, long, long nCollider)
Definition: atmdat.h:87
bool lgLamdaOn
Definition: atmdat.h:390
void LoadIsotopes()
Definition: isotopes.cpp:9
void ChargTranEval(void)
Definition: atmdat_char_tran.cpp:44
double CharExcIonOf[NCX][LIMELM][LIMELM+1]
Definition: atmdat.h:301
vector< double > SplineSecDer
Definition: atmdat.h:33
long nChiantiMaxLevelsFe
Definition: atmdat.h:383
void atmdat_3body(void)
Definition: atmdat_3body.cpp:52
const int ipHYDROGEN
Definition: cddefines.h:359
vector< double > collspline
Definition: atmdat.h:32
bool lgChiantiExp
Definition: atmdat.h:379
double CharExcRecTo[NCX][LIMELM][LIMELM+1]
Definition: atmdat.h:301
Definition: module.h:26
double atmdat_2phot_shapefunction(double EbyE2nu, long ipISO, long nelem)
Definition: atmdat_2photon.cpp:230
FunctLAMDA(void)
Definition: atmdat.h:491
bool lgLamdaLevelsSet
Definition: atmdat.h:398
double ElecTemp[2][HS_NZ][NHSDIM]
Definition: atmdat.h:330
Definition: atmdat.h:279
double FFmtRead(const char *chCard, long int *ipnt, long int last, bool *lgEOL)
Definition: service.cpp:393