volRegion.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) 2016 OpenFOAM Foundation
9  Copyright (C) 2016-2022 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::functionObjects::volRegion
29 
30 Group
31  grpFieldFunctionObjects
32 
33 Description
34  Volume (cell) region selection class.
35 
36  The adjustments for mesh changes have been implemented with a lazy
37  evaluation, to avoid unnecessary recalculation until the values are
38  actually required. The update() method is used to ensure the cache
39  values are up-to-date.
40 
41  Examples of function object specification:
42  \verbatim
43  volRegion0
44  {
45  .
46  .
47  regionType cellZone;
48  name c0;
49  .
50  .
51  }
52 
53  volRegionAll
54  {
55  .
56  .
57  regionType all;
58  .
59  .
60  }
61  \endverbatim
62 
63 Usage
64  \table
65  Property | Description | Required | Default
66  regionType | Selection type: all/cellSet/cellZone | no | all
67  name | Name of cellSet/cellZone if required | conditional |
68  \endtable
69 
70 See also
71  Foam::functionObject
72 
73 SourceFiles
74  volRegion.C
75 
76 \*---------------------------------------------------------------------------*/
77 
78 #ifndef Foam_functionObjects_volRegion_H
79 #define Foam_functionObjects_volRegion_H
80 
81 #include "writeFile.H"
82 #include "Enum.H"
83 
84 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
85 
86 namespace Foam
87 {
88 
89 // Forward Declarations
90 class fvMesh;
91 class polyMesh;
92 class mapPolyMesh;
93 
94 namespace functionObjects
95 {
96 
97 /*---------------------------------------------------------------------------*\
98  Class volRegion Declaration
99 \*---------------------------------------------------------------------------*/
100 
101 class volRegion
102 {
103 public:
104 
105  // Public Data Types
106 
107  //- Region type enumeration
108  enum regionTypes : char
109  {
110  vrtAll = 0,
112  vrtCellZone
113  };
114 
115  //- Region type names
116  static const Enum<regionTypes> regionTypeNames_;
117 
118 
119 private:
121  // Private Member Data
123  //- Reference to the volume mesh
124  const fvMesh& volMesh_;
125 
126  //- The cell ids, from cellSet or multiple cell zones
127  labelList cellIds_;
128 
129  //- Region IDs (zone ID, ...)
130  labelList regionIDs_;
131 
132  //- Cached total number of cells selected
133  label nCells_;
134 
135  //- Cached total selection volume
136  scalar V_;
137 
138  //- Flag to indicate whether the volRegion requires updating
139  bool requireUpdate_;
140 
141 
142  // Private Member Functions
143 
144  //- Update cellIds, nCells, volume
145  void calculateCache();
146 
147 
148 protected:
149 
150  // Protected Data
151 
152  //- Region type
154 
155  //- Region name (cellSet, cellZone, ...)
157 
158 
159  // Protected Member Functions
160 
161  //- Use all cells, not the cellIDs
162  inline bool useAllCells() const noexcept;
163 
164  //- Output file header information
165  void writeFileHeader(const writeFile& wf, Ostream& file) const;
166 
167 
168 public:
169 
170  //- Run-time type information
171  TypeName("volRegion");
172 
173 
174  // Constructors
175 
176  //- Construct from fvMesh and dictionary
177  volRegion(const fvMesh& mesh, const dictionary& dict);
178 
179 
180  //- Destructor
181  virtual ~volRegion() = default;
182 
184  // Member Functions
185 
186  //- The region type
187  inline regionTypes regionType() const noexcept;
189  //- Return the local list of cell IDs.
190  // Empty or invalid for 'all'
191  const labelList& cellIDs() const;
192 
193  //- Return the total number of cells selected in the region
194  inline label nCells() const;
195 
196  //- Return total volume of the selected region
197  inline scalar V() const;
198 
199  //- Update the cached values as required
200  // \return False if the values were already up to date
201  bool update();
202 
203 
204  //- Read from dictionary
205  virtual bool read(const dictionary& dict);
206 
207  //- Update for changes of mesh
208  virtual void updateMesh(const mapPolyMesh&);
209 
210  //- Update for mesh point-motion
211  virtual void movePoints(const polyMesh&);
212 };
213 
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace functionObjects
218 } // End namespace Foam
219 
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 
222 #include "volRegionI.H"
223 
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 
226 #endif
227 
228 // ************************************************************************* //
dictionary dict
regionTypes regionType() const noexcept
The region type.
Definition: volRegionI.H:31
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
void writeFileHeader(const writeFile &wf, Ostream &file) const
Output file header information.
Definition: volRegion.C:127
static const Enum< regionTypes > regionTypeNames_
Region type names.
Definition: volRegion.H:130
virtual bool read(const dictionary &dict)
Read from dictionary.
Definition: volRegion.C:171
virtual void movePoints(const polyMesh &)
Update for mesh point-motion.
Definition: volRegion.C:261
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: volRegion.C:255
bool useAllCells() const noexcept
Use all cells, not the cellIDs.
Definition: volRegionI.H:24
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
label nCells() const
Return the total number of cells selected in the region.
Definition: volRegionI.H:37
dynamicFvMesh & mesh
regionTypes
Region type enumeration.
Definition: volRegion.H:120
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings...
Definition: wordRe.H:78
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
scalar V() const
Return total volume of the selected region.
Definition: volRegionI.H:52
Volume (cell) region selection class.
Definition: volRegion.H:111
wordRe regionName_
Region name (cellSet, cellZone, ...)
Definition: volRegion.H:188
TypeName("volRegion")
Run-time type information.
const labelList & cellIDs() const
Return the local list of cell IDs.
Definition: volRegion.C:203
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
bool update()
Update the cached values as required.
Definition: volRegion.C:243
regionTypes regionType_
Region type.
Definition: volRegion.H:183
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Base class for writing single files from the function objects.
Definition: writeFile.H:112
Namespace for OpenFOAM.