STYLE: return orientedType, Switch directly instead of const reference

- noexcept on some Time methods

ENH: pass through is_oriented() method for clearer coding

- use logical and/or/xor instead of bitwise versions (clearer intent)
This commit is contained in:
Mark Olesen
2022-08-23 15:58:32 +02:00
parent 867b5e9060
commit ea51c2c0e4
22 changed files with 114 additions and 160 deletions

View File

@ -153,7 +153,7 @@ public:
return name_;
}
const Switch& forceInitialPointInsertion() const
Switch forceInitialPointInsertion() const noexcept
{
return forceInitialPointInsertion_;
}

View File

@ -264,7 +264,7 @@ void Foam::controlMeshRefinement::initialMeshPopulation
const cellSizeAndAlignmentControl& controlFunction =
controlFunctions[fI];
const Switch& forceInsertion =
const Switch forceInsertion =
controlFunction.forceInitialPointInsertion();
Info<< "Inserting points from " << controlFunction.name()
@ -450,7 +450,7 @@ void Foam::controlMeshRefinement::initialMeshPopulation
const cellSizeAndAlignmentControl& controlFunction =
controlFunctions[fI];
const Switch& forceInsertion =
const Switch forceInsertion =
controlFunction.forceInitialPointInsertion();
Info<< "Inserting points from " << controlFunction.name()

View File

@ -224,7 +224,7 @@ Foam::parFvFieldDistributor::distributeField
}
// Map all faces
primitiveField = Field<Type>(flatFld, mapper, fld.oriented()());
primitiveField = Field<Type>(flatFld, mapper, fld.is_oriented());
// Trim to internal faces (note: could also have special mapper)
primitiveField.resize

View File

@ -36,8 +36,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef volumeType_H
#define volumeType_H
#ifndef Foam_volumeType_H
#define Foam_volumeType_H
#include "contiguous.H"
#include "Enum.H"
@ -89,14 +89,14 @@ public:
// Constructors
//- Construct null as UNKNOWN state
volumeType()
//- Default construct as \c UNKNOWN state
constexpr volumeType() noexcept
:
t_(UNKNOWN)
{}
//- Construct from enumeration
volumeType(type t)
//- Implicit construct from enumeration
volumeType(type t) noexcept
:
t_(t)
{}
@ -123,7 +123,7 @@ public:
const word& str() const;
// IOstream operators
// IOstream Operators
friend Istream& operator>>(Istream& is, volumeType& vt);
friend Ostream& operator<<(Ostream& os, const volumeType& vt);

View File

@ -379,37 +379,37 @@ public:
}
//- The write stream option (format, compression, version)
IOstreamOption writeStreamOption() const
IOstreamOption writeStreamOption() const noexcept
{
return writeStreamOption_;
}
//- The write stream format
IOstreamOption::streamFormat writeFormat() const
IOstreamOption::streamFormat writeFormat() const noexcept
{
return writeStreamOption_.format();
}
//- The write stream compression
IOstreamOption::compressionType writeCompression() const
IOstreamOption::compressionType writeCompression() const noexcept
{
return writeStreamOption_.compression();
}
//- The write stream version
IOstreamOption::versionNumber writeVersion() const
IOstreamOption::versionNumber writeVersion() const noexcept
{
return writeStreamOption_.version();
}
//- Default graph format
const word& graphFormat() const
const word& graphFormat() const noexcept
{
return graphFormat_;
}
//- Supports re-reading
const Switch& runTimeModifiable() const
Switch runTimeModifiable() const noexcept
{
return runTimeModifiable_;
}
@ -508,7 +508,7 @@ public:
}
//- Mutable access to the loaded dynamic libraries
dlLibraryTable& libs() const
dlLibraryTable& libs() const noexcept
{
return libs_;
}
@ -518,7 +518,7 @@ public:
//- sub-cycles.
// The interpretation of non-zero values is dependent on the
// routine.
label subCycling() const
label subCycling() const noexcept
{
return subCycling_;
}

View File

@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef TimePaths_H
#define TimePaths_H
#ifndef Foam_TimePaths_H
#define Foam_TimePaths_H
#include "fileName.H"
#include "instantList.H"
@ -122,16 +122,16 @@ public:
inline bool processorCase(const bool isProcessorCase) noexcept;
//- Return root path
inline const fileName& rootPath() const;
inline const fileName& rootPath() const noexcept;
//- Return global case name
inline const fileName& globalCaseName() const;
inline const fileName& globalCaseName() const noexcept;
//- Return case name
inline const fileName& caseName() const;
inline const fileName& caseName() const noexcept;
//- The case name for modification (use with caution)
inline fileName& caseName();
inline fileName& caseName() noexcept;
//- Return path for the case
inline fileName path() const;
@ -154,10 +154,10 @@ public:
//- Return constant name
inline const word& constant() const;
inline const word& constant() const noexcept;
//- Return system name
inline const word& system() const;
inline const word& system() const noexcept;
//- Return the constant name for the case, which is
//- \c ../constant() for parallel runs.

View File

@ -47,25 +47,25 @@ inline bool Foam::TimePaths::processorCase(bool isProcessorCase) noexcept
}
inline const Foam::fileName& Foam::TimePaths::rootPath() const
inline const Foam::fileName& Foam::TimePaths::rootPath() const noexcept
{
return rootPath_;
}
inline const Foam::fileName& Foam::TimePaths::globalCaseName() const
inline const Foam::fileName& Foam::TimePaths::globalCaseName() const noexcept
{
return globalCaseName_;
}
inline const Foam::fileName& Foam::TimePaths::caseName() const
inline const Foam::fileName& Foam::TimePaths::caseName() const noexcept
{
return case_;
}
inline Foam::fileName& Foam::TimePaths::caseName()
inline Foam::fileName& Foam::TimePaths::caseName() noexcept
{
return case_;
}
@ -93,13 +93,13 @@ inline Foam::fileName Foam::TimePaths::relativePath
}
inline const Foam::word& Foam::TimePaths::constant() const
inline const Foam::word& Foam::TimePaths::constant() const noexcept
{
return constant_;
}
inline const Foam::word& Foam::TimePaths::system() const
inline const Foam::word& Foam::TimePaths::system() const noexcept
{
return system_;
}

View File

@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef TimeState_H
#define TimeState_H
#ifndef Foam_TimeState_H
#define Foam_TimeState_H
#include "dimensionedScalar.H"

View File

@ -360,13 +360,16 @@ public:
inline dimensionSet& dimensions() noexcept;
//- Return oriented type
inline const orientedType& oriented() const noexcept;
inline orientedType oriented() const noexcept;
//- Return non-const access to the oriented type
inline orientedType& oriented() noexcept;
//- Set the oriented flag
inline void setOriented(const bool oriented = true) noexcept;
//- True if field is ORIENTED
inline bool is_oriented() const noexcept;
//- Set the oriented flag: on/off
inline void setOriented(bool on = true) noexcept;
//- Return const-reference to the field values
inline const Field<Type>& field() const noexcept;

View File

@ -61,7 +61,7 @@ Foam::DimensionedField<Type, GeoMesh>::dimensions() noexcept
template<class Type, class GeoMesh>
inline const Foam::orientedType&
inline Foam::orientedType
Foam::DimensionedField<Type, GeoMesh>::oriented() const noexcept
{
return oriented_;
@ -77,12 +77,16 @@ Foam::DimensionedField<Type, GeoMesh>::oriented() noexcept
template<class Type, class GeoMesh>
inline void Foam::DimensionedField<Type, GeoMesh>::setOriented
(
const bool oriented
) noexcept
inline bool Foam::DimensionedField<Type, GeoMesh>::is_oriented() const noexcept
{
oriented_.setOriented(oriented);
return oriented_.is_oriented();
}
template<class Type, class GeoMesh>
inline void Foam::DimensionedField<Type, GeoMesh>::setOriented(bool on) noexcept
{
oriented_.setOriented(on);
}

View File

@ -50,37 +50,19 @@ bool Foam::orientedType::checkType
(
const orientedType& ot1,
const orientedType& ot2
)
) noexcept
{
return
(
(ot1.oriented() == UNKNOWN)
|| (ot2.oriented() == UNKNOWN)
|| (ot1.oriented() == ot2.oriented())
(ot1.oriented() == ot2.oriented())
|| (ot1.oriented() == orientedType::UNKNOWN)
|| (ot2.oriented() == orientedType::UNKNOWN)
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::orientedType::orientedType() noexcept
:
oriented_(UNKNOWN)
{}
Foam::orientedType::orientedType(const orientedType& ot) noexcept
:
oriented_(ot.oriented_)
{}
Foam::orientedType::orientedType(const bool isOriented) noexcept
:
oriented_(isOriented ? ORIENTED : UNORIENTED)
{}
Foam::orientedType::orientedType(Istream& is)
:
oriented_(orientedOptionNames.read(is))
@ -91,24 +73,6 @@ Foam::orientedType::orientedType(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::orientedType::orientedOption& Foam::orientedType::oriented() noexcept
{
return oriented_;
}
Foam::orientedType::orientedOption Foam::orientedType::oriented() const noexcept
{
return oriented_;
}
void Foam::orientedType::setOriented(const bool on) noexcept
{
oriented_ = on ? ORIENTED : UNORIENTED;
}
void Foam::orientedType::read(const dictionary& dict)
{
oriented_ = orientedOptionNames.getOrDefault
@ -136,13 +100,6 @@ bool Foam::orientedType::writeEntry(Ostream& os) const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::orientedType::operator=(const orientedType& ot)
{
// Oriented state is inherited on assignment
oriented_ = ot.oriented();
}
void Foam::orientedType::operator+=(const orientedType& ot)
{
// Set the oriented status if it was unknown
@ -183,29 +140,13 @@ void Foam::orientedType::operator-=(const orientedType& ot)
void Foam::orientedType::operator*=(const orientedType& ot)
{
const orientedType& ot1 = *this;
if (ot1() ^ ot())
{
oriented_ = ORIENTED;
}
else
{
oriented_ = UNORIENTED;
}
setOriented(is_oriented() != ot.is_oriented());
}
void Foam::orientedType::operator/=(const orientedType& ot)
{
const orientedType& ot1 = *this;
if (ot1() ^ ot())
{
oriented_ = ORIENTED;
}
else
{
oriented_ = UNORIENTED;
}
setOriented(is_oriented() != ot.is_oriented());
}
@ -221,12 +162,6 @@ void Foam::orientedType::operator/=(const scalar s)
}
bool Foam::orientedType::operator()() const noexcept
{
return oriented_ == ORIENTED;
}
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
Foam::orientedType Foam::max(const orientedType& ot1, const orientedType& ot2)
@ -492,8 +427,7 @@ Foam::orientedType Foam::operator+
<< abort(FatalError);
}
// Note use of () operators to convert to boolean op
return orientedType(ot1() || ot2());
return orientedType(ot1.is_oriented() || ot2.is_oriented());
}
@ -518,8 +452,7 @@ Foam::orientedType Foam::operator-
<< abort(FatalError);
}
// Note use of () operators to convert to boolean op
return orientedType(ot1() || ot2());
return orientedType(ot1.is_oriented() || ot2.is_oriented());
}
@ -561,8 +494,7 @@ Foam::orientedType Foam::operator^
const orientedType& ot2
)
{
// Note use of () operators to convert to boolean op
return orientedType(ot1() ^ ot2());
return orientedType(ot1.is_oriented() != ot2.is_oriented());
}

View File

@ -82,16 +82,34 @@ private:
public:
// Generated Methods
//- Copy construct
orientedType(const orientedType&) noexcept = default;
//- Copy assignment
orientedType& operator=(const orientedType&) noexcept = default;
// Constructors
//- Default construct as \c UNKNOWN
orientedType() noexcept;
constexpr orientedType() noexcept
:
oriented_(UNKNOWN)
{}
//- Copy construct
orientedType(const orientedType& ot) noexcept;
//- Implicit construct from enumeration
orientedType(orientedOption opt) noexcept
:
oriented_(opt)
{}
//- Construct from bool
explicit orientedType(const bool isOriented) noexcept;
explicit constexpr orientedType(const bool isOriented) noexcept
:
oriented_(isOriented ? ORIENTED : UNORIENTED)
{}
//- Construct from Istream
explicit orientedType(Istream& is);
@ -104,16 +122,22 @@ public:
(
const orientedType& ot1,
const orientedType& ot2
);
//- Return non-const reference to the oriented flag
orientedOption& oriented() noexcept;
) noexcept;
//- Return the oriented flag
orientedOption oriented() const noexcept;
orientedOption oriented() const noexcept { return oriented_; }
//- Return non-const reference to the oriented flag
orientedOption& oriented() noexcept { return oriented_; }
//- True if \c ORIENTED
bool is_oriented() const noexcept { return (oriented_ == ORIENTED); }
//- Set the oriented flag: on/off
void setOriented(const bool on = true) noexcept;
void setOriented(bool on = true) noexcept
{
oriented_ = on ? ORIENTED : UNORIENTED;
}
//- Read the "oriented" state from dictionary
void read(const dictionary& dict);
@ -125,14 +149,6 @@ public:
// Member Operators
//- True if type is \c ORIENTED
explicit operator bool() const noexcept
{
return (oriented_ == orientedOption::ORIENTED);
}
void operator=(const orientedType& ot);
void operator+=(const orientedType& ot);
void operator-=(const orientedType& ot);
void operator*=(const orientedType& ot);
@ -140,8 +156,8 @@ public:
void operator*=(const scalar s);
void operator/=(const scalar s);
//- True if type is \c ORIENTED. Same as bool operator
bool operator()() const noexcept;
//- Convert to bool. Same as is_oriented()
bool operator()() const noexcept { return is_oriented(); }
// IOstream Operators

View File

@ -144,7 +144,7 @@ public:
inline tmp<surfaceScalarField> phi() const;
//- Is combustion active?
inline const Switch& active() const;
inline Switch active() const noexcept;
//- Return const dictionary of the model
inline const dictionary& coeffs() const;

View File

@ -52,7 +52,7 @@ inline Foam::tmp<Foam::surfaceScalarField> Foam::combustionModel::phi() const
}
inline const Foam::Switch& Foam::combustionModel::active() const
inline Foam::Switch Foam::combustionModel::active() const noexcept
{
return active_;
}

View File

@ -303,31 +303,31 @@ public:
}
//- Pure free-surface
const Switch& pureFreeSurface() const
Switch pureFreeSurface() const noexcept
{
return pureFreeSurface_;
}
//- Rigid free-surface
const Switch& rigidFreeSurface() const
Switch rigidFreeSurface() const noexcept
{
return rigidFreeSurface_;
}
//- Rigid free-surface
Switch& rigidFreeSurface()
Switch& rigidFreeSurface() noexcept
{
return rigidFreeSurface_;
}
//- Correct contact line point normals
const Switch& correctContactLineNormals() const
Switch correctContactLineNormals() const noexcept
{
return correctContactLineNormals_;
}
//- Correct contact line point normals
Switch& correctContactLineNormals()
Switch& correctContactLineNormals() noexcept
{
return correctContactLineNormals_;
}

View File

@ -118,7 +118,7 @@ void Foam::dynamicRefineFvMesh::mapNewInternalFaces
GeoField& sFld = *iter();
if (sFld.oriented()())
if (sFld.is_oriented())
{
WarningInFunction << "Ignoring mapping oriented field "
<< sFld.name() << " since of type " << sFld.type()
@ -154,7 +154,7 @@ void Foam::dynamicRefineFvMesh::mapNewInternalFaces
GeoField& sFld = *iter();
if (sFld.oriented()())
if (sFld.is_oriented())
{
DebugInfo
<< "dynamicRefineFvMesh::mapNewInternalFaces(): "

View File

@ -282,7 +282,7 @@ void Foam::fvMeshDistribute::mapExposedFaces
forAllIters(flds, iter)
{
fldType& fld = *iter();
const bool oriented = fld.oriented()();
const bool oriented = fld.is_oriented();
typename fldType::Boundary& bfld = fld.boundaryFieldRef();

View File

@ -142,8 +142,7 @@ void Foam::fvsPatchField<Type>::check(const fvsPatchField<Type>& ptf) const
template<class Type>
void Foam::fvsPatchField<Type>::autoMap(const fvPatchFieldMapper& m)
{
const bool oriented = internalField_.oriented()();
Field<Type>::autoMap(m, oriented);
Field<Type>::autoMap(m, internalField_.is_oriented());
}

View File

@ -351,7 +351,7 @@ Foam::fvMeshSubset::interpolate
{
Type val = vf.internalField()[baseFacei];
if (cellMap[fc[i]] == own[baseFacei] || !vf.oriented()())
if (cellMap[fc[i]] == own[baseFacei] || !vf.is_oriented())
{
pfld[i] = val;
}

View File

@ -74,9 +74,9 @@ void MapInternalField<Type, MeshMapper, surfaceMesh>::operator()
// Passing in oriented flag so that oriented fields (e.g. phi) are negated
// if flipped. Un-oriented fields, e.g U interpolated to faces (Uf) are not
// touched
field.autoMap(mapper.surfaceMap(), field.oriented()());
field.autoMap(mapper.surfaceMap(), field.is_oriented());
if (field.oriented()())
if (field.is_oriented())
{
// Flip the flux
const labelList flipFaces = mapper.surfaceMap().flipFaceFlux().toc();

View File

@ -598,10 +598,10 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
if (debug)
{
Pout<< "field " << field.name() << " oriented: "
<< field.oriented()() << endl;
<< field.is_oriented() << endl;
}
if (field.oriented()())
if (field.is_oriented())
{
forAll(values, i)
{

View File

@ -326,7 +326,7 @@ Foam::fvFieldDecomposer::decomposeField
)
);
if (resF.oriented()())
if (resF.is_oriented())
{
bf[patchi] *= faceSign_[patchi];
}
@ -348,7 +348,7 @@ Foam::fvFieldDecomposer::decomposeField
)
);
if (resF.oriented()())
if (resF.is_oriented())
{
bf[patchi] *= faceSign_[patchi];
}