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 -------------------------------------------------------------------------------
10 License
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 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(limitFields, 0);
39  addToRunTimeSelectionTable(functionObject, limitFields, dictionary);
40 }
41 }
42 
43 const 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 
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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::functionObjects::limitFields::max_
scalar max_
Maximum limit.
Definition: limitFields.H:210
Foam::functionObjects::limitFields::limitScalarField
bool limitScalarField(const word &fieldName)
Limit a scalar field.
Definition: limitFields.C:58
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::limitFields::limitType
limitType
Definition: limitFields.H:185
Foam::functionObjects::limitFields::limitTypeNames_
static const Enum< limitType > limitTypeNames_
Limit type names.
Definition: limitFields.H:198
Foam::functionObjects::limitFields::limitFields
limitFields(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: limitFields.C:89
limitFields.H
Foam::functionObjects::limitFields::MIN
limit by minimum value
Definition: limitFields.H:187
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Enum::get
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
Definition: Enum.C:75
Foam::functionObjects::fvMeshFunctionObject
Specialization of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
Definition: fvMeshFunctionObject.H:64
Foam::functionObjects::limitFields::fieldSet_
volFieldSelection fieldSet_
Fields to limit.
Definition: limitFields.H:204
Foam::functionObjects::limitFields::read
virtual bool read(const dictionary &dict)
Read the field min/max data.
Definition: limitFields.C:107
Foam::functionObjects::limitFields::limit_
limitType limit_
Limiting type.
Definition: limitFields.H:201
Foam::blockMeshTools::read
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
Definition: blockMeshTools.C:57
Foam::functionObjects::limitFields::write
virtual bool write()
Write the limitFields.
Definition: limitFields.C:172
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
field
rDeltaTY field()
Foam::functionObjects::limitFields::execute
virtual bool execute()
Execute, currently does nothing.
Definition: limitFields.C:138
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
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
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::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
Foam::functionObjects::limitFields::min_
scalar min_
Minimum limit.
Definition: limitFields.H:207
Foam::functionObjects::fieldSelection::read
virtual bool read(const dictionary &dict)
Read the fieldSelection data from dictionary.
Definition: fieldSelection.C:125
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::functionObjects::limitFields::MAX
limit by maximum value
Definition: limitFields.H:188
fieldTypes.H
Header files for all the primitive types that Fields are instantiated for.
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592