Loading...
Searching...
No Matches
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-2022 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\*---------------------------------------------------------------------------*/
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 =
40 fileObr_.time().timeName(fileObr_.time().startTime().value());
41
42 forAll(names_, i)
43 {
44 if (!filePtrs_.set(i))
45 {
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);
76}
77
78
79// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80
81Foam::functionObjects::logFiles::logFiles
82(
83 const objectRegistry& obr,
84 const word& prefix
85)
87 writeFile(obr, prefix),
88 names_(),
89 filePtrs_()
90{}
91
92
93Foam::functionObjects::logFiles::logFiles
94(
95 const objectRegistry& obr,
96 const word& prefix,
97 const dictionary& dict
98)
99:
100 writeFile(obr, prefix),
101 names_(),
102 filePtrs_()
105}
106
107
108// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 << "Request for files() can only be done by the master process"
123 }
124
125 return filePtrs_;
126}
127
128
130{
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"
143 }
144
145 return filePtrs_[i];
146}
147
148
150{
152
153 return true;
154}
155
157// ************************************************************************* //
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition UPstream.H:1714
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
virtual void resetNames(const wordList &names)
Reset the list of names from a wordList.
Definition logFiles.C:48
virtual void createFiles()
Create the output file.
Definition logFiles.C:28
PtrList< OFstream > filePtrs_
File pointer.
Definition logFiles.H:72
PtrList< OFstream > & files()
Return access to the files.
Definition logFiles.C:109
virtual void resetName(const word &name)
Reset the list of names to a single name entry.
Definition logFiles.C:63
wordList names_
File names.
Definition logFiles.H:67
const wordList & names() const
Return const access to the names.
Definition logFiles.C:103
virtual bool write()
Write function.
Definition logFiles.C:142
Base class for writing single files from the function objects.
Definition writeFile.H:113
virtual autoPtr< OFstream > newFileAtStartTime(const word &name) const
Return autoPtr to a new file using the simulation start time.
Definition writeFile.C:156
writeFile(const objectRegistry &obr, const fileName &prefix, const word &name="undefined", const bool writeToFile=true, const string &ext=".dat")
Construct from objectRegistry, prefix, fileName.
Definition writeFile.C:200
virtual bool read(const dictionary &dict)
Read.
Definition writeFile.C:240
void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition writeFile.C:35
virtual void resetFile(const word &name)
Reset internal file pointer to new file with new name.
Definition writeFile.C:165
const objectRegistry & fileObr_
Reference to the region objectRegistry.
Definition writeFile.H:121
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
auto & names
List< word > wordList
List of word.
Definition fileName.H:60
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299