Scalar.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
00037
00038
00039 template<>
00040 class pTraits<Scalar>
00041 {
00042 Scalar p_;
00043
00044 public:
00045
00046
00047 typedef Scalar cmptType;
00048
00049
00050
00051 enum
00052 {
00053 dim = 3,
00054 rank = 0,
00055 nComponents = 1
00056 };
00057
00058
00059
00060 static const char* const typeName;
00061 static const char* componentNames[];
00062 static const Scalar zero;
00063 static const Scalar one;
00064 static const Scalar max;
00065 static const Scalar min;
00066
00067
00068
00069
00070 pTraits(Istream&);
00071
00072
00073
00074
00075 operator Scalar() const
00076 {
00077 return p_;
00078 }
00079 };
00080
00081
00082
00083
00084
00085 word name(const Scalar);
00086
00087
00088 inline Scalar& setComponent(Scalar& s, const direction)
00089 {
00090 return s;
00091 }
00092
00093 inline Scalar component(const Scalar s, const direction)
00094 {
00095 return s;
00096 }
00097
00098 inline Scalar sign(const Scalar s)
00099 {
00100 return (s >= 0)? 1: -1;
00101 }
00102
00103 inline Scalar pos(const Scalar s)
00104 {
00105 return (s >= 0)? 1: 0;
00106 }
00107
00108 inline Scalar neg(const Scalar s)
00109 {
00110 return (s < 0)? 1: 0;
00111 }
00112
00113 inline bool equal(const Scalar& s1, const Scalar& s2)
00114 {
00115 return mag(s1 - s2) <= ScalarVSMALL;
00116 }
00117
00118 inline bool notEqual(const Scalar s1, const Scalar s2)
00119 {
00120 return mag(s1 - s2) > ScalarVSMALL;
00121 }
00122
00123 inline Scalar limit(const Scalar s1, const Scalar s2)
00124 {
00125 return (mag(s1) < mag(s2)) ? s1: 0.0;
00126 }
00127
00128 inline Scalar minMod(const Scalar s1, const Scalar s2)
00129 {
00130 return (mag(s1) < mag(s2)) ? s1: s2;
00131 }
00132
00133 inline Scalar magSqr(const Scalar s)
00134 {
00135 return s*s;
00136 }
00137
00138 inline Scalar sqr(const Scalar s)
00139 {
00140 return s*s;
00141 }
00142
00143 inline Scalar sqrtSumSqr(const Scalar a, const Scalar b)
00144 {
00145 Scalar maga = mag(a);
00146 Scalar magb = mag(b);
00147
00148 if (maga > magb)
00149 {
00150 return maga*sqrt(1.0 + sqr(magb/maga));
00151 }
00152 else
00153 {
00154 return magb < ScalarVSMALL ? 0.0 : magb*sqrt(1.0 + sqr(maga/magb));
00155 }
00156 }
00157
00158 inline Scalar pow3(const Scalar s)
00159 {
00160 return s*sqr(s);
00161 }
00162
00163 inline Scalar pow4(const Scalar s)
00164 {
00165 return sqr(sqr(s));
00166 }
00167
00168 inline Scalar pow5(const Scalar s)
00169 {
00170 return s*pow4(s);
00171 }
00172
00173 inline Scalar pow6(const Scalar s)
00174 {
00175 return pow3(sqr(s));
00176 }
00177
00178 inline Scalar inv(const Scalar s)
00179 {
00180 return 1.0/s;
00181 }
00182
00183 inline Scalar dot(const Scalar s1, const Scalar s2)
00184 {
00185 return s1*s2;
00186 }
00187
00188 inline Scalar cmptMultiply(const Scalar s1, const Scalar s2)
00189 {
00190 return s1*s2;
00191 }
00192
00193 inline Scalar cmptDivide(const Scalar s1, const Scalar s2)
00194 {
00195 return s1/s2;
00196 }
00197
00198 inline Scalar cmptMax(const Scalar s)
00199 {
00200 return s;
00201 }
00202
00203 inline Scalar cmptMin(const Scalar s)
00204 {
00205 return s;
00206 }
00207
00208 inline Scalar cmptAv(const Scalar s)
00209 {
00210 return s;
00211 }
00212
00213 inline Scalar cmptMag(const Scalar s)
00214 {
00215 return mag(s);
00216 }
00217
00218
00219
00220 transFunc(sqrt)
00221 transFunc(cbrt)
00222 transFunc(exp)
00223 transFunc(log)
00224 transFunc(log10)
00225 transFunc(sin)
00226 transFunc(cos)
00227 transFunc(tan)
00228 transFunc(asin)
00229 transFunc(acos)
00230 transFunc(atan)
00231 transFunc(sinh)
00232 transFunc(cosh)
00233 transFunc(tanh)
00234 transFunc(asinh)
00235 transFunc(acosh)
00236 transFunc(atanh)
00237
00238
00239
00240 transFunc(erf)
00241 transFunc(erfc)
00242 transFunc(lgamma)
00243
00244 transFunc(j0)
00245 transFunc(j1)
00246
00247 transFunc(y0)
00248 transFunc(y1)
00249
00250
00251
00252 inline Scalar stabilise(const Scalar s, const Scalar small)
00253 {
00254 if (s >= 0)
00255 {
00256 return s + small;
00257 }
00258 else
00259 {
00260 return s - small;
00261 }
00262 }
00263
00264
00265
00266
00267 Scalar readScalar(Istream&);
00268 Istream& operator>>(Istream&, Scalar&);
00269 Ostream& operator<<(Ostream&, const Scalar);
00270
00271
00272
Copyright © 2000-2009 OpenCFD Ltd