ENH: reduce storage requirement for volumeType

- char instead of integer representation for the enumeration.

- additional constructor as lookupOrDefault from dictionary entry.
This commit is contained in:
Mark Olesen
2018-07-11 08:50:38 +02:00
parent d530bc254a
commit a7e37656e8
6 changed files with 70 additions and 65 deletions

View File

@ -32,7 +32,7 @@ License
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(conformationSurfaces, 0); defineTypeNameAndDebug(conformationSurfaces, 0);
} }
@ -71,8 +71,7 @@ void Foam::conformationSurfaces::hasBoundedVolume
referenceVolumeTypes[s] = vTypes[0]; referenceVolumeTypes[s] = vTypes[0];
Info<< " is " Info<< " is " << referenceVolumeTypes[s].str()
<< volumeType::names[referenceVolumeTypes[s]]
<< " surface " << surface.name() << " surface " << surface.name()
<< endl; << endl;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "volumeType.H" #include "volumeType.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -34,12 +35,33 @@ const Foam::Enum
Foam::volumeType::names Foam::volumeType::names
{ {
{ type::UNKNOWN, "unknown" }, { type::UNKNOWN, "unknown" },
{ type::MIXED, "mixed" },
{ type::INSIDE, "inside" }, { type::INSIDE, "inside" },
{ type::OUTSIDE, "outside" }, { type::OUTSIDE, "outside" },
{ type::MIXED, "mixed" },
}; };
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::volumeType::volumeType
(
const word& key,
const dictionary& dict,
const type deflt
)
:
t_(names.lookupOrDefault(key, dict, deflt))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::word& Foam::volumeType::str() const
{
return names[t_];
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, volumeType& vt) Foam::Istream& Foam::operator>>(Istream& is, volumeType& vt)
@ -47,10 +69,10 @@ Foam::Istream& Foam::operator>>(Istream& is, volumeType& vt)
// Read beginning of volumeType // Read beginning of volumeType
is.readBegin("volumeType"); is.readBegin("volumeType");
int type; int val;
is >> type; is >> val;
vt.t_ = static_cast<volumeType::type>(type); vt.t_ = static_cast<volumeType::type>(val);
// Read end of volumeType // Read end of volumeType
is.readEnd("volumeType"); is.readEnd("volumeType");

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,6 +25,8 @@ Class
Foam::volumeType Foam::volumeType
Description Description
An enumeration wrapper for classification of a location as being
inside/outside of a volume.
SourceFiles SourceFiles
volumeType.C volumeType.C
@ -41,8 +43,8 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of friend functions and operators // Forward declarations
class dictionary;
class volumeType; class volumeType;
Istream& operator>>(Istream& is, volumeType& vt); Istream& operator>>(Istream& is, volumeType& vt);
Ostream& operator<<(Ostream& os, const volumeType& vt); Ostream& operator<<(Ostream& os, const volumeType& vt);
@ -56,16 +58,18 @@ class volumeType
{ {
public: public:
//- Volume types //- Volume classification types
enum type enum type : char
{ {
UNKNOWN = 0, UNKNOWN = 0, //!< Unknown state
MIXED = 1, INSIDE = 0x1, //!< A location inside the volume
INSIDE = 2, OUTSIDE = 0x2, //!< A location outside the volume
OUTSIDE = 3 MIXED = 0x3 //!< A location that is partly inside and outside
}; };
// Static data // Static data
//- Names for the classification enumeration
static const Enum<volumeType> names; static const Enum<volumeType> names;
@ -81,18 +85,21 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null as UNKNOWN state
volumeType() volumeType()
: :
t_(UNKNOWN) t_(UNKNOWN)
{} {}
//- Construct from components //- Construct from enumeration
volumeType(type t) volumeType(type t)
: :
t_(t) t_(t)
{} {}
//- Construct as lookupOrDefault by name from dictionary
volumeType(const word& key, const dictionary& dict, const type deflt);
//- Construct from integer //- Construct from integer
explicit volumeType(const int t) explicit volumeType(const int t)
: :
@ -102,11 +109,15 @@ public:
// Member Functions // Member Functions
//- Return the enumeration
operator type() const operator type() const
{ {
return t_; return t_;
} }
//- The string representation of the volume type enumeration
const word& str() const;
// IOstream operators // IOstream operators

View File

@ -227,14 +227,9 @@ Foam::refinementSurfaces::refinementSurfaces
"gapLevel", "gapLevel",
nullGapLevel nullGapLevel
); );
globalGapMode[surfI] = volumeType::names globalGapMode[surfI] =
[ volumeType("gapMode", dict, volumeType::MIXED);
dict.lookupOrDefault<word>
(
"gapMode",
volumeType::names[volumeType::MIXED]
)
];
if if
( (
globalGapMode[surfI] == volumeType::UNKNOWN globalGapMode[surfI] == volumeType::UNKNOWN
@ -248,7 +243,7 @@ Foam::refinementSurfaces::refinementSurfaces
<< "Illegal gapLevel specification for surface " << "Illegal gapLevel specification for surface "
<< names_[surfI] << names_[surfI]
<< " : gapLevel:" << globalGapLevel[surfI] << " : gapLevel:" << globalGapLevel[surfI]
<< " gapMode:" << volumeType::names[globalGapMode[surfI]] << " gapMode:" << globalGapMode[surfI].str()
<< exit(FatalIOError); << exit(FatalIOError);
} }
@ -327,14 +322,9 @@ Foam::refinementSurfaces::refinementSurfaces
regionGapLevel[surfI].insert(regionI, gapSpec); regionGapLevel[surfI].insert(regionI, gapSpec);
volumeType gapModeSpec volumeType gapModeSpec
( (
volumeType::names "gapMode",
[ regionDict,
regionDict.lookupOrDefault<word> volumeType::MIXED
(
"gapMode",
volumeType::names[volumeType::MIXED]
)
]
); );
regionGapMode[surfI].insert(regionI, gapModeSpec); regionGapMode[surfI].insert(regionI, gapModeSpec);
if if
@ -350,7 +340,7 @@ Foam::refinementSurfaces::refinementSurfaces
<< "Illegal gapLevel specification for surface " << "Illegal gapLevel specification for surface "
<< names_[surfI] << names_[surfI]
<< " : gapLevel:" << gapSpec << " : gapLevel:" << gapSpec
<< " gapMode:" << volumeType::names[gapModeSpec] << " gapMode:" << gapModeSpec.str()
<< exit(FatalIOError); << exit(FatalIOError);
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -682,19 +682,9 @@ Foam::shellSurfaces::shellSurfaces
extendedGapLevel_[shellI].setSize(regionNames.size()); extendedGapLevel_[shellI].setSize(regionNames.size());
extendedGapLevel_[shellI] = gapSpec; extendedGapLevel_[shellI] = gapSpec;
volumeType gapModeSpec
(
volumeType::names
[
dict.lookupOrDefault<word>
(
"gapMode",
volumeType::names[volumeType::MIXED]
)
]
);
extendedGapMode_[shellI].setSize(regionNames.size()); extendedGapMode_[shellI].setSize(regionNames.size());
extendedGapMode_[shellI] = gapModeSpec; extendedGapMode_[shellI] =
volumeType("gapMode", dict, volumeType::MIXED);
// Override on a per-region basis? // Override on a per-region basis?
@ -721,23 +711,17 @@ Foam::shellSurfaces::shellSurfaces
); );
extendedGapLevel_[shellI][regionI] = gapSpec; extendedGapLevel_[shellI][regionI] = gapSpec;
volumeType gapModeSpec extendedGapMode_[shellI][regionI] =
( volumeType
volumeType::names (
[ "gapMode",
regionDict.lookupOrDefault<word> regionDict,
( volumeType::MIXED
"gapMode", );
volumeType::names[volumeType::MIXED]
)
]
);
extendedGapMode_[shellI][regionI] = gapModeSpec;
} }
} }
} }
checkGapLevels(dict, shellI, extendedGapLevel_[shellI]); checkGapLevels(dict, shellI, extendedGapLevel_[shellI]);
shellI++; shellI++;

View File

@ -644,8 +644,7 @@ void Foam::searchableSurfacesQueries::signedDistance
<< " point:" << surfPoints[i] << " point:" << surfPoints[i]
<< " surface:" << " surface:"
<< allSurfaces[surfacesToTest[testI]].name() << allSurfaces[surfacesToTest[testI]].name()
<< " volType:" << " volType:" << vT.str()
<< volumeType::names[vT]
<< exit(FatalError); << exit(FatalError);
break; break;
} }