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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2017-2018 OpenFOAM Foundation
9 Copyright (C) 2020-2021 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::decomposedBlockData
29
30Description
31 The decomposedBlockData comprise a \c List<char> for each output
32 processor, typically with IO on the master processor only.
33
34 For decomposedBlockData, we make a distinction between the container
35 description and the individual block contents.
36
37 The \b FoamFile header specifies the container characteristics and thus
38 has \c class = \c %decomposedBlockData and normally \c format = \c binary.
39 This description refers to the \em entire file container, not the
40 individual blocks.
41
42 Each processor block is simply a binary chunk of characters and the
43 first block also contains the header description for all of the blocks.
44 For example,
45\verbatim
46FoamFile
47{
48 version 2.0;
49 format binary;
50 arch "LSB;label=32;scalar=64";
51 class decomposedBlockData;
52 location "constant/polyMesh";
53 object points;
54}
55
56// processor0
57NCHARS
58(FoamFile
59{
60 version 2.0;
61 format ascii;
62 arch "LSB;label=32;scalar=64";
63 class vectorField;
64 location "constant/polyMesh";
65 object points;
66}
67...content...
68)
69
70// processor1
71NCHARS
72(...content...)
73
74...
75\endverbatim
76
77
78SourceFiles
79 decomposedBlockData.C
80 decomposedBlockDataHeader.C
81
82\*---------------------------------------------------------------------------*/
83
84#ifndef decomposedBlockData_H
85#define decomposedBlockData_H
86
87#include "IOList.H"
88#include "regIOobject.H"
89#include "UPstream.H"
90
91// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92
93namespace Foam
94{
95
96// Forward Declarations
97class dictionary;
98
99/*---------------------------------------------------------------------------*\
100 Class decomposedBlockData Declaration
101\*---------------------------------------------------------------------------*/
104:
105 public regIOobject
106{
107 // Private Functions
108
109 //- Helper: write content for FoamFile IOobject header
110 static void writeHeaderContent
111 (
112 Ostream& os,
113 IOstreamOption streamOptContainer,
114 const word& objectType,
115 const string& note,
116 const fileName& location,
117 const word& objectName
118 );
119
120
121protected:
122
123 // Protected Data
124
125 //- Type to use for gather
127
128 //- Communicator for all parallel comms
129 const label comm_;
130
131 //- The block content
133
134
135 // Protected Member Functions
136
137 //- Helper: determine number of processors whose recvSizes fits
138 //- into maxBufferSize
139 static label calcNumProcs
140 (
141 const label comm,
142 const off_t maxBufferSize,
143 const labelUList& recvSizes,
144 const label startProci
145 );
146
147 //- Read data into *this. ISstream is only valid on master.
148 static bool readBlocks
149 (
150 const label comm,
151 autoPtr<ISstream>& isPtr,
152 List<char>& contentChars,
153 const UPstream::commsTypes commsType
154 );
155
156
157public:
158
159 //- Declare type-name, virtual type (with debug switch)
160 TypeName("decomposedBlockData");
161
162
163 // Constructors
164
165 //- Construct given an IOobject
167 (
168 const label comm,
169 const IOobject& io,
171 );
172
173
174 //- Destructor
175 virtual ~decomposedBlockData() = default;
176
177
178 // Member Functions
179
180 //- Read object
181 virtual bool read();
182
183 //- Write separated content (assumes content is the serialised data)
184 // The serialised master data should also contain a FoamFile header
185 virtual bool writeData(Ostream& os) const;
186
187 //- Write using stream options
188 virtual bool writeObject
189 (
190 IOstreamOption streamOpt,
191 const bool valid
192 ) const;
193
194
195 // Helpers
196
197 //- True if object type is a known collated type
198 static bool isCollatedType(const word& objectType);
199
200 //- True if object header class is a known collated type
201 static bool isCollatedType(const IOobject& io);
202
203 //- Read header as per IOobject with additional handling of
204 //- decomposedBlockData
205 static bool readHeader(IOobject& io, Istream& is);
206
207 //- Helper: write FoamFile IOobject header
208 static void writeHeader
209 (
210 Ostream& os,
211 IOstreamOption streamOptContainer,
212 const word& objectType,
213 const string& note,
214 const fileName& location,
215 const word& objectName,
216 const dictionary& extraEntries
217 );
218
219 //- Helper: write FoamFile IOobject header
220 static void writeHeader
221 (
222 Ostream& os,
223 IOstreamOption streamOptData,
224 const IOobject& io
225 );
226
227 //- Helper: generate additional entries for FoamFile header
228 static void writeExtraHeaderContent
229 (
231 IOstreamOption streamOptData,
232 const IOobject& io
233 );
234
235 //- Helper: read block of (binary) character data
236 static bool readBlockEntry
237 (
238 Istream& is,
239 List<char>& charData
240 );
241
242 //- Helper: write block of (binary) character data
243 static std::streamoff writeBlockEntry
244 (
245 OSstream& os,
246 const label blocki,
247 const UList<char>& charData
248 );
249
250 //- Helper: write block of (binary) character data
251 // \return -1 on error
252 static std::streamoff writeBlockEntry
253 (
254 OSstream& os,
255 IOstreamOption streamOptData,
256 const regIOobject& io,
257 const label blocki,
258 const bool withLocalHeader
259 );
260
261 //- Read selected block (non-seeking) + header information
263 (
264 const label blocki,
265 ISstream& is,
266 IOobject& headerIO
267 );
268
269 //- Read master header information (into headerIO) and return
270 //- data in stream. Note: isPtr is only valid on master.
272 (
273 const label comm,
274 const fileName& fName,
275 autoPtr<ISstream>& isPtr,
276 IOobject& headerIO,
277 const UPstream::commsTypes commsType
278 );
279
280 //- Helper: gather single label. Note: using native Pstream.
281 // datas sized with num procs but undefined contents on
282 // slaves
283 static void gather
284 (
285 const label comm,
286 const label data,
287 labelList& datas
288 );
289
290 //- Helper: gather data from (subset of) slaves.
291 //
292 // Returns:
293 // - recvData : received data
294 // - recvOffsets : offset in data. recvOffsets is nProcs+1
295 static void gatherSlaveData
296 (
297 const label comm,
298 const UList<char>& data,
299 const labelUList& recvSizes,
300
301 const label startProc,
302 const label nProcs,
303
304 List<int>& recvOffsets,
305 List<char>& recvData
306 );
307
308 //- Write *this. Ostream only valid on master.
309 // Returns offsets of processor blocks in blockOffset
310 static bool writeBlocks
311 (
312 const label comm,
313 autoPtr<OSstream>& osPtr,
314 List<std::streamoff>& blockOffset,
315
316 const UList<char>& masterData,
317
318 const labelUList& recvSizes,
319
320 // optional slave data (on master)
321 const PtrList<SubList<char>>& slaveData,
322
324 const bool syncReturnState = true
325 );
326};
327
328
329// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330
331} // End namespace Foam
332
333// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334
335#endif
336
337// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const string & note() const noexcept
Return the optional note.
Definition: IOobjectI.H:95
The IOstreamOption is a simple container for options an IOstream can normally have.
Generic input stream using a standard (STL) stream.
Definition: ISstream.H:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:57
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
A List obtained as a section of another List.
Definition: SubList.H:70
commsTypes
Types of communications.
Definition: UPstream.H:67
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
The decomposedBlockData comprise a List<char> for each output processor, typically with IO on the mas...
static bool readBlockEntry(Istream &is, List< char > &charData)
Helper: read block of (binary) character data.
static void gatherSlaveData(const label comm, const UList< char > &data, const labelUList &recvSizes, const label startProc, const label nProcs, List< int > &recvOffsets, List< char > &recvData)
Helper: gather data from (subset of) slaves.
static std::streamoff writeBlockEntry(OSstream &os, const label blocki, const UList< char > &charData)
Helper: write block of (binary) character data.
virtual bool writeData(Ostream &os) const
Write separated content (assumes content is the serialised data)
TypeName("decomposedBlockData")
Declare type-name, virtual type (with debug switch)
static autoPtr< ISstream > readBlock(const label blocki, ISstream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
const label comm_
Communicator for all parallel comms.
static void writeHeader(Ostream &os, IOstreamOption streamOptContainer, const word &objectType, const string &note, const fileName &location, const word &objectName, const dictionary &extraEntries)
Helper: write FoamFile IOobject header.
static void writeExtraHeaderContent(dictionary &dict, IOstreamOption streamOptData, const IOobject &io)
Helper: generate additional entries for FoamFile header.
static void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
static bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &blockOffset, const UList< char > &masterData, const labelUList &recvSizes, const PtrList< SubList< char > > &slaveData, const UPstream::commsTypes, const bool syncReturnState=true)
Write *this. Ostream only valid on master.
virtual ~decomposedBlockData()=default
Destructor.
static bool isCollatedType(const word &objectType)
True if object type is a known collated type.
List< char > contentData_
The block content.
static bool readHeader(IOobject &io, Istream &is)
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
virtual bool read()
Read object.
const UPstream::commsTypes commsType_
Type to use for gather.
static bool readBlocks(const label comm, autoPtr< ISstream > &isPtr, List< char > &contentChars, const UPstream::commsTypes commsType)
Read data into *this. ISstream is only valid on master.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
dictionary dict
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73