chemistryModel: rewrite main solver loop and update chemistrySolvers

accordingly to reuse the estimated sub-time-step more effectively
This commit is contained in:
Henry
2013-10-01 17:58:26 +01:00
parent 2db9dec815
commit 131f1daa61
19 changed files with 178 additions and 152 deletions

View File

@ -514,7 +514,7 @@ void Foam::chemistryModel<CompType, ThermoType>::jacobian
} }
// calculate the dcdT elements numerically // calculate the dcdT elements numerically
const scalar delta = 1.0e-8; const scalar delta = 1.0e-3;
const scalarField dcdT0(omega(c2, T - delta, p)); const scalarField dcdT0(omega(c2, T - delta, p));
const scalarField dcdT1(omega(c2, T + delta, p)); const scalarField dcdT1(omega(c2, T + delta, p));
@ -772,9 +772,6 @@ Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve
this->thermo().rho() this->thermo().rho()
); );
tmp<volScalarField> thc = this->thermo().hc();
const scalarField& hc = thc();
const scalarField& he = this->thermo().he();
const scalarField& T = this->thermo().T(); const scalarField& T = this->thermo().T();
const scalarField& p = this->thermo().p(); const scalarField& p = this->thermo().p();
@ -784,8 +781,7 @@ Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve
forAll(rho, celli) forAll(rho, celli)
{ {
const scalar rhoi = rho[celli]; const scalar rhoi = rho[celli];
const scalar hi = he[celli] + hc[celli]; scalar pi = p[celli];
const scalar pi = p[celli];
scalar Ti = T[celli]; scalar Ti = T[celli];
for (label i=0; i<nSpecie_; i++) for (label i=0; i<nSpecie_; i++)
@ -794,32 +790,18 @@ Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve
c0[i] = c[i]; c0[i] = c[i];
} }
// initialise timing parameters // Initialise time progress
scalar t = 0;
scalar timeLeft = deltaT[celli]; scalar timeLeft = deltaT[celli];
scalar tauC = this->deltaTChem_[celli];
scalar dt = min(timeLeft, tauC);
// calculate the chemical source terms // Calculate the chemical source terms
while (timeLeft > SMALL) while (timeLeft > SMALL)
{ {
tauC = this->solve(c, Ti, pi, t, dt); scalar dt = timeLeft;
t += dt; this->solve(c, Ti, pi, dt, this->deltaTChem_[celli]);
// update the temperature
const scalar cTot = sum(c);
ThermoType mixture((c[0]/cTot)*specieThermo_[0]);
for (label i=1; i<nSpecie_; i++)
{
mixture += (c[i]/cTot)*specieThermo_[i];
}
Ti = mixture.THa(hi, pi, Ti);
timeLeft -= dt; timeLeft -= dt;
this->deltaTChem_[celli] = tauC;
dt = max(SMALL, min(timeLeft, tauC));
} }
deltaTMin = min(tauC, deltaTMin);
deltaTMin = min(this->deltaTChem_[celli], deltaTMin);
for (label i=0; i<nSpecie_; i++) for (label i=0; i<nSpecie_; i++)
{ {
@ -857,13 +839,13 @@ Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve
template<class CompType, class ThermoType> template<class CompType, class ThermoType>
Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve void Foam::chemistryModel<CompType, ThermoType>::solve
( (
scalarField &c, scalarField &c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const ) const
{ {
notImplemented notImplemented
@ -871,14 +853,12 @@ Foam::scalar Foam::chemistryModel<CompType, ThermoType>::solve
"chemistryModel::solve" "chemistryModel::solve"
"(" "("
"scalarField&, " "scalarField&, "
"const scalar, " "scalar&, "
"const scalar, " "scalar&, "
"const scalar, " "scalar&, "
"const scalar" "scalar&"
") const" ") const"
); );
return (0);
} }

View File

@ -78,6 +78,8 @@ class chemistryModel
protected: protected:
typedef ThermoType thermoType;
// Private data // Private data
//- Reference to the field of specie mass fractions //- Reference to the field of specie mass fractions
@ -260,13 +262,13 @@ public:
scalarSquareMatrix& dfdc scalarSquareMatrix& dfdc
) const; ) const;
virtual scalar solve virtual void solve
( (
scalarField &c, scalarField &c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const; ) const;
}; };

View File

@ -38,7 +38,8 @@ Foam::EulerImplicit<ChemistryModel>::EulerImplicit
chemistrySolver<ChemistryModel>(mesh), chemistrySolver<ChemistryModel>(mesh),
coeffsDict_(this->subDict("EulerImplicitCoeffs")), coeffsDict_(this->subDict("EulerImplicitCoeffs")),
cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))), cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))),
eqRateLimiter_(coeffsDict_.lookup("equilibriumRateLimiter")) eqRateLimiter_(coeffsDict_.lookup("equilibriumRateLimiter")),
cTp_(this->nEqns())
{} {}
@ -52,17 +53,16 @@ Foam::EulerImplicit<ChemistryModel>::~EulerImplicit()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ChemistryModel> template<class ChemistryModel>
Foam::scalar Foam::EulerImplicit<ChemistryModel>::solve void Foam::EulerImplicit<ChemistryModel>::solve
( (
scalarField& c, scalarField& c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const ) const
{ {
scalar pf, cf, pr, cr; deltaT = min(deltaT, subDeltaT);
label lRef, rRef;
const label nSpecie = this->nSpecie(); const label nSpecie = this->nSpecie();
simpleMatrix<scalar> RR(nSpecie, 0, 0); simpleMatrix<scalar> RR(nSpecie, 0, 0);
@ -72,13 +72,28 @@ Foam::scalar Foam::EulerImplicit<ChemistryModel>::solve
c[i] = max(0.0, c[i]); c[i] = max(0.0, c[i]);
} }
// Calculate the absolute enthalpy
scalar cTot = sum(c);
typename ChemistryModel::thermoType mixture
(
(c[0]/cTot)*this->specieThermo_[0]
);
for (label i=1; i<nSpecie; i++)
{
mixture += (c[i]/cTot)*this->specieThermo_[i];
}
scalar ha = mixture.Ha(p, T);
for (label i=0; i<nSpecie; i++) for (label i=0; i<nSpecie; i++)
{ {
RR.source()[i] = c[i]/dt; RR.source()[i] = c[i]/deltaT;
} }
forAll(this->reactions(), i) forAll(this->reactions(), i)
{ {
scalar pf, cf, pr, cr;
label lRef, rRef;
scalar omegai = this->omegaI(i, c, T, p, pf, cf, lRef, pr, cr, rRef); scalar omegai = this->omegaI(i, c, T, p, pf, cf, lRef, pr, cr, rRef);
scalar corr = 1.0; scalar corr = 1.0;
@ -86,11 +101,11 @@ Foam::scalar Foam::EulerImplicit<ChemistryModel>::solve
{ {
if (omegai < 0.0) if (omegai < 0.0)
{ {
corr = 1.0/(1.0 + pr*dt); corr = 1.0/(1.0 + pr*deltaT);
} }
else else
{ {
corr = 1.0/(1.0 + pf*dt); corr = 1.0/(1.0 + pf*deltaT);
} }
} }
@ -100,7 +115,7 @@ Foam::scalar Foam::EulerImplicit<ChemistryModel>::solve
for (label i=0; i<nSpecie; i++) for (label i=0; i<nSpecie; i++)
{ {
RR[i][i] += 1.0/dt; RR[i][i] += 1.0/deltaT;
} }
c = RR.LUsolve(); c = RR.LUsolve();
@ -109,26 +124,35 @@ Foam::scalar Foam::EulerImplicit<ChemistryModel>::solve
c[i] = max(0.0, c[i]); c[i] = max(0.0, c[i]);
} }
// estimate the next time step // Update the temperature
cTot = sum(c);
mixture = (c[0]/cTot)*this->specieThermo_[0];
for (label i=1; i<nSpecie; i++)
{
mixture += (c[i]/cTot)*this->specieThermo_[i];
}
T = mixture.THa(ha, p, T);
// Estimate the next time step
scalar tMin = GREAT; scalar tMin = GREAT;
const label nEqns = this->nEqns(); const label nEqns = this->nEqns();
scalarField c1(nEqns, 0.0);
for (label i=0; i<nSpecie; i++) for (label i=0; i<nSpecie; i++)
{ {
c1[i] = c[i]; cTp_[i] = c[i];
} }
c1[nSpecie] = T; cTp_[nSpecie] = T;
c1[nSpecie+1] = p; cTp_[nSpecie+1] = p;
scalarField dcdt(nEqns, 0.0); scalarField dcdt(nEqns, 0.0);
this->derivatives(0.0, c1, dcdt); this->derivatives(0.0, cTp_, dcdt);
const scalar sumC = sum(c); const scalar sumC = sum(c);
for (label i=0; i<nSpecie; i++) for (label i=0; i<nSpecie; i++)
{ {
scalar d = dcdt[i]; scalar d = dcdt[i];
if (d < -SMALL) if (d < -SMALL)
{ {
tMin = min(tMin, -(c[i] + SMALL)/d); tMin = min(tMin, -(c[i] + SMALL)/d);
@ -141,7 +165,7 @@ Foam::scalar Foam::EulerImplicit<ChemistryModel>::solve
} }
} }
return cTauChem_*tMin; subDeltaT = cTauChem_*tMin;
} }

View File

@ -65,6 +65,9 @@ class EulerImplicit
//- Equilibrium rate limiter flag (on/off) //- Equilibrium rate limiter flag (on/off)
Switch eqRateLimiter_; Switch eqRateLimiter_;
// Solver data
mutable scalarField cTp_;
public: public:
@ -85,13 +88,13 @@ public:
// Member Functions // Member Functions
//- Update the concentrations and return the chemical time //- Update the concentrations and return the chemical time
virtual scalar solve virtual void solve
( (
scalarField& c, scalarField& c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const; ) const;
}; };

View File

@ -69,13 +69,13 @@ public:
// Member Functions // Member Functions
//- Update the concentrations and return the chemical time //- Update the concentrations and return the chemical time
virtual scalar solve virtual void solve
( (
scalarField &c, scalarField &c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const = 0; ) const = 0;
}; };

View File

@ -31,9 +31,9 @@ License
#include "chemistryModel.H" #include "chemistryModel.H"
#include "noChemistrySolver.H" #include "noChemistrySolver.H"
#include "sequential.H"
#include "EulerImplicit.H" #include "EulerImplicit.H"
#include "ode.H" #include "ode.H"
#include "sequential.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -48,17 +48,15 @@ Foam::noChemistrySolver<ChemistryModel>::~noChemistrySolver()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ChemistryModel> template<class ChemistryModel>
Foam::scalar Foam::noChemistrySolver<ChemistryModel>::solve void Foam::noChemistrySolver<ChemistryModel>::solve
( (
scalarField&, scalarField&,
const scalar, scalar&,
const scalar, scalar&,
const scalar, scalar&,
const scalar scalar&
) const ) const
{ {}
return GREAT;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -72,13 +72,13 @@ public:
// Member Functions // Member Functions
//- Update the concentrations and return the chemical time //- Update the concentrations and return the chemical time
virtual scalar solve virtual void solve
( (
scalarField& c, scalarField& c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const; ) const;
}; };

View File

@ -38,7 +38,8 @@ Foam::ode<ChemistryModel>::ode
coeffsDict_(this->subDict("odeCoeffs")), coeffsDict_(this->subDict("odeCoeffs")),
solverName_(coeffsDict_.lookup("solver")), solverName_(coeffsDict_.lookup("solver")),
odeSolver_(ODESolver::New(solverName_, *this)), odeSolver_(ODESolver::New(solverName_, *this)),
eps_(readScalar(coeffsDict_.lookup("eps"))) eps_(readScalar(coeffsDict_.lookup("eps"))),
cTp_(this->nEqns())
{} {}
@ -52,44 +53,41 @@ Foam::ode<ChemistryModel>::~ode()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ChemistryModel> template<class ChemistryModel>
Foam::scalar Foam::ode<ChemistryModel>::solve void Foam::ode<ChemistryModel>::solve
( (
scalarField& c, scalarField& c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const ) const
{ {
label nSpecie = this->nSpecie(); label nSpecie = this->nSpecie();
scalarField c1(this->nEqns(), 0.0);
// copy the concentration, T and P to the total solve-vector // Copy the concentration, T and P to the total solve-vector
for (label i = 0; i < nSpecie; i++) for (register int i=0; i<nSpecie; i++)
{ {
c1[i] = c[i]; cTp_[i] = c[i];
} }
c1[nSpecie] = T; cTp_[nSpecie] = T;
c1[nSpecie+1] = p; cTp_[nSpecie+1] = p;
scalar dtEst = dt;
odeSolver_->solve odeSolver_->solve
( (
*this, *this,
t0, 0,
t0 + dt, deltaT,
c1, cTp_,
eps_, eps_,
dtEst subDeltaT
); );
forAll(c, i) for (register int i=0; i<nSpecie; i++)
{ {
c[i] = max(0.0, c1[i]); c[i] = max(0.0, cTp_[i]);
} }
T = cTp_[nSpecie];
return dtEst; p = cTp_[nSpecie+1];
} }

View File

@ -62,6 +62,9 @@ class ode
scalar eps_; scalar eps_;
// Solver data
mutable scalarField cTp_;
public: public:
@ -81,13 +84,14 @@ public:
// Member Functions // Member Functions
virtual scalar solve //- Update the concentrations and return the chemical time
virtual void solve
( (
scalarField& c, scalarField& c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const; ) const;
}; };

View File

@ -51,42 +51,67 @@ Foam::sequential<ChemistryModel>::~sequential()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ChemistryModel> template<class ChemistryModel>
Foam::scalar Foam::sequential<ChemistryModel>::solve void Foam::sequential<ChemistryModel>::solve
( (
scalarField& c, scalarField& c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const ) const
{ {
scalar tChemInv = SMALL; deltaT = min(deltaT, subDeltaT);
scalar pf, cf, pb, cb; const label nSpecie = this->nSpecie();
label lRef, rRef;
// Calculate the absolute enthalpy
scalar cTot = sum(c);
typename ChemistryModel::thermoType mixture
(
(c[0]/cTot)*this->specieThermo_[0]
);
for (label i=1; i<nSpecie; i++)
{
mixture += (c[i]/cTot)*this->specieThermo_[i];
}
scalar ha = mixture.Ha(p, T);
scalar tChemInv = SMALL;
forAll(this->reactions(), i) forAll(this->reactions(), i)
{ {
scalar pf, cf, pb, cb;
label lRef, rRef;
scalar omega = this->omegaI(i, c, T, p, pf, cf, lRef, pb, cb, rRef); scalar omega = this->omegaI(i, c, T, p, pf, cf, lRef, pb, cb, rRef);
if (eqRateLimiter_) if (eqRateLimiter_)
{ {
if (omega < 0.0) if (omega < 0.0)
{ {
omega /= 1.0 + pb*dt; omega /= 1.0 + pb*deltaT;
} }
else else
{ {
omega /= 1.0 + pf*dt; omega /= 1.0 + pf*deltaT;
} }
} }
tChemInv = max(tChemInv, mag(omega)); tChemInv = max(tChemInv, mag(omega));
this->updateConcsInReactionI(i, dt, omega, p, T, c); this->updateConcsInReactionI(i, deltaT, omega, p, T, c);
} }
return cTauChem_/tChemInv; // Update the temperature
cTot = sum(c);
mixture = (c[0]/cTot)*this->specieThermo_[0];
for (label i=1; i<nSpecie; i++)
{
mixture += (c[i]/cTot)*this->specieThermo_[i];
}
T = mixture.THa(ha, p, T);
subDeltaT = cTauChem_/tChemInv;
} }

View File

@ -28,9 +28,7 @@ Description
Foam::sequential Foam::sequential
SourceFiles SourceFiles
sequentialI.H
sequential.C sequential.C
sequentialIO.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -86,13 +84,13 @@ public:
// Member Functions // Member Functions
//- Update the concentrations and return the chemical time //- Update the concentrations and return the chemical time
virtual scalar solve virtual void solve
( (
scalarField& c, scalarField& c,
const scalar T, scalar& T,
const scalar p, scalar& p,
const scalar t0, scalar& deltaT,
const scalar dt scalar& subDeltaT
) const; ) const;
}; };

View File

@ -34,8 +34,8 @@ Description
#include "noChemistrySolver.H" #include "noChemistrySolver.H"
#include "EulerImplicit.H" #include "EulerImplicit.H"
#include "ode.H"
#include "sequential.H" #include "sequential.H"
#include "ode.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -40,7 +40,6 @@ odeCoeffs
{ {
solver KRR4; solver KRR4;
eps 0.05; eps 0.05;
scale 1;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -17,7 +17,7 @@ FoamFile
chemistryType chemistryType
{ {
chemistrySolver ode; chemistrySolver EulerImplicit;
chemistryThermo psi; chemistryThermo psi;
} }
@ -27,12 +27,12 @@ initialChemicalTimeStep 1e-07;
sequentialCoeffs sequentialCoeffs
{ {
cTauChem 0.001; cTauChem 0.05;
} }
EulerImplicitCoeffs EulerImplicitCoeffs
{ {
cTauChem 0.05; cTauChem 1;
equilibriumRateLimiter off; equilibriumRateLimiter off;
} }
@ -40,7 +40,6 @@ odeCoeffs
{ {
solver KRR4; solver KRR4;
eps 0.05; eps 0.05;
scale 1;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -41,7 +41,6 @@ odeCoeffs
{ {
solver SIBS; solver SIBS;
eps 0.05; eps 0.05;
scale 1;
} }

View File

@ -41,7 +41,6 @@ odeCoeffs
{ {
solver RK; solver RK;
eps 0.05; eps 0.05;
scale 1;
} }

View File

@ -41,7 +41,6 @@ odeCoeffs
{ {
solver RK; solver RK;
eps 0.05; eps 0.05;
scale 1;
} }

View File

@ -41,7 +41,6 @@ odeCoeffs
{ {
solver RK; solver RK;
eps 0.05; eps 0.05;
scale 1;
} }