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-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::masterOFstream
29
30Description
31 Master-only drop-in replacement for OFstream.
32
33SourceFiles
34 masterOFstream.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef masterOFstream_H
39#define masterOFstream_H
40
41#include "StringStream.H"
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45namespace Foam
46{
47
48/*---------------------------------------------------------------------------*\
49 Class masterOFstream Declaration
50\*---------------------------------------------------------------------------*/
53:
54 public OStringStream
55{
56 // Private Data
57
58 const fileName pathName_;
59
60 const IOstreamOption::compressionType compression_;
61
62 const bool append_;
63
64 //- Should file be written
65 const bool valid_;
66
67
68 // Private Member Functions
69
70 //- Open file with checking and write append contents
71 void checkWrite
72 (
73 const fileName& fName,
74 const char* str,
75 std::streamsize len
76 );
77
78 //- Open file with checking and write append contents
79 void checkWrite(const fileName& fName, const std::string& s);
80
81 //- Commit buffered information, including parallel gather as required
82 void commit();
83
84
85public:
86
87 // Constructors
88
89 //- Construct from pathname and set stream status
90 explicit masterOFstream
91 (
92 const fileName& pathname,
93 IOstreamOption streamOpt = IOstreamOption(),
94 const bool append = false,
95 const bool valid = true
96 );
97
98 //- Construct from pathname, version and set stream status
100 (
101 const fileName& pathname,
105 const bool append = false,
106 const bool valid = true
107 )
108 :
110 (
111 pathname,
112 IOstreamOption(fmt, ver, cmp),
113 append,
114 valid
115 )
116 {}
117
118
119 //- Destructor - commits buffered information to file
121};
122
123
124// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125
126} // End namespace Foam
127
128// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
129
130#endif
131
132// ************************************************************************* //
Input/output from string buffers.
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:88
Representation of a major/minor version number.
The IOstreamOption is a simple container for options an IOstream can normally have.
streamFormat
Data format (ascii | binary)
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
@ UNCOMPRESSED
compression = false
static const versionNumber currentVersion
The current version number (2.0)
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:231
A class for handling file names.
Definition: fileName.H:76
Master-only drop-in replacement for OFstream.
~masterOFstream()
Destructor - commits buffered information to file.
masterOFstream(const fileName &pathname, IOstreamOption::streamFormat fmt, IOstreamOption::versionNumber ver=IOstreamOption::currentVersion, IOstreamOption::compressionType cmp=IOstreamOption::UNCOMPRESSED, const bool append=false, const bool valid=true)
Construct from pathname, version and set stream status.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Namespace for OpenFOAM.