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 |
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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
55 (
56  const word& name,
57  const objectRegistry& obr,
58  const dictionary& dict,
59  const bool loadFromFiles
60 )
61 :
62  functionObjectFile(obr, name, typeName),
63  name_(name),
64  obr_(obr),
65  active_(true),
66  log_(true),
67  location_(true),
68  mode_(mdMag),
69  fieldSet_()
70 {
71  // Check if the available mesh is an fvMesh otherise deactivate
72  if (!isA<fvMesh>(obr_))
73  {
74  active_ = false;
75  WarningIn
76  (
77  "fieldMinMax::fieldMinMax"
78  "("
79  "const word&, "
80  "const objectRegistry&, "
81  "const dictionary&, "
82  "const bool"
83  ")"
84  ) << "No fvMesh available, deactivating " << name_
85  << endl;
86  }
87 
88  read(dict);
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
93 
95 {}
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 {
102  if (active_)
103  {
104  log_ = dict.lookupOrDefault<Switch>("log", true);
105  location_ = dict.lookupOrDefault<Switch>("location", true);
106 
107  mode_ = modeTypeNames_[dict.lookupOrDefault<word>("mode", "magnitude")];
108  dict.lookup("fields") >> fieldSet_;
109  }
110 }
111 
112 
114 {
115  OFstream& file = this->file();
116 
117  writeHeader(file, "Field minima and maxima");
118  writeCommented(file, "Time");
119 
120  if (location_)
121  {
122  writeTabbed(file, "field");
123 
124  writeTabbed(file, "min");
125  writeTabbed(file, "location(min)");
126 
127  if (Pstream::parRun())
128  {
129  writeTabbed(file, "processor");
130  }
131 
132  writeTabbed(file, "max");
133  writeTabbed(file, "location(max)");
134 
135  if (Pstream::parRun())
136  {
137  writeTabbed(file, "processor");
138  }
139  }
140  else
141  {
142  forAll(fieldSet_, fieldI)
143  {
144  writeTabbed(file, "min(" + fieldSet_[fieldI] + ')');
145  writeTabbed(file, "max(" + fieldSet_[fieldI] + ')');
146  }
147  }
148 
149  file<< endl;
150 }
151 
152 
154 {
155  // Do nothing - only valid on write
156 }
157 
158 
160 {
161  // Do nothing - only valid on write
162 }
163 
164 
166 {
167  // Do nothing - only valid on write
168 }
169 
170 
172 {
173  if (active_)
174  {
176 
177  if (!location_) file()<< obr_.time().value();
178  if (log_) Info<< type() << " " << name_ << " output:" << nl;
179 
180  forAll(fieldSet_, fieldI)
181  {
182  calcMinMaxFields<scalar>(fieldSet_[fieldI], mdCmpt);
183  calcMinMaxFields<vector>(fieldSet_[fieldI], mode_);
184  calcMinMaxFields<sphericalTensor>(fieldSet_[fieldI], mode_);
185  calcMinMaxFields<symmTensor>(fieldSet_[fieldI], mode_);
186  calcMinMaxFields<tensor>(fieldSet_[fieldI], mode_);
187  }
188 
189  if (!location_) file()<< endl;
190  if (log_) Info<< endl;
191  }
192 }
193 
194 
195 
196 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:81
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:380
virtual void write()
Write the fieldMinMax.
Definition: fieldMinMax.C:171
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: fieldMinMax.C:159
virtual void writeFileHeader(const label i)
Output file header information.
Definition: fieldMinMax.C:113
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 simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
messageStream Info
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
fieldMinMax(const fieldMinMax &)
Disallow default bitwise copy construct.
Namespace for OpenFOAM.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define WarningIn(functionName)
Report a warning using Foam::Warning.
virtual void execute()
Execute, currently does nothing.
Definition: fieldMinMax.C:153
#define forAll(list, i)
Definition: UList.H:421
virtual void read(const dictionary &)
Read the field min/max data.
Definition: fieldMinMax.C:100
virtual ~fieldMinMax()
Destructor.
Definition: fieldMinMax.C:94
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: fieldMinMax.C:165
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
static const NamedEnum< modeType, 2 > modeTypeNames_
Mode type names.
Definition: fieldMinMax.H:146
virtual void write()
Write function.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Registry of regIOobjects.
Base class for output file data handling.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Include the header files for all the primitive types that Fields are instantiated for...
defineTypeNameAndDebug(combustionModel, 0)