kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
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.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 14 September 2012, 14:33 (created) \n
14  * 04 September 2017, 10:54 (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 #ifndef MATRIX_CONTAINER_H
33 #define MATRIX_CONTAINER_H
34 
35 #include <map>
36 
39 
40 #include <Utils/MatrixNames.h>
41 #include <Utils/DimensionSizes.h>
42 
43 /**
44  * @class MatrixContainer
45  * @brief Class implementing the matrix container.
46  * @details This container is responsible to maintain all the matrices in the code except the output
47  * streams. The matrices are allocated, freed, loaded stored and check-pointed from here.
48  */
50 {
51  public:
52  /**
53  * @enum MatrixIdx
54  * @brief Matrix identifers of all matrices in the k-space code.
55  */
56  enum class MatrixIdx
57  {
58  /// Kappa matrix.
59  kKappa,
60  /// c^2 matrix.
61  kC2,
62  /// Pressure matrix.
63  kP,
64 
65  /// Acoustic density x.
66  kRhoX,
67  /// Acoustic density y.
68  kRhoY,
69  /// Acoustic density z.
70  kRhoZ,
71 
72  /// Velocity x on staggered grid.
73  kUxSgx,
74  /// Velocity y on staggered grid.
75  kUySgy,
76  /// Velocity z on staggered grid.
77  kUzSgz,
78 
79  /// Acoustic acceleration x.
80  kDuxdx,
81  /// Acoustic acceleration y.
82  kDuydy,
83  /// Acoustic acceleration z.
84  kDuzdz,
85 
86  /// Initial velocity
87  kRho0,
88  /// dt / initial velocity on staggered grid x.
89  kDtRho0Sgx,
90  /// dt / initial velocity on staggered grid y.
91  kDtRho0Sgy,
92  /// dt / initial velocity on staggered grid z.
93  kDtRho0Sgz,
94 
95  /// Positive Fourier shift in x.
97  /// Positive Fourier shift in y.
99  /// Positive Fourier shift in z.
101 
102  /// Negative Fourier shift in x
104  /// Negative Fourier shift in y
106  /// Negative Fourier shift in z
108 
109  /// PML on staggered grid x.
110  kPmlXSgx,
111  /// PML on staggered grid y.
112  kPmlYSgy,
113  /// PML on staggered grid z.
114  kPmlZSgz,
115  /// PML in x.
116  kPmlX,
117  /// PML in y.
118  kPmlY,
119  /// PML in z.
120  kPmlZ,
121 
122  /// Nonlinear coefficient.
123  kBOnA,
124  /// Absorbing coefficient Tau.
125  kAbsorbTau,
126  /// Absorbing coefficient Eau.
127  kAbsorbEta,
128  /// Absorbing coefficient Nabla 1.
130  /// Absorbing coefficient Nabla 2.
132 
133  /// Linear sensor mask.
135  /// Cuboid corners sensor mask.
137 
138  /// Initial pressure source data.
140  /// Pressure source input data.
142  /// Transducer source input data.
144  /// Velocity x source input data.
146  /// Velocity y source input data.
148  /// Velocity z source input data.
150  /// Pressure source geometry data.
152  /// Velocity source geometry data.
154  /// Delay mask for many types sources
155  kDelayMask,
156 
157  /// Non uniform grid acoustic velocity in x.
158  kDxudxn,
159  /// Non uniform grid acoustic velocity in y.
160  kDyudyn,
161  /// Non uniform grid acoustic velocity in z.
162  kDzudzn,
163  /// Non uniform grid acoustic velocity on staggered grid x.
164  kDxudxnSgx,
165  /// Non uniform grid acoustic velocity on staggered grid y.
166  kDyudynSgy,
167  /// Non uniform grid acoustic velocity on staggered grid z.
168  kDzudznSgz,
169 
170  /// velocity shift for non-staggered velocity in x.
171  kUxShifted,
172  /// velocity shift for non-staggered velocity in y.
173  kUyShifted,
174  /// velocity shift for non-staggered velocity in z.
175  kUzShifted,
176 
177  /// Negative shift for non-staggered velocity in x.
178  kXShiftNegR,
179  /// Negative shift for non-staggered velocity in y.
180  kYShiftNegR,
181  /// Negative shift for non-staggered velocity in z.
182  kZShiftNegR,
183 
184  /// 3D temporary matrix.
185  kTemp1Real3D,
186  /// 3D temporary matrix.
187  kTemp2Real3D,
188  /// 3D temporary matrix.
189  kTemp3Real3D,
190  /// Temporary matrix for 1D fft in x.
191  kTempFftwX,
192  /// Temporary matrix for 1D fft in y.
193  kTempFftwY,
194  /// Temporary matrix for 1D fft in z.
195  kTempFftwZ,
196  /// Temporary matrix for fft shift.
198  }; // end of MatrixIdx
199 
200  /// Constructor.
201  MatrixContainer();
202  /// Copy constructor is not allowed.
203  MatrixContainer(const MatrixContainer&) = delete;
204  /// Destructor.
206 
207  /// Operator = is not allowed.
208  MatrixContainer& operator=(const MatrixContainer&) = delete;
209 
210  /**
211  * @brief Get the number of matrices in the container.
212  * @return Number of matrices in the container.
213  */
214  size_t size() const
215  {
216  return mContainer.size();
217  };
218 
219  /**
220  * @brief Is the container empty?
221  * @return true - If the container is empty.
222  */
223  bool empty() const
224  {
225  return mContainer.empty();
226  };
227 
228  /**
229  * @brief operator[]
230  * @param [in] matrixIdx - Matrix identifier
231  * @return Matrix record.
232  */
233  inline MatrixRecord& operator[](const MatrixIdx matrixIdx)
234  {
235  return mContainer[matrixIdx];
236  };
237 
238  /**
239  * @brief Get the matrix with a specific type from the container.
240  * @details This template routine returns the reference to the matrix re-casted to the specific class type.
241  * @param [in] matrixIdx - Matrix identifier,
242  * @return Reference to the Matrix,
243  */
244  template <typename T>
245  inline T& getMatrix(const MatrixIdx matrixIdx)
246  {
247  return static_cast<T&> (*(mContainer[matrixIdx].matrixPtr));
248  };
249 
250  /**
251  * @brief Create all matrix objects in the container.
252  * @throw std::bad_alloc - Usually due to out of memory.
253  * @throw std::invalid_argument - If this routine is called more than once.
254  * @throw std::invalid_argument - If matrix type is unknown.
255  */
256  void createMatrices();
257  /// Populate the container based on the simulation type.
258  void addMatrices();
259  /// Destroy and free all matrices.
260  void freeMatrices();
261 
262  /// Load all marked matrices from the input HDF5 file.
263  void loadDataFromInputFile();
264  /// Load selected matrices from the checkpoint HDF5 file.
266  /// Store selected matrices into the checkpoint file.
268 
269  protected:
270 
271 
272  private:
273 
274  /// Map holding the container.
275  std::map<MatrixIdx, MatrixRecord> mContainer;
276 
277 
278 };// end of MatrixContainer
279 //----------------------------------------------------------------------------------------------------------------------
280 
281 #endif /* MATRIX_CONTAINER_H */
velocity shift for non-staggered velocity in x.
Non uniform grid acoustic velocity in y.
Class implementing the matrix container.
Temporary matrix for 1D fft in y.
Non uniform grid acoustic velocity on staggered grid x.
Temporary matrix for 1D fft in z.
MatrixContainer & operator=(const MatrixContainer &)=delete
Operator = is not allowed.
void loadDataFromCheckpointFile()
Load selected matrices from the checkpoint HDF5 file.
bool empty() const
Is the container empty?
Non uniform grid acoustic velocity in z.
Velocity x on staggered grid.
PML on staggered grid x.
The header file containing metadata about matrices stored in the matrix container.
MatrixRecord & operator[](const MatrixIdx matrixIdx)
operator[]
Absorbing coefficient Nabla 1.
Absorbing coefficient Tau.
Negative shift for non-staggered velocity in z.
Negative Fourier shift in z.
void freeMatrices()
Destroy and free all matrices.
Nonlinear coefficient.
std::map< MatrixIdx, MatrixRecord > mContainer
Map holding the container.
Negative shift for non-staggered velocity in y.
Acoustic acceleration z.
Absorbing coefficient Nabla 2.
void createMatrices()
Create all matrix objects in the container.
~MatrixContainer()
Destructor.
dt / initial velocity on staggered grid z.
Negative Fourier shift in y.
Positive Fourier shift in y.
Acoustic acceleration y.
MatrixContainer()
Constructor.
MatrixIdx
Matrix identifers of all matrices in the k-space code.
The header file storing names of all variables.
Non uniform grid acoustic velocity on staggered grid z.
Positive Fourier shift in z.
The header file containing the structure with 3D dimension sizes.
dt / initial velocity on staggered grid y.
Non uniform grid acoustic velocity in x.
PML on staggered grid z.
void storeDataIntoCheckpointFile()
Store selected matrices into the checkpoint file.
T & getMatrix(const MatrixIdx matrixIdx)
Get the matrix with a specific type from the container.
Positive Fourier shift in x.
Delay mask for many types sources.
Acoustic acceleration x.
Non uniform grid acoustic velocity on staggered grid y.
velocity shift for non-staggered velocity in y.
Negative shift for non-staggered velocity in x.
void loadDataFromInputFile()
Load all marked matrices from the input HDF5 file.
velocity shift for non-staggered velocity in z.
dt / initial velocity on staggered grid x.
PML on staggered grid y.
Negative Fourier shift in x.
Velocity z on staggered grid.
Velocity y on staggered grid.
Absorbing coefficient Eau.
size_t size() const
Get the number of matrices in the container.
Temporary matrix for fft shift.
Temporary matrix for 1D fft in x.
A structure storing details about the matrix.
Definition: MatrixRecord.h:47
The header file of the common ancestor of all matrix classes. A pure abstract class.
void addMatrices()
Populate the container based on the simulation type.