Added a pre-commit config file and reformatted all the files accordingly by using it.

这个提交包含在:
Sai-Suraj-27
2023-06-26 16:09:39 +05:30
父节点 c71e87e34f
当前提交 f9dd7f2420
共有 155 个文件被更改,包括 11383 次插入8802 次删除

查看文件

@@ -23,14 +23,14 @@ from gprMax.waveforms import Waveform
def hertzian_dipole_fs(iterations, dt, dxdydz, rx):
"""Analytical solution of a z-directed Hertzian dipole in free space with a
"""Analytical solution of a z-directed Hertzian dipole in free space with a
Gaussian current waveform (http://dx.doi.org/10.1016/0021-9991(83)90103-1).
Args:
iterations: int for number of time steps.
dt: float for time step (seconds).
dxdydz: tuple of floats for spatial resolution (metres).
rx: tuple of floats for coordinates of receiver position relative to
rx: tuple of floats for coordinates of receiver position relative to
transmitter position (metres).
Returns:
@@ -39,25 +39,25 @@ def hertzian_dipole_fs(iterations, dt, dxdydz, rx):
# Waveform
w = Waveform()
w.type = 'gaussianprime'
w.type = "gaussianprime"
w.amp = 1
w.freq = 1e9
# Waveform integral
wint = Waveform()
wint.type = 'gaussian'
wint.type = "gaussian"
wint.amp = w.amp
wint.freq = w.freq
# Waveform first derivative
wdot = Waveform()
wdot.type = 'gaussiandoubleprime'
wdot.type = "gaussiandoubleprime"
wdot.amp = w.amp
wdot.freq = w.freq
# Time
time = np.linspace(0, 1, iterations)
time *= (iterations * dt)
time *= iterations * dt
# Spatial resolution
dx = dxdydz[0]
@@ -77,43 +77,42 @@ def hertzian_dipole_fs(iterations, dt, dxdydz, rx):
Ex_y = y
Ex_z = z - 0.5 * dz
Er_x = np.sqrt((Ex_x**2 + Ex_y**2 + Ex_z**2))
tau_Ex = Er_x / config.sim_config.em_consts['c']
tau_Ex = Er_x / config.sim_config.em_consts["c"]
# Coordinates of Rx for Ey FDTD component
Ey_x = x
Ey_y = y + 0.5 * dy
Ey_z = z - 0.5 * dz
Er_y = np.sqrt((Ey_x**2 + Ey_y**2 + Ey_z**2))
tau_Ey = Er_y / config.sim_config.em_consts['c']
tau_Ey = Er_y / config.sim_config.em_consts["c"]
# Coordinates of Rx for Ez FDTD component
Ez_x = x
Ez_y = y
Ez_z = z
Er_z = np.sqrt((Ez_x**2 + Ez_y**2 + Ez_z**2))
tau_Ez = Er_z / config.sim_config.em_consts['c']
tau_Ez = Er_z / config.sim_config.em_consts["c"]
# Coordinates of Rx for Hx FDTD component
Hx_x = x
Hx_y = y + 0.5 * dy
Hx_z = z
Hr_x = np.sqrt((Hx_x**2 + Hx_y**2 + Hx_z**2))
tau_Hx = Hr_x / config.sim_config.em_consts['c']
tau_Hx = Hr_x / config.sim_config.em_consts["c"]
# Coordinates of Rx for Hy FDTD component
Hy_x = x + 0.5 * dx
Hy_y = y
Hy_z = z
Hr_y = np.sqrt((Hy_x**2 + Hy_y**2 + Hy_z**2))
tau_Hy = Hr_y / config.sim_config.em_consts['c']
tau_Hy = Hr_y / config.sim_config.em_consts["c"]
# Initialise fields
fields = np.zeros((iterations, 6))
# Calculate fields
for timestep in range(iterations):
# Calculate values for waveform, I * dl (current multiplied by dipole
# Calculate values for waveform, I * dl (current multiplied by dipole
# length) to match gprMax behaviour
fint_Ex = wint.calculate_value((timestep * dt) - tau_Ex, dt) * dl
f_Ex = w.calculate_value((timestep * dt) - tau_Ex, dt) * dl
@@ -134,31 +133,36 @@ def hertzian_dipole_fs(iterations, dt, dxdydz, rx):
fdot_Hy = wdot.calculate_value((timestep * dt) - tau_Hy, dt) * dl
# Ex
fields[timestep, 0] = (((Ex_x * Ex_z) / (4 * np.pi * config.sim_config.em_consts['e0'] * Er_x**5)) *
(3 * (fint_Ex + (tau_Ex * f_Ex)) + (tau_Ex**2 * fdot_Ex)))
fields[timestep, 0] = ((Ex_x * Ex_z) / (4 * np.pi * config.sim_config.em_consts["e0"] * Er_x**5)) * (
3 * (fint_Ex + (tau_Ex * f_Ex)) + (tau_Ex**2 * fdot_Ex)
)
# Ey
try:
tmp = Ey_y / Ey_x
except ZeroDivisionError:
tmp = 0
fields[timestep, 1] = (tmp * ((Ey_x * Ey_z) / (4 * np.pi * config.sim_config.em_consts['e0'] * Er_y**5)) *
(3 * (fint_Ey + (tau_Ey * f_Ey)) + (tau_Ey**2 * fdot_Ey)))
fields[timestep, 1] = (
tmp
* ((Ey_x * Ey_z) / (4 * np.pi * config.sim_config.em_consts["e0"] * Er_y**5))
* (3 * (fint_Ey + (tau_Ey * f_Ey)) + (tau_Ey**2 * fdot_Ey))
)
# Ez
fields[timestep, 2] = ((1 / (4 * np.pi * config.sim_config.em_consts['e0'] * Er_z**5)) *
((2 * Ez_z**2 - (Ez_x**2 + Ez_y**2)) * (fint_Ez + (tau_Ez * f_Ez)) -
(Ez_x**2 + Ez_y**2) * tau_Ez**2 * fdot_Ez))
fields[timestep, 2] = (1 / (4 * np.pi * config.sim_config.em_consts["e0"] * Er_z**5)) * (
(2 * Ez_z**2 - (Ez_x**2 + Ez_y**2)) * (fint_Ez + (tau_Ez * f_Ez))
- (Ez_x**2 + Ez_y**2) * tau_Ez**2 * fdot_Ez
)
# Hx
fields[timestep, 3] = - (Hx_y / (4 * np.pi * Hr_x**3)) * (f_Hx + (tau_Hx * fdot_Hx))
fields[timestep, 3] = -(Hx_y / (4 * np.pi * Hr_x**3)) * (f_Hx + (tau_Hx * fdot_Hx))
# Hy
try:
tmp = Hy_x / Hy_y
except ZeroDivisionError:
tmp = 0
fields[timestep, 4] = - tmp * (- (Hy_y / (4 * np.pi * Hr_y**3)) * (f_Hy + (tau_Hy * fdot_Hy)))
fields[timestep, 4] = -tmp * (-(Hy_y / (4 * np.pi * Hr_y**3)) * (f_Hy + (tau_Hy * fdot_Hy)))
# Hz
fields[timestep, 5] = 0