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