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-------------------------------------------------------------------------------
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
29#include "simpleControl.H"
30#include "Time.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
37}
38
39
40// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
41
43{
45 return true;
46}
47
48
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
94(
95 fvMesh& mesh,
96 const word& dictName,
97 const bool verbose
98)
99:
101 initialised_(false)
102{
103 read();
104
105 if (verbose)
106 {
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
137{
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
153 }
154 else
155 {
156 initialised_ = true;
157 storePrevIterFields();
158 }
159
160 return runTime.loop();
161}
162
163
164// ************************************************************************* //
T & first() noexcept
The first element of the list, position [0].
Definition: FixedListI.H:207
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
The TAB Method for Numerical Calculation of Spray Droplet Breakup.
Definition: TAB.H:69
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
bool writeAndEnd()
Write the objects now (not at end of iteration) and end the run.
Definition: TimeIO.C:603
virtual dimensionedScalar startTime() const
Return start time.
Definition: Time.C:861
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:951
virtual dimensionedScalar endTime() const
Return end time.
Definition: Time.C:867
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const Type & value() const
Return const reference to value.
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:290
SIMPLE control class to supply convergence information/checks for the SIMPLE loop.
Definition: simpleControl.H:55
bool criteriaSatisfied()
Return true if all convergence checks are satisfied.
Definition: simpleControl.C:49
virtual bool loop()
SIMPLE loop.
bool read()
Read controls from fvSolution dictionary.
Definition: simpleControl.C:42
Base class for solution control classes.
const word algorithmName_
The dictionary name, e.g. SIMPLE, PIMPLE.
List< fieldData > residualControl_
List of residual data per field.
fvMesh & mesh_
Reference to the mesh database.
virtual void setFirstIterFlag(const bool check=true, const bool force=false)
Set the firstIteration flag on the mesh data dictionary.
virtual bool read()
Read controls from fvSolution dictionary.
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
engineTime & runTime
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Simple convenient storage of field residuals.