ct2foam/ct2foam.C

209 lines
5.9 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 "fvCFD.H"
#include "psiReactionThermo.H"
#include "psiChemistryModel.H"
#include "chemistrySolver.H"
#include "OFstream.H"
#include "thermoPhysicsTypes.H"
#include "basicMultiComponentMixture.H"
#include "cellModeller.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
const scalar relTol = 10.0 / 100.;
inline scalar relError (scalar x, scalar x0)
{
return (x - x0) / x0;
}
inline bool exceedTolerence (scalar rError)
{
return rError > relTol || rError < -relTol;
}
int main(int argc, char *argv[])
{
argList::noParallel();
#define CREATE_MESH createSingleCellMesh.H
#define NO_CONTROL
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info<< "\nCreate Cantera object\n" << endl;
Cantera::IdealGasMix gas_ ("gri30.cti", "gri30_mix");
Cantera::Transport *tr_ = Cantera::newTransportMgr("Mix", &gas_);
label nCanteraSp_ = gas_.nSpecies();
Info<< "\nCreate temperature space\n" << endl;
scalar Tl = 300;
scalar Tu = 3000;
scalarField T(100, 0.0);
forAll (T, i)
{
T[i] = i * (Tu - Tl) / scalar(T.size()) + Tl;
}
/*
// initialize composition array
scalarField XY(nCanteraSp_, 0.0);
forAll(thermo.composition().species(), i)
{
XY[i] = Y[i][0];
}
Info<< "\nTemperature Loop\n" << endl;
label errorCount = 0;
label testCount = 0;
forAll(T, i)
{
// OpenFOAM diffusivity model
scalar h0 = 0.0;
forAll(Y, k)
{
h0 += XY[k]*specieData[k].Hs(p[0], T[i]);
}
thermo.he() = dimensionedScalar("h", dimEnergy/dimMass, h0);
thermo.correct();
diff.correct();
// Cantera gas transport
gas_.setState_TPY(T[i], p[0], XY.data());
scalarField Dc (composition.species().size(), 0.0);
scalarField Dij (composition.species().size()*composition.species().size(), 0.0);
const scalar relTol = 1.0e-15;
// check for singular case (Xi = 1)
label idxFracOne = -1;
scalar sumX = sum(XY);
forAll (XY, k)
{
if ((sumX-XY[k])/sumX < relTol)
{
idxFracOne = k;
break;
}
}
if (idxFracOne < 0)
{
tr_->getMixDiffCoeffsMass(Dc.data());
}
else
{
tr_->getBinaryDiffCoeffs(nCanteraSp_, Dij.data());
forAll(Dc, k)
{
Dc[k] = Dij[nCanteraSp_*idxFracOne+k];
}
}
forAll(thermo.composition().species(), k)
{
if (exceedTolerence(relError(diff.D(k)[0], Dc[k])))
{
Info << thermo.composition().species()[k] << ", T = " << T[i]
<< " relative error = " << (100. * relError(diff.D(k)[0], Dc[k])) << " %" << endl;
errorCount++;
}
testCount++;
post<< thermo.T()[0] << token::TAB
<< thermo.composition().species()[k] << token::TAB
<< diff.D(k)[0] << token::TAB
<< Dc[k] << token::TAB
<< 100*(relError(diff.D(k)[0], Dc[k])) << endl;
}
if (exceedTolerence(relError(diff.mu()[0], tr_->viscosity())))
{
Info << "mu, T = " << T[i] << " relative error = " << (100. * relError(diff.mu()[0], tr_->viscosity())) << " %"<< endl;
errorCount++;
}
testCount++;
post<< thermo.T()[0] << token::TAB
<< "mu" << token::TAB
<< diff.mu()[0] << token::TAB
<< tr_->viscosity() << token::TAB
<< 100*(relError(diff.mu()[0], tr_->viscosity())) << endl;
if (exceedTolerence(relError(diff.k()[0], tr_->thermalConductivity())))
{
Info << "k, T = " << T[i] << " relative error = " << (100. * relError(diff.k()[0], tr_->thermalConductivity())) << " %"<< endl;
errorCount++;
}
testCount++;
post<< thermo.T()[0] << token::TAB
<< "k" << token::TAB
<< diff.k()[0] << token::TAB
<< tr_->thermalConductivity() << token::TAB
<< 100*(relError(diff.k()[0], tr_->thermalConductivity())) << endl;
}
Info << errorCount << " / " << testCount << " End" << nl << endl;
if (errorCount == 0)
{
return 0;
}
else
{
return -1;
}
*/
}
// ************************************************************************* //