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

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

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
39 #include <MatrixClasses/BaseMatrix.h>
40 #include <MatrixClasses/BaseFloatMatrix.h>
41 #include <MatrixClasses/RealMatrix.h>
42 #include <MatrixClasses/ComplexMatrix.h>
43 #include <MatrixClasses/FFTWComplexMatrix.h>
44 #include <MatrixClasses/UXYZ_SGXYZMatrix.h>
45 #include <MatrixClasses/IndexMatrix.h>
46 #include <MatrixClasses/OutputHDF5Stream.h>
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 */
55 enum TMatrixID
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 */
110 struct TMatrixRecord
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.
119 TBaseMatrix * MatrixPtr;
120 /// Matrix data type.
121 TMatrixDataType MatrixDataType;
122 /// Matrix dimension sizes.
123 TDimensionSizes DimensionSizes;
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.
127 bool Checkpoint;
128 /// HDF5 matrix name.
129 string HDF5MatrixName;
130
131 /// Default constructor.
132 TMatrixRecord() : MatrixPtr(NULL), MatrixDataType(mdtReal),
133 DimensionSizes(), LoadData(false), Checkpoint(false),
134 HDF5MatrixName("")
135 {};
136
137 /// Copy constructor.
138 TMatrixRecord(const TMatrixRecord& src);
139
140 /// operator =
141 TMatrixRecord& operator = (const TMatrixRecord& src);
142
143 /// Set all values of the record.
144 void SetAllValues(TBaseMatrix * MatrixPtr,
145 const TMatrixDataType MatrixDataType,
146 const TDimensionSizes DimensionSizes,
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 */
165 class TMatrixContainer
166 {
167 public:
168
169 /// Constructor
170 TMatrixContainer() {}
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.
202 void StoreDataIntoCheckpointHDF5File(THDF5_File & HDF5_File);
203
204 /// Free all matrices - destroy them.
205 void FreeAllMatrices();
206
207 /// Set all matrices recored - populate the container
208 void AddMatricesIntoContainer();
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 */
216 TMatrixRecord& GetMatrixRecord(const TMatrixID MatrixID)
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 */
227 TMatrixRecord& operator [] (const TMatrixID MatrixID)
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.
254 TMatrixRecordContainer MatrixContainer;
255
256 /// Copy constructor is not allowed for public.
257 TMatrixContainer(const TMatrixContainer& src);
258
259 /// Operator = is not allowed for public.
260 TMatrixContainer & operator = (const TMatrixContainer& src);
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 */
278 class TOutputStreamContainer
279 {
280 public:
281 /// Constructor.
282 TOutputStreamContainer() {};
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 */
310 TBaseOutputHDF5Stream & operator [] (const TMatrixID MatrixID)
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.
338 TBaseOutputHDF5Stream * CreateNewOutputStream(TMatrixContainer & MatrixContainer,
339 const TMatrixID SampledMatrixID,
340 const char * HDF5_DatasetName,
341 const TBaseOutputHDF5Stream::TReductionOperator ReductionOp,
342 float * BufferToReuse = NULL);
343
344 /// Copy constructor not allowed for public.
345 TOutputStreamContainer(const TOutputStreamContainer &);
346 /// Operator = not allowed for public.
347 TOutputStreamContainer & operator = (TOutputStreamContainer &);
348
349 private:
350 /// Output stream map.
351 typedef map < TMatrixID, TBaseOutputHDF5Stream * > TOutputStreamMap;
352 /// Map with output streams.
353 TOutputStreamMap OutputStreamContainer;
354
355 }; // end of TOutputStreamContainer
356 //------------------------------------------------------------------------------
357
358 #endif /* MATRIXCONTAINER_H */
TMatrixContainer::GetMatrixRecord
TMatrixRecord & GetMatrixRecord(const TMatrixID MatrixID)
Get matrix record (data and information).
Definition: MatrixContainer.h:216
TMatrixRecord::LoadData
bool LoadData
Is the matrix content loaded from the HDF5 file.
Definition: MatrixContainer.h:125
TOutputStreamContainer::AddStreamsIntoContainer
void AddStreamsIntoContainer(TMatrixContainer &MatrixContainer)
Create all streams in container (no file manipulation).
Definition: MatrixContainer.cpp:622
TMatrixContainer::StoreDataIntoCheckpointHDF5File
void StoreDataIntoCheckpointHDF5File(THDF5_File &HDF5_File)
Store selected matrices into the checkpoint file.
Definition: MatrixContainer.cpp:248
TBaseOutputHDF5Stream::TReductionOperator
TReductionOperator
How to aggregate data.
Definition: OutputHDF5Stream.h:68
TBaseMatrix
Abstract base class, the common ancestor defining the common interface and allowing derived classes t...
Definition: BaseMatrix.h:52
TMatrixContainer::MatrixContainer
TMatrixRecordContainer MatrixContainer
Map holding the container.
Definition: MatrixContainer.h:254
TMatrixContainer::empty
bool empty() const
Is the container empty?
Definition: MatrixContainer.h:189
TOutputStreamContainer::empty
bool empty() const
Is the container empty?
Definition: MatrixContainer.h:299
TOutputStreamContainer::TOutputStreamContainer
TOutputStreamContainer()
Constructor.
Definition: MatrixContainer.h:282
RealMatrix.h
The header file containing the class for real matrices.
TOutputStreamContainer::FreeAllStreams
void FreeAllStreams()
Free all streams - destroy them.
Definition: MatrixContainer.cpp:906
TMatrixContainer::~TMatrixContainer
virtual ~TMatrixContainer()
Destructor.
Definition: MatrixContainer.cpp:144
TOutputStreamContainer::size
size_t size() const
Get size of the container.
Definition: MatrixContainer.h:290
UXYZ_SGXYZMatrix.h
The header file containing the particle velocity matrix.
TMatrixContainer::operator[]
TMatrixRecord & operator[](const TMatrixID MatrixID)
operator [].
Definition: MatrixContainer.h:227
TMatrixRecord::Checkpoint
bool Checkpoint
Is the matrix necessary to be preserver when checkpoint is enabled.
Definition: MatrixContainer.h:127
TMatrixRecord::MatrixDataType
TMatrixDataType MatrixDataType
Matrix data type.
Definition: MatrixContainer.h:121
TMatrixContainer::FreeAllMatrices
void FreeAllMatrices()
Free all matrices - destroy them.
Definition: MatrixContainer.cpp:267
TOutputStreamContainer::TOutputStreamMap
map< TMatrixID, TBaseOutputHDF5Stream * > TOutputStreamMap
Output stream map.
Definition: MatrixContainer.h:351
TMatrixRecord::operator=
TMatrixRecord & operator=(const TMatrixRecord &src)
operator =
Definition: MatrixContainer.cpp:78
OutputHDF5Stream.h
The header file of classes responsible for storing output quantities into the output HDF5 file...
TMatrixContainer::TMatrixRecordContainer
map< TMatrixID, TMatrixRecord > TMatrixRecordContainer
Datatype for map associating the matrix ID enum and matrix record.
Definition: MatrixContainer.h:243
IndexMatrix.h
The header file containing the class for 64b integer matrices.
TOutputStreamContainer::CreateNewOutputStream
TBaseOutputHDF5Stream * CreateNewOutputStream(TMatrixContainer &MatrixContainer, const TMatrixID SampledMatrixID, const char *HDF5_DatasetName, const TBaseOutputHDF5Stream::TReductionOperator ReductionOp, float *BufferToReuse=NULL)
Definition: MatrixContainer.cpp:934
TMatrixID
TMatrixID
Matrix identifers of all matrices in the k-space code.
Definition: MatrixContainer.h:55
TOutputStreamContainer::SampleStreams
void SampleStreams()
Sample all streams.
Definition: MatrixContainer.cpp:844
TMatrixContainer::LoadDataFromInputHDF5File
void LoadDataFromInputHDF5File(THDF5_File &HDF5_File)
Load all matrices from the HDF5 file.
Definition: MatrixContainer.cpp:215
MatrixNames.h
The header file storing names of all variables.
TMatrixRecord::HDF5MatrixName
string HDF5MatrixName
HDF5 matrix name.
Definition: MatrixContainer.h:129
TOutputStreamContainer::ReopenStreams
void ReopenStreams()
Reopen streams after checkpoint file (datasets).
Definition: MatrixContainer.cpp:828
TOutputStreamContainer::operator=
TOutputStreamContainer & operator=(TOutputStreamContainer &)
Operator = not allowed for public.
DimensionSizes.h
The header file containing the structure with 3D dimension sizes.
TBaseOutputHDF5Stream
Abstract base class for output data streams (sampled data).
Definition: OutputHDF5Stream.h:55
TMatrixContainer
Class implementing the matrix container.
Definition: MatrixContainer.h:165
TMatrixRecord::MatrixPtr
TBaseMatrix * MatrixPtr
Pointer to the matrix object.
Definition: MatrixContainer.h:119
TMatrixContainer::TMatrixContainer
TMatrixContainer()
Constructor.
Definition: MatrixContainer.h:170
ComplexMatrix.h
The header file with the class for complex matrices.
TMatrixRecord::DimensionSizes
TDimensionSizes DimensionSizes
Matrix dimension sizes.
Definition: MatrixContainer.h:123
TMatrixRecord
A structure storing details about the matrix. The matrix container stores this structures.
Definition: MatrixContainer.h:110
TMatrixContainer::operator=
TMatrixContainer & operator=(const TMatrixContainer &src)
Operator = is not allowed for public.
TOutputStreamContainer::OutputStreamContainer
TOutputStreamMap OutputStreamContainer
Map with output streams.
Definition: MatrixContainer.h:353
TMatrixRecord::SetAllValues
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.
Definition: MatrixContainer.cpp:105
TOutputStreamContainer::CheckpointStreams
void CheckpointStreams()
Checkpoint streams.
Definition: MatrixContainer.cpp:860
TMatrixRecord::TMatrixDataType
TMatrixDataType
All possible types of the matrix.
Definition: MatrixContainer.h:116
TOutputStreamContainer::~TOutputStreamContainer
virtual ~TOutputStreamContainer()
Destructor.
Definition: MatrixContainer.cpp:609
BaseFloatMatrix.h
The header file containing the base class for single precisions floating point numbers (floats) ...
TOutputStreamContainer::operator[]
TBaseOutputHDF5Stream & operator[](const TMatrixID MatrixID)
Operator [].
Definition: MatrixContainer.h:310
TOutputStreamContainer::CreateStreams
void CreateStreams()
Create all streams - opens the datasets.
Definition: MatrixContainer.cpp:813
TMatrixContainer::GetMatrix
T & GetMatrix(const TMatrixID MatrixID)
Get the matrix with a specific type from the container.
Definition: MatrixContainer.h:240
TMatrixContainer::AddMatricesIntoContainer
void AddMatricesIntoContainer()
Set all matrices recored - populate the container.
Definition: MatrixContainer.cpp:287
TMatrixContainer::LoadDataFromCheckpointHDF5File
void LoadDataFromCheckpointHDF5File(THDF5_File &HDF5_File)
Load all matrices from the HDF5 file.
Definition: MatrixContainer.cpp:232
TMatrixContainer::size
size_t size() const
Get number of matrices in the container.
Definition: MatrixContainer.h:179
TMatrixContainer::PrintErrorAndThrowException
void PrintErrorAndThrowException(const char *FMT, const string HDF5MatrixName, const char *File, const int Line)
Print error and throw an exception.
Definition: MatrixContainer.cpp:585
TOutputStreamContainer::CloseStreams
void CloseStreams()
Close all streams.
Definition: MatrixContainer.cpp:891
TMatrixRecord::TMatrixRecord
TMatrixRecord()
Default constructor.
Definition: MatrixContainer.h:132
TOutputStreamContainer
A container for output streams.
Definition: MatrixContainer.h:278
BaseMatrix.h
The header file of the common ancestor of all matrix classes. A pure abstract class.
TMatrixContainer::CreateAllObjects
void CreateAllObjects()
Create instances of all objects in the container.
Definition: MatrixContainer.cpp:155
THDF5_File
Class wrapping the HDF5 routines.
Definition: HDF5_File.h:506
TDimensionSizes
Structure with 4D dimension sizes (3 in space and 1 in time).
Definition: DimensionSizes.h:63
TOutputStreamContainer::PostProcessStreams
void PostProcessStreams()
Post-process all streams and flush them to the file.
Definition: MatrixContainer.cpp:875
FFTWComplexMatrix.h
The header file containing the class that implements 3D FFT using the FFTW interface.