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-2022 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 {
35  recalculate(mesh);
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 =
62  (
63  mesh.cellZones().size()
64  + mesh.boundaryMesh().size()
65  + 1
66  );
67 
68  partsList_.setSize(nPart);
69  nPart = 0;
70 
71  label nZoneCells = 0;
72 
73  // do cell zones
74  forAll(mesh.cellZones(), zoneI)
75  {
76  const cellZone& cZone = mesh.cellZones()[zoneI];
77  nZoneCells += cZone.size();
78 
79  if (cZone.size())
80  {
81  partsList_.set
82  (
83  nPart,
84  new ensightPartCells(nPart, mesh, cZone)
85  );
86 
87  nPart++;
88  }
89  }
90 
91  // collect unzoned cells
92 
93  // special case: no zones at all - do entire mesh
94  if (nZoneCells == 0)
95  {
96  partsList_.set
97  (
98  nPart,
99  new ensightPartCells(nPart, mesh)
100  );
101 
102  nPart++;
103  }
104  else if (mesh.nCells() > nZoneCells)
105  {
106  // determine which cells are not in a cellZone
107  labelList unzoned(mesh.nCells(), -1);
108 
109  forAll(mesh.cellZones(), zoneI)
110  {
111  const labelUList& idList = mesh.cellZones()[zoneI];
112 
113  forAll(idList, i)
114  {
115  unzoned[idList[i]] = idList[i];
116  }
117  }
118 
119  label nUnzoned = 0;
120  forAll(unzoned, i)
121  {
122  if (unzoned[i] < 0)
123  {
124  unzoned[nUnzoned] = i;
125  nUnzoned++;
126  }
127  }
128  unzoned.setSize(nUnzoned);
129 
130  if (unzoned.size())
131  {
132  partsList_.set
133  (
134  nPart,
135  new ensightPartCells(nPart, mesh, unzoned)
136  );
137 
138  nPart++;
139  }
140  }
141 
142 
143  // do boundaries, skipping empty and processor patches
144  forAll(mesh.boundaryMesh(), patchi)
145  {
146  const polyPatch& patch = mesh.boundaryMesh()[patchi];
147  if (patch.size() && !isA<processorPolyPatch>(patch))
148  {
149  partsList_.set
150  (
151  nPart,
152  new ensightPartFaces(nPart, mesh, patch)
153  );
154 
155  nPart++;
156  }
157  }
158 
159  // truncate to correct size
160  partsList_.setSize(nPart);
161 }
162 
163 
165 (
166  const labelUList& origCellId,
167  const labelUList& origFaceId
168 )
169 {
170  forAll(partsList_, partI)
171  {
172  if (partsList_[partI].isCellData())
173  {
174  partsList_[partI].renumber(origCellId);
175  }
176  else
177  {
178  partsList_[partI].renumber(origFaceId);
179  }
180  }
181 }
182 
183 
185 {
186  // with some feedback
187  Info<< "write geometry part:" << nl << flush;
188 
189  forAll(partsList_, partI)
190  {
191  Info<< " " << partI << flush;
192  partsList_[partI].writeGeometry(os);
193  }
194 }
195 
196 
198 {
199  forAll(partsList_, partI)
200  {
201  partsList_[partI].writeSummary(os);
202  }
203 
204  return true;
205 }
206 
207 
209 {
210  // Begin write list
211  os << nl << partsList_.size()
212  << nl << token::BEGIN_LIST;
213 
214  // Write list contents
215  forAll(partsList_, i)
216  {
217  os << nl << partsList_[i];
218  }
219 
220  // End write list
221  os << nl << token::END_LIST << nl;
222 
223  // Check state of IOstream
224  os.check("ensightParts::writeData(Ostream&)");
225 }
226 
227 
229 (
230  ensightFile& os,
231  const List<scalar>& field,
232  const bool useFaceData,
233  const bool perNode
234 ) const
235 {
236  forAll(partsList_, partI)
237  {
238  if
239  (
240  useFaceData
241  ? partsList_[partI].isFaceData()
242  : partsList_[partI].isCellData()
243  )
244  {
245  partsList_[partI].writeScalarField(os, field, perNode);
246  }
247  }
248 }
249 
250 
252 (
253  ensightFile& os,
254  const List<scalar>& field0,
255  const List<scalar>& field1,
256  const List<scalar>& field2,
257  const bool useFaceData,
258  const bool perNode
259 ) const
260 {
261  forAll(partsList_, partI)
262  {
263  if
264  (
265  useFaceData
266  ? partsList_[partI].isFaceData()
267  : partsList_[partI].isCellData()
268  )
269  {
270  partsList_[partI].writeVectorField
271  (
272  os,
273  field0, field1, field2,
274  perNode
275  );
276  }
277  }
278 }
279 
280 
281 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
282 
283 Foam::ensightGeoFile& Foam::operator<<
284 (
285  ensightGeoFile& os,
286  const ensightParts& parts
287 )
288 {
289  parts.writeGeometry(os);
290  return os;
291 }
292 
293 
294 // ************************************************************************* //
void writeGeometry(ensightGeoFile &) const
Write the geometry.
Definition: ensightParts.C:184
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:453
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:229
void recalculate(const polyMesh &)
Clear old information and construct anew from polyMesh.
Definition: ensightParts.C:56
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:252
const meshCellZones & cellZones() const
Return cell zones.
Definition: polyMesh.H:501
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.
fvMesh & mesh
void writeData(Ostream &) const
Write the lists.
Definition: ensightParts.C:208
~ensightParts()
Destructor.
Definition: ensightParts.C:50
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:31
bool writeSummary(Ostream &) const
Write summary information about the objects.
Definition: ensightParts.C:197
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:165
An implementation of ensightPart to hold volume mesh faces.
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
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:98