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-2023 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  return integerPow(x, e.integerExponent_);
107  }
108  else
109  {
110  return pow(x, e.scalarExponent_);
111  }
112 }
113 
114 
115 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
116 
117 inline Foam::specieExponent Foam::operator+
118 (
119  const specieExponent& a,
120  const specieExponent& b
121 )
122 {
123  if (a.hasIntegerExponent() && b.hasIntegerExponent())
124  {
125  return a.integerExponent_ + b.integerExponent_;
126  }
127  else
128  {
129  return a.scalarExponent_ + b.scalarExponent_;
130  }
131 }
132 
133 
134 inline Foam::specieExponent Foam::operator-
135 (
136  const specieExponent& a,
137  const specieExponent& b
138 )
139 {
140  return a + (-b);
141 }
142 
143 
144 // * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
145 
147 {
148  os << e.operator scalar();
149  return os;
150 }
151 
152 
153 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Type for exponents of species in reaction. Can take either integer or scalar value,...
specieExponent()
Construct null.
specieExponent & operator=(const label integerExponent)
Assign to integer.
specieExponent operator-() const
Negate a specie exponent.
volScalarField & b
Definition: createFields.H:27
static Type NaN()
Return a primitive with all components set to NaN.
const doubleScalar e
Definition: doubleScalar.H:105
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
Definition: scalarI.H:30
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
static const label labelMax
Definition: label.H:62
Ostream & operator<<(Ostream &, const ensightPart &)