cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mole.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 MOLE_H_
5 #define MOLE_H_
6 
7 /* mole.h */
8 
9 #include "count_ptr.h"
10 #include "elementnames.h"
11 #include "transition.h"
12 
13 #define SMALLABUND 1e-24
14 
16 
17 class chem_atom;
18 
19 class chem_element {
20  explicit chem_element(); // Do not implement
21  chem_element &operator=(const chem_element&); // Do not implement
22 public:
23  explicit chem_element(int Z, const char*label) : Z(Z), label(label)
24  {}
25  ~chem_element() throw()
26  {}
27  const int Z;
28  const string label;
29  map<int, count_ptr<chem_atom> > isotopes;
30  //(first -> Atomic A; second -> chem_atom )
31  //(first -> -1 for bogus isotope, i.e. where no
32  // isotopes have been explicitly defined)
33 };
34 
35 typedef map<int, count_ptr<chem_atom> >::iterator isotopes_i;
36 
37 class chem_atom {
38 public:
39  // Link back to basic element for convenience -- not a count_ptr
40  // as this would lead to a reference cycle (and hence the
41  // destructors never being called). Many-to-one relation suggests
42  // that the weak link should be this way around.
44  int A; /* mass number */
45  vector<int> ipMl; /* Atom and ion species in molecule arrays */
46  realnum mass_amu; /* mass of isotope in AMU */
47  double frac; /* fraction of element in this isotope */
48 
49  bool lgMeanAbundance( void ) const
50  {
51  return ( A < 0 );
52  }
53 
54  /* Chemical symbols for elements */
55  string label( void ) const
56  {
57  if( lgMeanAbundance() )
58  return el->label;
59  else if( el->Z==1 && A==2 )
60  {
61  // Deuterium is a special case
62  return "D\0";
63  }
64  else
65  {
66  char str[4];
67  sprintf(str,"^%d",A);
68  return ( str + el->label );
69  }
70  }
71 
72  int compare ( const chem_atom &b ) const
73  {
74  // sort by proton number first
75  if ( el->Z < b.el->Z )
76  return -1;
77  else if ( el->Z > b.el->Z )
78  return 1;
79 
80  if (mass_amu < b.mass_amu)
81  return -1;
82  else if (mass_amu > b.mass_amu)
83  return 1;
84  else if (A < b.A )
85  return -1;
86  else
87  return 0;
88  }
89 };
90 inline bool operator< (const chem_atom &a, const chem_atom &b)
91 {
92  return a.compare(b) < 0;
93 }
94 inline bool operator> (const chem_atom &a, const chem_atom &b)
95 {
96  return a.compare(b) > 0;
97 }
98 inline bool operator<= (const chem_atom &a, const chem_atom &b)
99 {
100  return a.compare(b) <= 0;
101 }
102 inline bool operator>= (const chem_atom &a, const chem_atom &b)
103 {
104  return a.compare(b) >= 0;
105 }
106 inline bool operator== (const chem_atom &a, const chem_atom &b)
107 {
108  return a.compare(b) == 0;
109 }
110 inline bool operator!= (const chem_atom &a, const chem_atom &b)
111 {
112  return !(a == b);
113 }
114 
115 typedef vector< count_ptr<chem_atom> > ChemAtomList;
116 extern ChemAtomList atom_list;
118 extern chem_element *null_element;
119 extern chem_atom *null_atom;
120 
122 {
123 public:
125  const count_ptr<chem_atom>& b) const
126  {
127  return *a < *b;
128  }
129 };
130 
131 /* Structure containing molecule data, initially only CO */
132 class molecule {
133 public:
134  typedef map<const count_ptr<chem_atom>, int,
136 
137  string parentLabel;
139  bool isEnabled; /* Is it enabled? */
140 
141  /* Species physical data */
142  string label;
144  int charge;
145  bool lgExcit;
146  bool lgGas_Phase;
147  int n_nuclei(void) const
148  {
149  int num = 0;
150  for (nAtomsMap::const_iterator el = nAtom.begin();
151  el != nAtom.end(); ++el)
152  {
153  num += el->second;
154  }
155  return num;
156  }
157  bool isMonatomic(void) const
158  {
159  if (nAtom.size() == 1 && nAtom.begin()->second == 1)
160  return true;
161  return false;
162  }
163 
167  /* Parameters as computational object */
170 
171  chem_atom *heavyAtom(void) //const
172  {
173  for( nAtomsMap::reverse_iterator it=nAtom.rbegin(); it!=nAtom.rend(); ++it )
174  {
175  if (0 != it->second )
176  {
177  return it->first.get_ptr();
178  }
179  }
180  return null_atom;
181  }
182 
183  int compare(const molecule &mol2) const
184  {
185  nAtomsMap::const_reverse_iterator it1, it2;
186 
187  for( it1 = nAtom.rbegin(), it2 = mol2.nAtom.rbegin();
188  it1 != nAtom.rend() && it2 != mol2.nAtom.rend(); ++it1, ++it2 )
189  {
190  if( *(it1->first) > *(it2->first) )
191  return 1;
192  else if( *(it1->first) < *(it2->first) )
193  return -1;
194  else if( it1->second > it2->second)
195  return 1;
196  else if( it1->second < it2->second)
197  return -1;
198  }
199 
200  if( it1 != nAtom.rend() && it2 == mol2.nAtom.rend() )
201  return 1;
202  else if( it1 == nAtom.rend() && it2 != mol2.nAtom.rend() )
203  return -1;
204  else
205  ASSERT( it1 == nAtom.rend() && it2 == mol2.nAtom.rend() );
206 
207  // sort by label if falls through to here
208  return ( label.compare(mol2.label) );
209 
210  }
211 };
212 
213 /* iterators on nAtom */
214 typedef molecule::nAtomsMap::iterator nAtoms_i;
215 typedef molecule::nAtomsMap::reverse_iterator nAtoms_ri;
216 typedef molecule::nAtomsMap::const_reverse_iterator nAtoms_cri;
217 
219 extern void mole_drive(void);
220 
222 extern void mole_create_react(void);
223 
224 class mole_reaction;
225 
226 mole_reaction *mole_findrate_s(const char buf[]);
227 
228 extern void mole_print_species_reactions( molecule *speciesToPrint );
229 
230 extern molecule *null_mole;
231 
232 extern molecule *findspecies(const char buf[]);
233 
267 
268 public:
269  void init(void);
270 
271  void make_species(void);
272 
274  void zero(void);
275 
277  bool lgNoMole;
278 
281 
283  bool lgH2Ozer;
284 
287 
289  bool lgStancil;
290 
295 
300 
305 
309 
310  // flag saying whether to model isotopes (and isotopologues) of a given element
311  vector<bool> lgTreatIsotopes;
312 
315 
316  typedef vector<count_ptr<molecule> > MoleculeList;
318 
319  static void sort(MoleculeList::iterator start,
320  MoleculeList::iterator end);
321  static void sort(molecule **start, molecule **end);
322 };
323 
325 
327 {
328 public:
329  void set_location( long nelem, long ion, double *dense );
330  void set_isotope_abundances( void );
331  double sink_rate_tot(const char chSpecies[]) const;
332  double sink_rate_tot(const molecule* const sp) const;
333  double sink_rate(const molecule* const sp, const mole_reaction& rate) const;
334  double sink_rate(const molecule* const sp, const char buf[]) const;
335  double source_rate_tot(const char chSpecies[]) const;
336  double source_rate_tot(const molecule* const sp) const;
339  double dissoc_rate(const char chSpecies[]) const;
340  double chem_heat(void) const;
341  double findrk(const char buf[]) const;
342  double findrate(const char buf[]) const;
343 
345 
347  double elec;
348 
351  double **source , **sink;
352 
353  realnum ***xMoleChTrRate;/***[LIMELM][LIMELM+1][LIMELM+1];*/
354 
355  valarray<class molezone> species;
356 
357  vector<double> reaction_rks;
358  vector<double> old_reaction_rks;
359  long old_zone;
360 };
361 
362 extern t_mole_local mole;
363 
364 class molezone {
365 public:
367  {
368  init();
369  }
370  void init (void)
371  {
372  location = NULL;
373  levels = NULL;
374  lines = NULL;
375  zero();
376  }
377  void zero (void)
378  {
379  src = 0.;
380  snk = 0.;
381  den = 0.;
382  column = 0.;
383  nAtomLim = -1;
384  xFracLim = 0.;
385  column_old = 0.;
386  }
387  double *location;
390  double src, snk;
391 
394 
395  /* Current zone data */
396  double den;
398  int nAtomLim;
401  /* Historical solution data */
403 };
404 
405 extern molezone *null_molezone;
406 
407 extern molezone *findspecieslocal(const char buf[]);
408 
409 extern void mole_punch(FILE *punit, const char speciesname[], const char args[], bool lgHeader, bool lgData, double depth);
410 
411 extern void total_molecule_elems(realnum total[LIMELM]);
412 extern void total_molecule_deut(realnum &total);
413 
414 extern realnum total_molecules(void);
415 
416 extern realnum total_molecules_gasphase(void);
417 
418 extern void mole_make_list(void);
419 extern void mole_make_groups(void);
420 
422 
423 bool lgDifferByExcitation( const molecule &mol1, const molecule &mol2 );
424 
425 extern void mole_update_species_cache(void);
426 
427 void mole_update_sources(void);
428 
429 void mole_rk_bigchange(void);
430 
433  vector< int >& numAtoms,
434  string atom_old,
435  string atom_new,
436  string embellishments,
437  vector<string>& newLabels );
438 
439 bool parse_species_label( const char label[], ChemAtomList &atomsLeftToRight, vector<int> &numAtoms, string &embellishments );
440 bool parse_species_label( const char mylab[], ChemAtomList &atomsLeftToRight, vector<int> &numAtoms, string &embellishments,
441  bool &lgExcit, int &charge, bool &lgGas_Phase );
442 
443 #endif /* MOLE_H_ */
444 
double sink_rate_tot(const char chSpecies[]) const
t_mole_global mole_global
Definition: mole.cpp:6
map< int, count_ptr< chem_atom > > isotopes
Definition: mole.h:29
double grain_area
Definition: mole.h:344
bool lgStancil
Definition: mole.h:289
static void sort(MoleculeList::iterator start, MoleculeList::iterator end)
vector< double > reaction_rks
Definition: mole.h:357
molecule * null_mole
void mole_create_react(void)
long old_zone
Definition: mole.h:359
void mole_punch(FILE *punit, const char speciesname[], const char args[], bool lgHeader, bool lgData, double depth)
chem_atom * heavyAtom(void)
Definition: mole.h:171
int n_nuclei(void) const
Definition: mole.h:147
vector< bool > lgTreatIsotopes
Definition: mole.h:311
int num_total
Definition: mole.h:314
ChemAtomList atom_list
mole_state
Definition: mole.h:15
realnum total_molecules(void)
int num_calc
Definition: mole.h:314
void mole_drive(void)
Definition: mole_drive.cpp:41
void make_species(void)
molecule::nAtomsMap::const_reverse_iterator nAtoms_cri
Definition: mole.h:216
void total_molecule_deut(realnum &total)
int parentIndex
Definition: mole.h:138
bool operator<(const count_ptr< T > &a, const count_ptr< T > &b)
Definition: count_ptr.h:88
void zero(void)
Definition: mole.cpp:36
int A
Definition: mole.h:44
bool lgH2Ozer
Definition: mole.h:283
const string label
Definition: mole.h:28
void mole_make_list(void)
double findrk(const char buf[]) const
t_dense dense
Definition: dense.cpp:24
map< int, count_ptr< chem_atom > >::iterator isotopes_i
Definition: mole.h:35
double frac
Definition: mole.h:47
TransitionList * lines
Definition: mole.h:393
realnum column
Definition: mole.h:397
bool lgProtElim
Definition: mole.h:299
molezone * findspecieslocal(const char buf[])
double source_rate_tot(const char chSpecies[]) const
Definition: mole.h:364
bool lgGas_Phase
Definition: mole.h:146
bool operator!=(const count_ptr< T > &a, const count_ptr< T > &b)
Definition: count_ptr.h:113
Definition: mole.h:132
int num_compacted
Definition: mole.h:314
vector< count_ptr< molecule > > MoleculeList
Definition: mole.h:316
char ** chSpecies
Definition: taulines.cpp:13
bool lgNonEquilChem
Definition: mole.h:294
realnum form_enthalpy
Definition: mole.h:164
realnum mass_amu
Definition: mole.h:46
double grain_density
Definition: mole.h:344
Definition: mole.h:15
bool isEnabled
Definition: mole.h:139
realnum xFracLim
Definition: mole.h:399
int compare(const chem_atom &b) const
Definition: mole.h:72
double ** sink
Definition: mole.h:351
void mole_cmp_num_in_out_reactions(void)
chem_element * el
Definition: mole.h:43
double chem_heat(void) const
void init(void)
Definition: mole.cpp:11
qList * levels
Definition: mole.h:392
int nAtomLim
Definition: mole.h:398
vector< double > old_reaction_rks
Definition: mole.h:358
bool lgLeidenHack
Definition: mole.h:286
double ** source
Definition: mole.h:351
string parentLabel
Definition: mole.h:137
int groupnum
Definition: mole.h:169
chem_atom * null_atom
void mole_print_species_reactions(molecule *speciesToPrint)
t_mole_local mole
Definition: mole.cpp:7
molecule * findspecies(const char buf[])
molecule::nAtomsMap::reverse_iterator nAtoms_ri
Definition: mole.h:215
chem_element & operator=(const chem_element &)
bool parse_species_label(const char label[], ChemAtomList &atomsLeftToRight, vector< int > &numAtoms, string &embellishments)
t_atoms atoms
Definition: atoms.cpp:5
molezone()
Definition: mole.h:366
realnum *** xMoleChTrRate
Definition: mole.h:353
~chem_element()
Definition: mole.h:25
float realnum
Definition: cddefines.h:107
valarray< class molezone > species
Definition: mole.h:355
enum mole_state state
Definition: mole.h:168
double sink_rate(const molecule *const sp, const mole_reaction &rate) const
void mole_rk_bigchange(void)
double snk
Definition: mole.h:390
void create_isotopologues_one(ChemAtomList &atoms, vector< int > &numAtoms, string atom_old, string atom_new, string embellishments, vector< string > &newLabels)
int index
Definition: mole.h:169
realnum total_molecules_gasphase(void)
const int Z
Definition: mole.h:27
bool lgExcit
Definition: mole.h:145
bool operator>=(const count_ptr< T > &a, const count_ptr< T > &b)
Definition: count_ptr.h:103
Definition: mole.h:37
vector< int > ipMl
Definition: mole.h:45
string label(void) const
Definition: mole.h:55
int compare(const molecule &mol2) const
Definition: mole.h:183
void mole_update_sources(void)
Definition: mole_drive.cpp:106
bool lgMeanAbundance(void) const
Definition: mole.h:49
#define ASSERT(exp)
Definition: cddefines.h:582
void set_isotope_abundances(void)
bool lgNeutrals
Definition: mole.h:304
double findrate(const char buf[]) const
STATIC void start(long, realnum[], realnum[], long, long[], realnum *, int *)
bool operator==(const count_ptr< T > &a, const count_ptr< T > &b)
Definition: count_ptr.h:108
const int LIMELM
Definition: cddefines.h:262
void set_location(long nelem, long ion, double *dense)
bool isMonatomic(void) const
Definition: mole.h:157
int charge
Definition: mole.h:144
bool operator<=(const count_ptr< T > &a, const count_ptr< T > &b)
Definition: count_ptr.h:98
double den
Definition: mole.h:396
bool operator>(const count_ptr< T > &a, const count_ptr< T > &b)
Definition: count_ptr.h:93
bool lgGrain_mole_deplete
Definition: mole.h:308
bool lgDifferByExcitation(const molecule &mol1, const molecule &mol2)
void mole_update_species_cache(void)
ChemAtomList unresolved_atom_list
string label
Definition: mole.h:142
void zero(void)
Definition: mole.h:377
double elec
Definition: mole.h:347
realnum mole_mass
Definition: mole.h:165
MoleculeList list
Definition: mole.h:317
double dissoc_rate(const char chSpecies[]) const
mole_reaction * mole_findrate_s(const char buf[])
nAtomsMap nAtom
Definition: mole.h:143
bool lgNoHeavyMole
Definition: mole.h:280
bool lgFederman
Definition: mole.h:288
bool lgNoMole
Definition: mole.h:277
bool operator()(const count_ptr< chem_atom > &a, const count_ptr< chem_atom > &b) const
Definition: mole.h:124
void mole_make_groups(void)
realnum column_old
Definition: mole.h:402
double src
Definition: mole.h:390
chem_element * null_element
void total_molecule_elems(realnum total[LIMELM])
map< const count_ptr< chem_atom >, int, element_pointer_value_less > nAtomsMap
Definition: mole.h:135
molezone * null_molezone
double * location
Definition: mole.h:387
chem_element(int Z, const char *label)
Definition: mole.h:23
vector< count_ptr< chem_atom > > ChemAtomList
Definition: mole.h:115
void init(void)
Definition: mole.h:370
double grain_saturation
Definition: mole.h:344
molecule::nAtomsMap::iterator nAtoms_i
Definition: mole.h:214