DynamicID.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 OpenFOAM Foundation
9 Copyright (C) 2018-2021 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
27Class
28 Foam::DynamicID
29
30Description
31 A class that holds the data needed to identify things (zones, patches)
32 in a dynamic mesh.
33
34 The thing is identified by name.
35 Its indices are updated if the mesh has changed.
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef DynamicID_H
40#define DynamicID_H
41
42#include "wordRe.H"
43#include "labelList.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class DynamicID Declaration
52\*---------------------------------------------------------------------------*/
53
54template<class ObjectType>
55class DynamicID
56{
57 // Private Data
58
59 //- Selector name
60 wordRe key_;
61
62 //- Selection indices
63 labelList indices_;
64
65
66public:
67
68 // Constructors
69
70 //- Construct from selector name and object
71 DynamicID(const wordRe& key, const ObjectType& obj)
72 :
73 key_(key),
74 indices_(obj.indices(key_))
75 {}
76
77 //- Construct from selector name and object
78 DynamicID(wordRe&& key, const ObjectType& obj)
79 :
80 key_(std::move(key)),
81 indices_(obj.indices(key_))
82 {}
83
84 //- Construct from selector name and object
85 DynamicID(const word& key, const ObjectType& obj)
86 :
87 DynamicID(wordRe(key), obj)
88 {}
89
90 //- Construct from selector name and object
91 DynamicID(const keyType& key, const ObjectType& obj)
92 :
93 DynamicID(wordRe(key), obj)
94 {}
95
96 //- Construct from Istream and object
97 DynamicID(Istream& is, const ObjectType& obj)
98 :
99 DynamicID(wordRe(is), obj)
100 {}
101
102
103 //- Destructor
104 ~DynamicID() = default;
105
106
107 // Member Functions
108
109 // Access
110
111 //- The selector name
112 const wordRe& name() const noexcept
113 {
114 return key_;
115 }
116
117 //- The indices of matching items
118 const labelList& indices() const noexcept
119 {
120 return indices_;
121 }
122
123 //- The index of the first matching items, -1 if no matches
124 label index() const
125 {
126 return indices_.empty() ? -1 : indices_.first();
127 }
128
129 //- Has the zone been found
130 bool active() const noexcept
131 {
132 return !indices_.empty();
133 }
134
135
136 // Edit
137
138 //- Update
139 void update(const ObjectType& obj)
140 {
141 indices_ = obj.indices(key_);
142 }
143};
144
145
146// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147
148template<class ObjectType>
150{
152 << obj.name() << token::SPACE << obj.index()
154
156 return os;
157}
158
159
160// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161
162} // End namespace Foam
163
164// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165
166#endif
167
168// ************************************************************************* //
A class that holds the data needed to identify things (zones, patches) in a dynamic mesh.
Definition: DynamicID.H:55
const labelList & indices() const noexcept
The indices of matching items.
Definition: DynamicID.H:117
~DynamicID()=default
Destructor.
DynamicID(const word &key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:84
label index() const
The index of the first matching items, -1 if no matches.
Definition: DynamicID.H:123
bool active() const noexcept
Has the zone been found.
Definition: DynamicID.H:129
DynamicID(wordRe &&key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:77
DynamicID(const wordRe &key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:70
DynamicID(Istream &is, const ObjectType &obj)
Construct from Istream and object.
Definition: DynamicID.H:96
DynamicID(const keyType &key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:90
void update(const ObjectType &obj)
Update.
Definition: DynamicID.H:138
const wordRe & name() const noexcept
The selector name.
Definition: DynamicID.H:111
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
T & first()
Return the first element of the list.
Definition: UListI.H:202
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
A class for handling keywords in dictionaries.
Definition: keyType.H:71
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
@ SPACE
Space [isspace].
Definition: token.H:125
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:83
A class for handling words, derived from Foam::string.
Definition: word.H:68
mesh update()
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
const direction noexcept
Definition: Scalar.H:223