64 const std::size_t minElements
70 if (
split.size() >= minElements)
75 if (
split.size() > minElements)
97 const auto pos = line.find(
'#');
98 if (
pos != std::string::npos)
104 while (
line.empty() && is.good());
106 return !
line.empty();
112 const word& expected,
113 const string& buffer,
121 if (!expected.empty() && !buffer.starts_with(expected))
124 <<
"Expected section header '" << expected
125 <<
"' but read " << buffer <<
nl
130 <<
"Read section header: " << buffer.c_str() <<
nl;
136 const word& expected,
141 readLine(is, buffer);
173 idHandling.first() = idTypes::IGNORE;
177 idHandling.first() = idTypes::GIVEN;
186 idHandling.second() = idTypes::IGNORE;
190 idHandling.second() = idTypes::GIVEN;
231 enum ParseSection { UNKNOWN, FORMAT, GEOMETRY, VARIABLE, TIME, FILE };
236 <<
"Cannot read file " << is.
name()
243 ParseSection parseState = ParseSection::UNKNOWN;
248 debugSection(
"FORMAT", is);
249 readLine(is, buffer);
250 parseState = ParseSection::FORMAT;
254 debugSection(
"GEOMETRY", is);
255 parseState = ParseSection::GEOMETRY;
259 readLine(is, buffer);
261 if (buffer.starts_with(
"VARIABLE"))
263 parseState = ParseSection::VARIABLE;
267 if (buffer.contains(
"change_coords_only"))
270 <<
"No support for moving points, only topology change" <<
nl
283 const auto pos_colon = buffer.find(
':');
287 (pos_colon == std::string::npos)
291 <<
"Error reading geometry 'model:'" <<
nl
300 <<
"Error reading geometry 'model:'" <<
nl
313 if (parseState != ParseSection::VARIABLE)
315 debugSection(
"VARIABLE", is);
316 parseState = ParseSection::VARIABLE;
329 readLine(is, buffer);
331 if (buffer.starts_with(
"TIME"))
333 parseState = ParseSection::TIME;
343 const auto pos_colon = buffer.find(
':');
345 if (pos_colon == std::string::npos)
347 DebugInfo<<
"ignore variable line: " << buffer <<
nl;
355 if (
split.size() < 2)
358 <<
"Error reading field file name, variable line: "
363 auto pos_key = buffer.find(
"element");
364 if ((pos_key == std::string::npos) || (pos_colon < pos_key))
366 DebugInfo<<
"ignore variable line: " << buffer <<
nl;
375 dynFieldNames.push_back(
split[
split.size()-2].str());
376 dynFieldFileNames.push_back(
split[
split.size()-1].str());
378 fieldTimesets_.transfer(dynFieldTimesets);
379 fieldNames_.transfer(dynFieldNames);
380 fieldFileNames_.transfer(dynFieldFileNames);
383 <<
"fieldNames: " << fieldNames_ <<
nl
384 <<
"fieldFileNames: " << fieldFileNames_ <<
nl;
387 if (parseState != ParseSection::TIME)
390 <<
"Did not find section header 'TIME'" <<
nl
400 expectTimeset.insert(meshTimeset_.first());
401 expectFileset.insert(meshTimeset_.second());
403 for (
const auto& tup : fieldTimesets_)
405 expectTimeset.insert(tup.first());
406 expectFileset.insert(tup.second());
410 expectTimeset.erase(-1);
411 expectFileset.erase(-1);
415 <<
"expect timesets: " <<
flatOutput(expectTimeset) <<
nl
416 <<
"expect filesets: " <<
flatOutput(expectFileset) <<
nl;
454 readLine(is, buffer);
460 readLine(is, buffer);
462 readFrom(
split.back(), nTimes);
471 readLine(is, buffer);
472 auto pos_colon = buffer.find(
':');
474 if (buffer.contains(
"numbers:"))
479 fileNumbers_.resize_nocopy(nTimes);
482 while (numRead < nTimes)
484 for (
const auto& chunk :
split)
486 std::string str(chunk.str());
491 <<
"Could not parse label: " << str <<
nl
496 if (numRead == nTimes)
503 if (numRead < nTimes)
505 readLine(is, buffer);
512 fileNumbers_.resize(numRead);
518 readFrom(
split.back(), timeStartIndex_);
521 readLine(is, buffer);
523 readFrom(
split.back(), timeIncrement_);
525 fileNumbers_.clear();
529 <<
"nTimes: " << nTimes
530 <<
" start-index: " << timeStartIndex_
531 <<
" increment: " << timeIncrement_
536 readLine(is, buffer);
540 const auto pos_colon = buffer.find(
':');
541 const auto pos_key = buffer.find(
"values");
545 (pos_colon == std::string::npos)
546 || (pos_key == std::string::npos) || (pos_colon < pos_key)
557 timeValues_.resize_nocopy(nTimes);
560 while (numRead < nTimes)
562 for (
const auto& chunk :
split)
564 auto& inst = timeValues_[numRead];
567 inst.name() =
word(chunk.str());
569 if (!Foam::readScalar(inst.name(), inst.value()))
572 <<
"Could not parse scalar: " << inst.name() <<
nl
577 if (numRead == nTimes)
584 if (numRead < nTimes)
586 readLine(is, buffer);
591 timeValues_.resize(numRead);
616 && options.getOrDefault(
"masterOnly", false)
619 baseDir_(fName.
path()),
658 const fileName& geometryFile,
666 ensightReadFile is(geometryFile);
669 readFormat_ = is.
format();
675 <<
"File: " << is.
name()
679 Pair<idTypes> idHandling = readGeometryHeader(is);
687 if (idHandling.first() == idTypes::GIVEN)
690 <<
"Treating node id 'given' as being 'ignore'" <<
nl
691 <<
"If something fails, this could be the reason" <<
nl
694 idHandling.first() = idTypes::IGNORE;
697 if (idHandling.first() == idTypes::IGNORE)
700 <<
"Ignore " <<
nPoints <<
" node ids" <<
nl;
725 else if (buffer.contains(
"BEGIN TIME STEP"))
730 else if (buffer.contains(
"END TIME STEP"))
745 faceTypeInfo.emplace_back
759 idHandling.second() == idTypes::IGNORE
760 || idHandling.second() == idTypes::GIVEN
764 <<
"Ignore " << elemCount <<
" element ids" <<
nl;
767 is.skip<label>(elemCount);
771 const label startElemi = dynFaces.size();
772 dynFaces.resize(startElemi+elemCount,
face(3));
775 for (
auto&
f : myElements)
792 faceTypeInfo.emplace_back
806 idHandling.second() == idTypes::IGNORE
807 || idHandling.second() == idTypes::GIVEN
811 <<
"Ignore " << elemCount <<
" element ids" <<
nl;
814 is.skip<label>(elemCount);
818 const label startElemi = dynFaces.size();
819 dynFaces.resize(startElemi + elemCount,
face(4));
822 for (
auto&
f : myElements)
839 faceTypeInfo.emplace_back
848 <<
"> count: " << elemCount <<
nl;
852 idHandling.second() == idTypes::IGNORE
853 || idHandling.second() == idTypes::GIVEN
857 <<
"Ignore " << elemCount <<
" element ids" <<
nl;
860 is.skip<label>(elemCount);
864 const label startElemi = dynFaces.size();
865 dynFaces.resize(startElemi + elemCount);
868 for (
auto&
f : myElements)
876 for (
auto&
f : myElements)
889 <<
"Unknown face type: <" << buffer.c_str()
890 <<
">. Stopping read and continuing with current "
891 <<
"elements only" <<
endl;
898 for (
auto&
f : dynFaces)
906 faceTypeInfo_.transfer(faceTypeInfo);
907 faceList faces(std::move(dynFaces));
910 <<
"read nFaces: " << faces.size() <<
nl
928 auto& surf = *surfPtr_;
938 surf = readGeometry(geomFile,
timeIndex);
970 const label fieldIndex,
971 const scalar& refValue
981 const label fieldIndex,
993 const label fieldIndex,
1004 const label fieldIndex,
1015 const label fieldIndex,
1019 return readField<tensor>(
timeIndex, fieldIndex);
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
T & emplace_back(Args &&... args)
Construct an element at the end of the list, return reference to the new list element.
void push_back(const T &val)
Copy append an element to the end of this list.
void resize(const label len)
Alter addressable list size, allocating new space if required while recovering old content.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
virtual const fileName & name() const override
Read/write access to the name of the stream.
A simple container for options an IOstream can normally have.
streamFormat format() const noexcept
Get the current stream format.
static const Enum< streamFormat > formatNames
Stream format names (ascii, binary).
bool good() const noexcept
True if next operation might succeed.
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
void reset(const char *buffer, size_t nbytes)
Reset input area, position to buffer start and clear errors.
Generic input stream using a standard (STL) stream.
virtual const fileName & name() const override
The name of the input serial stream. (eg, the name of the Fstream file name).
ISstream & getLine(std::string &str, char delim='\n')
Raw, low-level getline (until delimiter) into a string.
virtual Istream & read(token &t) override
Return next token from stream.
void resize(const label len)
Adjust allocated size of list.
An ordered pair of two objects of type <T> with first() and second() elements.
const T & first() const noexcept
Access the first element.
const T & second() const noexcept
Access the second element.
static void broadcasts(const int communicator, Type &value, Args &&... values)
Broadcast multiple items to all communicator ranks. Does nothing in non-parallel.
Sub-ranges of a string with a structure similar to std::match_results, but without the underlying reg...
SubList< T > slice(const label pos, label len=-1)
Return SubList slice (non-const access) - no range checking.
void size(const label n)
Older name for setAddressableSize.
Inter-processor communications stream.
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
@ broadcast
broadcast [MPI]
static bool & parRun() noexcept
Test if this a parallel run.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
static StringType expand_mask(const StringType &input, const label index)
Replace the '*' mask chars with zero-padded integer value.
static const char * elemNames[nTypes]
The ensight 'Face' element type names.
A variant of IFstream with specialised handling for Ensight reading of strings, integers and floats (...
bool seekTime(const label timeIndex)
Transient single-file: seek to the file position corresponding to the given time index.
void skip(label n=1)
Read and discard specified number of elements.
void readPoints(const label nPoints, List< floatVector > &points)
Component-wise reading of points/coordinates. Read all x components, y components and z components.
virtual Istream & read(char *buf, std::streamsize count) override
Binary read.
Ensight format surface reader.
static bool readLine(ISstream &is, std::string &line)
Helper function to read an ascii line from file, skipping blank lines and comments.
virtual instantList times() const
Return a list of the available times.
static void checkSection(const word &expected, const string &buffer, const ISstream &is)
Check a section header.
Pair< idTypes > readGeometryHeader(ensightReadFile &is) const
Read (and discard) geometry file header.
label timeIncrement_
Time increment.
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.
instantList timeValues_
Times.
labelList fileNumbers_
Numbers for files.
bool masterOnly_
Read on master and broadcast (in parallel).
labelPair meshTimeset_
The timeset/fileset (if any) associated with the mesh.
@ GIVEN
Use "given" values (not supported).
@ IGNORE
Read but "ignore".
void readCase(ISstream &is)
Read the case file.
static void debugSection(const word &expected, ISstream &is)
Read and check a section header.
fileName baseDir_
Base directory.
List< word > fieldNames_
Field names.
autoPtr< meshedSurface > surfPtr_
Pointer to the surface.
List< labelPair > fieldTimesets_
The timeset/fileset (if any) associated with fields.
meshedSurface readGeometry(const fileName &geometryFile, const label timeIndex=0)
Read and return surface geometry. Updates faceTypeInfo_.
virtual const meshedSurface & geometry(const label timeIndex)
Return a reference to the surface geometry.
label timeStartIndex_
Start time index.
IOstreamOption::streamFormat readFormat_
Format flag.
List< faceInfoTuple > faceTypeInfo_
List of face-type/count tuples.
List< string > fieldFileNames_
Field file names.
ensightSurfaceReader(const ensightSurfaceReader &)=delete
No copy construct.
fileName meshFileName_
Name of mesh file, including any subdirectory.
virtual wordList fieldNames(const label timeIndex) const
Return a list of the available fields at a given time.
static void readFrom(const std::string &buffer, Type &value)
Helper function to return Type from string.
tmp< Field< Type > > readField(const fileName &dataFile, const word &fieldName, const label timeIndex=0) const
Helper function to return a field.
A face is a list of labels corresponding to mesh vertices.
A class for handling file names.
static std::string::size_type length(const char *s)
Length of the character sequence (with nullptr protection).
bool contains(char c) const noexcept
True if string contains given character (cf. C++23).
bool starts_with(char c) const
True if string starts with given character (cf. C++20).
Abstract base class for surface readers with fields.
surfaceReader(const fileName &fName)
Construct from fileName.
A class for managing temporary objects.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static bool split(const std::string &line, std::string &key, std::string &val)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
#define DebugInFunction
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Foam::SubStrings splitSpace(const std::string &str, std::string::size_type pos=0)
Split string into sub-strings at whitespace (TAB, NL, VT, FF, CR, SPC).
void inplaceTrimRight(std::string &s)
Trim trailing whitespace inplace.
dimensionedScalar pos(const dimensionedScalar &ds)
Pair< label > labelPair
A pair of labels.
List< word > wordList
List of word.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
static labelPair extractTimeset(const SubStrings &split, const std::size_t minElements)
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
List< face > faceList
List of faces.
List< instant > instantList
List of instants.
Ostream & endl(Ostream &os)
Add newline and flush stream.
MeshedSurface< face > meshedSurface
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
SphericalTensor< scalar > sphericalTensor
SphericalTensor of scalars, i.e. SphericalTensor<scalar>.
SymmTensor< scalar > symmTensor
SymmTensor of scalars, i.e. SymmTensor<scalar>.
constexpr char nl
The newline '\n' character (0x0a).