cloudy  trunk
 All Data Structures 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-2022 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 };
20 
22 void lines(void);
23 
25 void lines_general(void);
26 
28 void lines_hydro(void);
29 
31 void LineStackCreate(void);
32 
34 void lines_grains(void);
35 
38 void lines_setup(void);
39 
41 void lines_continuum(void);
42 
44 void lines_molecules(void);
45 
47 void lines_helium(void);
48 
50 void lines_lv1_li_ne(void);
51 
53 void lines_lv1_k_zn(void);
54 
57 long int StuffComment( const char * chComment );
58 
61 int lines_table();
62 
63 class LinSv;
64 
65 void cdEmis(
66  const LinSv* line,
67  /* the vol emissivity of this line in last computed zone */
68  double *emiss ,
69  // intrinsic or emergent
70  bool lgEmergent );
71 
72 static const int NHOLDCOMMENTS = 100;
73 
76 struct t_LineSave : public module {
77  const char *chName() const
78  {
79  return "LineSave";
80  }
81  void zero();
82  void comment(t_warnings&) {}
87  long int nsum;
88 
90  long int nComment;
91 
96  long int ipass;
97 
100 
102  long int ipNormWavL;
103 
106 
109  long int sig_figs;
110  static const long sig_figs_max = 6;
111 
115 
118 
121 
123  bool lgNormSet;
124 
127 
128  long findline(const char *chLabel, realnum wavelength);
129 
132  vector<LinSv> lines;
133  vector<realnum> m_wavelength;
134  vector<size_t> SortWL;
135  void clear()
136  {
137  lines.clear();
138  m_wavelength.clear();
139  }
140  void resize(long nlines);
141 
142  void setSortWL();
143  void init(long index, char chSumTyp, const char *chComment, const char *label,
144  bool lgAdd, realnum wavelength, const TransitionProxy& tr);
145  realnum wavelength(long index)
146  {
147  return m_wavelength[index];
148  }
149 
151 };
152 extern t_LineSave LineSave;
153 
157 class LinSv {
158  long m_index;
162  double m_SumLine[4];
164  double m_emslin[2];
165  string m_chComment;
166  vector<long> m_component;
170  m_type;
171  // private accessors
172  void chALabSet(const char *that);
173 public:
174 
177  {
178  return m_tr;
179  }
180 
182  char chSumTyp() const
183  {
184  return m_chSumTyp;
185  }
186 
188  const char *chALab() const
189  {
190  return m_chALab;
191  }
193  const char *chCLab() const
194  {
195  return m_chCLab;
196  }
203  bool isBlend() const
204  {
205  return !m_component.empty();
206  }
207  char LineType() const
208  {
209  return m_chSumTyp;
210  }
211  void addComponent(const char* species,const double wavelength);
212  void addComponentID(long id);
213  void makeBlend(const char* species, const double wavelength,
214  const double width);
216  {
217  long id = m_component[ind];
218  if (id > 0)
219  return LineSave.lines[id].getTransition();
220  else
221  return TransitionProxy();
222  }
223  double SumLine(int i) const
224  {
225  if (!isBlend())
226  {
227  return m_SumLine[i];
228  }
229  else
230  {
231  double sum = 0.;
232  for (size_t j=0; j<m_component.size(); ++j)
233  {
234  long id = m_component[j];
235  /* Null emergent emission of non-transferred lines */
236  if( id > 0 && i == 1 && LineSave.lines[id].LineType() != 't' )
237  {
238  sum = 0.;
239  break;
240  }
241  if (id > 0)
242  sum += LineSave.lines[id].SumLine(i);
243  }
244  return sum;
245  }
246  }
247  void SumLineAdd(int i, double val)
248  {
249  if (!isBlend())
250  m_SumLine[i] += val;
251  }
252  void SumLineAccum(double cumulative_factor)
253  {
254  if (!isBlend())
255  {
256  for( long nEmType=0; nEmType<2; ++nEmType )
257  {
258  m_SumLine[nEmType+2] += cumulative_factor*m_SumLine[nEmType];
259  }
260  }
261  }
262  void SumLineZero()
263  {
264  if (!isBlend())
265  m_SumLine[0] = m_SumLine[1] = 0.0;
266  }
268  {
269  if (!isBlend())
270  m_SumLine[2] = m_SumLine[3] = 0.0;
271  }
272  void SumLineThin()
273  {
274  if (!isBlend() && m_chSumTyp == 't')
275  m_SumLine[1] = m_SumLine[0];
276  }
277 
279  double emslin(int i) const
280  {
281  if (!isBlend())
282  {
283  return m_emslin[i];
284  }
285  else
286  {
287  double sum = 0.;
288  for (size_t j=0; j<m_component.size(); ++j)
289  {
290  long id = m_component[j];
291  /* Null emergent emission of non-transferred lines */
292  if( id > 0 && i == 1 && LineSave.lines[id].LineType() != 't' )
293  {
294  sum = 0.;
295  break;
296  }
297  if (id > 0)
298  sum += LineSave.lines[id].emslin(i);
299  }
300  return sum;
301  }
302  }
303  void emslinZero()
304  {
305  if (!isBlend())
306  {
307  m_emslin[0] = 0.0;
308  m_emslin[1] = 0.0;
309  }
310  }
311  void emslinSet(int i, double v)
312  {
313  if (!isBlend())
314  m_emslin[i] = v;
315  }
316  void emslinThin()
317  {
318  if (!isBlend() && m_chSumTyp == 't')
319  m_emslin[1] = m_emslin[0];
320  }
321 
324  {
325  return LineSave.wavelength(m_index);
326  }
327 
329  string chComment() const;
330  void init(long index, char chSumTyp, const char *chComment, const char *label,
331  const TransitionProxy& tr);
332 
333  void prt(FILE *fp) const;
334  string label() const;
335  string biglabel() const;
336  bool isCat(const char *s) const;
337  bool isSeparator() const
338  {
339  return m_type == SEPARATOR;
340  }
341  bool isUnit() const
342  {
343  return m_type == UNIT;
344  }
345  bool isUnitD() const
346  {
347  return m_type == UNITD;
348  }
349  bool isInward() const
350  {
351  return m_type == INWARD;
352  }
353  bool isInwardTotal() const
354  {
355  return m_type == INWARDTOTAL;
356  }
357  bool isInwardContinuum() const
358  {
359  return m_type == INWARDCONTINUUM;
360  }
361  bool isCollisional() const
362  {
363  return m_type == COLLISIONAL;
364  }
365  bool isPump() const
366  {
367  return m_type == PUMP;
368  }
369  bool isHeat() const
370  {
371  return m_type == HEAT;
372  }
373  bool isCaseA() const
374  {
375  return m_type == CASEA;
376  }
377  bool isCaseB() const
378  {
379  return m_type == CASEB;
380  }
381  bool isNInu() const
382  {
383  return m_type == NINU;
384  }
385  bool isNFnu() const
386  {
387  return m_type == NFNU;
388  }
389  bool isPhoPlus() const
390  {
391  return m_type == PHOPLUS;
392  }
393  bool isPcon() const
394  {
395  return m_type == PCON;
396  }
397  bool isQH() const
398  {
399  return m_type == QH;
400  }
401 #ifndef NDEBUG
402  void checkEmergent( const long ipEmType ) const
403  {
404  /* Pick instantaneous or cumulative */
405  int ipIntr, ipEmer;
406  if( ipEmType == 1 )
407  {
408  ipIntr = 0;
409  ipEmer = 1;
410  }
411  else if( ipEmType == 3 )
412  {
413  ipIntr = 2;
414  ipEmer = 3;
415  }
416  else
417  return;
418 
419  if( !isBlend() )
420  {
421  if( m_chSumTyp != 't' || LineSave.wavelength(m_index) <= realnum(0.) )
422  ASSERT( m_SumLine[ipEmer] == 0. );
423  else
424  ASSERT( m_SumLine[ipIntr] > m_SumLine[ipEmer] ||
425  fp_equal( m_SumLine[ipIntr], m_SumLine[ipEmer], 10 ) );
426  }
427  }
428 #else
429  void checkEmergent( const long ) const
430  {
431  (void)0;
432  }
433 #endif
434 };
435 
436 inline void t_LineSave::init(long index, char chSumTyp, const char *chComment, const char *label,
437  bool lgAdd, realnum wavelength, const TransitionProxy& tr)
438 {
439  if (!lgAdd)
440  {
441  // number of lines OK, set parameters for first pass
442  // negative wavelength means it is just label, possibly not correct
443  wavelength = fabs(wavelength);
444  }
445 
446  m_wavelength[index] = wavelength;
447  lines[index].init(index,chSumTyp,chComment,label,tr);
448 
449 }
450 inline void t_LineSave::resize(long nlines)
451 {
452  lines.resize(nlines);
453  m_wavelength.resize(nlines);
454 }
455 
456 #endif /* LINES_H_ */
vector< long > m_component
Definition: lines.h:166
vector< realnum > m_wavelength
Definition: lines.h:133
void SumLineAdd(int i, double val)
Definition: lines.h:247
void setSortWL()
Definition: lines.cpp:283
vector< size_t > SortWL
Definition: lines.h:134
long m_index
Definition: lines.h:158
void lines_lv1_li_ne(void)
realnum wave
Definition: lines.h:18
double m_emslin[2]
Definition: lines.h:164
bool isPump() const
Definition: lines.h:365
long findline(const char *chLabel, realnum wavelength)
Definition: lines.cpp:294
bool isBlend() const
Definition: lines.h:203
void chALabSet(const char *that)
Definition: lines.cpp:75
void clear()
Definition: lines.h:135
double emslin(int i) const
Definition: lines.h:279
const int NRECCOEFCNO
Definition: atmdat_adfa.h:7
bool isInwardTotal() const
Definition: lines.h:353
void lines_setup(void)
string label() const
Definition: lines.cpp:41
t_LineSave LineSave
Definition: lines.cpp:10
bool lgNormSet
Definition: lines.h:123
void prt(FILE *fp) const
Definition: lines.cpp:35
Definition: lines.h:14
void SumLineZero()
Definition: lines.h:262
void SumLineThin()
Definition: lines.h:272
string chLabel
Definition: lines.h:17
void lines_continuum(void)
string chComment() const
Definition: lines.cpp:258
bool isNFnu() const
Definition: lines.h:385
int wl_length
Definition: lines.h:114
vector< LinSv > lines
Definition: lines.h:132
void SumLineAccum(double cumulative_factor)
Definition: lines.h:252
bool lgIsoContSubSignif
Definition: lines.h:150
void lines(void)
Definition: prt_lines.cpp:35
void emslinSet(int i, double v)
Definition: lines.h:311
bool fp_equal(sys_float x, sys_float y, int n=3)
Definition: cddefines.h:854
bool isCollisional() const
Definition: lines.h:361
void SumLineZeroAccum()
Definition: lines.h:267
char m_chCLab[NCHLAB]
Definition: lines.h:161
bool isCaseA() const
Definition: lines.h:373
const TransitionProxy getComponent(long ind)
Definition: lines.h:215
TransitionProxy m_tr
Definition: lines.h:167
void lines_hydro(void)
const char * chName() const
Definition: lines.h:77
void lines_helium(void)
void emslinThin()
Definition: lines.h:316
float realnum
Definition: cddefines.h:124
void lines_lv1_k_zn(void)
void LineStackCreate(void)
const int INPUT_LINE_LENGTH
Definition: cddefines.h:301
bool isInward() const
Definition: lines.h:349
realnum WavLNorm
Definition: lines.h:105
void comment(t_warnings &)
Definition: lines.h:82
bool isQH() const
Definition: lines.h:397
long int sig_figs
Definition: lines.h:109
void checkEmergent(const long ipEmType) const
Definition: lines.h:402
void lines_general(void)
char chNormLab[NCHLAB]
Definition: lines.h:120
bool isCaseB() const
Definition: lines.h:377
TransitionProxy getTransition()
Definition: lines.h:176
void init(long index, char chSumTyp, const char *chComment, const char *label, const TransitionProxy &tr)
Definition: lines.cpp:90
#define ASSERT(exp)
Definition: cddefines.h:613
void lines_molecules(void)
void addComponentID(long id)
Definition: lines.cpp:178
bool isCat(const char *s) const
Definition: lines.cpp:69
enum LinSv::@8 m_type
long int nComment
Definition: lines.h:90
void cdEmis(const char *chLabel, realnum wavelength, double *emiss, bool lgEmergent)
Definition: cddrive.cpp:552
void resize(long nlines)
Definition: lines.h:450
long int ipNormWavL
Definition: lines.h:102
char m_chALab[NCHLAB]
Definition: lines.h:160
bool isInwardContinuum() const
Definition: lines.h:357
string biglabel() const
Definition: lines.cpp:53
realnum RecCoefCNO[4][NRECCOEFCNO]
Definition: lines.h:126
const char * chALab() const
Definition: lines.h:188
void addComponent(const char *species, const double wavelength)
Definition: lines.cpp:194
char chSumTyp() const
Definition: lines.h:182
static vector< realnum > wavelength
char LineType() const
Definition: lines.h:207
string m_chComment
Definition: lines.h:165
static const int NHOLDCOMMENTS
Definition: lines.h:72
realnum wavelength() const
Definition: lines.h:323
const int NCHLAB
Definition: cddefines.h:304
char m_chSumTyp
Definition: lines.h:159
realnum wavelength(long index)
Definition: lines.h:145
const char * chCLab() const
Definition: lines.h:193
bool isNInu() const
Definition: lines.h:381
bool isPhoPlus() const
Definition: lines.h:389
void emslinZero()
Definition: lines.h:303
bool isSeparator() const
Definition: lines.h:337
long int nsum
Definition: lines.h:87
static const long sig_figs_max
Definition: lines.h:110
bool isHeat() const
Definition: lines.h:369
void init(long index, char chSumTyp, const char *chComment, const char *label, bool lgAdd, realnum wavelength, const TransitionProxy &tr)
Definition: lines.h:436
char chHoldComments[NHOLDCOMMENTS][INPUT_LINE_LENGTH]
Definition: lines.h:99
double SumLine(int i) const
Definition: lines.h:223
bool isUnitD() const
Definition: lines.h:345
void zero()
Definition: lines.cpp:13
void makeBlend(const char *species, const double wavelength, const double width)
Definition: lines.cpp:210
Definition: module.h:26
Definition: lines.h:157
int lines_table()
long int ipass
Definition: lines.h:96
bool isPcon() const
Definition: lines.h:393
double ScaleNormLine
Definition: lines.h:117
bool isUnit() const
Definition: lines.h:341
void lines_grains(void)
double m_SumLine[4]
Definition: lines.h:162
long int StuffComment(const char *chComment)
Definition: prt_final.cpp:1938