From 4582e724ee868d312573c60583194c273dc8fe02 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sat, 30 Jul 2016 17:36:16 -0400 Subject: [PATCH] Eliminate compiler warnings issued by Visual Studio 2015 --- include/cantera/thermo/ThermoPhase.h | 2 +- src/base/application.cpp | 2 +- src/equil/MultiPhase.cpp | 4 +- src/equil/vcs_rxnadj.cpp | 64 +++++++++---------- src/equil/vcs_solve_TP.cpp | 2 +- src/numerics/BandMatrix.cpp | 18 +++--- src/numerics/CVodesIntegrator.cpp | 2 +- src/oneD/Sim1D.cpp | 2 +- src/oneD/StFlow.cpp | 10 +-- src/thermo/MolalityVPSSTP.cpp | 2 +- src/thermo/MolarityIonicVPSSTP.cpp | 2 +- src/thermo/PureFluidPhase.cpp | 2 +- src/thermo/ThermoPhase.cpp | 2 +- test/general/test_matrices.cpp | 10 +-- .../cathermo/testWaterTP/testWaterSSTP.cpp | 2 +- 15 files changed, 64 insertions(+), 62 deletions(-) diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index 0a3dbc6904..e515e05164 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -175,7 +175,7 @@ class ThermoPhase : public Phase * @returns the current value of the Heat of Formation at 298K * and 1 bar */ - doublereal Hf298SS(const int k) const { + doublereal Hf298SS(const size_t k) const { return m_spthermo->reportOneHf298(k); } diff --git a/src/base/application.cpp b/src/base/application.cpp index 8b2d82c092..84f92e8b16 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -347,7 +347,7 @@ void Application::setDefaultDirectories() pythonpath += ";"; pythonpath.append(old_pythonpath); } - putenv(pythonpath.c_str()); + _putenv(pythonpath.c_str()); } #endif diff --git a/src/equil/MultiPhase.cpp b/src/equil/MultiPhase.cpp index f59a9c5f5d..88d6c21aa5 100644 --- a/src/equil/MultiPhase.cpp +++ b/src/equil/MultiPhase.cpp @@ -552,7 +552,7 @@ double MultiPhase::equilibrate_MultiPhaseEquil(int XY, doublereal err, strt = false; } - } catch (CanteraError& err) { + } catch (CanteraError&) { if (!strt) { strt = true; } else { @@ -599,7 +599,7 @@ double MultiPhase::equilibrate_MultiPhaseEquil(int XY, doublereal err, if (dta < 100.0) { strt = false; } - } catch (CanteraError& err) { + } catch (CanteraError&) { if (!strt) { strt = true; } else { diff --git a/src/equil/vcs_rxnadj.cpp b/src/equil/vcs_rxnadj.cpp index 4c25f7d06a..5b5f23d361 100644 --- a/src/equil/vcs_rxnadj.cpp +++ b/src/equil/vcs_rxnadj.cpp @@ -21,7 +21,7 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) { size_t iphDel = npos; size_t k = 0; - char ANOTE[128]; + std::string ANOTE; if (m_debug_print_lvl >= 2) { plogf(" "); for (int j = 0; j < 82; j++) { @@ -46,12 +46,12 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) // LOOP OVER THE FORMATION REACTIONS for (size_t irxn = 0; irxn < m_numRxnRdc; ++irxn) { - sprintf(ANOTE, "Normal Calc"); + ANOTE = "Normal Calc"; size_t kspec = m_indexRxnToSpecies[irxn]; if (m_speciesStatus[kspec] == VCS_SPECIES_ZEROEDPHASE) { m_deltaMolNumSpecies[kspec] = 0.0; - sprintf(ANOTE, "ZeroedPhase: Phase is artificially zeroed"); + ANOTE = "ZeroedPhase: Phase is artificially zeroed"; } else if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { if (m_molNumSpecies_old[kspec] == 0.0 && (!m_SSPhase[kspec])) { // MULTISPECIES PHASE WITH total moles equal to zero @@ -70,27 +70,26 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) m_deltaMolNumSpecies[kspec] = m_totalMolNum * VCS_SMALL_MULTIPHASE_SPECIES; if (m_speciesStatus[kspec] == VCS_SPECIES_STOICHZERO) { m_deltaMolNumSpecies[kspec] = 0.0; - sprintf(ANOTE, "MultSpec (%s): Species not born due to STOICH/PHASEPOP even though DG = %11.3E", - vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); + ANOTE = fmt::sprintf("MultSpec (%s): Species not born due to STOICH/PHASEPOP even though DG = %11.3E", + vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); } else { m_deltaMolNumSpecies[kspec] = m_totalMolNum * VCS_SMALL_MULTIPHASE_SPECIES * 10.0; - sprintf(ANOTE, "MultSpec (%s): small species born again DG = %11.3E", - vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); + ANOTE = fmt::sprintf("MultSpec (%s): small species born again DG = %11.3E", + vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); } } else { - sprintf(ANOTE, "MultSpec (%s):still dead, no phase pop, even though DG = %11.3E", - vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); + ANOTE = fmt::sprintf("MultSpec (%s):still dead, no phase pop, even though DG = %11.3E", + vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); m_deltaMolNumSpecies[kspec] = 0.0; if (Vphase->exists() > 0 && trphmoles > 0.0) { m_deltaMolNumSpecies[kspec] = m_totalMolNum * VCS_SMALL_MULTIPHASE_SPECIES * 10.; - sprintf(ANOTE, - "MultSpec (%s): birthed species because it was zero in a small existing phase with DG = %11.3E", - vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); + ANOTE = fmt::sprintf("MultSpec (%s): birthed species because it was zero in a small existing phase with DG = %11.3E", + vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); } } } else { - sprintf(ANOTE, "MultSpec (%s): still dead DG = %11.3E", vcs_speciesType_string(m_speciesStatus[kspec], 15), - m_deltaGRxn_new[irxn]); + ANOTE = fmt::sprintf("MultSpec (%s): still dead DG = %11.3E", + vcs_speciesType_string(m_speciesStatus[kspec], 15), m_deltaGRxn_new[irxn]); m_deltaMolNumSpecies[kspec] = 0.0; } } else { @@ -100,7 +99,7 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) // bother if superconvergence has already been achieved in this // mode. if (fabs(m_deltaGRxn_new[irxn]) <= m_tolmaj2) { - sprintf(ANOTE, "Skipped: superconverged DG = %11.3E", m_deltaGRxn_new[irxn]); + ANOTE = fmt::sprintf("Skipped: superconverged DG = %11.3E", m_deltaGRxn_new[irxn]); if (m_debug_print_lvl >= 2) { plogf(" --- %-12.12s", m_speciesName[kspec]); plogf(" %12.4E %12.4E %12.4E | %s\n", @@ -113,7 +112,8 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) // Don't calculate for minor or nonexistent species if their // values are to be decreasing anyway. if ((m_speciesStatus[kspec] != VCS_SPECIES_MAJOR) && (m_deltaGRxn_new[irxn] >= 0.0)) { - sprintf(ANOTE, "Skipped: IC = %3d and DG >0: %11.3E", m_speciesStatus[kspec], m_deltaGRxn_new[irxn]); + ANOTE = fmt::sprintf("Skipped: IC = %3d and DG >0: %11.3E", + m_speciesStatus[kspec], m_deltaGRxn_new[irxn]); if (m_debug_print_lvl >= 2) { plogf(" --- %-12.12s", m_speciesName[kspec]); plogf(" %12.4E %12.4E %12.4E | %s\n", @@ -148,8 +148,8 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) if (m_useActCoeffJac) { double s_old = s; s = vcs_Hessian_diag_adj(irxn, s_old); - sprintf(ANOTE, "Normal calc: diag adjusted from %g " - "to %g due to act coeff", s_old, s); + ANOTE = fmt::sprintf("Normal calc: diag adjusted from %g " + "to %g due to act coeff", s_old, s); } m_deltaMolNumSpecies[kspec] = -m_deltaGRxn_new[irxn] / s; @@ -160,14 +160,14 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) double negChangeComp = -stoicC * m_deltaMolNumSpecies[kspec]; if (negChangeComp > m_molNumSpecies_old[j]) { if (m_molNumSpecies_old[j] > 0.0) { - sprintf(ANOTE, "Delta damped from %g " - "to %g due to component %lu (%10s) going neg", m_deltaMolNumSpecies[kspec], - -m_molNumSpecies_old[j] / stoicC, j, m_speciesName[j].c_str()); + ANOTE = fmt::sprintf("Delta damped from %g " + "to %g due to component %d (%10s) going neg", m_deltaMolNumSpecies[kspec], + -m_molNumSpecies_old[j] / stoicC, j, m_speciesName[j]); m_deltaMolNumSpecies[kspec] = -m_molNumSpecies_old[j] / stoicC; } else { - sprintf(ANOTE, "Delta damped from %g " - "to %g due to component %lu (%10s) zero", m_deltaMolNumSpecies[kspec], - -m_molNumSpecies_old[j] / stoicC, j, m_speciesName[j].c_str()); + ANOTE = fmt::sprintf("Delta damped from %g " + "to %g due to component %d (%10s) zero", m_deltaMolNumSpecies[kspec], + -m_molNumSpecies_old[j] / stoicC, j, m_speciesName[j]); m_deltaMolNumSpecies[kspec] = 0.0; } } @@ -176,9 +176,9 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) // Implement a damping term that limits m_deltaMolNumSpecies // to the size of the mole number if (-m_deltaMolNumSpecies[kspec] > m_molNumSpecies_old[kspec]) { - sprintf(ANOTE, "Delta damped from %g " - "to %g due to %s going negative", m_deltaMolNumSpecies[kspec], -m_molNumSpecies_old[kspec], - m_speciesName[kspec].c_str()); + ANOTE = fmt::sprintf("Delta damped from %g " + "to %g due to %s going negative", m_deltaMolNumSpecies[kspec], -m_molNumSpecies_old[kspec], + m_speciesName[kspec]); m_deltaMolNumSpecies[kspec] = -m_molNumSpecies_old[kspec]; } } else { @@ -231,8 +231,8 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) // having all of the mole numbers of that phases. it // seems that we can suggest a zero of the species // and the code will recover. - sprintf(ANOTE, "Delta damped from %g to %g due to delete %s", m_deltaMolNumSpecies[kspec], - -m_molNumSpecies_old[kspec], m_speciesName[kspec].c_str()); + ANOTE = fmt::sprintf("Delta damped from %g to %g due to delete %s", m_deltaMolNumSpecies[kspec], + -m_molNumSpecies_old[kspec], m_speciesName[kspec]); m_deltaMolNumSpecies[kspec] = -m_molNumSpecies_old[kspec]; if (m_debug_print_lvl >= 2) { plogf(" --- %-12.12s", m_speciesName[kspec]); @@ -256,10 +256,10 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial) kSpecial = k; if (k != kspec) { - sprintf(ANOTE, "Delete component SS phase %lu named %s - SS phases only", iphDel, - m_speciesName[k].c_str()); + ANOTE = fmt::sprintf("Delete component SS phase %d named %s - SS phases only", + iphDel, m_speciesName[k]); } else { - sprintf(ANOTE, "Delete this SS phase %lu - SS components only", iphDel); + ANOTE = fmt::sprintf("Delete this SS phase %d - SS components only", iphDel); } if (m_debug_print_lvl >= 2) { plogf(" --- %-12.12s", m_speciesName[kspec]); diff --git a/src/equil/vcs_solve_TP.cpp b/src/equil/vcs_solve_TP.cpp index 92d791bfe9..93a3a85336 100644 --- a/src/equil/vcs_solve_TP.cpp +++ b/src/equil/vcs_solve_TP.cpp @@ -180,7 +180,7 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit) return -1; } solve_tp_inner(iti, it1, uptodate_minors, allMinorZeroedSpecies, - forceComponentCalc, stage, printDetails, ANOTE); + forceComponentCalc, stage, printDetails > 0, ANOTE); lec = false; } else if (stage == EQUILIB_CHECK) { // EQUILIBRIUM CHECK FOR MAJOR SPECIES diff --git a/src/numerics/BandMatrix.cpp b/src/numerics/BandMatrix.cpp index 0b4c27846e..b449d3db4c 100644 --- a/src/numerics/BandMatrix.cpp +++ b/src/numerics/BandMatrix.cpp @@ -238,10 +238,11 @@ int BandMatrix::factor() ct_dgbtrf(nRows(), nColumns(), nSubDiagonals(), nSuperDiagonals(), ludata.data(), ldim(), ipiv().data(), info); #else - long int nu = nSuperDiagonals(); - long int nl = nSubDiagonals(); - int smu = nu + nl; - info = bandGBTRF(m_lu_col_ptrs.data(), nColumns(), nu, nl, smu, m_ipiv.data()); + long int nu = static_cast(nSuperDiagonals()); + long int nl = static_cast(nSubDiagonals()); + long int smu = nu + nl; + info = bandGBTRF(m_lu_col_ptrs.data(), static_cast(nColumns()), + nu, nl, smu, m_ipiv.data()); #endif // if info = 0, LU decomp succeeded. if (info == 0) { @@ -275,11 +276,12 @@ int BandMatrix::solve(doublereal* b, size_t nrhs, size_t ldb) nSuperDiagonals(), nrhs, ludata.data(), ldim(), ipiv().data(), b, ldb, info); #else - long int nu = nSuperDiagonals(); - long int nl = nSubDiagonals(); - int smu = nu + nl; + long int nu = static_cast(nSuperDiagonals()); + long int nl = static_cast(nSubDiagonals()); + long int smu = nu + nl; double** a = m_lu_col_ptrs.data(); - bandGBTRS(a, nColumns(), smu, nl, m_ipiv.data(), b); + bandGBTRS(a, static_cast(nColumns()), smu, nl, m_ipiv.data(), + b); #endif } diff --git a/src/numerics/CVodesIntegrator.cpp b/src/numerics/CVodesIntegrator.cpp index dcc6b9a5f8..8bace1f807 100644 --- a/src/numerics/CVodesIntegrator.cpp +++ b/src/numerics/CVodesIntegrator.cpp @@ -115,7 +115,7 @@ CVodesIntegrator::~CVodesIntegrator() N_VDestroy_Serial(m_abstol); } if (m_yS) { - N_VDestroyVectorArray_Serial(m_yS, m_np); + N_VDestroyVectorArray_Serial(m_yS, static_cast(m_np)); } } diff --git a/src/oneD/Sim1D.cpp b/src/oneD/Sim1D.cpp index 34b0dc99a3..a2c4bec944 100644 --- a/src/oneD/Sim1D.cpp +++ b/src/oneD/Sim1D.cpp @@ -231,7 +231,7 @@ void Sim1D::solve(int loglevel, bool refine_grid) while (new_points > 0) { size_t istep = 0; - size_t nsteps = m_steps[istep]; + int nsteps = m_steps[istep]; bool ok = false; if (loglevel > 0) { diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index c68e85bf47..e3625f46a5 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -499,7 +499,7 @@ void StFlow::updateDiffFluxes(const doublereal* x, size_t j0, size_t j1) if (m_do_multicomponent) { for (size_t j = j0; j < j1; j++) { double dz = z(j+1) - z(j); - for (double k = 0; k < m_nsp; k++) { + for (size_t k = 0; k < m_nsp; k++) { doublereal sum = 0.0; for (size_t m = 0; m < m_nsp; m++) { sum += m_wt[m] * m_multidiff[mindex(k,m,j)] * (X(x,m,j+1)-X(x,m,j)); @@ -513,13 +513,13 @@ void StFlow::updateDiffFluxes(const doublereal* x, size_t j0, size_t j1) double wtm = m_wtm[j]; double rho = density(j); double dz = z(j+1) - z(j); - for (double k = 0; k < m_nsp; k++) { + for (size_t k = 0; k < m_nsp; k++) { m_flux(k,j) = m_wt[k]*(rho*m_diff[k+m_nsp*j]/wtm); m_flux(k,j) *= (X(x,k,j) - X(x,k,j+1))/dz; sum -= m_flux(k,j); } // correction flux to insure that \sum_k Y_k V_k = 0. - for (double k = 0; k < m_nsp; k++) { + for (size_t k = 0; k < m_nsp; k++) { m_flux(k,j) += sum*Y(x,k,j); } } @@ -704,7 +704,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel) getFloatArray(dom, x, false, "", "energy_enabled"); if (x.size() == nPoints()) { for (size_t i = 0; i < x.size(); i++) { - m_do_energy[i] = x[i]; + m_do_energy[i] = (x[i] != 0); } } else if (!x.empty()) { throw CanteraError("StFlow::restore", "energy_enabled is length {}" @@ -716,7 +716,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel) getFloatArray(dom, x, false, "", "species_enabled"); if (x.size() == m_nsp) { for (size_t i = 0; i < x.size(); i++) { - m_do_species[i] = x[i]; + m_do_species[i] = (x[i] != 0); } } else if (!x.empty()) { // This may occur when restoring from a mechanism with a different diff --git a/src/thermo/MolalityVPSSTP.cpp b/src/thermo/MolalityVPSSTP.cpp index cbadc75d88..663c9c4663 100644 --- a/src/thermo/MolalityVPSSTP.cpp +++ b/src/thermo/MolalityVPSSTP.cpp @@ -462,7 +462,7 @@ std::string MolalityVPSSTP::report(bool show_thermo, doublereal threshold) const try { b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n", cv_mass(), cv_mole()); - } catch (NotImplementedError& e) { + } catch (NotImplementedError&) { b.write(" heat capacity c_v \n"); } } diff --git a/src/thermo/MolarityIonicVPSSTP.cpp b/src/thermo/MolarityIonicVPSSTP.cpp index 3f1c7ecfff..eb8a9619e2 100644 --- a/src/thermo/MolarityIonicVPSSTP.cpp +++ b/src/thermo/MolarityIonicVPSSTP.cpp @@ -392,7 +392,7 @@ std::string MolarityIonicVPSSTP::report(bool show_thermo, doublereal threshold) try { b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n", cv_mass(), cv_mole()); - } catch (NotImplementedError& e) { + } catch (NotImplementedError&) { b.write(" heat capacity c_v \n"); } } diff --git a/src/thermo/PureFluidPhase.cpp b/src/thermo/PureFluidPhase.cpp index 728898a32c..7658d98966 100644 --- a/src/thermo/PureFluidPhase.cpp +++ b/src/thermo/PureFluidPhase.cpp @@ -417,7 +417,7 @@ std::string PureFluidPhase::report(bool show_thermo, doublereal threshold) const try { b.write(" heat capacity c_v {:12.6g} {:12.4g} J/K\n", cv_mass(), cv_mole()); - } catch (NotImplementedError& e) { + } catch (NotImplementedError&) { b.write(" heat capacity c_v \n"); } } diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index d8a681cbda..8467245320 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -948,7 +948,7 @@ std::string ThermoPhase::report(bool show_thermo, doublereal threshold) const try { b.write(" heat capacity c_v {:12.5g} {:12.4g} J/K\n", cv_mass(), cv_mole()); - } catch (NotImplementedError& err) { + } catch (NotImplementedError&) { b.write(" heat capacity c_v \n"); } } diff --git a/test/general/test_matrices.cpp b/test/general/test_matrices.cpp index c0065cc5cd..ab83854e67 100644 --- a/test/general/test_matrices.cpp +++ b/test/general/test_matrices.cpp @@ -17,13 +17,13 @@ class BandMatrixTest : public testing::Test A1.resize(6, 1, 2); // one lower, two upper A2.resize(6, 2, 1); // two lower, one upper // main diagonal - for (size_t i = 0; i < 6; i++) { + for (int i = 0; i < 6; i++) { A1(i, i) = i + 1; A2(i, i) = i + 1; } // first subdiagonal and superdiagonal - for (size_t i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) { A1(i+1, i) = 2 * i + 1; A1(i, i+1) = i * i; A2(i+1, i) = 2 * i + 1; @@ -31,9 +31,9 @@ class BandMatrixTest : public testing::Test } // second subdiagonal and superdiagonal - for (size_t i = 0; i < 4; i++) { - A1(i, i+2) = - static_cast(i + 3); - A2(i+2, i) = - static_cast(i + 1); + for (int i = 0; i < 4; i++) { + A1(i, i+2) = - i - 3; + A2(i+2, i) = - i - 1; } } diff --git a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp index 5a90178593..1f5673611e 100644 --- a/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp +++ b/test_problems/cathermo/testWaterTP/testWaterSSTP.cpp @@ -283,7 +283,7 @@ int main() Hset += deltaH; try { w->setState_HP(Hset, OneAtm); - } catch (CanteraError& err) { + } catch (CanteraError&) { printf(" %10g, -> Failed to converge, beyond the spinodal probably \n\n", Hset); break; }