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-2018 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 
49 Foam::functionObjects::residuals::residuals
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  resetName(typeName);
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
66 
68 {}
69 
70 
71 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72 
74 {
76 
77  dict.lookup("fields") >> fieldSet_;
78 
79  return true;
80 }
81 
82 
84 {
85  if (Pstream::master())
86  {
87  writeHeader(file(), "Residuals");
88  writeCommented(file(), "Time");
89 
90  forAll(fieldSet_, fieldi)
91  {
92  const word& fieldName = fieldSet_[fieldi];
93 
94  writeFileHeader<scalar>(fieldName);
95  writeFileHeader<vector>(fieldName);
96  writeFileHeader<sphericalTensor>(fieldName);
97  writeFileHeader<symmTensor>(fieldName);
98  writeFileHeader<tensor>(fieldName);
99  }
100 
101  file() << endl;
102  }
103 }
104 
105 
107 {
108  return true;
109 }
110 
111 
113 {
114  logFiles::write();
115 
116  if (Pstream::master())
117  {
118  writeTime(file());
119 
120  forAll(fieldSet_, fieldi)
121  {
122  const word& fieldName = fieldSet_[fieldi];
123 
124  writeResidual<scalar>(fieldName);
125  writeResidual<vector>(fieldName);
126  writeResidual<sphericalTensor>(fieldName);
127  writeResidual<symmTensor>(fieldName);
128  writeResidual<tensor>(fieldName);
129  }
130 
131  file() << endl;
132  }
133 
134  return true;
135 }
136 
137 
138 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
virtual bool write()
Write function.
Definition: logFiles.C:180
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:112
virtual bool execute()
Execute, currently does nothing.
Definition: residuals.C:106
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void writeFileHeader(const word &fieldName)
Output field header information.
virtual bool read(const dictionary &)
Read the controls.
Definition: residuals.C:73
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:421
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
A class for handling words, derived from string.
Definition: word.H:59
virtual ~residuals()
Destructor.
Definition: residuals.C:67
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, add, dictionary)
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57