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_; return name_;
} }
const Switch& forceInitialPointInsertion() const Switch forceInitialPointInsertion() const noexcept
{ {
return forceInitialPointInsertion_; return forceInitialPointInsertion_;
} }

View File

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

View File

@ -224,7 +224,7 @@ Foam::parFvFieldDistributor::distributeField
} }
// Map all faces // 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) // Trim to internal faces (note: could also have special mapper)
primitiveField.resize primitiveField.resize

View File

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

View File

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

View File

@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef TimePaths_H #ifndef Foam_TimePaths_H
#define TimePaths_H #define Foam_TimePaths_H
#include "fileName.H" #include "fileName.H"
#include "instantList.H" #include "instantList.H"
@ -122,16 +122,16 @@ public:
inline bool processorCase(const bool isProcessorCase) noexcept; inline bool processorCase(const bool isProcessorCase) noexcept;
//- Return root path //- Return root path
inline const fileName& rootPath() const; inline const fileName& rootPath() const noexcept;
//- Return global case name //- Return global case name
inline const fileName& globalCaseName() const; inline const fileName& globalCaseName() const noexcept;
//- Return case name //- Return case name
inline const fileName& caseName() const; inline const fileName& caseName() const noexcept;
//- The case name for modification (use with caution) //- The case name for modification (use with caution)
inline fileName& caseName(); inline fileName& caseName() noexcept;
//- Return path for the case //- Return path for the case
inline fileName path() const; inline fileName path() const;
@ -154,10 +154,10 @@ public:
//- Return constant name //- Return constant name
inline const word& constant() const; inline const word& constant() const noexcept;
//- Return system name //- Return system name
inline const word& system() const; inline const word& system() const noexcept;
//- Return the constant name for the case, which is //- Return the constant name for the case, which is
//- \c ../constant() for parallel runs. //- \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_; return rootPath_;
} }
inline const Foam::fileName& Foam::TimePaths::globalCaseName() const inline const Foam::fileName& Foam::TimePaths::globalCaseName() const noexcept
{ {
return globalCaseName_; return globalCaseName_;
} }
inline const Foam::fileName& Foam::TimePaths::caseName() const inline const Foam::fileName& Foam::TimePaths::caseName() const noexcept
{ {
return case_; return case_;
} }
inline Foam::fileName& Foam::TimePaths::caseName() inline Foam::fileName& Foam::TimePaths::caseName() noexcept
{ {
return case_; 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_; return constant_;
} }
inline const Foam::word& Foam::TimePaths::system() const inline const Foam::word& Foam::TimePaths::system() const noexcept
{ {
return system_; return system_;
} }

View File

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

View File

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

View File

@ -61,7 +61,7 @@ Foam::DimensionedField<Type, GeoMesh>::dimensions() noexcept
template<class Type, class GeoMesh> template<class Type, class GeoMesh>
inline const Foam::orientedType& inline Foam::orientedType
Foam::DimensionedField<Type, GeoMesh>::oriented() const noexcept Foam::DimensionedField<Type, GeoMesh>::oriented() const noexcept
{ {
return oriented_; return oriented_;
@ -77,12 +77,16 @@ Foam::DimensionedField<Type, GeoMesh>::oriented() noexcept
template<class Type, class GeoMesh> template<class Type, class GeoMesh>
inline void Foam::DimensionedField<Type, GeoMesh>::setOriented inline bool Foam::DimensionedField<Type, GeoMesh>::is_oriented() const noexcept
(
const bool oriented
) 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& ot1,
const orientedType& ot2 const orientedType& ot2
) ) noexcept
{ {
return return
( (
(ot1.oriented() == UNKNOWN) (ot1.oriented() == ot2.oriented())
|| (ot2.oriented() == UNKNOWN) || (ot1.oriented() == orientedType::UNKNOWN)
|| (ot1.oriented() == ot2.oriented()) || (ot2.oriented() == orientedType::UNKNOWN)
); );
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * 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) Foam::orientedType::orientedType(Istream& is)
: :
oriented_(orientedOptionNames.read(is)) oriented_(orientedOptionNames.read(is))
@ -91,24 +73,6 @@ Foam::orientedType::orientedType(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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) void Foam::orientedType::read(const dictionary& dict)
{ {
oriented_ = orientedOptionNames.getOrDefault oriented_ = orientedOptionNames.getOrDefault
@ -136,13 +100,6 @@ bool Foam::orientedType::writeEntry(Ostream& os) const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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) void Foam::orientedType::operator+=(const orientedType& ot)
{ {
// Set the oriented status if it was unknown // 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) void Foam::orientedType::operator*=(const orientedType& ot)
{ {
const orientedType& ot1 = *this; setOriented(is_oriented() != ot.is_oriented());
if (ot1() ^ ot())
{
oriented_ = ORIENTED;
}
else
{
oriented_ = UNORIENTED;
}
} }
void Foam::orientedType::operator/=(const orientedType& ot) void Foam::orientedType::operator/=(const orientedType& ot)
{ {
const orientedType& ot1 = *this; setOriented(is_oriented() != ot.is_oriented());
if (ot1() ^ ot())
{
oriented_ = ORIENTED;
}
else
{
oriented_ = UNORIENTED;
}
} }
@ -221,12 +162,6 @@ void Foam::orientedType::operator/=(const scalar s)
} }
bool Foam::orientedType::operator()() const noexcept
{
return oriented_ == ORIENTED;
}
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
Foam::orientedType Foam::max(const orientedType& ot1, const orientedType& ot2) Foam::orientedType Foam::max(const orientedType& ot1, const orientedType& ot2)
@ -492,8 +427,7 @@ Foam::orientedType Foam::operator+
<< abort(FatalError); << abort(FatalError);
} }
// Note use of () operators to convert to boolean op return orientedType(ot1.is_oriented() || ot2.is_oriented());
return orientedType(ot1() || ot2());
} }
@ -518,8 +452,7 @@ Foam::orientedType Foam::operator-
<< abort(FatalError); << abort(FatalError);
} }
// Note use of () operators to convert to boolean op return orientedType(ot1.is_oriented() || ot2.is_oriented());
return orientedType(ot1() || ot2());
} }
@ -561,8 +494,7 @@ Foam::orientedType Foam::operator^
const orientedType& ot2 const orientedType& ot2
) )
{ {
// Note use of () operators to convert to boolean op return orientedType(ot1.is_oriented() != ot2.is_oriented());
return orientedType(ot1() ^ ot2());
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -282,7 +282,7 @@ void Foam::fvMeshDistribute::mapExposedFaces
forAllIters(flds, iter) forAllIters(flds, iter)
{ {
fldType& fld = *iter(); fldType& fld = *iter();
const bool oriented = fld.oriented()(); const bool oriented = fld.is_oriented();
typename fldType::Boundary& bfld = fld.boundaryFieldRef(); 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> template<class Type>
void Foam::fvsPatchField<Type>::autoMap(const fvPatchFieldMapper& m) void Foam::fvsPatchField<Type>::autoMap(const fvPatchFieldMapper& m)
{ {
const bool oriented = internalField_.oriented()(); Field<Type>::autoMap(m, internalField_.is_oriented());
Field<Type>::autoMap(m, oriented);
} }

View File

@ -351,7 +351,7 @@ Foam::fvMeshSubset::interpolate
{ {
Type val = vf.internalField()[baseFacei]; 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; 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 // 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 // if flipped. Un-oriented fields, e.g U interpolated to faces (Uf) are not
// touched // touched
field.autoMap(mapper.surfaceMap(), field.oriented()()); field.autoMap(mapper.surfaceMap(), field.is_oriented());
if (field.oriented()()) if (field.is_oriented())
{ {
// Flip the flux // Flip the flux
const labelList flipFaces = mapper.surfaceMap().flipFaceFlux().toc(); const labelList flipFaces = mapper.surfaceMap().flipFaceFlux().toc();

View File

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

View File

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