Cloudy
Spectral Synthesis Code for Astrophysics
Loading...
Searching...
No Matches
lines.h
Go to the documentation of this file.
1/* This file is part of Cloudy and is copyright (C)1978-2025 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
12class cdstream;
13
14class LineID
15{
16 string p_chLabel;
17 // the constructors will make sure that this is always a wavelength in vacuum
19 // the remaining parameters are optional, used for line disambiguation
23public:
25 p_indLo(-1), p_indHi(-1), p_ELo(-1_r) {}
26 LineID(string lbl, t_wavl wv) :
27 p_chLabel(lbl), p_wave(wv), p_indLo(-1), p_indHi(-1), p_ELo(-1_r) {}
28 LineID(string lbl, t_wavl wv, realnum e) :
29 p_chLabel(lbl), p_wave(wv), p_indLo(-1), p_indHi(-1), p_ELo(e) {}
30 LineID(string lbl, t_wavl wv, int ilo, int ihi) :
31 p_chLabel(lbl), p_wave(wv), p_indLo(ilo), p_indHi(ihi), p_ELo(-1_r) {}
32 LineID(string lbl, t_wavl wv, int ilo, int ihi, realnum e) :
33 p_chLabel(lbl), p_wave(wv), p_indLo(ilo), p_indHi(ihi), p_ELo(e) {}
34 string chLabel() const { return p_chLabel; }
35 realnum wavlVac() const { return p_wave.wavlVac(); }
36 t_wavl twav() const { return p_wave; }
37 string str() const { return "\"" + p_chLabel + "\" " + p_wave.sprt_wl(); }
38 int indLo() const { return p_indLo; }
39 int indHi() const { return p_indHi; }
40 realnum ELo() const { return p_ELo; }
41};
42
44void lines(void);
45
47void lines_general(void);
48
50void lines_hydro(void);
51
53void LineStackCreate(void);
54
56void lines_grains(void);
57
60void lines_setup(void);
61
63void lines_continuum(void);
64
66void lines_molecules(void);
67
69void lines_helium(void);
70
72void lines_lv1_li_ne(void);
73
75void lines_lv1_k_zn(void);
76
79long int StuffComment( const char * chComment );
80
83int lines_table();
84
87
88class LinSv;
89
90void cdEmis(
91 const LinSv* line,
92 /* the vol emissivity of this line in last computed zone */
93 double *emiss ,
94 // intrinsic or emergent
95 bool lgEmergent );
96
97static const int NHOLDCOMMENTS = 100;
98
99extern const t_wavl Hbeta_WavLen;
100
103struct t_LineSave : public module {
104 const char *chName() const
105 {
106 return "LineSave";
107 }
108 void zero();
111
114 long int nsum;
115
117 long int nComment;
118
122 long int ipass;
123
126
129
131 long int ipNormLine;
132
135
138 long int sig_figs;
139 static const long sig_figs_max = 6;
140
144
147
148 long findline(const LineID& line, bool lgQuiet=false);
149
152 vector<LinSv> lines;
153 vector<realnum> m_wavelength;
154 vector<size_t> SortWL;
155 void clear()
156 {
157 lines.clear();
158 m_wavelength.clear();
159 }
160 size_t size() const;
161 void resize(long nlines);
162
163 void setSortWL();
164 void init(long index, char chSumTyp, const char *chComment, const char *label,
165 bool lgAdd, t_wavl wavelength, const TransitionProxy& tr);
166 realnum wavlVac(long index) const
167 {
168 return m_wavelength[index];
169 }
170 t_wavl twav(long index) const
171 {
172 return t_vac(wavlVac(index));
173 }
174
175 void resetWavlVac( long index, realnum wl )
176 {
177 m_wavelength[index] = wl;
178 }
179
181};
182extern t_LineSave LineSave;
183
187class LinSv {
192 double m_SumLine[4];
194 double m_emslin[2];
196 vector<long> m_component;
201 // private accessors
202 void chALabSet(const char *that);
203public:
204
207 {
208 return m_tr;
209 }
210
212 char chSumTyp() const
213 {
214 return m_chSumTyp;
215 }
216
218 const char *chALab() const
219 {
220 return m_chALab;
221 }
222
223 const char *chCLab() const
224 {
225 return m_chCLab;
226 }
227
233 bool isBlend() const
234 {
235 return !m_component.empty();
236 }
237 char LineType() const
238 {
239 return m_chSumTyp;
240 }
241 void addComponentID(long id);
242 void makeBlend(const char* species, const t_wavl& wavelength, const realnum width);
243 void setBlendWavl();
244
246 {
247 long id = m_component[ind];
248 return LineSave.lines[id].getTransition();
249 }
250 double SumLine(int i) const
251 {
252 if (!isBlend())
253 {
254 return m_SumLine[i];
255 }
256 else
257 {
258 double sum = 0.;
259 for (size_t j=0; j<m_component.size(); ++j)
260 {
261 long id = m_component[j];
262 sum += LineSave.lines[id].SumLine(i);
263 }
264 return sum;
265 }
266 }
267 void SumLineAdd(int i, double val)
268 {
269 if (!isBlend())
270 m_SumLine[i] += val;
271 }
272 void SumLineAccum(double cumulative_factor)
273 {
274 if (!isBlend())
275 {
276 for( long nEmType=0; nEmType<2; ++nEmType )
277 {
278 m_SumLine[nEmType+2] += cumulative_factor*m_SumLine[nEmType];
279 }
280 }
281 }
283 {
284 if (!isBlend())
285 m_SumLine[0] = m_SumLine[1] = 0.0;
286 }
288 {
289 if (!isBlend())
290 m_SumLine[2] = m_SumLine[3] = 0.0;
291 }
293 {
294 if (!isBlend() && m_chSumTyp == 't')
295 m_SumLine[1] = m_SumLine[0];
296 }
297
299 double emslin(int i) const
300 {
301 if (!isBlend())
302 {
303 return m_emslin[i];
304 }
305 else
306 {
307 double sum = 0.;
308 for (size_t j=0; j<m_component.size(); ++j)
309 {
310 long id = m_component[j];
311 sum += LineSave.lines[id].emslin(i);
312 }
313 return sum;
314 }
315 }
317 {
318 if (!isBlend())
319 {
320 m_emslin[0] = 0.0;
321 m_emslin[1] = 0.0;
322 }
323 }
324 void emslinSet(int i, double v)
325 {
326 if (!isBlend())
327 m_emslin[i] = v;
328 }
330 {
331 if (!isBlend() && m_chSumTyp == 't')
332 m_emslin[1] = m_emslin[0];
333 }
334
336 void prt_blend() const;
337
340 {
341 return LineSave.wavlVac(m_index);
342 }
343 t_wavl twav() const
344 {
345 return LineSave.twav(m_index);
346 }
347
349 string chComment() const;
350 void init(long index, char chSumTyp, const char *chComment, const char *label,
351 const TransitionProxy& tr);
352
353 void prt(FILE *fp) const;
354 string label() const;
355 string biglabel() const;
366 bool isCat(const char *s) const;
367 bool isSeparator() const
368 {
369 return m_type == SEPARATOR;
370 }
371 bool isUnit() const
372 {
373 return m_type == UNIT;
374 }
375 bool isUnitD() const
376 {
377 return m_type == UNITD;
378 }
379 bool isInward() const
380 {
381 return m_type == INWARD;
382 }
383 bool isInwardTotal() const
384 {
385 return m_type == INWARDTOTAL;
386 }
387 bool isInwardContinuum() const
388 {
389 return m_type == INWARDCONTINUUM;
390 }
391 bool isCollisional() const
392 {
393 return m_type == COLLISIONAL;
394 }
395 bool isPump() const
396 {
397 return m_type == PUMP;
398 }
399 bool isHeat() const
400 {
401 return m_type == HEAT;
402 }
403 bool isCaseA() const
404 {
405 return m_type == CASEA;
406 }
407 bool isCaseB() const
408 {
409 return m_type == CASEB;
410 }
411 bool isNInu() const
412 {
413 return m_type == NINU;
414 }
415 bool isNFnu() const
416 {
417 return m_type == NFNU;
418 }
419 bool isPhoPlus() const
420 {
421 return m_type == PHOPLUS;
422 }
423 bool isPcon() const
424 {
425 return m_type == PCON;
426 }
427 bool isQH() const
428 {
429 return m_type == QH;
430 }
431
432#ifndef NDEBUG
433 void checkEmergent( const long ipEmType ) const
434 {
435 /* Pick instantaneous or cumulative */
436 int ipIntr, ipEmer;
437 if( ipEmType == 1 )
438 {
439 ipIntr = 0;
440 ipEmer = 1;
441 }
442 else if( ipEmType == 3 )
443 {
444 ipIntr = 2;
445 ipEmer = 3;
446 }
447 else
448 return;
449
450 if( !isBlend() )
451 {
452 if( m_chSumTyp != 't' || LineSave.wavlVac(m_index) <= 0_r )
453 ASSERT( m_SumLine[ipEmer] == 0. );
454 else
455 ASSERT( m_SumLine[ipIntr] > m_SumLine[ipEmer] ||
456 fp_equal( m_SumLine[ipIntr], m_SumLine[ipEmer], 10 ) );
457 }
458 }
459#else
460 void checkEmergent( const long ) const
461 {
462 (void)0;
463 }
464#endif
465};
466
467inline size_t t_LineSave::size() const
468{
469 ASSERT( lines.size() == m_wavelength.size() );
470 return lines.size();
471}
472
473inline void t_LineSave::resize(long nlines)
474{
475 lines.resize(nlines);
476 m_wavelength.resize(nlines);
477}
478
479long findComponent(const LineID& line, bool lgQuiet);
480
481#endif /* LINES_H_ */
const int NRECCOEFCNO
Definition atmdat_adfa.h:10
#define ASSERT(exp)
Definition cddefines.h:650
const int NCHLAB
Definition cddefines.h:327
t_wavl t_vac(realnum w)
Definition cddefines.h:1361
float realnum
Definition cddefines.h:128
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition cddefines.h:877
Definition lines.h:187
bool isPump() const
Definition lines.h:395
void makeBlend(const char *species, const t_wavl &wavelength, const realnum width)
Definition lines.cpp:311
bool isHeat() const
Definition lines.h:399
bool isNFnu() const
Definition lines.h:415
bool isCaseB() const
Definition lines.h:407
double SumLine(int i) const
Definition lines.h:250
void emslinSet(int i, double v)
Definition lines.h:324
void init(long index, char chSumTyp, const char *chComment, const char *label, const TransitionProxy &tr)
Initializes a LinSv object with the provided parameters and sets its type based on the label.
Definition lines.cpp:133
enum LinSv::@015007117223277146246246257065170373066256225252 m_type
const char * chALab() const
Definition lines.h:218
t_wavl twav() const
Definition lines.h:343
void emslinThin()
Definition lines.h:329
bool isCollisional() const
Definition lines.h:391
const TransitionProxy getComponent(long ind)
Definition lines.h:245
void SumLineZero()
Definition lines.h:282
void chALabSet(const char *that)
Definition lines.cpp:103
string biglabel() const
Definition lines.cpp:67
void SumLineThin()
Definition lines.h:292
char m_chSumTyp
Definition lines.h:189
bool isCat(const char *s) const
Checks if the last four characters of the line label match the given string.
Definition lines.cpp:93
double m_emslin[2]
Definition lines.h:194
TransitionProxy getTransition()
Definition lines.h:206
const char * chCLab() const
Definition lines.h:223
double m_SumLine[4]
Definition lines.h:192
vector< long > m_component
Definition lines.h:196
void SumLineAccum(double cumulative_factor)
Definition lines.h:272
long m_index
Definition lines.h:188
bool isNInu() const
Definition lines.h:411
string chComment() const
Definition lines.cpp:397
string m_chComment
Definition lines.h:195
void emslinZero()
Definition lines.h:316
void checkEmergent(const long ipEmType) const
Definition lines.h:433
char m_chCLab[NCHLAB]
Definition lines.h:191
char m_chALab[NCHLAB]
Definition lines.h:190
bool isCaseA() const
Definition lines.h:403
@ NINU
Definition lines.h:199
@ INWARDTOTAL
Definition lines.h:198
@ INWARD
Definition lines.h:198
@ QH
Definition lines.h:199
@ CASEA
Definition lines.h:199
@ COLLISIONAL
Definition lines.h:199
@ PUMP
Definition lines.h:199
@ UNITD
Definition lines.h:198
@ PCON
Definition lines.h:199
@ UNIT
Definition lines.h:198
@ DEFAULT
Definition lines.h:198
@ PHOPLUS
Definition lines.h:199
@ INWARDCONTINUUM
Definition lines.h:198
@ CASEB
Definition lines.h:199
@ SEPARATOR
Definition lines.h:198
@ HEAT
Definition lines.h:199
@ NFNU
Definition lines.h:199
bool isUnit() const
Definition lines.h:371
bool isPhoPlus() const
Definition lines.h:419
bool isQH() const
Definition lines.h:427
char chSumTyp() const
Definition lines.h:212
realnum wavlVac() const
Definition lines.h:339
void SumLineAdd(int i, double val)
Definition lines.h:267
bool isInward() const
Definition lines.h:379
TransitionProxy m_tr
Definition lines.h:197
bool isBlend() const
Definition lines.h:233
bool isUnitD() const
Definition lines.h:375
string label() const
Definition lines.cpp:58
bool isPcon() const
Definition lines.h:423
void setBlendWavl()
Definition lines.cpp:373
double emslin(int i) const
Definition lines.h:299
bool isSeparator() const
Definition lines.h:367
void addComponentID(long id)
Definition lines.cpp:252
void prt_blend() const
Definition lines.cpp:359
bool isInwardTotal() const
Definition lines.h:383
void SumLineZeroAccum()
Definition lines.h:287
bool isInwardContinuum() const
Definition lines.h:387
char LineType() const
Definition lines.h:237
Definition lines.h:15
LineID(string lbl, t_wavl wv)
Definition lines.h:26
int p_indHi
Definition lines.h:21
realnum wavlVac() const
Definition lines.h:35
t_wavl p_wave
Definition lines.h:18
t_wavl twav() const
Definition lines.h:36
string str() const
Definition lines.h:37
realnum p_ELo
Definition lines.h:22
int p_indLo
Definition lines.h:20
int indHi() const
Definition lines.h:39
string chLabel() const
Definition lines.h:34
realnum ELo() const
Definition lines.h:40
LineID(string lbl, t_wavl wv, int ilo, int ihi, realnum e)
Definition lines.h:32
LineID(string lbl, t_wavl wv, int ilo, int ihi)
Definition lines.h:30
LineID(string lbl, t_wavl wv, realnum e)
Definition lines.h:28
int indLo() const
Definition lines.h:38
string p_chLabel
Definition lines.h:16
LineID()
Definition lines.h:24
Definition transition.h:24
module()
Definition module.h:29
Definition species.h:12
Definition warnings.h:11
Definition cddefines.h:1312
const t_wavl Hbeta_WavLen
Definition lines.cpp:12
t_LineSave LineSave
Definition lines.cpp:14
void lines(void)
Definition prt_lines.cpp:56
void LineStackCreate(void)
Definition lines_service.cpp:28
long int StuffComment(const char *chComment)
Definition prt_final.cpp:1944
void clear_lines_table()
Definition parse_table.cpp:1738
void lines_setup(void)
Definition atmdat_lines_setup.cpp:11
static const int NHOLDCOMMENTS
Definition lines.h:97
void lines_molecules(void)
Definition prt_lines_molecules.cpp:17
void lines_helium(void)
Definition prt_lines_helium.cpp:53
void lines_lv1_li_ne(void)
int lines_table()
Definition parse_table.cpp:1698
void cdEmis(const LinSv *line, double *emiss, bool lgEmergent)
Definition lines.cpp:761
void lines_lv1_k_zn(void)
void lines_general(void)
Definition prt_lines_general.cpp:20
void lines_continuum(void)
Definition prt_lines_continuum.cpp:22
t_LineSave LineSave
Definition lines.cpp:14
void lines_hydro(void)
Definition prt_lines_hydro.cpp:53
long findComponent(const LineID &line, bool lgQuiet)
Definition lines.cpp:270
void lines_grains(void)
Definition prt_lines_grains.cpp:12
static vector< realnum > wavelength
Definition monitor_results.cpp:79
t_prt prt
Definition prt.cpp:14
Definition lines.h:103
string chHoldComments[NHOLDCOMMENTS]
Definition lines.h:125
void setSortWL()
Definition lines.cpp:422
long int sig_figs
Definition lines.h:138
vector< LinSv > lines
Definition lines.h:152
long int ipNormLine
Definition lines.h:131
long int nComment
Definition lines.h:117
void comment(t_warnings &)
Definition lines.h:109
const char * chName() const
Definition lines.h:104
bool lgIsoContSubSignif
Definition lines.h:180
long findline(const LineID &line, bool lgQuiet=false)
Definition lines.cpp:433
void zero()
Definition lines.cpp:17
realnum RecCoefCNO[4][NRECCOEFCNO]
Definition lines.h:146
void clear()
Definition lines.h:155
t_wavl twav(long index) const
Definition lines.h:170
int wl_length
Definition lines.h:143
long int nsum
Definition lines.h:114
vector< size_t > SortWL
Definition lines.h:154
static const long sig_figs_max
Definition lines.h:139
vector< realnum > m_wavelength
Definition lines.h:153
void init(long index, char chSumTyp, const char *chComment, const char *label, bool lgAdd, t_wavl wavelength, const TransitionProxy &tr)
Definition lines.cpp:33
void resize(long nlines)
Definition lines.h:473
LineID NormLine
Definition lines.h:128
size_t size() const
Definition lines.h:467
double ScaleNormLine
Definition lines.h:134
realnum wavlVac(long index) const
Definition lines.h:166
long int ipass
Definition lines.h:122
void resetWavlVac(long index, realnum wl)
Definition lines.h:175