[Kinetics] Refactor KineticsFactory::newKinetics
Eliminate redundant implementations, eliminate unnecessary static arrays, and fix cases which were missing in the newKinetics(string) version.
This commit is contained in:
parent
25953f94d4
commit
3ad02817c5
1 changed files with 15 additions and 72 deletions
|
|
@ -20,10 +20,6 @@ namespace Cantera
|
|||
KineticsFactory* KineticsFactory::s_factory = 0;
|
||||
mutex_t KineticsFactory::kinetics_mutex;
|
||||
|
||||
static int ntypes = 5;
|
||||
static string _types[] = {"none", "GasKinetics", "Interface", "Edge", "AqueousKinetics"};
|
||||
static int _itypes[] = {0, cGasKinetics, cInterfaceKinetics, cEdgeKinetics, cAqueousKinetics};
|
||||
|
||||
Kinetics* KineticsFactory::newKinetics(XML_Node& phaseData,
|
||||
vector<ThermoPhase*> th)
|
||||
{
|
||||
|
|
@ -33,52 +29,9 @@ Kinetics* KineticsFactory::newKinetics(XML_Node& phaseData,
|
|||
* Store the value of that attribute in the variable kintype
|
||||
*/
|
||||
string kintype = phaseData.child("kinetics")["model"];
|
||||
/*
|
||||
* look up the string kintype in the list of known
|
||||
* kinetics managers (list is kept at the top of this file).
|
||||
* Translate it to an integer value, ikin.
|
||||
*/
|
||||
int ikin=-1;
|
||||
int n;
|
||||
for (n = 0; n < ntypes; n++) {
|
||||
if (kintype == _types[n]) {
|
||||
ikin = _itypes[n];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Assign the kinetics manager based on the value of ikin.
|
||||
* Kinetics managers are classes derived from the base
|
||||
* Kinetics class. Unknown kinetics managers will throw a
|
||||
* CanteraError here.
|
||||
*/
|
||||
Kinetics* k=0;
|
||||
switch (ikin) {
|
||||
|
||||
case 0:
|
||||
k = new Kinetics;
|
||||
break;
|
||||
|
||||
case cGasKinetics:
|
||||
k = new GasKinetics;
|
||||
break;
|
||||
|
||||
case cInterfaceKinetics:
|
||||
k = new InterfaceKinetics;
|
||||
break;
|
||||
|
||||
case cEdgeKinetics:
|
||||
k = new EdgeKinetics;
|
||||
break;
|
||||
|
||||
case cAqueousKinetics:
|
||||
k = new AqueousKinetics;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw UnknownKineticsModel("KineticsFactory::newKinetics",
|
||||
kintype);
|
||||
}
|
||||
|
||||
// Create a kinetics object of the desired type
|
||||
Kinetics* k = newKinetics(kintype);
|
||||
// Now that we have the kinetics manager, we can
|
||||
// import the reaction mechanism into it.
|
||||
importKinetics(phaseData, th, k);
|
||||
|
|
@ -89,30 +42,20 @@ Kinetics* KineticsFactory::newKinetics(XML_Node& phaseData,
|
|||
|
||||
Kinetics* KineticsFactory::newKinetics(const string& model)
|
||||
{
|
||||
|
||||
int ikin = -1;
|
||||
int n;
|
||||
for (n = 0; n < ntypes; n++) {
|
||||
if (model == _types[n]) {
|
||||
ikin = _itypes[n];
|
||||
}
|
||||
string lcmodel = lowercase(model);
|
||||
if (lcmodel == "none") {
|
||||
return new Kinetics();
|
||||
} else if (lcmodel == "gaskinetics") {
|
||||
return new GasKinetics();
|
||||
} else if (lcmodel == "interface") {
|
||||
return new InterfaceKinetics();
|
||||
} else if (lcmodel == "edge") {
|
||||
return new EdgeKinetics();
|
||||
} else if (lcmodel == "aqueouskinetics") {
|
||||
return new AqueousKinetics();
|
||||
} else {
|
||||
throw UnknownKineticsModel("KineticsFactory::newKinetics", model);
|
||||
}
|
||||
Kinetics* k=0;
|
||||
switch (ikin) {
|
||||
|
||||
case cGasKinetics:
|
||||
k = new GasKinetics;
|
||||
break;
|
||||
|
||||
case cInterfaceKinetics:
|
||||
k = new InterfaceKinetics;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw UnknownKineticsModel("KineticsFactory::newKinetics",
|
||||
model);
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue