Loading...
Searching...
No Matches
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\*---------------------------------------------------------------------------*/
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 * * * * * * * * * * * * * //
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
78(
79 const word& name,
80 const objectRegistry& obr,
81 const dictionary& dict,
82 stateFunctionObject& state
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 {
95 timeStart_ = obr.time().userTimeToTime(timeStart_);
96 }
97 else
98 {
99 WarningInFunction
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.data().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 }
220 }
221
222 return satisfied;
223}
224
225
231
232
235{
236 // do nothing
237}
238
239
240// ************************************************************************* //
#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.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
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
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
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
wordList sortedToc() const
Return the sorted table of contents.
Definition dictionary.C:601
Helper class to store a wordRe and label used by Foam::functionObjects::fieldSelection.
Definition fieldInfo.H:52
label component() const noexcept
Return the component.
Definition fieldInfo.H:122
const wordRe & name() const noexcept
Return the selector pattern for the field name(s).
Definition fieldInfo.H:117
virtual bool read(const dictionary &dict)
Read the fieldSelection data from dictionary.
scalar timeStart_
Start checking from time - always skips first iteration.
equationInitialResidualCondition(const word &name, const objectRegistry &obr, const dictionary &dict, stateFunctionObject &state)
Constructor.
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 SetResidual(Type)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
#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
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
Tensor< scalar > tensor
Definition symmTensor.H:57
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
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
Vector< scalar > vector
Definition vector.H:57
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition symmTensor.H:55
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