Compare commits

...
Sign in to create a new pull request.

3 commits

2 changed files with 99 additions and 40 deletions

129
ct2foam.C
View file

@ -33,6 +33,7 @@ Description
#include <cantera/transport.h>
#include <cantera/IdealGasMix.h>
#include <cantera/thermo/speciesThermoTypes.h>
#include <fstream>
@ -58,7 +59,7 @@ std::string stringNASACoefs (doublereal *coef)
void calculateSutherland (Cantera::IdealGasMix *gas_, doublereal As[], doublereal C[])
{
Cantera::Transport *tr_ = Cantera::newTransportMgr("Mix", gas_);
std::shared_ptr<Cantera::Transport> tr_ ( Cantera::newTransportMgr("Mix", gas_) );
doublereal mu0[gas_->nSpecies()];
doublereal muRatio[gas_->nSpecies()];
@ -116,11 +117,63 @@ void calculateSutherland (Cantera::IdealGasMix *gas_, doublereal As[], doublerea
As[j] = mu0[j] * (T0 + C[j]) / pow(T0, 3./2.);
}
delete tr_;
return ;
}
std::string ofReactionString (const std::shared_ptr<Cantera::Reaction> r)
{
std::ostringstream reaction;
for (auto iter = r->reactants.begin(); iter != r->reactants.end(); ++iter)
{
if (iter != r->reactants.begin())
{
reaction << " + ";
}
if (iter->second != 1.0)
{
reaction << iter->second;
}
reaction << iter->first;
if (iter->second != r->orders[iter->first] && r->orders[iter->first] != 0.0 )
{
reaction << "^" << r->orders[iter->first];
}
}
reaction << " = ";
for (Cantera::Composition::iterator iter = r->products.begin(); iter != r->products.end(); ++iter)
{
if (iter != r->products.begin())
{
reaction << " + ";
}
if (iter->second != 1.0)
{
reaction << iter->second;
}
reaction << iter->first;
if (iter->second != r->orders[iter->first] && r->orders[iter->first] != 0.0)
{
reaction << "^" << r->orders[iter->first];
}
}
return reaction.str();
}
bool is_file_exist(const std::string &fileName)
{
std::ifstream infile(fileName);
return infile.good();
}
int main(int argc, char *argv[])
{
@ -134,9 +187,9 @@ int main(int argc, char *argv[])
std::ofstream fthermo;
std::ofstream frxn;
options.add_options()
("name", "Name of ideal gas mix in CTI file", cxxopts::value(sgas))
("w,overwrite", "Overwrite exsisting files")
("h,help", "print help message")
;
@ -173,9 +226,26 @@ int main(int argc, char *argv[])
Cantera::IdealGasMix gas_(scti, sgas);
fthermo.open(sthermo);
bool overwrite = result["overwrite"].as<bool>();
if (is_file_exist(sthermo) && (!overwrite))
{
throw std::system_error(EEXIST, std::system_category(), sthermo);
}
else
{
fthermo.open(sthermo);
}
if (is_file_exist(srxn) && (!overwrite))
{
throw std::system_error(EEXIST, std::system_category(), srxn);
}
else
{
frxn.open(srxn);
}
frxn.open(srxn);
// Thermo Part =============================================================
@ -185,17 +255,6 @@ int main(int argc, char *argv[])
calculateSutherland (&gas_, As, C);
for (size_t n = 0; n < gas_.nSpecies(); n++)
{
std::cout << As[n] << std::endl;
}
std::cout << std::endl;
for (size_t n = 0; n < gas_.nSpecies(); n++)
{
std::cout << C[n] << std::endl;
}
// these constants define the location of coefficient "a6" in the
// cofficient array c. The c array contains Tmid in the first
@ -208,7 +267,14 @@ int main(int argc, char *argv[])
doublereal minTemp, maxTemp, refPressure;
// get the NASA coefficients in array c
gas_.speciesThermo().reportParams(n, type, c, minTemp, maxTemp, refPressure);
switch(gas_.speciesThermo().reportType(n))
{
case NASA2:
gas_.speciesThermo().reportParams(n, type, c, minTemp, maxTemp, refPressure);
break;
default:
throw std::domain_error(gas_.speciesName(n) + " has a non-NASA2-type thermodynamics interpolator");
}
fthermo<<(
fmt::format(
@ -270,14 +336,11 @@ int main(int argc, char *argv[])
{
case Cantera::ELEMENTARY_RXN:
frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn));
frxn<<( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
frxn<<(
fmt::format(
arrheniusFormat,
rxnTypeFormat + rxnEqnFormat + arrheniusFormat,
irn + rate + rxn,
ofReactionString(r),
std::dynamic_pointer_cast<Cantera::ElementaryReaction>(r)->rate.preExponentialFactor(),
std::dynamic_pointer_cast<Cantera::ElementaryReaction>(r)->rate.temperatureExponent(),
std::dynamic_pointer_cast<Cantera::ElementaryReaction>(r)->rate.activationEnergy_R()
@ -289,14 +352,11 @@ int main(int argc, char *argv[])
rate = "thirdBody" + rate;
frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn));
frxn<<( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
frxn<<(
fmt::format(
arrheniusFormat,
rxnTypeFormat + rxnEqnFormat + arrheniusFormat,
irn + rate + rxn,
ofReactionString(r),
std::dynamic_pointer_cast<Cantera::ElementaryReaction>(r)->rate.preExponentialFactor(),
std::dynamic_pointer_cast<Cantera::ElementaryReaction>(r)->rate.temperatureExponent(),
std::dynamic_pointer_cast<Cantera::ElementaryReaction>(r)->rate.activationEnergy_R()
@ -347,14 +407,11 @@ int main(int argc, char *argv[])
break;
}
frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn));
frxn<<( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
frxn<<(
fmt::format(
falloffFormat,
rxnTypeFormat + rxnEqnFormat + falloffFormat,
irn + rate + rxn,
ofReactionString(r),
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->low_rate.preExponentialFactor(),
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->low_rate.temperatureExponent(),
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->low_rate.activationEnergy_R(),

View file

@ -28,6 +28,12 @@ std::string thermoFormat = std::string() +
"}}\n"
;
std::string rxnTypeFormat =
" type {};\n";
std::string rxnEqnFormat =
" reaction \"{}\";\n";
std::string arrheniusFormat = std::string() +
" A {};\n" +
" beta {};\n" +
@ -80,8 +86,4 @@ std::string sriFormat = std::string() +
;
std::string rxnTypeFormat = " type {};\n";
std::string rxnEqnFormat = " reaction \"{}\";\n";
#endif