surfZoneIdentifier.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) 2011 OpenFOAM Foundation
9  Copyright (C) 2016-2020 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 "surfZoneIdentifier.H"
30 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 static inline word readOptionalWord(Istream& is)
38 {
39  token tok(is);
40 
41  if (tok.isWord())
42  {
43  return tok.wordToken();
44  }
45  else
46  {
47  // Allow empty words
48  return word::validate(tok.stringToken());
49  }
50 }
51 
52 } // End namespace Foam
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 :
59  name_(),
60  index_(0),
61  geometricType_()
62 {}
63 
64 
66 :
67  name_(),
68  index_(index),
69  geometricType_()
70 {}
71 
72 
74 (
75  const word& name,
76  const label index
77 )
78 :
79  name_(name),
80  index_(index),
81  geometricType_()
82 {}
83 
84 
86 (
87  const word& name,
88  const label index,
89  const word& geometricType
90 )
91 :
92  name_(name),
93  index_(index),
94  geometricType_(geometricType)
95 {}
96 
97 
99 (
100  const word& name,
101  const dictionary& dict,
102  const label index
103 )
104 :
105  name_(name),
106  index_(index),
107  geometricType_()
108 {
109  dict.readIfPresent("geometricType", geometricType_);
110 }
111 
112 
114 (
115  const surfZoneIdentifier& p,
116  const label index
117 )
118 :
119  name_(p.name()),
120  index_(index),
121  geometricType_(p.geometricType())
122 {}
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
128 {
129  if (geometricType_.size())
130  {
131  os.writeEntry("geometricType", geometricType_);
132  }
133 }
134 
135 
136 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
137 
138 bool Foam::operator==
139 (
140  const surfZoneIdentifier& a,
141  const surfZoneIdentifier& b
142 )
143 {
144  return
145  (
146  (a.index() == b.index())
147  && (a.name() == b.name())
148  && (a.geometricType() == b.geometricType())
149  );
150 }
151 
152 
153 bool Foam::operator!=
154 (
155  const surfZoneIdentifier& a,
156  const surfZoneIdentifier& b
157 )
158 {
159  return !(a == b);
160 }
161 
162 
163 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
164 
166 {
167  obj.name() = readOptionalWord(is);
168  obj.geometricType() = readOptionalWord(is);
169 
170  return is;
171 }
172 
173 
175 {
176  // Force unconditional line-breaks on list output.
177  // We otherwise risk extremely unreadable entries
178  os << nl;
179 
180  // Empty words are double-quoted so they are treated as 'string'
181 
182  os.writeQuoted(obj.name(), obj.name().empty()) << token::SPACE;
183  os.writeQuoted(obj.geometricType(), obj.geometricType().empty());
184 
185  os.check(FUNCTION_NAME);
186  return os;
187 }
188 
189 
190 // ************************************************************************* //
Foam::surfZoneIdentifier::write
void write(Ostream &os) const
Definition: surfZoneIdentifier.C:127
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::token::stringToken
const string & stringToken() const
Return const reference to the string contents.
Definition: tokenI.H:644
Foam::Ostream::writeQuoted
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)=0
Write std::string surrounded by quotes.
Foam::readOptionalWord
static word readOptionalWord(Istream &is)
Definition: geometricSurfacePatch.C:37
Foam::dimensioned::name
const word & name() const
Return const reference to name.
Definition: dimensionedType.C:406
Foam::word::validate
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
Definition: word.C:45
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::surfZoneIdentifier::index
label index() const
The index of this patch/zone in the surface mesh.
Definition: surfZoneIdentifier.H:165
surfZoneIdentifier.H
Foam::surfZoneIdentifier
Identifies a surface patch/zone by name, patch index and geometricType.
Definition: surfZoneIdentifier.H:59
Foam::token::isWord
bool isWord() const noexcept
Token is WORD or DIRECTIVE word.
Definition: tokenI.H:583
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
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::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.H:599
Foam::surfZoneIdentifier::surfZoneIdentifier
surfZoneIdentifier()
Default construct, with index zero.
Definition: surfZoneIdentifier.C:57
Foam::surfZoneIdentifier::geometricType
const word & geometricType() const
The geometric type of the patch/zone.
Definition: surfZoneIdentifier.H:153
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::token::SPACE
Space [isspace].
Definition: token.H:117
dictionary.H
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::surfZoneIdentifier::name
const word & name() const
The patch/zone name.
Definition: surfZoneIdentifier.H:141
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417