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
218 
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  {
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 // ************************************************************************* //
Foam::ensightPart::name
const string & name() const
Part name or description.
Definition: ensightPart.H:251
Foam::ensightPart::size
label size() const
Number of elements in this part.
Definition: ensightPart.H:227
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::ensightPart::materialId
label materialId() const
Material id.
Definition: ensightPart.H:257
Foam::ensightPart::isFieldDefined
bool isFieldDefined(const List< scalar > &) const
Check for fully defined fields.
Definition: ensightPart.C:44
typeInfo.H
Foam::ensightPart::elemLists_
labelListList elemLists_
Simple labelList with a name.
Definition: ensightPart.H:76
Foam::ensightPart::name
void name(const string &value)
non-const access to part name or description
Definition: ensightPart.H:263
Foam::ensightPart::calcLocalPoints
virtual localPoints calcLocalPoints() const
Track points used.
Definition: ensightPart.H:145
Foam::ensightPart::localPoints::localPoints
localPoints()
Null constructor.
Definition: ensightPart.H:107
Foam::ensightPart::localPoints::nPoints
label nPoints
Number of points used.
Definition: ensightPart.H:101
Foam::ensightPart::clone
autoPtr< ensightPart > clone() const
Construct and return clone.
Definition: ensightPart.H:202
Foam::ensightPart::writeData
bool writeData(Ostream &) const
Write reconstruction information for the object.
Definition: ensightPartIO.C:144
Foam::ensightPart::number
label number() const
Part number.
Definition: ensightPart.H:245
Foam::ensightPart::matId_
label matId_
Material id (numeric)
Definition: ensightPart.H:88
Foam::ensightPart::reconstruct
void reconstruct(Istream &)
Reconstruct part characteristics (eg, element types) from Istream.
Definition: ensightPartIO.C:101
polyMesh.H
Foam::ensightPart::~ensightPart
virtual ~ensightPart()
Destructor.
Definition: ensightPart.C:155
Foam::ensightPart::writeScalarField
void writeScalarField(ensightFile &, const List< scalar > &field, const bool perNode=false) const
Write scalar field.
Definition: ensightPartIO.C:217
Foam::ensightPart::writeConnectivity
virtual void writeConnectivity(ensightGeoFile &, const word &key, const labelUList &idList, const labelUList &pointMap) const
Write connectivities.
Definition: ensightPart.H:152
Foam::ensightPart::writeVectorField
void writeVectorField(ensightFile &, const List< scalar > &field0, const List< scalar > &field1, const List< scalar > &field2, const bool perNode=false) const
Write vector field components.
Definition: ensightPartIO.C:250
Foam::ensightPart::elemLists
const labelListList & elemLists() const
Simple labelList with a name.
Definition: ensightPart.H:275
Foam::ensightPart::localPoints::list
labelList list
Map global to local indices.
Definition: ensightPart.H:104
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:365
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:45
Foam::label
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
labelList.H
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
IOPtrList.H
ensightFile.H
IOstream.H
Field.H
Foam::ensightPart::TypeName
TypeName("ensightPart")
Runtime type information.
Foam::ensightPart::isCellData_
bool isCellData_
Cell or face data.
Definition: ensightPart.H:85
Foam::ensightPart::offset_
label offset_
Start offset for elemLists_.
Definition: ensightPart.H:79
Foam::ensightPart::operator<<
friend Ostream & operator<<(Ostream &, const ensightPart &)
Write data (reconstruction information)
Foam::ensightPart::elemTypes_
static const List< word > elemTypes_
Definition: ensightPart.H:62
Foam::ensightPart::number_
label number_
Part number.
Definition: ensightPart.H:70
Foam::ensightPart::New
static autoPtr< ensightPart > New(Istream &)
Reconstruct part characteristics on freestore from Istream.
Definition: ensightPart.C:130
Foam::ensightPart::localPoints
Track the points used by the part and map global to local indices.
Definition: ensightPart.H:97
Foam::ensightFile
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:47
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::ensightPart::renumber
void renumber(const labelUList &)
Renumber elements.
Definition: ensightPart.C:161
ensightPartTemplates.C
Template to write generalized field components.
Foam::ensightPart::isFaceData
bool isFaceData() const
Represents face data.
Definition: ensightPart.H:239
Foam::ensightPart::size_
label size_
Number of elements in this part.
Definition: ensightPart.H:82
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
ensightGeoFile.H
Foam::ensightPart::offset
label offset() const
Offset for element ids.
Definition: ensightPart.H:281
Foam::ensightPart::isCellData
bool isCellData() const
Represents cell data.
Definition: ensightPart.H:233
Foam::ensightPart::writeFieldList
void writeFieldList(ensightFile &os, const List< scalar > &field, const labelUList &idList) const
Write a scalar field for idList.
Definition: ensightPartIO.C:56
Foam::List< word >
Foam::ensightPart
Base class for ensightPartCells and ensightPartFaces.
Definition: ensightPart.H:57
Foam::ensightPart::writeSummary
bool writeSummary(Ostream &) const
Write summary information about the object.
Definition: ensightPartIO.C:127
Foam::UList
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
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::ensightPart::localPoints::localPoints
localPoints(const pointField &pts)
Construct for mesh points.
Definition: ensightPart.H:114
Foam::ensightPart::ensightPart
ensightPart()
Construct null.
Definition: ensightPart.C:67
Foam::ensightPart::operator=
void operator=(const ensightPart &)
Disallow default bitwise assignment.
Definition: ensightPart.H:340
Foam::ensightPart::elementTypes
virtual const List< word > & elementTypes() const
Definition: ensightPart.H:218
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::ensightPart::points_
const pointField & points_
pointField referenced
Definition: ensightPart.H:91
Foam::ensightPart::writeField
void writeField(ensightFile &, const Field< Type > &, const bool perNode=false) const
Write generalized field components.
Definition: ensightPartTemplates.C:35
Foam::ensightPart::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, ensightPart, istream,(Istream &is),(is))
Foam::ensightPart::writeHeader
void writeHeader(ensightFile &, bool withDescription=false) const
Write the part header.
Definition: ensightPartIO.C:36
Foam::ensightPart::name_
string name_
Part name (or description)
Definition: ensightPart.H:73
Foam::ensightPart::writeGeometry
virtual void writeGeometry(ensightGeoFile &) const
Write geometry.
Definition: ensightPart.H:299
Foam::ensightPart::materialId
void materialId(const label value)
non-const access to material id
Definition: ensightPart.H:269