32 #ifndef ARRAY3D_H_SEEN
33 #define ARRAY3D_H_SEEN
59 Array3D(): xsize_(0), ysize_(0), zsize_(0) {};
62 Array3D(
const size_t& nx,
const size_t& ny,
const size_t& nz):
63 xsize_(nx), ysize_(ny), zsize_(nz) {
64 data_.resize(xsize_*ysize_*zsize_);
68 Array3D(
const size_t& nx,
const size_t& ny,
const size_t& nz,
const T& t):
69 xsize_(nx), ysize_(ny), zsize_(nz) {
70 data_.resize(xsize_*ysize_*zsize_ , t);
85 size_t XSize()
const {
return xsize_;}
87 size_t YSize()
const {
return ysize_;}
89 size_t ZSize()
const {
return zsize_;}
98 void Resize(
const size_t& nx,
const size_t& ny,
const size_t& nz) {
102 data_.resize(xsize_*ysize_*zsize_);
110 void Resize(
const size_t& nx,
const size_t& ny,
const size_t& nz,
const T& t) {
115 data_.resize(xsize_*ysize_*zsize_ , t);
120 for(
size_t i=0; i < data_.size(); i++){
144 T&
operator()(
size_t ix,
size_t iy,
size_t iz) {
return data_[ix+xsize_*(iy+ysize_*iz)];}
151 const T&
operator()(
size_t ix,
size_t iy,
size_t iz)
const {
return data_[ix+xsize_*(iy+ysize_*iz)];}
155 fwrite(&xsize_,
sizeof(xsize_),1,f_out);
156 fwrite(&ysize_,
sizeof(ysize_),1,f_out);
157 fwrite(&zsize_,
sizeof(zsize_),1,f_out);
158 fwrite(this->GetConstArrayPointer(),
sizeof(T),xsize_*ysize_*zsize_,f_out);
166 vector<double>::const_iterator it1;
167 vector<double>::const_iterator it2;
170 for (
int iz=0;iz<zsize_;iz++) {
171 for (
int iy=0;iy<ysize_;iy++) {
174 std::copy(it1,it2,std::ostream_iterator<T>(f_out,
" "));
183 fread(&xsize_,
sizeof(xsize_),1,f_in);
184 fread(&ysize_,
sizeof(ysize_),1,f_in);
185 fread(&zsize_,
sizeof(zsize_),1,f_in);
186 data_.resize(xsize_*ysize_*zsize_);
187 fread(this->GetArrayPointer(),
sizeof(T),xsize_*ysize_*zsize_,f_in);
194 typedef std::istream_iterator<T> istream_iterator;
195 std::copy(istream_iterator(f_in),istream_iterator(),data_.begin());
Stores data of any type T in a 3D array.
Definition: Array3D.h:56
void SetValue(const T &t)
Set all values in the array to the given value.
Definition: Array3D.h:119
size_t XSize() const
Returns size in the x-direction.
Definition: Array3D.h:85
void DumpBinary(FILE *f_out) const
Dump contents of the array to a file in binary format.
Definition: Array3D.h:154
vector< T > data_
Data in the array with size = xsize_ * ysize_ * zsize_.
Definition: Array3D.h:217
Array3D()
Default constructor, which does not allocate any memory.
Definition: Array3D.h:59
void ReadBinary(std::ifstream &f_in)
Read contents of the array from a file in text format Added by Maher Salloum.
Definition: Array3D.h:192
~Array3D()
Destructor that frees up the memory.
Definition: Array3D.h:74
Array3D(const size_t &nx, const size_t &ny, const size_t &nz, const T &t)
Constructor that allocates and initializes the data.
Definition: Array3D.h:68
T * GetArrayPointer()
Return a pointer to the first element of the data in the vector so we can use it access the data in a...
Definition: Array3D.h:128
void Clear()
Function to clear the memory.
Definition: Array3D.h:77
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 m...
Definition: Array3D.h:165
size_t ysize_
Number of elements in the y-dimension.
Definition: Array3D.h:208
size_t zsize_
Number of elements in the z-dimension.
Definition: Array3D.h:210
Array3D(const size_t &nx, const size_t &ny, const size_t &nz)
Constructor that allocates the memory.
Definition: Array3D.h:62
void ReadText(FILE *f_in)
Read contents of the array from a file in binary format.
Definition: Array3D.h:182
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.
Definition: Array3D.h:110
size_t ZSize() const
Returns size in the z-direction.
Definition: Array3D.h:89
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 dat...
Definition: Array3D.h:135
void Resize(const size_t &nx, const size_t &ny, const size_t &nz)
Resizes the array.
Definition: Array3D.h:98
size_t YSize() const
Returns size in the y-direction.
Definition: Array3D.h:87
Array3D(const Array3D &obj)
Copy constructor, which is made private so it would not be used inadvertently (until we define a prop...
Definition: Array3D.h:203
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.
Definition: Array3D.h:151
size_t xsize_
Number of elements in the x-dimension.
Definition: Array3D.h:203
T & operator()(size_t ix, size_t iy, size_t iz)
Fortran-like () operator to access values in the 3D data array.
Definition: Array3D.h:144