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-------------------------------------------------------------------------------
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
29#include "IOobjectList.H"
30#include "IOField.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34template<class Type>
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
50 {
51 ++nCellData_;
52 vtk::fileWriter::writeBasicField<Type>(field.name(), field);
53 }
55 {
57 vtk::fileWriter::writeBasicField<Type>(field.name(), field);
58 }
59 else
60 {
62 (
66 )
67 << " for field " << field.name() << nl << endl
68 << exit(FatalError);
69 }
70}
71
72
73template<class Type>
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
93 (
94 fieldName,
95 mesh_.time().timeName(),
96 localDir,
97 mesh_,
99 );
100
101 // Check global existence to avoid any errors
102 const bool ok =
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
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
139template<class Type>
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// ************************************************************************* //
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
wordList allNames() const
The sorted names of all objects (synchronised across processors)
Definition: IOobjectList.C:429
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A class for handling file names.
Definition: fileName.H:76
virtual bool write()
Write the output fields.
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
bool isState(outputState test) const noexcept
True if output state corresponds to the test state.
label nCellData_
The number of CellData written for the Piece thus far.
label nPointData_
The number of PointData written for the Piece thus far.
@ POINT_DATA
Inside PointData.
@ CELL_DATA
Inside CellData.
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
error FatalError
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53