phasePairKey.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2014-2018 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 Operators * * * * * * * * * * * * * * //
57 
58 Foam::label Foam::phasePairKey::hash::operator()
59 (
60  const phasePairKey& key
61 ) const
62 {
63  if (key.ordered_)
64  {
65  return
66  word::hash()
67  (
68  key.first(),
69  word::hash()(key.second())
70  );
71  }
72  else
73  {
74  return
75  word::hash()(key.first())
76  + word::hash()(key.second());
77  }
78 }
79 
80 
81 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
82 
83 bool Foam::operator==
84 (
85  const phasePairKey& a,
86  const phasePairKey& b
87 )
88 {
89  const label c = Pair<word>::compare(a,b);
90 
91  return
92  (a.ordered_ == b.ordered_)
93  && (
94  (a.ordered_ && (c == 1))
95  || (!a.ordered_ && (c != 0))
96  );
97 }
98 
99 
100 bool Foam::operator!=
101 (
102  const phasePairKey& a,
103  const phasePairKey& b
104 )
105 {
106  return !(a == b);
107 }
108 
109 
110 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
111 
112 Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
113 {
114  const FixedList<word, 3> temp(is);
115 
116  key.first() = temp[0];
117 
118  if (temp[1] == "and")
119  {
120  key.ordered_ = false;
121  }
122  else if(temp[1] == "in")
123  {
124  key.ordered_ = true;
125  }
126  else
127  {
129  << "Phase pair type is not recognised. "
130  << temp
131  << "Use (phaseDispersed in phaseContinuous) for an ordered"
132  << "pair, or (phase1 and pase2) for an unordered pair."
133  << exit(FatalError);
134  }
135 
136  key.second() = temp[2];
137 
138  return is;
139 }
140 
141 
142 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
143 
144 Foam::Ostream& Foam::operator<<(Ostream& os, const phasePairKey& key)
145 {
146  os << token::BEGIN_LIST
147  << key.first()
148  << token::SPACE
149  << (key.ordered_ ? "in" : "and")
150  << token::SPACE
151  << key.second()
152  << token::END_LIST;
153 
154  return os;
155 }
156 
157 
158 // ************************************************************************* //
bool ordered() const
Return the ordered flag.
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:142
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Istream & operator>>(Istream &, directionInfo &)
virtual ~phasePairKey()
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.