Skip to content

Commit c4fe6c2

Browse files
committed
Update kspaceFirstOrder1D.py
1 parent ef39cb8 commit c4fe6c2

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

kwave/kspaceFirstOrder1D.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from typing import Union
22

3-
from kwave.options.simulation_execution_options import SimulationExecutionOptions
4-
53
try:
64
import cupy as cp
75
from cupy import fft as cp_fft
@@ -50,7 +48,7 @@ def get_array_module(verbose: bool = False):
5048
ngpus = cp.cuda.runtime.getDeviceCount()
5149
if ngpus > 0:
5250
return cp, True
53-
except Exception:
51+
except Exception(ImportError, RuntimeError, cp.cuda.runtime.CUDARuntimeError):
5452
pass
5553

5654
# Fallback (cupy but no gpu) to numpy
@@ -73,7 +71,7 @@ def dotdict_to_gpu(obj, verbose: bool = False):
7371
if isinstance(val, np.ndarray):
7472
if verbose:
7573
print(f"Converting {name} to cupy array")
76-
setattr(obj, name, cp.asarray(val))
74+
obj[name] = cp.asarray(val)
7775
return obj
7876

7977

@@ -86,7 +84,7 @@ def dotdict_to_cpu(obj, verbose: bool = False):
8684
if isinstance(val, cp.ndarray):
8785
if verbose:
8886
print(f"Converting {name} to numpy array")
89-
setattr(obj, name, val.get())
87+
obj[name] = val.get()
9088
return obj
9189

9290

@@ -514,7 +512,7 @@ def kspace_first_order_1D(kgrid: kWaveGrid,
514512

515513

516514
# add in the velocity source term
517-
if (k_sim.source_ux is not False and t_index < xp.shape(source.ux)[1]):
515+
if (k_sim.source_ux is not False and t_index < source.ux.shape[1]):
518516
if k_sim.source_ux >= t_index:
519517
match source.u_mode:
520518
case 'dirichlet':
@@ -564,7 +562,7 @@ def kspace_first_order_1D(kgrid: kWaveGrid,
564562

565563

566564
# add in the pre-scaled pressure source term as a mass source
567-
if (k_sim.source_p is not False and t_index < xp.shape(k_sim.source.p)[1]):
565+
if (k_sim.source_p is not False and t_index < k_sim.source.p.shape[1]):
568566
match k_sim.source.p_mode:
569567
case 'dirichlet':
570568
# enforce source values as a dirichlet boundary condition

0 commit comments

Comments
 (0)