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-------------------------------------------------------------------------------
10License
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
34template<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
69template<class Type>
71(
72 const IOField<Type>& field,
74)
75{
76 if (returnReduce(field.empty(), andOp<bool>()))
77 {
78 return false;
79 }
80
81 // Gather sizes (offsets irrelevant)
83
84 if (Pstream::master())
85 {
86 // 6 values per line
87 label count = 0;
88
89 // Write master data
90 count = ensightOutput::Detail::writeCloudFieldContent
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 recvData.resize_nocopy(procAddr.localSize(proci));
103 UIPstream::read
104 (
105 UPstream::commsTypes::scheduled,
106 proci,
107 recvData.data_bytes(),
108 recvData.size_bytes()
109 );
110
111 count = ensightOutput::Detail::writeCloudFieldContent
112 (
113 os,
114 recvData,
115 count
116 );
117 }
118
119 // Add final newline if required
120 if (count % 6)
121 {
122 os.newline();
123 }
124 }
125 else
126 {
127 // Send
128 UOPstream::write
129 (
130 UPstream::commsTypes::scheduled,
131 UPstream::masterNo(),
132 field.cdata_bytes(),
133 field.size_bytes()
134 );
135 }
136
137 return true;
138}
139
140
141template<class Type>
143(
144 const IOobject& io,
145 const bool exists,
147)
148{
149 if (exists)
150 {
151 // When exists == true, it exists globally,
152 // but can still be missing on the local processor.
153 // Handle this by READ_IF_PRESENT instead.
154
155 IOobject fieldObj(io);
156 fieldObj.readOpt(IOobject::READ_IF_PRESENT);
157
158 IOField<Type> field(fieldObj);
159
160 writeCloudField(field, output.ref());
161 }
162
163 return true;
164}
165
166
167// ************************************************************************* //
globalIndex procAddr(aMesh.nFaces())
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void resize_nocopy(const label len)
Definition: DynamicListI.H:363
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:251
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
Definition: UListI.H:258
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
T & ref()
Return reference to the managed object without nullptr checking.
Definition: autoPtr.H:161
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:55
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
rDeltaTY field()
A collection of functions for writing clouds as ensight file content.
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:78
label writeCloudFieldContent(ensightFile &os, const UList< Type > &fld, label count=0)
Write cloud field data (serial) with rounding and newlines.
bool writeCloudField(const IOField< Type > &field, ensightFile &os)
Write cloud field, returning true if the field is non-empty.
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:633
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
uint8_t direction
Definition: direction.H:56
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
volScalarField & e
Definition: createFields.H:11