kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
ComplexMatrix.cpp
Go to the documentation of this file.
1 /**
2  * @file ComplexMatrix.cpp
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 implementation file with the class for complex matrices.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 11 July 2011, 14:02 (created) \n
14  * 04 September 2017, 11:02 (revised)
15  *
16  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
17  *
18  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
21  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
22  * License, or (at your option) any later version.
23  *
24  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
26  * more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
29  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
30  */
31 
32 
34 #include <Logger/Logger.h>
35 
36 using std::ios;
37 //--------------------------------------------------------------------------------------------------------------------//
38 //---------------------------------------------------- Constants -----------------------------------------------------//
39 //--------------------------------------------------------------------------------------------------------------------//
40 
41 
42 //--------------------------------------------------------------------------------------------------------------------//
43 //------------------------------------------------- Public methods ---------------------------------------------------//
44 //--------------------------------------------------------------------------------------------------------------------//
45 
46 /**
47  * Constructor.
48  */
50  : BaseFloatMatrix()
51 {
52  initDimensions(dimensionSizes);
54 } // end of ComplexMatrixData
55 //----------------------------------------------------------------------------------------------------------------------
56 
57 /**
58  * Destructor.
59  */
61 {
62  freeMemory();
63 }// end of ComplexMatrix
64 //----------------------------------------------------------------------------------------------------------------------
65 
66 /**
67  * Read data from HDF5 file (do some basic checks). Only from the root group.
68  */
70  MatrixName& matrixName)
71 {
72  // check data type
74  {
75  throw std::ios::failure(Logger::formatMessage(kErrFmtMatrixNotFloat, matrixName.c_str()));
76  }
77 
78  // check domain type
80  {
81  throw std::ios::failure(Logger::formatMessage(kErrFmtMatrixNotComplex, matrixName.c_str()));
82  }
83 
84  // Initialise dimensions
85  DimensionSizes complexDims = mDimensionSizes;
86  complexDims.nx = 2 * complexDims.nx;
87 
88  // Read data from the file
89  file.readCompleteDataset(file.getRootGroup(), matrixName, complexDims, mData);
90 }// end of readData
91 //----------------------------------------------------------------------------------------------------------------------
92 
93 /**
94  * Write data to HDF5 file (only from the root group).
95  */
97  MatrixName& matrixName,
98  const size_t compressionLevel)
99 {
100  // set dimensions and chunks
101  DimensionSizes complexDims = mDimensionSizes;
102  complexDims.nx = 2 * complexDims.nx;
103 
104  DimensionSizes chunks = complexDims;
105  complexDims.nz = 1;
106 
107  // create a dataset
108  hid_t dataset = file.createDataset(file.getRootGroup(),
109  matrixName,
110  complexDims,
111  chunks,
113  compressionLevel);
114  // Write write the matrix at once.
115  file.writeHyperSlab(dataset, DimensionSizes(0, 0, 0), mDimensionSizes, mData);
116  file.closeDataset(dataset);
117 
118  // Write data and domain type
121 }// end of writeData
122 //----------------------------------------------------------------------------------------------------------------------
123 
124 
125 //--------------------------------------------------------------------------------------------------------------------//
126 //------------------------------------------------ Protected methods -------------------------------------------------//
127 //--------------------------------------------------------------------------------------------------------------------//
128 
129 //--------------------------------------------------------------------------------------------------------------------//
130 //-------------------------------------------------- Private methods -------------------------------------------------//
131 //--------------------------------------------------------------------------------------------------------------------//
132 
133 /**
134  * Initialize matrix dimension sizes.
135  */
137 {
138  mDimensionSizes = dimensionSizes;
139 
140  mSize = dimensionSizes.nx * dimensionSizes.ny * dimensionSizes.nz;
141 
142  mRowSize = 2 * dimensionSizes.nx;
143  mSlabSize = 2 * dimensionSizes.nx * dimensionSizes.ny;
144  // compute actual necessary memory sizes
145  mCapacity = 2 * mSize;
146 
147 }// end of initDimensions
148 //----------------------------------------------------------------------------------------------------------------------
size_t mRowSize
Size of a 1D row in X dimension.
virtual ~ComplexMatrix()
Destructor.
virtual void allocateMemory()
Aligned memory allocation (both on CPU and GPU).
hid_t getRootGroup() const
Get handle to the root group of the file.
Definition: Hdf5File.h:608
size_t nz
Number of elements in the z direction.
The matrix is defined on complex domain.
ErrorMessage kErrFmtMatrixNotComplex
Matrix class error message.
void writeMatrixDomainType(const hid_t parentGroup, MatrixName &datasetName, const MatrixDomainType &matrixDomainType)
Write matrix data type into the dataset at a specified place in the file tree.
Definition: Hdf5File.cpp:807
void closeDataset(const hid_t dataset)
Close dataset.
Definition: Hdf5File.cpp:325
float * mData
Raw matrix data.
DimensionSizes mDimensionSizes
Dimension sizes.
void writeMatrixDataType(const hid_t parentGroup, MatrixName &datasetName, const MatrixDataType &matrixDataType)
Write matrix data type into the dataset at a specified place in the file tree.
Definition: Hdf5File.cpp:793
virtual void writeData(Hdf5File &file, MatrixName &matrixName, const size_t compressionLevel)
Write data into HDF5 file.
The header file containing a class responsible for printing out info and error messages (stdout...
Class wrapping the HDF5 routines.
Definition: Hdf5File.h:490
void initDimensions(const DimensionSizes &dimensionSizes)
Initialize dimension sizes.
static std::string formatMessage(const std::string &format, Args ... args)
C++-11 replacement for sprintf that works with std::string instead of char*.
Definition: Logger.h:157
void writeHyperSlab(const hid_t dataset, const DimensionSizes &position, const DimensionSizes &size, const T *data)
Write a hyperslab into the dataset.
Definition: Hdf5File.cpp:335
const std::string MatrixName
Datatype for matrix names.
Definition: MatrixNames.h:39
Structure with 4D dimension sizes (3 in space and 1 in time).
The matrix is stored in floating point 32b wide format.
MatrixDataType readMatrixDataType(const hid_t parentGroup, MatrixName &datasetName)
Read matrix data type from the dataset at a specified place in the file tree.
Definition: Hdf5File.cpp:821
The header file with the class for complex matrices.
size_t ny
Number of elements in the y direction.
virtual void freeMemory()
Memory allocation (both on CPU and GPU).
virtual void readData(Hdf5File &file, MatrixName &matrixName)
Read matrix from HDF5 file.
size_t mSize
Total number of used elements.
void readCompleteDataset(const hid_t parentGroup, MatrixName &datasetName, const DimensionSizes &dimensionSizes, T *data)
Read data from the dataset at a specified place in the file tree.
Definition: Hdf5File.cpp:678
size_t nx
Number of elements in the x direction.
size_t mSlabSize
Size of a XY slab.
ComplexMatrix()=delete
Default constructor not allowed.
hid_t createDataset(const hid_t parentGroup, MatrixName &datasetName, const DimensionSizes &dimensionSizes, const DimensionSizes &chunkSizes, const MatrixDataType matrixDataType, const size_t compressionLevel)
Create a float HDF5 dataset at a specified place in the file tree (3D/4D).
Definition: Hdf5File.cpp:241
MatrixDomainType readMatrixDomainType(const hid_t parentGroup, MatrixName &datasetName)
Read matrix dataset domain type at a specified place in the file tree.
Definition: Hdf5File.cpp:848
ErrorMessage kErrFmtMatrixNotFloat
Matrix class error message.
size_t mCapacity
Total number of allocated elements (in terms of floats).
Abstract base class for float based matrices defining basic interface. Higher dimensional matrices st...