ensightPart.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 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 // Forward declaration of friend functions and operators
55 
56 class ensightPart;
57 
58 Ostream& operator<<(Ostream&, const ensightPart&);
59 ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&);
60 
61 
62 /*---------------------------------------------------------------------------*\
63  Class ensightPart Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class ensightPart
67 {
68  // Private Data
69 
70  // Static Data Members
71  static const List<word> elemTypes_;
72 
73 
74 protected:
75 
76  // Protected data
77 
78  //- Part number
79  label number_;
80 
81  //- Part name (or description)
82  string name_;
83 
84  //- Simple labelList with a name
86 
87  //- Start offset for elemLists_
88  label offset_;
89 
90  //- Number of elements in this part
91  label size_;
92 
93  //- Cell or face data
94  bool isCellData_;
95 
96  //- Material id (numeric)
97  label matId_;
98 
99  //- pointField referenced
100  const pointField& points_;
101 
102 
103  // Protected Classes
104 
105  //- Track the points used by the part and map global to local indices
106  class localPoints
107  {
108  public:
109  //- Number of points used
110  label nPoints;
111 
112  //- Map global to local indices
113  labelList list;
114 
115  //- Null constructor
116  localPoints()
117  :
118  nPoints(0),
119  list(0)
120  {}
121 
122  //- Construct for mesh points
123  localPoints(const pointField& pts)
124  :
125  nPoints(0),
126  list(pts.size(), -1)
127  {}
128  };
129 
130 
131  // Protected Member Functions
132 
133  //- Reconstruct part characteristics (eg, element types) from Istream
134  // A part reconstructed in this manner can be used when writing fields,
135  // but cannot be used to write a new geometry
136  void reconstruct(Istream&);
137 
138  //- Check for fully defined fields
139  bool isFieldDefined(const List<scalar>&) const;
140 
141  //- Write the part header
142  void writeHeader(ensightFile&, bool withDescription=false) const;
143 
144  //- Write a scalar field for idList
145  // A null reference for idList writes the perNode values
146  void writeFieldList
147  (
148  ensightFile& os,
149  const List<scalar>& field,
150  const labelUList& idList
151  ) const;
152 
153  //- Track points used
154  virtual localPoints calcLocalPoints() const
155  {
156  return localPoints();
157  }
158 
159  //- Write connectivities
160  virtual void writeConnectivity
161  (
163  const word& key,
164  const labelUList& idList,
165  const labelUList& pointMap
166  ) const
167  {}
168 
169 
170 public:
171 
172  //- Runtime type information
173  TypeName("ensightPart");
174 
175 
176  // Constructors
177 
178  //- Construct null
179  ensightPart();
180 
181  //- Construct empty part with number and description
182  ensightPart(label partNumber, const string& partDescription);
183 
184  //- Construct part with number, description and points reference
186  (
187  label partNumber,
188  const string& partDescription,
189  const pointField& points
190  );
191 
192  //- Copy constructor
193  ensightPart(const ensightPart&);
194 
195 
196  // Selectors
197 
198  // Declare run-time constructor selection table
200  (
201  autoPtr,
202  ensightPart,
203  istream,
204  (
205  Istream& is
206  ),
207  (is)
208  );
209 
210  //- Construct and return clone
212  {
213  return autoPtr<ensightPart>(new ensightPart(*this));
214  };
215 
216  //- Reconstruct part characteristics on freestore from Istream
217  // \sa reconstruct
219 
220 
221  //- Destructor
222  virtual ~ensightPart();
223 
224 
225  // Static members
227  virtual const List<word>& elementTypes() const
228  {
229  return elemTypes_;
230  }
231 
232 
233  // Access
234 
235  //- Number of elements in this part
236  label size() const
237  {
238  return size_;
239  }
240 
241  //- Represents cell data
242  bool isCellData() const
243  {
244  return isCellData_;
245  }
246 
247  //- Represents face data
248  bool isFaceData() const
249  {
250  return !isCellData_;
251  }
252 
253  //- Part number
254  label number() const
255  {
256  return number_;
257  }
258 
259  //- Part name or description
260  const string& name() const
261  {
262  return name_;
263  }
264 
265  //- Material id
266  label materialId() const
267  {
268  return matId_;
269  }
270 
271  //- non-const access to part name or description
272  void name(const string& value)
273  {
274  name_ = value;
275  }
276 
277  //- non-const access to material id
278  void materialId(const label value)
279  {
280  matId_ = value;
281  }
282 
283  //- Simple labelList with a name
284  const labelListList& elemLists() const
285  {
286  return elemLists_;
287  }
288 
289  //- Offset for element ids
290  label offset() const
291  {
292  return offset_;
293  }
294 
295 
296  // Edit
297 
298  //- Renumber elements
299  void renumber(const labelUList&);
300 
301  //- Write summary information about the object
302  bool writeSummary(Ostream&) const;
303 
304  //- Write reconstruction information for the object
305  bool writeData(Ostream&) const;
306 
307  //- Write geometry
308  virtual void writeGeometry(ensightGeoFile&) const
309  {}
310 
311  //- Helper: write geometry given the pointField
312  void writeGeometry(ensightGeoFile&, const pointField&) const;
313 
314  //- Write scalar field
315  // optionally write data per node
316  void writeScalarField
317  (
318  ensightFile&,
319  const List<scalar>& field,
320  const bool perNode = false
321  ) const;
322 
323  //- Write vector field components
324  // optionally write data per node
325  void writeVectorField
326  (
327  ensightFile&,
328  const List<scalar>& field0,
329  const List<scalar>& field1,
330  const List<scalar>& field2,
331  const bool perNode = false
332  ) const;
333 
334 
335  //- Write generalised field components
336  // optionally write data per node
337  template<class Type>
338  void writeField
339  (
340  ensightFile&,
341  const Field<Type>&,
342  const bool perNode = false
343  ) const;
344 
345 
346  // Member Operators
347 
348  //- Disallow default bitwise assignment
349  void operator=(const ensightPart&) = delete;
350 
351 
352  // IOstream Operators
353 
354  //- Write data (reconstruction information)
355  friend Ostream& operator<<(Ostream&, const ensightPart&);
356 
357  //- Write geometry
359 };
360 
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 } // End namespace Foam
365 
366 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
367 
368 #ifdef NoRepository
369  #include "ensightPartTemplates.C"
370 #endif
371 
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
373 
374 #endif
375 
376 // ************************************************************************* //
bool isFaceData() const
Represents face data.
Definition: ensightPart.H:247
TypeName("ensightPart")
Runtime type information.
virtual ~ensightPart()
Destructor.
Definition: ensightPart.C:155
Ensight output with specialised write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:47
label number_
Part number.
Definition: ensightPart.H:78
bool writeData(Ostream &) const
Write reconstruction information for the object.
label size() const
Number of elements in this part.
Definition: ensightPart.H:235
localPoints()
Null constructor.
Definition: ensightPart.H:115
ensightPart()
Construct null.
Definition: ensightPart.C:67
friend Ostream & operator<<(Ostream &, const ensightPart &)
Write data (reconstruction information)
label nPoints
Number of points used.
Definition: ensightPart.H:109
autoPtr< ensightPart > clone() const
Construct and return clone.
Definition: ensightPart.H:210
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
label number() const
Part number.
Definition: ensightPart.H:253
virtual localPoints calcLocalPoints() const
Track points used.
Definition: ensightPart.H:153
const labelListList & elemLists() const
Simple labelList with a name.
Definition: ensightPart.H:283
Specialised Ensight output with extra geometry file header.
const pointField & points_
pointField referenced
Definition: ensightPart.H:99
Track the points used by the part and map global to local indices.
Definition: ensightPart.H:105
void writeScalarField(ensightFile &, const List< scalar > &field, const bool perNode=false) const
Write scalar field.
bool isCellData_
Cell or face data.
Definition: ensightPart.H:93
labelListList elemLists_
Simple labelList with a name.
Definition: ensightPart.H:84
labelList list
Map global to local indices.
Definition: ensightPart.H:112
void writeFieldList(ensightFile &os, const List< scalar > &field, const labelUList &idList) const
Write a scalar field for idList.
Definition: ensightPartIO.C:56
void writeHeader(ensightFile &, bool withDescription=false) const
Write the part header.
Definition: ensightPartIO.C:36
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 size_
Number of elements in this part.
Definition: ensightPart.H:90
const pointField & points
const string & name() const
Part name or description.
Definition: ensightPart.H:259
A class for handling words, derived from string.
Definition: word.H:59
void reconstruct(Istream &)
Reconstruct part characteristics (eg, element types) from Istream.
void operator=(const ensightPart &)=delete
Disallow default bitwise assignment.
static autoPtr< ensightPart > New(Istream &)
Reconstruct part characteristics on freestore from Istream.
Definition: ensightPart.C:130
virtual void writeGeometry(ensightGeoFile &) const
Write geometry.
Definition: ensightPart.H:307
label materialId() const
Material id.
Definition: ensightPart.H:265
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
void renumber(const labelUList &)
Renumber elements.
Definition: ensightPart.C:161
void writeField(ensightFile &, const Field< Type > &, const bool perNode=false) const
Write generalised field components.
bool isCellData() const
Represents cell data.
Definition: ensightPart.H:241
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
declareRunTimeSelectionTable(autoPtr, ensightPart, istream,(Istream &is),(is))
Base class for ensightPartCells and ensightPartFaces.
Definition: ensightPart.H:65
virtual void writeConnectivity(ensightGeoFile &, const word &key, const labelUList &idList, const labelUList &pointMap) const
Write connectivities.
Definition: ensightPart.H:160
Template to write generalised field components.
bool isFieldDefined(const List< scalar > &) const
Check for fully defined fields.
Definition: ensightPart.C:44
label offset_
Start offset for elemLists_.
Definition: ensightPart.H:87
Ostream & operator<<(Ostream &, const ensightPart &)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
bool writeSummary(Ostream &) const
Write summary information about the object.
rDeltaTY field()
string name_
Part name (or description)
Definition: ensightPart.H:81
Namespace for OpenFOAM.
label offset() const
Offset for element ids.
Definition: ensightPart.H:289
virtual const List< word > & elementTypes() const
Definition: ensightPart.H:226
label matId_
Material id (numeric)
Definition: ensightPart.H:96