decomposedBlockData.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 | Copyright (C) 2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::decomposedBlockData
26 
27 Description
28  decomposedBlockData is a List<char> with IO on the master processor only.
29 
30 SourceFiles
31  decomposedBlockData.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef decomposedBlockData_H
36 #define decomposedBlockData_H
37 
38 #include "IOList.H"
39 #include "regIOobject.H"
40 #include "UPstream.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class decomposedBlockData Declaration
49 \*---------------------------------------------------------------------------*/
50 
52 :
53  public regIOobject,
54  public List<char>
55 {
56 protected:
57 
58  // Protected data
59 
60  //- Type to use for gather
62 
63  //- Communicator for all parallel comms
64  const label comm_;
65 
66 
67  // Protected member functions
68 
69  //- Read data into *this. ISstream is only valid on master.
70  static bool readBlocks
71  (
72  const label comm,
73  autoPtr<ISstream>& isPtr,
75  const UPstream::commsTypes commsType
76  );
77 
78 
79 public:
80 
81  TypeName("decomposedBlockData");
82 
83 
84  // Constructors
85 
86  //- Construct given an IOobject
88  (
89  const label comm,
90  const IOobject&,
92  );
93 
94  //- Construct given an IOobject and for READ_IF_MODIFIED a List<char>
96  (
97  const label comm,
98  const IOobject&,
99  const UList<char>&,
101  );
102 
103  //- Construct by transferring the IOList contents
105  (
106  const label comm,
107  const IOobject&,
108  const Xfer<List<char>>&,
110  );
111 
112 
113  //- Destructor
114  virtual ~decomposedBlockData();
115 
116 
117  // Member functions
118 
119  //- Read object
120  virtual bool read();
121 
122  //- Write separated content. Assumes content is the serialised data
123  // and that the master data contains a header
124  virtual bool writeData(Ostream&) const;
125 
126  //- Write using given format, version and compression
127  virtual bool writeObject
128  (
132  const bool valid
133  ) const;
134 
135 
136  // Helpers
137 
138  //- Read header. Call only on master.
139  static bool readMasterHeader(IOobject&, Istream&);
140 
141  //- Helper: write FoamFile IOobject header
142  static void writeHeader
143  (
144  Ostream& os,
145  const IOstream::versionNumber version,
147  const word& type,
148  const string& note,
149  const fileName& location,
150  const word& name
151  );
152 
153  //- Read selected block (non-seeking) + header information
155  (
156  const label blocki,
157  Istream& is,
158  IOobject& headerIO
159  );
160 
161  //- Read master header information (into headerIO) and return
162  // data in stream. Note: isPtr is only valid on master.
164  (
165  const label comm,
166  const fileName& fName,
167  autoPtr<ISstream>& isPtr,
168  IOobject& headerIO,
169  const UPstream::commsTypes commsType
170  );
171 
172  //- Write *this. Ostream only valid on master. Returns starts of
173  // processor blocks
174  static bool writeBlocks
175  (
176  const label comm,
177  autoPtr<OSstream>& osPtr,
178  List<std::streamoff>& start,
179  const UList<char>&,
180  const UPstream::commsTypes,
181  const bool syncReturnState = true
182  );
183 
184  //- Detect number of blocks in a file
185  static label numBlocks(const fileName&);
186 };
187 
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 } // End namespace Foam
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************************************************************* //
decomposedBlockData(const label comm, const IOobject &, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
virtual ~decomposedBlockData()
Destructor.
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &data, const UPstream::commsTypes commsType)
Read data into *this. ISstream is only valid on master.
virtual bool read()
Read object.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & name() const
Return name.
Definition: IOobject.H:291
A class for handling file names.
Definition: fileName.H:69
virtual bool writeData(Ostream &) const
Write separated content. Assumes content is the serialised data.
const label comm_
Communicator for all parallel comms.
const UPstream::commsTypes commsType_
Type to use for gather.
commsTypes
Types of communications.
Definition: UPstream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static label numBlocks(const fileName &)
Detect number of blocks in a file.
static bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &start, const UList< char > &, const UPstream::commsTypes, const bool syncReturnState=true)
Write *this. Ostream only valid on master. Returns starts of.
word format(conversionProperties.lookup("format"))
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:309
A class for handling words, derived from string.
Definition: word.H:59
static void writeHeader(Ostream &os, const IOstream::versionNumber version, const IOstream::streamFormat format, const word &type, const string &note, const fileName &location, const word &name)
Helper: write FoamFile IOobject header.
decomposedBlockData is a List<char> with IO on the master processor only.
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
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:61
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:485
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool valid) const
Write using given format, version and compression.
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
TypeName("decomposedBlockData")
Version number type.
Definition: IOstream.H:96
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:65
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.