STYLE: relocate geometryType enum to cloud class (issue #721)

This commit is contained in:
Mark Olesen
2018-02-19 12:40:06 +01:00
parent cbbb9753eb
commit d69c26311f
10 changed files with 59 additions and 70 deletions

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,11 +31,19 @@ License
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(cloud, 0); defineTypeNameAndDebug(cloud, 0);
const word cloud::prefix("lagrangian");
word cloud::defaultName("defaultCloud");
} }
const Foam::word Foam::cloud::prefix("lagrangian");
Foam::word Foam::cloud::defaultName("defaultCloud");
const Foam::Enum<Foam::cloud::geometryType>
Foam::cloud::geometryTypeNames
{
{ geometryType::COORDINATES, "coordinates" },
{ geometryType::POSITIONS, "positions" }
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName) Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName)
@ -55,12 +63,6 @@ Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName)
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::cloud::~cloud()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::cloud::autoMap(const mapPolyMesh&) void Foam::cloud::autoMap(const mapPolyMesh&)

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::cloud Foam::cloud
Description Description
A cloud is a collection of lagrangian particles A cloud is a registry collection of lagrangian particles.
SourceFiles SourceFiles
cloud.C cloud.C
@ -36,6 +36,7 @@ SourceFiles
#define cloud_H #define cloud_H
#include "objectRegistry.H" #include "objectRegistry.H"
#include "Enum.H"
#include "IOField.H" #include "IOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,14 +59,24 @@ class cloud
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
cloud(const cloud&); cloud(const cloud&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const cloud&); void operator=(const cloud&) = delete;
public: public:
//- Cloud geometry type (internal or IO representations)
enum class geometryType
{
COORDINATES, //!< barycentric coordinates
POSITIONS //!< positions
};
static const Enum<geometryType> geometryTypeNames;
//- Runtime type information //- Runtime type information
TypeName("cloud"); TypeName("cloud");
@ -83,7 +94,7 @@ public:
//- Destructor //- Destructor
virtual ~cloud(); virtual ~cloud() = default;
// Member Functions // Member Functions

View File

@ -79,7 +79,7 @@ Foam::Cloud<ParticleType>::Cloud
polyMesh_(pMesh), polyMesh_(pMesh),
labels_(), labels_(),
globalPositionsPtr_(), globalPositionsPtr_(),
geometryType_(IOPosition<Cloud<ParticleType>>::geometryType::COORDINATES) geometryType_(cloud::geometryType::COORDINATES)
{ {
checkPatches(); checkPatches();

View File

@ -109,7 +109,7 @@ class Cloud
protected: protected:
//- Geometry type //- Geometry type
typename IOPosition<Cloud<ParticleType>>::geometryType geometryType_; cloud::geometryType geometryType_;
public: public:

View File

@ -57,11 +57,11 @@ void Foam::Cloud<ParticleType>::readCloudUniformProperties()
// Fall back to positions mode if the entry is not present for // Fall back to positions mode if the entry is not present for
// backwards compatibility // backwards compatibility
geometryType_ = geometryType_ =
IOPosition<Cloud<ParticleType>>::geometryTypeNames_.lookupOrDefault cloud::geometryTypeNames.lookupOrDefault
( (
"geometry", "geometry",
uniformPropsDict, uniformPropsDict,
IOPosition<Cloud<ParticleType>>::geometryType::POSITIONS cloud::geometryType::POSITIONS
); );
const word procName("processor" + Foam::name(Pstream::myProcNo())); const word procName("processor" + Foam::name(Pstream::myProcNo()));
@ -104,7 +104,7 @@ void Foam::Cloud<ParticleType>::writeCloudUniformProperties() const
uniformPropsDict.add uniformPropsDict.add
( (
"geometry", "geometry",
IOPosition<Cloud<ParticleType>>::geometryTypeNames_[geometryType_] cloud::geometryTypeNames[geometryType_]
); );
forAll(np, i) forAll(np, i)
@ -146,8 +146,8 @@ void Foam::Cloud<ParticleType>::initCloud(const bool checkClass)
<< "Assuming the initial cloud contains 0 particles." << endl; << "Assuming the initial cloud contains 0 particles." << endl;
} }
// Always operate in co-ordinates mode after reading // Always operate in coordinates mode after reading
geometryType_ = IOPosition<Cloud<ParticleType>>::geometryType::COORDINATES; geometryType_ = cloud::geometryType::COORDINATES;
// Ask for the tetBasePtIs to trigger all processors to build // Ask for the tetBasePtIs to trigger all processors to build
// them, otherwise, if some processors have no particles then // them, otherwise, if some processors have no particles then
@ -170,7 +170,7 @@ Foam::Cloud<ParticleType>::Cloud
polyMesh_(pMesh), polyMesh_(pMesh),
labels_(), labels_(),
cellWallFacesPtr_(), cellWallFacesPtr_(),
geometryType_(IOPosition<Cloud<ParticleType>>::geometryType::COORDINATES) geometryType_(cloud::geometryType::COORDINATES)
{ {
checkPatches(); checkPatches();

View File

@ -23,31 +23,20 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class CloudType>
const Foam::Enum<typename Foam::IOPosition<CloudType>::geometryType>
Foam::IOPosition<CloudType>::geometryTypeNames_
{
{ geometryType::POSITIONS, "positions" },
{ geometryType::COORDINATES, "coordinates" }
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class CloudType> template<class CloudType>
Foam::IOPosition<CloudType>::IOPosition Foam::IOPosition<CloudType>::IOPosition
( (
const CloudType& c, const CloudType& c,
const geometryType& geomType const cloud::geometryType& geomType
) )
: :
regIOobject regIOobject
( (
IOobject IOobject
( (
geometryTypeNames_[geomType], cloud::geometryTypeNames[geomType],
c.time().timeName(), c.time().timeName(),
c, c,
IOobject::MUST_READ, IOobject::MUST_READ,
@ -75,16 +64,7 @@ bool Foam::IOPosition<CloudType>::writeData(Ostream& os) const
switch (geometryType_) switch (geometryType_)
{ {
case geometryType::POSITIONS: case cloud::geometryType::COORDINATES:
{
forAllConstIters(cloud_, iter)
{
iter().writePosition(os);
os << nl;
}
break;
}
case geometryType::COORDINATES:
{ {
forAllConstIters(cloud_, iter) forAllConstIters(cloud_, iter)
{ {
@ -93,6 +73,15 @@ bool Foam::IOPosition<CloudType>::writeData(Ostream& os) const
} }
break; break;
} }
case cloud::geometryType::POSITIONS:
{
forAllConstIters(cloud_, iter)
{
iter().writePosition(os);
os << nl;
}
break;
}
} }
os << token::END_LIST << endl; os << token::END_LIST << endl;
@ -108,7 +97,7 @@ void Foam::IOPosition<CloudType>::readData(Istream& is, CloudType& c)
token firstToken(is); token firstToken(is);
bool newFormat = geometryType_ == geometryType::COORDINATES; const bool newFormat = (geometryType_ == cloud::geometryType::COORDINATES);
if (firstToken.isLabel()) if (firstToken.isLabel())
{ {

View File

@ -35,8 +35,8 @@ SourceFiles
#ifndef IOPosition_H #ifndef IOPosition_H
#define IOPosition_H #define IOPosition_H
#include "cloud.H"
#include "regIOobject.H" #include "regIOobject.H"
#include "Enum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -52,22 +52,9 @@ class IOPosition
: :
public regIOobject public regIOobject
{ {
public:
enum class geometryType
{
POSITIONS,
COORDINATES
};
static const Enum<geometryType> geometryTypeNames_;
private:
// Private data // Private data
geometryType geometryType_; cloud::geometryType geometryType_;
//- Reference to the cloud //- Reference to the cloud
const CloudType& cloud_; const CloudType& cloud_;
@ -90,7 +77,8 @@ public:
IOPosition IOPosition
( (
const CloudType& c, const CloudType& c,
const geometryType& geomType = geometryType::COORDINATES const cloud::geometryType& geomType
= cloud::geometryType::COORDINATES
); );

View File

@ -41,8 +41,7 @@ Foam::injectedParticleCloud::injectedParticleCloud
: :
Cloud<injectedParticle>(mesh, cloudName, false) Cloud<injectedParticle>(mesh, cloudName, false)
{ {
geometryType_ = geometryType_ = cloud::geometryType::POSITIONS;
IOPosition<Cloud<injectedParticle>>::geometryType::POSITIONS;
if (readFields) if (readFields)
{ {

View File

@ -40,7 +40,7 @@ License
template<class TrackCloudType> template<class TrackCloudType>
void Foam::particle::readFields(TrackCloudType& c) void Foam::particle::readFields(TrackCloudType& c)
{ {
bool valid = c.size(); const bool valid = c.size();
IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ)); IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
@ -70,7 +70,7 @@ void Foam::particle::readFields(TrackCloudType& c)
template<class TrackCloudType> template<class TrackCloudType>
void Foam::particle::writeFields(const TrackCloudType& c) void Foam::particle::writeFields(const TrackCloudType& c)
{ {
label np = c.size(); const label np = c.size();
if (writeLagrangianCoordinates) if (writeLagrangianCoordinates)
{ {
@ -84,7 +84,7 @@ void Foam::particle::writeFields(const TrackCloudType& c)
IOPosition<TrackCloudType> ioP IOPosition<TrackCloudType> ioP
( (
c, c,
IOPosition<TrackCloudType>::geometryType::POSITIONS cloud::geometryType::POSITIONS
); );
ioP.write(np > 0); ioP.write(np > 0);
} }
@ -116,7 +116,7 @@ void Foam::particle::writeFields(const TrackCloudType& c)
template<class CloudType> template<class CloudType>
void Foam::particle::writeObjects(const CloudType& c, objectRegistry& obr) void Foam::particle::writeObjects(const CloudType& c, objectRegistry& obr)
{ {
label np = c.size(); const label np = c.size();
IOField<label>& origProc(cloud::createIOField<label>("origProc", np, obr)); IOField<label>& origProc(cloud::createIOField<label>("origProc", np, obr));
IOField<label>& origId(cloud::createIOField<label>("origId", np, obr)); IOField<label>& origId(cloud::createIOField<label>("origId", np, obr));

View File

@ -84,7 +84,7 @@ void Foam::reconstructLagrangianPositions
IOPosition<Cloud<passiveParticle>> IOPosition<Cloud<passiveParticle>>
( (
lagrangianPositions, lagrangianPositions,
IOPosition<Cloud<passiveParticle>>::geometryType::POSITIONS cloud::geometryType::POSITIONS
).write(); ).write();
} }
} }