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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "fieldMinMax.H"
30 #include "fieldTypes.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
39  defineTypeNameAndDebug(fieldMinMax, 0);
40  addToRunTimeSelectionTable(functionObject, fieldMinMax, dictionary);
41 }
42 }
43 
44 const Foam::Enum
45 <
47 >
49 ({
50  { modeType::mdMag, "magnitude" },
51  { modeType::mdCmpt, "component" },
52 });
53 
54 
55 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
56 
58 {
60  {
61  return;
62  }
63 
64  if (writtenHeader_)
65  {
66  writeBreak(file());
67  }
68  else
69  {
70  writeHeader(os, "Field minima and maxima");
71  }
72 
73  writeCommented(os, "Time");
74 
75  if (location_)
76  {
77  writeTabbed(os, "field");
78  writeTabbed(os, "min");
79  writeTabbed(os, "location(min)");
80 
81  if (Pstream::parRun())
82  {
83  writeTabbed(os, "processor");
84  }
85 
86  writeTabbed(os, "max");
87  writeTabbed(os, "location(max)");
88 
89  if (Pstream::parRun())
90  {
91  writeTabbed(os, "processor");
92  }
93  }
94  else
95  {
96  for (const word& fieldName : fieldSet_.selectionNames())
97  {
98  writeTabbed(os, "min(" + fieldName + ')');
99  writeTabbed(os, "max(" + fieldName + ')');
100  }
101  }
102 
103  os << endl;
104 
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 
112 (
113  const word& name,
114  const Time& runTime,
115  const dictionary& dict
116 )
117 :
119  writeFile(mesh_, name, typeName, dict),
120  location_(true),
121  mode_(mdMag),
122  fieldSet_(mesh_)
123 {
124  read(dict);
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
131 {
134 
135  location_ = dict.getOrDefault("location", true);
136 
137  mode_ = modeTypeNames_.getOrDefault("mode", dict, modeType::mdMag);
138 
139  fieldSet_.read(dict);
140 
141  return true;
142 }
143 
144 
146 {
147  return true;
148 }
149 
150 
152 {
153  writeFileHeader(file());
154 
155  if (!location_) writeCurrentTime(file());
156  Log << type() << " " << name() << " write:" << nl;
157 
158  for (const word& fieldName : fieldSet_.selectionNames())
159  {
160  calcMinMaxFields<scalar>(fieldName, mdCmpt);
161  calcMinMaxFields<vector>(fieldName, mode_);
162  calcMinMaxFields<sphericalTensor>(fieldName, mode_);
163  calcMinMaxFields<symmTensor>(fieldName, mode_);
164  calcMinMaxFields<tensor>(fieldName, mode_);
165  }
166 
167  if (!location_) file()<< endl;
168  Log << endl;
169 
170  return true;
171 }
172 
173 
174 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:53
Log
#define Log
Definition: PDRblock.C:28
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Definition: writeFile.C:229
Foam::functionObjects::writeFile::writtenHeader_
bool writtenHeader_
Definition: writeFile.H:144
Foam::read
bool read(const char *buf, int32_t &val)
Definition: int32.H:125
Foam::functionObjects::fieldMinMax::execute
virtual bool execute()
Definition: fieldMinMax.C:138
Foam::functionObjects::fieldMinMax::fieldSet_
volFieldSelection fieldSet_
Definition: fieldMinMax.H:200
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::functionObjects::fieldSelection::selectionNames
wordHashSet selectionNames() const
Definition: fieldSelectionI.H:43
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:60
fieldMinMax.H
Foam::functionObjects::fieldMinMax::write
virtual bool write()
Definition: fieldMinMax.C:144
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Definition: writeFile.C:291
Foam::functionObjects::writeFile::writeBreak
virtual void writeBreak(Ostream &os) const
Definition: writeFile.C:314
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Definition: writeFile.C:206
Foam::functionObjects::fieldMinMax::modeType
modeType
Definition: fieldMinMax.H:179
Foam::functionObjects::fieldMinMax::writeFileHeader
virtual void writeFileHeader(Ostream &os)
Definition: fieldMinMax.C:50
Foam::functionObjects::volFieldSelection::updateSelection
virtual bool updateSelection()
Definition: volFieldSelection.C:39
Foam::functionObjects::fieldMinMax::fieldMinMax
fieldMinMax(const word &name, const Time &runTime, const dictionary &dict)
Definition: fieldMinMax.C:105
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Definition: regionFunctionObject.C:166
os
OBJstream os(runTime.globalPath()/outputName)
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::functionObjects::fieldMinMax::modeTypeNames_
static const Enum< modeType > modeTypeNames_
Definition: fieldMinMax.H:191
Foam::functionObjects::fieldMinMax::location_
bool location_
Definition: fieldMinMax.H:194
Foam
Definition: atmBoundaryLayer.C:26
Foam::functionObjects::fieldMinMax::read
virtual bool read(const dictionary &)
Definition: fieldMinMax.C:123
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Definition: writeFile.C:265
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::UPstream::parRun
static bool & parRun() noexcept
Definition: UPstream.H:429
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Definition: POSIX.C:717
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:115
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
fieldTypes.H
Header files for all the primitive types that Fields are instantiated for.
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Definition: writeFile.C:281