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 
29 #include "IOobjectList.H"
30 #include "IOField.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 template<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  {
56  ++nPointData_;
57  vtk::fileWriter::writeBasicField<Type>(field.name(), field);
58  }
59  else
60  {
62  (
66  )
67  << " for field " << field.name() << nl << endl
69  }
70 }
71 
72 
73 template<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 
92  IOobject io
93  (
94  fieldName,
95  mesh_.time().timeName(),
96  localDir,
97  mesh_,
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  }
128  return nFields;
129 }
130 
131 
132 template<class Type>
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 // ************************************************************************* //
rDeltaTY field()
A class for handling file names.
Definition: fileName.H:72
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
label nCellData_
The number of CellData written for the Piece thus far.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
label nPointData_
The number of PointData written for the Piece thus far.
bool isState(outputState test) const noexcept
True if output state corresponds to the test state.
Ostream & reportBadState(Ostream &, outputState expected) const
Generate message reporting bad writer state.
A class for handling words, derived from Foam::string.
Definition: word.H:63
Reading is optional [identical to LAZY_READ].
wordList allNames() const
The sorted names of all objects (synchronised across processors)
Definition: IOobjectList.C:296
void write(const IOField< Type > &field)
Write the IOField.
label writeFields(const wordList &fieldNames, bool verbose=true)
Write IOFields.
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
A primitive field of type <T> with automated input and output.