solutionControl.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 "solutionControl.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(solutionControl, 0);
33 }
34 
35 
36 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
37 
38 void Foam::solutionControl::read(const bool absTolOnly)
39 {
40  const dictionary& solutionDict = this->dict();
41 
42  // Read solution controls
43  nNonOrthCorr_ =
44  solutionDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 0);
45  momentumPredictor_ =
46  solutionDict.lookupOrDefault("momentumPredictor", true);
47  transonic_ = solutionDict.lookupOrDefault("transonic", false);
48  consistent_ = solutionDict.lookupOrDefault("consistent", false);
49 
50  // Read residual information
51  const dictionary residualDict
52  (
53  solutionDict.subOrEmptyDict("residualControl")
54  );
55 
56  DynamicList<fieldData> data(residualControl_);
57 
58  forAllConstIter(dictionary, residualDict, iter)
59  {
60  const word& fName = iter().keyword();
61  const label fieldI = applyToField(fName, false);
62  if (fieldI == -1)
63  {
64  fieldData fd;
65  fd.name = fName.c_str();
66 
67  if (absTolOnly)
68  {
69  fd.absTol = readScalar(residualDict.lookup(fName));
70  fd.relTol = -1;
71  fd.initialResidual = -1;
72  }
73  else
74  {
75  if (iter().isDict())
76  {
77  const dictionary& fieldDict(iter().dict());
78  fd.absTol = readScalar(fieldDict.lookup("tolerance"));
79  fd.relTol = readScalar(fieldDict.lookup("relTol"));
80  fd.initialResidual = 0.0;
81  }
82  else
83  {
84  FatalErrorIn("bool Foam::solutionControl::read()")
85  << "Residual data for " << iter().keyword()
86  << " must be specified as a dictionary"
87  << exit(FatalError);
88  }
89  }
90 
91  data.append(fd);
92  }
93  else
94  {
95  fieldData& fd = data[fieldI];
96  if (absTolOnly)
97  {
98  fd.absTol = readScalar(residualDict.lookup(fName));
99  }
100  else
101  {
102  if (iter().isDict())
103  {
104  const dictionary& fieldDict(iter().dict());
105  fd.absTol = readScalar(fieldDict.lookup("tolerance"));
106  fd.relTol = readScalar(fieldDict.lookup("relTol"));
107  }
108  else
109  {
110  FatalErrorIn("bool Foam::solutionControl::read()")
111  << "Residual data for " << iter().keyword()
112  << " must be specified as a dictionary"
113  << exit(FatalError);
114  }
115  }
116  }
117  }
118 
119  residualControl_.transfer(data);
120 
121  if (debug)
122  {
123  forAll(residualControl_, i)
124  {
125  const fieldData& fd = residualControl_[i];
126  Info<< "residualControl[" << i << "]:" << nl
127  << " name : " << fd.name << nl
128  << " absTol : " << fd.absTol << nl
129  << " relTol : " << fd.relTol << nl
130  << " iniResid : " << fd.initialResidual << endl;
131  }
132  }
133 }
134 
135 
137 {
138  read(false);
139 }
140 
141 
143 (
144  const word& fieldName,
145  const bool useRegEx
146 ) const
147 {
148  forAll(residualControl_, i)
149  {
150  if (useRegEx && residualControl_[i].name.match(fieldName))
151  {
152  return i;
153  }
154  else if (residualControl_[i].name == fieldName)
155  {
156  return i;
157  }
158  }
159 
160  return -1;
161 }
162 
163 
165 {
166 // storePrevIter<label>();
167  storePrevIter<scalar>();
168  storePrevIter<vector>();
169  storePrevIter<sphericalTensor>();
170  storePrevIter<symmTensor>();
171  storePrevIter<tensor>();
172 }
173 
174 
175 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
176 
178 :
179  IOobject
180  (
181  "solutionControl",
182  mesh.time().timeName(),
183  mesh
184  ),
185  mesh_(mesh),
186  residualControl_(),
187  algorithmName_(algorithmName),
188  nNonOrthCorr_(0),
189  momentumPredictor_(true),
190  transonic_(false),
191  consistent_(false),
192  corr_(0),
193  corrNonOrtho_(0)
194 {}
195 
196 
197 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
198 
200 {}
201 
202 
203 // ************************************************************************* //
virtual label applyToField(const word &fieldName, const bool useRegEx=true) const
Return index of field in residualControl_ if present.
virtual void storePrevIterFields() const
Store previous iteration fields.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual ~solutionControl()
Destructor.
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
virtual void read()
Read controls from fvSolution dictionary.
solutionControl(const solutionControl &)
Disallow default bitwise copy construct.
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
messageStream Info
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
dictionary dict
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define forAll(list, i)
Definition: UList.H:421
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
fvSolution solutionDict(runTime)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
bool match(const std::string &) const
True when strings match literally.
Definition: stringI.H:179
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
defineTypeNameAndDebug(combustionModel, 0)
word timeName
Definition: getTimeIndex.H:3
dictionary subOrEmptyDict(const word &, const bool mustRead=false) const
Find and return a sub-dictionary as a copy, or.
Definition: dictionary.C:675