kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
FftwComplexMatrix.h
Go to the documentation of this file.
1 /**
2  * @file FftwComplexMatrix.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 class that implements 3D FFT using the FFTW interface
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 09 August 2011, 13:10 (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 #ifndef FFTW_COMPLEX_MATRIX_H
33 #define FFTW_COMPLEX_MATRIX_H
34 
35 
36 #include <fftw3.h>
37 
39 
40 /**
41  * @class FftwComplexMatrix
42  * @brief Class implementing 3D and 1D Real-To-Complex and Complex-To-Real transforms using FFTW interface.
43  * @details Class implementing 3D and 1D Real-To-Complex and Complex-To-Real transforms using FFTW interface.
44  *
45  */
47 {
48  public:
49  /// Default constructor not allowed for public
50  FftwComplexMatrix() = delete;
51  /**
52  * @brief Constructor, inherited from ComplexMatrix.
53  * @param [in] dimensionSizes - Dimension sizes of the matrix.
54  */
55  FftwComplexMatrix(const DimensionSizes& dimensionSizes);
56  /// Copy constructor not allowed for public.
57  FftwComplexMatrix(const FftwComplexMatrix& src) = delete;
58 
59  /// Destructor.
60  virtual ~FftwComplexMatrix();
61 
62  /// Operator = not allowed for public.
64 
65 
66  /**
67  * @brief Create FFTW plan for 3D Real-to-Complex.
68  * @param [in] inMatrix - Input matrix serving as scratch place for planning.
69  * @throw std::runtime_error - If the plan can't be created.
70  *
71  * @warning Unless FFTW_ESTIMATE flag is specified, the content of the inMatrix is destroyed!
72  */
73  void createR2CFftPlan3D(RealMatrix& inMatrix);
74  /**
75  * @brief Create FFTW plan for 3D Complex-to-Real.
76  * @param [in] outMatrix - Output matrix serving as scratch place for planning.
77  * @throw std::runtime_error - If the plan can't be created.
78  *
79  * @warning Unless FFTW_ESTIMATE flag is specified, the content of the outMatrix is destroyed!
80  */
81  void createC2RFftPlan3D(RealMatrix& outMatrix);
82 
83  /**
84  * @brief Create an FFTW plan for 1D Real-to-Complex in the x dimension.
85  *
86  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build! \n
87  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
88  *
89  * @param [in,out] inMatrix - RealMatrix of which to create the plan.
90  * @throw std::runtime_error - If the plan can't be created.
91  *
92  * @warning Unless FFTW_ESTIMATE flag is specified, the content of the inMatrix is destroyed!
93  */
94  void createR2CFftPlan1DX(RealMatrix& inMatrix);
95  /**
96  * @brief Create an FFTW plan for 1D Real-to-Complex in the y dimension.
97  *
98  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build! \n
99  * The FFTW version processes the whole matrix at one while the MKL slab by slab
100  *
101  * @param [in,out] inMatrix - RealMatrix of which to create the plan.
102  * @throw std::runtime_error - If the plan can't be created.
103  *
104  * @warning Unless FFTW_ESTIMATE flag is specified, the content of the inMatrix is destroyed!
105  * @warning The FFTW matrix must be able to store 2 * (nx * (ny /2 + 1) * nz) elements - possibly more than
106  * reduced dims!
107  */
108  void createR2CFftPlan1DY(RealMatrix& inMatrix);
109  /**
110  * @brief Create an FFTW plan for 1D Real-to-Complex in the z dimension.
111  *
112  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build! \n
113  * The FFTW version processes the whole matrix at one while the MKL slab by slab
114  *
115  * @param [in,out] inMatrix - RealMatrix of which to create the plan.
116  * @throw std::runtime_error - If the plan can't be created.
117  *
118  * @warning Unless FFTW_ESTIMATE flag is specified, the content of the inMatrix is destroyed!
119  * @warning The FFTW matrix must be able to store 2 * (nx * by * (nz / 2 + 1)) elements - possibly more than
120  * reduced dims!
121  */
122  void createR2CFftPlan1DZ(RealMatrix& inMatrix);
123 
124  /**
125  * @brief Create FFTW plan for Complex-to-Real in the x dimension.
126  *
127  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build! \n
128  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
129  *
130  * @param [in, out] outMatrix - RealMatrix of which to create the plan.
131  * @throw std::runtime_error - If the plan can't be created.
132  *
133  * @warning Unless FFTW_ESTIMATE flag is specified, the content of the outMatrix is destroyed!
134  */
135  void createC2RFftPlan1DX(RealMatrix& outMatrix);
136  /**
137  * @brief Create FFTW plan for Complex-to-Real in the y dimension.
138  *
139  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build! \n
140  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
141  *
142  * @param [in, out] outMatrix - RealMatrix of which to create the plan.
143  * @throw std::runtime_error - If the plan can't be created.
144  *
145  * @warning Unless FFTW_ESTIMATE flag is specified, the content of the outMatrix is destroyed!
146  */
147  void createC2RFftPlan1DY(RealMatrix& outMatrix);
148  /**
149  * @brief Create FFTW plan for Complex-to-Real in the z dimension.
150  *
151  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build! \n
152  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
153  *
154  * @param [in, out] outMatrix - RealMatrix of which to create the plan.
155  * @throw std::runtime_error - If the plan can't be created.
156  *
157  * @warning Unless FFTW_ESTIMATE flag is specified, the content of the outMatrix is destroyed!
158  */
159  void createC2RFftPlan1DZ(RealMatrix& outMatrix);
160 
161 
162 
163  /**
164  * @brief Compute forward out-of-place 3D Real-to-Complex FFT.
165  *
166  * @param [in] inMatrix - Input data for the forward FFT.
167  * @throw std::runtime_error - If the plan is not valid.
168  */
169  void computeR2CFft3D(RealMatrix& inMatrix);
170  /**
171  * @brief Compute forward out-of-place 3D Complex-to-Real FFT.
172  *
173  * @param [out] outMatrix - Output of the inverse FFT.
174  * @throw std::runtime_error - If the plan is not valid.
175  */
176  void computeC2RFft3D(RealMatrix& outMatrix);
177 
178  /**
179  * @brief Compute 1D out-of-place Real-to-Complex FFT in the x dimension.
180  *
181  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build!
182  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
183  *
184  * @param [in] inMatrix - Input matrix
185  * @throw std::runtime_error - If the plan is not valid.
186  */
187  void computeR2CFft1DX(RealMatrix& inMatrix);
188  /**
189  * @brief Compute 1D out-of-place Real-to-Complex FFT in the y dimension.
190  *
191  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build!
192  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
193  *
194  * @param [in] inMatrix - Input matrix
195  * @throw std::runtime_error - If the plan is not valid.
196  */
197  void computeR2CFft1DY(RealMatrix& inMatrix);
198  /**
199  * @brief Compute 1D out-of-place Real-to-Complex FFT in the z dimension.
200  *
201  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build!
202  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
203  *
204  * @param [in] inMatrix - Input matrix
205  * @throw std::runtime_error - If the plan is not valid.
206  */
207  void computeR2CFft1DZ(RealMatrix& inMatrix);
208 
209  /**
210  * @brief Compute 1D out-of-place Complex-to-Real FFT in the x dimension.
211  *
212  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build!
213  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
214  *
215  * @param [out] outMatrix - Output matrix
216  * @throw std::runtime_error - If the plan is not valid.
217  */
218  void computeC2RFft1DX(RealMatrix& outMatrix);
219  /**
220  * @brief Compute 1D out-of-place Complex-to-Real FFT in the y dimension.
221  *
222  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build!
223  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
224  *
225  * @param [out] outMatrix - Output matrix
226  * @throw std::runtime_error - If the plan is not valid.
227  */
228  void computeC2RFft1DY(RealMatrix& outMatrix);
229  /**
230  * @brief Compute 1D out-of-place Complex-to-Real FFT in the z dimension.
231  *
232  * There are two versions of this routine for GCC+FFTW and ICPC + MKL, otherwise it will not build!
233  * The FFTW version processes the whole matrix at one while the MKL slab by slab.
234  *
235  * @param [out] outMatrix Output matrix
236  * @throw std::runtime_error - If the plan is not valid.
237  */
238  void computeC2RFft1DZ(RealMatrix& outMatrix);
239 
240  /**
241  * @brief Export wisdom to the file.
242  * @warning This routine is supported only while compiling with the GNU C++ compiler.
243  */
244  static void exportWisdom();
245  /**
246  * @brief Import wisdom from the file.
247  * @warning This routine is supported only while compiling with the GNU C++ compiler.
248  */
249  static void importWisdom();
250  /// Destroy wisdom in the file (delete it).
251  static void deleteStoredWisdom();
252 
253 protected:
254 
255  /**
256  * Get Wisdom file name (derive it form the checkpoint filename).
257  * @return the filename for wisdom.
258  */
259  static std::string getWisdomFileName();
260 
261  /// Allocate memory for the FFTW matrix.
262  virtual void allocateMemory();
263  /// Free memory of the FFTW matrix.
264  virtual void freeMemory();
265 
266  /// FFTW plan flag.
267  static const unsigned kFftMeasureFlag = FFTW_MEASURE;
268  /// The file extension for FFTW wisdom.
269  static const std::string kFftWisdomFileExtension;// = "FFTW_Wisdom";
270 
271  /// FFTW plan for the 3D Real-to-Complex transform.
272  fftwf_plan mR2CFftPlan3D;
273  /// FFTW plan for the 3D Complex-to-Real transform.
274  fftwf_plan mC2RFftPlan3D;
275 
276  /// FFTW plan for the 1D Real-to-Complex transform in the x dimension.
277  fftwf_plan mR2CFftPlan1DX;
278  /// FFTW plan for the 3D Real-to-Complex transform in the y dimension.
279  fftwf_plan mR2CFftPlan1DY;
280  /// FFTW plan for the 3D Real-to-Complex transform in the z dimension.
281  fftwf_plan mR2CFftPlan1DZ;
282 
283  /// FFTW plan for the 3D Complex-to-Real transform in the x dimension.
284  fftwf_plan mC2RFftPlan1DX;
285  /// FFTW plan for the 3D Complex-to-Real transform in the y dimension.
286  fftwf_plan mC2RFftPlan1DY;
287  /// FFTW plan for the 3Z Complex-to-Real transform in the z dimension.
288  fftwf_plan mC2RFftPlan1DZ;
289 
290 private:
291 
292 };// end of FftwComplexMatrix
293 //----------------------------------------------------------------------------------------------------------------------
294 #endif /* FFTW_COMPLEX_MATRIX_H */
The class for real matrices.
Definition: RealMatrix.h:47
void createC2RFftPlan1DY(RealMatrix &outMatrix)
Create FFTW plan for Complex-to-Real in the y dimension.
void createC2RFftPlan3D(RealMatrix &outMatrix)
Create FFTW plan for 3D Complex-to-Real.
Class implementing 3D and 1D Real-To-Complex and Complex-To-Real transforms using FFTW interface...
void computeC2RFft1DX(RealMatrix &outMatrix)
Compute 1D out-of-place Complex-to-Real FFT in the x dimension.
virtual ~FftwComplexMatrix()
Destructor.
static const unsigned kFftMeasureFlag
FFTW plan flag.
void createC2RFftPlan1DX(RealMatrix &outMatrix)
Create FFTW plan for Complex-to-Real in the x dimension.
fftwf_plan mC2RFftPlan1DY
FFTW plan for the 3D Complex-to-Real transform in the y dimension.
fftwf_plan mC2RFftPlan1DZ
FFTW plan for the 3Z Complex-to-Real transform in the z dimension.
void computeC2RFft1DZ(RealMatrix &outMatrix)
Compute 1D out-of-place Complex-to-Real FFT in the z dimension.
fftwf_plan mR2CFftPlan1DY
FFTW plan for the 3D Real-to-Complex transform in the y dimension.
fftwf_plan mC2RFftPlan1DX
FFTW plan for the 3D Complex-to-Real transform in the x dimension.
void createR2CFftPlan1DY(RealMatrix &inMatrix)
Create an FFTW plan for 1D Real-to-Complex in the y dimension.
fftwf_plan mC2RFftPlan3D
FFTW plan for the 3D Complex-to-Real transform.
static void exportWisdom()
Export wisdom to the file.
void computeC2RFft3D(RealMatrix &outMatrix)
Compute forward out-of-place 3D Complex-to-Real FFT.
fftwf_plan mR2CFftPlan1DX
FFTW plan for the 1D Real-to-Complex transform in the x dimension.
static void deleteStoredWisdom()
Destroy wisdom in the file (delete it).
virtual void freeMemory()
Free memory of the FFTW matrix.
void computeR2CFft3D(RealMatrix &inMatrix)
Compute forward out-of-place 3D Real-to-Complex FFT.
FftwComplexMatrix & operator=(const FftwComplexMatrix &src)
Operator = not allowed for public.
The class for complex matrices.
Definition: ComplexMatrix.h:51
fftwf_plan mR2CFftPlan3D
FFTW plan for the 3D Real-to-Complex transform.
fftwf_plan mR2CFftPlan1DZ
FFTW plan for the 3D Real-to-Complex transform in the z dimension.
Structure with 4D dimension sizes (3 in space and 1 in time).
void createC2RFftPlan1DZ(RealMatrix &outMatrix)
Create FFTW plan for Complex-to-Real in the z dimension.
The header file with the class for complex matrices.
static std::string getWisdomFileName()
void computeR2CFft1DX(RealMatrix &inMatrix)
Compute 1D out-of-place Real-to-Complex FFT in the x dimension.
void computeR2CFft1DZ(RealMatrix &inMatrix)
Compute 1D out-of-place Real-to-Complex FFT in the z dimension.
void createR2CFftPlan1DX(RealMatrix &inMatrix)
Create an FFTW plan for 1D Real-to-Complex in the x dimension.
void computeC2RFft1DY(RealMatrix &outMatrix)
Compute 1D out-of-place Complex-to-Real FFT in the y dimension.
static void importWisdom()
Import wisdom from the file.
void createR2CFftPlan3D(RealMatrix &inMatrix)
Create FFTW plan for 3D Real-to-Complex.
static const std::string kFftWisdomFileExtension
The file extension for FFTW wisdom.
FftwComplexMatrix()=delete
Default constructor not allowed for public.
void createR2CFftPlan1DZ(RealMatrix &inMatrix)
Create an FFTW plan for 1D Real-to-Complex in the z dimension.
virtual void allocateMemory()
Allocate memory for the FFTW matrix.
void computeR2CFft1DY(RealMatrix &inMatrix)
Compute 1D out-of-place Real-to-Complex FFT in the y dimension.