Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce complexity of simulation options #521

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions kwave/kWaveSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def time_rev(self):

"""
if self.sensor is not None and not isinstance(self.sensor, NotATransducer):
if not self.options.simulation_type.is_elastic_simulation() and self.sensor.time_reversal_boundary_data is not None:
if not self.options.simulation_type.is_elastic and self.sensor.time_reversal_boundary_data is not None:
return True
else:
return self.userarg_time_rev
Expand Down Expand Up @@ -477,14 +477,13 @@ def input_checking(self, calling_func_name) -> None:
self.check_calling_func_name_and_dim(calling_func_name, k_dim)

# run subscript to check optional inputs
self.options = SimulationOptions.option_factory(self.kgrid, self.options)
opt = self.options

# TODO(Walter): clean this up with getters in simulation options pml size
pml_x_size, pml_y_size, pml_z_size = opt.pml_x_size, opt.pml_y_size, opt.pml_z_size
pml_size = Vector([pml_x_size, pml_y_size, pml_z_size])

is_elastic_code = opt.simulation_type.is_elastic_simulation()
is_elastic_code = opt.simulation_type.is_elastic
self.print_start_status(is_elastic_code=is_elastic_code)
self.set_index_data_type()

Expand Down Expand Up @@ -512,7 +511,7 @@ def input_checking(self, calling_func_name) -> None:
kgrid_N=Vector(self.kgrid.N),
pml_size=pml_size,
pml_inside=opt.pml_inside,
is_axisymmetric=opt.simulation_type.is_axisymmetric(),
is_axisymmetric=opt.simulation_type.is_axisymmetric,
)

@staticmethod
Expand Down Expand Up @@ -580,7 +579,7 @@ def check_medium(medium, kgrid_k, simulation_type: SimulationType) -> bool:
"""

# if using the fluid code, allow the density field to be blank if the medium is homogeneous
if (not simulation_type.is_elastic_simulation()) and medium.density is None and medium.sound_speed.size == 1:
if (not simulation_type.is_elastic) and medium.density is None and medium.sound_speed.size == 1:
user_medium_density_input = False
medium.density = 1
else:
Expand All @@ -589,7 +588,7 @@ def check_medium(medium, kgrid_k, simulation_type: SimulationType) -> bool:

# check medium absorption inputs for the fluid code
is_absorbing = any(medium.is_defined("alpha_coeff", "alpha_power"))
is_stokes = simulation_type.is_axisymmetric() or medium.alpha_mode == "stokes"
is_stokes = simulation_type.is_axisymmetric or medium.alpha_mode == "stokes"
medium.set_absorbing(is_absorbing, is_stokes)

if is_absorbing:
Expand Down Expand Up @@ -642,7 +641,7 @@ def check_sensor(self, kgrid_dim) -> None:
directivity.set_wavenumbers(self.kgrid)

# check for time reversal inputs and set flags
if not self.options.simulation_type.is_elastic_simulation() and self.sensor.time_reversal_boundary_data is not None:
if not self.options.simulation_type.is_elastic and self.sensor.time_reversal_boundary_data is not None:
self.record.p = False

# check for sensor.record and set usage flgs - if no flgs are
Expand All @@ -657,7 +656,7 @@ def check_sensor(self, kgrid_dim) -> None:
assert isinstance(self.sensor.record, list), 'sensor.record must be given as a list, e.g. ["p", "u"]'

# check the sensor record flgs
self.record.set_flags_from_list(self.sensor.record, self.options.simulation_type.is_elastic_simulation())
self.record.set_flags_from_list(self.sensor.record, self.options.simulation_type.is_elastic)

# enforce the sensor.mask field unless just recording the max_all
# and _final variables
Expand Down Expand Up @@ -777,7 +776,7 @@ def check_sensor(self, kgrid_dim) -> None:
# display, if flgs.time_rev = true or cartesian_interp =
# 'nearest' this grid is used as the sensor.mask
self.sensor.mask, self.order_index, self.reorder_index = cart2grid(
self.kgrid, self.sensor.mask, self.options.simulation_type.is_axisymmetric()
self.kgrid, self.sensor.mask, self.options.simulation_type.is_axisymmetric
)

# if in time reversal mode, reorder the p0 input data in
Expand Down Expand Up @@ -1029,7 +1028,7 @@ def check_kgrid_time(self) -> None:
self.kgrid.makeTime(self.medium.sound_speed, self.KSPACE_CFL)

# check kgrid.t_array for stability given medium properties
if not self.options.simulation_type.is_elastic_simulation():
if not self.options.simulation_type.is_elastic:
# calculate the largest timestep for which the model is stable

dt_stability_limit = check_stability(self.kgrid, self.medium)
Expand Down Expand Up @@ -1126,7 +1125,7 @@ def check_input_combinations(self, opt: SimulationOptions, user_medium_density_i
"The optional input " "StreamToDisk" " is currently only compatible " "with sensor.record = {" "p" "} (the default)."
)

is_axisymmetric = self.options.simulation_type.is_axisymmetric()
is_axisymmetric = self.options.simulation_type.is_axisymmetric
# make sure the PML size is smaller than the grid if PMLInside is true
if opt.pml_inside and (
(k_dim == 1 and (pml_size.x * 2 > self.kgrid.Nx))
Expand Down Expand Up @@ -1167,10 +1166,6 @@ def check_input_combinations(self, opt: SimulationOptions, user_medium_density_i
if not self.source_p0:
self.options.smooth_p0 = False

# start log if required
if opt.create_log:
raise NotImplementedError(f"diary({self.LOG_NAME}.txt');")

# update command line status
if self.time_rev:
logging.log(logging.INFO, " time reversal mode")
Expand Down Expand Up @@ -1206,7 +1201,7 @@ def smooth_and_enlarge(self, source, k_dim, kgrid_N, opt: SimulationOptions) ->
# update command line status
logging.log(logging.INFO, " smoothing p0 distribution...")

if self.options.simulation_type.is_axisymmetric():
if self.options.simulation_type.is_axisymmetric:
if self.options.radial_symmetry in ["WSWA-FFT", "WSWA"]:
# create a new kWave grid object with expanded radial grid
kgrid_exp = kWaveGrid([kgrid_N.x, kgrid_N.y * 4], [self.kgrid.dx, self.kgrid.dy])
Expand Down Expand Up @@ -1258,7 +1253,7 @@ def smooth_and_enlarge(self, source, k_dim, kgrid_N, opt: SimulationOptions) ->
),
dotdict(
{
"axisymmetric": self.options.simulation_type.is_axisymmetric(),
"axisymmetric": self.options.simulation_type.is_axisymmetric,
"use_sensor": self.use_sensor,
"blank_sensor": self.blank_sensor,
"cuboid_corners": self.cuboid_corners,
Expand All @@ -1280,7 +1275,7 @@ def smooth_and_enlarge(self, source, k_dim, kgrid_N, opt: SimulationOptions) ->
self.kgrid, self.index_data_type, self.p_source_pos_index, self.u_source_pos_index, self.s_source_pos_index = expand_results

# get maximum prime factors
if self.options.simulation_type.is_axisymmetric():
if self.options.simulation_type.is_axisymmetric:
prime_facs = self.kgrid.highest_prime_factors(self.options.radial_symmetry[:4])
else:
prime_facs = self.kgrid.highest_prime_factors()
Expand Down Expand Up @@ -1367,7 +1362,7 @@ def create_absorption_vars(self) -> None:
Returns:
None
"""
if not self.options.simulation_type.is_elastic_simulation() and not self.options.save_to_disk:
if not self.options.simulation_type.is_elastic and not self.options.save_to_disk:
self.absorb_nabla1, self.absorb_nabla2, self.absorb_tau, self.absorb_eta = create_absorption_variables(
self.kgrid, self.medium, self.equation_of_state
)
Expand Down
2 changes: 1 addition & 1 deletion kwave/kWaveSimulation_helper/save_to_disk_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def save_to_disk_func(
# =========================================================================

remove_z_dimension(float_variables, kgrid.dim)
save_file(opt.input_filename, integer_variables, float_variables, opt.hdf_compression_level, auto_chunk=auto_chunk)
save_file(opt.input_filename, integer_variables, float_variables, opt.compression_level, auto_chunk=auto_chunk)

# update command line status
logging.log(logging.INFO, " completed in ", scale_time(TicToc.toc()))
Expand Down
2 changes: 1 addition & 1 deletion kwave/kWaveSimulation_helper/set_sound_speed_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def set_sound_speed_ref(medium: kWaveMedium, simulation_type: SimulationType):
Returns:

"""
if not simulation_type.is_elastic_simulation():
if not simulation_type.is_elastic:
return get_ordinary_sound_speed_ref(medium)
elif simulation_type == SimulationType.ELASTIC: # pragma: no cover
return get_pstd_elastic_sound_speed_ref(medium)
Expand Down
4 changes: 2 additions & 2 deletions kwave/kspaceFirstOrder2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ def kspaceFirstOrder2D(
"source_syz": k_sim.source_syz,
"transducer_source": k_sim.transducer_source,
"nonuniform_grid": k_sim.nonuniform_grid,
"elastic_code": k_sim.options.simulation_type.is_elastic_simulation(),
"axisymmetric": k_sim.options.simulation_type.is_axisymmetric(),
"elastic_code": k_sim.options.simulation_type.is_elastic,
"axisymmetric": k_sim.options.simulation_type.is_axisymmetric,
"cuboid_corners": k_sim.cuboid_corners,
}
),
Expand Down
4 changes: 2 additions & 2 deletions kwave/kspaceFirstOrder3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ def kspaceFirstOrder3D(
"source_syz": k_sim.source_syz,
"transducer_source": k_sim.transducer_source,
"nonuniform_grid": k_sim.nonuniform_grid,
"elastic_code": k_sim.options.simulation_type.is_elastic_simulation(),
"axisymmetric": k_sim.options.simulation_type.is_axisymmetric(),
"elastic_code": k_sim.options.simulation_type.is_elastic,
"axisymmetric": k_sim.options.simulation_type.is_axisymmetric,
"cuboid_corners": k_sim.cuboid_corners,
}
),
Expand Down
4 changes: 2 additions & 2 deletions kwave/kspaceFirstOrderAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ def kspaceFirstOrderAS(
"source_syz": k_sim.source_syz,
"transducer_source": k_sim.transducer_source,
"nonuniform_grid": k_sim.nonuniform_grid,
"elastic_code": k_sim.options.simulation_type.is_elastic_simulation(),
"axisymmetric": k_sim.options.simulation_type.is_axisymmetric(),
"elastic_code": k_sim.options.simulation_type.is_elastic,
"axisymmetric": k_sim.options.simulation_type.is_axisymmetric,
"cuboid_corners": k_sim.cuboid_corners,
}
),
Expand Down
Loading
Loading