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 "polyMesh.H"
31 #include "globalIndex.H"
32 #include "globalMeshData.H"
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 void Foam::ensightCells::writePolysConnectivity
37 (
38  ensightGeoFile& os,
39  const polyMesh& mesh,
40  const ensightCells& part,
41  const labelList& pointToGlobal,
42  const bool parallel
43 )
44 {
46 
47  // Slaves
48  const label nSlaves = (parallel ? Pstream::nProcs() : 0);
49 
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  if (Pstream::master())
60  {
61  os.writeKeyword(ensightCells::key(etype));
62  os.write(nTotal);
63  os.newline();
64  }
65 
66  // Number of faces per polyhedral (1/line in ASCII)
67  {
68  labelList send
69  (
71  );
72 
73  if (Pstream::master())
74  {
75  // Master
76  os.writeLabels(send);
77 
78  // Slaves
79  for (int slave=1; slave < nSlaves; ++slave)
80  {
81  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
82 
83  labelList recv(fromSlave);
84  os.writeLabels(recv);
85  }
86  }
87  else if (nSlaves)
88  {
89  OPstream toMaster
90  (
93  );
94 
95  toMaster << send;
96  }
97  }
98 
99 
100  // Number of points for each polyhedral face (1/line in ASCII)
101  {
102  labelList send
103  (
105  );
106 
107  if (Pstream::master())
108  {
109  // Master
110  os.writeLabels(send);
111 
112  // Slaves
113  for (int slave=1; slave < nSlaves; ++slave)
114  {
115  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
116 
117  labelList recv(fromSlave);
118  os.writeLabels(recv);
119  }
120  }
121  else if (nSlaves)
122  {
123  OPstream toMaster
124  (
127  );
128 
129  toMaster << send;
130  }
131  }
132 
133 
134  // List of points id for each face of the above list
135  if (Pstream::master())
136  {
137  // Master
139  (
140  os,
141  mesh,
142  addr,
143  pointToGlobal
144  );
145 
146  // Slaves
147  for (int slave=1; slave < nSlaves; ++slave)
148  {
149  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
150 
151  cellList cells(fromSlave);
152  labelList addr(fromSlave);
153  faceList faces(fromSlave);
154  labelList owner(fromSlave);
155 
157  (
158  os,
159  cells,
160  addr,
161  faces,
162  owner
163  );
164  }
165  }
166  else if (nSlaves)
167  {
168  // Renumber faces to use global point numbers
169  faceList faces(mesh.faces());
170  ListListOps::inplaceRenumber(pointToGlobal, faces);
171 
172  OPstream toMaster
173  (
176  );
177 
178  toMaster
179  << mesh.cells()
180  << addr
181  << faces
182  << mesh.faceOwner();
183  }
184 }
185 
186 
187 void Foam::ensightCells::writeShapeConnectivity
188 (
189  ensightGeoFile& os,
190  const polyMesh& mesh,
191  const ensightCells::elemType etype,
192  const ensightCells& part,
193  const labelList& pointToGlobal,
194  const bool parallel
195 )
196 {
197  if (etype == ensightCells::NFACED)
198  {
200  << "Called for ensight NFACED cell. Programming error\n"
201  << exit(FatalError);
202  }
203 
204  // Slaves
205  const label nSlaves = (parallel ? Pstream::nProcs() : 0);
206 
207 
208  const label nTotal = part.total(etype);
209  const labelUList& addr = part.cellIds(etype);
210 
211  if (!nTotal)
212  {
213  return;
214  }
215 
216 
217  if (Pstream::master())
218  {
219  os.writeKeyword(ensightCells::key(etype));
220  os.write(nTotal);
221  os.newline();
222  }
223 
224 
225  // Primitive shape - get subset and renumber
226  cellShapeList shapes(mesh.cellShapes(), addr);
227 
228  ListListOps::inplaceRenumber(pointToGlobal, shapes);
229 
230  if (Pstream::master())
231  {
232  ensightOutput::writeCellShapes(os, shapes);
233 
234  for (int slave=1; slave < nSlaves; ++slave)
235  {
236  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
237  cellShapeList recv(fromSlave);
238 
240  }
241  }
242  else if (nSlaves)
243  {
244  OPstream toMaster
245  (
248  );
249 
250  toMaster << shapes;
251  }
252 }
253 
254 
256 (
257  ensightGeoFile& os,
258  const polyMesh& mesh,
259  bool parallel
260 ) const
261 {
262  const ensightCells& part = *this;
263 
264  parallel = parallel && Pstream::parRun();
265 
266  // Renumber the points/faces into unique points
267 
268  label nPoints = 0; // Total number of points
269  labelList pointToGlobal; // local point to unique global index
270  labelList uniqueMeshPointLabels; // unique global points
271 
272  nPoints = meshPointMapppings
273  (
274  mesh,
275  pointToGlobal,
276  uniqueMeshPointLabels,
277  parallel
278  );
279 
281  (
282  os,
283  part.index(),
284  part.name(),
285  nPoints, // nPoints (global)
286  UIndirectList<point>(mesh.points(), uniqueMeshPointLabels),
287  parallel
288  );
289 
290 
291  for (label typei=0; typei < ensightCells::nTypes; ++typei)
292  {
293  const auto etype = ensightCells::elemType(typei);
294 
295  if (etype == ensightCells::NFACED)
296  {
297  writePolysConnectivity
298  (
299  os,
300  mesh,
301  part,
302  pointToGlobal,
303  parallel
304  );
305  }
306  else
307  {
308  writeShapeConnectivity
309  (
310  os,
311  mesh,
312  etype,
313  part,
314  pointToGlobal,
315  parallel
316  );
317  }
318  }
319 }
320 
321 
322 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1038
Foam::ensightPart::index
label index() const
The index in a list (0-based)
Definition: ensightPart.H:124
Foam::UPstream::masterNo
static constexpr int masterNo() noexcept
Process index of the master.
Definition: UPstream.H:433
Foam::ensightPart::name
const string & name() const
The part name or description.
Definition: ensightPart.H:160
globalMeshData.H
Foam::ensightCells::key
static const char * key(const elemType etype)
The ensight element name for the specified 'Cell' type.
Definition: ensightCellsI.H:41
globalIndex.H
Foam::UPstream::nProcs
static label nProcs(const label communicator=0)
Number of processes in parallel run.
Definition: UPstream.H:427
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:415
Foam::cellShapeList
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:45
polyMesh.H
Foam::ensightOutput::Detail::getPolysNPointsPerFace
labelList getPolysNPointsPerFace(const polyMesh &mesh, const labelUList &addr)
The number of points for each face of the poly elements.
Definition: ensightOutput.C:102
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:48
ensightOutput.H
Foam::ensightCells::nTypes
static constexpr int nTypes
Number of 'Cell' element types (5)
Definition: ensightCells.H:74
Foam::cellList
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Foam::ensightCells
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:54
Foam::ensightCells::write
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Write geometry, using a mesh reference (serial only)
Definition: ensightCellsIO.C:256
Foam::ListListOps::inplaceRenumber
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Inplace renumber the values (not the indices) of a list of lists.
Definition: ensightOutput.H:88
Foam::UPstream::commsTypes::scheduled
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::primitiveMesh::cellShapes
const cellShapeList & cellShapes() const
Return cell shapes.
Definition: primitiveMesh.C:316
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:439
Foam::ensightCells::elemType
elemType
Supported ensight 'Cell' element types.
Definition: ensightCells.H:64
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:372
Foam::ensightOutput::Detail::getPolysNFaces
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
The number of faces per poly element.
Definition: ensightOutput.C:79
Foam::ensightCells::NFACED
"nfaced"
Definition: ensightCells.H:70
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::List< label >
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:109
Foam::ensightOutput::writePolysPoints
void writePolysPoints(ensightGeoFile &os, const cellUList &meshCells, const labelUList &addr, const faceUList &meshFaces, const labelUList &faceOwner)
Write the point ids per poly element.
Definition: ensightOutput.C:238
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
Foam::ensightOutput::writeCellShapes
void writeCellShapes(ensightGeoFile &os, const UList< cellShape > &shapes)
Write cell connectivity via cell shapes.
Definition: ensightOutput.C:173
Foam::ensightOutput::Detail::writeCoordinates
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.
Definition: ensightOutputTemplates.C:55
ensightCells.H