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