EulerImplicit.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "EulerImplicit.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "simpleMatrix.H"
00030
00031
00032
00033 template<class CompType, class ThermoType>
00034 Foam::EulerImplicit<CompType, ThermoType>::EulerImplicit
00035 (
00036 ODEChemistryModel<CompType, ThermoType>& model,
00037 const word& modelName
00038 )
00039 :
00040 chemistrySolver<CompType, ThermoType>(model, modelName),
00041 coeffsDict_(model.subDict(modelName + "Coeffs")),
00042 cTauChem_(readScalar(coeffsDict_.lookup("cTauChem"))),
00043 equil_(coeffsDict_.lookup("equilibriumRateLimiter"))
00044 {}
00045
00046
00047
00048
00049 template<class CompType, class ThermoType>
00050 Foam::EulerImplicit<CompType, ThermoType>::~EulerImplicit()
00051 {}
00052
00053
00054
00055
00056 template<class CompType, class ThermoType>
00057 Foam::scalar Foam::EulerImplicit<CompType, ThermoType>::solve
00058 (
00059 scalarField &c,
00060 const scalar T,
00061 const scalar p,
00062 const scalar t0,
00063 const scalar dt
00064 ) const
00065 {
00066 scalar pf, cf, pr, cr;
00067 label lRef, rRef;
00068
00069 label nSpecie = this->model_.nSpecie();
00070 simpleMatrix<scalar> RR(nSpecie);
00071
00072 for (label i=0; i<nSpecie; i++)
00073 {
00074 c[i] = max(0.0, c[i]);
00075 }
00076
00077 for (label i=0; i<nSpecie; i++)
00078 {
00079 RR.source()[i] = c[i]/dt;
00080 }
00081
00082 for (label i=0; i<this->model_.reactions().size(); i++)
00083 {
00084 const Reaction<ThermoType>& R = this->model_.reactions()[i];
00085
00086 scalar omegai = this->model_.omega
00087 (
00088 R, c, T, p, pf, cf, lRef, pr, cr, rRef
00089 );
00090
00091 scalar corr = 1.0;
00092 if (equil_)
00093 {
00094 if (omegai<0.0)
00095 {
00096 corr = 1.0/(1.0 + pr*dt);
00097 }
00098 else
00099 {
00100 corr = 1.0/(1.0 + pf*dt);
00101 }
00102 }
00103
00104 for (label s=0; s<R.lhs().size(); s++)
00105 {
00106 label si = R.lhs()[s].index;
00107 scalar sl = R.lhs()[s].stoichCoeff;
00108 RR[si][rRef] -= sl*pr*corr;
00109 RR[si][lRef] += sl*pf*corr;
00110 }
00111
00112 for (label s=0; s<R.rhs().size(); s++)
00113 {
00114 label si = R.rhs()[s].index;
00115 scalar sr = R.rhs()[s].stoichCoeff;
00116 RR[si][lRef] -= sr*pf*corr;
00117 RR[si][rRef] += sr*pr*corr;
00118 }
00119
00120 }
00121
00122
00123 for (label i=0; i<nSpecie; i++)
00124 {
00125 RR[i][i] += 1.0/dt;
00126 }
00127
00128 c = RR.LUsolve();
00129 for (label i=0; i<nSpecie; i++)
00130 {
00131 c[i] = max(0.0, c[i]);
00132 }
00133
00134
00135 scalar tMin = GREAT;
00136 label nEqns = this->model_.nEqns();
00137 scalarField c1(nEqns, 0.0);
00138
00139 for (label i=0; i<nSpecie; i++)
00140 {
00141 c1[i] = c[i];
00142 }
00143 c1[nSpecie] = T;
00144 c1[nSpecie+1] = p;
00145
00146 scalarField dcdt(nEqns, 0.0);
00147 this->model_.derivatives(0.0, c1, dcdt);
00148
00149 scalar sumC = sum(c);
00150
00151 for (label i=0; i<nSpecie; i++)
00152 {
00153 scalar d = dcdt[i];
00154 if (d < -SMALL)
00155 {
00156 tMin = min(tMin, -(c[i] + SMALL)/d);
00157 }
00158 else
00159 {
00160 d = max(d, SMALL);
00161 scalar cm = max(sumC - c[i], 1.0e-5);
00162 tMin = min(tMin, cm/d);
00163 }
00164 }
00165
00166 return cTauChem_*tMin;
00167 }
00168
00169
00170
Copyright © 2000-2009 OpenCFD Ltd