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-------------------------------------------------------------------------------
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 "minMaxCondition.H"
31#include "fieldTypes.H"
32
33// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
34
35template<>
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
50namespace Foam
51{
52namespace functionObjects
53{
54namespace runTimeControls
55{
58
59}
60}
61}
62
63const 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,
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 =
110 state_.objectResultType(functionObjectName_, fieldName);
111
112 if (valueType == word::null)
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
162
164{
165 // do nothing
166}
167
168
170{
171 // do nothing
172}
173
174
175// ************************************************************************* //
#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
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:78
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Base class for function objects, adding functionality to read/write state information (data required ...
Registry of regIOobjects.
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
Header files for all the primitive types that Fields are instantiated for.
#define WarningInFunction
Report a warning using Foam::Warning.
void Foam::functionObjects::runTimeControls::minMaxCondition::setValue< Foam::scalar >(const word &valueType, const word &fieldName, scalar &value) const
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
dictionary dict