Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lines.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 LINES_H_
5 #define LINES_H_
6 
7 #include <cstdio>
8 #include "module.h"
9 #include "transition.h"
10 #include "atmdat_adfa.h" // For NRECCOEFCNO
11 
12 class cdstream;
13 
14 class LineID
15 {
16 public:
17  string chLabel;
19  // the remaining parameters are optional
20  int indLo;
21  int indHi;
23  LineID() : wave(-1_r), indLo(-1), indHi(-1), ELo(-1_r) {}
24  LineID(string lbl, realnum wv) : chLabel(lbl), wave(wv), indLo(-1), indHi(-1), ELo(-1_r) {}
25  LineID(string lbl, realnum wv, realnum e) : chLabel(lbl), wave(wv), indLo(-1), indHi(-1), ELo(e) {}
26  LineID(string lbl, realnum wv, int ilo, int ihi) : chLabel(lbl), wave(wv), indLo(ilo), indHi(ihi), ELo(-1_r) {}
27 };
28 
30 void lines(void);
31 
33 void lines_general(void);
34 
36 void lines_hydro(void);
37 
39 void LineStackCreate(void);
40 
42 void lines_grains(void);
43 
46 void lines_setup(void);
47 
49 void lines_continuum(void);
50 
52 void lines_molecules(void);
53 
55 void lines_helium(void);
56 
58 void lines_lv1_li_ne(void);
59 
61 void lines_lv1_k_zn(void);
62 
65 long int StuffComment( const char * chComment );
66 
69 int lines_table();
70 
71 class LinSv;
72 
73 void cdEmis(
74  const LinSv* line,
75  /* the vol emissivity of this line in last computed zone */
76  double *emiss ,
77  // intrinsic or emergent
78  bool lgEmergent );
79 
80 static const int NHOLDCOMMENTS = 100;
81 
82 extern const realnum Hbeta_WavLen;
83 
86 struct t_LineSave : public module {
87  const char *chName() const
88  {
89  return "LineSave";
90  }
91  void zero();
92  void comment(t_warnings&) {}
97  long int nsum;
98 
100  long int nComment;
101 
106  long int ipass;
107 
110 
112  long int ipNormWavL;
113 
116 
119  long int sig_figs;
120  static const long sig_figs_max = 6;
121 
125 
128 
131 
133  bool lgNormSet;
134 
137 
138  long findline(const LineID& line);
139 
142  vector<LinSv> lines;
143  vector<realnum> m_wavelength;
144  vector<size_t> SortWL;
145  void clear()
146  {
147  lines.clear();
148  m_wavelength.clear();
149  }
150  void resize(long nlines);
151 
152  void setSortWL();
153  void init(long index, char chSumTyp, const char *chComment, const char *label,
154  bool lgAdd, realnum wavelength, const TransitionProxy& tr);
155  realnum wavelength(long index)
156  {
157  return m_wavelength[index];
158  }
159 
160  void resetWavelength( long index, realnum wl )
161  {
162  m_wavelength[index] = wl;
163  }
164 
166 };
167 extern t_LineSave LineSave;
168 
172 class LinSv {
173  long m_index;
177  double m_SumLine[4];
179  double m_emslin[2];
180  string m_chComment;
181  vector<long> m_component;
185  m_type;
186  // private accessors
187  void chALabSet(const char *that);
188 public:
189 
192  {
193  return m_tr;
194  }
195 
197  char chSumTyp() const
198  {
199  return m_chSumTyp;
200  }
201 
203  const char *chALab() const
204  {
205  return m_chALab;
206  }
208  const char *chCLab() const
209  {
210  return m_chCLab;
211  }
218  bool isBlend() const
219  {
220  return !m_component.empty();
221  }
222  char LineType() const
223  {
224  return m_chSumTyp;
225  }
226  void addComponent(const string& species,const double wavelength);
227  void addComponent(const LineID& line);
228  void addComponentID(long id);
229  void makeBlend(const char* species, const double wavelength,
230  const double width);
231  void setBlendWavl();
232 
234  {
235  long id = m_component[ind];
236  return LineSave.lines[id].getTransition();
237  }
238  double SumLine(int i) const
239  {
240  if (!isBlend())
241  {
242  return m_SumLine[i];
243  }
244  else
245  {
246  double sum = 0.;
247  for (size_t j=0; j<m_component.size(); ++j)
248  {
249  long id = m_component[j];
250  sum += LineSave.lines[id].SumLine(i);
251  }
252  return sum;
253  }
254  }
255  void SumLineAdd(int i, double val)
256  {
257  if (!isBlend())
258  m_SumLine[i] += val;
259  }
260  void SumLineAccum(double cumulative_factor)
261  {
262  if (!isBlend())
263  {
264  for( long nEmType=0; nEmType<2; ++nEmType )
265  {
266  m_SumLine[nEmType+2] += cumulative_factor*m_SumLine[nEmType];
267  }
268  }
269  }
270  void SumLineZero()
271  {
272  if (!isBlend())
273  m_SumLine[0] = m_SumLine[1] = 0.0;
274  }
276  {
277  if (!isBlend())
278  m_SumLine[2] = m_SumLine[3] = 0.0;
279  }
280  void SumLineThin()
281  {
282  if (!isBlend() && m_chSumTyp == 't')
283  m_SumLine[1] = m_SumLine[0];
284  }
285 
287  double emslin(int i) const
288  {
289  if (!isBlend())
290  {
291  return m_emslin[i];
292  }
293  else
294  {
295  double sum = 0.;
296  for (size_t j=0; j<m_component.size(); ++j)
297  {
298  long id = m_component[j];
299  sum += LineSave.lines[id].emslin(i);
300  }
301  return sum;
302  }
303  }
304  void emslinZero()
305  {
306  if (!isBlend())
307  {
308  m_emslin[0] = 0.0;
309  m_emslin[1] = 0.0;
310  }
311  }
312  void emslinSet(int i, double v)
313  {
314  if (!isBlend())
315  m_emslin[i] = v;
316  }
317  void emslinThin()
318  {
319  if (!isBlend() && m_chSumTyp == 't')
320  m_emslin[1] = m_emslin[0];
321  }
322 
325  {
326  return LineSave.wavelength(m_index);
327  }
328 
330  string chComment() const;
331  void init(long index, char chSumTyp, const char *chComment, const char *label,
332  const TransitionProxy& tr);
333 
334  void prt(FILE *fp) const;
335  string label() const;
336  string biglabel() const;
337  bool isCat(const char *s) const;
338  bool isSeparator() const
339  {
340  return m_type == SEPARATOR;
341  }
342  bool isUnit() const
343  {
344  return m_type == UNIT;
345  }
346  bool isUnitD() const
347  {
348  return m_type == UNITD;
349  }
350  bool isInward() const
351  {
352  return m_type == INWARD;
353  }
354  bool isInwardTotal() const
355  {
356  return m_type == INWARDTOTAL;
357  }
358  bool isInwardContinuum() const
359  {
360  return m_type == INWARDCONTINUUM;
361  }
362  bool isCollisional() const
363  {
364  return m_type == COLLISIONAL;
365  }
366  bool isPump() const
367  {
368  return m_type == PUMP;
369  }
370  bool isHeat() const
371  {
372  return m_type == HEAT;
373  }
374  bool isCaseA() const
375  {
376  return m_type == CASEA;
377  }
378  bool isCaseB() const
379  {
380  return m_type == CASEB;
381  }
382  bool isNInu() const
383  {
384  return m_type == NINU;
385  }
386  bool isNFnu() const
387  {
388  return m_type == NFNU;
389  }
390  bool isPhoPlus() const
391  {
392  return m_type == PHOPLUS;
393  }
394  bool isPcon() const
395  {
396  return m_type == PCON;
397  }
398  bool isQH() const
399  {
400  return m_type == QH;
401  }
402 
403 #ifndef NDEBUG
404  void checkEmergent( const long ipEmType ) const
405  {
406  /* Pick instantaneous or cumulative */
407  int ipIntr, ipEmer;
408  if( ipEmType == 1 )
409  {
410  ipIntr = 0;
411  ipEmer = 1;
412  }
413  else if( ipEmType == 3 )
414  {
415  ipIntr = 2;
416  ipEmer = 3;
417  }
418  else
419  return;
420 
421  if( !isBlend() )
422  {
423  if( m_chSumTyp != 't' || LineSave.wavelength(m_index) <= realnum(0.) )
424  ASSERT( m_SumLine[ipEmer] == 0. );
425  else
426  ASSERT( m_SumLine[ipIntr] > m_SumLine[ipEmer] ||
427  fp_equal( m_SumLine[ipIntr], m_SumLine[ipEmer], 10 ) );
428  }
429  }
430 #else
431  void checkEmergent( const long ) const
432  {
433  (void)0;
434  }
435 #endif
436 };
437 
438 inline void t_LineSave::init(long index, char chSumTyp, const char *chComment, const char *label,
439  bool lgAdd, realnum wavelength, const TransitionProxy& tr)
440 {
441  if (!lgAdd)
442  {
443  // number of lines OK, set parameters for first pass
444  // negative wavelength means it is just label, possibly not correct
445  wavelength = fabs(wavelength);
446  }
447 
448  m_wavelength[index] = wavelength;
449  lines[index].init(index,chSumTyp,chComment,label,tr);
450 }
451 inline void t_LineSave::resize(long nlines)
452 {
453  lines.resize(nlines);
454  m_wavelength.resize(nlines);
455 }
456 
457 #endif /* LINES_H_ */
vector< long > m_component
Definition: lines.h:181
vector< realnum > m_wavelength
Definition: lines.h:143
void SumLineAdd(int i, double val)
Definition: lines.h:255
void setBlendWavl()
Definition: lines.cpp:286
void setSortWL()
Definition: lines.cpp:335
Definition: warnings.h:11
vector< size_t > SortWL
Definition: lines.h:144
long m_index
Definition: lines.h:173
void lines_lv1_li_ne(void)
Definition: lines.h:184
realnum wave
Definition: lines.h:18
double m_emslin[2]
Definition: lines.h:179
int indHi
Definition: lines.h:21
LineID(string lbl, realnum wv, int ilo, int ihi)
Definition: lines.h:26
bool isPump() const
Definition: lines.h:366
bool isBlend() const
Definition: lines.h:218
void chALabSet(const char *that)
Definition: lines.cpp:84
void clear()
Definition: lines.h:145
Definition: lines.h:184
double emslin(int i) const
Definition: lines.h:287
const int NRECCOEFCNO
Definition: atmdat_adfa.h:10
bool isInwardTotal() const
Definition: lines.h:354
string label() const
Definition: lines.cpp:45
bool lgNormSet
Definition: lines.h:133
void prt(FILE *fp) const
Definition: lines.cpp:39
Definition: lines.h:14
void SumLineZero()
Definition: lines.h:270
void SumLineThin()
Definition: lines.h:280
string chLabel
Definition: lines.h:17
void lines_continuum(void)
Definition: prt_lines_continuum.cpp:22
string chComment() const
Definition: lines.cpp:310
bool isNFnu() const
Definition: lines.h:386
int wl_length
Definition: lines.h:124
vector< LinSv > lines
Definition: lines.h:142
Definition: lines.h:183
void SumLineAccum(double cumulative_factor)
Definition: lines.h:260
Definition: lines.h:184
Definition: lines.h:183
bool lgIsoContSubSignif
Definition: lines.h:165
void lines(void)
Definition: prt_lines.cpp:56
void emslinSet(int i, double v)
Definition: lines.h:312
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:864
bool isCollisional() const
Definition: lines.h:362
void SumLineZeroAccum()
Definition: lines.h:275
char m_chCLab[NCHLAB]
Definition: lines.h:176
bool isCaseA() const
Definition: lines.h:374
const TransitionProxy getComponent(long ind)
Definition: lines.h:233
void addComponent(const string &species, const double wavelength)
Definition: lines.cpp:232
TransitionProxy m_tr
Definition: lines.h:182
Definition: lines.h:183
Definition: lines.h:184
realnum ELo
Definition: lines.h:22
void lines_hydro(void)
Definition: prt_lines_hydro.cpp:46
LineID(string lbl, realnum wv)
Definition: lines.h:24
const char * chName() const
Definition: lines.h:87
void lines_helium(void)
Definition: prt_lines_helium.cpp:53
void emslinThin()
Definition: lines.h:317
float realnum
Definition: cddefines.h:127
void cdEmis(const LinSv *line, double *emiss, bool lgEmergent)
Definition: lines.cpp:659
void lines_lv1_k_zn(void)
void LineStackCreate(void)
Definition: lines_service.cpp:30
string chHoldComments[NHOLDCOMMENTS]
Definition: lines.h:109
bool isInward() const
Definition: lines.h:350
realnum WavLNorm
Definition: lines.h:115
void comment(t_warnings &)
Definition: lines.h:92
LineID()
Definition: lines.h:23
bool isQH() const
Definition: lines.h:398
long int sig_figs
Definition: lines.h:119
void checkEmergent(const long ipEmType) const
Definition: lines.h:404
Definition: lines.h:184
void lines_general(void)
Definition: prt_lines_general.cpp:20
char chNormLab[NCHLAB]
Definition: lines.h:130
bool isCaseB() const
Definition: lines.h:378
TransitionProxy getTransition()
Definition: lines.h:191
Definition: lines.h:183
void init(long index, char chSumTyp, const char *chComment, const char *label, const TransitionProxy &tr)
Definition: lines.cpp:99
Definition: lines.h:184
Definition: lines.h:86
#define ASSERT(exp)
Definition: cddefines.h:637
void lines_molecules(void)
Definition: prt_lines_molecules.cpp:17
void addComponentID(long id)
Definition: lines.cpp:187
bool isCat(const char *s) const
Definition: lines.cpp:73
long int nComment
Definition: lines.h:100
void resize(long nlines)
Definition: lines.h:451
Definition: lines.h:184
long int ipNormWavL
Definition: lines.h:112
char m_chALab[NCHLAB]
Definition: lines.h:175
bool isInwardContinuum() const
Definition: lines.h:358
string biglabel() const
Definition: lines.cpp:57
realnum RecCoefCNO[4][NRECCOEFCNO]
Definition: lines.h:136
const char * chALab() const
Definition: lines.h:203
char chSumTyp() const
Definition: lines.h:197
Definition: lines.h:183
void resetWavelength(long index, realnum wl)
Definition: lines.h:160
static vector< realnum > wavelength
Definition: monitor_results.cpp:79
char LineType() const
Definition: lines.h:222
string m_chComment
Definition: lines.h:180
int indLo
Definition: lines.h:20
static const int NHOLDCOMMENTS
Definition: lines.h:80
realnum wavelength() const
Definition: lines.h:324
const int NCHLAB
Definition: cddefines.h:314
char m_chSumTyp
Definition: lines.h:174
Definition: lines.h:184
realnum wavelength(long index)
Definition: lines.h:155
const char * chCLab() const
Definition: lines.h:208
bool isNInu() const
Definition: lines.h:382
bool isPhoPlus() const
Definition: lines.h:390
void emslinZero()
Definition: lines.h:304
Definition: lines.h:184
LineID(string lbl, realnum wv, realnum e)
Definition: lines.h:25
const realnum Hbeta_WavLen
Definition: lines.cpp:12
Definition: transition.h:23
enum LinSv::@7 m_type
t_LineSave LineSave
Definition: lines.cpp:14
bool isSeparator() const
Definition: lines.h:338
long int nsum
Definition: lines.h:97
static const long sig_figs_max
Definition: lines.h:120
bool isHeat() const
Definition: lines.h:370
void lines_setup(void)
Definition: atmdat_lines_setup.cpp:11
void init(long index, char chSumTyp, const char *chComment, const char *label, bool lgAdd, realnum wavelength, const TransitionProxy &tr)
Definition: lines.h:438
double SumLine(int i) const
Definition: lines.h:238
bool isUnitD() const
Definition: lines.h:346
long findline(const LineID &line)
Definition: lines.cpp:346
void zero()
Definition: lines.cpp:17
Definition: species.h:11
void makeBlend(const char *species, const double wavelength, const double width)
Definition: lines.cpp:238
Definition: module.h:26
Definition: lines.h:184
Definition: lines.h:172
int lines_table()
Definition: parse_table.cpp:1676
long int ipass
Definition: lines.h:106
bool isPcon() const
Definition: lines.h:394
Definition: lines.h:183
Definition: lines.h:183
double ScaleNormLine
Definition: lines.h:127
bool isUnit() const
Definition: lines.h:342
void lines_grains(void)
Definition: prt_lines_grains.cpp:12
double m_SumLine[4]
Definition: lines.h:177
long int StuffComment(const char *chComment)
Definition: prt_final.cpp:1945