Loading...
Searching...
No Matches
rawIOField.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) 2020-2023 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::rawIOField
28
29Description
30 Like IOField but falls back to raw IFstream if no header found.
31 Optionally reads average value. For use in MappedFile container.
32
33SourceFiles
34 rawIOField.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_rawIOField_H
39#define Foam_rawIOField_H
40
41#include "IOField.H"
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45namespace Foam
46{
47
48/*---------------------------------------------------------------------------*\
49 Class rawIOField Declaration
50\*---------------------------------------------------------------------------*/
51
52template<class Type>
53class rawIOField
54:
55 public regIOobject,
56 public Field<Type>
57{
58 // Private Data
59
60 //- Has an average value
61 bool hasAverage_;
62
63 //- The average for the field (zero if not used)
64 Type average_;
65
66
67 // Private Member Functions
68
69 //- Read contents and average
70 void readIOcontents(Istream&, IOobjectOption::readOption readAverage);
71
72 //- Read if IOobject flags set. Return true if read.
73 bool readIOcontents(IOobjectOption::readOption readAverage);
74
75
76public:
77
78 //- The underlying content type
80
81 //- Runtime type information
82 TypeName("rawField");
83
85 // Constructors
86
87 //- Default copy construct
88 rawIOField(const rawIOField&) = default;
90 //- Construct from IOobject and specified request for reading average
91 //- (default: NO_READ)
92 explicit rawIOField
93 (
94 const IOobject& io,
96 );
98 //- Construct from IOobject and specified request for reading average
99 rawIOField(const IOobject& io, const bool readAverage);
100
101
102 // Factory Methods
103
104 //- Read and return contents. The IOobject will not be registered
105 static Field<Type> readContents(const IOobject& io);
106
107
108 //- Destructor
109 virtual ~rawIOField() = default;
110
111
112 // Member Functions
113
114 //- The writeData method for regIOobject write operation
115 virtual bool writeData(Ostream& os) const;
116
117 //- The field content
118 const Field<Type>& field() const noexcept
119 {
120 return static_cast<const Field<Type>&>(*this);
121 }
122
123 //- The field content, non-const access
125 {
126 return static_cast<Field<Type>&>(*this);
127 }
128
129 //- The average value (if any)
130 const Type& average() const noexcept
131 {
132 return average_;
133 }
134
135 //- Has an average value
136 bool hasAverage() const noexcept
137 {
138 return hasAverage_;
140
141 //- Set an average value
142 void setAverage(const Type& val)
143 {
144 hasAverage_ = true;
145 average_ = val;
146 }
148 //- Clear average value
149 void clearAverage()
150 {
151 hasAverage_ = false;
152 average_ = Zero;
153 }
154
156 // Member Operators
157
158 //- Copy or move assignment of entries
159 using Field<Type>::operator=;
160};
161
162
163// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164
165} // End namespace Foam
166
167// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168
169#ifdef NoRepository
170 #include "rawIOField.C"
171#endif
172
173// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174
175#endif
176
177// ************************************************************************* //
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
constexpr Field() noexcept
Default construct.
Definition FieldI.H:24
readOption
Enumeration defining read preferences.
@ NO_READ
Nothing to be read.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
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
rawIOField(const rawIOField &)=default
Default copy construct.
TypeName("rawField")
Runtime type information.
const Field< Type > & field() const noexcept
The field content.
Definition rawIOField.H:139
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition rawIOField.C:205
bool hasAverage() const noexcept
Has an average value.
Definition rawIOField.H:163
static Field< Type > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
Definition rawIOField.C:187
void setAverage(const Type &val)
Set an average value.
Definition rawIOField.H:171
const Type & average() const noexcept
The average value (if any).
Definition rawIOField.H:155
virtual ~rawIOField()=default
Destructor.
void clearAverage()
Clear average value.
Definition rawIOField.H:180
Field< Type > content_type
The underlying content type.
Definition rawIOField.H:84
Field< Type > & field() noexcept
The field content, non-const access.
Definition rawIOField.H:147
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
OBJstream os(runTime.globalPath()/outputName)
const auto & io
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
const direction noexcept
Definition scalarImpl.H:265
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68