DimensionedFieldIO.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "DimensionedField.H"
30#include "IOstreams.H"
31
32// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33
34template<class Type, class GeoMesh>
36(
37 const dictionary& fieldDict,
38 const word& fieldDictEntry
39)
40{
41 dimensions_.readEntry("dimensions", fieldDict);
42
43 // Note: oriented state may have already been set on construction
44 // - if so - do not reset by re-reading
45 // - required for backwards compatibility in case of restarting from
46 // an old run where the oriented state may not have been set
47 if (oriented_.oriented() != orientedType::ORIENTED)
48 {
49 oriented_.read(fieldDict);
50 }
51
52 Field<Type> f(fieldDictEntry, fieldDict, GeoMesh::size(mesh_));
53 this->transfer(f);
54}
55
56
57template<class Type, class GeoMesh>
59(
60 const word& fieldDictEntry
61)
62{
63 if
64 (
65 (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
66 || this->readOpt() == IOobject::MUST_READ
67 || this->readOpt() == IOobject::MUST_READ_IF_MODIFIED
68 )
69 {
70 readField(dictionary(readStream(typeName)), fieldDictEntry);
71 }
72}
73
74
75// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
76
77template<class Type, class GeoMesh>
79(
80 const IOobject& io,
81 const Mesh& mesh,
82 const word& fieldDictEntry
83)
84:
86 Field<Type>(),
87 mesh_(mesh),
88 dimensions_(dimless),
89 oriented_()
90{
91 readField(dictionary(readStream(typeName)), fieldDictEntry);
92}
93
94
95template<class Type, class GeoMesh>
97(
98 const IOobject& io,
99 const Mesh& mesh,
100 const dictionary& fieldDict,
101 const word& fieldDictEntry
102)
103:
105 Field<Type>(),
106 mesh_(mesh),
107 dimensions_(dimless),
108 oriented_()
109{
110 readField(fieldDict, fieldDictEntry);
111}
112
113
114// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115
116template<class Type, class GeoMesh>
118(
119 Ostream& os,
120 const word& fieldDictEntry
121) const
122{
123 os.writeEntry("dimensions", dimensions());
124 os << nl;
125
126 if (oriented_.writeEntry(os))
127 {
128 os << nl;
129 }
130
131 Field<Type>::writeEntry(fieldDictEntry, os);
132
134 return os.good();
135}
136
137
138template<class Type, class GeoMesh>
140{
141 return writeData(os, "value");
142}
143
144
145// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
146
147template<class Type, class GeoMesh>
148Foam::Ostream& Foam::operator<<
149(
150 Ostream& os,
152)
153{
154 df.writeData(os);
155
156 return os;
157}
158
159
160template<class Type, class GeoMesh>
161Foam::Ostream& Foam::operator<<
162(
163 Ostream& os,
164 const tmp<DimensionedField<Type, GeoMesh>>& tdf
165)
166{
167 tdf().writeData(os);
168 tdf.clear();
169
170 return os;
171}
172
173
174// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
GeoMesh::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
static const char *const typeName
Typename for Field.
Definition: FieldBase.H:59
Generic templated field type.
Definition: Field.H:82
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:614
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:239
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
Istream & readStream(const word &, const bool valid=true)
Return Istream and check object type against that given.
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define FUNCTION_NAME
const dimensionSet dimless
Dimensionless.
static void writeData(Ostream &os, const Type &val)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList f(nPoints)