Skip to content

Commit

Permalink
Fix range of valid frequencies (NanoComp#335)
Browse files Browse the repository at this point in the history
* Fix range of valid frequencies

* Update warning text
  • Loading branch information
ChristopherHogan authored and stevengj committed May 18, 2018
1 parent ffe6329 commit 02ff65a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,19 @@ def _check_material_frequencies(self):
dft_freqs.append(dftf.freq_min)
dft_freqs.append(dftf.freq_min + dftf.Nfreq * dftf.dfreq)

warn_fmt = "{} frequency {} is out of material's range of {}-{}"
warn_src = ('Note: your sources include frequencies outside the range of validity of the ' +
'material models. This is fine as long as you eventually only look at outputs ' +
'(fluxes, resonant modes, etc.) at valid frequencies.')

warn_dft_fmt = "DFT frequency {} is out of material's range of {}-{}"

for sf in source_freqs:
if sf[0] + sf[1] > max_freq or sf[0] - sf[1] < min_freq:
warnings.warn(warn_fmt.format('source', sf, min_freq, max_freq), RuntimeWarning)
if sf[0] + 0.5 * sf[1] > max_freq or sf[0] - 0.5 * sf[1] < min_freq:
warnings.warn(warn_src, RuntimeWarning)

for dftf in dft_freqs:
if dftf > max_freq or dftf < min_freq:
warnings.warn(warn_fmt.format('DFT', dftf, min_freq, max_freq), RuntimeWarning)
warnings.warn(warn_dft_fmt.format(dftf, min_freq, max_freq), RuntimeWarning)

def _init_structure(self, k=False):
print('-' * 11)
Expand Down
2 changes: 1 addition & 1 deletion python/tests/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def check_warnings(sim, should_warn=True):

if should_warn:
self.assertEqual(len(w), 1)
self.assertIn("out of material's range", str(w[-1].message))
self.assertIn("material", str(w[-1].message))
else:
self.assertEqual(len(w), 0)

Expand Down

0 comments on commit 02ff65a

Please sign in to comment.