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-2023 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 "Time.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(boundaryDataSurfaceReader, 0);
39  (
40  surfaceReader,
41  boundaryDataSurfaceReader,
42  fileName
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
48 
50 (
51  const Time& runTime,
52  const fileName& baseDir,
53  const word& pointsName
54 )
55 {
56  fileName pointsFile
57  (
58  baseDir / (pointsName.empty() ? "points" : pointsName)
59  );
60  pointsFile.toAbsolute();
61 
62  IOobject io
63  (
64  pointsFile, // absolute path
65  runTime,
69  true // global object (currently not used)
70  );
71 
72  DebugInfo
73  << "File: " << io.objectPath() << endl;
74 
75  // Read data (no average value!)
76  rawIOField<point> rawData(io);
77 
78  pointField points(std::move(rawData.field()));
79 
80  DebugInfo
81  << "File: " << io.objectPath()
82  << " " << points.size() << " points" << endl;
83 
84  return points;
85 }
86 
87 
89 (
90  const fileName& dirName,
91  const word& pointsName
92 )
93 {
95 
96  return readPoints(*timePtr, dirName, pointsName);
97 }
98 
99 
100 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
101 
102 void Foam::boundaryDataSurfaceReader::readCase()
103 {
105 
106  timeValues_ = TimePaths::findTimes(baseDir_);
107 }
108 
109 
110 void Foam::boundaryDataSurfaceReader::readGeometry
111 (
112  meshedSurface& surf,
113  const label timeIndex
114 )
115 {
116  surf.clear();
117 
118  pointField points(this->readPoints(baseDir_, pointsName_));
119 
120  surf = meshedSurface(std::move(points), faceList());
121 }
122 
123 
124 template<class Type>
126 Foam::boundaryDataSurfaceReader::readFieldTemplate
127 (
128  const label timeIndex,
129  const label fieldIndex
130 ) const
131 {
132  Type dummyAvg;
133 
134  return readField<Type>
135  (
136  baseDir_,
137  timeValues_[timeIndex],
138  fieldNames_[fieldIndex],
139  dummyAvg
140  );
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
145 
147 (
148  const fileName& fName,
149  const word& pointsName
150 )
151 :
152  boundaryDataSurfaceReader(fName, dictionary(), pointsName)
153 {}
154 
155 
157 (
158  const fileName& fName,
159  const dictionary& options,
160  const word& pointsName
161 )
162 :
163  surfaceReader(fName, options),
164  baseDir_(fName.path()),
165  pointsName_(pointsName),
166  timeValues_(),
167  fieldNames_(),
168  surfPtr_(nullptr)
169 {
170  options.readIfPresent("points", pointsName_);
171 
172  baseDir_.toAbsolute();
173  debug = 1;
175  Info<< "create with " << baseDir_ << endl;
176 
177  readCase();
178 }
179 
180 
181 // * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
182 
184 (
185  const label timeIndex
186 )
187 {
189 
190  if (!surfPtr_)
191  {
192  surfPtr_.reset(new meshedSurface);
193  readGeometry(*surfPtr_, timeIndex);
194  }
195 
196  return *surfPtr_;
197 }
198 
199 
201 {
202  return timeValues_;
203 }
204 
205 
207 (
208  const label timeIndex
209 ) const
210 {
211  if (timeValues_.empty() || timeIndex >= timeValues_.size())
212  {
213  fieldNames_.clear();
214  return wordList();
215  }
216 
217  fileNameList items =
218  fileHandler().readDir(baseDir_/timeValues_[timeIndex].name());
219 
220  fieldNames_.resize_nocopy(items.size());
221 
223  (
224  items.begin(),
225  items.end(),
226  fieldNames_.begin(),
227  [](const fileName& f) { return word(f); }
228  );
229 
230  Foam::sort(fieldNames_);
231 
232  return fieldNames_;
233 }
234 
235 
237 (
238  const label timeIndex,
239  const label fieldIndex,
240  const scalar& refValue
241 ) const
242 {
243  return readFieldTemplate<scalar>(timeIndex, fieldIndex);
244 }
245 
246 
248 (
249  const label timeIndex,
250  const label fieldIndex,
251  const vector& refValue
252 ) const
253 {
254  return readFieldTemplate<vector>(timeIndex, fieldIndex);
255 }
256 
257 
260 (
261  const label timeIndex,
262  const label fieldIndex,
263  const sphericalTensor& refValue
264 ) const
265 {
266  return readFieldTemplate<sphericalTensor>(timeIndex, fieldIndex);
267 }
268 
269 
271 (
272  const label timeIndex,
273  const label fieldIndex,
274  const symmTensor& refValue
275 ) const
276 {
277  return readFieldTemplate<symmTensor>(timeIndex, fieldIndex);
278 }
279 
280 
282 (
283  const label timeIndex,
284  const label fieldIndex,
285  const tensor& refValue
286 ) const
287 {
288  return readFieldTemplate<tensor>(timeIndex, fieldIndex);
289 }
290 
291 
292 // ************************************************************************* //
A boundaryData format surface reader. However, the "surface" represented by boundaryData is actually ...
A class for handling file names.
Definition: fileName.H:72
static autoPtr< Time > NewGlobalTime()
Construct (dummy) global Time - no functionObjects or libraries, using the global path information st...
Definition: TimeNew.C:78
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:129
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual const meshedSurface & geometry(const label timeIndex)
Return a reference to the surface geometry.
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 expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const pointField & points
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
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:296
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.
static instantList findTimes(const fileName &directory, const word &constantDirName="constant")
Search a given directory for valid time directories.
Definition: TimePaths.C:109
List< word > wordList
List of word.
Definition: fileName.H:59
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:172
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
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)