From 521c1b1f69e47415a32a803c01067b0fa422532c Mon Sep 17 00:00:00 2001 From: Yeongdo Park Date: Thu, 8 Nov 2018 23:07:16 -0500 Subject: [PATCH] command line option logic done --- ct2foam.C | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/ct2foam.C b/ct2foam.C index c2e767d..d1c50e9 100644 --- a/ct2foam.C +++ b/ct2foam.C @@ -59,32 +59,59 @@ int main(int argc, char *argv[]) cxxopts::Options options("ct2foam", "Utility Converts Cantera formatted data in OpenFOAM format"); + std::string scti; + std::string sgas(""); + std::string sthermo; + std::string srxn; + + std::ofstream fthermo; + std::ofstream frxn; + + options.add_options() - ("cti", "Input CTI File name", cxxopts::value()) - ("reaction", "Output OpenFOAM Reaction File name", cxxopts::value()) - ("thermo", "Output OpenFOAM Thermo File name", cxxopts::value()) + ("name", "Name of ideal gas mix in CTI file", cxxopts::value(sgas)) ("h,help", "print help message") ; + options.add_options("internal") + ("cti", "Input CTI File name", cxxopts::value(scti)) + ("reaction", "Output OpenFOAM Reaction File name", cxxopts::value(srxn)->default_value("reactions")) + ("thermo", "Output OpenFOAM Thermo File name", cxxopts::value(sthermo)->default_value("thermos")) + ("rest", "Input CTI File name", cxxopts::value>()) + ; + + options.parse_positional({"cti", "reaction", "thermo", "rest"}); + + options.positional_help("CTI [REACTION [THERMO]]"); + cxxopts::ParseResult result = options.parse(argc, argv); - if (result["help"].as()) + if (result.count("help")) { std::cout << options.help(); return 0; } - std::ofstream fthermo(result["thermo"].as()); + if (!result["cti"].count()) + { + std::cerr << "CTI file name must be provided" << std::endl << std::endl; - std::ofstream frxn(result["reaction"].as()); + std::cout << options.help(); + + return -1; + } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - Cantera::IdealGasMix gas_ ("gri30.cti", "gri30_mix"); + Cantera::IdealGasMix gas_(scti, sgas); Cantera::Transport *tr_ = Cantera::newTransportMgr("Mix", &gas_); int nCanteraSp_ = gas_.nSpecies(); + fthermo.open(sthermo); + + frxn.open(srxn); + // these constants define the location of coefficient "a6" in the // cofficient array c. The c array contains Tmid in the first // location, followed by the 7 low-temperature coefficients, then