equationInitialResidualCondition.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-2020 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#include "volFields.H"
34
35#define SetResidual(Type) \
36 setResidual<Type>(mesh, solverDict, fieldName, component, canSet, residual);
37
38// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39
40namespace Foam
41{
42namespace functionObjects
43{
44namespace runTimeControls
45{
48 (
52 );
53
54}
55}
56}
57
58const Foam::Enum
59<
60 Foam
61 ::functionObjects
62 ::runTimeControls
63 ::equationInitialResidualCondition
64 ::operatingMode
65>
68({
69 { operatingMode::omMin, "minimum" },
70 { operatingMode::omMax, "maximum" },
71});
72
73
74// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75
76Foam::functionObjects::runTimeControls::
77equationInitialResidualCondition::equationInitialResidualCondition
78(
79 const word& name,
80 const objectRegistry& obr,
81 const dictionary& dict,
83)
84:
85 runTimeCondition(name, obr, dict, state),
86 fieldSelection_(obr, true),
87 value_(dict.get<scalar>("value")),
88 timeStart_(dict.getOrDefault("timeStart", -GREAT)),
89 mode_(operatingModeNames.get("mode", dict))
90{
92
94 {
96 }
97 else
98 {
100 << "No fields supplied: deactivating" << endl;
101
102 active_ = false;
103 }
104}
105
106
107// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
108
111{
112 fieldSelection_.updateSelection();
113
114 bool satisfied = false;
115
116 if (!active_)
117 {
118 return true;
119 }
120
121 if ((obr_.time().timeIndex() < 3) || (obr_.time().value() < timeStart_))
122 {
123 // Do not start checking until reached start time
124 return false;
125 }
126
127 const fvMesh& mesh = refCast<const fvMesh>(obr_);
128 const dictionary& solverDict = mesh.solverPerformanceDict();
129
130 const auto& selection = fieldSelection_.selection();
131 List<scalar> result(selection.size(), -VGREAT);
132
133 forAll(selection, fieldi)
134 {
135 const auto& fieldInfo = selection[fieldi];
136 const word& fieldName = fieldInfo.name();
137
138 if (solverDict.found(fieldName))
139 {
140 label component = fieldInfo.component();
141 scalar residual = VGREAT;
142 bool canSet = true;
143 SetResidual(scalar);
148
149 result[fieldi] = residual;
150
151 switch (mode_)
152 {
153 case omMin:
154 {
155 if (residual < value_)
156 {
157 satisfied = true;
158 }
159 break;
160 }
161 case omMax:
162 {
163 if (residual > value_)
164 {
165 satisfied = true;
166 }
167 break;
168 }
169 default:
170 {
172 << "Unhandled enumeration "
173 << operatingModeNames[mode_]
174 << abort(FatalError);
175 }
176 }
177 }
178 }
179
180 bool valid = false;
181 forAll(result, i)
182 {
183 if (result[i] < 0)
184 {
186 << "Initial residual data not found for field "
187 << selection[i].name()
188 << ". Solver dictionary contains " << solverDict.sortedToc()
189 << endl;
190 }
191 else
192 {
193 valid = true;
194 }
195 }
196
197 if (!valid)
198 {
200 << "Initial residual data not found for any fields: "
201 << "deactivating" << endl;
202
203 active_ = false;
204 }
205
206 if (satisfied && valid)
207 {
208 Log << type() << ": " << name_
209 << ": satisfied using threshold value: " << value_ << nl;
210
211 forAll(result, resulti)
212 {
213 if (result[resulti] > 0)
214 {
215 Log << " field: " << selection[resulti].name()
216 << ", residual: " << result[resulti] << nl;
217 }
218 }
219 Log << endl;
220 }
221
222 return satisfied;
223}
224
225
228{
229 // do nothing
230}
231
232
235{
236 // do nothing
237}
238
239
240// ************************************************************************* //
#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.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
virtual scalar userTimeToTime(const scalar theta) const
Convert the user-time (e.g. CA deg) to real-time (s).
Definition: TimeState.C:49
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
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
wordList sortedToc() const
Return the sorted table of contents.
Definition: dictionary.C:616
Watches for presence of the named trigger file in the case directory and signals a simulation stop (o...
Definition: abort.H:128
Helper class to store a wordRe and label used by Foam::functionObjects::fieldSelection.
Definition: fieldInfo.H:58
const wordRe & name() const
Definition: fieldInfo.H:107
virtual bool read(const dictionary &dict)
Read the fieldSelection data from dictionary.
scalar timeStart_
Start checking from time - 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.
const Time & time() const noexcept
Return time registry.
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 SetResidual(Type)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
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
error FatalError
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