cloudy trunk
Loading...
Searching...
No Matches
quantumstate.h
Go to the documentation of this file.
1/* This file is part of Cloudy and is copyright (C)1978-2013 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 "proxy_iterator.h"
8
10{
11 char m_chLabel[5];
12 char m_chConfig[11];
13public:
14 char *chLabel()
15 {
16 return m_chLabel;
17 }
18 const char *chLabel() const
19 {
20 return m_chLabel;
21 }
22 char *chConfig()
23 {
24 return m_chConfig;
25 }
26 const char *chConfig() const
27 {
28 return m_chConfig;
29 }
30};
31
32// Quantum state properties as structure of lists -- packing
33// like physical properties in vector storage is more cache efficient
34// than a list-of-structures layout.
35class qStateProxy;
37void Junk(qStateProxy);
38void Zero(qStateProxy);
39
40class qList
41{
42 vector<quantumStateLabels> m_labels;
43 vector<double> m_ConBoltz;
44 vector<double> m_Boltzmann;
45 vector<Energy> m_energy;
46 vector<realnum> m_g;
47 vector<long> m_j;
48 vector<long> m_J;
49 vector<int> m_IonStg;
50 vector<int> m_nelem;
51 vector<long> m_l;
52 vector<double> m_lifetime;
53 vector<long> m_n;
54 vector<double> m_ColDen;
55 vector<double> m_Pop;
56 vector<double> m_DestCollBB;
57 vector<double> m_DestPhotoBB;
58 vector<double> m_CreatCollBB;
59 vector<long> m_S;
60 vector<long> m_v;
61 friend class qStateProxy;
62 friend class qStateConstProxy;
63public:
68 explicit qList()
69 {
70 resize(0);
71 }
72 explicit qList(size_t i)
73 {
74 resize(i);
75 }
77 const_iterator begin() const;
78 iterator end();
79 const_iterator end() const;
80 reference operator[](int i);
81 const_reference operator[](int i) const;
82 // Must resize *all* the list members
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# ifdef USE_NLTE7
101 m_DestCollBB.resize(i);
102 m_DestPhotoBB.resize(i);
103 m_CreatCollBB.resize(i);
104# endif
105 m_S.resize(i);
106 m_v.resize(i);
107 for (size_t n=old_size; n<i; ++n)
108 {
109 reset(n);
110 }
111 }
112 void reset(int n);
113 // The size of any of the lists will do, as they should all be
114 // the same. No point really in asserting this, as the assert
115 // will be at least as fragile as the original resize.
116 size_t size() const
117 {
118 return m_labels.size();
119 }
120};
121
122// Quantum state proxy object. This is used to give access to
123// structure-of-lists class qList in an 'object-like' manner, e.g.
124//
125// qs = List[element]; qs.IonStg() = ???; qs.S() = ???; update(qs);
126//
127// The member functions of the proxy class must be the same as the
128// lists which are included in the qList class.
129class qStateConstProxy;
131{
132public:
135private:
139public:
140 explicit qStateProxy(list_type* list, int index) :
141 m_list(list), m_index(index) {}
142 explicit qStateProxy(void) : m_list(NULL), m_index(0) {}
143// Proxy functions for members of qList below
144 char *chLabel() const
145 {
146 return m_list->m_labels[m_index].chLabel();
147 }
148 char *chConfig() const
149 {
150 return m_list->m_labels[m_index].chConfig();
151 }
152
153 Energy &energy() const
154 {
155 return m_list->m_energy[m_index];
156 }
157
158 realnum &g() const
159 {
160 return m_list->m_g[m_index];
161 }
162
163 double &Pop() const
164 {
165 return m_list->m_Pop[m_index];
166 }
167
168 double &ColDen() const
169 {
170 return m_list->m_ColDen[m_index];
171 }
172# ifdef USE_NLTE7
174 double &DestCollBB() const
175 {
176 return m_list->m_DestCollBB[m_index];
177 }
179 double &DestPhotoBB() const
180 {
181 return m_list->m_DestPhotoBB[m_index];
182 }
184 double &CreatCollBB() const
185 {
186 return m_list->m_CreatCollBB[m_index];
187 }
188# endif
190 int &IonStg() const
191 {
192 return m_list->m_IonStg[m_index];
193 }
194
195 int &nelem() const
196 {
197 return m_list->m_nelem[m_index];
198 }
199
200 double &ConBoltz() const
201 {
202 return m_list->m_ConBoltz[m_index];
203 }
204
205 double &Boltzmann() const
206 {
207 return m_list->m_Boltzmann[m_index];
208 }
209
210 double &lifetime() const
211 {
212 return m_list->m_lifetime[m_index];
213 }
214 long &n() const
215 {
216 return m_list->m_n[m_index];
217 }
218 long &l() const
219 {
220 return m_list->m_l[m_index];
221 }
222 long &S() const
223 {
224 return m_list->m_S[m_index];
225 }
226 long &v() const
227 {
228 return m_list->m_v[m_index];
229 }
230 long &j() const
231 {
232 return m_list->m_j[m_index];
233 }
234 long &J() const
235 {
236 return m_list->m_J[m_index];
237 }
238};
240{
241public:
242 typedef const qList list_type;
244private:
248public:
249 explicit qStateConstProxy(const list_type* list, int index) :
250 m_list(list), m_index(index) {}
251 explicit qStateConstProxy(void) : m_list(NULL), m_index(0) {}
252// Proxy functions for members of qList below
253 const char *chLabel() const
254 {
255 return m_list->m_labels[m_index].chLabel();
256 }
257 const char *chConfig() const
258 {
259 return m_list->m_labels[m_index].chConfig();
260 }
262 {
263 return m_list->m_energy[m_index];
264 }
265 realnum g() const
266 {
267 return m_list->m_g[m_index];
268 }
269 double ColDen() const
270 {
271 return m_list->m_ColDen[m_index];
272 }
273 double Pop() const
274 {
275 return m_list->m_Pop[m_index];
276 }
277# ifdef USE_NLTE7
278 double DestCollBB() const
279 {
280 return m_list->m_DestCollBB[m_index];
281 }
282 double DestPhotoBB() const
283 {
284 return m_list->m_DestPhotoBB[m_index];
285 }
286 double CreatCollBB() const
287 {
288 return m_list->m_CreatCollBB[m_index];
289 }
290# endif
291 int IonStg() const
292 {
293 return m_list->m_IonStg[m_index];
294 }
295 int nelem() const
296 {
297 return m_list->m_nelem[m_index];
298 }
299 double ConBoltz() const
300 {
301 return m_list->m_ConBoltz[m_index];
302 }
303 double Boltzmann() const
304 {
305 return m_list->m_Boltzmann[m_index];
306 }
307 double lifetime() const
308 {
309 return m_list->m_lifetime[m_index];
310 }
311 long n() const
312 {
313 return m_list->m_n[m_index];
314 }
315 long l() const
316 {
317 return m_list->m_l[m_index];
318 }
319 long S() const
320 {
321 return m_list->m_S[m_index];
322 }
323 long v() const
324 {
325 return m_list->m_v[m_index];
326 }
327 long j() const
328 {
329 return m_list->m_j[m_index];
330 }
331 long J() const
332 {
333 return m_list->m_J[m_index];
334 }
335};
336
338{
339 return iterator(this,0);
340}
342{
343 return const_iterator(this,0);
344}
346{
347 return iterator(this,m_labels.size());
348}
350{
351 return const_iterator(this,m_labels.size());
352}
354{
355 return begin()[i];
356}
358{
359 return begin()[i];
360}
361inline void qList::reset(int n)
362{
363 Junk((*this)[n]);
364 Zero((*this)[n]);
365}
366
367
368#endif
float realnum
Definition cddefines.h:103
Definition energy.h:8
vector< long > m_S
vector< double > m_DestCollBB
ProxyIterator< qStateConstProxy, qStateConstProxy > const_iterator
vector< realnum > m_g
vector< long > m_n
vector< Energy > m_energy
void resize(size_t i)
vector< int > m_nelem
iterator end()
vector< double > m_CreatCollBB
vector< int > m_IonStg
vector< double > m_DestPhotoBB
vector< long > m_j
vector< double > m_ColDen
qStateConstProxy const_reference
vector< double > m_ConBoltz
friend class qStateProxy
vector< long > m_J
iterator begin()
vector< double > m_Pop
vector< double > m_Boltzmann
vector< quantumStateLabels > m_labels
reference operator[](int i)
vector< long > m_v
qList(size_t i)
size_t size() const
ProxyIterator< qStateProxy, qStateConstProxy > iterator
vector< double > m_lifetime
friend class qStateConstProxy
void reset(int n)
vector< long > m_l
qStateProxy reference
long j() const
const qList list_type
realnum g() const
double ConBoltz() const
long n() const
double lifetime() const
long S() const
double ColDen() const
double Boltzmann() const
qStateConstProxy(const list_type *list, int index)
long J() const
long v() const
double Pop() const
const list_type * m_list
int IonStg() const
const char * chConfig() const
const char * chLabel() const
long l() const
Energy energy() const
int nelem() const
ProxyIterator< qStateConstProxy, qStateConstProxy > iterator
realnum & g() const
double & ColDen() const
double & ConBoltz() const
long & l() const
char * chLabel() const
qStateProxy(void)
char * chConfig() const
long & j() const
long & J() const
double & Pop() const
long & S() const
int & IonStg() const
list_type * m_list
long & v() const
double & Boltzmann() const
double & lifetime() const
int & nelem() const
ProxyIterator< qStateProxy, qStateConstProxy > iterator
long & n() const
qStateProxy(list_type *list, int index)
Energy & energy() const
const char * chLabel() const
const char * chConfig() const
void Junk(qStateProxy)
void Zero(qStateProxy)