phasePairKey.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "phasePairKey.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 (
34  const word& name1,
35  const word& name2,
36  const bool ordered
37 )
38 :
39  Pair<word>(name1, name2),
40  ordered_(ordered)
41 {}
42 
43 
44 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
45 
47 {
48  return ordered_;
49 }
50 
51 
52 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
53 
54 Foam::label Foam::phasePairKey::hash::operator()
55 (
56  const phasePairKey& key
57 ) const
58 {
59  if (key.ordered_)
60  {
61  return
62  word::hash()
63  (
64  key.first(),
65  word::hash()(key.second())
66  );
67  }
68 
69  return word::hash()(key.first()) + word::hash()(key.second());
70 }
71 
72 
73 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
74 
75 bool Foam::operator==
76 (
77  const phasePairKey& a,
78  const phasePairKey& b
79 )
80 {
81  const auto cmp = Pair<word>::compare(a,b);
82 
83  return
84  (
85  (a.ordered_ == b.ordered_)
86  && (a.ordered_ ? (cmp == 1) : cmp)
87  );
88 }
89 
90 
91 bool Foam::operator!=
92 (
93  const phasePairKey& a,
94  const phasePairKey& b
95 )
96 {
97  return !(a == b);
98 }
99 
100 
101 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
102 
104 {
105  const FixedList<word, 3> temp(is);
106 
107  key.first() = temp[0];
108 
109  if (temp[1] == "and")
110  {
111  key.ordered_ = false;
112  }
113  else if (temp[1] == "to")
114  {
115  key.ordered_ = true;
116  }
117  else
118  {
120  << "Phase pair type is not recognised. "
121  << temp
122  << "Use (phaseDispersed to phaseContinuous) for an ordered pair, "
123  << "or (phase1 and phase2) for an unordered pair."
124  << exit(FatalError);
125  }
126 
127  key.second() = temp[2];
128 
129  return is;
130 }
131 
132 
133 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
134 
136 {
137  os << token::BEGIN_LIST
138  << key.first()
139  << token::SPACE
140  << (key.ordered_ ? "to" : "and")
141  << token::SPACE
142  << key.second()
143  << token::END_LIST;
144 
145  return os;
146 }
147 
148 
149 // ************************************************************************* //
Foam::Pair::second
const T & second() const noexcept
Return second element, which is also the last element.
Definition: PairI.H:122
phasePairKey.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::phasePairKey::phasePairKey
phasePairKey()
Construct null.
Definition: phasePairKey.H:80
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Pair::compare
static int compare(const Pair< T > &a, const Pair< T > &b)
Compare Pairs.
Definition: PairI.H:33
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::string::hash
Hashing function for string and derived string classes.
Definition: string.H:151
Foam::phasePairKey
Definition: phasePairKey.H:57
Foam::FatalError
error FatalError
Foam::phasePairKey::ordered
bool ordered() const
Return the ordered flag.
Definition: phasePairKey.C:46
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::Pair< word >
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::token::SPACE
Space [isspace].
Definition: token.H:117
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:123
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:122