Point sources¶
In [1]:
Copied!
import numpy as np
from jax import jit
from jaxdf import FourierSeries
from matplotlib import pyplot as plt
from jwave.acoustics import simulate_wave_propagation
from jwave.geometry import *
from jwave.signal_processing import analytic_signal, apply_ramp, gaussian_window, smooth
from jwave.utils import show_field, show_positive_field
domain = Domain((128, 128), (0.1e-3, 0.1e-3))
import numpy as np
from jax import jit
from jaxdf import FourierSeries
from matplotlib import pyplot as plt
from jwave.acoustics import simulate_wave_propagation
from jwave.geometry import *
from jwave.signal_processing import analytic_signal, apply_ramp, gaussian_window, smooth
from jwave.utils import show_field, show_positive_field
domain = Domain((128, 128), (0.1e-3, 0.1e-3))
Medium properties¶
In [2]:
Copied!
density = np.ones(domain.N) * 1000
density[50:90, 65:100] = 2300
density = FourierSeries(np.expand_dims(density, -1), domain)
show_positive_field(density)
density = np.ones(domain.N) * 1000
density[50:90, 65:100] = 2300
density = FourierSeries(np.expand_dims(density, -1), domain)
show_positive_field(density)
In [3]:
Copied!
medium = Medium(domain=domain, sound_speed=1500.0, density=density)
time_axis = TimeAxis.from_medium(medium, cfl=0.3)
medium = Medium(domain=domain, sound_speed=1500.0, density=density)
time_axis = TimeAxis.from_medium(medium, cfl=0.3)
In [4]:
Copied!
t = jnp.arange(0, time_axis.t_end, time_axis.dt)
s = jnp.sin(2 * jnp.pi * 4e6 * t)
s1 = gaussian_window(s, t, 2e-6, 4e-7)
s2 = gaussian_window(s, t, 5e-6, 4e-7)
plt.plot(s1)
plt.plot(s2)
t = jnp.arange(0, time_axis.t_end, time_axis.dt)
s = jnp.sin(2 * jnp.pi * 4e6 * t)
s1 = gaussian_window(s, t, 2e-6, 4e-7)
s2 = gaussian_window(s, t, 5e-6, 4e-7)
plt.plot(s1)
plt.plot(s2)
Out[4]:
[<matplotlib.lines.Line2D at 0x7efeb845be80>]
In [5]:
Copied!
from jwave.geometry import Sources
sources = Sources(
positions=((28, 64), (32, 32)),
signals=jnp.stack([s1, s2]),
dt=time_axis.dt,
domain=domain,
)
from jwave.geometry import Sources
sources = Sources(
positions=((28, 64), (32, 32)),
signals=jnp.stack([s1, s2]),
dt=time_axis.dt,
domain=domain,
)
In [6]:
Copied!
@jit
def compiled_simulator(sources):
return simulate_wave_propagation(medium, time_axis, sources=sources)
@jit
def compiled_simulator(sources):
return simulate_wave_propagation(medium, time_axis, sources=sources)
In [7]:
Copied!
pressure = compiled_simulator(sources)
pressure = compiled_simulator(sources)
In [8]:
Copied!
t = 300
show_field(pressure[t])
plt.title(f"Pressure field at t={time_axis.to_array()[t]}")
t = 300
show_field(pressure[t])
plt.title(f"Pressure field at t={time_axis.to_array()[t]}")
Out[8]:
Text(0.5, 1.0, 'Pressure field at t=5.999999757477781e-06')