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 | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "simpleControl.H"
27 #include "Time.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(simpleControl, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
38 
40 {
42 }
43 
44 
46 {
47  if (residualControl_.empty())
48  {
49  return false;
50  }
51 
52  bool achieved = true;
53  bool checked = false; // safety that some checks were indeed performed
54 
55  const dictionary& solverDict = mesh_.solverPerformanceDict();
56  forAllConstIter(dictionary, solverDict, iter)
57  {
58  const word& variableName = iter().keyword();
59  const label fieldi = applyToField(variableName);
60  if (fieldi != -1)
61  {
62  scalar lastResidual = 0;
63  const scalar residual =
64  maxResidual(variableName, iter().stream(), lastResidual);
65 
66  checked = true;
67 
68  bool absCheck = residual < residualControl_[fieldi].absTol;
69  achieved = achieved && absCheck;
70 
71  if (debug)
72  {
73  Info<< algorithmName_ << " solution statistics:" << endl;
74 
75  Info<< " " << variableName << ": tolerance = " << residual
76  << " (" << residualControl_[fieldi].absTol << ")"
77  << endl;
78  }
79  }
80  }
81 
82  return checked && achieved;
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87 
88 Foam::simpleControl::simpleControl(fvMesh& mesh)
89 :
90  solutionControl(mesh, "SIMPLE"),
91  initialised_(false)
92 {
93  read();
94 
95  Info<< nl;
96 
97  if (residualControl_.empty())
98  {
99  Info<< algorithmName_ << ": no convergence criteria found. "
100  << "Calculations will run for "
101  << mesh_.time().endTime().value() - mesh_.time().startTime().value()
102  << " steps." << nl << endl;
103  }
104  else
105  {
106  Info<< algorithmName_ << ": convergence criteria" << nl;
108  {
109  Info<< " field " << residualControl_[i].name << token::TAB
110  << " tolerance " << residualControl_[i].absTol
111  << nl;
112  }
113  Info<< endl;
114  }
115 }
116 
117 
118 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
119 
121 {}
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 {
128  read();
129 
130  Time& time = const_cast<Time&>(mesh_.time());
131 
132  if (initialised_)
133  {
134  if (criteriaSatisfied())
135  {
136  Info<< nl << algorithmName_ << " solution converged in "
137  << time.timeName() << " iterations" << nl << endl;
138 
139  // Set to finalise calculation
140  time.writeAndEnd();
141  }
142  else
143  {
145  }
146  }
147  else
148  {
149  initialised_ = true;
151  }
152 
153 
154  return time.loop();
155 }
156 
157 
158 // ************************************************************************* //
virtual ~simpleControl()
Destructor.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool writeAndEnd()
Write the objects now (not at end of iteration) and end the run.
Definition: TimeIO.C:575
fvMesh & mesh_
Reference to the mesh database.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
List< fieldData > residualControl_
List of residual data per field.
Base class for solution control classes.
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:819
virtual dimensionedScalar startTime() const
Return start time.
Definition: Time.C:769
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:644
virtual dimensionedScalar endTime() const
Return end time.
Definition: Time.C:775
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual bool loop()
Loop loop.
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
const Type & value() const
Return const reference to value.
const word algorithmName_
The dictionary name, e.g. SIMPLE, PIMPLE.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
virtual void read()
Read controls from fvSolution dictionary.
static const char nl
Definition: Ostream.H:262
defineTypeNameAndDebug(combustionModel, 0)
virtual void storePrevIterFields() const
Store previous iteration fields.
void read()
Read controls from fvSolution dictionary.
Definition: simpleControl.C:39
const Time & time() const
Return time.
Definition: IOobject.C:337
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
bool criteriaSatisfied()
Return true if all convergence checks are satisfied.
Definition: simpleControl.C:45
messageStream Info
bool initialised_
Initialised flag.
Definition: simpleControl.H:59
Namespace for OpenFOAM.