walberla::geometry::BasicVoxelFileReader< T > Class Template Reference

Detailed Description

template<typename T>
class walberla::geometry::BasicVoxelFileReader< T >

Provides a low level reader for waLBerla geometry files.

Template Parameters
TThe underlying datatype that is stored in binary form in the geometry file

#include <BasicVoxelFileReader.h>

Public Member Functions

 BasicVoxelFileReader ()
 Constructs on empty geometry file. More...
 
 BasicVoxelFileReader (const std::string &_filename)
 Opens an existing geometry file. More...
 
 BasicVoxelFileReader (const std::string &_filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, T value=T())
 Creates a new geometry file with extends xSize x ySize x zSize. More...
 
 BasicVoxelFileReader (const std::string &_filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, const T *values)
 Creates a new geometry file with extends xSize x ySize x zSize. More...
 
 ~BasicVoxelFileReader ()
 Destructor that closes the file if necessary. More...
 
void open (const std::string &_filename)
 Opens an existing geometry file. More...
 
void create (const std::string &_filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, T value=T())
 Creates a new geometry file with extends xSize x ySize x zSize. More...
 
void create (const std::string &_filename, std::size_t _xSize, std::size_t _ySize, std::size_t _zSize, const T *values)
 Creates a new geometry file with extends xSize x ySize x zSize. More...
 
void close ()
 Closes an opened geometry file. More...
 
bool isOpen () const
 Query if a geometry file is open. More...
 
const std::string & filename () const
 Gets the filename of the opened geometry file. More...
 
std::size_t numCells () const
 Gets the number of cells of the currently loaded geometry file. More...
 
std::size_t xSize () const
 Gets the extend of the geometry file in x direction. More...
 
std::size_t ySize () const
 Gets the extend of the geometry file in y direction. More...
 
std::size_t zSize () const
 Gets the extend of the geometry file in z direction. More...
 
void read (const CellAABB &cellAABB, std::vector< T > &data) const
 Reads a block of data from the opened geometry file. More...
 
void write (const CellAABB &cellAABB, const std::vector< T > &data)
 Writes a block of data to the geometry file. More...
 

Private Attributes

std::fstream filestream_
 fstream object managing the opened file More...
 
std::string filename_
 Filename of the geometry file currently opened. More...
 
std::streampos dataBegin_
 Position in the stream where to raw data starts. More...
 
std::size_t xSize_
 Extend of the currently open geometry file in x direction. More...
 
std::size_t ySize_
 Extend of the currently open geometry file in y direction. More...
 
std::size_t zSize_
 Extend of the currently open geometry file in z direction. More...
 

Constructor & Destructor Documentation

◆ BasicVoxelFileReader() [1/4]

Constructs on empty geometry file.

Postcondition
isOpen() == false

◆ BasicVoxelFileReader() [2/4]

template<typename T >
walberla::geometry::BasicVoxelFileReader< T >::BasicVoxelFileReader ( const std::string &  _filename)

Opens an existing geometry file.

Parameters
_filenameName (path) of the file.
Exceptions
std::runtime_erroron I/O errors.
Postcondition
isOpen() == true

◆ BasicVoxelFileReader() [3/4]

template<typename T >
walberla::geometry::BasicVoxelFileReader< T >::BasicVoxelFileReader ( const std::string &  _filename,
std::size_t  _xSize,
std::size_t  _ySize,
std::size_t  _zSize,
value = T() 
)

Creates a new geometry file with extends xSize x ySize x zSize.

Parameters
_filenameName (path) of the file.
_xSizeExtend of the geometry file in x direction.
_ySizeExtend of the geometry file in y direction.
_zSizeExtend of the geometry file in z direction.
valueThe value the cells are initialized with. Defaults to T().
Exceptions
std::runtime_erroron I/O errors.
Postcondition
isOpen() == true

◆ BasicVoxelFileReader() [4/4]

template<typename T >
walberla::geometry::BasicVoxelFileReader< T >::BasicVoxelFileReader ( const std::string &  _filename,
std::size_t  _xSize,
std::size_t  _ySize,
std::size_t  _zSize,
const T *  values 
)

Creates a new geometry file with extends xSize x ySize x zSize.

Parameters
_filenameName (path) of the file.
_xSizeExtend of the geometry file in x direction.
_ySizeExtend of the geometry file in y direction.
_zSizeExtend of the geometry file in z direction.
valuesAn array of size xSize * ySize * zSize with the values to initialize the geometry file with.
Exceptions
std::runtime_erroron I/O errors.
Precondition
values != nullptr
Postcondition
isOpen() == true

◆ ~BasicVoxelFileReader()

Destructor that closes the file if necessary.

Member Function Documentation

◆ close()

template<typename T >
void walberla::geometry::BasicVoxelFileReader< T >::close

Closes an opened geometry file.

If no geometry file is open, this does nothing.

Postcondition
isOpen() == false

◆ create() [1/2]

template<typename T >
void walberla::geometry::BasicVoxelFileReader< T >::create ( const std::string &  _filename,
std::size_t  _xSize,
std::size_t  _ySize,
std::size_t  _zSize,
const T *  values 
)

Creates a new geometry file with extends xSize x ySize x zSize.

An already opened file gets closed beforehand.

Parameters
_filenameName (path) of the file.
_xSizeExtend of the geometry file in x direction.
_ySizeExtend of the geometry file in y direction.
_zSizeExtend of the geometry file in z direction.
valuesAn array of size xSize * ySize * zSize with the values to initialize the geometry file with.
Exceptions
std::runtime_erroron I/O errors.
Precondition
values != nullptr
Postcondition
isOpen() == true

◆ create() [2/2]

template<typename T >
void walberla::geometry::BasicVoxelFileReader< T >::create ( const std::string &  _filename,
std::size_t  _xSize,
std::size_t  _ySize,
std::size_t  _zSize,
value = T() 
)

Creates a new geometry file with extends xSize x ySize x zSize.

An already opened file gets closed beforehand.

Parameters
_filenameName (path) of the file.
_xSizeExtend of the geometry file in x direction.
_ySizeExtend of the geometry file in y direction.
_zSizeExtend of the geometry file in z direction.
valueThe value the cells are initialized with. Defaults to T().
Exceptions
std::runtime_erroron I/O errors.
Postcondition
isOpen() == true

◆ filename()

template<typename T >
const std::string & walberla::geometry::BasicVoxelFileReader< T >::filename

Gets the filename of the opened geometry file.

Precondition
isOpen() == true
Returns
The filename of the opened geometry file.

◆ isOpen()

template<typename T >
bool walberla::geometry::BasicVoxelFileReader< T >::isOpen

Query if a geometry file is open.

Returns
true if a file is opened, false if not.

◆ numCells()

template<typename T >
std::size_t walberla::geometry::BasicVoxelFileReader< T >::numCells

Gets the number of cells of the currently loaded geometry file.

Precondition
isOpen() == true
Returns
xSize() * ySize() * zSize().

◆ open()

template<typename T >
void walberla::geometry::BasicVoxelFileReader< T >::open ( const std::string &  _filename)

Opens an existing geometry file.

An already opened file gets closed beforehand.

Parameters
_filenameName (path) of the file.
Exceptions
std::runtime_erroron I/O errors.
std::runtime_errorif the loaded geometry file's format is corrupt
Postcondition
isOpen() == true

◆ read()

template<typename T >
void walberla::geometry::BasicVoxelFileReader< T >::read ( const CellAABB cellAABB,
std::vector< T > &  data 
) const

Reads a block of data from the opened geometry file.

Parameters
cellAABBThe axis-aligned bounding box of the block of data to be read.
[out]dataThe vector the read data is stored to. The Storage order is zyx. (Meaning your innermost loop should iterate over x)
Exceptions
std::runtime_erroron I/O errors.
Precondition
isOpen() == true
cellAABB.xEnd < xSize()
cellAABB.yEnd < ySize()
cellAABB.zEnd < zSize()
Postcondition
data.size() == cellAABB.numCells()

◆ write()

template<typename T >
void walberla::geometry::BasicVoxelFileReader< T >::write ( const CellAABB cellAABB,
const std::vector< T > &  data 
)

Writes a block of data to the geometry file.

Parameters
cellAABBThe axis-aligned bounding box of the block of data to be written.
dataThe vector holding the data to bw written to the geometry file. The Storage order is zyx. (Meaning your innermost loop should iterate over x)
Exceptions
std::runtime_erroron I/O errors.
Precondition
isOpen() == true
cellAABB.xEnd < xSize()
cellAABB.yEnd < ySize()
cellAABB.zEnd < zSize()
data.size() >= cellAABB.numCells()

◆ xSize()

template<typename T >
std::size_t walberla::geometry::BasicVoxelFileReader< T >::xSize

Gets the extend of the geometry file in x direction.

Precondition
isOpen() == true
Returns
The extend of the geometry file in x direction.

◆ ySize()

template<typename T >
std::size_t walberla::geometry::BasicVoxelFileReader< T >::ySize

Gets the extend of the geometry file in y direction.

Precondition
isOpen() == true
Returns
The extend of the geometry file in y direction.

◆ zSize()

template<typename T >
std::size_t walberla::geometry::BasicVoxelFileReader< T >::zSize

Gets the extend of the geometry file in z direction.

Precondition
isOpen() == true
Returns
The extend of the geometry file in z direction.

Member Data Documentation

◆ dataBegin_

template<typename T >
std::streampos walberla::geometry::BasicVoxelFileReader< T >::dataBegin_
private

Position in the stream where to raw data starts.

◆ filename_

template<typename T >
std::string walberla::geometry::BasicVoxelFileReader< T >::filename_
private

Filename of the geometry file currently opened.

◆ filestream_

template<typename T >
std::fstream walberla::geometry::BasicVoxelFileReader< T >::filestream_
mutableprivate

fstream object managing the opened file

◆ xSize_

template<typename T >
std::size_t walberla::geometry::BasicVoxelFileReader< T >::xSize_
private

Extend of the currently open geometry file in x direction.

◆ ySize_

template<typename T >
std::size_t walberla::geometry::BasicVoxelFileReader< T >::ySize_
private

Extend of the currently open geometry file in y direction.

◆ zSize_

template<typename T >
std::size_t walberla::geometry::BasicVoxelFileReader< T >::zSize_
private

Extend of the currently open geometry file in z direction.


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