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-2016 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 // * * * * * * * * * * * * * Private 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  writeFiles(name, runTime, dict, name),
107  location_(true),
108  mode_(mdMag),
109  fieldSet_()
110 {
111  if (!isA<fvMesh>(obr_))
112  {
114  << "objectRegistry is not an fvMesh" << exit(FatalError);
115  }
116 
117  read(dict);
118  resetName(typeName);
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
131 {
132  writeFiles::read(dict);
133 
134  location_ = dict.lookupOrDefault<Switch>("location", true);
135 
136  mode_ = modeTypeNames_[dict.lookupOrDefault<word>("mode", "magnitude")];
137  dict.lookup("fields") >> fieldSet_;
138 
139  return true;
140 }
141 
142 
144 {
145  return true;
146 }
147 
148 
150 {
152 
153  if (!location_) writeTime(file());
154  Log << type() << " " << name() << " write:" << nl;
155 
156  forAll(fieldSet_, fieldi)
157  {
158  calcMinMaxFields<scalar>(fieldSet_[fieldi], mdCmpt);
159  calcMinMaxFields<vector>(fieldSet_[fieldi], mode_);
160  calcMinMaxFields<sphericalTensor>(fieldSet_[fieldi], mode_);
161  calcMinMaxFields<symmTensor>(fieldSet_[fieldi], mode_);
162  calcMinMaxFields<tensor>(fieldSet_[fieldi], mode_);
163  }
164 
165  if (!location_) file()<< endl;
166  Log << endl;
167 
168  return true;
169 }
170 
171 
172 
173 // ************************************************************************* //
virtual bool write()
Write the fieldMinMax.
Definition: fieldMinMax.C:149
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:143
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
fieldMinMax(const fieldMinMax &)
Disallow default bitwise copy construct.
Output to file stream.
Definition: OFstream.H:81
functionObject base class for writing files
Definition: writeFiles.H:56
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
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
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
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:130
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:124
static const char nl
Definition: Ostream.H:262
static const NamedEnum< modeType, 2 > modeTypeNames_
Mode type names.
Definition: fieldMinMax.H:140
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:393
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
addToRunTimeSelectionTable(functionObject, blendingFactor, dictionary)
virtual bool write()
Write function.
Definition: writeFiles.C:197
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451