FreeFOAM The Cross-Platform CFD Toolkit
ode.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ode.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class CompType, class ThermoType>
33 (
35  const word& modelName
36 )
37 :
38  chemistrySolver<CompType, ThermoType>(model, modelName),
39  coeffsDict_(model.subDict(modelName + "Coeffs")),
40  solverName_(coeffsDict_.lookup("ODESolver")),
41  odeSolver_(ODESolver::New(solverName_, model)),
42  eps_(readScalar(coeffsDict_.lookup("eps"))),
43  scale_(readScalar(coeffsDict_.lookup("scale")))
44 {}
45 
46 
47 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
48 
49 template<class CompType, class ThermoType>
51 {}
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
56 template<class CompType, class ThermoType>
58 (
59  scalarField& c,
60  const scalar T,
61  const scalar p,
62  const scalar t0,
63  const scalar dt
64 ) const
65 {
66  label nSpecie = this->model_.nSpecie();
67  scalarField c1(this->model_.nEqns(), 0.0);
68 
69  // copy the concentration, T and P to the total solve-vector
70  for (label i=0; i<nSpecie; i++)
71  {
72  c1[i] = c[i];
73  }
74  c1[nSpecie] = T;
75  c1[nSpecie+1] = p;
76 
77  scalar dtEst = dt;
78 
79  odeSolver_->solve
80  (
81  this->model_,
82  t0,
83  t0 + dt,
84  c1,
85  eps_,
86  dtEst
87  );
88 
89  for (label i=0; i<c.size(); i++)
90  {
91  c[i] = max(0.0, c1[i]);
92  }
93 
94  return dtEst;
95 }
96 
97 
98 // ************************ vim: set sw=4 sts=4 et: ************************ //