commit a731c3ad4b163df627ad7763803c287db5efdbd8 Author: Yeongdo Park Date: Tue Nov 6 15:45:28 2018 -0500 Cantera CTI To OpenFOAM reaction mechanism conversion utility, just read gri30.cti diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..170061b --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +lnInclude +/Make +!/Make/file +!/Make/option +.ycm_extra_conf.py diff --git a/Make/files b/Make/files new file mode 100644 index 0000000..e42cc17 --- /dev/null +++ b/Make/files @@ -0,0 +1,3 @@ +ct2foam.C + +EXE = $(FOAM_USER_APPBIN)/ct2foam diff --git a/Make/options b/Make/options new file mode 100644 index 0000000..d57f8a5 --- /dev/null +++ b/Make/options @@ -0,0 +1,18 @@ +EXE_INC = \ + -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ + -I$(LIB_SRC)/transportModels/compressible/lnInclude \ + -I$(LIB_SRC)/ODE/lnInclude\ + -I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude + +EXE_LIBS = \ + -lchemistryModel \ + -lfiniteVolume \ + -lmeshTools \ + -pthread \ + -lcantera \ + -lsundials_cvodes -lsundials_ida -lsundials_nvecserial \ + -llapack -lblas diff --git a/ct2foam.C b/ct2foam.C new file mode 100644 index 0000000..f03bb3e --- /dev/null +++ b/ct2foam.C @@ -0,0 +1,209 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +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 +#include + +#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; + } + + */ +} + + +// ************************************************************************* //