residuals.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2015-2016 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  writeFiles(name, runTime, dict, name),
57  fieldSet_()
58 {
59  if (!isA<fvMesh>(obr_))
60  {
62  << "objectRegistry is not an fvMesh" << exit(FatalError);
63  }
64 
65  read(dict);
66  resetName(typeName);
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
71 
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
79 {
80  dict.lookup("fields") >> fieldSet_;
81 
82  return true;
83 }
84 
85 
87 {
88  if (Pstream::master())
89  {
90  writeHeader(file(), "Residuals");
91  writeCommented(file(), "Time");
92 
93  forAll(fieldSet_, fieldi)
94  {
95  const word& fieldName = fieldSet_[fieldi];
96 
97  writeFileHeader<scalar>(fieldName);
98  writeFileHeader<vector>(fieldName);
99  writeFileHeader<sphericalTensor>(fieldName);
100  writeFileHeader<symmTensor>(fieldName);
101  writeFileHeader<tensor>(fieldName);
102  }
103 
104  file() << endl;
105  }
106 }
107 
108 
110 {
111  return true;
112 }
113 
114 
116 {
118 
119  if (Pstream::master())
120  {
121  writeTime(file());
122 
123  forAll(fieldSet_, fieldi)
124  {
125  const word& fieldName = fieldSet_[fieldi];
126 
127  writeResidual<scalar>(fieldName);
128  writeResidual<vector>(fieldName);
129  writeResidual<sphericalTensor>(fieldName);
130  writeResidual<symmTensor>(fieldName);
131  writeResidual<tensor>(fieldName);
132  }
133 
134  file() << endl;
135  }
136 
137  return true;
138 }
139 
140 
141 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:115
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool execute()
Execute, currently does nothing.
Definition: residuals.C:109
error FatalError
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.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
functionObject base class for writing files
Definition: writeFiles.H:56
virtual bool read(const dictionary &)
Read the controls.
Definition: residuals.C:78
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:411
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.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
addToRunTimeSelectionTable(functionObject, blendingFactor, dictionary)
virtual ~residuals()
Destructor.
Definition: residuals.C:72
virtual bool write()
Write function.
Definition: writeFiles.C:197
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451