zone.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-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2023 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::zone
29 
30 Description
31  Base class for mesh zones.
32 
33  A zone is a list of labels (eg, cells, faces, points) with
34  a name and associated with an index within another list.
35 
36 SourceFiles
37  zone.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_zone_H
42 #define Foam_zone_H
43 
44 #include "zoneIdentifier.H"
45 #include "labelList.H"
46 #include "typeInfo.H"
47 #include "Map.H"
48 #include "pointFieldFwd.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward Declarations
56 class zone;
57 class dictionary;
58 Ostream& operator<<(Ostream& os, const zone& zn);
59 
60 /*---------------------------------------------------------------------------*\
61  Class zone Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class zone
65 :
66  public zoneIdentifier,
67  public labelList
68 {
69  // Private Data
70 
71  //- Demand-driven: map of labels in zone for fast location lookup
72  mutable std::unique_ptr<Map<label>> lookupMapPtr_;
73 
74 
75 public:
76 
77  //- Runtime type information
78  TypeNameNoDebug("zone");
79 
80 
81  // Constructors
82 
83  //- Default construct
84  zone();
85 
86  //- Construct an empty zone with specified name and index
87  zone(const word& name, const label index);
88 
89  //- Copy construct from components
90  zone
91  (
92  const word& name,
93  const labelUList& addr,
94  const label index
95  );
96 
97  //- Move construct from components
98  zone
99  (
100  const word& name,
101  labelList&& addr,
102  const label index
103  );
104 
105  //- Construct from dictionary
106  zone
107  (
108  const word& name,
109  const dictionary& dict,
110  const word& labelsName,
111  const label index
112  );
113 
114  //- Construct given the name of the original zone (name is used)
115  //- with new addressing and index (-ve: retain zone index).
116  zone
117  (
118  const zone& originalZone,
119  const labelUList& addr,
120  const label index
121  );
122 
123  //- Construct given the name of the original zone (name is used)
124  //- and (move) resetting addressing and index (-ve: retain zone index).
125  zone
126  (
127  const zone& originalZone,
128  labelList&& addr,
129  const label index
130  );
131 
132 
133  //- Destructor
134  virtual ~zone() = default;
135 
136 
137  // Member Functions
138 
139  //- Demand-driven: the look-up map from global to local id
140  const Map<label>& lookupMap() const;
141 
142  //- Lookup local address in zone for given global index.
143  // \return the local address, or -1 if the item is not in the zone
144  label localID(const label globalID) const;
145 
146  //- The addressing used by the zone
147  const labelList& addressing() const noexcept
148  {
149  return static_cast<const labelList&>(*this);
150  }
151 
152  //- Clear addressing
153  //- (remove lookup maps and other auxiliary information)
154  virtual void clearAddressing();
155 
156  //- Clear primitive addressing
157  virtual void clearPrimitives();
158 
159  //- Check zone definition. Return true if in error.
160  virtual bool checkDefinition(const bool report = false) const = 0;
161 
162  //- Check zone definition with max size given. Return true if in error.
163  virtual bool checkDefinition
164  (
165  const label maxSize,
166  const bool report = false
167  ) const;
168 
169  //- Correct patch after moving points
170  virtual void movePoints(const pointField& pts)
171  {}
172 
173  //- Write
174  virtual void write(Ostream& os) const;
175 
176  //- Write dictionary
177  virtual void writeDict(Ostream& os) const = 0;
178 
179 
180  // I-O
181 
182  //- Ostream Operator
183  friend Ostream& operator<<(Ostream& os, const zone& zn);
184 };
185 
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 } // End namespace Foam
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 #endif
194 
195 // ************************************************************************* //
zone()
Default construct.
Definition: zone.C:37
virtual void clearAddressing()
Clear addressing (remove lookup maps and other auxiliary information)
Definition: zone.C:146
dictionary dict
label localID(const label globalID) const
Lookup local address in zone for given global index.
Definition: zone.C:140
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual void writeDict(Ostream &os) const =0
Write dictionary.
virtual void clearPrimitives()
Clear primitive addressing.
Definition: zone.C:152
TypeNameNoDebug("zone")
Runtime type information.
virtual ~zone()=default
Destructor.
Base class for mesh zones.
Definition: zone.H:59
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool checkDefinition(const bool report=false) const =0
Check zone definition. Return true if in error.
virtual void movePoints(const pointField &pts)
Correct patch after moving points.
Definition: zone.H:202
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
label index() const noexcept
The index of this zone in the zone list.
friend Ostream & operator<<(Ostream &os, const zone &zn)
Ostream Operator.
OBJstream os(runTime.globalPath()/outputName)
virtual void write(Ostream &os) const
Write.
Definition: zone.C:202
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
Identifies a mesh zone by name and index, with optional physical type and group information.
const Map< label > & lookupMap() const
Demand-driven: the look-up map from global to local id.
Definition: zone.C:121
const word & name() const noexcept
The zone name.
const labelList & addressing() const noexcept
The addressing used by the zone.
Definition: zone.H:169
Namespace for OpenFOAM.
const pointField & pts