1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 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
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
27 \*---------------------------------------------------------------------------*/
32 #include "ODESolver.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 dydx[1] = y[0] - (1.0/x)*y[1];
63 dydx[2] = y[1] - (2.0/x)*y[2];
64 dydx[3] = y[2] - (3.0/x)*y[3];
76 dfdx[1] = (1.0/sqr(x))*y[1];
77 dfdx[2] = (2.0/sqr(x))*y[2];
78 dfdx[3] = (3.0/sqr(x))*y[3];
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 int main(int argc, char *argv[])
108 argList::validArgs.clear();
109 argList::validArgs.append("ODESolver");
110 argList args(argc, argv);
112 word ODESolverName(args.additionalArgs()[0]);
115 autoPtr<ODESolver> odeSolver = ODESolver::New(ODESolverName, ode);
118 scalarField yStart(ode.nEqns());
119 yStart[0] = ::Foam::j0(xStart);
120 yStart[1] = ::Foam::j1(xStart);
121 yStart[2] = ::Foam::jn(2, xStart);
122 yStart[3] = ::Foam::jn(3, xStart);
124 scalarField dyStart(ode.nEqns());
125 ode.derivatives(xStart, yStart, dyStart);
127 Info<< setw(10) << "eps" << setw(12) << "hEst";
128 Info<< setw(13) << "hDid" << setw(14) << "hNext" << endl;
129 Info<< setprecision(6);
131 for (label i=0; i<15; i++)
133 scalar eps = ::Foam::exp(-scalar(i + 1));
136 scalarField y = yStart;
137 scalarField dydx = dyStart;
139 scalarField yScale(ode.nEqns(), 1.0);
143 odeSolver->solve(ode, x, y, dydx, eps, yScale, hEst, hDid, hNext);
145 Info<< scientific << setw(13) << eps;
146 Info<< fixed << setw(11) << hEst;
147 Info<< setw(13) << hDid << setw(13) << hNext
148 << setw(13) << y[0] << setw(13) << y[1]
149 << setw(13) << y[2] << setw(13) << y[3]
154 scalar xEnd = x + 1.0;
155 scalarField y = yStart;
157 scalarField yEnd(ode.nEqns());
158 yEnd[0] = ::Foam::j0(xEnd);
159 yEnd[1] = ::Foam::j1(xEnd);
160 yEnd[2] = ::Foam::jn(2, xEnd);
161 yEnd[3] = ::Foam::jn(3, xEnd);
165 odeSolver->solve(ode, x, xEnd, y, 1e-4, hEst);
167 Info<< nl << "Analytical: y(2.0) = " << yEnd << endl;
168 Info << "Numerical: y(2.0) = " << y << ", hEst = " << hEst << endl;
170 Info << "\nEnd\n" << endl;
176 // ************************************************************************* //