From 4dc35c6810d2bbebbeb4111318ea5bb56afecffd Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 15 Jun 2018 12:26:59 +0100 Subject: [PATCH] thermophysicalModels: Implementation of the full algebraic Jacobian including third-body and pressure dependent derivatives, and derivative of the temperature term. The complete Jacobian is more robust than the incomplete and partially approximate form used previously and improves the efficiency of the stiff ODE solvers which rely on the Jacobian. Reaction rate evaluation moved from the chemistryModel to specie library to simplfy support for alternative reaction rate expressions and associated Jacobian terms. Temperature clipping included in the Reaction class. This is inactive by default but for most cases it is advised to provide temperature limits (high and low). These are provided in the foamChemistryFile with the keywords Thigh and Tlow. When using chemkinToFoam these values are set to the limits of the Janaf thermodynamic data. With the new Jacobian this temperature clipping has proved very beneficial for stability and for some cases essential. Improvement of the TDAC MRU list better integrated in add and grow functions. To get the most out of this significant development it is important to re-tune the ODE integration tolerances, in particular the absTol in the odeCoeffs sub-dictionary of the chemistryProperties dictionary: odeCoeffs { solver seulex; absTol 1e-12; relTol 0.01; } Typically absTol can now be set to 1e-8 and relTol to 0.1 except for ignition time problems, and with theses settings the integration is still robust but for many cases a lot faster than previously. Code development and integration undertaken by Francesco Contino Henry G. Weller, CFD Direct --- .../chemkinToFoam/chemkinToFoam.C | 18 +- .../StandardChemistryModel.C | 319 +++----------- .../StandardChemistryModel.H | 20 +- .../TDACChemistryModel/TDACChemistryModel.C | 271 +++++------- .../TDACChemistryModel/TDACChemistryModel.H | 12 +- .../TDACChemistryModel/tabulation/ISAT/ISAT.C | 84 ++-- .../radiationCoupledBase.C | 21 +- .../chemkinReader/chemkinLexer.L | 12 + .../chemkinReader/chemkinReader.C | 20 +- .../Reactions/solidReaction/solidReaction.H | 31 +- .../solidArrheniusReactionRate.H | 33 +- .../solidArrheniusReactionRateI.H | 52 ++- .../IrreversibleReaction.C | 156 ++++++- .../IrreversibleReaction.H | 70 ++- .../NonEquilibriumReversibleReaction.C | 113 ++++- .../NonEquilibriumReversibleReaction.H | 47 +- .../reaction/Reactions/Reaction/Reaction.C | 417 +++++++++++++++++- .../reaction/Reactions/Reaction/Reaction.H | 161 ++++++- .../reaction/Reactions/Reaction/ReactionI.H | 21 + .../Reactions/ReactionList/ReactionList.C | 9 +- .../Reactions/ReactionProxy/ReactionProxy.C | 207 +++++++++ .../Reactions/ReactionProxy/ReactionProxy.H | 189 ++++++++ .../ReversibleReaction/ReversibleReaction.C | 111 +++++ .../ReversibleReaction/ReversibleReaction.H | 47 +- .../ArrheniusReactionRate.H | 33 +- .../ArrheniusReactionRateI.H | 51 +++ .../ChemicallyActivatedReactionRate.H | 37 +- .../ChemicallyActivatedReactionRateI.H | 124 +++++- .../FallOffReactionRate/FallOffReactionRate.H | 35 +- .../FallOffReactionRateI.H | 113 ++++- .../JanevReactionRate/JanevReactionRate.H | 31 +- .../JanevReactionRate/JanevReactionRateI.H | 71 ++- .../LandauTellerReactionRate.H | 31 +- .../LandauTellerReactionRateI.H | 77 +++- .../LangmuirHinshelwoodReactionRate.H | 31 +- .../LangmuirHinshelwoodReactionRateI.H | 73 ++- .../LindemannFallOffFunction.H | 18 +- .../LindemannFallOffFunctionI.H | 26 +- .../SRIFallOffFunction/SRIFallOffFunction.H | 18 +- .../SRIFallOffFunction/SRIFallOffFunctionI.H | 39 +- .../TroeFallOffFunction/TroeFallOffFunction.H | 18 +- .../TroeFallOffFunctionI.H | 97 +++- .../infiniteReactionRate.H | 31 +- .../infiniteReactionRateI.H | 40 +- .../powerSeries/powerSeriesReactionRate.H | 31 +- .../powerSeries/powerSeriesReactionRateI.H | 60 ++- .../thirdBodyArrheniusReactionRate.H | 33 ++ .../thirdBodyArrheniusReactionRateI.H | 63 ++- .../thirdBodyEfficienciesI.H | 4 +- .../specie/thermo/eConst/eConstThermo.H | 12 +- .../specie/thermo/eConst/eConstThermoI.H | 22 + .../specie/thermo/hConst/hConstThermo.H | 11 +- .../specie/thermo/hConst/hConstThermoI.H | 20 + .../thermo/hPolynomial/hPolynomialThermo.H | 11 +- .../thermo/hPolynomial/hPolynomialThermoI.H | 30 ++ .../specie/thermo/hPower/hPowerThermo.H | 11 +- .../specie/thermo/hPower/hPowerThermoI.H | 24 + .../specie/thermo/hRefConst/hRefConstThermo.H | 11 +- .../thermo/hRefConst/hRefConstThermoI.H | 20 + .../specie/thermo/janaf/janafThermo.H | 11 +- .../specie/thermo/janaf/janafThermoI.H | 25 ++ .../specie/thermo/thermo/thermo.H | 13 +- .../specie/thermo/thermo/thermoI.H | 29 ++ .../nc7h16/constant/chemistryProperties | 2 +- .../constant/panelRegion/chemistryProperties | 2 +- .../DLR_A_LTS/constant/chemistryProperties | 19 +- .../constant/chemistryProperties.test | 142 ------ .../RAS/DLR_A_LTS/constant/reactionsGRI | 3 + .../reactingFoam/RAS/SandiaD_LTS/Allrun | 4 +- .../SandiaD_LTS/constant/chemistryProperties | 6 +- .../RAS/SandiaD_LTS/constant/reactionsGRI | 3 + .../RAS/SandiaD_LTS/system/controlDict | 8 +- .../constant/chemistryProperties | 2 +- .../constant/chemistryProperties | 2 +- .../constant/chemistryProperties | 7 +- .../constant/reactionsGRI | 3 + .../system/controlDict | 2 +- .../constant/chemistryProperties | 21 +- .../constant/reactionsGRI | 85 ++-- .../constant/chemistryProperties | 8 +- .../constant/chemistryProperties.new | 2 +- .../constant/reactionsGRI | 85 ++-- .../constant/chemistryProperties | 2 +- .../constant/chemistryProperties.gas | 2 +- 84 files changed, 3380 insertions(+), 906 deletions(-) create mode 100644 src/thermophysicalModels/specie/reaction/Reactions/ReactionProxy/ReactionProxy.C create mode 100644 src/thermophysicalModels/specie/reaction/Reactions/ReactionProxy/ReactionProxy.H delete mode 100644 tutorials/combustion/reactingFoam/RAS/DLR_A_LTS/constant/chemistryProperties.test diff --git a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C index cb219fb83..e094ee28a 100644 --- a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C +++ b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C @@ -67,15 +67,13 @@ int main(int argc, char *argv[]) chemkinReader cr(species, args[1], args[3], args[2], newFormat); - OFstream reactionsFile(args[4]); - reactionsFile - << "elements" << cr.elementNames() << token::END_STATEMENT << nl << nl; - reactionsFile - << "species" << cr.species() << token::END_STATEMENT << nl << nl; + reactionsFile.writeKeyword("elements") + << cr.elementNames() << token::END_STATEMENT << nl << nl; + reactionsFile.writeKeyword("species") + << cr.species() << token::END_STATEMENT << nl << nl; cr.reactions().write(reactionsFile); - // Temporary hack to splice the specie composition data into the thermo file // pending complete integration into the thermodynamics structure @@ -103,6 +101,14 @@ int main(int argc, char *argv[]) thermoDict.write(OFstream(args[5])(), false); + reactionsFile << nl; + + reactionsFile.writeKeyword("Tlow") + << Reaction::TlowDefault + << token::END_STATEMENT << nl; + reactionsFile.writeKeyword("Thigh") + << Reaction::ThighDefault + << token::END_STATEMENT << nl << nl; Info<< "End\n" << endl; diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/StandardChemistryModel/StandardChemistryModel.C b/src/thermophysicalModels/chemistryModel/chemistryModel/StandardChemistryModel/StandardChemistryModel.C index ad2c75577..adc979f62 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/StandardChemistryModel/StandardChemistryModel.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/StandardChemistryModel/StandardChemistryModel.C @@ -56,7 +56,7 @@ Foam::StandardChemistryModel::StandardChemistryModel BasicChemistryModel::template lookupOrDefault ( "Treact", - 0.0 + 0 ) ), RR_(nSpecie_), @@ -80,7 +80,7 @@ Foam::StandardChemistryModel::StandardChemistryModel IOobject::NO_WRITE ), thermo.p().mesh(), - dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0.0) + dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0) ) ); } @@ -109,8 +109,6 @@ void Foam::StandardChemistryModel::omega scalarField& dcdt ) const { - scalar pf, cf, pr, cr; - label lRef, rRef; dcdt = Zero; @@ -118,24 +116,7 @@ void Foam::StandardChemistryModel::omega { const Reaction& R = reactions_[i]; - const scalar omegai = omega - ( - R, c, T, p, pf, cf, lRef, pr, cr, rRef - ); - - forAll(R.lhs(), s) - { - const label si = R.lhs()[s].index; - const scalar sl = R.lhs()[s].stoichCoeff; - dcdt[si] -= sl*omegai; - } - - forAll(R.rhs(), s) - { - const label si = R.rhs()[s].index; - const scalar sr = R.rhs()[s].stoichCoeff; - dcdt[si] += sr*omegai; - } + R.omega(p, T, c, dcdt); } } @@ -156,123 +137,11 @@ Foam::scalar Foam::StandardChemistryModel::omegaI ) const { const Reaction& R = reactions_[index]; - scalar w = omega(R, c, T, p, pf, cf, lRef, pr, cr, rRef); + scalar w = R.omega(p, T, c, pf, cf, lRef, pr, cr, rRef); return(w); } -template -Foam::scalar Foam::StandardChemistryModel::omega -( - const Reaction& R, - const scalarField& c, - const scalar T, - const scalar p, - scalar& pf, - scalar& cf, - label& lRef, - scalar& pr, - scalar& cr, - label& rRef -) const -{ - const scalar kf = R.kf(p, T, c); - const scalar kr = R.kr(kf, p, T, c); - - pf = 1.0; - pr = 1.0; - - const label Nl = R.lhs().size(); - const label Nr = R.rhs().size(); - - label slRef = 0; - lRef = R.lhs()[slRef].index; - - pf = kf; - for (label s = 1; s < Nl; s++) - { - const label si = R.lhs()[s].index; - - if (c[si] < c[lRef]) - { - const scalar exp = R.lhs()[slRef].exponent; - pf *= pow(max(c[lRef], 0.0), exp); - lRef = si; - slRef = s; - } - else - { - const scalar exp = R.lhs()[s].exponent; - pf *= pow(max(c[si], 0.0), exp); - } - } - cf = max(c[lRef], 0.0); - - { - const scalar exp = R.lhs()[slRef].exponent; - if (exp < 1.0) - { - if (cf > small) - { - pf *= pow(cf, exp - 1.0); - } - else - { - pf = 0.0; - } - } - else - { - pf *= pow(cf, exp - 1.0); - } - } - - label srRef = 0; - rRef = R.rhs()[srRef].index; - - // Find the matrix element and element position for the rhs - pr = kr; - for (label s = 1; s < Nr; s++) - { - const label si = R.rhs()[s].index; - if (c[si] < c[rRef]) - { - const scalar exp = R.rhs()[srRef].exponent; - pr *= pow(max(c[rRef], 0.0), exp); - rRef = si; - srRef = s; - } - else - { - const scalar exp = R.rhs()[s].exponent; - pr *= pow(max(c[si], 0.0), exp); - } - } - cr = max(c[rRef], 0.0); - - { - const scalar exp = R.rhs()[srRef].exponent; - if (exp < 1.0) - { - if (cr > small) - { - pr *= pow(cr, exp - 1.0); - } - else - { - pr = 0.0; - } - } - else - { - pr *= pow(cr, exp - 1.0); - } - } - - return pf*cf - pr*cr; -} - - template void Foam::StandardChemistryModel::derivatives ( @@ -286,29 +155,29 @@ void Foam::StandardChemistryModel::derivatives forAll(c_, i) { - c_[i] = max(c[i], 0.0); + c_[i] = max(c[i], 0); } omega(c_, T, p, dcdt); // Constant pressure // dT/dt = ... - scalar rho = 0.0; - scalar cSum = 0.0; + scalar rho = 0; + scalar cSum = 0; for (label i = 0; i < nSpecie_; i++) { const scalar W = specieThermo_[i].W(); cSum += c_[i]; rho += W*c_[i]; } - scalar cp = 0.0; + scalar cp = 0; for (label i=0; i::derivatives dcdt[nSpecie_] = -dT; // dp/dt = ... - dcdt[nSpecie_ + 1] = 0.0; + dcdt[nSpecie_ + 1] = 0; } @@ -329,7 +198,7 @@ void Foam::StandardChemistryModel::jacobian const scalar t, const scalarField& c, scalarField& dcdt, - scalarSquareMatrix& dfdc + scalarSquareMatrix& J ) const { const scalar T = c[nSpecie_]; @@ -337,131 +206,67 @@ void Foam::StandardChemistryModel::jacobian forAll(c_, i) { - c_[i] = max(c[i], 0.0); + c_[i] = max(c[i], 0); } - dfdc = Zero; - - // Length of the first argument must be nSpecie_ - omega(c_, T, p, dcdt); + J = Zero; + dcdt = Zero; + // To compute the species derivatives of the temperature term, + // the enthalpies of the individual species is needed + scalarField hi(nSpecie_); + scalarField cpi(nSpecie_); + for (label i = 0; i < nSpecie_; i++) + { + hi[i] = specieThermo_[i].ha(p, T); + cpi[i] = specieThermo_[i].cp(p, T); + } + scalar omegaI = 0; + List