kspaceFirstOrder3D-CUDA  1.1
The CUDA/C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
 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 
44 
45 #include <Utils/MatrixNames.h>
46 #include <Utils/DimensionSizes.h>
47 
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  */
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  */
97 {
98  public:
99 
100  /// Constructor.
102  /// Destructor.
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
179 
180  /// Copy constructor is not allowed for public
181  TMatrixContainer(const TMatrixContainer& orig);
182 
183  /// Operator = is not allowed for public.
185 
186 };// end of TMatrixContainer
187 //--------------------------------------------------------------------------------------------------
188 #endif /* MATRIX_CONTAINER_H */
189 
void AddMatrices()
Populate the container based on the simulation type.
void FreeMatrices()
Destroy and free all matrices.
void LoadDataFromCheckpointFile(THDF5_File &checkpointFile)
Load all matrices from the output HDF5 file.
TMatrixRecordContainer matrixContainer
map holding the container
The header file containing the class for real matrices.
~TMatrixContainer()
Destructor.
void LoadDataFromInputFile(THDF5_File &inputFile)
Load all matrices from the input HDF5 file.
std::map< TMatrixIdx, TMatrixRecord > TMatrixRecordContainer
Datatype for the map associating the matrix ID enum and matrix record.
TMatrixRecord & operator[](const TMatrixIdx matrixIdx)
operator[]
The header file containing metadata about matrices stored in the matrix container.
T & GetMatrix(const TMatrixIdx matrixIdx)
Get the matrix with a specific type from the container.
void CreateMatrices()
Create all matrices in the container.
size_t Size() const
Get the number of matrices in the container.
bool IsEmpty() const
Is the container empty?
The header file containing the class that implements 3D FFT using the cuFFT interface.
The header file containing the class for 64b integer matrices.
The header file storing names of all variables/matrices/output streams used in the simulation...
TMatrixIdx
Matrix identifers of all matrices in the k-space code, names based on the Matlab notation.
The header file containing the structure with 3D dimension sizes.
Class implementing the matrix container.
TMatrixContainer()
Constructor.
The header file with the class for complex matrices.
A structure storing details about the matrix.
Definition: MatrixRecord.h:49
TMatrixContainer & operator=(const TMatrixContainer &src)
Operator = is not allowed for public.
void CopyMatricesFromDevice()
Copy all matrices from device to host (GPU -> CPU).
The header file containing the base class for single precisions floating point numbers (floats)...
void CopyMatricesToDevice()
Copy all matrices from host to device (CPU -> GPU).
void StoreDataIntoCheckpointFile(THDF5_File &checkpointFile)
Store selected matrices into the checkpoint file.
The header file of the common ancestor of all matrix classes. A pure abstract class.
Class wrapping the HDF5 routines.
Definition: HDF5_File.h:500