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 | Copyright (C) 2015 OpenCFD Ltd.
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 
39 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
40 
42 {
43  writeHeader(os, "Residuals");
44  writeCommented(os, "Time");
45 
46  forAll(fieldSet_, fieldI)
47  {
48  writeTabbed(os, fieldSet_[fieldI]);
49  }
50 
51  os << endl;
52 }
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 (
59  const word& name,
60  const objectRegistry& obr,
61  const dictionary& dict,
62  const bool loadFromFiles
63 )
64 :
65  functionObjectFile(obr, name, typeName, dict),
66  name_(name),
67  obr_(obr),
68  active_(true),
69  fieldSet_()
70 {
71  // Check if the available mesh is an fvMesh otherwise deactivate
72  if (!isA<fvMesh>(obr_))
73  {
74  active_ = false;
76  << "No fvMesh available, deactivating " << name_
77  << endl;
78  }
79 
80  if (active_)
81  {
82  read(dict);
83  writeFileHeader(file());
84  }
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
89 
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
97 {
98  if (active_)
99  {
101 
102  wordList allFields(dict.lookup("fields"));
103  wordHashSet uniqueFields(allFields);
104  fieldSet_ = uniqueFields.toc();
105  }
106 }
107 
108 
110 {}
111 
112 
114 {}
115 
116 
118 {}
119 
120 
122 {
123  if (active_)
124  {
125  if (Pstream::master())
126  {
127  writeTime(file());
128 
129  forAll(fieldSet_, fieldI)
130  {
131  const word& fieldName = fieldSet_[fieldI];
132 
133  writeResidual<scalar>(fieldName);
134  writeResidual<vector>(fieldName);
135  writeResidual<sphericalTensor>(fieldName);
136  writeResidual<symmTensor>(fieldName);
137  writeResidual<tensor>(fieldName);
138  }
139 
140  file() << endl;
141  }
142  }
143 }
144 
145 
146 // ************************************************************************* //
volFields.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::HashTable::toc
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::residuals::residuals
residuals(const residuals &)
Disallow default bitwise copy construct.
Foam::functionObjectFile::writeTabbed
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: functionObjectFile.C:230
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::residuals::writeFileHeader
void writeFileHeader(const word &fieldName)
Output field header information.
Foam::functionObjectFile::read
void read(const dictionary &dict)
Read.
Definition: functionObjectFile.C:178
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::HashSet
A HashTable with keys but without contents.
Definition: HashSet.H:59
Foam::residuals::~residuals
virtual ~residuals()
Destructor.
Definition: residuals.C:90
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::residuals::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: residuals.C:113
residuals.H
Foam::residuals::read
virtual void read(const dictionary &)
Read the field residuals data.
Definition: residuals.C:96
Foam::residuals::fieldSet_
wordList fieldSet_
Fields to write residuals.
Definition: residuals.H:106
Foam::residuals::execute
virtual void execute()
Execute, currently does nothing.
Definition: residuals.C:109
Foam::residuals::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: residuals.C:117
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::functionObjectFile::writeHeader
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: functionObjectFile.C:240
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:399
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::functionObjectFile
Base class for output file data handling.
Definition: functionObjectFile.H:57
dictionary.H
Foam::residuals::write
virtual void write()
Write the residuals.
Definition: residuals.C:121
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::functionObjectFile::writeCommented
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: functionObjectFile.C:219
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47