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.valid())
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<IOobject>(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;
210
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>" ...
265 writeFunctions(os);
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().outputTime())
283 {
284 writer_->write();
285 }
286}
287
288
289// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
bool isHeaderClass() const
Check if headerClassName() equals Type::typeName.
Definition: IOobjectI.H:156
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:83
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:329
A collection of cell labels.
Definition: cellSet.H:54
Registered input/output for an expressions::fvExprDriver.
Base driver for parsing value expressions associated with an fvMesh.
Definition: fvExprDriver.H:139
virtual const fvMesh & mesh() const =0
The mesh we are attached to.
void createWriterAndRead(const word &name)
Create a writer for this object.
Ostream & writeCommon(Ostream &os, bool debug=false) const
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:54
A set of point labels.
Definition: pointSet.H:54
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
const faceZoneMesh & faceZones() const noexcept
Return face zone mesh.
Definition: polyMesh.H:498
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:504
const pointZoneMesh & pointZones() const noexcept
Return point zone mesh.
Definition: polyMesh.H:492
A class for managing references or pointers (no reference counting)
Definition: refPtr.H:58
const T & cref() const
Definition: refPtrI.H:189
bool valid() const noexcept
Identical to good(), or bool operator.
Definition: refPtr.H:300
void reset(refPtr< T > &&other) noexcept
Clear existing and transfer ownership.
Definition: refPtrI.H:303
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:75
@ POINTSET_SOURCE
Points as set.
Definition: topoSetSource.H:84
@ FACESET_SOURCE
Faces as set.
Definition: topoSetSource.H:83
@ FACEZONE_SOURCE
Faces as zone.
Definition: topoSetSource.H:88
@ POINTZONE_SOURCE
Points as zone.
Definition: topoSetSource.H:89
@ CELLSET_SOURCE
Cells as set.
Definition: topoSetSource.H:82
@ CELLZONE_SOURCE
Cells as zone.
Definition: topoSetSource.H:87
static IOobject findIOobject(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Find IOobject in the polyMesh/sets (used as constructor helper)
Definition: topoSet.C:318
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
const labelIOList & zoneID
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
#define DebugInfo
Report an information message using Foam::Info.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278
static const char *const typeName
The type name used in ensight case files.