Skip to content

Commit

Permalink
[Kinetics] Replace numerical constants for Kinetics types with strings
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Jul 8, 2016
1 parent 3b0cf9f commit 7f21aa0
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 19 deletions.
6 changes: 6 additions & 0 deletions include/cantera/kinetics/AqueousKinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ class AqueousKinetics : public BulkKinetics
virtual Kinetics* duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector) const;

virtual int type() const {
warn_deprecated("AqueousKinetics::type",
"To be removed after Cantera 2.3.");
return cAqueousKinetics;
}

virtual std::string kineticsType() const {
return "Aqueous";
}

virtual void getEquilibriumConstants(doublereal* kc);
virtual void getFwdRateConstants(doublereal* kfwd);
void updateROP();
Expand Down
6 changes: 6 additions & 0 deletions include/cantera/kinetics/EdgeKinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ class EdgeKinetics : public InterfaceKinetics
}

virtual int type() const {
warn_deprecated("EdgeKinetics::type",
"To be removed after Cantera 2.3.");
return cEdgeKinetics;
}

virtual std::string kineticsType() const {
return "Edge";
}
};
}

Expand Down
6 changes: 6 additions & 0 deletions include/cantera/kinetics/GasKinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ class GasKinetics : public BulkKinetics
virtual Kinetics* duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector) const;

virtual int type() const {
warn_deprecated("GasKinetics::type",
"To be removed after Cantera 2.3.");
return cGasKinetics;
}

virtual std::string kineticsType() const {
return "Gas";
}

//! @}
//! @name Reaction Rates Of Progress
//! @{
Expand Down
4 changes: 4 additions & 0 deletions include/cantera/kinetics/InterfaceKinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class InterfaceKinetics : public Kinetics

virtual int type() const;

virtual std::string kineticsType() const {
return "Surf";
}

//! Set the electric potential in the nth phase
/*!
* @param n phase Index in this kinetics object.
Expand Down
9 changes: 9 additions & 0 deletions include/cantera/kinetics/Kinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,18 @@ class Kinetics
/*!
* Each class derived from Kinetics should overload this method to return
* a unique integer. Standard values are defined in file mix_defs.h.
* @deprecated Use kineticsType() instead. To be removed after Cantera
* 2.3.
*/
virtual int type() const;

//! Identifies the Kinetics manager type.
//! Each class derived from Kinetics should override this method to return
//! a meaningful identifier.
virtual std::string kineticsType() const {
return "Kinetics";
}

//! Number of reactions in the reaction mechanism.
size_t nReactions() const {
return m_reactions.size();
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/thermo/mix_defs.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! @file mix_defs.h
//! @deprecated All of the constants defined in this header are no longer used.
//! To be removed after Cantera 2.3.
#ifndef CT_MIX_DEFS_H
#define CT_MIX_DEFS_H

Expand Down Expand Up @@ -135,6 +137,7 @@ enum VPSSMgr_enumType {


// kinetic manager types
// @deprecated To be removed after Cantera 2.3.
const int cGasKinetics = 2;
const int cInterfaceKinetics = 4;
const int cLineKinetics = 5;
Expand Down
8 changes: 1 addition & 7 deletions interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ cdef extern from "cantera/base/global.h" namespace "Cantera":
cdef XML_Node* CxxGetXmlFromString "Cantera::get_XML_from_string" (string) except +
cdef void Cxx_make_deprecation_warnings_fatal "Cantera::make_deprecation_warnings_fatal" ()

cdef extern from "cantera/thermo/mix_defs.h":
cdef int kinetics_type_gas "Cantera::cGasKinetics"
cdef int kinetics_type_interface "Cantera::cInterfaceKinetics"
cdef int kinetics_type_edge "Cantera::cEdgeKinetics"


cdef extern from "cantera/cython/funcWrapper.h":
ctypedef double (*callback_wrapper)(double, void*, void**)
cdef int translate_exception()
Expand Down Expand Up @@ -342,7 +336,7 @@ cdef extern from "cantera/kinetics/FalloffFactory.h" namespace "Cantera":
cdef extern from "cantera/kinetics/Kinetics.h" namespace "Cantera":
cdef cppclass CxxKinetics "Cantera::Kinetics":
CxxKinetics()
int type()
string kineticsType()
int nTotalSpecies()
int nReactions()
int nPhases()
Expand Down
3 changes: 1 addition & 2 deletions interfaces/cython/cantera/kinetics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,7 @@ cdef class InterfaceKinetics(Kinetics):
"""
def __init__(self, infile='', phaseid='', phases=(), *args, **kwargs):
super().__init__(infile, phaseid, phases, *args, **kwargs)
if self.kinetics.type() not in (kinetics_type_interface,
kinetics_type_edge):
if pystr(self.kinetics.kineticsType()) not in ("Surf", "Edge"):
raise TypeError("Underlying Kinetics class is not of the correct type.")

self._phase_indices = {}
Expand Down
3 changes: 1 addition & 2 deletions interfaces/cython/cantera/onedim.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ cdef class ReactingSurface1D(Boundary1D):

def set_kinetics(self, Kinetics kin):
"""Set the kinetics manager (surface reaction mechanism object)."""
if kin.kinetics.type() not in (kinetics_type_interface,
kinetics_type_edge):
if pystr(kin.kinetics.kineticsType()) not in ("Surf", "Edge"):
raise TypeError('Kinetics object must be derived from '
'InterfaceKinetics.')
self.surf.setKineticsMgr(<CxxInterfaceKinetics*>kin.kinetics)
Expand Down
2 changes: 1 addition & 1 deletion src/fortran/fct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ extern "C" {
{
try {
Kinetics* k = _fkin(n);
if (k->type() == cInterfaceKinetics) {
if (k->kineticsType() == "Surf" || k->kineticsType() == "Edge") {
((InterfaceKinetics*)k)->advanceCoverages(*tstep);
} else {
throw CanteraError("kin_advanceCoverages",
Expand Down
2 changes: 2 additions & 0 deletions src/kinetics/InterfaceKinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ InterfaceKinetics& InterfaceKinetics::operator=(const InterfaceKinetics& right)

int InterfaceKinetics::type() const
{
warn_deprecated("InterfaceKinetics::type",
"To be removed after Cantera 2.3.");
return cInterfaceKinetics;
}

Expand Down
9 changes: 2 additions & 7 deletions src/kinetics/Kinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Kinetics* Kinetics::duplMyselfAsKinetics(const std::vector<thermo_t*> & tpVector

int Kinetics::type() const
{
warn_deprecated("Kinetics::type", "To be removed after Cantera 2.3.");
return 0;
}

Expand Down Expand Up @@ -485,13 +486,7 @@ void Kinetics::addPhase(thermo_t& thermo)
}

// there should only be one surface phase
string ptype;
if (type() == cEdgeKinetics) {
ptype = "Edge";
} else if (type() == cInterfaceKinetics) {
ptype = "Surf";
}
if (thermo.type() == ptype) {
if (thermo.type() == kineticsType()) {
m_surfphase = nPhases();
m_rxnphase = nPhases();
}
Expand Down

0 comments on commit 7f21aa0

Please sign in to comment.