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 -------------------------------------------------------------------------------
10 License
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 
40 void 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 {
49  constexpr ensightCells::elemType etype(ensightCells::elemType::NFACED);
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 
196 void Foam::ensightCells::writeShapeConnectivity
197 (
198  ensightGeoFile& os,
199  const polyMesh& mesh,
200  const ensightCells::elemType etype,
201  const ensightCells& part,
202  const labelList& pointToGlobal,
203  const bool parallel
204 )
205 {
206  if (etype == ensightCells::elemType::NFACED)
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  {
249  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
250  cellShapeList recv(fromOther);
251 
253  }
254  }
255  else if (senders)
256  {
257  OPstream toMaster
258  (
261  );
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 = meshPointMapppings
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 
308  if (etype == ensightCells::elemType::NFACED)
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 (
337  ensightGeoFile& os,
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  {
364  os.writeKeyword(ensightCells::key(ensightCells::elemType::HEXA8));
365  os.write(shapes.size()); // one cell (global)
366  os.newline();
367 
369  }
370 }
371 
372 
373 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
374 
375 template<>
376 Foam::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 // ************************************************************************* //
List< cell > cellList
List of cell.
Definition: cellListFwd.H:39
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
virtual Ostream & write(const char c) override
Write character.
Definition: OBJstream.C:69
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
virtual const fileName & name() const override
Read/write access to the name of the stream.
Definition: OSstream.H:134
static const manifoldCellsMeshObject & New(const polyMesh &mesh, Args &&... args)
Get existing or create MeshObject registered with typeName.
Definition: MeshObject.C:53
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const cellShapeList & cellShapes() const
Return cell shapes.
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:1061
List< cellShape > cellShapeList
List of cellShape.
Definition: cellShapeList.H:32
labelList getPolysNPointsPerFace(const polyMesh &mesh, const labelUList &addr)
The number of points for each face of the poly elements.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Definition: ensightOutput.H:92
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
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...
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const cellShapeList & cells
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
const pointField & points
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...
Definition: labelLists.C:44
label nPoints
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
Definition: UPstream.H:1071
elemType
Supported ensight &#39;Cell&#39; element types.
Definition: ensightCells.H:63
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Write geometry, using a mesh reference (serial only) No beginGeometry() marker.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void writePolysPoints(ensightGeoFile &os, const cellUList &meshCells, const labelUList &addr, const faceUList &meshFaces, const labelUList &faceOwner)
Write the point ids per poly element.
OBJstream os(runTime.globalPath()/outputName)
static const char * key(const elemType etype) noexcept
The ensight element name for the specified &#39;Cell&#39; type.
Definition: ensightCellsI.H:42
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
Definition: ListI.H:205
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
The number of faces per poly element.
Definition: ensightOutput.C:89
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1094
static const char * elemNames[nTypes]
The ensight &#39;Cell&#39; element type names.
Definition: ensightCells.H:80
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition: UPstream.H:1197
List< label > labelList
A List of labels.
Definition: List.H:62
const cellList & cells() const
Return the (optionally compacted) cell list Triggers demand-driven filtering if required.
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.
void writeCellShapes(ensightGeoFile &os, const UList< cellShape > &shapes, const label pointOffset=0)
Write cell connectivity via cell shapes.
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:60
static constexpr int nTypes
Number of &#39;Cell&#39; element types (5)
Definition: ensightCells.H:75