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  const label nTotal = part.total(etype);
48  const labelUList& addr = part.cellIds(etype);
49 
50  if (!nTotal)
51  {
52  return;
53  }
54 
55  const IntRange<int> senders =
56  (
57  parallel
59  : IntRange<int>()
60  );
61 
62 
63  if (Pstream::master())
64  {
65  os.writeKeyword(ensightCells::key(etype));
66  os.write(nTotal);
67  os.newline();
68  }
69 
70  // Number of faces per polyhedral (1/line in ASCII)
71  {
72  labelList send
73  (
75  );
76 
77  if (Pstream::master())
78  {
79  // Main
80  os.writeLabels(send);
81 
82  // Others
83  for (const int proci : senders)
84  {
85  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
86  labelList recv(fromOther);
87 
88  os.writeLabels(recv);
89  }
90  }
91  else if (senders)
92  {
93  OPstream toMaster
94  (
97  );
98 
99  toMaster << send;
100  }
101  }
102 
103 
104  // Number of points for each polyhedral face (1/line in ASCII)
105  {
106  labelList send
107  (
109  );
110 
111  if (Pstream::master())
112  {
113  // Main
114  os.writeLabels(send);
115 
116  // Others
117  for (const int proci : senders)
118  {
119  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
120  labelList recv(fromOther);
121 
122  os.writeLabels(recv);
123  }
124  }
125  else if (senders)
126  {
127  OPstream toMaster
128  (
131  );
132 
133  toMaster << send;
134  }
135  }
136 
137 
138  // List of points id for each face of the above list
139  if (Pstream::master())
140  {
141  // Main
143  (
144  os,
145  mesh,
146  addr,
147  pointToGlobal
148  );
149 
150  // Others
151  for (const int proci : senders)
152  {
153  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
154  cellList cells(fromOther);
155  labelList addr(fromOther);
156  faceList faces(fromOther);
157  labelList owner(fromOther);
158 
160  (
161  os,
162  cells,
163  addr,
164  faces,
165  owner
166  );
167  }
168  }
169  else if (senders)
170  {
171  // Renumber faces to use global point numbers
172  faceList faces(mesh.faces());
173  ListListOps::inplaceRenumber(pointToGlobal, faces);
174 
175  OPstream toMaster
176  (
179  );
180 
181  toMaster
182  << mesh.cells()
183  << addr
184  << faces
185  << mesh.faceOwner();
186  }
187 }
188 
189 
190 void Foam::ensightCells::writeShapeConnectivity
191 (
192  ensightGeoFile& os,
193  const polyMesh& mesh,
194  const ensightCells::elemType etype,
195  const ensightCells& part,
196  const labelList& pointToGlobal,
197  const bool parallel
198 )
199 {
200  if (etype == ensightCells::NFACED)
201  {
203  << "Called for ensight NFACED cell. Programming error\n"
204  << exit(FatalError);
205  }
206 
207  const label nTotal = part.total(etype);
208  const labelUList& addr = part.cellIds(etype);
209 
210  if (!nTotal)
211  {
212  return;
213  }
214 
215 
216  const IntRange<int> senders =
217  (
218  parallel
220  : IntRange<int>()
221  );
222 
223 
224  if (Pstream::master())
225  {
227  os.write(nTotal);
228  os.newline();
229  }
230 
231 
232  // Primitive shape - get subset and renumber
233  cellShapeList shapes(mesh.cellShapes(), addr);
234 
235  ListListOps::inplaceRenumber(pointToGlobal, shapes);
236 
237  if (Pstream::master())
238  {
240 
241  for (const int proci : senders)
242  {
243  IPstream fromOther(Pstream::commsTypes::scheduled, proci);
244  cellShapeList recv(fromOther);
245 
247  }
248  }
249  else if (senders)
250  {
251  OPstream toMaster
252  (
255  );
256 
257  toMaster << shapes;
258  }
259 }
260 
261 
263 (
265  const polyMesh& mesh,
266  bool parallel
267 ) const
268 {
269  const ensightCells& part = *this;
270 
271  parallel = parallel && Pstream::parRun();
272 
273  // Renumber the points/faces into unique points
274 
275  label nPoints = 0; // Total number of points
276  labelList pointToGlobal; // local point to unique global index
277  labelList uniqueMeshPointLabels; // unique global points
278 
279  nPoints = meshPointMapppings
280  (
281  mesh,
282  pointToGlobal,
283  uniqueMeshPointLabels,
284  parallel
285  );
286 
288  (
289  os,
290  part.index(),
291  part.name(),
292  nPoints, // nPoints (global)
293  UIndirectList<point>(mesh.points(), uniqueMeshPointLabels),
294  parallel
295  );
296 
297 
298  for (label typei=0; typei < ensightCells::nTypes; ++typei)
299  {
300  const auto etype = ensightCells::elemType(typei);
301 
302  if (etype == ensightCells::NFACED)
303  {
304  writePolysConnectivity
305  (
306  os,
307  mesh,
308  part,
309  pointToGlobal,
310  parallel
311  );
312  }
313  else
314  {
315  writeShapeConnectivity
316  (
317  os,
318  mesh,
319  etype,
320  part,
321  pointToGlobal,
322  parallel
323  );
324  }
325  }
326 }
327 
328 
329 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::UPstream::masterNo
static constexpr int masterNo() noexcept
Process index of the master (always 0)
Definition: UPstream.H:451
Foam::ensightPart::index
label index() const noexcept
The index in a list (0-based)
Definition: ensightPart.H:124
globalMeshData.H
Foam::ensightCells::key
static const char * key(const elemType etype)
The ensight element name for the specified 'Cell' type.
Definition: ensightCellsI.H:43
globalIndex.H
Foam::cellShapeList
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:45
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
polyMesh.H
Foam::OBJstream::write
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
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
Foam::UPstream::subProcs
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
Definition: UPstream.H:515
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:263
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:89
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::ensightPart::name
const string & name() const noexcept
The part name or description.
Definition: ensightPart.H:160
Foam::Ostream::writeKeyword
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:57
Foam::primitiveMesh::cellShapes
const cellShapeList & cellShapes() const
Return cell shapes.
Definition: primitiveMesh.C:353
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
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:453
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::UPstream::commsTypes::scheduled
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::List< label >
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:60
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:85
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:136
ensightCells.H