logFile.H
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 Class
25  Foam::functionObjects::logFile
26 
27 Description
28  functionObject support for writing log files
29 
30  e.g. residuals or integral field values vs time.
31 
32 See also
33  Foam::functionObject
34  Foam::functionObjects::writeFile
35 
36 SourceFiles
37  logFile.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef functionObjects_logFile_H
42 #define functionObjects_logFile_H
43 
44 #include "writeFile.H"
45 #include "OFstream.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 namespace functionObjects
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class logFile Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class logFile
59 :
60  public writeFile
61 {
62  // Private data
63 
64  //- File name
65  word name_;
66 
67  //- File stream
68  OFstream file_;
69 
70 
71  // Private member functions
72 
73  fileName filePathName() const;
74 
75 
76 public:
77 
78  // Constructors
79 
80  //- Construct from objectRegistry, prefix and file name
81  logFile
82  (
83  const objectRegistry& obr,
84  const word& prefix,
85  const word& name
86  );
87 
88  //- Disallow default bitwise copy construction
89  logFile(const logFile&) = delete;
90 
91 
92  //- Destructor
93  ~logFile();
94 
95 
96  // Member Functions
97 
98  //- Return the log file name
99  const word& name() const;
100 
101  //- Write the time and column headers
102  void writeTimeColumnHeaders(const wordList& titles);
103 
104  //- Write a single column value
105  template<class T>
106  void write(const T& t)
107  {
108  file_ << tab << setw(charWidth()) << t << endl;
109  }
110 
111  //- Write the column values
112  template<class T, class... Args>
113  void write(const T& t, const Args& ... args)
114  {
115  file_ << tab << setw(charWidth()) << t;
116  write(args...);
117  }
118 
119  //- Write the time and column values
120  template<class... Args>
121  void writeTime(const Args& ... args)
122  {
123  writeFile::writeTime(file_);
124  write(args...);
125  }
126 
127 
128  // Member Operators
129 
130  //- Disallow default bitwise assignment
131  void operator=(const logFile&) = delete;
132 };
133 
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 } // End namespace functionObjects
138 } // End namespace Foam
139 
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
141 
142 #endif
143 
144 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:86
A class for handling file names.
Definition: fileName.H:82
functionObject support for writing log files
Definition: logFile.H:60
logFile(const objectRegistry &obr, const word &prefix, const word &name)
Construct from objectRegistry, prefix and file name.
Definition: logFile.C:44
void writeTime(const Args &... args)
Write the time and column values.
Definition: logFile.H:120
void operator=(const logFile &)=delete
Disallow default bitwise assignment.
void write(const T &t)
Write a single column value.
Definition: logFile.H:105
const word & name() const
Return the log file name.
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
void writeTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:141
label charWidth() const
Return width of character stream output.
Definition: writeFile.C:103
Registry of regIOobjects.
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
Omanip< int > setw(const int i)
Definition: IOmanip.H:199
static const char tab
Definition: Ostream.H:265
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::argList args(argc, argv)