| kspaceFirstOrder3D-CUDA 1.1 The CUDA/C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatrixContainer.h
Go to the documentation of this file.
1 /**
2 * @file MatrixContainer.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 matrix container and the related
10 * matrix record class.
11 *
12 * @version kspaceFirstOrder3D 3.4
13 *
14 * @date 02 December 2014, 16:17 (created) \n
15 * 10 August 2016, 10:42 (revised)
16 *
17 * @section License
18 * This file is part of the C++ extension of the k-Wave Toolbox
19 * (http://www.k-wave.org).\n Copyright (C) 2016 Jiri Jaros and Bradley Treeby.
20 *
21 * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify
22 * it under the terms of the GNU Lesser General Public License as published by the Free Software
23 * Foundation, either version 3 of the License, or (at your option) any later version.
24 *
25 * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
26 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
27 * General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
30 * If not, see http://www.gnu.org/licenses/.
31 */
32
33 #ifndef MATRIX_CONTAINER_H
34 #define MATRIX_CONTAINER_H
35
36 #include <map>
37
38 #include <MatrixClasses/BaseMatrix.h>
39 #include <MatrixClasses/BaseFloatMatrix.h>
40 #include <MatrixClasses/RealMatrix.h>
41 #include <MatrixClasses/ComplexMatrix.h>
42 #include <MatrixClasses/IndexMatrix.h>
43 #include <MatrixClasses/CUFFTComplexMatrix.h>
44
45 #include <Utils/MatrixNames.h>
46 #include <Utils/DimensionSizes.h>
47
48 #include <Containers/MatrixRecord.h>
49
50
51 /**
52 * @enum TMatrixIdx
53 * @brief Matrix identifers of all matrices in the k-space code, names based on the Matlab notation.
54 */
55 enum TMatrixIdx
56 {
57 kappa, c2, p,
58
59 ux_sgx , uy_sgy , uz_sgz,
60 ux_shifted, uy_shifted, uz_shifted,
61 duxdx , duydy , duzdz,
62 dxudxn , dyudyn , dzudzn,
63 dxudxn_sgx, dyudyn_sgy, dzudzn_sgz,
64
65 rhox, rhoy , rhoz, rho0,
66 dt_rho0_sgx, dt_rho0_sgy, dt_rho0_sgz,
67
68 p0_source_input, sensor_mask_index, sensor_mask_corners,
69 ddx_k_shift_pos, ddy_k_shift_pos, ddz_k_shift_pos,
70 ddx_k_shift_neg, ddy_k_shift_neg, ddz_k_shift_neg,
71 x_shift_neg_r , y_shift_neg_r , z_shift_neg_r,
72 pml_x_sgx , pml_y_sgy , pml_z_sgz,
73 pml_x , pml_y , pml_z,
74
75 absorb_tau, absorb_eta, absorb_nabla1, absorb_nabla2, BonA,
76
77 ux_source_input, uy_source_input, uz_source_input,
78 p_source_input,
79
80 u_source_index, p_source_index, transducer_source_input,
81 delay_mask,
82
83 //--------------Temporary matrices -------------//
84 temp_1_real_3D, temp_2_real_3D, temp_3_real_3D,
85 cufft_x_temp, cufft_y_temp, cufft_z_temp, cufft_shift_temp
86 };// end of TMatrixID
87 //--------------------------------------------------------------------------------------------------
88
89
90 /**
91 * @class TMatrixContainer
92 * @brief Class implementing the matrix container.
93 * @details This container is responsible to maintain all the matrices in the code except the output
94 * streams. The matrices are allocated, freed, loaded stored and check-pointed from here.
95 */
96 class TMatrixContainer
97 {
98 public:
99
100 /// Constructor.
101 TMatrixContainer();
102 /// Destructor.
103 ~TMatrixContainer();
104
105 /**
106 * @brief Get the number of matrices in the container.
107 * @details Get the number of matrices in the container.
108 * @return The number of matrices in the container.
109 */
110 inline size_t Size() const
111 {
112 return matrixContainer.size();
113 };
114
115 /**
116 * @brief Is the container empty?
117 * @details Is the container empty?
118 * @return true if the container is empty.
119 */
120 inline bool IsEmpty() const
121 {
122 return matrixContainer.empty();
123 };
124
125 /**
126 * @brief operator[]
127 * @details operator[]
128 * @param [in] matrixIdx - Matrix identifier
129 * @return Matrix record
130 */
131 inline TMatrixRecord& operator[] (const TMatrixIdx matrixIdx)
132 {
133 return matrixContainer[matrixIdx];
134 };
135
136 /**
137 * @brief Get the matrix with a specific type from the container.
138 * @details This template routine returns the reference to the matrix re-casted to the specific
139 * class type.
140 * @param [in] matrixIdx - Matrix identifier
141 * @return Reference to the Matrix
142 */
143 template <typename T>
144 inline T& GetMatrix(const TMatrixIdx matrixIdx)
145 {
146 return static_cast<T &> (*(matrixContainer[matrixIdx].matrixPtr));
147 };
148
149
150 /// Create all matrices in the container.
151 void CreateMatrices();
152 /// Populate the container based on the simulation type.
153 void AddMatrices();
154 /// Destroy and free all matrices.
155 void FreeMatrices();
156
157 /// Load all matrices from the input HDF5 file.
158 void LoadDataFromInputFile(THDF5_File& inputFile);
159 /// Load all matrices from the output HDF5 file.
160 void LoadDataFromCheckpointFile(THDF5_File& checkpointFile);
161 /// Store selected matrices into the checkpoint file.
162 void StoreDataIntoCheckpointFile(THDF5_File& checkpointFile);
163
164 /// Copy all matrices from host to device (CPU -> GPU).
165 void CopyMatricesToDevice();
166 /// Copy all matrices from device to host (GPU -> CPU).
167 void CopyMatricesFromDevice();
168
169
170 protected:
171
172 private:
173
174 /// Datatype for the map associating the matrix ID enum and matrix record.
175 typedef std::map<TMatrixIdx, TMatrixRecord> TMatrixRecordContainer;
176
177 /// map holding the container
178 TMatrixRecordContainer matrixContainer;
179
180 /// Copy constructor is not allowed for public
181 TMatrixContainer(const TMatrixContainer& orig);
182
183 /// Operator = is not allowed for public.
184 TMatrixContainer & operator = (const TMatrixContainer& src);
185
186 };// end of TMatrixContainer
187 //--------------------------------------------------------------------------------------------------
188 #endif /* MATRIX_CONTAINER_H */
189
TMatrixContainer::AddMatrices
void AddMatrices()
Populate the container based on the simulation type.
Definition: MatrixContainer.cpp:123
TMatrixContainer::FreeMatrices
void FreeMatrices()
Destroy and free all matrices.
Definition: MatrixContainer.cpp:458
TMatrixContainer::LoadDataFromCheckpointFile
void LoadDataFromCheckpointFile(THDF5_File &checkpointFile)
Load all matrices from the output HDF5 file.
Definition: MatrixContainer.cpp:422
TMatrixContainer::matrixContainer
TMatrixRecordContainer matrixContainer
map holding the container
Definition: MatrixContainer.h:178
RealMatrix.h
The header file containing the class for real matrices.
TMatrixContainer::~TMatrixContainer
~TMatrixContainer()
Destructor.
Definition: MatrixContainer.cpp:62
TMatrixContainer::LoadDataFromInputFile
void LoadDataFromInputFile(THDF5_File &inputFile)
Load all matrices from the input HDF5 file.
Definition: MatrixContainer.cpp:406
TMatrixContainer::TMatrixRecordContainer
std::map< TMatrixIdx, TMatrixRecord > TMatrixRecordContainer
Datatype for the map associating the matrix ID enum and matrix record.
Definition: MatrixContainer.h:175
TMatrixContainer::operator[]
TMatrixRecord & operator[](const TMatrixIdx matrixIdx)
operator[]
Definition: MatrixContainer.h:131
MatrixRecord.h
The header file containing metadata about matrices stored in the matrix container.
TMatrixContainer::GetMatrix
T & GetMatrix(const TMatrixIdx matrixIdx)
Get the matrix with a specific type from the container.
Definition: MatrixContainer.h:144
TMatrixContainer::CreateMatrices
void CreateMatrices()
Create all matrices in the container.
Definition: MatrixContainer.cpp:72
TMatrixContainer::Size
size_t Size() const
Get the number of matrices in the container.
Definition: MatrixContainer.h:110
TMatrixContainer::IsEmpty
bool IsEmpty() const
Is the container empty?
Definition: MatrixContainer.h:120
CUFFTComplexMatrix.h
The header file containing the class that implements 3D FFT using the cuFFT interface.
IndexMatrix.h
The header file containing the class for 64b integer matrices.
MatrixNames.h
The header file storing names of all variables/matrices/output streams used in the simulation...
TMatrixIdx
TMatrixIdx
Matrix identifers of all matrices in the k-space code, names based on the Matlab notation.
Definition: MatrixContainer.h:55
DimensionSizes.h
The header file containing the structure with 3D dimension sizes.
TMatrixContainer
Class implementing the matrix container.
Definition: MatrixContainer.h:96
TMatrixContainer::TMatrixContainer
TMatrixContainer()
Constructor.
Definition: MatrixContainer.cpp:51
ComplexMatrix.h
The header file with the class for complex matrices.
TMatrixRecord
A structure storing details about the matrix.
Definition: MatrixRecord.h:49
TMatrixContainer::operator=
TMatrixContainer & operator=(const TMatrixContainer &src)
Operator = is not allowed for public.
TMatrixContainer::CopyMatricesFromDevice
void CopyMatricesFromDevice()
Copy all matrices from device to host (GPU -> CPU).
Definition: MatrixContainer.cpp:486
BaseFloatMatrix.h
The header file containing the base class for single precisions floating point numbers (floats)...
TMatrixContainer::CopyMatricesToDevice
void CopyMatricesToDevice()
Copy all matrices from host to device (CPU -> GPU).
Definition: MatrixContainer.cpp:474
TMatrixContainer::StoreDataIntoCheckpointFile
void StoreDataIntoCheckpointFile(THDF5_File &checkpointFile)
Store selected matrices into the checkpoint file.
Definition: MatrixContainer.cpp:438
BaseMatrix.h
The header file of the common ancestor of all matrix classes. A pure abstract class.
THDF5_File
Class wrapping the HDF5 routines.
Definition: HDF5_File.h:500