OpenFOAM style reaction equation, still species order differs

This commit is contained in:
Yeongdo Park 2018-11-10 08:03:35 -05:00
parent 6e229d946b
commit e9252cb06a

View file

@ -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<Cantera::Transport> 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<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();
}
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(