floatScalar.H
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef floatScalar_H
00037 #define floatScalar_H
00038
00039 #include "label.H"
00040 #include "word.H"
00041
00042 #include <cmath>
00043
00044 #ifdef ibm
00045 float lgamma(float);
00046 #endif
00047
00048
00049
00050
00051 namespace Foam
00052 {
00053 typedef float floatScalar;
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #include "pTraits.H"
00076 #include "products.H"
00077 #include "direction.H"
00078
00079 namespace Foam
00080 {
00081
00082
00083
00084
00085 template<>
00086 class pTraits<floatScalar>
00087 {
00088 floatScalar p_;
00089
00090 public:
00091
00092
00093 typedef floatScalar cmptType;
00094
00095
00096
00097 enum
00098 {
00099 dim = 3,
00100 rank = 0,
00101 nComponents = 1
00102 };
00103
00104
00105
00106 static const char* const typeName;
00107 static const char* componentNames[];
00108 static const floatScalar zero;
00109 static const floatScalar one;
00110
00111
00112
00113
00114 pTraits(Istream& is);
00115
00116
00117
00118 operator floatScalar() const
00119 {
00120 return p_;
00121 }
00122 };
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 word name(const floatScalar s)
00140 {
00141 return name(scalar(s));
00142 }
00143
00144 #define MAXMINPOW(retType, type1, type2) \
00145 \
00146 MAXMIN(retType, type1, type2) \
00147 \
00148 inline float pow(const type1 s, const type2 e) \
00149 { \
00150 return ::pow(float(s), float(e)); \
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 #undef MAXMINPOW
00165
00166
00167 inline floatScalar mag(const floatScalar s)
00168 {
00169 return ::fabs(s);
00170 }
00171
00172 inline floatScalar sign(const floatScalar s)
00173 {
00174 return (s >= 0)? 1: -1;
00175 }
00176
00177 inline floatScalar pos(const floatScalar s)
00178 {
00179 return (s >= 0)? 1: 0;
00180 }
00181
00182 inline floatScalar neg(const floatScalar s)
00183 {
00184 return (s < 0)? 1: 0;
00185 }
00186
00187 inline floatScalar limit(const floatScalar s1, const floatScalar s2)
00188 {
00189 return (mag(s1) < mag(s2))? s1: 0.0;
00190 }
00191
00192 inline floatScalar magSqr(const floatScalar s)
00193 {
00194 return s*s;
00195 }
00196
00197 inline floatScalar sqr(const floatScalar s)
00198 {
00199 return s*s;
00200 }
00201
00202 inline floatScalar pow3(const floatScalar s)
00203 {
00204 return s*s*s;
00205 }
00206
00207 inline floatScalar pow4(const floatScalar s)
00208 {
00209 return sqr(sqr(s));
00210 }
00211
00212 inline floatScalar cmptAv(const floatScalar s)
00213 {
00214 return s;
00215 }
00216
00217 inline floatScalar cmptMag(const floatScalar s)
00218 {
00219 return mag(s);
00220 }
00221
00222 inline floatScalar scale(const floatScalar s, const floatScalar d)
00223 {
00224 return s*d;
00225 }
00226
00227
00228 #define transFunc(func) \
00229 inline floatScalar func(const floatScalar s) \
00230 { \
00231 return ::func(s); \
00232 }
00233
00234
00235 transFunc(sqrt)
00236 transFunc(exp)
00237 transFunc(log)
00238 transFunc(log10)
00239 transFunc(sin)
00240 transFunc(cos)
00241 transFunc(tan)
00242 transFunc(asin)
00243 transFunc(acos)
00244 transFunc(atan)
00245 transFunc(sinh)
00246 transFunc(cosh)
00247 transFunc(tanh)
00248 transFunc(asinh)
00249 transFunc(acosh)
00250 transFunc(atanh)
00251
00252
00253 transFunc(erf)
00254 transFunc(erfc)
00255 transFunc(lgamma)
00256 transFunc(j0)
00257 transFunc(j1)
00258 transFunc(y0)
00259 transFunc(y1)
00260
00261 #undef transFunc
00262
00263
00264 inline floatScalar stabilise(const floatScalar s, const floatScalar small)
00265 {
00266 if (s >= 0)
00267 {
00268 return s + small;
00269 }
00270 else
00271 {
00272 return s - small;
00273 }
00274 }
00275
00276
00277
00278
00279
00280 Istream& operator>>(Istream&, floatScalar&);
00281 Ostream& operator<<(Ostream&, const floatScalar);
00282
00283
00284
00285 }
00286
00287
00288
00289 #endif
00290
00291
Copyright © 2000-2009 OpenCFD Ltd