ensightOutputCloudTemplates.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) 2016-2021 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 "ensightOutputCloud.H"
29 #include "ensightPTraits.H"
30 #include "globalIndex.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 template<class Type>
36 (
37  ensightFile& os,
38  const UList<Type>& field,
39  label count
40 )
41 {
42  // Write master data
43  for (Type val : field) // <-- working on a copy!
44  {
45  if (mag(val) < 1e-90) // approximately root(ROOTVSMALL)
46  {
47  val = Zero;
48  }
49 
50  for (direction d=0; d < pTraits<Type>::nComponents; ++d)
51  {
52  const direction cmpt = ensightPTraits<Type>::componentOrder[d];
53 
54  os.write(component(val, cmpt));
55 
56  if (++count % 6 == 0)
57  {
58  os.newline();
59  }
60  }
61  }
62 
63  return count;
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
68 
69 template<class Type>
71 (
72  const IOField<Type>& field,
74 )
75 {
76  if (returnReduce(field.empty(), andOp<bool>()))
77  {
78  return false;
79  }
80 
81  // Size information (offsets are irrelevant)
82  globalIndex procAddr;
83  if (Pstream::parRun())
84  {
85  procAddr.reset(UPstream::listGatherValues<label>(field.size()));
86  }
87  else
88  {
89  procAddr.reset(labelList(Foam::one{}, field.size()));
90  }
91 
92 
93  if (Pstream::master())
94  {
95  // 6 values per line
96  label count = 0;
97 
98  // Write master data
100  (
101  os,
102  field,
103  count
104  );
105 
106  // Receive and write
107  DynamicList<Type> recvData(procAddr.maxNonLocalSize());
108 
109  for (const label proci : procAddr.subProcs())
110  {
111  recvData.resize_nocopy(procAddr.localSize(proci));
113  (
114  UPstream::commsTypes::scheduled,
115  proci,
116  recvData.data_bytes(),
117  recvData.size_bytes()
118  );
119 
121  (
122  os,
123  recvData,
124  count
125  );
126  }
127 
128  // Add final newline if required
129  if (count % 6)
130  {
131  os.newline();
132  }
133  }
134  else
135  {
136  // Send
138  (
139  UPstream::commsTypes::scheduled,
140  Pstream::masterNo(),
141  field.cdata_bytes(),
142  field.size_bytes()
143  );
144  }
145 
146  return true;
147 }
148 
149 
150 template<class Type>
152 (
153  const IOobject& io,
154  const bool exists,
156 )
157 {
158  if (exists)
159  {
160  // When exists == true, it exists globally,
161  // but can still be missing on the local processor.
162  // Handle this by READ_IF_PRESENT instead.
163 
164  IOobject fieldObj(io);
165  fieldObj.readOpt(IOobject::READ_IF_PRESENT);
166 
167  IOField<Type> field(fieldObj);
168 
169  writeCloudField(field, output.ref());
170  }
171 
172  return true;
173 }
174 
175 
176 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::component
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Definition: FieldFieldFunctions.C:44
Foam::exists
bool exists(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist (as DIRECTORY or FILE) in the file system?
Definition: MSwindows.C:625
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::DynamicList< Type >
globalIndex.H
Foam::one
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:61
Foam::globalIndex::localSize
label localSize() const
My local size.
Definition: globalIndexI.H:187
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
ensightPTraits.H
Foam::andOp
Definition: ops.H:233
field
rDeltaTY field()
Foam::ensightOutput::writeCloudField
bool writeCloudField(const IOField< Type > &field, ensightFile &os)
Write cloud field, returning true if the field is non-empty.
Definition: ensightOutputCloudTemplates.C:71
os
OBJstream os(runTime.globalPath()/outputName)
Foam::ensightFile
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:52
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::globalIndex::reset
void reset(const label localSize)
Reset from local size.
Definition: globalIndexI.H:157
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
Foam::globalIndex::subProcs
labelRange subProcs() const noexcept
Range of process indices for addressed sub-offsets (processes)
Definition: globalIndexI.H:121
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::globalIndex::maxNonLocalSize
label maxNonLocalSize() const
The max of localSizes, excluding current processor.
Definition: globalIndexI.H:200
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::direction
uint8_t direction
Definition: direction.H:52
ensightOutputCloud.H
A collection of functions for writing clouds as ensight file content.
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::DynamicList::resize_nocopy
void resize_nocopy(const label len)
Definition: DynamicListI.H:363
Foam::ensightOutput::Detail::writeCloudFieldContent
label writeCloudFieldContent(ensightFile &os, const UList< Type > &fld, label count=0)
Write cloud field data (serial) with rounding and newlines.