Loading...
Searching...
No Matches
masterOFstream.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 OpenFOAM Foundation
9 Copyright (C) 2020-2025 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::masterOFstream
29
30Description
31 Master-only drop-in replacement for OFstream.
32
33 Called on all processors (of the provided communicator).
34 Sends files to the master and writes them there.
35
36SourceFiles
37 masterOFstream.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_masterOFstream_H
42#define Foam_masterOFstream_H
43
44#include "SpanStream.H"
45#include "UPstream.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
52/*---------------------------------------------------------------------------*\
53 Class masterOFstream Declaration
54\*---------------------------------------------------------------------------*/
55
57:
58 public OCharStream
59{
60 // Private Data
61
62 //- The backend file name
63 const fileName pathName_;
64
65 //- Atomic file creation (ignored with append)
66 const IOstreamOption::atomicType atomic_;
67
68 //- Output file compression
69 const IOstreamOption::compressionType compression_;
70
71 //- Open file in append mode
72 const IOstreamOption::appendType append_;
73
74 //- Should file be written (on this processor)
75 const bool writeOnProc_;
76
77 //- Communicator
78 const label comm_;
79
80
81 // Private Member Functions
82
83 //- Open file with checking and write append contents.
84 // A no-op if str is null or len is zero
85 void checkWrite
86 (
87 const fileName& fName,
88 const char* str,
89 std::streamsize len
90 );
91
92 //- Open file with checking and write append contents
93 void checkWrite
94 (
95 const fileName& fName,
96 const UList<char>& charData
97 )
98 {
99 checkWrite(fName, charData.cdata(), charData.size_bytes());
100 }
101
102 //- Commit buffered information, including communication as required
103 void commit();
104
105
106public:
107
108 // Constructors
109
110 //- Construct with specified atomic behaviour and communicator
111 //- from pathname, stream option, optional append
113 (
116 const int communicator,
117 const fileName& pathname,
118 IOstreamOption streamOpt = IOstreamOption(),
120 const bool writeOnProc = true
121 );
122
123 //- Construct with specified communicator
124 //- from pathname, stream option, optional append
126 (
128 const int communicator,
129 const fileName& pathname,
130 IOstreamOption streamOpt = IOstreamOption(),
132 const bool writeOnProc = true
133 )
134 :
136 (
138 communicator,
139 pathname,
140 streamOpt,
141 append,
142 writeOnProc
144 {}
145
146 //- Construct with specified atomic behaviour (with worldComm)
147 //- from pathname, stream option, optional append
149 (
151 const fileName& pathname,
152 IOstreamOption streamOpt = IOstreamOption(),
154 const bool writeOnProc = true
155 )
156 :
158 (
159 atomic,
160 UPstream::worldComm,
161 pathname,
162 streamOpt,
163 append,
164 writeOnProc
165 )
166 {}
167
168 //- Construct (with worldComm)
169 //- from pathname, stream option, optional append
170 explicit masterOFstream
171 (
172 const fileName& pathname,
173 IOstreamOption streamOpt = IOstreamOption(),
175 const bool writeOnProc = true
176 )
177 :
179 (
181 UPstream::worldComm,
182 pathname,
183 streamOpt,
184 append,
185 writeOnProc
186 )
187 {}
188
189
190 //- Destructor - commits buffered information to file
193
194
195// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196
197} // End namespace Foam
198
199// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200
201#endif
202
203// ************************************************************************* //
Input/output streams with (internal or external) character storage.
A simple container for options an IOstream can normally have.
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Default construct (ASCII, UNCOMPRESSED, currentVersion) or construct with format, compression.
atomicType
Atomic operations (output).
@ NON_ATOMIC
atomic = false
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED).
appendType
File appending (NO_APPEND | APPEND_APP | APPEND_ATE).
@ NO_APPEND
no append (truncates existing)
OCharStream(IOstreamOption streamOpt=IOstreamOption())
Default construct (empty output).
void append(std::streamsize count, char c)
Append repeated character content.
auto str() const
For OStringStream compatibility, return the buffer as string copy.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition UListI.H:267
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
Definition UListI.H:295
Inter-processor communications stream.
Definition UPstream.H:69
A class for handling file names.
Definition fileName.H:75
Master-only drop-in replacement for OFstream.
masterOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), IOstreamOption::appendType append=IOstreamOption::NO_APPEND, const bool writeOnProc=true)
Construct (with worldComm) from pathname, stream option, optional append.
masterOFstream(IOstreamOption::atomicType atomic, const int communicator, const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), IOstreamOption::appendType append=IOstreamOption::NO_APPEND, const bool writeOnProc=true)
Construct with specified atomic behaviour and communicator from pathname, stream option,...
masterOFstream(const int communicator, const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), IOstreamOption::appendType append=IOstreamOption::NO_APPEND, const bool writeOnProc=true)
Construct with specified communicator from pathname, stream option, optional append.
~masterOFstream()
Destructor - commits buffered information to file.
masterOFstream(IOstreamOption::atomicType atomic, const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), IOstreamOption::appendType append=IOstreamOption::NO_APPEND, const bool writeOnProc=true)
Construct with specified atomic behaviour (with worldComm) from pathname, stream option,...
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Namespace for OpenFOAM.