ensightOutputTemplates.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) 2019 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 "ensightOutput.H"
29 #include "ensightPTraits.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<template<typename> class FieldContainer, class Type>
35 (
36  const char* key,
37  const FieldContainer<Type>& fld,
38  ensightFile& os,
39  bool parallel
40 )
41 {
42  // Preliminary checks
43  // ~~~~~~~~~~~~~~~~~~
44 
45  parallel = parallel && Pstream::parRun();
46 
47  bool hasField = !fld.empty();
48 
49  if (parallel)
50  {
51  reduce(hasField, orOp<bool>());
52  }
53 
54  // Nothing to write
55  if (!hasField) return false;
56 
57  // End preliminary checks
58  // ~~~~~~~~~~~~~~~~~~~~~~
59 
60 
61  if (Pstream::master())
62  {
63  os.writeKeyword(key);
64 
65  if (!parallel)
66  {
67  // Serial output
68  for (direction d=0; d < pTraits<Type>::nComponents; ++d)
69  {
71 
72  os.writeList(fld.component(cmpt));
73  }
74  }
75  else
76  {
77  // Parallel (master)
78 
79  for (direction d=0; d < pTraits<Type>::nComponents; ++d)
80  {
82 
83  os.writeList(fld.component(cmpt));
84 
85  for (int slave=1; slave<Pstream::nProcs(); ++slave)
86  {
87  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
88  scalarField received(fromSlave);
89  os.writeList(received);
90  }
91  }
92  }
93  }
94  else if (parallel)
95  {
96  // Parallel (slaves)
97 
98  for (direction d=0; d < pTraits<Type>::nComponents; ++d)
99  {
101 
102  OPstream toMaster
103  (
104  Pstream::commsTypes::scheduled,
105  Pstream::masterNo()
106  );
107 
108  toMaster
109  << fld.component(cmpt);
110  }
111  }
112 
113  return true;
114 }
115 
116 
117 template<class Type>
119 (
120  const Field<Type>& fld,
121  const ensightFaces& part,
122  ensightFile& os,
123  bool parallel
124 )
125 {
126  // Preliminary checks
127  // ~~~~~~~~~~~~~~~~~~
128 
129  parallel = parallel && Pstream::parRun();
130 
131  bool hasGeom = (parallel ? part.total() : part.size());
132  bool hasField = !fld.empty();
133 
134  if (parallel)
135  {
136  // Used 'pre-reduced' information for hasGeom
137  reduce(hasField, orOp<bool>());
138  }
139 
140  // Nothing to write
141  if (!hasGeom || !hasField) return false;
142 
143  // End preliminary checks
144  // ~~~~~~~~~~~~~~~~~~~~~~
145 
146 
147  if (Pstream::master())
148  {
149  os.beginPart(part.index());
150  }
151 
152  for (int typei=0; typei < ensightFaces::nTypes; ++typei)
153  {
155 
157  (
158  ensightFaces::key(what),
159  Field<Type>(fld, part.faceIds(what)),
160  os,
161  parallel
162  );
163  }
164 
165  return true;
166 }
167 
168 
169 template<class Type>
171 (
172  const Field<Type>& fld,
173  const ensightFaces& part,
174  ensightFile& os,
175  bool parallel
176 )
177 {
178  // Preliminary checks
179  // ~~~~~~~~~~~~~~~~~~
180 
181  parallel = parallel && Pstream::parRun();
182 
183  bool hasGeom = (parallel ? part.total() : part.size());
184  bool hasField = !fld.empty();
185 
186  if (parallel)
187  {
188  // Used 'pre-reduced' information for hasGeom
189  reduce(hasField, orOp<bool>());
190  }
191 
192  // Nothing to write
193  if (!hasGeom || !hasField) return false;
194 
195  // End preliminary checks
196  // ~~~~~~~~~~~~~~~~~~~~~~
197 
198 
199  if (Pstream::master())
200  {
201  os.beginPart(part.index());
202  }
203 
204 
205  label start = 0; // The start of the sub-list
206  for (int typei=0; typei < ensightFaces::nTypes; ++typei)
207  {
209 
210  const label size = part.faceIds(what).size();
211 
213  (
214  ensightFaces::key(what),
215  SubField<Type>(fld, size, start),
216  os,
217  parallel
218  );
219 
220  start += size; // Advance the start for next sub-list
221  }
222 
223  return true;
224 }
225 
226 
227 template<class Type>
229 (
230  const Field<Type>& fld,
231  const ensightFaces& part,
232  ensightFile& os
233 )
234 {
235  // Preliminary checks
236  // ~~~~~~~~~~~~~~~~~~
237 
238  bool parallel = false && Pstream::parRun();
239 
240  bool hasGeom = (parallel ? part.total() : part.size());
241  bool hasField = !fld.empty();
242 
243  if (parallel)
244  {
245  // Used 'pre-reduced' information for hasGeom
246  reduce(hasField, orOp<bool>());
247  }
248 
249  // Nothing to write
250  if (!hasGeom || !hasField) return false;
251 
252  // End preliminary checks
253  // ~~~~~~~~~~~~~~~~~~~~~~
254 
255 
256  if (Pstream::master())
257  {
258  os.beginPart(part.index());
259  }
260 
262  (
263  "coordinates",
264  fld,
265  os,
266  parallel
267  );
268 
269  return true;
270 }
271 
272 
273 template<class Type>
275 (
276  const Field<Type>& fld,
277  const ensightCells& part,
278  ensightFile& os,
279  bool parallel
280 )
281 {
282  // Preliminary checks
283  // ~~~~~~~~~~~~~~~~~~
284 
285  parallel = parallel && Pstream::parRun();
286 
287  bool hasGeom = (parallel ? part.total() : part.size());
288  bool hasField = !fld.empty();
289 
290  if (parallel)
291  {
292  // Used 'pre-reduced' information for hasGeom
293  reduce(hasField, orOp<bool>());
294  }
295 
296  // Nothing to write
297  if (!hasGeom || !hasField) return false;
298 
299  // End preliminary checks
300  // ~~~~~~~~~~~~~~~~~~~~~~
301 
302 
303  if (Pstream::master())
304  {
305  os.beginPart(part.index());
306  }
307 
308  for (int typei=0; typei < ensightCells::nTypes; ++typei)
309  {
311 
313  (
314  ensightCells::key(what),
315  Field<Type>(fld, part.cellIds(what)),
316  os,
317  parallel
318  );
319  }
320 
321  return true;
322 }
323 
324 
325 // ************************************************************************* //
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::ensightCells::index
label index() const
The index in a list.
Definition: ensightCellsI.H:38
Foam::ensightOutput::Detail::writeFieldComponents
bool writeFieldComponents(const char *key, const FieldContainer< Type > &fld, ensightFile &os, bool parallel)
Write field content (component-wise) for the given ensight element type.
Definition: ensightOutputTemplates.C:35
Foam::ensightFaces
Sorting/classification of faces (2D) into corresponding ensight types.
Definition: ensightFaces.H:51
Foam::ensightCells::cellIds
const labelUList cellIds(const enum elemType) const
Return the (local) cell ids of the specified element type.
Definition: ensightCellsI.H:81
Foam::ensightOutput::Detail::writeCellField
bool writeCellField(const Field< Type > &fld, const ensightCells &part, ensightFile &os, bool parallel)
Definition: ensightOutputTemplates.C:275
Foam::ensightFile::writeKeyword
virtual Ostream & writeKeyword(const keyType &key)
Write element keyword with trailing newline, optionally with undef.
Definition: ensightFile.C:285
Foam::ensightFaces::total
label total() const
The global number of all element types.
Definition: ensightFaces.C:162
Foam::SubField
SubField is a Field obtained as a section of another Field.
Definition: Field.H:64
Foam::ensightPTraits
Conversion of OpenFOAM pTraits into the Ensight equivalent.
Definition: ensightPTraits.H:54
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
ensightOutput.H
Foam::Field< scalar >
Foam::ensightOutput::Serial::writePointField
bool writePointField(const Field< Type > &fld, const ensightFaces &part, ensightFile &os)
Write a field of point (node) values (already compacted?)
Definition: ensightOutputTemplates.C:229
ensightPTraits.H
Foam::ensightCells
Sorting/classification of cells (3D) into corresponding ensight element types.
Definition: ensightCells.H:53
Foam::ensightFaces::faceIds
const labelUList faceIds(const enum elemType) const
Return the (local) face ids of the specified element type.
Definition: ensightFacesI.H:81
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::ensightFile
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:54
Foam::ensightFaces::size
label size() const
The processor local size of all elements.
Definition: ensightFacesI.H:50
Foam::ensightCells::elemType
elemType
Addressable ensight element types.
Definition: ensightCells.H:60
Foam::ensightFaces::elemType
elemType
Addressable ensight element types.
Definition: ensightFaces.H:58
Foam::ensightFaces::index
label index() const
The index in a list.
Definition: ensightFacesI.H:38
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::ensightFile::beginPart
void beginPart(const label index)
Begin a part (0-based index internally).
Definition: ensightFile.C:319
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
Foam::ensightOutput::Detail::writeFaceField
bool writeFaceField(const Field< Type > &fld, const ensightFaces &part, ensightFile &os, bool parallel)
Definition: ensightOutputTemplates.C:119
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
Foam::ensightFile::writeList
void writeList(const UList< label > &field)
Write a list of integers as float values.
Definition: ensightFile.C:337
Foam::ensightCells::size
label size() const
The processor local size of all elements.
Definition: ensightCellsI.H:50
Foam::orOp
Definition: ops.H:234
Foam::ensightCells::total
label total(const enum elemType) const
The global number of the specified element type.
Definition: ensightCellsI.H:62
Foam::ensightOutput::Detail::writeFaceSubField
bool writeFaceSubField(const Field< Type > &fld, const ensightFaces &part, ensightFile &os, bool parallel)
Definition: ensightOutputTemplates.C:171