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 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::decomposedBlockData
29 
30 Description
31  decomposedBlockData is a List<char> with IO on the master processor only.
32 
33 SourceFiles
34  decomposedBlockData.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef decomposedBlockData_H
39 #define decomposedBlockData_H
40 
41 #include "IOList.H"
42 #include "regIOobject.H"
43 #include "UPstream.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class decomposedBlockData Declaration
52 \*---------------------------------------------------------------------------*/
53 
55 :
56  public regIOobject,
57  public List<char>
58 {
59 protected:
60 
61  // Protected Data
62 
63  //- Type to use for gather
65 
66  //- Communicator for all parallel comms
67  const label comm_;
68 
69 
70  // Protected member functions
71 
72  //- Helper: determine number of processors whose recvSizes fits
73  // ito maxBufferSize
74  static label calcNumProcs
75  (
76  const label comm,
77  const off_t maxBufferSize,
78  const labelUList& recvSizes,
79  const label startProci
80  );
81 
82  //- Read data into *this. ISstream is only valid on master.
83  static bool readBlocks
84  (
85  const label comm,
86  autoPtr<ISstream>& isPtr,
88  const UPstream::commsTypes commsType
89  );
90 
91 
92 public:
93 
94  //- Declare type-name, virtual type (with debug switch)
95  TypeName("decomposedBlockData");
96 
97 
98  // Constructors
99 
100  //- Construct given an IOobject
102  (
103  const label comm,
104  const IOobject& io,
106  );
107 
108  //- Construct given an IOobject and for READ_IF_MODIFIED a List<char>
110  (
111  const label comm,
112  const IOobject& io,
113  const UList<char>& list,
115  );
116 
117  //- Construct by transferring the List contents
119  (
120  const label comm,
121  const IOobject& io,
122  List<char>&& list,
124  );
125 
126 
127  //- Destructor
128  virtual ~decomposedBlockData() = default;
129 
130 
131  // Member functions
132 
133  //- Read object
134  virtual bool read();
135 
136  //- Write separated content. Assumes content is the serialised data
137  // and that the master data contains a header
138  virtual bool writeData(Ostream& os) const;
139 
140  //- Write using stream options
141  virtual bool writeObject
142  (
143  IOstreamOption streamOpt,
144  const bool valid
145  ) const;
146 
147 
148  // Helpers
149 
150  //- Read header. Call only on master.
151  static bool readMasterHeader(IOobject&, Istream&);
152 
153  //- Helper: write FoamFile IOobject header
154  static void writeHeader
155  (
156  Ostream& os,
159  const word& type,
160  const string& note,
161  const fileName& location,
162  const word& name
163  );
164 
165  //- Read selected block (non-seeking) + header information
167  (
168  const label blocki,
169  Istream& is,
170  IOobject& headerIO
171  );
172 
173  //- Read master header information (into headerIO) and return
174  // data in stream. Note: isPtr is only valid on master.
176  (
177  const label comm,
178  const fileName& fName,
179  autoPtr<ISstream>& isPtr,
180  IOobject& headerIO,
181  const UPstream::commsTypes commsType
182  );
183 
184  //- Helper: gather single label. Note: using native Pstream.
185  // datas sized with num procs but undefined contents on
186  // slaves
187  static void gather
188  (
189  const label comm,
190  const label data,
191  labelList& datas
192  );
193 
194  //- Helper: gather data from (subset of) slaves. Returns
195  // recvData : received data
196  // recvOffsets : offset in data. recvOffsets is nProcs+1
197  static void gatherSlaveData
198  (
199  const label comm,
200  const UList<char>& data,
201  const labelUList& recvSizes,
202 
203  const label startProc,
204  const label nProcs,
205 
206  List<int>& recvOffsets,
207  List<char>& recvData
208  );
209 
210  //- Write *this. Ostream only valid on master. Returns starts of
211  // processor blocks
212  static bool writeBlocks
213  (
214  const label comm,
215  autoPtr<OSstream>& osPtr,
216  List<std::streamoff>& start,
217  const UList<char>& masterData,
218 
219  const labelUList& recvSizes,
220 
221  // optional slave data (on master)
222  const PtrList<SubList<char>>& slaveData,
223 
224  const UPstream::commsTypes,
225  const bool syncReturnState = true
226  );
227 
228  //- Detect number of blocks in a file
229  static label numBlocks(const fileName& fName);
230 };
231 
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 } // End namespace Foam
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 #endif
240 
241 // ************************************************************************* //
regIOobject.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::decomposedBlockData::comm_
const label comm_
Communicator for all parallel comms.
Definition: decomposedBlockData.H:66
Foam::decomposedBlockData::~decomposedBlockData
virtual ~decomposedBlockData()=default
Destructor.
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:70
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
UPstream.H
Foam::decomposedBlockData::readBlock
static autoPtr< ISstream > readBlock(const label blocki, Istream &is, IOobject &headerIO)
Read selected block (non-seeking) + header information.
Definition: decomposedBlockData.C:232
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::decomposedBlockData::calcNumProcs
static label calcNumProcs(const label comm, const off_t maxBufferSize, const labelUList &recvSizes, const label startProci)
Helper: determine number of processors whose recvSizes fits.
Definition: decomposedBlockData.C:696
Foam::decomposedBlockData::writeBlocks
static bool writeBlocks(const label comm, autoPtr< OSstream > &osPtr, List< std::streamoff > &start, 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. Returns starts of.
Definition: decomposedBlockData.C:736
Foam::decomposedBlockData::numBlocks
static label numBlocks(const fileName &fName)
Detect number of blocks in a file.
Definition: decomposedBlockData.C:1067
IOList.H
format
word format(conversionProperties.get< word >("format"))
Foam::decomposedBlockData::readMasterHeader
static bool readMasterHeader(IOobject &, Istream &)
Read header. Call only on master.
Definition: decomposedBlockData.C:165
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::decomposedBlockData::writeHeader
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.
Definition: decomposedBlockData.C:187
Foam::decomposedBlockData::TypeName
TypeName("decomposedBlockData")
Declare type-name, virtual type (with debug switch)
Foam::decomposedBlockData::gather
static void gather(const label comm, const label data, labelList &datas)
Helper: gather single label. Note: using native Pstream.
Definition: decomposedBlockData.C:597
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::decomposedBlockData::gatherSlaveData
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. Returns.
Definition: decomposedBlockData.C:636
Foam::decomposedBlockData::commsType_
const UPstream::commsTypes commsType_
Type to use for gather.
Definition: decomposedBlockData.H:63
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
Foam::UPstream::commsTypes::scheduled
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::decomposedBlockData::decomposedBlockData
decomposedBlockData(const label comm, const IOobject &io, const UPstream::commsTypes=UPstream::commsTypes::scheduled)
Construct given an IOobject.
Definition: decomposedBlockData.C:52
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::decomposedBlockData
decomposedBlockData is a List<char> with IO on the master processor only.
Definition: decomposedBlockData.H:53
Foam::foamVersion::version
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
Foam::decomposedBlockData::writeData
virtual bool writeData(Ostream &os) const
Write separated content. Assumes content is the serialised data.
Definition: decomposedBlockData.C:963
Foam::IOobject::note
const string & note() const
Return the optional note.
Definition: IOobjectI.H:100
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:71
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:69
Foam::decomposedBlockData::readBlocks
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.
Definition: decomposedBlockData.C:312
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::UList< label >
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::decomposedBlockData::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write using stream options.
Definition: decomposedBlockData.C:1032
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
Foam::decomposedBlockData::read
virtual bool read()
Read object.
Definition: decomposedBlockData.C:948