VCS solver now uses normal CanteraError exceptions

This commit is contained in:
Ray Speth 2012-08-08 22:17:15 +00:00
parent cde96e5191
commit 119cf8f5f4
10 changed files with 44 additions and 96 deletions

View file

@ -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.
*/

View file

@ -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)
{
}
}

View file

@ -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 <string>
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

View file

@ -14,7 +14,6 @@
#include "cantera/thermo/ThermoPhase.h"
#include "cantera/thermo/mix_defs.h"
#include "vcs_Exception.h"
#include <string>
#include <sstream>
@ -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;
}
/**********************************************************************/

View file

@ -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;

View file

@ -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 <cstdio>
#include <cstdlib>
@ -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

View file

@ -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 <cstdio>
#include <cstdlib>

View file

@ -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);

View file

@ -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);

View file

@ -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 <cstdio>
@ -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);