SIMPLEControlSingleRun.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) 2007-2019 PCOpt/NTUA
9 Copyright (C) 2013-2019 FOSS GP
10 Copyright (C) 2019 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
13 This file is part of OpenFOAM.
14
15 OpenFOAM is free software: you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27
28\*---------------------------------------------------------------------------*/
29
32#include "Time.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
40 (
44 );
45}
46
47// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
48
50{
51 return SIMPLEControl::read();
52}
53
54
56{
57 label nItersOld = nIters_;
58 nIters_ = dict().get<label>("nIters");
59
60 if (nIters_ != nItersOld || iter_ == 0)
61 {
62 Time& runTime = const_cast<Time&>(mesh_.time());
63 if (iter_ == 0)
64 {
65 startTime_ = runTime.value();
66 }
67 Info<< "Setting endTime to " << startTime_ + nIters_ << endl;
68 runTime.setEndTime(startTime_ + nIters_);
69 endTime_ = runTime.endTime().value();
70 }
71}
72
73
75{
76 // If controlDict is modified during run-time, time.endTime() is reset
77 // to what is read from controlDict and overwrites the one set through
78 // nIters. Silently reset
79 Time& time = const_cast<Time&>(mesh_.time());
80
81 if (time.endTime().value() != endTime_)
82 {
83 time.setEndTime(startTime_ + nIters_);
84 endTime_ = time.endTime().value();
85 isRunning =
86 time.value() < (time.endTime().value() - 0.5*time.deltaTValue());
87 }
88}
89
90
91// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92
94(
95 fvMesh& mesh,
96 const word& managerType,
97 const solver& solver
98)
99:
100 SIMPLEControl(mesh, managerType, solver),
101 startTime_(Zero),
102 endTime_(Zero)
103{}
104
105
106// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107
108bool Foam::SIMPLEControlSingleRun::write(const bool valid) const
109{
110 Time& time = const_cast<Time&>(mesh_.time());
111 time.write();
112 solver_.write();
113
114 return true;
115}
116
117
119{
120 Time& time = const_cast<Time&>(mesh_.time());
121 // Avoid writing fields if already in an outputTime iter
122 // since results will be written by the solver class either way
123 if (!time.writeTime())
124 {
125 time.writeNow();
126 solver_.writeNow();
127 }
128}
129
130
132{
134
135 this->read();
136 ++iter_;
137
138 Time& runTime = const_cast<Time&>(mesh_.time());
139
140 if (initialised_ && criteriaSatisfied())
141 {
142 Info<< nl
143 << solver_.solverName()
144 << " solution converged in "
145 << runTime.timeName() << " iterations" << nl << endl;
146
147 // write fields (including dummy turbulence fields in multi-point runs)
148 writeNow();
149
150 // Check whether mean fields have not been computed due to an
151 // unexpectedly early convergence
152 checkMeanSolution();
153
154 return false;
155 }
156 else
157 {
158 initialised_ = true;
159 storePrevIterFields();
160 }
161
162 bool isRunning = runTime.loop();
163 checkEndTime(isRunning);
164
165 if (!isRunning)
166 {
167 Info<< nl
168 << solver_.solverName()
169 << " solution reached max. number of iterations "
170 << nIters_ << nl << endl;
171
172 // Write fields (including dummy turbulence fields in multi-point runs)
173 writeNow();
174 }
175
176 return isRunning;
177}
178
179
180// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
SIMPLE control class for single runs (i.e. not optimisation). Time acts as in simpleFoam,...
void writeNow()
Write fields, even if it is not a writeTime.
virtual void readIters()
Set end time if number of iters has changed.
void checkEndTime(bool &isRunning)
virtual bool read()
Read controls from optimisationDict.
SIMPLE control class to supply convergence information/checks for the SIMPLE loop.
Definition: SIMPLEControl.H:56
virtual bool read()
Read controls from fvSolution dictionary.
Definition: SIMPLEControl.C:86
scalar deltaTValue() const noexcept
Return time step value.
Definition: TimeStateI.H:43
bool writeTime() const noexcept
True if this is a write time.
Definition: TimeStateI.H:67
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
bool writeNow()
Definition: TimeIO.C:596
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
virtual void setEndTime(const dimensionedScalar &endTime)
Reset end time.
Definition: Time.C:1048
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
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
const Type & value() const
Return const reference to value.
virtual bool write()
Write the output fields.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
virtual bool write(const bool valid=true) const
Write using setting from DB.
virtual void setFirstIterFlag(const bool check=true, const bool force=false)
Set the firstIteration flag on the mesh data dictionary.
Base class for solution control classes.
Definition: solver.H:54
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
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
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict