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-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 "geometricSurfacePatch.H"
30 #include "dictionary.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
35 :
37 {}
38 
39 
41 :
42  name_("patch"),
43  index_(index),
44  geometricType_()
45 {}
46 
47 
49 (
50  const word& name,
51  const label index
52 )
53 :
54  name_(name),
55  index_(index),
56  geometricType_()
57 {}
58 
59 
61 (
62  const word& name,
63  const label index,
64  const word& geometricType
65 )
66 :
67  name_(name),
68  index_(index),
69  geometricType_(geometricType)
70 {}
71 
72 
74 (
75  const word& name,
76  const dictionary& dict,
77  const label index
78 )
79 :
81 {
82  dict.readIfPresent("geometricType", geometricType_);
83 }
84 
85 
87 (
88  const surfZoneIdentifier& ident
89 )
90 :
91  geometricSurfacePatch(ident.name(), ident.index(), ident.geometricType())
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
96 
98 {
99  if (!geometricType_.empty())
100  {
101  os.writeEntry("geometricType", geometricType_);
102  }
103 }
104 
105 
106 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
107 
108 bool Foam::operator==
109 (
110  const geometricSurfacePatch& a,
111  const geometricSurfacePatch& b
112 )
113 {
114  return
115  (
116  (a.name() == b.name())
117  && (a.geometricType() == b.geometricType())
118  );
119 }
120 
121 
122 bool Foam::operator!=
123 (
124  const geometricSurfacePatch& a,
125  const geometricSurfacePatch& b
126 )
127 {
128  return !(a == b);
129 }
130 
131 
132 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
133 
134 Foam::Istream& Foam::operator>>(Istream& is, geometricSurfacePatch& obj)
135 {
136  // Also read "" for empty words
137  obj.name() = word::validate(token(is).stringToken());
138  obj.geometricType() = word::validate(token(is).stringToken());
139 
140  return is;
141 }
142 
143 
144 Foam::Ostream& Foam::operator<<(Ostream& os, const geometricSurfacePatch& obj)
145 {
146  // Force unconditional line-breaks on list output.
147  // We otherwise risk extremely unreadable entries
148  os << nl;
149 
150  // Empty words are double-quoted so they are treated as 'string'
151  // and not simply lost
152 
153  os.writeQuoted(obj.name(), obj.name().empty()) << token::SPACE;
154  os.writeQuoted(obj.geometricType(), obj.geometricType().empty());
155 
156  // Equivalent for OpenFOAM-1912 and earlier:
157  // if (obj.geometricType().empty())
158  // {
159  // os << emptyType;
160  // }
161  // else
162  // {
163  // os << obj.geometricType();
164  // }
165 
167  return os;
168 }
169 
170 
171 // ************************************************************************* //
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
Definition: word.C:39
dictionary dict
virtual const fileName & name() const
The name of the stream.
Definition: IOstream.C:33
Identifies a surface patch/zone by name and index, with optional geometric type.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A token holds an item read from Istream.
Definition: token.H:65
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:321
geometricSurfacePatch()
Default construct. Uses name="patch", index=0, type="".
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
A class for handling words, derived from Foam::string.
Definition: word.H:63
Istream & operator>>(Istream &, directionInfo &)
virtual Ostream & writeQuoted(const char *str, std::streamsize len, const bool quoted=true) override
Write character/string content, with/without surrounding quotes.
Definition: OBJstream.C:78
Space [isspace].
Definition: token.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
const word & name() const noexcept
Return const reference to name.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
Identifies a surface patch/zone by name and index, with geometric type.
void write(Ostream &os) const
Write (geometricType) dictionary entry (without surrounding braces)