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-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 "ensightOutputCloud.H"
29 #include "ensightPTraits.H"
30 
31 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const IOField<Type>& field,
37  ensightFile& os,
39 )
40 {
41  if (returnReduce(field.empty(), andOp<bool>()))
42  {
43  return false;
44  }
45 
46  if (Pstream::master())
47  {
48  // 6 values per line
49  label count = 0;
50 
51  // Master
52  for (Type val : field) // <-- working on a copy
53  {
54  if (mag(val) < 1e-90) // approximately root(ROOTVSMALL)
55  {
56  val = Zero;
57  }
58 
59  for (direction d=0; d < pTraits<Type>::nComponents; ++d)
60  {
61  const direction cmpt =
63 
64  os.write(component(val, cmpt));
65 
66  if (++count % 6 == 0)
67  {
68  os.newline();
69  }
70  }
71  }
72 
73  // Slaves
74  for (const int slave : Pstream::subProcs())
75  {
76  IPstream fromSlave(comm, slave);
77  Field<Type> recv(fromSlave);
78 
79  for (Type val : recv) // <-- working on a copy
80  {
81  if (mag(val) < 1e-90) // approximately root(ROOTVSMALL)
82  {
83  val = Zero;
84  }
85 
86  for (direction d=0; d < pTraits<Type>::nComponents; ++d)
87  {
88  const direction cmpt =
90 
91  os.write(component(val, cmpt));
92 
93  if (++count % 6 == 0)
94  {
95  os.newline();
96  }
97  }
98  }
99  }
100 
101  // Add final newline if required
102  if (count % 6)
103  {
104  os.newline();
105  }
106  }
107  else
108  {
109  OPstream toMaster(comm, Pstream::masterNo());
110  toMaster << field;
111  }
112 
113  return true;
114 }
115 
116 
117 template<class Type>
119 (
120  const IOobject& io,
121  const bool exists,
124 )
125 {
126  if (exists)
127  {
128  // When exists == true, it exists globally,
129  // but can still be missing on the local processor.
130  // Handle this by READ_IF_PRESENT instead.
131 
132  IOobject fieldObj(io);
133  fieldObj.readOpt() = IOobject::READ_IF_PRESENT;
134 
135  IOField<Type> field(fieldObj);
136 
137  writeCloudField(field, output.ref(), comm);
138  }
139 
140  return true;
141 }
142 
143 
144 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
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::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::ensightPTraits
Conversion of OpenFOAM pTraits into the Ensight equivalent.
Definition: ensightPTraits.H:54
Foam::Field
Generic templated field type.
Definition: Field.H:63
ensightPTraits.H
Foam::ensightFile::newline
void newline()
Add carriage return to ascii stream.
Definition: ensightFile.C:304
Foam::andOp
Definition: ops.H:233
field
rDeltaTY field()
Foam::ensightFile::write
virtual bool write(const token &)
Writing token does not make sense.
Definition: ensightFile.H:176
Foam::ensightFile
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:52
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::IOobject::readOpt
readOption readOpt() const
The read option.
Definition: IOobjectI.H:165
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
Foam::ensightOutput::writeCloudField
bool writeCloudField(const IOField< Type > &field, ensightFile &os, Pstream::commsTypes comm=Pstream::commsTypes::blocking)
Write cloud field, returning true if the field is non-empty.
Definition: ensightOutputCloudTemplates.C:35