linearEqnI.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
27\*---------------------------------------------------------------------------*/
28
29// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30
32{}
33
34
36:
37 VectorSpace<linearEqn, scalar, 2>(Foam::zero{})
38{}
39
40
41inline Foam::linearEqn::linearEqn(const scalar a, const scalar b)
42{
43 this->v_[A] = a;
44 this->v_[B] = b;
45}
46
47
48// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49
50inline Foam::scalar Foam::linearEqn::a() const
51{
52 return this->v_[A];
53}
54
55
56inline Foam::scalar Foam::linearEqn::b() const
57{
58 return this->v_[B];
59}
60
61
62inline Foam::scalar& Foam::linearEqn::a()
63{
64 return this->v_[A];
65}
66
67
68inline Foam::scalar& Foam::linearEqn::b()
69{
70 return this->v_[B];
71}
72
73
74inline Foam::scalar Foam::linearEqn::value(const scalar x) const
75{
76 return x*a() + b();
77}
78
79
80inline Foam::scalar Foam::linearEqn::derivative(const scalar x) const
81{
82 return a();
83}
84
85
86inline Foam::scalar Foam::linearEqn::error(const scalar x) const
87{
88 return SMALL*(mag(x*a()) + mag(b()));
89}
90
91
93{
94 const scalar a = this->a();
95 const scalar b = this->b();
96
97 if (mag(a) < VSMALL)
98 {
99 return Roots<1>(roots::nan, 0);
100 }
101 else if (mag(b/VGREAT) >= mag(a))
102 {
103 return Roots<1>(sign(a) == sign(b) ? roots::negInf : roots::posInf, 0);
104 }
105
106 return Roots<1>(roots::real, -b/a);
107}
108
109
110// ************************************************************************* //
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
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 linear equation of the forms with real coefficients:
Definition: linearEqn.H:63
linearEqn()
Construct null.
Definition: linearEqnI.H:31
scalar value(const scalar x) const
Evaluate the linear equation at x.
Definition: linearEqnI.H:74
scalar derivative(const scalar x) const
Evaluate the derivative of the linear equation at x.
Definition: linearEqnI.H:80
Roots< 1 > roots() const
Return the real root of the linear equation.
Definition: linearEqnI.H:92
scalar a() const
Definition: linearEqnI.H:50
scalar b() const
Definition: linearEqnI.H:56
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
@ posInf
Definition: Roots.H:58
@ real
Definition: Roots.H:56
@ negInf
Definition: Roots.H:59
Namespace for OpenFOAM.
dimensionedScalar sign(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
volScalarField & b
Definition: createFields.H:27