logFiles.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2016 OpenFOAM Foundation
9 Copyright (C) 2016 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
27\*---------------------------------------------------------------------------*/
28
29#include "logFiles.H"
30#include "Time.H"
31#include "IFstream.H"
32
33// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
34
36{
37 if (Pstream::master())
38 {
39 const word startTimeName =
41
42 forAll(names_, i)
43 {
44 if (!filePtrs_.set(i))
45 {
46 filePtrs_.set(i, createFile(names_[i]));
47
49 }
50 }
51 }
52}
53
54
56{
57 names_.clear();
58 names_.append(names);
59
60 if (Pstream::master())
61 {
62 filePtrs_.clear();
63 filePtrs_.setSize(names_.size());
64 }
65
66 createFiles();
67}
68
69
71{
72 names_.clear();
73 names_.append(name);
74
76}
77
78
79// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80
82(
83 const objectRegistry& obr,
84 const word& prefix
85)
86:
87 writeFile(obr, prefix),
88 names_(),
89 filePtrs_()
90{}
91
92
94(
95 const objectRegistry& obr,
96 const word& prefix,
97 const dictionary& dict
98)
99:
100 writeFile(obr, prefix),
101 names_(),
102 filePtrs_()
103{
105}
106
107
108// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109
111{
112 return names_;
113}
114
115
117{
118 if (!Pstream::master())
119 {
121 << "Request for files() can only be done by the master process"
122 << abort(FatalError);
123 }
124
125 return filePtrs_;
126}
127
128
131 if (!Pstream::master())
132 {
134 << "Request for file(i) can only be done by the master process"
135 << abort(FatalError);
136 }
137
138 if (!filePtrs_.set(i))
139 {
141 << "File pointer at index " << i << " not allocated"
142 << abort(FatalError);
143 }
144
145 return filePtrs_[i];
146}
147
148
150{
151 createFiles();
152
153 return true;
154}
155
156
157// ************************************************************************* //
Output to file stream, using an OSstream.
Definition: OFstream.H:57
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
virtual bool read()
Re-read model coefficients if they have changed.
virtual dimensionedScalar startTime() const
Return start time.
Definition: Time.C:861
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const Type & value() const
Return const reference to value.
Watches for presence of the named trigger file in the case directory and signals a simulation stop (o...
Definition: abort.H:128
functionObject base class for creating, maintaining and writing log files e.g. integrated or averaged...
Definition: logFiles.H:62
virtual void resetNames(const wordList &names)
Reset the list of names from a wordList.
Definition: logFiles.C:55
virtual void createFiles()
Create the output file.
Definition: logFiles.C:35
PtrList< OFstream > filePtrs_
File pointer.
Definition: logFiles.H:72
PtrList< OFstream > & files()
Return access to the files.
Definition: logFiles.C:116
virtual void resetName(const word &name)
Reset the list of names to a single name entry.
Definition: logFiles.C:70
wordList names_
File names.
Definition: logFiles.H:69
const wordList & names() const
Return const access to the names.
Definition: logFiles.C:110
virtual bool write()
Write function.
Definition: logFiles.C:149
Base class for writing single files from the function objects.
Definition: writeFile.H:120
virtual autoPtr< OFstream > createFile(const word &name, scalar timeValue) const
Return autoPtr to a new file for a given time.
Definition: writeFile.C:80
void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: writeFile.C:42
virtual void resetFile(const word &name)
Reset internal file pointer to new file with new name.
Definition: writeFile.C:134
const objectRegistry & fileObr_
Reference to the region objectRegistry.
Definition: writeFile.H:126
Registry of regIOobjects.
const Time & time() const noexcept
Return time registry.
splitCell * master() const
Definition: splitCell.H:113
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333