All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
specieExponentI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "specieExponent.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 inline bool Foam::specieExponent::hasIntegerExponent() const
31 {
32  return integerExponent_ != noIntegerExponent_;
33 }
34 
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
39 :
40  integerExponent_(noIntegerExponent_),
41  scalarExponent_(NaN)
42 {}
43 
44 
45 inline Foam::specieExponent::specieExponent(const label integerExponent)
46 :
47  integerExponent_(integerExponent),
48  scalarExponent_(integerExponent)
49 {}
50 
51 
52 inline Foam::specieExponent::specieExponent(const scalar scalarExponent)
53 :
54  integerExponent_(labelMax),
55  scalarExponent_(scalarExponent)
56 {
57  const label integerExponent = floor(scalarExponent);
58  if (integerExponent == scalarExponent)
59  {
60  integerExponent_ = integerExponent;
61  }
62 }
63 
64 
65 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
66 
67 inline Foam::specieExponent::operator scalar() const
68 {
69  return scalarExponent_;
70 }
71 
72 
74 Foam::specieExponent::operator=(const label integerExponent)
75 {
76  return *this = specieExponent(integerExponent);
77 }
78 
79 
81 Foam::specieExponent::operator=(const scalar scalarExponent)
82 {
83  return *this = specieExponent(scalarExponent);
84 }
85 
86 
88 {
89  if (hasIntegerExponent())
90  {
91  return -integerExponent_;
92  }
93  else
94  {
95  return -scalarExponent_;
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
101 
102 inline Foam::scalar Foam::pow(const scalar x, const specieExponent& e)
103 {
104  if (e.hasIntegerExponent())
105  {
106  if (e.integerExponent_ == 0)
107  {
108  return 1;
109  }
110  else
111  {
112  scalar xx = e.integerExponent_ > 0 ? x : 1/x;
113 
114  scalar y = 1;
115 
116  for (label i = e.integerExponent_; i != 0; i /= 2)
117  {
118  if (i % 2)
119  {
120  y *= xx;
121  }
122 
123  xx *= xx;
124  }
125 
126  return y;
127  }
128  }
129  else
130  {
131  return pow(x, e.scalarExponent_);
132  }
133 }
134 
135 
136 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
137 
138 inline Foam::specieExponent Foam::operator+
139 (
140  const specieExponent& a,
141  const specieExponent& b
142 )
143 {
144  if (a.hasIntegerExponent() && b.hasIntegerExponent())
145  {
146  return a.integerExponent_ + b.integerExponent_;
147  }
148  else
149  {
150  return a.scalarExponent_ + b.scalarExponent_;
151  }
152 }
153 
154 
155 inline Foam::specieExponent Foam::operator-
156 (
157  const specieExponent& a,
158  const specieExponent& b
159 )
160 {
161  return a + (-b);
162 }
163 
164 
165 // * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
166 
168 {
169  os << e.operator scalar();
170  return os;
171 }
172 
173 
174 // ************************************************************************* //
specieExponent & operator=(const label integerExponent)
Assign to integer.
specieExponent operator-() const
Negate a specie exponent.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
friend scalar pow(const scalar x, const specieExponent &e)
Compute the power of a number to a specie exponent.
scalar y
specieExponent()
Construct null.
static const label labelMax
Definition: label.H:62
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Ostream & operator<<(Ostream &, const ensightPart &)
const doubleScalar e
Elementary charge.
Definition: doubleScalar.H:105