ZoneMesh.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 | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::ZoneMesh
26 
27 Description
28  A list of mesh zones.
29 
30 SourceFiles
31  ZoneMesh.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef ZoneMesh_H
36 #define ZoneMesh_H
37 
38 #include "List.H"
39 #include "regIOobject.H"
40 #include "pointField.H"
41 #include "Map.H"
42 #include "PackedBoolList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 // Forward declaration of friend functions and operators
52 
53 template<class ZoneType, class MeshType> class ZoneMesh;
54 
55 template<class ZoneType, class MeshType>
56 Ostream& operator<<(Ostream&, const ZoneMesh<ZoneType, MeshType>&);
57 
58 /*---------------------------------------------------------------------------*\
59  Class ZoneMesh Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 template<class ZoneType, class MeshType>
63 class ZoneMesh
64 :
65  public PtrList<ZoneType>,
66  public regIOobject
67 {
68  // Private data
69 
70  //- Reference to mesh
71  const MeshType& mesh_;
72 
73  //- Map of zone labels for given element
74  mutable Map<label>* zoneMapPtr_;
75 
76 
77  // Private Member Functions
78 
79  //- Read if IOobject flags set. Return true if read.
80  bool read();
81 
82  //- Disallow construct as copy
83  ZoneMesh(const ZoneMesh&);
84 
85  //- Disallow assignment
86  void operator=(const ZoneMesh<ZoneType, MeshType>&);
87 
88 
89  //- Create zone map
90  void calcZoneMap() const;
91 
92 
93 public:
94 
95  // Constructors
96 
97  //- Read constructor given IOobject and a MeshType reference
98  ZoneMesh
99  (
100  const IOobject&,
101  const MeshType&
102  );
103 
104  //- Construct given size
105  ZoneMesh
106  (
107  const IOobject&,
108  const MeshType&,
109  const label size
110  );
111 
112  //- Construct given a PtrList
113  ZoneMesh
114  (
115  const IOobject&,
116  const MeshType&,
117  const PtrList<ZoneType>&
118  );
119 
120 
121  //- Destructor
122  ~ZoneMesh();
123 
124 
125  // Member Functions
126 
127  //- Return the mesh reference
128  const MeshType& mesh() const
129  {
130  return mesh_;
131  }
132 
133  //- Map of zones containing zone index for all zoned elements
134  // Return -1 if the object is not in the zone
135  const Map<label>& zoneMap() const;
136 
137  //- Given a global object index, return the zone it is in.
138  // If object does not belong to any zones, return -1
139  label whichZone(const label objectIndex) const;
140 
141  //- Return a list of zone types
142  wordList types() const;
143 
144  //- Return a list of zone names
145  wordList names() const;
146 
147  //- Return zone indices for all matches
148  labelList findIndices(const keyType&) const;
149 
150  //- Return zone index for the first match, return -1 if not found
151  label findIndex(const keyType&) const;
152 
153  //- Find zone index given a name
154  label findZoneID(const word& zoneName) const;
155 
156  //- Mark cells that match the zone specification
157  PackedBoolList findMatching(const keyType&) const;
158 
159  //- Clear addressing
160  void clearAddressing();
161 
162  //- Clear the zones
163  void clear();
164 
165  //- Check zone definition. Return true if in error.
166  bool checkDefinition(const bool report = false) const;
167 
168  //- Check whether all procs have all zones and in same order. Return
169  // true if in error.
170  bool checkParallelSync(const bool report = false) const;
171 
172  //- Correct zone mesh after moving points
173  void movePoints(const pointField&);
174 
175  //- writeData member function required by regIOobject
176  bool writeData(Ostream&) const;
177 
178  // Member Operators
179 
180  //- Return const and non-const reference to ZoneType by index.
182 
183  //- Return const reference to ZoneType by name.
184  const ZoneType& operator[](const word&) const;
185 
186  //- Return reference to ZoneType by name.
187  ZoneType& operator[](const word&);
188 
189 
190  // Ostream operator
191 
192  friend Ostream& operator<< <ZoneType, MeshType>
193  (
194  Ostream&,
196  );
197 };
198 
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 } // End namespace Foam
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #ifdef NoRepository
207 # include "ZoneMesh.C"
208 #endif
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************************************************************* //
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order. Return.
Definition: ZoneMesh.C:442
label size() const
Return the number of elements in the PtrList.
~ZoneMesh()
Destructor.
Definition: ZoneMesh.C:206
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
Definition: ZoneMesh.C:232
wordList types() const
Return a list of zone types.
Definition: ZoneMesh.C:252
A bit-packed bool list.
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
Definition: ZoneMesh.C:217
Namespace for OpenFOAM.
A class for handling keywords in dictionaries.
Definition: keyType.H:56
PackedBoolList findMatching(const keyType &) const
Mark cells that match the zone specification.
Definition: ZoneMesh.C:383
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:400
labelList findIndices(const keyType &) const
Return zone indices for all matches.
Definition: ZoneMesh.C:286
const MeshType & mesh() const
Return the mesh reference.
Definition: ZoneMesh.H:127
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: ZoneMesh.C:424
const ZoneType & operator[](const word &) const
Return const reference to ZoneType by name.
Definition: ZoneMesh.C:543
A list of mesh zones.
IOobject(const word &name, const fileName &instance, const objectRegistry &registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true)
Construct from name, instance, registry, io options.
Definition: IOobject.C:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:354
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:269
label findIndex(const keyType &) const
Return zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:319
void movePoints(const pointField &)
Correct zone mesh after moving points.
Definition: ZoneMesh.C:520
void clear()
Clear the zones.
Definition: ZoneMesh.C:414
bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: ZoneMesh.C:533