ensightParts.C
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-2018 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 \*---------------------------------------------------------------------------*/
25 
26 #include "ensightParts.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
31 :
32  partsList_()
33 {
34  recalculate(mesh);
35 }
36 
37 
39 :
40  partsList_()
41 {
42  IOPtrList<ensightPart> ioList(ioObj);
43  partsList_.transfer(ioList);
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
48 
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
56 {
57  partsList_.clear();
58 
59  // extra space for unzoned cells
60  label nPart =
61  (
62  mesh.cellZones().size()
63  + mesh.boundaryMesh().size()
64  + 1
65  );
66 
67  partsList_.setSize(nPart);
68  nPart = 0;
69 
70  label nZoneCells = 0;
71 
72  // do cell zones
73  forAll(mesh.cellZones(), zoneI)
74  {
75  const cellZone& cZone = mesh.cellZones()[zoneI];
76  nZoneCells += cZone.size();
77 
78  if (cZone.size())
79  {
80  partsList_.set
81  (
82  nPart,
83  new ensightPartCells(nPart, mesh, cZone)
84  );
85 
86  nPart++;
87  }
88  }
89 
90  // collect unzoned cells
91 
92  // special case: no zones at all - do entire mesh
93  if (nZoneCells == 0)
94  {
95  partsList_.set
96  (
97  nPart,
98  new ensightPartCells(nPart, mesh)
99  );
100 
101  nPart++;
102  }
103  else if (mesh.nCells() > nZoneCells)
104  {
105  // determine which cells are not in a cellZone
106  labelList unzoned(mesh.nCells(), -1);
107 
108  forAll(mesh.cellZones(), zoneI)
109  {
110  const labelUList& idList = mesh.cellZones()[zoneI];
111 
112  forAll(idList, i)
113  {
114  unzoned[idList[i]] = idList[i];
115  }
116  }
117 
118  label nUnzoned = 0;
119  forAll(unzoned, i)
120  {
121  if (unzoned[i] < 0)
122  {
123  unzoned[nUnzoned] = i;
124  nUnzoned++;
125  }
126  }
127  unzoned.setSize(nUnzoned);
128 
129  if (unzoned.size())
130  {
131  partsList_.set
132  (
133  nPart,
134  new ensightPartCells(nPart, mesh, unzoned)
135  );
136 
137  nPart++;
138  }
139  }
140 
141 
142  // do boundaries, skipping empty and processor patches
143  forAll(mesh.boundaryMesh(), patchi)
144  {
145  const polyPatch& patch = mesh.boundaryMesh()[patchi];
146  if (patch.size() && !isA<processorPolyPatch>(patch))
147  {
148  partsList_.set
149  (
150  nPart,
151  new ensightPartFaces(nPart, mesh, patch)
152  );
153 
154  nPart++;
155  }
156  }
157 
158  // truncate to correct size
159  partsList_.setSize(nPart);
160 }
161 
162 
164 (
165  const labelUList& origCellId,
166  const labelUList& origFaceId
167 )
168 {
169  forAll(partsList_, partI)
170  {
171  if (partsList_[partI].isCellData())
172  {
173  partsList_[partI].renumber(origCellId);
174  }
175  else
176  {
177  partsList_[partI].renumber(origFaceId);
178  }
179  }
180 }
181 
182 
184 {
185  // with some feedback
186  Info<< "write geometry part:" << nl << flush;
187 
188  forAll(partsList_, partI)
189  {
190  Info<< " " << partI << flush;
191  partsList_[partI].writeGeometry(os);
192  }
193 }
194 
195 
197 {
198  forAll(partsList_, partI)
199  {
200  partsList_[partI].writeSummary(os);
201  }
202 
203  return true;
204 }
205 
206 
208 {
209  // Begin write list
210  os << nl << partsList_.size()
211  << nl << token::BEGIN_LIST;
212 
213  // Write list contents
214  forAll(partsList_, i)
215  {
216  os << nl << partsList_[i];
217  }
218 
219  // End write list
220  os << nl << token::END_LIST << nl;
221 
222  // Check state of IOstream
223  os.check("ensightParts::writeData(Ostream&)");
224 }
225 
226 
228 (
229  ensightFile& os,
230  const List<scalar>& field,
231  const bool useFaceData,
232  const bool perNode
233 ) const
234 {
235  forAll(partsList_, partI)
236  {
237  if
238  (
239  useFaceData
240  ? partsList_[partI].isFaceData()
241  : partsList_[partI].isCellData()
242  )
243  {
244  partsList_[partI].writeScalarField(os, field, perNode);
245  }
246  }
247 }
248 
249 
251 (
252  ensightFile& os,
253  const List<scalar>& field0,
254  const List<scalar>& field1,
255  const List<scalar>& field2,
256  const bool useFaceData,
257  const bool perNode
258 ) const
259 {
260  forAll(partsList_, partI)
261  {
262  if
263  (
264  useFaceData
265  ? partsList_[partI].isFaceData()
266  : partsList_[partI].isCellData()
267  )
268  {
269  partsList_[partI].writeVectorField
270  (
271  os,
272  field0, field1, field2,
273  perNode
274  );
275  }
276  }
277 }
278 
279 
280 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
281 
282 Foam::ensightGeoFile& Foam::operator<<
283 (
284  ensightGeoFile& os,
285  const ensightParts& parts
286 )
287 {
288  parts.writeGeometry(os);
289  return os;
290 }
291 
292 
293 // ************************************************************************* //
void writeGeometry(ensightGeoFile &) const
Write the geometry.
Definition: ensightParts.C:183
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
Ensight output with specialised write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:47
void writeScalarField(ensightFile &, const List< scalar > &field, const bool useFaceData=false, const bool perNode=false) const
Write (volume) scalar field.
Definition: ensightParts.C:228
void recalculate(const polyMesh &)
Clear old information and construct anew from polyMesh.
Definition: ensightParts.C:55
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
A collection of several ensightPart elements.
Definition: ensightParts.H:59
void writeVectorField(ensightFile &, const List< scalar > &field0, const List< scalar > &field1, const List< scalar > &field2, const bool useFaceData=false, const bool perNode=false) const
Write (volume) vector field components.
Definition: ensightParts.C:251
const meshCellZones & cellZones() const
Return cell zones.
Definition: polyMesh.H:482
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
label nCells() const
Specialised Ensight output with extra geometry file header.
An implementation of ensightPart to hold volume mesh cells.
void writeData(Ostream &) const
Write the lists.
Definition: ensightParts.C:207
~ensightParts()
Destructor.
Definition: ensightParts.C:49
dynamicFvMesh & mesh
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
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
ensightParts(const polyMesh &)
Construct from polyMesh.
Definition: ensightParts.C:30
bool writeSummary(Ostream &) const
Write summary information about the objects.
Definition: ensightParts.C:196
A subset of mesh cells.
Definition: cellZone.H:61
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:50
label patchi
Ostream & flush(Ostream &os)
Flush stream.
Definition: Ostream.H:243
void renumber(const labelUList &origCellId, const labelUList &origFaceId)
Renumber elements.
Definition: ensightParts.C:164
An implementation of ensightPart to hold volume mesh faces.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92