scalar.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) 2011-2026 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 Typedef
25  Foam::scalar
26 
27 Description
28  Single floating point number identical to float or double depending on
29  whether WM_SP, WM_DP or WM_LP is defined.
30 
31 SourceFiles
32  scalar.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef scalar_H
37 #define scalar_H
38 
39 #include "floatScalar.H"
40 #include "doubleScalar.H"
41 #include "longDoubleScalar.H"
42 #include "scaleable.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 #if defined(WM_SP)
47 
48 // Define scalar as a float
49 
50 namespace Foam
51 {
52  typedef floatScalar scalar;
53 
54  static const scalar great = floatScalarGreat;
55  static const scalar rootGreat = floatScalarRootGreat;
56  static const scalar vGreat = floatScalarVGreat;
57  static const scalar rootVGreat = floatScalarRootVGreat;
58  static const scalar small = floatScalarSmall;
59  static const scalar rootSmall = floatScalarRootSmall;
60  static const scalar vSmall = floatScalarVSmall;
61  static const scalar rootVSmall = floatScalarRootVSmall;
62  static const scalar NaN = floatScalarNaN;
63 }
64 
65 #elif defined(WM_DP)
66 
67 // Define scalar as a double
68 
69 namespace Foam
70 {
71  typedef doubleScalar scalar;
72 
73  static const scalar great = doubleScalarGreat;
74  static const scalar rootGreat = doubleScalarRootGreat;
75  static const scalar vGreat = doubleScalarVGreat;
76  static const scalar rootVGreat = doubleScalarRootVGreat;
77  static const scalar small = doubleScalarSmall;
78  static const scalar rootSmall = doubleScalarRootSmall;
79  static const scalar vSmall = doubleScalarVSmall;
80  static const scalar rootVSmall = doubleScalarRootVSmall;
81  static const scalar NaN = doubleScalarNaN;
82 }
83 
84 #elif defined(WM_LP)
85 
86 // Define scalar as a long double
87 
88 namespace Foam
89 {
90  typedef longDoubleScalar scalar;
91 
92  static const scalar great = longDoubleScalarGreat;
93  static const scalar rootGreat = longDoubleScalarRootGreat;
94  static const scalar vGreat = longDoubleScalarVGreat;
95  static const scalar rootVGreat = longDoubleScalarRootVGreat;
96  static const scalar small = longDoubleScalarSmall;
97  static const scalar rootSmall = longDoubleScalarRootSmall;
98  static const scalar vSmall = longDoubleScalarVSmall;
99  static const scalar rootVSmall = longDoubleScalarRootVSmall;
100  static const scalar NaN = longDoubleScalarNaN;
101 }
102 
103 #else
104 
105  #error "Precision not set, please set either WM_SP, WM_DP or WM_LP"
106 
107 #endif
108 
109 //- Deprecated limit constant for backward-compatibility
110 namespace Foam
111 {
112  static const scalar GREAT = great;
113  static const scalar ROOTGREAT = rootGreat;
114  static const scalar VGREAT = vGreat;
115  static const scalar ROOTVGREAT = rootVGreat;
116  static const scalar SMALL = small;
117  static const scalar ROOTSMALL = rootSmall;
118  static const scalar VSMALL = vSmall;
119  static const scalar ROOTVSMALL = rootVSmall;
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 // Additional global and transcendental functions
125 
126 namespace Foam
127 {
128  //- Read a single scalar from an input stream
129  scalar readScalar(Istream& is);
130 
131  //- Normalised upper incomplete gamma function
132  scalar incGammaRatio_Q(const scalar a, const scalar x);
133 
134  //- Normalised lower incomplete gamma function
135  scalar incGammaRatio_P(const scalar a, const scalar x);
136 
137  //- Upper incomplete gamma function
138  scalar incGamma_Q(const scalar a, const scalar x);
139 
140  //- Lower incomplete gamma function
141  scalar incGamma_P(const scalar a, const scalar x);
142 
143  //- Inverse normalised lower incomplete gamma function
144  scalar invIncGammaRatio_P(const scalar a, const scalar P);
145 
146  //- Compute the power of the number x to the integer e
147  inline scalar integerPow(const scalar x, const label e);
148 
149  //- Compute the power of the number x to the reciprocal integer 1/e
150  inline scalar integerRoot(const scalar x, const label e);
151 }
152 
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 // Rank type
156 
157 namespace Foam
158 {
159  template<direction Ncmpts>
160  struct typeOfNcmpts;
161 
162  //- Rank type
163  template<>
164  struct typeOfNcmpts<1>
165  {
166  using type = scalar;
167  };
168 }
169 
170 
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 // Define a scalar to be scaleable
173 
174 namespace Foam
175 {
176  template<>
177  struct scaleable<scalar> : public std::true_type {};
178 }
179 
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 // Enable conditional instantiation for types with a scalar component type
183 
184 namespace Foam
185 {
186  template<class Type, class Void = void>
188  std::enable_if_t
189  <
190  std::is_same
191  <
192  scalar,
193  typename pTraits<Type>::cmptType
194  >::value,
195  Void
196  >;
197 }
198 
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #include "scalarI.H"
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #endif
207 
208 // ************************************************************************* //
Traits class for primitives.
Definition: pTraits.H:53
Namespace for OpenFOAM.
static const doubleScalar doubleScalarRootVGreat
Definition: doubleScalar.H:65
scalar integerRoot(const scalar x, const label e)
Compute the power of the number x to the reciprocal integer 1/e.
Definition: scalarI.H:55
static const longDoubleScalar longDoubleScalarNaN
static const floatScalar floatScalarRootVSmall
Definition: floatScalar.H:66
const doubleScalar e
Definition: doubleScalar.H:106
static const longDoubleScalar longDoubleScalarSmall
static const scalar ROOTSMALL
Definition: scalar.H:117
static const scalar SMALL
Definition: scalar.H:116
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
static const longDoubleScalar longDoubleScalarRootGreat
static const scalar VGREAT
Definition: scalar.H:114
std::enable_if_t< std::is_same< scalar, typename pTraits< Type >::cmptType >::value, Void > enableIfScalarCmptType
Definition: scalar.H:196
scalar incGamma_P(const scalar a, const scalar x)
Lower incomplete gamma function.
Definition: incGamma.C:447
static const longDoubleScalar longDoubleScalarGreat
static const scalar ROOTVGREAT
Definition: scalar.H:115
static const floatScalar floatScalarGreat
Definition: floatScalar.H:63
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
static const doubleScalar doubleScalarSmall
Definition: doubleScalar.H:61
static const doubleScalar doubleScalarNaN
Definition: doubleScalar.H:72
static const floatScalar floatScalarRootVGreat
Definition: floatScalar.H:65
static const scalar ROOTVSMALL
Definition: scalar.H:119
scalar integerPow(const scalar x, const label e)
Compute the power of the number x to the integer e.
Definition: scalarI.H:30
static const longDoubleScalar longDoubleScalarRootVSmall
static const floatScalar floatScalarRootGreat
Definition: floatScalar.H:68
static const longDoubleScalar longDoubleScalarVSmall
static const longDoubleScalar longDoubleScalarRootVGreat
scalar invIncGammaRatio_P(const scalar a, const scalar P)
Inverse normalised lower incomplete gamma function.
Definition: invIncGamma.C:115
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
static const longDoubleScalar longDoubleScalarVGreat
static const doubleScalar doubleScalarRootGreat
Definition: doubleScalar.H:68
static const floatScalar floatScalarRootSmall
Definition: floatScalar.H:69
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
static const doubleScalar doubleScalarGreat
Definition: doubleScalar.H:63
static const scalar VSMALL
Definition: scalar.H:118
static const scalar ROOTGREAT
Definition: scalar.H:113
static const floatScalar floatScalarVSmall
Definition: floatScalar.H:58
scalar incGamma_Q(const scalar a, const scalar x)
Upper incomplete gamma function.
Definition: incGamma.C:441
static const scalar GREAT
Definition: scalar.H:112
scalar incGammaRatio_P(const scalar a, const scalar x)
Normalised lower incomplete gamma function.
Definition: incGamma.C:435
static const floatScalar floatScalarNaN
Definition: floatScalar.H:72
static const doubleScalar doubleScalarVSmall
Definition: doubleScalar.H:58
long double longDoubleScalar
Lang double precision floating point scalar type.
static const floatScalar floatScalarSmall
Definition: floatScalar.H:61
scalar incGammaRatio_Q(const scalar a, const scalar x)
Normalised upper incomplete gamma function.
Definition: incGamma.C:221
static const doubleScalar doubleScalarVGreat
Definition: doubleScalar.H:56
static const doubleScalar doubleScalarRootSmall
Definition: doubleScalar.H:69
static const doubleScalar doubleScalarRootVSmall
Definition: doubleScalar.H:66
static const longDoubleScalar longDoubleScalarRootSmall
static const floatScalar floatScalarVGreat
Definition: floatScalar.H:56
Trait to identify types which are "scaleable"; i.e., that can be multiply-equals-d with a scalar....