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-2022 OpenCFD Ltd.
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 Class
27  Foam::rawIOField
28 
29 Description
30  Like IOField but falls back to raw IFstream if no header found.
31  Optionally reads average value. For use in MappedFile container.
32 
33 SourceFiles
34  rawIOField.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_rawIOField_H
39 #define Foam_rawIOField_H
40 
41 #include "IOField.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class rawIOField Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 template<class Type>
53 class 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 readContents(Istream&, IOobjectOption::readOption readAverage);
71 
72  //- Read if IOobject flags set. Return true if read.
73  bool readContents(IOobjectOption::readOption readAverage);
74 
75 
76 public:
77 
78  //- The underlying content type
79  typedef Field<Type> content_type;
80 
81  //- Runtime type information
82  TypeName("rawField");
83 
84 
85  // Constructors
86 
87  //- Default copy construct
88  rawIOField(const rawIOField&) = default;
89 
90  //- Construct from IOobject and specified request for reading average
91  //- (default: NO_READ)
92  explicit rawIOField
93  (
94  const IOobject& io,
96  );
97 
98  //- Construct from IOobject and specified request for reading average
99  rawIOField(const IOobject& io, const bool readAverage);
100 
101 
102  //- Destructor
103  virtual ~rawIOField() = default;
104 
105 
106  // Member Functions
107 
108  //- The writeData method for regIOobject write operation
109  virtual bool writeData(Ostream& os) const;
110 
111  //- The field content
112  const Field<Type>& field() const noexcept
113  {
114  return static_cast<const Field<Type>&>(*this);
115  }
116 
117  //- The field content, non-const access
119  {
120  return static_cast<Field<Type>&>(*this);
121  }
122 
123  //- The average value (if any)
124  const Type& average() const noexcept
125  {
126  return average_;
127  }
128 
129  //- Has an average value
130  bool hasAverage() const noexcept
131  {
132  return hasAverage_;
133  }
134 
135  //- Set an average value
136  void setAverage(const Type& val)
137  {
138  hasAverage_ = true;
139  average_ = val;
140  }
141 
142  //- Clear average value
143  void clearAverage()
144  {
145  hasAverage_ = false;
146  average_ = Zero;
147  }
148 
149 
150  // Member Operators
151 
152  //- Copy or move assignment of entries
153  using Field<Type>::operator=;
154 };
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #ifdef NoRepository
164  #include "rawIOField.C"
165 #endif
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 #endif
170 
171 // ************************************************************************* //
void setAverage(const Type &val)
Set an average value.
Definition: rawIOField.H:163
rawIOField(const rawIOField &)=default
Default copy construct.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual bool writeData(Ostream &os) const
The writeData method for regIOobject write operation.
Definition: rawIOField.C:187
Field< Type > content_type
The underlying content type.
Definition: rawIOField.H:84
const Type & average() const noexcept
The average value (if any)
Definition: rawIOField.H:147
Like IOField but falls back to raw IFstream if no header found. Optionally reads average value...
Definition: rawIOField.H:48
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Generic templated field type.
Definition: Field.H:61
virtual ~rawIOField()=default
Destructor.
bool hasAverage() const noexcept
Has an average value.
Definition: rawIOField.H:155
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
TypeName("rawField")
Runtime type information.
Nothing to be read.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:69
void clearAverage()
Clear average value.
Definition: rawIOField.H:172
const Field< Type > & field() const noexcept
The field content.
Definition: rawIOField.H:131
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157
readOption
Enumeration defining read preferences.