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-------------------------------------------------------------------------------
11License
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
35namespace Foam
36{
37namespace functionObjects
38{
41}
42}
43
44const 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
65 {
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// ************************************************************************* //
#define Log
Definition: PDRblock.C:35
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Abstract base-class for Time/database function objects.
Computes the values and locations of field minima and maxima. These are good indicators of calculatio...
Definition: fieldMinMax.H:177
volFieldSelection fieldSet_
Fields to assess min/max.
Definition: fieldMinMax.H:204
bool location_
Flag to write location of min/max values.
Definition: fieldMinMax.H:198
static const Enum< modeType > modeTypeNames_
Mode type names.
Definition: fieldMinMax.H:195
virtual void writeFileHeader(Ostream &os)
Output file header information.
Definition: fieldMinMax.C:57
virtual bool execute()
Execute, currently does nothing.
Definition: fieldMinMax.C:145
virtual bool write()
Write the fieldMinMax.
Definition: fieldMinMax.C:151
virtual bool read(const dictionary &)
Read the field min/max data.
Definition: fieldMinMax.C:130
wordHashSet selectionNames() const
Return the current field selection.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual bool updateSelection()
Update the selection using current contents of obr_.
Base class for writing single files from the function objects.
Definition: writeFile.H:120
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:285
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:295
virtual void writeBreak(Ostream &os) const
Write a break marker to the stream.
Definition: writeFile.C:318
bool writtenHeader_
Flag to identify whether the header has been written.
Definition: writeFile.H:148
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:233
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:269
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
Header files for all the primitive types that Fields are instantiated for.
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict