Particles and Nuclei Sub-Library: Version 0.910
reaction_lib.h
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2008-2012, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020 
00021   -------------------------------------------------------------------
00022 */
00023 #ifndef REACTION_LIB_H
00024 #define REACTION_LIB_H
00025 
00026 #include <iostream>
00027 #include <fstream>
00028 #include <string>
00029 #include <sstream>
00030 
00031 #include <o2scl/err_hnd.h>
00032 #include <o2scl/string_conv.h>
00033 #include <o2scl/nucleus.h>
00034 #include <o2scl/nuclear_mass.h>
00035 
00036 #ifndef DOXYGENP
00037 namespace o2scl {
00038 #endif
00039 
00040   /** \brief A simple nuclear reaction specification
00041 
00042       This class is very experimental.
00043   */
00044   class nuclear_reaction {
00045 
00046   public:
00047 
00048     /// Chapter
00049     size_t chap;
00050     /// Names of the participating nuclei
00051     std::string name[6];
00052     /// Reference
00053     std::string ref;
00054     /// Type of rate (resonant/non-resonant/weak)
00055     char type;
00056     /// Forward or reverse
00057     char rev;
00058     /// Q value
00059     double Q;
00060     /// Coefficients
00061     double a[7];
00062     /// Proton number of participating nuclei
00063     size_t Z[6];
00064     /// Mass number of participating nuclei
00065     size_t A[6];
00066     /// Isomer designation of participating nuclei
00067     size_t isomer[6];
00068 
00069     nuclear_reaction() {
00070     }
00071 
00072     /** \brief Convert the reaction to a string for screen output
00073      */
00074     std::string to_string() {
00075       std::ostringstream outs;
00076       outs.width(2);
00077       outs << chap << ": ";
00078       nuclear_mass_info nmi;
00079       for(size_t i=0;i<6;i++) {
00080         if (name[i].length()>0 && A[i]>0) {
00081           if (Z[i]==0 && A[i]==1) outs << "n ";
00082           else if (Z[i]==1 && A[i]==1) outs << "p ";
00083           else if (Z[i]==1 && A[i]==2) outs << "d ";
00084           else if (Z[i]==1 && A[i]==3) outs << "t ";
00085           else outs << nmi.Ztoel(Z[i]) << A[i] << " ";
00086           if (i==0 && (chap==1 || chap==2 || chap==3 || chap==11)) {
00087             outs << "-> ";
00088           } else if (i==1 && (chap==4 || chap==5 || chap==6 || chap==7)) {
00089             outs << "-> ";
00090           } else if (i==2 && (chap==8 || chap==9)) {
00091             outs << "-> ";
00092           } else if (i==3 && chap==10) {
00093             outs << "-> ";
00094           } else if (i<5 && name[i+1].length()>0 && A[i+1]>0) {
00095             outs << "+ ";
00096           }
00097         } else {
00098           i=6;
00099         }
00100       }
00101       return outs.str();
00102     }
00103 
00104     /// Clear the rate
00105     int clear() {
00106       chap=0;
00107       ref="";
00108       type=0;
00109       rev=0;
00110       Q=0.0;
00111       for(size_t i=0;i<6;i++) {
00112         name[i]="";
00113         a[i]=0.0;
00114         Z[i]=0;
00115         A[i]=0;
00116         isomer[i]=0;
00117       }
00118       a[6]=0.0;
00119       
00120       return 0;
00121     }
00122 
00123     /// Copy constructor
00124     nuclear_reaction(const nuclear_reaction &nr) {
00125       chap=nr.chap;
00126       ref=nr.ref;
00127       type=nr.type;
00128       rev=nr.rev;
00129       Q=nr.Q;
00130       for(size_t i=0;i<6;i++) {
00131         name[i]=nr.name[i];
00132         a[i]=nr.a[i];
00133         Z[i]=nr.Z[i];
00134         A[i]=nr.A[i];
00135         isomer[i]=nr.isomer[i];
00136       }
00137       a[6]=nr.a[6];
00138     }
00139     
00140     /// Copy constructor
00141     nuclear_reaction &operator=(const nuclear_reaction &nr) {
00142       
00143       // Check for self-assignment
00144       if (this==&nr) return *this;
00145       
00146       chap=nr.chap;
00147       ref=nr.ref;
00148       type=nr.type;
00149       rev=nr.rev;
00150       Q=nr.Q;
00151       for(size_t i=0;i<6;i++) {
00152         name[i]=nr.name[i];
00153         a[i]=nr.a[i];
00154         Z[i]=nr.Z[i];
00155         A[i]=nr.A[i];
00156         isomer[i]=nr.isomer[i];
00157       }
00158       a[6]=nr.a[6];
00159 
00160       return *this;
00161     }
00162 
00163     /** \brief Compute the reaction rate from the temperature in units of 
00164         \f$ 10^9 K \f$ 
00165     */
00166     double rate(double T9) {
00167       double ret;
00168       double T913=cbrt(T9);
00169       ret=exp(a[0]+a[1]/T9+a[2]/T913+a[3]*T913+a[4]*T9+
00170               a[5]*T9*T913*T913)*pow(T9,a[6]);
00171       return ret;
00172     }
00173     
00174   };
00175 
00176   /** \brief Simple reaction library 
00177 
00178       This class is very experimental.
00179       
00180       Units:
00181       - Chapters 1,2,3, and 11: 1/s
00182       - Chapters 4,5,6, and 7: cm^3/g/s
00183       - Chapter 8 and 9: cm^6/g^2/s
00184       - Chapter 10: cm^9/g^3/s
00185 
00186       Chapters:
00187       - 1: nuc1 -> nuc2
00188       - 2: nuc1 -> nuc2 + nuc3
00189       - 3: nuc1 -> nuc2 + nuc3 + nuc4
00190       - 4: nuc1 + nuc2 -> nuc3
00191       - 5: nuc1 + nuc2 -> nuc3 + nuc4
00192       - 6: nuc1 + nuc2 -> nuc3 + nuc4 + nuc5
00193       - 7: nuc1 + nuc2 -> nuc3 + nuc4 + nuc5 + nuc6
00194       - 8: nuc1 + nuc2 + nuc3 -> nuc4
00195       - 9: nuc1 + nuc2 + nuc3 -> nuc4 + nuc5
00196       - 10: nuc1 + nuc2 + nuc3 + nuc4 -> nuc5 + num6
00197       - 11: nuc1 -> nuc2 + nuc3 + nuc4 + nuc5
00198 
00199       Original FORTRAN format:
00200       \verbatim
00201       FORMAT(i1,4x,6a5,8x,a4,a1,a1,3x,1pe12.5) 
00202       FORMAT(4e13.6) 
00203       FORMAT(3e13.6) 
00204       \endverbatim
00205   */
00206   class reaction_lib {
00207 
00208   public:
00209 
00210     /// The library
00211     std::vector<nuclear_reaction> lib;
00212     
00213     /** \brief Read from a file in the REACLIB2 format
00214 
00215         \note This function does not check that the chapter numbers
00216         are correct for the subsequent reaction.
00217      */
00218     int read_file_reaclib2(std::string fname);
00219     
00220     /** \brief Find a set of nuclear reactions in a specified chapter
00221 
00222         \comment
00223         This function doesn't make any assumptions about the ordering of 
00224         the rates and the chapters.
00225         \endcomment
00226      */
00227     int find_in_chap(std::vector<nuclear_reaction> &nrl,
00228                      size_t chap, std::string nuc1, std::string nuc2="", 
00229                      std::string nuc3="", std::string nuc4="", 
00230                      std::string nuc5="", std::string nuc6="");
00231     
00232   protected:
00233     
00234     /// \name Storage for the find function
00235     //@{
00236     int fN[6], fZ[6], fA[6];
00237     size_t fi;
00238     //@}
00239     
00240     /// Test if entry \c ul in the arrays matches the library reaction
00241     bool matches(size_t ul, size_t ri);
00242 
00243   };
00244 
00245 #ifndef DOXYGENP
00246 }
00247 #endif
00248 
00249 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Friends

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

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.