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 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 Static Models
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  cellModel(Istream& is);
159 
160  //- Return a new cellModel on free-store 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;
177 
178  //- Return index of model in the model list
179  inline label index() const;
180 
181  //- Return number of points
182  inline label nPoints() const;
183 
184  //- Return number of edges
185  inline label nEdges() const;
186 
187  //- Return number of faces
188  inline label nFaces() const;
189 
190  //- Return a raw list of model edges
191  inline const edgeList& modelEdges() const;
192 
193  //- Return a raw list of model faces
194  inline const faceList& modelFaces() const;
195 
196  //- Return list of edges
197  inline edgeList edges(const labelUList& pointLabels) const;
198 
199  //- Return list of faces
200  inline faceList faces(const labelUList& pointLabels) const;
201 
202 
203  //- Vector centroid
204  vector centre
205  (
206  const labelList& pointLabels,
207  const UList<point>& points
208  ) const;
209 
210  //- Cell volume
211  scalar mag
212  (
213  const labelList& pointLabels,
214  const UList<point>& points
215  ) const;
216 
217  //- Return info proxy.
218  // Used to print information to a stream
219  InfoProxy<cellModel> info() const
220  {
221  return *this;
222  }
223 
224  //- WriteData member function required by regIOobject
225  bool writeData(Ostream& os) const
226  {
227  os << *this;
228  return os.good();
229  }
230 
231 
232  // Ostream operator
233 
234  friend Ostream& operator<<(Ostream& os, const cellModel& cm);
235 
236 };
237 
238 
239 // Ostream operators
240 
241 template<>
242 Ostream& operator<<(Ostream& os, const InfoProxy<cellModel>& ip);
243 
244 
245 // Global operators
246 
247 //- Equality: true when model pointers are identical
248 inline bool operator==(const cellModel& lhs, const cellModel& rhs);
249 
250 //- Inequality: true when model pointers are not identical
251 inline bool operator!=(const cellModel& lhs, const cellModel& rhs);
252 
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 } // End namespace Foam
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 #include "cellModelI.H"
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #endif
265 
266 // ************************************************************************* //
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:218
Foam::cellModel::nFaces
label nFaces() const
Return number of faces.
Definition: cellModelI.H:54
Foam::Enum< modelType >
Foam::cellModel::faces
faceList faces(const labelUList &pointLabels) const
Return list of faces.
Definition: cellModelI.H:99
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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::cellModel::New
static autoPtr< cellModel > New(Istream &is)
Return a new cellModel on free-store 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::nEdges
label nEdges() const
Return number of edges.
Definition: cellModelI.H:48
Foam::cellModel::edges
edgeList edges(const labelUList &pointLabels) const
Return list of edges.
Definition: cellModelI.H:75
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:33
Foam::cellModel::centre
vector centre(const labelList &pointLabels, const UList< point > &points) const
Vector centroid.
Definition: cellModel.C:35
cellModelI.H
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:235
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
WriteData member function required by regIOobject.
Definition: cellModel.H:224
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::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:62
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::modelFaces
const faceList & modelFaces() const
Return a raw list of model faces.
Definition: cellModelI.H:66
edgeList.H
Foam::cellModel::name
const word & name() const
Return model name.
Definition: cellModelI.H:30
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::cellModel::modelEdges
const edgeList & modelEdges() const
Return a raw list of model edges.
Definition: cellModelI.H:60
pointField.H
Foam::cellModel::WEDGE
wedge
Definition: cellModel.H:82
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::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:102
Foam::UList< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::cellModel::UNKNOWN
unknown
Definition: cellModel.H:80
PtrList.H
Foam::cellModel::TETWEDGE
tetWedge
Definition: cellModel.H:87
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::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:224
Foam::cellModel::mag
scalar mag(const labelList &pointLabels, const UList< point > &points) const
Cell volume.
Definition: cellModel.C:92
Foam::cellModel::index
label index() const
Return index of model in the model list.
Definition: cellModelI.H:36
pointLabels
labelList pointLabels(nPoints, -1)
Foam::cellModel::SPLITHEX
splitHex
Definition: cellModel.H:86
Foam::cellModel::nPoints
label nPoints() const
Return number of points.
Definition: cellModelI.H:42
autoPtr.H
Enum.H