From 4a1d303fe4ca457bc115e8a7ac20f5965dbd9e34 Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Thu, 14 Feb 2008 04:37:43 +0000 Subject: [PATCH] put all C++ interface code in the Cantera_CXX namespace --- Cantera/cxx/include/Edge.h | 2 +- Cantera/cxx/include/GRI30.h | 20 ++++++++++++----- Cantera/cxx/include/IdealGasMix.h | 27 ++++++++++++++--------- Cantera/cxx/include/IncompressibleSolid.h | 19 ++++++++-------- Cantera/cxx/include/Metal.h | 24 ++++++++------------ Cantera/cxx/include/importPhase.h | 13 +++++------ Cantera/cxx/src/importPhase.cpp | 6 ++--- Cantera/cxx/src/writelog.cpp | 10 ++++----- Cantera/src/kinetics/GasKinetics.h | 11 ++++----- Cantera/src/thermo/SurfPhase.h | 9 ++++---- tools/templates/cxx/demo.cpp | 4 +++- 11 files changed, 78 insertions(+), 67 deletions(-) diff --git a/Cantera/cxx/include/Edge.h b/Cantera/cxx/include/Edge.h index 296a34014..8ea710d19 100644 --- a/Cantera/cxx/include/Edge.h +++ b/Cantera/cxx/include/Edge.h @@ -7,7 +7,7 @@ #include "kernel/EdgeKinetics.h" #include "kernel/importKinetics.h" -namespace Cantera { +namespace Cantera_CXX { class Edge : public EdgePhase, public EdgeKinetics diff --git a/Cantera/cxx/include/GRI30.h b/Cantera/cxx/include/GRI30.h index 9edd9da54..63462648b 100644 --- a/Cantera/cxx/include/GRI30.h +++ b/Cantera/cxx/include/GRI30.h @@ -11,20 +11,30 @@ #include "kernel/importKinetics.h" #include "kernel/stringUtils.h" -namespace Cantera { +namespace Cantera_CXX { + /** + * This class is a convenience class for use in C++ programs that + * hard-wires the GRI 3.0 reaction mechanism. It derivees from + * both Cantera::IdealGasPhase, which handles all composition and + * state information, as well as thermodynamic properties, and + * class GRI_30_Kinetics, which is the kinetics manager with + * hard-wired replacements for some of the generic kinetics + * methods like "getNetReactionRates." + */ class GRI30 : - public IdealGasPhase, public GRI_30_Kinetics + public Cantera::IdealGasPhase, + public Cantera::GRI_30_Kinetics { public: GRI30() : m_ok(false), m_r(0) { m_r = get_XML_File("gri30.xml"); - m_ok = buildSolutionFromXML(*m_r, "gri30", "phase", this, this); + m_ok = Cantera::buildSolutionFromXML(*m_r, "gri30", + "phase", this, this); if (!m_ok) throw CanteraError("GRI30", "buildSolutionFromXML returned false"); } - virtual ~GRI30() {} bool operator!() { return !m_ok;} @@ -37,7 +47,7 @@ namespace Cantera { protected: bool m_ok; - XML_Node* m_r; + Cantera::XML_Node* m_r; private: }; diff --git a/Cantera/cxx/include/IdealGasMix.h b/Cantera/cxx/include/IdealGasMix.h index 006a30ac9..bd840fab7 100644 --- a/Cantera/cxx/include/IdealGasMix.h +++ b/Cantera/cxx/include/IdealGasMix.h @@ -8,27 +8,32 @@ #include "kernel/importKinetics.h" #include "kernel/stringUtils.h" -namespace Cantera { +namespace Cantera_CXX { class IdealGasMix : - public IdealGasPhase, public GasKinetics + public Cantera::IdealGasPhase, + public Cantera::GasKinetics { public: IdealGasMix() : m_ok(false), m_r(0) {} - IdealGasMix(std::string infile, std::string id="") : m_ok(false), m_r(0) { + IdealGasMix(std::string infile, std::string id="") : + m_ok(false), m_r(0) { - m_r = get_XML_File(infile); - if (id == "-") id = ""; - m_ok = buildSolutionFromXML(*m_r, id, "phase", this, this); - if (!m_ok) throw CanteraError("IdealGasMix", - "buildSolutionFromXML returned false"); + m_r = Cantera::get_XML_File(infile); + if (id == "-") id = ""; + m_ok = Cantera::buildSolutionFromXML(*m_r, + id, "phase", this, this); + if (!m_ok) throw Cantera::CanteraError("IdealGasMix", + "Cantera::buildSolutionFromXML returned false"); } - IdealGasMix(XML_Node& root, std::string id) : m_ok(false), m_r(0) { - m_ok = buildSolutionFromXML(root, id, "phase", this, this); + IdealGasMix(Cantera::XML_Node& root, + std::string id) : m_ok(false), m_r(0) { + m_ok = Cantera::buildSolutionFromXML(root, id, + "phase", this, this); } virtual ~IdealGasMix() {} @@ -43,7 +48,7 @@ namespace Cantera { protected: bool m_ok; - XML_Node* m_r; + Cantera::XML_Node* m_r; private: }; diff --git a/Cantera/cxx/include/IncompressibleSolid.h b/Cantera/cxx/include/IncompressibleSolid.h index b0160bc78..f9fd3d0b0 100644 --- a/Cantera/cxx/include/IncompressibleSolid.h +++ b/Cantera/cxx/include/IncompressibleSolid.h @@ -6,18 +6,19 @@ #include "kernel/ConstDensityThermo.h" #include "kernel/importKinetics.h" -namespace Cantera { +namespace Cantera_CXX { - class IncompressibleSolid : public ConstDensityThermo + class IncompressibleSolid : public Cantera::ConstDensityThermo { public: - IncompressibleSolid(std::string infile, std::string id="") : m_ok(false), m_r(0) { + IncompressibleSolid(std::string infile, + std::string id="") : m_ok(false), m_r(0) { - m_r = get_XML_File(infile); - if (id == "-") id = ""; - m_ok = buildSolutionFromXML(*m_r, id, "phase", this, 0); - if (!m_ok) throw CanteraError("IncompressibleSolid", - "buildSolutionFromXML returned false"); + m_r = Cantera::get_XML_File(infile); + if (id == "-") id = ""; + m_ok = Cantera::buildSolutionFromXML(*m_r, id, "phase", this, 0); + if (!m_ok) throw Cantera::CanteraError("IncompressibleSolid", + "buildSolutionFromXML returned false"); } @@ -33,7 +34,7 @@ namespace Cantera { protected: bool m_ok; - XML_Node* m_r; + Cantera::XML_Node* m_r; private: }; diff --git a/Cantera/cxx/include/Metal.h b/Cantera/cxx/include/Metal.h index 3beaefb06..3c3b08cc6 100644 --- a/Cantera/cxx/include/Metal.h +++ b/Cantera/cxx/include/Metal.h @@ -6,34 +6,28 @@ #include "kernel/MetalPhase.h" #include "kernel/importKinetics.h" -namespace Cantera { +namespace Cantera_CXX { - class Metal : public MetalPhase + class Metal : public Cantera::MetalPhase { public: Metal(std::string infile, std::string id="") : m_ok(false), m_r(0) { - m_r = get_XML_File(infile); - if (id == "-") id = ""; - m_ok = buildSolutionFromXML(*m_r, id, "phase", this, 0); - if (!m_ok) throw CanteraError("Metal", - "buildSolutionFromXML returned false"); + m_r = Cantera::get_XML_File(infile); + if (id == "-") id = ""; + m_ok = Cantera::buildSolutionFromXML(*m_r, id, "phase", this, 0); + if (!m_ok) throw Cantera::CanteraError("Metal", + "buildSolutionFromXML returned false"); } - - + virtual ~Metal() {} bool operator!() { return !m_ok;} bool ready() const { return m_ok; } - //friend std::ostream& operator<<(std::ostream& s, IdealGasMix& mix) { - // std::string r = Cantera::report(mix, true); - // s << r; - // return s; - protected: bool m_ok; - XML_Node* m_r; + Cantera::XML_Node* m_r; private: }; diff --git a/Cantera/cxx/include/importPhase.h b/Cantera/cxx/include/importPhase.h index 4c51a2c9d..44eb9c4d7 100644 --- a/Cantera/cxx/include/importPhase.h +++ b/Cantera/cxx/include/importPhase.h @@ -11,15 +11,14 @@ * libctxx.a */ -namespace Cantera { - ThermoPhase* importPhase(std::string infile, std::string id=""); +namespace Cantera_CXX { + ThermoPhase* importPhase(std::string infile, std::string id=""); - // -> this is a duplicate of a src/thermo/phasereport function - // We'll leave it here so that these are available externally - std::string report(const ThermoPhase& th, bool show_thermo); + // -> this is a duplicate of a src/thermo/phasereport function + // We'll leave it here so that these are available externally + std::string report(const Cantera::ThermoPhase& th, bool show_thermo); - - std::string formatCompList(const Phase& mix, int xyc); + std::string formatCompList(const Cantera::Phase& mix, int xyc); } diff --git a/Cantera/cxx/src/importPhase.cpp b/Cantera/cxx/src/importPhase.cpp index 90d88ac4a..8c2afd053 100644 --- a/Cantera/cxx/src/importPhase.cpp +++ b/Cantera/cxx/src/importPhase.cpp @@ -8,10 +8,10 @@ #include "ThermoFactory.h" //#include "../include/importPhase.h" -namespace Cantera { +namespace Cantera_CXX { - ThermoPhase* importPhase(std::string infile, std::string id) { - ThermoPhase* p = newPhase(infile, id); + Cantera::ThermoPhase* importPhase(std::string infile, std::string id) { + Cantera::ThermoPhase* p = Cantera::newPhase(infile, id); return p; } } diff --git a/Cantera/cxx/src/writelog.cpp b/Cantera/cxx/src/writelog.cpp index 11f4f452f..43bc904b8 100644 --- a/Cantera/cxx/src/writelog.cpp +++ b/Cantera/cxx/src/writelog.cpp @@ -10,9 +10,9 @@ #include #include -using namespace std; +//using namespace std; -namespace Cantera { +namespace Cantera_CXX { /** * * writelog(): @@ -38,14 +38,14 @@ namespace Cantera { * own versions of writelog. */ void writelog(const string& s) { - cout << s; + std::cout << s; } /** * Write an error message and quit. */ - void error(const string& msg) { - cerr << msg << endl; + void error(const std::string& msg) { + std::cerr << msg << endl; exit(-1); } diff --git a/Cantera/src/kinetics/GasKinetics.h b/Cantera/src/kinetics/GasKinetics.h index 2ee57ca84..b8c3324ef 100755 --- a/Cantera/src/kinetics/GasKinetics.h +++ b/Cantera/src/kinetics/GasKinetics.h @@ -221,11 +221,12 @@ namespace Cantera { */ virtual void getNetProductionRates(doublereal* net) { updateROP(); -#ifdef HWMECH - get_wdot(&m_kdata->m_ropnet[0], net); -#else - m_rxnstoich->getNetProductionRates(m_kk, &m_kdata->m_ropnet[0], net); -#endif + //#ifdef HWMECH + //get_wdot(&m_kdata->m_ropnet[0], net); + //#else + m_rxnstoich->getNetProductionRates(m_kk, + &m_kdata->m_ropnet[0], net); + //#endif } /** diff --git a/Cantera/src/thermo/SurfPhase.h b/Cantera/src/thermo/SurfPhase.h index 46e3c9c9b..690a2808c 100644 --- a/Cantera/src/thermo/SurfPhase.h +++ b/Cantera/src/thermo/SurfPhase.h @@ -24,18 +24,17 @@ namespace Cantera { - //! A simple thermoydnamics model for a surface phase, //! assuming an ideal solution model. /*! - * The surface consists of a grid of equivalent sites. Surface species may be defined to + * The surface consists of a grid of equivalent sites. + * Surface species may be defined to * occupy one or more sites. The surface species are assumed to be * independent, and thus the species form an ideal solution. * - * The density of surface sites is given by the variable \f$ n_0 \f$, which has MKS units - * of kmol m-2. - * + * The density of surface sites is given by the variable \f$ n_0 \f$, + * which has SI units of kmol m-2. * * Specification of Species Standard State Properties * diff --git a/tools/templates/cxx/demo.cpp b/tools/templates/cxx/demo.cpp index 23ad4ba49..7472f2232 100644 --- a/tools/templates/cxx/demo.cpp +++ b/tools/templates/cxx/demo.cpp @@ -20,11 +20,13 @@ #include // transport properties -// All Cantera names are in namespace Cantera. You can either +// All Cantera kernel names are in namespace Cantera. You can either // reference everything as Cantera::, or include the following // 'using namespace' line. using namespace Cantera; +using namespace Cantera_CXX; +// All Cantera C++ interface names are in namespace Cantera_CXX // The program is put into a function so that error handling code can // be conveniently put around the whole thing. See main() below.