Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
35namespace Foam
36{
39 (
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
63 (
64 pointsFile, // absolute path
65 runTime,
69 true // global object (currently not used)
70 );
71
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
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
102void Foam::boundaryDataSurfaceReader::readCase()
103{
105
106 timeValues_ = TimePaths::findTimes(baseDir_);
107}
108
109
110void Foam::boundaryDataSurfaceReader::readGeometry
111(
112 meshedSurface& surf,
113 const label timeIndex
114)
115{
116 surf.clear();
117
118 pointField points(this->readPoints(baseDir_, pointsName_));
120 surf = meshedSurface(std::move(points), faceList());
121}
122
123
124template<class Type>
126Foam::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;
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
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
222 std::transform
223 (
224 items.begin(),
225 items.end(),
226 fieldNames_.begin(),
227 [](const fileName& f) { return word(f); }
228 );
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
@ NO_REGISTER
Do not request registration (bool: false).
@ 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
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition ListI.H:171
static instantList findTimes(const fileName &directory, const word &constantDirName="constant")
Search a given directory for valid time directories.
Definition TimePaths.C:109
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
static autoPtr< Time > NewGlobalTime()
Construct (dummy) global Time - no functionObjects or libraries, using the global path information st...
Definition TimeNew.C:78
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition UListI.H:410
iterator end() noexcept
Return an iterator to end traversing the UList.
Definition UListI.H:454
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A boundaryData format surface reader. However, the "surface" represented by boundaryData is actually ...
virtual instantList times() const
Return a list of the available times.
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.
boundaryDataSurfaceReader(const fileName &fName, const word &pointsName="points")
Construct from fileName.
static pointField readPoints(const Time &runTime, const fileName &baseDir, const word &pointsName="points")
Read points file.
static tmp< Field< Type > > readField(const Time &runTime, const fileName &baseDir, const instant &timeDir, const word &fieldName, Type &avg)
Read and return given field.
virtual const meshedSurface & geometry(const label timeIndex)
Return a reference to the surface geometry.
virtual wordList fieldNames(const label timeIndex) const
Return a list of the available fields at a given time.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
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...
A class for handling file names.
Definition fileName.H:75
fileName & toAbsolute()
Convert from relative to absolute.
Definition fileName.C:370
Like IOField but falls back to raw IFstream if no header found. Optionally reads average value....
Definition rawIOField.H:52
const Field< Type > & field() const noexcept
The field content.
Definition rawIOField.H:139
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
Abstract base class for surface readers with fields.
surfaceReader(const fileName &fName)
Construct from fileName.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
engineTime & runTime
const auto & io
auto & name
const pointField & points
#define DebugInfo
Report an information message using Foam::Info.
#define DebugInFunction
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< fileName > fileNameList
List of fileName.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler().
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< face > faceList
List of faces.
Definition faceListFwd.H:41
List< instant > instantList
List of instants.
Definition instantList.H:41
Tensor< scalar > tensor
Definition symmTensor.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
MeshedSurface< face > meshedSurface
void sort(UList< T > &list)
Sort the list.
Definition UList.C:283
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
Definition symmTensor.H:55
label timeIndex
labelList f(nPoints)