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-2021 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 {
35  defineTypeNameAndDebug(residuals, 0);
36 
38  (
39  functionObject,
40  residuals,
41  dictionary
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  if (Pstream::master())
87  {
88  writeHeader(file(), "Residuals");
89  writeCommented(file(), "Time");
90 
91  forAll(fieldSet_, fieldi)
92  {
93  const word& fieldName = fieldSet_[fieldi];
94 
95  writeFileHeader<scalar>(fieldName);
96  writeFileHeader<vector>(fieldName);
97  writeFileHeader<sphericalTensor>(fieldName);
98  writeFileHeader<symmTensor>(fieldName);
99  writeFileHeader<tensor>(fieldName);
100  }
101 
102  file() << endl;
103  }
104 }
105 
106 
108 {
109  return true;
110 }
111 
112 
114 {
115  logFiles::write();
116 
117  if (Pstream::master())
118  {
119  writeTime(file());
120 
121  forAll(fieldSet_, fieldi)
122  {
123  const word& fieldName = fieldSet_[fieldi];
124 
125  writeResidual<scalar>(fieldName);
126  writeResidual<vector>(fieldName);
127  writeResidual<sphericalTensor>(fieldName);
128  writeResidual<symmTensor>(fieldName);
129  writeResidual<tensor>(fieldName);
130  }
131 
132  file() << endl;
133  }
134 
135  return true;
136 }
137 
138 
139 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual bool write()
Write function.
Definition: logFiles.C:167
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
virtual bool write()
Write the residuals.
Definition: residuals.C:113
virtual bool execute()
Execute, currently does nothing.
Definition: residuals.C:107
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
void writeFileHeader(const word &fieldName)
Output field header information.
virtual bool read(const dictionary &)
Read the controls.
Definition: residuals.C:72
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
A class for handling words, derived from string.
Definition: word.H:59
defineTypeNameAndDebug(Qdot, 0)
virtual ~residuals()
Destructor.
Definition: residuals.C:66
residuals(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: residuals.C:50
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57