fieldMinMax.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) 2011-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 "fieldMinMax.H"
27 #include "fieldTypes.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(fieldMinMax, 0);
34 
35  template<>
36  const char* NamedEnum
37  <
39  2
40  >::names[] =
41  {
42  "magnitude",
43  "component"
44  };
45 }
46 
47 
50 
51 
52 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
53 
55 {
56  writeHeader(os, "Field minima and maxima");
57  writeCommented(os, "Time");
58 
59  if (writeLocation_)
60  {
61  writeTabbed(os, "field");
62  writeTabbed(os, "min");
63  writeTabbed(os, "position(min)");
64 
65  if (Pstream::parRun())
66  {
67  writeTabbed(os, "processor");
68  }
69 
70  writeTabbed(os, "max");
71  writeTabbed(os, "position(max)");
72 
73  if (Pstream::parRun())
74  {
75  writeTabbed(os, "processor");
76  }
77  }
78  else
79  {
80  forAll(fieldSet_, fieldI)
81  {
82  writeTabbed(os, "min(" + fieldSet_[fieldI] + ')');
83  writeTabbed(os, "max(" + fieldSet_[fieldI] + ')');
84  }
85  }
86 
87  os << endl;
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
94 (
95  const word& name,
96  const objectRegistry& obr,
97  const dictionary& dict,
98  const bool loadFromFiles
99 )
100 :
102  functionObjectFile(obr, name, typeName, dict),
103  obr_(obr),
104  log_(true),
105  writeLocation_(true),
106  mode_(mdMag),
107  fieldSet_()
108 {
109  // Check if the available mesh is an fvMesh otherise deactivate
110  if (setActive<fvMesh>())
111  {
112  read(dict);
113  writeFileHeader(file());
114  }
115 }
116 
117 
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
119 
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 {
128  if (active_)
129  {
131 
132  log_ = dict.lookupOrDefault<Switch>("log", true);
133  writeLocation_ = dict.lookupOrDefault<Switch>("writeLocation", true);
134 
135  mode_ = modeTypeNames_[dict.lookupOrDefault<word>("mode", "magnitude")];
136  dict.lookup("fields") >> fieldSet_;
137  }
138 }
139 
140 
142 {
143  // Do nothing - only valid on write
144 }
145 
146 
148 {
149  // Do nothing - only valid on write
150 }
151 
152 
154 {
155  // Do nothing - only valid on write
156 }
157 
158 
160 {
161  if (active_)
162  {
163  if (!writeLocation_) writeTime(file());
164 
165  if (log_) Info<< type() << " " << name_ << " output:" << nl;
166 
167  forAll(fieldSet_, fieldI)
168  {
169  calcMinMaxFields<scalar>(fieldSet_[fieldI], mdCmpt);
170  calcMinMaxFields<vector>(fieldSet_[fieldI], mode_);
171  calcMinMaxFields<sphericalTensor>(fieldSet_[fieldI], mode_);
172  calcMinMaxFields<symmTensor>(fieldSet_[fieldI], mode_);
173  calcMinMaxFields<tensor>(fieldSet_[fieldI], mode_);
174  }
175 
176  if (!writeLocation_) file()<< endl;
177  if (log_) Info<< endl;
178  }
179 }
180 
181 
182 
183 // ************************************************************************* //
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fieldMinMax::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: fieldMinMax.C:153
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::fieldMinMax::~fieldMinMax
virtual ~fieldMinMax()
Destructor.
Definition: fieldMinMax.C:120
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::functionObjectFile::writeTabbed
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: functionObjectFile.C:230
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
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::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
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::fieldMinMax::modeType
modeType
Definition: fieldMinMax.H:145
fieldMinMax.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
modeTypeNames_
const Foam::NamedEnum< Foam::scene::modeType, 2 > modeTypeNames_
Definition: scene.C:53
Foam::fieldMinMax::fieldSet_
wordList fieldSet_
Fields to assess min/max.
Definition: fieldMinMax.H:172
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::fieldMinMax::read
virtual void read(const dictionary &)
Read the field min/max data.
Definition: fieldMinMax.C:126
Foam::fieldMinMax::execute
virtual void execute()
Execute, currently does nothing.
Definition: fieldMinMax.C:141
Foam::fieldMinMax::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: fieldMinMax.C:147
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fieldMinMax::write
virtual void write()
Write the fieldMinMax.
Definition: fieldMinMax.C:159
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::fieldMinMax::fieldMinMax
fieldMinMax(const fieldMinMax &)
Disallow default bitwise copy construct.
Foam::functionObjectFile
Base class for output file data handling.
Definition: functionObjectFile.H:57
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::fieldMinMax::writeLocation_
Switch writeLocation_
Switch to write location of min/max values.
Definition: fieldMinMax.H:166
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::functionObjectFile::writeCommented
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: functionObjectFile.C:219
fieldTypes.H
Include the header files for all the primitive types that Fields are instantiated for.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::fieldMinMax::modeTypeNames_
static const NamedEnum< modeType, 2 > modeTypeNames_
Mode type names.
Definition: fieldMinMax.H:157
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::fieldMinMax::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Output file header information.
Definition: fieldMinMax.C:54
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52