fieldMinMax.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
36  defineTypeNameAndDebug(fieldMinMax, 0);
37  addToRunTimeSelectionTable(functionObject, fieldMinMax, dictionary);
38 }
39 }
40 
41 template<>
42 const char* Foam::NamedEnum
43 <
45  2
46 >::names[] = {"magnitude", "component"};
47 
48 const Foam::NamedEnum
49 <
51  2
53 
54 
55 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
56 
58 {
59  OFstream& file = this->file();
60 
61  writeHeader(file, "Field minima and maxima");
62  writeCommented(file, "Time");
63 
64  if (location_)
65  {
66  writeTabbed(file, "field");
67 
68  writeTabbed(file, "min");
69  writeTabbed(file, "location(min)");
70 
71  if (Pstream::parRun())
72  {
73  writeTabbed(file, "processor");
74  }
75 
76  writeTabbed(file, "max");
77  writeTabbed(file, "location(max)");
78 
79  if (Pstream::parRun())
80  {
81  writeTabbed(file, "processor");
82  }
83  }
84  else
85  {
86  forAll(fieldSet_, fieldi)
87  {
88  writeTabbed(file, "min(" + fieldSet_[fieldi] + ')');
89  writeTabbed(file, "max(" + fieldSet_[fieldi] + ')');
90  }
91  }
92 
93  file<< endl;
94 }
95 
96 
97 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
98 
100 (
101  const word& name,
102  const Time& runTime,
103  const dictionary& dict
104 )
105 :
106  fvMeshFunctionObject(name, runTime, dict),
107  logFiles(obr_, name),
108  location_(true),
109  mode_(modeType::mag),
110  fieldSet_()
111 {
112  read(dict);
113  resetName(typeName);
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
118 
120 {}
121 
122 
123 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124 
126 {
128 
129  location_ = dict.lookupOrDefault<Switch>("location", true);
130 
131  mode_ = modeTypeNames_[dict.lookupOrDefault<word>("mode", "magnitude")];
132  dict.lookup("fields") >> fieldSet_;
133 
134  return true;
135 }
136 
137 
139 {
140  return true;
141 }
142 
143 
145 {
146  logFiles::write();
147 
148  if (Pstream::master() && !location_) writeTime(file());
149  Log << type() << " " << name() << " write:" << nl;
150 
151  forAll(fieldSet_, fieldi)
152  {
153  calcMinMaxFields<scalar>(fieldSet_[fieldi], modeType::cmpt);
154  calcMinMaxFields<vector>(fieldSet_[fieldi], mode_);
155  calcMinMaxFields<sphericalTensor>(fieldSet_[fieldi], mode_);
156  calcMinMaxFields<symmTensor>(fieldSet_[fieldi], mode_);
157  calcMinMaxFields<tensor>(fieldSet_[fieldi], mode_);
158  }
159 
160  if (Pstream::master() && !location_) file() << endl;
161  Log << endl;
162 
163  return true;
164 }
165 
166 
167 
168 // ************************************************************************* //
virtual bool write()
Write the fieldMinMax.
Definition: fieldMinMax.C:144
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual bool write()
Write function.
Definition: logFiles.C:180
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 execute()
Execute, currently does nothing.
Definition: fieldMinMax.C:138
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
Output to file stream.
Definition: OFstream.H:82
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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/any.
Definition: Switch.H:60
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
fieldMinMax(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: fieldMinMax.C:100
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
virtual void writeFileHeader(const label i)
Output file header information.
Definition: fieldMinMax.C:57
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.
virtual bool read(const dictionary &)
Read optional controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
virtual bool read(const dictionary &)
Read the field min/max data.
Definition: fieldMinMax.C:125
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
Include the header files for all the primitive types that Fields are instantiated for...
A class for handling words, derived from string.
Definition: word.H:59
virtual ~fieldMinMax()
Destructor.
Definition: fieldMinMax.C:119
static const char nl
Definition: Ostream.H:260
static const NamedEnum< modeType, 2 > modeTypeNames_
Mode type names.
Definition: fieldMinMax.H:133
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
defineTypeNameAndDebug(Qdot, 0)
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:399
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
#define Log
Report write to Foam::Info if the local log switch is true.
dimensioned< scalar > mag(const dimensioned< Type > &)
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:57