Cloudy
Spectral Synthesis Code for Astrophysics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
collision.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 COLLISION_H_
5 #define COLLISION_H_
6 
7 #include "global.h"
8 
9  /* these are flags for various colliders that are used across the code */
10 enum collider {
21 };
22 
23 class t_collider
24 {
25 public:
26  long charge;
27  double *density;
29 
31  {
32  charge = LONG_MAX;
33  density = NULL;
34  mass_amu = FLT_MAX;
35  }
36 };
37 
39 {
40 public:
41  vector<t_collider> list;
42  ColliderList(const t_dense &d);
43  void init();
44 };
46 {
48 public:
50  {
51  ASSERT( colls.list.size() == ipNCOLLIDER );
52  for( unsigned i = 0; i < ipNCOLLIDER; ++i )
53  {
54  m_dens[i] = (*colls.list[i].density);
55  }
56  }
57  double density(long ipCollider) const
58  {
59  return m_dens[ipCollider];
60  }
61 };
62 
64 {
66 public:
68  {
69  for( long i=0; i<ipNCOLLIDER; i++ )
70  m_rate_coef_ul[i] = 0.;
71  }
73  double *rate_coef_ul_set()
74  {
75  return m_rate_coef_ul;
76  }
77  const double *rate_coef_ul() const
78  {
79  return m_rate_coef_ul;
80  }
81 };
82 
83 class CollisionList;
85 {
87  int m_index;
88 public:
89  explicit CollisionProxy(CollisionList *list, int index)
90  : m_list(list), m_index(index) {}
91 
93  realnum &col_str() const;
95  int &is_gbar() const;
97  double *rate_coef_ul_set() const;
98  const double *rate_coef_ul() const;
100  realnum rate_lu_nontherm() const;
102  double &cool() const;
103  double &heat() const;
104 
106  double ColUL( const ColliderList& colls ) const
107  {
108  double rate = 0.;
109  ASSERT( colls.list.size() == ipNCOLLIDER );
110  for( unsigned i = 0; i < colls.list.size(); ++i )
111  {
112  ASSERT( rate_coef_ul()[i] >= 0.0 );
113  rate += rate_coef_ul()[i] * (*colls.list[i].density);
114  }
115  ASSERT( rate >= 0. );
116  return rate;
117  }
118  double ColUL( const ColliderDensities& colld ) const
119  {
120  double rate = 0.;
121  for( unsigned i = 0; i < ipNCOLLIDER; ++i )
122  {
123  ASSERT( rate_coef_ul()[i] >= 0.0 );
124  rate += rate_coef_ul()[i] * colld.density(i);
125  }
126  ASSERT( rate >= 0. );
127  return rate;
128  }
129 
130  void copy(CollisionProxy other)
131  {
132  col_str() = other.col_str();
133  cool() = other.cool();
134  heat() = other.heat();
135  for (int i=0; i<ipNCOLLIDER; ++i)
136  {
137  rate_coef_ul_set()[i] = other.rate_coef_ul()[i];
138  }
140  }
141 };
142 
144 {
145  vector<collision_rates> m_rates;
146  vector<realnum> m_col_str;
147  vector<realnum> m_rate_lu_nontherm;
148  vector<int> m_is_gbar;
149  vector<double> m_cool;
150  vector<double> m_heat;
151  // DO NOT IMPEMENT
154 public:
155  friend class CollisionProxy;
157  explicit CollisionList(size_t i)
158  {
159  resize(i);
160  }
161  explicit CollisionList() {}
163  {
164  return CollisionProxy(this,i);
165  }
166  size_t size(void) const
167  {
168  return m_rates.size();
169  }
170  void resize(size_t i)
171  {
172  m_rates.resize(i);
173  m_rate_lu_nontherm.resize(i);
174  m_col_str.resize(i);
175  m_is_gbar.resize(i);
176  m_cool.resize(i);
177  m_heat.resize(i);
178  }
179  void reserve(size_t i)
180  {
181  m_rates.reserve(i);
182  m_rate_lu_nontherm.reserve(i);
183  m_col_str.reserve(i);
184  m_is_gbar.reserve(i);
185  m_cool.reserve(i);
186  m_heat.reserve(i);
187  }
188 };
189 
192 {
193  return m_list->m_col_str[m_index];
194 }
197 inline int &CollisionProxy::is_gbar() const
198 {
199  return m_list->m_is_gbar[m_index];
200 }
202 inline double *CollisionProxy::rate_coef_ul_set() const
203 {
204  return m_list->m_rates[m_index].rate_coef_ul_set();
205 }
206 inline const double *CollisionProxy::rate_coef_ul() const
207 {
208  return m_list->m_rates[m_index].rate_coef_ul();
209 }
210 // nonthermal collisional excitation rate [s-1]
212 {
214 }
216 {
218 }
220 inline double &CollisionProxy::cool() const
221 {
222  return m_list->m_cool[m_index];
223 }
224 inline double &CollisionProxy::heat() const
225 {
226  return m_list->m_heat[m_index];
227 }
228 
232 void CollisionJunk( const CollisionProxy & t );
233 
237 void CollisionZero( const CollisionProxy & t );
238 
239 #endif // COLLISION_H_
int m_index
Definition: collision.h:87
size_t size(void) const
Definition: collision.h:166
Definition: collision.h:14
CollisionList * m_list
Definition: collision.h:86
vector< realnum > m_rate_lu_nontherm
Definition: collision.h:147
double * rate_coef_ul_set()
Definition: collision.h:73
ColliderList(const t_dense &d)
Definition: collision.cpp:11
collision_rates()
Definition: collision.h:67
Definition: collision.h:143
double ColUL(const ColliderDensities &colld) const
Definition: collision.h:118
double * density
Definition: collision.h:27
void init()
Definition: collision.cpp:49
CollisionProxy operator[](size_t i)
Definition: collision.h:162
Definition: collision.h:38
int & is_gbar() const
Definition: collision.h:197
Definition: dense.h:26
double * rate_coef_ul_set() const
Definition: collision.h:202
Definition: collision.h:23
friend class CollisionProxy
Definition: collision.h:155
vector< double > m_cool
Definition: collision.h:149
CollisionList(size_t i)
Definition: collision.h:157
Definition: collision.h:63
double density(long ipCollider) const
Definition: collision.h:57
CollisionList()
Definition: collision.h:161
double m_dens[ipNCOLLIDER]
Definition: collision.h:47
Definition: collision.h:17
double & heat() const
Definition: collision.h:224
vector< collision_rates > m_rates
Definition: collision.h:145
collider
Definition: collision.h:10
long charge
Definition: collision.h:26
realnum rate_lu_nontherm() const
Definition: collision.h:215
void resize(size_t i)
Definition: collision.h:170
void copy(CollisionProxy other)
Definition: collision.h:130
void reserve(size_t i)
Definition: collision.h:179
float realnum
Definition: cddefines.h:127
vector< double > m_heat
Definition: collision.h:150
double m_rate_coef_ul[ipNCOLLIDER]
Definition: collision.h:65
Definition: collision.h:13
#define NULL
Definition: cddefines.h:115
CollisionProxy reference
Definition: collision.h:156
void CollisionJunk(const CollisionProxy &t)
Definition: collision.cpp:65
#define ASSERT(exp)
Definition: cddefines.h:637
vector< int > m_is_gbar
Definition: collision.h:148
Definition: collision.h:20
vector< t_collider > list
Definition: collision.h:41
realnum & col_str() const
Definition: collision.h:191
double & cool() const
Definition: collision.h:220
Definition: collision.h:45
realnum & rate_lu_nontherm_set() const
Definition: collision.h:211
const double * rate_coef_ul() const
Definition: collision.h:206
CollisionProxy(CollisionList *list, int index)
Definition: collision.h:89
Definition: collision.h:11
Definition: collision.h:16
Definition: collision.h:12
Definition: collision.h:18
Definition: collision.h:15
vector< realnum > m_col_str
Definition: collision.h:146
void CollisionZero(const CollisionProxy &t)
Definition: collision.cpp:88
CollisionList & operator=(const CollisionList &)
ColliderDensities(const ColliderList &colls)
Definition: collision.h:49
realnum mass_amu
Definition: collision.h:28
double ColUL(const ColliderList &colls) const
Definition: collision.h:106
t_collider()
Definition: collision.h:30
Definition: collision.h:19
const double * rate_coef_ul() const
Definition: collision.h:77
Definition: collision.h:84