OpenFOAM: API Guide
v2112
The open source CFD toolbox
foamVtkLagrangianWriterTemplates.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-2021 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 "
foamVtkLagrangianWriter.H
"
29
#include "
IOobjectList.H
"
30
#include "
IOField.H
"
31
32
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34
template
<
class
Type>
35
void
Foam::vtk::lagrangianWriter::write
(
const
IOField<Type>
&
field
)
36
{
37
// Other integral types (eg, bool etc) would need cast/convert to label.
38
// Similarly for labelVector etc.
39
40
// Ensure consistent output width
41
// for (const Type& val : field)
42
// {
43
// for (int cmpt=0; cmpt < nCmpt; ++cmpt)
44
// {
45
// format().write(label(component(val, cmpt)));
46
// }
47
// }
48
49
if
(
isState
(
outputState::CELL_DATA
))
50
{
51
++
nCellData_
;
52
vtk::fileWriter::writeBasicField<Type>(
field
.name(),
field
);
53
}
54
else
if
(
isState
(
outputState::POINT_DATA
))
55
{
56
++
nPointData_
;
57
vtk::fileWriter::writeBasicField<Type>(
field
.name(),
field
);
58
}
59
else
60
{
61
reportBadState
62
(
63
FatalErrorInFunction
,
64
outputState::CELL_DATA
,
65
outputState::POINT_DATA
66
)
67
<<
" for field "
<<
field
.name() <<
nl
<<
endl
68
<<
exit
(
FatalError
);
69
}
70
}
71
72
73
template
<
class
Type>
74
Foam::label
Foam::vtk::lagrangianWriter::writeFields
75
(
76
const
wordList
&
fieldNames
,
77
bool
verbose
78
)
79
{
80
const
fileName
localDir(cloudDir());
81
82
label nFields = 0;
83
84
for
(
const
word
& fieldName :
fieldNames
)
85
{
86
// Globally the field is expected to exist (MUST_READ), but can
87
// be missing on a local processor.
88
//
89
// However, constructing IOField with MUST_READ and valid=false fails.
90
// Workaround: READ_IF_PRESENT and verify the header globally
91
92
IOobject
io
93
(
94
fieldName,
95
mesh_.time().timeName(),
96
localDir,
97
mesh_,
98
IOobject::READ_IF_PRESENT
99
);
100
101
// Check global existence to avoid any errors
102
const
bool
ok =
103
returnReduce
104
(
105
io.typeHeaderOk<
IOField<Type>
>(
false
),
106
orOp<bool>
()
107
);
108
109
if
(!ok)
110
{
111
continue
;
112
}
113
114
if
(verbose)
115
{
116
if
(!nFields)
117
{
118
Info
<<
" "
<<
pTraits<Type>::typeName
<<
":"
;
119
}
120
121
Info
<<
" "
<< fieldName;
122
}
123
124
IOField<Type>
field
(io);
125
this->write<Type>(
field
);
126
127
++nFields;
128
}
129
130
if
(verbose && nFields)
131
{
132
Info
<<
endl
;
133
}
134
135
return
nFields;
136
}
137
138
139
template
<
class
Type>
140
Foam::label
Foam::vtk::lagrangianWriter::writeFields
141
(
142
const
IOobjectList
& objects,
143
const
bool
verbose
144
)
145
{
146
return
writeFields<Type>
147
(
148
objects.
allNames
<
IOField<Type>
>(),
// These are in sorted order
149
verbose
150
);
151
}
152
153
154
// ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition:
IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition:
word.H:65
Foam::fileName
A class for handling file names.
Definition:
fileName.H:73
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition:
foamVtkLagrangianWriter.H:61
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::vtk::lagrangianWriter::writeFields
label writeFields(const wordList &fieldNames, bool verbose=true)
Write IOFields.
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition:
Ostream.H:369
foamVtkLagrangianWriter.H
Foam::vtk::fileWriter::nPointData_
label nPointData_
The number of PointData written for the Piece thus far.
Definition:
foamVtkFileWriter.H:104
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::vtk::lagrangianWriter::write
void write(const IOField< Type > &field)
Write the IOField.
Definition:
foamVtkLagrangianWriterTemplates.C:35
Foam::IOobject::READ_IF_PRESENT
Definition:
IOobject.H:187
Foam::vtk::fileWriter::isState
bool isState(outputState test) const noexcept
True if output state corresponds to the test state.
Definition:
foamVtkFileWriterI.H:42
field
rDeltaTY field()
Foam::FatalError
error FatalError
fieldNames
const wordRes fieldNames(propsDict.getOrDefault< wordRes >("fields", wordRes()))
Foam::IOobjectList::allNames
wordList allNames() const
The sorted names of all objects (synchronised across processors)
Definition:
IOobjectList.C:391
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition:
IOobjectList.H:55
Foam::vtk::fileTag::POINT_DATA
"PointData"
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition:
errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition:
error.H:453
Foam::nl
constexpr char nl
Definition:
Ostream.H:404
IOField.H
Foam::vtk::fileWriter::reportBadState
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
Definition:
foamVtkFileWriter.C:65
Foam::List< word >
Foam::pTraits
A traits class, which is primarily used for primitives.
Definition:
pTraits.H:56
Foam::vtk::fileTag::CELL_DATA
"CellData"
Foam::vtk::fileWriter::nCellData_
label nCellData_
The number of CellData written for the Piece thus far.
Definition:
foamVtkFileWriter.H:101
Foam::orOp
Definition:
ops.H:234
src
lagrangian
intermediate
conversion
vtk
foamVtkLagrangianWriterTemplates.C
Generated by
1.8.17
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.