OpenFOAM: API Guide
v2012
The open source CFD toolbox
ensightOutputCloud.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 "
fvMesh.H
"
30
#include "
Cloud.H
"
31
#include "
passiveParticle.H
"
32
#include "
pointField.H
"
33
34
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
35
36
namespace
Foam
37
{
38
//- Binary output
39
static
inline
void
writeMeasured
40
(
41
ensightFile
& os,
42
const
pointField
&
points
43
)
44
{
45
for
(
const
point
&
p
:
points
)
46
{
47
os.
write
(
p
.x());
48
os.
write
(
p
.y());
49
os.
write
(
p
.z());
50
}
51
}
52
53
//- ASCII output. Id + position together
54
static
inline
label
writeMeasured
55
(
56
ensightFile
& os,
57
label pointId,
58
const
pointField
&
points
59
)
60
{
61
for
(
const
point
&
p
:
points
)
62
{
63
os.
write
(++pointId, 8);
// 1-index and an unusual width
64
os.
write
(
p
.x());
65
os.
write
(
p
.y());
66
os.
write
(
p
.z());
67
os.
newline
();
68
}
69
70
return
pointId;
71
}
72
73
}
// End namespace Foam
74
75
76
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
77
78
bool
Foam::ensightOutput::writeCloudPositions
79
(
80
const
fvMesh
&
mesh
,
81
const
word
&
cloudName
,
82
bool
exists
,
83
autoPtr<ensightFile>
&
output
,
84
Pstream::commsTypes
comm
85
)
86
{
87
pointField
positions;
88
89
if
(
exists
)
90
{
91
Cloud<passiveParticle>
parcels(
mesh
,
cloudName
,
false
);
92
93
positions.resize(parcels.size());
94
95
auto
outIter = positions.begin();
96
97
for
(
const
passiveParticle
&
p
: parcels)
98
{
99
*outIter =
p
.position();
100
++outIter;
101
}
102
}
103
104
105
// Total number of parcels on all processes
106
const
label nTotParcels =
returnReduce
(positions.size(),
sumOp<label>
());
107
108
// Update the exists/not exists information (for return value)
109
exists
= nTotParcels;
110
111
if
(Pstream::master())
112
{
113
ensightFile
& os =
output
();
114
115
os.
beginParticleCoordinates
(nTotParcels);
116
if
(!
exists
)
117
{
118
return
exists
;
// DONE
119
}
120
121
if
(os.
format
() == IOstream::BINARY)
122
{
123
// binary write is Ensight6 - first ids, then positions
124
125
// 1-index
126
for
(label parcelId = 1; parcelId <= nTotParcels; ++parcelId)
127
{
128
os.
write
(parcelId);
129
}
130
131
// Master
132
writeMeasured
(os, positions);
133
134
// Slaves
135
for
(
const
int
slave : Pstream::subProcs())
136
{
137
IPstream
fromSlave(comm, slave);
138
pointField
recv(fromSlave);
139
140
writeMeasured
(os, recv);
141
}
142
}
143
else
144
{
145
// ASCII id + position together
146
label parcelId = 0;
147
148
// Master
149
parcelId =
writeMeasured
(os, parcelId, positions);
150
151
// Slaves
152
for
(
const
int
slave : Pstream::subProcs())
153
{
154
IPstream
fromSlave(comm, slave);
155
pointField
recv(fromSlave);
156
157
parcelId =
writeMeasured
(os, parcelId, recv);
158
}
159
}
160
}
161
else
if
(nTotParcels)
162
{
163
// SLAVE, and data exist
164
OPstream
toMaster(comm, Pstream::masterNo());
165
166
toMaster
167
<< positions;
168
}
169
170
return
exists
;
171
}
172
173
174
// ************************************************************************* //
p
volScalarField & p
Definition:
createFieldRefs.H:8
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
cloudName
const word cloudName(propsDict.get< word >("cloud"))
Foam::word
A class for handling words, derived from Foam::string.
Definition:
word.H:62
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::OPstream
Output inter-processor communications stream.
Definition:
OPstream.H:52
Foam::passiveParticle
Copy of base particle.
Definition:
passiveParticle.H:53
Cloud.H
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition:
IOstreamOption.H:289
Foam::ensightOutput::writeCloudPositions
bool writeCloudPositions(const fvMesh &mesh, const word &cloudName, bool exists, autoPtr< ensightFile > &output, Pstream::commsTypes comm=Pstream::commsTypes::blocking)
Write cloud positions.
Definition:
ensightOutputCloud.C:79
Foam::writeMeasured
static label writeMeasured(ensightFile &os, label pointId, const pointField &points)
ASCII output. Id + position together.
Definition:
ensightOutputCloud.C:55
Foam::sumOp
Definition:
ops.H:213
Foam::ensightFile::beginParticleCoordinates
void beginParticleCoordinates(const label nparticles)
Begin a "particle coordinates" block (measured data)
Definition:
ensightFile.C:363
Foam::Field< vector >
passiveParticle.H
Foam::ensightFile::newline
void newline()
Add carriage return to ascii stream.
Definition:
ensightFile.C:304
Foam::ensightFile::write
virtual bool write(const token &)
Writing token does not make sense.
Definition:
ensightFile.H:176
mesh
dynamicFvMesh & mesh
Definition:
createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition:
fvMesh.H:83
fvMesh.H
Foam::ensightFile
Ensight output with specialized write() for strings, integers and floats. Correctly handles binary wr...
Definition:
ensightFile.H:52
Foam
Namespace for OpenFOAM.
Definition:
atmBoundaryLayer.C:33
pointField.H
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::Vector< scalar >
Foam::Cloud< passiveParticle >
points
const pointField & points
Definition:
gmvOutputHeader.H:1
ensightOutputCloud.H
A collection of functions for writing clouds as ensight file content.
Foam::writeMeasured
static void writeMeasured(ensightFile &os, const pointField &points)
Binary output.
Definition:
ensightOutputCloud.C:40
Foam::IPstream
Input inter-processor communications stream.
Definition:
IPstream.H:52
src
lagrangian
intermediate
conversion
ensight
ensightOutputCloud.C
Generated by
1.8.17
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.