Loading...
Searching...
No Matches
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 (
42 SIMPLEControlSingleRun,
44 );
45}
46
47// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
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
93Foam::SIMPLEControlSingleRun::SIMPLEControlSingleRun
94(
95 fvMesh& mesh,
96 const word& managerType,
97 const solver& solver
98)
99:
100 SIMPLEControl(mesh, managerType, solver),
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 writeTime iter
122 // since results will be written by the solver class either way
123 if (!time.writeTime())
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;
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.
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition IOobject.C:456
SIMPLE control class for single runs (i.e. not optimisation). Time acts as in simpleFoam,...
virtual bool write(const bool valid=true) const
Whether to call time.write() or not.
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)
Check whether endTime has been overwritten by a run-time modification of controlDict.
virtual bool read()
Read controls from optimisationDict.
SIMPLE control class to supply convergence information/checks for the SIMPLE loop.
label nIters_
Number of SIMPLE iterations.
void checkMeanSolution() const
virtual bool read()
Read controls from optimisationDict.
bool writeTime() const noexcept
True if this is a write interval.
Definition TimeStateI.H:73
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
virtual bool loop()
Return true if run should continue and if so increment time.
Definition Time.C:859
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
bool criteriaSatisfied()
Return true if all convergence checks are satisfied.
bool initialised_
Initialised flag.
fvMesh & mesh_
Reference to the mesh database.
virtual void storePrevIterFields() const
Store previous iteration fields.
virtual void setFirstIterFlag(const bool check=true, const bool force=false)
Set the firstIteration flag on the mesh data dictionary.
const solver & solver_
Reference to the underlaying solver.
label iter_
Current iteration index.
Base solver class.
Definition solver.H:48
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
engineTime & runTime
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
static bool initialised_(false)
dictionary dict