From e9252cb06aaac4930c1ef54c709497d64a60c4c0 Mon Sep 17 00:00:00 2001 From: Yeongdo Park Date: Sat, 10 Nov 2018 08:03:35 -0500 Subject: [PATCH] OpenFOAM style reaction equation, still species order differs --- ct2foam.C | 71 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 20 deletions(-) diff --git a/ct2foam.C b/ct2foam.C index 9db95cb..5a8b80e 100644 --- a/ct2foam.C +++ b/ct2foam.C @@ -58,7 +58,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 tr_ ( Cantera::newTransportMgr("Mix", gas_) ); doublereal mu0[gas_->nSpecies()]; doublereal muRatio[gas_->nSpecies()]; @@ -116,11 +116,56 @@ 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 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(); +} + + int main(int argc, char *argv[]) { @@ -185,17 +230,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 @@ -272,8 +306,7 @@ int main(int argc, char *argv[]) frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn)); - frxn<<( fmt::format( rxnEqnFormat, - r->Reaction::reactantString() + " = " + r->Reaction::productString())); + frxn<<( fmt::format( rxnEqnFormat, ofReactionString(r) ) ); frxn<<( fmt::format( @@ -291,8 +324,7 @@ int main(int argc, char *argv[]) frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn)); - frxn<<( fmt::format( rxnEqnFormat, - r->Reaction::reactantString() + " = " + r->Reaction::productString())); + frxn<<( fmt::format( rxnEqnFormat, ofReactionString(r) ) ); frxn<<( fmt::format( @@ -349,8 +381,7 @@ int main(int argc, char *argv[]) frxn<<( fmt::format( rxnTypeFormat, irn + rate + rxn)); - frxn<<( fmt::format( rxnEqnFormat, - r->Reaction::reactantString() + " = " + r->Reaction::productString())); + frxn<<( fmt::format( rxnEqnFormat, ofReactionString(r) ) ); frxn<<( fmt::format(