All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2018 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 {
51  fileName baseDir = fileObr_.time().path();
52 
53  if (Pstream::parRun())
54  {
55  // Put in undecomposed case (Note: gives problems for
56  // distributed data running)
57  baseDir = baseDir/".."/outputPrefix;
58  }
59  else
60  {
61  baseDir = baseDir/outputPrefix;
62  }
63 
64  // Append mesh name if not default region
65  if (isA<polyMesh>(fileObr_))
66  {
67  const polyMesh& mesh = refCast<const polyMesh>(fileObr_);
68  if (mesh.name() != polyMesh::defaultRegion)
69  {
70  baseDir = baseDir/mesh.name();
71  }
72  }
73 
74  // Remove any ".."
75  baseDir.clean();
76 
77  return baseDir;
78 }
79 
80 
82 {
84 }
85 
86 
88 (
89  const label offset
90 ) const
91 {
92  return setw(IOstream::defaultPrecision() + addChars + offset);
93 }
94 
95 
96 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
97 
99 (
100  const objectRegistry& obr,
101  const word& prefix
102 )
103 :
104  fileObr_(obr),
105  prefix_(prefix)
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
110 
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
118 {
120 }
121 
122 
124 (
125  Ostream& os,
126  const string& str
127 ) const
128 {
129  os << setw(1) << "#" << setw(1) << ' '
130  << setf(ios_base::left) << setw(charWidth() - 2) << str.c_str();
131 }
132 
133 
135 (
136  Ostream& os,
137  const string& str
138 ) const
139 {
140  os << tab << setw(charWidth()) << str.c_str();
141 }
142 
143 
145 (
146  Ostream& os,
147  const string& str
148 ) const
149 {
150  os << setw(1) << "#" << setw(1) << ' '
151  << setf(ios_base::left) << setw(charWidth() - 2) << str.c_str() << nl;
152 }
153 
154 
156 {
157  os << setw(charWidth()) << fileObr_.time().timeName();
158 }
159 
160 
161 // ************************************************************************* //
fileName path() const
Return path.
Definition: Time.H:265
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:145
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:496
static const char tab
Definition: Ostream.H:259
bool clean()
Cleanup file name.
Definition: fileName.C:81
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:461
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:622
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:124
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:99
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:81
label charWidth() const
Return width of character stream output.
Definition: writeFile.C:117
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 baseFileDir() const
Return the base directory for output.
Definition: writeFile.C:49
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
void writeTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:155
Omanip< int > valueWidth(const label offset=0) const
Return the value width when writing to stream with optional offset.
Definition: writeFile.C:88
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:582
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:135