这个提交包含在:
Craig Warren
2017-01-26 12:16:10 +00:00
当前提交 d4ceeb721a
共有 3 个文件被更改,包括 64 次插入66 次删除

查看文件

@@ -38,31 +38,29 @@ cpdef void update_electric(int nx, int ny, int nz, int nthreads, floattype_t[:,
cdef Py_ssize_t i, j, k cdef Py_ssize_t i, j, k
cdef int materialEx, materialEy, materialEz cdef int materialEx, materialEy, materialEz
# 2D # 2D - Ex component
if nx == 1 or ny == 1 or nz == 1: if nx == 1:
# Ex component for i in prange(0, nx, nogil=True, schedule='static', num_threads=nthreads):
if nx == 1: for j in range(1, ny):
for i in prange(0, nx, nogil=True, schedule='static', num_threads=nthreads): for k in range(1, nz):
for j in range(1, ny): materialEx = ID[0, i, j, k]
for k in range(1, nz): Ex[i, j, k] = updatecoeffsE[materialEx, 0] * Ex[i, j, k] + updatecoeffsE[materialEx, 2] * (Hz[i, j, k] - Hz[i, j - 1, k]) - updatecoeffsE[materialEx, 3] * (Hy[i, j, k] - Hy[i, j, k - 1])
materialEx = ID[0, i, j, k]
Ex[i, j, k] = updatecoeffsE[materialEx, 0] * Ex[i, j, k] + updatecoeffsE[materialEx, 2] * (Hz[i, j, k] - Hz[i, j - 1, k]) - updatecoeffsE[materialEx, 3] * (Hy[i, j, k] - Hy[i, j, k - 1])
# Ey component # 2D - Ey component
if ny == 1: elif ny == 1:
for i in prange(1, nx, nogil=True, schedule='static', num_threads=nthreads): for i in prange(1, nx, nogil=True, schedule='static', num_threads=nthreads):
for j in range(0, ny): for j in range(0, ny):
for k in range(1, nz): for k in range(1, nz):
materialEy = ID[1, i, j, k] materialEy = ID[1, i, j, k]
Ey[i, j, k] = updatecoeffsE[materialEy, 0] * Ey[i, j, k] + updatecoeffsE[materialEy, 3] * (Hx[i, j, k] - Hx[i, j, k - 1]) - updatecoeffsE[materialEy, 1] * (Hz[i, j, k] - Hz[i - 1, j, k]) Ey[i, j, k] = updatecoeffsE[materialEy, 0] * Ey[i, j, k] + updatecoeffsE[materialEy, 3] * (Hx[i, j, k] - Hx[i, j, k - 1]) - updatecoeffsE[materialEy, 1] * (Hz[i, j, k] - Hz[i - 1, j, k])
# Ez component # 2D - Ez component
if nz == 1: elif nz == 1:
for i in prange(1, nx, nogil=True, schedule='static', num_threads=nthreads): for i in prange(1, nx, nogil=True, schedule='static', num_threads=nthreads):
for j in range(1, ny): for j in range(1, ny):
for k in range(0, nz): for k in range(0, nz):
materialEz = ID[2, i, j, k] materialEz = ID[2, i, j, k]
Ez[i, j, k] = updatecoeffsE[materialEz, 0] * Ez[i, j, k] + updatecoeffsE[materialEz, 1] * (Hy[i, j, k] - Hy[i - 1, j, k]) - updatecoeffsE[materialEz, 2] * (Hx[i, j, k] - Hx[i, j - 1, k]) Ez[i, j, k] = updatecoeffsE[materialEz, 0] * Ez[i, j, k] + updatecoeffsE[materialEz, 1] * (Hy[i, j, k] - Hy[i - 1, j, k]) - updatecoeffsE[materialEz, 2] * (Hx[i, j, k] - Hx[i, j - 1, k])
# 3D # 3D
else: else:

查看文件

@@ -35,7 +35,7 @@ cpdef void update_pml_1order_electric_xminus(int xs, int xf, int ys, int yf, int
updatecoeffs, ID, E, H (memoryviews): Access to update coeffients, ID and field component arrays updatecoeffs, ID, E, H (memoryviews): Access to update coeffients, ID and field component arrays
EPhi, HPhi, ERA, ERB, ERE, ERF (memoryviews): Access to PML coefficient arrays EPhi, HPhi, ERA, ERB, ERE, ERF (memoryviews): Access to PML coefficient arrays
d (float): Spatial discretisation, e.g. dx, dy or dz d (float): Spatial discretisation, e.g. dx, dy or dz
""" """
cdef Py_ssize_t i, j, k, ii, jj, kk cdef Py_ssize_t i, j, k, ii, jj, kk
cdef int nx, ny, nz, materialEy, materialEz cdef int nx, ny, nz, materialEy, materialEz

查看文件

@@ -27,62 +27,62 @@ import matplotlib.pyplot as plt
Usage: Usage:
cd gprMax cd gprMax
python -m tests.test_compare_numerical path_to_new_file path_to_old_file python -m tests.test_compare_numerical path_to_file1 path_to_file2
""" """
newfile = sys.argv[1] filename1 = sys.argv[1]
oldfile = sys.argv[2] filename2 = sys.argv[2]
path = '/rxs/rx1/' path = '/rxs/rx1/'
# Key refers to subplot location # Key refers to subplot location
fields = {0: 'Ex', 2: 'Ey', 4: 'Ez', 1: 'Hx', 3: 'Hy', 5: 'Hz'} fields = {0: 'Ex', 2: 'Ey', 4: 'Ez', 1: 'Hx', 3: 'Hy', 5: 'Hz'}
plotorder = list(fields.keys()) plotorder = list(fields.keys())
# New results # File 1 results
f = h5py.File(newfile, 'r') f = h5py.File(filename1, 'r')
floattype = f[path + 'Ex'].dtype floattype = f[path + 'Ex'].dtype
new = np.zeros((f.attrs['Iterations'], 6), dtype=floattype) data1 = np.zeros((f.attrs['Iterations'], 6), dtype=floattype)
timenew = np.zeros((f.attrs['Iterations']), dtype=floattype) time1 = np.zeros((f.attrs['Iterations']), dtype=floattype)
timenew = np.arange(0, f.attrs['dt'] * f.attrs['Iterations'], f.attrs['dt']) / 1e-9 time1 = np.arange(0, f.attrs['dt'] * f.attrs['Iterations'], f.attrs['dt']) / 1e-9
for ID, name in fields.items(): for ID, name in fields.items():
new[:,ID] = f[path + str(name)][:] data1[:,ID] = f[path + str(name)][:]
f.close() f.close()
# Old results # File 2 results
f = h5py.File(oldfile, 'r') f = h5py.File(filename2, 'r')
old = np.zeros((f.attrs['Iterations'], 6), dtype=floattype) data2 = np.zeros((f.attrs['Iterations'], 6), dtype=floattype)
timeold = np.zeros((f.attrs['Iterations']), dtype=floattype) time2 = np.zeros((f.attrs['Iterations']), dtype=floattype)
timeold = np.arange(0, f.attrs['dt'] * f.attrs['Iterations'], f.attrs['dt']) / 1e-9 time2 = np.arange(0, f.attrs['dt'] * f.attrs['Iterations'], f.attrs['dt']) / 1e-9
for ID, name in fields.items(): for ID, name in fields.items():
old[:,ID] = f[path + str(name)][:] data2[:,ID] = f[path + str(name)][:]
f.close() f.close()
# Differences # Differences
# In case there is any difference in the number of iterations, take the smaller # In case there is any difference in the number of iterations, take the smaller
timesmallest = np.amin((timeold.shape, timenew.shape)) timesmallest = np.amin((time2.shape, time1.shape))
fieldssmallest = np.amin((old.shape[0], new.shape[0])) fieldssmallest = np.amin((data2.shape[0], data1.shape[0]))
threshold = 1e-4 # Threshold, below which ignore differences threshold = 1e-4 # Threshold, below which ignore differences
diffs = np.zeros((fieldssmallest, 6), dtype=floattype) diffs = np.zeros((fieldssmallest, 6), dtype=floattype)
for ID, name in fields.items(): for ID, name in fields.items():
max = np.amax(np.abs(new[:fieldssmallest,ID])) max = np.amax(np.abs(data1[:fieldssmallest,ID]))
if max < threshold: if max < threshold:
diffs[:,ID] = 0 diffs[:,ID] = 0
diffsum = 0 diffsum = 0
print('Detected differences of less than {} when comparing {} field component, therefore set as zero.'.format(threshold, fields[ID])) print('Detected differences of less than {} when comparing {} field component, therefore set as zero.'.format(threshold, fields[ID]))
else: else:
diffs[:,ID] = (np.abs(new[:fieldssmallest,ID] - old[:fieldssmallest,ID]) / max) * 100 diffs[:,ID] = (np.abs(data1[:fieldssmallest,ID] - data2[:fieldssmallest,ID]) / max) * 100
diffsum = (np.sum(np.abs(new[:fieldssmallest,ID] - old[:fieldssmallest,ID])) / np.sum(np.abs(new[:fieldssmallest,ID]))) * 100 diffsum = (np.sum(np.abs(data1[:fieldssmallest,ID] - data2[:fieldssmallest,ID])) / np.sum(np.abs(data1[:fieldssmallest,ID]))) * 100
print('Total differences in field component {}: {:.1f}%'.format(name, diffsum)) print('Total differences in field component {}: {:.1f}%'.format(name, diffsum))
# Plot new # Plot data1
fig1, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num=newfile + ' versus ' + oldfile, figsize=(20, 10), facecolor='w', edgecolor='w') fig1, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num=filename1 + ' versus ' + filename2, figsize=(20, 10), facecolor='w', edgecolor='w')
ax1.plot(timenew, new[:,0],'r', lw=2, label='Ex') ax1.plot(time1, data1[:,0],'r', lw=2, label='Ex')
ax3.plot(timenew, new[:,2],'r', lw=2, label='Ey') ax3.plot(time1, data1[:,2],'r', lw=2, label='Ey')
ax5.plot(timenew, new[:,4],'r', lw=2, label='Ez') ax5.plot(time1, data1[:,4],'r', lw=2, label='Ez')
ax2.plot(timenew, new[:,1],'b', lw=2, label='Hx') ax2.plot(time1, data1[:,1],'b', lw=2, label='Hx')
ax4.plot(timenew, new[:,3],'b', lw=2, label='Hy') ax4.plot(time1, data1[:,3],'b', lw=2, label='Hy')
ax6.plot(timenew, new[:,5],'b', lw=2, label='Hz') ax6.plot(time1, data1[:,5],'b', lw=2, label='Hz')
# Set ylabels # Set ylabels
ylabels = ['$E_x$, field strength [V/m]', '$H_x$, field strength [A/m]', '$E_y$, field strength [V/m]', '$H_y$, field strength [A/m]', '$E_z$, field strength [V/m]', '$H_z$, field strength [A/m]'] ylabels = ['$E_x$, field strength [V/m]', '$H_x$, field strength [A/m]', '$E_y$, field strength [V/m]', '$H_y$, field strength [A/m]', '$E_z$, field strength [V/m]', '$H_z$, field strength [A/m]']
@@ -91,24 +91,24 @@ ylabels = ['$E_x$, field strength [V/m]', '$H_x$, field strength [A/m]', '$E_y$,
# Turn on grid # Turn on grid
[ax.grid() for ax in fig1.axes] [ax.grid() for ax in fig1.axes]
# Add old and set legend # Add data2 and set legend
for index, ax in enumerate(fig1.axes): for index, ax in enumerate(fig1.axes):
if plotorder[index] in [0, 2, 4]: if plotorder[index] in [0, 2, 4]:
ax.plot(timeold, old[:,plotorder[index]], 'r', label='old', lw=2, ls='--') ax.plot(time2, data2[:,plotorder[index]], 'r', label='data2', lw=2, ls='--')
else: else:
ax.plot(timeold, old[:,plotorder[index]], label='old', lw=2, ls='--') ax.plot(time2, data2[:,plotorder[index]], label='data2', lw=2, ls='--')
ax.set_xlim(0, timeold[-1]) ax.set_xlim(0, time2[-1])
handles, existlabels = ax.get_legend_handles_labels() handles, existlabels = ax.get_legend_handles_labels()
ax.legend(handles, ['Model 1', 'Model 2']) ax.legend(handles, [os.path.split(filename1)[1], os.path.split(filename2)[1]])
# Plots of differences # Plots of differences
fig2, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num='Deltas: ' + newfile + ' versus ' + oldfile, figsize=(20, 10), facecolor='w', edgecolor='w') fig2, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(nrows=3, ncols=2, sharex=False, sharey='col', subplot_kw=dict(xlabel='Time [ns]'), num='Deltas: ' + filename1 + ' versus ' + filename2, figsize=(20, 10), facecolor='w', edgecolor='w')
ax1.plot(timenew[:timesmallest], diffs[:,0],'r', lw=2, label='Ex') ax1.plot(time1[:timesmallest], diffs[:,0],'r', lw=2, label='Ex')
ax3.plot(timenew[:timesmallest], diffs[:,2],'r', lw=2, label='Ey') ax3.plot(time1[:timesmallest], diffs[:,2],'r', lw=2, label='Ey')
ax5.plot(timenew[:timesmallest], diffs[:,4],'r', lw=2, label='Ez') ax5.plot(time1[:timesmallest], diffs[:,4],'r', lw=2, label='Ez')
ax2.plot(timenew[:timesmallest], diffs[:,1],'b', lw=2, label='Hx') ax2.plot(time1[:timesmallest], diffs[:,1],'b', lw=2, label='Hx')
ax4.plot(timenew[:timesmallest], diffs[:,3],'b', lw=2, label='Hy') ax4.plot(time1[:timesmallest], diffs[:,3],'b', lw=2, label='Hy')
ax6.plot(timenew[:timesmallest], diffs[:,5],'b', lw=2, label='Hz') ax6.plot(time1[:timesmallest], diffs[:,5],'b', lw=2, label='Hz')
# Set ylabels # Set ylabels
ylabels = ['$E_x$', '$H_x$', '$E_y$', '$H_y$', '$E_z$', '$H_z$'] ylabels = ['$E_x$', '$H_x$', '$E_y$', '$H_y$', '$E_z$', '$H_z$']
@@ -117,11 +117,11 @@ ylabels = [ylabel + ', percentage difference [%]' for ylabel in ylabels]
# Set axes limits and turn on grid # Set axes limits and turn on grid
[ax.grid() for ax in fig2.axes] [ax.grid() for ax in fig2.axes]
[ax.set_xlim(0, timenew[timesmallest - 1]) for ax in fig2.axes] [ax.set_xlim(0, time1[timesmallest - 1]) for ax in fig2.axes]
[ax.set_ylim(0, np.ceil(np.amax(np.abs(diffs)))) for ax in fig2.axes] [ax.set_ylim(0, np.ceil(np.amax(np.abs(diffs)))) for ax in fig2.axes]
# Show/print plots # Show/print plots
savename = os.path.abspath(os.path.dirname(newfile)) + os.sep + os.path.splitext(os.path.split(newfile)[1])[0] + '_vs_' + os.path.splitext(os.path.split(oldfile)[1])[0] savename = os.path.abspath(os.path.dirname(filename1)) + os.sep + os.path.splitext(os.path.split(filename1)[1])[0] + '_vs_' + os.path.splitext(os.path.split(filename2)[1])[0]
#fig1.savefig(savename + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) #fig1.savefig(savename + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
#fig2.savefig(savename + '_diffs.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) #fig2.savefig(savename + '_diffs.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1)
plt.show() plt.show()