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 -------------------------------------------------------------------------------
11 License
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 
81 Foam::functionObjects::logFiles::logFiles
82 (
83  const objectRegistry& obr,
84  const word& prefix
85 )
86 :
87  writeFile(obr, prefix),
88  names_(),
89  filePtrs_()
90 {}
91 
92 
93 Foam::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_()
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 
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"
142  << abort(FatalError);
143  }
144 
145  return filePtrs_[i];
146 }
147 
148 
150 {
151  createFiles();
152 
153  return true;
154 }
155 
156 
157 // ************************************************************************* //
Foam::functionObjects::logFiles::filePtrs_
PtrList< OFstream > filePtrs_
File pointer.
Definition: logFiles.H:72
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::writeFile::fileObr_
const objectRegistry & fileObr_
Reference to the region objectRegistry.
Definition: writeFile.H:126
Foam::functionObjects::logFiles::files
PtrList< OFstream > & files()
Return access to the files.
Definition: logFiles.C:116
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:434
Foam::functionObjects::logFiles::names_
wordList names_
File names.
Definition: logFiles.H:69
Foam::functionObjects::logFiles::resetName
virtual void resetName(const word &name)
Reset the list of names to a single name entry.
Definition: logFiles.C:70
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:213
Foam::PtrList< Foam::OFstream >
IFstream.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::functionObjects::writeFile::initStream
void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: writeFile.C:42
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
logFiles.H
Foam::functionObjects::logFiles::resetNames
virtual void resetNames(const wordList &names)
Reset the list of names from a wordList.
Definition: logFiles.C:55
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::functionObjects::writeFile::createFile
virtual autoPtr< OFstream > createFile(const word &name, scalar timeValue) const
Return autoPtr to a new file for a given time.
Definition: writeFile.C:83
Foam::List< word >
Foam::functionObjects::writeFile::resetFile
virtual void resetFile(const word &name)
Reset internal file pointer to new file with new name.
Definition: writeFile.C:137
Foam::functionObjects::logFiles::names
const wordList & names() const
Return const access to the names.
Definition: logFiles.C:110
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::PtrListOps::names
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Foam::functionObjects::logFiles::write
virtual bool write()
Write function.
Definition: logFiles.C:149
Foam::Time::startTime
virtual dimensionedScalar startTime() const
Return start time.
Definition: Time.C:867
Foam::functionObjects::logFiles::createFiles
virtual void createFiles()
Create the output file.
Definition: logFiles.C:35
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178