meshState.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2020-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "meshState.H"
30 #include "Time.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
37 
38 
39 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
40 
41 bool Foam::meshState::getBoolEntry
42 (
43  const dictionary& dict,
44  const word& keyword
45 )
46 {
47  bool value = false;
48  return dict.readIfPresent(keyword, value) && value;
49 }
50 
51 
52 void Foam::meshState::setBoolEntry
53 (
54  dictionary& dict,
55  const word& keyword,
56  bool on
57 )
58 {
59  if (on)
60  {
61  dict.set(keyword, true);
62  }
63  else
64  {
65  dict.remove(keyword);
66  }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
72 Foam::meshState::meshState
73 (
74  const word& name,
75  const objectRegistry& obr,
76  const dictionary* content
77 )
78 :
79  IOdictionary
80  (
81  IOobject
82  (
83  name,
84  obr.time().system(),
85  obr,
86  IOobject::NO_READ,
87  IOobject::NO_WRITE,
88  IOobject::REGISTER
89  ),
90  content
91  ),
92  prevTimeIndex_(-1)
93 {
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
102 void Foam::meshState::reset(const meshState& ms)
103 {
105 }
106 
109 {
110  return subDict(controlsDictName);
111 }
112 
115 {
116  return subDict(controlsDictName);
117 }
118 
121 {
122  return subDict(meshDictName);
123 }
124 
127 {
128  return subDict(meshDictName);
129 }
130 
133 {
134  return subDict(solverPerformanceDictName);
135 }
136 
139 {
140  return subDict(solverPerformanceDictName);
141 }
142 
145 {
146  return getBoolEntry(controlsDict(), "firstIteration");
147 }
148 
151 {
152  return getBoolEntry(controlsDict(), "finalIteration");
153 }
154 
157 {
158  return setBoolEntry(controlsDict(), "firstIteration", on);
159 }
160 
161 
163 {
164  return setBoolEntry(controlsDict(), "finalIteration", on);
165 }
166 
167 
168 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
bool isFirstIteration() const
True if "firstIteration" entry exists (in controls) and is set.
Definition: meshState.C:137
Database for mesh data, solution data, solver performance and other reduced data. ...
Definition: meshState.H:53
static const word meshDictName
Name for "mesh" sub-dictionary.
Definition: meshState.H:105
bool isFinalIteration() const
True if "finalIteration" entry exists (in controls) and is set.
Definition: meshState.C:143
dictionary & subDictOrAdd(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary for manipulation.
Definition: dictionary.C:481
bool remove(const word &keyword)
Remove an entry specified by keyword.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void operator=(const dictionary &rhs)
Copy assignment.
Definition: dictionary.C:868
void setFinalIteration(bool on)
Add/remove "finalIteration" entry (from controls)
Definition: meshState.C:155
A class for handling words, derived from Foam::string.
Definition: word.H:63
void reset(const meshState &ms)
Reset the dictionary.
Definition: meshState.C:95
static const word controlsDictName
Name for "controls" sub-dictionary.
Definition: meshState.H:100
dictionary & solverPerformanceDict()
Return the dictionary of solver performance data which includes initial and final residuals for conve...
Definition: meshState.C:125
void setFirstIteration(bool on)
Add/remove "firstIteration" entry (from controls)
Definition: meshState.C:149
dictionary & controlsDict()
Return the dictionary of controls.
Definition: meshState.C:101
static const word solverPerformanceDictName
Name for "solver" (solver performance) sub-dictionary.
Definition: meshState.H:110
entry * set(entry *entryPtr)
Assign a new entry, overwriting any existing entry.
Definition: dictionary.C:765
int system(const std::string &command, const bool bg=false)
Execute the specified command via the shell.
Definition: POSIX.C:1702
dictionary & meshDict()
Return the dictionary of mesh data, typically populated by the polyMesh::checkXXX functions...
Definition: meshState.C:113