Added a version of writelog which takes the log level as an argument

This commit is contained in:
Ray Speth 2012-12-30 00:17:08 +00:00
parent 48383de86e
commit 1e43e4f333
9 changed files with 46 additions and 94 deletions

View file

@ -251,6 +251,12 @@ std::string canteraRoot();
void writelog(const std::string& msg);
inline void writelog(const std::string& msg, int loglevel) {
if (loglevel > 0) {
writelog(msg);
}
}
//! Write a message to the screen.
/*!
* The string may be of any

View file

@ -235,9 +235,7 @@ void get_CTML_Tree(Cantera::XML_Node* rootPtr, const std::string& file, const in
// find the input file on the Cantera search path
std::string inname = findInputFile(file);
if (debug > 0) {
writelog("Found file: "+inname+"\n");
}
writelog("Found file: "+inname+"\n", debug);
if (inname == "") {
throw CanteraError("get_CTML_Tree", "file "+file+" not found");
@ -267,9 +265,7 @@ void get_CTML_Tree(Cantera::XML_Node* rootPtr, const std::string& file, const in
} else {
ff = inname;
}
if (debug > 0) {
writelog("Attempting to parse xml file " + ff + "\n");
}
writelog("Attempting to parse xml file " + ff + "\n", debug);
ifstream fin(ff.c_str());
if (!fin) {
throw

View file

@ -1579,9 +1579,7 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x,
nCutoff = 1.0E-9 * n_t_calc;
#ifdef DEBUG_MODE
if (ChemEquil_print_lvl > 0) {
writelog(" Lump Sum Elements Calculation: \n");
}
writelog(" Lump Sum Elements Calculation: \n", ChemEquil_print_lvl);
#endif
for (m = 0; m < m_mm; m++) {
size_t kMSp = npos;
@ -1831,9 +1829,7 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x,
err.save();
addLogEntry("estimateEP_Brinkley:Jacobian is singular.");
#ifdef DEBUG_MODE
if (ChemEquil_print_lvl > 0) {
writelog("Matrix is SINGULAR.ERROR\n");
}
writelog("Matrix is SINGULAR.ERROR\n", ChemEquil_print_lvl);
#endif
s.restoreState(state);
throw CanteraError("equilibrate:estimateEP_Brinkley()",

View file

@ -335,9 +335,7 @@ int MultiNewton::dampStep(const doublereal* x0, const doublereal* step0,
// this case, the Newton algorithm fails, so return an error
// condition.
if (fbound < 1.e-10) {
if (loglevel > 0) {
writelog("\nAt limits.\n");
}
writelog("\nAt limits.\n", loglevel);
return -3;
}
@ -434,9 +432,7 @@ int MultiNewton::solve(doublereal* x0, doublereal* x1,
// Check whether the Jacobian should be re-evaluated.
if (jac.age() > m_maxAge) {
if (loglevel > 0) {
writelog("\nMaximum Jacobian age reached ("+int2str(m_maxAge)+")\n");
}
writelog("\nMaximum Jacobian age reached ("+int2str(m_maxAge)+")\n", loglevel);
forceNewJac = true;
}
@ -491,9 +487,9 @@ int MultiNewton::solve(doublereal* x0, doublereal* x1,
break;
}
nJacReeval++;
if (loglevel > 0)
writelog("\nRe-evaluating Jacobian, since no damping "
"coefficient\ncould be found with this Jacobian.\n");
writelog("\nRe-evaluating Jacobian, since no damping "
"coefficient\ncould be found with this Jacobian.\n",
loglevel);
} else {
break;
}

View file

@ -411,11 +411,8 @@ doublereal OneDim::timeStep(int nsteps, doublereal dt, doublereal* x,
// set the Jacobian age parameter to the transient value
newton().setOptions(m_ts_jac_age);
if (loglevel > 0) {
//writelog("Begin time stepping.\n\n");
writelog("\n\n step size (s) log10(ss) \n");
writelog("===============================\n");
}
writelog("\n\n step size (s) log10(ss) \n", loglevel);
writelog("===============================\n", loglevel);
int n = 0, m;
doublereal ss;
@ -437,9 +434,7 @@ doublereal OneDim::timeStep(int nsteps, doublereal dt, doublereal* x,
// the current solution in x.
if (m >= 0) {
n += 1;
if (loglevel > 0) {
writelog("\n");
}
writelog("\n", loglevel);
copy(r, r + m_size, x);
if (m == 100) {
dt *= 1.5;
@ -453,9 +448,7 @@ doublereal OneDim::timeStep(int nsteps, doublereal dt, doublereal* x,
// No solution could be found with this time step.
// Decrease the stepsize and try again.
else {
if (loglevel > 0) {
writelog("...failure.\n");
}
writelog("...failure.\n", loglevel);
dt *= m_tfactor;
if (dt < m_tmin)
throw CanteraError("OneDim::timeStep",
@ -520,9 +513,7 @@ void OneDim::save(const std::string& fname, std::string id,
}
ct->write(s);
s.close();
if (loglevel > 0) {
writelog("Solution saved to file "+fname+" as solution "+id+".\n");
}
writelog("Solution saved to file "+fname+" as solution "+id+".\n", loglevel);
}

View file

@ -292,9 +292,7 @@ void Sim1D::solve(int loglevel, bool refine_grid)
sim1D_drawline();
}
while (!ok) {
if (loglevel > 0) {
writelog("Attempt Newton solution of steady-state problem...");
}
writelog("Attempt Newton solution of steady-state problem...", loglevel);
int status = newtonSolve(loglevel-1);
if (status == 0) {
@ -307,8 +305,7 @@ void Sim1D::solve(int loglevel, bool refine_grid)
writelog(", ");
}
}
writelog("]");
writelog(" point grid(s).\n");
writelog("] point grid(s).\n");
}
if (loglevel > 6) {
save("debug_sim1d.xml", "debug",
@ -322,19 +319,16 @@ void Sim1D::solve(int loglevel, bool refine_grid)
soln_number++;
} else {
char buf[100];
if (loglevel > 0) {
writelog(" failure. \n");
if (loglevel > 6) {
save("debug_sim1d.xml", "debug",
"After unsuccessful Newton solve");
}
if (loglevel > 7) {
saveResidual("debug_sim1d.xml", "residual",
"After unsuccessful Newton solve");
}
writelog("Take "+int2str(nsteps)+" timesteps ");
writelog(" failure. \n", loglevel);
if (loglevel > 6) {
save("debug_sim1d.xml", "debug",
"After unsuccessful Newton solve");
}
if (loglevel > 7) {
saveResidual("debug_sim1d.xml", "residual",
"After unsuccessful Newton solve");
}
writelog("Take "+int2str(nsteps)+" timesteps ", loglevel);
dt = timeStep(nsteps, dt, DATA_PTR(m_x), DATA_PTR(m_xnew),
loglevel-1);
if (loglevel > 6) {
@ -383,9 +377,7 @@ void Sim1D::solve(int loglevel, bool refine_grid)
new_points = 0;
}
} else {
if (loglevel > 0) {
writelog("grid refinement disabled.\n");
}
writelog("grid refinement disabled.\n", loglevel);
new_points = 0;
}
}
@ -454,9 +446,7 @@ int Sim1D::refine(int loglevel)
}
}
} else {
if (loglevel > 0) {
writelog(string("refine: discarding point at ")+fp2str(d.grid(m))+"\n");
}
writelog("refine: discarding point at "+fp2str(d.grid(m))+"\n", loglevel);
}
}
dsize.push_back(znew.size() - nstart);

View file

@ -1084,10 +1084,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
if (nm == "z") {
getFloatArray(fa,x,false);
np = x.size();
if (loglevel >= 2) {
writelog("Grid contains "+int2str(np)+
" points.\n");
}
writelog("Grid contains "+int2str(np)+" points.\n", loglevel >= 2);
readgrid = true;
setupGrid(np, DATA_PTR(x));
}
@ -1097,17 +1094,13 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
"domain contains no grid points.");
}
if (loglevel >= 2) {
writelog("Importing datasets:\n");
}
writelog("Importing datasets:\n", loglevel >= 2);
for (n = 0; n < nd; n++) {
const XML_Node& fa = *d[n];
nm = fa["title"];
getFloatArray(fa,x,false);
if (nm == "u") {
if (loglevel >= 2) {
writelog("axial velocity ");
}
writelog("axial velocity ", loglevel >= 2);
if (x.size() == np) {
for (j = 0; j < np; j++) {
soln[index(0,j)] = x[j];
@ -1118,9 +1111,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
} else if (nm == "z") {
; // already read grid
} else if (nm == "V") {
if (loglevel >= 2) {
writelog("radial velocity ");
}
writelog("radial velocity ", loglevel >= 2);
if (x.size() == np) {
for (j = 0; j < np; j++) {
soln[index(1,j)] = x[j];
@ -1129,9 +1120,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
goto error;
}
} else if (nm == "T") {
if (loglevel >= 2) {
writelog("temperature ");
}
writelog("temperature ", loglevel >= 2);
if (x.size() == np) {
for (j = 0; j < np; j++) {
soln[index(2,j)] = x[j];
@ -1151,9 +1140,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
goto error;
}
} else if (nm == "L") {
if (loglevel >=2) {
writelog("lambda ");
}
writelog("lambda ", loglevel >= 2);
if (x.size() == np) {
for (j = 0; j < np; j++) {
soln[index(3,j)] = x[j];
@ -1162,9 +1149,7 @@ void StFlow::restore(const XML_Node& dom, doublereal* soln, int loglevel)
goto error;
}
} else if (m_thermo->speciesIndex(nm) != npos) {
if (loglevel >=2) {
writelog(nm+" ");
}
writelog(nm+" ", loglevel >= 2);
if (x.size() == np) {
k = m_thermo->speciesIndex(nm);
did_species[k] = 1;

View file

@ -113,10 +113,8 @@ initThermo()
double s_R = s0_R - log(p/refPressure());
m_sub->setStdState(h0_RT*GasConstant*298.15/m_mw,
s_R*GasConstant/m_mw, T0, p);
if (m_verbose) {
writelog("PureFluidPhase::initThermo: initialized phase "
+id()+"\n");
}
writelog("PureFluidPhase::initThermo: initialized phase "
+id()+"\n", m_verbose);
}
void PureFluidPhase::

View file

@ -50,9 +50,7 @@ void ReactorNet::initialize()
m_nv = 0;
m_reactors.clear();
m_nreactors = 0;
if (m_verbose) {
writelog("Initializing reactor network.\n");
}
writelog("Initializing reactor network.\n", m_verbose);
if (m_nr == 0)
throw CanteraError("ReactorNet::initialize",
"no reactors in network!");
@ -179,14 +177,10 @@ void ReactorNet::addReactor(ReactorBase* r, bool iown)
m_r.push_back(r);
m_iown.push_back(iown);
m_nr++;
if (m_verbose) {
writelog("Adding reactor "+r->name()+"\n");
}
writelog("Adding reactor "+r->name()+"\n", m_verbose);
} else {
if (m_verbose) {
writelog("Not adding reactor "+r->name()+
", since type = "+int2str(r->type())+"\n");
}
writelog("Not adding reactor "+r->name()+
", since type = "+int2str(r->type())+"\n", m_verbose);
}
}