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-2022 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 
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  ensightFile& os,
73  const IOField<Type>& field
74 )
75 {
76  if (returnReduceAnd(field.empty()))
77  {
78  return false;
79  }
80 
81  // Gather sizes (offsets irrelevant)
82  const globalIndex procAddr(globalIndex::gatherOnly{}, field.size());
83 
84  if (Pstream::master())
85  {
86  // 6 values per line
87  label count = 0;
88 
89  // Write master data
91  (
92  os,
93  field,
94  count
95  );
96 
97  // Receive and write
98  DynamicList<Type> recvData(procAddr.maxNonLocalSize());
99 
100  for (const label proci : procAddr.subProcs())
101  {
102  const label procSize = procAddr.localSize(proci);
103 
104  if (procSize)
105  {
106  recvData.resize_nocopy(procSize);
107 
109  (
110  UPstream::commsTypes::scheduled,
111  proci,
112  recvData.data_bytes(),
113  recvData.size_bytes()
114  );
115 
117  (
118  os,
119  recvData,
120  count
121  );
122  }
123  }
124 
125  // Add final newline if required
126  if (count % 6)
127  {
128  os.newline();
129  }
130  }
131  else
132  {
133  if (field.size())
134  {
136  (
137  UPstream::commsTypes::scheduled,
138  UPstream::masterNo(),
139  field.cdata_bytes(),
140  field.size_bytes()
141  );
142  }
143  }
145  return true;
146 }
147 
148 
149 template<class Type>
151 (
152  ensightFile& os,
153  const IOobject& fieldObject,
154  const bool existsAny
155 )
156 {
157  if (existsAny)
158  {
159  // When exists == true, it exists somewhere globally,
160  // but can still be missing on the local processor.
161  // Handle this by READ_IF_PRESENT instead.
162 
163  IOobject io(fieldObject);
164  io.readOpt(IOobject::READ_IF_PRESENT);
165 
167 
169  }
170 
171  return true;
172 }
173 
174 
175 // ************************************************************************* //
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:46
rDeltaTY field()
uint8_t direction
Definition: direction.H:46
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
A collection of functions for writing clouds as ensight file content.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
bool readWriteCloudField(ensightFile &os, const IOobject &fieldObject, bool existsAny)
Read cloud field from IOobject (if exists == true) and write, always returning true.
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
OBJstream os(runTime.globalPath()/outputName)
bool writeCloudField(ensightFile &os, const IOField< Type > &field)
Write cloud field, returning true if the field is non-empty.
globalIndex procAddr(aMesh.nFaces())
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
A primitive field of type <T> with automated input and output.
label writeCloudFieldContent(ensightFile &os, const UList< Type > &fld, label count=0)
Write cloud field data (serial) with rounding and newlines.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127