equationInitialResidualCondition.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) 2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 
28 #include "fvMesh.H"
29 #include "Time.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(equationInitialResidualCondition, 0);
37  (
38  runTimeCondition,
39  equationInitialResidualCondition,
40  dictionary
41  );
42 
43  template<>
44  const char* Foam::NamedEnum
45  <
47  2
48  >::names[] =
49  {
50  "minimum",
51  "maximum"
52  };
53 
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 (
63  const word& name,
64  const objectRegistry& obr,
65  const dictionary& dict,
66  functionObjectState& state
67 )
68 :
69  runTimeCondition(name, obr, dict, state),
70  fieldNames_(dict.lookup("fields")),
71  value_(readScalar(dict.lookup("value"))),
72  timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
73  mode_(operatingModeNames.read(dict.lookup("mode")))
74 {
75  if (!fieldNames_.size())
76  {
78  << "No fields supplied: deactivating" << endl;
79 
80  active_ = false;
81  }
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
86 
89 {}
90 
91 
92 // * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
93 
95 {
96  bool satisfied = false;
97 
98  if (!active_)
99  {
100  return true;
101  }
102 
103  if ((obr_.time().timeIndex() < 3) || (obr_.time().value() < timeStart_))
104  {
105  // Do not start checking until reached start time
106  return false;
107  }
108 
109  const fvMesh& mesh = refCast<const fvMesh>(obr_);
110  const dictionary& solverDict = mesh.solverPerformanceDict();
111 
112  List<scalar> result(fieldNames_.size(), -VGREAT);
113 
114  forAll(fieldNames_, fieldI)
115  {
116  const word& fieldName = fieldNames_[fieldI];
117 
118  if (solverDict.found(fieldName))
119  {
120  const List<solverPerformance> sp(solverDict.lookup(fieldName));
121  const scalar residual = sp.first().initialResidual();
122  result[fieldI] = residual;
123 
124  switch (mode_)
125  {
126  case omMin:
127  {
128  if (residual < value_)
129  {
130  satisfied = true;
131  }
132  break;
133  }
134  case omMax:
135  {
136  if (residual > value_)
137  {
138  satisfied = true;
139  }
140  break;
141  }
142  default:
143  {
145  << "Unhandled enumeration "
146  << operatingModeNames[mode_]
147  << abort(FatalError);
148  }
149  }
150  }
151  }
152 
153  bool valid = false;
154  forAll(result, i)
155  {
156  if (result[i] < 0)
157  {
159  << "Initial residual data not found for field "
160  << fieldNames_[i] << endl;
161  }
162  else
163  {
164  valid = true;
165  }
166  }
167 
168  if (!valid)
169  {
171  << "Initial residual data not found for any fields: "
172  << "deactivating" << endl;
173 
174  active_ = false;
175  }
176 
177  if (satisfied && valid)
178  {
179  if (log_)
180  {
181  Info<< type() << ": " << name_
182  << ": satisfied using threshold value: " << value_ << nl;
183  }
184 
185  forAll(result, resultI)
186  {
187  if (result[resultI] > 0)
188  {
189  if (log_)
190  {
191  Info<< " field: " << fieldNames_[resultI]
192  << ", residual: " << result[resultI] << nl;
193  }
194  }
195  }
196  if (log_) Info<< endl;
197  }
198 
199  return satisfied;
200 }
201 
202 
204 {
205  // do nothing
206 }
207 
208 
209 // ************************************************************************* //
Foam::runTimeCondition
Base class for run time conditions.
Definition: runTimeCondition.H:54
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
equationInitialResidualCondition.H
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::equationInitialResidualCondition::operatingModeNames
static const NamedEnum< operatingMode, 2 > operatingModeNames
Definition: equationInitialResidualCondition.H:62
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::data::solverPerformanceDict
const dictionary & solverPerformanceDict() const
Return the dictionary of solver performance data.
Definition: data.C:56
dict
dictionary dict
Definition: searchingEngine.H:14
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
Foam::equationInitialResidualCondition::apply
virtual bool apply()
Apply the condition.
Definition: equationInitialResidualCondition.C:94
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
readScalar
#define readScalar
Definition: doubleScalar.C:38
Foam::equationInitialResidualCondition::equationInitialResidualCondition
equationInitialResidualCondition(const word &name, const objectRegistry &obr, const dictionary &dict, functionObjectState &state)
Constructor.
Definition: equationInitialResidualCondition.C:62
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::List< scalar >
Foam::equationInitialResidualCondition::operatingMode
operatingMode
Definition: equationInitialResidualCondition.H:56
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::NamedEnum
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
Foam::equationInitialResidualCondition::write
virtual void write()
Write.
Definition: equationInitialResidualCondition.C:203
Foam::equationInitialResidualCondition::~equationInitialResidualCondition
virtual ~equationInitialResidualCondition()
Destructor.
Definition: equationInitialResidualCondition.C:88