Coverage for kwave/kWaveSimulation_helper/display_simulation_params.py: 15%

46 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-24 11:55 -0700

1from kwave import kWaveGrid, kWaveMedium 

2from kwave.utils import scale_SI 

3import numpy as np 

4 

5 

6def display_simulation_params(kgrid: kWaveGrid, medium: kWaveMedium, elastic_code: bool): 

7 dt = kgrid.dt 

8 t_array_end = kgrid.t_array[0][-1] 

9 Nt = int(kgrid.Nt) 

10 k_size = kgrid.size 

11 

12 # display time step information 

13 print(' dt: ', f'{scale_SI(dt)[0]}s', f', t_end: {scale_SI(t_array_end)[0]}s', ', time steps:', Nt) 

14 

15 c_min, c_min_comp, c_min_shear = get_min_sound_speed(medium, elastic_code) 

16 

17 # get suitable scaling factor 

18 _, scale, _, _ = scale_SI(np.min(k_size[k_size != 0])) 

19 

20 print_grid_size(kgrid, scale) 

21 print_max_supported_freq(kgrid, c_min) 

22 

23 

24def get_min_sound_speed(medium, is_elastic_code): 

25 # if using the elastic code, 

26 # get the minimum sound speeds (not including zero if set for the shear speed) 

27 if not is_elastic_code: 

28 c_min = np.min(medium.sound_speed) 

29 return c_min, None, None 

30 else: # pragma: no cover 

31 c_min_comp = np.min(medium.sound_speed_compression) 

32 c_min_shear = np.min(medium.sound_speed_shear[medium.sound_speed_shear != 0]) 

33 return None, c_min_comp, c_min_shear 

34 

35 

36def print_grid_size(kgrid, scale): 

37 k_size = kgrid.size 

38 

39 grid_size_pts = [int(kgrid.Nx)] 

40 if kgrid.dim >= 2: 

41 grid_size_pts.append(int(kgrid.Ny)) 

42 if kgrid.dim == 3: 

43 grid_size_pts.append(int(kgrid.Nz)) 

44 

45 if kgrid.dim == 1: 

46 grid_size_scale = [scale_SI(k_size[0])[0]] 

47 elif kgrid.dim == 2: 

48 grid_size_scale = [k_size[0] * scale, k_size[1] * scale] 

49 elif kgrid.dim == 3: 

50 grid_size_scale = [round(k_size[0]*scale, 4), round(k_size[1]*scale, 4), round(k_size[2]*scale, 4)] 

51 else: 

52 raise NotImplementedError 

53 

54 grid_size_str = ' by '.join(map(str, grid_size_pts)) 

55 grid_scale_str = ' by '.join(map(str, grid_size_scale)) 

56 

57 # display grid size 

58 print(f' input grid size: {grid_size_str} grid points ({grid_scale_str} m)') 

59 

60 

61def print_max_supported_freq(kgrid, c_min): 

62 # display the grid size and maximum supported frequency 

63 k_max, k_max_all = kgrid.k_max, kgrid.k_max_all 

64 

65 if kgrid.dim == 1: 

66 # display maximum supported frequency 

67 print(' maximum supported frequency: ', scale_SI(k_max_all * c_min / (2*np.pi))[0], 'Hz') 

68 

69 elif kgrid.dim == 2: 

70 # display maximum supported frequency 

71 if k_max.x == k_max.y: 

72 print(' maximum supported frequency: ', scale_SI(k_max_all * c_min / (2*np.pi))[0], 'Hz') 

73 else: 

74 print(' maximum supported frequency: ', scale_SI(k_max.x * c_min / (2*np.pi))[0], 

75 'Hz by ', scale_SI(kgrid.ky_max * c_min / (2*np.pi))[0], 'Hz') 

76 

77 elif kgrid.dim == 3: 

78 # display maximum supported frequency 

79 if k_max.x == k_max.z and k_max.x == k_max.y: 

80 print(' maximum supported frequency: ', f'{scale_SI(k_max_all * c_min / (2*np.pi))[0]}Hz') 

81 else: 

82 print(' maximum supported frequency: ', f'{scale_SI(k_max.x * c_min / (2*np.pi))[0]}Hz by {scale_SI(k_max.y * c_min / (2*np.pi))[0]}Hz by {scale_SI(k_max.z * c_min / (2*np.pi))[0]}Hz')