From 56ed18b70550c3ec714de626524f2933044d9c8e Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Sat, 9 Oct 2004 15:21:43 +0000 Subject: [PATCH] *** empty log message *** --- Cantera/Makefile.in | 4 + Cantera/README.txt | 4 +- Cantera/clib/src/Cabinet.h | 1 + Cantera/clib/src/ct.cpp | 24 ++- Cantera/clib/src/ct.h | 3 + Cantera/cxx/include/IdealGasMix.h | 3 + Cantera/cxx/include/Interface.h | 7 +- Cantera/cxx/include/kinetics.h | 320 +--------------------------- Cantera/python/examples/dustygas.py | 10 +- Cantera/python/src/methods.h | 1 + ext/tpx/Makefile.in | 3 +- ext/tpx/Sub.cpp | 6 +- ext/tpx/subs.h | 1 + ext/tpx/utils.cpp | 42 +++- 14 files changed, 93 insertions(+), 336 deletions(-) diff --git a/Cantera/Makefile.in b/Cantera/Makefile.in index 34b5e089f..ff67d1335 100755 --- a/Cantera/Makefile.in +++ b/Cantera/Makefile.in @@ -12,6 +12,7 @@ build_f90=@BUILD_F90@ build_python=@BUILD_PYTHON@ build_particles=@BUILD_PARTICLES@ +build_matlab = @BUILD_MATLAB@ all: cd src; @MAKE@ @@ -46,6 +47,9 @@ endif ifeq ($(build_particles),1) cd cads; @MAKE@ depends endif +ifeq ($(build_matlab),1) + cd matlab; @MAKE@ depends +endif install: cd src; @MAKE@ install diff --git a/Cantera/README.txt b/Cantera/README.txt index aec0914a7..23de2a853 100644 --- a/Cantera/README.txt +++ b/Cantera/README.txt @@ -2,8 +2,8 @@ This directory contains the source for Cantera and its various language interfaces. -clib - the library of C-callable functions used by the Python and - Matlab interfaces. +clib - the library of C-callable functions used by the Python and + Matlab interfaces. cxx - files that are only required for C++ application programs. matlab - the Cantera Matlab toolbox python - the Cantera Python package diff --git a/Cantera/clib/src/Cabinet.h b/Cantera/clib/src/Cabinet.h index 1f145d16a..088ab922a 100755 --- a/Cantera/clib/src/Cabinet.h +++ b/Cantera/clib/src/Cabinet.h @@ -6,6 +6,7 @@ #define CT_CABINET_H #include +#include "stringUtils.h" /** * Template for classes to hold pointers to objects. The Cabinet diff --git a/Cantera/clib/src/ct.cpp b/Cantera/clib/src/ct.cpp index 3adef7a8d..7b95c3701 100755 --- a/Cantera/clib/src/ct.cpp +++ b/Cantera/clib/src/ct.cpp @@ -78,7 +78,10 @@ extern "C" { } int DLL_EXPORT phase_setTemperature(int n, double t) { - ph(n)->setTemperature(t); + try { + ph(n)->setTemperature(t); + } + catch(CanteraError) {return -1;} return 0; } @@ -545,7 +548,10 @@ extern "C" { } double DLL_EXPORT th_satTemperature(int n, double p) { - return purefluid(n)->satTemperature(p); + try { + return purefluid(n)->satTemperature(p); + } + catch (CanteraError) { return DERR; } } double DLL_EXPORT th_satPressure(int n, double t) { @@ -902,6 +908,15 @@ extern "C" { catch (CanteraError) { return -1; } } + int DLL_EXPORT trans_getMolarFluxes(int n, const double* state1, + const double* state2, double delta, double* fluxes) { + try { + trans(n)->getMolarFluxes(state1, state2, delta, fluxes); + return 0; + } + catch (CanteraError) { return -1; } + } + //-------------------- Functions --------------------------- int DLL_EXPORT import_phase(int nth, int nxml, char* id) { @@ -959,6 +974,11 @@ extern "C" { return int(e.size()); } + int DLL_EXPORT showCanteraErrors() { + showErrors(); + return 0; + } + int DLL_EXPORT addCanteraDirectory(int buflen, char* buf) { addDirectory(string(buf)); return 0; diff --git a/Cantera/clib/src/ct.h b/Cantera/clib/src/ct.h index 3fbebc732..25cd9cec2 100755 --- a/Cantera/clib/src/ct.h +++ b/Cantera/clib/src/ct.h @@ -131,6 +131,8 @@ extern "C" { int DLL_IMPORT trans_getBinDiffCoeffs(int n, int ld, double* d); int DLL_IMPORT trans_getMultiDiffCoeffs(int n, int ld, double* d); int DLL_IMPORT trans_setParameters(int n, int type, int k, double* d); + int DLL_IMPORT trans_getMolarFluxes(int n, const double* state1, + const double* state2, double delta, double* fluxes); int DLL_IMPORT import_phase(int nth, int nxml, char* id); int DLL_IMPORT import_kinetics(int nxml, char* id, @@ -138,6 +140,7 @@ extern "C" { int DLL_IMPORT import_from_file(int nth, int nkin, char* fname, char* db, char* id, int validate, double threshold); int DLL_IMPORT getCanteraError(int buflen, char* buf); + int DLL_IMPORT showCanteraErrors(); int DLL_IMPORT addCanteraDirectory(int buflen, char* buf); int DLL_IMPORT clearStorage(); int DLL_IMPORT delPhase(int n); diff --git a/Cantera/cxx/include/IdealGasMix.h b/Cantera/cxx/include/IdealGasMix.h index 9e4665e7e..d8681f617 100644 --- a/Cantera/cxx/include/IdealGasMix.h +++ b/Cantera/cxx/include/IdealGasMix.h @@ -13,6 +13,9 @@ namespace Cantera { public IdealGasPhase, public GasKinetics { public: + + IdealGasMix() : m_ok(false), m_r(0) {} + IdealGasMix(string infile, string id="") : m_ok(false), m_r(0) { m_r = get_XML_File(infile); diff --git a/Cantera/cxx/include/Interface.h b/Cantera/cxx/include/Interface.h index 2f0414ec7..4afa88d65 100644 --- a/Cantera/cxx/include/Interface.h +++ b/Cantera/cxx/include/Interface.h @@ -29,7 +29,6 @@ namespace Cantera { m_ok = true; } - virtual ~Interface() {} bool operator!() { return !m_ok;} @@ -41,6 +40,12 @@ namespace Cantera { private: }; + + inline Interface* importInterface(string infile, string id, + vector phases) { + return new Interface(infile, id, phases); + } + } diff --git a/Cantera/cxx/include/kinetics.h b/Cantera/cxx/include/kinetics.h index 99c995213..4a94caa93 100644 --- a/Cantera/cxx/include/kinetics.h +++ b/Cantera/cxx/include/kinetics.h @@ -1,320 +1,6 @@ -/** - * @file Kinetics.h - * - * $Author$ - * $Revision$ - * $Date$ - */ - -// Copyright 2001 California Institute of Technology - -/** - * @defgroup kineticsGroup Kinetics - */ - -#ifndef CT_KINETICS_H -#define CT_KINETICS_H - -#include "ctexceptions.h" -//#include "Phase.h" -#include "ThermoPhase.h" - -namespace Cantera { - - class ReactionData; - - /** - * Public interface for kinetics managers. This class serves as a - * base class to derive 'kinetics managers', which are classes - * that manage homogeneous chemistry within one phase. - */ - class Kinetics { - - public: - - // typedefs - typedef ThermoPhase thermo_t; - - /// Constructor. - Kinetics() : m_ii(0), m_thermo(0), m_index(-1) {} - Kinetics(thermo_t* thermo) - : m_ii(0), m_index(-1) { - if (thermo) { - m_start.push_back(0); - m_thermo.push_back(thermo); - } - } - - /// Destructor. Does nothing. - virtual ~Kinetics() {} // delete m_xml; } - - int index(){ return m_index; } - void setIndex(int index) { m_index = index; } - - //XML_Node& xml() { return *m_xml; } - - /// Identifies subclass. - virtual int type() { return 0; } - - int start(int n) { return m_start[n]; } - - /// Number of reactions - int nReactions() const {return m_ii;} - - /// Number of species - int nTotalSpecies() const { - int n=0, np; - np = nPhases(); - for (int p = 0; p < np; p++) n += thermo(p).nSpecies(); - return n; - } - - /** - * Stoichiometric coefficient of species k as a reactant in - * reaction i. - */ - virtual doublereal reactantStoichCoeff(int k, int i) const { - err("reactantStoichCoeff"); - return -1.0; - } - - /** - * Stoichiometric coefficient of species k as a product in - * reaction i. - */ - virtual doublereal productStoichCoeff(int k, int i) const { - err("productStoichCoeff"); - return -1.0; - } - - - /** - * Returns a read-only reference to the vector of reactant - * index numbers for reaction i. - */ - virtual const vector_int& reactants(int i) const { - return m_reactants[i]; - } - virtual const vector_int& products(int i) const { - return m_products[i]; - } - - /** - * Flag specifying the type of reaction. The legal values and - * their meaning are specific to the particular kinetics - * manager. - */ - virtual int reactionType(int i) const { - err("reactionType"); - return -1; - } - - /** - * @name Reaction Rates Of Progress - */ - //@{ - - /** - * Forward rates of progress. - * Return the forward rates of progress in array fwdROP, which - * must be dimensioned at least as large as the total number - * of reactions. - */ - virtual void getFwdRatesOfProgress(doublereal* fwdROP) { - err("getFwdRatesOfProgress"); - } - - /** - * Reverse rates of progress. - * Return the reverse rates of progress in array revROP, which - * must be dimensioned at least as large as the total number - * of reactions. - */ - virtual void getRevRatesOfProgress(doublereal* revROP) { - err("getRevRatesOfProgress"); - } - - /** - * Net rates of progress. Return the net (forward - reverse) - * rates of progress in array netROP, which must be - * dimensioned at least as large as the total number of - * reactions. - */ - virtual void getNetRatesOfProgress(doublereal* netROP) { - err("getNetRatesOfProgress"); - } - - /** - * True if reaction i has been declared to be reversible. If - * isReversible(i) is false, then the reverse rate of progress - * for reaction i is always zero. - */ - virtual bool isReversible(int i){return false;} - - /** - * Species creation rates [kmol/m^3]. Return the species - * creation rates in array cdot, which must be - * dimensioned at least as large as the total number of - * species. - * - */ - virtual void getCreationRates(doublereal* cdot) { - err("getCreationRates"); - } - - /** - * Species destruction rates [kmol/m^3]. Return the species - * destruction rates in array ddot, which must be - * dimensioned at least as large as the total number of - * species. - * - */ - virtual void getDestructionRates(doublereal* ddot) { - err("getDestructionRates"); - } - - /** - * Species net production rates [kmol/m^3]. Return the species - * net production rates (creation - destruction) in array - * wdot, which must be dimensioned at least as large as the - * total number of species. - */ - virtual void getNetProductionRates(doublereal* wdot) { - err("getNetProductionRates"); - } - - /** - * Equilibrium constants. Return the equilibrium constants of - * the reactions in concentration units in array kc, which - * must be dimensioned at least as large as the total number - * of reactions. - */ - virtual void getEquilibriumConstants(doublereal* kc) { - err("getEquilibriumConstants"); - } - //@} - - - /** - * @name Reaction Mechanism Construction - */ - //@{ - - - /** - * Get the nth Phase object. - */ - //phase_t& phase(int n=0) { return *m_phase[n]; } - //const phase_t& phase(int n=0) const { return *m_phase[n]; } - int nPhases() const { return m_thermo.size(); } - int phaseIndex(string ph) { return m_phaseindex[ph] - 1; } - - /** - * Add a phase. - */ - void addPhase(thermo_t& thermo) { - if (m_thermo.size() > 0) { - m_start.push_back(m_start.back() - + m_thermo.back()->nSpecies()); - } - else { - m_start.push_back(0); - } - m_thermo.push_back(&thermo); - m_phaseindex[m_thermo.back()->id()] = nPhases(); - } - thermo_t& thermo(int n=0) { return *m_thermo[n]; } - const thermo_t& thermo(int n=0) const { return *m_thermo[n]; } - thermo_t& phase(int n=0) { return *m_thermo[n]; } - const thermo_t& phase(int n=0) const { return *m_thermo[n]; } - - int speciesIndex(int k, int n) { - return m_start[n] + k; - } - - int speciesIndex(string nm, string ph = "") { - int np = m_thermo.size(); - int k; - string id; - for (int n = 0; n < np; n++) { - id = thermo(n).id(); - if (ph == id) { - k = thermo(n).speciesIndex(nm); - if (k < 0) return -1; - return k + m_start[n]; - } - else if (ph == "") { - k = thermo(n).speciesIndex(nm); - if (k >= 0) return k + m_start[n]; - } - } - return -2; - } - - /** - * Prepare to add reactions. - */ - virtual void init() {err("init");} - - /// Finished adding reactions. Prepare for use. - virtual void finalize() {err("finalize");} - - virtual void addReaction(const ReactionData& r) {err("addReaction");} - - virtual string reactionString(int i) const { - err("reactionString"); return ""; - } - - - virtual const vector& reactantGroups(int i) - { err("reactantGroups"); return m_dummygroups; } - - virtual const vector& productGroups(int i) - { err("productGroups"); return m_dummygroups; } - - /** - * @name Altering Reaction Rates - * - * These methods alter reaction rates. They are designed - * primarily for carrying out sensitivity analysis. - */ - //@{ - - /// The current value of the multiplier for reaction i. - doublereal multiplier(int i) const {return m_perturb[i];} - - /// Set the multiplier for reaction i to f. - void setMultiplier(int i, doublereal f) {m_perturb[i] = f;} - - //@} - - void incrementRxnCount() { m_ii++; m_perturb.push_back(1.0); } - - virtual bool ready() const {return false;} - - protected: - - int m_ii; - vector_fp m_perturb; - vector m_reactants; - vector m_products; - vector m_thermo; - vector_int m_start; - // XML_Node* m_xml; - map m_phaseindex; - int m_index; - - private: - - vector m_dummygroups; - void err(string m) const { - throw CanteraError("Kinetics::"+m,"Base class method called."); - } - }; - - typedef Kinetics kinetics_t; -} - +#ifndef CXX_INCL_KINETICS +#define CXX_INCL_KINETICS +#include "kernel/Kinetics.h" #endif diff --git a/Cantera/python/examples/dustygas.py b/Cantera/python/examples/dustygas.py index 6a11cbf82..60bb85354 100644 --- a/Cantera/python/examples/dustygas.py +++ b/Cantera/python/examples/dustygas.py @@ -26,5 +26,13 @@ d.set(porosity = 0.2, tortuosity = 4.0, pore_radius = 1.5e-7, diameter = 1.5e-6) # lengths in meters # print the multicomponent diffusion coefficients -print d.multiDiffCoeffs() +#print d.multiDiffCoeffs() +# compute molar species fluxes +state1 = g.saveState() + +g.set(P = 1.2*OneAtm) +state2 = g.saveState() +delta = 0.001 + +print d.molarFluxes(state1, state1, delta) diff --git a/Cantera/python/src/methods.h b/Cantera/python/src/methods.h index f62b28512..8ce3b131e 100644 --- a/Cantera/python/src/methods.h +++ b/Cantera/python/src/methods.h @@ -80,6 +80,7 @@ static PyMethodDef ct_methods[] = { {"tran_mixDiffCoeffs", py_mixDiffCoeffs, METH_VARARGS}, {"tran_multiDiffCoeffs", py_multiDiffCoeffs, METH_VARARGS}, {"tran_setParameters", py_setParameters, METH_VARARGS}, + {"tran_getMolarFluxes", py_getMolarFluxes, METH_VARARGS}, {"get_Cantera_Error", ct_get_cantera_error, METH_VARARGS}, //{"ct_print", ct_print, METH_VARARGS}, diff --git a/ext/tpx/Makefile.in b/ext/tpx/Makefile.in index 284251ced..4d7e01616 100755 --- a/ext/tpx/Makefile.in +++ b/ext/tpx/Makefile.in @@ -7,7 +7,8 @@ OBJDIR = . CXX_FLAGS = @CXXFLAGS@ $(CXX_OPT) -COBJS = Methane.o Nitrogen.o Oxygen.o Water.o Hydrogen.o lk.o Sub.o utils.o +COBJS = Methane.o Nitrogen.o Oxygen.o Water.o Hydrogen.o RedlichKwong.o \ + lk.o Sub.o utils.o FOBJS = diff --git a/ext/tpx/Sub.cpp b/ext/tpx/Sub.cpp index b1b3a17e8..2c3f10422 100755 --- a/ext/tpx/Sub.cpp +++ b/ext/tpx/Sub.cpp @@ -129,11 +129,11 @@ namespace tpx { double TolAbsH = 0.0001; // J/kg double TolAbsU = 0.0001; - double TolAbsS = 1.e-6; + double TolAbsS = 1.e-7; double TolAbsP = 0.000; // Pa - double TolAbsV = 1.e-7; + double TolAbsV = 1.e-8; double TolAbsT = 1.e-3; - double TolRel = 3.e-7; + double TolRel = 3.e-8; void Substance::Set(int XY, double x0, double y0) { double temp; diff --git a/ext/tpx/subs.h b/ext/tpx/subs.h index 639f5f41f..2e7d9b05f 100755 --- a/ext/tpx/subs.h +++ b/ext/tpx/subs.h @@ -7,6 +7,7 @@ #include "Nitrogen.h" #include "Oxygen.h" #include "Water.h" +#include "RedlichKwong.h" // #include "lk.h" #endif diff --git a/ext/tpx/utils.cpp b/ext/tpx/utils.cpp index a2f74cb09..05fddf3ed 100755 --- a/ext/tpx/utils.cpp +++ b/ext/tpx/utils.cpp @@ -3,20 +3,44 @@ namespace tpx { + static string lowercase(string s) { + size_t i, n = s.size(); + string lc(s); + for (int i = 0; i < n; i++) lc[i] = tolower(s[i]); + return lc; + } -Substance * GetSub(int isub) { - if (isub == 0) - return new water; + Substance* GetSubstanceByName(string name) { + string lcname = lowercase(name); + if (lcname == "water") + return new water; + else if (lcname == "nitrogen") + return new nitrogen; + else if (lcname == "methane") + return new methane; + else if (lcname == "hydrogen") + return new hydrogen; + else if (lcname == "oxygen") + return new oxygen; + else if (lcname == "rk") + return new RedlichKwong; + } + + Substance * GetSub(int isub) { + if (isub == 0) + return new water; else if (isub == 1) - return new nitrogen; + return new nitrogen; else if (isub == 2) - return new methane; + return new methane; else if (isub == 3) - return new hydrogen; + return new hydrogen; else if (isub == 4) - return new oxygen; -// else if (isub == 5) -// return new HFC134a; + return new oxygen; + // else if (isub == 5) + // return new HFC134a; + else if (isub == 6) + return new RedlichKwong; else return 0; }