ensightSurfaceReaderTemplates.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) 2015-2020 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
28#include <iomanip>
29#include <sstream>
30
31// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32
33template<class Type>
35(
36 const label nSkip,
37 IStringStream& is,
38 Type& value
39) const
40{
41 skip(nSkip, is);
42
43 is >> value;
44}
45
46
47template<class Type>
49(
50 const label nSkip,
51 const string& buffer,
52 Type& value
53) const
54{
55 IStringStream is(buffer);
56
57 readFromLine(nSkip, is, value);
58}
59
60
61template<class Type>
63(
64 const label timeIndex,
65 const label fieldIndex
66) const
67{
69
70 const word& fieldName(fieldNames_[fieldIndex]);
71 const label fileIndex = timeStartIndex_ + timeIndex*timeIncrement_;
72
73 fileName fieldFileName(replaceMask(fieldFileNames_[fieldIndex], fileIndex));
74 ensightReadFile is(baseDir_/fieldFileName, streamFormat_);
75
76 if (!is.good())
77 {
79 << "Cannot read file " << is.name()
80 << " for field " << fieldName
81 << exit(FatalError);
82 }
83
84 // Check that data type is as expected
85 string primitiveType;
86 is.read(primitiveType);
87
88
89 DebugInfo << "primitiveType: " << primitiveType << endl;
90
91 if (primitiveType != pTraits<Type>::typeName)
92 {
94 << "Expected '" << pTraits<Type>::typeName
95 << "' values but found type " << primitiveType << nl
96 << " This may be okay, but could also indicate an error"
97 << nl << nl;
98 }
99
100 scalar value;
101 string strValue;
102 label iValue;
103
104 // Read header info: part index, e.g. part 1
105 is.read(strValue);
106 is.read(iValue);
107
108 // Allocate storage for data as a list per component
110 label n = surfPtr_->size();
111 forAll(values, cmptI)
112 {
113 values[cmptI].setCapacity(n);
114 }
115
116 // Read data file using schema generated while reading the surface
117 forAll(schema_, i)
118 {
120 << "Reading face type "
121 << schema_[i].first() << " data" << endl;
122
123 const label nFace = schema_[i].second();
124
125 if (nFace != 0)
126 {
127 is.read(strValue);
128
129 for
130 (
131 direction cmptI=0;
132 cmptI < pTraits<Type>::nComponents;
133 ++cmptI
134 )
135 {
136 for (label faceI = 0; faceI < nFace; ++faceI)
137 {
138 is.read(value);
139 values[cmptI].append(value);
140 }
141 }
142 }
143 }
144
145 auto tfield = tmp<Field<Type>>::New(n, Zero);
146 auto& field = tfield.ref();
147
148 for (direction cmpti=0; cmpti < pTraits<Type>::nComponents; ++cmpti)
149 {
150 field.replace(cmpti, values[cmpti]);
151 values[cmpti].clear();
152 }
153
154 return tfield;
155}
156
157
158// ************************************************************************* //
label n
virtual const fileName & name() const
Read/write access to the name of the stream.
Definition: ISstream.H:113
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:112
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
Ensight output with specialized read() for strings, integers and floats. Correctly handles binary rea...
virtual Istream & read(char *buf, std::streamsize count)
Binary read.
void skip(const label n, Istream &is) const
Helper function to skip forward n steps in stream.
void readFromLine(const label nSkip, IStringStream &is, Type &value) const
Helper function to return Type after skipping n tokens.
tmp< Field< Type > > readField(const label timeIndex, const label fieldIndex) const
Helper function to return a field.
A class for handling file names.
Definition: fileName.H:76
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define DebugInfo
Report an information message using Foam::Info.
#define IOWarningInFunction(ios)
Report an IO warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
uint8_t direction
Definition: direction.H:56
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
error FatalError
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
label timeIndex
Definition: getTimeIndex.H:30
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333