<jupyter_start><jupyter_text>Basic exampleIn this notebook we show how to perform a basic simulation.<jupyter_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<jupyter_output><empty_output><jupyter_text>ConfigurationThe following are the parameters for our simulation<jupyter_code>x = 30.0
y = 20.0
z = 0.0

soundspeed = 343.2
density = 1.296
maximum_frequency_target = 200.0<jupyter_output><empty_output><jupyter_text>Create modelWe now create a model. Waves propagate in a medium which we define first.<jupyter_code>medium = Medium(soundspeed=soundspeed, density=density)<jupyter_output><empty_output><jupyter_text>The model is only finite and to prevent aliasing we need a Perfectly Matched Layer.<jupyter_code>pml = PML(absorption_coefficient=(1000.0, 1000.0), depth=10.0)<jupyter_output><empty_output><jupyter_text>Now we create the actual model.<jupyter_code>model = PSTD(
    maximum_frequency=maximum_frequency_target,
    pml=pml,
    medium=medium,
    cfl=None,
    size=[x, y]
)<jupyter_output><empty_output><jupyter_text>In this example our source excites a pulse.<jupyter_code>source_position = (x/4.0, y/2.0)

source = model.add_object('source', 'PointSource', position=source_position, 
                          excitation='pulse', quantity='pressure', amplitude=0.1)<jupyter_output><empty_output><jupyter_text>We also add a receiver on the other side of the domain<jupyter_code>receiver_position = (x*3.0/4.0, y/2.0)

receiver = model.add_object('receiver', 'Receiver', position=receiver_position, quantity='pressure')<jupyter_output><empty_output><jupyter_text>Check modelTo get a quick overview of all parameters, for example to check them, we can print one<jupyter_code>print(model.overview())<jupyter_output><empty_output><jupyter_text>To check whether the geometry is as we want it to be, we can simply draw it.<jupyter_code>_ = model.plot_scene()<jupyter_output><empty_output><jupyter_text>Running the simulationNow 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.<jupyter_code>model.run(seconds=0.002)<jupyter_output><empty_output><jupyter_text>Let's see how the sound pressure field looks like now.<jupyter_code>_ = model.plot_field()<jupyter_output><empty_output><jupyter_text>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.<jupyter_code>%%prun
model.run(seconds=0.06)<jupyter_output><empty_output><jupyter_text>as you can see.<jupyter_code>_ = model.plot_field()<jupyter_output><empty_output><jupyter_text>RecordingsThe 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`.<jupyter_code>_ = receiver.recording().plot()<jupyter_output><empty_output><jupyter_text>If however, you want to restart the simulation you can do so with `model.restart()`.<jupyter_code>model.restart()<jupyter_output><empty_output><jupyter_text>Show logSome simulations can take a very long time. To check how far the simulation is, you can check the log.<jupyter_code>import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)<jupyter_output><empty_output><jupyter_text>When we now run the simulation, you will see which step it is at.<jupyter_code>model.run(steps=10)
_ = model.plot_field()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0988499452354874, 'fraction_numerical': 0.014786418400876232, 'mean_word_length': 6.958605664488018, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '443359', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1180, 'n_words': 321, 'path': 'examples/basic_example.ipynb', 'repo_name': 'FRidh/pstd', 'size': '3652'}