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 | 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 
31 #include "fvMesh.H"
32 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
40 namespace runTimeControls
41 {
42  defineTypeNameAndDebug(equationMaxIterCondition, 0);
44  (
45  runTimeCondition,
46  equationMaxIterCondition,
47  dictionary
48  );
49 }
50 }
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
58 (
59  const word& name,
60  const objectRegistry& obr,
61  const dictionary& dict,
62  stateFunctionObject& state
63 )
64 :
65  runTimeCondition(name, obr, dict, state),
66  fieldNames_(dict.get<wordList>("fields")),
67  threshold_(dict.get<label>("threshold")),
68  startIter_(dict.getOrDefault("startIter", 2))
69 {
70  if (!fieldNames_.size())
71  {
73  << "No fields supplied: deactivating" << endl;
74 
75  active_ = false;
76  }
77 
79 }
80 
81 
82 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
83 
85 {
86  bool satisfied = false;
87 
88  if (!active_)
89  {
90  return true;
91  }
92 
93  if (obr_.time().timeIndex() < startIter_)
94  {
95  // Do not start checking until start iter
96  return false;
97  }
98 
99  const fvMesh& mesh = refCast<const fvMesh>(obr_);
100  const dictionary& solverDict = mesh.data().solverPerformanceDict();
101 
102  List<label> result(fieldNames_.size(), -1);
103 
104  forAll(fieldNames_, fieldi)
105  {
106  const word& fieldName = fieldNames_[fieldi];
107 
108  if (solverDict.found(fieldName))
109  {
110  const List<solverPerformance> sp(solverDict.lookup(fieldName));
111  const label nIterations = sp.first().nIterations();
112  result[fieldi] = nIterations;
113 
114  if (nIterations > threshold_)
115  {
116  satisfied = true;
117  }
118  }
119  }
120 
121  bool valid = false;
122  forAll(result, i)
123  {
124  if (result[i] < 0)
125  {
127  << "Number of iterations data not found for field "
128  << fieldNames_[i] << endl;
129  }
130  else
131  {
132  valid = true;
133  }
134  }
135 
136  if (!valid)
137  {
139  << "Number of iterations data not found for any fields: "
140  << "deactivating" << endl;
141 
142  active_ = false;
143  }
144 
145  if (satisfied && valid)
146  {
147  Log << type() << ": " << name_
148  << ": satisfied using threshold value: " << threshold_ << nl;
149 
150  forAll(result, resulti)
151  {
152  if (result[resulti] != -1)
153  {
154  Log << " field: " << fieldNames_[resulti]
155  << ", iterations: " << result[resulti] << nl;
156  }
157  }
158  Log << endl;
159  }
160 
161  return satisfied;
162 }
163 
164 
166 {
167  // do nothing
168 }
169 
170 
171 
173 {
174  // do nothing
175 }
176 
177 
178 // ************************************************************************* //
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
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label startIter_
Start checking from iteration - always skips first iteration.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
T & first()
Access first element of the list, position [0].
Definition: UList.H:853
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
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
dynamicFvMesh & mesh
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
equationMaxIterCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
defineTypeNameAndDebug(averageCondition, 0)
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary)
#define WarningInFunction
Report a warning using Foam::Warning.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
#define Log
Definition: PDRblock.C:28
Base class for function objects, adding functionality to read/write state information (data required ...
Registry of regIOobjects.
Namespace for OpenFOAM.