minMaxCondition.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) 2015 OpenFOAM Foundation
9  Copyright (C) 2015-2022 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 "minMaxCondition.H"
31 #include "fieldTypes.H"
32 
33 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
34 
35 template<>
36 void Foam::functionObjects::runTimeControls::minMaxCondition::
37 setValue<Foam::scalar>
38 (
39  const word& valueType,
40  const word& fieldName,
41  scalar& value
42 ) const
43 {
44  state_.getObjectResult(functionObjectName_, fieldName, value);
45 }
46 
47 
48 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 namespace functionObjects
53 {
54 namespace runTimeControls
55 {
56  defineTypeNameAndDebug(minMaxCondition, 0);
57  addToRunTimeSelectionTable(runTimeCondition, minMaxCondition, dictionary);
58 
59 }
60 }
61 }
62 
63 const Foam::Enum
64 <
65  Foam
66  ::functionObjects
67  ::runTimeControls
68  ::minMaxCondition
69  ::modeType
70 >
72 ({
73  { modeType::mdMin, "minimum" },
74  { modeType::mdMax, "maximum" },
75 });
76 
77 
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 
81 (
82  const word& name,
83  const objectRegistry& obr,
84  const dictionary& dict,
85  stateFunctionObject& state
86 )
87 :
88  runTimeCondition(name, obr, dict, state),
89  functionObjectName_(dict.get<word>("functionObject")),
90  mode_(modeTypeNames_.get("mode", dict)),
91  fieldNames_(dict.get<wordList>("fields")),
92  value_(dict.get<scalar>("value"))
93 {}
94 
95 
96 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
97 
99 {
100  bool satisfied = true;
101 
102  if (!active_)
103  {
104  return satisfied;
105  }
106 
107  for (const word& fieldName :fieldNames_)
108  {
109  const word valueType =
111 
112  if (valueType.empty())
113  {
115  << "Unable to find entry " << fieldName
116  << " for function object " << functionObjectName_
117  << ". Condition will not be applied."
118  << endl;
119 
120  continue;
121  }
122 
123  scalar v = 0;
124  setValue<scalar>(valueType, fieldName, v);
125  setValue<vector>(valueType, fieldName, v);
126  setValue<sphericalTensor>(valueType, fieldName, v);
127  setValue<symmTensor>(valueType, fieldName, v);
128  setValue<tensor>(valueType, fieldName, v);
129 
130  Switch ok = false;
131  switch (mode_)
132  {
133  case mdMin:
134  {
135  if (v < value_)
136  {
137  ok = true;
138  }
139  break;
140  }
141  case mdMax:
142  {
143  if (v > value_)
144  {
145  ok = true;
146  }
147  break;
148  }
149  }
150 
151  Log << " " << type() << ": " << modeTypeNames_[mode_] << " "
152  << fieldName << ": value = " << v
153  << ", threshold value = " << value_
154  << ", satisfied = " << ok << endl;
155 
156  satisfied = satisfied && ok;
157  }
158 
159  return satisfied;
160 }
161 
164 {
165  // do nothing
166 }
167 
168 
170 {
171  // do nothing
172 }
173 
174 
175 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, any/none. Also accepts 0/1 as a string and shortcuts t/f, y/n.
Definition: Switch.H:77
Macros for easy insertion into run-time selection tables.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
defineTypeNameAndDebug(averageCondition, 0)
word functionObjectName_
Name of function object to retrueve data from.
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary)
#define WarningInFunction
Report a warning using Foam::Warning.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
#define Log
Definition: PDRblock.C:28
Base class for function objects, adding functionality to read/write state information (data required ...
Registry of regIOobjects.
minMaxCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
Namespace for OpenFOAM.