Loading...
Searching...
No Matches
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 * * * * * * * * * * * * * //
36namespace Foam
37{
38namespace functionObjects
39{
40namespace runTimeControls
41{
44 (
48 );
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 {
72 WarningInFunction
73 << "No fields supplied: deactivating" << endl;
74
75 active_ = false;
76 }
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 Pair<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 }
159 }
160
161 return satisfied;
162}
163
164
169
170
171
173{
174 // do nothing
175}
176
177
178// ************************************************************************* //
#define Log
Definition PDRblock.C:28
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
An ordered pair of two objects of type <T> with first() and second() elements.
Definition Pair.H:66
const T & first() const noexcept
Access the first element.
Definition Pair.H:137
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return an entry data stream. FatalIOError if not found, or not a stream.
Definition dictionary.C:367
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Maximum number of equation iterations run time condition.
equationMaxIterCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
const label threshold_
Threshold for maximum number of iterations.
label startIter_
Start checking from iteration - always skips first iteration.
const objectRegistry & obr_
Reference to the object registry.
runTimeCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
virtual const word & name() const
Return the condition name.
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:85
Registry of regIOobjects.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Function objects are OpenFOAM utilities to ease workflow configurations and enhance workflows.
Namespace for OpenFOAM.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
List< word > wordList
List of word.
Definition fileName.H:60
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299