Loading...
Searching...
No Matches
patchIdentifier.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-2013 OpenFOAM Foundation
9 Copyright (C) 2020-2023 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 "patchIdentifier.H"
30#include "dictionary.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 const word& name,
43 const label index
45:
46 name_(name),
47 index_(index)
48{}
49
50
52(
53 const word& name,
54 const label index,
55 const word& physicalType,
56 const wordList& inGroups
57)
58:
59 name_(name),
60 index_(index),
61 physicalType_(physicalType),
62 inGroups_(inGroups)
63{}
64
65
67(
68 const word& name,
69 const dictionary& dict,
70 const label index
71)
72:
74{
75 dict.readIfPresent("physicalType", physicalType_);
76 dict.readIfPresent("inGroups", inGroups_);
77}
78
79
81(
82 const patchIdentifier& ident,
83 const label newIndex
84)
85:
86 patchIdentifier(ident)
87{
88 if (newIndex >= 0)
89 {
90 index_ = newIndex;
91 }
92}
93
94
96(
97 patchIdentifier&& ident,
98 const label newIndex
99)
100:
101 patchIdentifier(std::move(ident))
102{
103 if (newIndex >= 0)
104 {
105 index_ = newIndex;
106 }
107}
108
109
110// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111
113{
114 label idx = name.empty() ? -1 : inGroups_.find(name);
115
116 if (idx >= 0)
117 {
118 for (label i = idx + 1; i < inGroups_.size(); ++i)
119 {
120 if (inGroups_[i] != name)
121 {
122 inGroups_[idx] = std::move(inGroups_[i]);
123 ++idx;
125 }
126 inGroups_.resize(idx);
127 }
128}
129
130
132{
133 if (!physicalType_.empty())
134 {
135 os.writeEntry("physicalType", physicalType_);
136 }
137
138 if (!inGroups_.empty())
139 {
140 os.writeKeyword("inGroups");
141 inGroups_.writeList(os, 0); // Flat output
142 os.endEntry();
143 }
144}
145
146
147// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
148
149Foam::Ostream& Foam::operator<<(Ostream& os, const patchIdentifier& ident)
150{
151 ident.write(os);
153 return os;
154}
155
156
157// ************************************************************************* //
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
Identifies a patch by name and index, with optional physical type and group information.
const word & physicalType() const noexcept
The (optional) physical type of the patch.
patchIdentifier()
Default construct: name="", index=0.
const wordList & inGroups() const noexcept
The (optional) groups that the patch belongs to.
void write(Ostream &os) const
Write (physicalType, inGroups) dictionary entries (without surrounding braces).
label index() const noexcept
The index of this patch in the boundaryMesh.
const word & name() const noexcept
The patch name.
void removeGroup(const word &name)
Remove group for the patch.
patchIdentifier(const patchIdentifier &)=default
Copy construct.
A class for handling words, derived from Foam::string.
Definition word.H:66
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