Loading...
Searching...
No Matches
zoneIdentifier.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) 2021-2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "zoneIdentifier.H"
29#include "dictionary.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 const word& name,
42 const label index
44:
45 name_(name),
46 index_(index)
47{}
48
49
51(
52 const word& name,
53 const label index,
54 const word& physicalType,
55 const wordList& inGroups
56)
57:
58 name_(name),
59 index_(index),
60 physicalType_(physicalType),
61 inGroups_(inGroups)
62{}
63
64
66(
67 const word& name,
68 const dictionary& dict,
69 const label index
70)
71:
73{
74 dict.readIfPresent("physicalType", physicalType_);
75 dict.readIfPresent("inGroups", inGroups_);
76}
77
78
80(
81 const zoneIdentifier& ident,
82 const label newIndex
83)
84:
85 zoneIdentifier(ident)
86{
87 if (newIndex >= 0)
88 {
89 index_ = newIndex;
90 }
91}
92
93
95(
96 zoneIdentifier&& ident,
97 const label newIndex
98)
99:
100 zoneIdentifier(std::move(ident))
101{
102 if (newIndex >= 0)
103 {
104 index_ = newIndex;
105 }
106}
107
108
109// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110
112{
113 label idx = name.empty() ? -1 : inGroups_.find(name);
114
115 if (idx >= 0)
116 {
117 for (label i = idx + 1; i < inGroups_.size(); ++i)
118 {
119 if (inGroups_[i] != name)
120 {
121 inGroups_[idx] = std::move(inGroups_[i]);
122 ++idx;
124 }
125 inGroups_.resize(idx);
126 }
127}
128
129
131{
132 if (!physicalType_.empty())
133 {
134 os.writeEntry("physicalType", physicalType_);
135 }
136
137 if (!inGroups_.empty())
138 {
139 os.writeKeyword("inGroups");
140 inGroups_.writeList(os, 0); // Flat output
141 os.endEntry();
142 }
143}
144
145
146// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
147
148Foam::Ostream& Foam::operator<<(Ostream& os, const zoneIdentifier& ident)
149{
150 ident.write(os);
152 return os;
153}
154
155
156// ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition Ostream.H:331
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition Ostream.C:60
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A class for handling words, derived from Foam::string.
Definition word.H:66
Identifies a mesh zone by name and index, with optional physical type and group information.
const word & physicalType() const noexcept
The (optional) type of the zone.
zoneIdentifier()
Default construct: name="", index=0.
zoneIdentifier(const zoneIdentifier &)=default
Copy construct.
const wordList & inGroups() const noexcept
The (optional) groups that the zone belongs to.
void write(Ostream &os) const
Write (physicalType, inGroups) dictionary entries (without surrounding braces).
label index() const noexcept
The index of this zone in the zone list.
const word & name() const noexcept
The zone name.
void removeGroup(const word &name)
Remove group for the zone.
OBJstream os(runTime.globalPath()/outputName)
auto & name
#define FUNCTION_NAME
List< word > wordList
List of word.
Definition fileName.H:60
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dictionary dict