cellModel.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-2015 OpenFOAM Foundation
9  Copyright (C) 2017-2020 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::cellModel
29 
30 Description
31  Maps a geometry to a set of cell primitives.
32 
33  This enables geometric cell data to be calculated without access
34  to the primitive geometric level. This means mapping a 3D
35  geometry to a set of pyramids which are each described by a cell
36  face and the cell centre point.
37 
38  Also includes a static collection of cell models (normally loaded from
39  etc/cellModels), and a means of looking them up.
40 
41 SourceFiles
42  cellModelI.H
43  cellModel.C
44  cellModels.C
45  cellModelIO.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef cellModel_H
50 #define cellModel_H
51 
52 #include "pointField.H"
53 #include "edgeList.H"
54 #include "faceList.H"
55 #include "InfoProxy.H"
56 #include "autoPtr.H"
57 #include "PtrList.H"
58 #include "Enum.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 // Forward Declarations
66 class cellModel;
67 Ostream& operator<<(Ostream& os, const cellModel& cm);
68 
69 /*---------------------------------------------------------------------------*\
70  Class cellModel Declaration
71 \*---------------------------------------------------------------------------*/
72 
73 class cellModel
74 {
75 public:
76 
77  //- Enumeration of commonly used cellModel types.
78  // The indices must match those in "etc/cellModels"
79  enum modelType
80  {
81  UNKNOWN = 0,
82  HEX = 3,
83  WEDGE = 4,
84  PRISM = 5,
85  PYR = 6,
86  TET = 7,
87  SPLITHEX = 8,
88  TETWEDGE = 9,
89  };
90 
91  //- Names of commonly used cellModels corresponding to modelType.
92  // The names must match those in "etc/cellModels"
93  static const Enum<modelType> modelNames;
94 
95 
96  // Lookup Methods
97 
98  //- Look up pointer to cellModel by enumeration, or nullptr on failure.
99  static const cellModel* ptr(const modelType model);
100 
101  //- Look up pointer to cellModel by name, or nullptr on failure.
102  static const cellModel* ptr(const word& modelName);
103 
104  //- Look up pointer to cellModel by index, or nullptr on failure
105  static const cellModel* ptr(const label modelIndex);
106 
107 
108  //- Look up reference to cellModel by enumeration. Fatal on failure
109  static const cellModel& ref(const modelType model);
110 
111  //- Look up reference to cellModel by name. Fatal on failure
112  static const cellModel& ref(const word& modelName);
113 
114  //- Look up reference to cellModel by index. Fatal on failure
115  static const cellModel& ref(const label modelIndex);
116 
117 
118 private:
119 
120  // Private Static Data
121 
122  //- PtrList of predefined models
123  static PtrList<cellModel> models_;
124 
125  //- Lookup of model pointers (in models_) by index
126  static List<const cellModel*> modelPtrs_;
127 
128 
129  // Private Data
130 
131  //- (Unique) model name
132  word name_;
133 
134  //- Index in the model list
135  label index_;
136 
137  //- Number of points in the model which determines the geometry
138  label nPoints_;
139 
140  //- Faces of the model
141  faceList faces_;
142 
143  //- Edges of the model
144  edgeList edges_;
145 
146 
147  // Private Member Functions
148 
149  //- Construct from central "etc/cellModels" file.
150  static void constructModels();
151 
152 
153 public:
154 
155  // Constructors
156 
157  //- Construct from Istream
158  explicit cellModel(Istream& is);
159 
160  //- Return a new cellModel created from Istream
161  static autoPtr<cellModel> New(Istream& is)
162  {
163  return autoPtr<cellModel>::New(is);
164  }
165 
166  //- Return clone
167  autoPtr<cellModel> clone() const
168  {
169  return autoPtr<cellModel>::New(*this);
170  }
171 
172 
173  // Member Functions
174 
175  //- Return model name
176  inline const word& name() const noexcept;
177 
178  //- Return index of model in the model list
179  inline label index() const noexcept;
180 
181  //- Return number of points
182  inline label nPoints() const noexcept;
183 
184  //- Return number of edges
185  inline label nEdges() const noexcept;
186 
187  //- Return number of faces
188  inline label nFaces() const noexcept;
189 
190  //- Return a raw list of model edges
191  inline const edgeList& modelEdges() const noexcept;
192 
193  //- Return a raw list of model faces
194  inline const faceList& modelFaces() const noexcept;
195 
196  //- Return list of cell edges
197  inline edgeList edges(const labelUList& pointLabels) const;
198 
199  //- Return list of cell faces
200  inline faceList faces(const labelUList& pointLabels) const;
201 
202  //- Return the cell edge for specified model edge
203  inline Foam::edge edge
204  (
205  const label modelEdgei,
206  const labelUList& pointLabels
207  ) const;
208 
209  //- Return the cell face for specified model face
210  inline Foam::face face
211  (
212  const label modelFacei,
213  const labelUList& pointLabels
214  ) const;
215 
216 
217  //- Centroid of the cell
218  vector centre
219  (
220  const labelList& pointLabels,
221  const UList<point>& points
222  ) const;
223 
224  //- Cell volume
225  scalar mag
226  (
227  const labelList& pointLabels,
228  const UList<point>& points
229  ) const;
230 
231  //- Return info proxy.
232  // Used to print information to a stream
233  InfoProxy<cellModel> info() const
234  {
235  return *this;
236  }
237 
238  //- The writeData member function required by regIOobject
239  bool writeData(Ostream& os) const
240  {
241  os << *this;
242  return os.good();
243  }
244 
245 
246  // Ostream Operator
247 
248  friend Ostream& operator<<(Ostream& os, const cellModel& cm);
249 };
250 
251 
252 // Ostream Operators
253 
254 template<>
255 Ostream& operator<<(Ostream& os, const InfoProxy<cellModel>& ip);
256 
257 
258 // Global Operators
259 
260 //- Equality: true when model pointers are identical
261 inline bool operator==(const cellModel& lhs, const cellModel& rhs) noexcept;
262 
263 //- Inequality: true when model pointers are not identical
264 inline bool operator!=(const cellModel& lhs, const cellModel& rhs) noexcept;
265 
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 } // End namespace Foam
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #include "cellModelI.H"
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #endif
278 
279 // ************************************************************************* //
Foam::cellModel::index
label index() const noexcept
Return index of model in the model list.
Definition: cellModelI.H:37
Foam::autoPtr::New
static autoPtr< T > New(Args &&... args)
Construct autoPtr of T with forwarding arguments.
Foam::cellModel::info
InfoProxy< cellModel > info() const
Return info proxy.
Definition: cellModel.H:232
Foam::Enum< modelType >
Foam::cellModel::faces
faceList faces(const labelUList &pointLabels) const
Return list of cell faces.
Definition: cellModelI.H:102
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::InfoProxy
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:47
Foam::cellModel::modelNames
static const Enum< modelType > modelNames
Names of commonly used cellModels corresponding to modelType.
Definition: cellModel.H:92
InfoProxy.H
Foam::cellModel::HEX
hex
Definition: cellModel.H:81
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:63
Foam::cellModel::New
static autoPtr< cellModel > New(Istream &is)
Return a new cellModel created from Istream.
Definition: cellModel.H:160
Foam::cellModel::ptr
static const cellModel * ptr(const modelType model)
Look up pointer to cellModel by enumeration, or nullptr on failure.
Definition: cellModels.C:120
faceList.H
Foam::cellModel::operator<<
friend Ostream & operator<<(Ostream &os, const cellModel &cm)
Foam::cellModel::edges
edgeList edges(const labelUList &pointLabels) const
Return list of cell edges.
Definition: cellModelI.H:74
Foam::cellModel::clone
autoPtr< cellModel > clone() const
Return clone.
Definition: cellModel.H:166
Foam::cellModel::TET
tet
Definition: cellModel.H:85
Foam::cellModel::cellModel
cellModel(Istream &is)
Construct from Istream.
Definition: cellModelIO.C:34
Foam::cellModel::centre
vector centre(const labelList &pointLabels, const UList< point > &points) const
Centroid of the cell.
Definition: cellModel.C:35
cellModelI.H
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::cellModel::writeData
bool writeData(Ostream &os) const
The writeData member function required by regIOobject.
Definition: cellModel.H:238
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::cellModel::modelEdges
const edgeList & modelEdges() const noexcept
Return a raw list of model edges.
Definition: cellModelI.H:61
Foam::cellModel::PRISM
prism
Definition: cellModel.H:83
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::cellModel::ref
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition: cellModels.C:157
Foam::cellModel::nEdges
label nEdges() const noexcept
Return number of edges.
Definition: cellModelI.H:49
edgeList.H
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
pointField.H
Foam::cellModel::WEDGE
wedge
Definition: cellModel.H:82
Foam::cellModel::name
const word & name() const noexcept
Return model name.
Definition: cellModelI.H:31
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::cellModel::PYR
pyr
Definition: cellModel.H:84
Foam::Vector< scalar >
Foam::cellModel::nFaces
label nFaces() const noexcept
Return number of faces.
Definition: cellModelI.H:55
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::cellModel::nPoints
label nPoints() const noexcept
Return number of points.
Definition: cellModelI.H:43
Foam::cellModel::UNKNOWN
unknown
Definition: cellModel.H:80
Foam::cellModel::modelFaces
const faceList & modelFaces() const noexcept
Return a raw list of model faces.
Definition: cellModelI.H:67
PtrList.H
Foam::cellModel::TETWEDGE
tetWedge
Definition: cellModel.H:87
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::cellModel::modelType
modelType
Enumeration of commonly used cellModel types.
Definition: cellModel.H:78
Foam::cellModel
Maps a geometry to a set of cell primitives.
Definition: cellModel.H:72
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::cellModel::mag
scalar mag(const labelList &pointLabels, const UList< point > &points) const
Cell volume.
Definition: cellModel.C:78
pointLabels
labelList pointLabels(nPoints, -1)
Foam::cellModel::SPLITHEX
splitHex
Definition: cellModel.H:86
autoPtr.H
Enum.H