residuals.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) 2015-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 "residuals.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace functionObjects
34 {
36 
38  (
40  residuals,
42  );
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const word& name,
52  const Time& runTime,
53  const dictionary& dict
54 )
55 :
56  fvMeshFunctionObject(name, runTime, dict),
57  logFiles(obr_, name),
58  fieldSet_()
59 {
60  read(dict);
61 }
62 
63 
64 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
65 
67 {}
68 
69 
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 
73 {
75 
76  dict.lookup("fields") >> fieldSet_;
77 
78  resetName(typeName);
79 
80  return true;
81 }
82 
83 
85 {
86  writeHeader(file(), "Residuals");
87  writeCommented(file(), "Time");
88 
89  forAll(fieldSet_, fieldi)
90  {
91  const word& fieldName = fieldSet_[fieldi];
92 
93  #define WRITE_FILE_HEADER(Type, nullArg) \
94  writeFileHeader<Type>(fieldName);
96  #undef WRITE_FILE_HEADER
97  }
98 
99  file() << endl;
100 }
101 
102 
104 {
105  return true;
106 }
107 
108 
110 {
111  logFiles::write();
112 
113  if (Pstream::master())
114  {
115  writeTime(file());
116 
117  forAll(fieldSet_, fieldi)
118  {
119  const word& fieldName = fieldSet_[fieldi];
120 
121  #define WRITE_RESIDUAL(Type, nullArg) \
122  writeResidual<Type>(fieldName);
124  #undef WRITE_RESIDUAL
125  }
126 
127  file() << endl;
128  }
129 
130  return true;
131 }
132 
133 
134 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
Macros for easy insertion into run-time selection tables.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
virtual bool write()
Write function.
Definition: logFiles.C:173
virtual bool read(const dictionary &)
Read optional controls.
Writes out the initial residual for specified fields.
Definition: residuals.H:83
residuals(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: residuals.C:50
virtual ~residuals()
Destructor.
Definition: residuals.C:66
void writeFileHeader(const word &fieldName)
Output field header information.
virtual bool execute()
Execute, currently does nothing.
Definition: residuals.C:103
virtual bool write()
Write the residuals.
Definition: residuals.C:109
virtual bool read(const dictionary &)
Read the controls.
Definition: residuals.C:72
A class for handling words, derived from string.
Definition: word.H:62
#define WRITE_RESIDUAL(Type, nullArg)
#define WRITE_FILE_HEADER(Type, nullArg)
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
dictionary dict