kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
KSpaceFirstOrder3DSolver.h
Go to the documentation of this file.
1 /**
2  * @file KSpaceFirstOrder3DSolver.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 main class of the project responsible for the entire simulation.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 12 July 2012, 10:27 (created)\n
14  * 04 September 2017, 10:58 (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 KSPACE_FIRST_ORDER_3D_SOLVER_H
33 #define KSPACE_FIRST_ORDER_3D_SOLVER_H
34 
35 //#include <fftw3.h>
36 
37 #include <Parameters/Parameters.h>
38 
41 
47 
48 #include <Utils/TimeMeasure.h>
49 
50 /**
51  * @class KSpaceFirstOrder3DSolver
52  * @brief Class responsible for running the k-space first order 3D method.
53  * @details Class responsible for running the k-space first order 3D method. This class maintain
54  * the whole k-wave (implements the time loop).
55  *
56  */
58 {
59  public:
60  /// Constructor.
62  /// Copy constructor not allowed for public.
64  /// Destructor.
65  virtual ~KSpaceFirstOrder3DSolver();
66  /// operator= not allowed for public.
68 
69  /// Memory allocation.
70  virtual void allocateMemory();
71  /// Memory deallocation.
72  virtual void freeMemory();
73 
74  /**
75  * @brief Load simulation data.
76  *
77  * If checkpointing is enabled, this may include reading data from checkpoint and output file.
78  */
79  virtual void loadInputData();
80  /**
81  * @brief This method computes k-space First Order 3D simulation.
82  *
83  * This method computes k-space First Order 3D simulation. It launches calculation on a given
84  * dataset going through FFT initialization, pre-processing, main loop and post-processing phases.
85  */
86  virtual void compute();
87 
88  /**
89  * @brief Get memory usage in MB on the host side.
90  * @return Memory consumed on the host side in MB.
91  */
92  virtual size_t getMemoryUsage() const;
93 
94  /**
95  * @brief Get code name - release code version.
96  * @return Release code version.
97  */
98  std::string getCodeName() const;
99 
100  /// Print the code name and license.
101  void printFullCodeNameAndLicense() const;
102 
103  /**
104  * @brief Set processor affinity.
105  * @warning This may not work on some OS, it should be done by user before launching the code. Moreover, the user
106  * may want to change the thread placement, e.g. on NUMA systems. This the routine was disabled in ver 2.16
107  */
108  void setProcessorAffinity();
109 
110  /**
111  * @brief Get total simulation time.
112  * @return Total simulation time in seconds.
113  */
114  double getTotalTime() const { return mTotalTime.getElapsedTime(); };
115  /**
116  * @brief Get pre-processing time.
117  * @return Pre-processing time in seconds.
118  */
120  /**
121  * @brief Get data load time.
122  * @return Time to load data in seconds.
123  */
124  double getDataLoadTime() const { return mDataLoadTime.getElapsedTime(); };
125  /**
126  * @brief Get simulation time (time loop).
127  * @return Time to execute the simulation in seconds.
128  */
129  double getSimulationTime() const { return mSimulationTime.getElapsedTime(); };
130  /**
131  * @brief Get post-processing time.
132  * @return Time to postprocess simulation data in seconds.
133  */
135 
136  /**
137  * @brief Get total simulation time accumulated over all legs.
138  * @return Total execution time in seconds accumulated over all legs.
139  */
141  /**
142  * @brief Get pre-processing time accumulated over all legs.
143  * @return Time to load data in seconds accumulated over all legs.
144  */
146  /**
147  * @brief Get simulation time (time loop) accumulated over all legs.
148  * @return Time to execute the simulation in seconds accumulated over all legs.
149  */
151  /**
152  * @brief Get simulation time (time loop) accumulated over all legs.
153  * @return Time to execute the simulation in seconds accumulated over all legs.
154  */
156  /**
157  * @brief Get post-processing time accumulated over all legs.
158  * @return Time to post-processing simulation data in seconds accumulated over all legs.
159  */
161 
162  protected:
163 
164  /// Initialize FFTW plans.
165  void InitializeFftwPlans();
166 
167  /**
168  * @brief Compute pre-processing phase.
169  *
170  * Initialize all indices, pre-compute constants such as c^2, rho0Sgx * dt and create kappa,
171  * absorbEta, absorbTau, absorbNabla1, absorbNabla2 matrices.
172  *
173  */
174  void preProcessing();
175  /// Compute the main time loop of the kspaceFirstOrder3D.
176  void computeMainLoop();
177  /// Post processing, and closing the output streams.
178  void postProcessing();
179 
180  /// Store sensor data.
181  void storeSensorData();
182  /// Write statistics and header into the output file.
183  void writeOutputDataInfo();
184  /// Save checkpoint data and flush aggregated outputs into the output file.
185  void saveCheckpointData();
186 
187 
188  /// Compute new values of acoustic velocity.
189  void computeVelocity();
190  /// Compute new values of acoustic velocity gradients.
192 
193 
194  /// Compute new values of acoustic density for nonlinear case.
195  void computeDensityNonliner();
196  /// Compute new values of acoustic density for linear case.
197  void computeDensityLinear();
198 
199  /// Compute acoustic pressure for nonlinear case.
201  /// Compute acoustic pressure for linear case.
202  void computePressureLinear();
203 
204 
205  /// Add in all velocity sources.
206  void addVelocitySource();
207  /**
208  * @brief Add in velocity source terms.
209  * @param [in] velocityMatrix - Velocity matrix to add the source in.
210  * @param [in] velocitySourceInput - Source input to add.
211  * @param [in] velocitySourceIndex - Source geometry index matrix.
212  */
213  void computeVelocitySourceTerm(RealMatrix& velocityMatrix,
214  const RealMatrix& velocitySourceInput,
215  const IndexMatrix& velocitySourceIndex);
216  /// Add in pressure source.
217  void addPressureSource();
218  /// Calculate initial pressure source.
220  /// Add transducer data source to velocity x component.
221  void addTransducerSource();
222 
223 
224  /// Generate kappa matrix for lossless media.
225  void generateKappa();
226  /// Generate kappa matrix, absorbNabla1, absorbNabla2 for absorbing medium.
227  void generateKappaAndNablas();
228  /// Generate absorbTau, absorbEta for heterogenous medium.
229  void generateTauAndEta();
230  /// Calculate dt ./ rho0 for nonuniform grids.
231  void generateInitialDenisty();
232  /// Calculate square of velocity
233  void computeC2();
234 
235  /**
236  * @brief Compute velocity for the initial pressure problem, heterogeneous medium, uniform grid.
237  *
238  * <b> Matlab code: </b>
239  *
240  * \verbatim
241  ux_sgx = dt ./ rho0_sgx .* ifft(ux_sgx).
242  uy_sgy = dt ./ rho0_sgy .* ifft(uy_sgy).
243  uz_sgz = dt ./ rho0_sgz .* ifft(uz_sgz).
244  \endverbatim
245  */
247 
248  /**
249  * @brief Compute velocity for the initial pressure problem, homogeneous medium, uniform grid.
250  *
251  * <b> Matlab code: </b>
252  *
253  * \verbatim
254  ux_sgx = dt ./ rho0_sgx .* ifft(ux_sgx).
255  uy_sgy = dt ./ rho0_sgy .* ifft(uy_sgy).
256  uz_sgz = dt ./ rho0_sgz .* ifft(uz_sgz).
257  \endverbatim
258  *
259  */
261 
262  /**
263  * @brief Compute acoustic velocity for initial pressure problem, homogenous medium, nonuniform grid.
264  *
265  * <b> Matlab code: </b>
266  *
267  * \verbatim
268  ux_sgx = dt ./ rho0_sgx .* dxudxn_sgx .* ifft(ux_sgx)
269  uy_sgy = dt ./ rho0_sgy .* dyudxn_sgy .* ifft(uy_sgy)
270  uz_sgz = dt ./ rho0_sgz .* dzudzn_sgz .* ifft(uz_sgz)
271  \endverbatim
272  *
273  */
275 
276  /**
277  * @brief Compute acoustic velocity for heterogeneous medium and a uniform grid.
278  *
279  * <b> Matlab code: </b>
280  *
281  * \verbatim
282  ux_sgx = bsxfun(@times, pml_x_sgx, bsxfun(@times, pml_x_sgx, ux_sgx) - dt .* rho0_sgx_inv .* real(ifftX)
283  uy_sgy = bsxfun(@times, pml_y_sgy, bsxfun(@times, pml_y_sgy, uy_sgy) - dt .* rho0_sgy_inv .* real(ifftY)
284  uz_sgz = bsxfun(@times, pml_z_sgz, bsxfun(@times, pml_z_sgz, uz_sgz) - dt .* rho0_sgz_inv .* real(ifftZ)
285  \endverbatim
286  *
287  */
289 
290  /**
291  * @brief Compute acoustic velocity for homogeneous medium and a uniform grid.
292  *
293  * <b> Matlab code: </b>
294  *
295  * \verbatim
296  ux_sgx = bsxfun(@times, pml_x_sgx, bsxfun(@times, pml_x_sgx, ux_sgx) - dt .* rho0_sgx_inv .* real(ifftX)
297  uy_sgy = bsxfun(@times, pml_y_sgy, bsxfun(@times, pml_y_sgy, uy_sgy) - dt .* rho0_sgy_inv .* real(ifftY)
298  uz_sgz = bsxfun(@times, pml_z_sgz, bsxfun(@times, pml_z_sgz, uz_sgz) - dt .* rho0_sgz_inv .* real(ifftZ)
299  \endverbatim
300  *
301  */
303 
304  /**
305  * @brief Compute acoustic velocity for homogenous medium and nonuniform grid.
306  *
307  * <b> Matlab code: </b>
308  *
309  * \verbatim
310  ux_sgx = bsxfun(@times, pml_x_sgx, bsxfun(@times, pml_x_sgx, ux_sgx) ...
311  - dt .* rho0_sgx_inv .* dxudxnSgx.* real(ifftX))
312  uy_sgy = bsxfun(@times, pml_y_sgy, bsxfun(@times, pml_y_sgy, uy_sgy) ...
313  - dt .* rho0_sgy_inv .* dyudynSgy.* real(ifftY)
314  uz_sgz = bsxfun(@times, pml_z_sgz, bsxfun(@times, pml_z_sgz, uz_sgz)
315  - dt .* rho0_sgz_inv .* dzudznSgz.* real(ifftZ)
316  \endverbatim
317  */
319 
320 
321 
322  /// Compute part of the new velocity term - gradient of pressure.
324  /**
325  * @brief Calculate three temporary sums in the new pressure formula before taking the FFT,
326  * nonlinear absorbing case.
327  * @tparam bOnAScalarFlag - is nonlinearity homogenous?
328  * @tparam rho0ScalarFlag - is density homogeneous?
329  * @param [out] densitySum - rhoX + rhoY + rhoZ
330  * @param [out] nonlinearTerm - BOnA + densitySum ^2 / 2 * rho0
331  * @param [out] velocityGradientSum - rho0* (duxdx + duydy + duzdz)
332  */
333  template<bool bOnAScalarFlag, bool rho0ScalarFlag>
334  void computePressureTermsNonlinear(RealMatrix& densitySum,
335  RealMatrix& nonlinearTerm,
336  RealMatrix& velocityGradientSum);
337  /**
338  * @brief Calculate two temporary sums in the new pressure formula before taking the FFT,
339  * linear absorbing case.
340  * @param [out] densitySum - rhoxSgx + rhoySgy + rhozSgz
341  * @param [out] velocityGradientSum - rho0* (duxdx + duydy + duzdz)
342  */
343  void computePressureTermsLinear(RealMatrix& densitySum,
344  RealMatrix& velocityGradientSum);
345 
346  /**
347  * @brief Compute absorbing term with abosrbNabla1 and absorbNabla2.
348  *
349  * @param [in,out] fftPart1 - fftPart1 = absorbNabla1 .* fftPart1
350  * @param [in,out] fftPart2 - fftPart1 = absorbNabla1 .* fftPart2
351  */
353  FftwComplexMatrix& fftPart2);
354 
355  /**
356  * @brief Sum sub-terms to calculate new pressure, after FFTs, nonlinear case.
357  *
358  * @tparam c0ScalarFlag - is sound speed homogeneous?
359  * @tparam areTauAndEtaScalars - are absorbTau and absorbEeta scalars
360  * @param [in] absorbTauTerm - tau component
361  * @param [in] absorbEtaTerm - eta component of the pressure term
362  * @param [in] nonlinearTerm - rho0 * (duxdx + duydy + duzdz)
363  */
364  template<bool c0ScalarFlag, bool areTauAndEtaScalars>
365  void sumPressureTermsNonlinear(const RealMatrix& absorbTauTerm,
366  const RealMatrix& absorbEtaTerm,
367  const RealMatrix& nonlinearTerm);
368  /**
369  * @brief Sum sub-terms to calculate new pressure, after FFTs, linear case.
370  *
371  * @tparam c0ScalarFlag - is sound speed homogeneous?
372  * @tparam areTauAndEtaScalars - are absorbTau and absorbEeta homogeneous?
373  * @param [in] absorbTauTerm - tau component
374  * @param [in] absorbEtaTerm - eta component of the pressure term
375  * @param [in] densitySum - Sum of three components of density (rhoXSgx + rhoYSgy + rhoZSgx)
376  */
377  template<bool c0ScalarFlag, bool areTauAndEtaScalars>
378  void sumPressureTermsLinear(const RealMatrix& absorbTauTerm,
379  const RealMatrix& absorbEtaTerm,
380  const RealMatrix& densitySum);
381 
382  /**
383  * @brief Sum sub-terms for new pressure, linear lossless case.
384  * @tparam c0ScalarFlag - is sound speed homogeneous?
385  * @tparam nonlinearFlag - is nonlinearity homogeneous?
386  * @tparam rho0ScalarFlag - is density homogeneous?
387  */
388  template<bool c0ScalarFlag, bool nonlinearFlag, bool rho0ScalarFlag>
390  /// Sum sub-terms for new pressure, linear lossless case.
392 
393  /// compute shifted velocity for --u_non_staggered flag.
394  void computeShiftedVelocity();
395 
396  /// Print progress statistics.
397  void printStatistics();
398 
399  /**
400  * @brief Is time to checkpoint (save actual state on disk).
401  * @return true if it is time to interrupt the simulation and checkpoint.
402  */
403  bool isTimeToCheckpoint();
404  /**
405  * @brief Was the loop interrupted to checkpoint?
406  * @return true if the simulation has been interrupted.
407  */
408  bool isCheckpointInterruption() const;
409 
410  /**
411  * @brief Check the output file has the correct format and version.
412  * @throw ios::failure - If an error happens.
413  */
414  void checkOutputFile();
415  /**
416  * @brief Check the file type and the version of the checkpoint file.
417  * @throw ios::failure - If an error happens
418  */
419  void checkCheckpointFile();
420 
421  /// Reads the header of the output file and sets the cumulative elapsed time from the first log.
423 
424  /**
425  * @brief Compute 1D index using 3 spatial coordinates and the size of the matrix.
426  * @param [in] z - z coordinate
427  * @param [in] y - y coordinate
428  * @param [in] x - x coordinate
429  * @param [in] dimensionSizes - Size of the matrix.
430  * @return
431  */
432 
433  size_t get1DIndex(const size_t z,
434  const size_t y,
435  const size_t x,
436  const DimensionSizes& dimensionSizes);
437  //----------------------------------------------- Get matrices ---------------------------------------------------//
438  /**
439  * @brief Get the kappa matrix from the container.
440  * @return kappa matrix
441  */
443  {
445  };
446 
447  /**
448  * @brief Get the c^2 matrix from the container.
449  * @return c^2 matrix.
450  */
452  {
454  };
455 
456  /**
457  * @brief Get pressure matrix
458  * @return Pressure matrix
459  */
461  {
463  };
464 
465  //--------------------------------------------- Velocity matrices ------------------------------------------------//
466  /**
467  * @brief Get velocity matrix on staggered grid in x direction.
468  * @return Velocity matrix on staggered grid.
469  */
471  {
473  };
474  /**
475  * @brief Get velocity matrix on staggered grid in y direction.
476  * @return Velocity matrix on staggered grid.
477  */
479  {
481  };
482  /**
483  * @brief Get velocity matrix on staggered grid in z direction.
484  * @return Velocity matrix on staggered grid.
485  */
487  {
489  };
490 
491  /**
492  * @brief Get velocity shifted on normal grid in x direction.
493  * @return Unstaggeted velocity matrix.
494  */
496  {
498  };
499  /**
500  * @brief Get velocity shifted on normal grid in y direction.
501  * @return Unstaggered velocity matrix.
502  */
504  {
506  };
507  /**
508  * @brief Get velocity shifted on normal grid in z direction.
509  * @return Unstaggered velocity matrix.
510  */
512  {
514  };
515 
516  //----------------------------------------- Velocity gradient matrices -------------------------------------------//
517  /**
518  * @brief Get velocity gradient on in x direction.
519  * @return Velocity gradient matrix.
520  */
522  {
524  };
525  /**
526  * @brief Get velocity gradient on in y direction.
527  * @return Velocity gradient matrix.
528  */
530  {
532  };
533  /**
534  * @brief Get velocity gradient on in z direction.
535  * @return Velocity gradient matrix.
536  */
538  {
540  };
541 
542  //---------------------------------------------- Density matrices ------------------------------------------------//
543  /**
544  * @brief Get dt * rho0Sgx matrix (time step size * ambient velocity on staggered grid in x direction).
545  * @return Density matrix
546  */
548  {
550  };
551  /**
552  * @brief Get dt * rho0Sgy matrix (time step size * ambient velocity on staggered grid in y direction).
553  * @return Density matrix
554  */
556  {
558  };
559  /**
560  * @brief Get dt * rho0Sgz matrix (time step size * ambient velocity on staggered grid in z direction).
561  * @return Density matrix
562  */
564  {
566  };
567 
568  /**
569  * @brief Get density matrix in x direction.
570  * @return Density matrix.
571  */
573  {
575  };
576  /**
577  * @brief Get density matrix in y direction.
578  * @return Density matrix.
579  */
581  {
583  };
584  /**
585  * @brief Get density matrix in z direction.
586  * @return Density matrix.
587  */
589  {
591  };
592  /**
593  * @brief Get ambient density matrix.
594  * @return Density matrix.
595  */
597  {
599  };
600 
601  //----------------------------------------------- Shift matrices -------------------------------------------------//
602  /**
603  * @brief Get positive Fourier shift in x.
604  * @return Shift matrix.
605  */
607  {
609  };
610  /**
611  * @brief Get positive Fourier shift in y.
612  * @return Shift matrix.
613  */
615  {
617  };
618  /**
619  * @brief Get positive Fourier shift in z.
620  * @return Shift matrix.
621  */
623  {
625  };
626  /**
627  * @brief Get negative Fourier shift in x.
628  * @return Shift matrix.
629  */
631  {
633  };
634  /**
635  * @brief Get negative Fourier shift in y.
636  * @return Shift matrix.
637  */
639  {
641  };
642  /**
643  * @brief Get negative Fourier shift in z.
644  * @return shift matrix.
645  */
647  {
649  };
650 
651  /**
652  * @brief Get negative shift for non-staggered velocity in x.
653  * @return Shift matrix.
654  */
656  {
658  };
659  /**
660  * @brief Get negative shift for non-staggered velocity in y.
661  * @return Shift matrix.
662  */
664  {
666  };
667  /**
668  * @brief Get negative shift for non-staggered velocity in z.
669  * @return Shift matrix.
670  */
672  {
674  };
675 
676  //------------------------------------------------ PML matrices --------------------------------------------------//
677  /**
678  * @brief Get PML on staggered grid x.
679  * @return PML matrix.
680  */
682  {
684  };
685  /**
686  * @brief Get PML on staggered grid y.
687  * @return PML matrix.
688  */
690  {
692  };
693  /**
694  * @brief Get PML on staggered grid z.
695  * @return PML matrix.
696  */
698  {
700  };
701 
702  /**
703  * @brief Get PML in x.
704  * @return PML matrix.
705  */
707  {
709  };
710  /**
711  * @brief Get PML in y.
712  * @return PML matrix.
713  */
715  {
717  };
718  /**
719  * @brief Get PML in z.
720  * @return PML matrix.
721  */
723  {
725  };
726 
727  //------------------------------------------- Nonlinear grid matrices --------------------------------------------//
728  /**
729  * @brief Non uniform grid acoustic velocity in x.
730  * @return Velocity matrix.
731  */
733  {
735  };
736  /**
737  * @brief Non uniform grid acoustic velocity in y.
738  * @return Velocity matrix.
739  */
741  {
743  };
744  /**
745  * @brief Non uniform grid acoustic velocity in z.
746  * @return Velocity matrix.
747  */
749  {
751  };
752  /**
753  * @brief Non uniform grid acoustic velocity on staggered grid x.
754  * @return Velocity matrix.
755  */
757  {
759  };
760  /**
761  * @brief Non uniform grid acoustic velocity on staggered grid x.
762  * @return Velocity matrix.
763  */
765  {
767  };
768  /**
769  * @brief Non uniform grid acoustic velocity on staggered grid x.
770  * @return Velocity matrix.
771  */
773  {
775  };
776 
777  //-------------------------------------- Nonlinear and absorption matrices ---------------------------------------//
778  /**
779  * @brief Get B on A (nonlinear coefficient).
780  * @return Nonlinear coefficient.
781  */
783  {
785  };
786  /**
787  * @brief Get absorbing coefficient Tau.
788  * @return Absorbing coefficient.
789  */
791  {
793  };
794  /**
795  * @brief Get absorbing coefficient Eta.
796  * @return Absorbing coefficient.
797  */
799  {
801  };
802 
803  /**
804  * @brief Get absorbing coefficient Nabla1.
805  * @return Absorbing coefficient.
806  */
808  {
810  };
811  /**
812  * @brief Get absorbing coefficient Nabla2.
813  * @return Absorbing coefficient.
814  */
816  {
818  };
819 
820  //----------------------------------------------- Index matrices -------------------------------------------------//
821  /**
822  * @brief Get linear sensor mask (spatial geometry of the sensor).
823  * @return Sensor mask data.
824  */
826  {
828  };
829  /**
830  * @brief Get cuboid corners sensor mask. (Spatial geometry of multiple sensors).
831  * @return Sensor mask data.
832  */
834  {
836  };
837  /**
838  * @brief Get velocity source geometry data.
839  * @return Source geometry indices
840  */
842  {
844  };
845  /**
846  * @brief Get pressure source geometry data.
847  * @return Source geometry indices
848  */
850  {
852  };
853  /**
854  * @brief Get delay mask for many types sources
855  * @return delay mask.
856  */
858  {
860  }
861 
862  //-------------------------------------------------- Sources ----------------------------------------------------//
863  /**
864  * @brief Get transducer source input data (signal).
865  * @return Transducer source input data.
866  */
868  {
870  };
871  /**
872  * @brief Get pressure source input data (signal).
873  * @return Pressure source input data.
874  */
876  {
878  };
879  /**
880  * @brief Get initial pressure source input data (whole matrix).
881  * @return Initial pressure source input data.
882  */
884  {
886  };
887 
888  /**
889  * @brief Get Velocity source input data in x direction.
890  * @return Velocity source input data.
891  */
893  {
895  };
896  /**
897  * @brief Get Velocity source input data in y direction.
898  * @return Velocity source input data.
899  */
901  {
903  };
904  /**
905  * @brief Get Velocity source input data in z direction.
906  * @return Velocity source input data.
907  */
909  {
911  };
912 
913 
914  //--------------------------------------------- Temporary matrices -----------------------------------------------//
915  /**
916  * @brief Get first real 3D temporary matrix.
917  * @return Temporary real 3D matrix.
918  */
920  {
922  };
923  /**
924  * @brief Get second real 3D temporary matrix.
925  * @return Temporary real 3D matrix.
926  */
928  {
930  };
931  /**
932  * @brief Get third real 3D temporary matrix.
933  * @return Temporary real 3D matrix.
934  */
936  {
938  };
939 
940  /**
941  * @brief Get temporary matrix for 1D fft in x.
942  * @return Temporary complex 3D matrix.
943  */
945  {
947  };
948  /**
949  * @brief Get temporary matrix for 1D fft in y.
950  * @return Temporary complex 3D matrix.
951  */
953  {
955  };
956  /**
957  * @brief Get temporary matrix for 1D fft in z.
958  * @return Temporary complex 3D matrix.
959  */
961  {
963  };
964  /**
965  * @brief Get temporary matrix for fft shift.
966  * @return Temporary complex 3D matrix.
967  */
969  {
971  };
972 
973  private:
974 
975  /// Matrix container with all the matrix classes.
977  /// Output stream container.
979  /// Global parameters of the simulation.
981 
982  /// Percentage of the simulation done.
983  size_t mActPercent;
984 
985  /// Total time of the simulation.
987  /// Pre-processing time of the simulation.
989  /// Data load time of the simulation.
991  /// Simulation time of the simulation.
993  /// Post-processing time of the simulation.
995  /// Iteration time of the simulation.
997 
998 };// end of KSpaceFirstOrder3DSolver
999 //----------------------------------------------------------------------------------------------------------------------
1000 
1001 #endif /* KSPACE_FIRST_ORDER_3D_SOLVER_H */
1002 
ComplexMatrix & getDdyKShiftNeg()
Get negative Fourier shift in y.
IndexMatrix & getDelayMask()
Get delay mask for many types sources.
RealMatrix & getVelocityZSourceInput()
Get Velocity source input data in z direction.
ComplexMatrix & getDdyKShiftPos()
Get positive Fourier shift in y.
The class for real matrices.
Definition: RealMatrix.h:47
void generateKappa()
Generate kappa matrix for lossless media.
bool isCheckpointInterruption() const
Was the loop interrupted to checkpoint?
RealMatrix & getDuydy()
Get velocity gradient on in y direction.
void sumPressureTermsLinear(const RealMatrix &absorbTauTerm, const RealMatrix &absorbEtaTerm, const RealMatrix &densitySum)
Sum sub-terms to calculate new pressure, after FFTs, linear case.
RealMatrix & getRhoX()
Get density matrix in x direction.
void computePressureTermsLinear(RealMatrix &densitySum, RealMatrix &velocityGradientSum)
Calculate two temporary sums in the new pressure formula before taking the FFT, linear absorbing case...
RealMatrix & getAbsorbNabla2()
Get absorbing coefficient Nabla2.
velocity shift for non-staggered velocity in x.
void addTransducerSource()
Add transducer data source to velocity x component.
double getDataLoadTime() const
Get data load time.
double getCumulatedSimulationTime() const
Get simulation time (time loop) accumulated over all legs.
RealMatrix & getPmlX()
Get PML in x.
RealMatrix & getUzSgz()
Get velocity matrix on staggered grid in z direction.
RealMatrix & getDtRho0Sgz()
Get dt * rho0Sgz matrix (time step size * ambient velocity on staggered grid in z direction)...
Class implementing 3D and 1D Real-To-Complex and Complex-To-Real transforms using FFTW interface...
void saveCheckpointData()
Save checkpoint data and flush aggregated outputs into the output file.
Non uniform grid acoustic velocity in y.
Class implementing the matrix container.
RealMatrix & getRho0()
Get ambient density matrix.
RealMatrix & getAbsorbEta()
Get absorbing coefficient Eta.
Temporary matrix for 1D fft in y.
Non uniform grid acoustic velocity on staggered grid x.
ComplexMatrix & getDdzKShiftPos()
Get positive Fourier shift in z.
TimeMeasure mTotalTime
Total time of the simulation.
RealMatrix & getRhoZ()
Get density matrix in z direction.
void computeVelocityHomogeneousUniform()
Compute acoustic velocity for homogeneous medium and a uniform grid.
Temporary matrix for 1D fft in z.
RealMatrix & getUyShifted()
Get velocity shifted on normal grid in y direction.
MatrixContainer mMatrixContainer
Matrix container with all the matrix classes.
TimeMeasure mPostProcessingTime
Post-processing time of the simulation.
RealMatrix & getTransducerSourceInput()
Get transducer source input data (signal).
void generateKappaAndNablas()
Generate kappa matrix, absorbNabla1, absorbNabla2 for absorbing medium.
double getSimulationTime() const
Get simulation time (time loop).
RealMatrix & getAbsorbNabla1()
Get absorbing coefficient Nabla1.
double getTotalTime() const
Get total simulation time.
double getCumulatedPreProcessingTime() const
Get pre-processing time accumulated over all legs.
TimeMeasure mPreProcessingTime
Pre-processing time of the simulation.
The header file containing the class for real matrices.
void computeAbsorbtionTerm(FftwComplexMatrix &fftPart1, FftwComplexMatrix &fftPart2)
Compute absorbing term with abosrbNabla1 and absorbNabla2.
virtual void loadInputData()
Load simulation data.
TimeMeasure mIterationTime
Iteration time of the simulation.
RealMatrix & getTemp2Real3D()
Get second real 3D temporary matrix.
Class storing all parameters of the simulation.
Definition: Parameters.h:50
void computeInitialVelocityHeterogeneous()
Compute velocity for the initial pressure problem, heterogeneous medium, uniform grid.
void postProcessing()
Post processing, and closing the output streams.
void addInitialPressureSource()
Calculate initial pressure source.
RealMatrix & getAbsorbTau()
Get absorbing coefficient Tau.
Non uniform grid acoustic velocity in z.
void computePressureNonlinear()
Compute acoustic pressure for nonlinear case.
virtual void compute()
This method computes k-space First Order 3D simulation.
double getElapsedTime() const
Get elapsed time.
Definition: TimeMeasure.h:119
RealMatrix & getTemp3Real3D()
Get third real 3D temporary matrix.
Velocity x on staggered grid.
Class measuring elapsed time.
Definition: TimeMeasure.h:48
IndexMatrix & getSensorMaskIndex()
Get linear sensor mask (spatial geometry of the sensor).
void storeSensorData()
Store sensor data.
double getCumulatedDataLoadTime() const
Get simulation time (time loop) accumulated over all legs.
std::string getCodeName() const
Get code name - release code version.
PML on staggered grid x.
size_t mActPercent
Percentage of the simulation done.
RealMatrix & getBOnA()
Get B on A (nonlinear coefficient).
RealMatrix & getUzShifted()
Get velocity shifted on normal grid in z direction.
double getPreProcessingTime() const
Get pre-processing time.
FftwComplexMatrix & getTempFftwZ()
Get temporary matrix for 1D fft in z.
void computeVelocityHomogeneousNonuniform()
Compute acoustic velocity for homogenous medium and nonuniform grid.
The header file containing the parameters of the simulation.
RealMatrix & getDtRho0Sgx()
Get dt * rho0Sgx matrix (time step size * ambient velocity on staggered grid in x direction)...
Absorbing coefficient Nabla 1.
Absorbing coefficient Tau.
double getElapsedTimeOverAllLegs() const
Get cumulated elapsed time over all simulation legs.
Definition: TimeMeasure.h:129
Negative shift for non-staggered velocity in z.
RealMatrix & getC2()
Get the c^2 matrix from the container.
virtual void freeMemory()
Memory deallocation.
void computeDensityLinear()
Compute new values of acoustic density for linear case.
Negative Fourier shift in z.
double getCumulatedTotalTime() const
Get total simulation time accumulated over all legs.
The header file containing the class measuring elapsed time.
Nonlinear coefficient.
size_t get1DIndex(const size_t z, const size_t y, const size_t x, const DimensionSizes &dimensionSizes)
Compute 1D index using 3 spatial coordinates and the size of the matrix.
RealMatrix & getUxSgx()
Get velocity matrix on staggered grid in x direction.
void checkCheckpointFile()
Check the file type and the version of the checkpoint file.
RealMatrix & getPmlYSgy()
Get PML on staggered grid y.
void computeVelocitySourceTerm(RealMatrix &velocityMatrix, const RealMatrix &velocitySourceInput, const IndexMatrix &velocitySourceIndex)
Add in velocity source terms.
Negative shift for non-staggered velocity in y.
RealMatrix & getPmlZSgz()
Get PML on staggered grid z.
FftwComplexMatrix & getTempFftwX()
Get temporary matrix for 1D fft in x.
KSpaceFirstOrder3DSolver & operator=(const KSpaceFirstOrder3DSolver &)=delete
operator= not allowed for public.
void computeVelocityGradient()
Compute new values of acoustic velocity gradients.
RealMatrix & getP()
Get pressure matrix.
Acoustic acceleration z.
FftwComplexMatrix & getTempFftwY()
Get temporary matrix for 1D fft in y.
Absorbing coefficient Nabla 2.
The class for complex matrices.
Definition: ComplexMatrix.h:51
void addVelocitySource()
Add in all velocity sources.
void computeC2()
Calculate square of velocity.
dt / initial velocity on staggered grid z.
RealMatrix & getDuxdx()
Get velocity gradient on in x direction.
ComplexMatrix & getYShiftNegR()
Get negative shift for non-staggered velocity in y.
TimeMeasure mSimulationTime
Simulation time of the simulation.
Negative Fourier shift in y.
Positive Fourier shift in y.
void computePressureLinear()
Compute acoustic pressure for linear case.
The header file containing the class for 64b integer matrices.
Acoustic acceleration y.
OutputStreamContainer mOutputStreamContainer
Output stream container.
ComplexMatrix & getDdxKShiftNeg()
Get negative Fourier shift in x.
RealMatrix & getPmlZ()
Get PML in z.
Structure with 4D dimension sizes (3 in space and 1 in time).
Non uniform grid acoustic velocity on staggered grid z.
virtual ~KSpaceFirstOrder3DSolver()
Destructor.
RealMatrix & getDxudxn()
Non uniform grid acoustic velocity in x.
Positive Fourier shift in z.
Class responsible for running the k-space first order 3D method.
IndexMatrix & getSensorMaskCorners()
Get cuboid corners sensor mask. (Spatial geometry of multiple sensors).
dt / initial velocity on staggered grid y.
double getPostProcessingTime() const
Get post-processing time.
TimeMeasure mDataLoadTime
Data load time of the simulation.
A container for output streams.
RealMatrix & getKappa()
Get the kappa matrix from the container.
Non uniform grid acoustic velocity in x.
The header file with the class for complex matrices.
void checkOutputFile()
Check the output file has the correct format and version.
void computeDensityNonliner()
Compute new values of acoustic density for nonlinear case.
RealMatrix & getDyudyn()
Non uniform grid acoustic velocity in y.
RealMatrix & getDzudzn()
Non uniform grid acoustic velocity in z.
IndexMatrix & getVelocitySourceIndex()
Get velocity source geometry data.
void computeInitialVelocityHomogeneousUniform()
Compute velocity for the initial pressure problem, homogeneous medium, uniform grid.
virtual size_t getMemoryUsage() const
Get memory usage in MB on the host side.
IndexMatrix & getPressureSourceIndex()
Get pressure source geometry data.
double getCumulatedPostProcessingTime() const
Get post-processing time accumulated over all legs.
PML on staggered grid z.
void generateTauAndEta()
Generate absorbTau, absorbEta for heterogenous medium.
virtual void allocateMemory()
Memory allocation.
RealMatrix & getInitialPressureSourceInput()
Get initial pressure source input data (whole matrix).
void printFullCodeNameAndLicense() const
Print the code name and license.
Parameters & mParameters
Global parameters of the simulation.
T & getMatrix(const MatrixIdx matrixIdx)
Get the matrix with a specific type from the container.
Positive Fourier shift in x.
void computePressureGradient()
Compute part of the new velocity term - gradient of pressure.
Delay mask for many types sources.
RealMatrix & getPmlY()
Get PML in y.
Acoustic acceleration x.
void computeVelocityHeterogeneous()
Compute acoustic velocity for heterogeneous medium and a uniform grid.
RealMatrix & getDtRho0Sgy()
Get dt * rho0Sgy matrix (time step size * ambient velocity on staggered grid in y direction)...
RealMatrix & GetVelocityYSourceInput()
Get Velocity source input data in y direction.
RealMatrix & getDyudynSgy()
Non uniform grid acoustic velocity on staggered grid x.
Non uniform grid acoustic velocity on staggered grid y.
The header file containing the matrix container.
velocity shift for non-staggered velocity in y.
The header file of the class saving RealMatrix data into the output HDF5 file.
Negative shift for non-staggered velocity in x.
RealMatrix & getDzudznSgz()
Non uniform grid acoustic velocity on staggered grid x.
void sumPressureTermsLinearLossless()
Sum sub-terms for new pressure, linear lossless case.
The header file containing the class that implements 3D FFT using the FFTW interface.
velocity shift for non-staggered velocity in z.
RealMatrix & getPressureSourceInput()
Get pressure source input data (signal).
dt / initial velocity on staggered grid x.
PML on staggered grid y.
Negative Fourier shift in x.
void computeMainLoop()
Compute the main time loop of the kspaceFirstOrder3D.
Velocity z on staggered grid.
The header file defining the output stream container.
void setProcessorAffinity()
Set processor affinity.
RealMatrix & getRhoY()
Get density matrix in y direction.
Velocity y on staggered grid.
void computeVelocity()
Compute new values of acoustic velocity.
RealMatrix & getUySgy()
Get velocity matrix on staggered grid in y direction.
void loadElapsedTimeFromOutputFile()
Reads the header of the output file and sets the cumulative elapsed time from the first log...
RealMatrix & GetVelocityXSourceInput()
Get Velocity source input data in x direction.
RealMatrix & getUxShifted()
Get velocity shifted on normal grid in x direction.
Absorbing coefficient Eau.
ComplexMatrix & getDdxKShiftPos()
Get positive Fourier shift in x.
ComplexMatrix & getXShiftNegR()
Get negative shift for non-staggered velocity in x.
void addPressureSource()
Add in pressure source.
RealMatrix & getPmlXSgx()
Get PML on staggered grid x.
Temporary matrix for fft shift.
void printStatistics()
Print progress statistics.
RealMatrix & getTemp1Real3D()
Get first real 3D temporary matrix.
The class for 64b unsigned integers (indices). It is used for linear and cuboid corners masks to get ...
Definition: IndexMatrix.h:47
void computePressureTermsNonlinear(RealMatrix &densitySum, RealMatrix &nonlinearTerm, RealMatrix &velocityGradientSum)
Calculate three temporary sums in the new pressure formula before taking the FFT, nonlinear absorbing...
void computeInitialVelocityHomogeneousNonuniform()
Compute acoustic velocity for initial pressure problem, homogenous medium, nonuniform grid...
void sumPressureTermsNonlinear(const RealMatrix &absorbTauTerm, const RealMatrix &absorbEtaTerm, const RealMatrix &nonlinearTerm)
Sum sub-terms to calculate new pressure, after FFTs, nonlinear case.
RealMatrix & getDxudxnSgx()
Non uniform grid acoustic velocity on staggered grid x.
Temporary matrix for 1D fft in x.
void sumPressureTermsNonlinearLossless()
Sum sub-terms for new pressure, linear lossless case.
FftwComplexMatrix & getTempFftwShift()
Get temporary matrix for fft shift.
void writeOutputDataInfo()
Write statistics and header into the output file.
RealMatrix & getDuzdz()
Get velocity gradient on in z direction.
void InitializeFftwPlans()
Initialize FFTW plans.
void preProcessing()
Compute pre-processing phase.
ComplexMatrix & getZShiftNegR()
Get negative shift for non-staggered velocity in z.
void generateInitialDenisty()
Calculate dt ./ rho0 for nonuniform grids.
ComplexMatrix & getDdzKShiftNeg()
Get negative Fourier shift in z.
void computeShiftedVelocity()
compute shifted velocity for –u_non_staggered flag.
bool isTimeToCheckpoint()
Is time to checkpoint (save actual state on disk).