FEDEM Solver  R8.0
Source code of the dynamics solver
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
FFrResultContainer Class Reference

Class holding the data of a Fedem results file. More...

#include <FFrResultContainer.H>

Collaboration diagram for FFrResultContainer:
Collaboration graph
[legend]

Public Types

enum  Status {
  FFR_CONTAINER_INVALID = 1 , FFR_NO_FILE_FOUND , FFR_TEXT_FILE , FFR_TEXT_PRESENT ,
  FFR_NEW_TEXT , FFR_HEADER_INCOMPLETE , FFR_HEADER_COMPLETE , FFR_DATA_CLOSED ,
  FFR_DATA_PRESENT , FFR_NEW_DATA
}
 Enums defining the various container statuses that may occur. More...
 
enum  PositionStatus { FFR_NOT_SET , FFR_BEFORE_START , FFR_INSIDE , FFR_AFTER_END }
 Enums defining the file position statuses that may occur. More...
 

Public Member Functions

 FFrResultContainer (FFrExtractor *extractor, const std::string &fileName)
 The constructor initializes the data members. More...
 
 ~FFrResultContainer ()
 The destructor closes the file and releases heap-allocated data. More...
 
 FFrResultContainer (const FFrResultContainer &)=delete
 Disable default copy constructor. More...
 
FFrResultContaineroperator= (const FFrResultContainer &)=delete
 Disable default assignment operator. More...
 
Status close ()
 Closes the results file of this container, if still open. More...
 
Status updateContainerStatus ()
 Updates the container to a new status (used from the system ticks). More...
 
Status getContainerStatus () const
 Returns the current status of this results container. More...
 
bool isHeaderComplete () const
 Returns true, if the file header has been successfully parsed. More...
 
const std::string & getFileName () const
 Returns the file name of this results container. More...
 
unsigned int getDate () const
 Returns the time stamp of this results container. More...
 
int getStepsInFile () const
 Returns the number of time steps in this results container. More...
 
int getStepSize () const
 Returns the size (in bytes) of the results data of each time step. More...
 
FT_int getHeaderSize () const
 Returns the size (in bytes) of the results file header. More...
 
void printInfo () const
 Prints out some size parameters for this results container. More...
 
const FFrEntrySettopLevel () const
 Returns a const reference to the top-level entries container. More...
 
const FFrTimeMapgetPhysicalTime () const
 Returns a const reference to the time step mapping. More...
 
int positionAtKey (double key, bool getNextHigher=false)
 Positions the file to the specified key (physical time). More...
 
bool isPositioned () const
 Returns whether the file has been positioned. More...
 
void resetPositioning ()
 Resets the file position. More...
 
int readPositionedTimestepData (const double *values, int nvals, int bitPos, int cellBits, int repeats)
 Reads a double variable from the specified position. More...
 
int readPositionedTimestepData (const float *values, int nvals, int bitPos, int cellBits, int repeats)
 Reads a float variable from the specified position. More...
 
int readPositionedTimestepData (const int *values, int nvals, int bitPos, int cellBits, int repeats)
 Reads an integer variable from the specified position. More...
 
PositionStatus getPositioningStatus () const
 Returns current file position status flag. More...
 
double getCurrentKey () const
 Returns current physical time of this container. More...
 
double getFirstKey () const
 Returns first physical time of this container. More...
 
double getLastKey () const
 Returns last physical time of this container. More...
 
double getDistanceFromPosKey (bool usePositionedKey=false) const
 Returns the difference between current position and the wanted key. More...
 
bool getDistanceToNextKey (double &dist)
 Calculates the distance to the next key for this results container. More...
 
void collectGarbage (FFrEntryBase *entry)
 Collects temporary entries to be deleted when parsing finished. More...
 
void enablePreRead (bool f)
 Enables time step pre-read cache. More...
 
bool isPreReadEnabled () const
 Checks if the time step cache is enabled. More...
 
void clearPreRead ()
 Clears the time step cache. More...
 

Protected Member Functions

void printSizeParameters (FT_int fileSize) const
 Prints out sime size parameters for the results file. More...
 
bool readFileHeader ()
 Reads the header of the file. More...
 
FFrStatus readVariables (FILE *fp, FFrCreatorData &cd, bool dataBlocks=false)
 Reads variable definitions and references. More...
 
bool buildAndResolveHierarchy ()
 Builds and resolves the results hierarchy of the file. More...
 
bool readTimeStepInformation ()
 Reads time step information from the file. More...
 
bool readText ()
 Reads the file squentially from current file position. More...
 
bool reopenForDataAccess ()
 Reopens the results file for direct access of binary data. More...
 
void fillPreRead ()
 Reads all data associated with current time step into a cache. More...
 
double getKey (int flag) const
 Returns current, first or last physical time of this container. More...
 
int actualRead (void *var, int nvals, int bitPos, int cellBits, int repeats)
 Reads a certain number of bytes from the binary results file. More...
 

Private Attributes

FFrVariableReferencemyPhysTimeRef
 Pointer to physical time variable. More...
 
bool swapBytes
 Endian mismatch? More...
 
int timeStepSize
 Time step size in bytes (max 2GB) More...
 
FT_int myHeaderSize
 Binary start position in bytes. More...
 
FILE * myFile
 File descriptor used in header parsing. More...
 
FT_FILE myDataFile
 File handle used for data access. More...
 
Status myStatus
 Current status of the file reading. More...
 
std::string myFileName
 File name associated with this result container. More...
 
std::string myModule
 Program module that wrote the results file. More...
 
unsigned int myDate
 Time stamp of the results file. More...
 
FFrExtractormyExtractor
 Result extractor that own this container. More...
 
FFrEntrySet myTopLevelEntries
 List of all top-level entries. More...
 
FFrEntrySet myGarbage
 Garbage collection container. More...
 
int myPositionedTimeStep
 Current file position. More...
 
int myLastReadEndPos
 Position after the last data read. More...
 
FFrTimeMap myPhysicalTimeMap
 Physical time to results mapping. More...
 
FFrTimeMap::iterator myCurrentIndexIt
 Pointer to what we should read. More...
 
double myWantedKey
 The physical time to read results for. More...
 
PositionStatus myWantedKeyStatus
 Is the key inside, exact, front or rear. More...
 
bool iAmLazyPositioned
 Only move file pointer first time reading data. More...
 
bool iAmPreReading
 Read all results for current time step into core. More...
 
char * myPreRead
 Pre-read cache. More...
 
int myPreReadTimeStep
 Current time step in pre-read cache. More...
 

Detailed Description

Class holding the data of a Fedem results file.

Instances of this class represents one results file each of a Fedem model. The class also contains methods for parsing the file header and populating the datastructure for traversing the results hierarchy, as well as methods for reading the results themselves (binary data).

Member Enumeration Documentation

◆ PositionStatus

Enums defining the file position statuses that may occur.

Enumerator
FFR_NOT_SET 
FFR_BEFORE_START 
FFR_INSIDE 
FFR_AFTER_END 

◆ Status

Enums defining the various container statuses that may occur.

Enumerator
FFR_CONTAINER_INVALID 
FFR_NO_FILE_FOUND 
FFR_TEXT_FILE 
FFR_TEXT_PRESENT 
FFR_NEW_TEXT 
FFR_HEADER_INCOMPLETE 
FFR_HEADER_COMPLETE 
FFR_DATA_CLOSED 
FFR_DATA_PRESENT 
FFR_NEW_DATA 

Constructor & Destructor Documentation

◆ FFrResultContainer() [1/2]

FFrResultContainer::FFrResultContainer ( FFrExtractor extractor,
const std::string &  fileName 
)

The constructor initializes the data members.

◆ ~FFrResultContainer()

FFrResultContainer::~FFrResultContainer ( )

The destructor closes the file and releases heap-allocated data.

◆ FFrResultContainer() [2/2]

FFrResultContainer::FFrResultContainer ( const FFrResultContainer )
delete

Disable default copy constructor.

Member Function Documentation

◆ actualRead()

int FFrResultContainer::actualRead ( void *  var,
int  nvals,
int  bitPos,
int  cellBits,
int  repeats 
)
protected

Reads a certain number of bytes from the binary results file.

Parameters
[out]varThe memory segment to read into
[in]nvalsNumber of values (cell) that we want to read
[in]bitPosFile position to start reading from
[in]cellBitsNumber of bits in each cell
[in]repeatsNumber of values present on file for the variable to read

The data values associated with a variable is read from the physical file. Note: nvals < repeats is not an error condition (it used to be earlier). It should be allowed to read only a part of a variable, if the user wants to.

◆ buildAndResolveHierarchy()

bool FFrResultContainer::buildAndResolveHierarchy ( )
protected

Builds and resolves the results hierarchy of the file.

Recursively builds and resolves the file's hierarchy. The return value is the length of one binary line (e.g., one time step) in the file.

Resolving:

  • For FFrFieldEntryBase objects (OG or IG on first level) traverse depth-first on all data fields.
  • For IGs, copy the IG information (title) and VRs for that IG to a new IG.
  • For VRs create a new FFrVariableReference as a copy of the original and insert it into the dataField, adding file info and position.

◆ clearPreRead()

void FFrResultContainer::clearPreRead ( )

Clears the time step cache.

◆ close()

FFrResultContainer::Status FFrResultContainer::close ( )

Closes the results file of this container, if still open.

◆ collectGarbage()

void FFrResultContainer::collectGarbage ( FFrEntryBase entry)

Collects temporary entries to be deleted when parsing finished.

◆ enablePreRead()

void FFrResultContainer::enablePreRead ( bool  f)
inline

Enables time step pre-read cache.

◆ fillPreRead()

void FFrResultContainer::fillPreRead ( )
protected

Reads all data associated with current time step into a cache.

◆ getContainerStatus()

Status FFrResultContainer::getContainerStatus ( ) const
inline

Returns the current status of this results container.

◆ getCurrentKey()

double FFrResultContainer::getCurrentKey ( ) const
inline

Returns current physical time of this container.

◆ getDate()

unsigned int FFrResultContainer::getDate ( ) const
inline

Returns the time stamp of this results container.

◆ getDistanceFromPosKey()

double FFrResultContainer::getDistanceFromPosKey ( bool  usePositionedKey = false) const

Returns the difference between current position and the wanted key.

◆ getDistanceToNextKey()

bool FFrResultContainer::getDistanceToNextKey ( double &  dist)

Calculates the distance to the next key for this results container.

Calculates the distance to the next key for this container. Returns true if the wanted key (as set with positionAtKey()) is either within or in front of the container values.

Returns false if the wanted key is after the values in the container or if the container is empty.

◆ getFileName()

const std::string& FFrResultContainer::getFileName ( ) const
inline

Returns the file name of this results container.

◆ getFirstKey()

double FFrResultContainer::getFirstKey ( ) const
inline

Returns first physical time of this container.

◆ getHeaderSize()

FT_int FFrResultContainer::getHeaderSize ( ) const
inline

Returns the size (in bytes) of the results file header.

◆ getKey()

double FFrResultContainer::getKey ( int  flag) const
protected

Returns current, first or last physical time of this container.

◆ getLastKey()

double FFrResultContainer::getLastKey ( ) const
inline

Returns last physical time of this container.

◆ getPhysicalTime()

const FFrTimeMap& FFrResultContainer::getPhysicalTime ( ) const
inline

Returns a const reference to the time step mapping.

◆ getPositioningStatus()

PositionStatus FFrResultContainer::getPositioningStatus ( ) const
inline

Returns current file position status flag.

◆ getStepsInFile()

int FFrResultContainer::getStepsInFile ( ) const
inline

Returns the number of time steps in this results container.

◆ getStepSize()

int FFrResultContainer::getStepSize ( ) const
inline

Returns the size (in bytes) of the results data of each time step.

◆ isHeaderComplete()

bool FFrResultContainer::isHeaderComplete ( ) const
inline

Returns true, if the file header has been successfully parsed.

◆ isPositioned()

bool FFrResultContainer::isPositioned ( ) const
inline

Returns whether the file has been positioned.

◆ isPreReadEnabled()

bool FFrResultContainer::isPreReadEnabled ( ) const
inline

Checks if the time step cache is enabled.

◆ operator=()

FFrResultContainer& FFrResultContainer::operator= ( const FFrResultContainer )
delete

Disable default assignment operator.

◆ positionAtKey()

int FFrResultContainer::positionAtKey ( double  key,
bool  getNextHigher = false 
)

Positions the file to the specified key (physical time).

◆ printInfo()

void FFrResultContainer::printInfo ( ) const

Prints out some size parameters for this results container.

◆ printSizeParameters()

void FFrResultContainer::printSizeParameters ( FT_int  fileSize) const
protected

Prints out sime size parameters for the results file.

◆ readFileHeader()

bool FFrResultContainer::readFileHeader ( )
protected

Reads the header of the file.

Reads the file header and stores the obtained binary position in the object.

◆ readPositionedTimestepData() [1/3]

int FFrResultContainer::readPositionedTimestepData ( const double *  values,
int  nvals,
int  bitPos,
int  cellBits,
int  repeats 
)
inline

Reads a double variable from the specified position.

◆ readPositionedTimestepData() [2/3]

int FFrResultContainer::readPositionedTimestepData ( const float *  values,
int  nvals,
int  bitPos,
int  cellBits,
int  repeats 
)
inline

Reads a float variable from the specified position.

◆ readPositionedTimestepData() [3/3]

int FFrResultContainer::readPositionedTimestepData ( const int *  values,
int  nvals,
int  bitPos,
int  cellBits,
int  repeats 
)
inline

Reads an integer variable from the specified position.

◆ readText()

bool FFrResultContainer::readText ( )
protected

Reads the file squentially from current file position.

Reads the file from current file position to check if the size has increased. Should be called on initial read and for each new "beep" from other processes.

◆ readTimeStepInformation()

bool FFrResultContainer::readTimeStepInformation ( )
protected

Reads time step information from the file.

Should be called on initial read and for each new "beep" from other processes.

◆ readVariables()

FFrStatus FFrResultContainer::readVariables ( FILE *  fp,
FFrCreatorData cd,
bool  dataBlocks = false 
)
protected

Reads variable definitions and references.

◆ reopenForDataAccess()

bool FFrResultContainer::reopenForDataAccess ( )
protected

Reopens the results file for direct access of binary data.

Reopens the results file using low-lewel IO-routines. To handle data files larger than 2GB on Windows.

◆ resetPositioning()

void FFrResultContainer::resetPositioning ( )

Resets the file position.

◆ topLevel()

const FFrEntrySet& FFrResultContainer::topLevel ( ) const
inline

Returns a const reference to the top-level entries container.

◆ updateContainerStatus()

FFrResultContainer::Status FFrResultContainer::updateContainerStatus ( )

Updates the container to a new status (used from the system ticks).

Tries to open the results file, read the header and the time step information in the file. Returns an enum telling the new status of the container.

Member Data Documentation

◆ iAmLazyPositioned

bool FFrResultContainer::iAmLazyPositioned
private

Only move file pointer first time reading data.

◆ iAmPreReading

bool FFrResultContainer::iAmPreReading
private

Read all results for current time step into core.

◆ myCurrentIndexIt

FFrTimeMap::iterator FFrResultContainer::myCurrentIndexIt
private

Pointer to what we should read.

◆ myDataFile

FT_FILE FFrResultContainer::myDataFile
private

File handle used for data access.

◆ myDate

unsigned int FFrResultContainer::myDate
private

Time stamp of the results file.

◆ myExtractor

FFrExtractor* FFrResultContainer::myExtractor
private

Result extractor that own this container.

◆ myFile

FILE* FFrResultContainer::myFile
private

File descriptor used in header parsing.

◆ myFileName

std::string FFrResultContainer::myFileName
private

File name associated with this result container.

◆ myGarbage

FFrEntrySet FFrResultContainer::myGarbage
private

Garbage collection container.

◆ myHeaderSize

FT_int FFrResultContainer::myHeaderSize
private

Binary start position in bytes.

◆ myLastReadEndPos

int FFrResultContainer::myLastReadEndPos
private

Position after the last data read.

◆ myModule

std::string FFrResultContainer::myModule
private

Program module that wrote the results file.

◆ myPhysicalTimeMap

FFrTimeMap FFrResultContainer::myPhysicalTimeMap
private

Physical time to results mapping.

◆ myPhysTimeRef

FFrVariableReference* FFrResultContainer::myPhysTimeRef
private

Pointer to physical time variable.

◆ myPositionedTimeStep

int FFrResultContainer::myPositionedTimeStep
private

Current file position.

◆ myPreRead

char* FFrResultContainer::myPreRead
private

Pre-read cache.

◆ myPreReadTimeStep

int FFrResultContainer::myPreReadTimeStep
private

Current time step in pre-read cache.

◆ myStatus

Status FFrResultContainer::myStatus
private

Current status of the file reading.

◆ myTopLevelEntries

FFrEntrySet FFrResultContainer::myTopLevelEntries
private

List of all top-level entries.

◆ myWantedKey

double FFrResultContainer::myWantedKey
private

The physical time to read results for.

◆ myWantedKeyStatus

PositionStatus FFrResultContainer::myWantedKeyStatus
private

Is the key inside, exact, front or rear.

◆ swapBytes

bool FFrResultContainer::swapBytes
private

Endian mismatch?

◆ timeStepSize

int FFrResultContainer::timeStepSize
private

Time step size in bytes (max 2GB)


The documentation for this class was generated from the following files: