Skip to content

Commit

Permalink
[Samples] Replace printf with writelog
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Oct 28, 2016
1 parent 388dbaf commit af076ba
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 53 deletions.
36 changes: 17 additions & 19 deletions samples/cxx/NASA_coeffs/NASA_coeffs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace Cantera;

void demoprog()
{
printf("\n\n**** Testing modifying NASA polynomial coefficients ****\n\n");
writelog("\n**** Testing modifying NASA polynomial coefficients ****\n");

IdealGasMix gas("h2o2.cti","ohmech");
int nsp = gas.nSpecies();
Expand All @@ -27,46 +27,44 @@ void demoprog()
// cofficient array c. The c array contains Tmid in the first
// location, followed by the 7 low-temperature coefficients, then
// the seven high-temperature ones.
const int LOW_A6 = 6;

for (n = 0; n < nsp; n++) {
printf("\n\n %s (original):", gas.speciesName(n).c_str());
writelog("\n\n {} (original):", gas.speciesName(n));

// get the NASA coefficients in array c
sp.reportParams(n, type, c, minTemp, maxTemp, refPressure);

// print the unmodified NASA coefficients
printf("\n ");
writelog("\n ");
for (j = 1; j < 8; j++) {
printf(" A%d ", j);
writelog(" A{} ", j);
}
printf("\n low:");
writelog("\n low:");
for (j = 1; j < 8; j++) {
printf(" %10.4E ", c[j]);
writelog(" {:10.4E} ", c[j]);
}

printf("\n high:");
writelog("\n high:");
for (j = 8; j < 15; j++) {
printf(" %10.4E ", c[j]);
writelog(" {:10.4E} ", c[j]);
}
printf("\n ");
writelog("\n ");

// print the modified NASA coefficients
printf("\n\n %s (modified):", gas.speciesName(n).c_str());
printf("\n ");
writelog("\n\n {} (modified):", gas.speciesName(n).c_str());
writelog("\n ");
for (j = 1; j < 8; j++) {
printf(" A%d ", j);
writelog(" A{} ", j);
}
printf("\n low:");
writelog("\n low:");
for (j = 1; j < 8; j++) {
printf(" %10.4E ", c[j]);
writelog(" {:10.4E} ", c[j]);
}

printf("\n high:");
writelog("\n high:");
for (j = 8; j < 15; j++) {
printf(" %10.4E ", c[j]);
writelog(" {:10.4E} ", c[j]);
}
printf("\n ");
writelog("\n");
}
}

Expand Down
50 changes: 25 additions & 25 deletions samples/cxx/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace Cantera;

void demoprog()
{
printf("\n\n**** C++ Test Program ****\n\n");
writelog("\n**** C++ Test Program ****\n");

IdealGasMix gas("h2o2.cti","ohmech");
double temp = 1200.0;
Expand All @@ -35,29 +35,29 @@ void demoprog()

// Thermodynamic properties

printf("\n\nInitial state:\n\n");
printf(
"Temperature: %14.5g K\n"
"Pressure: %14.5g Pa\n"
"Density: %14.5g kg/m3\n"
"Molar Enthalpy: %14.5g J/kmol\n"
"Molar Entropy: %14.5g J/kmol-K\n"
"Molar cp: %14.5g J/kmol-K\n",
writelog("\n\nInitial state:\n\n");
writelog(
"Temperature: {:14.5g} K\n"
"Pressure: {:14.5g} Pa\n"
"Density: {:14.5g} kg/m3\n"
"Molar Enthalpy: {:14.5g} J/kmol\n"
"Molar Entropy: {:14.5g} J/kmol-K\n"
"Molar cp: {:14.5g} J/kmol-K\n",
gas.temperature(), gas.pressure(), gas.density(),
gas.enthalpy_mole(), gas.entropy_mole(), gas.cp_mole());

// set the gas to the equilibrium state with the same specific
// enthalpy and pressure
gas.equilibrate("HP");

printf("\n\nEquilibrium state:\n\n");
printf(
"Temperature: %14.5g K\n"
"Pressure: %14.5g Pa\n"
"Density: %14.5g kg/m3\n"
"Molar Enthalpy: %14.5g J/kmol\n"
"Molar Entropy: %14.5g J/kmol-K\n"
"Molar cp: %14.5g J/kmol-K\n",
writelog("\n\nEquilibrium state:\n\n");
writelog(
"Temperature: {:14.5g} K\n"
"Pressure: {:14.5g} Pa\n"
"Density: {:14.5g} kg/m3\n"
"Molar Enthalpy: {:14.5g} J/kmol\n"
"Molar Entropy: {:14.5g} J/kmol-K\n"
"Molar cp: {:14.5g} J/kmol-K\n",
gas.temperature(), gas.pressure(), gas.density(),
gas.enthalpy_mole(), gas.entropy_mole(), gas.cp_mole());

Expand All @@ -76,31 +76,31 @@ void demoprog()
gas.getRevRatesOfProgress(&qr[0]);
gas.getNetRatesOfProgress(&q[0]);

printf("\n\n");
writelog("\n\n");
for (int i = 0; i < irxns; i++) {
printf("%30s %14.5g %14.5g %14.5g kmol/m3/s\n",
gas.reactionString(i).c_str(), qf[i], qr[i], q[i]);
writelog("{:30s} {:14.5g} {:14.5g} {:14.5g} kmol/m3/s\n",
gas.reactionString(i), qf[i], qr[i], q[i]);
}


// transport properties

// create a transport manager for the gas that computes
// mixture-averaged properties
std::unique_ptr<Transport> tr(newTransportMgr("Mix", &gas, 1));
std::unique_ptr<Transport> tr(newTransportMgr("Mix", &gas, 0));

// print the viscosity, thermal conductivity, and diffusion
// coefficients
printf("\n\nViscosity: %14.5g Pa-s\n", tr->viscosity());
printf("Thermal conductivity: %14.5g W/m/K\n", tr->thermalConductivity());
writelog("\n\nViscosity: {:14.5g} Pa-s\n", tr->viscosity());
writelog("Thermal conductivity: {:14.5g} W/m/K\n", tr->thermalConductivity());

int nsp = gas.nSpecies();
vector_fp diff(nsp);
tr->getMixDiffCoeffs(&diff[0]);
int k;
printf("\n\n%20s %26s\n", "Species","Diffusion Coefficient");
writelog("\n\n{:20s} {:26s}\n", "Species", "Diffusion Coefficient");
for (k = 0; k < nsp; k++) {
printf("%20s %14.5g m2/s \n", gas.speciesName(k).c_str(), diff[k]);
writelog("{:20s} {:14.5g} m2/s \n", gas.speciesName(k), diff[k]);
}
}

Expand Down
13 changes: 4 additions & 9 deletions samples/cxx/rankine/rankine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ void saveState(F& fluid, std::string name)

void printStates()
{
std::string name;
int n;
int nStates = states.size();
for (n = 0; n < nStates; n++) {
name = states[n];
printf(" %5s %10.6g %10.6g %12.6g %12.6g %5.2g \n",
name.c_str(), T[name], P[name], h[name], s[name], x[name]);
for (int n = 0; n < nStates; n++) {
std::string name = states[n];
writelog(" {:5s} {:10.6g} {:10.6g} {:12.6g} {:12.6g} {:5.2g}\n",
name, T[name], P[name], h[name], s[name], x[name]);
}
}

Expand Down Expand Up @@ -71,8 +69,6 @@ int openRankine(int np, void* p)
return 0;
}


#ifndef CXX_DEMO
int main()
{
try {
Expand All @@ -82,4 +78,3 @@ int main()
return -1;
}
}
#endif

0 comments on commit af076ba

Please sign in to comment.