ct2foam/ct2foam.C
2018-11-08 14:50:34 -05:00

265 lines
9.6 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
chemFoam
Description
Solver for chemistry problems, designed for use on single cell cases to
provide comparison against other chemistry solvers, that uses a single cell
mesh, and fields created from the initial conditions.
\*---------------------------------------------------------------------------*/
#include <cantera/transport.h>
#include <cantera/IdealGasMix.h>
#include "ofFormats.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
std::string stringNASACoefs (doublereal *coef)
{
std::string arr;
for (int j = 0; j < 7; j++)
{
arr += fmt::format(" {:15.10E} ", coef[j]);
}
return arr;
}
int main(int argc, char *argv[])
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Cantera::IdealGasMix gas_ ("gri30.cti", "gri30_mix");
Cantera::Transport *tr_ = Cantera::newTransportMgr("Mix", &gas_);
int nCanteraSp_ = gas_.nSpecies();
// 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
// the seven high-temperature ones.
for (size_t n = 0; n < gas_.nSpecies(); n++)
{
int type;
doublereal c[15];
doublereal minTemp, maxTemp, refPressure;
// get the NASA coefficients in array c
gas_.speciesThermo().reportParams(n, type, c, minTemp, maxTemp, refPressure);
Cantera::writelog(
fmt::format(
thermoFormat,
gas_.speciesName(n),
gas_.molecularWeight(n),
gas_.charge(n),
minTemp,
maxTemp,
c[0],
stringNASACoefs(&c[1]),
stringNASACoefs(&c[8])
)
);
}
// Write species name list
Cantera::writelog("species\n");
Cantera::writelog("{}\n", gas_.nSpecies());
Cantera::writelog("(\n");
for (size_t n = 0; n < gas_.nSpecies(); n++)
{
Cantera::writelog("{}\n", gas_.speciesName(n));
}
Cantera::writelog(")\n");
Cantera::writelog(";\n\n");
// Write reaction list
Cantera::writelog( "reactions\n{\n");
for (size_t k = 0; k < gas_.nReactions(); k++)
{
std::shared_ptr<Cantera::Reaction> r(gas_.reaction(k));
std::string irn( r->reversible ? "reversible" : "irreversible" );
std::string rate("Arrhenius");
std::string rxn("Reaction");
std::string ffn;
double c[5] = {0};
// reaction name
Cantera::writelog( fmt::format( " un-named-reaction-{}\n", k));
Cantera::writelog( " {\n" );
switch (gas_.reactionType(k))
{
case Cantera::ELEMENTARY_RXN:
Cantera::writelog( fmt::format( rxnTypeFormat, irn + rate + rxn));
Cantera::writelog( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
Cantera::writelog(
fmt::format(
arrheniusFormat,
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()
)
);
break;
case Cantera::THREE_BODY_RXN:
rate = "thirdBody" + rate;
Cantera::writelog( fmt::format( rxnTypeFormat, irn + rate + rxn));
Cantera::writelog( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
Cantera::writelog(
fmt::format(
arrheniusFormat,
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()
)
);
Cantera::writelog(" coeffs \n");
Cantera::writelog(fmt::format("{}\n(\n", gas_.nSpecies()));
for (size_t l = 0; l < gas_.nSpecies(); l++)
{
Cantera::writelog(
fmt::format(
"({} {})\n",
gas_.speciesName(l),
std::dynamic_pointer_cast<Cantera::ThreeBodyReaction>(r)->third_body.efficiency(gas_.speciesName(l))
)
);
}
Cantera::writelog(")\n;\n");
break;
case Cantera::FALLOFF_RXN:
case Cantera::CHEMACT_RXN:
rxn = (r->reaction_type == Cantera::FALLOFF_RXN ? "FallOff" : "ChemicallyActivated") + rxn;
switch (std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->falloff->getType())
{
case Cantera::SIMPLE_FALLOFF:
rxn = "Lindemann" + rxn;
ffn = lindemannFormat;
break;
case Cantera::TROE_FALLOFF:
rxn = "Troe" + rxn;
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->falloff->getParameters(c);
ffn = fmt::format(troeFormat, c[0], c[1], c[2], c[3]);
break;
case Cantera::SRI_FALLOFF:
rxn = "SRI" + rxn;
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->falloff->getParameters(c);
ffn = fmt::format(sriFormat, c[0], c[1], c[2], c[3], c[4]);
break;
}
Cantera::writelog( fmt::format( rxnTypeFormat, irn + rate + rxn));
Cantera::writelog( fmt::format( rxnEqnFormat,
r->Reaction::reactantString() + " = " + r->Reaction::productString()));
Cantera::writelog(
fmt::format(
falloffFormat,
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(),
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->high_rate.preExponentialFactor(),
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->high_rate.temperatureExponent(),
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->high_rate.activationEnergy_R()
)
);
Cantera::writelog( ffn );
Cantera::writelog( std::string() +
" thirdBodyEfficiencies\n" +
" {\n" +
" coeffs \n"
);
Cantera::writelog(fmt::format("{}\n(\n", gas_.nSpecies()));
for (size_t l = 0; l < gas_.nSpecies(); l++)
{
Cantera::writelog(
fmt::format(
"({} {})\n",
gas_.speciesName(l),
std::dynamic_pointer_cast<Cantera::FalloffReaction>(r)->third_body.efficiency(gas_.speciesName(l))
)
);
}
Cantera::writelog(")\n;\n");
Cantera::writelog(" }\n");
break;
case Cantera::PLOG_RXN:
break;
case Cantera::CHEBYSHEV_RXN:
break;
default:
break;
}
Cantera::writelog( " }\n" );
}
Cantera::writelog( "}\n");
return 0;
}
// ************************************************************************* //