Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
transition.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 TRANSITION_H_
5 #define TRANSITION_H_
6 
7 #include "emission.h"
8 #include "collision.h"
9 #include "quantumstate.h"
10 
14 /* create a dummy emission structure. Non-radiative transitions will point to this */
16 
17 // Proxy class provides 'object' access to struct-of-vectors
18 class TransitionList;
19 class TransitionListImpl;
21 class ExtraInten;
22 
24 {
25 public:
29 private:
32  int m_index;
33 public:
34  explicit TransitionProxy(): m_list(0), m_index(-1) {}
35  explicit TransitionProxy(TransitionListImpl *list, int index) :
36  m_list(list), m_index(index) {}
37  void copy(const TransitionProxy& other) const;
38  qList::iterator Lo() const;
39  qList::iterator Hi() const;
40  void setLo(int ipLo) const;
41  void setHi(int ipHi) const;
42  void AddLine2Stack() const;
44  int &ipEmis() const;
45  string chLabel() const;
46  void setComment( const string &comment ) const;
47  string &getComment() const;
48  bool associated() const
49  {
50  return m_list != NULL && m_index >= 0;
51  }
52  bool isSameAs(const TransitionProxy& other) const
53  {
54  return m_list == other.m_list && m_index == other.m_index;
55  }
56  bool hasEmis() const
57  {
58  return ipEmis() != -1;
59  }
60  void resetEmis() const
61  {
62  Emis().ipTran() = m_index;
63  }
64  bool systemIs(const TransitionList *query) const;
65  const TransitionListImpl& system() const
66  {
67  return *m_list;
68  }
69  void check() const
70  {
71  ASSERT(!hasEmis() || Emis().ipTran() == m_index);
72  }
73  CollisionProxy Coll() const;
74 
76  realnum &WLAng() const;
77 
79  realnum EnergyK() const
80  {
81  return (realnum)T1CM*EnergyWN();
82  }
85  {
86  return (realnum)ERG1CM*EnergyWN();
87  }
89  double EnergyRyd() const
90  {
91  return WAVNRYD*EnergyWN();
92  }
95  {
96  return 1e8f/EnergyWN();
97  }
98 
99 
101  realnum &EnergyWN() const;
102 
107  long &ipCont() const;
108 
109 
113  void Junk() const;
114 
118  void Zero() const;
119 
121  void outline( double nonScatteredFraction, bool lgDoChecks ) const ;
122 
123 
126  void outline_resonance( ) const ;
127  int &ipLo() const;
128  int &ipHi() const;
130  void AddHiState() const;
131  void AddLoState() const;
132  realnum width() const;
133  list_type *list() const
134  {
135  return m_list;
136  }
137 };
138 
140 {
141 public:
145 private:
148  int m_index;
149 public:
150  explicit TransitionConstProxy(): m_list(0), m_index(-1) {}
151  explicit TransitionConstProxy(const TransitionListImpl *list, int index) :
152  m_list(list), m_index(index) {}
153  void copy(const TransitionConstProxy& other) const;
154  qList::iterator Lo() const;
155  qList::iterator Hi() const;
156  void AddLine2Stack() const;
157  EmissionList::reference Emis() const;
158  int ipEmis() const;
159  string getComment() const;
160  bool associated() const
161  {
162  return m_list != NULL && m_index >= 0;
163  }
164  bool hasEmis() const
165  {
166  return ipEmis() != -1;
167  }
168  void check() const
169  {
170  ASSERT(!hasEmis() || Emis().ipTran() == m_index);
171  }
172  CollisionProxy Coll() const;
173 
175  realnum WLAng() const;
176 
178  realnum EnergyK() const
179  {
180  return (realnum)T1CM*EnergyWN();
181  }
184  {
185  return (realnum)ERG1CM*EnergyWN();
186  }
188  double EnergyRyd() const
189  {
190  return WAVNRYD*EnergyWN();
191  }
194  {
195  return 1e8f/EnergyWN();
196  }
197 
198 
200  realnum EnergyWN() const;
201 
206  long ipCont() const;
207 
209  void outline( double nonScatteredFraction, bool lgDoChecks ) const ;
210 
213  void outline_resonance( ) const ;
214  int ipLo() const;
215  int ipHi() const;
216 };
217 
218 
219 // Structure-of-vectors for transition data
221 {
222  vector<int> ipHi, ipLo;
223  vector<long> ipCont;
225  vector<realnum> EnergyWN, WLAng;
226  vector<string> chComment;
227  // DO NOT IMPLEMENT
230 public:
231  friend class TransitionProxy;
232  friend class TransitionConstProxy;
233  string chLabel;
234  qList *states; // List of individual states
236  vector<int> ipEmis;
238  const string &chLabel,
239  qList *states) : chLabel(chLabel), states(states), Emis(this)
240  {}
242  const string &chLabel,
243  qList *states,
244  size_t size) : chLabel(chLabel), states(states), Emis(this)
245  {
246  resize(size);
247  }
248  void resize(size_t newsize);
249  void reserve(size_t newsize);
254  {
255  return TransitionProxy(this,i);
256  }
257  size_t size(void) const
258  {
259  return ipCont.size();
260  }
261  void pop_back(void)
262  {
263  resize(size()-1);
264  }
266  {
267  return iterator(this,0);
268  }
269  const_iterator begin(void) const
270  {
271  return const_iterator(this,0);
272  }
273  iterator end(void)
274  {
275  return iterator(this,size());
276  }
277  const_iterator end(void) const
278  {
279  return const_iterator(this,size());
280  }
281  void push_back(const TransitionProxy &tr)
282  {
283  int newsize=size()+1;
284  resize(newsize);
285  (*this)[newsize-1].copy(tr);
286  }
287  const TransitionProxy back(void)
288  {
289  return *(end()-1);
290  }
291  realnum width() const
292  {
293  return states->width();
294  }
295 };
296 
298 {
299  // Internal vectors all need to be sized consistently (see three
300  // functions below)
301  shared_ptr<TransitionListImpl> p_impl;
302 public:
305  explicit TransitionList(const string &chLabel, qList *states, size_t size=0)
306  : p_impl(new TransitionListImpl(chLabel, states, size))
307  {}
308  void resize(size_t newsize)
309  {
310  p_impl->resize(newsize);
311  }
312  void reserve(size_t newsize)
313  {
314  p_impl->reserve(newsize);
315  }
317  {
318  return (*p_impl)[i];
319  }
320  size_t size(void) const
321  {
322  return p_impl->size();
323  }
324  void pop_back(void)
325  {
326  p_impl->pop_back();
327  }
329  {
330  return p_impl->begin();
331  }
332  iterator end(void)
333  {
334  return p_impl->end();
335  }
336  void push_back(const TransitionProxy &tr)
337  {
338  p_impl->push_back(tr);
339  }
340  const TransitionProxy back(void)
341  {
342  return p_impl->back();
343  }
344  string &chLabel()
345  {
346  return p_impl->chLabel;
347  }
349  {
350  return p_impl->states;
351  }
353  {
354  return p_impl->Emis;
355  }
356  vector<int> &ipEmis()
357  {
358  return p_impl->ipEmis;
359  }
360  bool isSame (const TransitionListImpl *other) const
361  {
362  return p_impl.get() == other;
363  }
364  realnum width() const
365  {
366  return p_impl->width();
367  }
368 };
369 
370 inline bool TransitionProxy::systemIs(const TransitionList *query) const
371 {
372  return query->isSame(m_list);
373 }
374 
375 // Must include all internal vector elements in these three functions
376 inline void TransitionListImpl::resize(size_t newsize)
377 {
378  ipLo.resize(newsize);
379  ipHi.resize(newsize);
380  ipCont.resize(newsize);
381  Coll.resize(newsize);
382  EnergyWN.resize(newsize);
383  WLAng.resize(newsize);
384  ipEmis.resize(newsize,-1);
385  chComment.resize(newsize);
386 }
387 inline void TransitionListImpl::reserve(size_t newsize)
388 {
389  ipLo.reserve(newsize);
390  ipHi.reserve(newsize);
391  ipCont.reserve(newsize);
392  Coll.reserve(newsize);
393  EnergyWN.reserve(newsize);
394  WLAng.reserve(newsize);
395  ipEmis.reserve(newsize);
396 }
397 inline void TransitionProxy::copy(const TransitionProxy& other) const
398 {
399  m_list->ipLo[m_index] = other.m_list->ipLo[other.m_index];
400  m_list->ipHi[m_index] = other.m_list->ipHi[other.m_index];
401  m_list->ipCont[m_index] = other.m_list->ipCont[other.m_index];
402  m_list->Coll[m_index].copy(other.m_list->Coll[other.m_index]);
403  m_list->EnergyWN[m_index] = other.m_list->EnergyWN[other.m_index];
404  m_list->WLAng[m_index] = other.m_list->WLAng[other.m_index];
405  if (other.m_list->ipEmis[other.m_index] == -1)
406  {
407  m_list->ipEmis[m_index] = -1;
408  }
409  else
410  {
411  ASSERT (m_list->ipEmis[m_index] == -1);
412  AddLine2Stack();
413  m_list->Emis[m_list->ipEmis[m_index]].copy(
414  other.m_list->Emis[other.m_list->ipEmis[other.m_index]]);
415  }
416 }
417 // End of region needing consistency with TransitionListImpl class
418 
419 // Handle accessors need to see the structure of the TransitionList
421 {
422  return m_list->states->begin()+m_list->ipLo[m_index];
423 }
425 {
426  return m_list->states->begin()+m_list->ipHi[m_index];
427 }
428 inline void TransitionProxy::setLo(int ipLo) const
429 {
430  m_list->ipLo[m_index] = ipLo;
431 }
432 inline void TransitionProxy::setHi(int ipHi) const
433 {
434  m_list->ipHi[m_index] = ipHi;
435 }
437 {
438  int ipEmis = m_list->ipEmis[m_index];
439  if (ipEmis == -1)
440  return DummyEmis;
441  else
442  return m_list->Emis[ipEmis];
443 }
444 inline int& TransitionProxy::ipEmis() const
445 {
446  return m_list->ipEmis[m_index];
447 }
449 {
450  return m_list->ipEmis[m_index];
451 }
453 {
454  return m_list->Coll[m_index];
455 }
458 {
459  return m_list->WLAng[m_index];
460 }
462 {
463  return m_list->WLAng[m_index];
464 }
467 {
468  return m_list->EnergyWN[m_index];
469 }
471 {
472  return m_list->EnergyWN[m_index];
473 }
478 inline long &TransitionProxy::ipCont() const
479 {
480  return m_list->ipCont[m_index];
481 }
482 inline long TransitionConstProxy::ipCont() const
483 {
484  return m_list->ipCont[m_index];
485 }
486 inline int &TransitionProxy::ipLo() const
487 {
488  return m_list->ipLo[m_index];
489 }
490 inline int TransitionConstProxy::ipLo() const
491 {
492  return m_list->ipLo[m_index];
493 }
494 inline int &TransitionProxy::ipHi() const
495 {
496  return m_list->ipHi[m_index];
497 }
498 inline int TransitionConstProxy::ipHi() const
499 {
500  return m_list->ipHi[m_index];
501 }
502 
504 {
506  t.check();
507  return t;
508 }
510 {
512  t.check();
513  return t;
514 }
515 
516 inline void TransitionProxy::setComment( const string &comment ) const
517 {
518  m_list->chComment[m_index] = comment;
519 }
520 inline string &TransitionProxy::getComment() const
521 {
522  return m_list->chComment[m_index];
523 }
524 inline string TransitionConstProxy::getComment() const
525 {
526  return m_list->chComment[m_index];
527 }
528 
530 {
531  return m_list->width();
532 }
533 
546 void PutLine(const TransitionProxy &t, const char *chComment);
547 
553 void PutLine(const TransitionProxy &t, const char *chComment, const char *chLabel);
554 
555 void PutLine(const TransitionProxy& t, const char *chComment, const char *chLabel, const ExtraInten& extra);
556 
560 double TexcLine(const TransitionProxy &t);
561 
565 void DumpLine(const TransitionProxy &t);
566 
570 double emit_frac(const TransitionProxy &t);
571 
572 double GetLineRec(
573  /* this is the number of the emission line in the stack of lines, on the C scale */
574  long int ip,
575  /* the multiplet wavelength */
576  long int lWl);
577 
581 string chIonLbl(const TransitionProxy &t);
582 string chIonLbl(const long& nelem, const long& IonStg);
583 
588 inline string chLineLbl(const TransitionProxy &t)
589 {
590  return t.chLabel();
591 }
592 
597 void PutCS(double cs,
598  const TransitionProxy & t);
599 
606 
610 double OccupationNumberLine(const TransitionProxy &t);
611 
616 {
617 public:
618  double v;
619  ExtraInten() : v(0.0) {}
620  explicit ExtraInten( double extra ) : v(extra) {}
621 };
622 
627 void LineConvRate2CS( const TransitionProxy & t , realnum rate );
628 
633 inline bool lgTauGood( const TransitionProxy& t )
634 {
635  bool lgOverrunOK = true;
636  if ( lgOverrunOK )
637  {
638  return true;
639  }
640  else
641  {
642  // first iteration only use inward optical depths so scale good
643  return ( iteration == 1 ||
644  // maser - optical depths also ok (but bizarre)
645  t.Emis().TauIn() <= 0. ||
646  // TauIn < TauTot means outward optical depth is positive, so OK
647  t.Emis().TauIn() < t.Emis().TauTot() );
648  }
649 }
650 
654 void MakeCS(const TransitionProxy & t );
655 
656 extern map<std::string,std::vector<TransitionProxy> > blends;
657 typedef map<std::string,std::vector<TransitionProxy> >::iterator blend_iterator;
658 
659 inline double phots( const TransitionProxy &t )
660 {
661  return t.Emis().xIntensity() / t.EnergyErg();
662 }
663 
664 #endif // _TRANSITION_H_
EmissionList Emis
Definition: transition.h:235
int ipEmis() const
Definition: transition.h:448
const TransitionListImpl list_type
Definition: transition.h:142
TransitionConstProxy::iterator const_iterator
Definition: transition.h:251
realnum width() const
Definition: quantumstate.h:128
void DumpLine(const TransitionProxy &t)
Definition: transition.cpp:138
realnum EnergyWN() const
Definition: transition.h:470
void push_back(const TransitionProxy &tr)
Definition: transition.h:281
bool hasEmis() const
Definition: transition.h:164
size_t size(void) const
Definition: transition.h:320
realnum EnergyErg() const
Definition: transition.h:84
double OccupationNumberLine(const TransitionProxy &t)
Definition: transition.cpp:177
bool isSame(const TransitionListImpl *other) const
Definition: transition.h:360
string chLineLbl(const TransitionProxy &t)
Definition: transition.h:588
map< std::string, std::vector< TransitionProxy > >::iterator blend_iterator
Definition: transition.h:657
string chIonLbl(const TransitionProxy &t)
Definition: transition.cpp:233
void pop_back(void)
Definition: transition.h:261
EmissionList * m_list
Definition: emission.h:27
const_iterator end(void) const
Definition: transition.h:277
vector< string > chComment
Definition: transition.h:226
friend class TransitionProxy
Definition: transition.h:231
string & chLabel()
Definition: transition.h:344
vector< int > & ipEmis()
Definition: transition.h:356
Definition: collision.h:143
void Zero() const
Definition: transition.cpp:470
string GenerateTransitionConfiguration(const TransitionProxy &t)
Definition: transition.cpp:311
realnum EnergyAng() const
Definition: transition.h:193
double TexcLine(const TransitionProxy &t)
Definition: transition.cpp:207
realnum & TauTot() const
Definition: emission.h:492
void reserve(size_t newsize)
Definition: transition.h:312
bool isSameAs(const TransitionProxy &other) const
Definition: transition.h:52
const TransitionProxy back(void)
Definition: transition.h:287
TransitionListImpl & operator=(const TransitionListImpl &)
TransitionListImpl(const TransitionListImpl &)
void PutLine(const TransitionProxy &t, const char *chComment)
Definition: transition.cpp:433
iterator begin(void)
Definition: transition.h:328
TransitionProxy::iterator iterator
Definition: transition.h:250
Definition: transition.h:220
TransitionListImpl * m_tlist
Definition: emission.h:332
reference operator[](size_t i)
Definition: transition.h:253
const EmissionList * m_list
Definition: emission.h:182
realnum EnergyK() const
Definition: transition.h:79
void check() const
Definition: transition.h:168
double phots(const TransitionProxy &t)
Definition: transition.h:659
realnum WLAng() const
Definition: transition.h:461
CollisionProxy Coll() const
ExtraInten(double extra)
Definition: transition.h:620
vector< realnum > WLAng
Definition: transition.h:225
iterator end(void)
Definition: transition.h:273
TransitionProxy reference
Definition: transition.h:252
TransitionProxy Tran() const
Definition: transition.h:503
int ipTran() const
Definition: emission.h:567
bool associated() const
Definition: transition.h:48
int & ipTran() const
Definition: emission.h:562
TransitionConstProxy::iterator const_iterator
Definition: transition.h:304
qList::iterator Lo() const
map< std::string, std::vector< TransitionProxy > > blends
Definition: transition.cpp:36
qList *& states()
Definition: transition.h:348
long int iteration
Definition: cddefines.cpp:15
realnum EnergyAng() const
Definition: transition.h:94
TransitionProxy operator[](size_t i)
Definition: transition.h:316
void resize(size_t newsize)
Definition: transition.h:308
realnum & EnergyWN() const
Definition: transition.h:466
Definition: quantumstate.h:35
void MakeCS(const TransitionProxy &t)
Definition: transition.cpp:578
int & ipHi() const
Definition: transition.h:494
TransitionProxy()
Definition: transition.h:34
Definition: emission.h:19
const_iterator begin(void) const
Definition: transition.h:269
vector< int > ipHi
Definition: transition.h:222
realnum EnergyK() const
Definition: transition.h:178
void push_back(const TransitionProxy &tr)
Definition: transition.h:336
int ipLo() const
Definition: transition.h:490
TransitionList(const string &chLabel, qList *states, size_t size=0)
Definition: transition.h:305
double & xIntensity() const
Definition: emission.h:542
EmissionList::reference Emis() const
Definition: transition.h:436
Definition: proxy_iterator.h:58
void check() const
Definition: transition.h:69
int & ipEmis() const
Definition: transition.h:444
void copy(const TransitionConstProxy &other) const
string & getComment() const
Definition: transition.h:520
void resize(size_t i)
Definition: collision.h:170
long & ipCont() const
Definition: transition.h:478
void reserve(size_t i)
Definition: collision.h:179
float realnum
Definition: cddefines.h:127
void resetEmis() const
Definition: transition.h:60
size_t size(void) const
Definition: transition.h:257
int m_index
Definition: transition.h:148
realnum width() const
Definition: transition.h:364
qList::iterator Hi() const
Definition: transition.h:424
double emit_frac(const TransitionProxy &t)
Definition: transition.cpp:88
void setLo(int ipLo) const
Definition: transition.h:428
realnum EnergyErg() const
Definition: transition.h:183
shared_ptr< TransitionListImpl > p_impl
Definition: transition.h:301
int & ipLo() const
Definition: transition.h:486
void copy(const TransitionProxy &other) const
Definition: transition.h:397
long ipCont() const
Definition: transition.h:482
#define NULL
Definition: cddefines.h:115
vector< realnum > EnergyWN
Definition: transition.h:225
void pop_back(void)
Definition: transition.h:324
TransitionListImpl list_type
Definition: transition.h:26
void reserve(size_t newsize)
Definition: transition.h:387
TransitionProxy::iterator iterator
Definition: transition.h:303
double v
Definition: transition.h:618
const TransitionProxy back(void)
Definition: transition.h:340
ProxyIterator< TransitionConstProxy, TransitionConstProxy > const_iterator
Definition: transition.h:144
string chLabel() const
Definition: transition.cpp:274
EmissionProxy DummyEmis
Definition: taulines.cpp:122
ExtraInten()
Definition: transition.h:619
iterator end(void)
Definition: transition.h:332
double GetLineRec(long int ip, long int lWl)
Definition: transition.cpp:107
void setHi(int ipHi) const
Definition: transition.h:432
#define ASSERT(exp)
Definition: cddefines.h:637
qList::iterator Lo() const
Definition: transition.h:420
vector< int > ipLo
Definition: transition.h:222
qList::iterator Hi() const
void AddHiState() const
Definition: transition.cpp:653
void resize(size_t newsize)
Definition: transition.h:376
double EnergyRyd() const
Definition: transition.h:188
const list_type * m_list
Definition: transition.h:147
TransitionListImpl(const string &chLabel, qList *states)
Definition: transition.h:237
const TransitionListImpl & system() const
Definition: transition.h:65
realnum width() const
Definition: transition.h:529
CollisionProxy Coll() const
Definition: transition.h:452
void outline(double nonScatteredFraction, bool lgDoChecks) const
Definition: transition.cpp:46
CollisionList Coll
Definition: transition.h:224
string getComment() const
Definition: transition.h:524
TransitionConstProxy()
Definition: transition.h:150
iterator begin()
Definition: quantumstate.h:378
TransitionProxy(TransitionListImpl *list, int index)
Definition: transition.h:35
void AddLine2Stack() const
Definition: transition.h:297
vector< int > ipEmis
Definition: transition.h:236
list_type * list() const
Definition: transition.h:133
iterator begin(void)
Definition: transition.h:265
void Junk() const
Definition: transition.cpp:442
double EnergyRyd() const
Definition: transition.h:89
int ipHi() const
Definition: transition.h:498
Definition: transition.h:139
ProxyIterator< TransitionConstProxy, TransitionConstProxy > const_iterator
Definition: transition.h:28
realnum width() const
Definition: transition.h:291
TransitionConstProxy(const TransitionListImpl *list, int index)
Definition: transition.h:151
void PutCS(double cs, const TransitionProxy &t)
Definition: transition.cpp:298
Definition: transition.h:23
TransitionConstProxy Tran() const
Definition: transition.h:509
void outline(double nonScatteredFraction, bool lgDoChecks) const
void setComment(const string &comment) const
Definition: transition.h:516
int m_index
Definition: transition.h:32
qList * states
Definition: transition.h:234
Definition: transition.h:615
TransitionListImpl(const string &chLabel, qList *states, size_t size)
Definition: transition.h:241
vector< long > ipCont
Definition: transition.h:223
bool lgTauGood(const TransitionProxy &t)
Definition: transition.h:633
ProxyIterator< TransitionProxy, TransitionConstProxy > iterator
Definition: transition.h:27
bool hasEmis() const
Definition: transition.h:56
Definition: emission.h:330
bool systemIs(const TransitionList *query) const
Definition: transition.h:370
void outline_resonance() const
bool associated() const
Definition: transition.h:160
void AddLoState() const
Definition: transition.cpp:642
ProxyIterator< TransitionConstProxy, TransitionConstProxy > iterator
Definition: transition.h:143
realnum & WLAng() const
Definition: transition.h:457
void LineConvRate2CS(const TransitionProxy &t, realnum rate)
Definition: transition.cpp:486
realnum & TauIn() const
Definition: emission.h:472
EmissionList & Emis()
Definition: transition.h:352
EmissionList::reference Emis() const
string chLabel
Definition: transition.h:233
void AddLine2Stack() const
Definition: transition.cpp:630
Definition: collision.h:84
void outline_resonance() const
Definition: transition.cpp:39
list_type * m_list
Definition: transition.h:31