initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / chemistryModel / chemistrySolver / ode / ode.C
blob7a4bde923f7610abde7a598c8d1d97d09e114a39
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "ode.H"
28 #include "ODEChemistryModel.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 template<class CompType, class ThermoType>
33 Foam::ode<CompType, ThermoType>::ode
35     ODEChemistryModel<CompType, ThermoType>& model,
36     const word& modelName
39     chemistrySolver<CompType, ThermoType>(model, modelName),
40     coeffsDict_(model.subDict(modelName + "Coeffs")),
41     solverName_(coeffsDict_.lookup("ODESolver")),
42     odeSolver_(ODESolver::New(solverName_, model)),
43     eps_(readScalar(coeffsDict_.lookup("eps"))),
44     scale_(readScalar(coeffsDict_.lookup("scale")))
48 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
50 template<class CompType, class ThermoType>
51 Foam::ode<CompType, ThermoType>::~ode()
55 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
57 template<class CompType, class ThermoType>
58 Foam::scalar Foam::ode<CompType, ThermoType>::solve
60     scalarField& c,
61     const scalar T,
62     const scalar p,
63     const scalar t0,
64     const scalar dt
65 ) const
67     label nSpecie = this->model_.nSpecie();
68     scalarField c1(this->model_.nEqns(), 0.0);
70     // copy the concentration, T and P to the total solve-vector
71     for (label i=0; i<nSpecie; i++)
72     {
73         c1[i] = c[i];
74     }
75     c1[nSpecie] = T;
76     c1[nSpecie+1] = p;
78     scalar dtEst = dt;
80     odeSolver_->solve
81     (
82         this->model_,
83         t0,
84         t0 + dt,
85         c1,
86         eps_,
87         dtEst
88     );
90     for (label i=0; i<c.size(); i++)
91     {
92         c[i] = max(0.0, c1[i]);
93     }
95     return dtEst;
99 // ************************************************************************* //