diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phasePair/phasePairKey/phasePairKey.C b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phasePair/phasePairKey/phasePairKey.C index 5115d8ddc7..1604ec51d4 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phasePair/phasePairKey/phasePairKey.C +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phasePair/phasePairKey/phasePairKey.C @@ -27,14 +27,6 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::phasePairKey::hash::hash() -{} - - -Foam::phasePairKey::phasePairKey() -{} - - Foam::phasePairKey::phasePairKey ( const word& name1, @@ -71,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator() word::hash()(key.second()) ); } - else - { - return - word::hash()(key.first()) - + word::hash()(key.second()); - } + + return word::hash()(key.first()) + word::hash()(key.second()); } @@ -88,14 +76,13 @@ bool Foam::operator== const phasePairKey& b ) { - const label c = Pair::compare(a,b); + const auto cmp = Pair::compare(a,b); return + ( (a.ordered_ == b.ordered_) - && ( - (a.ordered_ && (c == 1)) - || (!a.ordered_ && (c != 0)) - ); + && (a.ordered_ ? (cmp == 1) : cmp) + ); } @@ -121,7 +108,7 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key) { key.ordered_ = false; } - else if(temp[1] == "to") + else if (temp[1] == "to") { key.ordered_ = true; } @@ -130,8 +117,8 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key) FatalErrorInFunction << "Phase pair type is not recognised. " << temp - << "Use (phaseDispersed to phaseContinuous) for an ordered" - << "pair, or (phase1 and pase2) for an unordered pair." + << "Use (phaseDispersed to phaseContinuous) for an ordered pair, " + << "or (phase1 and phase2) for an unordered pair." << exit(FatalError); } diff --git a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phasePair/phasePairKey/phasePairKey.H b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phasePair/phasePairKey/phasePairKey.H index babb4b887b..13d711eab4 100644 --- a/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phasePair/phasePairKey/phasePairKey.H +++ b/applications/solvers/multiphase/icoReactingMultiphaseInterFoam/phasesSystem/phasePair/phasePairKey/phasePairKey.H @@ -40,6 +40,15 @@ SourceFiles namespace Foam { +// Forward declarations +class phasePairKey; + +bool operator==(const phasePairKey& a, const phasePairKey& b); +bool operator!=(const phasePairKey& a, const phasePairKey& b); + +Istream& operator>>(Istream& is, phasePairKey& key); +Ostream& operator<<(Ostream& os, const phasePairKey& key); + /*---------------------------------------------------------------------------*\ Class phasePairKey Declaration \*---------------------------------------------------------------------------*/ @@ -48,29 +57,6 @@ class phasePairKey : public Pair { -public: - - class hash - : - public Hash - { - public: - - // Constructors - - //- Construct null - hash(); - - - // Member operators - - //- Generate a hash from a phase pair key - label operator()(const phasePairKey& key) const; - }; - - -private: - // Private data //- Flag to indicate whether ordering is important @@ -79,12 +65,20 @@ private: public: + //- Ordered or unordered hashing of word pair + struct hash + { + //- Generate a hash from a phase pair key + label operator()(const phasePairKey& key) const; + }; + + // Constructors //- Construct null - phasePairKey(); + phasePairKey() {} // = default - //- Construct from names and the ordering flag + //- Construct from names and optional ordering flag phasePairKey ( const word& name1, @@ -93,7 +87,7 @@ public: ); - // Destructor + //- Destructor virtual ~phasePairKey() = default; @@ -105,16 +99,16 @@ public: // Friend Operators - //- Test if keys are equal + //- Test for equality friend bool operator==(const phasePairKey& a, const phasePairKey& b); - //- Test if keys are unequal + //- Test for inequality friend bool operator!=(const phasePairKey& a, const phasePairKey& b); - //- Read from stdin + //- Read from Istream friend Istream& operator>>(Istream& is, phasePairKey& key); - //- Write to stdout + //- Write to Ostream friend Ostream& operator<<(Ostream& os, const phasePairKey& key); }; diff --git a/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePairKey/phasePairKey.C b/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePairKey/phasePairKey.C index c3cebe7b5c..326c333889 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePairKey/phasePairKey.C +++ b/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePairKey/phasePairKey.C @@ -63,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator() word::hash()(key.second()) ); } - else - { - return - word::hash()(key.first()) - + word::hash()(key.second()); - } + + return word::hash()(key.first()) + word::hash()(key.second()); } @@ -80,14 +76,13 @@ bool Foam::operator== const phasePairKey& b ) { - const label cmp = Pair::compare(a,b); + const auto cmp = Pair::compare(a,b); return + ( (a.ordered_ == b.ordered_) - && ( - (a.ordered_ && (cmp == 1)) - || (!a.ordered_ && (cmp != 0)) - ); + && (a.ordered_ ? (cmp == 1) : cmp) + ); } diff --git a/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePairKey/phasePairKey.H b/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePairKey/phasePairKey.H index dae60dafcc..919ddaf7a7 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePairKey/phasePairKey.H +++ b/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/phasePair/phasePairKey/phasePairKey.H @@ -41,14 +41,13 @@ namespace Foam { // Forward declarations - class phasePairKey; -bool operator==(const phasePairKey&, const phasePairKey&); -bool operator!=(const phasePairKey&, const phasePairKey&); +bool operator==(const phasePairKey& a, const phasePairKey& b); +bool operator!=(const phasePairKey& a, const phasePairKey& b); -Istream& operator>>(Istream&, phasePairKey&); -Ostream& operator<<(Ostream&, const phasePairKey&); +Istream& operator>>(Istream& is, phasePairKey& key); +Ostream& operator<<(Ostream& os, const phasePairKey& key); /*---------------------------------------------------------------------------*\ @@ -64,11 +63,13 @@ class phasePairKey //- Flag to indicate whether ordering is important bool ordered_; + public: + //- Ordered or unordered hashing of word pair struct hash { - // Generate a hash from a phase pair key + //- Generate a hash from a phase pair key label operator()(const phasePairKey& key) const; }; @@ -78,7 +79,7 @@ public: //- Construct null phasePairKey() {} // = default - //- Construct from names and the ordering flag + //- Construct from names and optional ordering flag phasePairKey ( const word& name1, @@ -87,7 +88,7 @@ public: ); - // Destructor + //- Destructor virtual ~phasePairKey() = default; @@ -99,16 +100,16 @@ public: // Friend Operators - //- Test if keys are equal + //- Test for equality friend bool operator==(const phasePairKey& a, const phasePairKey& b); - //- Test if keys are unequal + //- Test for inequality friend bool operator!=(const phasePairKey& a, const phasePairKey& b); - //- Read from stdin + //- Read from Istream friend Istream& operator>>(Istream& is, phasePairKey& key); - //- Write to stdout + //- Write to Ostream friend Ostream& operator<<(Ostream& os, const phasePairKey& key); }; diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phasePair/phasePairKey/phasePairKey.C b/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phasePair/phasePairKey/phasePairKey.C index b9bec10152..cf1097602e 100644 --- a/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phasePair/phasePairKey/phasePairKey.C +++ b/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phasePair/phasePairKey/phasePairKey.C @@ -39,6 +39,14 @@ Foam::phasePairKey::phasePairKey {} +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +bool Foam::phasePairKey::ordered() const +{ + return ordered_; +} + + // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // Foam::label Foam::phasePairKey::hash::operator() @@ -55,12 +63,8 @@ Foam::label Foam::phasePairKey::hash::operator() word::hash()(key.second()) ); } - else - { - return - word::hash()(key.first()) - + word::hash()(key.second()); - } + + return word::hash()(key.first()) + word::hash()(key.second()); } @@ -72,14 +76,13 @@ bool Foam::operator== const phasePairKey& b ) { - const label cmp = Pair::compare(a,b); + const auto cmp = Pair::compare(a,b); return + ( (a.ordered_ == b.ordered_) - && ( - (a.ordered_ && (cmp == 1)) - || (!a.ordered_ && (cmp != 0)) - ); + && (a.ordered_ ? (cmp == 1) : cmp) + ); } @@ -114,8 +117,8 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key) FatalErrorInFunction << "Phase pair type is not recognised. " << temp - << "Use (phaseDispersed in phaseContinuous) for an ordered" - << "pair, or (phase1 and pase2) for an unordered pair." + << "Use (phaseDispersed in phaseContinuous) for an ordered pair, " + << "or (phase1 and phase2) for an unordered pair." << exit(FatalError); } diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phasePair/phasePairKey/phasePairKey.H b/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phasePair/phasePairKey/phasePairKey.H index eaa257df9f..6f9203b405 100644 --- a/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phasePair/phasePairKey/phasePairKey.H +++ b/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phasePair/phasePairKey/phasePairKey.H @@ -41,15 +41,13 @@ namespace Foam { // Forward declarations - class phasePairKey; -bool operator==(const phasePairKey&, const phasePairKey&); -bool operator!=(const phasePairKey&, const phasePairKey&); - -Istream& operator>>(Istream&, phasePairKey&); -Ostream& operator<<(Ostream&, const phasePairKey&); +bool operator==(const phasePairKey& a, const phasePairKey& b); +bool operator!=(const phasePairKey& a, const phasePairKey& b); +Istream& operator>>(Istream& is, phasePairKey& key); +Ostream& operator<<(Ostream& os, const phasePairKey& key); /*---------------------------------------------------------------------------*\ Class phasePairKey Declaration @@ -66,9 +64,10 @@ class phasePairKey public: + //- Ordered or unordered hashing of word pair struct hash { - // Generate a hash from a phase pair key + //- Generate a hash from a phase pair key label operator()(const phasePairKey& key) const; }; @@ -78,31 +77,37 @@ public: //- Construct null phasePairKey() {} // = default - //- Construct from names and the ordering flag + //- Construct from names and optional ordering flag phasePairKey ( const word& name1, const word& name2, - const bool ordered + const bool ordered = false ); - // Destructor + //- Destructor virtual ~phasePairKey() = default; + // Access + + //- Return the ordered flag + bool ordered() const; + + // Friend Operators - //- Test if keys are equal + //- Test for equality friend bool operator==(const phasePairKey& a, const phasePairKey& b); - //- Test if keys are unequal + //- Test for inequality friend bool operator!=(const phasePairKey& a, const phasePairKey& b); - //- Read from stdin + //- Read from Istream friend Istream& operator>>(Istream& is, phasePairKey& key); - //- Write to stdout + //- Write to Ostream friend Ostream& operator<<(Ostream& os, const phasePairKey& key); };