kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
RealMatrix.h
Go to the documentation of this file.
1 /**
2  * @file RealMatrix.h
3  *
4  * @author Jiri Jaros \n
5  * Faculty of Information Technology \n
6  * Brno University of Technology \n
7  * jarosjir@fit.vutbr.cz
8  *
9  * @brief The header file containing the class for real matrices.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 11 July 2011, 10:30 (created) \n
14  * 04 September 2017, 11:02 (revised)
15  *
16  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
17  *
18  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
21  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
22  * License, or (at your option) any later version.
23  *
24  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
26  * more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
29  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
30  */
31 
32 #ifndef REAL_MATRIX_H
33 #define REAL_MATRIX_H
34 
35 
37 #include <Utils/DimensionSizes.h>
38 
39 // forward declaration
40 class ComplexMatrix;
41 
42 /**
43  * @class RealMatrix
44  * @brief The class for real matrices.
45  * @details The class for real matrices (floats) on both CPU and GPU side.
46  */
48 {
49  public:
50 
51  /// Default constructor is not allowed.
52  RealMatrix() = delete;
53  /**
54  * @brief Constructor.
55  * @param [in] dimensionSizes - Dimension sizes of the matrix.
56  */
57  RealMatrix(const DimensionSizes& dimensionSizes);
58  /// Copy constructor not allowed.
59  RealMatrix(const RealMatrix&) = delete;
60  /// Destructor.
61  virtual ~RealMatrix();
62 
63  /// Operator= is not allowed.
65 
66  /**
67  * @brief Read matrix from HDF5 file.
68  * @details Read matrix from HDF5 file.
69  * @param [in] file - Handle to the HDF5 file
70  * @param [in] matrixName - HDF5 dataset name to read from
71  * @throw ios::failure - If error occurred.
72  */
73  virtual void readData(Hdf5File& file,
74  MatrixName& matrixName);
75  /**
76  * @brief Write data into HDF5 file.
77  * @details Write data into HDF5 file.
78  * @param [in] file - Handle to the HDF5 file
79  * @param [in] matrixName - HDF5 dataset name to write to
80  * @param [in] compressionLevel - Compression level for the HDF5 dataset
81  * @throw ios::failure - If an error occurred.
82  */
83  virtual void writeData(Hdf5File& file,
84  MatrixName& matrixName,
85  const size_t compressionLevel);
86 
87  /**
88  * @brief operator[].
89  * @param [in] index - 1D index into the matrix.
90  * @return An element of the matrix.
91  */
92  inline float& operator[](const size_t& index) { return mData[index]; };
93  /**
94  * @brief Operator[], constant version.
95  * @param [in] index - 1D index into the matrix.
96  * @return An element of the matrix.
97  */
98  inline const float& operator[](const size_t& index) const { return mData[index]; };
99 
100  /**
101  * @brief Get element from 3D matrix.
102  * @param [in] x - x dimension
103  * @param [in] y - y dimension
104  * @param [in] z - z dimension
105  * @return an element
106  */
107  float& getElementFrom3D(const size_t x, const size_t y, const size_t z)
108  {
109  return mData[z * mSlabSize + y * mRowSize + x];
110  };
111 
112  /**
113  * @brief Get element from 3D matrix, const version.
114  * @param [in] x - z dimension
115  * @param [in] y - y dimension
116  * @param [in] z - z dimension
117  * @return an element
118  */
119  const float& getElementFrom3D(const size_t x, const size_t y, const size_t z) const
120  {
121  return mData[z * mSlabSize + y * mRowSize + x];
122  };
123 
124  protected:
125 
126  private:
127  /// Init dimension.
128  void initDimensions(const DimensionSizes& dimensionSizes);
129 
130  /// Number of elements to get 4MB block of data.
131  static constexpr size_t kChunkSize1D4MB = 1048576; //(4MB)
132  /// Number of elements to get 1MB block of data.
133  static constexpr size_t kChunkSize1D1MB = 262144; //(1MB)
134  /// Number of elements to get 256KB block of data.
135  static constexpr size_t kChunkSize1D256kB = 65536; //(256KB)
136 
137 };// end of RealMatrix
138 //----------------------------------------------------------------------------------------------------------------------
139 
140 #endif /* REAL_MATRIX_DATA_H */
141 
142 
143 
static constexpr size_t kChunkSize1D256kB
Number of elements to get 256KB block of data.
Definition: RealMatrix.h:135
The class for real matrices.
Definition: RealMatrix.h:47
size_t mRowSize
Size of a 1D row in X dimension.
float & getElementFrom3D(const size_t x, const size_t y, const size_t z)
Get element from 3D matrix.
Definition: RealMatrix.h:107
virtual void writeData(Hdf5File &file, MatrixName &matrixName, const size_t compressionLevel)
Write data into HDF5 file.
Definition: RealMatrix.cpp:94
RealMatrix & operator=(const RealMatrix &)
Operator= is not allowed.
virtual void readData(Hdf5File &file, MatrixName &matrixName)
Read matrix from HDF5 file.
Definition: RealMatrix.cpp:72
void initDimensions(const DimensionSizes &dimensionSizes)
Init dimension.
Definition: RealMatrix.cpp:147
float * mData
Raw matrix data.
const float & getElementFrom3D(const size_t x, const size_t y, const size_t z) const
Get element from 3D matrix, const version.
Definition: RealMatrix.h:119
Class wrapping the HDF5 routines.
Definition: Hdf5File.h:490
The class for complex matrices.
Definition: ComplexMatrix.h:51
const std::string MatrixName
Datatype for matrix names.
Definition: MatrixNames.h:39
Structure with 4D dimension sizes (3 in space and 1 in time).
static constexpr size_t kChunkSize1D4MB
Number of elements to get 4MB block of data.
Definition: RealMatrix.h:131
The header file containing the structure with 3D dimension sizes.
const float & operator[](const size_t &index) const
Operator[], constant version.
Definition: RealMatrix.h:98
float & operator[](const size_t &index)
operator[].
Definition: RealMatrix.h:92
The header file containing the base class for single precisions floating point numbers (floats)...
static constexpr size_t kChunkSize1D1MB
Number of elements to get 1MB block of data.
Definition: RealMatrix.h:133
size_t mSlabSize
Size of a XY slab.
virtual ~RealMatrix()
Destructor.
Definition: RealMatrix.cpp:63
RealMatrix()=delete
Default constructor is not allowed.
Abstract base class for float based matrices defining basic interface. Higher dimensional matrices st...