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 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"
27 #include "volFields.H"
28 #include "dictionary.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(residuals, 0);
36 }
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 (
42  const word& name,
43  const objectRegistry& obr,
44  const dictionary& dict,
45  const bool loadFromFiles
46 )
47 :
48  functionObjectFile(obr, name, typeName),
49  name_(name),
50  obr_(obr),
51  active_(true),
52  fieldSet_()
53 {
54  // Check if the available mesh is an fvMesh otherwise deactivate
55  if (!isA<fvMesh>(obr_))
56  {
57  active_ = false;
58  WarningIn
59  (
60  "residuals::residuals"
61  "("
62  "const word&, "
63  "const objectRegistry&, "
64  "const dictionary&, "
65  "const bool"
66  ")"
67  ) << "No fvMesh available, deactivating " << name_
68  << endl;
69  }
70 
71  read(dict);
72 }
73 
74 
75 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
76 
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
82 
84 {
85  if (active_)
86  {
87  dict.lookup("fields") >> fieldSet_;
88  }
89 }
90 
91 
93 {
94  if (Pstream::master())
95  {
96  writeHeader(file(), "Residuals");
97  writeCommented(file(), "Time");
98 
99  forAll(fieldSet_, fieldI)
100  {
101  writeTabbed(file(), fieldSet_[fieldI]);
102  }
103 
104  file() << endl;
105  }
106 }
107 
108 
110 {
111  // Do nothing - only valid on write
112 }
113 
114 
116 {
117  // Do nothing - only valid on write
118 }
119 
120 
122 {
123  // Do nothing - only valid on write
124 }
125 
126 
128 {
129  if (active_)
130  {
132 
133  if (Pstream::master())
134  {
135  file()<< obr_.time().value();
136 
137  forAll(fieldSet_, fieldI)
138  {
139  const word& fieldName = fieldSet_[fieldI];
140 
141  writeResidual<scalar>(fieldName);
142  writeResidual<vector>(fieldName);
143  writeResidual<sphericalTensor>(fieldName);
144  writeResidual<symmTensor>(fieldName);
145  writeResidual<tensor>(fieldName);
146  }
147 
148  file() << endl;
149  }
150  }
151 }
152 
153 // ************************************************************************* //
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: residuals.C:121
virtual ~residuals()
Destructor.
Definition: residuals.C:77
A class for handling words, derived from string.
Definition: word.H:59
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
#define forAll(list, i)
Definition: UList.H:421
virtual void writeFileHeader(const label i)
Output file header information.
Definition: residuals.C:92
virtual void write()
Write function.
residuals(const residuals &)
Disallow default bitwise copy construct.
virtual void execute()
Execute, currently does nothing.
Definition: residuals.C:109
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
virtual void write()
Write the residuals.
Definition: residuals.C:127
Registry of regIOobjects.
Base class for output file data handling.
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:398
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: residuals.C:115
virtual void read(const dictionary &)
Read the field min/max data.
Definition: residuals.C:83
defineTypeNameAndDebug(combustionModel, 0)