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 | Copyright (C) 2014-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "phasePairKey.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 {}
32 
33 
35 {}
36 
37 
39 (
40  const word& name1,
41  const word& name2,
42  const bool ordered
43 )
44 :
45  Pair<word>(name1, name2),
46  ordered_(ordered)
47 {}
48 
49 
50 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
51 
53 {}
54 
55 
56 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
57 
58 bool Foam::phasePairKey::ordered() const
59 {
60  return ordered_;
61 }
62 
63 
64 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
65 
66 Foam::label Foam::phasePairKey::hash::operator()
67 (
68  const phasePairKey& key
69 ) const
70 {
71  if (key.ordered_)
72  {
73  return
74  word::hash()
75  (
76  key.first(),
77  word::hash()(key.second())
78  );
79  }
80  else
81  {
82  return
83  word::hash()(key.first())
84  + word::hash()(key.second());
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
90 
91 bool Foam::operator==
92 (
93  const phasePairKey& a,
94  const phasePairKey& b
95 )
96 {
97  const label c = Pair<word>::compare(a,b);
98 
99  return
100  (a.ordered_ == b.ordered_)
101  && (
102  (a.ordered_ && (c == 1))
103  || (!a.ordered_ && (c != 0))
104  );
105 }
106 
107 
108 bool Foam::operator!=
109 (
110  const phasePairKey& a,
111  const phasePairKey& b
112 )
113 {
114  return !(a == b);
115 }
116 
117 
118 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
119 
120 Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
121 {
122  const FixedList<word, 3> temp(is);
123 
124  key.first() = temp[0];
125 
126  if (temp[1] == "and")
127  {
128  key.ordered_ = false;
129  }
130  else if(temp[1] == "in")
131  {
132  key.ordered_ = true;
133  }
134  else
135  {
137  << "Phase pair type is not recognised. "
138  << temp
139  << "Use (phaseDispersed in phaseContinuous) for an ordered"
140  << "pair, or (phase1 and pase2) for an unordered pair."
141  << exit(FatalError);
142  }
143 
144  key.second() = temp[2];
145 
146  return is;
147 }
148 
149 
150 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
151 
152 Foam::Ostream& Foam::operator<<(Ostream& os, const phasePairKey& key)
153 {
154  os << token::BEGIN_LIST
155  << key.first()
156  << token::SPACE
157  << (key.ordered_ ? "in" : "and")
158  << token::SPACE
159  << key.second()
160  << token::END_LIST;
161 
162  return os;
163 }
164 
165 
166 // ************************************************************************* //
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:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static int compare(const Pair< Type > &a, const Pair< Type > &b)
Compare Pairs.
Definition: Pair.H:141
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Istream & operator>>(Istream &, directionInfo &)
virtual ~phasePairKey()
bool ordered() const
Return the ordered flag.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Pair()
Null constructor.
Definition: Pair.H:61
Ostream & operator<<(Ostream &, const ensightPart &)
phasePairKey()
Construct null.