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 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 "keyType.H"
43 #include "labelList.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward declarations
51 template<class> class DynamicID;
52 template<class ObjectType>
54 
55 /*---------------------------------------------------------------------------*\
56  Class DynamicID Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class ObjectType>
60 class DynamicID
61 {
62  // Private data
63 
64  //- Zone name
65  keyType key_;
66 
67  //- Zone indices
68  labelList indices_;
69 
70 
71 public:
72 
73  // Constructors
74 
75  //- Construct from name
76  DynamicID(const keyType& key, const ObjectType& obj)
77  :
78  key_(key),
79  indices_(obj.indices(key_))
80  {}
81 
82  //- Construct from Istream
83  DynamicID(Istream& is, const ObjectType& obj)
84  :
85  key_(is),
86  indices_(obj.indices(key_))
87  {}
88 
89 
90  //- Destructor
91  ~DynamicID() = default;
92 
93 
94  // Member Functions
95 
96  // Access
97 
98  //- Return name
99  const keyType& name() const
100  {
101  return key_;
102  }
103 
104  //- Return indices of matching zones
105  const labelList& indices() const
106  {
107  return indices_;
108  }
109 
110  //- Return index of first matching zone
111  label index() const
112  {
113  return indices_.empty() ? -1 : indices_.first();
114  }
115 
116  //- Has the zone been found
117  bool active() const
118  {
119  return !indices_.empty();
120  }
121 
122 
123  // Edit
124 
125  //- Update
126  void update(const ObjectType& obj)
127  {
128  indices_ = obj.indices(key_);
129  }
130 
131 
132  // IOstream Operators
133 
134  friend Ostream& operator<< <ObjectType>
135  (Ostream&, const DynamicID<ObjectType>&);
136 };
137 
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 template<class ObjectType>
143 {
144  os << token::BEGIN_LIST
145  << dynId.name() << token::SPACE << dynId.index()
146  << token::END_LIST;
147 
148  os.check(FUNCTION_NAME);
149  return os;
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace Foam
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #endif
160 
161 // ************************************************************************* //
Foam::DynamicID::DynamicID
DynamicID(const keyType &key, const ObjectType &obj)
Construct from name.
Definition: DynamicID.H:75
Foam::DynamicID::indices
const labelList & indices() const
Return indices of matching zones.
Definition: DynamicID.H:104
Foam::DynamicID
A class that holds the data needed to identify things (zones, patches) in a dynamic mesh.
Definition: DynamicID.H:50
Foam::DynamicID::update
void update(const ObjectType &obj)
Update.
Definition: DynamicID.H:125
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:60
labelList.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::DynamicID::~DynamicID
~DynamicID()=default
Destructor.
Foam::List< label >
Foam::token::SPACE
Space [isspace].
Definition: token.H:117
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:123
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::DynamicID::name
const keyType & name() const
Return name.
Definition: DynamicID.H:98
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:122
Foam::DynamicID::DynamicID
DynamicID(Istream &is, const ObjectType &obj)
Construct from Istream.
Definition: DynamicID.H:82
keyType.H
Foam::DynamicID::active
bool active() const
Has the zone been found.
Definition: DynamicID.H:116
Foam::DynamicID::index
label index() const
Return index of first matching zone.
Definition: DynamicID.H:110