| 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
ComplexMatrix.cpp
Go to the documentation of this file.
1 /**
2 * @file ComplexMatrix.cpp
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 implementation file with the class for complex matrices.
9 *
10 * @version kspaceFirstOrder3D 2.15
11 *
12 * @date 11 July 2011, 14:02 (created) \n
13 * 25 September 2014, 12:35 (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 #include <iostream>
34
35 #include <MatrixClasses/ComplexMatrix.h>
36
37 #include <Utils/ErrorMessages.h>
38
39 //----------------------------------------------------------------------------//
40 // Constants //
41 //----------------------------------------------------------------------------//
42
43 //----------------------------------------------------------------------------//
44 // Definitions //
45 //----------------------------------------------------------------------------//
46
47
48 //----------------------------------------------------------------------------//
49 // Implementation //
50 // public methods //
51 //----------------------------------------------------------------------------//
52
53 /**
54 * Constructor.
55 * @param [in] DimensionSizes - Dimension sizes
56 */
57
58 TComplexMatrix::TComplexMatrix(const TDimensionSizes & DimensionSizes)
59 : TBaseFloatMatrix()
60 {
61 InitDimensions(DimensionSizes);
62
63 AllocateMemory();
64 } // end of TComplexMatrixData
65 //-----------------------------------------------------------------------------
66
67
68 /**
69 * Read data from HDF5 file (do some basic checks). Only from the root group.
70 * \throw ios::failure when there is a problem
71 *
72 * @param [in] HDF5_File - HDF5 file
73 * @param [in] MatrixName - HDF5 dataset name
74 */
75 void TComplexMatrix::ReadDataFromHDF5File(THDF5_File & HDF5_File,
76 const char * MatrixName)
77 {
78 // check data type
79 if (HDF5_File.ReadMatrixDataType(HDF5_File.GetRootGroup(), MatrixName) != THDF5_File::hdf5_mdt_float)
80 {
81 char ErrorMessage[256];
82 sprintf(ErrorMessage, Matrix_ERR_FMT_MatrixNotFloat, MatrixName);
83 throw ios::failure(ErrorMessage);
84 }
85
86 // check domain type
87 if (HDF5_File.ReadMatrixDomainType(HDF5_File.GetRootGroup(), MatrixName) != THDF5_File::hdf5_mdt_complex)
88 {
89 char ErrorMessage[256];
90 sprintf(ErrorMessage, Matrix_ERR_FMT_MatrixNotComplex, MatrixName);
91 throw ios::failure(ErrorMessage);
92 }
93
94 // Initialise dimensions
95 TDimensionSizes ComplexDims = pDimensionSizes;
96 ComplexDims.X = 2 * ComplexDims.X;
97
98 // Read data from the file
99 HDF5_File.ReadCompleteDataset(HDF5_File.GetRootGroup(),
100 MatrixName,
101 ComplexDims,
102 pMatrixData);
103 }// end of LoadDataFromMatlabFile
104 //------------------------------------------------------------------------------
105
106 /**
107 * Write data to HDF5 file (only from the root group).
108 * \throw ios::failure an exception what the operation fails
109 *
110 * @param [in] HDF5_File - HDF5 file handle
111 * @param [in] MatrixName - HDF5 dataset name
112 * @param [in] CompressionLevel - Compression level for the dataset
113 */
114 void TComplexMatrix::WriteDataToHDF5File(THDF5_File & HDF5_File,
115 const char * MatrixName,
116 const size_t CompressionLevel)
117 {
118 // set dimensions and chunks
119 TDimensionSizes ComplexDims = pDimensionSizes;
120 ComplexDims.X = 2 * ComplexDims.X;
121
122 TDimensionSizes Chunks = ComplexDims;
123 ComplexDims.Z = 1;
124
125 // create a dataset
126 hid_t HDF5_Dataset_id = HDF5_File.CreateFloatDataset(HDF5_File.GetRootGroup(),
127 MatrixName,
128 ComplexDims,
129 Chunks,
130 CompressionLevel);
131 // Write write the matrix at once.
132 HDF5_File.WriteHyperSlab(HDF5_Dataset_id,
133 TDimensionSizes(0, 0, 0),
134 pDimensionSizes,
135 pMatrixData);
136 HDF5_File.CloseDataset(HDF5_Dataset_id);
137
138 // Write data and domain type
139 HDF5_File.WriteMatrixDataType(HDF5_File.GetRootGroup(),
140 MatrixName,
141 THDF5_File::hdf5_mdt_float);
142
143 HDF5_File.WriteMatrixDomainType(HDF5_File.GetRootGroup(),
144 MatrixName,
145 THDF5_File::hdf5_mdt_complex);
146 }// end of WriteDataToHDF5File
147 //---------------------------------------------------------------------------
148
149
150
151
152 //----------------------------------------------------------------------------//
153 // Implementation //
154 // protected methods //
155 //----------------------------------------------------------------------------//
156 /**
157 * Initialize matrix dimension sizes.
158 * @param [in] DimensionSizes
159 */
160 void TComplexMatrix::InitDimensions(const TDimensionSizes & DimensionSizes)
161 {
162
163 pDimensionSizes = DimensionSizes;
164
165 pTotalElementCount = pDimensionSizes.X *
166 pDimensionSizes.Y *
167 pDimensionSizes.Z;
168
169 pDataRowSize = (pDimensionSizes.X << 1);
170
171 p2DDataSliceSize = (pDimensionSizes.X *
172 pDimensionSizes.Y) << 1;
173
174 // compute actual necessary memory sizes
175 pTotalAllocatedElementCount = pTotalElementCount << 1;
176
177 }// end of InitDimensions
178 //------------------------------------------------------------------------------
179
180 //----------------------------------------------------------------------------//
181 // Implementation //
182 // private methods //
183 //----------------------------------------------------------------------------//
TDimensionSizes::Z
size_t Z
Z dimension size.
Definition: DimensionSizes.h:70
TBaseFloatMatrix
Abstract base class for float based matrices defining basic interface. Higher dimensional matrices st...
Definition: BaseFloatMatrix.h:52
THDF5_File::ReadMatrixDataType
THDF5_File::THDF5_MatrixDataType ReadMatrixDataType(const hid_t ParentGroup, const char *DatasetName)
Read matrix data type from the dataset.
Definition: HDF5_File.cpp:1155
TComplexMatrix::WriteDataToHDF5File
virtual void WriteDataToHDF5File(THDF5_File &HDF5_File, const char *MatrixName, const size_t CompressionLevel)
Write data into the HDF5_File.
Definition: ComplexMatrix.cpp:114
TComplexMatrix::ReadDataFromHDF5File
virtual void ReadDataFromHDF5File(THDF5_File &HDF5_File, const char *MatrixName)
Load data from the HDF5_File.
Definition: ComplexMatrix.cpp:75
TBaseFloatMatrix::AllocateMemory
virtual void AllocateMemory()
Memory allocation.
Definition: BaseFloatMatrix.cpp:115
TBaseFloatMatrix::p2DDataSliceSize
size_t p2DDataSliceSize
Size of a 2D slab (X,Y).
Definition: BaseFloatMatrix.h:119
TComplexMatrix::InitDimensions
virtual void InitDimensions(const TDimensionSizes &DimensionSizes)
Initialize dimension sizes and related structures.
Definition: ComplexMatrix.cpp:160
TDimensionSizes::X
size_t X
X dimension size.
Definition: DimensionSizes.h:66
THDF5_File::WriteHyperSlab
void WriteHyperSlab(const hid_t HDF5_Dataset_id, const TDimensionSizes &Position, const TDimensionSizes &Size, const float *Data)
Write a hyper-slab into the dataset - float dataset.
Definition: HDF5_File.cpp:467
TBaseFloatMatrix::pTotalAllocatedElementCount
size_t pTotalAllocatedElementCount
Total number of allocated elements (in terms of floats).
Definition: BaseFloatMatrix.h:111
TBaseFloatMatrix::pTotalElementCount
size_t pTotalElementCount
Total number of elements.
Definition: BaseFloatMatrix.h:109
THDF5_File::WriteMatrixDataType
void WriteMatrixDataType(const hid_t ParentGroup, const char *DatasetName, const THDF5_MatrixDataType &MatrixDataType)
Write matrix data type into the dataset under a specified group.
Definition: HDF5_File.cpp:1116
THDF5_File::WriteMatrixDomainType
void WriteMatrixDomainType(const hid_t ParentGroup, const char *DatasetName, const THDF5_MatrixDomainType &MatrixDomainType)
Write matrix domain type into the dataset under the root group.
Definition: HDF5_File.cpp:1135
TBaseFloatMatrix::pDimensionSizes
struct TDimensionSizes pDimensionSizes
Dimension sizes.
Definition: BaseFloatMatrix.h:114
THDF5_File::GetRootGroup
hid_t GetRootGroup() const
Get handle to the root group.
Definition: HDF5_File.h:581
ErrorMessages.h
The header file containing all error messages of the project.
THDF5_File::CreateFloatDataset
hid_t CreateFloatDataset(const hid_t ParentGroup, const char *DatasetName, const TDimensionSizes &DimensionSizes, const TDimensionSizes &ChunkSizes, const size_t CompressionLevel)
Create the HDF5 dataset at a specified place in the file tree (3D/4D).
Definition: HDF5_File.cpp:291
TBaseFloatMatrix::pDataRowSize
size_t pDataRowSize
Size of a 1D row in X dimension.
Definition: BaseFloatMatrix.h:117
ComplexMatrix.h
The header file with the class for complex matrices.
THDF5_File::ReadMatrixDomainType
THDF5_File::THDF5_MatrixDomainType ReadMatrixDomainType(const hid_t ParentGroup, const char *DatasetName)
Read matrix domain type from the dataset under a specified group.
Definition: HDF5_File.cpp:1190
TDimensionSizes::Y
size_t Y
Y dimension size.
Definition: DimensionSizes.h:68
THDF5_File::ReadCompleteDataset
void ReadCompleteDataset(const hid_t ParentGroup, const char *DatasetName, const TDimensionSizes &DimensionSizes, float *Data)
Read data from the dataset under a specified group - float dataset.
Definition: HDF5_File.cpp:954
TComplexMatrix::TComplexMatrix
TComplexMatrix()
Default constructor not allowed for public.
Definition: ComplexMatrix.h:141
TDimensionSizes::TDimensionSizes
TDimensionSizes()
Default constructor.
Definition: DimensionSizes.h:75
Matrix_ERR_FMT_MatrixNotComplex
const char *const Matrix_ERR_FMT_MatrixNotComplex
Matrix class error message.
Definition: ErrorMessages.h:87
Matrix_ERR_FMT_MatrixNotFloat
const char *const Matrix_ERR_FMT_MatrixNotFloat
Matrix class error message.
Definition: ErrorMessages.h:83
TBaseFloatMatrix::pMatrixData
float * pMatrixData
Raw matrix data.
Definition: BaseFloatMatrix.h:122
THDF5_File::CloseDataset
void CloseDataset(const hid_t HDF5_Dataset_id)
Close the HDF5 dataset.
Definition: HDF5_File.cpp:451
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