Loading...
Searching...
No Matches
fvExprDriverIO.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) 2010-2018 Bernhard Gschaider
9 Copyright (C) 2019-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "fvExprDriver.H"
30#include "fvExprDriverWriter.H"
31#include "cellSet.H"
32#include "faceSet.H"
33#include "pointSet.H"
34
35// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
36
39(
40 const word& name,
41 enum topoSetSource::sourceType setType
42) const
43{
44 refPtr<labelList> selected;
45
46 // Zones first
47 // - cheap to handle (no IO) and can simply reference their labels
48
49 switch (setType)
50 {
52 {
53 const auto& zones = mesh().cellZones();
54 const word& zoneTypeName = cellZone::typeName;
55
56 const label zoneID = zones.findZoneID(name);
57 if (zoneID < 0)
58 {
60 << "No " << zoneTypeName << " named "
61 << name << "found. Has zones: " << zones.names() << endl
62 << exit(FatalError);
63 }
64
65 selected.cref(zones[zoneID]);
66 break;
67 }
68
70 {
71 const auto& zones = mesh().faceZones();
72 const word& zoneTypeName = faceZone::typeName;
73
74 const label zoneID = zones.findZoneID(name);
75 if (zoneID < 0)
76 {
78 << "No " << zoneTypeName << " named "
79 << name << "found. Has zones: " << zones.names() << endl
80 << exit(FatalError);
81 }
82
83 selected.cref(zones[zoneID]);
84 break;
85 }
86
88 {
89 const auto& zones = mesh().pointZones();
90 const word& zoneTypeName = pointZone::typeName;
91
92 const label zoneID = zones.findZoneID(name);
93 if (zoneID < 0)
94 {
96 << "No " << zoneTypeName << " named "
97 << name << "found. Has zones: " << zones.names() << endl
98 << exit(FatalError);
99 }
100
101 selected.cref(zones[zoneID]);
102 break;
103 }
104
105 default:
106 break;
107 }
108
109
110 if (selected.good())
111 {
112 return selected;
113 }
114
115
117
118 switch (setType)
119 {
121 {
122 typedef cellSet classType;
123
124 if (!io.isHeaderClass<classType>())
125 {
127 << "Error reading " << classType::typeName
128 << " <" << name << "> : found "
129 << io.headerClassName() << nl
130 << exit(FatalError);
131 }
132
133 classType set(io);
134 selected.reset(refPtr<labelList>::New(set.sortedToc()));
135 break;
136 }
137
139 {
140 typedef faceSet classType;
141
142 if (!io.isHeaderClass<classType>())
143 {
145 << "Error reading " << classType::typeName
146 << " <" << name << "> : found "
147 << io.headerClassName() << nl
148 << exit(FatalError);
149 }
150
151 classType set(io);
152 selected.reset(refPtr<labelList>::New(set.sortedToc()));
153 break;
154 }
155
157 {
158 typedef pointSet classType;
159
160 if (!io.isHeaderClass<classType>())
161 {
163 << "Error reading " << classType::typeName
164 << " <" << name << "> : found "
165 << io.headerClassName() << nl
166 << exit(FatalError);
167 }
168
169 classType set(io);
170 selected.reset(refPtr<labelList>::New(set.sortedToc()));
171 break;
172 }
173
174 default:
175 {
177 << "Unexpected sourceType: " << int(setType) << nl
178 << " for set <" << name << ">" << nl
179 << exit(FatalError);
180 break;
181 }
182 }
183
184 return selected;
185}
186
187
188Foam::word Foam::expressions::fvExprDriver::getHeaderClassName
189(
190 const polyMesh& mesh,
191 const word& name
192)
193{
195 (
196 name,
197 mesh.time().timeName(),
198 mesh,
201 );
202 io.typeHeaderOk<regIOobject>(false);
203
205 << "Registry: " << mesh.path()
206 << " Name: " << name
207 << " Time: " << mesh.time().timeName()
208 << " Path: " << io.localFilePath(io.headerClassName())
209 << " Class: " << io.headerClassName() << endl;
211 return io.headerClassName();
212}
213
214
215// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
216
218(
219 Ostream& os,
220 bool debug
221) const
222{
223 // Write "variables", even if empty
224 writeVariableStrings(os, "variables");
225
226 if (debug)
227 {
228 os.writeEntry("variableValues", variables_);
229 }
230
231 if (!storedVariables_.empty() || !delayedVariables_.empty())
232 {
233 const_cast<fvExprDriver&>
234 (
235 *this
236 ).updateSpecialVariables(true);
237 }
238
239 if (!storedVariables_.empty())
240 {
241 os.writeEntry("storedVariables", storedVariables_);
242 }
243
244 if (!delayedVariables_.empty())
245 {
246 List<exprResultDelayed> list(delayedVariables_.size());
247
248 auto outIter = list.begin();
249
250 forAllConstIters(delayedVariables_, iter)
251 {
252 *outIter = *iter;
253 ++outIter;
254 }
255
256 os.writeEntry("delayedVariables", list);
257 }
258
259 if (!globalScopes_.empty())
260 {
261 os.writeEntry("globalScopes", globalScopes_);
262 }
263
264 // Write "functions<scalar>" ...
266
267 return os;
268}
269
270
272{
273 if (!writer_ && hasDataToWrite())
274 {
275 writer_.reset(new fvExprDriverWriter(name + "_" + this->type(), *this));
276 }
277}
278
279
281{
282 if (writer_ && mesh().time().writeTime())
283 {
284 writer_->write();
285 }
286}
287
288
289// ************************************************************************* //
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition UListI.H:410
A collection of cell labels.
Definition cellSet.H:50
Ostream & writeVariableStrings(Ostream &os, const word &keyword="") const
Write "variables".
void writeFunctions(Ostream &os) const
Write scalar/vector Function1 entries in dictionary format.
HashTable< exprResult > variables_
The variables table.
Definition exprDriver.H:211
virtual void updateSpecialVariables(bool force=false)
Examine current variable values and update stored variables.
virtual bool hasDataToWrite() const
Do we need a data file to be written.
virtual const fvMesh & mesh() const =0
The mesh we are attached to.
void tryWrite() const
Write data if appropriate Should enable exact restarts.
fvExprDriver(enum exprDriver::searchControls search=exprDriver::searchControls::DEFAULT_SEARCH, const dictionary &dict=dictionary::null)
Default construct, and default construct with search preferences.
void createWriterAndRead(const word &name)
Create a writer for this object.
Ostream & writeCommon(Ostream &os, bool debug=false) const
Write "variables", "storedVariables", "delayedVariables", "globalScopes" if they are present.
refPtr< labelList > getTopoSetLabels(const word &name, enum topoSetSource::sourceType setType) const
Get the labels associated with the topo set.
A list of face labels.
Definition faceSet.H:50
A set of point labels.
Definition pointSet.H:50
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition polyMesh.H:671
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition polyMesh.H:679
const pointZoneMesh & pointZones() const noexcept
Return point zone mesh.
Definition polyMesh.H:663
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
Definition refPtrI.H:216
bool good() const noexcept
True if pointer/reference is non-null.
Definition refPtr.H:221
void reset(T *p=nullptr) noexcept
Delete managed pointer and set to new given pointer.
Definition refPtrI.H:314
static refPtr< T > New(Args &&... args)
Construct refPtr with forwarding arguments.
Definition refPtr.H:187
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
sourceType
Enumeration defining the types of sources.
@ POINTSET_SOURCE
Points as set.
@ FACESET_SOURCE
Faces as set.
@ FACEZONE_SOURCE
Faces as zone.
@ POINTZONE_SOURCE
Points as zone.
@ CELLSET_SOURCE
Cells as set.
@ CELLZONE_SOURCE
Cells as zone.
static IOobject findIOobject(const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE, IOobjectOption::registerOption reg=IOobjectOption::LEGACY_REGISTER)
Find IOobject in the polyMesh/sets/ (used as constructor helper).
Definition topoSet.C:352
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
const auto & io
#define DebugInfo
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Definition debug.C:45
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition POSIX.C:801
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition stdFoam.H:235