equationMaxIterCondition.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 
28 #include "fvMesh.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(equationMaxIterCondition, 0);
37  (
38  runTimeCondition,
39  equationMaxIterCondition,
40  dictionary
41  );
42 }
43 
44 
45 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
46 
48 (
49  const word& name,
50  const objectRegistry& obr,
51  const dictionary& dict,
52  functionObjectState& state
53 )
54 :
55  runTimeCondition(name, obr, dict, state),
56  fieldNames_(dict.lookup("fields")),
57  threshold_(readLabel(dict.lookup("threshold"))),
58  startIter_(dict.lookupOrDefault("startIter", 2))
59 {
60  if (!fieldNames_.size())
61  {
63  << "No fields supplied: deactivating" << endl;
64 
65  active_ = false;
66  }
67 
68  startIter_ = max(startIter_, 2);
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
73 
75 {}
76 
77 
78 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
79 
81 {
82  bool satisfied = false;
83 
84  if (!active_)
85  {
86  return true;
87  }
88 
89  if (obr_.time().timeIndex() < startIter_)
90  {
91  // Do not start checking until start iter
92  return false;
93  }
94 
95  const fvMesh& mesh = refCast<const fvMesh>(obr_);
96  const dictionary& solverDict = mesh.solverPerformanceDict();
97 
98  List<label> result(fieldNames_.size(), -1);
99 
100  forAll(fieldNames_, fieldI)
101  {
102  const word& fieldName = fieldNames_[fieldI];
103 
104  if (solverDict.found(fieldName))
105  {
106  const List<solverPerformance> sp(solverDict.lookup(fieldName));
107  const label nIterations = sp.first().nIterations();
108  result[fieldI] = nIterations;
109 
110  if (nIterations > threshold_)
111  {
112  satisfied = true;
113  }
114  }
115  }
116 
117  bool valid = false;
118  forAll(result, i)
119  {
120  if (result[i] < 0)
121  {
123  << "Number of iterations data not found for field "
124  << fieldNames_[i] << endl;
125  }
126  else
127  {
128  valid = true;
129  }
130  }
131 
132  if (!valid)
133  {
135  << "Number of iterations data not found for any fields: "
136  << "deactivating" << endl;
137 
138  active_ = false;
139  }
140 
141  if (satisfied && valid)
142  {
143  if (log_)
144  {
145  Info<< type() << ": " << name_
146  << ": satisfied using threshold value: " << threshold_ << nl;
147  }
148 
149  forAll(result, resultI)
150  {
151  if (result[resultI] != -1)
152  {
153  if (log_)
154  {
155  Info<< " field: " << fieldNames_[resultI]
156  << ", iterations: " << result[resultI] << nl;
157  }
158  }
159  }
160  if (log_) Info<< endl;
161  }
162 
163  return satisfied;
164 }
165 
166 
168 {
169  // do nothing
170 }
171 
172 
173 // ************************************************************************* //
Foam::runTimeCondition
Base class for run time conditions.
Definition: runTimeCondition.H:54
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
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::equationMaxIterCondition::write
virtual void write()
Write.
Definition: equationMaxIterCondition.C:167
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
equationMaxIterCondition.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::equationMaxIterCondition::apply
virtual bool apply()
Apply the condition.
Definition: equationMaxIterCondition.C:80
Foam::data::solverPerformanceDict
const dictionary & solverPerformanceDict() const
Return the dictionary of solver performance data.
Definition: data.C:56
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
Foam::equationMaxIterCondition::~equationMaxIterCondition
virtual ~equationMaxIterCondition()
Destructor.
Definition: equationMaxIterCondition.C:74
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::List< label >
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::equationMaxIterCondition::equationMaxIterCondition
equationMaxIterCondition(const word &name, const objectRegistry &obr, const dictionary &dict, functionObjectState &state)
Constructor.
Definition: equationMaxIterCondition.C:48
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