zoneIdentifier.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) 2021-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 Class
27  Foam::zoneIdentifier
28 
29 Description
30  Identifies a mesh zone by name and index, with optional physical type
31  and group information.
32 
33 SeeAlso
34  patchIdentifier
35 
36 SourceFiles
37  zoneIdentifier.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_zoneIdentifier_H
42 #define Foam_zoneIdentifier_H
43 
44 #include "wordList.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward Declarations
52 class dictionary;
53 
54 /*---------------------------------------------------------------------------*\
55  Class zoneIdentifier Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class zoneIdentifier
59 {
60  // Private Data
61 
62  //- Zone name
63  word name_;
64 
65  //- Zone index in mesh
66  label index_;
67 
68  //- Zone type (optional)
69  word physicalType_;
70 
71  //- Groups to which the zone belongs (optional)
72  wordList inGroups_;
73 
74 public:
75 
76  // Generated Methods
77 
78  //- Copy construct
79  zoneIdentifier(const zoneIdentifier&) = default;
80 
81  //- Move construct
82  zoneIdentifier(zoneIdentifier&&) = default;
83 
84  //- Copy assignment
85  zoneIdentifier& operator=(const zoneIdentifier&) = default;
86 
87  //- Move assignment
89 
90  //- Destructor
91  virtual ~zoneIdentifier() = default;
92 
93 
94  // Constructors
95 
96  //- Default construct: name="", index=0
98 
99  //- Construct from mandatory components
100  zoneIdentifier(const word& name, const label index);
101 
102  //- Construct from components
104  (
105  const word& name,
106  const label index,
107  const word& physicalType,
108  const wordList& inGroups = wordList()
109  );
110 
111  //- Construct from dictionary
113  (
114  const word& name,
115  const dictionary& dict,
116  const label index
117  );
118 
119  //- Copy construct, resetting the index (if non-negative)
121  (
122  const zoneIdentifier& ident,
123  const label newIndex
124  );
125 
126  //- Move construct, resetting the index (if non-negative)
128  (
129  zoneIdentifier&& ident,
130  const label newIndex
131  );
132 
133 
134  // Member Functions
135 
136  //- The zone name
137  const word& name() const noexcept { return name_; }
138 
139  //- Modifiable zone name
140  word& name() noexcept { return name_; }
141 
142  //- The index of this zone in the zone list
143  label index() const noexcept { return index_; }
144 
145  //- Modifiable index of this zone in the zone list
146  label& index() noexcept { return index_; }
147 
148  //- The (optional) type of the zone
149  const word& physicalType() const noexcept { return physicalType_; }
150 
151  //- Modifiable (optional) type of the zone
152  word& physicalType() noexcept { return physicalType_; }
153 
154  //- The (optional) groups that the zone belongs to
155  const wordList& inGroups() const noexcept { return inGroups_; }
156 
157  //- Modifiable (optional) groups that the zone belongs to
158  wordList& inGroups() noexcept { return inGroups_; }
159 
160  //- True if given name is in a group
161  bool inGroup(const word& name) const
162  {
163  return (!name.empty() && inGroups_.contains(name));
164  }
165 
166  //- Add (unique) group for the zone
167  void addGroup(const word& name)
168  {
169  if (!name.empty() && !inGroups_.contains(name))
170  {
171  inGroups_.push_back(name);
172  }
173  }
175  //- Remove group for the zone
176  void removeGroup(const word& name);
177 
178  //- Write (physicalType, inGroups) dictionary entries
179  //- (without surrounding braces)
180  void write(Ostream& os) const;
181 };
182 
183 
184 // Global Operators
185 
186 //- Write (physicalType, inGroups) dictionary entries
187 //- (without surrounding braces)
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 } // End namespace Foam
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 #endif
198 
199 // ************************************************************************* //
dictionary dict
bool inGroup(const word &name) const
True if given name is in a group.
zoneIdentifier()
Default construct: name="", index=0.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
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
void removeGroup(const word &name)
Remove group for the zone.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual ~zoneIdentifier()=default
Destructor.
void write(Ostream &os) const
Write (physicalType, inGroups) dictionary entries (without surrounding braces)
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
label index() const noexcept
The index of this zone in the zone list.
OBJstream os(runTime.globalPath()/outputName)
const word & physicalType() const noexcept
The (optional) type of the zone.
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
Identifies a mesh zone by name and index, with optional physical type and group information.
const word & name() const noexcept
The zone name.
const wordList & inGroups() const noexcept
The (optional) groups that the zone belongs to.
zoneIdentifier & operator=(const zoneIdentifier &)=default
Copy assignment.
volScalarField & p
void addGroup(const word &name)
Add (unique) group for the zone.
Namespace for OpenFOAM.