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-2025 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
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 if (UPstream::is_subrank())
132  {
133  if (field.size())
134  {
136  (
137  UPstream::commsTypes::scheduled,
138  UPstream::masterNo(),
139  field
140  );
141  }
142  }
144  return true;
145 }
146 
147 
148 template<class Type>
150 (
151  ensightFile& os,
152  const UList<Type>& field
153 )
154 {
156  (
157  os,
158  field,
159  // Gather sizes (offsets irrelevant)
161  );
162 }
163 
164 
165 template<class Type>
167 (
168  ensightFile& os,
169  const IOobject& fieldObject,
170  const bool existsAny
171 )
172 {
173  if (existsAny)
174  {
175  // When exists == true, it exists somewhere globally,
176  // but can still be missing on the local processor.
177  // Handle this by READ_IF_PRESENT instead.
178 
179  IOobject io(fieldObject);
180  io.readOpt(IOobject::READ_IF_PRESENT);
181  io.registerObject(IOobject::NO_REGISTER);
182 
183  IOField<Type> field(io);
184 
186  }
187 
188  return true;
189 }
190 
191 
192 // ************************************************************************* //
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:117
bool broadcast(Type *values, int count, MPI_Datatype datatype, const int communicator)
::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