kspaceFirstOrder3D-OMP  1.1
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
 All Classes Files Functions Variables Typedefs Enumerations Friends Pages
MatrixContainer.h
Go to the documentation of this file.
1 /**
2  * @file MatrixContainer.h
3  * @author Jiri Jaros \n
4  * Faculty of Information Technology\n
5  * Brno University of Technology \n
6  * jarosjir@fit.vutbr.cz
7  *
8  * @brief The header file containing the matrix container.
9  *
10  * @version kspaceFirstOrder3D 2.15
11  *
12  * @date 14 September 2012, 14:33 (created) \n
13  * 26 September 2014, 17:10 (revised)
14  *
15  * @section License
16  * This file is part of the C++ extension of the k-Wave Toolbox (http://www.k-wave.org).\n
17  * Copyright (C) 2014 Jiri Jaros and Bradley Treeby
18  *
19  * This file is part of k-Wave. k-Wave is free software: you can redistribute it
20  * and/or modify it under the terms of the GNU Lesser General Public License as
21  * published by the Free Software Foundation, either version 3 of the License,
22  * or (at your option) any later version.
23  *
24  * k-Wave is distributed in the hope that it will be useful, but
25  * WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27  * See the GNU Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License
30  * along with k-Wave. If not, see <http://www.gnu.org/licenses/>.
31  */
32 
33 #ifndef MATRIXCONTAINER_H
34 #define MATRIXCONTAINER_H
35 
36 #include <string.h>
37 #include <map>
38 
47 
48 #include <Utils/MatrixNames.h>
49 #include <Utils/DimensionSizes.h>
50 
51 /**
52  * @enum TMatrixID
53  * @brief Matrix identifers of all matrices in the k-space code
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  //---------------- output matrices -------------//
84  p_sensor_raw, p_sensor_rms, p_sensor_max, p_sensor_min,
85  p_sensor_max_all, p_sensor_min_all,
86  ux_sensor_raw, uy_sensor_raw, uz_sensor_raw,
87 
88  ux_shifted_sensor_raw, uy_shifted_sensor_raw, uz_shifted_sensor_raw, //non_staggered
89  ux_sensor_rms, uy_sensor_rms, uz_sensor_rms,
90  ux_sensor_max, uy_sensor_max, uz_sensor_max,
91  ux_sensor_min, uy_sensor_min, uz_sensor_min,
92  ux_sensor_max_all, uy_sensor_max_all, uz_sensor_max_all,
93  ux_sensor_min_all, uy_sensor_min_all, uz_sensor_min_all,
94 
95 
96  //--------------Temporary matrices -------------//
97  Temp_1_RS3D, Temp_2_RS3D, Temp_3_RS3D,
98  FFT_X_temp, FFT_Y_temp, FFT_Z_temp, FFT_shift_temp
99 }; // enum TMatrixID
100 //------------------------------------------------------------------------------
101 
102 
103 /**
104  * @struct TMatrixRecord
105  * @brief A structure storing details about the matrix. The matrix container
106  * stores this structures.
107  * @details A structure storing details about the matrix. The matrix container
108  * stores the list of these records with the data.
109  */
111 {
112  /**
113  * @enum TMatrixDataType
114  * @brief All possible types of the matrix.
115  */
116  enum TMatrixDataType {mdtReal, mdtComplex, mdtIndex, mdtFFTW, mdtUxyz};
117 
118  /// Pointer to the matrix object.
120  /// Matrix data type.
122  /// Matrix dimension sizes.
124  /// Is the matrix content loaded from the HDF5 file.
125  bool LoadData;
126  /// Is the matrix necessary to be preserver when checkpoint is enabled.
128  /// HDF5 matrix name.
130 
131  /// Default constructor.
133  DimensionSizes(), LoadData(false), Checkpoint(false),
134  HDF5MatrixName("")
135  {};
136 
137  /// Copy constructor.
138  TMatrixRecord(const TMatrixRecord& src);
139 
140  /// operator =
142 
143  /// Set all values of the record.
147  const bool LoadData,
148  const bool Checkpoint,
149  const string HDF5MatrixName);
150 
151  // Destructor.
152  virtual ~TMatrixRecord() {};
153 };// end of TMatrixRecord
154 //------------------------------------------------------------------------------
155 
156 
157 
158 /**
159  * @class TMatrixContainer
160  * @brief Class implementing the matrix container.
161  * @details This container is responsible to maintain all the matrices in the
162  * code except the output streams. The matrices are allocated, freed, loaded
163  * stored and checkpointed from here.
164  */
166 {
167  public:
168 
169  /// Constructor
171  /// Destructor.
172  virtual ~TMatrixContainer();
173 
174  /**
175  * @brief Get number of matrices in the container.
176  * @details Get number of matrices in the container.
177  * @return number of matrices in the container.
178  */
179  size_t size() const
180  {
181  return MatrixContainer.size();
182  };
183 
184  /**
185  * @brief Is the container empty?
186  * @details Is the container empty?
187  * @return true if the container is empty
188  */
189  bool empty() const
190  {
191  return MatrixContainer.empty();
192  };
193 
194  /// Create instances of all objects in the container.
195  void CreateAllObjects();
196 
197  /// Load all matrices from the HDF5 file.
198  void LoadDataFromInputHDF5File(THDF5_File & HDF5_File);
199  /// Load all matrices from the HDF5 file.
200  void LoadDataFromCheckpointHDF5File(THDF5_File & HDF5_File);
201  /// Store selected matrices into the checkpoint file.
203 
204  /// Free all matrices - destroy them.
205  void FreeAllMatrices();
206 
207  /// Set all matrices recored - populate the container
209 
210  /**
211  * @brief Get matrix record (data and information).
212  * @details Get matrix record (data and information).
213  * @param [in] MatrixID - Matrix identifier
214  * @return the matrix record.
215  */
217  {
218  return MatrixContainer[MatrixID];
219  };
220 
221  /**
222  * @brief operator [].
223  * @details operator [].
224  * @param [in] MatrixID - Matrix identifier
225  * @return the matrix record.
226  */
228  {
229  return MatrixContainer[MatrixID];
230  };
231 
232  /**
233  * @brief Get the matrix with a specific type from the container.
234  * @details This template routine returns the reference to the matrix recasted to
235  * the specific class.
236  * @param [in] MatrixID - Matrix identifier
237  * @return Base Matrix
238  */
239  template <typename T>
240  inline T& GetMatrix(const TMatrixID MatrixID)
241  {
242  return static_cast<T &> (*(MatrixContainer[MatrixID].MatrixPtr));
243  };
244 
245  protected:
246 
247 
248  private:
249 
250  /// Datatype for map associating the matrix ID enum and matrix record.
251  typedef map<TMatrixID, TMatrixRecord> TMatrixRecordContainer;
252 
253  /// Map holding the container.
255 
256  /// Copy constructor is not allowed for public.
258 
259  /// Operator = is not allowed for public.
261 
262  /// Print error and throw an exception.
263  void PrintErrorAndThrowException(const char * FMT,
264  const string HDF5MatrixName,
265  const char * File,
266  const int Line);
267 
268 };// end of TMatrixContainer
269 //------------------------------------------------------------------------------
270 
271 
272 /**
273  * @class TOutputStreamContainer
274  * @brief A container for output streams.
275  * @details The output stream container maintains matrices used for sampling data.
276  * These may or may not require some scratch place or reuse temp matrices.
277  */
279 {
280  public:
281  /// Constructor.
283  /// Destructor.
284  virtual ~TOutputStreamContainer();
285 
286  /**
287  * @brief Get size of the container.
288  * @details Get size of the container.
289  */
290  size_t size() const
291  {
292  return OutputStreamContainer.size();
293  };
294 
295  /**
296  * @brief Is the container empty?
297  * @details Is the container empty?
298  */
299  bool empty() const
300  {
301  return OutputStreamContainer.empty();
302  };
303 
304  /**
305  * @brief Operator [].
306  * @details Operator [].
307  * @param [in] MatrixID
308  * @return Ouptut stream
309  */
311  {
312  return (* (OutputStreamContainer[MatrixID]));
313  };
314 
315  /// Create all streams in container (no file manipulation).
316  void AddStreamsIntoContainer(TMatrixContainer & MatrixContainer);
317 
318  /// Create all streams - opens the datasets.
319  void CreateStreams();
320  /// Reopen streams after checkpoint file (datasets).
321  void ReopenStreams();
322 
323  /// Sample all streams.
324  void SampleStreams();
325  /// Post-process all streams and flush them to the file.
326  void PostProcessStreams();
327  /// Checkpoint streams.
328  void CheckpointStreams();
329 
330  /// Close all streams.
331  void CloseStreams();
332 
333  /// Free all streams - destroy them.
334  void FreeAllStreams();
335 
336  protected:
337  // Create a new output stream.
339  const TMatrixID SampledMatrixID,
340  const char * HDF5_DatasetName,
342  float * BufferToReuse = NULL);
343 
344  /// Copy constructor not allowed for public.
346  /// Operator = not allowed for public.
348 
349  private:
350  /// Output stream map.
351  typedef map < TMatrixID, TBaseOutputHDF5Stream * > TOutputStreamMap;
352  /// Map with output streams.
354 
355 }; // end of TOutputStreamContainer
356 //------------------------------------------------------------------------------
357 
358 #endif /* MATRIXCONTAINER_H */
TMatrixRecord & GetMatrixRecord(const TMatrixID MatrixID)
Get matrix record (data and information).
bool LoadData
Is the matrix content loaded from the HDF5 file.
void AddStreamsIntoContainer(TMatrixContainer &MatrixContainer)
Create all streams in container (no file manipulation).
void StoreDataIntoCheckpointHDF5File(THDF5_File &HDF5_File)
Store selected matrices into the checkpoint file.
TReductionOperator
How to aggregate data.
Abstract base class, the common ancestor defining the common interface and allowing derived classes t...
Definition: BaseMatrix.h:52
TMatrixRecordContainer MatrixContainer
Map holding the container.
bool empty() const
Is the container empty?
bool empty() const
Is the container empty?
TOutputStreamContainer()
Constructor.
The header file containing the class for real matrices.
void FreeAllStreams()
Free all streams - destroy them.
virtual ~TMatrixContainer()
Destructor.
size_t size() const
Get size of the container.
The header file containing the particle velocity matrix.
TMatrixRecord & operator[](const TMatrixID MatrixID)
operator [].
bool Checkpoint
Is the matrix necessary to be preserver when checkpoint is enabled.
TMatrixDataType MatrixDataType
Matrix data type.
void FreeAllMatrices()
Free all matrices - destroy them.
map< TMatrixID, TBaseOutputHDF5Stream * > TOutputStreamMap
Output stream map.
TMatrixRecord & operator=(const TMatrixRecord &src)
operator =
The header file of classes responsible for storing output quantities into the output HDF5 file...
map< TMatrixID, TMatrixRecord > TMatrixRecordContainer
Datatype for map associating the matrix ID enum and matrix record.
The header file containing the class for 64b integer matrices.
TBaseOutputHDF5Stream * CreateNewOutputStream(TMatrixContainer &MatrixContainer, const TMatrixID SampledMatrixID, const char *HDF5_DatasetName, const TBaseOutputHDF5Stream::TReductionOperator ReductionOp, float *BufferToReuse=NULL)
TMatrixID
Matrix identifers of all matrices in the k-space code.
void SampleStreams()
Sample all streams.
void LoadDataFromInputHDF5File(THDF5_File &HDF5_File)
Load all matrices from the HDF5 file.
The header file storing names of all variables.
string HDF5MatrixName
HDF5 matrix name.
void ReopenStreams()
Reopen streams after checkpoint file (datasets).
TOutputStreamContainer & operator=(TOutputStreamContainer &)
Operator = not allowed for public.
The header file containing the structure with 3D dimension sizes.
Abstract base class for output data streams (sampled data).
Class implementing the matrix container.
TBaseMatrix * MatrixPtr
Pointer to the matrix object.
TMatrixContainer()
Constructor.
The header file with the class for complex matrices.
TDimensionSizes DimensionSizes
Matrix dimension sizes.
A structure storing details about the matrix. The matrix container stores this structures.
TMatrixContainer & operator=(const TMatrixContainer &src)
Operator = is not allowed for public.
TOutputStreamMap OutputStreamContainer
Map with output streams.
void SetAllValues(TBaseMatrix *MatrixPtr, const TMatrixDataType MatrixDataType, const TDimensionSizes DimensionSizes, const bool LoadData, const bool Checkpoint, const string HDF5MatrixName)
Set all values of the record.
void CheckpointStreams()
Checkpoint streams.
TMatrixDataType
All possible types of the matrix.
virtual ~TOutputStreamContainer()
Destructor.
The header file containing the base class for single precisions floating point numbers (floats) ...
TBaseOutputHDF5Stream & operator[](const TMatrixID MatrixID)
Operator [].
void CreateStreams()
Create all streams - opens the datasets.
T & GetMatrix(const TMatrixID MatrixID)
Get the matrix with a specific type from the container.
void AddMatricesIntoContainer()
Set all matrices recored - populate the container.
void LoadDataFromCheckpointHDF5File(THDF5_File &HDF5_File)
Load all matrices from the HDF5 file.
size_t size() const
Get number of matrices in the container.
void PrintErrorAndThrowException(const char *FMT, const string HDF5MatrixName, const char *File, const int Line)
Print error and throw an exception.
void CloseStreams()
Close all streams.
TMatrixRecord()
Default constructor.
A container for output streams.
The header file of the common ancestor of all matrix classes. A pure abstract class.
void CreateAllObjects()
Create instances of all objects in the container.
Class wrapping the HDF5 routines.
Definition: HDF5_File.h:506
Structure with 4D dimension sizes (3 in space and 1 in time).
void PostProcessStreams()
Post-process all streams and flush them to the file.
The header file containing the class that implements 3D FFT using the FFTW interface.