Loading...
Searching...
No Matches
Trapezoid.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2013-2016 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "Trapezoid.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
38}
39
40
41// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42
44:
47 err_(n_)
48{}
49
50
51// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52
54{
56 {
58
59 resizeField(err_);
60
61 return true;
62 }
63
64 return false;
65}
66
67
68Foam::scalar Foam::Trapezoid::solve
69(
70 const scalar x0,
71 const scalarField& y0,
72 const scalarField& dydx0,
73 const scalar dx,
75) const
76{
77 // Predict the state using 1st-order Trapezoid method
78 forAll(y, i)
79 {
80 y[i] = y0[i] + dx*dydx0[i];
81 }
82
83 // Evaluate the system for the predicted state
84 odes_.derivatives(x0 + dx, y, err_);
85
86 // Update the state as the average between the prediction and the correction
87 // and estimate the error from the difference
88 forAll(y, i)
89 {
90 y[i] = y0[i] + 0.5*dx*(dydx0[i] + err_[i]);
91 err_[i] = 0.5*dx*(err_[i] - dydx0[i]);
92 }
93
94 return normalizeError(y0, y, err_);
95}
96
97
99(
100 scalar& x,
101 scalarField& y,
102 scalar& dxTry
103) const
104{
105 adaptiveSolver::solve(odes_, x, y, dxTry);
106}
107
108
109// ************************************************************************* //
scalar y
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Abstract base-class for ODE system solvers.
Definition ODESolver.H:53
scalar normalizeError(const scalarField &y0, const scalarField &y, const scalarField &err) const
Return the nomalized scalar error.
Definition ODESolver.C:36
ODESolver(const ODESolver &)=delete
No copy construct.
label n_
Size of the ODESystem (adjustable).
Definition ODESolver.H:71
const ODESystem & odes_
Reference to ODESystem.
Definition ODESolver.H:61
virtual bool resize()=0
Resize the ODE solver.
Definition ODESolver.C:85
friend class ODESystem
Definition ODESolver.H:114
static void resizeField(UList< Type > &f, const label n)
Definition ODESolverI.H:24
Abstract base class for the systems of ordinary differential equations.
Definition ODESystem.H:44
Trapezoidal ODE solver of order (1)2.
Definition Trapezoid.H:55
virtual bool resize()
Resize the ODE solver.
Definition Trapezoid.C:46
Trapezoid(const ODESystem &ode, const dictionary &dict)
Construct from ODESystem.
Definition Trapezoid.C:36
virtual scalar solve(const scalar x0, const scalarField &y0, const scalarField &dydx0, const scalar dx, scalarField &y) const
Solve a single step dx and return the error.
Definition Trapezoid.C:62
adaptiveSolver(const ODESystem &ode, const dictionary &dict)
Construct from ODESystem.
bool resize(const label n)
Resize the ODE solver.
virtual scalar solve(const scalar x0, const scalarField &y0, const scalarField &dydx0, const scalar dx, scalarField &y) const =0
Solve a single step dx and return the error.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
An ODE solver for chemistry.
Definition ode.H:51
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
Namespace for OpenFOAM.
dimensionedScalar y0(const dimensionedScalar &ds)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299