Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37{}
38
48 const word& name,
49 const label index
51:
52 name_(name),
53 index_(index)
54{}
55
56
58(
59 const word& name,
60 const label index,
61 const word& geometricType
62)
64 name_(name),
65 index_(index),
66 geometricType_(geometricType)
67{}
68
69
71(
72 const word& name,
73 const dictionary& dict,
74 const label index
75)
78{
79 dict.readIfPresent("geometricType", geometricType_);
80}
81
82
84(
85 const surfZoneIdentifier& ident,
86 const label newIndex
87)
88:
90{
91 if (newIndex >= 0)
92 {
93 index_ = newIndex;
94 }
95}
96
97
99(
100 surfZoneIdentifier&& ident,
101 const label newIndex
102)
103:
104 surfZoneIdentifier(std::move(ident))
105{
106 if (newIndex >= 0)
107 {
108 index_ = newIndex;
109 }
110}
111
112
113// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114
115void Foam::surfZoneIdentifier::write(Ostream& os) const
116{
117 if (!geometricType_.empty())
118 {
119 os.writeEntry("geometricType", geometricType_);
120 }
121}
122
123
124// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
125
126bool Foam::operator==
127(
128 const surfZoneIdentifier& a,
129 const surfZoneIdentifier& b
130)
131{
132 return
133 (
134 (a.index() == b.index())
135 && (a.name() == b.name())
136 && (a.geometricType() == b.geometricType())
137 );
138}
139
140
141bool Foam::operator!=
142(
143 const surfZoneIdentifier& a,
144 const surfZoneIdentifier& b
145)
147 return !(a == b);
148}
149
150
151// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
152
153Foam::Istream& Foam::operator>>(Istream& is, surfZoneIdentifier& obj)
154{
155 // Also read "" for empty words
156 obj.name() = word::validate(token(is).stringToken());
157 obj.geometricType() = word::validate(token(is).stringToken());
158
159 return is;
160}
161
162
163Foam::Ostream& Foam::operator<<(Ostream& os, const surfZoneIdentifier& obj)
164{
165 // Force unconditional line-breaks on list output.
166 // We otherwise risk extremely unreadable entries
167 os << nl;
168
169 // Empty words are double-quoted so they are treated as 'string'
170 // and not simply lost
171
172 os.writeQuoted(obj.name(), obj.name().empty()) << token::SPACE;
173 os.writeQuoted(obj.geometricType(), obj.geometricType().empty());
174
175 os.check(FUNCTION_NAME);
176 return os;
177}
178
179
180// ************************************************************************* //
virtual const fileName & name() const
The name of the stream.
Definition IOstream.C:33
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Identifies a surface patch/zone by name and index, with optional geometric type.
surfZoneIdentifier()
Default construct. Uses name="", index=0.
const word & geometricType() const noexcept
The (optional) geometric type of the patch/zone.
void write(Ostream &os) const
Write (geometricType) dictionary entry (without surrounding braces).
label index() const noexcept
The index of this patch/zone in the surface mesh.
const word & name() const noexcept
The patch/zone name.
surfZoneIdentifier(const surfZoneIdentifier &)=default
Copy construct.
A token holds an item read from Istream.
Definition token.H:70
@ SPACE
Space [isspace].
Definition token.H:144
A class for handling words, derived from Foam::string.
Definition word.H:66
static word validate(const std::string &s, const bool prefix=false)
Construct validated word (no invalid characters).
Definition word.C:39
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
volScalarField & b