Commit 1d7d5b2d authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: provide lightweight labelFwd, scalarFwd headers

- centralizes sizing information and typedefs
  without dependencies beyond <cstdint>

COMP: ensure label typedef exists for nullObject.H
parent 727ea48e
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -38,19 +38,20 @@ SourceFiles
#ifndef doubleScalar_H
#define doubleScalar_H
#include "scalarFwd.H"
#include "doubleFloat.H"
#include "direction.H"
#include "word.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Typedef (doubleScalar) in scalarFwd.H
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef double doubleScalar;
// Largest and smallest scalar values allowed in certain parts of the code.
// See std::numeric_limits max(), min(), epsilon()
constexpr doubleScalar doubleScalarGREAT = 1.0e+15;
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -38,19 +38,20 @@ SourceFiles
#ifndef floatScalar_H
#define floatScalar_H
#include "scalarFwd.H"
#include "doubleFloat.H"
#include "direction.H"
#include "word.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Typedef (floatScalar) in scalarFwd.H
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef float floatScalar;
// Largest and smallest scalar values allowed in certain parts of the code.
// See std::numeric_limits max(), min(), epsilon()
constexpr floatScalar floatScalarGREAT = 1.0e+6;
......
......@@ -44,19 +44,14 @@ SourceFiles
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Typedefs (floatScalar, doubleScalar, scalar, solveScalar) in scalarFwd.H
#if defined(WM_SP) || defined(WM_SPDP)
// Define scalar as a float
// With scalar == (float), solveScalar == (float | double)
namespace Foam
{
typedef floatScalar scalar;
#if defined(WM_SPDP)
typedef doubleScalar solveScalar;
#else
typedef floatScalar solveScalar;
#endif
constexpr scalar GREAT = floatScalarGREAT;
constexpr scalar VGREAT = floatScalarVGREAT;
constexpr scalar ROOTVGREAT = floatScalarROOTVGREAT;
......@@ -101,13 +96,10 @@ namespace Foam
#elif defined(WM_DP)
// Define scalar as a double
// With scalar == (double), solveScalar == (double)
namespace Foam
{
typedef doubleScalar scalar;
typedef doubleScalar solveScalar;
constexpr scalar GREAT = doubleScalarGREAT;
constexpr scalar VGREAT = doubleScalarVGREAT;
constexpr scalar ROOTVGREAT = doubleScalarROOTVGREAT;
......@@ -151,6 +143,8 @@ namespace Foam
void readRawScalar(Istream& is, scalar* data, size_t nElem = 1);
}
#else
// #error "PRECISION must be set to WM_SP, WM_SPDP or WM_DP"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Description
Typedefs for float/double/scalar without requiring scalar.H
The definition of scalar as a floating-point number depends
on pre-processor macros WM_SP, WM_SPDP or WM_DP being defined.
SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef scalarFwd_H
#define scalarFwd_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
//- A typedef for float
typedef float floatScalar;
//- A typedef for double
typedef double doubleScalar;
#if defined(WM_SP)
typedef floatScalar scalar;
typedef floatScalar solveScalar;
#elif defined(WM_SPDP)
typedef floatScalar scalar;
typedef doubleScalar solveScalar;
#elif defined(WM_DP)
typedef doubleScalar scalar;
typedef doubleScalar solveScalar;
#else
// #error "PRECISION must be set to WM_SP, WM_SPDP or WM_DP"
#endif
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -40,6 +40,7 @@ Description
#define label_H
#include "int.H"
#include "labelFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -47,10 +48,7 @@ Description
#define INT_ADD_DEF_SIZE(x,s,y) INT_ADD_SIZE(x,s,y)
#define INT_SIZE(x,y) INT_ADD_DEF_SIZE(x,WM_LABEL_SIZE,y)
#if WM_LABEL_SIZE != 32 && WM_LABEL_SIZE != 64
#error "label.H: WM_LABEL_SIZE must be set to either 32 or 64"
#endif
// Size checks and typedefs (label) in labelFwd.H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -59,8 +57,6 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef INT_SIZE(int, _t) label;
constexpr label labelMin = INT_SIZE(INT, _MIN);
constexpr label labelMax = INT_SIZE(INT, _MAX);
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Description
Typedefs for label/uLabel without requiring label.H
The definitions of label/uLabel as an integral value depend on the
pre-processor macro WM_LABEL_SIZE.
\*---------------------------------------------------------------------------*/
#ifndef labelFwd_H
#define labelFwd_H
#include <cstdint>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
#if WM_LABEL_SIZE == 32
typedef int32_t label;
typedef uint32_t uLabel;
#elif WM_LABEL_SIZE == 64
typedef int64_t label;
typedef uint64_t uLabel;
#else
#error "WM_LABEL_SIZE must be set to either 32 or 64"
#endif
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -40,6 +40,7 @@ Description
#define uLabel_H
#include "uint.H"
#include "labelFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -47,10 +48,7 @@ Description
#define UINT_ADD_DEF_SIZE(x,s,y) UINT_ADD_SIZE(x,s,y)
#define UINT_SIZE(x,y) UINT_ADD_DEF_SIZE(x,WM_LABEL_SIZE,y)
#if WM_LABEL_SIZE != 32 && WM_LABEL_SIZE != 64
#error "uLabel.H: WM_LABEL_SIZE must be set to either 32 or 64"
#endif
// Size checks and typedefs (uLabel) in labelFwd.H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -59,8 +57,6 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef UINT_SIZE(uint, _t) uLabel;
constexpr uLabel uLabelMax = UINT_SIZE(UINT, _MAX);
//- Read uLabel from stream.
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2014 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -42,6 +42,8 @@ SourceFiles
#ifndef nullObject_H
#define nullObject_H
#include "labelFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
......
......@@ -44,7 +44,7 @@ SeeAlso
#ifndef zero_H
#define zero_H
#include "label.H"
#include "labelFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -133,13 +133,13 @@ static constexpr const zero Zero;
// IOstream Operators
//- Read from Istream consumes no content.
//- Read from Istream consumes no content
inline constexpr Istream& operator>>(Istream& is, zero&) noexcept
{
return is;
}
//- Write to Ostream emits no content.
//- Write to Ostream emits no content
inline constexpr Ostream& operator<<(Ostream& os, const zero::null&) noexcept
{
return os;
......@@ -153,6 +153,7 @@ inline constexpr Ostream& operator<<(Ostream& os, const zero::null&) noexcept
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Global Operators, Functions
#include "zeroI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment