floatScalar.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-2018 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::floatScalar
26 
27 Description
28  Float precision floating point scalar type.
29 
30 SourceFiles
31  floatScalar.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef floatScalar_H
36 #define floatScalar_H
37 
38 #include "doubleFloat.H"
39 #include "direction.H"
40 #include "word.H"
41 
42 #include <limits>
43 using std::numeric_limits;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 typedef float floatScalar;
53 
54 // Largest and smallest scalar values allowed in certain parts of the code
55 static const floatScalar floatScalarVGreat = numeric_limits<float>::max()/10;
56 static const floatScalar floatScalarVSmall = numeric_limits<float>::min();
57 
58 static const floatScalar floatScalarSmall = numeric_limits<float>::epsilon();
59 static const floatScalar floatScalarGreat = 1.0/floatScalarSmall;
60 
61 static const floatScalar floatScalarRootVGreat = ::sqrt(floatScalarVGreat);
62 static const floatScalar floatScalarRootVSmall = ::sqrt(floatScalarVSmall);
63 
64 static const floatScalar floatScalarRootGreat = ::sqrt(floatScalarGreat);
65 static const floatScalar floatScalarRootSmall = ::sqrt(floatScalarSmall);
66 
67 //- Read whole of buf as a scalar. Return true if successful.
68 inline bool readScalar(const char* buf, floatScalar& s)
69 {
70  char* endPtr;
71  s = strtof(buf, &endPtr);
72 
73  return (*endPtr == '\0');
74 }
75 
76 #define Scalar floatScalar
77 #define ScalarVGreat floatScalarVGreat
78 #define ScalarVSmall floatScalarVSmall
79 #define ScalarRootVGreat floatScalarRootVGreat
80 #define ScalarRootVSmall floatScalarRootVSmall
81 #define readScalar readFloatScalar
82 
83 inline Scalar mag(const Scalar s)
84 {
85  return ::fabsf(s);
86 }
87 
88 
89 #define MAXMINPOW(retType, type1, type2) \
90  \
91 MAXMIN(retType, type1, type2) \
92  \
93 inline double pow(const type1 s, const type2 e) \
94 { \
95  return ::powf(s, e); \
96 }
97 
99 MAXMINPOW(Scalar, Scalar, int)
100 MAXMINPOW(Scalar, int, Scalar)
101 MAXMINPOW(Scalar, Scalar, long)
102 MAXMINPOW(Scalar, long, Scalar)
103 
104 #undef MAXMINPOW
105 
106 
107 #define transFunc(func) \
108 inline Scalar func(const Scalar s) \
109 { \
110  return ::func##f(s); \
111 }
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 } // End namespace Foam
116 
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
118 
119 #include "Scalar.H"
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 namespace Foam
124 {
125 
126 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
127 
128 inline Scalar hypot(const Scalar x, const Scalar y)
129 {
130  return ::hypotf(x, y);
131 }
132 
133 inline Scalar atan2(const Scalar y, const Scalar x)
134 {
135  return ::atan2f(y, x);
136 }
137 
138 inline Scalar jn(const int n, const Scalar s)
139 {
140  return ::jnf(n, s);
141 }
142 
143 inline Scalar yn(const int n, const Scalar s)
144 {
145  return ::ynf(n, s);
146 }
147 
148 #undef Scalar
149 #undef ScalarVGreat
150 #undef ScalarVSmall
151 #undef ScalarRootVGreat
152 #undef ScalarRootVSmall
153 #undef readScalar
154 #undef transFunc
155 
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #endif
164 
165 // ************************************************************************* //
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionedScalar yn(const int n, const dimensionedScalar &ds)
dimensionedScalar sqrt(const dimensionedScalar &ds)
scalar y
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define MAXMINPOW(retType, type1, type2)
Definition: floatScalar.H:89
dimensionedScalar jn(const int n, const dimensionedScalar &ds)
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:68
#define Scalar
Definition: floatScalar.H:76
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Direction is an 8-bit unsigned integer type used to represent the Cartesian directions etc...
scalar epsilon
dimensioned< scalar > mag(const dimensioned< Type > &)
label n
static const floatScalar floatScalarSmall
Definition: floatScalar.H:58
dimensionedScalar hypot(const dimensionedScalar &x, const dimensionedScalar &y)
Namespace for OpenFOAM.