boundaryDataSurfaceReader.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) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 #include "rawIOField.H"
30 #include "argList.H"
31 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(boundaryDataSurfaceReader, 0);
40  (
41  surfaceReader,
42  boundaryDataSurfaceReader,
43  fileName
44  );
45 }
46 
47 
48 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
49 
51 (
52  const Time& runTime,
53  const fileName& baseDir,
54  const word& pointsName
55 )
56 {
57  fileName pointsFile
58  (
59  baseDir / (pointsName.empty() ? "points" : pointsName)
60  );
61  pointsFile.toAbsolute();
62 
63  IOobject io
64  (
65  pointsFile, // absolute path
66  runTime,
70  true // global object (currently not used)
71  );
72 
73  DebugInfo
74  << "File: " << io.objectPath() << endl;
75 
76  // Read data (no average value!)
77  rawIOField<point> rawData(io);
78 
79  pointField points(std::move(rawData.field()));
80 
81  DebugInfo
82  << "File: " << io.objectPath()
83  << " " << points.size() << " points" << endl;
84 
85  return points;
86 }
87 
88 
90 (
91  const fileName& dirName,
92  const word& pointsName
93 )
94 {
96 
97  return readPoints(*timePtr, dirName, pointsName);
98 }
99 
100 
101 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
102 
103 void Foam::boundaryDataSurfaceReader::readCase()
104 {
106 
107  timeValues_ = TimePaths::findTimes(baseDir_);
108 }
109 
110 
111 void Foam::boundaryDataSurfaceReader::readGeometry
112 (
113  meshedSurface& surf,
114  const label timeIndex
115 )
116 {
117  surf.clear();
118 
119  pointField points(this->readPoints(baseDir_, pointsName_));
120 
121  surf = meshedSurface(std::move(points), faceList());
122 }
123 
124 
125 template<class Type>
127 Foam::boundaryDataSurfaceReader::readFieldTemplate
128 (
129  const label timeIndex,
130  const label fieldIndex
131 ) const
132 {
133  Type dummyAvg;
134 
135  return readField<Type>
136  (
137  baseDir_,
138  timeValues_[timeIndex],
139  fieldNames_[fieldIndex],
140  dummyAvg
141  );
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
146 
148 (
149  const fileName& fName,
150  const word& pointsName
151 )
152 :
153  boundaryDataSurfaceReader(fName, dictionary(), pointsName)
154 {}
155 
156 
158 (
159  const fileName& fName,
160  const dictionary& options,
161  const word& pointsName
162 )
163 :
164  surfaceReader(fName, options),
165  baseDir_(fName.path()),
166  pointsName_(pointsName),
167  timeValues_(),
168  fieldNames_(),
169  surfPtr_(nullptr)
170 {
171  options.readIfPresent("points", pointsName_);
172 
173  baseDir_.toAbsolute();
174  debug = 1;
176  Info<< "create with " << baseDir_ << endl;
177 
178  readCase();
179 }
180 
181 
182 // * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
183 
185 (
186  const label timeIndex
187 )
188 {
190 
191  if (!surfPtr_)
192  {
193  surfPtr_.reset(new meshedSurface);
194  readGeometry(*surfPtr_, timeIndex);
195  }
196 
197  return *surfPtr_;
198 }
199 
200 
202 {
203  return timeValues_;
204 }
205 
206 
208 (
209  const label timeIndex
210 ) const
211 {
212  if (timeValues_.empty() || timeIndex >= timeValues_.size())
213  {
214  fieldNames_.clear();
215  return wordList();
216  }
217 
218  fileNameList items =
219  fileHandler().readDir(baseDir_/timeValues_[timeIndex].name());
220 
221  fieldNames_.resize_nocopy(items.size());
222 
224  (
225  items.begin(),
226  items.end(),
227  fieldNames_.begin(),
228  [](const fileName& f) { return word(f); }
229  );
230 
231  Foam::sort(fieldNames_);
232 
233  return fieldNames_;
234 }
235 
236 
238 (
239  const label timeIndex,
240  const label fieldIndex,
241  const scalar& refValue
242 ) const
243 {
244  return readFieldTemplate<scalar>(timeIndex, fieldIndex);
245 }
246 
247 
249 (
250  const label timeIndex,
251  const label fieldIndex,
252  const vector& refValue
253 ) const
254 {
255  return readFieldTemplate<vector>(timeIndex, fieldIndex);
256 }
257 
258 
261 (
262  const label timeIndex,
263  const label fieldIndex,
264  const sphericalTensor& refValue
265 ) const
266 {
267  return readFieldTemplate<sphericalTensor>(timeIndex, fieldIndex);
268 }
269 
270 
272 (
273  const label timeIndex,
274  const label fieldIndex,
275  const symmTensor& refValue
276 ) const
277 {
278  return readFieldTemplate<symmTensor>(timeIndex, fieldIndex);
279 }
280 
281 
283 (
284  const label timeIndex,
285  const label fieldIndex,
286  const tensor& refValue
287 ) const
288 {
289  return readFieldTemplate<tensor>(timeIndex, fieldIndex);
290 }
291 
292 
293 // ************************************************************************* //
A boundaryData format surface reader. However, the "surface" represented by boundaryData is actually ...
A class for handling file names.
Definition: fileName.H:71
static pointField readPoints(const Time &runTime, const fileName &baseDir, const word &pointsName="points")
Read points file.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
virtual const meshedSurface & geometry(const label timeIndex)
Return a reference to the surface geometry.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:707
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
Ignore writing from objectRegistry::writeObject()
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
Like IOField but falls back to raw IFstream if no header found. Optionally reads average value...
Definition: rawIOField.H:48
Macros for easy insertion into run-time selection tables.
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
const pointField & points
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:109
A class for handling words, derived from Foam::string.
Definition: word.H:63
MeshedSurface< face > meshedSurface
#define DebugInFunction
Report an information message using Foam::Info.
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:348
virtual instantList times() const
Return a list of the available times.
#define DebugInfo
Report an information message using Foam::Info.
fileName & toAbsolute()
Convert from relative to absolute.
Definition: fileName.C:370
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
int debug
Static debugging option.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
defineTypeNameAndDebug(combustionModel, 0)
labelList f(nPoints)
virtual wordList fieldNames(const label timeIndex) const
Return a list of the available fields at a given time.
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
List< word > wordList
List of word.
Definition: fileName.H:58
static instantList findTimes(const fileName &directory, const word &constantName="constant")
Search a given directory for valid time directories.
Definition: TimePaths.C:133
static fileName envGlobalPath()
Global case (directory) from environment variable.
Definition: argList.C:651
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
List< fileName > fileNameList
List of fileName.
Definition: fileNameList.H:32
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
Tensor of scalars, i.e. Tensor<scalar>.
Abstract base class for surface readers with fields.
Definition: surfaceReader.H:67
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:171
boundaryDataSurfaceReader(const fileName &fName, const word &pointsName="points")
Construct from fileName.
virtual tmp< Field< scalar > > field(const label timeIndex, const label fieldIndex, const scalar &refValue=pTraits< scalar >::zero) const
Return a scalar field at a given time.
Do not request registration (bool: false)
Namespace for OpenFOAM.
label timeIndex
Definition: getTimeIndex.H:24