35 #include <sys/resource.h>
41 #define _USE_MATH_DEFINES
45 #pragma comment(lib, "Psapi.lib")
78 matrixContainer(), outputStreamContainer(), parameters(
TParameters::GetInstance()),
79 actPercent(0), isTimestepRightAfterRestore(false),
80 totalTime(), preProcessingTime(), dataLoadTime(), simulationTime(),
81 postProcessingTime(), iterationTime()
86 H5Eset_auto(H5E_DEFAULT, NULL, NULL);
171 if (recoverFromCheckpoint)
191 checkpointFile.
Close();
272 catch (
const std::exception& e)
310 catch (
const std::exception& e)
359 catch (
const std::exception &e)
376 catch (
const std::exception &e)
393 struct rusage memUsage;
394 getrusage(RUSAGE_SELF, &memUsage);
396 return memUsage.ru_maxrss >> 10;
402 PROCESS_MEMORY_COUNTERS pmc;
404 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
406 GetCurrentProcessId());
408 GetProcessMemoryInfo(hProcess, &pmc,
sizeof(pmc));
409 CloseHandle(hProcess);
411 return pmc.PeakWorkingSetSize >> 20;
424 cudaMemGetInfo(&free,&total);
426 return ((total-free) >> 20);
468 #if (defined(__GNUC__) || defined(__GNUG__)) && !(defined(__clang__) || defined(__INTEL_COMPILER))
471 #ifdef __INTEL_COMPILER
479 #if (defined (__AVX2__))
481 #elif (defined (__AVX__))
483 #elif (defined (__SSE4_2__))
485 #elif (defined (__SSE4_1__))
487 #elif (defined (__SSE3__))
489 #elif (defined (__SSE2__))
496 int cudaRuntimeVersion;
497 if (cudaRuntimeGetVersion(&cudaRuntimeVersion) != cudaSuccess)
505 cudaRuntimeVersion/1000, (cudaRuntimeVersion%100)/10);
508 int cudaDriverVersion;
509 cudaDriverGetVersion(&cudaDriverVersion);
512 cudaDriverVersion/1000, (cudaDriverVersion%100)/10);
528 int paddingLength = 65 - ( 22 + strlen(cudaParameters.
GetDeviceName().c_str()));
990 if (checkpointFile.
IsOpen()) checkpointFile.
Close();
1021 checkpointFileHeader.
SetFileType(THDF5_FileHeader::CHECKPOINT);
1027 checkpointFile.
Close();
1416 #pragma omp parallel
1434 #pragma omp for schedule (static)
1435 for (
size_t z = 0; z < nz; z++)
1437 const float z_f = (float) z;
1438 float z_part = 0.5f - fabs(0.5f - z_f * nz_rec );
1439 z_part = (z_part * z_part) * dz_sq_rec;
1441 for (
size_t y = 0; y < ny; y++)
1443 const float y_f = (float) y;
1444 float y_part = 0.5f - fabs(0.5f - y_f * ny_rec);
1445 y_part = (y_part * y_part) * dy_sq_rec;
1447 const float yz_part = z_part + y_part;
1448 for (
size_t x = 0; x < nx; x++)
1450 const float x_f = (float) x;
1451 float x_part = 0.5f - fabs(0.5f - x_f * nx_rec);
1452 x_part = (x_part * x_part) * dx_sq_rec;
1454 float k = c_ref_dt_pi * sqrt(x_part + yz_part);
1457 kappa[(z*ny + y) * nx + x ] = (k == 0.0f) ? 1.0f : sin(k)/k;
1470 #pragma omp parallel
1477 const float pi_2 = float(M_PI) * 2.0f;
1483 const float nx_rec = 1.0f / (float) nx;
1484 const float ny_rec = 1.0f / (float) ny;
1485 const float nz_rec = 1.0f / (float) nz;
1496 #pragma omp for schedule (static)
1497 for (
size_t z = 0; z < nzComplex; z++)
1499 const float z_f = (float) z;
1500 float z_part = 0.5f - fabs(0.5f - z_f * nz_rec );
1501 z_part = (z_part * z_part) * dz_sq_rec;
1503 for (
size_t y = 0; y < nyComplex; y++)
1505 const float y_f = (float) y;
1506 float y_part = 0.5f - fabs(0.5f - y_f * ny_rec);
1507 y_part = (y_part * y_part) * dy_sq_rec;
1509 const float yz_part = z_part + y_part;
1511 size_t i = (z * nyComplex + y) * nxComplex;
1513 for (
size_t x = 0; x < nxComplex; x++)
1515 const float x_f = (float) x;
1516 float x_part = 0.5f - fabs(0.5f - x_f * nx_rec);
1517 x_part = (x_part * x_part) * dx_sq_rec;
1519 float k = pi_2 * sqrt(x_part + yz_part);
1520 float c_ref_k = c_ref_dt_2 * k;
1522 absorb_nabla1[i] = pow(k, alpha_power - 2);
1523 absorb_nabla2[i] = pow(k, alpha_power - 1);
1525 kappa[i] = (c_ref_k == 0.0f) ? 1.0f : sin(c_ref_k)/c_ref_k;
1527 if (absorb_nabla1[i] == std::numeric_limits<float>::infinity()) absorb_nabla1[i] = 0.0f;
1528 if (absorb_nabla2[i] == std::numeric_limits<float>::infinity()) absorb_nabla2[i] = 0.0f;
1547 const float tan_pi_y_2 = tan(static_cast<float> (M_PI_2) * alpha_power);
1548 const float alpha_db_neper_coeff = (100.0f * pow(1.0e-6f /(2.0f * static_cast<float>(M_PI)), alpha_power)) /
1549 (20.0f * static_cast<float>(M_LOG10E));
1558 #pragma omp parallel
1595 const float tan_pi_y_2 = tan(static_cast<float>(M_PI_2) * alpha_power);
1599 const float alpha_db_neper_coeff = (100.0f * pow(1.0e-6f / (2.0f * static_cast<float>(M_PI)), alpha_power)) /
1600 (20.0f * static_cast<float>(M_LOG10E));
1603 #pragma omp for schedule (static)
1604 for (
size_t z = 0; z < nz; z++)
1606 for (
size_t y = 0; y < ny; y++)
1608 size_t i = (z * ny + y) * nx;
1609 for (
size_t x = 0; x < nx; x++)
1611 const float alpha_coeff_2 = 2.0f * alpha_coeff[i*alpha_shift] * alpha_db_neper_coeff;
1613 absorb_tau[i] = (-alpha_coeff_2) * pow(c0[i * c0_shift],alpha_power - 1);
1614 absorb_eta[i] = alpha_coeff_2 * pow(c0[i * c0_shift],alpha_power) * tan_pi_y_2;
1631 #pragma omp parallel
1647 const size_t sliceSize = (nx * ny );
1649 #pragma omp for schedule (static)
1650 for (
size_t z = 0; z < nz; z++)
1652 register size_t i = z* sliceSize;
1653 for (
size_t y = 0; y < ny; y++)
1655 for (
size_t x = 0; x < nx; x++)
1657 dt_rho0_sgx[i] = (dt * duxdxn_sgx[x]) / dt_rho0_sgx[i];
1663 #pragma omp for schedule (static)
1664 for (
size_t z = 0; z < nz; z++)
1666 register size_t i = z* sliceSize;
1667 for (
size_t y = 0; y < ny; y++)
1669 const float duydyn_el = duydyn_sgy[y];
1670 for (
size_t x = 0; x < nx; x++)
1672 dt_rho0_sgy[i] = (dt * duydyn_el) / dt_rho0_sgy[i];
1679 #pragma omp for schedule (static)
1680 for (
size_t z = 0; z < nz; z++)
1682 register size_t i = z* sliceSize;
1683 const float duzdzn_el = duzdzn_sgz[z];
1684 for (
size_t y = 0; y < ny; y++)
1686 for (
size_t x = 0; x < nx; x++)
1688 dt_rho0_sgz[i] = (dt * duzdzn_el) / dt_rho0_sgz[i];
1712 #pragma omp parallel for schedule (static)
1715 c2[i] = c2[i] * c2[i];
1802 const float* Absorb_tau_data = absorb_tau_temp.
GetDeviceData();
1803 const float* Absorb_eta_data = absorb_eta_temp.
GetDeviceData();
1940 const double toGo = ((elTimeWithLegs / (float) (t_index + 1)) * nt) - elTimeWithLegs;
1946 current = localtime(&now);
1950 (
size_t) ((t_index) / (nt * 0.01f)),
'%',
1952 current->tm_mday, current->tm_mon+1, current->tm_year-100,
1953 current->tm_hour, current->tm_min, current->tm_sec);
1998 if (fileHeader.
GetFileType() != THDF5_FileHeader::OUTPUT)
2055 if (fileHeader.
GetFileType() != THDF5_FileHeader::CHECKPOINT)
2086 checkpointDimSizes.
nx,
2087 checkpointDimSizes.
ny,
2088 checkpointDimSizes.
nz,
2111 postProcessingTime);
2113 this->totalTime.SetCumulatedElapsedTimeOverPreviousLegs(totalTime);
2114 this->dataLoadTime.SetCumulatedElapsedTimeOverPreviousLegs(dataLoadTime);
2115 this->preProcessingTime.SetCumulatedElapsedTimeOverPreviousLegs(preProcessingTime);
2116 this->simulationTime.SetCumulatedElapsedTimeOverPreviousLegs(simulationTime);
2117 this->postProcessingTime.SetCumulatedElapsedTimeOverPreviousLegs(postProcessingTime);
void Compute_FFT_1DY_R2C(TRealMatrix &inMatrix)
Compute 1D out-of-place Real-to-Complex FFT in the Y dimension.
size_t GetDeviceMemoryUsageInMB()
Get memory usage in MB on the GPU side.
size_t nx
number of elements in the x direction
TOutputMessage OUT_FMT_MEMORY_ALLOCATION
Output message.
TDimensionSizes GetReducedDimensionSizes() const
Reduced dimension sizes of the simulation (complex classes).
TRealMatrix & Get_absorb_nabla1()
Get the absorb_nabla1 matrix from the container.
TOutputMessage OUT_FMT_LICENCE
Print version output message.
std::string GetCheckpointFileName() const
Get checkpoint filename.
float & Get_c0_scalar()
Get c0_scalar value.
TRealMatrix & Get_dt_rho0_sgy()
Get the dt.*rho0_sgy matrix from the container.
void ComputePressurePartsLinear(TRealMatrix &rhoxyz_sum, TRealMatrix &rho0_du_sum)
Calculate two temporary sums in the new pressure formula, linear absorbing case.
float Get_dz() const
Get dz value.
void AddPressureSource()
Add in pressure source.
void AddMatrices()
Populate the container based on the simulation type.
void FreeMatrices()
Destroy and free all matrices.
void AddVelocitySource(TRealMatrix &uxyz_sgxyz, const TRealMatrix &u_source_input, const TIndexMatrix &u_source_index, const size_t t_index)
Add in velocity source terms.
TOutputMessage OUT_FMT_STORING_SENSOR_DATA
Output message.
double GetTotalTime() const
Get total simulation time.
TRealMatrix & Get_ux_sgx()
Get the ux_sgx matrix from the container.
static std::string WordWrapString(const std::string &inputString, const std::string &delimiters, const int indentation=0, const int lineSize=65)
Wrap the line based on logger conventions.
int GetSamplerGridSize1D() const
Get Number of blocks for the 1D data sampling kernels.
size_t GetProgressPrintInterval() const
Get progress print interval.
TRealMatrix & Get_ux_source_input()
Get the ux_source_input matrix from the container.
size_t GetStartTimeIndex() const
Get start time index for sensor recording.
static void Create_FFT_Plan_1DZ_R2C(const TDimensionSizes &inMatrixDims)
Create static cuFFT plan for Real-to-Complex in the Z dimension.
int GetCUDACodeVersion()
Get the CUDA architecture and GPU code version the code was compiled with.
TRealMatrix & Get_absorb_tau()
Get the absorb_tau matrix from the container.
TComplexMatrix & Get_x_shift_neg_r()
Get the x_shift_neg_r matrix from the container.
void ComputeDensityLinear()
Compute new values of acoustic density for linear case.
static const int DEFAULT_DEVICE_IDX
Default Device Index - no default GPU.
static TLogLevel GetLevel()
Get the log level.
void LoadDataFromCheckpointFile(THDF5_File &checkpointFile)
Load all matrices from the output HDF5 file.
TErrorMessage ERR_FMT_PATH_DELIMITERS
delimiters for linux paths
void SumPressureLinearLossless()
Sum sub-terms for new p, linear lossless case.
TErrorMessage ERR_FMT_BAD_OUTPUT_FILE_FORMAT
KSpaceFirstOrder3DSolver error message.
void Compute_FFT_3D_C2R(TRealMatrix &outMatrix)
Compute 3D out-of-place Complex-to-Real FFT.
float Get_c_ref() const
Get c_ref value.
void PrintStatistics()
Print progress statistics.
bool isTimestepRightAfterRestore
This variable is true when calculating first time step after restore from checkpoint (to allow asynch...
TRealMatrix & Get_duydy()
Get the duydy matrix from the container.
static void DestroyAllPlansAndStaticData()
Destroy all static plans and error messages.
TErrorMessage ERR_FMT_BAD_CHECKPOINT_FILE_FORMAT
KSpaceFirstOrder3DSolver error message.
TOutputMessage OUT_FMT_CHECKPOINT_HEADER
Output message.
TRealMatrix & Get_pml_x()
Get the pml_x matrix from the container.
bool IsCheckpointInterruption() const
Was the loop interrupted to checkpoint?
TRealMatrix & Get_uz_shifted()
Get the uz_shifted matrix from the container.
bool IsTimeToCheckpoint()
Is time to checkpoint (save actual state on disk).
void InitializeFFTPlans()
Initialize FFT plans.
TRealMatrix & Get_dzudzn_sgz()
Get the dzudzn_sgz matrix from the container.
void Open(const std::string &fileName, unsigned int flags=H5F_ACC_RDONLY)
Open a file.
void ComputeGradientVelocity()
Compute new values of acoustic velocity gradients.
void AddVelocitySource()
Add in velocity source.
static void Create_FFT_Plan_1DX_R2C(const TDimensionSizes &inMatrixDims)
Create static cuFFT plan for Real-to-Complex in the X dimension.
TComplexMatrix & Get_ddz_k_shift_neg()
Get the ddz_k_shift_neg matrix from the container.
TCUFFTComplexMatrix & Get_cufft_z_temp()
Get the FFT_Z_temp from the container.
TOutputStreamContainer outputStreamContainer
Output stream container.
TOutputMessage OUT_FMT_CURRENT_DEVICE_MEMORY
Output message.
TRealMatrix & Get_kappa()
Get the kappa matrix from the container.
TOutputMessage OUT_FMT_READING_INPUT_FILE
Output message.
virtual void FreeMemory()
Memory deallocation.
TTimeMeasure dataLoadTime
Data load time of the simulation.
TMatrixName uz_final_NAME
uz_final variable name
TOutputMessage OUT_FMT_VISUAL_STUDIO_COMPILER
Print version output message.
TOutputMessage OUT_FMT_CURRENT_HOST_MEMORY
Output message.
TRealMatrix & Get_pml_z()
Get the pml_z matrix from the container.
TOutputMessage OUT_FMT_SIMULATION_FINAL_SEPARATOR
Output message.
TComplexMatrix & Get_ddz_k_shift_pos()
Get the ddz_k_shift_pos matrix from the container.
TRealMatrix & Get_dxudxn_sgx()
Get the dxudxn_sgx matrix from the container.
TOutputMessage OUT_FMT_READING_CHECKPOINT_FILE
Output message.
TOutputMessage OUT_FMT_CUDA_DEVICE_INFO_NA
Print version output message.
TMatrixName sensor_mask_index_NAME
sensor_mask_index variable name
TOutputMessage OUT_FMT_SIMULATION_PROGRESS
Output message.
size_t Get_ux_source_flag() const
Get ux_source_flag value.
void SumPressureLinearLossless(TRealMatrix &p, const TRealMatrix &rhox, const TRealMatrix &rhoy, const TRealMatrix &rhoz, const bool is_c2_scalar, const float *c2_matrix)
Sum sub-terms for new p, linear lossless case.
TRealMatrix & Get_pml_z_sgz()
Get the pml_z_sgz matrix from the container.
void Compute_FFT_1DZ_R2C(TRealMatrix &inMatrix)
Compute 1D out-of-place Real-to-Complex FFT in the Z dimension.
TOutputMessage OUT_FMT_CUDA_RUNTIME_NA
Print version output message.
TMatrixName p_final_NAME
p_final variable name
void ComputeVelocityGradientNonuniform(TRealMatrix &duxdx, TRealMatrix &duydy, TRealMatrix &duzdz, const TRealMatrix &dxudxn, const TRealMatrix &dyudyn, const TRealMatrix &dzudzn)
Shift gradient of acoustic velocity on non-uniform grid.
void GenerateKappa()
Generate kappa matrix for non-absorbing media.
static TParameters & GetInstance()
Get instance of the singleton class.
TRealMatrix & Get_c2()
Get the c^2 matrix from the container.
void Set_t_index(const size_t new_t_index)
Set simulation time step - should be used only when recovering from checkpoint.
void SetUpDeviceConstants() const
Upload useful simulation constants into device constant memory.
virtual void WriteDataToHDF5File(THDF5_File &file, TMatrixName &matrixName, const size_t compressionLevel)
Write data into the HDF5 file.
TOutputMessage OUT_FMT_GNU_COMPILER
Print version output message.
static void Create_FFT_Plan_1DY_C2R(const TDimensionSizes &outMatrixDims)
Create static cuFFT plan for Complex-to-Real in the Y dimension.
void LoadDataFromInputFile(THDF5_File &inputFile)
Load all matrices from the input HDF5 file.
TOutputMessage OUT_FMT_CHECKPOINT_TIME_STEPS
Output message.
TCUFFTComplexMatrix & Get_cufft_y_temp()
Get the FFT_Y_temp from the container.
TOutputMessage OUT_FMT_KWAVE_VERSION
Output message.
void Compute_FFT_1DY_C2R(TRealMatrix &outMatrix)
Compute 1D out-of-place Complex-to-Real FFT in the Y dimension.
TOutputMessage OUT_FMT_SSE2
Print version output message.
TRealMatrix & Get_ux_shifted()
Get the ux_shifted matrix from the container.
void ComputePressurePartsNonLinear(TRealMatrix &rho_sum, TRealMatrix &BonA_sum, TRealMatrix &du_sum, const TRealMatrix &rhox, const TRealMatrix &rhoy, const TRealMatrix &rhoz, const TRealMatrix &duxdx, const TRealMatrix &duydy, const TRealMatrix &duzdz, const bool is_BonA_scalar, const float *BonA_matrix, const bool is_rho0_scalar, const float *rho0_matrix)
Calculate three temporary sums in the new pressure formula, non-linear absorbing case.
void AddPressureSource(TRealMatrix &rhox, TRealMatrix &rhoy, TRealMatrix &rhoz, const TRealMatrix &p_source_input, const TIndexMatrix &p_source_index, const size_t t_index)
Add in pressure source term.
double GetPreProcessingTime() const
Get pre-processing time.
TTimeMeasure iterationTime
Iteration time of the simulation.
static void ErrorAndTerminate(const std::string &errorMessage)
Log an error and terminate the execution.
TOutputMessage OUT_FMT_FINSIH_NO_DONE
Output message - finish line without done.
void ComputeVelocityScalarNonuniform(TRealMatrix &ux_sgx, TRealMatrix &uy_sgy, TRealMatrix &uz_sgz, const TRealMatrix &ifft_x, const TRealMatrix &ifft_y, const TRealMatrix &ifft_z, const TRealMatrix &dxudxn_sgx, const TRealMatrix &dyudyn_sgy, const TRealMatrix &dzudzn_sgz, const TRealMatrix &pml_x, const TRealMatrix &pml_y, const TRealMatrix &pml_z)
Compute acoustic velocity, scalar, non-uniform case.
TMatrixName Ny_NAME
Ny variable name.
TRealMatrix & Get_dyudyn_sgy()
Get the dyudyn_sgy matrix from the container.
void WriteScalarValue(const hid_t parentGroup, TMatrixName &datasetName, const float value)
Write the scalar value under a specified group, float value.
static void Create_FFT_Plan_1DZ_C2R(const TDimensionSizes &outMatrixDims)
Create static cuFFT plan for Complex-to-Real in the Z dimension.
virtual size_t GetElementCount() const
Get element count of the matrix.
TKSpaceFirstOrder3DSolver()
Constructor.
TCUFFTComplexMatrix & Get_cufft_x_temp()
Get the CUFFT_X_temp from the container.
TRealMatrix & Get_p_source_input()
Get the p_source_input matrix from the container.
virtual void WriteDataToHDF5File(THDF5_File &file, TMatrixName &matrixName, const size_t compressionLevel)
Write data into the HDF5 file.
TOutputMessage OUT_FMT_POST_PROCESSING
Output message.
static void Create_FFT_Plan_3D_C2R(const TDimensionSizes &outMatrixDims)
Create static cuFFT plan for Complex-to-Real.
bool Get_c0_scalar_flag() const
Get c0_scalar_flag value.
TOutputMessage OUT_FMT_SSE41
Print version output message.
TTimeMeasure totalTime
Total time of the simulation.
void FreeStreams()
Free all streams - destroy them.
TOutputMessage OUT_FMT_DATA_LOADING
Output message.
TRealMatrix & Get_temp_3_real_3D()
Get the Temp_3_RS3D matrix from the container.
TOutputMessage OUT_FMT_CUDA_GRID_SHAPE_FORMAT
Output message.
void Compute_c2()
Calculate square of velocity.
void PrintFullNameCodeAndLicense() const
Print the code name and license.
TOutputMessage OUT_FMT_CUDA_CAPABILITY
Print version output message.
TRealMatrix & Get_transducer_source_input()
Get the transducer_source_input matrix from the container.
TOutputMessage OUT_FMT_CUDA_CODE_ARCH
Print version output message.
bool Get_BonA_scalar_flag() const
Get BonA_scalar_flag value.
bool IsOpen() const
Is the file opened?
virtual float * GetHostData()
Get raw CPU data out of the class (for direct CPU kernel access).
void AddTransducerSource(TRealMatrix &ux_sgx, const TIndexMatrix &u_source_index, TIndexMatrix &delay_mask, const TRealMatrix &transducer_signal)
Add transducer data source to X component.
void SumPressureNonlinearLossless()
Sum sub-terms for new p, linear lossless case.
TComplexMatrix & Get_z_shift_neg_r()
Get the y_shift_neg_r from the container.
The header file containing the main class of the project responsible for the entire 3D fluid simulati...
const std::string GetCodeName() const
Get code name - release code version.
void AddStreams(TMatrixContainer &matrixContainer)
Add all streams into the container.
void CheckCheckpointFile()
Check the checkpoint file has the correct format and version.
void RecomputeIndicesToMatlab()
Recompute indices C++ -> MATLAB.
static void Create_FFT_Plan_1DX_C2R(const TDimensionSizes &outMatrixDims)
Create static cuFFT plan for Complex-to-Real in the X dimension.
TRealMatrix & Get_p0_source_input()
Get the p0_source_input from the container.
void SumPressureTermsNonlinear(TRealMatrix &p, const TRealMatrix &BonA_temp, const bool is_c2_scalar, const float *c2_matrix, const bool is_tau_eta_scalar, const float *absorb_tau, const float *tau_matrix, const float *absorb_eta, const float *eta_matrix)
Sum sub-terms to calculate new pressure, non-linear case.
void Compute_FFT_1DX_R2C(TRealMatrix &inMatrix)
Compute 1D out-of-place Real-to-Complex FFT in the X dimension.
TRealMatrix & Get_p()
Get the p matrix from the container.
TComplexMatrix & Get_ddy_k_shift_pos()
Get the ddy_k_shift_pos matrix from the container.
TOutputMessage OUT_FMT_FFT_PLANS
Output message.
TRealMatrix & Get_BonA()
Get the BonA matrix from the container.
TRealMatrix & Get_dxudxn()
Get the dxudxn matrix from the container.
TRealMatrix & Get_uz_sgz()
Get the uz_sgz matrix from the container.
TMatrixName sensor_mask_corners_NAME
sensor_mask_corners variable name
double GetCumulatedElapsedTimeOverPreviousLegs() const
Get time spent in previous legs.
TMatrixContainer matrixContainer
Matrix container with all the matrix classes.
virtual TDimensionSizes GetDimensionSizes() const
Get dimension sizes of the matrix.
TMatrixName uy_final_NAME
uy_final variable name
bool Get_alpha_coeff_scalar_flag() const
Get alpha_coeff_scalar_flag value.
static void Create_FFT_Plan_1DY_R2C(const TDimensionSizes &inMatrixDims)
Create static cuFFT plan for Real-to-Complex in the Y dimension.
Class responsible for CUDA runtime setup.
std::string GetDeviceName() const
Get the name of the device used.
TOutputMessage OUT_FMT_SIMULATION_HEADER
Output message.
void CreateMatrices()
Create all matrices in the container.
TErrorMessage ERR_FMT_OUTPUT_DIMENSIONS_NOT_MATCH
KSpaceFirstOrder3DSolver error message.
TRealMatrix & Get_dzudzn()
Get the dzudzn matrix from the container.
TOutputMessage OUT_FMT_SIMULATOIN_END_SEPARATOR
Output message.
size_t Get_t_index() const
Get simulation time step.
TOutputMessage OUT_FMT_SSE3
Print version output message.
void Compute_p0_AddInitialPressure(TRealMatrix &p, TRealMatrix &rhox, TRealMatrix &rhoy, TRealMatrix &rhoz, const TRealMatrix &p0, const bool Is_c2_scalar, const float *c2)
Add initial pressure to p0 (as p0 source).
double GetSimulationTime() const
Get simulation time (time loop).
void Calculate_p0_source()
Calculate p0_ ource.
TRealMatrix & Get_absorb_nabla2()
Get the absorb_nabla2 matrix from the container.
TDimensionSizes GetFullDimensionSizes() const
Full dimension sizes of the simulation (real classes).
void ComputePressurelGradient(TCUFFTComplexMatrix &fft_x, TCUFFTComplexMatrix &fft_y, TCUFFTComplexMatrix &fft_z, const TRealMatrix &kappa, const TComplexMatrix &ddx, const TComplexMatrix &ddy, const TComplexMatrix &ddz)
Compute part of the new velocity - gradient of p.
The header file containing a class responsible for printing out info and error messages (stdout...
TOutputMessage OUT_FMT_AVX2
Print version output message.
void GenerateKappaAndNablas()
Generate kappa matrix, absorb_nabla1, absorb_nabla2 for absorbing media.
void Compute_FFT_3D_R2C(TRealMatrix &inMatrix)
Compute 3D out-of-place Real-to-Complex FFT.
void StoreSensorData()
Store sensor data.
TRealMatrix & Get_rho0()
Get the rho0 matrix from the container.
void WriteOutputDataInfo()
Write statistics and header into the output file.
TOutputMessage OUT_FMT_CUDA_DEVICE
Print version output message.
void ComputeDensityNonlinearHeterogeneous(TRealMatrix &rhox, TRealMatrix &rhoy, TRealMatrix &rhoz, const TRealMatrix &pml_x, const TRealMatrix &pml_y, const TRealMatrix &pml_z, const TRealMatrix &duxdx, const TRealMatrix &duydy, const TRealMatrix &duzdz, const TRealMatrix &rho0)
Calculate acoustic density for non-linear case, heterogenous case.
void ComputeVelocityGradient(TCUFFTComplexMatrix &fft_x, TCUFFTComplexMatrix &fft_y, TCUFFTComplexMatrix &fft_z, const TRealMatrix &kappa, const TComplexMatrix &ddx_k_shift_neg, const TComplexMatrix &ddy_k_shift_neg, const TComplexMatrix &ddz_k_shift_neg)
Compute gradient of acoustic velocity on uniform grid.
TRealMatrix & Get_uz_source_input()
Get the uz_source_input matrix from the container.
void Compute_FFT_1DX_C2R(TRealMatrix &outMatrix)
Compute 1D out-of-place Complex-to-Real FFT in the X dimension.
static void Flush(const TLogLevel queryLevel)
Flush output messages.
void SumPressureTermsLinear(TRealMatrix &absorb_tau_temp, TRealMatrix &absorb_eta_temp, TRealMatrix &rhoxyz_sum)
Sum sub-terms to calculate new pressure, linear case.
TIndexMatrix & Get_sensor_mask_index()
Get the sensor_mask_index matrix from the container.
TOutputMessage OUT_FMT_ELAPSED_TIME
Output message.
void Start()
Get start timestamp.
void ReadScalarValue(const hid_t parentGroup, TMatrixName &datasetName, float &value)
Read the scalar value under a specified group, float value.
bool IsStore_u_non_staggered_raw() const
Is –u_non_staggered_raw set?
Class storing all parameters of the simulation.
TOutputMessage OUT_FMT_INTEL_COMPILER
Print version output message.
TIndexMatrix & Get_delay_mask()
Get the delay_mask matrix from the container.
TRealMatrix & Get_temp_2_real_3D()
Get the Temp_2_RS3D matrix from the container.
size_t Get_uy_source_flag() const
Get uy_source_flag value.
const TCUDAParameters & GetCudaParameters() const
Get class with CUDA Parameters (runtime setup), cosnt version.
void ComputeDensityLinearHomogeneous(TRealMatrix &rhox, TRealMatrix &rhoy, TRealMatrix &rhoz, const TRealMatrix &pml_x, const TRealMatrix &pml_y, const TRealMatrix &pml_z, const TRealMatrix &duxdx, const TRealMatrix &duydy, const TRealMatrix &duzdz)
Calculate acoustic density for linear case, homogenous case.
THDF5_FileHeader & GetFileHeader()
Get File header handle.
void PostProcessing()
Post processing, and closing the output streams.
TRealMatrix & Get_dt_rho0_sgz()
Get the dt.*rho0_sgz matrix from the container.
static bool IsHDF5(const std::string &fileName)
Does the file exist?
hid_t GetRootGroup() const
Get handle to the root group.
TOutputMessage OUT_FMT_LINUX_BUILD
Print version output message.
TIndexMatrix & Get_p_source_index()
Get the p_source_index matrix from the container.
THDF5_File & GetCheckpointFile()
Gest checkpoint file handle.
void SampleStreams()
Sample all streams (only sample, no disk operations).
TOutputMessage OUT_FMT_VERSION_GIT_HASH
Print version output message.
bool IsStore_p_final() const
Is –p_final specified at the command line?
void ComputeMainLoop()
Compute the main time loop of the kspaceFirstOrder3D.
TRealMatrix & Get_dyudyn()
Get the dyudyn matrix from the container.
TRealMatrix & Get_pml_y_sgy()
Get the pml_y_sgy matrix from the container.
TRealMatrix & Get_pml_y()
Get the pml_y matrix from the container.
TIndexMatrix & Get_u_source_index()
Get the u_source_index matrix from the container.
void ComputePressureLinear()
Compute acoustic pressure for linear case.
int GetSamplerBlockSize1D() const
Get number of threads for the 1D data sampling kernels.
double GetCumulatedTotalTime() const
Get total simulation time cumulated over all legs.
The header file containing routines for error messages and error messages common for both linux and w...
TIndexMatrix & Get_sensor_mask_corners()
Get the sensor_mask_corners matrix from the container.
size_t Get_p0_source_flag() const
Get p0_source_flag value.
void ReopenStreams()
Reopen streams after checkpoint file (datasets).
TRealMatrix & Get_duxdx()
Get the duxdx matrix from the container.
size_t ny
number of elements in the y direction
static void Create_FFT_Plan_3D_R2C(const TDimensionSizes &inMatrixDims)
Create static cuFFT plan for Real-to-Complex.
float Get_dt() const
Get dt value.
TCUFFTComplexMatrix & Get_cufft_shift_temp()
Get the FFT_shift_temp the container.
float Get_dx() const
Get dx value.
TOutputMessage OUT_FMT_CUDA_SAMPLER_GRID_SHAPE
Output message.
void SumPressureTermsNonlinear(TRealMatrix &absorb_tau_temp, TRealMatrix &absorb_eta_temp, TRealMatrix &BonA_temp)
Sum sub-terms to calculate new pressure, non-linear case.
void ComputeVelocity(TRealMatrix &ux_sgx, TRealMatrix &uy_sgy, TRealMatrix &uz_sgz, const TRealMatrix &ifft_x, const TRealMatrix &ifft_y, const TRealMatrix &ifft_z, const TRealMatrix &dt_rho0_sgx, const TRealMatrix &dt_rho0_sgy, const TRealMatrix &dt_rho0_sgz, const TRealMatrix &pml_x, const TRealMatrix &pml_y, const TRealMatrix &pml_z)
Compute acoustic velocity for default case (heterogeneous).
TOutputMessage OUT_FMT_READING_OUTPUT_FILE
Output message.
int GetSolverGridSize1D() const
Get number of block for 1D grid used by kSpaceSolver.
virtual void LoadInputData()
Load simulation data from the input file.
TMatrixName Nz_NAME
Nz variable name.
float Get_dy() const
Get dy value.
int GetDeviceIdx() const
Get Idx of the device being used.
void FlushRawStreams()
Flush streams to disk - only raw streams.
void ComputeDensityNonlinearHomogeneous(TRealMatrix &rhox, TRealMatrix &rhoy, TRealMatrix &rhoz, const TRealMatrix &pml_x, const TRealMatrix &pml_y, const TRealMatrix &pml_z, const TRealMatrix &duxdx, const TRealMatrix &duydy, const TRealMatrix &duzdz)
Calculate acoustic density for non-linear case, homogenous case.
size_t Get_nonlinear_flag() const
Get nonlinear_flag value.
Basic (default) level of verbosity.
The class for real matrices.
TOutputMessage OUT_FMT_CUDA_RUNTIME
Print version output message.
void RecomputeIndicesToCPP()
Recompute indices MATALAB->C++.
virtual ~TKSpaceFirstOrder3DSolver()
Destructor.
float & Get_absorb_eta_scalar()
Get absorb_eta_scalar value.
void Compute_FFT_1DZ_C2R(TRealMatrix &outMatrix)
Compute 1D out-of-place Complex-to-Real FFT in the Z dimension.
void Create(const std::string &fileName, unsigned int flags=H5F_ACC_TRUNC)
Create a file.
TRealMatrix & Get_dt_rho0_sgx()
Get the dt.*rho0_sgx matrix from the container.
TMatrixName Nx_NAME
Nx variable name.
float & Get_rho0_sgy_scalar()
Get rho0_sgy_scalar value.
float & Get_rho0_scalar()
Get rho0_scalar value.
size_t Get_uz_source_flag() const
Get uz_source_flag value.
void ComputePressurePartsLinear(TRealMatrix &sum_rhoxyz, TRealMatrix &sum_rho0_du, const TRealMatrix &rhox, const TRealMatrix &rhoy, const TRealMatrix &rhoz, const TRealMatrix &duxdx, const TRealMatrix &duydy, const TRealMatrix &duzdz, const bool is_rho0_scalar, const float *rho0_matrix)
Calculate two temporary sums in the new pressure formula, linear absorbing case.
void ComputePressurePartsNonLinear(TRealMatrix &rho_part, TRealMatrix &BonA_part, TRealMatrix &du_part)
Calculate three temporary sums in the new pressure formula, non-linear absorbing case.
void ComputeVelocityShiftInX(TCUFFTComplexMatrix &cufft_shift_temp, const TComplexMatrix &x_shift_neg_r)
Compute the velocity shift in Fourier space over the X axis.
void SaveScalarsToFile(THDF5_File &outputFile)
Save scalar values into the output HDF5 file.
TOutputMessage OUT_FMT_CUDA_DEVICE_NAME
Print version output message.
double GetCumulatedPostProcessingTime() const
Get post-processing time cumulated over all legs.
TOutputMessage OUT_FMT_LAST_SEPARATOR
Output message -last separator.
void SumPressureTermsLinear(TRealMatrix &p, const TRealMatrix &absorb_tau_temp, const TRealMatrix &absorb_eta_temp, const TRealMatrix &sum_rhoxyz, const bool is_c2_scalar, const float *c2_matrix, const bool is_tau_eta_scalar, const float *tau_matrix, const float *eta_matrix)
Sum sub-terms to calculate new pressure, linear case.
void CheckpointStreams()
Checkpoint streams.
TErrorMessage ERR_FMT_BAD_MINOR_FILE_VERSION
Command line parameters error message.
void ComputeDensityLinearHeterogeneous(TRealMatrix &rhox, TRealMatrix &rhoy, TRealMatrix &rhoz, const TRealMatrix &pml_x, const TRealMatrix &pml_y, const TRealMatrix &pml_z, const TRealMatrix &duxdx, const TRealMatrix &duydy, const TRealMatrix &duzdz, const TRealMatrix &rho0)
Calculate acoustic density for linear case, heterogeneous case.
TTimeMeasure postProcessingTime
Post-processing time of the simulation.
void CheckOutputFile()
Check the output file has the correct format and version.
void GenerateTauAndEta()
Generate absorb_tau, absorb_eta for heterogenous media.
TRealMatrix & Get_uy_sgy()
Get the uy_sgy matrix from the container.
void ComputeAbsorbtionTerm(TCUFFTComplexMatrix &fft1, TCUFFTComplexMatrix &fft2, const TRealMatrix &absorb_nabla1, const TRealMatrix &absorb_nabla2)
Compute absorbing term with abosrb_nabla1 and absorb_nabla2.
TOutputMessage OUT_FMT_CUDA_SOLVER_GRID_SHAPE
Output message.
size_t Get_p_source_flag() const
Get p_source_flag value.
void Compute_p0_VelocityScalarNonUniform(TRealMatrix &ux_sgx, TRealMatrix &uy_sgy, TRealMatrix &uz_sgz, const TRealMatrix &dxudxn_sgx, const TRealMatrix &dyudyn_sgy, const TRealMatrix &dzudzn_sgz)
Compute acoustic velocity for initial pressure problem, if rho0_sgx is scalar, non uniform grid...
void LoadElapsedTimeFromOutputFile(THDF5_File &o1utputFile)
Reads the header of the output file and sets the cumulative elapsed time from the first log...
TParameters & parameters
Global parameters of the simulation.
size_t Get_transducer_source_flag() const
Get transducer_source_flag value.
void Compute_p0_Velocity(TRealMatrix &ux_sgx, TRealMatrix &uy_sgy, TRealMatrix &uz_sgz, const TRealMatrix &dt_rho0_sgx, const TRealMatrix &dt_rho0_sgy, const TRealMatrix &dt_rho0_sgz)
Compute velocity for the initial pressure problem.
void ComputePressureNonlinear()
Compute acoustic pressure for nonlinear case.
Name space for all CUDA kernels used in the 3D solver.
size_t GetCompressionLevel() const
Get compression level.
TTimeMeasure preProcessingTime
Pre-processing time of the simulation.
static std::string FormatMessage(const std::string &format, Args...args)
C++-11 replacement for sprintf that works with std::string instead of char *.
The header file containing the matrix container and the related matrix record class.
int GetSolverBlockSize1D() const
Get number of threads for 1D block used by kSpaceSolver.
double GetCumulatedSimulationTime() const
Get simulation time (time loop) cumulated over all legs.
TOutputMessage OUT_FMT_WINDOWS_BUILD
Print version output message.
TOutputMessage OUT_FMT_SSE42
Print version output message.
void Stop()
Get stop timestamp.
void CopyMatricesToDevice()
Copy all matrices from host to device (CPU -> GPU).
size_t actPercent
Percentage of the simulation done.
TRealMatrix & Get_duzdz()
Get the duzdz matrix from the container.
void ComputeVelocityScalarUniform(TRealMatrix &ux_sgx, TRealMatrix &uy_sgy, TRealMatrix &uz_sgz, const TRealMatrix &ifft_x, const TRealMatrix &ifft_y, const TRealMatrix &ifft_z, const TRealMatrix &pml_x, const TRealMatrix &pml_y, const TRealMatrix &pml_z)
Compute acoustic velocity, scalar and uniform case.
bool IsStore_u_final() const
Is –u_final specified at the command line.
TOutputMessage OUT_FMT_CUDA_DRIVER
Print version output message.
virtual void Compute()
Compute the k-space simulation.
TErrorMessage ERR_FMT_BAD_MAJOR_File_Version
Command line parameters error message.
TRealMatrix & Get_rhoz()
Get the rhoz matrix from the container.
TComplexMatrix & Get_ddx_k_shift_neg()
Get the ddx_k_shift_neg matrix from the container.
double GetCumulatedDataLoadTime() const
Get data load time cumulated over all legs.
double GetPostProcessingTime() const
Get post-processing time.
virtual float * GetDeviceData()
Get raw GPU data out of the class (for direct GPU kernel access).
void ComputeVelocityShiftInZ(TCUFFTComplexMatrix &cufft_shift_temp, const TComplexMatrix &z_shift_neg_r)
Compute the velocity shift in Fourier space over the Z axis.
float & Get_absorb_tau_scalar()
Get absorb_tau_scalar value.
TTimeMeasure simulationTime
Simulation time of the simulation.
void CreateStreams()
Create all streams - opens the datasets.
TComplexMatrix & Get_ddy_k_shift_neg()
Get the ddy_k_shift_neg matrix from the container.
bool Get_rho0_scalar_flag() const
Get rho0_scalar_flag value.
virtual void AllocateMemory()
Memory allocation.
void SaveCheckpointData()
Save checkpoint data.
void CalculateShiftedVelocity()
Calculate ux_shifted, uy_shifted and uz_shifted.
double GetCumulatedPreProcessingTime() const
Get pre-processing time cumulated over all legs.
TErrorMessage ERR_FMT_CHECKPOINT_DIMENSIONS_NOT_MATCH
KSpaceFirstOrder3DSolver error message.
TComplexMatrix & Get_ddx_k_shift_pos()
Get the ddx_k_shift_pos matrix from the container.
THDF5_File & GetInputFile()
Get input file handle.
TOutputMessage OUT_FMT_BUILD_NO_DATE_TIME
Print version output message.
float & Get_alpha_coeff_scalar()
Get alpha_coeff_scalar value. Note: cannot be const because of other optimizations.
float Get_alpha_power() const
Get alpha_power value.
TOutputMessage OUT_FMT_CREATING_OUTPUT_FILE
Output message.
size_t Get_absorbing_flag() const
Get absorbing_flag value.
void StoreDataIntoCheckpointFile(THDF5_File &checkpointFile)
Store selected matrices into the checkpoint file.
TRealMatrix & Get_pml_x_sgx()
Get the pml_x_sgx matrix from the container.
double GetDataLoadTime() const
Get data load time.
size_t Get_nonuniform_grid_flag() const
Get nonuniform_grid_flag value.
TOutputMessage OUT_FMT_MAC_OS_BUILD
Print version output message.
void SetKernelConfiguration()
Set kernel configurations based on the simulation parameters.
TRealMatrix & Get_rhox()
Get the rhox matrix from the container.
const cudaDeviceProp & GetDeviceProperties() const
Return properties of currently used GPU.
size_t nz
number of elements in the z direction
static void Log(const TLogLevel queryLevel, const std::string &format, Args...args)
Log desired activity for a given log level, version with string format.
TOutputMessage OUT_FMT_SEPARATOR
Output message - separator.
void ComputeDensityNonliner()
Compute new values of acoustic density for non-linear case.
virtual void ScalarDividedBy(const float scalar)
Divide scalar/ matrix_element[i].
double GetElapsedTime() const
Get elapsed time.
void CloseStreams()
Close all streams.
void Increment_t_index()
Increment simulation time step.
TOutputMessage OUT_FMT_AVX
Print version output message.
virtual void CopyFromDevice()
Copy data from GPU -> CPU (Device -> Host).
TOutputMessage OUT_FMT_PRE_PROCESSING
Output message.
size_t Get_nt() const
Get Nt value.
TComplexMatrix & Get_y_shift_neg_r()
Get the y_shift_neg_r from the container.
TRealMatrix & Get_temp_1_real_3D()
Get the Temp_1_RS3D matrix from the container.
std::string GetOutputFileName() const
Get output file name.
TOutputMessage OUT_FMT_CREATING_CHECKPOINT
Output message.
TOutputMessage OUT_FMT_FAILED
Output message - failed message.
std::string GetGitHash() const
Get Git hash of the code.
TOutputMessage OUT_FMT_COMP_RESOURCES_HEADER
Output message.
void SumPressureNonlinearLossless(TRealMatrix &p, const TRealMatrix &rhox, const TRealMatrix &rhoy, const TRealMatrix &rhoz, const bool is_c2_scalar, const float *c2_matrix, const bool is_BonA_scalar, const float *BonA_matrix, const bool is_rho0_scalar, const float *rho0_matrix)
Sum sub-terms for new p, linear lossless case.
TRealMatrix & Get_rhoy()
Get the rhoy matrix from the container.
float & Get_rho0_sgx_scalar()
Get rho0_sgx_scalar value.
TSensorMaskType Get_sensor_mask_type() const
Get sensor mask type (linear or corners).
bool IsCopySensorMask() const
is –copy_mask set
void GenerateInitialDenisty()
Calculate dt ./ rho0 for non-uniform grids.
TRealMatrix & Get_absorb_eta()
Get the absorb_eta matrix from the container.
bool IsCheckpointEnabled() const
Is checkpoint enabled?
TMatrixName ux_final_NAME
ux_final variable name
Class wrapping the HDF5 routines.
void ComputeVelocity()
Compute new values of acoustic velocity.
void ComputeVelocityShiftInY(TCUFFTComplexMatrix &cufft_shift_temp, const TComplexMatrix &y_shift_neg_r)
Compute the velocity shift in Fourier space over the Y axis.
Structure with 4D dimension sizes (3 in space and 1 in time).
size_t GetCheckpointInterval() const
Get checkpoint interval.
TOutputMessage OUT_FMT_DONE
Output message - Done with two spaces.
TRealMatrix & Get_uy_shifted()
Get the uy_shifted matrix from the container.
THDF5_File & GetOutputFile()
Get output file handle.
TOutputMessage OUT_FMT_CUDA_DEVICE_NAME_PADDING
Print version output message.
size_t GetHostMemoryUsageInMB()
Get memory usage in MB on the CPU side.
float & Get_rho0_sgz_scalar()
Get rho0_sgz_scalar value.
void PostProcessStreams()
Post-process all streams and flush them to the file.
TOutputMessage OUT_FMT_STORING_CHECKPOINT_DATA
Output message.
TMatrixName t_index_NAME
t_index name
TRealMatrix & Get_uy_source_input()
Get the uy_source_input matrix from the container.
void PreProcessingPhase()
Compute pre-processing phase.
double GetCumulatedElapsedTimeOverAllLegs() const
Get cumulated elapsed time over all simulation legs.