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) 2014-2018 OpenFOAM Foundation
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 
35 
37 {}
38 
39 
41 (
42  const word& name1,
43  const word& name2,
44  const bool ordered
45 )
46 :
47  Pair<word>(name1, name2),
48  ordered_(ordered)
49 {}
50 
51 
52 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
53 
55 {}
56 
57 
58 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
59 
61 {
62  return ordered_;
63 }
64 
65 
66 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
67 
68 Foam::label Foam::phasePairKey::hash::operator()
69 (
70  const phasePairKey& key
71 ) const
72 {
73  if (key.ordered_)
74  {
75  return
76  word::hash()
77  (
78  key.first(),
79  word::hash()(key.second())
80  );
81  }
82  else
83  {
84  return
85  word::hash()(key.first())
86  + word::hash()(key.second());
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
92 
93 bool Foam::operator==
94 (
95  const phasePairKey& a,
96  const phasePairKey& b
97 )
98 {
99  const label c = Pair<word>::compare(a, b);
100 
101  return
102  (a.ordered_ == b.ordered_)
103  && (
104  (a.ordered_ && (c == 1))
105  || (!a.ordered_ && (c != 0))
106  );
107 }
108 
109 
110 bool Foam::operator!=
111 (
112  const phasePairKey& a,
113  const phasePairKey& b
114 )
115 {
116  return !(a == b);
117 }
118 
119 
120 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
121 
123 {
124  const FixedList<word, 3> temp(is);
125 
126  key.first() = temp[0];
127 
128  if (temp[1] == "and")
129  {
130  key.ordered_ = false;
131  }
132  else if (temp[1] == "in")
133  {
134  key.ordered_ = true;
135  }
136  else
137  {
139  << "Phase pair type is not recognised. "
140  << temp
141  << "Use (phaseDispersed in phaseContinuous) for an ordered"
142  << "pair, or (phase1 and pase2) for an unordered pair."
143  << exit(FatalError);
144  }
145 
146  key.second() = temp[2];
147 
148  return is;
149 }
150 
151 
152 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
153 
155 {
156  os << token::BEGIN_LIST
157  << key.first()
158  << token::SPACE
159  << (key.ordered_ ? "in" : "and")
160  << token::SPACE
161  << key.second()
162  << token::END_LIST;
163 
164  return os;
165 }
166 
167 
168 // ************************************************************************* //
Foam::Pair::second
const T & second() const noexcept
Return second element, which is also the last element.
Definition: PairI.H:122
phasePairKey.H
Foam::phasePairKey::~phasePairKey
virtual ~phasePairKey()
Definition: phasePairKey.C:54
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:228
Foam::phasePairKey::phasePairKey
phasePairKey()
Construct null.
Definition: phasePairKey.C:36
Foam::Pair::compare
static int compare(const Pair< T > &a, const Pair< T > &b)
Compare Pairs.
Definition: PairI.H:33
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:59
Foam::FatalError
error FatalError
Foam::phasePairKey::ordered
bool ordered() const
Return the ordered flag.
Definition: phasePairKey.C:60
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:355
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:112
Foam::phasePairKey::hash::hash
hash()
Definition: phasePairKey.C:32
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:118
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
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:117
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102