Update AssertThrowMsg and AssertFinite to use cppformat

This commit is contained in:
Ray Speth 2015-10-07 16:30:35 -04:00
parent fb4eece9f8
commit c3a16ec1fb
11 changed files with 27 additions and 30 deletions

View file

@ -225,7 +225,7 @@ public:
# define AssertThrow(expr, procedure) ((void) (0))
#endif
#ifndef AssertThrowMsg
# define AssertThrowMsg(expr,procedure, message) ((void) (0))
# define AssertThrowMsg(expr,procedure, ...) ((void) (0))
#endif
#else
@ -271,14 +271,14 @@ public:
* @ingroup errorhandling
*/
#ifndef AssertThrowMsg
# define AssertThrowMsg(expr, procedure, message) ((expr) ? (void) 0 : throw CanteraError(procedure + std::string(": at failed assert: \"") + std::string(#expr) + std::string("\""), message))
# define AssertThrowMsg(expr, procedure, ...) ((expr) ? (void) 0 : throw CanteraError(procedure + std::string(":\nfailed assert: \"") + std::string(#expr) + std::string("\""), __VA_ARGS__))
#endif
#endif
//! Throw an exception if the specified exception is not a finite number.
#ifndef AssertFinite
# define AssertFinite(expr, procedure, message) AssertThrowMsg(expr < BigNumber && expr > -BigNumber, procedure, message)
# define AssertFinite(expr, procedure, ...) AssertThrowMsg(expr < BigNumber && expr > -BigNumber, procedure, __VA_ARGS__)
#endif
}

View file

@ -192,9 +192,9 @@ public:
auto iter = pressures_.upper_bound(c[0]);
AssertThrowMsg(iter != pressures_.end(), "Plog::update_C",
"Pressure out of range: " + fp2str(logP_));
"Pressure out of range: {}", logP_);
AssertThrowMsg(iter != pressures_.begin(), "Plog::update_C",
"Pressure out of range: " + fp2str(logP_));
"Pressure out of range: {}", logP_);
// upper interpolation pressure
logP2_ = iter->first;

View file

@ -821,8 +821,8 @@ void vcs_VolPhase::setTotalMoles(const double totalMols)
m_existence = VCS_PHASE_EXIST_ALWAYS;
AssertThrowMsg(totalMols >= m_totalMolesInert,
"vcs_VolPhase::setTotalMoles",
"totalMoles less than inert moles: " +
fp2str(totalMols) + " " + fp2str(m_totalMolesInert));
"totalMoles less than inert moles: {} {}",
totalMols, m_totalMolesInert);
} else {
if (m_singleSpecies && (m_phiVarIndex == 0)) {
m_existence = VCS_PHASE_EXIST_ALWAYS;

View file

@ -170,7 +170,7 @@ void VCS_SOLVE::vcs_switch_elem_pos(size_t ipos, size_t jpos)
}
AssertThrowMsg(ipos < m_numElemConstraints && jpos < m_numElemConstraints,
"vcs_switch_elem_pos",
"inappropriate args: " + int2str(ipos) + " " + int2str(jpos));
"inappropriate args: {} {}", ipos, jpos);
/*
* Change the element Global Index list in each vcs_VolPhase object
* to reflect the switch in the element positions.

View file

@ -29,8 +29,8 @@ bool VCS_SOLVE::vcs_popPhasePossible(const size_t iphasePop) const
size_t kspec = Vphase->spGlobalIndexVCS(k);
AssertThrowMsg(m_molNumSpecies_old[kspec] <= 0.0,
"VCS_SOLVE::vcs_popPhasePossible",
"we shouldn't be here " + int2str(kspec) + " "+
fp2str(m_molNumSpecies_old[kspec]) + " > 0.0");
"we shouldn't be here {}: {} > 0.0", kspec,
m_molNumSpecies_old[kspec]);
size_t irxn = kspec - m_numComponents;
if (kspec >= m_numComponents) {
bool iPopPossible = true;

View file

@ -947,9 +947,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
AssertThrowMsg(fabs(m_deltaMolNumSpecies[kspec] -dx) <
1.0E-14*(fabs(m_deltaMolNumSpecies[kspec]) + fabs(dx) + 1.0E-32),
"VCS_SOLVE::solve_tp_inner",
"ds[kspec] = " + fp2str(m_deltaMolNumSpecies[kspec]) +
" dx = " + fp2str(dx) + " , kspec = " + int2str(kspec) +
"\nwe have a problem!");
"ds[kspec] = {}, dx = {}, kspec = {}\nwe have a problem!",
m_deltaMolNumSpecies[kspec], dx, kspec);
for (size_t k = 0; k < m_numComponents; ++k) {
m_deltaMolNumSpecies[k] += sc_irxn[k] * dx;
}
@ -1748,7 +1747,7 @@ int VCS_SOLVE::delta_species(const size_t kspec, double* const delta_ptr)
int retn = 1;
double delta = *delta_ptr;
AssertThrowMsg(kspec >= m_numComponents, "VCS_SOLVE::delta_species",
"delete_species() ERROR: called for a component " + int2str(kspec));
"delete_species() ERROR: called for a component {}", kspec);
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
/*
* Attempt the given dx. If it doesn't work, try to see if a smaller
@ -3315,8 +3314,8 @@ void VCS_SOLVE::vcs_dfe(const int stateCalc,
for (size_t iph = 0; iph < m_numPhases; iph++) {
AssertThrowMsg(vcs_doubleEqual(tlogMoles[iph], tPhMoles_ptr[iph]),
"VCS_SOLVE::vcs_dfe",
"phase Moles may be off, iph = " + int2str(iph) + ", " +
fp2str(tlogMoles[iph]) + " " + fp2str(tPhMoles_ptr[iph]));
"phase Moles may be off, iph = {}, {} {}",
iph, tlogMoles[iph], tPhMoles_ptr[iph]);
}
m_TmpPhase.assign(m_TmpPhase.size(), 0.0);
for (size_t iph = 0; iph < m_numPhases; iph++) {

View file

@ -296,7 +296,7 @@ extern "C" {
// array not big enough
if (*n < nv) {
throw CanteraError("ctml_getfloatarray",
"array must be dimensioned at least "+Cantera::int2str(nv));
"array must be dimensioned at least {}", nv);
}
for (int i = 0; i < nv; i++) {

View file

@ -144,7 +144,7 @@ void GasKinetics::processFalloffReactions()
for (size_t i = 0; i < m_nfall; i++) {
pr[i] = concm_falloff_values[i] * m_rfn_low[i] / (m_rfn_high[i] + SmallNumber);
AssertFinite(pr[i], "GasKinetics::processFalloffReactions",
"pr[" + int2str(i) + "] is not finite.");
"pr[{}] is not finite.", i);
}
m_falloffn.pr_to_falloff(pr.data(), falloff_work.data());
@ -203,11 +203,11 @@ void GasKinetics::updateROP()
for (size_t i = 0; i < m_rfn.size(); i++) {
AssertFinite(m_rfn[i], "GasKinetics::updateROP",
"m_rfn[" + int2str(i) + "] is not finite.");
"m_rfn[{}] is not finite.", i);
AssertFinite(m_ropf[i], "GasKinetics::updateROP",
"m_ropf[" + int2str(i) + "] is not finite.");
"m_ropf[{}] is not finite.", i);
AssertFinite(m_ropr[i], "GasKinetics::updateROP",
"m_ropr[" + int2str(i) + "] is not finite.");
"m_ropr[{}] is not finite.", i);
}
m_ROP_ok = true;
}

View file

@ -224,7 +224,7 @@ std::pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
throw CanteraError("installReaction",
"Undeclared duplicate reactions detected:\n"
"Reaction {}: {}\nReaction {}: {}\n",
int2str(i+1), other.equation(), int2str(m+1), R.equation());
i+1, other.equation(), m+1, R.equation());
} else {
return make_pair(i,m);
}

View file

@ -51,8 +51,7 @@ void Sim1D::setValue(size_t dom, size_t comp, size_t localPoint, doublereal valu
{
size_t iloc = domain(dom).loc() + domain(dom).index(comp, localPoint);
AssertThrowMsg(iloc < m_x.size(), "Sim1D::setValue",
"Index out of bounds:" + int2str(iloc) + " > " +
int2str(m_x.size()));
"Index out of bounds: {} > {}", iloc, m_x.size());
m_x[iloc] = value;
}
@ -60,8 +59,7 @@ doublereal Sim1D::value(size_t dom, size_t comp, size_t localPoint) const
{
size_t iloc = domain(dom).loc() + domain(dom).index(comp, localPoint);
AssertThrowMsg(iloc < m_x.size(), "Sim1D::value",
"Index out of bounds:" + int2str(iloc) + " > " +
int2str(m_x.size()));
"Index out of bounds: {} > {}", iloc, m_x.size());
return m_x[iloc];
}
@ -69,8 +67,7 @@ doublereal Sim1D::workValue(size_t dom, size_t comp, size_t localPoint) const
{
size_t iloc = domain(dom).loc() + domain(dom).index(comp, localPoint);
AssertThrowMsg(iloc < m_x.size(), "Sim1D::workValue",
"Index out of bounds:" + int2str(iloc) + " > " +
int2str(m_x.size()));
"Index out of bounds: {} > {}", iloc, m_x.size());
return m_xnew[iloc];
}

View file

@ -80,8 +80,9 @@ void GeneralSpeciesThermo::install_STIT(size_t index,
throw CanteraError("GeneralSpeciesThermo::install_STIT",
"zero pointer");
}
AssertThrow(m_speciesLoc.find(index) == m_speciesLoc.end(),
"Index position isn't null, duplication of assignment: " + int2str(index));
AssertThrowMsg(m_speciesLoc.find(index) == m_speciesLoc.end(),
"GeneralSpeciesThermo::install_STIT",
"Index position isn't null, duplication of assignment: {}", index);
int type = stit_ptr->reportType();
m_speciesLoc[index] = std::make_pair(type, m_sp[type].size());
m_sp[type].push_back(std::make_pair(index, stit_ptr));