Updated with ruff formatter

这个提交包含在:
Craig Warren
2025-02-04 20:38:27 +00:00
父节点 e2c5a23f28
当前提交 548a0a550c
共有 70 个文件被更改,包括 3601 次插入982 次删除

查看文件

@@ -157,14 +157,18 @@ def hertzian_dipole_fs(iterations, dt, dxdydz, rx):
)
# 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

查看文件

@@ -1,9 +1,8 @@
"""A series of models with different domain sizes used for benchmarking.
The domain is free space with a simple source (Hertzian Dipole) and
receiver at the centre.
The domain is free space with a simple source (Hertzian Dipole) and
receiver at the centre.
"""
import itertools
from pathlib import Path
@@ -36,7 +35,9 @@ for d, threads in itertools.product(domains, ompthreads):
dxdydz = gprMax.Discretisation(p1=(dl, dl, dl))
time_window = gprMax.TimeWindow(time=3e-9)
wv = gprMax.Waveform(wave_type="gaussiandotnorm", amp=1, freq=900e6, id="MySource")
src = gprMax.HertzianDipole(p1=(x / 2, y / 2, z / 2), polarisation="x", waveform_id="MySource")
src = gprMax.HertzianDipole(
p1=(x / 2, y / 2, z / 2), polarisation="x", waveform_id="MySource"
)
omp = gprMax.OMPThreads(n=threads)

查看文件

@@ -60,9 +60,13 @@ def diff_output_files(filename1, filename2):
# Arrays for storing time
time1 = np.zeros((file1.attrs["Iterations"]), dtype=floattype1)
time1 = np.linspace(0, (file1.attrs["Iterations"] - 1), num=file1.attrs["Iterations"])
time1 = np.linspace(
0, (file1.attrs["Iterations"] - 1), num=file1.attrs["Iterations"]
)
time2 = np.zeros((file2.attrs["Iterations"]), dtype=floattype2)
time2 = np.linspace(0, (file2.attrs["Iterations"] - 1), num=file2.attrs["Iterations"])
time2 = np.linspace(
0, (file2.attrs["Iterations"] - 1), num=file2.attrs["Iterations"]
)
# Arrays for storing field data
data1 = np.zeros((file1.attrs["Iterations"], len(outputs1)), dtype=floattype1)
@@ -82,7 +86,10 @@ def diff_output_files(filename1, filename2):
for i in range(len(outputs2)):
maxi = np.amax(np.abs(data1[:, i]))
datadiffs[:, i] = np.divide(
np.abs(data2[:, i] - data1[:, i]), maxi, out=np.zeros_like(data1[:, i]), where=maxi != 0
np.abs(data2[:, i] - data1[:, i]),
maxi,
out=np.zeros_like(data1[:, i]),
where=maxi != 0,
) # Replace any division by zero with zero
# Calculate power (ignore warning from taking a log of any zero values)

查看文件

@@ -46,12 +46,16 @@ maxerrors = []
testmodels = [basename + "_" + s for s in PMLIDs]
fig, ax = plt.subplots(
subplot_kw=dict(xlabel="Iterations", ylabel="Error [dB]"), figsize=(20, 10), facecolor="w", edgecolor="w"
subplot_kw=dict(xlabel="Iterations", ylabel="Error [dB]"),
figsize=(20, 10),
facecolor="w",
edgecolor="w",
)
for x, model in enumerate(testmodels):
time, datadiffs = diff_output_files(
fn.parent.joinpath(basename + "_ref.h5"), fn.parent.joinpath(basename + str(x + 1) + ".h5")
fn.parent.joinpath(basename + "_ref.h5"),
fn.parent.joinpath(basename + str(x + 1) + ".h5"),
)
# Print maximum error value
@@ -60,7 +64,14 @@ for x, model in enumerate(testmodels):
logger.info(f"{model}: Max. error {maxerrors[x]}")
# Plot diffs (select column to choose field component, 0-Ex, 1-Ey etc..)
ax.plot(time[start::], datadiffs[start::, 1], color=next(colors), lw=2, ls=next(lines), label=model)
ax.plot(
time[start::],
datadiffs[start::, 1],
color=next(colors),
lw=2,
ls=next(lines),
label=model,
)
ax.set_xticks(np.arange(0, 2200, step=100))
ax.set_xlim([0, 2100])
ax.set_yticks(np.arange(-160, 0, step=20))

查看文件

@@ -21,11 +21,17 @@ dxdydz = gprMax.Discretisation(p1=(dl, dl, dl))
time_window = gprMax.TimeWindow(iterations=2100)
tssf = gprMax.TimeStepStabilityFactor(f=0.99)
waveform = gprMax.Waveform(wave_type="gaussiandotnorm", amp=1, freq=9.42e9, id="mypulse")
hertzian_dipole = gprMax.HertzianDipole(polarisation="z", p1=(0.013, 0.013, 0.014), waveform_id="mypulse")
waveform = gprMax.Waveform(
wave_type="gaussiandotnorm", amp=1, freq=9.42e9, id="mypulse"
)
hertzian_dipole = gprMax.HertzianDipole(
polarisation="z", p1=(0.013, 0.013, 0.014), waveform_id="mypulse"
)
rx = gprMax.Rx(p1=(0.038, 0.114, 0.013))
plate = gprMax.Plate(p1=(0.013, 0.013, 0.013), p2=(0.038, 0.113, 0.013), material_id="pec")
plate = gprMax.Plate(
p1=(0.013, 0.013, 0.013), p2=(0.038, 0.113, 0.013), material_id="pec"
)
gv1 = gprMax.GeometryView(
p1=(0, 0, 0),

查看文件

@@ -21,11 +21,17 @@ dxdydz = gprMax.Discretisation(p1=(dl, dl, dl))
time_window = gprMax.TimeWindow(iterations=2100)
tssf = gprMax.TimeStepStabilityFactor(f=0.99)
waveform = gprMax.Waveform(wave_type="gaussiandotnorm", amp=1, freq=9.42e9, id="mypulse")
hertzian_dipole = gprMax.HertzianDipole(polarisation="z", p1=(0.088, 0.088, 0.089), waveform_id="mypulse")
waveform = gprMax.Waveform(
wave_type="gaussiandotnorm", amp=1, freq=9.42e9, id="mypulse"
)
hertzian_dipole = gprMax.HertzianDipole(
polarisation="z", p1=(0.088, 0.088, 0.089), waveform_id="mypulse"
)
rx = gprMax.Rx(p1=(0.113, 0.189, 0.088))
plate = gprMax.Plate(p1=(0.088, 0.088, 0.088), p2=(0.113, 0.188, 0.088), material_id="pec")
plate = gprMax.Plate(
p1=(0.088, 0.088, 0.088), p2=(0.113, 0.188, 0.088), material_id="pec"
)
gv1 = gprMax.GeometryView(
p1=(0, 0, 0),

查看文件

@@ -74,7 +74,13 @@ for x, PMLID in enumerate(PMLIDs):
ax.set_ylabel(f"{output} error [dB]")
# Save a PDF/PNG of the figure
fig.savefig(basename + "_diffs_" + PMLID + ".pdf", dpi=None, format="pdf", bbox_inches="tight", pad_inches=0.1)
fig.savefig(
basename + "_diffs_" + PMLID + ".pdf",
dpi=None,
format="pdf",
bbox_inches="tight",
pad_inches=0.1,
)
# fig.savefig(basename + "_diffs_" + PMLID + ".png", dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
plt.show()

查看文件

@@ -18,7 +18,9 @@ dxdydz = gprMax.Discretisation(p1=(dl, dl, dl))
time_window = gprMax.TimeWindow(time=3e-9)
waveform = gprMax.Waveform(wave_type="gaussian", amp=1, freq=1e9, id="mypulse")
hertzian_dipole = gprMax.HertzianDipole(polarisation="z", p1=(0.050, 0.050, 0.050), waveform_id="mypulse")
hertzian_dipole = gprMax.HertzianDipole(
polarisation="z", p1=(0.050, 0.050, 0.050), waveform_id="mypulse"
)
rx = gprMax.Rx(p1=(0.070, 0.070, 0.070))
# PML cases

查看文件

@@ -31,7 +31,10 @@ tx_pos = (x / 2, y / 2, z / 2)
# Source excitation and type
wave = gprMax.Waveform(wave_type="gaussian", amp=1, freq=1.5e9, id="mypulse")
tl = gprMax.TransmissionLine(
p1=(tx_pos[0], tx_pos[1], tx_pos[2]), polarisation="x", resistance=50, waveform_id="mypulse"
p1=(tx_pos[0], tx_pos[1], tx_pos[2]),
polarisation="x",
resistance=50,
waveform_id="mypulse",
)
scene.add(wave)
scene.add(tl)
@@ -59,8 +62,16 @@ scene.add(t2)
# Detailed geometry view around bowtie and feed position
gv1 = gprMax.GeometryView(
p1=(tx_pos[0] - bowtie_dims[0] - 2 * dl, tx_pos[1] - bowtie_dims[1] / 2 - 2 * dl, tx_pos[2] - 2 * dl),
p2=(tx_pos[0] + bowtie_dims[0] + 2 * dl, tx_pos[1] + bowtie_dims[1] / 2 + 2 * dl, tx_pos[2] + 2 * dl),
p1=(
tx_pos[0] - bowtie_dims[0] - 2 * dl,
tx_pos[1] - bowtie_dims[1] / 2 - 2 * dl,
tx_pos[2] - 2 * dl,
),
p2=(
tx_pos[0] + bowtie_dims[0] + 2 * dl,
tx_pos[1] + bowtie_dims[1] / 2 + 2 * dl,
tx_pos[2] + 2 * dl,
),
dl=(dl, dl, dl),
filename="antenna_bowtie_fs_pcb",
output_type="f",

查看文件

@@ -32,11 +32,14 @@ logger = logging.getLogger(__name__)
# Parse command line arguments
parser = argparse.ArgumentParser(
description="Plots a comparison of fields between " + "given simulation output and experimental data files.",
description="Plots a comparison of fields between "
+ "given simulation output and experimental data files.",
usage="cd gprMax; python -m testing.test_experimental modelfile realfile output",
)
parser.add_argument("modelfile", help="name of model output file including path")
parser.add_argument("realfile", help="name of file containing experimental data including path")
parser.add_argument(
"realfile", help="name of file containing experimental data including path"
)
parser.add_argument("output", help="output to be plotted, i.e. Ex Ey Ez", nargs="+")
args = parser.parse_args()

查看文件

@@ -90,13 +90,19 @@ for i, model in enumerate(testmodels):
# Arrays for storing time
float_or_double = filetest[path + outputstest[0]].dtype
timetest = (
np.linspace(0, (filetest.attrs["Iterations"] - 1) * filetest.attrs["dt"], num=filetest.attrs["Iterations"])
np.linspace(
0,
(filetest.attrs["Iterations"] - 1) * filetest.attrs["dt"],
num=filetest.attrs["Iterations"],
)
/ 1e-9
)
timeref = timetest
# Arrays for storing field data
datatest = np.zeros((filetest.attrs["Iterations"], len(outputstest)), dtype=float_or_double)
datatest = np.zeros(
(filetest.attrs["Iterations"], len(outputstest)), dtype=float_or_double
)
for ID, name in enumerate(outputstest):
datatest[:, ID] = filetest[path + str(name)][:]
if np.any(np.isnan(datatest[:, ID])):
@@ -106,11 +112,18 @@ for i, model in enumerate(testmodels):
# Tx/Rx position to feed to analytical solution
rxpos = filetest[path].attrs["Position"]
txpos = filetest["/srcs/src1/"].attrs["Position"]
rxposrelative = ((rxpos[0] - txpos[0]), (rxpos[1] - txpos[1]), (rxpos[2] - txpos[2]))
rxposrelative = (
(rxpos[0] - txpos[0]),
(rxpos[1] - txpos[1]),
(rxpos[2] - txpos[2]),
)
# Analytical solution of a dipole in free space
dataref = hertzian_dipole_fs(
filetest.attrs["Iterations"], filetest.attrs["dt"], filetest.attrs["dx_dy_dz"], rxposrelative
filetest.attrs["Iterations"],
filetest.attrs["dt"],
filetest.attrs["dx_dy_dz"],
rxposrelative,
)
filetest.close()
@@ -143,18 +156,30 @@ for i, model in enumerate(testmodels):
# Arrays for storing time
timeref = np.zeros((fileref.attrs["Iterations"]), dtype=float_or_doubleref)
timeref = (
np.linspace(0, (fileref.attrs["Iterations"] - 1) * fileref.attrs["dt"], num=fileref.attrs["Iterations"])
np.linspace(
0,
(fileref.attrs["Iterations"] - 1) * fileref.attrs["dt"],
num=fileref.attrs["Iterations"],
)
/ 1e-9
)
timetest = np.zeros((filetest.attrs["Iterations"]), dtype=float_or_doubletest)
timetest = (
np.linspace(0, (filetest.attrs["Iterations"] - 1) * filetest.attrs["dt"], num=filetest.attrs["Iterations"])
np.linspace(
0,
(filetest.attrs["Iterations"] - 1) * filetest.attrs["dt"],
num=filetest.attrs["Iterations"],
)
/ 1e-9
)
# Arrays for storing field data
dataref = np.zeros((fileref.attrs["Iterations"], len(outputsref)), dtype=float_or_doubleref)
datatest = np.zeros((filetest.attrs["Iterations"], len(outputstest)), dtype=float_or_doubletest)
dataref = np.zeros(
(fileref.attrs["Iterations"], len(outputsref)), dtype=float_or_doubleref
)
datatest = np.zeros(
(filetest.attrs["Iterations"], len(outputstest)), dtype=float_or_doubletest
)
for ID, name in enumerate(outputsref):
dataref[:, ID] = fileref[path + str(name)][:]
datatest[:, ID] = filetest[path + str(name)][:]
@@ -170,7 +195,10 @@ for i, model in enumerate(testmodels):
for i in range(len(outputstest)):
maxi = np.amax(np.abs(dataref[:, i]))
datadiffs[:, i] = np.divide(
np.abs(dataref[:, i] - datatest[:, i]), maxi, out=np.zeros_like(dataref[:, i]), where=maxi != 0
np.abs(dataref[:, i] - datatest[:, i]),
maxi,
out=np.zeros_like(dataref[:, i]),
where=maxi != 0,
) # Replace any division by zero with zero
# Calculate power (ignore warning from taking a log of any zero values)
@@ -260,8 +288,20 @@ for i, model in enumerate(testmodels):
# bbox_inches='tight', pad_inches=0.1)
# fig2.savefig(savediffs.with_suffix('.pdf'), dpi=None, format='pdf',
# bbox_inches='tight', pad_inches=0.1)
fig1.savefig(file.with_suffix(".png"), dpi=150, format="png", bbox_inches="tight", pad_inches=0.1)
fig2.savefig(filediffs.with_suffix(".png"), dpi=150, format="png", bbox_inches="tight", pad_inches=0.1)
fig1.savefig(
file.with_suffix(".png"),
dpi=150,
format="png",
bbox_inches="tight",
pad_inches=0.1,
)
fig2.savefig(
filediffs.with_suffix(".png"),
dpi=150,
format="png",
bbox_inches="tight",
pad_inches=0.1,
)
# Summary of results
for name, data in sorted(testresults.items()):