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
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 // ************************************************************************* //
Foam::ZoneMesh::zoneMap
const Map< label > & zoneMap() const
Map of zones containing zone index for all zoned elements.
Definition: ZoneMesh.C:211
ZoneMesh.C
regIOobject.H
Foam::ZoneMesh::checkDefinition
bool checkDefinition(const bool report=false) const
Check zone definition. Return true if in error.
Definition: ZoneMesh.C:418
Foam::ZoneMesh::clear
void clear()
Clear the zones.
Definition: ZoneMesh.C:408
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::PackedBoolList
A bit-packed bool list.
Definition: PackedBoolList.H:63
Foam::ZoneMesh::findIndex
label findIndex(const keyType &) const
Return zone index for the first match, return -1 if not found.
Definition: ZoneMesh.C:313
List.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::ZoneMesh::mesh
const MeshType & mesh() const
Return the mesh reference.
Definition: ZoneMesh.H:127
Foam::ZoneMesh::operator=
void operator=(const ZoneMesh< ZoneType, MeshType > &)
Disallow assignment.
Foam::Map< label >
Foam::ZoneMesh::read
bool read()
Read if IOobject flags set. Return true if read.
Definition: ZoneMesh.C:74
Foam::ZoneMesh::ZoneMesh
ZoneMesh(const ZoneMesh &)
Disallow construct as copy.
Map.H
Foam::ZoneMesh::~ZoneMesh
~ZoneMesh()
Destructor.
Definition: ZoneMesh.C:200
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:56
Foam::ZoneMesh::operator[]
const ZoneType & operator[](const word &) const
Return const reference to ZoneType by name.
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::ZoneMesh::movePoints
void movePoints(const pointField &)
Correct zone mesh after moving points.
Definition: ZoneMesh.C:514
PackedBoolList.H
Foam::ZoneMesh
A list of mesh zones.
Definition: cellZoneMeshFwd.H:39
Foam::PtrList
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
Foam::ZoneMesh::mesh_
const MeshType & mesh_
Reference to mesh.
Definition: ZoneMesh.H:70
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::ZoneMesh::whichZone
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
Definition: ZoneMesh.C:226
Foam::ZoneMesh::findMatching
PackedBoolList findMatching(const keyType &) const
Mark cells that match the zone specification.
Definition: ZoneMesh.C:377
Foam::ZoneMesh::calcZoneMap
void calcZoneMap() const
Create zone map.
Definition: ZoneMesh.C:35
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:348
Foam::ZoneMesh::names
wordList names() const
Return a list of zone names.
Definition: ZoneMesh.C:263
pointField.H
Foam::ZoneMesh::findIndices
labelList findIndices(const keyType &) const
Return zone indices for all matches.
Definition: ZoneMesh.C:280
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::ZoneMesh::writeData
bool writeData(Ostream &) const
writeData member function required by regIOobject
Definition: ZoneMesh.C:527
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::ZoneMesh::clearAddressing
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:394
Foam::ZoneMesh::checkParallelSync
bool checkParallelSync(const bool report=false) const
Check whether all procs have all zones and in same order. Return.
Definition: ZoneMesh.C:436
Foam::ZoneMesh::zoneMapPtr_
Map< label > * zoneMapPtr_
Map of zone labels for given element.
Definition: ZoneMesh.H:73
Foam::ZoneMesh::types
wordList types() const
Return a list of zone types.
Definition: ZoneMesh.C:246