From ee95c60813ae376b35a9e07b0e0d90bf0dd940db Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 16 Nov 2015 00:12:33 -0500 Subject: [PATCH] Simplify error handling to eliminate need for global error stack All of the functions for manipulating the global error stack (CanteraError::save, setError, showErrors, etc.) are deprecated. The ability to store an error is retained only for use in the C and Fortran interfaces so that the last error message can be retrieved after a function returns an error code. --- doc/sphinx/cxx-guide/simple-example.rst | 4 +- include/cantera/base/ctexceptions.h | 10 +- include/cantera/base/global.h | 6 + src/base/application.cpp | 58 ++--- src/base/application.h | 10 +- src/base/ctexceptions.cpp | 4 +- src/base/global.cpp | 4 + src/clib/clib_defs.h | 7 +- src/clib/ct.cpp | 2 +- src/equil/ChemEquil.cpp | 76 +++---- src/equil/MultiPhase.cpp | 10 +- src/fortran/fct.cpp | 2 +- src/thermo/MolalityVPSSTP.cpp | 5 +- src/thermo/MolarityIonicVPSSTP.cpp | 5 +- src/thermo/PureFluidPhase.cpp | 3 +- src/thermo/ThermoPhase.cpp | 5 +- src/thermo/VPSSMgrFactory.cpp | 1 - src/transport/MultiTransport.cpp | 8 +- src/transport/TransportFactory.cpp | 208 +++++++++--------- .../cathermo/testWaterTP/testWaterSSTP.cpp | 2 - .../simpleTransport/simpleTransportTest.cpp | 4 +- 21 files changed, 183 insertions(+), 251 deletions(-) diff --git a/doc/sphinx/cxx-guide/simple-example.rst b/doc/sphinx/cxx-guide/simple-example.rst index 8f1ea2715..a6ea2ea3d 100644 --- a/doc/sphinx/cxx-guide/simple-example.rst +++ b/doc/sphinx/cxx-guide/simple-example.rst @@ -50,9 +50,7 @@ The entire body of the program is put inside a function that is invoked within a ``try`` block in the main program. In this way, exceptions thrown in the function or in any procedure it calls may be caught. In this program, a ``catch`` block is defined for exceptions of type :ct:`CanteraError`. Cantera -throws exceptions of this type, so it is always a good idea to catch them. In -the ``catch`` block, function :ct:`showErrors` may be called to print the error -message associated with the exception. +throws exceptions of this type, so it is always a good idea to catch them. The ``report`` function ======================= diff --git a/include/cantera/base/ctexceptions.h b/include/cantera/base/ctexceptions.h index c36a5ea83..085b3a900 100644 --- a/include/cantera/base/ctexceptions.h +++ b/include/cantera/base/ctexceptions.h @@ -35,9 +35,6 @@ namespace Cantera * * \include demo1a.cpp * - * The function showErrors() will print out the fatal error condition to - * standard output. - * * A group of defines may be used during debugging to assert conditions which * should be true. These are named AssertTrace(), AssertThrow(), and * AssertThrowMsg(). Examples of their usage is given below. @@ -69,9 +66,6 @@ class CanteraError : public std::exception public: //! Normal Constructor for the CanteraError base class /*! - * In the constructor, a call to the Application class is made to store - * the strings associated with the generated error condition. - * * @param procedure String name for the function within which the error was * generated. * @param msg Descriptive string describing the type of error message. @@ -87,9 +81,6 @@ public: } else { msg_ = fmt::format(msg, args...); } - // Save the error in the global list of errors so that showError() - // can work - save(); } //! Destructor for base class does nothing @@ -99,6 +90,7 @@ public: const char* what() const throw(); //! Function to put this error onto Cantera's error stack + //! @deprecated Unused. To be removed after Cantera 2.3. void save(); //! Method overridden by derived classes to format the error message diff --git a/include/cantera/base/global.h b/include/cantera/base/global.h index 785506735..64c379edc 100644 --- a/include/cantera/base/global.h +++ b/include/cantera/base/global.h @@ -29,22 +29,28 @@ class Logger; //! Return the number of errors that have been encountered so far /*! * @ingroup errorhandling + * @deprecated Unused. To be removed after Cantera 2.3. */ int nErrors(); //! @copydoc Application::Messages::lastErrorMessage +//! @deprecated Unused. To be removed after Cantera 2.3. std::string lastErrorMessage(); //! @copydoc Application::Messages::addError +//! @deprecated Unused. To be removed after Cantera 2.3. void setError(const std::string& r, const std::string& msg); //! @copydoc Application::Messages::getErrors +//! @deprecated Unused. To be removed after Cantera 2.3. void showErrors(std::ostream& f); //! @copydoc Application::Messages::logErrors +//! @deprecated Unused. To be removed after Cantera 2.3. void showErrors(); //! @copydoc Application::Messages::popError +//! @deprecated Unused. To be removed after Cantera 2.3. void popError(); /*! diff --git a/src/base/application.cpp b/src/base/application.cpp index 8a0667f3b..78526623a 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -60,8 +60,7 @@ Application::Messages::Messages() } Application::Messages::Messages(const Messages& r) : - errorMessage(r.errorMessage), - errorRoutine(r.errorRoutine) + errorMessage(r.errorMessage) { // install a default logwriter that writes to standard // output / standard error @@ -74,15 +73,22 @@ Application::Messages& Application::Messages::operator=(const Messages& r) return *this; } errorMessage = r.errorMessage; - errorRoutine = r.errorRoutine; logwriter.reset(new Logger(*r.logwriter)); return *this; } void Application::Messages::addError(const std::string& r, const std::string& msg) { - errorMessage.push_back(msg); - errorRoutine.push_back(r); + if (msg.size() != 0) { + errorMessage.push_back( + "\n\n************************************************\n" + " Cantera Error! \n" + "************************************************\n\n" + "Procedure: " + r + + "\nError: " + msg + "\n"); + } else { + errorMessage.push_back(msg); + } } int Application::Messages::getErrorCount() @@ -289,7 +295,6 @@ long int Application::readStringRegistryKey(const std::string& keyName, const st void Application::Messages::popError() { if (!errorMessage.empty()) { - errorRoutine.pop_back(); errorMessage.pop_back(); } } @@ -297,12 +302,7 @@ void Application::Messages::popError() std::string Application::Messages::lastErrorMessage() { if (!errorMessage.empty()) { - string head = - "\n\n************************************************\n" - " Cantera Error! \n" - "************************************************\n\n"; - return head+string("\nProcedure: ")+errorRoutine.back() - +string("\nError: ")+errorMessage.back(); + return errorMessage.back(); } else { return ""; } @@ -310,43 +310,19 @@ std::string Application::Messages::lastErrorMessage() void Application::Messages::getErrors(std::ostream& f) { - size_t i = errorMessage.size(); - if (i == 0) { - return; + for (size_t j = 0; j < errorMessage.size(); j++) { + f << errorMessage[j] << endl; } - f << endl << endl; - f << "************************************************" << endl; - f << " Cantera Error! " << endl; - f << "************************************************" << endl - << endl; - for (size_t j = 0; j < i; j++) { - f << endl; - f << "Procedure: " << errorRoutine[j] << endl; - f << "Error: " << errorMessage[j] << endl; - } - f << endl << endl; errorMessage.clear(); - errorRoutine.clear(); } void Application::Messages::logErrors() { - size_t i = errorMessage.size(); - if (i == 0) { - return; + for (size_t j = 0; j < errorMessage.size(); j++) { + writelog(errorMessage[j]); + writelogendl(); } - writelog("\n\n"); - writelog("************************************************\n"); - writelog(" Cantera Error! \n"); - writelog("************************************************\n\n"); - for (size_t j = 0; j < i; j++) { - writelog("\n"); - writelog(string("Procedure: ")+ errorRoutine[j]+" \n"); - writelog(string("Error: ")+ errorMessage[j]+" \n"); - } - writelog("\n\n"); errorMessage.clear(); - errorRoutine.clear(); } void Application::setDefaultDirectories() diff --git a/src/base/application.h b/src/base/application.h index 1033d0454..aab56d088 100644 --- a/src/base/application.h +++ b/src/base/application.h @@ -54,9 +54,12 @@ protected: * that Cantera accumulates in the Application class. * @param r Procedure name which is generating the error condition * @param msg Descriptive message of the error condition. + * + * If only one argument is specified, that string is used as the + * entire message. * @ingroup errorhandling */ - void addError(const std::string& r, const std::string& msg); + void addError(const std::string& r, const std::string& msg=""); //! Return the number of errors that have been encountered so far. /*! @@ -141,9 +144,6 @@ protected: //! Current list of error messages std::vector errorMessage; - //! Current error Routine - std::vector errorRoutine; - //! Current pointer to the logwriter std::unique_ptr logwriter; }; @@ -198,7 +198,7 @@ public: static void ApplicationDestroy(); //! @copydoc Messages::addError - void addError(const std::string& r, const std::string& msg) { + void addError(const std::string& r, const std::string& msg="") { pMessenger->addError(r, msg); } diff --git a/src/base/ctexceptions.cpp b/src/base/ctexceptions.cpp index 388c1836b..c86060f47 100644 --- a/src/base/ctexceptions.cpp +++ b/src/base/ctexceptions.cpp @@ -1,6 +1,7 @@ //! @file ctexceptions.cpp #include "cantera/base/ctexceptions.h" #include "application.h" +#include "cantera/base/global.h" #include @@ -15,12 +16,11 @@ CanteraError::CanteraError(const std::string& procedure) : procedure_(procedure), saved_(false) { - // Save the error in the global list of errors so that showError() can work - save(); } void CanteraError::save() { + warn_deprecated("CanteraError::save", "To be removed after Cantera 2.3."); if (!saved_) { Application::Instance()->addError(procedure_, getMessage()); saved_ = true; diff --git a/src/base/global.cpp b/src/base/global.cpp index b5e39feb7..51243395b 100644 --- a/src/base/global.cpp +++ b/src/base/global.cpp @@ -93,21 +93,25 @@ void close_XML_File(const std::string& file) int nErrors() { + warn_deprecated("nErrors", "To be removed after Cantera 2.3"); return app()->getErrorCount(); } void popError() { + warn_deprecated("popError", "To be removed after Cantera 2.3"); app()->popError(); } string lastErrorMessage() { + warn_deprecated("lastErrorMessage", "To be removed after Cantera 2.3"); return app()->lastErrorMessage(); } void showErrors(std::ostream& f) { + warn_deprecated("showErrors", "To be removed after Cantera 2.3"); app()->getErrors(f); } diff --git a/src/clib/clib_defs.h b/src/clib/clib_defs.h index b8552f008..37f4c3174 100644 --- a/src/clib/clib_defs.h +++ b/src/clib/clib_defs.h @@ -6,6 +6,7 @@ #include "cantera/base/global.h" #include "cantera/base/ctexceptions.h" +#include "../base/application.h" #include #ifdef _WIN32 @@ -53,17 +54,17 @@ T handleAllExceptions(T ctErrorCode, T otherErrorCode) try { throw; } catch (CanteraError& cterr) { - cterr.save(); + Application::Instance()->addError(cterr.what()); return ctErrorCode; } catch (std::exception& err) { std::cerr << "Cantera: caught an instance of " << err.what() << std::endl; - setError("handleAllExceptions", err.what()); + Application::Instance()->addError(err.what()); return otherErrorCode; } catch (...) { std::cerr << "Cantera: caught an instance of " "an unknown exception type" << std::endl; - setError("handleAllExceptions", "unknown exception"); + Application::Instance()->addError("unknown C++ exception"); return otherErrorCode; } } diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index 2c8a004c1..a3bbc2e0a 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -1374,7 +1374,7 @@ extern "C" { int getCanteraError(int buflen, char* buf) { try { - string e = lastErrorMessage(); + string e = Application::Instance()->lastErrorMessage(); copyString(e, buf, buflen); return int(e.size()); } catch (...) { diff --git a/src/equil/ChemEquil.cpp b/src/equil/ChemEquil.cpp index dc501ab43..b5dacbdcc 100644 --- a/src/equil/ChemEquil.cpp +++ b/src/equil/ChemEquil.cpp @@ -188,45 +188,37 @@ void ChemEquil::update(const thermo_t& s) int ChemEquil::setInitialMoles(thermo_t& s, vector_fp& elMoleGoal, int loglevel) { - int iok = 0; - try { - MultiPhase mp; - mp.addPhase(&s, 1.0); - mp.init(); - MultiPhaseEquil e(&mp, true, loglevel-1); - e.setInitialMixMoles(loglevel-1); + MultiPhase mp; + mp.addPhase(&s, 1.0); + mp.init(); + MultiPhaseEquil e(&mp, true, loglevel-1); + e.setInitialMixMoles(loglevel-1); - // store component indices - m_nComponents = std::min(m_nComponents, m_kk); - for (size_t m = 0; m < m_nComponents; m++) { - m_component[m] = e.componentIndex(m); - } - - // Update the current values of the temp, density, and mole fraction, - // and element abundance vectors kept within the ChemEquil object. - update(s); - - if (DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0) { - writelog("setInitialMoles: Estimated Mole Fractions\n"); - writelogf(" Temperature = %g\n", s.temperature()); - writelogf(" Pressure = %g\n", s.pressure()); - for (size_t k = 0; k < m_kk; k++) { - writelogf(" %-12s % -10.5g\n", - s.speciesName(k), s.moleFraction(k)); - } - writelog(" Element_Name ElementGoal ElementMF\n"); - for (size_t m = 0; m < m_mm; m++) { - writelogf(" %-12s % -10.5g% -10.5g\n", - s.elementName(m), elMoleGoal[m], m_elementmolefracs[m]); - } - } - - iok = 0; - } catch (CanteraError& err) { - err.save(); - iok = -1; + // store component indices + m_nComponents = std::min(m_nComponents, m_kk); + for (size_t m = 0; m < m_nComponents; m++) { + m_component[m] = e.componentIndex(m); } - return iok; + + // Update the current values of the temp, density, and mole fraction, + // and element abundance vectors kept within the ChemEquil object. + update(s); + + if (DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0) { + writelog("setInitialMoles: Estimated Mole Fractions\n"); + writelogf(" Temperature = %g\n", s.temperature()); + writelogf(" Pressure = %g\n", s.pressure()); + for (size_t k = 0; k < m_kk; k++) { + writelogf(" %-12s % -10.5g\n", + s.speciesName(k), s.moleFraction(k)); + } + writelog(" Element_Name ElementGoal ElementMF\n"); + for (size_t m = 0; m < m_mm; m++) { + writelogf(" %-12s % -10.5g% -10.5g\n", + s.elementName(m), elMoleGoal[m], m_elementmolefracs[m]); + } + } + return 0; } int ChemEquil::estimateElementPotentials(thermo_t& s, vector_fp& lambda_RT, @@ -676,13 +668,11 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr, try { info = solve(jac, res_trial.data()); } catch (CanteraError& err) { - err.save(); s.restoreState(state); - throw CanteraError("equilibrate", "Jacobian is singular. \nTry adding more species, " "changing the elemental composition slightly, \nor removing " - "unused elements."); + "unused elements.\n\n" + err.getMessage()); } // find the factor by which the Newton step can be multiplied @@ -1320,15 +1310,11 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x, try { solve(a1, resid.data()); } catch (CanteraError& err) { - err.save(); - if (DEBUG_MODE_ENABLED) { - debuglog("Matrix is SINGULAR.ERROR\n", ChemEquil_print_lvl); - } s.restoreState(state); throw CanteraError("equilibrate:estimateEP_Brinkley()", "Jacobian is singular. \nTry adding more species, " "changing the elemental composition slightly, \nor removing " - "unused elements."); + "unused elements.\n\n" + err.getMessage()); } // Figure out the damping coefficient: Use a delta damping diff --git a/src/equil/MultiPhase.cpp b/src/equil/MultiPhase.cpp index f543e6338..e7256522e 100644 --- a/src/equil/MultiPhase.cpp +++ b/src/equil/MultiPhase.cpp @@ -569,13 +569,7 @@ double MultiPhase::equilibrate_MultiPhaseEquil(int XY, doublereal err, if (XY == TP) { // create an equilibrium manager MultiPhaseEquil e(this); - try { - e.equilibrate(XY, err, maxsteps, loglevel); - } catch (CanteraError& err) { - err.save(); - throw err; - } - return err; + return e.equilibrate(XY, err, maxsteps, loglevel); } else if (XY == HP) { h0 = enthalpy(); Tlow = 0.5*m_Tmin; // lower bound on T @@ -637,7 +631,6 @@ double MultiPhase::equilibrate_MultiPhaseEquil(int XY, doublereal err, } } catch (CanteraError& err) { - err.save(); if (!strt) { strt = true; } else { @@ -685,7 +678,6 @@ double MultiPhase::equilibrate_MultiPhaseEquil(int XY, doublereal err, strt = false; } } catch (CanteraError& err) { - err.save(); if (!strt) { strt = true; } else { diff --git a/src/fortran/fct.cpp b/src/fortran/fct.cpp index 9f0bd1eac..e6ef00857 100644 --- a/src/fortran/fct.cpp +++ b/src/fortran/fct.cpp @@ -1026,7 +1026,7 @@ extern "C" { { try { std::string e; - e = lastErrorMessage(); + e = Application::Instance()->lastErrorMessage(); int n = std::min((int) e.size(), buflen-1); copy(e.begin(), e.begin() + n, buf); for (int nn = n; nn < buflen; nn++) { diff --git a/src/thermo/MolalityVPSSTP.cpp b/src/thermo/MolalityVPSSTP.cpp index 488236c95..95ab24b67 100644 --- a/src/thermo/MolalityVPSSTP.cpp +++ b/src/thermo/MolalityVPSSTP.cpp @@ -478,8 +478,7 @@ std::string MolalityVPSSTP::report(bool show_thermo, doublereal threshold) const try { b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n", cv_mass(), cv_mole()); - } catch (CanteraError& e) { - e.save(); + } catch (NotImplementedError& e) { b.write(" heat capacity c_v \n"); } } @@ -527,7 +526,7 @@ std::string MolalityVPSSTP::report(bool show_thermo, doublereal threshold) const b.write(" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor); } } catch (CanteraError& err) { - err.save(); + return b.str() + err.what(); } return b.str(); } diff --git a/src/thermo/MolarityIonicVPSSTP.cpp b/src/thermo/MolarityIonicVPSSTP.cpp index a2853bf11..fcea65e04 100644 --- a/src/thermo/MolarityIonicVPSSTP.cpp +++ b/src/thermo/MolarityIonicVPSSTP.cpp @@ -401,13 +401,12 @@ std::string MolarityIonicVPSSTP::report(bool show_thermo, doublereal threshold) try { b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n", cv_mass(), cv_mole()); - } catch (CanteraError& e) { - e.save(); + } catch (NotImplementedError& e) { b.write(" heat capacity c_v \n"); } } } catch (CanteraError& e) { - e.save(); + return b.str() + e.what(); } return b.str(); } diff --git a/src/thermo/PureFluidPhase.cpp b/src/thermo/PureFluidPhase.cpp index f3baed2e3..d22d76be7 100644 --- a/src/thermo/PureFluidPhase.cpp +++ b/src/thermo/PureFluidPhase.cpp @@ -374,8 +374,7 @@ std::string PureFluidPhase::report(bool show_thermo, doublereal threshold) const try { b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n", cv_mass(), cv_mole()); - } catch (CanteraError& e) { - e.save(); + } catch (NotImplementedError& e) { b.write(" heat capacity c_v \n"); } } diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index 56dde824f..b53507f88 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -914,8 +914,7 @@ std::string ThermoPhase::report(bool show_thermo, doublereal threshold) const try { b.write(" heat capacity c_v {:12.5g} {:12.4g} J/K\n", cv_mass(), cv_mole()); - } catch (CanteraError& err) { - err.save(); + } catch (NotImplementedError& err) { b.write(" heat capacity c_v \n"); } } @@ -969,7 +968,7 @@ std::string ThermoPhase::report(bool show_thermo, doublereal threshold) const nMinor, xMinor, yMinor); } } catch (CanteraError& err) { - err.save(); + return b.str() + err.what(); } return b.str(); } diff --git a/src/thermo/VPSSMgrFactory.cpp b/src/thermo/VPSSMgrFactory.cpp index 4ad1a7382..536a388c3 100644 --- a/src/thermo/VPSSMgrFactory.cpp +++ b/src/thermo/VPSSMgrFactory.cpp @@ -257,7 +257,6 @@ VPSSMgr* VPSSMgrFactory::newVPSSMgr(VPStandardStateTP* vp_ptr, isimpleIG, isimpleCV, iwater, itpx, ihptx, iother); } catch (UnknownVPSSMgrModel) { iother = 1; - popError(); } if (iwater == 1) { diff --git a/src/transport/MultiTransport.cpp b/src/transport/MultiTransport.cpp index 04edceeb5..87465dfcf 100644 --- a/src/transport/MultiTransport.cpp +++ b/src/transport/MultiTransport.cpp @@ -157,13 +157,7 @@ void MultiTransport::solveLMatrixEquation() // Solve it using GMRES or LU decomposition. The last solution in m_a should // provide a good starting guess, so convergence should be fast. m_a = m_b; - try { - solve(m_Lmatrix, m_a.data()); - } catch (CanteraError& err) { - err.save(); - throw CanteraError("MultiTransport::solveLMatrixEquation", - "error in solving L matrix."); - } + solve(m_Lmatrix, m_a.data()); m_lmatrix_soln_ok = true; m_molefracs_last = m_molefracs; // L matrix is overwritten with LU decomposition diff --git a/src/transport/TransportFactory.cpp b/src/transport/TransportFactory.cpp index 51238dc42..df4bf7900 100644 --- a/src/transport/TransportFactory.cpp +++ b/src/transport/TransportFactory.cpp @@ -368,83 +368,78 @@ void TransportFactory::getLiquidSpeciesTransportData(const std::vectorspeciesIndex(firstSpec)+nsp*temp_thermo->speciesIndex(secondSpec); - data.mobilityRatio[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], temp_thermo); - }; - }; + switch (m_tranPropMap[nodeName]) { + case TP_VISCOSITY: + data.viscosity = newLTP(xmlChild, name, m_tranPropMap[nodeName], temp_thermo); break; - case TP_SELFDIFFUSION: { - for (size_t iSpec = 0; iSpec< nsp; iSpec++) { - XML_Node& propSpecNode = xmlChild.child(iSpec); - std::string specName = propSpecNode.name(); - size_t index = temp_thermo->speciesIndex(specName); - data.selfDiffusion[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], temp_thermo); - }; - }; + case TP_IONCONDUCTIVITY: + data.ionConductivity = newLTP(xmlChild, name, m_tranPropMap[nodeName], temp_thermo); break; - case TP_THERMALCOND: - data.thermalCond = newLTP(xmlChild, - name, - m_tranPropMap[nodeName], - temp_thermo); - break; - case TP_DIFFUSIVITY: - data.speciesDiffusivity = newLTP(xmlChild, - name, - m_tranPropMap[nodeName], - temp_thermo); - break; - case TP_HYDRORADIUS: - data.hydroRadius = newLTP(xmlChild, - name, - m_tranPropMap[nodeName], - temp_thermo); - break; - case TP_ELECTCOND: - data.electCond = newLTP(xmlChild, - name, - m_tranPropMap[nodeName], - temp_thermo); - break; - default: - throw CanteraError("getLiquidSpeciesTransportData","unknown transport property: " + nodeName); - } + case TP_MOBILITYRATIO: { + for (size_t iSpec = 0; iSpec< nBinInt; iSpec++) { + XML_Node& propSpecNode = xmlChild.child(iSpec); + std::string specName = propSpecNode.name(); + size_t loc = specName.find(":"); + std::string firstSpec = specName.substr(0,loc); + std::string secondSpec = specName.substr(loc+1); + size_t index = temp_thermo->speciesIndex(firstSpec)+nsp*temp_thermo->speciesIndex(secondSpec); + data.mobilityRatio[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], temp_thermo); + }; + }; + break; + case TP_SELFDIFFUSION: { + for (size_t iSpec = 0; iSpec< nsp; iSpec++) { + XML_Node& propSpecNode = xmlChild.child(iSpec); + std::string specName = propSpecNode.name(); + size_t index = temp_thermo->speciesIndex(specName); + data.selfDiffusion[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], temp_thermo); + }; + }; + break; + case TP_THERMALCOND: + data.thermalCond = newLTP(xmlChild, + name, + m_tranPropMap[nodeName], + temp_thermo); + break; + case TP_DIFFUSIVITY: + data.speciesDiffusivity = newLTP(xmlChild, + name, + m_tranPropMap[nodeName], + temp_thermo); + break; + case TP_HYDRORADIUS: + data.hydroRadius = newLTP(xmlChild, + name, + m_tranPropMap[nodeName], + temp_thermo); + break; + case TP_ELECTCOND: + data.electCond = newLTP(xmlChild, + name, + m_tranPropMap[nodeName], + temp_thermo); + break; + default: + throw CanteraError("getLiquidSpeciesTransportData","unknown transport property: " + nodeName); } - datatable[name] = data; } - } catch (CanteraError& err) { - err.save(); - throw err; + datatable[name] = data; } } @@ -596,49 +591,44 @@ void TransportFactory::getSolidTransportData(const XML_Node& transportNode, const std::string phaseName, SolidTransportData& trParam) { - try { - size_t num = transportNode.nChildren(); - for (size_t iChild = 0; iChild < num; iChild++) { - //tranTypeNode is a type of transport property like viscosity - XML_Node& tranTypeNode = transportNode.child(iChild); - std::string nodeName = tranTypeNode.name(); - ThermoPhase* temp_thermo = trParam.thermo; + size_t num = transportNode.nChildren(); + for (size_t iChild = 0; iChild < num; iChild++) { + //tranTypeNode is a type of transport property like viscosity + XML_Node& tranTypeNode = transportNode.child(iChild); + std::string nodeName = tranTypeNode.name(); + ThermoPhase* temp_thermo = trParam.thermo; - //tranTypeNode contains the interaction model - switch (m_tranPropMap[nodeName]) { - case TP_IONCONDUCTIVITY: - trParam.ionConductivity = newLTP(tranTypeNode, phaseName, + //tranTypeNode contains the interaction model + switch (m_tranPropMap[nodeName]) { + case TP_IONCONDUCTIVITY: + trParam.ionConductivity = newLTP(tranTypeNode, phaseName, + m_tranPropMap[nodeName], + temp_thermo); + break; + case TP_THERMALCOND: + trParam.thermalConductivity = newLTP(tranTypeNode, phaseName, m_tranPropMap[nodeName], temp_thermo); - break; - case TP_THERMALCOND: - trParam.thermalConductivity = newLTP(tranTypeNode, phaseName, - m_tranPropMap[nodeName], - temp_thermo); - break; - case TP_DEFECTDIFF: - trParam.defectDiffusivity = newLTP(tranTypeNode, phaseName, - m_tranPropMap[nodeName], - temp_thermo); - break; - case TP_DEFECTCONC: - trParam.defectActivity = newLTP(tranTypeNode, phaseName, - m_tranPropMap[nodeName], - temp_thermo); - break; - case TP_ELECTCOND: - trParam.electConductivity = newLTP(tranTypeNode, phaseName, - m_tranPropMap[nodeName], - temp_thermo); - break; - default: - throw CanteraError("getSolidTransportData","unknown transport property: " + nodeName); - } + break; + case TP_DEFECTDIFF: + trParam.defectDiffusivity = newLTP(tranTypeNode, phaseName, + m_tranPropMap[nodeName], + temp_thermo); + break; + case TP_DEFECTCONC: + trParam.defectActivity = newLTP(tranTypeNode, phaseName, + m_tranPropMap[nodeName], + temp_thermo); + break; + case TP_ELECTCOND: + trParam.electConductivity = newLTP(tranTypeNode, phaseName, + m_tranPropMap[nodeName], + temp_thermo); + break; + default: + throw CanteraError("getSolidTransportData","unknown transport property: " + nodeName); } - } catch (CanteraError) { - showErrors(std::cout); } - return; } diff --git a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp index acd3ba2f3..7236e4a9b 100644 --- a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp +++ b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp @@ -286,9 +286,7 @@ int main() try { w->setState_HP(Hset, OneAtm); } catch (CanteraError& err) { - err.save(); printf(" %10g, -> Failed to converge, beyond the spinodal probably \n\n", Hset); - popError(); break; } vapFrac = w->vaporFraction(); diff --git a/test_problems/simpleTransport/simpleTransportTest.cpp b/test_problems/simpleTransport/simpleTransportTest.cpp index 0c31ba0dd..8b5ef34bf 100644 --- a/test_problems/simpleTransport/simpleTransportTest.cpp +++ b/test_problems/simpleTransport/simpleTransportTest.cpp @@ -69,8 +69,8 @@ int main(int argc, char** argv) Cantera::appdelete(); return 0; - } catch (CanteraError) { - showErrors(); + } catch (CanteraError& err) { + std::cout << err.what() << std::endl; return -1; } }