Renamed some modules.

这个提交包含在:
Craig Warren
2017-02-21 12:57:42 +00:00
父节点 c51a501d05
当前提交 acc23f45ad
共有 4 个文件被更改,包括 394 次插入119 次删除

查看文件

@@ -0,0 +1,8 @@
#title: Magnetic dipole in free-space
#domain: 0.100 0.100 0.100
#dx_dy_dz: 0.001 0.001 0.001
#time_window: 3e-9
#waveform: gaussiandot 1 1e9 myWave
#magnetic_dipole: z 0.050 0.050 0.050 myWave
#rx: 0.070 0.070 0.070

查看文件

@@ -16,16 +16,13 @@
# You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import datetime
import os
import sys
from time import perf_counter
from colorama import init, Fore, Style
init()
import h5py
import numpy as np
np.seterr(divide='raise')
import matplotlib.pyplot as plt
if sys.platform == 'linux':
@@ -39,16 +36,21 @@ from tests.analytical_solutions import hertzian_dipole_fs
Usage:
cd gprMax
python -m tests.test_models_basic
python -m tests.test_models
"""
basepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'models_basic')
basepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'models_')
basepath += 'basic'
#basepath += 'advanced'
# List of available test models
testmodels = ['hertzian_dipole_fs_analytical', '2D_ExHyHz', '2D_EyHxHz', '2D_EzHxHy', 'cylinder_Ascan_2D', 'hertzian_dipole_fs', 'hertzian_dipole_hs', 'hertzian_dipole_dispersive']
# List of available basic test models
testmodels = ['hertzian_dipole_fs_analytical', '2D_ExHyHz', '2D_EyHxHz', '2D_EzHxHy', 'cylinder_Ascan_2D', 'hertzian_dipole_fs', 'hertzian_dipole_hs', 'hertzian_dipole_dispersive', 'magnetic_dipole_fs']
# List of available advanced test models
#testmodels = ['antenna_GSSI_1500_fs', 'antenna_MALA_1200_fs']
# Select a specific model if desired
#testmodels = [testmodels[0], testmodels[1], testmodels[2], testmodels[3], testmodels[4], testmodels[5]]
#testmodels = [testmodels[0], testmodels[5], testmodels[7]]
#testmodels = [testmodels[5]]
testresults = dict.fromkeys(testmodels)
path = '/rxs/rx1/'
@@ -56,8 +58,6 @@ path = '/rxs/rx1/'
# Minimum value of difference to plot (dB)
plotmin = -160
starttime = perf_counter()
for i, model in enumerate(testmodels):
testresults[model] = {}
@@ -96,10 +96,6 @@ for i, model in enumerate(testmodels):
dataref = hertzian_dipole_fs(filetest.attrs['Iterations'], filetest.attrs['dt'], filetest.attrs['dx, dy, dz'], rxposrelative)
filetest.close()
# Threshold below which test is considered passed (dB)
threshold = -35
testresults[model]['Threshold'] = threshold
else:
# Get output for model and reference files
@@ -116,25 +112,19 @@ for i, model in enumerate(testmodels):
# Check that type of float used to store fields matches
if filetest[path + outputstest[0]].dtype != fileref[path + outputsref[0]].dtype:
raise GeneralError('Type of floating point number does not match reference solution')
else:
floattype = fileref[path + outputsref[0]].dtype
print(Fore.RED + 'WARNING: Type of floating point number in test model ({}) does not match type in reference solution ({})\n'.format(filetest[path + outputstest[0]].dtype, fileref[path + outputsref[0]].dtype) + Style.RESET_ALL)
floattyperef = fileref[path + outputsref[0]].dtype
floattypetest = filetest[path + outputstest[0]].dtype
# Array for storing time
timeref = np.zeros((fileref.attrs['Iterations']), dtype=floattype)
timeref = np.zeros((fileref.attrs['Iterations']), dtype=floattyperef)
timeref = np.arange(0, fileref.attrs['dt'] * fileref.attrs['Iterations'], fileref.attrs['dt']) / 1e-9
timetest = np.zeros((filetest.attrs['Iterations']), dtype=floattype)
timetest = np.zeros((filetest.attrs['Iterations']), dtype=floattypetest)
timetest = np.arange(0, filetest.attrs['dt'] * filetest.attrs['Iterations'], filetest.attrs['dt']) / 1e-9
# Get available field output component names
outputsref = list(fileref[path].keys())
outputstest = list(filetest[path].keys())
if outputsref != outputstest:
raise GeneralError('Field output components do not match reference solution')
# Arrays for storing field data
dataref = np.zeros((fileref.attrs['Iterations'], len(outputsref)), dtype=floattype)
datatest = np.zeros((filetest.attrs['Iterations'], len(outputstest)), dtype=floattype)
dataref = np.zeros((fileref.attrs['Iterations'], len(outputsref)), dtype=floattyperef)
datatest = np.zeros((filetest.attrs['Iterations'], len(outputstest)), dtype=floattypetest)
for ID, name in enumerate(outputsref):
dataref[:, ID] = fileref[path + str(name)][:]
datatest[:, ID] = filetest[path + str(name)][:]
@@ -143,27 +133,17 @@ for i, model in enumerate(testmodels):
fileref.close()
filetest.close()
# Threshold below which test is considered passed (dB)
threshold = -120
testresults[model]['Threshold'] = threshold
# Diffs
datadiffs = np.zeros(datatest.shape, dtype=floattype)
datadiffs = np.zeros(datatest.shape, dtype=np.float64)
for i in range(len(outputstest)):
max = np.amax(np.abs(dataref[:, i]))
try:
datadiffs[:, i] = 20 * np.log10(((np.abs(dataref[:, i] - datatest[:, i])) / max))
# If a divide by zero error is encountered, consider the difference to be minimum plotted
except FloatingPointError:
datadiffs[:, i] = plotmin
datadiffs[:, i] = np.divide(np.abs(dataref[:, i] - datatest[:, i]), max, out=np.zeros_like(dataref[:, i]), where=max!=0) # Replace any division by zero with zero
with np.errstate(divide='ignore'):
datadiffs[:, i] = 20 * np.log10(datadiffs[:, i]) # Ignore any zero division in log10
# Register test passed/failed
# Store max difference
maxdiff = np.amax(np.amax(datadiffs))
if maxdiff <= threshold:
testresults[model]['Pass'] = True
else:
testresults[model]['Pass'] = False
testresults[model]['Max diff'] = maxdiff
# Plot datasets
@@ -199,7 +179,7 @@ for i, model in enumerate(testmodels):
for i, ax in enumerate(fig2.axes):
ax.set_ylabel(ylabels[i])
ax.set_xlim(0, np.amax(timetest))
ax.set_ylim([plotmin, 0])
ax.set_ylim([plotmin, np.amax(np.amax(datadiffs))])
ax.grid()
# Save a PDF/PNG of the figure
@@ -209,21 +189,9 @@ for i, model in enumerate(testmodels):
fig1.savefig(savename + '.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
fig2.savefig(savename + '_diffs.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1)
stoptime = perf_counter()
# Summary of results
passed = 0
for name, data in testresults.items():
for name, data in sorted(testresults.items()):
if 'analytical' in name:
if data['Pass']:
print(Fore.GREEN + "Test '{}.in' using v.{} compared to analytical solution passed. Max difference {:.2f}dB <= {:.2f}dB threshold".format(name, data['Test version'], data['Max diff'], data['Threshold']) + Style.RESET_ALL)
passed += 1
else:
print(Fore.RED + "Test '{}.in' using v.{} compared to analytical solution failed. Max difference {:.2f}dB <= {:.2f}dB threshold".format(name, data['Test version'], data['Max diff'], data['Threshold']) + Style.RESET_ALL)
print(Fore.CYAN + "Test '{}.in' using v.{} compared to analytical solution. Max difference {:.2f}dB.".format(name, data['Test version'], data['Max diff']) + Style.RESET_ALL)
else:
if data['Pass']:
print(Fore.GREEN + "Test '{}.in' using v.{} compared to reference solution using v.{} passed. Max difference {:.2f}dB <= {:.2f}dB threshold".format(name, data['Test version'], data['Ref version'], data['Max diff'], data['Threshold']) + Style.RESET_ALL)
passed += 1
else:
print(Fore.RED + "Test '{}.in' using v.{} compared to reference solution using v.{} failed. Max difference {:.2f}dB <= {:.2f}dB threshold".format(name, data['Test version'], data['Ref version'], data['Max diff'], data['Threshold']) + Style.RESET_ALL)
print('{} of {} tests passed successfully in [HH:MM:SS]: {}'.format(passed, len(testmodels), datetime.timedelta(seconds=int(stoptime - starttime))))
print(Fore.CYAN + "Test '{}.in' using v.{} compared to reference solution using v.{}. Max difference {:.2f}dB.".format(name, data['Test version'], data['Ref version'], data['Max diff']) + Style.RESET_ALL)