Loading...
Searching...
No Matches
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-2024 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 "boundBox.H"
32#include "polyMesh.H"
33#include "cellModel.H"
34#include "globalIndex.H"
35#include "globalMeshData.H"
37
38// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39
40void Foam::ensightCells::writePolysConnectivity
41(
42 ensightGeoFile& os,
43 const polyMesh& mesh,
44 const ensightCells& part,
45 const labelList& pointToGlobal,
46 const bool parallel
47)
48{
50
51 const label nTotal = part.total(etype);
52 const labelUList& addr = part.cellIds(etype);
53
54 if (!nTotal)
55 {
56 return;
57 }
58
59 const IntRange<int> senders =
60 (
61 parallel
63 : IntRange<int>()
64 );
65
66
67 if (Pstream::master())
68 {
69 os.writeKeyword(ensightCells::key(etype));
70 os.write(nTotal);
71 os.newline();
72 }
73
74 // Number of faces per polyhedral (1/line in ASCII)
75 {
76 labelList send
77 (
79 );
80
81 if (Pstream::master())
82 {
83 // Main
84 os.writeLabels(send);
85
86 // Others
87 for (const int proci : senders)
88 {
89 IPstream fromOther(Pstream::commsTypes::scheduled, proci);
90 labelList recv(fromOther);
91
92 os.writeLabels(recv);
93 }
94 }
95 else if (senders)
96 {
97 OPstream toMaster
98 (
101 );
102
103 toMaster << send;
104 }
105 }
106
107
108 // Number of points for each polyhedral face (1/line in ASCII)
109 {
110 labelList send
111 (
113 );
114
115 if (Pstream::master())
116 {
117 // Main
118 os.writeLabels(send);
119
120 // Others
121 for (const int proci : senders)
122 {
123 IPstream fromOther(Pstream::commsTypes::scheduled, proci);
124 labelList recv(fromOther);
125
126 os.writeLabels(recv);
127 }
128 }
129 else if (senders)
130 {
131 OPstream toMaster
132 (
135 );
136
137 toMaster << send;
138 }
139 }
140
142 const cellList& meshCells = manifoldCellsMeshObject::New(mesh).cells();
143
144 // List of points id for each face of the above list
145 if (Pstream::master())
146 {
147 // Main
149 (
150 os,
151 mesh,
152 addr,
153 pointToGlobal
154 );
155
156 // Others
157 for (const int proci : senders)
158 {
159 IPstream fromOther(Pstream::commsTypes::scheduled, proci);
160 cellList cells(fromOther);
161 labelList addr(fromOther);
162 faceList faces(fromOther);
163 labelList owner(fromOther);
164
166 (
167 os,
168 cells,
169 addr,
170 faces,
171 owner
172 );
173 }
174 }
175 else if (senders)
176 {
177 // Renumber faces to use global point numbers
178 faceList faces(mesh.faces());
179 ListListOps::inplaceRenumber(pointToGlobal, faces);
180
181 OPstream toMaster
182 (
185 );
186
187 toMaster
188 << meshCells
189 << addr
190 << faces
191 << mesh.faceOwner();
192 }
193}
194
195
196void Foam::ensightCells::writeShapeConnectivity
197(
199 const polyMesh& mesh,
200 const ensightCells::elemType etype,
201 const ensightCells& part,
202 const labelList& pointToGlobal,
203 const bool parallel
204)
205{
207 {
209 << "Called for ensight NFACED cell. Programming error\n"
210 << exit(FatalError);
211 }
212
213 const label nTotal = part.total(etype);
214 const labelUList& addr = part.cellIds(etype);
215
216 if (!nTotal)
217 {
218 return;
219 }
220
221
222 const IntRange<int> senders =
223 (
224 parallel
226 : IntRange<int>()
227 );
228
229
230 if (Pstream::master())
231 {
233 os.write(nTotal);
234 os.newline();
235 }
236
237
238 // Primitive shape - get subset and renumber
239 cellShapeList shapes(mesh.cellShapes(), addr);
240
241 ListListOps::inplaceRenumber(pointToGlobal, shapes);
242
243 if (Pstream::master())
244 {
246
247 for (const int proci : senders)
248 {
250 cellShapeList recv(fromOther);
251
253 }
254 }
255 else if (senders)
256 {
257 OPstream toMaster
258 (
261 );
262
263 toMaster << shapes;
264 }
265}
266
267
269(
270 ensightGeoFile& os,
271 const polyMesh& mesh,
272 bool parallel
273) const
274{
275 const ensightCells& part = *this;
276
277 parallel = parallel && Pstream::parRun();
278
279 // Renumber the points/faces into unique points
280
281 label nPoints = 0; // Total number of points
282 labelList pointToGlobal; // local point to unique global index
283 labelList uniqueMeshPointLabels; // unique global points
284
285 nPoints = meshPointMappings
286 (
287 mesh,
288 pointToGlobal,
289 uniqueMeshPointLabels,
290 parallel
291 );
292
294 (
295 os,
296 part.index(),
297 part.name(),
298 nPoints, // nPoints (global)
299 UIndirectList<point>(mesh.points(), uniqueMeshPointLabels),
300 parallel
301 );
302
303
304 for (label typei=0; typei < ensightCells::nTypes; ++typei)
305 {
306 const auto etype = ensightCells::elemType(typei);
307
309 {
310 writePolysConnectivity
311 (
312 os,
313 mesh,
314 part,
315 pointToGlobal,
316 parallel
317 );
318 }
319 else
320 {
321 writeShapeConnectivity
322 (
323 os,
324 mesh,
325 etype,
326 part,
327 pointToGlobal,
328 parallel
329 );
330 }
331 }
332}
333
334
336(
338 const boundBox& bb,
339 const label partIndex,
340 const word& partName
341)
342{
344 cellShapeList shapes;
345
346 if (UPstream::master())
347 {
348 points = bb.hexCorners();
350 }
351
353 (
354 os,
355 partIndex,
356 partName,
357 8, // nPoints (global)
358 points,
359 false // serial only! (parallel=false)
360 );
361
362 if (UPstream::master())
363 {
365 os.write(shapes.size()); // one cell (global)
366 os.newline();
367
370}
371
372
373// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
374
375template<>
376Foam::Ostream& Foam::operator<<
377(
378 Ostream& os,
379 const InfoProxy<ensightCells>& iproxy
380)
381{
382 const auto& part = *iproxy;
383
384 os << part.name().c_str();
385
386 for (label typei=0; typei < ensightCells::nTypes; ++typei)
387 {
388 const auto etype = ensightCells::elemType(typei);
389
390 os << ' ' << ensightCells::elemNames[etype]
391 << ':' << part.total(etype);
392 }
393 os << nl;
394
395 return os;
396}
397
398
399// ************************************************************************* //
Input inter-processor communications stream.
Definition IPstream.H:53
A helper class for outputting values to Ostream.
Definition InfoProxy.H:49
An interval of (signed) integers defined by a start and a size.
Definition IntRange.H:69
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
Definition ListI.H:206
static FOAM_NO_DANGLING_REFERENCE const manifoldCellsMeshObject & New(const polyMesh &mesh, Args &&... args)
virtual Ostream & write(const char c) override
Write character.
Definition OBJstream.C:69
virtual const fileName & name() const override
Read/write access to the name of the stream.
Definition OSstream.H:134
Output inter-processor communications stream.
Definition OPstream.H:53
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition Ostream.C:60
A List with indirect addressing. Like IndirectList but does not store addressing.
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
@ scheduled
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
Definition UPstream.H:83
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
Definition UPstream.H:1691
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition UPstream.H:1714
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition UPstream.H:1866
static bool & parRun() noexcept
Test if this a parallel run.
Definition UPstream.H:1681
A bounding box defined in terms of min/max extrema points.
Definition boundBox.H:71
tmp< pointField > hexCorners() const
Corner points in an order corresponding to a 'hex' cell.
Sorting/classification of cells (3D) into corresponding ensight element types.
static void writeBox(ensightGeoFile &os, const boundBox &bb, const label partIndex=0, const word &partName="geometry-box")
Write bounding box geometry. All parameters are only relevant on master No beginGeometry() marker.
static const char * key(const elemType etype) noexcept
The ensight element name for the specified 'Cell' type.
static constexpr int nTypes
Number of 'Cell' element types (5).
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Write geometry, using a mesh reference (serial only) No beginGeometry() marker.
ensightCells()
Default construct, with part index 0.
static const char * elemNames[nTypes]
The ensight 'Cell' element type names.
elemType
Supported ensight 'Cell' element types.
A variant of ensightFile (Ensight writing) that includes the extra geometry file header information.
label index() const noexcept
The index in a list (0-based).
const string & name() const noexcept
The part name or description.
const cellList & cells() const
Return the (optionally compacted) cell list Triggers demand-driven filtering if required.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const cellShapeList & cellShapes() const
Return cell shapes.
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
const pointField & points
label nPoints
const cellShapeList & cells
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
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.
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< label > labelList
A List of labels.
Definition List.H:62
List< face > faceList
List of faces.
Definition faceListFwd.H:41
List< cell > cellList
List of cell.
Definition cellListFwd.H:41
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
UList< label > labelUList
A UList of labels.
Definition UList.H:75
List< cellShape > cellShapeList
List of cellShape.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50