Loading...
Searching...
No Matches
CompactIOField.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) 2020-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::CompactIOField
29
30Description
31 A Field of objects of type <T> with automated input and output using
32 a compact storage. Behaves like IOField except when binary output in
33 case it writes a CompactListList.
34
35 Useful for fields of small subfields e.g. in lagrangian
36
37SourceFiles
38 CompactIOField.C
39
40\*---------------------------------------------------------------------------*/
41
42#ifndef Foam_CompactIOField_H
43#define Foam_CompactIOField_H
44
45#include "IOField.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
52// Forward Declarations
53template<class T> class CompactIOField;
54
55template<class T> Istream& operator>>(Istream&, CompactIOField<T>&);
56template<class T> Ostream& operator<<(Ostream&, const CompactIOField<T>&);
57
58/*---------------------------------------------------------------------------*\
59 Class CompactIOField Declaration
60\*---------------------------------------------------------------------------*/
61
62template<class T>
64:
65 public regIOobject,
66 public Field<T>
67{
68 // Private Member Functions
69
70 //- Read if IOobject flags set and 'on-proc' is true.
71 //- Reads according to the header type.
72 // Return true if read (only accurate when readOnProc == true).
73 bool readIOcontents(bool readOnProc = true);
74
75 //- Read the content size.
76 // Return the size if read, -1 otherwise
77 label readIOsize(bool readOnProc = true);
78
79 //- Has too many elements in it?
80 bool overflows() const;
81
82public:
83
84 //- The underlying content type
85 typedef Field<T> content_type;
86
87 //- Runtime type information
88 TypeName("FieldField");
89
91 // Constructors
92
93 //- Default copy construct
94 CompactIOField(const CompactIOField&) = default;
96 //- Construct from IOobject. Will be zero size if not read.
97 explicit CompactIOField(const IOobject& io);
98
99 //- Construct from IOobject, with local processor conditional reading
100 CompactIOField(const IOobject& io, const bool readOnProc);
101
102 //- Construct from IOobject and zero size (if not read)
104
105 //- Construct from IOobject and size (if not read)
106 CompactIOField(const IOobject& io, const label len);
107
108 //- Construct from IOobject and a List/Field content
109 CompactIOField(const IOobject& io, const UList<T>& content);
110
111 //- Construct by transferring the Field contents
112 CompactIOField(const IOobject& io, Field<T>&& content);
114
115 // Factory Methods
116
117 //- Read and return content size, -1 if not read.
118 // The IOobject is never registered
119 static label readContentsSize(const IOobject& io);
120
121 //- Read and return contents. The IOobject is never registered
122 static Field<T> readContents(const IOobject& io);
124
125 //- Destructor
126 virtual ~CompactIOField() = default;
127
129 // Member Functions
130
131 //- Read as offsets/packed-values and transcribe into *this
134 //- Write as offsets/packed-values
136
137 //- Write using stream options. Checks for overflow in binary
138 virtual bool writeObject
139 (
140 IOstreamOption streamOpt,
141 const bool writeOnProc
142 ) const;
144 //- Write as plain or compact content (depends on stream format)
145 virtual bool writeData(Ostream& os) const;
146
147
148 // Member Operators
149
150 //- Copy or move assignment of entries
151 using Field<T>::operator=;
152
153 //- Copy assignment of entries
155 {
157 }
158
159 //- Move assignment of entries
161 {
162 Field<T>::operator=(std::move(static_cast<Field<T>&>(rhs)));
163 }
164};
165
166
167// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168
169} // End namespace Foam
170
171// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173#ifdef NoRepository
174 #include "CompactIOField.C"
175#endif
176
177// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178
179#endif
180
181// ************************************************************************* //
A Field of objects of type <T> with automated input and output using a compact storage....
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options. Checks for overflow in binary.
CompactIOField(const IOobject &io, const label len)
Construct from IOobject and size (if not read).
static Field< T > readContents(const IOobject &io)
Read and return contents. The IOobject is never registered.
Ostream & writeCompact(Ostream &os) const
Write as offsets/packed-values.
virtual bool writeData(Ostream &os) const
Write as plain or compact content (depends on stream format).
CompactIOField(const IOobject &io, const UList< T > &content)
Construct from IOobject and a List/Field content.
virtual ~CompactIOField()=default
Destructor.
CompactIOField(const IOobject &io, Field< T > &&content)
Construct by transferring the Field contents.
void operator=(CompactIOField< T > &&rhs)
Move assignment of entries.
CompactIOField(const IOobject &io, const bool readOnProc)
Construct from IOobject, with local processor conditional reading.
TypeName("FieldField")
Runtime type information.
void operator=(const CompactIOField< T > &rhs)
Copy assignment of entries.
CompactIOField(const IOobject &io)
Construct from IOobject. Will be zero size if not read.
Istream & readCompact(Istream &is)
Read as offsets/packed-values and transcribe into *this.
CompactIOField(const IOobject &io, Foam::zero)
Construct from IOobject and zero size (if not read).
Field< T > content_type
The underlying content type.
CompactIOField(const CompactIOField &)=default
Default copy construct.
static label readContentsSize(const IOobject &io)
Read and return content size, -1 if not read.
tmp< Field< Type > > T() const
Return the field transpose (only defined for second rank tensors).
Definition Field.C:745
void operator=(const Field< Type > &)
Copy assignment.
Definition Field.C:781
constexpr Field() noexcept
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A simple container for options an IOstream can normally have.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
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
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 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.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Istream & operator>>(Istream &, directionInfo &)
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