ensightCellsIO.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2020 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "ensightCells.H"
29#include "ensightOutput.H"
30#include "InfoProxy.H"
31#include "polyMesh.H"
32#include "globalIndex.H"
33#include "globalMeshData.H"
35
36// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37
38void Foam::ensightCells::writePolysConnectivity
39(
40 ensightGeoFile& os,
41 const polyMesh& mesh,
42 const ensightCells& part,
43 const labelList& pointToGlobal,
44 const bool parallel
45)
46{
48
49 const label nTotal = part.total(etype);
50 const labelUList& addr = part.cellIds(etype);
51
52 if (!nTotal)
53 {
54 return;
55 }
56
57 const IntRange<int> senders =
58 (
59 parallel
61 : IntRange<int>()
62 );
63
64
65 if (Pstream::master())
66 {
68 os.write(nTotal);
69 os.newline();
70 }
71
72 // Number of faces per polyhedral (1/line in ASCII)
73 {
74 labelList send
75 (
77 );
78
79 if (Pstream::master())
80 {
81 // Main
82 os.writeLabels(send);
83
84 // Others
85 for (const int proci : senders)
86 {
87 IPstream fromOther(Pstream::commsTypes::scheduled, proci);
88 labelList recv(fromOther);
89
90 os.writeLabels(recv);
91 }
92 }
93 else if (senders)
94 {
95 OPstream toMaster
96 (
99 );
100
101 toMaster << send;
102 }
103 }
104
105
106 // Number of points for each polyhedral face (1/line in ASCII)
107 {
108 labelList send
109 (
111 );
112
113 if (Pstream::master())
114 {
115 // Main
116 os.writeLabels(send);
117
118 // Others
119 for (const int proci : senders)
120 {
121 IPstream fromOther(Pstream::commsTypes::scheduled, proci);
122 labelList recv(fromOther);
123
124 os.writeLabels(recv);
125 }
126 }
127 else if (senders)
128 {
129 OPstream toMaster
130 (
133 );
134
135 toMaster << send;
136 }
137 }
138
140 const cellList& meshCells = manifoldCellsMeshObject::New(mesh).cells();
141
142 // List of points id for each face of the above list
143 if (Pstream::master())
144 {
145 // Main
147 (
148 os,
149 mesh,
150 addr,
151 pointToGlobal
152 );
153
154 // Others
155 for (const int proci : senders)
156 {
157 IPstream fromOther(Pstream::commsTypes::scheduled, proci);
158 cellList cells(fromOther);
159 labelList addr(fromOther);
160 faceList faces(fromOther);
161 labelList owner(fromOther);
162
164 (
165 os,
166 cells,
167 addr,
168 faces,
169 owner
170 );
171 }
172 }
173 else if (senders)
174 {
175 // Renumber faces to use global point numbers
176 faceList faces(mesh.faces());
177 ListListOps::inplaceRenumber(pointToGlobal, faces);
178
179 OPstream toMaster
180 (
183 );
184
185 toMaster
186 << meshCells
187 << addr
188 << faces
189 << mesh.faceOwner();
190 }
191}
192
193
194void Foam::ensightCells::writeShapeConnectivity
195(
196 ensightGeoFile& os,
197 const polyMesh& mesh,
198 const ensightCells::elemType etype,
199 const ensightCells& part,
200 const labelList& pointToGlobal,
201 const bool parallel
202)
203{
204 if (etype == ensightCells::NFACED)
205 {
207 << "Called for ensight NFACED cell. Programming error\n"
208 << exit(FatalError);
209 }
210
211 const label nTotal = part.total(etype);
212 const labelUList& addr = part.cellIds(etype);
213
214 if (!nTotal)
215 {
216 return;
217 }
218
219
220 const IntRange<int> senders =
221 (
222 parallel
224 : IntRange<int>()
225 );
226
227
228 if (Pstream::master())
229 {
231 os.write(nTotal);
232 os.newline();
233 }
234
235
236 // Primitive shape - get subset and renumber
237 cellShapeList shapes(mesh.cellShapes(), addr);
238
239 ListListOps::inplaceRenumber(pointToGlobal, shapes);
240
241 if (Pstream::master())
242 {
244
245 for (const int proci : senders)
246 {
247 IPstream fromOther(Pstream::commsTypes::scheduled, proci);
248 cellShapeList recv(fromOther);
249
251 }
252 }
253 else if (senders)
254 {
255 OPstream toMaster
256 (
259 );
260
261 toMaster << shapes;
262 }
263}
264
265
267(
269 const polyMesh& mesh,
270 bool parallel
271) const
272{
273 const ensightCells& part = *this;
274
275 parallel = parallel && Pstream::parRun();
276
277 // Renumber the points/faces into unique points
278
279 label nPoints = 0; // Total number of points
280 labelList pointToGlobal; // local point to unique global index
281 labelList uniqueMeshPointLabels; // unique global points
282
283 nPoints = meshPointMapppings
284 (
285 mesh,
286 pointToGlobal,
287 uniqueMeshPointLabels,
288 parallel
289 );
290
292 (
293 os,
294 part.index(),
295 part.name(),
296 nPoints, // nPoints (global)
297 UIndirectList<point>(mesh.points(), uniqueMeshPointLabels),
298 parallel
299 );
300
301
302 for (label typei=0; typei < ensightCells::nTypes; ++typei)
303 {
304 const auto etype = ensightCells::elemType(typei);
305
306 if (etype == ensightCells::NFACED)
307 {
308 writePolysConnectivity
309 (
310 os,
311 mesh,
312 part,
313 pointToGlobal,
314 parallel
315 );
316 }
317 else
318 {
319 writeShapeConnectivity
320 (
321 os,
322 mesh,
323 etype,
324 part,
325 pointToGlobal,
326 parallel
327 );
328 }
329 }
330}
331
332
333// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
334
335template<>
336Foam::Ostream& Foam::operator<<
337(
338 Ostream& os,
340)
341{
342 const ensightCells& part = ip.t_;
343
344 os << part.name().c_str();
345
346 for (label typei=0; typei < ensightCells::nTypes; ++typei)
347 {
348 const auto etype = ensightCells::elemType(typei);
349
350 os << ' ' << ensightCells::elemNames[etype]
351 << ':' << part.total(etype);
352 }
353 os << nl;
354
355 return os;
356}
357
358
359// ************************************************************************* //
const Key & key() const
The key associated with the iterator.
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:52
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:57
UPstream::rangeType subProcs() const noexcept
Range of sub-processes indices associated with PstreamBuffers.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
static constexpr int masterNo() noexcept
Process index of the master (always 0)
Definition: UPstream.H:451
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:58
static constexpr int nTypes
Number of 'Cell' element types (5)
Definition: ensightCells.H:75
static const char * elemNames[nTypes]
The ensight 'Cell' element type names.
Definition: ensightCells.H:78
elemType
Supported ensight 'Cell' element types.
Definition: ensightCells.H:66
label total() const
The global size of all element types.
Definition: ensightCells.C:111
Specialized Ensight output with extra geometry file header.
label index() const noexcept
The index in a list (0-based)
Definition: ensightPart.H:124
const string & name() const noexcept
The part name or description.
Definition: ensightPart.H:160
virtual bool write()
Write the output fields.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1108
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1121
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1083
const cellShapeList & cellShapes() const
Return cell shapes.
splitCell * master() const
Definition: splitCell.H:113
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
label nPoints
const cellShapeList & cells
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Definition: ensightOutput.H:90
bool writeCoordinates(ensightGeoFile &os, const label partId, const word &partName, const label nPoints, const FieldContainer< Foam::point > &fld, bool parallel)
Write coordinates (component-wise) for the given part.
labelList getPolysNPointsPerFace(const polyMesh &mesh, const labelUList &addr)
The number of points for each face of the poly elements.
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
The number of faces per poly element.
Definition: ensightOutput.C:79
void writePolysPoints(ensightGeoFile &os, const cellUList &meshCells, const labelUList &addr, const faceUList &meshFaces, const labelUList &faceOwner)
Write the point ids per poly element.
void writeCellShapes(ensightGeoFile &os, const UList< cellShape > &shapes, const label pointOffset=0)
Write cell connectivity via cell shapes.
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:45
List< label > labelList
A List of labels.
Definition: List.H:66
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
error FatalError
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
UList< label > labelUList
A UList of labels.
Definition: UList.H:85
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53