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-2016 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 {
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 == 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 
169 // ************************************************************************* //
Foam::functionObjects::runTimeControls::defineTypeNameAndDebug
defineTypeNameAndDebug(averageCondition, 0)
minMaxCondition.H
Foam::functionObjects::runTimeControls::minMaxCondition::apply
virtual bool apply()
Apply the condition.
Definition: minMaxCondition.C:98
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:77
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::functionObjects::runTimeControls::runTimeCondition
Base class for run time conditions.
Definition: runTimeCondition.H:61
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::functionObjects::runTimeControls::runTimeCondition::active_
bool active_
On/off switch.
Definition: runTimeCondition.H:78
Foam::functionObjects::runTimeControls::minMaxCondition::mdMin
Minimum.
Definition: minMaxCondition.H:68
Foam::functionObjects::runTimeControls::addToRunTimeSelectionTable
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary)
Foam::functionObjects::runTimeControls::minMaxCondition::mdMax
Maximum.
Definition: minMaxCondition.H:69
Foam::functionObjects::stateFunctionObject
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: stateFunctionObject.H:69
Foam::functionObjects::runTimeControls::minMaxCondition::functionObjectName_
word functionObjectName_
Name of function object to retrueve data from.
Definition: minMaxCondition.H:80
Foam::functionObjects::runTimeControls::minMaxCondition::minMaxCondition
minMaxCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
Definition: minMaxCondition.C:81
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::runTimeControls::minMaxCondition::modeTypeNames_
static const Enum< modeType > modeTypeNames_
Definition: minMaxCondition.H:72
Foam::functionObjects::runTimeControls::minMaxCondition::write
virtual void write()
Write.
Definition: minMaxCondition.C:163
Foam::functionObjects::runTimeControls::runTimeCondition::state_
stateFunctionObject & state_
State.
Definition: runTimeCondition.H:75
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::functionObjects::runTimeControls::minMaxCondition::mode_
modeType mode_
Mode.
Definition: minMaxCondition.H:83
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
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
minMaxCondition
Minimum/maximum run time conditions. If the value type is not scalar, the magnitude of the value is u...
Foam::functionObjects::stateFunctionObject::objectResultType
word objectResultType(const word &objectName, const word &entryName) const
Return the type of result.
Definition: stateFunctionObject.C:139
Foam::List< word >
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::runTimeControls::minMaxCondition::value_
const scalar value_
Value to compare.
Definition: minMaxCondition.H:89
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::functionObjects::runTimeControls::minMaxCondition::fieldNames_
const wordList fieldNames_
Field names.
Definition: minMaxCondition.H:86
fieldTypes.H
Header files for all the primitive types that Fields are instantiated for.
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328