reaction_lib.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2008-2017, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef REACTION_LIB_H
24 #define REACTION_LIB_H
25 
26 /** \file reaction_lib.h
27  \brief File defining \ref o2scl::nuclear_reaction
28 */
29 
30 #include <iostream>
31 #include <fstream>
32 #include <string>
33 #include <sstream>
34 
35 #include <o2scl/err_hnd.h>
36 #include <o2scl/string_conv.h>
37 #include <o2scl/nucleus.h>
38 #include <o2scl/nucmass.h>
39 
40 #ifndef DOXYGEN_NO_O2NS
41 namespace o2scl {
42 #endif
43 
44  /** \brief A simple nuclear reaction specification
45 
46  This class is very experimental.
47  */
49 
50  public:
51 
52  /// Chapter
53  size_t chap;
54  /// Names of the participating nuclei
55  std::string name[6];
56  /// Reference
57  std::string ref;
58  /// Type of rate (resonant/non-resonant/weak)
59  char type;
60  /// Forward or reverse
61  char rev;
62  /// Q value
63  double Q;
64  /// Coefficients
65  double a[7];
66  /// Proton number of participating nuclei
67  size_t Z[6];
68  /// Mass number of participating nuclei
69  size_t A[6];
70  /// Isomer designation of participating nuclei
71  size_t isomer[6];
72 
74  }
75 
76  /** \brief Convert the reaction to a string for screen output
77  */
78  std::string to_string() {
79  std::ostringstream outs;
80  outs.width(2);
81  outs << chap << ": ";
82  nucmass_info nmi;
83  for(size_t i=0;i<6;i++) {
84  if (name[i].length()>0 && A[i]>0) {
85  if (Z[i]==0 && A[i]==1) outs << "n ";
86  else if (Z[i]==1 && A[i]==1) outs << "p ";
87  else if (Z[i]==1 && A[i]==2) outs << "d ";
88  else if (Z[i]==1 && A[i]==3) outs << "t ";
89  else outs << nmi.Ztoel(Z[i]) << A[i] << " ";
90  if (i==0 && (chap==1 || chap==2 || chap==3 || chap==11)) {
91  outs << "-> ";
92  } else if (i==1 && (chap==4 || chap==5 || chap==6 || chap==7)) {
93  outs << "-> ";
94  } else if (i==2 && (chap==8 || chap==9)) {
95  outs << "-> ";
96  } else if (i==3 && chap==10) {
97  outs << "-> ";
98  } else if (i<5 && name[i+1].length()>0 && A[i+1]>0) {
99  outs << "+ ";
100  }
101  } else {
102  i=6;
103  }
104  }
105  return outs.str();
106  }
107 
108  /// Clear the rate
109  int clear() {
110  chap=0;
111  ref="";
112  type=0;
113  rev=0;
114  Q=0.0;
115  for(size_t i=0;i<6;i++) {
116  name[i]="";
117  a[i]=0.0;
118  Z[i]=0;
119  A[i]=0;
120  isomer[i]=0;
121  }
122  a[6]=0.0;
123 
124  return 0;
125  }
126 
127  /// Copy constructor
129  chap=nr.chap;
130  ref=nr.ref;
131  type=nr.type;
132  rev=nr.rev;
133  Q=nr.Q;
134  for(size_t i=0;i<6;i++) {
135  name[i]=nr.name[i];
136  a[i]=nr.a[i];
137  Z[i]=nr.Z[i];
138  A[i]=nr.A[i];
139  isomer[i]=nr.isomer[i];
140  }
141  a[6]=nr.a[6];
142  }
143 
144  /// Copy constructor
146 
147  // Check for self-assignment
148  if (this==&nr) return *this;
149 
150  chap=nr.chap;
151  ref=nr.ref;
152  type=nr.type;
153  rev=nr.rev;
154  Q=nr.Q;
155  for(size_t i=0;i<6;i++) {
156  name[i]=nr.name[i];
157  a[i]=nr.a[i];
158  Z[i]=nr.Z[i];
159  A[i]=nr.A[i];
160  isomer[i]=nr.isomer[i];
161  }
162  a[6]=nr.a[6];
163 
164  return *this;
165  }
166 
167  /** \brief Compute the reaction rate from the temperature in units of
168  \f$ 10^9 K \f$
169  */
170  double rate(double T9) {
171  double ret;
172  double T913=cbrt(T9);
173  ret=exp(a[0]+a[1]/T9+a[2]/T913+a[3]*T913+a[4]*T9+
174  a[5]*T9*T913*T913)*pow(T9,a[6]);
175  return ret;
176  }
177 
178  };
179 
180  /** \brief Simple reaction library
181 
182  This class is very experimental.
183 
184  Units:
185  - Chapters 1,2,3, and 11: 1/s
186  - Chapters 4,5,6, and 7: cm^3/g/s
187  - Chapter 8 and 9: cm^6/g^2/s
188  - Chapter 10: cm^9/g^3/s
189 
190  Chapters:
191  - 1: nuc1 -> nuc2
192  - 2: nuc1 -> nuc2 + nuc3
193  - 3: nuc1 -> nuc2 + nuc3 + nuc4
194  - 4: nuc1 + nuc2 -> nuc3
195  - 5: nuc1 + nuc2 -> nuc3 + nuc4
196  - 6: nuc1 + nuc2 -> nuc3 + nuc4 + nuc5
197  - 7: nuc1 + nuc2 -> nuc3 + nuc4 + nuc5 + nuc6
198  - 8: nuc1 + nuc2 + nuc3 -> nuc4
199  - 9: nuc1 + nuc2 + nuc3 -> nuc4 + nuc5
200  - 10: nuc1 + nuc2 + nuc3 + nuc4 -> nuc5 + num6
201  - 11: nuc1 -> nuc2 + nuc3 + nuc4 + nuc5
202 
203  Original FORTRAN format:
204  \verbatim
205  FORMAT(i1,4x,6a5,8x,a4,a1,a1,3x,1pe12.5)
206  FORMAT(4e13.6)
207  FORMAT(3e13.6)
208  \endverbatim
209  */
210  class reaction_lib {
211 
212  public:
213 
214  /// The library
215  std::vector<nuclear_reaction> lib;
216 
217  /** \brief Read from a file in the REACLIB2 format
218 
219  \note This function does not check that the chapter numbers
220  are correct for the subsequent reaction.
221  */
222  int read_file_reaclib2(std::string fname);
223 
224  /** \brief Find a set of nuclear reactions in a specified chapter
225 
226  \comment
227  This function doesn't make any assumptions about the ordering of
228  the rates and the chapters.
229  \endcomment
230  */
231  int find_in_chap(std::vector<nuclear_reaction> &nrl,
232  size_t chap, std::string nuc1, std::string nuc2="",
233  std::string nuc3="", std::string nuc4="",
234  std::string nuc5="", std::string nuc6="");
235 
236  protected:
237 
238  /// \name Storage for the find function
239  //@{
240  int fN[6], fZ[6], fA[6];
241  size_t fi;
242  //@}
243 
244  /// Test if entry \c ul in the arrays matches the library reaction
245  bool matches(size_t ul, size_t ri);
246 
247  };
248 
249 #ifndef DOXYGEN_NO_O2NS
250 }
251 #endif
252 
253 #endif
size_t chap
Chapter.
Definition: reaction_lib.h:53
int clear()
Clear the rate.
Definition: reaction_lib.h:109
A simple nuclear reaction specification.
Definition: reaction_lib.h:48
std::string Ztoel(size_t Z)
Return the element name abbreviation given Z.
std::string name[6]
Names of the participating nuclei.
Definition: reaction_lib.h:55
Simple reaction library.
Definition: reaction_lib.h:210
size_t A[6]
Mass number of participating nuclei.
Definition: reaction_lib.h:69
Nuclear mass information.
Definition: nucmass.h:62
std::string ref
Reference.
Definition: reaction_lib.h:57
nuclear_reaction & operator=(const nuclear_reaction &nr)
Copy constructor.
Definition: reaction_lib.h:145
size_t Z[6]
Proton number of participating nuclei.
Definition: reaction_lib.h:67
std::string to_string()
Convert the reaction to a string for screen output.
Definition: reaction_lib.h:78
char type
Type of rate (resonant/non-resonant/weak)
Definition: reaction_lib.h:59
double a[7]
Coefficients.
Definition: reaction_lib.h:65
size_t isomer[6]
Isomer designation of participating nuclei.
Definition: reaction_lib.h:71
std::vector< nuclear_reaction > lib
The library.
Definition: reaction_lib.h:215
double Q
Q value.
Definition: reaction_lib.h:63
char rev
Forward or reverse.
Definition: reaction_lib.h:61
double rate(double T9)
Compute the reaction rate from the temperature in units of .
Definition: reaction_lib.h:170
nuclear_reaction(const nuclear_reaction &nr)
Copy constructor.
Definition: reaction_lib.h:128

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).