IOField.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-2017 OpenFOAM Foundation
9 Copyright (C) 2016-2022 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 "IOField.H"
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33template<class Type>
35{
36 if
37 (
38 (
39 readOpt() == IOobject::MUST_READ
40 || readOpt() == IOobject::MUST_READ_IF_MODIFIED
41 )
42 || (readOpt() == IOobject::READ_IF_PRESENT && headerOk())
43 )
44 {
45 readStream(typeName) >> *this;
46 close();
47 return true;
48 }
49
50 return false;
51}
52
53
54// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55
56template<class Type>
58:
60{
61 // Check for MUST_READ_IF_MODIFIED
62 warnNoRereading<IOField<Type>>();
63
64 readContents();
65}
66
67
68template<class Type>
69Foam::IOField<Type>::IOField(const IOobject& io, const bool valid)
70:
72{
73 // Check for MUST_READ_IF_MODIFIED
74 warnNoRereading<IOField<Type>>();
75
76 if
77 (
80 )
81 {
83
84 if (valid)
85 {
86 is >> *this;
87 }
89 }
91 {
92 bool haveFile = headerOk();
93
94 Istream& is = readStream(typeName, haveFile && valid);
95
96 if (valid && haveFile)
97 {
98 is >> *this;
99 }
100 close();
101 }
102}
103
104
105template<class Type>
109{
110 // Check for MUST_READ_IF_MODIFIED
111 warnNoRereading<IOField<Type>>();
112
113 readContents();
114}
115
116
117template<class Type>
119:
121{
122 // Check for MUST_READ_IF_MODIFIED
123 warnNoRereading<IOField<Type>>();
124
125 if (!readContents())
126 {
128 }
129}
130
131
132template<class Type>
134:
136{
137 // Check for MUST_READ_IF_MODIFIED
138 warnNoRereading<IOField<Type>>();
139
140 if (!readContents())
141 {
142 Field<Type>::operator=(content);
143 }
144}
145
146
147template<class Type>
149:
151{
152 // Check for MUST_READ_IF_MODIFIED
153 warnNoRereading<IOField<Type>>();
154
155 Field<Type>::transfer(content);
156
157 readContents();
158}
159
160
161template<class Type>
163:
165{
166 const bool reuse = tfld.movable();
167
168 if (reuse)
169 {
170 Field<Type>::transfer(tfld.ref());
171 }
172
173 if (!readContents() && !reuse)
174 {
176 }
177
178 tfld.clear();
179}
180
181
182template<class Type>
184(
185 const IOobject& io,
186 const Field<Type>& content
187)
188:
190 contentRef_(content) // cref
191{}
192
193
194// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
195
196template<class Type>
198{
199 os << static_cast<const Field<Type>&>(*this);
200 return os.good();
201}
202
203
204template<class Type>
206{
207 os << contentRef_.cref();
208 return os.good();
209}
210
211
212// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
213
214template<class Type>
216{
218}
219
220
221// ************************************************************************* //
virtual bool resize()
Resize the ODE solver.
Definition: Euler.C:53
static const char *const typeName
Typename for Field.
Definition: FieldBase.H:59
Generic templated field type.
Definition: Field.H:82
void operator=(const Field< Type > &)
Copy assignment.
Definition: Field.C:641
A IOField wrapper for writing external data.
Definition: IOField.H:129
IOFieldRef()=delete
No default construct.
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
void operator=(const IOField< Type > &rhs)
Copy assignment of entries.
Definition: IOField.C:215
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:180
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
void close()
Close Istream.
Istream & readStream(const word &, const bool valid=true)
Return Istream and check object type against that given.
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:438
A class for managing temporary objects.
Definition: tmp.H:65
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)