Replace usage of int2str with cppformat and deprecate int2str

This commit is contained in:
Ray Speth 2016-02-04 19:11:18 -05:00
parent f91afda8cb
commit f44b5fed57
18 changed files with 75 additions and 50 deletions

View file

@ -27,12 +27,14 @@ std::string fp2str(const double x, const std::string& fmt="%g");
/*!
* @param n int to be converted
* @param fmt format converter for an int int the printf command
* @deprecated Unused. To be removed after Cantera 2.3. Use fmt::format instead
*/
std::string int2str(const int n, const std::string& fmt="%d");
//! Convert an unsigned integer to a string
/*!
* @param n int to be converted
* @deprecated Unused. To be removed after Cantera 2.3. Use fmt::format instead
*/
std::string int2str(const size_t n);

View file

@ -203,7 +203,7 @@ public:
if (m_name[n] != "") {
return m_name[n];
} else {
return "component " + int2str(n);
return fmt::format("component {}", n);
}
}
@ -480,7 +480,7 @@ public:
if (m_id != "") {
return m_id;
} else {
return std::string("domain ") + int2str(m_index);
return fmt::format("domain {}", m_index);
}
}

View file

@ -130,7 +130,7 @@ public:
m_refiner->setActive(n, c.refine);
// set a default name if one has not been entered
if (c.name == "") {
c.name = "Component "+Cantera::int2str(n);
c.name = fmt::format("Component {}", n);
}
setComponentName(n, c.name);
}

View file

@ -41,6 +41,8 @@ std::string fp2str(const double x, const std::string& fmt)
std::string int2str(const int n, const std::string& fmt)
{
warn_deprecated("int2str", "Unused. To be removed after Cantera 2.3. "
"Use fmt::format instead.");
char buf[30];
int m = SNPRINTF(buf, 30, fmt.c_str(), n);
if (m > 0) {
@ -52,6 +54,8 @@ std::string int2str(const int n, const std::string& fmt)
std::string int2str(const size_t n)
{
warn_deprecated("int2str", "Unused. To be removed after Cantera 2.3. "
"Use fmt::format instead.");
std::stringstream ss;
ss << n;
return ss.str();

View file

@ -34,7 +34,7 @@ protected:
m_line(line),
m_msg("Error in XML file") {
if (line > 0) {
m_msg += " at line " + int2str(line+1);
m_msg += fmt::format(" at line {}", line+1);
}
m_msg += ".\n";
}
@ -487,12 +487,12 @@ void XML_Node::addAttribute(const std::string& attrib,
void XML_Node::addAttribute(const std::string& aattrib, const int vvalue)
{
m_attribs[aattrib] = int2str(vvalue);
m_attribs[aattrib] = fmt::format("{}", vvalue);
}
void XML_Node::addAttribute(const std::string& aattrib, const size_t vvalue)
{
m_attribs[aattrib] = int2str(vvalue);
m_attribs[aattrib] = fmt::format("{}", vvalue);
}
std::string XML_Node::operator[](const std::string& attr) const
@ -622,7 +622,7 @@ XML_Node* XML_Node::findNameIDIndex(const std::string& nameTarget,
XML_Node* scResult = 0;
std::string idattrib = id();
std::string ii = attrib("index");
std::string index_s = int2str(index_i);
std::string index_s = fmt::format("{}", index_i);
int iMax = -1000000;
if (name() == nameTarget && (idTarget == "" || idTarget == idattrib) && index_s == ii) {
return const_cast<XML_Node*>(this);

View file

@ -341,7 +341,8 @@ void CVodesIntegrator::reinitialize(double t0, FuncEval& func)
int result;
result = CVodeReInit(m_cvode_mem, m_t0, m_y);
if (result != CV_SUCCESS) {
throw CVodesErr("CVodeReInit failed. result = "+int2str(result));
throw CanteraError("CVodesIntegrator::reinitialize",
"CVodeReInit failed. result = {}", result);
}
applyOptions();
}
@ -393,8 +394,10 @@ void CVodesIntegrator::integrate(double tout)
{
int flag = CVode(m_cvode_mem, tout, m_y, &m_time, CV_NORMAL);
if (flag != CV_SUCCESS) {
throw CVodesErr("CVodes error encountered. Error code: " + int2str(flag) + "\n" + m_error_message +
"\nComponents with largest weighted error estimates:\n" + getErrorInfo(10));
throw CanteraError("CVodesIntegrator::integrate",
"CVodes error encountered. Error code: {}\n{}\n"
"Components with largest weighted error estimates:\n{}",
flag, m_error_message, getErrorInfo(10));
}
m_sens_ok = false;
}
@ -403,8 +406,10 @@ double CVodesIntegrator::step(double tout)
{
int flag = CVode(m_cvode_mem, tout, m_y, &m_time, CV_ONE_STEP);
if (flag != CV_SUCCESS) {
throw CVodesErr("CVodes error encountered. Error code: " + int2str(flag) + "\n" + m_error_message +
"\nComponents with largest weighted error estimates:\n" + getErrorInfo(10));
throw CanteraError("CVodesIntegrator::step",
"CVodes error encountered. Error code: {}\n{}\n"
"Components with largest weighted error estimates:\n{}",
flag, m_error_message, getErrorInfo(10));
}
m_sens_ok = false;
@ -427,16 +432,19 @@ double CVodesIntegrator::sensitivity(size_t k, size_t p)
if (!m_sens_ok && m_np) {
int flag = CVodeGetSens(m_cvode_mem, &m_time, m_yS);
if (flag != CV_SUCCESS) {
throw CVodesErr("CVodeGetSens failed. Error code: " + int2str(flag));
throw CanteraError("CVodesIntegrator::sensitivity",
"CVodeGetSens failed. Error code: {}", flag);
}
m_sens_ok = true;
}
if (k >= m_neq) {
throw CVodesErr("sensitivity: k out of range ("+int2str(p)+")");
throw CanteraError("CVodesIntegrator::sensitivity",
"sensitivity: k out of range ({})", k);
}
if (p >= m_np) {
throw CVodesErr("sensitivity: p out of range ("+int2str(p)+")");
throw CanteraError("CVodesIntegrator::sensitivity",
"sensitivity: p out of range ({})", p);
}
return NV_Ith_S(m_yS[p],k);
}

View file

@ -143,10 +143,10 @@ int solve(DenseMatrix& A, double* b, size_t nrhs, size_t ldb)
"it is used to solve a system of equations.\n", info);
}
if (!A.m_useReturnErrorCode) {
throw CELapackError("solve(DenseMatrix& A, double* b)",
"DGETRF returned INFO = "+int2str(info) + ". U(i,i) is exactly zero. The factorization has"
throw CanteraError("solve(DenseMatrix& A, double* b)",
"DGETRF returned INFO = {}. U(i,i) is exactly zero. The factorization has"
" been completed, but the factor U is exactly singular, and division by zero will occur if "
"it is used to solve a system of equations.");
"it is used to solve a system of equations.", info);
}
return info;
} else if (info < 0) {
@ -154,8 +154,8 @@ int solve(DenseMatrix& A, double* b, size_t nrhs, size_t ldb)
writelogf("solve(DenseMatrix& A, double* b): DGETRF returned INFO = %d. The argument i has an illegal value\n", info);
}
throw CELapackError("solve(DenseMatrix& A, double* b)",
"DGETRF returned INFO = "+int2str(info) + ". The argument i has an illegal value");
throw CanteraError("solve(DenseMatrix& A, double* b)",
"DGETRF returned INFO = {}. The argument i has an illegal value", info);
}
if (ldb == 0) {
@ -168,7 +168,7 @@ int solve(DenseMatrix& A, double* b, size_t nrhs, size_t ldb)
writelogf("solve(DenseMatrix& A, double* b): DGETRS returned INFO = %d\n", info);
}
if (info < 0 || !A.m_useReturnErrorCode) {
throw CELapackError("solve(DenseMatrix& A, double* b)", "DGETRS returned INFO = "+int2str(info));
throw CanteraError("solve(DenseMatrix& A, double* b)", "DGETRS returned INFO = {}", info);
}
}
return info;
@ -204,7 +204,7 @@ int invert(DenseMatrix& A, size_t nn)
writelogf("invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info);
}
if (! A.m_useReturnErrorCode) {
throw CELapackError("invert(DenseMatrix& A, int nn)", "DGETRS returned INFO = "+int2str(info));
throw CanteraError("invert(DenseMatrix& A, int nn)", "DGETRS returned INFO = {}", info);
}
return info;
}
@ -218,7 +218,7 @@ int invert(DenseMatrix& A, size_t nn)
writelogf("invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info);
}
if (! A.m_useReturnErrorCode) {
throw CELapackError("invert(DenseMatrix& A, int nn)", "DGETRI returned INFO="+int2str(info));
throw CanteraError("invert(DenseMatrix& A, int nn)", "DGETRI returned INFO={}", info);
}
}
return info;

View file

@ -465,12 +465,14 @@ void IDA_Solver::correctInitial_Y_given_Yp(doublereal* y, doublereal* yp, double
int flag = IDACalcIC(m_ida_mem, icopt, tout1);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDACalcIC failed: error = " + int2str(flag));
throw CanteraError("IDA_Solver::correctInitial_Y_given_Yp",
"IDACalcIC failed: error = {}", flag);
}
flag = IDAGetConsistentIC(m_ida_mem, m_y, m_ydot);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDAGetSolution failed: error = " + int2str(flag));
throw CanteraError("IDA_Solver::correctInitial_Y_given_Yp",
"IDAGetSolution failed: error = {}", flag);
}
doublereal* yy = NV_DATA_S(m_y);
doublereal* yyp = NV_DATA_S(m_ydot);
@ -495,12 +497,14 @@ void IDA_Solver::correctInitial_YaYp_given_Yd(doublereal* y, doublereal* yp, dou
int flag = IDACalcIC(m_ida_mem, icopt, tout1);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDACalcIC failed: error = " + int2str(flag));
throw CanteraError("IDA_Solver::correctInitial_YaYp_given_Yd",
"IDACalcIC failed: error = {}", flag);
}
flag = IDAGetConsistentIC(m_ida_mem, m_y, m_ydot);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDAGetSolution failed: error = " + int2str(flag));
throw CanteraError("IDA_Solver::correctInitial_YaYp_given_Yd",
"IDAGetSolution failed: error = {}", flag);
}
doublereal* yy = NV_DATA_S(m_y);
doublereal* yyp = NV_DATA_S(m_ydot);

View file

@ -78,7 +78,7 @@ int SquareMatrix::solve(doublereal* b, size_t nrhs, size_t ldb)
writelogf("SquareMatrix::solve(): DGETRS returned INFO = %d\n", info);
}
if (! m_useReturnErrorCode) {
throw CELapackError("SquareMatrix::solve()", "DGETRS returned INFO = " + int2str(info));
throw CanteraError("SquareMatrix::solve()", "DGETRS returned INFO = {}", info);
}
}
return info;
@ -124,7 +124,7 @@ int SquareMatrix::factor()
writelogf("SquareMatrix::factor(): DGETRS returned INFO = %d\n", info);
}
if (! m_useReturnErrorCode) {
throw CELapackError("SquareMatrix::factor()", "DGETRS returned INFO = "+int2str(info));
throw CanteraError("SquareMatrix::factor()", "DGETRS returned INFO = {}", info);
}
}
return info;
@ -151,7 +151,7 @@ int SquareMatrix::factorQR()
writelogf("SquareMatrix::factorQR(): DGEQRF returned INFO = %d\n", info);
}
if (! m_useReturnErrorCode) {
throw CELapackError("SquareMatrix::factorQR()", "DGEQRF returned INFO = " + int2str(info));
throw CanteraError("SquareMatrix::factorQR()", "DGEQRF returned INFO = {}", info);
}
}
size_t lworkOpt = static_cast<size_t>(work[0]);
@ -187,7 +187,7 @@ int SquareMatrix::solveQR(doublereal* b)
writelogf("SquareMatrix::solveQR(): DORMQR returned INFO = %d\n", info);
}
if (! m_useReturnErrorCode) {
throw CELapackError("SquareMatrix::solveQR()", "DORMQR returned INFO = " + int2str(info));
throw CanteraError("SquareMatrix::solveQR()", "DORMQR returned INFO = {}", info);
}
}
size_t lworkOpt = static_cast<size_t>(work[0]);
@ -203,7 +203,7 @@ int SquareMatrix::solveQR(doublereal* b)
writelogf("SquareMatrix::solveQR(): DTRTRS returned INFO = %d\n", info);
}
if (! m_useReturnErrorCode) {
throw CELapackError("SquareMatrix::solveQR()", "DTRTRS returned INFO = " + int2str(info));
throw CanteraError("SquareMatrix::solveQR()", "DTRTRS returned INFO = {}", info);
}
}
return info;
@ -230,7 +230,7 @@ doublereal SquareMatrix::rcond(doublereal anorm)
writelogf("SquareMatrix::rcond(): DGECON returned INFO = %d\n", rinfo);
}
if (! m_useReturnErrorCode) {
throw CELapackError("SquareMatrix::rcond()", "DGECON returned INFO = " + int2str(rinfo));
throw CanteraError("SquareMatrix::rcond()", "DGECON returned INFO = {}", rinfo);
}
}
return rcond;
@ -262,7 +262,7 @@ doublereal SquareMatrix::rcondQR()
writelogf("SquareMatrix::rcondQR(): DTRCON returned INFO = %d\n", rinfo);
}
if (! m_useReturnErrorCode) {
throw CELapackError("SquareMatrix::rcondQR()", "DTRCON returned INFO = " + int2str(rinfo));
throw CanteraError("SquareMatrix::rcondQR()", "DTRCON returned INFO = {}", rinfo);
}
}
return rcond;

View file

@ -111,10 +111,10 @@ void Domain1D::restore(const XML_Node& dom, doublereal* soln, int loglevel)
getFloatArray(*nodes[i], values, false);
if (values.size() != nComponents()) {
if (loglevel > 0) {
writelog("Warning: Domain1D::restore: Got an array of length " +
int2str(values.size()) + " when one of length " +
int2str(nComponents()) + " was expected. " +
"Tolerances for individual species may not be preserved.\n");
writelog("Warning: Domain1D::restore: Got an array of length {}"
" when one of length {} was expected. "
"Tolerances for individual species may not be preserved.\n",
values.size(), nComponents());
}
// The number of components will differ when restoring from a
// mechanism with a different number of species. Assuming that

View file

@ -310,7 +310,9 @@ int MultiNewton::solve(doublereal* x0, doublereal* x1,
while (true) {
// Check whether the Jacobian should be re-evaluated.
if (jac.age() > m_maxAge) {
debuglog("\nMaximum Jacobian age reached ("+int2str(m_maxAge)+")\n", loglevel);
if (loglevel > 0) {
writelog("\nMaximum Jacobian age reached ({})\n", m_maxAge);
}
forceNewJac = true;
}

View file

@ -256,7 +256,9 @@ void Sim1D::solve(int loglevel, bool refine_grid)
saveResidual("debug_sim1d.xml", "residual",
"After unsuccessful Newton solve");
}
debuglog("Take "+int2str(nsteps)+" timesteps ", loglevel);
if (loglevel > 0) {
writelog("Take {} timesteps ", nsteps);
}
dt = timeStep(nsteps, dt, m_x.data(), m_xnew.data(),
loglevel-1);
if (loglevel > 6) {

View file

@ -643,7 +643,9 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
if (nm == "z") {
getFloatArray(fa,x,false);
np = x.size();
debuglog("Grid contains "+int2str(np)+" points.\n", loglevel >= 2);
if (loglevel >= 2) {
writelog("Grid contains {} points.\n", np);
}
readgrid = true;
setupGrid(np, x.data());
}

View file

@ -152,7 +152,7 @@ int Refiner::analyze(size_t n, const doublereal* z,
// Add a new point if the ratio with left interval is too large
if (dz[j] > m_ratio*dz[j-1]) {
m_loc[j] = 1;
m_c["point "+int2str(j)] = 1;
m_c[fmt::format("point {}", j)] = 1;
m_keep[j-1] = 1;
m_keep[j] = 1;
m_keep[j+1] = 1;
@ -162,7 +162,7 @@ int Refiner::analyze(size_t n, const doublereal* z,
// Add a point if the ratio with right interval is too large
if (dz[j] < dz[j-1]/m_ratio) {
m_loc[j-1] = 1;
m_c["point "+int2str(j-1)] = 1;
m_c[fmt::format("point {}", j-1)] = 1;
m_keep[j-2] = 1;
m_keep[j-1] = 1;
m_keep[j] = 1;

View file

@ -343,7 +343,7 @@ void LatticeSolidPhase::installSlavePhases(XML_Node* phaseNode)
}
// Add in the lattice stoichiometry constraint
if (n > 0) {
string econ = "LC_" + int2str(n) + "_" + id();
string econ = fmt::format("LC_{}_{}", n, id());
size_t m = addElement(econ, 0.0, 0, 0.0, CT_ELEM_TYPE_LATTICERATIO);
size_t mm = nElements();
size_t nsp0 = m_lattice[0]->nSpecies();

View file

@ -305,7 +305,8 @@ VPSSMgr* VPSSMgrFactory::newVPSSMgr(VPSSMgr_enumType type,
return new VPSSMgr_General(vp_ptr, &spthermoRef);
case cVPSSMGR_UNDEF:
default:
throw UnknownVPSSMgrModel("VPSSMgrFactory::newVPSSMgr", int2str(type));
throw CanteraError("VPSSMgrFactory::newVPSSMgr",
"Specified VPSSMgr model {} does not match any known type.", type);
return 0;
}
}

View file

@ -214,8 +214,8 @@ void Substance::Set(PropertyPair::type XY, double x0, double y0)
throw CanteraError("Substance::Set",
"Invalid vapor fraction, {}", y0);
} else if (temp >= Tcrit()) {
throw TPX_Error("Substance::Set",
"Can't set vapor fraction above the critical point");
throw CanteraError("Substance::Set",
"Can't set vapor fraction above the critical point");
} else {
set_T(temp);
update_sat();
@ -227,8 +227,8 @@ void Substance::Set(PropertyPair::type XY, double x0, double y0)
throw CanteraError("Substance::Set",
"Invalid vapor fraction, {}", y0);
} else if (x0 >= Tcrit()) {
throw TPX_Error("Substance::Set",
"Can't set vapor fraction above the critical point");
throw CanteraError("Substance::Set",
"Can't set vapor fraction above the critical point");
} else {
set_T(x0);
update_sat();

View file

@ -237,7 +237,7 @@ void DustyGasTransport::updateMultiDiffCoeffs()
int ierr = invert(m_multidiff);
if (ierr != 0) {
throw CanteraError("DustyGasTransport::updateMultiDiffCoeffs",
"invert returned ierr = "+int2str(ierr));
"invert returned ierr = {}", ierr);
}
}