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-2024 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  for (Type val : field) // <-- working on a copy!
43  {
44  if (mag(val) < 1e-90) // approximately root(ROOTVSMALL)
45  {
46  val = Zero;
47  }
48 
50  {
51  const direction cmpt = ensightPTraits<Type>::componentOrder[d];
52 
53  os.write(component(val, cmpt));
54 
55  if (++count % 6 == 0)
56  {
57  os.newline();
58  }
59  }
60  }
61 
62  return count;
63 }
64 
65 
66 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
67 
68 template<class Type>
70 (
71  ensightFile& os,
72  const UList<Type>& field,
73  const globalIndex& procAddr
74 )
75 {
76  bool allEmpty(!procAddr.totalSize());
77  Pstream::broadcast(allEmpty);
78 
79  if (allEmpty)
80  {
81  return false; // All empty
82  }
83 
84 
85  if (UPstream::master())
86  {
87  // 6 values per line
88  label count = 0;
89 
90  // Write master data
92  (
93  os,
94  field,
95  count
96  );
97 
98  // Receive and write
99  DynamicList<Type> recvData(procAddr.maxNonLocalSize());
100 
101  for (const label proci : procAddr.subProcs())
102  {
103  const label procSize = procAddr.localSize(proci);
104 
105  if (procSize)
106  {
107  recvData.resize_nocopy(procSize);
108 
110  (
111  UPstream::commsTypes::scheduled,
112  proci,
113  recvData.data_bytes(),
114  recvData.size_bytes()
115  );
116 
118  (
119  os,
120  recvData,
121  count
122  );
123  }
124  }
125 
126  // Add final newline if required
127  if (count % 6)
128  {
129  os.newline();
130  }
131  }
132  else if (UPstream::is_subrank())
133  {
134  if (field.size())
135  {
137  (
138  UPstream::commsTypes::scheduled,
139  UPstream::masterNo(),
140  field.cdata_bytes(),
141  field.size_bytes()
142  );
143  }
144  }
146  return true;
147 }
148 
149 
150 template<class Type>
152 (
153  ensightFile& os,
154  const UList<Type>& field
155 )
156 {
158  (
159  os,
160  field,
161  // Gather sizes (offsets irrelevant)
163  );
164 }
165 
166 
167 template<class Type>
169 (
170  ensightFile& os,
171  const IOobject& fieldObject,
172  const bool existsAny
173 )
174 {
175  if (existsAny)
176  {
177  // When exists == true, it exists somewhere globally,
178  // but can still be missing on the local processor.
179  // Handle this by READ_IF_PRESENT instead.
180 
181  IOobject io(fieldObject);
182  io.readOpt(IOobject::READ_IF_PRESENT);
183  io.registerObject(IOobject::NO_REGISTER);
184 
185  IOField<Type> field(io);
186 
188  }
189 
190  return true;
191 }
192 
193 
194 // ************************************************************************* //
A variant of OFstream with specialised handling for Ensight writing of strings, integers and floats (...
Definition: ensightFile.H:47
rDeltaTY field()
uint8_t direction
Definition: direction.H:46
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Dispatch tag: Construct &#39;one-sided&#39; from local sizes, using gather but no broadcast.
Definition: globalIndex.H:118
::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.
bool writeCloudField(ensightFile &os, const UList< Type > &field, const globalIndex &procAddr)
Write cloud field, returning true if the field is non-empty.
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
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:61
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)
globalIndex procAddr(aMesh.nFaces())
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
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