diff --git a/gprMax/grid.py b/gprMax/grid.py index 4b7d792e..964d10ad 100644 --- a/gprMax/grid.py +++ b/gprMax/grid.py @@ -164,15 +164,14 @@ def dispersion_analysis(G): results (dict): Results from dispersion analysis """ - # Physical phase velocity error (percentage); grid sampling density; material with maximum permittivity; maximum frequency of interest - results = {'deltavp': False, 'N': False, 'material': False, 'maxfreq': False} + # Physical phase velocity error (percentage); grid sampling density; material with maximum permittivity; maximum significant frequency + results = {'deltavp': False, 'N': False, 'material': False, 'maxfreq': []} - # Find maximum frequency - maxfreqs = [] + # Find maximum significant frequency for waveform in G.waveforms: if waveform.type == 'sine' or waveform.type == 'contsine': - maxfreqs.append(4 * waveform.freq) + results['maxfreq'].append(4 * waveform.freq) elif waveform.type == 'impulse': pass @@ -207,13 +206,13 @@ def dispersion_analysis(G): # Set maximum frequency to a threshold drop from maximum power, ignoring DC value freq = np.where((np.amax(power[freqmaxpower::]) - power[freqmaxpower::]) > G.highestfreqthres)[0][0] + 1 - maxfreqs.append(freqs[freq]) + results['maxfreq'].append(freqs[freq]) else: - print(Fore.RED + "\nWARNING: Duration of source waveform '{}' means it does not fit within specified time window and is therefore being truncated.".format(waveform.ID) + Style.RESET_ALL) + results['waveformID'] = waveform.ID - if maxfreqs: - results['maxfreq'] = max(maxfreqs) + if results['maxfreq']: + results['maxfreq'] = max(results['maxfreq']) # Find minimum wavelength (material with maximum permittivity) maxer = 0 diff --git a/gprMax/model_build_run.py b/gprMax/model_build_run.py index b423de50..c5b66285 100644 --- a/gprMax/model_build_run.py +++ b/gprMax/model_build_run.py @@ -173,9 +173,11 @@ def run_model(args, currentmodelrun, numbermodelruns, inputfile, usernamespace): # Check to see if numerical dispersion might be a problem results = dispersion_analysis(G) - if results['N'] < G.mingridsampling: + if 'waveformID' in results: + print(Fore.RED + "\nWARNING: Numerical dispersion analysis not carried out as duration of waveform '{}' means it does not fit within specified time window and is therefore being truncated.".format(results['waveformID']) + Style.RESET_ALL) + elif results['N'] < G.mingridsampling: raise GeneralError("Non-physical wave propagation: Material '{}' has wavelength sampled by {} cells, less than required minimum for physical wave propagation. Maximum significant frequency estimated as {:g}Hz".format(results['material'].ID, results['N'], results['maxfreq'])) - elif results['deltavp'] and np.abs(results['deltavp']) > G.maxnumericaldisp and G.messages: + elif results['deltavp'] and np.abs(results['deltavp']) > G.maxnumericaldisp: print(Fore.RED + "\nWARNING: Potentially significant numerical dispersion. Estimated largest physical phase-velocity error is {:.2f}% in material '{}' whose wavelength sampled by {} cells. Maximum significant frequency estimated as {:g}Hz".format(results['deltavp'], results['material'].ID, results['N'], results['maxfreq']) + Style.RESET_ALL) elif results['deltavp'] and G.messages: print("\nNumerical dispersion analysis: estimated largest physical phase-velocity error is {:.2f}% in material '{}' whose wavelength sampled by {} cells. Maximum significant frequency estimated as {:g}Hz".format(results['deltavp'], results['material'].ID, results['N'], results['maxfreq']))