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-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 Class
28  Foam::CompactIOField
29 
30 Description
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 
37 SourceFiles
38  CompactIOField.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_CompactIOField_H
43 #define Foam_CompactIOField_H
44 
45 #include "IOField.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward Declarations
53 template<class T, class BaseType> class CompactIOField;
54 
55 template<class T, class BaseType> Istream& operator>>
56 (
57  Istream&,
59 );
60 
61 template<class T, class BaseType> Ostream& operator<<
62 (
63  Ostream&,
65 );
66 
67 /*---------------------------------------------------------------------------*\
68  Class CompactIOField Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 template<class T, class BaseType>
72 class CompactIOField
73 :
74  public regIOobject,
75  public Field<T>
76 {
77  // Private Member Functions
78 
79  //- Read if IOobject flags set and 'on-proc' is true.
80  //- Reads according to the header type.
81  // Return true if read (only accurate when readOnProc == true).
82  bool readIOcontents(bool readOnProc = true);
83 
84 public:
85 
86  //- Runtime type information
87  TypeName("FieldField");
88 
89 
90  // Constructors
91 
92  //- Default copy construct
93  CompactIOField(const CompactIOField&) = default;
94 
95  //- Construct from IOobject
96  explicit CompactIOField(const IOobject& io);
97 
98  //- Construct from IOobject, with local processor conditional reading
99  CompactIOField(const IOobject& io, const bool readOnProc);
100 
101  //- Construct from IOobject and zero size (if not read)
103 
104  //- Construct from IOobject and size (if not read)
105  CompactIOField(const IOobject& io, const label len);
106 
107  //- Construct from IOobject and a List/Field content
108  CompactIOField(const IOobject& io, const UList<T>& content);
109 
110  //- Construct by transferring the Field contents
111  CompactIOField(const IOobject& io, Field<T>&& content);
112 
113 
114  //- Destructor
115  virtual ~CompactIOField() = default;
116 
117 
118  // Member Functions
119 
120  //- Write using stream options
121  virtual bool writeObject
122  (
123  IOstreamOption streamOpt,
124  const bool writeOnProc
125  ) const;
126 
127  virtual bool writeData(Ostream& os) const;
128 
129 
130  // Member Operators
131 
132  //- Copy assignment of entries
133  void operator=(const CompactIOField<T, BaseType>& rhs);
134 
135  //- Copy or move assignment of entries
136  using Field<T>::operator=;
137 };
138 
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 } // End namespace Foam
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 #ifdef NoRepository
147  #include "CompactIOField.C"
148 #endif
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 #endif
153 
154 // ************************************************************************* //
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
CompactIOField(const CompactIOField &)=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
Pure virtual writeData function.
A simple container for options an IOstream can normally have.
void operator=(const CompactIOField< T, BaseType > &rhs)
Copy assignment of entries.
Generic templated field type.
Definition: Field.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: HashTable.H:105
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
A Field of objects of type <T> with automated input and output using a compact storage. Behaves like IOField except when binary output in case it writes a CompactListList.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:68
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
virtual ~CompactIOField()=default
Destructor.
TypeName("FieldField")
Runtime type information.
Namespace for OpenFOAM.