limitFields.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) 2019 OpenCFD Ltd
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "limitFields.H"
29#include "fieldTypes.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
36namespace functionObjects
37{
40}
41}
42
43const Foam::Enum
44<
46>
48({
49 { limitType::MIN, "min" },
50 { limitType::MAX, "max" },
51 { limitType::BOTH, "both" },
52});
53
54
55// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
56
58(
59 const word& fieldName
60)
61{
62 auto* fieldPtr = obr_.getObjectPtr<volScalarField>(fieldName);
63 if (!fieldPtr)
64 {
65 return false;
66 }
67
68 auto& field = *fieldPtr;
69
70 if (limit_ & MIN)
71 {
72 Log << ": min(" << gMin(field) << ")";
73 field.max(dimensionedScalar("", field.dimensions(), min_));
74 }
75
76 if (limit_ & MAX)
77 {
78 Log << ": max(" << gMax(field) << ")";
79 field.min(dimensionedScalar("", field.dimensions(), max_));
80 }
81
82 return true;
83}
84
85
86// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87
89(
90 const word& name,
91 const Time& runTime,
92 const dictionary& dict
93)
94:
96 limit_(MIN),
97 fieldSet_(mesh_),
98 min_(-VGREAT),
99 max_(VGREAT)
100{
101 read(dict);
102}
103
104
105// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106
108{
110 {
111 Info<< type() << " " << name() << ":" << nl;
112
113 limit_ = limitTypeNames_.get("limit", dict);
114
115 if (limit_ & MIN)
116 {
117 min_ = dict.get<scalar>("min");
118 Info<< " Imposing lower limit " << min_ << nl;
119 }
120
121 if (limit_ & MAX)
122 {
123 max_ = dict.get<scalar>("max");
124 Info<< " Imposing upper limit " << max_ << nl;
125 }
126
127 fieldSet_.read(dict);
128
129 Info<< endl;
130
131 return true;
132 }
133
134 return false;
135}
136
137
139{
140 fieldSet_.updateSelection();
141
142 Log << type() << " " << name() << ":" << nl;
143
144 label count = 0;
145 for (const word& fieldName : fieldSet_.selectionNames())
146 {
147 if
148 (
149 limitScalarField(fieldName)
150 || limitField<vector>(fieldName)
151 || limitField<sphericalTensor>(fieldName)
152 || limitField<symmTensor>(fieldName)
153 || limitField<tensor>(fieldName)
154 )
155 {
156 ++count;
157 }
158 }
159
160 if (debug)
161 {
162 Log << " - limited " << count << '/'
163 << fieldSet_.selectionNames().size() << " fields";
164 }
165
166 Log << endl;
167
168 return true;
169}
170
171
173{
174 for (const word& fieldName : fieldSet_.selectionNames())
175 {
176 lookupObject<regIOobject>(fieldName).write();
177 }
178
179 return true;
180}
181
182
183// ************************************************************************* //
#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
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
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.
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Limits input fields to user-specified min and max bounds.
Definition: limitFields.H:180
@ MIN
limit by minimum value
Definition: limitFields.H:187
@ MAX
limit by maximum value
Definition: limitFields.H:188
limitType limit_
Limiting type.
Definition: limitFields.H:201
bool limitScalarField(const word &fieldName)
Limit a scalar field.
Definition: limitFields.C:58
static const Enum< limitType > limitTypeNames_
Limit type names.
Definition: limitFields.H:198
virtual bool read(const dictionary &dict)
Read the field min/max data.
Definition: limitFields.C:107
virtual bool execute()
Execute, currently does nothing.
Definition: limitFields.C:138
virtual bool write()
Write the limitFields.
Definition: limitFields.C:172
const objectRegistry & obr_
Reference to the region objectRegistry.
Type * getObjectPtr(const word &name, const bool recursive=false) const
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
rDeltaTY field()
engineTime & runTime
Header files for all the primitive types that Fields are instantiated for.
Namespace for OpenFOAM.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
messageStream Info
Information stream (stdout output on master, null elsewhere)
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
Type gMin(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Type gMax(const FieldField< Field, Type > &f)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict