diff --git a/include/cantera/base/ctexceptions.h b/include/cantera/base/ctexceptions.h index bb417b70a..1d60f3823 100644 --- a/include/cantera/base/ctexceptions.h +++ b/include/cantera/base/ctexceptions.h @@ -52,9 +52,8 @@ namespace Cantera * * Their first argument is a boolean. If the boolean is not true, a * CanteraError is thrown, with descriptive information indicating - * where the error occurred. These functions may be eliminated from - * the source code, if the -DNDEBUG option is specified to the - * compiler. + * where the error occurred. The Assert* checks are skipped if the NDEBUG + * preprocessor symbol is defined, e.g. with the compiler option -DNDEBUG. */ diff --git a/src/equil/vcs_Exception.cpp b/src/equil/vcs_Exception.cpp deleted file mode 100644 index b375a37b0..000000000 --- a/src/equil/vcs_Exception.cpp +++ /dev/null @@ -1,15 +0,0 @@ - -#include "vcs_Exception.h" - -namespace VCSnonideal -{ - -vcsError::vcsError(std::string proc, std::string msg, int errorCode) : - m_proc(proc), - m_msg(msg), - m_errorCode(errorCode) -{ - -} - -} diff --git a/src/equil/vcs_Exception.h b/src/equil/vcs_Exception.h deleted file mode 100644 index b1971b65c..000000000 --- a/src/equil/vcs_Exception.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * @file vcs_Exception.h - */ -/* - * Copyright (2005) Sandia Corporation. Under the terms of - * Contract DE-AC04-94AL85000 with Sandia Corporation, the - * U.S. Government retains certain rights in this software. - */ -#ifndef VCS_EXCEPTION_H -#define VCS_EXCEPTION_H - -#include - -namespace VCSnonideal -{ - -class vcsError -{ -public: - vcsError(std::string proc, std::string msg, int errorCode=-1); - virtual ~vcsError() {} -protected: - std::string m_proc; - std::string m_msg; - int m_errorCode; -}; - - -//! Assertion must be true or an error is thrown -/*! - * Assertion must be true or else a vcsError is thrown. A diagnostic - * string indicating where the error - * occured is added to the thrown object. - * - * @param expr Boolean expression that must be true - * @param proc Character string or std:string expression indicating the procedure - * where the assertion failed - * @ingroup errorhandling - */ -#define AssertThrowVCS(expr, proc) ((expr) ? (void) 0 : throw vcsError(proc, std::string("failed Assert: ") + #expr,-1)) - -#ifdef DEBUG_HKM -#define DebugAssertThrowVCS(expr, proc) ((expr) ? (void) 0 : throw vcsError(proc, std::string("failed debugAssert: ") + #expr,-1)) -#else -#define DebugAssertThrowVCS(expr, proc) -#endif - -} - -#endif diff --git a/src/equil/vcs_VolPhase.cpp b/src/equil/vcs_VolPhase.cpp index 036e56b55..480835d67 100644 --- a/src/equil/vcs_VolPhase.cpp +++ b/src/equil/vcs_VolPhase.cpp @@ -14,7 +14,6 @@ #include "cantera/thermo/ThermoPhase.h" #include "cantera/thermo/mix_defs.h" -#include "vcs_Exception.h" #include #include @@ -1404,7 +1403,7 @@ double vcs_VolPhase::totalMolesInert() const // Returns the global index of the local element index for the phase size_t vcs_VolPhase::elemGlobalIndex(const size_t e) const { - DebugAssertThrowVCS(e < m_numElemConstraints, " vcs_VolPhase::elemGlobalIndex") ; + AssertThrow(e < m_numElemConstraints, " vcs_VolPhase::elemGlobalIndex"); return m_elemGlobalIndex[e]; } /**********************************************************************/ @@ -1412,8 +1411,8 @@ size_t vcs_VolPhase::elemGlobalIndex(const size_t e) const // Returns the global index of the local element index for the phase void vcs_VolPhase::setElemGlobalIndex(const size_t eLocal, const size_t eGlobal) { - DebugAssertThrowVCS(eLocal < m_numElemConstraints, - "vcs_VolPhase::setElemGlobalIndex"); + AssertThrow(eLocal < m_numElemConstraints, + "vcs_VolPhase::setElemGlobalIndex"); m_elemGlobalIndex[eLocal] = eGlobal; } /**********************************************************************/ diff --git a/src/equil/vcs_elem.cpp b/src/equil/vcs_elem.cpp index be09de131..2ea7d84ed 100644 --- a/src/equil/vcs_elem.cpp +++ b/src/equil/vcs_elem.cpp @@ -6,7 +6,7 @@ */ #include "cantera/equil/vcs_solve.h" #include "cantera/equil/vcs_internal.h" -#include "vcs_Exception.h" +#include "cantera/base/ctexceptions.h" #include "math.h" namespace VCSnonideal @@ -78,8 +78,10 @@ bool VCS_SOLVE::vcs_elabcheck(int ibound) /* * This logic is for charge neutrality condition */ - if (m_elType[i] == VCS_ELEM_TYPE_CHARGENEUTRALITY) { - AssertThrowVCS(m_elemAbundancesGoal[i] == 0.0, "vcs_elabcheck"); + if (m_elType[i] == VCS_ELEM_TYPE_CHARGENEUTRALITY && + m_elemAbundancesGoal[i] != 0.0) { + throw Cantera::CanteraError("VCS_SOLVE::vcs_elabcheck", + "Problem with charge neutrality condition"); } if (m_elemAbundancesGoal[i] == 0.0 || (m_elType[i] == VCS_ELEM_TYPE_ELECTRONCHARGE)) { scale = VCS_DELETE_MINORSPECIES_CUTOFF; diff --git a/src/equil/vcs_nondim.cpp b/src/equil/vcs_nondim.cpp index 0d1b9f5b8..745ff0471 100644 --- a/src/equil/vcs_nondim.cpp +++ b/src/equil/vcs_nondim.cpp @@ -12,7 +12,7 @@ #include "cantera/equil/vcs_internal.h" #include "cantera/equil/vcs_VolPhase.h" #include "cantera/base/stringUtils.h" -#include "vcs_Exception.h" +#include "cantera/base/ctexceptions.h" #include #include @@ -159,8 +159,9 @@ void VCS_SOLVE::vcs_nondim_TP() plogf(" VCS_SOLVE::vcs_nondim_TP ERROR: Total input moles , %g, is outside the range handled by vcs. exit", tmole_orig); plogendl(); - throw vcsError("VCS_SOLVE::vcs_nondim_TP", " Total input moles ," + Cantera::fp2str(tmole_orig) + - "is outside the range handled by vcs.\n"); + throw Cantera::CanteraError("VCS_SOLVE::vcs_nondim_TP", + " Total input moles ," + Cantera::fp2str(tmole_orig) + + "is outside the range handled by vcs.\n"); } // Determine the scale of the problem diff --git a/src/equil/vcs_phaseStability.cpp b/src/equil/vcs_phaseStability.cpp index f9a476feb..68ee59885 100644 --- a/src/equil/vcs_phaseStability.cpp +++ b/src/equil/vcs_phaseStability.cpp @@ -7,7 +7,6 @@ #include "cantera/equil/vcs_internal.h" #include "vcs_species_thermo.h" #include "cantera/equil/vcs_VolPhase.h" -#include "vcs_Exception.h" #include #include diff --git a/src/equil/vcs_solve.cpp b/src/equil/vcs_solve.cpp index 8324857e3..b0674f111 100644 --- a/src/equil/vcs_solve.cpp +++ b/src/equil/vcs_solve.cpp @@ -10,7 +10,7 @@ #include "cantera/equil/vcs_solve.h" -#include "vcs_Exception.h" +#include "cantera/base/ctexceptions.h" #include "cantera/equil/vcs_internal.h" #include "cantera/equil/vcs_prob.h" @@ -100,21 +100,18 @@ void VCS_SOLVE::vcs_initSizes(const size_t nspecies0, const size_t nelements, string ser = "VCS_SOLVE: ERROR:\n\t"; if (nspecies0 <= 0) { plogf("%s Number of species is nonpositive\n", ser.c_str()); - throw vcsError("VCS_SOLVE()", - ser + " Number of species is nonpositive\n", - VCS_PUB_BAD); + throw Cantera::CanteraError("VCS_SOLVE()", ser + + " Number of species is nonpositive\n"); } if (nelements <= 0) { plogf("%s Number of elements is nonpositive\n", ser.c_str()); - throw vcsError("VCS_SOLVE()", - ser + " Number of species is nonpositive\n", - VCS_PUB_BAD); + throw Cantera::CanteraError("VCS_SOLVE()", ser + + " Number of species is nonpositive\n"); } if (nphase0 <= 0) { plogf("%s Number of phases is nonpositive\n", ser.c_str()); - throw vcsError("VCS_SOLVE()", - ser + " Number of species is nonpositive\n", - VCS_PUB_BAD); + throw Cantera::CanteraError("VCS_SOLVE()", ser + + " Number of species is nonpositive\n"); } //vcs_priv_init(this); diff --git a/src/equil/vcs_solve_TP.cpp b/src/equil/vcs_solve_TP.cpp index fc9e11e97..4943d4cfe 100644 --- a/src/equil/vcs_solve_TP.cpp +++ b/src/equil/vcs_solve_TP.cpp @@ -17,12 +17,13 @@ #include "cantera/equil/vcs_internal.h" #include "cantera/equil/vcs_VolPhase.h" #include "vcs_species_thermo.h" -#include "vcs_Exception.h" +#include "cantera/base/ctexceptions.h" #include "cantera/base/clockWC.h" #include "cantera/base/stringUtils.h" using namespace std; +using namespace Cantera; #ifndef MAX #define MAX(x,y) (( (x) > (y) ) ? (x) : (y)) @@ -3648,9 +3649,15 @@ size_t VCS_SOLVE::vcs_basisOptMax(const double* const molNum, const size_t j, { size_t largest = j; double big = molNum[j] * m_spSize[j] * 1.01; - AssertThrowVCS(m_spSize[j] > 0.0, "spsize is nonpos"); + if (m_spSize[j] <= 0.0) { + throw CanteraError("VCS_SOLVE::vcs_basisOptMax", + "spSize is nonpositive"); + } for (size_t i = j + 1; i < n; ++i) { - AssertThrowVCS(m_spSize[i] > 0.0, "spsize is nonpos"); + if (m_spSize[i] <= 0.0) { + throw CanteraError("VCS_SOLVE::vcs_basisOptMax", + "spSize is nonpositive"); + } bool doSwap = false; if (m_SSPhase[j]) { doSwap = (molNum[i] * m_spSize[i]) > (big); diff --git a/src/equil/vcs_species_thermo.cpp b/src/equil/vcs_species_thermo.cpp index f12141e5e..e4be883a3 100644 --- a/src/equil/vcs_species_thermo.cpp +++ b/src/equil/vcs_species_thermo.cpp @@ -15,7 +15,7 @@ #include "cantera/equil/vcs_defs.h" #include "cantera/equil/vcs_VolPhase.h" -#include "vcs_Exception.h" +#include "cantera/base/ctexceptions.h" #include "cantera/equil/vcs_internal.h" #include @@ -178,7 +178,10 @@ double VCS_SPECIES_THERMO::GStar_R_calc(size_t kglob, double TKelvin, fe = G0_R_calc(kglob, TKelvin); T = TKelvin; if (UseCanteraCalls) { - AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency"); + if (m_VCS_UnitsFormat != VCS_UNITS_MKS) { + throw Cantera::CanteraError("VCS_SPECIES_THERMO::GStar_R_calc", + "Possible inconsistency"); + } size_t kspec = IndexSpeciesPhase; OwningPhase->setState_TP(TKelvin, pres); fe = OwningPhase->GStar_calc_one(kspec); @@ -221,7 +224,10 @@ VolStar_calc(size_t kglob, double TKelvin, double presPA) T = TKelvin; if (UseCanteraCalls) { - AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency"); + if (m_VCS_UnitsFormat != VCS_UNITS_MKS) { + throw Cantera::CanteraError("VCS_SPECIES_THERMO::VolStar_calc", + "Possible inconsistency"); + } size_t kspec = IndexSpeciesPhase; OwningPhase->setState_TP(TKelvin, presPA); vol = OwningPhase->VolStar_calc_one(kspec); @@ -270,7 +276,10 @@ double VCS_SPECIES_THERMO::G0_R_calc(size_t kglob, double TKelvin) return fe; } if (UseCanteraCalls) { - AssertThrowVCS(m_VCS_UnitsFormat == VCS_UNITS_MKS, "Possible inconsistency"); + if (m_VCS_UnitsFormat != VCS_UNITS_MKS) { + throw Cantera::CanteraError("VCS_SPECIES_THERMO::G0_R_calc", + "Possible inconsistency"); + } size_t kspec = IndexSpeciesPhase; OwningPhase->setState_T(TKelvin); fe = OwningPhase->G0_calc_one(kspec);