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 (
264  ensightGeoFile& os,
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:63
Foam::polyMesh::points
virtual const pointField & points() const
Definition: polyMesh.C:1062
Foam::UPstream::masterNo
static constexpr int masterNo() noexcept
Definition: UPstream.H:447
Foam::ensightPart::index
label index() const noexcept
Definition: ensightPart.H:120
Foam::OFstream::name
virtual const fileName & name() const
Definition: OSstream.H:103
globalMeshData.H
Foam::ensightCells::key
static const char * key(const elemType etype)
Definition: ensightCellsI.H:36
globalIndex.H
Foam::cellShapeList
List< cellShape > cellShapeList
List of cellShapes and PtrList of List of cellShape.
Definition: cellShapeList.H:39
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Definition: UPstream.H:453
polyMesh.H
Foam::OBJstream::write
virtual Ostream & write(const char c)
Definition: OBJstream.C:71
Foam::ensightOutput::Detail::getPolysNPointsPerFace
labelList getPolysNPointsPerFace(const polyMesh &mesh, const labelUList &addr)
Definition: ensightOutput.C:95
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::ensightGeoFile
Specialized Ensight output with extra geometry file header.
Definition: ensightGeoFile.H:42
Foam::UPstream::subProcs
static rangeType subProcs(const label communicator=worldComm)
Definition: UPstream.H:511
ensightOutput.H
Foam::ensightCells::nTypes
static constexpr int nTypes
Definition: ensightCells.H:68
Foam::cellList
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:41
Foam::ensightCells
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:48
Foam::ensightCells::write
virtual void write(ensightGeoFile &os, const polyMesh &mesh, bool parallel) const
Definition: ensightCellsIO.C:256
Foam::ListListOps::inplaceRenumber
void inplaceRenumber(const labelUList &oldToNew, IntListType &lists)
Definition: ensightOutput.H:90
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
Definition: ensightPart.H:156
Foam::Ostream::writeKeyword
virtual Ostream & writeKeyword(const keyType &kw)
Definition: Ostream.C:50
Foam::primitiveMesh::cellShapes
const cellShapeList & cellShapes() const
Definition: primitiveMesh.C:346
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
Foam::ensightCells::elemType
elemType
Definition: ensightCells.H:58
FatalErrorInFunction
#define FatalErrorInFunction
Definition: error.H:465
Foam::ensightOutput::Detail::getPolysNFaces
labelList getPolysNFaces(const polyMesh &mesh, const labelUList &addr)
Definition: ensightOutput.C:72
Foam::ensightCells::NFACED
@ NFACED
"nfaced"
Definition: ensightCells.H:64
Foam::UPstream::commsTypes::scheduled
@ scheduled
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:41
Foam::UPstream::parRun
static bool & parRun() noexcept
Definition: UPstream.H:429
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
Foam::UIndirectList
A List with indirect addressing.
Definition: faMatrix.H:56
Foam::ensightOutput::writePolysPoints
void writePolysPoints(ensightGeoFile &os, const cellUList &meshCells, const labelUList &addr, const faceUList &meshFaces, const labelUList &faceOwner)
Definition: ensightOutput.C:231
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:81
Foam::ensightOutput::writeCellShapes
void writeCellShapes(ensightGeoFile &os, const UList< cellShape > &shapes)
Definition: ensightOutput.C:166
Foam::ensightOutput::Detail::writeCoordinates
bool writeCoordinates(ensightGeoFile &os, const label partId, const word &partName, const label nPoints, const FieldContainer< Foam::point > &fld, bool parallel)
Definition: ensightOutputTemplates.C:129
ensightCells.H