FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

ODESolver.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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <ODE/ODESolver.H>
00027 
00028 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00029 
00030 defineTypeNameAndDebug(Foam::ODESolver, 0);
00031 namespace Foam
00032 {
00033     defineRunTimeSelectionTable(ODESolver, ODE);
00034 };
00035 
00036 
00037 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00038 
00039 Foam::ODESolver::ODESolver(const ODE& ode)
00040 :
00041     n_(ode.nEqns()),
00042     yScale_(n_),
00043     dydx_(n_)
00044 {}
00045 
00046 
00047 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00048 
00049 void Foam::ODESolver::solve
00050 (
00051     const ODE& ode,
00052     const scalar xStart,
00053     const scalar xEnd,
00054     scalarField& y,
00055     const scalar eps,
00056     scalar& hEst
00057 ) const
00058 {
00059     const label MAXSTP = 10000;
00060 
00061     scalar x = xStart;
00062     scalar h = hEst;
00063     scalar hNext = 0;
00064     scalar hPrev = 0;
00065 
00066     for (label nStep=0; nStep<MAXSTP; nStep++)
00067     {
00068         ode.derivatives(x, y, dydx_);
00069 
00070         for (label i=0; i<n_; i++)
00071         {
00072             yScale_[i] = mag(y[i]) + mag(dydx_[i]*h) + SMALL;
00073         }
00074 
00075         if ((x + h - xEnd)*(x + h - xStart) > 0.0)
00076         {
00077             h = xEnd - x;
00078             hPrev = hNext;
00079         }
00080 
00081         hNext = 0;
00082         scalar hDid;
00083         solve(ode, x, y, dydx_, eps, yScale_, h, hDid, hNext);
00084 
00085         if ((x - xEnd)*(xEnd - xStart) >= 0.0)
00086         {
00087             if (hPrev != 0)
00088             {
00089                 hEst = hPrev;
00090             }
00091             else
00092             {
00093                 hEst = hNext;
00094             }
00095 
00096             return;
00097         }
00098 
00099         h = hNext;
00100     }
00101 
00102     FatalErrorIn
00103     (
00104         "ODESolver::solve"
00105         "(const ODE& ode, const scalar xStart, const scalar xEnd,"
00106         "scalarField& yStart, const scalar eps, scalar& hEst) const"
00107     )   << "Too many integration steps"
00108         << exit(FatalError);
00109 }
00110 
00111 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines