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-2012 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  const List<solverPerformance> sp(iter().stream());
63  const scalar residual = sp.first().initialResidual();
64 
65  checked = true;
66 
67  bool absCheck = residual < residualControl_[fieldI].absTol;
68  achieved = achieved && absCheck;
69 
70  if (debug)
71  {
72  Info<< algorithmName_ << " solution statistics:" << endl;
73 
74  Info<< " " << variableName << ": tolerance = " << residual
75  << " (" << residualControl_[fieldI].absTol << ")"
76  << endl;
77  }
78  }
79  }
80 
81  return checked && achieved;
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
88 :
89  solutionControl(mesh, "SIMPLE"),
90  initialised_(false)
91 {
92  read();
93 
94  Info<< nl;
95 
96  if (residualControl_.empty())
97  {
98  Info<< algorithmName_ << ": no convergence criteria found. "
99  << "Calculations will run for " << mesh_.time().endTime().value()
100  << " steps." << nl << endl;
101  }
102  else
103  {
104  Info<< algorithmName_ << ": convergence criteria" << nl;
106  {
107  Info<< " field " << residualControl_[i].name << token::TAB
108  << " tolerance " << residualControl_[i].absTol
109  << nl;
110  }
111  Info<< endl;
112  }
113 }
114 
115 
116 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
117 
119 {}
120 
121 
122 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
123 
125 {
126  read();
127 
128  Time& time = const_cast<Time&>(mesh_.time());
129 
130  if (initialised_)
131  {
132  if (criteriaSatisfied())
133  {
134  Info<< nl << algorithmName_ << " solution converged in "
135  << time.timeName() << " iterations" << nl << endl;
136 
137  // Set to finalise calculation
138  time.writeAndEnd();
139  }
140  else
141  {
143  }
144  }
145  else
146  {
147  initialised_ = true;
149  }
150 
151 
152  return time.loop();
153 }
154 
155 
156 // ************************************************************************* //
Base class for solution control classes.
virtual void storePrevIterFields() const
Store previous iteration fields.
fvMesh & mesh_
Reference to the mesh database.
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
simpleControl(const simpleControl &)
Disallow default bitwise copy construct.
virtual void read()
Read controls from fvSolution dictionary.
const Type & initialResidual() const
Return initial residual.
A class for handling words, derived from string.
Definition: word.H:59
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
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
virtual bool loop()
Loop loop.
messageStream Info
bool writeAndEnd()
Write the objects now (not at end of iteration) and end the run.
Definition: TimeIO.C:579
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual ~simpleControl()
Destructor.
T & first()
Return the first element of the list.
Definition: UListI.H:117
Namespace for OpenFOAM.
bool initialised_
Initialised flag.
Definition: simpleControl.H:56
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
void read()
Read controls from fvSolution dictionary.
Definition: simpleControl.C:39
List< fieldData > residualControl_
List of residual data per field.
virtual dimensionedScalar endTime() const
Return end time.
Definition: Time.C:878
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:924
const Time & time() const
Return time.
Definition: IOobject.C:251
const word algorithmName_
The dictionary name, e.g. SIMPLE, PIMPLE.
const Type & value() const
Return const reference to value.
defineTypeNameAndDebug(combustionModel, 0)