logFile.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) 2024 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 "logFile.H"
27 #include "Time.H"
28 #include "OSspecific.H"
29 
30 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
31 
32 Foam::fileName Foam::functionObjects::logFile::filePathName() const
33 {
34  const word timeName = fileObr_.time().name();
35  const fileName outputDir(baseFileDir()/prefix_/timeName);
36  mkDir(outputDir);
37  return outputDir/(name_ + ".dat");
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 (
45  const objectRegistry& obr,
46  const word& prefix,
47  const word& name
48 )
49 :
50  writeFile(obr, prefix),
51  name_(name),
52  file_(filePathName())
53 {
54  initStream(file_);
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
59 
61 {}
62 
63 
64 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
65 
67 (
68  const wordList& titles
69 )
70 {
71  writeCommented(file_, "Time");
72  forAll(titles, i)
73  {
74  writeTabbed(file_, titles[i]);
75  }
76  file_ << endl;
77 }
78 
79 
80 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
const word & name() const
Return const reference to name.
A class for handling file names.
Definition: fileName.H:82
logFile(const objectRegistry &obr, const word &prefix, const word &name)
Construct from objectRegistry, prefix and file name.
Definition: logFile.C:44
void writeTimeColumnHeaders(const wordList &titles)
Write the time and column headers.
Definition: logFile.C:67
functionObject base class for writing single files
Definition: writeFile.H:56
fileName baseFileDir() const
Return the base directory for output.
Definition: writeFile.C:49
const word prefix_
Prefix.
Definition: writeFile.H:66
void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: writeFile.C:42
const objectRegistry & fileObr_
Reference to the region objectRegistry.
Definition: writeFile.H:63
Registry of regIOobjects.
const Time & time() const
Return time.
A class for handling words, derived from string.
Definition: word.H:62
word timeName
Definition: getTimeIndex.H:3
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39