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 <bgschaid@hfd-research.com>
9  Copyright (C) 2019-2020 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 "fvExprDriver.H"
30 #include "exprDriverWriter.H"
31 #include "cellSet.H"
32 #include "faceSet.H"
33 #include "pointSet.H"
34 
35 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
36 
38 (
39  const word& name,
40  enum topoSetSource::sourceType setType
41 ) const
42 {
43  // Zones first - they are cheap to handle (no IO)
44 
45  switch (setType)
46  {
47  case topoSetSource::sourceType::CELLZONE_SOURCE:
48  {
49  const auto& zones = mesh().cellZones();
50  const word& zoneTypeName = cellZone::typeName;
51 
52  const label zoneID = zones.findZoneID(name);
53  if (zoneID < 0)
54  {
56  << "No " << zoneTypeName << " named "
57  << name << "found. Has zones: " << zones.names() << endl
58  << exit(FatalError);
59  }
60 
61  return zones[zoneID];
62  break;
63  }
64 
65  case topoSetSource::sourceType::FACEZONE_SOURCE:
66  {
67  const auto& zones = mesh().faceZones();
68  const word& zoneTypeName = faceZone::typeName;
69 
70  const label zoneID = zones.findZoneID(name);
71  if (zoneID < 0)
72  {
74  << "No " << zoneTypeName << " named "
75  << name << "found. Has zones: " << zones.names() << endl
76  << exit(FatalError);
77  }
78 
79  return zones[zoneID];
80  break;
81  }
82 
83  case topoSetSource::sourceType::POINTZONE_SOURCE:
84  {
85  const auto& zones = mesh().pointZones();
86  const word& zoneTypeName = pointZone::typeName;
87 
88  const label zoneID = zones.findZoneID(name);
89  if (zoneID < 0)
90  {
92  << "No " << zoneTypeName << " named "
93  << name << "found. Has zones: " << zones.names() << endl
94  << exit(FatalError);
95  }
96 
97  return zones[zoneID];
98  break;
99  }
100 
101  default:
102  break;
103  }
104 
105 
106  IOobject io(topoSet::findIOobject(mesh(), name));
107 
108  switch (setType)
109  {
110  case topoSetSource::sourceType::CELLSET_SOURCE:
111  {
112  typedef cellSet classType;
113 
114  if (classType::typeName != io.headerClassName())
115  {
117  << "Error reading " << classType::typeName
118  << " <" << name << "> : found "
119  << io.headerClassName() << nl
120  << exit(FatalError);
121  }
122 
123  classType set(io);
124  return set.sortedToc();
125  break;
126  }
127 
128  case topoSetSource::sourceType::FACESET_SOURCE:
129  {
130  typedef faceSet classType;
131 
132  if (classType::typeName != io.headerClassName())
133  {
135  << "Error reading " << classType::typeName
136  << " <" << name << "> : found "
137  << io.headerClassName() << nl
138  << exit(FatalError);
139  }
140 
141  classType set(io);
142  return set.sortedToc();
143  break;
144  }
145 
146  case topoSetSource::sourceType::POINTSET_SOURCE:
147  {
148  typedef pointSet classType;
149 
150  if (classType::typeName != io.headerClassName())
151  {
153  << "Error reading " << classType::typeName
154  << " <" << name << "> : found "
155  << io.headerClassName() << nl
156  << exit(FatalError);
157  }
158 
159  classType set(io);
160  return set.sortedToc();
161  break;
162  }
163 
164  default:
165  {
167  << "Unexpected sourceType: " << int(setType) << nl
168  << " for set <" << name << ">" << nl
169  << exit(FatalError);
170  break;
171  }
172  }
173 
174  return labelList::null();
175 }
176 
177 
178 Foam::word Foam::expressions::fvExprDriver::getHeaderClassName
179 (
180  const polyMesh& mesh,
181  const word& name
182 )
183 {
184  IOobject io
185  (
186  name,
187  mesh.time().timeName(),
188  mesh,
191  );
192  io.typeHeaderOk<IOobject>(false);
193 
194  DebugInfo
195  << "Registry: " << mesh.path()
196  << " Name: " << name
197  << " Time: " << mesh.time().timeName()
198  << " Path: " << io.localFilePath(io.headerClassName())
199  << " Class: " << io.headerClassName() << endl;
200 
201  return io.headerClassName();
202 }
203 
204 
205 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
206 
208 (
209  Ostream& os,
210  bool debug
211 ) const
212 {
213  // Write "variables", even if empty
214  writeVariableStrings(os, "variables");
215 
216  if (debug)
217  {
218  os.writeEntry("variableValues", variables_);
219  }
220 
221  if (!storedVariables_.empty() || !delayedVariables_.empty())
222  {
223  const_cast<fvExprDriver&>
224  (
225  *this
226  ).updateSpecialVariables(true);
227  }
228 
229  if (!storedVariables_.empty())
230  {
231  os.writeEntry("storedVariables", storedVariables_);
232  }
233 
234  if (!delayedVariables_.empty())
235  {
236  List<exprResultDelayed> list(delayedVariables_.size());
237 
238  auto outIter = list.begin();
239 
240  forAllConstIters(delayedVariables_, iter)
241  {
242  *outIter = *iter;
243  ++outIter;
244  }
245 
246  os.writeEntry("delayedVariables", list);
247  }
248 
249  if (!globalScopes_.empty())
250  {
251  os.writeEntry("globalScopes", globalScopes_);
252  }
253 
254  // writeTable(os, "timelines", lines_);
255  // writeTable(os, "lookuptables", lookup_);
256  // writeTable(os, "lookuptables2D", lookup2D_);
257 
258  return os;
259 }
260 
261 
263 {
264  if (!writer_ && hasDataToWrite())
265  {
266  writer_.reset(new exprDriverWriter(name + "_" + this->type(), *this));
267  }
268 }
269 
270 
272 {
273  if (writer_ && mesh().time().outputTime())
274  {
275  writer_->write();
276  }
277 }
278 
279 
280 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::topoSetSource::sourceType
sourceType
Enumeration defining the types of sources.
Definition: topoSetSource.H:73
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::IOobject::typeHeaderOk
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) and check its info.
Definition: IOobjectTemplates.C:39
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::faceSet
A list of face labels.
Definition: faceSet.H:51
Foam::expressions::fvExprDriver
Base driver for parsing value expressions associated with an fvMesh.
Definition: fvExprDriver.H:137
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
fvExprDriver.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::expressions::fvExprDriver::getTopoSetLabels
labelList getTopoSetLabels(const word &name, enum topoSetSource::sourceType setType) const
Read and return labels associated with the topo set.
Definition: fvExprDriverIO.C:38
Foam::expressions::fvExprDriver::mesh
virtual const fvMesh & mesh() const =0
The mesh we are attached to.
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::expressions::fvExprDriver::writeCommon
Ostream & writeCommon(Ostream &os, bool debug=false) const
Definition: fvExprDriverIO.C:208
faceSet.H
exprDriverWriter.H
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::IOobject::headerClassName
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobjectI.H:88
Foam::expressions::fvExprDriver::createWriterAndRead
void createWriterAndRead(const word &name)
Create a writer for this object.
Definition: fvExprDriverIO.C:262
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:359
Foam::nl
constexpr char nl
Definition: Ostream.H:385
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::pointSet
A set of point labels.
Definition: pointSet.H:51
Foam::expressions::fvExprDriver::tryWrite
void tryWrite() const
Definition: fvExprDriverIO.C:271
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::expressions::exprDriverWriter
Registered input/output for an expressions::fvExprDriver.
Definition: exprDriverWriter.H:54
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:275
cellSet.H
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOobject::path
fileName path() const
The complete path.
Definition: IOobject.C:481
Foam::IOobject::MUST_READ
Definition: IOobject.H:120
pointSet.H