From 3b1694fdfbcfc57554f0ce7b1a0b1c28b3a7575c Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 27 Feb 2012 18:12:00 +0000 Subject: [PATCH] Class Storage has been eliminated in favor of class Cabinet --- interfaces/python/Cantera/ThermoPhase.py | 3 - src/base/misc.cpp | 1 - src/clib/Storage.cpp | 147 -------- src/clib/Storage.h | 77 ---- src/clib/ct.cpp | 436 +++++++++++------------ src/clib/ctbdry.cpp | 24 +- src/clib/ctmultiphase.cpp | 9 +- src/clib/ctonedim.cpp | 43 +-- src/clib/ctreactor.cpp | 26 +- src/clib/ctrpath.cpp | 12 +- src/clib/ctsurf.cpp | 6 +- src/clib/ctxml.cpp | 4 - src/fortran/fct.cpp | 31 +- src/python/ctthermo_methods.cpp | 10 - src/python/methods.h | 1 - 15 files changed, 249 insertions(+), 581 deletions(-) delete mode 100644 src/clib/Storage.cpp delete mode 100644 src/clib/Storage.h diff --git a/interfaces/python/Cantera/ThermoPhase.py b/interfaces/python/Cantera/ThermoPhase.py index 4d7dd79b6..1fa4d0079 100644 --- a/interfaces/python/Cantera/ThermoPhase.py +++ b/interfaces/python/Cantera/ThermoPhase.py @@ -8,9 +8,6 @@ from Cantera.Phase import Phase import _cantera import types -def thermoIndex(id): - return _cantera.thermo_thermoIndex(id) - class ThermoPhase(Phase): """ A phase with an equation of state. diff --git a/src/base/misc.cpp b/src/base/misc.cpp index 1957b462a..a428d8a0e 100644 --- a/src/base/misc.cpp +++ b/src/base/misc.cpp @@ -22,7 +22,6 @@ #include "cantera/base/FactoryBase.h" #include "cantera/base/logger.h" - #include #include diff --git a/src/clib/Storage.cpp b/src/clib/Storage.cpp deleted file mode 100644 index dedfb4749..000000000 --- a/src/clib/Storage.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/** - * @file Storage.cpp - */ -// Cantera includes -#include "cantera/kinetics/Kinetics.h" -#include "cantera/transport/TransportFactory.h" - -#include "Storage.h" - -using namespace std; -using namespace Cantera; - - -Storage::Storage() -{ - addThermo(new ThermoPhase); - addKinetics(new Kinetics); - addTransport(newTransportMgr()); -} - -Storage::~Storage() -{ - clear(); -} - -size_t Storage::addThermo(thermo_t* th) -{ - if (th->index() != npos) { - return th->index(); - } - __thtable.push_back(th); - size_t n = __thtable.size() - 1; - th->setIndex(n); - //string id = th->id(); - //if (__thmap.count(id) == 0) { - // __thmap[id] = n; - // th->setID(id); - //} - //else { - // throw CanteraError("Storage::addThermo","id already used"); - // return -1; - //} - return n; -} - -size_t Storage::nThermo() -{ - return __thtable.size(); -} - -size_t Storage::addKinetics(Kinetics* kin) -{ - if (kin->index() != npos) { - return kin->index(); - } - __ktable.push_back(kin); - size_t n = __ktable.size() - 1; - kin->setIndex(n); - return n; -} - -size_t Storage::addTransport(Transport* tr) -{ - if (tr->index() != npos) { - return tr->index(); - } - __trtable.push_back(tr); - size_t n = __trtable.size() - 1; - tr->setIndex(n); - return n; -} - -// int Storage::addNewTransport(int model, char* dbase, int th, -// int loglevel) { -// try { -// ThermoPhase* thrm = __thtable[th]; -// Transport* tr = newTransportMgr(model, -// string(dbase), thrm, loglevel); -// __trtable.push_back(tr); -// return __trtable.size() - 1; -// } -// catch (CanteraError) {return -1;} -// catch (...) {return ERR;} -// } - -int Storage::clear() -{ - size_t i, n; - n = __thtable.size(); - for (i = 1; i < n; i++) { - if (__thtable[i] != __thtable[0]) { - delete __thtable[i]; - __thtable[i] = __thtable[0]; - } - } - n = __ktable.size(); - for (i = 1; i < n; i++) { - if (__ktable[i] != __ktable[0]) { - delete __ktable[i]; - __ktable[i] = __ktable[0]; - } - } - n = __trtable.size(); - for (i = 1; i < n; i++) { - if (__trtable[i] != __trtable[0]) { - delete __trtable[i]; - __trtable[i] = __trtable[0]; - } - } - return 0; -} - -void Storage::deleteKinetics(int n) -{ - if (n == 0) { - return; - } - if (__ktable[n] != __ktable[0]) { - delete __ktable[n]; - } - __ktable[n] = __ktable[0]; -} - -void Storage::deleteThermo(int n) -{ - if (n == 0) { - return; - } - if (n < 0 || n >= (int) __thtable.size()) { - throw CanteraError("deleteThermo","illegal index"); - } - __thtable[n] = __thtable[0]; -} - -void Storage::deleteTransport(int n) -{ - if (n == 0) { - return; - } - if (__trtable[n] != __trtable[0]) { - delete __trtable[n]; - } - __trtable[n] = __trtable[0]; -} - -Storage* Storage::__storage = 0; - diff --git a/src/clib/Storage.h b/src/clib/Storage.h deleted file mode 100644 index d9fddab49..000000000 --- a/src/clib/Storage.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * @file Storage.h - */ -#ifndef CTC_STORAGE_H -#define CTC_STORAGE_H - -// Cantera includes -#include "cantera/kinetics/Kinetics.h" -#include "cantera/transport/TransportBase.h" - -#include "Cabinet.h" -#include "clib_defs.h" - - -/** - * Class to hold pointers to Cantera objects. Only one instance of - * this class is needed. - */ -class Storage -{ -public: - Storage(); - virtual ~Storage(); - - // vectors to hold pointers to objects - std::vector __ktable; - std::vector __thtable; - std::vector __trtable; - - std::map __thmap; - - static Storage* storage() { - if (__storage == 0) { - __storage = new Storage; - } - return __storage; - } - - - size_t addThermo(Cantera::ThermoPhase* th); - size_t addKinetics(Cantera::Kinetics* kin); - size_t addTransport(Cantera::Transport* tr); - // int addNewTransport(int model, char* dbase, int th, int loglevel); - int clear(); - void deleteKinetics(int n); - void deleteThermo(int n); - void deleteTransport(int n); - size_t nThermo(); - static Storage* __storage; -}; - -inline Cantera::ThermoPhase* ph(int n) -{ - return Storage::__storage->__thtable[n]; -} - -inline Cantera::Kinetics* kin(int n) -{ - return Storage::__storage->__ktable[n]; -} - -inline Cantera::ThermoPhase* th(size_t n) -{ - return Storage::__storage->__thtable[n]; -} - -inline int thermo_index(std::string id) -{ - return Storage::__storage->__thmap[id]; -} - -inline Cantera::Transport* trans(int n) -{ - return Storage::__storage->__trtable[n]; -} - -#endif diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index db04d361d..b88499450 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -19,12 +19,10 @@ #include "cantera/kinetics/importKinetics.h" #include "cantera/thermo/ThermoFactory.h" #include "converters/ck2ct.h" -#include "Storage.h" #include "Cabinet.h" #include "cantera/kinetics/InterfaceKinetics.h" #include "cantera/thermo/PureFluidPhase.h" - using namespace std; using namespace Cantera; @@ -32,15 +30,22 @@ using namespace Cantera; #include "windows.h" #endif +typedef Cabinet ThermoCabinet; +typedef Cabinet KineticsCabinet; +typedef Cabinet TransportCabinet; typedef Cabinet XmlCabinet; +template<> ThermoCabinet* ThermoCabinet::__storage = 0; +template<> KineticsCabinet* KineticsCabinet::__storage = 0; +template<> TransportCabinet* TransportCabinet::__storage = 0; + #ifdef WITH_PURE_FLUIDS static PureFluidPhase* purefluid(int n) { try { - ThermoPhase* tp = th(n); - if (tp->eosType() == cPureFluid) { - return (PureFluidPhase*)tp; + ThermoPhase& tp = ThermoCabinet::item(n); + if (tp.eosType() == cPureFluid) { + return dynamic_cast(&tp); } else { throw CanteraError("purefluid","object is not a PureFluidPhase object"); } @@ -92,11 +97,6 @@ static double pfprop(int n, int i, double v=0.0, double x=0.0) #endif -inline size_t nThermo() -{ - return Storage::storage()->nThermo(); -} - namespace Cantera { void writephase(const ThermoPhase& th, bool show_thermo); @@ -143,23 +143,23 @@ extern "C" { size_t DLL_EXPORT phase_nElements(int n) { - return ph(n)->nElements(); + return ThermoCabinet::item(n).nElements(); } size_t DLL_EXPORT phase_nSpecies(int n) { - return ph(n)->nSpecies(); + return ThermoCabinet::item(n).nSpecies(); } doublereal DLL_EXPORT phase_temperature(int n) { - return ph(n)->temperature(); + return ThermoCabinet::item(n).temperature(); } int DLL_EXPORT phase_setTemperature(int n, double t) { try { - ph(n)->setTemperature(t); + ThermoCabinet::item(n).setTemperature(t); } catch (CanteraError) { return -1; } @@ -168,7 +168,7 @@ extern "C" { doublereal DLL_EXPORT phase_density(int n) { - return ph(n)->density(); + return ThermoCabinet::item(n).density(); } int DLL_EXPORT phase_setDensity(int n, double rho) @@ -176,13 +176,13 @@ extern "C" { if (rho < 0.0) { return -1; } - ph(n)->setDensity(rho); + ThermoCabinet::item(n).setDensity(rho); return 0; } doublereal DLL_EXPORT phase_molarDensity(int n) { - return ph(n)->molarDensity(); + return ThermoCabinet::item(n).molarDensity(); } int DLL_EXPORT phase_setMolarDensity(int n, double ndens) @@ -190,32 +190,32 @@ extern "C" { if (ndens < 0.0) { return -1; } - ph(n)->setMolarDensity(ndens); + ThermoCabinet::item(n).setMolarDensity(ndens); return 0; } doublereal DLL_EXPORT phase_meanMolecularWeight(int n) { - return ph(n)->meanMolecularWeight(); + return ThermoCabinet::item(n).meanMolecularWeight(); } size_t DLL_EXPORT phase_elementIndex(int n, char* nm) { string elnm = string(nm); - return ph(n)->elementIndex(elnm); + return ThermoCabinet::item(n).elementIndex(elnm); } size_t DLL_EXPORT phase_speciesIndex(int n, char* nm) { string spnm = string(nm); - return ph(n)->speciesIndex(spnm); + return ThermoCabinet::item(n).speciesIndex(spnm); } int DLL_EXPORT phase_getMoleFractions(int n, size_t lenx, double* x) { - ThermoPhase* p = ph(n); - if (lenx >= p->nSpecies()) { - p->getMoleFractions(x); + ThermoPhase& p = ThermoCabinet::item(n); + if (lenx >= p.nSpecies()) { + p.getMoleFractions(x); return 0; } else { return -1; @@ -224,15 +224,14 @@ extern "C" { doublereal DLL_EXPORT phase_moleFraction(int n, size_t k) { - ThermoPhase* p = ph(n); - return p->moleFraction(k); + return ThermoCabinet::item(n).moleFraction(k); } int DLL_EXPORT phase_getMassFractions(int n, size_t leny, double* y) { - ThermoPhase* p = ph(n); - if (leny >= p->nSpecies()) { - p->getMassFractions(y); + ThermoPhase& p = ThermoCabinet::item(n); + if (leny >= p.nSpecies()) { + p.getMassFractions(y); return 0; } else { return -1; @@ -241,18 +240,17 @@ extern "C" { doublereal DLL_EXPORT phase_massFraction(int n, size_t k) { - ThermoPhase* p = ph(n); - return p->massFraction(k); + return ThermoCabinet::item(n).massFraction(k); } int DLL_EXPORT phase_setMoleFractions(int n, size_t lenx, double* x, int norm) { - ThermoPhase* p = ph(n); - if (lenx >= p->nSpecies()) { + ThermoPhase& p = ThermoCabinet::item(n); + if (lenx >= p.nSpecies()) { if (norm) { - p->setMoleFractions(x); + p.setMoleFractions(x); } else { - p->setMoleFractions_NoNorm(x); + p.setMoleFractions_NoNorm(x); } return 0; } else { @@ -263,14 +261,14 @@ extern "C" { int DLL_EXPORT phase_setMoleFractionsByName(int n, char* x) { try { - ThermoPhase* p = ph(n); + ThermoPhase& p = ThermoCabinet::item(n); compositionMap xx; - size_t nsp = p->nSpecies(); + size_t nsp = p.nSpecies(); for (size_t n = 0; n < nsp; n++) { - xx[p->speciesName(n)] = -1; + xx[p.speciesName(n)] = -1; } parseCompString(string(x), xx); - p->setMoleFractionsByName(xx); + p.setMoleFractionsByName(xx); return 0; } catch (CanteraError) { return -1; @@ -281,12 +279,12 @@ extern "C" { int DLL_EXPORT phase_setMassFractions(int n, size_t leny, double* y, int norm) { - ThermoPhase* p = ph(n); - if (leny >= p->nSpecies()) { + ThermoPhase& p = ThermoCabinet::item(n); + if (leny >= p.nSpecies()) { if (norm) { - p->setMassFractions(y); + p.setMassFractions(y); } else { - p->setMassFractions_NoNorm(y); + p.setMassFractions_NoNorm(y); } return 0; } else { @@ -297,14 +295,14 @@ extern "C" { int DLL_EXPORT phase_setMassFractionsByName(int n, char* y) { try { - ThermoPhase* p = ph(n); + ThermoPhase& p = ThermoCabinet::item(n); compositionMap yy; - size_t nsp = p->nSpecies(); + size_t nsp = p.nSpecies(); for (size_t n = 0; n < nsp; n++) { - yy[p->speciesName(n)] = -1; + yy[p.speciesName(n)] = -1; } parseCompString(string(y), yy); - p->setMassFractionsByName(yy); + p.setMassFractionsByName(yy); return 0; } catch (CanteraError) { return -1; @@ -314,9 +312,9 @@ extern "C" { int DLL_EXPORT phase_getAtomicWeights(int n, size_t lenm, double* atw) { - ThermoPhase* p = ph(n); - if (lenm >= p->nElements()) { - const vector_fp& wt = p->atomicWeights(); + ThermoPhase& p = ThermoCabinet::item(n); + if (lenm >= p.nElements()) { + const vector_fp& wt = p.atomicWeights(); copy(wt.begin(), wt.end(), atw); return 0; } else { @@ -327,9 +325,9 @@ extern "C" { int DLL_EXPORT phase_getMolecularWeights(int n, size_t lenm, double* mw) { - ThermoPhase* p = ph(n); - if (lenm >= p->nSpecies()) { - const vector_fp& wt = p->molecularWeights(); + ThermoPhase& p = ThermoCabinet::item(n); + if (lenm >= p.nSpecies()) { + const vector_fp& wt = p.molecularWeights(); copy(wt.begin(), wt.end(), mw); return 0; } else { @@ -339,7 +337,7 @@ extern "C" { int DLL_EXPORT phase_getName(int n, size_t lennm, char* nm) { - string name = ph(n)->name(); + string name = ThermoCabinet::item(n).name(); size_t lout = min(lennm, name.size()); copy(name.c_str(), name.c_str() + lout, nm); nm[lout] = '\0'; @@ -349,14 +347,14 @@ extern "C" { int DLL_EXPORT phase_setName(int n, const char* nm) { string name = string(nm); - ph(n)->setName(name); + ThermoCabinet::item(n).setName(name); return 0; } int DLL_EXPORT phase_getSpeciesName(int n, size_t k, size_t lennm, char* nm) { try { - string spnm = ph(n)->speciesName(k); + string spnm = ThermoCabinet::item(n).speciesName(k); size_t lout = min(lennm, spnm.size()); copy(spnm.c_str(), spnm.c_str() + lout, nm); nm[lout] = '\0'; @@ -370,7 +368,7 @@ extern "C" { int DLL_EXPORT phase_getElementName(int n, size_t m, size_t lennm, char* nm) { try { - string elnm = ph(n)->elementName(m); + string elnm = ThermoCabinet::item(n).elementName(m); size_t lout = min(lennm, elnm.size()); copy(elnm.c_str(), elnm.c_str() + lout, nm); nm[lout] = '\0'; @@ -384,7 +382,7 @@ extern "C" { doublereal DLL_EXPORT phase_nAtoms(int n, size_t k, size_t m) { try { - return ph(n)->nAtoms(k,m); + return ThermoCabinet::item(n).nAtoms(k,m); } catch (CanteraError) { return -1; } @@ -393,7 +391,7 @@ extern "C" { int DLL_EXPORT phase_addElement(int n, char* name, doublereal weight) { try { - ph(n)->addElement(string(name),weight); + ThermoCabinet::item(n).addElement(string(name),weight); return 0; } catch (CanteraError) { return -1; @@ -422,53 +420,31 @@ extern "C" { //-------------- Thermo --------------------// - // int DLL_EXPORT newThermo(int eos, int ph, int sptherm) { - // return Storage::storage()->addNewThermo(eos, ph, sptherm); - // } - - int DLL_EXPORT th_thermoIndex(char* id) - { - return thermo_index(id); - } - - // int DLL_EXPORT newThermo(char* model) { - // try { - // string m = string(model); - // thermo_t* th = newThermoPhase(m); - // return Storage::storage()->addThermo(th); - // } - // catch (CanteraError) { return -1; } - // } - size_t DLL_EXPORT newThermoFromXML(int mxml) { try { XML_Node& x = XmlCabinet::item(mxml); thermo_t* th = newPhase(x); - return Storage::storage()->addThermo(th); + return ThermoCabinet::add(th); } catch (CanteraError) { return -1; } } - //int DLL_EXPORT th_phase(int n) { - // return th(n)->phase().index(); - // } - size_t DLL_EXPORT th_nSpecies(size_t n) { - return th(n)->nSpecies(); + return ThermoCabinet::item(n).nSpecies(); } int DLL_EXPORT th_eosType(int n) { - return th(n)->eosType(); + return ThermoCabinet::item(n).eosType(); } double DLL_EXPORT th_enthalpy_mole(int n) { try { - return th(n)->enthalpy_mole(); + return ThermoCabinet::item(n).enthalpy_mole(); } catch (CanteraError) { return DERR; } @@ -477,7 +453,7 @@ extern "C" { double DLL_EXPORT th_intEnergy_mole(int n) { try { - return th(n)->intEnergy_mole(); + return ThermoCabinet::item(n).intEnergy_mole(); } catch (CanteraError) { return DERR; } @@ -486,7 +462,7 @@ extern "C" { double DLL_EXPORT th_entropy_mole(int n) { try { - return th(n)->entropy_mole(); + return ThermoCabinet::item(n).entropy_mole(); } catch (CanteraError) { return DERR; } @@ -495,7 +471,7 @@ extern "C" { double DLL_EXPORT th_gibbs_mole(int n) { try { - return th(n)->gibbs_mole(); + return ThermoCabinet::item(n).gibbs_mole(); } catch (CanteraError) { return DERR; } @@ -504,7 +480,7 @@ extern "C" { double DLL_EXPORT th_cp_mole(int n) { try { - return th(n)->cp_mole(); + return ThermoCabinet::item(n).cp_mole(); } catch (CanteraError) { return DERR; } @@ -513,7 +489,7 @@ extern "C" { double DLL_EXPORT th_cv_mole(int n) { try { - return th(n)->cv_mole(); + return ThermoCabinet::item(n).cv_mole(); } catch (CanteraError) { return DERR; } @@ -522,7 +498,7 @@ extern "C" { double DLL_EXPORT th_pressure(int n) { try { - return th(n)->pressure(); + return ThermoCabinet::item(n).pressure(); } catch (CanteraError) { return DERR; } @@ -531,7 +507,7 @@ extern "C" { double DLL_EXPORT th_enthalpy_mass(int n) { try { - return th(n)->enthalpy_mass(); + return ThermoCabinet::item(n).enthalpy_mass(); } catch (CanteraError) { return DERR; } @@ -540,7 +516,7 @@ extern "C" { double DLL_EXPORT th_intEnergy_mass(int n) { try { - return th(n)->intEnergy_mass(); + return ThermoCabinet::item(n).intEnergy_mass(); } catch (CanteraError) { return DERR; } @@ -549,7 +525,7 @@ extern "C" { double DLL_EXPORT th_entropy_mass(int n) { try { - return th(n)->entropy_mass(); + return ThermoCabinet::item(n).entropy_mass(); } catch (CanteraError) { return DERR; } @@ -558,7 +534,7 @@ extern "C" { double DLL_EXPORT th_gibbs_mass(int n) { try { - return th(n)->gibbs_mass(); + return ThermoCabinet::item(n).gibbs_mass(); } catch (CanteraError) { return DERR; } @@ -567,7 +543,7 @@ extern "C" { double DLL_EXPORT th_cp_mass(int n) { try { - return th(n)->cp_mass(); + return ThermoCabinet::item(n).cp_mass(); } catch (CanteraError) { return DERR; } @@ -576,7 +552,7 @@ extern "C" { double DLL_EXPORT th_cv_mass(int n) { try { - return th(n)->cv_mass(); + return ThermoCabinet::item(n).cv_mass(); } catch (CanteraError) { return DERR; } @@ -585,7 +561,7 @@ extern "C" { double DLL_EXPORT th_electricPotential(int n) { try { - return th(n)->electricPotential(); + return ThermoCabinet::item(n).electricPotential(); } catch (CanteraError) { return DERR; } @@ -593,10 +569,10 @@ extern "C" { int DLL_EXPORT th_chemPotentials(int n, size_t lenm, double* murt) { - thermo_t* thrm = th(n); - size_t nsp = thrm->nSpecies(); + ThermoPhase& thrm = ThermoCabinet::item(n); + size_t nsp = thrm.nSpecies(); if (lenm >= nsp) { - thrm->getChemPotentials(murt); + thrm.getChemPotentials(murt); return 0; } else { return -10; @@ -605,11 +581,11 @@ extern "C" { int DLL_EXPORT th_elementPotentials(int n, size_t lenm, double* lambda) { - thermo_t* thrm = th(n); - size_t nel = thrm->nElements(); + ThermoPhase& thrm = ThermoCabinet::item(n); + size_t nel = thrm.nElements(); if (lenm >= nel) { - equilibrate(*thrm, "TP", 0); - thrm->getElementPotentials(lambda); + equilibrate(thrm, "TP", 0); + thrm.getElementPotentials(lambda); return 0; } else { return -10; @@ -621,7 +597,7 @@ extern "C" { try { if (p < 0.0) throw CanteraError("th_setPressure", "pressure cannot be negative"); - th(n)->setPressure(p); + ThermoCabinet::item(n).setPressure(p); return 0; } catch (CanteraError) { return -1; @@ -634,8 +610,8 @@ extern "C" { if (vals[1] < 0.0) throw CanteraError("th_set_HP", "pressure cannot be negative"); - th(n)->setState_HP(vals[0],vals[1]); - if (th(n)->temperature() < 0.0) + ThermoCabinet::item(n).setState_HP(vals[0],vals[1]); + if (ThermoCabinet::item(n).temperature() < 0.0) throw CanteraError("th_set_HP", "temperature cannot be negative"); return 0; @@ -650,8 +626,8 @@ extern "C" { if (vals[1] < 0.0) throw CanteraError("th_set_UV", "specific volume cannot be negative"); - th(n)->setState_UV(vals[0],vals[1]); - if (th(n)->temperature() < 0.0) + ThermoCabinet::item(n).setState_UV(vals[0],vals[1]); + if (ThermoCabinet::item(n).temperature() < 0.0) throw CanteraError("th_set_UV", "temperature cannot be negative"); return 0; @@ -663,7 +639,7 @@ extern "C" { int DLL_EXPORT th_set_SV(int n, double* vals) { try { - th(n)->setState_SV(vals[0],vals[1]); + ThermoCabinet::item(n).setState_SV(vals[0],vals[1]); return 0; } catch (CanteraError) { return -1; @@ -673,7 +649,7 @@ extern "C" { int DLL_EXPORT th_set_SP(int n, double* vals) { try { - th(n)->setState_SP(vals[0],vals[1]); + ThermoCabinet::item(n).setState_SP(vals[0],vals[1]); return 0; } catch (CanteraError) { return -1; @@ -684,7 +660,7 @@ extern "C" { double rtol, int maxsteps, int maxiter, int loglevel) { try { - equilibrate(*th(n), XY, solver, rtol, maxsteps, + equilibrate(ThermoCabinet::item(n), XY, solver, rtol, maxsteps, maxiter, loglevel); return 0; } catch (CanteraError) { @@ -694,27 +670,27 @@ extern "C" { doublereal DLL_EXPORT th_refPressure(int n) { - return th(n)->refPressure(); + return ThermoCabinet::item(n).refPressure(); } doublereal DLL_EXPORT th_minTemp(int n, int k) { - return th(n)->minTemp(k); + return ThermoCabinet::item(n).minTemp(k); } doublereal DLL_EXPORT th_maxTemp(int n, int k) { - return th(n)->maxTemp(k); + return ThermoCabinet::item(n).maxTemp(k); } int DLL_EXPORT th_getEnthalpies_RT(int n, size_t lenm, double* h_rt) { try { - thermo_t* thrm = th(n); - size_t nsp = thrm->nSpecies(); + ThermoPhase& thrm = ThermoCabinet::item(n); + size_t nsp = thrm.nSpecies(); if (lenm >= nsp) { - thrm->getEnthalpy_RT_ref(h_rt); + thrm.getEnthalpy_RT_ref(h_rt); return 0; } else { return -10; @@ -727,10 +703,10 @@ extern "C" { int DLL_EXPORT th_getEntropies_R(int n, size_t lenm, double* s_r) { try { - thermo_t* thrm = th(n); - size_t nsp = thrm->nSpecies(); + ThermoPhase& thrm = ThermoCabinet::item(n); + size_t nsp = thrm.nSpecies(); if (lenm >= nsp) { - thrm->getEntropy_R_ref(s_r); + thrm.getEntropy_R_ref(s_r); return 0; } else { return -10; @@ -743,10 +719,10 @@ extern "C" { int DLL_EXPORT th_getCp_R(int n, size_t lenm, double* cp_r) { try { - thermo_t* thrm = th(n); - size_t nsp = thrm->nSpecies(); + ThermoPhase& thrm = ThermoCabinet::item(n); + size_t nsp = thrm.nSpecies(); if (lenm >= nsp) { - thrm->getCp_R_ref(cp_r); + thrm.getCp_R_ref(cp_r); return 0; } else { return -10; @@ -758,7 +734,7 @@ extern "C" { int DLL_EXPORT th_setElectricPotential(int n, double v) { - th(n)->setElectricPotential(v); + ThermoCabinet::item(n).setElectricPotential(v); return 0; } @@ -876,22 +852,22 @@ extern "C" { try { XML_Node& x = XmlCabinet::item(mxml); vector phases; - phases.push_back(th(iphase)); + phases.push_back(&ThermoCabinet::item(iphase)); if (neighbor1 >= 0) { - phases.push_back(th(neighbor1)); + phases.push_back(&ThermoCabinet::item(neighbor1)); if (neighbor2 >= 0) { - phases.push_back(th(neighbor2)); + phases.push_back(&ThermoCabinet::item(neighbor2)); if (neighbor3 >= 0) { - phases.push_back(th(neighbor3)); + phases.push_back(&ThermoCabinet::item(neighbor3)); if (neighbor4 >= 0) { - phases.push_back(th(neighbor4)); + phases.push_back(&ThermoCabinet::item(neighbor4)); } } } } Kinetics* kin = newKineticsMgr(x, phases); if (kin) { - return Storage::storage()->addKinetics(kin); + return KineticsCabinet::add(kin); } else { return 0; } @@ -905,9 +881,9 @@ extern "C" { { try { XML_Node& p = XmlCabinet::item(pxml); - kinetics_t* k = kin(ikin); + Kinetics& k = KineticsCabinet::item(ikin); string defphase = string(default_phase); - installReactionArrays(p, *k, defphase); + installReactionArrays(p, k, defphase); return 0; } catch (CanteraError) { return -1; @@ -917,67 +893,67 @@ extern "C" { //------------------------------------- int DLL_EXPORT kin_type(int n) { - return kin(n)->type(); + return KineticsCabinet::item(n).type(); } size_t DLL_EXPORT kin_start(int n, int p) { - return kin(n)->kineticsSpeciesIndex(0,p); + return KineticsCabinet::item(n).kineticsSpeciesIndex(0,p); } size_t DLL_EXPORT kin_speciesIndex(int n, const char* nm, const char* ph) { - return kin(n)->kineticsSpeciesIndex(string(nm), string(ph)); + return KineticsCabinet::item(n).kineticsSpeciesIndex(string(nm), string(ph)); } //--------------------------------------- size_t DLL_EXPORT kin_nSpecies(int n) { - return kin(n)->nTotalSpecies(); + return KineticsCabinet::item(n).nTotalSpecies(); } size_t DLL_EXPORT kin_nReactions(int n) { - return kin(n)->nReactions(); + return KineticsCabinet::item(n).nReactions(); } size_t DLL_EXPORT kin_nPhases(int n) { - return kin(n)->nPhases(); + return KineticsCabinet::item(n).nPhases(); } size_t DLL_EXPORT kin_phaseIndex(int n, char* ph) { - return kin(n)->phaseIndex(string(ph)); + return KineticsCabinet::item(n).phaseIndex(string(ph)); } size_t DLL_EXPORT kin_reactionPhaseIndex(int n) { - return kin(n)->reactionPhaseIndex(); + return KineticsCabinet::item(n).reactionPhaseIndex(); } double DLL_EXPORT kin_reactantStoichCoeff(int n, int k, int i) { - return kin(n)->reactantStoichCoeff(k,i); + return KineticsCabinet::item(n).reactantStoichCoeff(k,i); } double DLL_EXPORT kin_productStoichCoeff(int n, int k, int i) { - return kin(n)->productStoichCoeff(k,i); + return KineticsCabinet::item(n).productStoichCoeff(k,i); } int DLL_EXPORT kin_reactionType(int n, int i) { - return kin(n)->reactionType(i); + return KineticsCabinet::item(n).reactionType(i); } int DLL_EXPORT kin_getFwdRatesOfProgress(int n, size_t len, double* fwdROP) { - Kinetics* k = kin(n); + Kinetics& k = KineticsCabinet::item(n); try { - if (len >= k->nReactions()) { - k->getFwdRatesOfProgress(fwdROP); + if (len >= k.nReactions()) { + k.getFwdRatesOfProgress(fwdROP); return 0; } else { return ERR; @@ -989,10 +965,10 @@ extern "C" { int DLL_EXPORT kin_getRevRatesOfProgress(int n, size_t len, double* revROP) { - Kinetics* k = kin(n); + Kinetics& k = KineticsCabinet::item(n); try { - if (len >= k->nReactions()) { - k->getRevRatesOfProgress(revROP); + if (len >= k.nReactions()) { + k.getRevRatesOfProgress(revROP); return 0; } else { return ERR; @@ -1004,15 +980,15 @@ extern "C" { int DLL_EXPORT kin_isReversible(int n, int i) { - return (int)kin(n)->isReversible(i); + return (int) KineticsCabinet::item(n).isReversible(i); } int DLL_EXPORT kin_getNetRatesOfProgress(int n, size_t len, double* netROP) { try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getNetRatesOfProgress(netROP); + Kinetics& k = KineticsCabinet::item(n); + if (len >= k.nReactions()) { + k.getNetRatesOfProgress(netROP); return 0; } else { return ERR; @@ -1025,9 +1001,9 @@ extern "C" { int DLL_EXPORT kin_getFwdRateConstants(int n, size_t len, double* kfwd) { try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getFwdRateConstants(kfwd); + Kinetics& k = KineticsCabinet::item(n); + if (len >= k.nReactions()) { + k.getFwdRateConstants(kfwd); return 0; } else { return ERR; @@ -1040,13 +1016,13 @@ extern "C" { int DLL_EXPORT kin_getRevRateConstants(int n, int doIrreversible, size_t len, double* krev) { try { - Kinetics* k = kin(n); + Kinetics& k = KineticsCabinet::item(n); bool doirrev = false; if (doIrreversible != 0) { doirrev = true; } - if (len >= k->nReactions()) { - k->getRevRateConstants(krev, doirrev); + if (len >= k.nReactions()) { + k.getRevRateConstants(krev, doirrev); return 0; } else { return ERR; @@ -1060,9 +1036,9 @@ extern "C" { int DLL_EXPORT kin_getActivationEnergies(int n, size_t len, double* E) { try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getActivationEnergies(E); + Kinetics& k = KineticsCabinet::item(n); + if (len >= k.nReactions()) { + k.getActivationEnergies(E); return 0; } else { return ERR; @@ -1076,28 +1052,28 @@ extern "C" { int DLL_EXPORT kin_getDelta(int n, int job, size_t len, double* delta) { try { - Kinetics* k = kin(n); - if (len < k->nReactions()) { + Kinetics& k = KineticsCabinet::item(n); + if (len < k.nReactions()) { return ERR; } switch (job) { case 0: - k->getDeltaEnthalpy(delta); + k.getDeltaEnthalpy(delta); break; case 1: - k->getDeltaGibbs(delta); + k.getDeltaGibbs(delta); break; case 2: - k->getDeltaEntropy(delta); + k.getDeltaEntropy(delta); break; case 3: - k->getDeltaSSEnthalpy(delta); + k.getDeltaSSEnthalpy(delta); break; case 4: - k->getDeltaSSGibbs(delta); + k.getDeltaSSGibbs(delta); break; case 5: - k->getDeltaSSEntropy(delta); + k.getDeltaSSEntropy(delta); break; default: return ERR; @@ -1112,9 +1088,9 @@ extern "C" { int DLL_EXPORT kin_getDeltaEntropy(int n, size_t len, double* deltaS) { try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getDeltaEntropy(deltaS); + Kinetics& k = KineticsCabinet::item(n); + if (len >= k.nReactions()) { + k.getDeltaEntropy(deltaS); return 0; } else { return ERR; @@ -1128,9 +1104,9 @@ extern "C" { int DLL_EXPORT kin_getCreationRates(int n, size_t len, double* cdot) { try { - Kinetics* k = kin(n); - if (len >= k->nTotalSpecies()) { - k->getCreationRates(cdot); + Kinetics& k = KineticsCabinet::item(n); + if (len >= k.nTotalSpecies()) { + k.getCreationRates(cdot); return 0; } else { return ERR; @@ -1143,9 +1119,9 @@ extern "C" { int DLL_EXPORT kin_getDestructionRates(int n, size_t len, double* ddot) { try { - Kinetics* k = kin(n); - if (len >= k->nTotalSpecies()) { - k->getDestructionRates(ddot); + Kinetics& k = KineticsCabinet::item(n); + if (len >= k.nTotalSpecies()) { + k.getDestructionRates(ddot); return 0; } else { return ERR; @@ -1159,9 +1135,9 @@ extern "C" { int DLL_EXPORT kin_getNetProductionRates(int n, size_t len, double* wdot) { try { - Kinetics* k = kin(n); - if (len >= k->nTotalSpecies()) { - k->getNetProductionRates(wdot); + Kinetics& k = KineticsCabinet::item(n); + if (len >= k.nTotalSpecies()) { + k.getNetProductionRates(wdot); return 0; } else { return ERR; @@ -1174,13 +1150,13 @@ extern "C" { int DLL_EXPORT kin_getSourceTerms(int n, size_t len, double* ydot) { try { - Kinetics* k = kin(n); - ThermoPhase* p = &k->thermo(); - const vector_fp& mw = p->molecularWeights(); + Kinetics& k = KineticsCabinet::item(n); + ThermoPhase& p = k.thermo(); + const vector_fp& mw = p.molecularWeights(); size_t nsp = mw.size(); - double rrho = 1.0/p->density(); + double rrho = 1.0/p.density(); if (len >= nsp) { - k->getNetProductionRates(ydot); + k.getNetProductionRates(ydot); multiply_each(ydot, ydot + nsp, mw.begin()); scale(ydot, ydot + nsp, ydot, rrho); return 0; @@ -1194,20 +1170,20 @@ extern "C" { double DLL_EXPORT kin_multiplier(int n, int i) { - return kin(n)->multiplier(i); + return KineticsCabinet::item(n).multiplier(i); } size_t DLL_EXPORT kin_phase(int n, size_t i) { - return kin(n)->thermo(i).index(); + return KineticsCabinet::item(n).thermo(i).index(); } int DLL_EXPORT kin_getEquilibriumConstants(int n, size_t len, double* kc) { try { - Kinetics* k = kin(n); - if (len >= k->nReactions()) { - k->getEquilibriumConstants(kc); + Kinetics& k = KineticsCabinet::item(n); + if (len >= k.nReactions()) { + k.getEquilibriumConstants(kc); return 0; } else { return ERR; @@ -1220,8 +1196,8 @@ extern "C" { int DLL_EXPORT kin_getReactionString(int n, int i, int len, char* buf) { try { - Kinetics* k = kin(n); - string r = k->reactionString(i); + Kinetics& k = KineticsCabinet::item(n); + string r = k.reactionString(i); int lout = min(len, (int)r.size()); copy(r.c_str(), r.c_str() + lout, buf); buf[lout] = '\0'; @@ -1235,7 +1211,7 @@ extern "C" { { try { if (v >= 0.0) { - kin(n)->setMultiplier(i,v); + KineticsCabinet::item(n).setMultiplier(i,v); return 0; } else { return ERR; @@ -1248,9 +1224,9 @@ extern "C" { int DLL_EXPORT kin_advanceCoverages(int n, double tstep) { try { - Kinetics* k = kin(n); - if (k->type() == cInterfaceKinetics) { - ((InterfaceKinetics*)k)->advanceCoverages(tstep); + Kinetics& k = KineticsCabinet::item(n); + if (k.type() == cInterfaceKinetics) { + dynamic_cast(&k)->advanceCoverages(tstep); } else { throw CanteraError("kin_advanceCoverages", "wrong kinetics manager type"); @@ -1267,10 +1243,10 @@ extern "C" { int ith, int loglevel) { string mstr = string(model); - thermo_t* t = th(ith); + ThermoPhase& t = ThermoCabinet::item(ith); try { - Transport* tr = newTransportMgr(mstr,t, loglevel); - return Storage::storage()->addTransport(tr); + Transport* tr = newTransportMgr(mstr, &t, loglevel); + return TransportCabinet::add(tr); } catch (CanteraError) { return -1; } @@ -1279,7 +1255,7 @@ extern "C" { double DLL_EXPORT trans_viscosity(int n) { try { - return trans(n)->viscosity(); + return TransportCabinet::item(n).viscosity(); } catch (CanteraError) { return -1.0; } @@ -1288,7 +1264,7 @@ extern "C" { double DLL_EXPORT trans_thermalConductivity(int n) { try { - return trans(n)->thermalConductivity(); + return TransportCabinet::item(n).thermalConductivity(); } catch (CanteraError) { return -1.0; } @@ -1297,7 +1273,7 @@ extern "C" { int DLL_EXPORT trans_getThermalDiffCoeffs(int n, int ldt, double* dt) { try { - trans(n)->getThermalDiffCoeffs(dt); + TransportCabinet::item(n).getThermalDiffCoeffs(dt); return 0; } catch (CanteraError) { return -1; @@ -1307,7 +1283,7 @@ extern "C" { int DLL_EXPORT trans_getMixDiffCoeffs(int n, int ld, double* d) { try { - trans(n)->getMixDiffCoeffs(d); + TransportCabinet::item(n).getMixDiffCoeffs(d); return 0; } catch (CanteraError) { return -1; @@ -1317,7 +1293,7 @@ extern "C" { int DLL_EXPORT trans_getBinDiffCoeffs(int n, int ld, double* d) { try { - trans(n)->getBinaryDiffCoeffs(ld,d); + TransportCabinet::item(n).getBinaryDiffCoeffs(ld,d); return 0; } catch (CanteraError) { return -1; @@ -1327,7 +1303,7 @@ extern "C" { int DLL_EXPORT trans_getMultiDiffCoeffs(int n, int ld, double* d) { try { - trans(n)->getMultiDiffCoeffs(ld,d); + TransportCabinet::item(n).getMultiDiffCoeffs(ld,d); return 0; } catch (CanteraError) { return -1; @@ -1337,7 +1313,7 @@ extern "C" { int DLL_EXPORT trans_setParameters(int n, int type, int k, double* d) { try { - trans(n)->setParameters(type, k, d); + TransportCabinet::item(n).setParameters(type, k, d); return 0; } catch (CanteraError) { return -1; @@ -1348,7 +1324,7 @@ extern "C" { const double* state2, double delta, double* fluxes) { try { - trans(n)->getMolarFluxes(state1, state2, delta, fluxes); + TransportCabinet::item(n).getMolarFluxes(state1, state2, delta, fluxes); return 0; } catch (CanteraError) { return -1; @@ -1359,7 +1335,7 @@ extern "C" { const double* state2, double delta, double* fluxes) { try { - trans(n)->getMassFluxes(state1, state2, delta, fluxes); + TransportCabinet::item(n).getMassFluxes(state1, state2, delta, fluxes); return 0; } catch (CanteraError) { return -1; @@ -1370,11 +1346,11 @@ extern "C" { int DLL_EXPORT import_phase(int nth, int nxml, char* id) { - thermo_t* thrm = th(nth); + ThermoPhase& thrm = ThermoCabinet::item(nth); XML_Node& node = XmlCabinet::item(nxml); string idstr = string(id); try { - importPhase(node, thrm); + importPhase(node, &thrm); return 0; } catch (CanteraError) { return -1; @@ -1386,13 +1362,13 @@ extern "C" { { vector phases; for (int i = 0; i < nphases; i++) { - phases.push_back(th(ith[i])); + phases.push_back(&ThermoCabinet::item(ith[i])); } XML_Node& node = XmlCabinet::item(nxml); - Kinetics* k = kin(nkin); + Kinetics& k = KineticsCabinet::item(nkin); string idstr = string(id); try { - importKinetics(node, phases, k); + importKinetics(node, phases, &k); return 0; } catch (CanteraError) { return -1; @@ -1405,7 +1381,7 @@ extern "C" { { try { bool stherm = (show_thermo != 0); - string s = report(*th(nth), stherm); + string s = report(ThermoCabinet::item(nth), stherm); if (int(s.size()) > ibuf - 1) { return -(static_cast(s.size()) + 1); } @@ -1422,7 +1398,7 @@ extern "C" { { try { bool stherm = (show_thermo != 0); - writephase(*th(nth), stherm); + writephase(ThermoCabinet::item(nth), stherm); return 0; } catch (CanteraError) { return -1; @@ -1486,7 +1462,9 @@ extern "C" { int DLL_EXPORT clearStorage() { try { - Storage::storage()->clear(); + ThermoCabinet::clear(); + KineticsCabinet::clear(); + TransportCabinet::clear(); return 0; } catch (CanteraError) { return -1; @@ -1496,7 +1474,7 @@ extern "C" { int DLL_EXPORT delThermo(int n) { try { - Storage::storage()->deleteThermo(n); + ThermoCabinet::del(n); return 0; } catch (CanteraError) { return -1; @@ -1505,13 +1483,13 @@ extern "C" { int DLL_EXPORT delKinetics(int n) { - Storage::storage()->deleteKinetics(n); + KineticsCabinet::del(n); return 0; } int DLL_EXPORT delTransport(int n) { - Storage::storage()->deleteTransport(n); + TransportCabinet::del(n); return 0; } @@ -1524,10 +1502,8 @@ extern "C" { root = &XmlCabinet::item(ixml); } - thermo_t* t = th(ith); - kinetics_t* k = kin(ikin); - - Kinetics& kin = *k; + ThermoPhase& t = ThermoCabinet::item(ith); + Kinetics& kin = KineticsCabinet::item(ikin); XML_Node* x, *r=0; if (root) { r = &root->root(); @@ -1537,11 +1513,11 @@ extern "C" { if (!x) { return false; } - importPhase(*x, t); - kin.addPhase(*t); + importPhase(*x, &t); + kin.addPhase(t); kin.init(); installReactionArrays(*x, kin, x->id()); - t->setState_TP(300.0, OneAtm); + t.setState_TP(300.0, OneAtm); if (r) { if (&x->root() != &r->root()) { delete &x->root(); diff --git a/src/clib/ctbdry.cpp b/src/clib/ctbdry.cpp index 6b940ba4a..0fee114c1 100644 --- a/src/clib/ctbdry.cpp +++ b/src/clib/ctbdry.cpp @@ -9,28 +9,12 @@ #include "cantera/oneD/Inlet1D.h" #include "cantera/kinetics/InterfaceKinetics.h" #include "Cabinet.h" -#include "Storage.h" - using namespace std; using namespace Cantera; typedef Cabinet BoundaryCabinet; -template<> BoundaryCabinet* BoundaryCabinet::__storage = 0; - -//inline Phase* _phase(int n) { -// return Storage::__storage->__phasetable[n]; -//} - -inline ThermoPhase* _thermo(int n) -{ - return Storage::__storage->__thtable[n]; -} - -inline Kinetics* _kin(int n) -{ - return Storage::__storage->__ktable[n]; -} +template<> BoundaryCabinet* BoundaryCabinet::__storage = 0; extern "C" { @@ -137,8 +121,10 @@ extern "C" { int DLL_EXPORT surf_setkinetics(int i, int j) { try { - ReactingSurf1D* srf = dynamic_cast(&BoundaryCabinet::item(i)); - InterfaceKinetics* k = (InterfaceKinetics*)_kin(j); + ReactingSurf1D* srf = + dynamic_cast(&BoundaryCabinet::item(i)); + InterfaceKinetics* k = + dynamic_cast(&Cabinet::item(j)); srf->setKineticsMgr(k); } catch (CanteraError) { return -1; diff --git a/src/clib/ctmultiphase.cpp b/src/clib/ctmultiphase.cpp index 4c4321b58..24fc3dd5f 100644 --- a/src/clib/ctmultiphase.cpp +++ b/src/clib/ctmultiphase.cpp @@ -9,9 +9,7 @@ #include "cantera/equil/MultiPhase.h" #include "cantera/equil/MultiPhaseEquil.h" #include "cantera/equil/vcs_MultiPhaseEquil.h" - #include "Cabinet.h" -#include "Storage.h" using namespace std; using namespace Cantera; @@ -19,11 +17,6 @@ using namespace Cantera; typedef Cabinet mixCabinet; template<> mixCabinet* mixCabinet::__storage = 0; -inline ThermoPhase* _th(int n) -{ - return Storage::__storage->__thtable[n]; -} - static bool checkSpecies(int i, size_t k) { try { @@ -91,7 +84,7 @@ extern "C" { int DLL_EXPORT mix_addPhase(int i, int j, double moles) { - mixCabinet::item(i).addPhase(_th(j), moles); + mixCabinet::item(i).addPhase(&Cabinet::item(j), moles); return 0; } diff --git a/src/clib/ctonedim.cpp b/src/clib/ctonedim.cpp index ea768238f..28d75b6c0 100644 --- a/src/clib/ctonedim.cpp +++ b/src/clib/ctonedim.cpp @@ -11,10 +11,7 @@ #include "cantera/oneD/StFlow.h" #include "cantera/oneD/Inlet1D.h" #include "cantera/numerics/DenseMatrix.h" - -// local includes #include "Cabinet.h" -#include "Storage.h" using namespace std; using namespace Cantera; @@ -24,6 +21,10 @@ typedef Cabinet DomainCabinet; template<> SimCabinet* SimCabinet::__storage = 0; template<> DomainCabinet* DomainCabinet::__storage = 0; +typedef Cabinet ThermoCabinet; +typedef Cabinet KineticsCabinet; +typedef Cabinet TransportCabinet; + static StFlow* _stflow(int i) { Domain1D* d = &DomainCabinet::item(i); @@ -44,27 +45,6 @@ static Bdry1D* _bdry(int i) return dynamic_cast(d); } -inline ThermoPhase* _phase(int n) -{ - return Storage::__storage->__thtable[n]; -} - -inline Kinetics* _kinetics(int n) -{ - return Storage::__storage->__ktable[n]; -} - -inline ThermoPhase* _thermo(int n) -{ - return Storage::__storage->__thtable[n]; -} - -inline Transport* _transport(int n) -{ - return Storage::__storage->__trtable[n]; -} - - extern "C" { int DLL_EXPORT domain_clear() @@ -349,7 +329,8 @@ extern "C" { { try { ReactingSurf1D* srf = (ReactingSurf1D*)_bdry(i); - InterfaceKinetics* k = (InterfaceKinetics*)_kinetics(j); + InterfaceKinetics* k = + dynamic_cast(&Cabinet::item(j)); srf->setKineticsMgr(k); return 0; } catch (CanteraError) { @@ -388,16 +369,16 @@ extern "C" { int DLL_EXPORT stflow_new(int iph, int ikin, int itr, int itype) { try { - IdealGasPhase* ph = (IdealGasPhase*)_thermo(iph); + IdealGasPhase* ph = dynamic_cast(&ThermoCabinet::item(iph)); if (itype == 1) { AxiStagnFlow* x = new AxiStagnFlow(ph, ph->nSpecies(), 2); - x->setKinetics(*_kinetics(ikin)); - x->setTransport(*_transport(itr)); + x->setKinetics(KineticsCabinet::item(ikin)); + x->setTransport(TransportCabinet::item(itr)); return DomainCabinet::add(x); } else if (itype == 2) { FreeFlame* x = new FreeFlame(ph, ph->nSpecies(), 2); - x->setKinetics(*_kinetics(ikin)); - x->setTransport(*_transport(itr)); + x->setKinetics(KineticsCabinet::item(ikin)); + x->setTransport(TransportCabinet::item(itr)); return DomainCabinet::add(x); } else { return -2; @@ -415,7 +396,7 @@ extern "C" { withSoret = true; } try { - _stflow(i)->setTransport(*_transport(itr), withSoret); + _stflow(i)->setTransport(TransportCabinet::item(itr), withSoret); return 0; } catch (CanteraError) { return -1; diff --git a/src/clib/ctreactor.cpp b/src/clib/ctreactor.cpp index 11dcaf18c..390e7ba26 100644 --- a/src/clib/ctreactor.cpp +++ b/src/clib/ctreactor.cpp @@ -12,9 +12,7 @@ #include "cantera/zeroD/Reservoir.h" #include "cantera/zeroD/Wall.h" #include "cantera/zeroD/flowControllers.h" - #include "Cabinet.h" -#include "Storage.h" using namespace Cantera; using namespace std; @@ -24,16 +22,8 @@ typedef Cabinet NetworkCabinet; typedef Cabinet FlowDeviceCabinet; typedef Cabinet WallCabinet; typedef Cabinet FuncCabinet; - -inline Kinetics* _kin(int n) -{ - return Storage::__storage->__ktable[n]; -} - -inline ThermoPhase* _th(int n) -{ - return Storage::__storage->__thtable[n]; -} +typedef Cabinet ThermoCabinet; +typedef Cabinet KineticsCabinet; template<> ReactorCabinet* ReactorCabinet::__storage = 0; template<> NetworkCabinet* NetworkCabinet::__storage = 0; @@ -91,7 +81,7 @@ extern "C" { int DLL_EXPORT reactor_setThermoMgr(int i, int n) { - ReactorCabinet::item(i).setThermoMgr(*_th(n)); + ReactorCabinet::item(i).setThermoMgr(ThermoCabinet::item(n)); return 0; } @@ -99,7 +89,7 @@ extern "C" { { ReactorBase* r = &ReactorCabinet::item(i); if (r->type() >= ReactorType) { - ((Reactor*)r)->setKineticsMgr(*_kin(n)); + ((Reactor*)r)->setKineticsMgr(KineticsCabinet::item(n)); } return 0; } @@ -423,12 +413,12 @@ extern "C" { { Kinetics* left=0, *right=0; if (n > 0) - if (_kin(n)->type() == cInterfaceKinetics) { - left = _kin(n); + if (KineticsCabinet::item(n).type() == cInterfaceKinetics) { + left = &KineticsCabinet::item(n); } if (m > 0) - if (_kin(m)->type() == cInterfaceKinetics) { - right = _kin(m); + if (KineticsCabinet::item(m).type() == cInterfaceKinetics) { + right = &KineticsCabinet::item(m); } WallCabinet::item(i).setKinetics(left, right); return 0; diff --git a/src/clib/ctrpath.cpp b/src/clib/ctrpath.cpp index 5bbd025c3..2e8550515 100644 --- a/src/clib/ctrpath.cpp +++ b/src/clib/ctrpath.cpp @@ -7,22 +7,16 @@ // Cantera includes #include "cantera/kinetics/ReactionPath.h" #include "Cabinet.h" -#include "Storage.h" using namespace Cantera; using namespace std; -typedef ReactionPathBuilder builder_t; - typedef Cabinet BuilderCabinet; typedef Cabinet DiagramCabinet; template<> DiagramCabinet* DiagramCabinet::__storage = 0; template<> BuilderCabinet* BuilderCabinet::__storage = 0; -inline Kinetics* _kin(int n) -{ - return Storage::__storage->__ktable[n]; -} +typedef Cabinet KineticsCabinet; extern "C" { @@ -188,7 +182,7 @@ extern "C" { int DLL_EXPORT rbuild_init(int i, char* logfile, int k) { ofstream flog(logfile); - BuilderCabinet::item(i).init(flog, *_kin(k)); + BuilderCabinet::item(i).init(flog, KineticsCabinet::item(k)); return 0; } @@ -200,7 +194,7 @@ extern "C" { if (iquiet > 0) { quiet = true; } - BuilderCabinet::item(i).build(*_kin(k), string(el), fdot, + BuilderCabinet::item(i).build(KineticsCabinet::item(k), string(el), fdot, DiagramCabinet::item(idiag), quiet); return 0; } diff --git a/src/clib/ctsurf.cpp b/src/clib/ctsurf.cpp index b14ce981e..9d55d143c 100644 --- a/src/clib/ctsurf.cpp +++ b/src/clib/ctsurf.cpp @@ -9,21 +9,19 @@ #include "cantera/thermo/SurfPhase.h" #include "cantera/kinetics/InterfaceKinetics.h" #include "kinetics/ImplicitSurfChem.h" - #include "Cabinet.h" -#include "Storage.h" using namespace std; using namespace Cantera; inline SurfPhase* _surfphase(int n) { - return (SurfPhase*)Storage::__storage->__thtable[n]; + return dynamic_cast(&Cabinet::item(n)); } inline InterfaceKinetics* _surfkin(int n) { - return (InterfaceKinetics*)Storage::__storage->__ktable[n]; + return dynamic_cast(&Cabinet::item(n)); } extern "C" { diff --git a/src/clib/ctxml.cpp b/src/clib/ctxml.cpp index cd6eaf119..38f261d48 100644 --- a/src/clib/ctxml.cpp +++ b/src/clib/ctxml.cpp @@ -7,7 +7,6 @@ // Cantera includes #include "cantera/base/ctml.h" #include "Cabinet.h" -#include "Storage.h" #include @@ -15,9 +14,6 @@ using namespace std; using namespace Cantera; using namespace ctml; -// Assign storage for the static member of the Templated Cabinet class -// class Cabinet; - typedef Cabinet XmlCabinet; template<> XmlCabinet* XmlCabinet::__storage = 0; diff --git a/src/fortran/fct.cpp b/src/fortran/fct.cpp index 0382a7f7a..ce9044446 100644 --- a/src/fortran/fct.cpp +++ b/src/fortran/fct.cpp @@ -13,7 +13,6 @@ #include "cantera/thermo/ThermoFactory.h" #include "cantera/base/ctml.h" #include "cantera/kinetics/importKinetics.h" -#include "clib/Storage.h" #include "clib/Cabinet.h" #include "cantera/kinetics/InterfaceKinetics.h" #include "cantera/thermo/PureFluidPhase.h" @@ -23,6 +22,9 @@ using namespace Cantera; typedef Cabinet XmlCabinet; +typedef Cabinet ThermoCabinet; +typedef Cabinet KineticsCabinet; +typedef Cabinet TransportCabinet; inline XML_Node* _xml(const integer* n) { @@ -31,27 +33,27 @@ inline XML_Node* _xml(const integer* n) inline ThermoPhase* _fph(const integer* n) { - return th(*n); + return &ThermoCabinet::item(*n); } static Kinetics* _fkin(const integer* n) { if (*n >= 0) { - return kin(*n); + return &KineticsCabinet::item(*n); } else { error("_fkin: negative kinetics index"); - return kin(0); + return &KineticsCabinet::item(0); } } inline ThermoPhase* _fth(const integer* n) { - return th(*n); + return &ThermoCabinet::item(*n); } inline Transport* _ftrans(const integer* n) { - return trans(*n); + return &TransportCabinet::item(*n); } std::string f2string(const char* s, ftnlen n) @@ -310,17 +312,12 @@ extern "C" { //-------------- Thermo --------------------// - - // status_t DLL_EXPORT th_thermoIndex(char* id) { - // return thermo_index(id); - //} - integer DLL_EXPORT newthermofromxml_(integer* mxml) { try { XML_Node* x = _xml(mxml); thermo_t* th = newPhase(*x); - return Storage::storage()->addThermo(th); + return ThermoCabinet::add(th); } catch (CanteraError) { handleError(); return -1; @@ -602,8 +599,8 @@ extern "C" { } Kinetics* kin = newKineticsMgr(*x, phases); if (kin) { - int k = Storage::storage()->addKinetics(kin); - return k; //Storage::storage()->addKinetics(kin); + int k = KineticsCabinet::add(kin); + return k; } else { return 0; } @@ -762,10 +759,6 @@ extern "C" { return _fkin(n)->multiplier(*i); } - //status_t DLL_EXPORT kin_phase_(const integer* n, integer* i) { - // return thermo_index(_fkin(n)->thermo(*i).id()); - //} - status_t DLL_EXPORT kin_getequilibriumconstants_(const integer* n, doublereal* kc) { try { @@ -832,7 +825,7 @@ extern "C" { thermo_t* t = _fth(ith); try { Transport* tr = newTransportMgr(mstr, t, *loglevel); - return Storage::storage()->addTransport(tr); + return TransportCabinet::add(tr); } catch (CanteraError) { handleError(); return -1; diff --git a/src/python/ctthermo_methods.cpp b/src/python/ctthermo_methods.cpp index 6a3aa2a03..d1f2bebab 100644 --- a/src/python/ctthermo_methods.cpp +++ b/src/python/ctthermo_methods.cpp @@ -25,16 +25,6 @@ thermo_delete(PyObject* self, PyObject* args) return Py_BuildValue("i",0); } -static PyObject* -thermo_index(PyObject* self, PyObject* args) -{ - char* id; - if (!PyArg_ParseTuple(args, "s:index", &id)) { - return NULL; - } - return Py_BuildValue("i",th_thermoIndex(id)); -} - static PyObject* thermo_refpressure(PyObject* self, PyObject* args) { diff --git a/src/python/methods.h b/src/python/methods.h index 6033c3931..b5e216dc5 100644 --- a/src/python/methods.h +++ b/src/python/methods.h @@ -25,7 +25,6 @@ static PyMethodDef ct_methods[] = { {"thermo_delete", thermo_delete, METH_VARARGS}, {"thermo_mintemp", thermo_mintemp, METH_VARARGS}, {"thermo_maxtemp", thermo_maxtemp, METH_VARARGS}, - {"thermo_thermoIndex", thermo_index, METH_VARARGS}, {"thermo_refpressure", thermo_refpressure, METH_VARARGS}, {"thermo_getfp", thermo_getfp, METH_VARARGS}, {"thermo_setfp", thermo_setfp, METH_VARARGS},