OpenFOAM
v2406
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-2022 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
if
(!
returnReduceOr
(
io
.typeHeaderOk<
IOField<Type>
>(
false
)))
103
{
104
continue
;
105
}
106
107
if
(verbose)
108
{
109
if
(!nFields)
110
{
111
Info
<<
" "
<< pTraits<Type>::typeName <<
":"
;
112
}
113
114
Info
<<
" "
<< fieldName;
115
}
116
117
IOField<Type>
field
(
io
);
118
this->write<Type>(
field
);
119
120
++nFields;
121
}
122
123
if
(verbose && nFields)
124
{
125
Info
<<
endl
;
126
}
127
128
return
nFields;
129
}
130
131
132
template
<
class
Type>
133
Foam::label
Foam::vtk::lagrangianWriter::writeFields
134
(
135
const
IOobjectList
& objects,
136
const
bool
verbose
137
)
138
{
139
return
writeFields<Type>
140
(
141
objects.
allNames
<
IOField<Type>
>(),
// These are in sorted order
142
verbose
143
);
144
}
145
146
147
// ************************************************************************* //
IOField.H
field
rDeltaTY field()
Foam::fileName
A class for handling file names.
Definition:
fileName.H:72
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition:
IOobjectList.H:55
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition:
errorManip.H:125
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:113
Foam::FatalError
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition:
error.H:608
Foam::List< word >
Foam::nl
constexpr char nl
The newline '\n' character (0x0a)
Definition:
Ostream.H:50
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition:
Ostream.H:531
Foam::vtk::fileWriter::nPointData_
label nPointData_
The number of PointData written for the Piece thus far.
Definition:
foamVtkFileWriter.H:118
Foam::vtk::fileWriter::isState
bool isState(outputState test) const noexcept
True if output state corresponds to the test state.
Definition:
foamVtkFileWriterI.H:35
IOobjectList.H
Foam::vtk::fileWriter::reportBadState
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
Definition:
foamVtkFileWriter.C:58
foamVtkLagrangianWriter.H
Foam::word
A class for handling words, derived from Foam::string.
Definition:
word.H:63
Foam::IOobjectOption::READ_IF_PRESENT
Reading is optional [identical to LAZY_READ].
Definition:
IOobjectOption.H:77
Foam::IOobjectList::allNames
wordList allNames() const
The sorted names of all objects (synchronised across processors)
Definition:
IOobjectList.C:296
Foam::vtk::lagrangianWriter::write
void write(const IOField< Type > &field)
Write the IOField.
Definition:
foamVtkLagrangianWriterTemplates.C:28
Foam::vtk::lagrangianWriter::writeFields
label writeFields(const wordList &fieldNames, bool verbose=true)
Write IOFields.
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
io
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Foam::returnReduceOr
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Definition:
PstreamReduceOps.H:480
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition:
IOobject.H:180
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition:
foamVtkLagrangianWriter.H:57
Foam::vtk::fileTag::POINT_DATA
"PointData"
src
lagrangian
intermediate
conversion
vtk
foamVtkLagrangianWriterTemplates.C
Generated by
1.8.14