From 9e54a6857e4599ea118a90e04276e38e9e34e19b Mon Sep 17 00:00:00 2001 From: Dave Goodwin Date: Fri, 22 Jul 2005 04:02:05 +0000 Subject: [PATCH] *** empty log message *** --- Cantera/clib/src/ct.cpp | 9 +- Cantera/clib/src/ct.h | 4 +- Cantera/clib/src/ctmultiphase.cpp | 4 +- Cantera/cxx/demos/flamespeed.cpp | 2 +- Cantera/cxx/include/equilibrium.h | 1 + Cantera/fortran/src/fct.cpp | 6 +- .../matlab/cantera/@ThermoPhase/equilibrate.m | 97 ++++++++++++------- .../cantera/@ThermoPhase/private/thermo_set.m | 4 +- .../matlab/cantera/private/thermomethods.cpp | 7 +- Cantera/python/Cantera/ThermoPhase.py | 39 ++++++-- Cantera/python/Cantera/mixture.py | 2 - Cantera/python/examples/equilibrium/stoich.py | 14 ++- Cantera/python/src/ctthermo_methods.cpp | 9 +- Cantera/src/Makefile.in | 4 +- Cantera/src/PropertyCalculator.h | 11 +++ Cantera/src/ThermoPhase.h | 9 +- Cantera/src/global.h | 20 +++- Cantera/src/misc.cpp | 91 +++++++++++++---- config.h.in | 2 + config/configure | 20 ++-- config/configure.in | 16 ++- configure | 4 +- examples/cxx/equil_example1.cpp | 3 +- examples/cxx/transport_example2.cpp | 2 +- test_problems/ck2cti_test/runtest.in | 6 ++ test_problems/cxx_ex/runtest | 7 ++ test_problems/python/runtest | 29 ++++-- test_problems/silane_equil/silane_equil.cpp | 2 +- 28 files changed, 292 insertions(+), 132 deletions(-) diff --git a/Cantera/clib/src/ct.cpp b/Cantera/clib/src/ct.cpp index 176be3325..1183e5f55 100755 --- a/Cantera/clib/src/ct.cpp +++ b/Cantera/clib/src/ct.cpp @@ -16,7 +16,7 @@ #endif // Cantera includes -#include "ChemEquil.h" +#include "equil.h" //"ChemEquil.h" #include "KineticsFactory.h" #include "transport/TransportFactory.h" #include "ctml.h" @@ -487,14 +487,13 @@ extern "C" { catch (CanteraError) {return -1;} } - int DLL_EXPORT th_equil(int n, int XY, int solver, - double rtol, int maxsteps, int loglevel) { + int DLL_EXPORT th_equil(int n, char* XY, int solver, + double rtol, int maxsteps, int maxiter, int loglevel) { try { equilibrate(*th(n), XY, solver, rtol, maxsteps, - loglevel); return 0; + maxiter, loglevel); return 0; } catch (CanteraError) { - cout << "exception caught in th_equil. returning -1." << endl; return -1; } } diff --git a/Cantera/clib/src/ct.h b/Cantera/clib/src/ct.h index 990450f25..1c05f2134 100755 --- a/Cantera/clib/src/ct.h +++ b/Cantera/clib/src/ct.h @@ -80,8 +80,8 @@ extern "C" { int DLL_IMPORT th_set_UV(int n, double* vals); int DLL_IMPORT th_set_SV(int n, double* vals); int DLL_IMPORT th_set_SP(int n, double* vals); - int DLL_IMPORT th_equil(int n, int XY, int solver, - double rtol, int maxsteps, int loglevel); + int DLL_IMPORT th_equil(int n, char* XY, int solver, + double rtol, int maxsteps, int maxiter, int loglevel); #ifdef INCL_PURE_FLUIDS double DLL_IMPORT th_critTemperature(int n); diff --git a/Cantera/clib/src/ctmultiphase.cpp b/Cantera/clib/src/ctmultiphase.cpp index 3919591ae..e858b15d1 100644 --- a/Cantera/clib/src/ctmultiphase.cpp +++ b/Cantera/clib/src/ctmultiphase.cpp @@ -1,5 +1,6 @@ // Cantera includes +#include "equil.h" #include "MultiPhase.h" #include "MultiPhaseEquil.h" @@ -196,11 +197,10 @@ extern "C" { doublereal DLL_EXPORT mix_equilibrate(int i, char* XY, doublereal err, int maxsteps, int maxiter, int loglevel) { try { - return _mix(i)->equilibrate(_equilflag(XY), + return equilibrate(*_mix(i), XY, err, maxsteps, maxiter, loglevel); } catch (CanteraError) { - write_logfile("equil_err.html"); return DERR; } } diff --git a/Cantera/cxx/demos/flamespeed.cpp b/Cantera/cxx/demos/flamespeed.cpp index 2133e4dcd..0d10d8f30 100644 --- a/Cantera/cxx/demos/flamespeed.cpp +++ b/Cantera/cxx/demos/flamespeed.cpp @@ -57,7 +57,7 @@ int flamespeed(int np, void* p) { gas.getMassFractions(yin); try { - equilibrate(gas,HP); + equilibrate(gas,"HP"); } catch (CanteraError) { showErrors(cout); diff --git a/Cantera/cxx/include/equilibrium.h b/Cantera/cxx/include/equilibrium.h index 169970b72..31c746cad 100755 --- a/Cantera/cxx/include/equilibrium.h +++ b/Cantera/cxx/include/equilibrium.h @@ -5,6 +5,7 @@ */ #ifndef CT_EQUIL_INCL #define CT_EQUIL_INCL +#include "kernel/equil.h" #include "kernel/ChemEquil.h" #include "kernel/MultiPhaseEquil.h" #endif diff --git a/Cantera/fortran/src/fct.cpp b/Cantera/fortran/src/fct.cpp index c04d89c93..c1cbbc036 100644 --- a/Cantera/fortran/src/fct.cpp +++ b/Cantera/fortran/src/fct.cpp @@ -14,7 +14,7 @@ #endif // Cantera includes -#include "ChemEquil.h" +#include "equil.h" #include "KineticsFactory.h" #include "transport/TransportFactory.h" #include "ctml.h" @@ -368,9 +368,9 @@ extern "C" { catch (CanteraError) {handleError(); return -1;} } - status_t DLL_EXPORT th_equil_(const integer* n, integer* XY) { + status_t DLL_EXPORT th_equil_(const integer* n, char* XY, ftnlen lenxy) { try { - equilibrate(*_fth(n), *XY); return 0; + equilibrate(*_fth(n), f2string(XY,lenxy).c_str()); return 0; } catch (CanteraError) {handleError(); return -1;} } diff --git a/Cantera/matlab/cantera/@ThermoPhase/equilibrate.m b/Cantera/matlab/cantera/@ThermoPhase/equilibrate.m index 24bfee247..5749641a4 100644 --- a/Cantera/matlab/cantera/@ThermoPhase/equilibrate.m +++ b/Cantera/matlab/cantera/@ThermoPhase/equilibrate.m @@ -1,17 +1,38 @@ -function a = equilibrate(a, xy, solver, rtol, maxsteps, loglevel) +function a = equilibrate(a, xy, solver, rtol, maxsteps, maxiter, loglevel) % EQUILIBRATE Set the phase to a state of chemical equilibrium. % -% The second argument must be one of the strings 'TP', 'TV', -% 'HP', 'SP', 'SV', 'UV', 'PT', 'VT', 'PH', 'PS', 'VS', or 'VU', -% and specifies the two thermodynamic properties held fixed at -% the values in the initial state. Note that if U, H, V, or S is -% specified, it is the specific value (per unit mass), not the -% molar value, that is held fixed. +% XY -- A two-letter string, which must be one of the set +% ['TP','TV','HP','SP','SV','UV','PT','VT','PH','PS','VS','VU']. +% If H, U, S, or V is specified, the value must be the specific +% value (per unit mass). +% +% solver -- specifies the equilibrium solver to use. If solver +% = 0, a fast solver using the element potential method will be +% used. If solver > 0, a slower but more robust Gibbs +% minimization solver will be used. If solver < 0 or +% unspecified, the fast solver will be tried first, then if it +% fails the other will be tried. +% +% rtol -- the relative error tolerance. +% +% maxsteps -- maximum number of steps in composition to take to +% find a converged solution. +% +% maxiter -- for the Gibbs minimization solver only, this +% specifies the number of 'outer' iterations on T or P when +% some property pair other than TP is specified. +% +% loglevel -- set to a value > 0 to write diagnostic output to +% a file in HTML format. Larger values generate more detailed +% information. The file will be named 'equilibrate_log.html.' +% Subsequent files will be named 'equillibrate_log1.html', +% etc., so that log files are not overwritten. +% % % use the ChemEquil solver by default if nargin < 3 - solver = 0; + solver = -1; end if nargin < 4 rtol = 1.0e-9; @@ -20,38 +41,42 @@ if nargin < 5 maxsteps = 1000; end if nargin < 6 + maxiter = 100; +end +if nargin < 7 loglevel = 0; end iok = 0; -switch xy - case 'TP' - iok = thermo_set(a.tp_id, 50, 104, solver, rtol, maxsteps, loglevel); - case 'TV' - iok = thermo_set(a.tp_id, 50, 100, solver, rtol, maxsteps, loglevel); - case 'HP' - iok = thermo_set(a.tp_id, 50, 101, solver, rtol, maxsteps, loglevel); - case 'SP' - iok = thermo_set(a.tp_id, 50, 102, solver, rtol, maxsteps, loglevel); - case 'SV' - iok = thermo_set(a.tp_id, 50, 107, solver, rtol, maxsteps, loglevel); - case 'UV' - iok = thermo_set(a.tp_id, 50, 105, solver, rtol, maxsteps, loglevel); - case 'PT' - iok = thermo_set(a.tp_id, 50, 104, solver, rtol, maxsteps, loglevel); - case 'VT' - iok = thermo_set(a.tp_id, 50, 100, solver, rtol, maxsteps, loglevel); - case 'PH' - iok = thermo_set(a.tp_id, 50, 101, solver, rtol, maxsteps, loglevel); - case 'PS' - iok = thermo_set(a.tp_id, 50, 102, solver, rtol, maxsteps, loglevel); - case 'VS' - iok = thermo_set(a.tp_id, 50, 107, solver, rtol, maxsteps, loglevel); - case 'VU' - iok = thermo_set(a.tp_id, 50, 105, solver, rtol, maxsteps, loglevel); - otherwise - error('unsupported option') -end +iok = thermo_set(a.tp_id, 50, xy, solver, rtol, maxsteps, maxiter, loglevel); +% $$$ switch xy +% $$$ case 'TP' +% $$$ iok = thermo_set(a.tp_id, 50, 104, solver, rtol, maxsteps, loglevel); +% $$$ case 'TV' +% $$$ iok = thermo_set(a.tp_id, 50, 100, solver, rtol, maxsteps, loglevel); +% $$$ case 'HP' +% $$$ iok = thermo_set(a.tp_id, 50, 101, solver, rtol, maxsteps, loglevel); +% $$$ case 'SP' +% $$$ iok = thermo_set(a.tp_id, 50, 102, solver, rtol, maxsteps, loglevel); +% $$$ case 'SV' +% $$$ iok = thermo_set(a.tp_id, 50, 107, solver, rtol, maxsteps, loglevel); +% $$$ case 'UV' +% $$$ iok = thermo_set(a.tp_id, 50, 105, solver, rtol, maxsteps, loglevel); +% $$$ case 'PT' +% $$$ iok = thermo_set(a.tp_id, 50, 104, solver, rtol, maxsteps, loglevel); +% $$$ case 'VT' +% $$$ iok = thermo_set(a.tp_id, 50, 100, solver, rtol, maxsteps, loglevel); +% $$$ case 'PH' +% $$$ iok = thermo_set(a.tp_id, 50, 101, solver, rtol, maxsteps, loglevel); +% $$$ case 'PS' +% $$$ iok = thermo_set(a.tp_id, 50, 102, solver, rtol, maxsteps, loglevel); +% $$$ case 'VS' +% $$$ iok = thermo_set(a.tp_id, 50, 107, solver, rtol, maxsteps, loglevel); +% $$$ case 'VU' +% $$$ iok = thermo_set(a.tp_id, 50, 105, solver, rtol, maxsteps, loglevel); +% $$$ otherwise +% $$$ error('unsupported option') +% $$$ end if iok < 0 e = geterr; if e == 0 diff --git a/Cantera/matlab/cantera/@ThermoPhase/private/thermo_set.m b/Cantera/matlab/cantera/@ThermoPhase/private/thermo_set.m index 5341b05dd..a9f8394ba 100644 --- a/Cantera/matlab/cantera/@ThermoPhase/private/thermo_set.m +++ b/Cantera/matlab/cantera/@ThermoPhase/private/thermo_set.m @@ -1,4 +1,4 @@ -function i = thermo_set(n, job, a, b, c, d, e) +function i = thermo_set(n, job, a, b, c, d, e, f) if nargin == 2 i = ctmethods(20,n,-job); elseif nargin == 3 @@ -11,4 +11,6 @@ elseif nargin == 6 i = ctmethods(20, n,-job, a, b, c, d); elseif nargin == 7 i = ctmethods(20, n,-job, a, b, c, d, e); +elseif nargin == 8 + i = ctmethods(20, n,-job, a, b, c, d, e, f); end \ No newline at end of file diff --git a/Cantera/matlab/cantera/private/thermomethods.cpp b/Cantera/matlab/cantera/private/thermomethods.cpp index 571ceab3d..e6a593022 100644 --- a/Cantera/matlab/cantera/private/thermomethods.cpp +++ b/Cantera/matlab/cantera/private/thermomethods.cpp @@ -60,12 +60,13 @@ static void thermoset( int nlhs, mxArray *plhs[], // equilibrate else if (job == 50) { - int xy = getInt(prhs[3]); //int(*ptr); + char* xy = getString(prhs[3]); //int(*ptr); int solver = getInt(prhs[4]); double rtol = getDouble(prhs[5]); int maxsteps = getInt(prhs[6]); - int loglevel = getInt(prhs[7]); - ierr = th_equil(th, xy, solver, rtol, maxsteps, loglevel); + int maxiter = getInt(prhs[7]); + int loglevel = getInt(prhs[8]); + ierr = th_equil(th, xy, solver, rtol, maxsteps, maxiter, loglevel); } if (ierr < 0) reportError(); diff --git a/Cantera/python/Cantera/ThermoPhase.py b/Cantera/python/Cantera/ThermoPhase.py index 604f7ecf5..ded478e29 100644 --- a/Cantera/python/Cantera/ThermoPhase.py +++ b/Cantera/python/Cantera/ThermoPhase.py @@ -269,20 +269,41 @@ class ThermoPhase(Phase): """Set the electric potential.""" _cantera.thermo_setfp(self._phase_id, 6, v, 0); - def equilibrate(self, XY, solver = 0, rtol = 1.0e-9, - maxsteps = 1000, loglevel = 0): + def equilibrate(self, XY, solver = -1, rtol = 1.0e-9, + maxsteps = 1000, maxiter = 100, loglevel = 0): """Set to a state of chemical equilibrium holding property pair - 'XY' constant. The pair is specified by a two-letter string, - which must be one of the set + 'XY' constant. + + XY -- A two-letter string, which must be one of the set ['TP','TV','HP','SP','SV','UV','PT','VT','PH','PS','VS','VU']. If H, U, S, or V is specified, the value must be the specific value (per unit mass). + + solver -- specifies the equilibrium solver to use. If solver = + 0, a fast solver using the element potential method will be + used. If solver > 0, a slower but more robust Gibbs + minimization solver will be used. If solver < 0 or + unspecified, the fast solver will be tried first, then if it + fails the other will be tried. + + rtol -- the relative error tolerance. + + maxsteps -- maximum number of steps in composition to take to + find a converged solution. + + maxiter -- for the Gibbs minimization solver only, this + specifies the number of 'outer' iterations on T or P when some + property pair other than TP is specified. + + loglevel -- set to a value > 0 to write diagnostic output to a + file in HTML format. Larger values generate more detailed + information. The file will be named 'equilibrate_log.html.' + Subsequent files will be named 'equillibrate_log1.html', etc., + so that log files are not overwritten. + """ - ixy = ThermoPhase._equilmap[XY] - if ixy > 0: - _cantera.thermo_equil(self._phase_id, ixy, solver, rtol, maxsteps, loglevel) - else: - raise 'invalid equilibrium option: '+XY + _cantera.thermo_equil(self._phase_id, XY, solver, + rtol, maxsteps, maxiter, loglevel) def critTemperature(self): diff --git a/Cantera/python/Cantera/mixture.py b/Cantera/python/Cantera/mixture.py index 3054f3e3d..66556e39b 100644 --- a/Cantera/python/Cantera/mixture.py +++ b/Cantera/python/Cantera/mixture.py @@ -288,8 +288,6 @@ class Mixture: """ i = _cantera.mix_equilibrate(self.__mixid, XY, err, maxsteps, maxiter, loglevel) - if loglevel > 0: - writeLogFile("equilibrate_log"); def selectSpecies(self, f, species): """Given an array 'f' of floating-point species properties, diff --git a/Cantera/python/examples/equilibrium/stoich.py b/Cantera/python/examples/equilibrium/stoich.py index 77339c617..50f51b107 100644 --- a/Cantera/python/examples/equilibrium/stoich.py +++ b/Cantera/python/examples/equilibrium/stoich.py @@ -27,8 +27,17 @@ gas.set(T = temp, P = OneAtm, X = comp) # (ChemEquil) solver... (This will fail, throwing an exception that # will be caught in the 'except' block, where we will try the other # solver.) + +#################################################################### +# Note: We are setting solver = 0 here to demonstrate the difference +# between the two solvers. If you do not set 'solver', or set it to a +# negative value, then ChemEquil will be tried first, and if it fails +# the MultiPhaseEquil solver will be tried. In most cases this will +# give the best results. +#################################################################### + try: - gas.equilibrate("TP") + gas.equilibrate("TP", solver = 0) # use the ChemEquil (0) solver except: print "ChemEquil solver failed! Try the MultiPhaseEquil solver..." @@ -42,6 +51,9 @@ except: # 1.0e-9), max_steps (default = 1000), loglevel (default = 0). mix = Mixture([(gas,1.0)]) mix.equilibrate("TP", loglevel=4) + + # Note: another way to do this is: + # gas.equilibrate("TP", solver = 1, loglevel = 4) # print a summary of the results print gas diff --git a/Cantera/python/src/ctthermo_methods.cpp b/Cantera/python/src/ctthermo_methods.cpp index 87de53e01..8da921e6a 100644 --- a/Cantera/python/src/ctthermo_methods.cpp +++ b/Cantera/python/src/ctthermo_methods.cpp @@ -231,17 +231,18 @@ thermo_equil(PyObject *self, PyObject *args) { int iok = -2; int th; - int XY; + char* XY; int solver; double rtol; int maxsteps; + int maxiter; int loglevel; - if (!PyArg_ParseTuple(args, "iiidii:thermo_equil", &th, &XY, - &solver, &rtol, &maxsteps, &loglevel)) + if (!PyArg_ParseTuple(args, "isidiii:thermo_equil", &th, &XY, + &solver, &rtol, &maxsteps, &maxiter, &loglevel)) return NULL; - iok = th_equil(th, XY, solver, rtol, maxsteps, loglevel); + iok = th_equil(th, XY, solver, rtol, maxsteps, maxiter, loglevel); if (iok >= 0) return Py_BuildValue("i",iok); if (iok == -1) return reportCanteraError(); diff --git a/Cantera/src/Makefile.in b/Cantera/src/Makefile.in index 0608c3f8f..98e039d1a 100755 --- a/Cantera/src/Makefile.in +++ b/Cantera/src/Makefile.in @@ -72,8 +72,8 @@ HETEROKIN = $(THERMO) $(HETEROKIN_OBJ) CK = $(KINETICS) # chemical equilibrium -EQUIL_OBJ = ChemEquil.o MultiPhaseEquil.o sort.o MultiPhase.o -EQUIL_H = ChemEquil.h MultiPhaseEquil.h MultiPhase.h sort.h +EQUIL_OBJ = ChemEquil.o MultiPhaseEquil.o sort.o MultiPhase.o equilibrate.o +EQUIL_H = ChemEquil.h MultiPhaseEquil.h MultiPhase.h sort.h equil.h EQUIL = $(THERMO) $(EQUIL_OBJ) # reaction path analysis diff --git a/Cantera/src/PropertyCalculator.h b/Cantera/src/PropertyCalculator.h index 669205b28..efa37d38a 100755 --- a/Cantera/src/PropertyCalculator.h +++ b/Cantera/src/PropertyCalculator.h @@ -15,10 +15,15 @@ namespace Cantera { + /// Classes used by ChemEquil. These classes are used only by the + /// ChemEquil equilibrium solver. Each one returns a particular + /// property of the object supplied as the argument. + /// template class PropertyCalculator { public: virtual doublereal value(const M& s) =0; + virtual string symbol() =0; }; template @@ -27,6 +32,7 @@ namespace Cantera { virtual doublereal value(const M& s) { return s.enthalpy_mass(); } + virtual string symbol() { return "H"; } }; template @@ -35,6 +41,7 @@ namespace Cantera { virtual doublereal value(const M& s) { return s.entropy_mass(); } + virtual string symbol() { return "S"; } }; template @@ -43,6 +50,7 @@ namespace Cantera { virtual doublereal value(const M& s) { return s.temperature(); } + virtual string symbol() { return "T"; } }; template @@ -51,6 +59,7 @@ namespace Cantera { virtual doublereal value(const M& s) { return s.pressure(); } + virtual string symbol() { return "P"; } }; template @@ -59,6 +68,7 @@ namespace Cantera { virtual doublereal value(const M& s) { return s.density(); } + virtual string symbol() { return "V"; } }; template @@ -67,6 +77,7 @@ namespace Cantera { virtual doublereal value(const M& s) { return s.intEnergy_mass(); } + virtual string symbol() { return "U"; } }; } diff --git a/Cantera/src/ThermoPhase.h b/Cantera/src/ThermoPhase.h index b267fa7e3..b739f524a 100755 --- a/Cantera/src/ThermoPhase.h +++ b/Cantera/src/ThermoPhase.h @@ -73,7 +73,7 @@ namespace Cantera { /// a base class, so this constructor should not be called /// explicitly. ThermoPhase() : Phase(), m_spthermo(0), m_speciesData(0), - m_index(-1), m_phi(0.0) {} + m_index(-1), m_phi(0.0), m_hasElementPotentials(false) {} /// Destructor. Deletes the species thermo manager. @@ -684,10 +684,12 @@ namespace Cantera { // the element potentials to this object void setElementPotentials(const vector_fp& lambda) { m_lambda = lambda; + m_hasElementPotentials = true; } void getElementPotentials(doublereal* lambda) { - copy(m_lambda.begin(), m_lambda.end(), lambda); + if (m_hasElementPotentials) + copy(m_lambda.begin(), m_lambda.end(), lambda); } //@} @@ -809,7 +811,7 @@ namespace Cantera { * * @see importCTML.cpp */ - virtual void initThermo() {} + virtual void initThermo() { } @@ -876,6 +878,7 @@ namespace Cantera { int m_index; doublereal m_phi; vector_fp m_lambda; + bool m_hasElementPotentials; private: diff --git a/Cantera/src/global.h b/Cantera/src/global.h index 3f787648d..016cd0577 100755 --- a/Cantera/src/global.h +++ b/Cantera/src/global.h @@ -91,10 +91,24 @@ namespace Cantera { /// Close a Cantera input file. void close_XML_File(string file); - void beginLogGroup(string title, int loglevel=1); - void addLogEntry(string tag, string value, int loglevel=1); - void endLogGroup(int loglevel=1); +#ifdef WITH_HTML_LOGS + void beginLogGroup(string title, int loglevel=-99); + void addLogEntry(string tag, string value); + void addLogEntry(string tag, doublereal value); + void addLogEntry(string tag, int value); + void addLogEntry(string msg); + void endLogGroup(string title=""); void write_logfile(string file = "log.html"); +#else + inline void beginLogGroup(string title, int loglevel=-99) {} + inline void addLogEntry(string tag, string value) {} + inline void addLogEntry(string tag, doublereal value) {} + inline void addLogEntry(string tag, int value) {} + inline void addLogEntry(string msg) {} + inline void endLogGroup(string title="") {} + inline void write_logfile(string file = "log.html") {} +#endif + } #endif diff --git a/Cantera/src/misc.cpp b/Cantera/src/misc.cpp index de0cf7fd5..86663f6ce 100755 --- a/Cantera/src/misc.cpp +++ b/Cantera/src/misc.cpp @@ -57,8 +57,11 @@ namespace Cantera { // install a default logwriter that writes to standard // output / standard error logwriter = new Logger(); + + // HTML log files xmllog = 0; current = 0; + loglevel = 0; } /// Delete any open XML trees, the logwriter, and @@ -72,7 +75,8 @@ namespace Cantera { } delete logwriter; if (xmllog) { - delete xmllog; + write_logfile("orphan"); + //delete xmllog; } } @@ -89,6 +93,9 @@ namespace Cantera { string sleep; Logger* logwriter; XML_Node *xmllog, *current; + int loglevel; + vector loglevels; + vector loggroups; }; @@ -624,7 +631,7 @@ namespace Cantera { __app->logwriter = logwriter; } - +#ifdef WITH_HTML_LOGS ///////////////////////////////////////////////////////////////// /// @@ -638,16 +645,19 @@ namespace Cantera { /// C. You want to be able to print diagnostic messages just from /// function A, or from A and B, or from A, B, and C, or to turn /// off printing diagnostic messages altogether. All you need to - /// do is to pass into each function the parameter loglevel, and - /// when calling other functions decrement the value of - /// logvalue. Since the procedures that print HTML log output only - /// do so if loglevel > 0, the initial value of loglevel controls - /// how deeply nested the log messages will be. For an example of - /// how to do this, see files MultiPhase.cpp and - /// MultiPhaseEquil.cpp. + /// do is call 'beginLogGroup' within function A, and specify a + /// loglevel value. Then in B, call beginLogGroup again, but + /// without an explicit value for loglevel. By default, the + /// current level is decremented by one in beginLogGroup. If it + /// is <= 0, no log messages are written. Thus, if each function + /// begins with beginLogGroup and calls endLogGroup before + /// returning, then setting loglevel = 3 will cause messages from + /// A, B, and C to be written (in nested HTML lists), loglevel = + /// 2 results in messages only being written from A and B, etc. /// ////////////////////////////////////////////////////////////////// + /// Create a new group for log messages. Usually this is called /// upon entering the function, with the title parameter equal to /// the name of the function or method. Subsequent messages @@ -655,22 +665,49 @@ namespace Cantera { /// heading, until endLogGroup() is called. /// @ingroup HTML_logs void beginLogGroup(string title, int loglevel) { - if (loglevel <= 0) return; appinit(); + if (loglevel != -99) __app->loglevel = loglevel; + else __app->loglevel--; + __app->loglevels.push_back(__app->loglevel); + __app->loggroups.push_back(title); + if (__app->loglevel <= 0) return; if (__app->xmllog == 0) { __app->xmllog = new XML_Node("html"); __app->current = &__app->xmllog->addChild("ul"); } - __app->current = &__app->current->addChild("li",title); + __app->current = &__app->current->addChild("li",""+title+""); __app->current = &__app->current->addChild("ul"); } /// Add an entry to the log file. Entries appear in the form "tag: /// value". /// @ingroup HTML_logs - void addLogEntry(string tag, string value, int loglevel) { - if (loglevel <= 0) return; - __app->current->addChild("li",tag+": "+value); + void addLogEntry(string tag, string value) { + if (__app->loglevel > 0) + __app->current->addChild("li",tag+": "+value); + } + + /// Add an entry to the log file. Entries appear in the form "tag: + /// value". + /// @ingroup HTML_logs + void addLogEntry(string tag, doublereal value) { + if (__app->loglevel > 0) + __app->current->addChild("li",tag+": "+fp2str(value)); + } + + /// Add an entry to the log file. Entries appear in the form "tag: + /// value". + /// @ingroup HTML_logs + void addLogEntry(string tag, int value) { + if (__app->loglevel > 0) + __app->current->addChild("li",tag+": "+int2str(value)); + } + + /// Add an entry to the log file. + /// @ingroup HTML_logs + void addLogEntry(string msg) { + if (__app->loglevel > 0) + __app->current->addChild("li",msg); } /// Close the current group of log messages. This is typically @@ -680,13 +717,27 @@ namespace Cantera { /// appear at the next-higher level in the outline, unless /// beginLogGroup is called first to create a new group. /// @ingroup HTML_logs - void endLogGroup(int loglevel) { - if (loglevel <= 0) return; - __app->current = __app->current->parent(); - __app->current = __app->current->parent(); + void endLogGroup(string title) { + if (__app->loglevel > 0) { + __app->current = __app->current->parent(); + __app->current = __app->current->parent(); + } + __app->loglevels.pop_back(); + __app->loglevel = __app->loglevels.back(); + if (title != "" && title != __app->loggroups.back()) { + writelog("Logfile error." + "\n beginLogGroup: "+ __app->loggroups.back()+ + "\n endLogGroup; "+title+"\n"); + } + if (__app->loggroups.size() == 1) { + write_logfile(__app->loggroups.back()+"_log"); + __app->loggroups.clear(); + __app->loglevels.clear(); + } + else + __app->loggroups.pop_back(); } - /// Write the HTML log file. Log entries are stored in memory in /// an XML tree until this function is called, which writes the /// tree to a file and clears the entries stored in memory. The @@ -739,5 +790,7 @@ namespace Cantera { __app->current = 0; } } + +#endif // WITH_HTML_LOGS } diff --git a/config.h.in b/config.h.in index c106217f2..fd2930a79 100755 --- a/config.h.in +++ b/config.h.in @@ -97,6 +97,8 @@ typedef int ftnlen; // Fortran hidden string length type #undef INCL_PURE_FLUIDS +#define WITH_HTML_LOGS + //--------------------- compile options ---------------------------- #undef USE_PCH diff --git a/config/configure b/config/configure index 5f66ba3a6..478329d4e 100755 --- a/config/configure +++ b/config/configure @@ -1589,7 +1589,7 @@ BUILD_CK= NEED_CKREADER= NEED_LAPACK= -NEED_RECIPES= +#NEED_RECIPES= NEED_MATH= NEED_TPX= NEED_F2C= @@ -1661,7 +1661,7 @@ if test "$ENABLE_EQUIL" = "y" ; then KERNEL=$KERNEL' 'equil KERNEL_OBJ=$KERNEL_OBJ' $(EQUIL_OBJ)' NEED_LAPACK=1 - NEED_RECIPES=1 +# NEED_RECIPES=1 fi if test "$ENABLE_REACTORS" = "y" ; then @@ -1786,9 +1786,9 @@ fi LOCAL_LIBS=$LOCAL_LIBS' '-lcantera -if test -n "$NEED_RECIPES" -then LOCAL_LIBS=$LOCAL_LIBS' '-lrecipes -fi +#if test -n "$NEED_RECIPES" +#then LOCAL_LIBS=$LOCAL_LIBS' '-lrecipes +#fi if test -n "$NEED_CVODE" then LOCAL_LIBS=$LOCAL_LIBS' '-lcvode @@ -3875,8 +3875,6 @@ fi if test "x${BUILD_F90}" != "x0"; then - echo F90 = $F90 - echo BUILD_F90 = $BUILD_F90 if test "$F90" = "default" -o \ "$F90"x = "x"; then for ac_prog in f95 gfortran g95 @@ -4045,11 +4043,11 @@ if test -z "$OBJ_EXT"; then OBJ_EXT=$OBJEXT; fi if test -z "$EXE_EXT"; then EXE_EXT=$EXEEXT; fi -local_math_libs='-lrecipes -lcvode' +local_math_libs='-lcvode' -math_libs='-lrecipes -lcvode -lctmath' +math_libs='-lcvode -lctmath' if test "$LAPACK_FTN_TRAILING_UNDERSCORE" = "y" @@ -4108,7 +4106,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu - ac_config_files="$ac_config_files ../Cantera/Makefile ../Cantera/src/Makefile ../Cantera/src/zeroD/Makefile ../Cantera/src/oneD/Makefile ../Cantera/src/converters/Makefile ../Cantera/src/transport/Makefile ../Cantera/clib/src/Makefile ../Cantera/fortran/src/Makefile ../Cantera/fortran/f77demos/f77demos.mak ../Cantera/fortran/f77demos/isentropic.dsp ../Cantera/matlab/Makefile ../Cantera/matlab/setup_matlab.py ../Cantera/matlab/setup_winmatlab.py ../Cantera/python/Makefile ../Cantera/python/setup.py ../Cantera/cxx/Makefile ../Cantera/cxx/src/Makefile ../Cantera/cxx/demos/Makefile ../Cantera/user/Makefile ../Cantera/python/src/Makefile ../ext/lapack/Makefile ../ext/blas/Makefile ../ext/cvode/Makefile ../ext/math/Makefile ../ext/tpx/Makefile ../ext/Makefile ../ext/recipes/Makefile ../ext/f2c_libs/Makefile ../ext/f2c_blas/Makefile ../ext/f2c_lapack/Makefile ../ext/f2c_math/Makefile ../ext/f2c_recipes/Makefile ../examples/Makefile ../examples/cxx/Makefile ../Makefile ../tools/Makefile ../tools/src/Makefile ../tools/src/sample.mak ../tools/src/finish_install.py ../tools/src/package4mac ../tools/templates/f77/demo.mak ../tools/templates/f90/demo.mak ../tools/templates/cxx/demo.mak ../tools/testtools/Makefile ../data/inputs/Makefile ../test_problems/Makefile ../test_problems/cxx_ex/Makefile ../test_problems/silane_equil/Makefile ../test_problems/surfkin/Makefile ../test_problems/diamondSurf/Makefile ../test_problems/ck2cti_test/Makefile ../test_problems/ck2cti_test/runtest ../test_problems/python/Makefile ../bin/install_tsc" + ac_config_files="$ac_config_files ../Cantera/Makefile ../Cantera/src/Makefile ../Cantera/src/zeroD/Makefile ../Cantera/src/oneD/Makefile ../Cantera/src/converters/Makefile ../Cantera/src/transport/Makefile ../Cantera/clib/src/Makefile ../Cantera/fortran/src/Makefile ../Cantera/fortran/f77demos/f77demos.mak ../Cantera/fortran/f77demos/isentropic.dsp ../Cantera/matlab/Makefile ../Cantera/matlab/setup_matlab.py ../Cantera/matlab/setup_winmatlab.py ../Cantera/python/Makefile ../Cantera/python/setup.py ../Cantera/cxx/Makefile ../Cantera/cxx/src/Makefile ../Cantera/cxx/demos/Makefile ../Cantera/user/Makefile ../Cantera/python/src/Makefile ../ext/lapack/Makefile ../ext/blas/Makefile ../ext/cvode/Makefile ../ext/math/Makefile ../ext/tpx/Makefile ../ext/Makefile ../ext/f2c_libs/Makefile ../ext/f2c_blas/Makefile ../ext/f2c_lapack/Makefile ../ext/f2c_math/Makefile ../examples/Makefile ../examples/cxx/Makefile ../Makefile ../tools/Makefile ../tools/src/Makefile ../tools/src/sample.mak ../tools/src/finish_install.py ../tools/src/package4mac ../tools/templates/f77/demo.mak ../tools/templates/f90/demo.mak ../tools/templates/cxx/demo.mak ../tools/testtools/Makefile ../data/inputs/Makefile ../test_problems/Makefile ../test_problems/cxx_ex/Makefile ../test_problems/silane_equil/Makefile ../test_problems/surfkin/Makefile ../test_problems/diamondSurf/Makefile ../test_problems/ck2cti_test/Makefile ../test_problems/ck2cti_test/runtest ../test_problems/python/Makefile ../bin/install_tsc" test "x$prefix" = xNONE && prefix=$ac_default_prefix @@ -4606,12 +4604,10 @@ do "../ext/math/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/math/Makefile" ;; "../ext/tpx/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/tpx/Makefile" ;; "../ext/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/Makefile" ;; - "../ext/recipes/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/recipes/Makefile" ;; "../ext/f2c_libs/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/f2c_libs/Makefile" ;; "../ext/f2c_blas/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/f2c_blas/Makefile" ;; "../ext/f2c_lapack/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/f2c_lapack/Makefile" ;; "../ext/f2c_math/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/f2c_math/Makefile" ;; - "../ext/f2c_recipes/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../ext/f2c_recipes/Makefile" ;; "../examples/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../examples/Makefile" ;; "../examples/cxx/Makefile" ) CONFIG_FILES="$CONFIG_FILES ../examples/cxx/Makefile" ;; "../Makefile" ) CONFIG_FILES="$CONFIG_FILES ../Makefile" ;; diff --git a/config/configure.in b/config/configure.in index 9ac1856da..6b7383576 100755 --- a/config/configure.in +++ b/config/configure.in @@ -246,7 +246,7 @@ BUILD_CK= NEED_CKREADER= NEED_LAPACK= -NEED_RECIPES= +#NEED_RECIPES= NEED_MATH= NEED_TPX= NEED_F2C= @@ -306,7 +306,7 @@ if test "$ENABLE_EQUIL" = "y" ; then KERNEL=$KERNEL' 'equil KERNEL_OBJ=$KERNEL_OBJ' $(EQUIL_OBJ)' NEED_LAPACK=1 - NEED_RECIPES=1 +# NEED_RECIPES=1 fi if test "$ENABLE_REACTORS" = "y" ; then @@ -428,9 +428,9 @@ fi LOCAL_LIBS=$LOCAL_LIBS' '-lcantera -if test -n "$NEED_RECIPES" -then LOCAL_LIBS=$LOCAL_LIBS' '-lrecipes -fi +#if test -n "$NEED_RECIPES" +#then LOCAL_LIBS=$LOCAL_LIBS' '-lrecipes +#fi if test -n "$NEED_CVODE" then LOCAL_LIBS=$LOCAL_LIBS' '-lcvode @@ -768,11 +768,11 @@ if test -z "$EXE_EXT"; then EXE_EXT=$EXEEXT; fi AC_SUBST(EXE_EXT) dnl AC_LANG_FORTRAN77 -local_math_libs='-lrecipes -lcvode' +local_math_libs='-lcvode' AC_SUBST(local_math_libs) -math_libs='-lrecipes -lcvode -lctmath' +math_libs='-lcvode -lctmath' AC_SUBST(math_libs) if test "$LAPACK_FTN_TRAILING_UNDERSCORE" = "y" @@ -845,12 +845,10 @@ AC_OUTPUT(../Cantera/Makefile \ ../ext/math/Makefile \ ../ext/tpx/Makefile \ ../ext/Makefile \ - ../ext/recipes/Makefile \ ../ext/f2c_libs/Makefile \ ../ext/f2c_blas/Makefile \ ../ext/f2c_lapack/Makefile \ ../ext/f2c_math/Makefile \ - ../ext/f2c_recipes/Makefile \ ../examples/Makefile \ ../examples/cxx/Makefile \ ../Makefile \ diff --git a/configure b/configure index 1ce6f8a58..9cb7391c7 100755 --- a/configure +++ b/configure @@ -139,7 +139,7 @@ F90=${F90:="default"} # these compilers will be added automatically, and you do not need to # specify them here. Otherwise, add any required compiler-specific # flags here. -F90FLAGS=${F90FLAGS:='-O3 -g'} +F90FLAGS=${F90FLAGS:='-O3'} #---------------------------------------------------------------------- @@ -305,7 +305,7 @@ F77=${F77:=g77} # Fortran 77 compiler flags. Note that the Fortran compiler flags must be set # to produce object code compatible with the C/C++ compiler you are using. -FFLAGS=${FFLAGS:='-O3 -g'} +FFLAGS=${FFLAGS:='-O3'} # the additional Fortran flags required for linking, if any. Leave commented # out if no additional flags are required. diff --git a/examples/cxx/equil_example1.cpp b/examples/cxx/equil_example1.cpp index 310ef983a..997ff0f56 100755 --- a/examples/cxx/equil_example1.cpp +++ b/examples/cxx/equil_example1.cpp @@ -88,8 +88,7 @@ int equil_example1(int job) { if (temp > gas.maxTemp()) break; gas.setState_TPX(temp, pres, "SIH4:0.01, H2:1.0"); try { - // This uses the MultiPhaseEquil solver. - equilibrate(gas,TP,1); + equilibrate(gas,"TP",-1,1.0e-9,1000,100,10); output(0,i) = temp; output(1,i) = gas.pressure(); gas.getMoleFractions(&output(2,i)); diff --git a/examples/cxx/transport_example2.cpp b/examples/cxx/transport_example2.cpp index cd95bc23d..e37a07b1b 100755 --- a/examples/cxx/transport_example2.cpp +++ b/examples/cxx/transport_example2.cpp @@ -65,7 +65,7 @@ int transport_example2(int job) { doublereal temp = 2000.0; doublereal pres = 2.0*OneAtm; gas.setState_TPX(temp, pres, "H2:1.0, O2:0.5, CH4:0.1, N2:0.2"); - equilibrate(gas,TP); + equilibrate(gas,"TP"); // create a transport manager that implements diff --git a/test_problems/ck2cti_test/runtest.in b/test_problems/ck2cti_test/runtest.in index 3734e05d0..5b8bb2b73 100755 --- a/test_problems/ck2cti_test/runtest.in +++ b/test_problems/ck2cti_test/runtest.in @@ -1,6 +1,11 @@ #!/bin/sh # $Id$ # +echo " " +echo "***************************************************" +echo " Testing CK2CTI " +echo "***************************************************" +echo " " BINDIR=@buildbin@ CK2CTI=$BINDIR/ck2cti $CK2CTI -i ./gri30.inp -id gri30 -tr ./gri30_tran.dat @@ -26,4 +31,5 @@ then else echo "unsuccessful diff comparison on ck2cti test" fi +echo diff --git a/test_problems/cxx_ex/runtest b/test_problems/cxx_ex/runtest index e22deeb31..8963e4f5d 100755 --- a/test_problems/cxx_ex/runtest +++ b/test_problems/cxx_ex/runtest @@ -6,6 +6,11 @@ temp_success="1" /bin/rm -f eq1.csv tr1.csv tr2.csv kin1.csv kin2.csv \ kin1_blessed_tmp.csv kin2_blessed_tmp.csv +echo " " +echo "***************************************************" +echo " Testing the Cantera C++ Examples " +echo "***************************************************" +echo " " ################################################################# # ################################################################# @@ -140,6 +145,8 @@ else echo 'cxx_examples csv test FAILED!' fi +echo + ################################################################# # ################################################################# diff --git a/test_problems/python/runtest b/test_problems/python/runtest index 877da74fb..1283d4502 100755 --- a/test_problems/python/runtest +++ b/test_problems/python/runtest @@ -27,7 +27,12 @@ FIRSTARG=$1 PYTHON_CMD=${FIRSTARG:=PYTHON_CMDA} #echo $PYTHON_CMD - +echo " " +echo "***************************************************" +echo " Testing the Cantera Python Interface " +echo "***************************************************" +echo " " +echo "Testing a flame simulation..." $PYTHON_CMD ../../Cantera/python/examples/flames/flame1.py > flame1.out retnStat=$? if [ $retnStat != "0" ] @@ -36,14 +41,6 @@ then echo "flame1.py returned with bad status, $retnStat, check output" fi -$PYTHON_CMD ../../Cantera/python/examples/surface_chemistry/diamond.py > diamond.out -retnStat=$? -if [ $retnStat != "0" ] -then - temp_success="0" - echo "diamond.py returned with bad status, $retnStat, check output" -fi - ################################################################# # ################################################################# @@ -70,11 +67,21 @@ else echo "FAILED" > csvCode.txt temp_success="0" fi +echo " " ################################################################# # ################################################################# +echo "Testing surface chemistry..." +$PYTHON_CMD ../../Cantera/python/examples/surface_chemistry/diamond.py > diamond.out +retnStat=$? +if [ $retnStat != "0" ] +then + temp_success="0" + echo "diamond.py returned with bad status, $retnStat, check output" +fi + $CANTERA_BIN/csvdiff diamond.csv diamond_blessed.csv > diamond_test.out retnStat=$? if [ $retnStat = "1" ] @@ -89,10 +96,12 @@ else echo "FAILED" > csvCode.txt temp_success="0" fi +echo ################################################################# # ################################################################# +echo "testing handling of fractional product stoichiometric coefficients..." $PYTHON_CMD frac.py > frac_test.out diff -w frac_test.out frac_blessed.out > diff_test.out retnStat=$? @@ -104,6 +113,7 @@ else echo "FAILED" > csvCode.txt temp_success="0" fi +echo if [ $temp_success = "1" ] then @@ -112,6 +122,7 @@ else echo 'Python csv test FAILED!' fi + ################################################################# # ################################################################# diff --git a/test_problems/silane_equil/silane_equil.cpp b/test_problems/silane_equil/silane_equil.cpp index 655ce42cc..2bf2e97d9 100644 --- a/test_problems/silane_equil/silane_equil.cpp +++ b/test_problems/silane_equil/silane_equil.cpp @@ -17,7 +17,7 @@ int main(int argc, char **argv) { IdealGasMix g("silane.xml", "silane"); g.setState_TPX(1500.0, 100.0, "SIH4:0.01, H2:0.99"); //g.setState_TPX(1500.0, 1.0132E5, "SIH4:0.01, H2:0.99"); - equilibrate(g, TP); + equilibrate(g, "TP"); cout << g; return 0; }