2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2010-05-12 13:27:55 +00:00
|
|
|
\\ / O peration |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / A nd | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
\\/ M anipulation |
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Typedef
|
|
|
|
Foam::floatScalar
|
|
|
|
|
|
|
|
Description
|
|
|
|
single floating point number identical to float
|
|
|
|
|
|
|
|
SourceFiles
|
|
|
|
floatScalar.C
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#ifndef floatScalar_H
|
|
|
|
#define floatScalar_H
|
|
|
|
|
|
|
|
#include "label.H"
|
|
|
|
#include "word.H"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#ifdef ibm
|
|
|
|
float lgamma(float);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
// Define floatScalar as a float
|
|
|
|
|
|
|
|
namespace Foam
|
|
|
|
{
|
|
|
|
typedef float floatScalar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
// Define floatScalar as a float
|
|
|
|
|
|
|
|
namespace Foam
|
|
|
|
{
|
|
|
|
typedef float floatScalar;
|
|
|
|
|
|
|
|
// Largest and smallest floatScalar values allowed in certain parts of the code
|
|
|
|
// (6 is the number of significant figures in an
|
|
|
|
// IEEE single precision number. See limits.h or float.h)
|
|
|
|
static const floatScalar GREAT = 1.0e+6;
|
|
|
|
static const floatScalar VGREAT = 1.0e+37;
|
|
|
|
static const floatScalar SMALL = 1.0e-6;
|
|
|
|
static const floatScalar VSMALL = 1.0e-37;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
#include "pTraits.H"
|
|
|
|
#include "products.H"
|
|
|
|
#include "direction.H"
|
|
|
|
|
|
|
|
namespace Foam
|
|
|
|
{
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
// template specialisation for pTraits<floatScalar>
|
|
|
|
template<>
|
|
|
|
class pTraits<floatScalar>
|
|
|
|
{
|
|
|
|
floatScalar p_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
//- Component type
|
|
|
|
typedef floatScalar cmptType;
|
|
|
|
|
|
|
|
// Member constants
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
dim = 3, // Dimensionality of space
|
|
|
|
rank = 0, // Rank od floatScalar is 0
|
|
|
|
nComponents = 1 // Number of components in floatScalar is 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// Static data members
|
|
|
|
|
|
|
|
static const char* const typeName;
|
|
|
|
static const char* componentNames[];
|
|
|
|
static const floatScalar zero;
|
|
|
|
static const floatScalar one;
|
|
|
|
|
|
|
|
// Constructors
|
|
|
|
|
|
|
|
//- Construct from Istream
|
|
|
|
pTraits(Istream& is);
|
|
|
|
|
|
|
|
// Member Functions
|
|
|
|
|
|
|
|
operator floatScalar() const
|
|
|
|
{
|
|
|
|
return p_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
//template<class Cmpt>
|
|
|
|
//class typeOfRank<Cmpt, 0>
|
|
|
|
//{
|
|
|
|
//public:
|
|
|
|
//
|
|
|
|
// typedef Cmpt type;
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
// Return a string representation of a floatScalar
|
|
|
|
word name(const floatScalar s)
|
|
|
|
{
|
|
|
|
return name(scalar(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAXMINPOW(retType, type1, type2) \
|
|
|
|
\
|
|
|
|
MAXMIN(retType, type1, type2) \
|
|
|
|
\
|
|
|
|
inline float pow(const type1 s, const type2 e) \
|
|
|
|
{ \
|
|
|
|
return ::pow(float(s), float(e)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//MAXMINPOW(float, float, float)
|
|
|
|
//MAXMINPOW(float, float, int)
|
|
|
|
//MAXMINPOW(float, int, float)
|
|
|
|
//MAXMINPOW(float, float, long)
|
|
|
|
//MAXMINPOW(float, long, float)
|
|
|
|
//MAXMINPOW(float, float, int)
|
|
|
|
//MAXMINPOW(float, int, float)
|
|
|
|
//MAXMINPOW(float, float, long)
|
|
|
|
//MAXMINPOW(float, long, float)
|
|
|
|
|
|
|
|
#undef MAXMINPOW
|
|
|
|
|
|
|
|
|
|
|
|
inline floatScalar mag(const floatScalar s)
|
|
|
|
{
|
|
|
|
return ::fabs(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar sign(const floatScalar s)
|
|
|
|
{
|
|
|
|
return (s >= 0)? 1: -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar pos(const floatScalar s)
|
|
|
|
{
|
|
|
|
return (s >= 0)? 1: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar neg(const floatScalar s)
|
|
|
|
{
|
|
|
|
return (s < 0)? 1: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar limit(const floatScalar s1, const floatScalar s2)
|
|
|
|
{
|
|
|
|
return (mag(s1) < mag(s2))? s1: 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar magSqr(const floatScalar s)
|
|
|
|
{
|
|
|
|
return s*s;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar sqr(const floatScalar s)
|
|
|
|
{
|
|
|
|
return s*s;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar pow3(const floatScalar s)
|
|
|
|
{
|
|
|
|
return s*s*s;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar pow4(const floatScalar s)
|
|
|
|
{
|
|
|
|
return sqr(sqr(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar cmptAv(const floatScalar s)
|
|
|
|
{
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar cmptMag(const floatScalar s)
|
|
|
|
{
|
|
|
|
return mag(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline floatScalar scale(const floatScalar s, const floatScalar d)
|
|
|
|
{
|
|
|
|
return s*d;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define transFunc(func) \
|
|
|
|
inline floatScalar func(const floatScalar s) \
|
|
|
|
{ \
|
|
|
|
return ::func(s); \
|
|
|
|
}
|
|
|
|
|
|
|
|
// Standard C++ transcendental functions
|
|
|
|
transFunc(sqrt)
|
|
|
|
transFunc(exp)
|
|
|
|
transFunc(log)
|
|
|
|
transFunc(log10)
|
|
|
|
transFunc(sin)
|
|
|
|
transFunc(cos)
|
|
|
|
transFunc(tan)
|
|
|
|
transFunc(asin)
|
|
|
|
transFunc(acos)
|
|
|
|
transFunc(atan)
|
|
|
|
transFunc(sinh)
|
|
|
|
transFunc(cosh)
|
|
|
|
transFunc(tanh)
|
|
|
|
transFunc(asinh)
|
|
|
|
transFunc(acosh)
|
|
|
|
transFunc(atanh)
|
|
|
|
|
|
|
|
// Standard ANSI-C (but not in <cmath>) transcendental functions
|
|
|
|
transFunc(erf)
|
|
|
|
transFunc(erfc)
|
|
|
|
transFunc(lgamma)
|
|
|
|
transFunc(j0)
|
|
|
|
transFunc(j1)
|
|
|
|
transFunc(y0)
|
|
|
|
transFunc(y1)
|
|
|
|
|
|
|
|
#undef transFunc
|
|
|
|
|
|
|
|
// Stabilisation around zero for division
|
|
|
|
inline floatScalar stabilise(const floatScalar s, const floatScalar small)
|
|
|
|
{
|
|
|
|
if (s >= 0)
|
|
|
|
{
|
|
|
|
return s + small;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return s - small;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
//floatScalar readScalar(Istream& is);
|
|
|
|
Istream& operator>>(Istream&, floatScalar&);
|
|
|
|
Ostream& operator<<(Ostream&, const floatScalar);
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
} // End namespace Foam
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ************************************************************************* //
|