Replace printf with writelogf in all library code

This commit is contained in:
Ray Speth 2015-09-08 17:35:34 -04:00
parent 6f4c73c9d4
commit 0b2c7b59b8
12 changed files with 392 additions and 530 deletions

View file

@ -136,17 +136,17 @@ public:
const int time_step_num,
const double* y, const double* ydot) {
int k;
printf("ResidEval::writeSolution\n");
printf(" Time = %g, ievent = %d, deltaT = %g\n", time, ievent, deltaT);
writelog("ResidEval::writeSolution\n");
writelogf(" Time = %g, ievent = %d, deltaT = %g\n", time, ievent, deltaT);
if (ydot) {
printf(" k y[] ydot[]\n");
writelogf(" k y[] ydot[]\n");
for (k = 0; k < nEquations(); k++) {
printf("%d %g %g\n", k, y[k], ydot[k]);
writelogf("%d %g %g\n", k, y[k], ydot[k]);
}
} else {
printf(" k y[]\n");
writelogf(" k y[]\n");
for (k = 0; k < nEquations(); k++) {
printf("%d %g \n", k, y[k]);
writelogf("%d %g \n", k, y[k]);
}
}
}

View file

@ -114,4 +114,3 @@ int main()
std::cout << err.what() << std::endl;
}
}

View file

@ -12,7 +12,6 @@
#include "cantera/base/ct_defs.h"
#include <stdexcept>
#include <cstdio>
#include "cantera/base/stringUtils.h"
#include "cantera/base/ctexceptions.h"
@ -46,13 +45,12 @@ void checkFinite(const double tmp)
{
if (!finite(tmp)) {
if (isnan(tmp)) {
printf("checkFinite() ERROR: we have encountered a nan!\n");
throw CanteraError("checkFinite", "found NaN");
} else if (tmp > 0) {
printf("checkFinite() ERROR: we have encountered a pos inf!\n");
throw CanteraError("checkFinite", "found +Inf");
} else {
printf("checkFinite() ERROR: we have encountered a neg inf!\n");
throw CanteraError("checkFinite", "found -Inf");
}
throw std::range_error("checkFinite()");
}
}

View file

@ -3514,9 +3514,9 @@ void VCS_SOLVE::vcs_printSpeciesChemPot(const int stateCalc) const
}
double RT = m_temperature * GasConstant;
printf(" --- CHEMICAL POT TABLE (J/kmol) Name PhID MolFR ChemoSS "
" logMF Gamma Elect extra ElectrChem\n");
printf(" ");
writelog(" --- CHEMICAL POT TABLE (J/kmol) Name PhID MolFR ChemoSS "
" logMF Gamma Elect extra ElectrChem\n");
writelog(" ");
writeline('-', 132);
for (size_t kspec = 0; kspec < m_numSpeciesTot; ++kspec) {
@ -3546,21 +3546,21 @@ void VCS_SOLVE::vcs_printSpeciesChemPot(const int stateCalc) const
double total = (m_SSfeSpecies[kspec] + log(mfValue) + elect + log(actCoeff_ptr[kspec]) + comb);
if (zeroedPhase) {
printf(" --- ** zp *** ");
writelog(" --- ** zp *** ");
} else {
printf(" --- ");
writelog(" --- ");
}
printf("%-24.24s", m_speciesName[kspec].c_str());
printf(" %-3s", int2str(iphase).c_str());
printf(" % -12.4e", mfValue);
printf(" % -12.4e", m_SSfeSpecies[kspec] * RT);
printf(" % -12.4e", log(mfValue) * RT);
printf(" % -12.4e", log(actCoeff_ptr[kspec]) * RT);
printf(" % -12.4e", elect * RT);
printf(" % -12.4e", comb * RT);
printf(" % -12.4e\n", total *RT);
writelogf("%-24.24s", m_speciesName[kspec]);
writelogf(" %3d", iphase);
writelogf(" % -12.4e", mfValue);
writelogf(" % -12.4e", m_SSfeSpecies[kspec] * RT);
writelogf(" % -12.4e", log(mfValue) * RT);
writelogf(" % -12.4e", log(actCoeff_ptr[kspec]) * RT);
writelogf(" % -12.4e", elect * RT);
writelogf(" % -12.4e", comb * RT);
writelogf(" % -12.4e\n", total *RT);
}
printf(" ");
writelog(" ");
writeline('-', 132);
}
@ -3997,9 +3997,9 @@ void VCS_SOLVE::vcs_printDeltaG(const int stateCalc)
plogf("\n");
}
printf(" --- DeltaG Table (J/kmol) Name PhID MoleNum MolFR "
writelog(" --- DeltaG Table (J/kmol) Name PhID MoleNum MolFR "
" ElectrChemStar ElectrChem DeltaGStar DeltaG(Pred) Stability\n");
printf(" ");
writelog(" ");
writeline('-', 132);
for (size_t kspec = 0; kspec < m_numSpeciesTot; kspec++) {
@ -4028,48 +4028,48 @@ void VCS_SOLVE::vcs_printDeltaG(const int stateCalc)
mfValue = Vphase->moleFraction(klocal);
}
if (zeroedPhase) {
printf(" --- ** zp *** ");
writelog(" --- ** zp *** ");
} else {
printf(" --- ");
writelog(" --- ");
}
double feFull = feSpecies[kspec];
if ((m_speciesStatus[kspec] == VCS_SPECIES_ZEROEDMS) ||
(m_speciesStatus[kspec] == VCS_SPECIES_ZEROEDPHASE)) {
feFull += log(actCoeff_ptr[kspec]) + log(mfValue);
}
printf("%-24.24s", m_speciesName[kspec].c_str());
printf(" %-3s", int2str(iphase).c_str());
writelogf("%-24.24s", m_speciesName[kspec]);
writelogf(" %3d", iphase);
if (m_speciesUnknownType[kspec] == VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
printf(" NA ");
writelog(" NA ");
} else {
printf(" % -12.4e", molNumSpecies[kspec]);
writelogf(" % -12.4e", molNumSpecies[kspec]);
}
printf(" % -12.4e", mfValue);
printf(" % -12.4e", feSpecies[kspec] * RT);
printf(" % -12.4e", feFull * RT);
writelogf(" % -12.4e", mfValue);
writelogf(" % -12.4e", feSpecies[kspec] * RT);
writelogf(" % -12.4e", feFull * RT);
if (irxn != npos) {
printf(" % -12.4e", deltaGRxn[irxn] * RT);
printf(" % -12.4e", (deltaGRxn[irxn] + feFull - feSpecies[kspec]) * RT);
writelogf(" % -12.4e", deltaGRxn[irxn] * RT);
writelogf(" % -12.4e", (deltaGRxn[irxn] + feFull - feSpecies[kspec]) * RT);
if (deltaGRxn[irxn] < 0.0) {
if (molNumSpecies[kspec] > 0.0) {
printf(" growing");
writelog(" growing");
} else {
printf(" stable");
writelog(" stable");
}
} else if (deltaGRxn[irxn] > 0.0) {
if (molNumSpecies[kspec] > 0.0) {
printf(" shrinking");
writelog(" shrinking");
} else {
printf(" unstable");
writelog(" unstable");
}
} else {
printf(" balanced");
writelog(" balanced");
}
}
printf(" \n");
writelog(" \n");
}
printf(" ");
writelog(" ");
writeline('-', 132);
}

View file

@ -278,11 +278,11 @@ void InterfaceKinetics::checkPartialEquil()
updateROP();
for (size_t i = 0; i < m_nrev; i++) {
size_t irxn = m_revindex[i];
cout << "Reaction " << reactionString(irxn)
<< " " << rmu[irxn]/thermo(0).RT() << endl;
printf("%12.6e %12.6e %12.6e %12.6e \n",
m_ropf[irxn], m_ropr[irxn], m_ropnet[irxn],
m_ropnet[irxn]/(m_ropf[irxn] + m_ropr[irxn]));
writelog("Reaction {} {}\n",
reactionString(irxn), rmu[irxn]/thermo(0).RT());
writelogf("%12.6e %12.6e %12.6e %12.6e \n",
m_ropf[irxn], m_ropr[irxn], m_ropnet[irxn],
m_ropnet[irxn]/(m_ropf[irxn] + m_ropr[irxn]));
}
}
}

View file

@ -12,8 +12,6 @@
#include "cantera/thermo/SurfPhase.h"
#include "cantera/kinetics/ImplicitSurfChem.h"
#include <cstdio>
using namespace std;
namespace Cantera
{
@ -276,8 +274,8 @@ int solveSP::solveSurfProb(int ifunc, doublereal time_scale, doublereal TKelvin,
* "nan" results from the linear solve.
*/
if (m_ioflag) {
printf("solveSurfSS: Zero pivot, assuming converged: %g (%d)\n",
resid_norm, info);
writelogf("solveSurfSS: Zero pivot, assuming converged: %g (%d)\n",
resid_norm, info);
}
for (size_t jcol = 0; jcol < m_neq; jcol++) {
m_resid[jcol] = 0.0;
@ -285,17 +283,17 @@ int solveSP::solveSurfProb(int ifunc, doublereal time_scale, doublereal TKelvin,
/* print out some helpful info */
if (m_ioflag > 1) {
printf("-----\n");
printf("solveSurfProb: iter %d t_real %g delta_t %g\n\n",
iter,t_real, 1.0/inv_t);
printf("solveSurfProb: init guess, current concentration,"
"and prod rate:\n");
writelog("-----\n");
writelogf("solveSurfProb: iter %d t_real %g delta_t %g\n\n",
iter,t_real, 1.0/inv_t);
writelog("solveSurfProb: init guess, current concentration,"
"and prod rate:\n");
for (size_t jcol = 0; jcol < m_neq; jcol++) {
printf("\t%s %g %g %g\n", int2str(jcol).c_str(),
writelog("\t%d %g %g %g\n", jcol,
m_CSolnSPInit[jcol], m_CSolnSP[jcol],
m_netProductionRatesSave[m_kinSpecIndex[jcol]]);
}
printf("-----\n");
writelog("-----\n");
}
if (do_time) {
t_real += time_scale;
@ -358,10 +356,10 @@ int solveSP::solveSurfProb(int ifunc, doublereal time_scale, doublereal TKelvin,
* recalculate sdot's at equal site fractions.
*/
if (not_converged && m_ioflag) {
printf("#$#$#$# Error in solveSP $#$#$#$ \n");
printf("Newton iter on surface species did not converge, "
"update_norm = %e \n", update_norm);
printf("Continuing anyway\n");
writelog("#$#$#$# Error in solveSP $#$#$#$ \n");
writelogf("Newton iter on surface species did not converge, "
"update_norm = %e \n", update_norm);
writelog("Continuing anyway\n");
}
/*
@ -773,48 +771,48 @@ void solveSP::print_header(int ioflag, int ifunc, doublereal time_scale,
int damping, doublereal reltol, doublereal abstol)
{
if (ioflag) {
printf("\n================================ SOLVESP CALL SETUP "
"========================================\n");
writelog("\n================================ SOLVESP CALL SETUP "
"========================================\n");
if (ifunc == SFLUX_INITIALIZE) {
printf("\n SOLVESP Called with Initialization turned on\n");
printf(" Time scale input = %9.3e\n", time_scale);
writelog("\n SOLVESP Called with Initialization turned on\n");
writelogf(" Time scale input = %9.3e\n", time_scale);
} else if (ifunc == SFLUX_RESIDUAL) {
printf("\n SOLVESP Called to calculate steady state residual\n");
printf(" from a good initial guess\n");
writelog("\n SOLVESP Called to calculate steady state residual\n");
writelog(" from a good initial guess\n");
} else if (ifunc == SFLUX_JACOBIAN) {
printf("\n SOLVESP Called to calculate steady state Jacobian\n");
printf(" from a good initial guess\n");
writelog("\n SOLVESP Called to calculate steady state Jacobian\n");
writelog(" from a good initial guess\n");
} else if (ifunc == SFLUX_TRANSIENT) {
printf("\n SOLVESP Called to integrate surface in time\n");
printf(" for a total of %9.3e sec\n", time_scale);
writelog("\n SOLVESP Called to integrate surface in time\n");
writelogf(" for a total of %9.3e sec\n", time_scale);
} else {
throw CanteraError("solveSP::print_header",
"Unknown ifunc flag = " + int2str(ifunc));
}
if (m_bulkFunc == BULK_DEPOSITION) {
printf(" The composition of the Bulk Phases will be calculated\n");
writelog(" The composition of the Bulk Phases will be calculated\n");
} else if (m_bulkFunc == BULK_ETCH) {
printf(" Bulk Phases have fixed compositions\n");
writelog(" Bulk Phases have fixed compositions\n");
} else {
throw CanteraError("solveSP::print_header",
"Unknown bulkFunc flag = " + int2str(m_bulkFunc));
}
if (damping) {
printf(" Damping is ON \n");
writelog(" Damping is ON \n");
} else {
printf(" Damping is OFF \n");
writelog(" Damping is OFF \n");
}
printf(" Reltol = %9.3e, Abstol = %9.3e\n", reltol, abstol);
writelogf(" Reltol = %9.3e, Abstol = %9.3e\n", reltol, abstol);
}
if (ioflag == 1) {
printf("\n\n\t Iter Time Del_t Damp DelX "
" Resid Name-Time Name-Damp\n");
printf("\t -----------------------------------------------"
"------------------------------------\n");
writelog("\n\n\t Iter Time Del_t Damp DelX "
" Resid Name-Time Name-Damp\n");
writelog("\t -----------------------------------------------"
"------------------------------------\n");
}
}
@ -827,47 +825,41 @@ void solveSP::printIteration(int ioflag, doublereal damp, int label_d,
string nm;
if (ioflag == 1) {
if (final) {
printf("\tFIN%3s ", int2str(iter).c_str());
writelogf("\tFIN%3d ", iter);
} else {
printf("\t%6s ", int2str(iter).c_str());
writelogf("\t%6d ", iter);
}
if (do_time) {
printf("%9.4e %9.4e ", t_real, 1.0/inv_t);
writelogf("%9.4e %9.4e ", t_real, 1.0/inv_t);
} else {
for (i = 0; i < 22; i++) {
printf(" ");
}
writeline(' ', 22, false);
}
if (damp < 1.0) {
printf("%9.4e ", damp);
writelogf("%9.4e ", damp);
} else {
for (i = 0; i < 11; i++) {
printf(" ");
}
writeline(' ', 11, false);
}
printf("%9.4e %9.4e", update_norm, resid_norm);
writelogf("%9.4e %9.4e", update_norm, resid_norm);
if (do_time) {
k = m_kinSpecIndex[label_t];
size_t isp = m_kinObjIndex[label_t];
InterfaceKinetics* m_kin = m_objects[isp];
nm = m_kin->kineticsSpeciesName(k);
printf(" %-16s", nm.c_str());
writelog(" %-16s", nm);
} else {
for (i = 0; i < 16; i++) {
printf(" ");
}
writeline(' ', 16, false);
}
if (label_d >= 0) {
k = m_kinSpecIndex[label_d];
size_t isp = m_kinObjIndex[label_d];
InterfaceKinetics* m_kin = m_objects[isp];
nm = m_kin->kineticsSpeciesName(k);
printf(" %-16s", nm.c_str());
writelogf(" %-16s", nm);
}
if (final) {
printf(" -- success");
writelog(" -- success");
}
printf("\n");
writelog("\n");
}
} /* printIteration */

View file

@ -1107,18 +1107,18 @@ void RootFind::setDeltaXMax(doublereal deltaX)
void RootFind::printTable()
{
printf("\t----------------------------------------------------------------------------------------------------------------------------------------\n");
printf("\t RootFinder Summary table: \n");
printf("\t FTarget = %g\n", m_funcTargetValue);
printf("\t Iter | xval delX deltaXConv | slope | foundP foundN| F - F_targ deltaFConv | Reasoning\n");
printf("\t----------------------------------------------------------------------------------------------------------------------------------------\n");
writelogf("\t----------------------------------------------------------------------------------------------------------------------------------------\n");
writelogf("\t RootFinder Summary table: \n");
writelogf("\t FTarget = %g\n", m_funcTargetValue);
writelogf("\t Iter | xval delX deltaXConv | slope | foundP foundN| F - F_targ deltaFConv | Reasoning\n");
writelogf("\t----------------------------------------------------------------------------------------------------------------------------------------\n");
for (int i = 0; i < (int) rfHistory_.size(); i++) {
struct rfTable rfT = rfHistory_[i];
printf("\t %3d |%- 17.11E %- 13.7E %- 13.7E |%- 13.5E| %3d %3d | %- 12.5E %- 12.5E | %s \n",
writelogf("\t %3d |%- 17.11E %- 13.7E %- 13.7E |%- 13.5E| %3d %3d | %- 12.5E %- 12.5E | %s \n",
rfT.its, rfT.xval, rfT.delX, rfT.deltaXConverged, rfT.slope, rfT.foundPos, rfT.foundNeg, rfT.fval,
rfT.deltaFConverged, (rfT.reasoning).c_str());
rfT.deltaFConverged, rfT.reasoning);
}
printf("\t----------------------------------------------------------------------------------------------------------------------------------------\n");
writelogf("\t----------------------------------------------------------------------------------------------------------------------------------------\n");
}
}

File diff suppressed because it is too large Load diff

View file

@ -851,11 +851,11 @@ doublereal MixtureFugacityTP::calculatePsat(doublereal TKelvin, doublereal& mola
}
}
if (!foundGas || !foundLiquid) {
printf("error couldn't find a starting pressure\n");
writelog("error couldn't find a starting pressure\n");
return 0.0;
}
if (presGas != presLiquid) {
printf("error couldn't find a starting pressure\n");
writelog("error couldn't find a starting pressure\n");
return 0.0;
}

View file

@ -1234,7 +1234,6 @@ int RedlichKwongMFTP::NicholsSolve(double TKelvin, double pres, doublereal a, do
if (fabs(fabs(h) - fabs(yN)) < 1.0E-10) {
if (desc != 0.0) {
// this is for getting to other cases
printf("NicholsSolve(): numerical issues\n");
throw CanteraError("NicholsSolve()", "numerical issues");
}
desc = 0.0;

View file

@ -10,15 +10,14 @@
* U.S. Government retains certain rights in this software.
*/
#include "cantera/thermo/WaterPropsIAPWSphi.h"
#include "cantera/base/global.h"
#include <cstdio>
#include <cmath>
#include <algorithm>
namespace Cantera
{
using std::printf;
using std::sqrt;
using std::log;
using std::exp;
@ -392,12 +391,12 @@ void WaterPropsIAPWSphi::intCheck(doublereal tau, doublereal delta)
doublereal res_dt = phiR_dt();
doublereal nau_dt = phi0_dt();
std::printf("nau = %20.12e\t\tres = %20.12e\n", nau, res);
std::printf("nau_d = %20.12e\t\tres_d = %20.12e\n", nau_d, res_d);
printf("nau_dd = %20.12e\t\tres_dd = %20.12e\n", nau_dd, res_dd);
printf("nau_t = %20.12e\t\tres_t = %20.12e\n", nau_t, res_t);
printf("nau_tt = %20.12e\t\tres_tt = %20.12e\n", nau_tt, res_tt);
printf("nau_dt = %20.12e\t\tres_dt = %20.12e\n", nau_dt, res_dt);
writelogf("nau = %20.12e\t\tres = %20.12e\n", nau, res);
writelogf("nau_d = %20.12e\t\tres_d = %20.12e\n", nau_d, res_d);
writelogf("nau_dd = %20.12e\t\tres_dd = %20.12e\n", nau_dd, res_dd);
writelogf("nau_t = %20.12e\t\tres_t = %20.12e\n", nau_t, res_t);
writelogf("nau_tt = %20.12e\t\tres_tt = %20.12e\n", nau_tt, res_tt);
writelogf("nau_dt = %20.12e\t\tres_dt = %20.12e\n", nau_dt, res_dt);
}
void WaterPropsIAPWSphi::check1()
@ -406,7 +405,7 @@ void WaterPropsIAPWSphi::check1()
doublereal rho = 838.025;
doublereal tau = T_c/T;
doublereal delta = rho / Rho_c;
printf(" T = 500 K, rho = 838.025 kg m-3\n");
writelog(" T = 500 K, rho = 838.025 kg m-3\n");
intCheck(tau, delta);
}
@ -416,7 +415,7 @@ void WaterPropsIAPWSphi::check2()
doublereal rho = 358.0;
doublereal tau = T_c/T;
doublereal delta = rho / Rho_c;
printf(" T = 647 K, rho = 358.0 kg m-3\n");
writelog(" T = 647 K, rho = 358.0 kg m-3\n");
intCheck(tau, delta);
}

View file

@ -5,8 +5,6 @@
#include "cantera/transport/LiquidTransport.h"
#include "cantera/base/stringUtils.h"
#include <cstdio>
using namespace std;
namespace Cantera
@ -1109,9 +1107,7 @@ void LiquidTransport::stefan_maxwell_solve()
solve(m_A, m_B);
break;
default:
printf("unimplemented\n");
throw CanteraError("routine", "not done");
break;
}
for (size_t a = 0; a < m_nDim; a++) {