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 
105  writtenHeader_ = true;
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:57
Log
#define Log
Definition: PDRblock.C:35
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::writeFile::file
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:236
Foam::functionObjects::writeFile::writtenHeader_
bool writtenHeader_
Flag to identify whether the header has been written.
Definition: writeFile.H:148
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::fieldMinMax::execute
virtual bool execute()
Execute, currently does nothing.
Definition: fieldMinMax.C:145
Foam::functionObjects::fieldMinMax::fieldSet_
volFieldSelection fieldSet_
Fields to assess min/max.
Definition: fieldMinMax.H:204
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::fieldSelection::selectionNames
wordHashSet selectionNames() const
Return the current field selection.
Definition: fieldSelectionI.H:50
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
fieldMinMax.H
Foam::functionObjects::fieldMinMax::write
virtual bool write()
Write the fieldMinMax.
Definition: fieldMinMax.C:151
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:298
Foam::functionObjects::writeFile::writeBreak
virtual void writeBreak(Ostream &os) const
Write a break marker to the stream.
Definition: writeFile.C:321
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:213
Foam::functionObjects::fieldMinMax::modeType
modeType
Definition: fieldMinMax.H:183
Foam::functionObjects::fieldMinMax::writeFileHeader
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: fieldMinMax.C:57
Foam::functionObjects::volFieldSelection::updateSelection
virtual bool updateSelection()
Update the selection using current contents of obr_.
Definition: volFieldSelection.C:46
Foam::functionObjects::fieldMinMax::fieldMinMax
fieldMinMax(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: fieldMinMax.C:112
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:123
Foam::functionObjects::regionFunctionObject::read
virtual bool read(const dictionary &dict)
Read optional controls.
Definition: regionFunctionObject.C:173
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_
Mode type names.
Definition: fieldMinMax.H:195
Foam::functionObjects::fieldMinMax::location_
bool location_
Flag to write location of min/max values.
Definition: fieldMinMax.H:198
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::fieldMinMax::read
virtual bool read(const dictionary &)
Read the field min/max data.
Definition: fieldMinMax.C:130
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:272
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::UPstream::parRun
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(ObukhovLength, 0)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::writeFile
Base class for writing single files from the function objects.
Definition: writeFile.H:119
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
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
Write a tabbed string to stream.
Definition: writeFile.C:288