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-------------------------------------------------------------------------------
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
31#include "fvMesh.H"
32#include "Time.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
38namespace functionObjects
39{
40namespace runTimeControls
41{
44 (
48 );
49}
50}
51}
52
53
54// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55
56Foam::functionObjects::runTimeControls::equationMaxIterCondition::
57equationMaxIterCondition
58(
59 const word& name,
60 const objectRegistry& obr,
61 const dictionary& dict,
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.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// ************************************************************************* //
#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.
T & first()
Return the first element of the list.
Definition: UListI.H:202
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:386
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Maximum number of equation iterations run time condition.
label startIter_
Start checking from iteration - always skips first iteration.
Base class for function objects, adding functionality to read/write state information (data required ...
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
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
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
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
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333