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