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 -------------------------------------------------------------------------------
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 "polyMesh.H"
32 #include "globalIndex.H"
33 #include "globalMeshData.H"
35 
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 
38 void 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 {
47  constexpr ensightCells::elemType etype(ensightCells::elemType::NFACED);
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  {
67  os.writeKeyword(ensightCells::key(etype));
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 
194 void 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::elemType::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  );
261  toMaster << shapes;
262  }
263 }
264 
265 
267 (
268  ensightGeoFile& os,
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::elemType::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 
335 template<>
336 Foam::Ostream& Foam::operator<<
337 (
338  Ostream& os,
339  const InfoProxy<ensightCells>& iproxy
340 )
341 {
342  const auto& part = *iproxy;
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 // ************************************************************************* //
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:598
virtual const fileName & name() const override
Read/write access to the name of the stream.
Definition: OSstream.H:128
static const manifoldCellsMeshObject & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new 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:1049
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
dynamicFvMesh & mesh
const cellShapeList & cells
"scheduled" : (MPI_Send, MPI_Recv)
label nPoints
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
Definition: UPstream.H:1059
elemType
Supported ensight &#39;Cell&#39; element types.
Definition: ensightCells.H:62
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Write geometry, using a mesh reference (serial only)
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
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:1082
static const char * elemNames[nTypes]
The ensight &#39;Cell&#39; element type names.
Definition: ensightCells.H:79
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition: UPstream.H:1185
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:74