Loading...
Searching...
No Matches
quadraticEqn.H
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) 2017 OpenFOAM Foundation
9 Copyright (C) 2020 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
27Class
28 Foam::quadraticEqn
29
30Description
31 Container to encapsulate various operations for
32 quadratic equation of the forms with real coefficients:
33
34 \f[
35 a*x^2 + b*x + c = 0
36 x^2 + B*x + C = 0
37 \f]
38
39 The expressions for the roots of \c quadraticEqn are as follows:
40
41 \f[
42 x1 = - (b + sign(b) sqrt(b^2 - 4ac)/(2*a))
43
44 x2 = c/(a*x1)
45 \f]
46
47 where \c (b^2 - 4ac) is evaluated by fused multiply-adds to avoid
48 detrimental cancellation.
49
50 Reference:
51 \verbatim
52 Cancellation-avoiding quadratic formula (tag:F):
53 Ford, W. (2014).
54 Numerical linear algebra with applications: Using MATLAB.
55 London: Elsevier/Academic Press.
56 DOI:10.1016/C2011-0-07533-6
57
58 Kahan's algo. to compute 'b^2-a*c' using fused multiply-adds (tag:JML):
59 Jeannerod, C. P., Louvet, N., & Muller, J. M. (2013).
60 Further analysis of Kahan's algorithm for the accurate
61 computation of 2× 2 determinants.
62 Mathematics of Computation, 82(284), 2245-2264.
63 DOI:10.1090/S0025-5718-2013-02679-8
64 \endverbatim
65
66See also
67 Test-quadraticEqn.C
68
69SourceFiles
70 quadraticEqnI.H
71 quadraticEqn.C
72
73\*---------------------------------------------------------------------------*/
74
75#ifndef Foam_quadraticEqn_H
76#define Foam_quadraticEqn_H
77
78#include "Roots.H"
79
80// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81
82namespace Foam
83{
85/*---------------------------------------------------------------------------*\
86 Class quadraticEqn Declaration
87\*---------------------------------------------------------------------------*/
88
89class quadraticEqn
90:
91 public VectorSpace<quadraticEqn, scalar, 3>
92{
93public:
94
95 //- Component labeling enumeration
96 enum components { A, B, C };
97
98
99 // Constructors
100
101 //- Default construct
102 quadraticEqn() = default;
103
104 //- Construct initialized to zero
105 inline quadraticEqn(const Foam::zero);
106
107 //- Construct from components
108 inline quadraticEqn(const scalar a, const scalar b, const scalar c);
109
110
111 // Member Functions
112
113 // Access
114
115 scalar a() const noexcept { return this->v_[A]; }
116 scalar b() const noexcept { return this->v_[B]; }
117 scalar c() const noexcept { return this->v_[C]; }
119 scalar& a() noexcept { return this->v_[A]; }
120 scalar& b() noexcept { return this->v_[B]; }
121 scalar& c() noexcept { return this->v_[C]; }
124 // Evaluate
125
126 //- Evaluate the quadratic equation at x
127 inline scalar value(const scalar x) const;
128
129 //- Evaluate the derivative of the quadratic equation at x
130 inline scalar derivative(const scalar x) const;
131
132 //- Estimate the error of evaluation of the quadratic equation at x
133 inline scalar error(const scalar x) const;
134
135 //- Return the roots of the quadratic equation with no particular order
136 // if discriminant > 0: return two distinct real roots
137 // if discriminant < 0: return one of the complex conjugate-pair roots
138 // otherwise : return two identical real roots
139 Roots<2> roots() const;
140};
141
142
143// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144
145} // End namespace Foam
146
147// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148
149#include "quadraticEqnI.H"
150
151// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152
153#endif
154
155// ************************************************************************* //
static const Foam::dimensionedScalar C("", Foam::dimTemperature, 234.5)
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
Graphite solid properties.
Definition C.H:49
Templated storage for the roots of polynomial equations, plus flags to indicate the nature of the roo...
Definition Roots.H:71
scalar c() const noexcept
components
Component labeling enumeration.
scalar & a() noexcept
scalar value(const scalar x) const
Evaluate the quadratic equation at x.
scalar & b() noexcept
scalar derivative(const scalar x) const
Evaluate the derivative of the quadratic equation at x.
scalar a() const noexcept
quadraticEqn()=default
Default construct.
Roots< 2 > roots() const
Return the roots of the quadratic equation with no particular order.
scalar b() const noexcept
scalar error(const scalar x) const
Estimate the error of evaluation of the quadratic equation at x.
scalar & c() noexcept
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265