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-2015 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 
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 " << mesh_.time().endTime().value()
101  << " steps." << nl << endl;
102  }
103  else
104  {
105  Info<< algorithmName_ << ": convergence criteria" << nl;
107  {
108  Info<< " field " << residualControl_[i].name << token::TAB
109  << " tolerance " << residualControl_[i].absTol
110  << nl;
111  }
112  Info<< endl;
113  }
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
118 
120 {}
121 
122 
123 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
124 
126 {
127  read();
128 
129  Time& time = const_cast<Time&>(mesh_.time());
130 
131  if (initialised_)
132  {
133  if (criteriaSatisfied())
134  {
135  Info<< nl << algorithmName_ << " solution converged in "
136  << time.timeName() << " iterations" << nl << endl;
137 
138  // Set to finalise calculation
139  time.writeAndEnd();
140  }
141  else
142  {
143  storePrevIterFields();
144  }
145  }
146  else
147  {
148  initialised_ = true;
149  storePrevIterFields();
150  }
151 
152 
153  return time.loop();
154 }
155 
156 
157 // ************************************************************************* //
Foam::token::TAB
@ TAB
Definition: token.H:96
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::solutionControl
Base class for solution control classes.
Definition: solutionControl.H:45
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::solutionControl::residualControl_
List< fieldData > residualControl_
List of residual data per field.
Definition: solutionControl.H:68
Foam::simpleControl::simpleControl
simpleControl(const simpleControl &)
Disallow default bitwise copy construct.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:261
Foam::solutionControl::read
virtual void read()
Read controls from fvSolution dictionary.
Definition: solutionControl.C:136
Foam::simpleControl::criteriaSatisfied
bool criteriaSatisfied()
Return true if all convergence checks are satisfied.
Definition: simpleControl.C:45
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::Time::writeAndEnd
bool writeAndEnd()
Write the objects now (not at end of iteration) and end the run.
Definition: TimeIO.C:579
Foam::label
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
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::solutionControl::algorithmName_
const word algorithmName_
The dictionary name, e.g. SIMPLE, PIMPLE.
Definition: solutionControl.H:71
Foam::simpleControl::loop
virtual bool loop()
Loop loop.
Definition: simpleControl.C:125
simpleControl.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::Time::loop
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:927
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::solutionControl::mesh_
fvMesh & mesh_
Reference to the mesh database.
Definition: solutionControl.H:65
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
Foam::simpleControl::~simpleControl
virtual ~simpleControl()
Destructor.
Definition: simpleControl.C:119
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::simpleControl::read
void read()
Read controls from fvSolution dictionary.
Definition: simpleControl.C:39
Foam::Time::endTime
virtual dimensionedScalar endTime() const
Return end time.
Definition: Time.C:878
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)