ensightPart.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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::ensightPart
26 
27 Description
28  Base class for ensightPartCells and ensightPartFaces
29 
30 SourceFiles
31  ensightPart.C
32  ensightPartIO.C
33  ensightPartTemplates.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef ensightPart_H
38 #define ensightPart_H
39 
40 #include "ensightFile.H"
41 #include "ensightGeoFile.H"
42 #include "typeInfo.H"
43 #include "labelList.H"
44 #include "polyMesh.H"
45 #include "Field.H"
46 #include "IOPtrList.H"
47 #include "IOstream.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class ensightPart Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class ensightPart
59 {
60  // Private data
61 
62  // Static data members
63  static const List<word> elemTypes_;
64 
65 
66 protected:
67 
68  // Protected data
69 
70  //- Part number
71  label number_;
72 
73  //- Part name (or description)
74  string name_;
75 
76  //- Simple labelList with a name
78 
79  //- Start offset for elemLists_
80  label offset_;
81 
82  //- Number of elements in this part
83  label size_;
84 
85  //- Cell or face data
86  bool isCellData_;
87 
88  //- Material id (numeric)
89  label matId_;
90 
91  //- pointField referenced
92  const pointField& points_;
93 
94 
95  // Protected Classes
96 
97  //- Track the points used by the part and map global to local indices
98  class localPoints
99  {
100  public:
101  //- Number of points used
102  label nPoints;
103 
104  //- Map global to local indices
105  labelList list;
106 
107  //- Null constructor
108  localPoints()
109  :
110  nPoints(0),
111  list(0)
112  {}
113 
114  //- Construct for mesh points
115  localPoints(const pointField& pts)
116  :
117  nPoints(0),
118  list(pts.size(), -1)
119  {}
120  };
121 
122 
123  // Protected Member Functions
124 
125  //- Reconstruct part characteristics (eg, element types) from Istream
126  // A part reconstructed in this manner can be used when writing fields,
127  // but cannot be used to write a new geometry
128  void reconstruct(Istream&);
129 
130  //- Check for fully defined fields
131  bool isFieldDefined(const List<scalar>&) const;
132 
133  //- Write the part header
134  void writeHeader(ensightFile&, bool withDescription=false) const;
135 
136  //- Write a scalar field for idList
137  // A null reference for idList writes the perNode values
138  void writeFieldList
139  (
140  ensightFile& os,
141  const List<scalar>& field,
142  const labelUList& idList
143  ) const;
144 
145  //- Track points used
146  virtual localPoints calcLocalPoints() const
147  {
148  return localPoints();
149  }
150 
151  //- Write connectivities
152  virtual void writeConnectivity
153  (
155  const word& key,
156  const labelUList& idList,
157  const labelUList& pointMap
158  ) const
159  {}
160 
161 
162 public:
163 
164  //- Runtime type information
165  TypeName("ensightPart");
166 
167 
168  // Constructors
169 
170  //- Construct null
171  ensightPart();
172 
173  //- Construct empty part with number and description
174  ensightPart(label partNumber, const string& partDescription);
175 
176  //- Construct part with number, description and points reference
178  (
179  label partNumber,
180  const string& partDescription,
181  const pointField& points
182  );
183 
184  //- Construct as copy
185  ensightPart(const ensightPart&);
186 
187 
188  // Selectors
189 
190  // Declare run-time constructor selection table
192  (
193  autoPtr,
194  ensightPart,
195  istream,
196  (
197  Istream& is
198  ),
199  (is)
200  );
201 
202  //- Construct and return clone
204  {
205  return autoPtr<ensightPart>(new ensightPart(*this));
206  };
207 
208  //- Reconstruct part characteristics on freestore from Istream
209  // \sa reconstruct
211 
212 
213  //- Destructor
214  virtual ~ensightPart();
215 
216 
217  // Static members
219  virtual const List<word>& elementTypes() const
220  {
221  return elemTypes_;
222  }
223 
224 
225  // Access
226 
227  //- Number of elements in this part
228  label size() const
229  {
230  return size_;
231  }
232 
233  //- Represents cell data
234  bool isCellData() const
235  {
236  return isCellData_;
237  }
238 
239  //- Represents face data
240  bool isFaceData() const
241  {
242  return !isCellData_;
243  }
244 
245  //- Part number
246  label number() const
247  {
248  return number_;
249  }
250 
251  //- Part name or description
252  const string& name() const
253  {
254  return name_;
255  }
256 
257  //- Material id
258  label materialId() const
259  {
260  return matId_;
261  }
262 
263  //- non-const access to part name or description
264  void name(const string& value)
265  {
266  name_ = value;
267  }
268 
269  //- non-const access to material id
270  void materialId(const label value)
271  {
272  matId_ = value;
273  }
274 
275  //- Simple labelList with a name
276  const labelListList& elemLists() const
277  {
278  return elemLists_;
279  }
280 
281  //- Offset for element ids
282  label offset() const
283  {
284  return offset_;
285  }
286 
287 
288  // Edit
289 
290  //- Renumber elements
291  void renumber(const labelUList&);
292 
293  //- Write summary information about the object
294  bool writeSummary(Ostream&) const;
295 
296  //- Write reconstruction information for the object
297  bool writeData(Ostream&) const;
298 
299  //- Write geometry
300  virtual void writeGeometry(ensightGeoFile&) const
301  {}
302 
303  //- Helper: write geometry given the pointField
304  void writeGeometry(ensightGeoFile&, const pointField&) const;
305 
306  //- Write scalar field
307  // optionally write data per node
308  void writeScalarField
309  (
310  ensightFile&,
311  const List<scalar>& field,
312  const bool perNode = false
313  ) const;
314 
315  //- Write vector field components
316  // optionally write data per node
317  void writeVectorField
318  (
319  ensightFile&,
320  const List<scalar>& field0,
321  const List<scalar>& field1,
322  const List<scalar>& field2,
323  const bool perNode = false
324  ) const;
325 
326 
327  //- Write generalized field components
328  // optionally write data per node
329  template<class Type>
330  void writeField
331  (
332  ensightFile&,
333  const Field<Type>&,
334  const bool perNode = false
335  ) const;
336 
337 
338  // Member Operators
339 
340  //- Disallow default bitwise assignment
341  void operator=(const ensightPart&)
342  {
343  notImplemented("ensightPart::operator=(const ensightPart&)");
344  }
345 
346 
347  // IOstream Operators
348 
349  //- Write data (reconstruction information)
350  friend Ostream& operator<<(Ostream&, const ensightPart&);
351 
352  //- Write geometry
354 
355 };
356 
357 
358 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359 
360 } // End namespace Foam
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 #ifdef NoRepository
365 # include "ensightPartTemplates.C"
366 #endif
367 
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
369 
370 #endif
371 
372 // ************************************************************************* //
bool isCellData_
Cell or face data.
Definition: ensightPart.H:85
labelList list
Map global to local indices.
Definition: ensightPart.H:104
const pointField & points
label size_
Number of elements in this part.
Definition: ensightPart.H:82
Specialized Ensight output with extra geometry file header.
virtual void writeGeometry(ensightGeoFile &) const
Write geometry.
Definition: ensightPart.H:299
const string & name() const
Part name or description.
Definition: ensightPart.H:251
void writeVectorField(ensightFile &, const List< scalar > &field0, const List< scalar > &field1, const List< scalar > &field2, const bool perNode=false) const
Write vector field components.
label number() const
Part number.
Definition: ensightPart.H:245
label offset() const
Offset for element ids.
Definition: ensightPart.H:281
void writeFieldList(ensightFile &os, const List< scalar > &field, const labelUList &idList) const
Write a scalar field for idList.
Definition: ensightPartIO.C:56
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
ensightPart()
Construct null.
Definition: ensightPart.C:67
label nPoints
Number of points used.
Definition: ensightPart.H:101
label matId_
Material id (numeric)
Definition: ensightPart.H:88
virtual localPoints calcLocalPoints() const
Track points used.
Definition: ensightPart.H:145
void writeField(ensightFile &, const Field< Type > &, const bool perNode=false) const
Write generalized field components.
labelListList elemLists_
Simple labelList with a name.
Definition: ensightPart.H:76
Base class for ensightPartCells and ensightPartFaces.
Definition: ensightPart.H:57
virtual void writeConnectivity(ensightGeoFile &, const word &key, const labelUList &idList, const labelUList &pointMap) const
Write connectivities.
Definition: ensightPart.H:152
Namespace for OpenFOAM.
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:47
void writeHeader(ensightFile &, bool withDescription=false) const
Write the part header.
Definition: ensightPartIO.C:36
bool isFieldDefined(const List< scalar > &) const
Check for fully defined fields.
Definition: ensightPart.C:44
bool writeSummary(Ostream &) const
Write summary information about the object.
void operator=(const ensightPart &)
Disallow default bitwise assignment.
Definition: ensightPart.H:340
Track the points used by the part and map global to local indices.
Definition: ensightPart.H:97
label size() const
Number of elements in this part.
Definition: ensightPart.H:227
label number_
Part number.
Definition: ensightPart.H:70
label materialId() const
Material id.
Definition: ensightPart.H:257
const pointField & points_
pointField referenced
Definition: ensightPart.H:91
autoPtr< ensightPart > clone() const
Construct and return clone.
Definition: ensightPart.H:202
virtual const List< word > & elementTypes() const
Definition: ensightPart.H:218
Template to write generalized field components.
label offset_
Start offset for elemLists_.
Definition: ensightPart.H:79
void renumber(const labelUList &)
Renumber elements.
Definition: ensightPart.C:161
string name_
Part name (or description)
Definition: ensightPart.H:73
bool isCellData() const
Represents cell data.
Definition: ensightPart.H:233
virtual ~ensightPart()
Destructor.
Definition: ensightPart.C:155
const labelListList & elemLists() const
Simple labelList with a name.
Definition: ensightPart.H:275
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
friend Ostream & operator<<(Ostream &, const ensightPart &)
Write data (reconstruction information)
declareRunTimeSelectionTable(autoPtr, ensightPart, istream,( Istream &is ),(is))
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void writeScalarField(ensightFile &, const List< scalar > &field, const bool perNode=false) const
Write scalar field.
bool isFaceData() const
Represents face data.
Definition: ensightPart.H:239
localPoints()
Null constructor.
Definition: ensightPart.H:107
#define notImplemented(functionName)
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:356
bool writeData(Ostream &) const
Write reconstruction information for the object.
void reconstruct(Istream &)
Reconstruct part characteristics (eg, element types) from Istream.
TypeName("ensightPart")
Runtime type information.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
static autoPtr< ensightPart > New(Istream &)
Reconstruct part characteristics on freestore from Istream.
Definition: ensightPart.C:130