<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Basic example
In this notebook we show how to perform a basic simulation.
Step1:  Configuration
The following are the parameters for our simulation
Step2:  Create model
We now create a model. Waves propagate in a medium which we define first.
Step3:  The model is only finite and to prevent aliasing we need a Perfectly Matched Layer.
Step4:  Now we create the actual model.
Step5:  In this example our source excites a pulse.
Step6:  We also add a receiver on the other side of the domain
Step7:  Check model
To get a quick overview of all parameters, for example to check them, we can print one
Step8:  To check whether the geometry is as we want it to be, we can simply draw it.
Step9:  Running the simulation
Now that we've defined and checked our model we can run it.
With model.run() you can specify the amount of time steps or amount of seconds it should run.
Step10:  Let's see how the sound pressure field looks like now.
Step11:  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.
Step12:  as you can see.
Step13:  Recordings
The receivers can record a quantity at a specific location. In this case, we're measuring an impulse response. The method receiver.recording() returns an instance of acoustics.Signal.
Step14:  If however, you want to restart the simulation you can do so with model.restart().
Step15:  Show log
Some simulations can take a very long time. To check how far the simulation is, you can check the log.
Step16:  When we now run the simulation, you will see which step it is at.
<ASSISTANT_TASK:>
Python Code:
import sys
sys.path.append("..")
import numpy as np
from pstd import PSTD, PML, Medium, PointSource
from acoustics import Signal
#import seaborn as sns
%matplotlib inline
Explanation: Basic example
In this notebook we show how to perform a basic simulation.
End of explanation
x = 30.0
y = 20.0
z = 0.0
soundspeed = 343.2
density = 1.296
maximum_frequency_target = 200.0
Explanation: Configuration
The following are the parameters for our simulation
End of explanation
medium = Medium(soundspeed=soundspeed, density=density)
Explanation: Create model
We now create a model. Waves propagate in a medium which we define first.
End of explanation
pml = PML(absorption_coefficient=(1000.0, 1000.0), depth=10.0)
Explanation: The model is only finite and to prevent aliasing we need a Perfectly Matched Layer.
End of explanation
model = PSTD(
    maximum_frequency=maximum_frequency_target,
    pml=pml,
    medium=medium,
    cfl=None,
    size=[x, y]
)
Explanation: Now we create the actual model.
End of explanation
source_position = (x/4.0, y/2.0)
source = model.add_object('source', 'PointSource', position=source_position, 
                          excitation='pulse', quantity='pressure', amplitude=0.1)
Explanation: In this example our source excites a pulse.
End of explanation
receiver_position = (x*3.0/4.0, y/2.0)
receiver = model.add_object('receiver', 'Receiver', position=receiver_position, quantity='pressure')
Explanation: We also add a receiver on the other side of the domain
End of explanation
print(model.overview())
Explanation: Check model
To get a quick overview of all parameters, for example to check them, we can print one
End of explanation
_ = model.plot_scene()
Explanation: To check whether the geometry is as we want it to be, we can simply draw it.
End of explanation
model.run(seconds=0.002)
Explanation: Running the simulation
Now that we've defined and checked our model we can run it.
With model.run() you can specify the amount of time steps or amount of seconds it should run.
End of explanation
_ = model.plot_field()
Explanation: Let's see how the sound pressure field looks like now.
End of explanation
%%prun
model.run(seconds=0.06)
Explanation: 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.
End of explanation
_ = model.plot_field()
Explanation: as you can see.
End of explanation
_ = receiver.recording().plot()
Explanation: Recordings
The receivers can record a quantity at a specific location. In this case, we're measuring an impulse response. The method receiver.recording() returns an instance of acoustics.Signal.
End of explanation
model.restart()
Explanation: If however, you want to restart the simulation you can do so with model.restart().
End of explanation
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
Explanation: Show log
Some simulations can take a very long time. To check how far the simulation is, you can check the log.
End of explanation
model.run(steps=10)
_ = model.plot_field()
Explanation: When we now run the simulation, you will see which step it is at.
End of explanation
<END_TASK>