Replace most uses of sprintf with cppformat
This commit is contained in:
parent
1411419b0f
commit
16143b47b6
9 changed files with 33 additions and 72 deletions
|
|
@ -77,8 +77,7 @@ namespace Cantera
|
||||||
* sets the chemical potential to a specific value in J / kmol.
|
* sets the chemical potential to a specific value in J / kmol.
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* sprintf(file_ID,"%s#Li(Fixed)", iFile);
|
* XML_Node *xm = get_XML_NameID("phase", iFile + "#Li(Fixed)", 0);
|
||||||
* XML_Node *xm = get_XML_NameID("phase", file_ID, 0);
|
|
||||||
* FixedChemPotSSTP *LiFixed = new FixedChemPotSSTP(*xm);
|
* FixedChemPotSSTP *LiFixed = new FixedChemPotSSTP(*xm);
|
||||||
// Set the chemical potential to -2.3E7 J/kmol
|
// Set the chemical potential to -2.3E7 J/kmol
|
||||||
* LiFixed->setChemicalPotential(-2.3E7.)
|
* LiFixed->setChemicalPotential(-2.3E7.)
|
||||||
|
|
@ -87,8 +86,7 @@ namespace Cantera
|
||||||
* or by the following call to importPhase():
|
* or by the following call to importPhase():
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* sprintf(file_ID,"%s#NaCl(S)", iFile);
|
* XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0);
|
||||||
* XML_Node *xm = get_XML_NameID("phase", file_ID, 0);
|
|
||||||
* FixedChemPotSSTP solid;
|
* FixedChemPotSSTP solid;
|
||||||
* importPhase(*xm, &solid);
|
* importPhase(*xm, &solid);
|
||||||
* @endcode
|
* @endcode
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,7 @@ namespace Cantera
|
||||||
* or by the following call to importPhase():
|
* or by the following call to importPhase():
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* sprintf(file_ID,"%s#MetalSHEelectrons", iFile);
|
* XML_Node *xm = get_XML_NameID("phase", iFile + "#MetalSHEelectrons", 0);
|
||||||
* XML_Node *xm = get_XML_NameID("phase", file_ID, 0);
|
|
||||||
* MetalSHEelectrons eMetal;
|
* MetalSHEelectrons eMetal;
|
||||||
* importPhase(*xm, &eMetal);
|
* importPhase(*xm, &eMetal);
|
||||||
* @endcode
|
* @endcode
|
||||||
|
|
|
||||||
|
|
@ -95,16 +95,14 @@ namespace Cantera
|
||||||
* the following code snippets:
|
* the following code snippets:
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* sprintf(file_ID,"%s#NaCl(S)", iFile);
|
* XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0);
|
||||||
* XML_Node *xm = get_XML_NameID("phase", file_ID, 0);
|
|
||||||
* StoichSubstanceSSTP *solid = new StoichSubstanceSSTP(*xm);
|
* StoichSubstanceSSTP *solid = new StoichSubstanceSSTP(*xm);
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* or by the following call to importPhase():
|
* or by the following call to importPhase():
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* sprintf(file_ID,"%s#NaCl(S)", iFile);
|
* XML_Node *xm = get_XML_NameID("phase", iFile + "#NaCl(S)", 0);
|
||||||
* XML_Node *xm = get_XML_NameID("phase", file_ID, 0);
|
|
||||||
* StoichSubstanceSSTP solid;
|
* StoichSubstanceSSTP solid;
|
||||||
* importPhase(*xm, &solid);
|
* importPhase(*xm, &solid);
|
||||||
* @endcode
|
* @endcode
|
||||||
|
|
|
||||||
|
|
@ -553,7 +553,7 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,
|
||||||
bool haveEm = s.getElementPotentials(DATA_PTR(x));
|
bool haveEm = s.getElementPotentials(DATA_PTR(x));
|
||||||
if (haveEm) {
|
if (haveEm) {
|
||||||
if (s.temperature() < 100.) {
|
if (s.temperature() < 100.) {
|
||||||
printf("we are here %g\n", s.temperature());
|
writelog("we are here {:g}\n", s.temperature());
|
||||||
}
|
}
|
||||||
for (m = 0; m < m_mm; m++) {
|
for (m = 0; m < m_mm; m++) {
|
||||||
x[m] *= 1.0 / s.RT();
|
x[m] *= 1.0 / s.RT();
|
||||||
|
|
@ -696,24 +696,19 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,
|
||||||
for (m = 0; m <= m_mm; m++) {
|
for (m = 0; m <= m_mm; m++) {
|
||||||
writelog(" [ ");
|
writelog(" [ ");
|
||||||
for (size_t n = 0; n <= m_mm; n++) {
|
for (size_t n = 0; n <= m_mm; n++) {
|
||||||
writelogf("%10.5g ", jac(m,n));
|
writelog("{:10.5g} ", jac(m,n));
|
||||||
}
|
}
|
||||||
writelog(" ]");
|
writelog(" ]");
|
||||||
char xName[32];
|
|
||||||
if (m < m_mm) {
|
if (m < m_mm) {
|
||||||
string nnn = s.elementName(m);
|
writelog("x_{:10s}", s.elementName(m));
|
||||||
sprintf(xName, "x_%-10s", nnn.c_str());
|
} else if (m_eloc == m) {
|
||||||
|
writelog("x_ELOC");
|
||||||
|
} else if (m == m_skip) {
|
||||||
|
writelog("x_YY");
|
||||||
} else {
|
} else {
|
||||||
sprintf(xName, "x_XX");
|
writelog("x_XX");
|
||||||
}
|
}
|
||||||
if (m_eloc == m) {
|
writelog(" = - ({:10.5g})\n", res_trial[m]);
|
||||||
sprintf(xName, "x_ELOC");
|
|
||||||
}
|
|
||||||
if (m == m_skip) {
|
|
||||||
sprintf(xName, "x_YY");
|
|
||||||
}
|
|
||||||
writelogf("%-12s", xName);
|
|
||||||
writelogf(" = - (%10.5g)\n", res_trial[m]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,9 +207,7 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
|
||||||
|
|
||||||
callNum++;
|
callNum++;
|
||||||
if (DEBUG_MODE_ENABLED && printLvl >= 3 && writeLogAllowed_) {
|
if (DEBUG_MODE_ENABLED && printLvl >= 3 && writeLogAllowed_) {
|
||||||
char fileName[80];
|
fp = fopen(fmt::format("RootFind_%d.log", callNum).c_str(), "w");
|
||||||
sprintf(fileName, "RootFind_%d.log", callNum);
|
|
||||||
fp = fopen(fileName, "w");
|
|
||||||
fprintf(fp, " Iter TP_its xval Func_val | Reasoning\n");
|
fprintf(fp, " Iter TP_its xval Func_val | Reasoning\n");
|
||||||
fprintf(fp, "-----------------------------------------------------"
|
fprintf(fp, "-----------------------------------------------------"
|
||||||
"-------------------------------\n");
|
"-------------------------------\n");
|
||||||
|
|
@ -382,7 +380,7 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
|
||||||
* a linear approximation from the last two points.
|
* a linear approximation from the last two points.
|
||||||
*/
|
*/
|
||||||
if (DEBUG_MODE_ENABLED && fabs(x2 - x1) < 1.0E-14) {
|
if (DEBUG_MODE_ENABLED && fabs(x2 - x1) < 1.0E-14) {
|
||||||
printf(" RootFind: we are here x2 = %g x1 = %g\n", x2, x1);
|
writelogf(" RootFind: we are here x2 = %g x1 = %g\n", x2, x1);
|
||||||
}
|
}
|
||||||
doublereal delXtmp = deltaXControlled(x2, x1);
|
doublereal delXtmp = deltaXControlled(x2, x1);
|
||||||
slope = (f2 - f1) / delXtmp;
|
slope = (f2 - f1) / delXtmp;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ ReactorNet::~ReactorNet()
|
||||||
void ReactorNet::initialize()
|
void ReactorNet::initialize()
|
||||||
{
|
{
|
||||||
size_t n, nv;
|
size_t n, nv;
|
||||||
char buf[100];
|
|
||||||
m_nv = 0;
|
m_nv = 0;
|
||||||
debuglog("Initializing reactor network.\n", m_verbose);
|
debuglog("Initializing reactor network.\n", m_verbose);
|
||||||
if (m_reactors.empty()) {
|
if (m_reactors.empty()) {
|
||||||
|
|
@ -62,12 +61,8 @@ void ReactorNet::initialize()
|
||||||
m_start.push_back(m_nv);
|
m_start.push_back(m_nv);
|
||||||
|
|
||||||
if (m_verbose) {
|
if (m_verbose) {
|
||||||
sprintf(buf,"Reactor %s: %s variables.\n",
|
writelog("Reactor {:d}: {:d} variables.\n", n, nv);
|
||||||
int2str(n).c_str(), int2str(nv).c_str());
|
writelog(" {:d} sensitivity params.\n", r.nSensParams());
|
||||||
writelog(buf);
|
|
||||||
sprintf(buf," %s sensitivity params.\n",
|
|
||||||
int2str(r.nSensParams()).c_str());
|
|
||||||
writelog(buf);
|
|
||||||
}
|
}
|
||||||
if (r.type() == FlowReactorType && m_reactors.size() > 1) {
|
if (r.type() == FlowReactorType && m_reactors.size() > 1) {
|
||||||
throw CanteraError("ReactorNet::initialize",
|
throw CanteraError("ReactorNet::initialize",
|
||||||
|
|
@ -83,10 +78,8 @@ void ReactorNet::initialize()
|
||||||
m_integ->setMaxStepSize(m_maxstep);
|
m_integ->setMaxStepSize(m_maxstep);
|
||||||
m_integ->setMaxErrTestFails(m_maxErrTestFails);
|
m_integ->setMaxErrTestFails(m_maxErrTestFails);
|
||||||
if (m_verbose) {
|
if (m_verbose) {
|
||||||
sprintf(buf, "Number of equations: %s\n", int2str(neq()).c_str());
|
writelog("Number of equations: {:d}\n", neq());
|
||||||
writelog(buf);
|
writelog("Maximum time step: {:14.6g}\n", m_maxstep);
|
||||||
sprintf(buf, "Maximum time step: %14.6g\n", m_maxstep);
|
|
||||||
writelog(buf);
|
|
||||||
}
|
}
|
||||||
m_integ->initialize(m_time, *this);
|
m_integ->initialize(m_time, *this);
|
||||||
m_integrator_init = true;
|
m_integrator_init = true;
|
||||||
|
|
|
||||||
|
|
@ -46,13 +46,10 @@ int main(int argc, char** argv)
|
||||||
HMW->getMoleFractions(mf);
|
HMW->getMoleFractions(mf);
|
||||||
string sName;
|
string sName;
|
||||||
FILE* ff;
|
FILE* ff;
|
||||||
char fname[64];
|
|
||||||
|
|
||||||
for (int jTemp = 0; jTemp < 7; jTemp++) {
|
for (int jTemp = 0; jTemp < 7; jTemp++) {
|
||||||
Temp = aTemp[jTemp];
|
Temp = aTemp[jTemp];
|
||||||
sprintf(fname, "T%3.0f.csv", Temp);
|
ff = fopen(fmt::format("T{:3.0f}.csv", Temp).c_str(), "w");
|
||||||
|
|
||||||
ff = fopen(fname, "w");
|
|
||||||
HMW->setState_TP(Temp, 1.01325E5);
|
HMW->setState_TP(Temp, 1.01325E5);
|
||||||
printf(" Temperature = %g K\n", Temp);
|
printf(" Temperature = %g K\n", Temp);
|
||||||
size_t i1 = HMW->speciesIndex("Na+");
|
size_t i1 = HMW->speciesIndex("Na+");
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do
|
||||||
{
|
{
|
||||||
double x[MSSIZE];
|
double x[MSSIZE];
|
||||||
double C[MSSIZE];
|
double C[MSSIZE];
|
||||||
char buf[256];
|
|
||||||
oooo.precision(3);
|
oooo.precision(3);
|
||||||
string gasPhaseName = "gas";
|
string gasPhaseName = "gas";
|
||||||
gasTP->getMoleFractions(x);
|
gasTP->getMoleFractions(x);
|
||||||
|
|
@ -57,10 +56,8 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do
|
||||||
size_t nspGas = gasTP->nSpecies();
|
size_t nspGas = gasTP->nSpecies();
|
||||||
for (size_t k = 0; k < nspGas; k++) {
|
for (size_t k = 0; k < nspGas; k++) {
|
||||||
kstart = iKin_ptr->kineticsSpeciesIndex(k, 0);
|
kstart = iKin_ptr->kineticsSpeciesIndex(k, 0);
|
||||||
sprintf(buf, "%4d %24s %14.3g %14.3g %14.3e\n",
|
fmt::print(oooo, "{:4d} {:>24s} {:14.3g} {:14.3g} {:14.3e}\n",
|
||||||
(int) k, gasTP->speciesName(k).c_str(),
|
k, gasTP->speciesName(k), C[k], x[k], src[kstart]);
|
||||||
C[k], x[k], src[kstart]);
|
|
||||||
oooo << buf;
|
|
||||||
sum += x[k];
|
sum += x[k];
|
||||||
}
|
}
|
||||||
oooo << "Sum of gas mole fractions= " << sum << endl;
|
oooo << "Sum of gas mole fractions= " << sum << endl;
|
||||||
|
|
@ -72,7 +69,6 @@ void printBulk(ostream& oooo,
|
||||||
{
|
{
|
||||||
double x[MSSIZE];
|
double x[MSSIZE];
|
||||||
double C[MSSIZE];
|
double C[MSSIZE];
|
||||||
char buf[256];
|
|
||||||
oooo.precision(3);
|
oooo.precision(3);
|
||||||
string bulkParticlePhaseName = bulkPhaseTP->id();
|
string bulkParticlePhaseName = bulkPhaseTP->id();
|
||||||
bulkPhaseTP->getMoleFractions(x);
|
bulkPhaseTP->getMoleFractions(x);
|
||||||
|
|
@ -95,10 +91,8 @@ void printBulk(ostream& oooo,
|
||||||
size_t nspBulk = bulkPhaseTP->nSpecies();
|
size_t nspBulk = bulkPhaseTP->nSpecies();
|
||||||
for (size_t k = 0; k < nspBulk; k++) {
|
for (size_t k = 0; k < nspBulk; k++) {
|
||||||
kstart = iKin_ptr->kineticsSpeciesIndex(k, 1);
|
kstart = iKin_ptr->kineticsSpeciesIndex(k, 1);
|
||||||
sprintf(buf, "%4d %24s %14.3g %14.3g %14.3e\n",
|
fmt::print(oooo, "{:4d} {:>24s} {:14.3g} {:14.3g} {:14.3e}\n",
|
||||||
(int) k, bulkPhaseTP->speciesName(k).c_str(),
|
k, bulkPhaseTP->speciesName(k), C[k], x[k], src[kstart]);
|
||||||
C[k], x[k], src[kstart]);
|
|
||||||
oooo << buf;
|
|
||||||
sum += x[k];
|
sum += x[k];
|
||||||
Wsum += src[kstart] * molecW[k];
|
Wsum += src[kstart] * molecW[k];
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +113,6 @@ void printSurf(ostream& oooo,
|
||||||
ThermoPhase* surfPhaseTP, InterfaceKinetics* iKin_ptr, double* src)
|
ThermoPhase* surfPhaseTP, InterfaceKinetics* iKin_ptr, double* src)
|
||||||
{
|
{
|
||||||
double x[MSSIZE];
|
double x[MSSIZE];
|
||||||
char buf[256];
|
|
||||||
string surfParticlePhaseName = surfPhaseTP->id();
|
string surfParticlePhaseName = surfPhaseTP->id();
|
||||||
surfPhaseTP->getMoleFractions(x);
|
surfPhaseTP->getMoleFractions(x);
|
||||||
size_t kstart = iKin_ptr->kineticsSpeciesIndex(0, 2);
|
size_t kstart = iKin_ptr->kineticsSpeciesIndex(0, 2);
|
||||||
|
|
@ -139,10 +132,8 @@ void printSurf(ostream& oooo,
|
||||||
if (fabs(srcK) < 1.0E-7) {
|
if (fabs(srcK) < 1.0E-7) {
|
||||||
srcK = 0.0;
|
srcK = 0.0;
|
||||||
}
|
}
|
||||||
sprintf(buf, "%4d %24s %14.3g %14.3e\n",
|
fmt::print(oooo, "{:4d} {:>24s} {:14.3g} {:14.3e}\n",
|
||||||
(int) k, surfPhaseTP->speciesName(k).c_str(),
|
k, surfPhaseTP->speciesName(k), x[k], srcK);
|
||||||
x[k], srcK);
|
|
||||||
oooo << buf;
|
|
||||||
sum += x[k];
|
sum += x[k];
|
||||||
}
|
}
|
||||||
oooo << "Sum of coverages = " << sum << endl;
|
oooo << "Sum of coverages = " << sum << endl;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do
|
||||||
{
|
{
|
||||||
double x[MSSIZE];
|
double x[MSSIZE];
|
||||||
double C[MSSIZE];
|
double C[MSSIZE];
|
||||||
char buf[256];
|
|
||||||
oooo.precision(3);
|
oooo.precision(3);
|
||||||
string gasPhaseName = "gas";
|
string gasPhaseName = "gas";
|
||||||
gasTP->getMoleFractions(x);
|
gasTP->getMoleFractions(x);
|
||||||
|
|
@ -57,10 +56,8 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do
|
||||||
size_t nspGas = gasTP->nSpecies();
|
size_t nspGas = gasTP->nSpecies();
|
||||||
for (size_t k = 0; k < nspGas; k++) {
|
for (size_t k = 0; k < nspGas; k++) {
|
||||||
kstart = iKin_ptr->kineticsSpeciesIndex(k, 0);
|
kstart = iKin_ptr->kineticsSpeciesIndex(k, 0);
|
||||||
sprintf(buf, "%4d %24s %14g %14g %14e\n",
|
fmt::print(oooo, "{:4d} {:>24s} {:14g} {:14g} {:14e}\n",
|
||||||
(int) k, gasTP->speciesName(k).c_str(),
|
k, gasTP->speciesName(k), C[k], x[k], src[kstart]);
|
||||||
C[k], x[k], src[kstart]);
|
|
||||||
oooo << buf;
|
|
||||||
sum += x[k];
|
sum += x[k];
|
||||||
}
|
}
|
||||||
oooo << "Sum of gas mole fractions= " << sum << endl;
|
oooo << "Sum of gas mole fractions= " << sum << endl;
|
||||||
|
|
@ -73,7 +70,6 @@ void printBulk(ostream& oooo,ThermoPhase* bulkPhaseTP, InterfaceKinetics* iKin_p
|
||||||
{
|
{
|
||||||
double x[MSSIZE];
|
double x[MSSIZE];
|
||||||
double C[MSSIZE];
|
double C[MSSIZE];
|
||||||
char buf[256];
|
|
||||||
oooo.precision(3);
|
oooo.precision(3);
|
||||||
string bulkParticlePhaseName = bulkPhaseTP->id();
|
string bulkParticlePhaseName = bulkPhaseTP->id();
|
||||||
bulkPhaseTP->getMoleFractions(x);
|
bulkPhaseTP->getMoleFractions(x);
|
||||||
|
|
@ -96,10 +92,8 @@ void printBulk(ostream& oooo,ThermoPhase* bulkPhaseTP, InterfaceKinetics* iKin_p
|
||||||
size_t nspBulk = bulkPhaseTP->nSpecies();
|
size_t nspBulk = bulkPhaseTP->nSpecies();
|
||||||
for (size_t k = 0; k < nspBulk; k++) {
|
for (size_t k = 0; k < nspBulk; k++) {
|
||||||
kstart = iKin_ptr->kineticsSpeciesIndex(k, 1);
|
kstart = iKin_ptr->kineticsSpeciesIndex(k, 1);
|
||||||
sprintf(buf, "%4d %24s %14g %14g %14e\n",
|
fmt::print(oooo, "{:4d} {:>24s} {:14g} {:14g} {:14e}\n",
|
||||||
(int) k, bulkPhaseTP->speciesName(k).c_str(),
|
k, bulkPhaseTP->speciesName(k), C[k], x[k], src[kstart]);
|
||||||
C[k], x[k], src[kstart]);
|
|
||||||
oooo << buf;
|
|
||||||
sum += x[k];
|
sum += x[k];
|
||||||
Wsum += src[kstart] * molecW[k];
|
Wsum += src[kstart] * molecW[k];
|
||||||
}
|
}
|
||||||
|
|
@ -140,10 +134,8 @@ void printSurf(ostream& oooo, ThermoPhase* surfPhaseTP,
|
||||||
if (fabs(srcK) < 1.0E-8) {
|
if (fabs(srcK) < 1.0E-8) {
|
||||||
srcK = 0.0;
|
srcK = 0.0;
|
||||||
}
|
}
|
||||||
sprintf(buf, "%4d %24s %14g %14e\n",
|
fmt::print(oooo, "{:4d} {:>24s} {:14g} {:14e}\n",
|
||||||
(int) k, surfPhaseTP->speciesName(k).c_str(),
|
k, surfPhaseTP->speciesName(k), x[k], srcK);
|
||||||
x[k], srcK);
|
|
||||||
oooo << buf;
|
|
||||||
sum += x[k];
|
sum += x[k];
|
||||||
}
|
}
|
||||||
oooo << "Sum of coverages = " << sum << endl;
|
oooo << "Sum of coverages = " << sum << endl;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue