diff --git a/Cantera/Makefile.in b/Cantera/Makefile.in index 338cc8988..34b5e089f 100755 --- a/Cantera/Makefile.in +++ b/Cantera/Makefile.in @@ -26,7 +26,7 @@ endif clean: cd src; @MAKE@ clean - cd cxx/src; @MAKE@ clean + cd cxx; @MAKE@ clean cd clib/src; @MAKE@ clean cd python; @MAKE@ clean ifeq ($(build_f90),1) diff --git a/Cantera/clib/src/ct.cpp b/Cantera/clib/src/ct.cpp index 59d15762f..471727fec 100755 --- a/Cantera/clib/src/ct.cpp +++ b/Cantera/clib/src/ct.cpp @@ -34,12 +34,17 @@ inline XML_Node* _xml(int i) { #ifdef INCL_PURE_FLUID static PureFluid* purefluid(int n) { - ThermoPhase* tp = th(n); - if (tp->eosType() == cPureFluid) { - return (PureFluid*)tp; + try { + ThermoPhase* tp = th(n); + if (tp->eosType() == cPureFluid) { + return (PureFluid*)tp; + } + else { + throw CanteraError("purefluid","object is not a PureFluid object"); + } } - else { - throw CanteraError("purefluid","object is not a PureFluid object"); + catch (CanteraError) { + return 0; } } #else @@ -82,8 +87,7 @@ extern "C" { } int DLL_EXPORT phase_setDensity(int n, double rho) { - if (rho < 0.0) throw CanteraError("phase_setDensity", - "density cannot be negative"); + if (rho < 0.0) return -1; ph(n)->setDensity(rho); return 0; } diff --git a/Cantera/clib/src/ct.h b/Cantera/clib/src/ct.h index fc305da1b..150f608e6 100755 --- a/Cantera/clib/src/ct.h +++ b/Cantera/clib/src/ct.h @@ -2,7 +2,7 @@ #define CTC_CT_H #include "clib_defs.h" -#include +#include "../../../config.h" extern "C" { diff --git a/Cantera/clib/src/ctreactor.cpp b/Cantera/clib/src/ctreactor.cpp index f6769e8d4..f2ecd3772 100755 --- a/Cantera/clib/src/ctreactor.cpp +++ b/Cantera/clib/src/ctreactor.cpp @@ -94,10 +94,10 @@ extern "C" { return 0; } - //int DLL_EXPORT reactor_setInitialTime(int i, double t) { - // _reactor(i)->setInitialTime(t); - // return 0; - //} + int DLL_EXPORT reactor_setInitialTime(int i, double t) { + _reactor(i)->setInitialTime(t); + return 0; + } int DLL_EXPORT reactor_setThermoMgr(int i, int n) { _reactor(i)->setThermoMgr(*_th(n)); @@ -111,17 +111,17 @@ extern "C" { return 0; } - //int DLL_EXPORT reactor_advance(int i, double t) { - // try { - // _reactor(i)->advance(t); - // return 0; - // } - // catch (CanteraError) {return -1;} - //} + int DLL_EXPORT reactor_advance(int i, double t) { + try { + _reactor(i)->advance(t); + return 0; + } + catch (CanteraError) {return -1;} + } - // double DLL_EXPORT reactor_step(int i, double t) { - // return _reactor(i)->step(t); - //} + double DLL_EXPORT reactor_step(int i, double t) { + return _reactor(i)->step(t); + } double DLL_EXPORT reactor_time(int i) { return _reactor(i)->time(); @@ -196,11 +196,26 @@ extern "C" { return 0; } - int DLL_EXPORT reactornet_addreactor(int i, int n) { - _reactornet(i)->addReactor(_reactor(n)); + int DLL_EXPORT reactornet_setMaxTimeStep(int i, double maxstep) { + _reactornet(i)->setMaxTimeStep(maxstep); return 0; } + int DLL_EXPORT reactornet_setTolerances(int i, double rtol, double atol) { + _reactornet(i)->setTolerances(rtol, atol); + return 0; + } + + int DLL_EXPORT reactornet_addreactor(int i, int n) { + try { + _reactornet(i)->addReactor(_reactor(n)); + return 0; + } + catch (CanteraError) { + return -1; + } + } + int DLL_EXPORT reactornet_advance(int i, double t) { try { _reactornet(i)->advance(t); @@ -218,6 +233,19 @@ extern "C" { } } + double DLL_EXPORT reactornet_time(int i) { + return _reactornet(i)->time(); + } + + double DLL_EXPORT reactornet_rtol(int i) { + return _reactornet(i)->rtol(); + } + + double DLL_EXPORT reactornet_atol(int i) { + return _reactornet(i)->atol(); + } + + // flow devices diff --git a/Cantera/clib/src/ctreactor.h b/Cantera/clib/src/ctreactor.h index 8fa53a5e6..5619a2878 100755 --- a/Cantera/clib/src/ctreactor.h +++ b/Cantera/clib/src/ctreactor.h @@ -10,12 +10,12 @@ extern "C" { int DLL_IMPORT reactor_copy(int i); int DLL_IMPORT reactor_assign(int i, int j); int DLL_IMPORT reactor_setInitialVolume(int i, double v); - // int DLL_IMPORT reactor_setInitialTime(int i, double t); + int DLL_IMPORT reactor_setInitialTime(int i, double t); int DLL_IMPORT reactor_setEnergy(int i, int eflag); int DLL_IMPORT reactor_setThermoMgr(int i, int n); int DLL_IMPORT reactor_setKineticsMgr(int i, int n); - //int DLL_IMPORT reactor_advance(int i, double t); - //double DLL_IMPORT reactor_step(int i, double t); + int DLL_IMPORT reactor_advance(int i, double t); + double DLL_IMPORT reactor_step(int i, double t); double DLL_IMPORT reactor_time(int i); double DLL_IMPORT reactor_mass(int i); double DLL_IMPORT reactor_volume(int i); @@ -31,9 +31,14 @@ extern "C" { int DLL_IMPORT reactornet_copy(int i); int DLL_IMPORT reactornet_assign(int i, int j); int DLL_IMPORT reactornet_setInitialTime(int i, double t); + int DLL_IMPORT reactornet_setMaxTimeStep(int i, double maxstep); + int DLL_IMPORT reactornet_setTolerances(int i, double rtol, double atol); int DLL_IMPORT reactornet_addreactor(int i, int n); int DLL_IMPORT reactornet_advance(int i, double t); double DLL_IMPORT reactornet_step(int i, double t); + double DLL_IMPORT reactornet_time(int i); + double DLL_IMPORT reactornet_rtol(int i); + double DLL_IMPORT reactornet_atol(int i); int DLL_IMPORT flowdev_new(int type); int DLL_IMPORT flowdev_del(int i); diff --git a/Cantera/python/Cantera/Kinetics.py b/Cantera/python/Cantera/Kinetics.py index a8afe475a..a6fcabfa8 100755 --- a/Cantera/python/Cantera/Kinetics.py +++ b/Cantera/python/Cantera/Kinetics.py @@ -100,11 +100,12 @@ class Kinetics: return _cantera.kin_speciesIndex(self.ckin, name, phase) def kineticsStart(self, n): + """The starting location of phase n in production rate arrays.""" return _cantera.kin_start(self.ckin, n) def phase(self, n): + """Return an object representing the nth phase.""" return ThermoPhase(index = _cantera.kin_phase(self.ckin, n)) - #return self._ph[_cantera.kin_phase(self.ckin, n)] def nReactions(self): """Number of reactions.""" @@ -121,10 +122,9 @@ class Kinetics: """Type of reaction 'i'""" return _cantera.kin_rxntype(self.ckin,i) - #def reactionString(self,i): - # return _cantera.kin_getstring(self.ckin,1,i) - def reactionEqn(self,i): + """The equation for the specified reaction. If a list of equation numbers + is given, then a list of equation strings is returned.""" try: eqs = [] for rxn in i: @@ -134,6 +134,7 @@ class Kinetics: return self.reactionString(i) def reactionString(self, i): + """Reaction string for reaction number 'i'""" s = '' nsp = _cantera.kin_nspecies(self.ckin) for k in range(nsp): @@ -157,9 +158,13 @@ class Kinetics: return s def reactantStoichCoeff(self,k,i): + """The stoichiometric coefficient of species k as a reactant in reaction i.""" return _cantera.kin_rstoichcoeff(self.ckin,k,i) def reactantStoichCoeffs(self): + """The array of reactant stoichiometric coefficients. Element + [k,i] of this array is the reactant stoichiometric + coefficient of species k in reaction i.""" nsp = _cantera.kin_nspecies(self.ckin) nr = _cantera.kin_nreactions(self.ckin) nu = Numeric.zeros((nsp,nr),'d') @@ -169,9 +174,13 @@ class Kinetics: return nu def productStoichCoeff(self,k,i): + """The stoichiometric coefficient of species k as a product in reaction i.""" return _cantera.kin_pstoichcoeff(self.ckin,k,i) def productStoichCoeffs(self): + """The array of product stoichiometric coefficients. Element + [k,i] of this array is the product stoichiometric + coefficient of species k in reaction i.""" nsp = _cantera.kin_nspecies(self.ckin) nr = _cantera.kin_nreactions(self.ckin) nu = Numeric.zeros((nsp,nr),'d') @@ -181,12 +190,15 @@ class Kinetics: return nu def fwdRatesOfProgress(self): + """Forward rates of progress of the reactions.""" return _cantera.kin_getarray(self.ckin,10) def revRatesOfProgress(self): + """Reverse rates of progress of the reactions.""" return _cantera.kin_getarray(self.ckin,20) def netRatesOfProgress(self): + """Net rates of progress of the reactions.""" return _cantera.kin_getarray(self.ckin,30) def equilibriumConstants(self): @@ -198,9 +210,11 @@ class Kinetics: return _cantera.kin_getarray(self.ckin,32) def fwdRateConstants(self): + """Forward rate constants for all reactions.""" return _cantera.kin_getarray(self.ckin,34) def revRateConstants(self, doIrreversible = 0): + """Reverse rate constants for all reactions.""" if doIrreversible: return _cantera.kin_getarray(self.ckin,35) else: diff --git a/Cantera/python/Cantera/Transport.py b/Cantera/python/Cantera/Transport.py index 010896579..f6b0fe296 100755 --- a/Cantera/python/Cantera/Transport.py +++ b/Cantera/python/Cantera/Transport.py @@ -35,11 +35,12 @@ class Transport: self._models[self.model] = self.__tr_id def __del__(self): - for m in self._models.keys(): - try: - _cantera.tran_delete(self._models[m]) - except: - pass + if hasattr(self,'_models'): + for m in self._models.keys(): + try: + _cantera.tran_delete(self._models[m]) + except: + pass def addTransportModel(self, model, loglevel=1): new_id = _cantera.Transport(model, diff --git a/Cantera/python/Cantera/constants.py b/Cantera/python/Cantera/constants.py index 3dd496fbc..7534e9bfc 100755 --- a/Cantera/python/Cantera/constants.py +++ b/Cantera/python/Cantera/constants.py @@ -2,14 +2,31 @@ Physical Constants """ +# One atmosphere in Pascals OneAtm = 101325.0 + +# The ideal gas constant in J/kmo-K GasConstant = 8314.0 + +# Avogadro's Number, /kmol Avogadro = 6.022136736e26 +# The ideal gas constant in cal/mol-K GasConst_cal_mol_K = 1.987 + +# Boltzmann-s constant Boltzmann = GasConstant / Avogadro + +# The Stefan-Boltzmann constant, W/m^2K^4 StefanBoltz = 5.67e-8 + +# The charge on an electron ElectronCharge = 1.602e-19 + Pi = 3.1415926 + +# Faraday's constant, C/kmol Faraday = ElectronCharge * Avogadro + +# Planck's constant Planck = 6.6262e-34 diff --git a/Cantera/python/Makefile.in b/Cantera/python/Makefile.in index 42e652ec1..dba09737c 100755 --- a/Cantera/python/Makefile.in +++ b/Cantera/python/Makefile.in @@ -38,7 +38,7 @@ win: _winbuild _build: $(SRCS) $(LIB_DEPS) touch src/pycantera.cpp - (@PYTHON_CMD@ setup.py build) + (CXX=@CXX@; export CXX; CC=@CC@; export CC; @PYTHON_CMD@ setup.py build) echo 'ok' > _build diff --git a/Cantera/python/src/ctthermo_methods.cpp b/Cantera/python/src/ctthermo_methods.cpp index 27daae7d4..3dbe8d1af 100644 --- a/Cantera/python/src/ctthermo_methods.cpp +++ b/Cantera/python/src/ctthermo_methods.cpp @@ -71,7 +71,7 @@ thermo_getfp(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "ii:thermo_getfp", &th, &job)) return NULL; - try { + // try { // floating-point attributes switch (job) { @@ -123,10 +123,10 @@ thermo_getfp(PyObject *self, PyObject *args) PyErr_SetString(ErrorObject,"Unknown floating-point attribute"); return NULL; } - } - catch (CanteraError) { - return reportCanteraError(); - } + //} + //catch (CanteraError) { + // return reportCanteraError(); + //} } static PyObject* diff --git a/Cantera/python/src/pycantera.cpp b/Cantera/python/src/pycantera.cpp index 3dd882cd9..c52e854b3 100644 --- a/Cantera/python/src/pycantera.cpp +++ b/Cantera/python/src/pycantera.cpp @@ -11,6 +11,7 @@ #pragma warning(disable:4503) #endif +#include "../../../config.h" #include "Python.h" #include "Numeric/arrayobject.h" diff --git a/Cantera/src/IdealGasPhase.h b/Cantera/src/IdealGasPhase.h index f00df4451..53d93645e 100644 --- a/Cantera/src/IdealGasPhase.h +++ b/Cantera/src/IdealGasPhase.h @@ -178,6 +178,7 @@ namespace Cantera { */ virtual void getActivityConcentrations(doublereal* c) const { getConcentrations(c); + //for (int k = 0; k < m_kk; k++) if (c[k] < 0.0) c[k] = 0.0; } /** diff --git a/Cantera/src/converters/ck2ct.cpp b/Cantera/src/converters/ck2ct.cpp index 946191eb1..1559972c5 100644 --- a/Cantera/src/converters/ck2ct.cpp +++ b/Cantera/src/converters/ck2ct.cpp @@ -12,14 +12,7 @@ #include #include -// on cygwin, #include doesn't work -#if defined(__CYGWIN__) -#undef USE_STRINGSTREAM -#else -#define USE_STRINGSTREAM -#endif - -#ifdef USE_STRINGSTREAM +#ifdef HAS_SSTREAM #include #endif using namespace std; @@ -64,7 +57,7 @@ namespace pip { * somehow. Should probably default to the USE_STRINGSTREAM * option. */ -#ifdef USE_STRINGSTREAM +#ifdef HAS_SSTREAM /* * Read a line from the file */ diff --git a/Cantera/src/zeroD/Reactor.h b/Cantera/src/zeroD/Reactor.h index 5c9aba71e..b9fb5bae0 100644 --- a/Cantera/src/zeroD/Reactor.h +++ b/Cantera/src/zeroD/Reactor.h @@ -21,6 +21,8 @@ #include "../CVode.h" #include "../Kinetics.h" +#define INCL_REACTOR_INTEG + namespace Cantera { /** diff --git a/Cantera/src/zeroD/ReactorNet.cpp b/Cantera/src/zeroD/ReactorNet.cpp index 3918cca74..fd1a8b771 100644 --- a/Cantera/src/zeroD/ReactorNet.cpp +++ b/Cantera/src/zeroD/ReactorNet.cpp @@ -5,9 +5,9 @@ namespace Cantera { ReactorNet::ReactorNet() : FuncEval(), m_nr(0), m_nreactors(0), m_integ(0), m_time(0.0), m_init(false), - m_nv(0), m_rtol(1.0e-6), m_atols(1.0e-15), + m_nv(0), m_rtol(1.0e-9), m_atols(1.0e-15), m_maxstep(-1.0), - m_verbose(false) + m_verbose(true) { m_integ = new CVodeInt; @@ -50,7 +50,7 @@ namespace Cantera { if (m_verbose) { sprintf(buf, "Number of equations: %d\n", neq()); writelog(buf); - sprintf(buf, "Maximum time step: %g14.6\n", m_maxstep); + sprintf(buf, "Maximum time step: %14.6g\n", m_maxstep); writelog(buf); } m_integ->initialize(t0, *this); @@ -59,8 +59,8 @@ namespace Cantera { void ReactorNet::advance(doublereal time) { if (!m_init) { - if (m_maxstep < 0.0) - m_maxstep = time - m_time; + //if (m_maxstep < 0.0) + m_maxstep = time;// - m_time; initialize(); } m_integ->integrate(time); @@ -70,8 +70,8 @@ namespace Cantera { double ReactorNet::step(doublereal time) { if (!m_init) { - if (m_maxstep < 0.0) - m_maxstep = time - m_time; + //if (m_maxstep < 0.0) + m_maxstep = time;// - m_time; initialize(); } m_time = m_integ->step(time); diff --git a/Cantera/src/zeroD/ReactorNet.h b/Cantera/src/zeroD/ReactorNet.h index b8ef90346..33ee6dc01 100644 --- a/Cantera/src/zeroD/ReactorNet.h +++ b/Cantera/src/zeroD/ReactorNet.h @@ -54,8 +54,8 @@ namespace Cantera { } void setTolerances(doublereal rtol, doublereal atol) { - m_rtol = rtol; - m_atols = atol; + if (rtol >= 0.0) m_rtol = rtol; + if (atol >= 0.0) m_atols = atol; m_init = false; } diff --git a/Makefile.in b/Makefile.in index d6eb70a27..20104880f 100755 --- a/Makefile.in +++ b/Makefile.in @@ -245,7 +245,7 @@ depends: endif changes: - perl cvs2cl.pl --prune + cvs2cl.pl --prune export: changes @INSTALL@ -d $(export_dir) diff --git a/config.h.in b/config.h.in index 3e06e669e..43b22a197 100755 --- a/config.h.in +++ b/config.h.in @@ -50,7 +50,7 @@ typedef int ftnlen; // Fortran hidden string length type // OS X, This used to add some Mac-specific directories to the default // data file search path. #undef DARWIN - +#undef HAS_SSTREAM //--------- Fonts for reaction path diagrams ---------------------- #undef RXNPATH_FONT diff --git a/config/configure b/config/configure index 044881677..03f80a9c7 100755 --- a/config/configure +++ b/config/configure @@ -3167,6 +3167,26 @@ fi echo "$as_me:$LINENO: result: ${precompile_headers}" >&5 echo "${ECHO_T}${precompile_headers}" >&6 +has_sstream=no +echo "$as_me:$LINENO: checking for sstream" >&5 +echo $ECHO_N "checking for sstream... $ECHO_C" >&6 +cat >> teststream.cpp << \EOF +#include +main() {} +EOF + msg=`$CXX -c testsstream &> /dev/null` + if test -f testsstream.o; then + has_sstream=yes + rm teststream.o + cat >>confdefs.h <<\_ACEOF +#define HAS_SSTREAM 1 +_ACEOF + + fi +rm teststream.cpp +echo "$as_me:$LINENO: result: ${has_sstream}" >&5 +echo "${ECHO_T}${has_sstream}" >&6 + #--------------------------------- # Fortran @@ -3264,7 +3284,7 @@ fi # Provide some information about the compiler. -echo "$as_me:3267:" \ +echo "$as_me:3287:" \ "checking for Fortran 77 compiler version" >&5 ac_compiler=`set X $ac_compile; echo $2` { (eval echo "$as_me:$LINENO: \"$ac_compiler --version &5\"") >&5 @@ -3441,7 +3461,7 @@ _ACEOF # flags. ac_save_FFLAGS=$FFLAGS FFLAGS="$FFLAGS $ac_verb" -(eval echo $as_me:3444: \"$ac_link\") >&5 +(eval echo $as_me:3464: \"$ac_link\") >&5 ac_f77_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'` echo "$ac_f77_v_output" >&5 FFLAGS=$ac_save_FFLAGS @@ -3521,7 +3541,7 @@ _ACEOF # flags. ac_save_FFLAGS=$FFLAGS FFLAGS="$FFLAGS $ac_cv_prog_f77_v" -(eval echo $as_me:3524: \"$ac_link\") >&5 +(eval echo $as_me:3544: \"$ac_link\") >&5 ac_f77_v_output=`eval $ac_link 5>&1 2>&1 | grep -v 'Driving:'` echo "$ac_f77_v_output" >&5 FFLAGS=$ac_save_FFLAGS diff --git a/config/configure.in b/config/configure.in index 3fcc200f3..76f8b2ec8 100755 --- a/config/configure.in +++ b/config/configure.in @@ -481,6 +481,21 @@ if test -n "$GCC"; then fi AC_MSG_RESULT(${precompile_headers}) +has_sstream=no +AC_MSG_CHECKING(for sstream) +cat >> teststream.cpp << \EOF +#include +main() {} +EOF + msg=`$CXX -c testsstream &> /dev/null` + if test -f testsstream.o; then + has_sstream=yes + rm teststream.o + AC_DEFINE(HAS_SSTREAM) + fi +rm teststream.cpp +AC_MSG_RESULT(${has_sstream}) + #--------------------------------- # Fortran diff --git a/tools/src/finish_install.py.in b/tools/src/finish_install.py.in index bd5ec8a07..1b696cfc2 100644 --- a/tools/src/finish_install.py.in +++ b/tools/src/finish_install.py.in @@ -76,8 +76,8 @@ except: ctpath = "-" fm = open(ctdir+"/ctpath.m","w") -fm.write("""path(path,'"""+prefix+"""/matlab/toolbox/cantera/cantera')\n""") -fm.write("""path(path,'"""+prefix+"""/matlab/toolbox/cantera/cantera/1D')\n""") +fm.write("""path('"""+prefix+"""/matlab/toolbox/cantera/cantera',path)\n""") +fm.write("""path('"""+prefix+"""/matlab/toolbox/cantera/cantera/1D',path)\n""") fm.close() print """