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
44  solutionDict.lookupOrDefault<label>("nNonOrthogonalCorrectors", 0);
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 
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  {
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  {
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  {
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 template<class Type>
177 (
178  const word& fieldName,
179  ITstream& data,
180  scalar& firstRes,
181  scalar& lastRes
182 ) const
183 {
185 
186  if (mesh_.foundObject<fieldType>(fieldName))
187  {
189  firstRes = cmptMax(sp.first().initialResidual());
190  lastRes = cmptMax(sp.last().initialResidual());
191  }
192 }
193 
194 
196 (
197  const word& fieldName,
198  ITstream& data,
199  scalar& lastRes
200 ) const
201 {
202  scalar firstRes = 0;
203 
204  maxTypeResidual<scalar>(fieldName, data, firstRes, lastRes);
205  maxTypeResidual<vector>(fieldName, data, firstRes, lastRes);
206  maxTypeResidual<sphericalTensor>(fieldName, data, firstRes, lastRes);
207  maxTypeResidual<symmTensor>(fieldName, data, firstRes, lastRes);
208  maxTypeResidual<tensor>(fieldName, data, firstRes, lastRes);
209 
210  return firstRes;
211 }
212 
213 
214 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
215 
217 :
218  IOobject
219  (
220  "solutionControl",
221  mesh.time().timeName(),
222  mesh
223  ),
224  mesh_(mesh),
225  residualControl_(),
226  algorithmName_(algorithmName),
227  nNonOrthCorr_(0),
228  momentumPredictor_(true),
229  transonic_(false),
230  consistent_(false),
231  corr_(0),
232  corrNonOrtho_(0)
233 {}
234 
235 
236 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
237 
239 {}
240 
241 
242 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
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::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::solutionControl::dict
const dictionary & dict() const
Return the solution dictionary.
Definition: solutionControlI.H:28
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::solutionControl::residualControl_
List< fieldData > residualControl_
List of residual data per field.
Definition: solutionControl.H:68
Foam::dictionary::lookupOrDefault
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Definition: dictionaryTemplates.C:33
Foam::solutionControl::fieldData::absTol
scalar absTol
Definition: solutionControl.H:54
Foam::solutionControl::nNonOrthCorr_
label nNonOrthCorr_
Maximum number of non-orthogonal correctors.
Definition: solutionControl.H:77
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
solutionControl.H
Foam::string::match
bool match(const std::string &) const
True when strings match literally.
Definition: stringI.H:179
Foam::solutionControl::read
virtual void read()
Read controls from fvSolution dictionary.
Definition: solutionControl.C:136
Foam::solutionControl::storePrevIterFields
virtual void storePrevIterFields() const
Store previous iteration fields.
Definition: solutionControl.C:164
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::solutionControl::applyToField
virtual label applyToField(const word &fieldName, const bool useRegEx=true) const
Return index of field in residualControl_ if present.
Definition: solutionControl.C:143
Foam::cmptMax
void cmptMax(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:224
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::ITstream
Input token stream.
Definition: ITstream.H:49
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::solutionControl::momentumPredictor_
bool momentumPredictor_
Flag to indicate to solve for momentum.
Definition: solutionControl.H:80
Foam::solutionControl::solutionControl
solutionControl(const solutionControl &)
Disallow default bitwise copy construct.
Foam::solutionControl::fieldData::initialResidual
scalar initialResidual
Definition: solutionControl.H:56
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
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::maxTypeResidual
void maxTypeResidual(const word &fieldName, ITstream &data, scalar &firstRes, scalar &lastRes) const
Definition: solutionControl.C:177
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::solutionControl::transonic_
bool transonic_
Flag to indicate to solve using transonic algorithm.
Definition: solutionControl.H:83
Foam::solutionControl::~solutionControl
virtual ~solutionControl()
Destructor.
Definition: solutionControl.C:238
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::solutionControl::fieldData::relTol
scalar relTol
Definition: solutionControl.H:55
Foam::solutionControl::maxResidual
scalar maxResidual(const word &fieldName, ITstream &data, scalar &lastRes) const
Definition: solutionControl.C:196
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::solutionControl::fieldData
Definition: solutionControl.H:51
Foam::List
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
Foam::solutionControl::consistent_
bool consistent_
Flag to indicate to relax pressure using the.
Definition: solutionControl.H:87
timeName
word timeName
Definition: getTimeIndex.H:3
solutionDict
fvSolution solutionDict(runTime)
Foam::solutionControl::fieldData::name
wordRe name
Definition: solutionControl.H:53
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47