ODESolvers: Add support for efficient ODE solver resizing

Note: this reuses the existing storage rather than costly reallocation
which requires the initial allocation to be sufficient for the largest
size the ODE system might have.  Attempt to set a size larger than the
initial size is a fatal error.
This commit is contained in:
Henry Weller
2016-07-11 17:27:04 +01:00
parent b3386623a2
commit d50bce000d
37 changed files with 673 additions and 106 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -47,6 +47,23 @@ Foam::Euler::Euler(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::Euler::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(err_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::Euler::solve Foam::scalar Foam::Euler::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -75,17 +75,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
Euler(const ODESystem& ode, const dictionary& dict); Euler(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~Euler()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -95,7 +103,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -52,6 +52,28 @@ Foam::EulerSI::EulerSI(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::EulerSI::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(err_);
resizeField(dydx_);
resizeField(dfdx_);
resizeMatrix(dfdy_);
resizeMatrix(a_);
resizeField(pivotIndices_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::EulerSI::solve Foam::scalar Foam::EulerSI::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -82,17 +82,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
EulerSI(const ODESystem& ode, const dictionary& dict); EulerSI(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~EulerSI()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -102,7 +110,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -34,34 +34,7 @@ namespace Foam
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
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)),
maxSteps_(10000)
{}
Foam::ODESolver::ODESolver
(
const ODESystem& ode,
const scalarField& absTol,
const scalarField& relTol
)
:
odes_(ode),
n_(ode.nEqns()),
absTol_(absTol),
relTol_(relTol),
maxSteps_(10000)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::ODESolver::normalizeError Foam::scalar Foam::ODESolver::normalizeError
( (
@ -82,6 +55,76 @@ Foam::scalar Foam::ODESolver::normalizeError
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::ODESolver::ODESolver(const ODESystem& ode, const dictionary& dict)
:
odes_(ode),
maxN_(ode.nEqns()),
n_(ode.nEqns()),
absTol_(n_, dict.lookupOrDefault<scalar>("absTol", SMALL)),
relTol_(n_, dict.lookupOrDefault<scalar>("relTol", 1e-4)),
maxSteps_(10000)
{}
Foam::ODESolver::ODESolver
(
const ODESystem& ode,
const scalarField& absTol,
const scalarField& relTol
)
:
odes_(ode),
maxN_(ode.nEqns()),
n_(ode.nEqns()),
absTol_(absTol),
relTol_(relTol),
maxSteps_(10000)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::ODESolver::resize()
{
if (odes_.nEqns() != n_)
{
if (odes_.nEqns() > maxN_)
{
FatalErrorInFunction
<< "Specified number of equations " << odes_.nEqns()
<< " greater than maximum " << maxN_
<< abort(FatalError);
}
n_ = odes_.nEqns();
resizeField(absTol_);
resizeField(relTol_);
return true;
}
else
{
return false;
}
}
void Foam::ODESolver::solve
(
scalar& x,
scalarField& y,
scalar& dxTry
) const
{
stepState step(dxTry);
solve(x, y, step);
dxTry = step.dxTry;
}
void Foam::ODESolver::solve void Foam::ODESolver::solve
( (
scalar& x, scalar& x,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -58,8 +58,11 @@ protected:
//- Reference to ODESystem //- Reference to ODESystem
const ODESystem& odes_; const ODESystem& odes_;
//- Size of the ODESystem //- Maximum size of the ODESystem
label n_; const label maxN_;
//- Size of the ODESystem (adjustable)
mutable label n_;
//- Absolute convergence tolerance per step //- Absolute convergence tolerance per step
scalarField absTol_; scalarField absTol_;
@ -90,6 +93,8 @@ protected:
public: public:
friend class ODESystem;
//- Runtime type information //- Runtime type information
TypeName("ODESolver"); TypeName("ODESolver");
@ -161,15 +166,25 @@ public:
// Member Functions // Member Functions
scalarField& absTol() //- Return the number of equations to solve
{ inline label nEqns() const;
return absTol_;
}
scalarField& relTol() //- Return access to the absolute tolerance field
{ inline scalarField& absTol();
return relTol_;
} //- Return access to the relative tolerance field
inline scalarField& relTol();
//- Resize the ODE solver
virtual bool resize() = 0;
template<class Type>
static inline void resizeField(UList<Type>& f, const label n);
template<class Type>
inline void resizeField(UList<Type>& f) const;
inline void resizeMatrix(scalarSquareMatrix& m) const;
//- Solve the ODE system as far as possible upto dxTry //- Solve the ODE system as far as possible upto dxTry
// adjusting the step as necessary to provide a solution within // adjusting the step as necessary to provide a solution within
@ -180,12 +195,7 @@ public:
scalar& x, scalar& x,
scalarField& y, scalarField& y,
scalar& dxTry scalar& dxTry
) const //= 0; ) const;
{
stepState step(dxTry);
solve(x, y, step);
dxTry = step.dxTry;
}
//- Solve the ODE system as far as possible upto dxTry //- Solve the ODE system as far as possible upto dxTry
// adjusting the step as necessary to provide a solution within // adjusting the step as necessary to provide a solution within
@ -216,6 +226,10 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "ODESolverI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::ODESolver::nEqns() const
{
return n_;
}
inline Foam::scalarField& Foam::ODESolver::absTol()
{
return absTol_;
}
inline Foam::scalarField& Foam::ODESolver::relTol()
{
return relTol_;
}
template<class Type>
inline void Foam::ODESolver::resizeField(UList<Type>& f, const label n)
{
f.shallowCopy(UList<Type>(f.begin(), n));
}
template<class Type>
inline void Foam::ODESolver::resizeField(UList<Type>& f) const
{
resizeField(f, n_);
}
inline void Foam::ODESolver::resizeMatrix(scalarSquareMatrix& m) const
{
m.shallowResize(n_);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -87,6 +87,29 @@ Foam::RKCK45::RKCK45(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::RKCK45::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(yTemp_);
resizeField(k2_);
resizeField(k3_);
resizeField(k4_);
resizeField(k5_);
resizeField(k6_);
resizeField(err_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::RKCK45::solve Foam::scalar Foam::RKCK45::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -98,17 +98,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
RKCK45(const ODESystem& ode, const dictionary& dict); RKCK45(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~RKCK45()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -118,7 +126,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -92,6 +92,29 @@ Foam::RKDP45::RKDP45(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::RKDP45::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(yTemp_);
resizeField(k2_);
resizeField(k3_);
resizeField(k4_);
resizeField(k5_);
resizeField(k6_);
resizeField(err_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::RKDP45::solve Foam::scalar Foam::RKDP45::solve
( (
const scalar x0, const scalar x0,

View File

@ -102,17 +102,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
RKDP45(const ODESystem& ode, const dictionary& dict); RKDP45(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~RKDP45()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -122,7 +130,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -88,6 +88,29 @@ Foam::RKF45::RKF45(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::RKF45::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(yTemp_);
resizeField(k2_);
resizeField(k3_);
resizeField(k4_);
resizeField(k5_);
resizeField(k6_);
resizeField(err_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::RKF45::solve Foam::scalar Foam::RKF45::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -102,17 +102,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
RKF45(const ODESystem& ode, const dictionary& dict); RKF45(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~RKF45()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -122,7 +130,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -66,6 +66,30 @@ Foam::Rosenbrock12::Rosenbrock12(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::Rosenbrock12::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(k1_);
resizeField(k2_);
resizeField(err_);
resizeField(dydx_);
resizeField(dfdx_);
resizeMatrix(dfdy_);
resizeMatrix(a_);
resizeField(pivotIndices_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::Rosenbrock12::solve Foam::scalar Foam::Rosenbrock12::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -92,17 +92,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
Rosenbrock12(const ODESystem& ode, const dictionary& dict); Rosenbrock12(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~Rosenbrock12()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -112,7 +120,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -79,6 +79,31 @@ Foam::Rosenbrock23::Rosenbrock23(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::Rosenbrock23::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(k1_);
resizeField(k2_);
resizeField(k3_);
resizeField(err_);
resizeField(dydx_);
resizeField(dfdx_);
resizeMatrix(dfdy_);
resizeMatrix(a_);
resizeField(pivotIndices_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::Rosenbrock23::solve Foam::scalar Foam::Rosenbrock23::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -96,17 +96,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
Rosenbrock23(const ODESystem& ode, const dictionary& dict); Rosenbrock23(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~Rosenbrock23()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -116,7 +124,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -124,6 +124,32 @@ Foam::Rosenbrock34::Rosenbrock34(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::Rosenbrock34::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(k1_);
resizeField(k2_);
resizeField(k3_);
resizeField(k4_);
resizeField(err_);
resizeField(dydx_);
resizeField(dfdx_);
resizeMatrix(dfdy_);
resizeMatrix(a_);
resizeField(pivotIndices_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::Rosenbrock34::solve Foam::scalar Foam::Rosenbrock34::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -104,17 +104,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
Rosenbrock34(const ODESystem& ode, const dictionary& dict); Rosenbrock34(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~Rosenbrock34()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -124,7 +132,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -68,6 +68,26 @@ Foam::SIBS::SIBS(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool Foam::SIBS::resize()
{
if (ODESolver::resize())
{
resizeField(yTemp_);
resizeField(ySeq_);
resizeField(yErr_);
resizeField(dydx0_);
resizeField(dfdx_);
resizeMatrix(dfdy_);
return true;
}
else
{
return false;
}
}
void Foam::SIBS::solve void Foam::SIBS::solve
( (
scalar& x, scalar& x,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -114,13 +114,21 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODE system
SIBS(const ODESystem& ode, const dictionary& dict); SIBS(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~SIBS()
{}
// Member Functions // Member Functions
void solve //- Resize the ODE solver
virtual bool resize();
virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -47,6 +47,23 @@ Foam::Trapezoid::Trapezoid(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::Trapezoid::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(err_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::Trapezoid::solve Foam::scalar Foam::Trapezoid::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -65,17 +65,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
Trapezoid(const ODESystem& ode, const dictionary& dict); Trapezoid(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~Trapezoid()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -85,7 +93,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -46,6 +46,15 @@ Foam::adaptiveSolver::adaptiveSolver
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::adaptiveSolver::resize(const label n)
{
ODESolver::resizeField(dydx0_, n);
ODESolver::resizeField(yTemp_, n);
return true;
}
void Foam::adaptiveSolver::solve void Foam::adaptiveSolver::solve
( (
const ODESystem& odes, const ODESystem& odes,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -74,6 +74,9 @@ public:
// Member Functions // Member Functions
//- Resize the ODE solver
virtual bool resize(const label n);
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
virtual scalar solve virtual scalar solve
( (
@ -85,7 +88,7 @@ public:
) const = 0; ) const = 0;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
const ODESystem& ode, const ODESystem& ode,
scalar& x, scalar& x,

View File

@ -70,6 +70,32 @@ Foam::rodas23::rodas23(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::rodas23::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(k1_);
resizeField(k2_);
resizeField(k3_);
resizeField(dy_);
resizeField(err_);
resizeField(dydx_);
resizeField(dfdx_);
resizeMatrix(dfdy_);
resizeMatrix(a_);
resizeField(pivotIndices_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::rodas23::solve Foam::scalar Foam::rodas23::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -96,17 +96,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
rodas23(const ODESystem& ode, const dictionary& dict); rodas23(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~rodas23()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -116,7 +124,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -93,6 +93,34 @@ Foam::rodas34::rodas34(const ODESystem& ode, const dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::rodas34::resize()
{
if (ODESolver::resize())
{
adaptiveSolver::resize(n_);
resizeField(k1_);
resizeField(k2_);
resizeField(k3_);
resizeField(k4_);
resizeField(k5_);
resizeField(dy_);
resizeField(err_);
resizeField(dydx_);
resizeField(dfdx_);
resizeMatrix(dfdy_);
resizeMatrix(a_);
resizeField(pivotIndices_);
return true;
}
else
{
return false;
}
}
Foam::scalar Foam::rodas34::solve Foam::scalar Foam::rodas34::solve
( (
const scalar x0, const scalar x0,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -97,17 +97,25 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
rodas34(const ODESystem& ode, const dictionary& dict); rodas34(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~rodas34()
{}
// Member Functions // Member Functions
//- Inherit solve from ODESolver //- Inherit solve from ODESolver
using ODESolver::solve; using ODESolver::solve;
//- Resize the ODE solver
virtual bool resize();
//- Solve a single step dx and return the error //- Solve a single step dx and return the error
scalar solve virtual scalar solve
( (
const scalar x0, const scalar x0,
const scalarField& y0, const scalarField& y0,
@ -117,7 +125,7 @@ public:
) const; ) const;
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -211,6 +211,30 @@ void Foam::seulex::extrapolate
} }
bool Foam::seulex::resize()
{
if (ODESolver::resize())
{
resizeField(dfdx_);
resizeMatrix(dfdy_);
resizeMatrix(a_);
resizeField(pivotIndices_);
resizeField(y0_);
resizeField(ySequence_);
resizeField(scale_);
resizeField(dy_);
resizeField(yTemp_);
resizeField(dydx_);
return true;
}
else
{
return false;
}
}
void Foam::seulex::solve void Foam::seulex::solve
( (
scalar& x, scalar& x,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -133,14 +133,22 @@ public:
// Constructors // Constructors
//- Construct from ODE //- Construct from ODESystem
seulex(const ODESystem& ode, const dictionary& dict); seulex(const ODESystem& ode, const dictionary& dict);
//- Destructor
virtual ~seulex()
{}
// Member Functions // Member Functions
//- Resize the ODE solver
virtual bool resize();
//- Solve the ODE system and the update the state //- Solve the ODE system and the update the state
void solve virtual void solve
( (
scalar& x, scalar& x,
scalarField& y, scalarField& y,

View File

@ -249,6 +249,9 @@ public:
//- Resize the matrix preserving the elements //- Resize the matrix preserving the elements
void setSize(const label m, const label n); void setSize(const label m, const label n);
//- Resize the matrix without reallocating storage (unsafe)
inline void shallowResize(const label m, const label n);
//- Return the transpose of the matrix //- Return the transpose of the matrix
Form T() const; Form T() const;

View File

@ -280,6 +280,14 @@ Foam::Matrix<Form, Type>::col
} }
template<class Form, class Type>
void Foam::Matrix<Form, Type>::shallowResize(const label m, const label n)
{
mRows_ = m;
nCols_ = n;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Form, class Type> template<class Form, class Type>

View File

@ -113,6 +113,9 @@ public:
//- Resize the matrix preserving the elements //- Resize the matrix preserving the elements
inline void setSize(const label m); inline void setSize(const label m);
//- Resize the matrix without reallocating storage (unsafe)
inline void shallowResize(const label m);
// Member operators // Member operators

View File

@ -161,6 +161,13 @@ inline void Foam::SquareMatrix<Type>::setSize(const label m)
} }
template<class Type>
inline void Foam::SquareMatrix<Type>::shallowResize(const label m)
{
Matrix<SquareMatrix<Type>, Type>::shallowResize(m, m);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type> template<class Type>

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -61,7 +61,14 @@ void Foam::ode<ChemistryModel>::solve
scalar& subDeltaT scalar& subDeltaT
) const ) const
{ {
label nSpecie = this->nSpecie(); // Reset the size of the ODE system to the simplified size when mechanism
// reduction is active
if (odeSolver_->resize())
{
odeSolver_->resizeField(cTp_);
}
const label nSpecie = this->nSpecie();
// Copy the concentration, T and P to the total solve-vector // Copy the concentration, T and P to the total solve-vector
for (int i=0; i<nSpecie; i++) for (int i=0; i<nSpecie; i++)

View File

@ -55,7 +55,8 @@ class ode
// Private data // Private data
dictionary coeffsDict_; dictionary coeffsDict_;
autoPtr<ODESolver> odeSolver_;
mutable autoPtr<ODESolver> odeSolver_;
// Solver data // Solver data
mutable scalarField cTp_; mutable scalarField cTp_;