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 | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "minMaxCondition.H"
28 #include "fieldTypes.H"
29 
30 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
31 
32 template<>
33 void Foam::minMaxCondition::setValue<Foam::scalar>
34 (
35  const word& valueType,
36  const word& fieldName,
37  scalar& value
38 ) const
39 {
40  state_.getObjectResult(functionObjectName_, fieldName, value);
41 }
42 
43 
44 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48  defineTypeNameAndDebug(minMaxCondition, 0);
49  addToRunTimeSelectionTable(runTimeCondition, minMaxCondition, dictionary);
50 
51  template<>
53  {
54  "minimum",
55  "maximum"
56  };
57 }
58 
61 
62 
63 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
64 
66 (
67  const word& name,
68  const objectRegistry& obr,
69  const dictionary& dict,
70  functionObjectState& state
71 )
72 :
73  runTimeCondition(name, obr, dict, state),
74  functionObjectName_(dict.lookup("functionObjectName")),
75  mode_(modeTypeNames_.read(dict.lookup("mode"))),
76  fieldNames_(dict.lookup("fields")),
77  value_(readScalar(dict.lookup("value")))
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
82 
84 {}
85 
86 
87 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
88 
90 {
91  bool satisfied = true;
92 
93  if (!active_)
94  {
95  return satisfied;
96  }
97 
98  forAll(fieldNames_, fieldI)
99  {
100  const word& fieldName = fieldNames_[fieldI];
101 
102  const word valueType =
103  state_.objectResultType(functionObjectName_, fieldName);
104 
105  if (valueType == word::null)
106  {
108  << "Unable to find entry " << fieldName
109  << " for function object " << functionObjectName_
110  << ". Condition will not be applied."
111  << endl;
112 
113  continue;
114  }
115 
116  scalar v = 0;
117  setValue<scalar>(valueType, fieldName, v);
118  setValue<vector>(valueType, fieldName, v);
119  setValue<sphericalTensor>(valueType, fieldName, v);
120  setValue<symmTensor>(valueType, fieldName, v);
121  setValue<tensor>(valueType, fieldName, v);
122 
123  Switch ok = false;
124  switch (mode_)
125  {
126  case mdMin:
127  {
128  if (v < value_)
129  {
130  ok = true;
131  }
132  break;
133  }
134  case mdMax:
135  {
136  if (v > value_)
137  {
138  ok = true;
139  }
140  break;
141  }
142  }
143 
144  if (log_)
145  {
146  Info<< " " << type() << ": " << modeTypeNames_[mode_] << " "
147  << fieldName << ": value = " << v
148  << ", threshold value = " << value_
149  << ", satisfied = " << ok << endl;
150  }
151 
152  satisfied = satisfied && ok;
153  }
154 
155  return satisfied;
156 }
157 
158 
160 {
161  // do nothing
162 }
163 
164 
165 // ************************************************************************* //
minMaxCondition.H
Foam::runTimeCondition
Base class for run time conditions.
Definition: runTimeCondition.H:54
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::minMaxCondition::apply
virtual bool apply()
Apply the condition.
Definition: minMaxCondition.C:89
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::minMaxCondition::write
virtual void write()
Write.
Definition: minMaxCondition.C:159
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
modeTypeNames_
const Foam::NamedEnum< Foam::scene::modeType, 2 > modeTypeNames_
Definition: scene.C:53
Foam::Info
messageStream Info
Foam::minMaxCondition::~minMaxCondition
virtual ~minMaxCondition()
Destructor.
Definition: minMaxCondition.C:83
Foam::minMaxCondition::minMaxCondition
minMaxCondition(const word &name, const objectRegistry &obr, const dictionary &dict, functionObjectState &state)
Constructor.
Definition: minMaxCondition.C:66
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
readScalar
#define readScalar
Definition: doubleScalar.C:38
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::minMaxCondition::modeTypeNames_
static const NamedEnum< modeType, 2 > modeTypeNames_
Definition: minMaxCondition.H:66
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
fieldTypes.H
Include the header files for all the primitive types that Fields are instantiated for.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52