patchIdentifier.H
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 -------------------------------------------------------------------------------
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 Class
28  Foam::patchIdentifier
29 
30 Description
31  Identifies a patch by name and index, with optional physical type
32  and group information.
33 
34 SourceFiles
35  patchIdentifier.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_patchIdentifier_H
40 #define Foam_patchIdentifier_H
41 
42 #include "wordList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward Declarations
50 class dictionary;
51 
52 /*---------------------------------------------------------------------------*\
53  Class patchIdentifier Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class patchIdentifier
57 {
58  // Private Data
59 
60  //- Patch name
61  word name_;
62 
63  //- Patch index in boundary
64  label index_;
65 
66  //- Patch physical type (optional)
67  word physicalType_;
68 
69  //- Groups to which the patch belongs (optional)
70  wordList inGroups_;
71 
72 public:
73 
74  // Static Member Functions
75 
76  //- Default patch name: "patch" or "patchN"
77  static word defaultName(const label n = -1)
78  {
79  return
80  (
81  n < 0
82  ? word("patch", false)
83  : word("patch" + std::to_string(n), false)
84  );
85  }
86 
87 
88  // Generated Methods
89 
90  //- Copy construct
91  patchIdentifier(const patchIdentifier&) = default;
92 
93  //- Move construct
94  patchIdentifier(patchIdentifier&&) = default;
95 
96  //- Copy assignment
97  patchIdentifier& operator=(const patchIdentifier&) = default;
98 
99  //- Move assignment
101 
102  //- Destructor
103  virtual ~patchIdentifier() = default;
104 
105 
106  // Constructors
107 
108  //- Default construct: name="", index=0
109  patchIdentifier();
110 
111  //- Construct from mandatory components
112  patchIdentifier(const word& name, const label index);
113 
114  //- Construct from components
116  (
117  const word& name,
118  const label index,
119  const word& physicalType,
120  const wordList& inGroups = wordList()
121  );
122 
123  //- Construct from dictionary
125  (
126  const word& name,
127  const dictionary& dict,
128  const label index
129  );
130 
131  //- Copy construct, resetting the index (if non-negative)
133  (
134  const patchIdentifier& ident,
135  const label newIndex
136  );
137 
138  //- Move construct, resetting the index (if non-negative)
140  (
141  patchIdentifier&& ident,
142  const label newIndex
143  );
144 
145 
146  // Member Functions
147 
148  //- The patch name
149  const word& name() const noexcept { return name_; }
150 
151  //- Modifiable patch name
152  word& name() noexcept { return name_; }
153 
154  //- The index of this patch in the boundaryMesh
155  label index() const noexcept { return index_; }
156 
157  //- Modifiable index of this patch in the boundaryMesh
158  label& index() noexcept { return index_; }
159 
160  //- The (optional) physical type of the patch
161  const word& physicalType() const noexcept { return physicalType_; }
162 
163  //- Modifiable (optional) physical type of the patch
164  word& physicalType() noexcept { return physicalType_; }
165 
166  //- The (optional) groups that the patch belongs to
167  const wordList& inGroups() const noexcept { return inGroups_; }
168 
169  //- Modifiable (optional) groups that the patch belongs to
170  wordList& inGroups() noexcept { return inGroups_; }
171 
172  //- True if given name is in a group
173  bool inGroup(const word& name) const
174  {
175  return (!name.empty() && inGroups_.contains(name));
176  }
177 
178  //- Add (unique) group for the patch
179  void addGroup(const word& name)
180  {
181  if (!name.empty() && !inGroups_.contains(name))
182  {
183  inGroups_.push_back(name);
184  }
185  }
186 
187  //- Remove group for the patch
188  void removeGroup(const word& name);
189 
190  //- Write (physicalType, inGroups) dictionary entries
191  //- (without surrounding braces)
192  void write(Ostream& os) const;
193 };
194 
195 
196 // Global Operators
197 
198 //- Write (physicalType, inGroups) dictionary entries
199 //- (without surrounding braces)
200 Ostream& operator<<(Ostream& os, const patchIdentifier& ident);
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace Foam
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 #endif
210 
211 // ************************************************************************* //
void addGroup(const word &name)
Add (unique) group for the patch.
dictionary dict
static word defaultName(const label n=-1)
Default patch name: "patch" or "patchN".
void removeGroup(const word &name)
Remove group for the patch.
void write(Ostream &os) const
Write (physicalType, inGroups) dictionary entries (without surrounding braces)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Identifies a patch by name and index, with optional physical type and group information.
virtual ~patchIdentifier()=default
Destructor.
const wordList & inGroups() const noexcept
The (optional) groups that the patch belongs to.
void push_back(const T &val)
Append an element at the end of the list.
Definition: ListI.H:227
bool contains(const T &val) const
True if the value is contained in the list.
Definition: UListI.H:300
patchIdentifier()
Default construct: name="", index=0.
A class for handling words, derived from Foam::string.
Definition: word.H:63
const word & name() const noexcept
The patch name.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
bool inGroup(const word &name) const
True if given name is in a group.
const word & physicalType() const noexcept
The (optional) physical type of the patch.
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
List< word > wordList
List of word.
Definition: fileName.H:59
label n
label index() const noexcept
The index of this patch in the boundaryMesh.
patchIdentifier & operator=(const patchIdentifier &)=default
Copy assignment.
Namespace for OpenFOAM.