added cmd line options and write-to-files

This commit is contained in:
Yeongdo Park 2018-11-08 19:02:08 -05:00
parent d903af4d2b
commit 4ebde595d0
2 changed files with 2062 additions and 31 deletions

View file

@ -34,6 +34,10 @@ Description
#include <cantera/transport.h>
#include <cantera/IdealGasMix.h>
#include <fstream>
#include "cxxopts/cxxopts.hpp"
#include "ofFormats.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -53,6 +57,28 @@ std::string stringNASACoefs (doublereal *coef)
int main(int argc, char *argv[])
{
cxxopts::Options options("ct2foam", "Utility Converts Cantera formatted data in OpenFOAM format");
options.add_options()
("cti", "Input CTI File name", cxxopts::value<std::string>())
("reaction", "Output OpenFOAM Reaction File name", cxxopts::value<std::string>())
("thermo", "Output OpenFOAM Thermo File name", cxxopts::value<std::string>())
("h,help", "print help message")
;
cxxopts::ParseResult result = options.parse(argc, argv);
if (result["help"].as<bool>())
{
std::cout << options.help();
return 0;
}
std::ofstream fthermo(result["thermo"].as<std::string>());
std::ofstream frxn(result["reaction"].as<std::string>());
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Cantera::IdealGasMix gas_ ("gri30.cti", "gri30_mix");
@ -72,7 +98,7 @@ int main(int argc, char *argv[])
// get the NASA coefficients in array c
gas_.speciesThermo().reportParams(n, type, c, minTemp, maxTemp, refPressure);
Cantera::writelog(
fthermo<<(
fmt::format(
thermoFormat,
gas_.speciesName(n),
@ -88,18 +114,18 @@ int main(int argc, char *argv[])
}
// Write species name list
Cantera::writelog("species\n");
Cantera::writelog("{}\n", gas_.nSpecies());
Cantera::writelog("(\n");
frxn<<("species\n");
frxn<<fmt::format("{}\n", gas_.nSpecies());
frxn<<("(\n");
for (size_t n = 0; n < gas_.nSpecies(); n++)
{
Cantera::writelog("{}\n", gas_.speciesName(n));
frxn<<fmt::format("{}\n", gas_.speciesName(n));
}
Cantera::writelog(")\n");
Cantera::writelog(";\n\n");
frxn<<(")\n");
frxn<<(";\n\n");
// Write reaction list
Cantera::writelog( "reactions\n{\n");
frxn<<( "reactions\n{\n");
for (size_t k = 0; k < gas_.nReactions(); k++)
{
@ -116,19 +142,19 @@ int main(int argc, char *argv[])
double c[5] = {0};
// reaction name
Cantera::writelog( fmt::format( " un-named-reaction-{}\n", k));
Cantera::writelog( " {\n" );
frxn<<( fmt::format( " un-named-reaction-{}\n", k));
frxn<<( " {\n" );
switch (gas_.reactionType(k))
{
case Cantera::ELEMENTARY_RXN:
Cantera::writelog( fmt::format( rxnTypeFormat, irn + rate + rxn));
frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn));
Cantera::writelog( fmt::format( rxnEqnFormat,
frxn<<( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
Cantera::writelog(
frxn<<(
fmt::format(
arrheniusFormat,
std::dynamic_pointer_cast<Cantera::ElementaryReaction>(r)->rate.preExponentialFactor(),
@ -142,12 +168,12 @@ int main(int argc, char *argv[])
rate = "thirdBody" + rate;
Cantera::writelog( fmt::format( rxnTypeFormat, irn + rate + rxn));
frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn));
Cantera::writelog( fmt::format( rxnEqnFormat,
frxn<<( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
Cantera::writelog(
frxn<<(
fmt::format(
arrheniusFormat,
std::dynamic_pointer_cast<Cantera::ElementaryReaction>(r)->rate.preExponentialFactor(),
@ -156,13 +182,13 @@ int main(int argc, char *argv[])
)
);
Cantera::writelog(" coeffs \n");
frxn<<(" coeffs \n");
Cantera::writelog(fmt::format("{}\n(\n", gas_.nSpecies()));
frxn<<(fmt::format("{}\n(\n", gas_.nSpecies()));
for (size_t l = 0; l < gas_.nSpecies(); l++)
{
Cantera::writelog(
frxn<<(
fmt::format(
"({} {})\n",
gas_.speciesName(l),
@ -171,7 +197,7 @@ int main(int argc, char *argv[])
);
}
Cantera::writelog(")\n;\n");
frxn<<(")\n;\n");
break;
@ -200,12 +226,12 @@ int main(int argc, char *argv[])
break;
}
Cantera::writelog( fmt::format( rxnTypeFormat, irn + rate + rxn));
frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn));
Cantera::writelog( fmt::format( rxnEqnFormat,
frxn<<( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
Cantera::writelog(
frxn<<(
fmt::format(
falloffFormat,
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->low_rate.preExponentialFactor(),
@ -217,19 +243,19 @@ int main(int argc, char *argv[])
)
);
Cantera::writelog( ffn );
frxn<<( ffn );
Cantera::writelog( std::string() +
frxn<<( std::string() +
" thirdBodyEfficiencies\n" +
" {\n" +
" coeffs \n"
);
Cantera::writelog(fmt::format("{}\n(\n", gas_.nSpecies()));
frxn<<(fmt::format("{}\n(\n", gas_.nSpecies()));
for (size_t l = 0; l < gas_.nSpecies(); l++)
{
Cantera::writelog(
frxn<<(
fmt::format(
"({} {})\n",
gas_.speciesName(l),
@ -238,8 +264,8 @@ int main(int argc, char *argv[])
);
}
Cantera::writelog(")\n;\n");
Cantera::writelog(" }\n");
frxn<<(")\n;\n");
frxn<<(" }\n");
break;
@ -253,10 +279,10 @@ int main(int argc, char *argv[])
break;
}
Cantera::writelog( " }\n" );
frxn<<( " }\n" );
}
Cantera::writelog( "}\n");
frxn<<( "}\n");
return 0;
}

2005
cxxopts/cxxopts.hpp Normal file

File diff suppressed because it is too large Load diff