OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

EulerImplicit.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "EulerImplicit.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "simpleMatrix.H"
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
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 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00048 
00049 template<class CompType, class ThermoType>
00050 Foam::EulerImplicit<CompType, ThermoType>::~EulerImplicit()
00051 {}
00052 
00053 
00054 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
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     } // end for(label i...
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     // estimate the next time step
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