In [1]:
Copied!
import numpy as np
from jax import jit
from jax import numpy as jnp
from jwave import FourierSeries
from jwave.geometry import Domain, Medium, TimeAxis
from jwave.acoustics import simulate_wave_propagation
from jwave.geometry import circ_mask
domain = Domain((128, 128), (0.1e-3, 0.1e-3))
import numpy as np
from jax import jit
from jax import numpy as jnp
from jwave import FourierSeries
from jwave.geometry import Domain, Medium, TimeAxis
from jwave.acoustics import simulate_wave_propagation
from jwave.geometry import circ_mask
domain = Domain((128, 128), (0.1e-3, 0.1e-3))
In [2]:
Copied!
# Defining an heterogeneous density map
density = np.ones(domain.N) * 1000
density[50:90, 65:100] = 2300
density = FourierSeries(np.expand_dims(density, -1), domain)
medium = Medium(domain=domain, sound_speed=1500.0, density=density)
time_axis = TimeAxis.from_medium(medium, cfl=0.3)
# Defining the initial pressure
N = domain.N
p0 = circ_mask(N, 3, (64, 30))
p0 = 1.0 * jnp.expand_dims(p0, -1)
p0 = FourierSeries(p0, domain)
# Defining an heterogeneous density map
density = np.ones(domain.N) * 1000
density[50:90, 65:100] = 2300
density = FourierSeries(np.expand_dims(density, -1), domain)
medium = Medium(domain=domain, sound_speed=1500.0, density=density)
time_axis = TimeAxis.from_medium(medium, cfl=0.3)
# Defining the initial pressure
N = domain.N
p0 = circ_mask(N, 3, (64, 30))
p0 = 1.0 * jnp.expand_dims(p0, -1)
p0 = FourierSeries(p0, domain)
No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
In [3]:
Copied!
medium = Medium(domain=domain, sound_speed=1500.0, density=density)
pressure = simulate_wave_propagation(medium, time_axis, p0=p0)
medium = Medium(domain=domain, sound_speed=1500.0, density=density)
pressure = simulate_wave_propagation(medium, time_axis, p0=p0)
In [4]:
Copied!
from jwave.extras.export import save_video
save_video(pressure, './sample_video.mp4', vmax=0.05, vmin=-0.05, fps=50)
from jwave.extras.export import save_video
save_video(pressure, './sample_video.mp4', vmax=0.05, vmin=-0.05, fps=50)
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 599/599 [00:01<00:00, 347.57it/s]
You can now find a video in the same folder as this notebook
In [ ]:
Copied!