Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
quantumstate.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 QUANTUMSTATE_H_
5 #define QUANTUMSTATE_H_
6 
7 #include "energy.h"
8 #include "vectorize.h"
9 #include "proxy_iterator.h"
10 
12 
14 {
15  string m_chConfig;
16 public:
17  string& chConfig()
18  {
19  return m_chConfig;
20  }
21  const string& chConfig() const
22  {
23  return m_chConfig;
24  }
25 };
26 
27 // Quantum state properties as structure of lists -- packing
28 // like physical properties in vector storage is more cache efficient
29 // than a list-of-structures layout.
30 class qStateProxy;
31 class qStateConstProxy;
32 void Junk(qStateProxy);
33 void Zero(qStateProxy);
34 
35 class qList
36 {
37  string m_chLabel;
38  vector<quantumStateLabels> m_labels;
41  vector<Energy> m_energy;
42  vector<realnum> m_g;
43  vector<long> m_j;
44  vector<long> m_J;
45  vector<int> m_IonStg;
46  vector<int> m_nelem;
47  vector<long> m_l;
48  vector<double> m_lifetime;
49  vector<long> m_n;
50  vector<double> m_ColDen;
51  vector<double> m_Pop;
52  vector<double> m_DepartCoef;
53  vector<double> m_NCrit;
54  vector<long> m_S;
55  vector<long> m_v;
56  vector<enum level_status> m_status;
58  friend class qStateProxy;
59  friend class qStateConstProxy;
60 public:
65  explicit qList()
66  {
67  init("",0);
68  m_width = 0.f;
69  }
70  explicit qList(const char *chLabel, size_t i)
71  {
72  init(chLabel,i);
73  m_width = 0.f;
74  }
75  iterator begin();
76  const_iterator begin() const;
77  iterator end();
78  const_iterator end() const;
79  reference operator[](int i);
80  const_reference operator[](int i) const;
81  // Must resize *all* the list members
82 private:
83  void resize(size_t i)
84  {
85  size_t old_size = size();
86  m_labels.resize(i);
87  m_ConBoltz.resize(i);
88  m_Boltzmann.resize(i);
89  m_energy.resize(i);
90  m_g.resize(i);
91  m_IonStg.resize(i);
92  m_j.resize(i);
93  m_J.resize(i);
94  m_lifetime.resize(i);
95  m_l.resize(i);
96  m_n.resize(i);
97  m_nelem.resize(i);
98  m_ColDen.resize(i);
99  m_Pop.resize(i);
100  m_DepartCoef.resize(i);
101  m_NCrit.resize(i);
102  m_S.resize(i);
103  m_v.resize(i);
104  m_status.resize(i);
105  for (size_t n=old_size; n<i; ++n)
106  {
107  reset(n);
108  }
109  }
110 public:
111  void init(const char* label, size_t i)
112  {
113  m_chLabel = label;
114  resize(i);
115  }
116  void addone()
117  {
118  resize(size()+1);
119  }
120  void reset(int n);
121  // The size of any of the lists will do, as they should all be
122  // the same. No point really in asserting this, as the assert
123  // will be at least as fragile as the original resize.
124  size_t size() const
125  {
126  return m_labels.size();
127  }
128  realnum width() const
129  {
130  return m_width;
131  }
133  {
134  m_width = width;
135  }
136  string chLabel() const
137  {
138  return m_chLabel;
139  }
140  void chLabel_set(const char *s)
141  {
142  m_chLabel = s;
143  }
144  double* ConBoltz()
145  {
146  return get_ptr(m_ConBoltz);
147  }
148  const double* ConBoltz() const
149  {
150  return get_ptr(m_ConBoltz);
151  }
152  double* Boltzmann()
153  {
154  return get_ptr(m_Boltzmann);
155  }
156  const double* Boltzmann() const
157  {
158  return get_ptr(m_Boltzmann);
159  }
160 };
161 
162 // Quantum state proxy object. This is used to give access to
163 // structure-of-lists class qList in an 'object-like' manner, e.g.
164 //
165 // qs = List[element]; qs.IonStg() = ???; qs.S() = ???; update(qs);
166 //
167 // The member functions of the proxy class must be the same as the
168 // lists which are included in the qList class.
169 class qStateConstProxy;
171 {
172 public:
173  typedef qList list_type;
175 private:
177  friend class qStateConstProxy;
179  int m_index;
180 public:
181  explicit qStateProxy(list_type* list, int index) :
182  m_list(list), m_index(index) {}
183  explicit qStateProxy(void) : m_list(NULL), m_index(0) {}
184  // Proxy functions for members of qList below
185  bool associated() const
186  {
187  return m_list != NULL;
188  }
189  string chLabel() const;
190  string& chConfig() const
191  {
192  return m_list->m_labels[m_index].chConfig();
193  }
195  Energy &energy() const
196  {
197  return m_list->m_energy[m_index];
198  }
200  realnum &g() const
201  {
202  return m_list->m_g[m_index];
203  }
205  double &Pop() const
206  {
207  return m_list->m_Pop[m_index];
208  }
210  double &DepartCoef() const
211  {
212  return m_list->m_DepartCoef[m_index];
213  }
215  double &NCrit() const
216  {
217  return m_list->m_NCrit[m_index];
218  }
219 
221  double &ColDen() const
222  {
223  return m_list->m_ColDen[m_index];
224  }
226  int &IonStg() const
227  {
228  return m_list->m_IonStg[m_index];
229  }
231  int &nelem() const
232  {
233  return m_list->m_nelem[m_index];
234  }
236  double &ConBoltz() const
237  {
238  return m_list->m_ConBoltz[m_index];
239  }
241  double &Boltzmann() const
242  {
243  return m_list->m_Boltzmann[m_index];
244  }
246  double &lifetime() const
247  {
248  return m_list->m_lifetime[m_index];
249  }
250  long &n() const
251  {
252  return m_list->m_n[m_index];
253  }
254  long &l() const
255  {
256  return m_list->m_l[m_index];
257  }
258  long &S() const
259  {
260  return m_list->m_S[m_index];
261  }
262  long &v() const
263  {
264  return m_list->m_v[m_index];
265  }
266  long &j() const
267  {
268  return m_list->m_j[m_index];
269  }
270  long &J() const
271  {
272  return m_list->m_J[m_index];
273  }
274  enum level_status &status() const
275  {
276  return m_list->m_status[m_index];
277  }
278 };
280 {
281 public:
282  typedef const qList list_type;
284 private:
287  int m_index;
288 public:
289  explicit qStateConstProxy(const list_type* list, int index) :
290  m_list(list), m_index(index) {}
291  explicit qStateConstProxy(void) : m_list(NULL), m_index(0) {}
293  m_list(q.m_list), m_index(q.m_index) {}
294  // Proxy functions for members of qList below
295  bool associated() const
296  {
297  return m_list != NULL;
298  }
299  string chLabel() const;
300  const string& chConfig() const
301  {
302  return m_list->m_labels[m_index].chConfig();
303  }
304  Energy energy() const
305  {
306  return m_list->m_energy[m_index];
307  }
308  realnum g() const
309  {
310  return m_list->m_g[m_index];
311  }
312  double ColDen() const
313  {
314  return m_list->m_ColDen[m_index];
315  }
316  double Pop() const
317  {
318  return m_list->m_Pop[m_index];
319  }
320  double DepartCoef() const
321  {
322  return m_list->m_DepartCoef[m_index];
323  }
324  double NCrit() const
325  {
326  return m_list->m_NCrit[m_index];
327  }
328  int IonStg() const
329  {
330  return m_list->m_IonStg[m_index];
331  }
332  int nelem() const
333  {
334  return m_list->m_nelem[m_index];
335  }
336  double ConBoltz() const
337  {
338  return m_list->m_ConBoltz[m_index];
339  }
340  double Boltzmann() const
341  {
342  return m_list->m_Boltzmann[m_index];
343  }
344  double lifetime() const
345  {
346  return m_list->m_lifetime[m_index];
347  }
348  long n() const
349  {
350  return m_list->m_n[m_index];
351  }
352  long l() const
353  {
354  return m_list->m_l[m_index];
355  }
356  long S() const
357  {
358  return m_list->m_S[m_index];
359  }
360  long v() const
361  {
362  return m_list->m_v[m_index];
363  }
364  long j() const
365  {
366  return m_list->m_j[m_index];
367  }
368  long J() const
369  {
370  return m_list->m_J[m_index];
371  }
372  enum level_status status() const
373  {
374  return m_list->m_status[m_index];
375  }
376 };
377 
379 {
380  return iterator(this,0);
381 }
383 {
384  return const_iterator(this,0);
385 }
387 {
388  return iterator(this,m_labels.size());
389 }
391 {
392  return const_iterator(this,m_labels.size());
393 }
395 {
396  return begin()[i];
397 }
399 {
400  return begin()[i];
401 }
402 inline void qList::reset(int n)
403 {
404  Junk((*this)[n]);
405  Zero((*this)[n]);
406 }
407 
408 #endif
const string & chConfig() const
Definition: quantumstate.h:21
realnum width() const
Definition: quantumstate.h:128
qStateProxy(void)
Definition: quantumstate.h:183
vector< double > m_ColDen
Definition: quantumstate.h:50
qStateProxy(list_type *list, int index)
Definition: quantumstate.h:181
string & chConfig() const
Definition: quantumstate.h:190
double ConBoltz() const
Definition: quantumstate.h:336
ProxyIterator< qStateProxy, qStateConstProxy > iterator
Definition: quantumstate.h:61
qStateConstProxy(const list_type *list, int index)
Definition: quantumstate.h:289
int m_index
Definition: quantumstate.h:179
ProxyIterator< qStateProxy, qStateConstProxy > iterator
Definition: quantumstate.h:174
const qList list_type
Definition: quantumstate.h:282
T * get_ptr(T *v)
Definition: cddefines.h:1115
Energy & energy() const
Definition: quantumstate.h:195
double lifetime() const
Definition: quantumstate.h:344
vector< realnum > m_g
Definition: quantumstate.h:42
long & j() const
Definition: quantumstate.h:266
qList()
Definition: quantumstate.h:65
int & IonStg() const
Definition: quantumstate.h:226
vector< int > m_IonStg
Definition: quantumstate.h:45
vector< long > m_S
Definition: quantumstate.h:54
string m_chConfig
Definition: quantumstate.h:15
vector< long > m_J
Definition: quantumstate.h:44
double NCrit() const
Definition: quantumstate.h:324
qStateConstProxy const_reference
Definition: quantumstate.h:64
long & l() const
Definition: quantumstate.h:254
long & v() const
Definition: quantumstate.h:262
vector< double > m_DepartCoef
Definition: quantumstate.h:52
vector< double > m_Pop
Definition: quantumstate.h:51
double DepartCoef() const
Definition: quantumstate.h:320
qStateConstProxy(const qStateProxy &q)
Definition: quantumstate.h:292
Definition: quantumstate.h:11
bool associated() const
Definition: quantumstate.h:185
vector< enum level_status > m_status
Definition: quantumstate.h:56
void resize(size_t i)
Definition: quantumstate.h:83
double & Pop() const
Definition: quantumstate.h:205
double Boltzmann() const
Definition: quantumstate.h:340
ProxyIterator< qStateConstProxy, qStateConstProxy > iterator
Definition: quantumstate.h:283
int m_index
Definition: quantumstate.h:287
vector< long > m_n
Definition: quantumstate.h:49
void Zero(qStateProxy)
Definition: quantumstate.cpp:39
double & ConBoltz() const
Definition: quantumstate.h:236
long & n() const
Definition: quantumstate.h:250
typename std::vector< T, allocator_avx< T >> vector_avx
Definition: vectorize.h:331
level_status
Definition: quantumstate.h:11
vector< int > m_nelem
Definition: quantumstate.h:46
int IonStg() const
Definition: quantumstate.h:328
qList list_type
Definition: quantumstate.h:173
Definition: quantumstate.h:35
long n() const
Definition: quantumstate.h:348
double * Boltzmann()
Definition: quantumstate.h:152
vector< long > m_l
Definition: quantumstate.h:47
enum level_status & status() const
Definition: quantumstate.h:274
Definition: proxy_iterator.h:58
double & ColDen() const
Definition: quantumstate.h:221
vector< quantumStateLabels > m_labels
Definition: quantumstate.h:38
vector< Energy > m_energy
Definition: quantumstate.h:41
vector_avx< double > m_Boltzmann
Definition: quantumstate.h:40
list_type * m_list
Definition: quantumstate.h:178
float realnum
Definition: cddefines.h:127
void set_width(realnum width)
Definition: quantumstate.h:132
size_t size() const
Definition: quantumstate.h:124
qList(const char *chLabel, size_t i)
Definition: quantumstate.h:70
vector< long > m_j
Definition: quantumstate.h:43
vector< long > m_v
Definition: quantumstate.h:55
double & lifetime() const
Definition: quantumstate.h:246
#define NULL
Definition: cddefines.h:115
qStateConstProxy(void)
Definition: quantumstate.h:291
long S() const
Definition: quantumstate.h:356
void reset(int n)
Definition: quantumstate.h:402
string & chConfig()
Definition: quantumstate.h:17
void Junk(qStateProxy)
Definition: quantumstate.cpp:8
double & DepartCoef() const
Definition: quantumstate.h:210
realnum g() const
Definition: quantumstate.h:308
iterator end()
Definition: quantumstate.h:386
enum level_status status() const
Definition: quantumstate.h:372
ProxyIterator< qStateConstProxy, qStateConstProxy > const_iterator
Definition: quantumstate.h:62
Definition: quantumstate.h:279
reference operator[](int i)
Definition: quantumstate.h:394
vector< double > m_lifetime
Definition: quantumstate.h:48
string chLabel() const
Definition: quantumstate.cpp:57
Definition: energy.h:9
bool associated() const
Definition: quantumstate.h:295
qStateProxy reference
Definition: quantumstate.h:63
iterator begin()
Definition: quantumstate.h:378
long v() const
Definition: quantumstate.h:360
double Pop() const
Definition: quantumstate.h:316
string m_chLabel
Definition: quantumstate.h:37
double & Boltzmann() const
Definition: quantumstate.h:241
realnum m_width
Definition: quantumstate.h:57
Energy energy() const
Definition: quantumstate.h:304
vector_avx< double > m_ConBoltz
Definition: quantumstate.h:39
string chLabel() const
Definition: quantumstate.cpp:51
long J() const
Definition: quantumstate.h:368
realnum & g() const
Definition: quantumstate.h:200
long l() const
Definition: quantumstate.h:352
vector< double > m_NCrit
Definition: quantumstate.h:53
const list_type * m_list
Definition: quantumstate.h:286
int nelem() const
Definition: quantumstate.h:332
Definition: quantumstate.h:170
Definition: quantumstate.h:11
double & NCrit() const
Definition: quantumstate.h:215
int & nelem() const
Definition: quantumstate.h:231
long & S() const
Definition: quantumstate.h:258
double * ConBoltz()
Definition: quantumstate.h:144
void addone()
Definition: quantumstate.h:116
void chLabel_set(const char *s)
Definition: quantumstate.h:140
const string & chConfig() const
Definition: quantumstate.h:300
Definition: quantumstate.h:13
long j() const
Definition: quantumstate.h:364
const double * ConBoltz() const
Definition: quantumstate.h:148
long & J() const
Definition: quantumstate.h:270
double ColDen() const
Definition: quantumstate.h:312
const double * Boltzmann() const
Definition: quantumstate.h:156
void init(const char *label, size_t i)
Definition: quantumstate.h:111
string chLabel() const
Definition: quantumstate.h:136