OpenFOAM: API Guide
v2012
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
-------------------------------------------------------------------------------
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 "
DimensionedField.H
"
29
#include "
IOstreams.H
"
30
31
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33
template
<
class
Type,
class
GeoMesh>
34
void
Foam::DimensionedField<Type, GeoMesh>::readField
35
(
36
const
dictionary
& fieldDict,
37
const
word
& fieldDictEntry
38
)
39
{
40
dimensions_.reset(
dimensionSet
(fieldDict,
"dimensions"
));
41
42
// Note: oriented state may have already been set on construction
43
// - if so - do not reset by re-reading
44
// - required for backwards compatibility in case of restarting from
45
// an old run where the oriented state may not have been set
46
if
(oriented_.oriented() != orientedType::ORIENTED)
47
{
48
oriented_.read(fieldDict);
49
}
50
51
Field<Type>
f
(fieldDictEntry, fieldDict, GeoMesh::size(mesh_));
52
this->transfer(
f
);
53
}
54
55
56
template
<
class
Type,
class
GeoMesh>
57
void
Foam::DimensionedField<Type, GeoMesh>::readIfPresent
58
(
59
const
word
& fieldDictEntry
60
)
61
{
62
if
63
(
64
(this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk())
65
|| this->readOpt() == IOobject::MUST_READ
66
|| this->readOpt() == IOobject::MUST_READ_IF_MODIFIED
67
)
68
{
69
readField(
dictionary
(readStream(typeName)), fieldDictEntry);
70
}
71
}
72
73
74
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75
76
template
<
class
Type,
class
GeoMesh>
77
Foam::DimensionedField<Type, GeoMesh>::DimensionedField
78
(
79
const
IOobject
& io,
80
const
Mesh
&
mesh
,
81
const
word
& fieldDictEntry
82
)
83
:
84
regIOobject
(io),
85
Field<Type>
(),
86
mesh_(
mesh
),
87
dimensions_(
dimless
),
88
oriented_()
89
{
90
readField(
dictionary
(readStream(typeName)), fieldDictEntry);
91
}
92
93
94
template
<
class
Type,
class
GeoMesh>
95
Foam::DimensionedField<Type, GeoMesh>::DimensionedField
96
(
97
const
IOobject
& io,
98
const
Mesh
&
mesh
,
99
const
dictionary
& fieldDict,
100
const
word
& fieldDictEntry
101
)
102
:
103
regIOobject
(io),
104
Field<Type>
(),
105
mesh_(
mesh
),
106
dimensions_(
dimless
),
107
oriented_()
108
{
109
readField(fieldDict, fieldDictEntry);
110
}
111
112
113
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114
115
template
<
class
Type,
class
GeoMesh>
116
bool
Foam::DimensionedField<Type, GeoMesh>::writeData
117
(
118
Ostream
& os,
119
const
word
& fieldDictEntry
120
)
const
121
{
122
os.
writeEntry
(
"dimensions"
, dimensions());
123
oriented_.
writeEntry
(os);
124
125
os<<
nl
<<
nl
;
126
127
Field<Type>::writeEntry
(fieldDictEntry, os);
128
129
os.
check
(
FUNCTION_NAME
);
130
return
os.
good
();
131
}
132
133
134
template
<
class
Type,
class
GeoMesh>
135
bool
Foam::DimensionedField<Type, GeoMesh>::writeData
(
Ostream
& os)
const
136
{
137
return
writeData
(os,
"value"
);
138
}
139
140
141
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
142
143
template
<
class
Type,
class
GeoMesh>
144
Foam::Ostream
& Foam::operator<<
145
(
146
Ostream
& os,
147
const
DimensionedField<Type, GeoMesh>
& df
148
)
149
{
150
df.writeData(os);
151
152
return
os;
153
}
154
155
156
template
<
class
Type,
class
GeoMesh>
157
Foam::Ostream
& Foam::operator<<
158
(
159
Ostream& os,
160
const
tmp<DimensionedField<Type, GeoMesh>>& tdf
161
)
162
{
163
tdf().writeData(os);
164
tdf.clear();
165
166
return
os;
167
}
168
169
170
// ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition:
IOobject.H:104
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition:
dimensionSets.H:50
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:35
Foam::word
A class for handling words, derived from Foam::string.
Definition:
word.H:62
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::dimensionSet
Dimension set for the base types.
Definition:
dimensionSet.H:65
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::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition:
IOstream.C:51
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition:
dictionary.H:121
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:71
Foam::nl
constexpr char nl
Definition:
Ostream.H:385
f
labelList f(nPoints)
Foam::DimensionedField::writeData
bool writeData(Ostream &os, const word &fieldDictEntry) const
Definition:
DimensionedFieldIO.C:117
FUNCTION_NAME
#define FUNCTION_NAME
Definition:
messageStream.H:270
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition:
Ostream.H:232
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition:
Ostream.H:56
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition:
IOstream.H:224
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition:
DimensionedField.H:54
src
OpenFOAM
fields
DimensionedFields
DimensionedField
DimensionedFieldIO.C
Generated by
1.8.17
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.