geometricSurfacePatch.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) 2017-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 "geometricSurfacePatch.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 :
60 {}
61 
62 
64 :
65  name_("patch"),
66  index_(index),
67  geometricType_(emptyType)
68 {}
69 
70 
72 (
73  const word& name,
74  const label index
75 )
76 :
77  name_(name),
78  index_(index),
79  geometricType_()
80 {}
81 
82 
84 (
85  const word& name,
86  const label index,
87  const word& geometricType
88 )
89 :
90  name_(name),
91  index_(index),
92  geometricType_(geometricType)
93 {}
94 
95 
97 (
98  const word& name,
99  const dictionary& dict,
100  const label index
101 )
102 :
103  name_(name),
104  index_(index),
105  geometricType_()
106 {
107  dict.readIfPresent("geometricType", geometricType_);
108 }
109 
110 
112 (
113  const surfZoneIdentifier& ident
114 )
115 :
116  geometricSurfacePatch(ident.name(), ident.index(), ident.geometricType())
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 {
124  if (geometricType_.size())
125  {
126  os.writeEntry("geometricType", geometricType_);
127  }
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
132 
133 bool Foam::operator==
134 (
135  const geometricSurfacePatch& a,
136  const geometricSurfacePatch& b
137 )
138 {
139  return
140  (
141  (a.geometricType() == b.geometricType())
142  && (a.name() == b.name())
143  );
144 }
145 
146 
147 bool Foam::operator!=
148 (
149  const geometricSurfacePatch& a,
150  const geometricSurfacePatch& b
151 )
152 {
153  return !(a == b);
154 }
155 
156 
157 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
158 
160 {
161  obj.name() = readOptionalWord(is);
162  obj.geometricType() = readOptionalWord(is);
163 
164  return is;
165 }
166 
167 
169 {
170  // Force unconditional line-breaks on list output.
171  // We otherwise risk extremely unreadable entries
172  os << nl;
173 
174  // Empty words are double-quoted so they are treated as 'string'
175 
176  os.writeQuoted(obj.name(), obj.name().empty()) << token::SPACE;
177  os.writeQuoted(obj.geometricType(), obj.geometricType().empty());
178 
179  // Equivalent for OpenFOAM-1912 and earlier:
180  // if (obj.geometricType().empty())
181  // {
182  // os << emptyType;
183  // }
184  // else
185  // {
186  // os << obj.geometricType();
187  // }
188 
189  os.check(FUNCTION_NAME);
190  return os;
191 }
192 
193 
194 // * * * * * * * * * * * * * * * Housekeeping * * * * * * * * * * * * * * * //
195 
197 (
198  const word& geometricType,
199  const word& name,
200  const label index
201 )
202 :
203  geometricSurfacePatch(name, index, geometricType)
204 {}
205 
206 
207 // ************************************************************************* //
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::geometricSurfacePatch
The geometricSurfacePatch is like patchIdentifier but for surfaces. Holds type, name and index.
Definition: geometricSurfacePatch.H:52
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::geometricSurfacePatch::geometricSurfacePatch
geometricSurfacePatch()
Default construct, use index=0, name="patch".
Definition: geometricSurfacePatch.C:57
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
geometricSurfacePatch.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::geometricSurfacePatch::geometricType
const word & geometricType() const
The geometric type of the patch/zone.
Definition: geometricSurfacePatch.H:156
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::geometricSurfacePatch::write
void write(Ostream &os) const
Definition: geometricSurfacePatch.C:122
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::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::geometricSurfacePatch::name
const word & name() const
The patch/zone name.
Definition: geometricSurfacePatch.H:144
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417