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 -------------------------------------------------------------------------------
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::DynamicID
29 
30 Description
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 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class DynamicID Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 template<class ObjectType>
55 class DynamicID
56 {
57  // Private Data
58 
59  //- Selector name
60  wordRe key_;
61 
62  //- Selection indices
63  labelList indices_;
64 
65 
66 public:
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 
148 template<class ObjectType>
150 {
152  << obj.name() << token::SPACE << obj.index()
153  << token::END_LIST;
154 
156  return os;
157 }
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace Foam
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #endif
167 
168 // ************************************************************************* //
Foam::DynamicID::DynamicID
DynamicID(const word &key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:84
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::DynamicID::DynamicID
DynamicID(const keyType &key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:90
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::DynamicID
A class that holds the data needed to identify things (zones, patches) in a dynamic mesh.
Definition: DynamicID.H:54
Foam::DynamicID::update
void update(const ObjectType &obj)
Update.
Definition: DynamicID.H:138
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:68
labelList.H
Foam::DynamicID::name
const wordRe & name() const noexcept
The selector name.
Definition: DynamicID.H:111
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
wordRe.H
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::DynamicID::DynamicID
DynamicID(wordRe &&key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:77
Foam::DynamicID::~DynamicID
~DynamicID()=default
Destructor.
Foam::List< label >
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::DynamicID::active
bool active() const noexcept
Has the zone been found.
Definition: DynamicID.H:129
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::DynamicID::indices
const labelList & indices() const noexcept
The indices of matching items.
Definition: DynamicID.H:117
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
Foam::DynamicID::DynamicID
DynamicID(Istream &is, const ObjectType &obj)
Construct from Istream and object.
Definition: DynamicID.H:96
Foam::DynamicID::index
label index() const
The index of the first matching items, -1 if no matches.
Definition: DynamicID.H:123
Foam::DynamicID::DynamicID
DynamicID(const wordRe &key, const ObjectType &obj)
Construct from selector name and object.
Definition: DynamicID.H:70