Commit 630a4b0b authored by mattijs's avatar mattijs
Browse files

Merge branch 'master' of /home/dm4/OpenFOAM/OpenFOAM-dev

Conflicts:
	src/postProcessing/functionObjects/field/Make/files
parents 202d7c1a feacb903
......@@ -53,7 +53,7 @@ else
)
);
fvOptions.makeRelative(fvc::interpolate(psi), phiHbyA);
fvOptions.makeRelative(fvc::interpolate(rho), phiHbyA);
while (pimple.correctNonOrthogonal())
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -142,7 +142,7 @@ int main(int argc, char *argv[])
scalar dxNext = dxEst;
odeSolver->relTol() = relTol;
odeSolver->solve(ode, x, y, dxNext);
odeSolver->solve(x, y, dxNext);
Info<< scientific << setw(13) << relTol;
Info<< fixed << setw(11) << dxEst;
......@@ -165,7 +165,7 @@ int main(int argc, char *argv[])
scalar dxEst = 0.5;
odeSolver->relTol() = 1e-4;
odeSolver->solve(ode, x, xEnd, y, dxEst);
odeSolver->solve(x, xEnd, y, dxEst);
Info<< nl << "Analytical: y(2.0) = " << yEnd << endl;
Info << "Numerical: y(2.0) = " << y << ", dxEst = " << dxEst << endl;
......
......@@ -62,7 +62,7 @@ foamInstall=$HOME/$WM_PROJECT
foamCompiler=system
#- Compiler:
# WM_COMPILER = Gcc | Gcc43 | Gcc44 | Gcc45 | Gcc46 | Clang | Icc (Intel icc)
# WM_COMPILER = Gcc | Gcc45 | Gcc46 | Gcc47 | Clang | Icc (Intel icc)
export WM_COMPILER=Gcc
unset WM_COMPILER_ARCH WM_COMPILER_LIB_ARCH
......
......@@ -61,7 +61,7 @@ if ( ! $?FOAM_INST_DIR ) setenv FOAM_INST_DIR $foamInstall
set foamCompiler=system
#- Compiler:
# WM_COMPILER = Gcc | Gcc43 | Gcc44 | Gcc45 | Gcc46 | Clang | Icc (Intel icc)
# WM_COMPILER = Gcc | Gcc45 | Gcc46 | Gcc47 | Clang | Icc (Intel icc)
setenv WM_COMPILER Gcc
setenv WM_COMPILER_ARCH # defined but empty
unsetenv WM_COMPILER_LIB_ARCH
......
......@@ -8,13 +8,14 @@ ODESolvers/Trapezoid/Trapezoid.C
ODESolvers/RKF45/RKF45.C
ODESolvers/RKCK45/RKCK45.C
ODESolvers/RKDP45/RKDP45.C
ODESolvers/Rosenbrock21/Rosenbrock21.C
ODESolvers/Rosenbrock32/Rosenbrock32.C
ODESolvers/Rosenbrock43/Rosenbrock43.C
ODESolvers/rodas32/rodas32.C
ODESolvers/rodas43/rodas43.C
ODESolvers/Rosenbrock12/Rosenbrock12.C
ODESolvers/Rosenbrock23/Rosenbrock23.C
ODESolvers/Rosenbrock34/Rosenbrock34.C
ODESolvers/rodas23/rodas23.C
ODESolvers/rodas34/rodas34.C
ODESolvers/SIBS/SIBS.C
ODESolvers/SIBS/SIMPR.C
ODESolvers/SIBS/polyExtrapolate.C
ODESolvers/seulex/seulex.C
LIB = $(FOAM_LIBBIN)/libODE
......@@ -49,7 +49,6 @@ Foam::Euler::Euler(const ODESystem& ode, const dictionary& dict)
Foam::scalar Foam::Euler::solve
(
const ODESystem& ode,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -75,13 +74,12 @@ Foam::scalar Foam::Euler::solve
void Foam::Euler::solve
(
const ODESystem& odes,
scalar& x,
scalarField& y,
scalar& dxTry
) const
{
adaptiveSolver::solve(odes, x, y, dxTry);
adaptiveSolver::solve(odes_, x, y, dxTry);
}
......
......@@ -84,7 +84,6 @@ public:
//- Solve a single step dx and return the error
scalar solve
(
const ODESystem& ode,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -95,7 +94,6 @@ public:
//- Solve the ODE system and the update the state
void solve
(
const ODESystem& ode,
scalar& x,
scalarField& y,
scalar& dxTry
......
......@@ -54,7 +54,6 @@ Foam::EulerSI::EulerSI(const ODESystem& ode, const dictionary& dict)
Foam::scalar Foam::EulerSI::solve
(
const ODESystem& ode,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -62,7 +61,7 @@ Foam::scalar Foam::EulerSI::solve
scalarField& y
) const
{
ode.jacobian(x0, y0, dfdx_, dfdy_);
odes_.jacobian(x0, y0, dfdx_, dfdy_);
for (register label i=0; i<n_; i++)
{
......@@ -95,13 +94,12 @@ Foam::scalar Foam::EulerSI::solve
void Foam::EulerSI::solve
(
const ODESystem& odes,
scalar& x,
scalarField& y,
scalar& dxTry
) const
{
adaptiveSolver::solve(odes, x, y, dxTry);
adaptiveSolver::solve(odes_, x, y, dxTry);
}
......
......@@ -91,7 +91,6 @@ public:
//- Solve a single step dx and return the error
scalar solve
(
const ODESystem& ode,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -102,7 +101,6 @@ public:
//- Solve the ODE system and the update the state
void solve
(
const ODESystem& ode,
scalar& x,
scalarField& y,
scalar& dxTry
......
......@@ -38,6 +38,7 @@ namespace Foam
Foam::ODESolver::ODESolver(const ODESystem& ode, const dictionary& dict)
:
odes_(ode),
n_(ode.nEqns()),
absTol_(n_, dict.lookupOrDefault<scalar>("absTol", SMALL)),
relTol_(n_, dict.lookupOrDefault<scalar>("relTol", 1e-4)),
......@@ -52,6 +53,7 @@ Foam::ODESolver::ODESolver
const scalarField& relTol
)
:
odes_(ode),
n_(ode.nEqns()),
absTol_(absTol),
relTol_(relTol),
......@@ -82,48 +84,70 @@ Foam::scalar Foam::ODESolver::normalizeError
void Foam::ODESolver::solve
(
const ODESystem& ode,
scalar& x,
scalarField& y,
stepState& step
) const
{
solve(x, y, step.dxTry);
}
void Foam::ODESolver::solve
(
const scalar xStart,
const scalar xEnd,
scalarField& y,
scalar& dxEst
scalar& dxTry
) const
{
stepState step(dxTry);
scalar x = xStart;
bool truncated = false;
for (label nStep=0; nStep<maxSteps_; nStep++)
{
// Store previous iteration dxEst
scalar dxEst0 = dxEst;
// Store previous iteration dxTry
scalar dxTry0 = step.dxTry;
step.reject = false;
// Check if this is a truncated step and set dxEst to integrate to xEnd
if ((x + dxEst - xEnd)*(x + dxEst - xStart) > 0)
// Check if this is a truncated step and set dxTry to integrate to xEnd
if ((x + step.dxTry - xEnd)*(x + step.dxTry - xStart) > 0)
{
truncated = true;
dxEst = xEnd - x;
step.last = true;
step.dxTry = xEnd - x;
}
// Integrate as far as possible up to dxEst
solve(ode, x, y, dxEst);
// Integrate as far as possible up to step.dxTry
solve(x, y, step);
// Check if reached xEnd
if ((x - xEnd)*(xEnd - xStart) >= 0)
{
if (nStep > 0 && truncated)
if (nStep > 0 && step.last)
{
dxEst = dxEst0;
step.dxTry = dxTry0;
}
dxTry = step.dxTry;
return;
}
step.first = false;
// If the step.dxTry was reject set step.prevReject
if (step.reject)
{
step.prevReject = true;
}
}
FatalErrorIn
(
"ODESolver::solve"
"(const ODESystem& ode, const scalar xStart, const scalar xEnd,"
"scalarField& y, scalar& dxEst) const"
"(const scalar xStart, const scalar xEnd,"
"scalarField& y, scalar& dxTry) const"
) << "Integration steps greater than maximum " << maxSteps_
<< exit(FatalError);
}
......
......@@ -55,6 +55,9 @@ protected:
// Protected data
//- Reference to ODESystem
const ODESystem& odes_;
//- Size of the ODESystem
label n_;
......@@ -90,6 +93,30 @@ public:
//- Runtime type information
TypeName("ODESolver");
class stepState
{
public:
const bool forward;
scalar dxTry;
scalar dxDid;
bool first;
bool last;
bool reject;
bool prevReject;
stepState(const scalar dx)
:
forward(dx > 0 ? true : false),
dxTry(dx),
dxDid(0),
first(true),
last(false),
reject(false),
prevReject(false)
{}
};
// Declare run-time constructor selection table
......@@ -150,17 +177,31 @@ public:
// Update the state and return an estimate for the next step in dxTry
virtual void solve
(
const ODESystem& ode,
scalar& x,
scalarField& y,
scalar& dxTry
) const = 0;
) const //= 0;
{
stepState step(dxTry);
solve(x, y, step);
dxTry = step.dxTry;
}
//- Solve the ODE system as far as possible upto dxTry
// adjusting the step as necessary to provide a solution within
// the specified tolerance.
// Update the state and return an estimate for the next step in dxTry
virtual void solve
(
scalar& x,
scalarField& y,
stepState& step
) const;
//- Solve the ODE system from xStart to xEnd, update the state
// and return an estimate for the next step in dxTry
virtual void solve
(
const ODESystem& ode,
const scalar xStart,
const scalar xEnd,
scalarField& y,
......
......@@ -89,7 +89,6 @@ Foam::RKCK45::RKCK45(const ODESystem& ode, const dictionary& dict)
Foam::scalar Foam::RKCK45::solve
(
const ODESystem& odes,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -102,21 +101,21 @@ Foam::scalar Foam::RKCK45::solve
yTemp_[i] = y0[i] + a21*dx*dydx0[i];
}
odes.derivatives(x0 + c2*dx, yTemp_, k2_);
odes_.derivatives(x0 + c2*dx, yTemp_, k2_);
forAll(yTemp_, i)
{
yTemp_[i] = y0[i] + dx*(a31*dydx0[i] + a32*k2_[i]);
}
odes.derivatives(x0 + c3*dx, yTemp_, k3_);
odes_.derivatives(x0 + c3*dx, yTemp_, k3_);
forAll(yTemp_, i)
{
yTemp_[i] = y0[i] + dx*(a41*dydx0[i] + a42*k2_[i] + a43*k3_[i]);
}
odes.derivatives(x0 + c4*dx, yTemp_, k4_);
odes_.derivatives(x0 + c4*dx, yTemp_, k4_);
forAll(yTemp_, i)
{
......@@ -124,7 +123,7 @@ Foam::scalar Foam::RKCK45::solve
+ dx*(a51*dydx0[i] + a52*k2_[i] + a53*k3_[i] + a54*k4_[i]);
}
odes.derivatives(x0 + c5*dx, yTemp_, k5_);
odes_.derivatives(x0 + c5*dx, yTemp_, k5_);
forAll(yTemp_, i)
{
......@@ -133,7 +132,7 @@ Foam::scalar Foam::RKCK45::solve
*(a61*dydx0[i] + a62*k2_[i] + a63*k3_[i] + a64*k4_[i] + a65*k5_[i]);
}
odes.derivatives(x0 + c6*dx, yTemp_, k6_);
odes_.derivatives(x0 + c6*dx, yTemp_, k6_);
forAll(y, i)
{
......@@ -154,13 +153,12 @@ Foam::scalar Foam::RKCK45::solve
void Foam::RKCK45::solve
(
const ODESystem& odes,
scalar& x,
scalarField& y,
scalar& dxTry
) const
{
adaptiveSolver::solve(odes, x, y, dxTry);
adaptiveSolver::solve(odes_, x, y, dxTry);
}
......
......@@ -34,10 +34,7 @@ Description
Cash, J.R.,
Karp, A.H.
ACM Transactions on Mathematical Software, vol. 16, 1990, pp. 201–222.
\endverbatim
Based on code from:
\verbatim
"Solving Ordinary Differential Equations I: Nonstiff Problems,
second edition",
Hairer, E.,
......@@ -110,7 +107,6 @@ public:
//- Solve a single step dx and return the error
scalar solve
(
const ODESystem& ode,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -121,7 +117,6 @@ public:
//- Solve the ODE system and the update the state
void solve
(
const ODESystem& ode,
scalar& x,
scalarField& y,
scalar& dxTry
......
......@@ -94,7 +94,6 @@ Foam::RKDP45::RKDP45(const ODESystem& ode, const dictionary& dict)
Foam::scalar Foam::RKDP45::solve
(
const ODESystem& odes,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -107,21 +106,21 @@ Foam::scalar Foam::RKDP45::solve
yTemp_[i] = y0[i] + a21*dx*dydx0[i];
}
odes.derivatives(x0 + c2*dx, yTemp_, k2_);
odes_.derivatives(x0 + c2*dx, yTemp_, k2_);
forAll(yTemp_, i)
{
yTemp_[i] = y0[i] + dx*(a31*dydx0[i] + a32*k2_[i]);
}
odes.derivatives(x0 + c3*dx, yTemp_, k3_);
odes_.derivatives(x0 + c3*dx, yTemp_, k3_);
forAll(yTemp_, i)
{
yTemp_[i] = y0[i] + dx*(a41*dydx0[i] + a42*k2_[i] + a43*k3_[i]);
}
odes.derivatives(x0 + c4*dx, yTemp_, k4_);
odes_.derivatives(x0 + c4*dx, yTemp_, k4_);
forAll(yTemp_, i)
{
......@@ -129,7 +128,7 @@ Foam::scalar Foam::RKDP45::solve
+ dx*(a51*dydx0[i] + a52*k2_[i] + a53*k3_[i] + a54*k4_[i]);
}
odes.derivatives(x0 + c5*dx, yTemp_, k5_);
odes_.derivatives(x0 + c5*dx, yTemp_, k5_);
forAll(yTemp_, i)
{
......@@ -138,7 +137,7 @@ Foam::scalar Foam::RKDP45::solve
*(a61*dydx0[i] + a62*k2_[i] + a63*k3_[i] + a64*k4_[i] + a65*k5_[i]);
}
odes.derivatives(x0 + dx, yTemp_, k6_);
odes_.derivatives(x0 + dx, yTemp_, k6_);
forAll(y, i)
{
......@@ -147,7 +146,7 @@ Foam::scalar Foam::RKDP45::solve
}
// Reuse k2_ for the derivative of the new state
odes.derivatives(x0 + dx, y, k2_);
odes_.derivatives(x0 + dx, y, k2_);
forAll(err_, i)
{
......@@ -163,13 +162,12 @@ Foam::scalar Foam::RKDP45::solve
void Foam::RKDP45::solve
(
const ODESystem& odes,
scalar& x,
scalarField& y,
scalar& dxTry
) const
{
adaptiveSolver::solve(odes, x, y, dxTry);
adaptiveSolver::solve(odes_, x, y, dxTry);
}
......
......@@ -34,10 +34,7 @@ Description
Prince, P. J.,
Journal of Computational and Applied Mathematics,
6 (1), 1980: pp. 19-26.
\endverbatim
Based on code from:
\verbatim
"Solving Ordinary Differential Equations I: Nonstiff Problems,
second edition",
Hairer, E.,
......@@ -114,7 +111,6 @@ public:
//- Solve a single step dx and return the error
scalar solve
(
const ODESystem& ode,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -125,7 +121,6 @@ public:
//- Solve the ODE system and the update the state
void solve
(
const ODESystem& ode,
scalar& x,
scalarField& y,
scalar& dxTry
......
......@@ -90,7 +90,6 @@ Foam::RKF45::RKF45(const ODESystem& ode, const dictionary& dict)
Foam::scalar Foam::RKF45::solve
(
const ODESystem& odes,
const scalar x0,
const scalarField& y0,
const scalarField& dydx0,
......@@ -103,21 +102,21 @@ Foam::scalar Foam::RKF45::solve
yTemp_[i] = y0[i] + a21*dx*dydx0[i];
}
odes.derivatives(x0 + c2*dx, yTemp_, k2_);
odes_.derivatives(x0 + c2*dx, yTemp_, k2_);
forAll(yTemp_, i)
{
yTemp_[i] = y0[i] + dx*(a31*dydx0[i] + a32*k2_[i]);
}
odes.derivatives(x0 + c3*dx, yTemp_, k3_);
odes_.derivatives(x0 + c3*dx, yTemp_, k3_);
forAll(yTemp_, i)
{
yTemp_[i] = y0[i] + dx*(a41*dydx0[i] + a42*k2_[i] + a43*k3_[i]);
}
odes.derivatives(x0 + c4*dx, yTemp_, k4_);
odes_.derivatives(x0 + c4*dx, yTemp_, k4_);
forAll(yTemp_, i)
{
......@@ -125,7 +124,7 @@ Foam::scalar Foam::RKF45::solve
+ dx*(a51*dydx0[i] + a52*k2_[i] + a53*k3_[i] + a54*k4_[i]);
}
odes.derivatives(x0 + c5*dx, yTemp_, k5_);
odes_.derivatives(x0 + c5*dx, yTemp_, k5_);
forAll(yTemp_, i)
{
......@@ -134,7 +133,7 @@ Foam::scalar Foam::RKF45::solve
*(a61*dydx0[i] + a62*k2_[i] + a63*k3_[i] + a64*k4_[i] + a65*k5_[i]);
}
odes.derivatives(x0 + c6*dx, yTemp_, k6_);
odes_.derivatives(x0 + c6*dx, yTemp_, k6_);
// Calculate the 5th-order solution
forAll(y, i)
......@@ -159,13 +158,12 @@ Foam::scalar Foam::RKF45::solve
void Foam::RKF45::solve
(
const ODESystem& odes,
scalar& x,
scalarField& y,
scalar& dxTry
) const
{
adaptiveSolver::solve(odes, x, y, dxTry);
adaptiveSolver::solve(odes_, x, y, dxTry);
}
......
......@@ -34,8 +34,6 @@ Description
Fehlberg, E.,
NASA Technical Report 315, 1969.
Based on code from:
\verbatim
"Solving Ordinary Differential Equations I: Nonstiff Problems,
second edition",
Hairer, E.,
......@@ -48,31 +46,6 @@ Description
and allows to perform an adapdive step-size control using these two order
without the need of re-evaluation.
\f{align}{
k_1 &= h f(t_k, y_k) \\
k_2 &= h f(t_k + \frac{1}{4}h, y_k + \frac{1}{4}k_1) \\
k_3 &= h f(t_k + \frac{3}{8}h, y_k + \frac{3}{32}k_1 + \frac{9}{32}k_2) \\
k_4 &= h f(t_k + \frac{12}{13}h, y_k + \frac{1932}{2197}k_1
\frac{7200}{2197}k_2 + \frac{7296}{2197}k_3) - \\
k_5 &= h f(t_k + h, y_k + \frac{439}{216}k_1 - 8k_2 + \frac{3680}{513}k_3 -
\frac{845}{4104}k_4) \\
k_6 &= h f(t_k + \frac{1}{2}h, y_k - \frac{8}{27}k_1 + 2k_2 -
\frac{3544}{2565}k_3 + \frac{1859}{4104}k_4 - \frac{11}{40}k_5) \\
\f}