Loading...
Searching...
No Matches
IOField.H
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) 2018-2025 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
27Class
28 Foam::IOField
29
30Description
31 A primitive field of type <T> with automated input and output.
32
33SourceFiles
34 IOField.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_IOField_H
39#define Foam_IOField_H
40
41#include "Field.H"
42#include "regIOobject.H"
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46namespace Foam
47{
48
49/*---------------------------------------------------------------------------*\
50 Class IOField Declaration
51\*---------------------------------------------------------------------------*/
52
53template<class Type>
54class IOField
55:
56 public regIOobject,
57 public Field<Type>
58{
59 // Private Member Functions
60
61 //- Read if IOobject flags set and 'on-proc' is true.
62 // Return true if read (only accurate when readOnProc == true).
63 bool readIOcontents(bool readOnProc = true);
64
65 //- Read the content size.
66 // Return the size if read, -1 otherwise
67 label readIOsize();
68
69public:
70
71 //- The underlying content type
73
74 //- Runtime type information
75 TypeName("Field");
76
77
78 // Constructors
79
80 //- Default copy construct
81 IOField(const IOField&) = default;
82
83 //- Construct from IOobject. Will be zero size if not read.
84 explicit IOField(const IOobject& io);
85
86 //- Construct from IOobject, with local processor conditional reading
87 IOField(const IOobject& io, const bool readOnProc);
89 //- Construct from IOobject and zero size (if not read)
91
92 //- Construct from IOobject and field size (if not read)
93 IOField(const IOobject& io, const label len);
94
95 //- Construct from IOobject and copy of List/Field content
96 IOField(const IOobject& io, const UList<Type>& content);
97
98 //- Construct by transferring the Field content
99 IOField(const IOobject& io, Field<Type>&& content);
100
101 //- Construct by copying/moving tmp content
102 IOField(const IOobject& io, const tmp<Field<Type>>& tfld);
104
105 // Factory Methods
106
107 //- Read and return content size, -1 if not read.
108 // The IOobject will not be registered
109 static label readContentsSize(const IOobject& io);
110
111 //- Read and return contents. The IOobject will not be registered
112 static Field<Type> readContents(const IOobject& io);
114
115 //- Destructor
116 virtual ~IOField() = default;
117
119 // Member Functions
120
121 //- The writeData method for regIOobject write operation
122 virtual bool writeData(Ostream& os) const;
124
125 // Member Operators
126
127 //- Copy or move assignment of entries
128 using Field<Type>::operator=;
129
130 //- Copy assignment of entries
131 void operator=(const IOField<Type>& rhs)
132 {
134 }
135
136 //- Move assignment of entries
139 Field<Type>::operator=(std::move(static_cast<Field<Type>&>(rhs)));
140 }
141};
142
143
144/*---------------------------------------------------------------------------*\
145 Class IOFieldRef Declaration
146\*---------------------------------------------------------------------------*/
147
148//- A IOField wrapper for writing external data.
149template<class Type>
150class IOFieldRef
151:
153{
154 // Private Data
155
156 //- Reference to the external content
157 refPtr<Field<Type>> contentRef_;
158
159
160public:
161
162 //- The underlying content type
164
166 //- Type is identical to IOField
167 virtual const word& type() const
168 {
170 }
171
172
173 // Generated Methods
174
175 //- No default construct
176 IOFieldRef() = delete;
177
178 //- No copy construct
179 IOFieldRef(const IOFieldRef&) = delete;
180
181 //- No copy assignment
182 void operator=(const IOFieldRef&) = delete;
183
184
185 // Constructors
186
187 //- Construct from IOobject and const data reference
188 IOFieldRef(const IOobject& io, const Field<Type>& content);
189
190
191 //- Destructor
192 virtual ~IOFieldRef() = default;
193
194
195 // Member Functions
196
197 //- Allow cast to const content
198 // Fatal if content is not set
199 operator const Field<Type>&() const
200 {
201 return contentRef_.cref();
202 }
203
204 //- The writeData method for regIOobject write operation
205 // Fatal if content is not set
206 virtual bool writeData(Ostream& os) const;
207};
208
209
210// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212} // End namespace Foam
213
214// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215
216#ifdef NoRepository
217 #include "IOField.C"
218#endif
219
220// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221
222#endif
223
224// ************************************************************************* //
static const char *const typeName
Typename for Field.
Definition Field.H:93
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
void operator=(const Field< Type > &)
Copy assignment.
Definition Field.C:781
constexpr Field() noexcept
Default construct.
Definition FieldI.H:24
A IOField wrapper for writing external data.
Definition IOField.H:191
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition IOField.C:242
virtual ~IOFieldRef()=default
Destructor.
virtual const word & type() const
Type is identical to IOField.
Definition IOField.H:211
void operator=(const IOFieldRef &)=delete
No copy assignment.
IOFieldRef(const IOFieldRef &)=delete
No copy construct.
IOFieldRef()=delete
No default construct.
Field< Type > content_type
The underlying content type.
Definition IOField.H:205
A primitive field of type <T> with automated input and output.
Definition IOField.H:53
virtual ~IOField()=default
Destructor.
IOField(const IOobject &io, const label len)
Construct from IOobject and field size (if not read).
Definition IOField.C:117
IOField(const IOobject &io, const bool readOnProc)
Construct from IOobject, with local processor conditional reading.
Definition IOField.C:93
IOField(const IOField &)=default
Default copy construct.
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition IOField.C:234
IOField(const IOobject &io, Field< Type > &&content)
Construct by transferring the Field content.
Definition IOField.C:147
static Field< Type > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
Definition IOField.C:216
IOField(const IOobject &io)
Construct from IOobject. Will be zero size if not read.
Definition IOField.C:81
TypeName("Field")
Runtime type information.
IOField(const IOobject &io, const tmp< Field< Type > > &tfld)
Construct by copying/moving tmp content.
Definition IOField.C:161
void operator=(IOField< Type > &&rhs)
Move assignment of entries.
Definition IOField.H:173
void operator=(const IOField< Type > &rhs)
Copy assignment of entries.
Definition IOField.H:165
IOField(const IOobject &io, const UList< Type > &content)
Construct from IOobject and copy of List/Field content.
Definition IOField.C:132
IOField(const IOobject &io, Foam::zero)
Construct from IOobject and zero size (if not read).
Definition IOField.C:105
Field< Type > content_type
The underlying content type.
Definition IOField.H:75
static label readContentsSize(const IOobject &io)
Read and return content size, -1 if not read.
Definition IOField.C:196
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
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:89
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
OBJstream os(runTime.globalPath()/outputName)
const auto & io
Namespace for OpenFOAM.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68