Cantera  2.0
KineticsFactory.cpp
Go to the documentation of this file.
1 /**
2  * @file KineticsFactory.cpp
3  */
4 // Copyright 2001 California Institute of Technology
5 
7 
14 
15 using namespace std;
16 
17 namespace Cantera
18 {
19 
20 KineticsFactory* KineticsFactory::s_factory = 0;
21 mutex_t KineticsFactory::kinetics_mutex;
22 
23 static int ntypes = 6;
24 static string _types[] = {"none", "GasKinetics", "GRI30", "Interface", "Edge", "AqueousKinetics"};
25 static int _itypes[] = {0, cGasKinetics, cGRI30, cInterfaceKinetics, cEdgeKinetics, cAqueousKinetics};
26 
27 /**
28  * Return a new kinetics manager that implements a reaction
29  * mechanism specified in a CTML file. In other words, the
30  * kinetics manager, given the rate constants and formulation of the
31  * reactions that make up a kinetics mechanism, is responsible for
32  * calculating the rates of progress of the reactions and for
33  * calculating the source terms for species.
34  *
35  * Input
36  * ------
37  * phaseData = This is an XML_Node that contains the xml data
38  * describing the phase. Of particular note to this
39  * routine is the child xml element called "kinetics".
40  * The element has one attribute called "model",
41  * with a string value. The value of this string
42  * is used to decide which kinetics manager is used
43  * to calculate the reacton mechanism.
44  *
45  * Return
46  * ---------
47  * Pointer to the new kinetics manager.
48  */
49 
50 Kinetics* KineticsFactory::
51 newKinetics(XML_Node& phaseData, vector<ThermoPhase*> th)
52 {
53  /*
54  * Look for a child of the xml element phase called
55  * "kinetics". It has an attribute name "model".
56  * Store the value of that attribute in the variable kintype
57  */
58  string kintype = phaseData.child("kinetics")["model"];
59  /*
60  * look up the string kintype in the list of known
61  * kinetics managers (list is kept at the top of this file).
62  * Translate it to an integer value, ikin.
63  */
64  int ikin=-1;
65  int n;
66  for (n = 0; n < ntypes; n++) {
67  if (kintype == _types[n]) {
68  ikin = _itypes[n];
69  }
70  }
71  /*
72  * Assign the kinetics manager based on the value of ikin.
73  * Kinetics managers are classes derived from the base
74  * Kinetics class. Unknown kinetics managers will throw a
75  * CanteraError here.
76  */
77  Kinetics* k=0;
78  switch (ikin) {
79 
80  case 0:
81  k = new Kinetics;
82  break;
83 
84  case cGasKinetics:
85  k = new GasKinetics;
86  break;
87 
88  case cGRI30:
89  k = new GRI_30_Kinetics;
90  break;
91 
92  case cInterfaceKinetics:
93  k = new InterfaceKinetics;
94  break;
95 
96  case cEdgeKinetics:
97  k = new EdgeKinetics;
98  break;
99 
100  case cAqueousKinetics:
101  k = new AqueousKinetics;
102  break;
103 
104  default:
105  throw UnknownKineticsModel("KineticsFactory::newKinetics",
106  kintype);
107  }
108 
109  // Now that we have the kinetics manager, we can
110  // import the reaction mechanism into it.
111  importKinetics(phaseData, th, k);
112 
113  // Return the pointer to the kinetics manager
114  return k;
115 }
116 
117 
118 /**
119  * Return a new, empty kinetics manager.
120  */
121 Kinetics* KineticsFactory::newKinetics(string model)
122 {
123 
124  int ikin = -1;
125  int n;
126  for (n = 0; n < ntypes; n++) {
127  if (model == _types[n]) {
128  ikin = _itypes[n];
129  }
130  }
131  Kinetics* k=0;
132  switch (ikin) {
133 
134  case cGasKinetics:
135  k = new GasKinetics;
136  break;
137 
138  case cGRI30:
139  k = new GRI_30_Kinetics;
140  break;
141 
142  case cInterfaceKinetics:
143  k = new InterfaceKinetics;
144  break;
145 
146  default:
147  throw UnknownKineticsModel("KineticsFactory::newKinetics",
148  model);
149  }
150  return k;
151 }
152 
153 }
154