OpenFOAM: Added support for extended precision scalar

OpenFOAM can now be compiled with single, double or long double scalars by
setting the WM_PRECISION_OPTION environment variable to either SP, DP or LP
respectively.

On most 64bit systems long double is stored as 128bit but computed in the
floating point hardware to 80bit.  Due to the increased storage compared to
double precision cache and memory access is significantly more time consuming
causing a slow-down of floating point intensive operations by a factor of 2 to
3.
This commit is contained in:
Henry Weller
2018-01-29 15:03:13 +00:00
parent 22bfee0e77
commit d82cc36c5a
37 changed files with 534 additions and 69 deletions

View File

@ -1344,11 +1344,15 @@ void Foam::diameterModels::populationBalanceModel::solve()
d_() = dsm();
}
volScalarField fAlpha0 =
*sizeGroups_.first()*sizeGroups_.first()->phase();
volScalarField fAlpha0
(
*sizeGroups_.first()*sizeGroups_.first()->phase()
);
volScalarField fAlphaN =
*sizeGroups_.last()*sizeGroups_.last()->phase();
volScalarField fAlphaN
(
*sizeGroups_.last()*sizeGroups_.last()->phase()
);
Info<< this->name() << " sizeGroup phase fraction first, last = "
<< fAlpha0.weightedAverage(this->mesh().V()).value()

View File

@ -2,7 +2,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
@ -72,7 +72,7 @@ unset WM_COMPILER_ARCH WM_COMPILER_LIB_ARCH
export WM_ARCH_OPTION=64
#- Precision:
# WM_PRECISION_OPTION = DP | SP
# WM_PRECISION_OPTION = SP | DP | LP
export WM_PRECISION_OPTION=DP
#- Label size:

View File

@ -2,7 +2,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
@ -37,6 +37,7 @@ alias wm64 'wmSet WM_ARCH_OPTION=64'
alias wm32 'wmSet WM_ARCH_OPTION=32'
alias wmSP 'wmSet WM_PRECISION_OPTION=SP'
alias wmDP 'wmSet WM_PRECISION_OPTION=DP'
alias wmLP 'wmSet WM_PRECISION_OPTION=LP'
# Clear env
alias wmUnset 'source $WM_PROJECT_DIR/etc/config.csh/unset'

View File

@ -2,7 +2,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
@ -37,6 +37,7 @@ alias wm64='wmSet WM_ARCH_OPTION=64'
alias wm32='wmSet WM_ARCH_OPTION=32'
alias wmSP='wmSet WM_PRECISION_OPTION=SP'
alias wmDP='wmSet WM_PRECISION_OPTION=DP'
alias wmLP='wmSet WM_PRECISION_OPTION=LP'
# Clear env
alias wmUnset='. $WM_PROJECT_DIR/etc/config.sh/unset'

View File

@ -300,6 +300,7 @@ DebugSwitches
ThermoParcel<fluidThermoParcel> 0;
UMIST 0;
UMISTV 0;
UPstream 0;
UpwindFitData<cubicUpwindFitPolynomial> 0;
UpwindFitData<quadraticLinearUpwindFitPolynomial> 0;
UpwindFitData<quadraticUpwindFitPolynomial> 0;

View File

@ -2,7 +2,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
@ -72,7 +72,7 @@ unsetenv WM_COMPILER_LIB_ARCH
setenv WM_ARCH_OPTION 64
#- Precision:
# WM_PRECISION_OPTION = DP | SP
# WM_PRECISION_OPTION = SP | DP | LP
setenv WM_PRECISION_OPTION DP
#- Label size:

View File

@ -42,6 +42,7 @@ $(ints)/uLabel/uLabel.C
$(ints)/lists/labelIOList.C
$(ints)/lists/labelListIOList.C
primitives/Scalar/longDoubleScalar/longDoubleScalar.C
primitives/Scalar/doubleScalar/doubleScalar.C
primitives/Scalar/floatScalar/floatScalar.C
primitives/Scalar/scalar/scalar.C

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -128,6 +128,9 @@ public:
//- Read a doubleScalar
virtual Istream& read(doubleScalar&) = 0;
//- Read a longDoubleScalar
virtual Istream& read(longDoubleScalar&) = 0;
//- Read binary block
virtual Istream& read(char*, std::streamsize) = 0;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -136,6 +136,9 @@ public:
//- Write doubleScalar
virtual Ostream& write(const doubleScalar) = 0;
//- Write longDoubleScalar
virtual Ostream& write(const longDoubleScalar) = 0;
//- Write binary block
virtual Ostream& write(const char*, std::streamsize) = 0;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -27,6 +27,7 @@ License
#include "UIPstream.H"
#include "int.H"
#include "token.H"
#include <cctype>
@ -243,6 +244,21 @@ Foam::Istream& Foam::UIPstream::read(token& t)
return *this;
}
// longDoubleScalar
case token::LONG_DOUBLE_SCALAR :
{
longDoubleScalar val;
if (read(val))
{
t = val;
}
else
{
t.setBad();
}
return *this;
}
// Character (returned as a single character word) or error
default:
{
@ -313,6 +329,13 @@ Foam::Istream& Foam::UIPstream::read(doubleScalar& val)
}
Foam::Istream& Foam::UIPstream::read(longDoubleScalar& val)
{
readFromBuffer(val);
return *this;
}
Foam::Istream& Foam::UIPstream::read(char* data, std::streamsize count)
{
if (format() != BINARY)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -159,6 +159,9 @@ public:
//- Read a doubleScalar
Istream& read(doubleScalar&);
//- Read a longDoubleScalar
Istream& read(longDoubleScalar&);
//- Read binary block
Istream& read(char*, std::streamsize);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -155,12 +155,12 @@ Foam::Ostream& Foam::UOPstream::write(const token& t)
// Raw token output only supported for verbatim strings for now
if (t.type() == token::VERBATIMSTRING)
{
write(char(token::VERBATIMSTRING));
writeToBuffer(char(token::VERBATIMSTRING));
write(t.stringToken());
}
else if (t.type() == token::VARIABLE)
{
write(char(token::VARIABLE));
writeToBuffer(char(token::VARIABLE));
write(t.stringToken());
}
else
@ -204,7 +204,7 @@ Foam::Ostream& Foam::UOPstream::write(const char* str)
Foam::Ostream& Foam::UOPstream::write(const word& str)
{
write(char(token::WORD));
writeToBuffer(char(token::WORD));
size_t len = str.size();
writeToBuffer(len);
@ -216,7 +216,7 @@ Foam::Ostream& Foam::UOPstream::write(const word& str)
Foam::Ostream& Foam::UOPstream::write(const string& str)
{
write(char(token::STRING));
writeToBuffer(char(token::STRING));
size_t len = str.size();
writeToBuffer(len);
@ -234,11 +234,11 @@ Foam::Ostream& Foam::UOPstream::writeQuoted
{
if (quoted)
{
write(char(token::STRING));
writeToBuffer(char(token::STRING));
}
else
{
write(char(token::WORD));
writeToBuffer(char(token::WORD));
}
size_t len = str.size();
@ -251,7 +251,7 @@ Foam::Ostream& Foam::UOPstream::writeQuoted
Foam::Ostream& Foam::UOPstream::write(const int32_t val)
{
write(char(token::LABEL));
writeToBuffer(char(token::LABEL));
writeToBuffer(val);
return *this;
}
@ -259,7 +259,7 @@ Foam::Ostream& Foam::UOPstream::write(const int32_t val)
Foam::Ostream& Foam::UOPstream::write(const int64_t val)
{
write(char(token::LABEL));
writeToBuffer(char(token::LABEL));
writeToBuffer(val);
return *this;
}
@ -267,7 +267,7 @@ Foam::Ostream& Foam::UOPstream::write(const int64_t val)
Foam::Ostream& Foam::UOPstream::write(const floatScalar val)
{
write(char(token::FLOAT_SCALAR));
writeToBuffer(char(token::FLOAT_SCALAR));
writeToBuffer(val);
return *this;
}
@ -275,7 +275,15 @@ Foam::Ostream& Foam::UOPstream::write(const floatScalar val)
Foam::Ostream& Foam::UOPstream::write(const doubleScalar val)
{
write(char(token::DOUBLE_SCALAR));
writeToBuffer(char(token::DOUBLE_SCALAR));
writeToBuffer(val);
return *this;
}
Foam::Ostream& Foam::UOPstream::write(const longDoubleScalar val)
{
writeToBuffer(char(token::LONG_DOUBLE_SCALAR));
writeToBuffer(val);
return *this;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -168,6 +168,9 @@ public:
//- Write doubleScalar
Ostream& write(const doubleScalar);
//- Write longDoubleScalar
Ostream& write(const longDoubleScalar);
//- Write binary block
Ostream& write(const char*, std::streamsize);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -777,6 +777,14 @@ Foam::Istream& Foam::ISstream::read(doubleScalar& val)
}
Foam::Istream& Foam::ISstream::read(longDoubleScalar& val)
{
is_ >> val;
setState(is_.rdstate());
return *this;
}
// read binary block
Foam::Istream& Foam::ISstream::read(char* buf, std::streamsize count)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -160,6 +160,9 @@ public:
//- Read a doubleScalar
virtual Istream& read(doubleScalar&);
//- Read a longDoubleScalar
virtual Istream& read(longDoubleScalar&);
//- Read binary block
virtual Istream& read(char*, std::streamsize);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -215,6 +215,14 @@ Foam::Ostream& Foam::OSstream::write(const doubleScalar val)
}
Foam::Ostream& Foam::OSstream::write(const longDoubleScalar val)
{
os_ << val;
setState(os_.rdstate());
return *this;
}
Foam::Ostream& Foam::OSstream::write(const char* buf, std::streamsize count)
{
if (format() != BINARY)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -142,6 +142,9 @@ public:
//- Write doubleScalar
virtual Ostream& write(const doubleScalar);
//- Write longDoubleScalar
virtual Ostream& write(const longDoubleScalar);
//- Write binary block
virtual Ostream& write(const char*, std::streamsize);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -165,6 +165,13 @@ Foam::Ostream& Foam::prefixOSstream::write(const doubleScalar val)
}
Foam::Ostream& Foam::prefixOSstream::write(const longDoubleScalar val)
{
checkWritePrefix();
return OSstream::write(val);
}
Foam::Ostream& Foam::prefixOSstream::write
(
const char* buf,

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -133,6 +133,9 @@ public:
//- Write doubleScalar
virtual Ostream& write(const doubleScalar);
//- Write longDoubleScalar
virtual Ostream& write(const longDoubleScalar);
//- Write binary block
virtual Ostream& write(const char*, std::streamsize);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -147,6 +147,13 @@ Foam::Istream& Foam::ITstream::read(doubleScalar&)
}
Foam::Istream& Foam::ITstream::read(longDoubleScalar&)
{
NotImplemented;
return *this;
}
Foam::Istream& Foam::ITstream::read(char*, std::streamsize)
{
NotImplemented;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -185,6 +185,9 @@ public:
//- Read a doubleScalar
virtual Istream& read(doubleScalar&);
//- Read a longDoubleScalar
virtual Istream& read(longDoubleScalar&);
//- Read binary block
virtual Istream& read(char*, std::streamsize);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -119,6 +119,13 @@ public:
return *this;
}
//- Read a longDoubleScalar
virtual Istream& read(longDoubleScalar&)
{
NotImplemented;
return *this;
}
//- Read binary block
virtual Istream& read(char*, std::streamsize)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -120,6 +120,13 @@ public:
return *this;
}
//- Read a longDoubleScalar
virtual Istream& read(longDoubleScalar&)
{
NotImplemented;
return *this;
}
//- Read binary block
virtual Istream& read(char*, std::streamsize)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -73,11 +73,11 @@ class token
public:
//- Enumeration defining the types of token
enum tokenType
enum tokenType : char
{
UNDEFINED,
UNDEFINED = 0,
PUNCTUATION,
PUNCTUATION = -127,
WORD,
VARIABLE,
STRING,
@ -85,14 +85,14 @@ public:
LABEL,
FLOAT_SCALAR,
DOUBLE_SCALAR,
LONG_DOUBLE_SCALAR,
COMPOUND,
ERROR
};
//- Standard punctuation tokens
enum punctuationToken
enum punctuationToken : char
{
NULL_TOKEN = '\0',
SPACE = ' ',
@ -120,7 +120,6 @@ public:
DIVIDE = '/'
};
//- Abstract base class for complex tokens
class compound
:
@ -260,6 +259,7 @@ private:
label labelToken_;
floatScalar floatScalarToken_;
doubleScalar doubleScalarToken_;
longDoubleScalar* longDoubleScalarTokenPtr_;
mutable compound* compoundTokenPtr_;
};
@ -309,6 +309,9 @@ public:
//- Construct doubleScalar token
inline token(const doubleScalar, label lineNumber=0);
//- Construct longDoubleScalar token
inline token(const longDoubleScalar, label lineNumber=0);
//- Construct from Istream
token(Istream&);
@ -348,6 +351,9 @@ public:
inline bool isDoubleScalar() const;
inline doubleScalar doubleScalarToken() const;
inline bool isLongDoubleScalar() const;
inline longDoubleScalar longDoubleScalarToken() const;
inline bool isScalar() const;
inline scalar scalarToken() const;
@ -395,6 +401,7 @@ public:
inline void operator=(const label);
inline void operator=(const floatScalar);
inline void operator=(const doubleScalar);
inline void operator=(const longDoubleScalar);
inline void operator=(compound*);
@ -408,6 +415,7 @@ public:
inline bool operator==(const label) const;
inline bool operator==(const floatScalar) const;
inline bool operator==(const doubleScalar) const;
inline bool operator==(const longDoubleScalar) const;
// Inequality
@ -419,6 +427,7 @@ public:
inline bool operator!=(const label) const;
inline bool operator!=(const floatScalar) const;
inline bool operator!=(const doubleScalar) const;
inline bool operator!=(const longDoubleScalar) const;
// IOstream operators

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -37,6 +37,10 @@ inline void Foam::token::clear()
{
delete stringTokenPtr_;
}
else if (type_ == LONG_DOUBLE_SCALAR)
{
delete longDoubleScalarTokenPtr_;
}
else if (type_ == COMPOUND)
{
if (compoundTokenPtr_->unique())
@ -98,6 +102,11 @@ inline Foam::token::token(const token& t)
doubleScalarToken_ = t.doubleScalarToken_;
break;
case LONG_DOUBLE_SCALAR:
longDoubleScalarTokenPtr_ =
new longDoubleScalar(*t.longDoubleScalarTokenPtr_);
break;
case COMPOUND:
compoundTokenPtr_ = t.compoundTokenPtr_;
compoundTokenPtr_->refCount::operator++();
@ -157,6 +166,14 @@ inline Foam::token::token(const doubleScalar s, label lineNumber)
{}
inline Foam::token::token(const longDoubleScalar s, label lineNumber)
:
type_(LONG_DOUBLE_SCALAR),
longDoubleScalarTokenPtr_(new longDoubleScalar(s)),
lineNumber_(lineNumber)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
inline Foam::token::~token()
@ -307,9 +324,33 @@ inline Foam::doubleScalar Foam::token::doubleScalarToken() const
}
inline bool Foam::token::isLongDoubleScalar() const
{
return (type_ == LONG_DOUBLE_SCALAR);
}
inline Foam::longDoubleScalar Foam::token::longDoubleScalarToken() const
{
if (type_ == LONG_DOUBLE_SCALAR)
{
return *longDoubleScalarTokenPtr_;
}
else
{
parseError("longDoubleScalar");
return 0.0;
}
}
inline bool Foam::token::isScalar() const
{
return (type_ == FLOAT_SCALAR || type_ == DOUBLE_SCALAR);
return
(
type_ == FLOAT_SCALAR
|| type_ == DOUBLE_SCALAR
|| type_ == LONG_DOUBLE_SCALAR
);
}
inline Foam::scalar Foam::token::scalarToken() const
@ -322,6 +363,10 @@ inline Foam::scalar Foam::token::scalarToken() const
{
return doubleScalarToken_;
}
else if (type_ == LONG_DOUBLE_SCALAR)
{
return *longDoubleScalarTokenPtr_;
}
else
{
parseError(pTraits<scalar>::typeName);
@ -426,6 +471,11 @@ inline void Foam::token::operator=(const token& t)
doubleScalarToken_ = t.doubleScalarToken_;
break;
case LONG_DOUBLE_SCALAR:
longDoubleScalarTokenPtr_ =
new longDoubleScalar(*t.longDoubleScalarTokenPtr_);
break;
case COMPOUND:
compoundTokenPtr_ = t.compoundTokenPtr_;
compoundTokenPtr_->refCount::operator++();
@ -490,6 +540,13 @@ inline void Foam::token::operator=(const doubleScalar s)
doubleScalarToken_ = s;
}
inline void Foam::token::operator=(const longDoubleScalar s)
{
clear();
type_ = LONG_DOUBLE_SCALAR;
longDoubleScalarTokenPtr_ = new longDoubleScalar(s);
}
inline void Foam::token::operator=(Foam::token::compound* cPtr)
{
clear();
@ -530,6 +587,13 @@ inline bool Foam::token::operator==(const token& t) const
case DOUBLE_SCALAR:
return equal(doubleScalarToken_, t.doubleScalarToken_);
case LONG_DOUBLE_SCALAR:
return equal
(
*longDoubleScalarTokenPtr_,
*t.longDoubleScalarTokenPtr_
);
case COMPOUND:
return compoundTokenPtr_ == t.compoundTokenPtr_;
@ -574,6 +638,14 @@ inline bool Foam::token::operator==(const doubleScalar s) const
return (type_ == DOUBLE_SCALAR && equal(doubleScalarToken_, s));
}
inline bool Foam::token::operator==(const longDoubleScalar s) const
{
return
(
type_ == LONG_DOUBLE_SCALAR && equal(*longDoubleScalarTokenPtr_, s)
);
}
inline bool Foam::token::operator!=(const token& t) const
{
return !operator==(t);
@ -604,6 +676,11 @@ inline bool Foam::token::operator!=(const doubleScalar s) const
return !operator==(s);
}
inline bool Foam::token::operator!=(const longDoubleScalar s) const
{
return !operator==(s);
}
inline bool Foam::token::operator!=(const label l) const
{
return !operator==(l);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -88,6 +88,10 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const token& t)
os << t.doubleScalarToken_;
break;
case token::LONG_DOUBLE_SCALAR:
os << *t.longDoubleScalarTokenPtr_;
break;
case token::COMPOUND:
os << *t.compoundTokenPtr_;
break;
@ -179,6 +183,10 @@ ostream& Foam::operator<<(ostream& os, const InfoProxy<token>& ip)
os << " the doubleScalar " << t.doubleScalarToken();
break;
case token::LONG_DOUBLE_SCALAR:
os << " the longDoubleScalar " << t.longDoubleScalarToken();
break;
case token::COMPOUND:
{
if (t.compoundToken().empty())
@ -251,6 +259,10 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<token>& ip)
os << " the doubleScalar " << t.doubleScalarToken();
break;
case token::LONG_DOUBLE_SCALAR:
os << " the longDoubleScalar " << t.longDoubleScalarToken();
break;
case token::COMPOUND:
{
if (t.compoundToken().empty())

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -96,7 +96,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
{
is.fatalCheck
(
"primitiveEntry::readData(const dictionary&, Istream&)"
"primitiveEntry::read(const dictionary&, Istream&) start"
);
label blockCount = 0;
@ -150,7 +150,7 @@ bool Foam::primitiveEntry::read(const dictionary& dict, Istream& is)
is.fatalCheck
(
"primitiveEntry::readData(const dictionary&, Istream&)"
"primitiveEntry::read(const dictionary&, Istream&) end"
);
if (currToken.good())

View File

@ -31,8 +31,8 @@ License
namespace Foam
{
defineTypeNameAndDebug(dimensionSet, 1);
const scalar dimensionSet::smallExponent = small;
defineTypeNameAndDebug(dimensionSet, 1);
const scalar dimensionSet::smallExponent = small;
}

View File

@ -322,9 +322,10 @@ Foam::scalar Foam::plane::normalIntersect
const vector& dir
) const
{
scalar denom = stabilise((dir & normal_), vSmall);
const scalar num = (point_ - pnt0) & normal_;
const scalar den = dir & normal_;
return ((point_ - pnt0) & normal_)/denom;
return mag(den) > mag(num)*vSmall ? num/den : vGreat;
}

View File

@ -0,0 +1,47 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "longDoubleScalar.H"
#include "IOstreams.H"
#include <sstream>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#define Scalar longDoubleScalar
#define ScalarVGreat longDoubleScalarVGreat
#define ScalarVSmall longDoubleScalarVSmall
#define ScalarRootVGreat longDoubleScalarRootVGreat
#define ScalarRootVSmall longDoubleScalarRootVSmall
#define readScalar readLongDoubleScalar
#include "Scalar.C"
#undef Scalar
#undef ScalarVGreat
#undef ScalarVSmall
#undef ScalarRootVGreat
#undef ScalarRootVSmall
#undef readScalar
// ************************************************************************* //

View File

@ -0,0 +1,175 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM 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.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::longDoubleScalar
Description
Lang double precision floating point scalar type.
SourceFiles
longDoubleScalar.C
\*---------------------------------------------------------------------------*/
#ifndef longDoubleScalar_H
#define longDoubleScalar_H
#include "doubleFloat.H"
#include "direction.H"
#include "word.H"
#include <limits>
using std::numeric_limits;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef long double longDoubleScalar;
// Largest and smallest scalar values allowed in certain parts of the code.
static const longDoubleScalar longDoubleScalarVGreat
= numeric_limits<long double>::max()/10;
static const longDoubleScalar longDoubleScalarVSmall
= numeric_limits<double>::min();
static const longDoubleScalar longDoubleScalarSmall
= 1e3*numeric_limits<long double>::epsilon();
static const longDoubleScalar longDoubleScalarGreat
= 1.0/longDoubleScalarSmall;
static const longDoubleScalar longDoubleScalarRootVGreat
= ::sqrtl(longDoubleScalarVGreat);
static const longDoubleScalar longDoubleScalarRootVSmall
= ::sqrtl(longDoubleScalarVSmall);
static const longDoubleScalar longDoubleScalarRootGreat
= ::sqrtl(longDoubleScalarGreat);
static const longDoubleScalar longDoubleScalarRootSmall
= ::sqrtl(longDoubleScalarSmall);
//- Read whole of buf as a scalar. Return true if succesful.
inline bool readScalar(const char* buf, longDoubleScalar& s)
{
char* endPtr;
s = strtold(buf, &endPtr);
return (*endPtr == '\0');
}
#define Scalar longDoubleScalar
#define ScalarVGreat longDoubleScalarVGreat
#define ScalarVSmall longDoubleScalarVSmall
#define ScalarRootVGreat longDoubleScalarRootVGreat
#define ScalarRootVSmall longDoubleScalarRootVSmall
#define readScalar readLongDoubleScalar
inline Scalar mag(const Scalar s)
{
return ::fabsl(s);
}
#define MAXMINPOW(retType, type1, type2) \
\
MAXMIN(retType, type1, type2) \
\
inline double pow(const type1 s, const type2 e) \
{ \
return ::powl(Scalar(s), Scalar(e)); \
}
MAXMINPOW(Scalar, Scalar, Scalar)
MAXMINPOW(Scalar, Scalar, int)
MAXMINPOW(Scalar, int, Scalar)
MAXMINPOW(Scalar, Scalar, long)
MAXMINPOW(Scalar, long, Scalar)
MAXMINPOW(Scalar, Scalar, float)
MAXMINPOW(Scalar, float, Scalar)
MAXMINPOW(Scalar, Scalar, double)
MAXMINPOW(Scalar, double, Scalar)
#undef MAXMINPOW
#define transFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return ::func(s); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "Scalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Scalar hypot(const Scalar x, const Scalar y)
{
return ::hypotl(x, y);
}
inline Scalar atan2(const Scalar y, const Scalar x)
{
return ::atan2l(y, x);
}
inline Scalar jn(const int n, const Scalar s)
{
return ::jnl(n, s);
}
inline Scalar yn(const int n, const Scalar s)
{
return ::ynl(n, s);
}
#undef Scalar
#undef ScalarVGreat
#undef ScalarVSmall
#undef ScalarRootVGreat
#undef ScalarRootVSmall
#undef readScalar
#undef transFunc
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -26,7 +26,7 @@ Typedef
Description
Single floating point number identical to float or double depending on
whether WM_SP or WM_DP is defined.
whether WM_SP, WM_DP or WM_LP is defined.
SourceFiles
scalar.C
@ -38,6 +38,7 @@ SourceFiles
#include "floatScalar.H"
#include "doubleScalar.H"
#include "longDoubleScalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -57,8 +58,6 @@ namespace Foam
static const scalar rootSmall = floatScalarRootSmall;
static const scalar vSmall = floatScalarVSmall;
static const scalar rootVSmall = floatScalarRootVSmall;
scalar readScalar(Istream& is);
}
#elif defined(WM_DP)
@ -77,10 +76,30 @@ namespace Foam
static const scalar rootSmall = doubleScalarRootSmall;
static const scalar vSmall = doubleScalarVSmall;
static const scalar rootVSmall = doubleScalarRootVSmall;
scalar readScalar(Istream& is);
}
#elif defined(WM_LP)
// Define scalar as a long double
namespace Foam
{
typedef longDoubleScalar scalar;
static const scalar great = longDoubleScalarGreat;
static const scalar rootGreat = longDoubleScalarRootGreat;
static const scalar vGreat = longDoubleScalarVGreat;
static const scalar rootVGreat = longDoubleScalarRootVGreat;
static const scalar small = longDoubleScalarSmall;
static const scalar rootSmall = longDoubleScalarRootSmall;
static const scalar vSmall = longDoubleScalarVSmall;
static const scalar rootVSmall = longDoubleScalarRootVSmall;
}
#else
#error "Precision not set, please set either WM_SP, WM_DP or WM_LP"
#endif
//- Deprecated limit constant for backward-compatibility
@ -96,15 +115,19 @@ namespace Foam
static const scalar ROOTVSMALL = rootVSmall;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Additional transcendental functions
// Additional global and transcendental functions
namespace Foam
{
scalar readScalar(Istream& is);
//- Inverse normalized incomplete gamma function
scalar invIncGamma(const scalar a, const scalar P);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -80,6 +80,12 @@ public:
{
return 1;
}
//- Return 1 for double
inline operator long double() const
{
return 1;
}
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -85,6 +85,12 @@ public:
{
return 0;
}
//- Return 0 for double
inline operator long double() const
{
return 0;
}
};

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -44,6 +44,8 @@ Note
#define MPI_SCALAR MPI_FLOAT
#elif defined(WM_DP)
#define MPI_SCALAR MPI_DOUBLE
#elif defined(WM_LP)
#define MPI_SCALAR MPI_LONG_DOUBLE
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -105,7 +105,7 @@ Foam::Ostream& Foam::OBJstream::write(const word& str)
Foam::Ostream& Foam::OBJstream::write(const string& str)
{
OFstream::write(token::BEGIN_STRING);
OFstream::write(char(token::BEGIN_STRING));
int backslash = 0;
for (string::const_iterator iter = str.begin(); iter != str.end(); ++iter)
@ -141,7 +141,7 @@ Foam::Ostream& Foam::OBJstream::write(const string& str)
// silently drop any trailing backslashes
// they would otherwise appear like an escaped end-quote
OFstream::write(token::END_STRING);
OFstream::write(char(token::END_STRING));
return *this;
}
@ -154,7 +154,7 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
{
if (quoted)
{
OFstream::write(token::BEGIN_STRING);
OFstream::write(char(token::BEGIN_STRING));
int backslash = 0;
for
@ -194,7 +194,7 @@ Foam::Ostream& Foam::OBJstream::writeQuoted
// silently drop any trailing backslashes
// they would otherwise appear like an escaped end-quote
OFstream::write(token::END_STRING);
OFstream::write(char(token::END_STRING));
}
else
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -80,7 +80,7 @@ public:
// Member Operators
#ifdef WM_DP
#if defined(WM_DP) || defined(WM_LP)
//- Conversion to double-precision point
inline operator point() const
{