writeFile.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2016 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 #include "IOmanip.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
34 (
35  "postProcessing"
36 );
37 
39 
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
44 {
45  os.setf(ios_base::scientific, ios_base::floatfield);
46  os.width(charWidth());
47 }
48 
49 
51 {
52  fileName baseDir = obr_.time().path();
53 
54  if (Pstream::parRun())
55  {
56  // Put in undecomposed case (Note: gives problems for
57  // distributed data running)
58  baseDir = baseDir/".."/outputPrefix;
59  }
60  else
61  {
62  baseDir = baseDir/outputPrefix;
63  }
64 
65  // Append mesh name if not default region
66  if (isA<polyMesh>(obr_))
67  {
68  const polyMesh& mesh = refCast<const polyMesh>(obr_);
69  if (mesh.name() != polyMesh::defaultRegion)
70  {
71  baseDir = baseDir/mesh.name();
72  }
73  }
74 
75  return baseDir;
76 }
77 
78 
80 {
81  return baseFileDir()/prefix_/obr_.time().timeName();
82 }
83 
84 
86 {}
87 
88 
90 (
91  const label offset
92 ) const
93 {
94  return setw(IOstream::defaultPrecision() + addChars + offset);
95 }
96 
97 
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 
101 (
102  const word& name,
103  const Time& runTime,
104  const dictionary& dict,
105  const word& prefix
106 )
107 :
108  regionFunctionObject(name, runTime, dict),
109  prefix_(prefix)
110 {}
111 
112 
114 (
115  const word& name,
116  const objectRegistry& obr,
117  const dictionary& dict,
118  const word& prefix
119 )
120 :
121  regionFunctionObject(name, obr, dict),
122  prefix_(prefix)
123 {}
124 
125 
126 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
127 
129 {}
130 
131 
132 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
133 
135 {
137 }
138 
139 
141 (
142  Ostream& os,
143  const string& str
144 ) const
145 {
146  os << setw(1) << "#" << setw(1) << ' '
147  << setw(charWidth() - 2) << str.c_str();
148 }
149 
150 
152 (
153  Ostream& os,
154  const string& str
155 ) const
156 {
157  os << tab << setw(charWidth()) << str.c_str();
158 }
159 
160 
162 (
163  Ostream& os,
164  const string& str
165 ) const
166 {
167  os << setw(1) << "#" << setw(1) << ' '
168  << setf(ios_base::left) << setw(charWidth() - 2) << str.c_str() << nl;
169 }
170 
171 
173 {
174  os << setw(charWidth()) << obr_.time().timeName();
175 }
176 
177 
178 // ************************************************************************* //
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:152
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
const Time & time() const
Return time.
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:162
virtual void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: writeFile.C:43
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
A class for handling file names.
Definition: fileName.H:69
ios_base::fmtflags setf(const ios_base::fmtflags f)
Set flags of stream.
Definition: IOstream.H:496
static const char tab
Definition: Ostream.H:261
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:461
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:306
virtual fileName baseTimeDir() const
Return the base directory for the current time value.
Definition: writeFile.C:79
static label addChars
Additional characters for writing.
Definition: writeFile.H:99
label charWidth() const
Return width of character stream output.
Definition: writeFile.C:134
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:715
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual fileName baseFileDir() const
Return the base directory for output.
Definition: writeFile.C:50
virtual void writeFileHeader(const label i=0)
File header information.
Definition: writeFile.C:85
dynamicFvMesh & mesh
void writeTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:172
static const word outputPrefix
Directory prefix.
Definition: writeFile.H:96
A class for handling words, derived from string.
Definition: word.H:59
writeFile(const writeFile &)
Disallow default bitwise copy construct.
Smanip< ios_base::fmtflags > setf(const ios_base::fmtflags flags)
Definition: IOmanip.H:164
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual int width() const =0
Get width of output field.
Istream and Ostream manipulators taking arguments.
virtual Omanip< int > valueWidth(const label offset=0) const
Return the value width when writing to stream with optional offset.
Definition: writeFile.C:90
static const char nl
Definition: Ostream.H:262
const word prefix_
Prefix.
Definition: writeFile.H:66
virtual ~writeFile()
Destructor.
Definition: writeFile.C:128
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:393
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:141
const objectRegistry & obr_
Reference to the region objectRegistry.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
Registry of regIOobjects.
fileName path() const
Return path.
Definition: Time.H:269
const word & name() const
Return name.
Definition: IOobject.H:260
IOstream & scientific(IOstream &io)
Definition: IOstream.H:582