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-2022 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::masterOFstream
29 
30 Description
31  Master-only drop-in replacement for OFstream.
32 
33 SourceFiles
34  masterOFstream.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_masterOFstream_H
39 #define Foam_masterOFstream_H
40 
41 #include "StringStream.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class masterOFstream Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class masterOFstream
53 :
54  public OStringStream
55 {
56  // Private Data
57 
58  //- The backend file name
59  const fileName pathName_;
60 
61  //- Atomic file creation (ignored with append)
62  const IOstreamOption::atomicType atomic_;
63 
64  //- Output file compression
65  const IOstreamOption::compressionType compression_;
66 
67  //- Open file in append mode
68  const IOstreamOption::appendType append_;
69 
70  //- Should file be written (on this processor)
71  const bool valid_;
72 
73 
74  // Private Member Functions
75 
76  //- Open file with checking and write append contents
77  void checkWrite
78  (
79  const fileName& fName,
80  const char* str,
81  std::streamsize len
82  );
83 
84  //- Open file with checking and write append contents
85  void checkWrite(const fileName& fName, const std::string& s);
86 
87  //- Commit buffered information, including parallel gather as required
88  void commit();
89 
90 
91 public:
92 
93  // Constructors
94 
95  //- Construct with specified atomic behaviour (with worldComm)
96  //- from pathname, stream option, optional append
98  (
100  const fileName& pathname,
101  IOstreamOption streamOpt = IOstreamOption(),
103  const bool valid = true
104  );
105 
106  //- Construct (with worldComm)
107  //- from pathname, stream option, optional append
108  explicit masterOFstream
109  (
110  const fileName& pathname,
111  IOstreamOption streamOpt = IOstreamOption(),
113  const bool valid = true
114  )
115  :
117  (
119  pathname,
120  streamOpt,
121  append,
122  valid
123  )
124  {}
125 
126 
127  //- Destructor - commits buffered information to file
128  ~masterOFstream();
129 };
130 
131 
132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
133 
134 } // End namespace Foam
135 
136 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
137 
138 #endif
139 
140 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:71
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:96
Input/output from string buffers.
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)
Master-only drop-in replacement for OFstream.
masterOFstream(IOstreamOption::atomicType atomic, const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), IOstreamOption::appendType append=IOstreamOption::NON_APPEND, const bool valid=true)
Construct with specified atomic behaviour (with worldComm) from pathname, stream option, optional append.
appendType
File appending (NON_APPEND | APPEND)
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
~masterOFstream()
Destructor - commits buffered information to file.
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))
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:256
Namespace for OpenFOAM.