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