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-2015 OpenFOAM Foundation
9  Copyright (C) 2017-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "phasePairKey.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 (
35  const word& name1,
36  const word& name2,
37  const bool ordered
38 )
39 :
40  Pair<word>(name1, name2),
41  ordered_(ordered)
42 {}
43 
44 
45 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
46 
47 bool Foam::operator==
48 (
49  const phasePairKey& a,
50  const phasePairKey& b
51 )
52 {
53  const int cmp = Pair<word>::compare(a, b);
54  return
55  (
56  (a.ordered() == b.ordered())
57  && (a.ordered() ? (cmp == 1) : cmp)
58  );
59 }
60 
61 
62 bool Foam::operator!=
63 (
64  const phasePairKey& a,
65  const phasePairKey& b
66 )
67 {
68  return !(a == b);
69 }
70 
71 
72 // * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
73 
75 {
76  const FixedList<word, 3> toks(is);
77 
78  key.first() = toks[0];
79  key.second() = toks[2];
80  const word& order = toks[1];
81 
82  if (order == "to")
83  {
84  key.ordered_ = true;
85  }
86  else if (order == "and")
87  {
88  key.ordered_ = false;
89  }
90  else
91  {
93  << "Phase pair type is not recognised. " << toks
94  << "Use (phaseDispersed to phaseContinuous) for an ordered pair,"
95  " or (phase1 and phase2) for an unordered pair.\n"
96  << exit(FatalError);
97  }
98 
99  return is;
100 }
101 
102 
103 // * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
104 
106 {
107  os << token::BEGIN_LIST
108  << key.first()
109  << token::SPACE
110  << (key.ordered() ? "to" : "and")
111  << token::SPACE
112  << key.second()
113  << token::END_LIST;
114 
115  return os;
116 }
117 
118 
119 // ************************************************************************* //
phasePairKey.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::phasePairKey::phasePairKey
phasePairKey()=default
Default construct.
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::phasePairKey::ordered
bool ordered() const noexcept
Return the ordered flag.
Definition: phasePairKey.H:98
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::phasePairKey
An ordered or unorder pair of phase names. Typically specified as follows.
Definition: phasePairKey.H:65
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
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:453
Foam::Pair< word >
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56