1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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
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/>.
26 \*---------------------------------------------------------------------------*/
31 #include "ODESolver.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 dydx[1] = y[0] - (1.0/x)*y[1];
62 dydx[2] = y[1] - (2.0/x)*y[2];
63 dydx[3] = y[2] - (3.0/x)*y[3];
71 scalarSquareMatrix& dfdy
75 dfdx[1] = (1.0/sqr(x))*y[1];
76 dfdx[2] = (2.0/sqr(x))*y[2];
77 dfdx[3] = (3.0/sqr(x))*y[3];
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
105 int main(int argc, char *argv[])
107 argList::validArgs.append("ODESolver");
108 argList args(argc, argv);
111 autoPtr<ODESolver> odeSolver = ODESolver::New(args[1], ode);
114 scalarField yStart(ode.nEqns());
115 yStart[0] = ::Foam::j0(xStart);
116 yStart[1] = ::Foam::j1(xStart);
117 yStart[2] = ::Foam::jn(2, xStart);
118 yStart[3] = ::Foam::jn(3, xStart);
120 scalarField dyStart(ode.nEqns());
121 ode.derivatives(xStart, yStart, dyStart);
123 Info<< setw(10) << "eps" << setw(12) << "hEst";
124 Info<< setw(13) << "hDid" << setw(14) << "hNext" << endl;
125 Info<< setprecision(6);
127 for (label i=0; i<15; i++)
129 scalar eps = ::Foam::exp(-scalar(i + 1));
132 scalarField y(yStart);
133 scalarField dydx(dyStart);
135 scalarField yScale(ode.nEqns(), 1.0);
139 odeSolver->solve(ode, x, y, dydx, eps, yScale, hEst, hDid, hNext);
141 Info<< scientific << setw(13) << eps;
142 Info<< fixed << setw(11) << hEst;
143 Info<< setw(13) << hDid << setw(13) << hNext
144 << setw(13) << y[0] << setw(13) << y[1]
145 << setw(13) << y[2] << setw(13) << y[3]
150 scalar xEnd = x + 1.0;
151 scalarField y(yStart);
153 scalarField yEnd(ode.nEqns());
154 yEnd[0] = ::Foam::j0(xEnd);
155 yEnd[1] = ::Foam::j1(xEnd);
156 yEnd[2] = ::Foam::jn(2, xEnd);
157 yEnd[3] = ::Foam::jn(3, xEnd);
161 odeSolver->solve(ode, x, xEnd, y, 1e-4, hEst);
163 Info<< nl << "Analytical: y(2.0) = " << yEnd << endl;
164 Info << "Numerical: y(2.0) = " << y << ", hEst = " << hEst << endl;
166 Info<< "\nEnd\n" << endl;
172 // ************************************************************************* //