/src/openbabel/include/openbabel/kinetics.h
Line | Count | Source |
1 | | /********************************************************************** |
2 | | Copyright (C) 2005 by Chris Morley |
3 | | |
4 | | This file is part of the Open Babel project. |
5 | | For more information, see <http://openbabel.org/> |
6 | | |
7 | | This program is free software; you can redistribute it and/or modify |
8 | | it under the terms of the GNU General Public License as published by |
9 | | the Free Software Foundation version 2 of the License. |
10 | | |
11 | | This program is distributed in the hope that it will be useful, |
12 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | GNU General Public License for more details. |
15 | | ***********************************************************************/ |
16 | | #ifndef OB_KINETICS_H |
17 | | #define OB_KINETICS_H |
18 | | |
19 | | #include <openbabel/generic.h> |
20 | | |
21 | | namespace OpenBabel |
22 | | { |
23 | | |
24 | | const unsigned RateData = 55555; |
25 | | const unsigned ThermoData = 55556; |
26 | | |
27 | | /// \class OBRateData kinetics.h <openbabel/kinetics.h> |
28 | | /// \brief Holds rate constant data for OBReaction |
29 | | /**The data is in a form used by CHEMKIN, at least the original |
30 | | free versions developed by Sandia Labs. Cantera is a GPL chemical |
31 | | kinetics program with similar capabilities. |
32 | | Used by chemkin format and cml reaction format |
33 | | **/ |
34 | | |
35 | | |
36 | | class OBRateData : public OBGenericData |
37 | | { |
38 | | protected: |
39 | | double Rates[3]; |
40 | | double LoRates[3]; |
41 | | double TroeParams[4]; |
42 | | std::map<std::string,double> Efficiencies; |
43 | | public: |
44 | 0 | OBGenericData* Clone(OBBase* /*parent*/) const override { return new OBRateData(*this); } |
45 | | enum rate_type {A, n, E}; |
46 | | enum reaction_type {ARRHENIUS=55555, LINDERMANN, TROE, SRI, THREEBODY}; |
47 | | reaction_type ReactionType; |
48 | 0 | OBRateData():OBGenericData("Rate data", RateData) |
49 | 0 | { |
50 | 0 | Rates[0]=Rates[1]=Rates[2]=0; |
51 | 0 | LoRates[0]=LoRates[1]=LoRates[2]=0; |
52 | 0 | TroeParams[0]=TroeParams[1]=TroeParams[2]=TroeParams[3]=0; |
53 | 0 | ReactionType = ARRHENIUS; |
54 | 0 | } |
55 | | |
56 | | double GetRate(rate_type n) const |
57 | 0 | { |
58 | 0 | return Rates[n]; |
59 | 0 | } |
60 | | |
61 | | void SetRate(rate_type n, const double val) |
62 | 0 | { |
63 | 0 | if(n<3) |
64 | 0 | Rates[n] = val; |
65 | 0 | } |
66 | | |
67 | | double GetLoRate(rate_type n) const |
68 | 0 | { |
69 | 0 | return LoRates[n]; |
70 | 0 | } |
71 | | |
72 | | void SetLoRate(rate_type n, const double val) |
73 | 0 | { |
74 | 0 | if(n<3) |
75 | 0 | LoRates[n] = val; |
76 | 0 | } |
77 | | |
78 | | double GetTroeParam(int n) const |
79 | 0 | { |
80 | 0 | return TroeParams[n]; |
81 | 0 | } |
82 | | |
83 | | void SetTroeParams(int n, const double val) |
84 | 0 | { |
85 | 0 | if(n<4) |
86 | 0 | TroeParams[n] = val; |
87 | 0 | } |
88 | | |
89 | | void SetEfficiency(std::string id, double Eff) |
90 | 0 | { |
91 | 0 | Efficiencies[id] = Eff; |
92 | 0 | } |
93 | | |
94 | | double GetEfficiency(std::string id) |
95 | 0 | { |
96 | 0 | return Efficiencies[id]; //will be 0 if not found |
97 | 0 | } |
98 | | |
99 | | bool GetNextEff(std::string& id, double& Eff) |
100 | 0 | { |
101 | | //Supply id empty to begin, then id is the*last* id |
102 | 0 | std::map<std::string, double>::iterator itr; |
103 | 0 | if(id.empty()) |
104 | 0 | itr = Efficiencies.begin(); |
105 | 0 | else |
106 | 0 | { |
107 | 0 | itr = Efficiencies.find(id); |
108 | 0 | if(itr!=Efficiencies.end()) |
109 | 0 | ++itr; |
110 | 0 | } |
111 | 0 | if(itr==Efficiencies.end()) |
112 | 0 | return false; |
113 | 0 | id = itr->first; |
114 | 0 | Eff = itr->second; |
115 | 0 | return true; |
116 | 0 | } |
117 | | }; |
118 | | |
119 | | //****************************************************************************** |
120 | | /// \class OBNasaThermoData kinetics.h <openbabel/kinetics.h> |
121 | | /// \brief Thermodynamic data in old style NASA polynomial form for OBMol |
122 | | /**This is a venerable data format used to describe specific heats, enthalpies |
123 | | and entropies, particularly in the gas phase and at high temperatures. |
124 | | There is a standard datafile with fixed format (for punched cards!) which |
125 | | can be read and written to this OBMol extension using the thermo format. It |
126 | | is also used in chemkin format and in cmlreact format |
127 | | For a brief description of the meaning of the coefficients see |
128 | | http://www.me.berkeley.edu/gri_mech/data/nasa_plnm.html |
129 | | The first 7 coefficients are for the high temperature range MidT to HiT; |
130 | | and the second 7 are for the low temperature range LoT to MidT |
131 | | Note that there is a more modern NASA polynomial with more terms, which |
132 | | is not supported here. |
133 | | **/ |
134 | | class OBNasaThermoData : public OBGenericData |
135 | | { |
136 | | protected: |
137 | | double Coeffs[14]; |
138 | | double LoT, MidT, HiT; |
139 | | char phase; |
140 | | public: |
141 | 0 | OBNasaThermoData(): LoT(300),MidT(1000),HiT(3000),phase('G') |
142 | 0 | { _type = ThermoData; _attr = "Nasa thermo data";} |
143 | | |
144 | 0 | OBGenericData* Clone(OBBase* /*parent*/) const override { return new OBNasaThermoData(*this); } |
145 | | |
146 | | double GetCoeff(unsigned n) const |
147 | 0 | { |
148 | 0 | return Coeffs[n]; |
149 | 0 | } |
150 | | |
151 | | void SetCoeff(unsigned n, const double val) |
152 | 0 | { |
153 | 0 | if(n<14) |
154 | 0 | Coeffs[n] = val; |
155 | 0 | } |
156 | 0 | double GetLoT() const {return LoT;} |
157 | 0 | double GetMidT() const {return MidT;} |
158 | 0 | double GetHiT() const {return HiT;} |
159 | 0 | void SetLoT(double val){LoT=val;} |
160 | 0 | void SetMidT(double val){MidT=val;} |
161 | 0 | void SetHiT(double val){HiT=val;} |
162 | | |
163 | 0 | char GetPhase() const {return phase;} |
164 | 0 | void SetPhase(char ph){phase=ph;} |
165 | | }; |
166 | | |
167 | | } //namespace OpenBabel |
168 | | |
169 | | #endif //OB_KINETICS_H |
170 | | |
171 | | //! \file kinetics.h |
172 | | //! \brief OBRateData and OBNasaThermoData classes |