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.
This commit is contained in:
parent
eb8695dffa
commit
ee95c60813
21 changed files with 183 additions and 251 deletions
|
|
@ -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
|
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
|
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
|
``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
|
throws exceptions of this type, so it is always a good idea to catch them.
|
||||||
the ``catch`` block, function :ct:`showErrors` may be called to print the error
|
|
||||||
message associated with the exception.
|
|
||||||
|
|
||||||
The ``report`` function
|
The ``report`` function
|
||||||
=======================
|
=======================
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,6 @@ namespace Cantera
|
||||||
*
|
*
|
||||||
* \include demo1a.cpp
|
* \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
|
* A group of defines may be used during debugging to assert conditions which
|
||||||
* should be true. These are named AssertTrace(), AssertThrow(), and
|
* should be true. These are named AssertTrace(), AssertThrow(), and
|
||||||
* AssertThrowMsg(). Examples of their usage is given below.
|
* AssertThrowMsg(). Examples of their usage is given below.
|
||||||
|
|
@ -69,9 +66,6 @@ class CanteraError : public std::exception
|
||||||
public:
|
public:
|
||||||
//! Normal Constructor for the CanteraError base class
|
//! 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
|
* @param procedure String name for the function within which the error was
|
||||||
* generated.
|
* generated.
|
||||||
* @param msg Descriptive string describing the type of error message.
|
* @param msg Descriptive string describing the type of error message.
|
||||||
|
|
@ -87,9 +81,6 @@ public:
|
||||||
} else {
|
} else {
|
||||||
msg_ = fmt::format(msg, args...);
|
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
|
//! Destructor for base class does nothing
|
||||||
|
|
@ -99,6 +90,7 @@ public:
|
||||||
const char* what() const throw();
|
const char* what() const throw();
|
||||||
|
|
||||||
//! Function to put this error onto Cantera's error stack
|
//! Function to put this error onto Cantera's error stack
|
||||||
|
//! @deprecated Unused. To be removed after Cantera 2.3.
|
||||||
void save();
|
void save();
|
||||||
|
|
||||||
//! Method overridden by derived classes to format the error message
|
//! Method overridden by derived classes to format the error message
|
||||||
|
|
|
||||||
|
|
@ -29,22 +29,28 @@ class Logger;
|
||||||
//! Return the number of errors that have been encountered so far
|
//! Return the number of errors that have been encountered so far
|
||||||
/*!
|
/*!
|
||||||
* @ingroup errorhandling
|
* @ingroup errorhandling
|
||||||
|
* @deprecated Unused. To be removed after Cantera 2.3.
|
||||||
*/
|
*/
|
||||||
int nErrors();
|
int nErrors();
|
||||||
|
|
||||||
//! @copydoc Application::Messages::lastErrorMessage
|
//! @copydoc Application::Messages::lastErrorMessage
|
||||||
|
//! @deprecated Unused. To be removed after Cantera 2.3.
|
||||||
std::string lastErrorMessage();
|
std::string lastErrorMessage();
|
||||||
|
|
||||||
//! @copydoc Application::Messages::addError
|
//! @copydoc Application::Messages::addError
|
||||||
|
//! @deprecated Unused. To be removed after Cantera 2.3.
|
||||||
void setError(const std::string& r, const std::string& msg);
|
void setError(const std::string& r, const std::string& msg);
|
||||||
|
|
||||||
//! @copydoc Application::Messages::getErrors
|
//! @copydoc Application::Messages::getErrors
|
||||||
|
//! @deprecated Unused. To be removed after Cantera 2.3.
|
||||||
void showErrors(std::ostream& f);
|
void showErrors(std::ostream& f);
|
||||||
|
|
||||||
//! @copydoc Application::Messages::logErrors
|
//! @copydoc Application::Messages::logErrors
|
||||||
|
//! @deprecated Unused. To be removed after Cantera 2.3.
|
||||||
void showErrors();
|
void showErrors();
|
||||||
|
|
||||||
//! @copydoc Application::Messages::popError
|
//! @copydoc Application::Messages::popError
|
||||||
|
//! @deprecated Unused. To be removed after Cantera 2.3.
|
||||||
void popError();
|
void popError();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,7 @@ Application::Messages::Messages()
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::Messages::Messages(const Messages& r) :
|
Application::Messages::Messages(const Messages& r) :
|
||||||
errorMessage(r.errorMessage),
|
errorMessage(r.errorMessage)
|
||||||
errorRoutine(r.errorRoutine)
|
|
||||||
{
|
{
|
||||||
// install a default logwriter that writes to standard
|
// install a default logwriter that writes to standard
|
||||||
// output / standard error
|
// output / standard error
|
||||||
|
|
@ -74,15 +73,22 @@ Application::Messages& Application::Messages::operator=(const Messages& r)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
errorMessage = r.errorMessage;
|
errorMessage = r.errorMessage;
|
||||||
errorRoutine = r.errorRoutine;
|
|
||||||
logwriter.reset(new Logger(*r.logwriter));
|
logwriter.reset(new Logger(*r.logwriter));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Messages::addError(const std::string& r, const std::string& msg)
|
void Application::Messages::addError(const std::string& r, const std::string& msg)
|
||||||
{
|
{
|
||||||
errorMessage.push_back(msg);
|
if (msg.size() != 0) {
|
||||||
errorRoutine.push_back(r);
|
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()
|
int Application::Messages::getErrorCount()
|
||||||
|
|
@ -289,7 +295,6 @@ long int Application::readStringRegistryKey(const std::string& keyName, const st
|
||||||
void Application::Messages::popError()
|
void Application::Messages::popError()
|
||||||
{
|
{
|
||||||
if (!errorMessage.empty()) {
|
if (!errorMessage.empty()) {
|
||||||
errorRoutine.pop_back();
|
|
||||||
errorMessage.pop_back();
|
errorMessage.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -297,12 +302,7 @@ void Application::Messages::popError()
|
||||||
std::string Application::Messages::lastErrorMessage()
|
std::string Application::Messages::lastErrorMessage()
|
||||||
{
|
{
|
||||||
if (!errorMessage.empty()) {
|
if (!errorMessage.empty()) {
|
||||||
string head =
|
return errorMessage.back();
|
||||||
"\n\n************************************************\n"
|
|
||||||
" Cantera Error! \n"
|
|
||||||
"************************************************\n\n";
|
|
||||||
return head+string("\nProcedure: ")+errorRoutine.back()
|
|
||||||
+string("\nError: ")+errorMessage.back();
|
|
||||||
} else {
|
} else {
|
||||||
return "<no Cantera error>";
|
return "<no Cantera error>";
|
||||||
}
|
}
|
||||||
|
|
@ -310,43 +310,19 @@ std::string Application::Messages::lastErrorMessage()
|
||||||
|
|
||||||
void Application::Messages::getErrors(std::ostream& f)
|
void Application::Messages::getErrors(std::ostream& f)
|
||||||
{
|
{
|
||||||
size_t i = errorMessage.size();
|
for (size_t j = 0; j < errorMessage.size(); j++) {
|
||||||
if (i == 0) {
|
f << errorMessage[j] << endl;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
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();
|
errorMessage.clear();
|
||||||
errorRoutine.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Messages::logErrors()
|
void Application::Messages::logErrors()
|
||||||
{
|
{
|
||||||
size_t i = errorMessage.size();
|
for (size_t j = 0; j < errorMessage.size(); j++) {
|
||||||
if (i == 0) {
|
writelog(errorMessage[j]);
|
||||||
return;
|
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();
|
errorMessage.clear();
|
||||||
errorRoutine.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setDefaultDirectories()
|
void Application::setDefaultDirectories()
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,12 @@ protected:
|
||||||
* that Cantera accumulates in the Application class.
|
* that Cantera accumulates in the Application class.
|
||||||
* @param r Procedure name which is generating the error condition
|
* @param r Procedure name which is generating the error condition
|
||||||
* @param msg Descriptive message of 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
|
* @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.
|
//! Return the number of errors that have been encountered so far.
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -141,9 +144,6 @@ protected:
|
||||||
//! Current list of error messages
|
//! Current list of error messages
|
||||||
std::vector<std::string> errorMessage;
|
std::vector<std::string> errorMessage;
|
||||||
|
|
||||||
//! Current error Routine
|
|
||||||
std::vector<std::string> errorRoutine;
|
|
||||||
|
|
||||||
//! Current pointer to the logwriter
|
//! Current pointer to the logwriter
|
||||||
std::unique_ptr<Logger> logwriter;
|
std::unique_ptr<Logger> logwriter;
|
||||||
};
|
};
|
||||||
|
|
@ -198,7 +198,7 @@ public:
|
||||||
static void ApplicationDestroy();
|
static void ApplicationDestroy();
|
||||||
|
|
||||||
//! @copydoc Messages::addError
|
//! @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);
|
pMessenger->addError(r, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
//! @file ctexceptions.cpp
|
//! @file ctexceptions.cpp
|
||||||
#include "cantera/base/ctexceptions.h"
|
#include "cantera/base/ctexceptions.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
#include "cantera/base/global.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
@ -15,12 +16,11 @@ CanteraError::CanteraError(const std::string& procedure) :
|
||||||
procedure_(procedure),
|
procedure_(procedure),
|
||||||
saved_(false)
|
saved_(false)
|
||||||
{
|
{
|
||||||
// Save the error in the global list of errors so that showError() can work
|
|
||||||
save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CanteraError::save()
|
void CanteraError::save()
|
||||||
{
|
{
|
||||||
|
warn_deprecated("CanteraError::save", "To be removed after Cantera 2.3.");
|
||||||
if (!saved_) {
|
if (!saved_) {
|
||||||
Application::Instance()->addError(procedure_, getMessage());
|
Application::Instance()->addError(procedure_, getMessage());
|
||||||
saved_ = true;
|
saved_ = true;
|
||||||
|
|
|
||||||
|
|
@ -93,21 +93,25 @@ void close_XML_File(const std::string& file)
|
||||||
|
|
||||||
int nErrors()
|
int nErrors()
|
||||||
{
|
{
|
||||||
|
warn_deprecated("nErrors", "To be removed after Cantera 2.3");
|
||||||
return app()->getErrorCount();
|
return app()->getErrorCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void popError()
|
void popError()
|
||||||
{
|
{
|
||||||
|
warn_deprecated("popError", "To be removed after Cantera 2.3");
|
||||||
app()->popError();
|
app()->popError();
|
||||||
}
|
}
|
||||||
|
|
||||||
string lastErrorMessage()
|
string lastErrorMessage()
|
||||||
{
|
{
|
||||||
|
warn_deprecated("lastErrorMessage", "To be removed after Cantera 2.3");
|
||||||
return app()->lastErrorMessage();
|
return app()->lastErrorMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void showErrors(std::ostream& f)
|
void showErrors(std::ostream& f)
|
||||||
{
|
{
|
||||||
|
warn_deprecated("showErrors", "To be removed after Cantera 2.3");
|
||||||
app()->getErrors(f);
|
app()->getErrors(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "cantera/base/global.h"
|
#include "cantera/base/global.h"
|
||||||
#include "cantera/base/ctexceptions.h"
|
#include "cantera/base/ctexceptions.h"
|
||||||
|
#include "../base/application.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
@ -53,17 +54,17 @@ T handleAllExceptions(T ctErrorCode, T otherErrorCode)
|
||||||
try {
|
try {
|
||||||
throw;
|
throw;
|
||||||
} catch (CanteraError& cterr) {
|
} catch (CanteraError& cterr) {
|
||||||
cterr.save();
|
Application::Instance()->addError(cterr.what());
|
||||||
return ctErrorCode;
|
return ctErrorCode;
|
||||||
} catch (std::exception& err) {
|
} catch (std::exception& err) {
|
||||||
std::cerr << "Cantera: caught an instance of "
|
std::cerr << "Cantera: caught an instance of "
|
||||||
<< err.what() << std::endl;
|
<< err.what() << std::endl;
|
||||||
setError("handleAllExceptions", err.what());
|
Application::Instance()->addError(err.what());
|
||||||
return otherErrorCode;
|
return otherErrorCode;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::cerr << "Cantera: caught an instance of "
|
std::cerr << "Cantera: caught an instance of "
|
||||||
"an unknown exception type" << std::endl;
|
"an unknown exception type" << std::endl;
|
||||||
setError("handleAllExceptions", "unknown exception");
|
Application::Instance()->addError("unknown C++ exception");
|
||||||
return otherErrorCode;
|
return otherErrorCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1374,7 +1374,7 @@ extern "C" {
|
||||||
int getCanteraError(int buflen, char* buf)
|
int getCanteraError(int buflen, char* buf)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
string e = lastErrorMessage();
|
string e = Application::Instance()->lastErrorMessage();
|
||||||
copyString(e, buf, buflen);
|
copyString(e, buf, buflen);
|
||||||
return int(e.size());
|
return int(e.size());
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
|
|
||||||
|
|
@ -188,45 +188,37 @@ void ChemEquil::update(const thermo_t& s)
|
||||||
int ChemEquil::setInitialMoles(thermo_t& s, vector_fp& elMoleGoal,
|
int ChemEquil::setInitialMoles(thermo_t& s, vector_fp& elMoleGoal,
|
||||||
int loglevel)
|
int loglevel)
|
||||||
{
|
{
|
||||||
int iok = 0;
|
MultiPhase mp;
|
||||||
try {
|
mp.addPhase(&s, 1.0);
|
||||||
MultiPhase mp;
|
mp.init();
|
||||||
mp.addPhase(&s, 1.0);
|
MultiPhaseEquil e(&mp, true, loglevel-1);
|
||||||
mp.init();
|
e.setInitialMixMoles(loglevel-1);
|
||||||
MultiPhaseEquil e(&mp, true, loglevel-1);
|
|
||||||
e.setInitialMixMoles(loglevel-1);
|
|
||||||
|
|
||||||
// store component indices
|
// store component indices
|
||||||
m_nComponents = std::min(m_nComponents, m_kk);
|
m_nComponents = std::min(m_nComponents, m_kk);
|
||||||
for (size_t m = 0; m < m_nComponents; m++) {
|
for (size_t m = 0; m < m_nComponents; m++) {
|
||||||
m_component[m] = e.componentIndex(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;
|
|
||||||
}
|
}
|
||||||
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,
|
int ChemEquil::estimateElementPotentials(thermo_t& s, vector_fp& lambda_RT,
|
||||||
|
|
@ -676,13 +668,11 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,
|
||||||
try {
|
try {
|
||||||
info = solve(jac, res_trial.data());
|
info = solve(jac, res_trial.data());
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
|
||||||
s.restoreState(state);
|
s.restoreState(state);
|
||||||
|
|
||||||
throw CanteraError("equilibrate",
|
throw CanteraError("equilibrate",
|
||||||
"Jacobian is singular. \nTry adding more species, "
|
"Jacobian is singular. \nTry adding more species, "
|
||||||
"changing the elemental composition slightly, \nor removing "
|
"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
|
// 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 {
|
try {
|
||||||
solve(a1, resid.data());
|
solve(a1, resid.data());
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
|
||||||
if (DEBUG_MODE_ENABLED) {
|
|
||||||
debuglog("Matrix is SINGULAR.ERROR\n", ChemEquil_print_lvl);
|
|
||||||
}
|
|
||||||
s.restoreState(state);
|
s.restoreState(state);
|
||||||
throw CanteraError("equilibrate:estimateEP_Brinkley()",
|
throw CanteraError("equilibrate:estimateEP_Brinkley()",
|
||||||
"Jacobian is singular. \nTry adding more species, "
|
"Jacobian is singular. \nTry adding more species, "
|
||||||
"changing the elemental composition slightly, \nor removing "
|
"changing the elemental composition slightly, \nor removing "
|
||||||
"unused elements.");
|
"unused elements.\n\n" + err.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out the damping coefficient: Use a delta damping
|
// Figure out the damping coefficient: Use a delta damping
|
||||||
|
|
|
||||||
|
|
@ -569,13 +569,7 @@ double MultiPhase::equilibrate_MultiPhaseEquil(int XY, doublereal err,
|
||||||
if (XY == TP) {
|
if (XY == TP) {
|
||||||
// create an equilibrium manager
|
// create an equilibrium manager
|
||||||
MultiPhaseEquil e(this);
|
MultiPhaseEquil e(this);
|
||||||
try {
|
return e.equilibrate(XY, err, maxsteps, loglevel);
|
||||||
e.equilibrate(XY, err, maxsteps, loglevel);
|
|
||||||
} catch (CanteraError& err) {
|
|
||||||
err.save();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
} else if (XY == HP) {
|
} else if (XY == HP) {
|
||||||
h0 = enthalpy();
|
h0 = enthalpy();
|
||||||
Tlow = 0.5*m_Tmin; // lower bound on T
|
Tlow = 0.5*m_Tmin; // lower bound on T
|
||||||
|
|
@ -637,7 +631,6 @@ double MultiPhase::equilibrate_MultiPhaseEquil(int XY, doublereal err,
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
|
||||||
if (!strt) {
|
if (!strt) {
|
||||||
strt = true;
|
strt = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -685,7 +678,6 @@ double MultiPhase::equilibrate_MultiPhaseEquil(int XY, doublereal err,
|
||||||
strt = false;
|
strt = false;
|
||||||
}
|
}
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
|
||||||
if (!strt) {
|
if (!strt) {
|
||||||
strt = true;
|
strt = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1026,7 +1026,7 @@ extern "C" {
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
std::string e;
|
std::string e;
|
||||||
e = lastErrorMessage();
|
e = Application::Instance()->lastErrorMessage();
|
||||||
int n = std::min((int) e.size(), buflen-1);
|
int n = std::min((int) e.size(), buflen-1);
|
||||||
copy(e.begin(), e.begin() + n, buf);
|
copy(e.begin(), e.begin() + n, buf);
|
||||||
for (int nn = n; nn < buflen; nn++) {
|
for (int nn = n; nn < buflen; nn++) {
|
||||||
|
|
|
||||||
|
|
@ -478,8 +478,7 @@ std::string MolalityVPSSTP::report(bool show_thermo, doublereal threshold) const
|
||||||
try {
|
try {
|
||||||
b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
|
b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
|
||||||
cv_mass(), cv_mole());
|
cv_mass(), cv_mole());
|
||||||
} catch (CanteraError& e) {
|
} catch (NotImplementedError& e) {
|
||||||
e.save();
|
|
||||||
b.write(" heat capacity c_v <not implemented>\n");
|
b.write(" heat capacity c_v <not implemented>\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -527,7 +526,7 @@ std::string MolalityVPSSTP::report(bool show_thermo, doublereal threshold) const
|
||||||
b.write(" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor);
|
b.write(" [{:+5d} minor] {:12.6g}\n", nMinor, xMinor);
|
||||||
}
|
}
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
return b.str() + err.what();
|
||||||
}
|
}
|
||||||
return b.str();
|
return b.str();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -401,13 +401,12 @@ std::string MolarityIonicVPSSTP::report(bool show_thermo, doublereal threshold)
|
||||||
try {
|
try {
|
||||||
b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
|
b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
|
||||||
cv_mass(), cv_mole());
|
cv_mass(), cv_mole());
|
||||||
} catch (CanteraError& e) {
|
} catch (NotImplementedError& e) {
|
||||||
e.save();
|
|
||||||
b.write(" heat capacity c_v <not implemented>\n");
|
b.write(" heat capacity c_v <not implemented>\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (CanteraError& e) {
|
} catch (CanteraError& e) {
|
||||||
e.save();
|
return b.str() + e.what();
|
||||||
}
|
}
|
||||||
return b.str();
|
return b.str();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -374,8 +374,7 @@ std::string PureFluidPhase::report(bool show_thermo, doublereal threshold) const
|
||||||
try {
|
try {
|
||||||
b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
|
b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n",
|
||||||
cv_mass(), cv_mole());
|
cv_mass(), cv_mole());
|
||||||
} catch (CanteraError& e) {
|
} catch (NotImplementedError& e) {
|
||||||
e.save();
|
|
||||||
b.write(" heat capacity c_v <not implemented>\n");
|
b.write(" heat capacity c_v <not implemented>\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -914,8 +914,7 @@ std::string ThermoPhase::report(bool show_thermo, doublereal threshold) const
|
||||||
try {
|
try {
|
||||||
b.write(" heat capacity c_v {:12.5g} {:12.4g} J/K\n",
|
b.write(" heat capacity c_v {:12.5g} {:12.4g} J/K\n",
|
||||||
cv_mass(), cv_mole());
|
cv_mass(), cv_mole());
|
||||||
} catch (CanteraError& err) {
|
} catch (NotImplementedError& err) {
|
||||||
err.save();
|
|
||||||
b.write(" heat capacity c_v <not implemented> \n");
|
b.write(" heat capacity c_v <not implemented> \n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -969,7 +968,7 @@ std::string ThermoPhase::report(bool show_thermo, doublereal threshold) const
|
||||||
nMinor, xMinor, yMinor);
|
nMinor, xMinor, yMinor);
|
||||||
}
|
}
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
return b.str() + err.what();
|
||||||
}
|
}
|
||||||
return b.str();
|
return b.str();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,6 @@ VPSSMgr* VPSSMgrFactory::newVPSSMgr(VPStandardStateTP* vp_ptr,
|
||||||
isimpleIG, isimpleCV, iwater, itpx, ihptx, iother);
|
isimpleIG, isimpleCV, iwater, itpx, ihptx, iother);
|
||||||
} catch (UnknownVPSSMgrModel) {
|
} catch (UnknownVPSSMgrModel) {
|
||||||
iother = 1;
|
iother = 1;
|
||||||
popError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iwater == 1) {
|
if (iwater == 1) {
|
||||||
|
|
|
||||||
|
|
@ -157,13 +157,7 @@ void MultiTransport::solveLMatrixEquation()
|
||||||
// Solve it using GMRES or LU decomposition. The last solution in m_a should
|
// Solve it using GMRES or LU decomposition. The last solution in m_a should
|
||||||
// provide a good starting guess, so convergence should be fast.
|
// provide a good starting guess, so convergence should be fast.
|
||||||
m_a = m_b;
|
m_a = m_b;
|
||||||
try {
|
solve(m_Lmatrix, m_a.data());
|
||||||
solve(m_Lmatrix, m_a.data());
|
|
||||||
} catch (CanteraError& err) {
|
|
||||||
err.save();
|
|
||||||
throw CanteraError("MultiTransport::solveLMatrixEquation",
|
|
||||||
"error in solving L matrix.");
|
|
||||||
}
|
|
||||||
m_lmatrix_soln_ok = true;
|
m_lmatrix_soln_ok = true;
|
||||||
m_molefracs_last = m_molefracs;
|
m_molefracs_last = m_molefracs;
|
||||||
// L matrix is overwritten with LU decomposition
|
// L matrix is overwritten with LU decomposition
|
||||||
|
|
|
||||||
|
|
@ -368,83 +368,78 @@ void TransportFactory::getLiquidSpeciesTransportData(const std::vector<const XML
|
||||||
|
|
||||||
// Species with no 'transport' child are skipped. However, if that
|
// Species with no 'transport' child are skipped. However, if that
|
||||||
// species is in the list, it will throw an exception below.
|
// species is in the list, it will throw an exception below.
|
||||||
try {
|
if (sp.hasChild("transport")) {
|
||||||
if (sp.hasChild("transport")) {
|
XML_Node& trNode = sp.child("transport");
|
||||||
XML_Node& trNode = sp.child("transport");
|
|
||||||
|
|
||||||
// Fill datatable with LiquidTransportData objects for error checking
|
// Fill datatable with LiquidTransportData objects for error checking
|
||||||
// and then insertion into LiquidTransportData objects below.
|
// and then insertion into LiquidTransportData objects below.
|
||||||
LiquidTransportData data;
|
LiquidTransportData data;
|
||||||
data.speciesName = name;
|
data.speciesName = name;
|
||||||
data.mobilityRatio.resize(nsp*nsp,0);
|
data.mobilityRatio.resize(nsp*nsp,0);
|
||||||
data.selfDiffusion.resize(nsp,0);
|
data.selfDiffusion.resize(nsp,0);
|
||||||
ThermoPhase* temp_thermo = trParam.thermo;
|
ThermoPhase* temp_thermo = trParam.thermo;
|
||||||
size_t num = trNode.nChildren();
|
size_t num = trNode.nChildren();
|
||||||
for (size_t iChild = 0; iChild < num; iChild++) {
|
for (size_t iChild = 0; iChild < num; iChild++) {
|
||||||
XML_Node& xmlChild = trNode.child(iChild);
|
XML_Node& xmlChild = trNode.child(iChild);
|
||||||
std::string nodeName = xmlChild.name();
|
std::string nodeName = xmlChild.name();
|
||||||
|
|
||||||
switch (m_tranPropMap[nodeName]) {
|
switch (m_tranPropMap[nodeName]) {
|
||||||
case TP_VISCOSITY:
|
case TP_VISCOSITY:
|
||||||
data.viscosity = newLTP(xmlChild, name, m_tranPropMap[nodeName], temp_thermo);
|
data.viscosity = newLTP(xmlChild, name, m_tranPropMap[nodeName], temp_thermo);
|
||||||
break;
|
|
||||||
case TP_IONCONDUCTIVITY:
|
|
||||||
data.ionConductivity = newLTP(xmlChild, name, m_tranPropMap[nodeName], temp_thermo);
|
|
||||||
break;
|
|
||||||
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;
|
break;
|
||||||
case TP_SELFDIFFUSION: {
|
case TP_IONCONDUCTIVITY:
|
||||||
for (size_t iSpec = 0; iSpec< nsp; iSpec++) {
|
data.ionConductivity = newLTP(xmlChild, name, m_tranPropMap[nodeName], temp_thermo);
|
||||||
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;
|
break;
|
||||||
case TP_THERMALCOND:
|
case TP_MOBILITYRATIO: {
|
||||||
data.thermalCond = newLTP(xmlChild,
|
for (size_t iSpec = 0; iSpec< nBinInt; iSpec++) {
|
||||||
name,
|
XML_Node& propSpecNode = xmlChild.child(iSpec);
|
||||||
m_tranPropMap[nodeName],
|
std::string specName = propSpecNode.name();
|
||||||
temp_thermo);
|
size_t loc = specName.find(":");
|
||||||
break;
|
std::string firstSpec = specName.substr(0,loc);
|
||||||
case TP_DIFFUSIVITY:
|
std::string secondSpec = specName.substr(loc+1);
|
||||||
data.speciesDiffusivity = newLTP(xmlChild,
|
size_t index = temp_thermo->speciesIndex(firstSpec)+nsp*temp_thermo->speciesIndex(secondSpec);
|
||||||
name,
|
data.mobilityRatio[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], temp_thermo);
|
||||||
m_tranPropMap[nodeName],
|
};
|
||||||
temp_thermo);
|
};
|
||||||
break;
|
break;
|
||||||
case TP_HYDRORADIUS:
|
case TP_SELFDIFFUSION: {
|
||||||
data.hydroRadius = newLTP(xmlChild,
|
for (size_t iSpec = 0; iSpec< nsp; iSpec++) {
|
||||||
name,
|
XML_Node& propSpecNode = xmlChild.child(iSpec);
|
||||||
m_tranPropMap[nodeName],
|
std::string specName = propSpecNode.name();
|
||||||
temp_thermo);
|
size_t index = temp_thermo->speciesIndex(specName);
|
||||||
break;
|
data.selfDiffusion[index] = newLTP(propSpecNode, name, m_tranPropMap[nodeName], temp_thermo);
|
||||||
case TP_ELECTCOND:
|
};
|
||||||
data.electCond = newLTP(xmlChild,
|
};
|
||||||
name,
|
break;
|
||||||
m_tranPropMap[nodeName],
|
case TP_THERMALCOND:
|
||||||
temp_thermo);
|
data.thermalCond = newLTP(xmlChild,
|
||||||
break;
|
name,
|
||||||
default:
|
m_tranPropMap[nodeName],
|
||||||
throw CanteraError("getLiquidSpeciesTransportData","unknown transport property: " + 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) {
|
datatable[name] = data;
|
||||||
err.save();
|
|
||||||
throw err;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -596,49 +591,44 @@ void TransportFactory::getSolidTransportData(const XML_Node& transportNode,
|
||||||
const std::string phaseName,
|
const std::string phaseName,
|
||||||
SolidTransportData& trParam)
|
SolidTransportData& trParam)
|
||||||
{
|
{
|
||||||
try {
|
size_t num = transportNode.nChildren();
|
||||||
size_t num = transportNode.nChildren();
|
for (size_t iChild = 0; iChild < num; iChild++) {
|
||||||
for (size_t iChild = 0; iChild < num; iChild++) {
|
//tranTypeNode is a type of transport property like viscosity
|
||||||
//tranTypeNode is a type of transport property like viscosity
|
XML_Node& tranTypeNode = transportNode.child(iChild);
|
||||||
XML_Node& tranTypeNode = transportNode.child(iChild);
|
std::string nodeName = tranTypeNode.name();
|
||||||
std::string nodeName = tranTypeNode.name();
|
ThermoPhase* temp_thermo = trParam.thermo;
|
||||||
ThermoPhase* temp_thermo = trParam.thermo;
|
|
||||||
|
|
||||||
//tranTypeNode contains the interaction model
|
//tranTypeNode contains the interaction model
|
||||||
switch (m_tranPropMap[nodeName]) {
|
switch (m_tranPropMap[nodeName]) {
|
||||||
case TP_IONCONDUCTIVITY:
|
case TP_IONCONDUCTIVITY:
|
||||||
trParam.ionConductivity = newLTP(tranTypeNode, phaseName,
|
trParam.ionConductivity = newLTP(tranTypeNode, phaseName,
|
||||||
|
m_tranPropMap[nodeName],
|
||||||
|
temp_thermo);
|
||||||
|
break;
|
||||||
|
case TP_THERMALCOND:
|
||||||
|
trParam.thermalConductivity = newLTP(tranTypeNode, phaseName,
|
||||||
m_tranPropMap[nodeName],
|
m_tranPropMap[nodeName],
|
||||||
temp_thermo);
|
temp_thermo);
|
||||||
break;
|
break;
|
||||||
case TP_THERMALCOND:
|
case TP_DEFECTDIFF:
|
||||||
trParam.thermalConductivity = newLTP(tranTypeNode, phaseName,
|
trParam.defectDiffusivity = newLTP(tranTypeNode, phaseName,
|
||||||
m_tranPropMap[nodeName],
|
m_tranPropMap[nodeName],
|
||||||
temp_thermo);
|
temp_thermo);
|
||||||
break;
|
break;
|
||||||
case TP_DEFECTDIFF:
|
case TP_DEFECTCONC:
|
||||||
trParam.defectDiffusivity = newLTP(tranTypeNode, phaseName,
|
trParam.defectActivity = newLTP(tranTypeNode, phaseName,
|
||||||
m_tranPropMap[nodeName],
|
m_tranPropMap[nodeName],
|
||||||
temp_thermo);
|
temp_thermo);
|
||||||
break;
|
break;
|
||||||
case TP_DEFECTCONC:
|
case TP_ELECTCOND:
|
||||||
trParam.defectActivity = newLTP(tranTypeNode, phaseName,
|
trParam.electConductivity = newLTP(tranTypeNode, phaseName,
|
||||||
m_tranPropMap[nodeName],
|
m_tranPropMap[nodeName],
|
||||||
temp_thermo);
|
temp_thermo);
|
||||||
break;
|
break;
|
||||||
case TP_ELECTCOND:
|
default:
|
||||||
trParam.electConductivity = newLTP(tranTypeNode, phaseName,
|
throw CanteraError("getSolidTransportData","unknown transport property: " + nodeName);
|
||||||
m_tranPropMap[nodeName],
|
|
||||||
temp_thermo);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw CanteraError("getSolidTransportData","unknown transport property: " + nodeName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (CanteraError) {
|
|
||||||
showErrors(std::cout);
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -286,9 +286,7 @@ int main()
|
||||||
try {
|
try {
|
||||||
w->setState_HP(Hset, OneAtm);
|
w->setState_HP(Hset, OneAtm);
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
|
||||||
printf(" %10g, -> Failed to converge, beyond the spinodal probably \n\n", Hset);
|
printf(" %10g, -> Failed to converge, beyond the spinodal probably \n\n", Hset);
|
||||||
popError();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vapFrac = w->vaporFraction();
|
vapFrac = w->vaporFraction();
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,8 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
Cantera::appdelete();
|
Cantera::appdelete();
|
||||||
return 0;
|
return 0;
|
||||||
} catch (CanteraError) {
|
} catch (CanteraError& err) {
|
||||||
showErrors();
|
std::cout << err.what() << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue