OpenFOAM: API Guide
v2112
The open source CFD toolbox
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
-------------------------------------------------------------------------------
11
License
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
34
template
<
class
Type,
class
GeoMesh>
35
void
Foam::DimensionedField<Type, GeoMesh>::readField
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
57
template
<
class
Type,
class
GeoMesh>
58
void
Foam::DimensionedField<Type, GeoMesh>::readIfPresent
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
77
template
<
class
Type,
class
GeoMesh>
78
Foam::DimensionedField<Type, GeoMesh>::DimensionedField
79
(
80
const
IOobject
& io,
81
const
Mesh
&
mesh
,
82
const
word
& fieldDictEntry
83
)
84
:
85
regIOobject
(io),
86
Field<Type>
(),
87
mesh_(
mesh
),
88
dimensions_(
dimless
),
89
oriented_()
90
{
91
readField(
dictionary
(readStream(typeName)), fieldDictEntry);
92
}
93
94
95
template
<
class
Type,
class
GeoMesh>
96
Foam::DimensionedField<Type, GeoMesh>::DimensionedField
97
(
98
const
IOobject
& io,
99
const
Mesh
&
mesh
,
100
const
dictionary
& fieldDict,
101
const
word
& fieldDictEntry
102
)
103
:
104
regIOobject
(io),
105
Field<Type>
(),
106
mesh_(
mesh
),
107
dimensions_(
dimless
),
108
oriented_()
109
{
110
readField(fieldDict, fieldDictEntry);
111
}
112
113
114
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115
116
template
<
class
Type,
class
GeoMesh>
117
bool
Foam::DimensionedField<Type, GeoMesh>::writeData
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
133
os
.check(
FUNCTION_NAME
);
134
return
os
.good();
135
}
136
137
138
template
<
class
Type,
class
GeoMesh>
139
bool
Foam::DimensionedField<Type, GeoMesh>::writeData
(
Ostream
&
os
)
const
140
{
141
return
writeData
(
os
,
"value"
);
142
}
143
144
145
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
146
147
template
<
class
Type,
class
GeoMesh>
148
Foam::Ostream
& Foam::operator<<
149
(
150
Ostream
&
os
,
151
const
DimensionedField<Type, GeoMesh>
& df
152
)
153
{
154
df.writeData(
os
);
155
156
return
os
;
157
}
158
159
160
template
<
class
Type,
class
GeoMesh>
161
Foam::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
// ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition:
IOobject.H:169
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::DimensionedField::readField
void readField(const dictionary &fieldDict, const word &fieldDictEntry="value")
Definition:
DimensionedFieldIO.C:36
Foam::word
A class for handling words, derived from Foam::string.
Definition:
word.H:65
DimensionedField.H
Foam::DimensionedField::DimensionedField
DimensionedField(const IOobject &io, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &field)
Construct from components.
Definition:
DimensionedField.C:71
writeData
const bool writeData(pdfDictionary.get< bool >("writeData"))
Foam::DimensionedField< Type, Foam::pointMesh >::Mesh
Foam::pointMesh ::Mesh Mesh
Type of mesh on which this DimensionedField is instantiated.
Definition:
DimensionedField.H:86
Foam::Field
Generic templated field type.
Definition:
Field.H:63
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition:
dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition:
createDynamicFvMesh.H:6
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition:
regIOobject.H:73
Foam::nl
constexpr char nl
Definition:
Ostream.H:404
f
labelList f(nPoints)
Foam::DimensionedField::writeData
bool writeData(Ostream &os, const word &fieldDictEntry) const
Definition:
DimensionedFieldIO.C:118
FUNCTION_NAME
#define FUNCTION_NAME
Definition:
messageStream.H:295
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition:
Ostream.H:56
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition:
DimensionedField.H:54
Foam::dimless
const dimensionSet dimless
Dimensionless.
Definition:
dimensionSets.C:189
src
OpenFOAM
fields
DimensionedFields
DimensionedField
DimensionedFieldIO.C
Generated by
1.8.17
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.