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 quadraticEqn_H
76#define quadraticEqn_H
77
78#include "Roots.H"
79
80// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
81
82namespace Foam
83{
84
85/*---------------------------------------------------------------------------*\
86 Class quadraticEqn Declaration
87\*---------------------------------------------------------------------------*/
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 //- Construct null
102 inline quadraticEqn();
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 inline scalar a() const;
116 inline scalar b() const;
117 inline scalar c() const;
118
119 inline scalar& a();
120 inline scalar& b();
121 inline scalar& c();
122
123 // Evaluate
124
125 //- Evaluate the quadratic equation at x
126 inline scalar value(const scalar x) const;
127
128 //- Evaluate the derivative of the quadratic equation at x
129 inline scalar derivative(const scalar x) const;
130
131 //- Estimate the error of evaluation of the quadratic equation at x
132 inline scalar error(const scalar x) const;
133
134 //- Return the roots of the quadratic equation with no particular order
135 // if discriminant > 0: return two distinct real roots
136 // if discriminant < 0: return one of the complex conjugate-pair roots
137 // otherwise : return two identical real roots
138 Roots<2> roots() const;
139};
140
141
142// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143
144} // End namespace Foam
145
146// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147
148#include "quadraticEqnI.H"
149
150// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151
152#endif
153
154// ************************************************************************* //
Graphite solid properties.
Definition: C.H:53
Templated storage for the roots of polynomial equations, plus flags to indicate the nature of the roo...
Definition: Roots.H:73
Templated vector space.
Definition: VectorSpace.H:79
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:77
Container to encapsulate various operations for quadratic equation of the forms with real coefficient...
Definition: quadraticEqn.H:91
components
Component labeling enumeration.
Definition: quadraticEqn.H:95
scalar value(const scalar x) const
Evaluate the quadratic equation at x.
Definition: quadraticEqnI.H:91
scalar c() const
Definition: quadraticEqnI.H:67
scalar derivative(const scalar x) const
Evaluate the derivative of the quadratic equation at x.
Definition: quadraticEqnI.H:97
Roots< 2 > roots() const
Return the roots of the quadratic equation with no particular order.
Definition: quadraticEqn.C:34
scalar a() const
Definition: quadraticEqnI.H:55
scalar b() const
Definition: quadraticEqnI.H:61
quadraticEqn()
Construct null.
Definition: quadraticEqnI.H:30
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
Namespace for OpenFOAM.