OpenFOAM: API Guide
v2112
The open source CFD toolbox
simpleControl.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) 2011-2016 OpenFOAM Foundation
9
Copyright (C) 2017 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
29
#include "
simpleControl.H
"
30
#include "
Time.H
"
31
32
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34
namespace
Foam
35
{
36
defineTypeNameAndDebug
(simpleControl, 0);
37
}
38
39
40
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
41
42
bool
Foam::simpleControl::read
()
43
{
44
solutionControl::read
(
true
);
45
return
true
;
46
}
47
48
49
bool
Foam::simpleControl::criteriaSatisfied
()
50
{
51
if
(residualControl_.empty())
52
{
53
return
false
;
54
}
55
56
bool
achieved =
true
;
57
bool
checked =
false
;
// safety that some checks were indeed performed
58
59
const
dictionary
& solverDict = mesh_.solverPerformanceDict();
60
for
(
const
entry
& solverPerfDictEntry : solverDict)
61
{
62
const
word
& fieldName = solverPerfDictEntry.keyword();
63
const
label fieldi = applyToField(fieldName);
64
65
if
(fieldi != -1)
66
{
67
Pair<scalar>
residuals = maxResidual(solverPerfDictEntry);
68
checked =
true
;
69
70
const
bool
absCheck =
71
(residuals.first() < residualControl_[fieldi].absTol);
72
73
achieved = achieved && absCheck;
74
75
if
(
debug
)
76
{
77
Info
<< algorithmName_ <<
" solution statistics:"
<<
endl
;
78
79
Info
<<
" "
<< fieldName <<
": tolerance = "
80
<< residuals.first()
81
<<
" ("
<< residualControl_[fieldi].absTol <<
")"
82
<<
endl
;
83
}
84
}
85
}
86
87
return
checked && achieved;
88
}
89
90
91
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92
93
Foam::simpleControl::simpleControl
94
(
95
fvMesh
&
mesh
,
96
const
word
&
dictName
,
97
const
bool
verbose
98
)
99
:
100
solutionControl
(
mesh
,
dictName
),
101
initialised_(
false
)
102
{
103
read
();
104
105
if
(verbose)
106
{
107
Info
<<
nl
<< algorithmName_;
108
109
if
(residualControl_.empty())
110
{
111
const
scalar duration =
112
mesh_.time().endTime().value()
113
- mesh_.time().startTime().value();
114
115
Info
<<
": no convergence criteria found. "
116
<<
"Calculations will run for "
<< duration <<
" steps."
117
<<
nl
;
118
}
119
else
120
{
121
Info
<<
": convergence criteria"
<<
nl
;
122
for
(
const
fieldData
& ctrl : residualControl_)
123
{
124
Info
<<
" field "
<< ctrl.name <<
token::TAB
125
<<
" tolerance "
<< ctrl.absTol
126
<<
nl
;
127
}
128
}
129
Info
<<
endl
;
130
}
131
}
132
133
134
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
135
136
bool
Foam::simpleControl::loop
()
137
{
138
solutionControl::setFirstIterFlag
(
true
,
true
);
139
140
read
();
141
142
Time
&
runTime
=
const_cast<
Time
&
>
(mesh_.time());
143
144
if
(initialised_ && criteriaSatisfied())
145
{
146
Info
<<
nl
147
<< algorithmName_
148
<<
" solution converged in "
149
<<
runTime
.
timeName
() <<
" iterations"
<<
nl
<<
endl
;
150
151
// Set to finalise calculation
152
runTime
.
writeAndEnd
();
153
}
154
else
155
{
156
initialised_ =
true
;
157
storePrevIterFields();
158
}
159
160
return
runTime
.
loop
();
161
}
162
163
164
// ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition:
entry.H:67
runTime
engineTime & runTime
Definition:
createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition:
Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition:
word.H:65
Foam::solutionControl
Base class for solution control classes.
Definition:
solutionControl.H:49
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition:
int32.H:108
dictName
const word dictName("faMeshDefinition")
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition:
Time.C:780
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition:
Ostream.H:369
Foam::simpleControl::criteriaSatisfied
bool criteriaSatisfied()
Return true if all convergence checks are satisfied.
Definition:
simpleControl.C:49
Foam::solutionControl::setFirstIterFlag
virtual void setFirstIterFlag(const bool check=true, const bool force=false)
Set the firstIteration flag on the mesh data dictionary.
Definition:
solutionControl.C:181
Foam::Time::writeAndEnd
bool writeAndEnd()
Write the objects now (not at end of iteration) and end the run.
Definition:
TimeIO.C:603
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::simpleControl::loop
virtual bool loop()
SIMPLE loop.
Definition:
simpleControl.C:136
simpleControl.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition:
dictionary.H:123
Foam::Time::loop
virtual bool loop()
Return true if run should continue and if so increment time.
Definition:
Time.C:957
mesh
dynamicFvMesh & mesh
Definition:
createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition:
fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition:
atmBoundaryLayer.C:33
Foam::solutionControl::read
virtual bool read()
Read controls from fvSolution dictionary.
Definition:
solutionControl.C:136
Time.H
Foam::nl
constexpr char nl
Definition:
Ostream.H:404
Foam::Pair< scalar >
Foam::solutionControl::fieldData
Simple convenient storage of field residuals.
Definition:
solutionControl.H:56
Foam::token::TAB
Tab [isspace].
Definition:
token.H:123
Foam::simpleControl::read
bool read()
Read controls from fvSolution dictionary.
Definition:
simpleControl.C:42
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
src
finiteVolume
cfdTools
general
solutionControl
simpleControl
simpleControl.C
Generated by
1.8.17
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.