UQTk: Uncertainty Quantification Toolkit 3.1.5
Array3D< T > Class Template Reference

Stores data of any type T in a 3D array. More...

#include <Array3D.h>

Public Member Functions

 Array3D ()
 Default constructor, which does not allocate any memory.
 
 Array3D (const size_t &nx, const size_t &ny, const size_t &nz)
 Constructor that allocates the memory.
 
 Array3D (const size_t &nx, const size_t &ny, const size_t &nz, const T &t)
 Constructor that allocates and initializes the data.
 
 ~Array3D ()
 Destructor that frees up the memory.
 
void Clear ()
 Function to clear the memory.
 
size_t XSize () const
 Returns size in the x-direction.
 
size_t YSize () const
 Returns size in the y-direction.
 
size_t ZSize () const
 Returns size in the z-direction.
 
void Resize (const size_t &nx, const size_t &ny, const size_t &nz)
 Resizes the array.
 
void Resize (const size_t &nx, const size_t &ny, const size_t &nz, const T &t)
 Resizes the array and sets ALL entries to the specified value.
 
void SetValue (const T &t)
 Set all values in the array to the given value.
 
T * GetArrayPointer ()
 Return a pointer to the first element of the data in the vector so we can use it access the data in array format (e.g. for passing it to a Fortran program).
 
const T * GetConstArrayPointer () const
 Return a const pointer to the first element of the data in the vector so we can use it access the data in array format (e.g. for passing it to a Fortran program).
 
T & operator() (size_t ix, size_t iy, size_t iz)
 Fortran-like () operator to access values in the 3D data array.
 
const T & operator() (size_t ix, size_t iy, size_t iz) const
 Fortran-like () const operator to access values in the 3D data array.
 
void DumpBinary (FILE *f_out) const
 Dump contents of the array to a file in binary format.
 
void DumpText (std::ofstream &f_out) const
 Dump contents of the array to a file in text format Added by Maher Salloum When post-processing (in matlab for example), one has to transpose each 2-D sub-matrix imported from the text file.
 
void ReadText (FILE *f_in)
 Read contents of the array from a file in binary format.
 
void ReadBinary (std::ifstream &f_in)
 Read contents of the array from a file in text format Added by Maher Salloum.
 

Private Member Functions

 Array3D (const Array3D &obj)
 Copy constructor, which is made private so it would not be used inadvertently (until we define a proper copy constructor)
 

Private Attributes

size_t xsize_
 Number of elements in the x-dimension.
 
size_t ysize_
 Number of elements in the y-dimension.
 
size_t zsize_
 Number of elements in the z-dimension.
 
vector< T > data_
 Data in the array with size = xsize_ * ysize_ * zsize_.
 

Detailed Description

template<typename T>
class Array3D< T >

Stores data of any type T in a 3D array.

This class also provides a Fortran-like access operator () as well as a function to access the data in the array through a pointer that can be passed to F77 or C routines.

Author
Bert Debusschere bjdeb.nosp@m.us@s.nosp@m.andia.nosp@m..gov
Date
Jan 2005
Note
Inspired by Helgi Adalsteinsson's Array class implementation
Todo

Define copy constructor

Several functions, e.g. insert/erase columns/rows, available in Array1D and Array2D, are missing.

Constructor & Destructor Documentation

◆ Array3D() [1/4]

template<typename T >
Array3D< T >::Array3D ( )
inline

Default constructor, which does not allocate any memory.

◆ Array3D() [2/4]

template<typename T >
Array3D< T >::Array3D ( const size_t & nx,
const size_t & ny,
const size_t & nz )
inline

Constructor that allocates the memory.

◆ Array3D() [3/4]

template<typename T >
Array3D< T >::Array3D ( const size_t & nx,
const size_t & ny,
const size_t & nz,
const T & t )
inline

Constructor that allocates and initializes the data.

◆ ~Array3D()

template<typename T >
Array3D< T >::~Array3D ( )
inline

Destructor that frees up the memory.

◆ Array3D() [4/4]

template<typename T >
Array3D< T >::Array3D ( const Array3D< T > & obj)
inlineprivate

Copy constructor, which is made private so it would not be used inadvertently (until we define a proper copy constructor)

Member Function Documentation

◆ Clear()

template<typename T >
void Array3D< T >::Clear ( )
inline

Function to clear the memory.

◆ DumpBinary()

template<typename T >
void Array3D< T >::DumpBinary ( FILE * f_out) const
inline

Dump contents of the array to a file in binary format.

◆ DumpText()

template<typename T >
void Array3D< T >::DumpText ( std::ofstream & f_out) const
inline

Dump contents of the array to a file in text format Added by Maher Salloum When post-processing (in matlab for example), one has to transpose each 2-D sub-matrix imported from the text file.

◆ GetArrayPointer()

template<typename T >
T * Array3D< T >::GetArrayPointer ( )
inline

Return a pointer to the first element of the data in the vector so we can use it access the data in array format (e.g. for passing it to a Fortran program).

◆ GetConstArrayPointer()

template<typename T >
const T * Array3D< T >::GetConstArrayPointer ( ) const
inline

Return a const pointer to the first element of the data in the vector so we can use it access the data in array format (e.g. for passing it to a Fortran program).

◆ operator()() [1/2]

template<typename T >
T & Array3D< T >::operator() ( size_t ix,
size_t iy,
size_t iz )
inline

Fortran-like () operator to access values in the 3D data array.

If "my_data" is an object of type Array3D, then its array values can be accessed as my_data(ix,iy,iz), where ix, iy, iz are the indices in the x, y, and z dimensions respectively.

◆ operator()() [2/2]

template<typename T >
const T & Array3D< T >::operator() ( size_t ix,
size_t iy,
size_t iz ) const
inline

Fortran-like () const operator to access values in the 3D data array.

If "my_data" is an object of type Array3D, then its array values can be accessed as my_data(ix,iy,iz), where ix, iy, iz are the indices in the x, y, and z dimensions respectively.

◆ ReadBinary()

template<typename T >
void Array3D< T >::ReadBinary ( std::ifstream & f_in)
inline

Read contents of the array from a file in text format Added by Maher Salloum.

◆ ReadText()

template<typename T >
void Array3D< T >::ReadText ( FILE * f_in)
inline

Read contents of the array from a file in binary format.

◆ Resize() [1/2]

template<typename T >
void Array3D< T >::Resize ( const size_t & nx,
const size_t & ny,
const size_t & nz )
inline

Resizes the array.

Warning
In its current implementation, most of the original data will get lost if the xsize or ysize changes as this changes the indexing for all entries.
Todo
Write a better implementation that preserves the original data by copying it to a temporary array and putting the elements back where they were before. This would bring this resize() command more closely in line with vector::resize() function in the original vector class.

◆ Resize() [2/2]

template<typename T >
void Array3D< T >::Resize ( const size_t & nx,
const size_t & ny,
const size_t & nz,
const T & t )
inline

Resizes the array and sets ALL entries to the specified value.

Warning
All original data will get lost if this function is used!
Todo
Write an implementation that is more closely follows the resize command in the vector class, which keeps the original elements and only initializes the new elements.

◆ SetValue()

template<typename T >
void Array3D< T >::SetValue ( const T & t)
inline

Set all values in the array to the given value.

◆ XSize()

template<typename T >
size_t Array3D< T >::XSize ( ) const
inline

Returns size in the x-direction.

◆ YSize()

template<typename T >
size_t Array3D< T >::YSize ( ) const
inline

Returns size in the y-direction.

◆ ZSize()

template<typename T >
size_t Array3D< T >::ZSize ( ) const
inline

Returns size in the z-direction.

Member Data Documentation

◆ data_

template<typename T >
vector<T> Array3D< T >::data_
private

Data in the array with size = xsize_ * ysize_ * zsize_.

The data is stored with the fastest running index in the x-dimension then the y-dimension and the slowest one in the z-dimension. The indices in every dimension run from 0 to their respective "size-1"

◆ xsize_

template<typename T >
size_t Array3D< T >::xsize_
private

Number of elements in the x-dimension.

◆ ysize_

template<typename T >
size_t Array3D< T >::ysize_
private

Number of elements in the y-dimension.

◆ zsize_

template<typename T >
size_t Array3D< T >::zsize_
private

Number of elements in the z-dimension.


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