In the tools
sub-package is a module called plot_source_wave
which can be used to plot any of the builtin waveforms in time and frequency domains. The module takes the following arguments:
type
is the type of the waveform, e.g. rickeramp
is the amplitude of the waveformfreq
is the centre frequency of the waveformtimewindow
is the time window used to view the waveform, i.e. the time window of the proposed simulationdt
is the time step used to view the waveform, i.e. the time step of the proposed simulationThere is an optional argument:
-fft
a switch to turn on the FFT plotting for a single field component or currentFor example (to use the module outside this notebook) to plot a Ricker waveform (and FFT) with an amplitude of 1, centre frequency of 1.5GHz and with a time window of 3ns and time step of 1.926ps:
python -m tools.plot_source_wave ricker 1 1.5e9 3e-9 1.926e-12 -fft
You can use the following code to experiment (in this notebook) with plotting different waveforms.
In [1]:
%matplotlib inline
from gprMax.waveforms import Waveform
from tools.plot_source_wave import check_timewindow, mpl_plot
w = Waveform()
w.type = 'ricker'
w.amp = 1
w.freq = 25e6
timewindow = 300e-9
dt = 8.019e-11
timewindow, iterations = check_timewindow(timewindow, dt)
plt = mpl_plot(w, timewindow, dt, iterations, fft=True)
In [2]:
%matplotlib inline
import numpy as np
from gprMax.waveforms import Waveform
from tools.plot_source_wave import check_timewindow, mpl_plot
waveformvalues = np.loadtxt('/Users/cwarren/Desktop/sajad/SW_corrected.txt', skiprows=1, dtype=np.float32)
w = Waveform()
w.type = 'user'
w.amp = 1
w.freq = 0
w.uservalues = waveformvalues[:]
timewindow = 2e-9
dt = 4.71731e-12
timewindow, iterations = check_timewindow(timewindow, dt)
w.uservalues = np.zeros(iterations, dtype=np.float32)
w.uservalues[0:len(waveformvalues)] = waveformvalues[:]
plt = mpl_plot(w, timewindow, dt, iterations, fft=True)
In [10]:
from math import sqrt
# Speed of light in vacuum (m/s)
c = 299792458
# Highest relative permittivity present in model
er = 81
# Maximum frequency present in model
fmax = 80e6
# Minimum wavelength
wmin = c / (fmax * sqrt(er))
# Maximum spatial resolution (allowing 10 cells per wavelength)
dmin = wmin / 10
# Time steps at CFL limits for cubic cells
dt3D = dmin / (sqrt(3) * c)
dt2D = dmin / (sqrt(2) * c)
print('Minimum wavelength: {:g} m'.format(wmin))
print('Maximum spatial resolution: {:g} m'.format(dmin))
print('Time step for 3D cubic cell: {:g} s'.format(dt3D))
print('Time step for 2D square cell: {:g} s'.format(dt2D))