In [1]:
import numpy as np
from pstd import PSTD, PML, Medium, PointSource
from acoustics import Signal
import seaborn as sns
%matplotlib inline
In [2]:
x = 30.0
y = 20.0
z = 0.0
soundspeed = 343.2
density = 1.296
maximum_frequency_target = 200.0
In [3]:
medium = Medium(soundspeed=soundspeed, density=density)
The model is only finite and to prevent aliasing we need a Perfectly Matched Layer.
In [4]:
pml = PML(absorption_coefficient=(1000.0, 1000.0), depth=10.0)
Now we create the actual model.
In [5]:
model = PSTD(maximum_frequency=maximum_frequency_target, pml=pml, medium=medium, cfl=0.05, size=[x, y])
In this example our source excites a pulse.
In [6]:
source_position = (x/4.0, y/2.0)
source = model.add_object('source', 'PointSource', position=source_position,
excitation='pulse', quantity='pressure', amplitude=0.1)
We also add a receiver on the other side of the domain
In [7]:
receiver_position = (x*3.0/4.0, y/2.0)
receiver = model.add_object('receiver', 'Receiver', position=receiver_position, quantity='pressure')
In [8]:
print(model.overview())
To check whether the geometry is as we want it to be, we can simply draw it.
In [9]:
_ = model.plot_scene()
With model.run() you can specify the amount of time steps or amount of seconds it should run.
In [10]:
model.run(seconds=0.002)
Out[10]:
Let's see how the sound pressure field looks like now.
In [11]:
_ = model.plot_field()
It might happen that you realize that you actually need to calculate a bit further. This can easily be done, since the state is remembered. Simply use model.run() again and the simulation continues.
In [12]:
model.run(seconds=0.060)
Out[12]:
as you can see.
In [13]:
_ = model.plot_field()
In [14]:
_ = receiver.recording().plot()
If however, you want to restart the simulation you can do so with model.restart().
In [15]:
model.restart()
Out[15]:
In [16]:
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
When we now run the simulation, you will see which step it is at.
In [17]:
model.run(steps=10)
Out[17]:
In [18]:
_ = model.plot_field()