writeFile.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "writeFile.H"
27 #include "Time.H"
28 #include "polyMesh.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
33 (
34  "postProcessing"
35 );
36 
38 
39 
40 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
41 
43 {
44  os.setf(ios_base::scientific, ios_base::floatfield);
45  os.width(charWidth());
46 }
47 
48 
50 {
52 
53  // Append mesh name if not default region
54  if (isA<polyMesh>(fileObr_))
55  {
56  const polyMesh& mesh = refCast<const polyMesh>(fileObr_);
57  if (mesh.name() != polyMesh::defaultRegion)
58  {
59  baseDir = baseDir/mesh.name();
60  }
61  }
62 
63  return baseDir;
64 }
65 
66 
68 {
70 }
71 
72 
74 (
75  const label offset
76 ) const
77 {
78  return setw(IOstream::defaultPrecision() + addChars + offset);
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
83 
85 (
86  const objectRegistry& obr,
87  const word& prefix
88 )
89 :
90  fileObr_(obr),
91  prefix_(prefix)
92 {}
93 
94 
95 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
96 
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 
104 {
106 }
107 
108 
110 (
111  Ostream& os,
112  const string& str
113 ) const
114 {
115  os << setw(1) << "#" << setw(1) << ' '
116  << setf(ios_base::left) << setw(charWidth() - 2) << str.c_str();
117 }
118 
119 
121 (
122  Ostream& os,
123  const string& str
124 ) const
125 {
126  os << tab << setw(charWidth()) << str.c_str();
127 }
128 
129 
131 (
132  Ostream& os,
133  const string& str
134 ) const
135 {
136  os << setw(1) << "#" << setw(1) << ' '
137  << setf(ios_base::left) << setw(charWidth() - 2) << str.c_str() << nl;
138 }
139 
140 
142 {
143  os << setw(charWidth()) << fileObr_.time().timeName();
144 }
145 
146 
147 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const word & name() const
Return name.
Definition: IOobject.H:303
A class for handling file names.
Definition: fileName.H:79
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:131
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:493
static const char tab
Definition: Ostream.H:259
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:458
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:309
static label addChars
Additional characters for writing.
Definition: writeFile.H:75
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:636
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:110
dynamicFvMesh & mesh
void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: writeFile.C:42
static const word outputPrefix
Directory prefix.
Definition: writeFile.H:72
A class for handling words, derived from string.
Definition: word.H:59
writeFile(const objectRegistry &obr, const word &prefix)
Construct from objectRegistry and prefix.
Definition: writeFile.C:85
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
Definition: IOmanip.H:164
fileName baseTimeDir() const
Return the base directory for the current time value.
Definition: writeFile.C:67
label charWidth() const
Return width of character stream output.
Definition: writeFile.C:103
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual int width() const =0
Get width of output field.
static const char nl
Definition: Ostream.H:260
const word prefix_
Prefix.
Definition: writeFile.H:66
const Time & time() const
Return time.
fileName globalPath() const
Return the global path.
Definition: TimePaths.H:133
fileName baseFileDir() const
Return the base directory for output.
Definition: writeFile.C:49
void writeTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:141
Omanip< int > valueWidth(const label offset=0) const
Return the value width when writing to stream with optional offset.
Definition: writeFile.C:74
const objectRegistry & fileObr_
Reference to the region objectRegistry.
Definition: writeFile.H:63
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Registry of regIOobjects.
IOstream & scientific(IOstream &io)
Definition: IOstream.H:579
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:121