@@ -173,20 +173,37 @@ def _test_monitor_size():
173173 s .validate_contents ()
174174
175175
176- @pytest .mark .parametrize ("fwidth, log_level" , [(0.001 , None ), (3 , 30 )])
177- def test_sim_frequency_range (caplog , fwidth , log_level ):
178- # small fwidth should be inside range, large one should throw warning
176+ @pytest .mark .parametrize ("freq, log_level" , [(1.5 , 30 ), ( 2.5 , None ), (3.5 , 30 )])
177+ def test_monitor_medium_frequency_range (caplog , freq , log_level ):
178+ # monitor frequency above or below a given medium's range should throw a warning
179179
180180 size = (1 , 1 , 1 )
181181 medium = Medium (frequency_range = (2 , 3 ))
182182 box = Structure (geometry = Box (size = (0.1 , 0.1 , 0.1 )), medium = medium )
183+ mnt = FieldMonitor (size = (0 , 0 , 0 ), name = "freq" , freqs = [freq ])
183184 src = VolumeSource (
184- source_time = GaussianPulse (freq0 = 2.4 , fwidth = fwidth ),
185+ source_time = GaussianPulse (freq0 = 2.5 , fwidth = 0.5 ),
185186 size = (0 , 0 , 0 ),
186187 polarization = "Ex" ,
187188 )
188- _ = Simulation (size = (1 , 1 , 1 ), grid_size = (0.1 , 0.1 , 0.1 ), structures = [box ], sources = [src ])
189+ sim = Simulation (
190+ size = (1 , 1 , 1 ), grid_size = (0.1 , 0.1 , 0.1 ), structures = [box ], monitors = [mnt ], sources = [src ]
191+ )
192+ assert_log_level (caplog , log_level )
193+
189194
195+ @pytest .mark .parametrize ("fwidth, log_level" , [(0.1 , 30 ), (2 , None )])
196+ def test_monitor_simulation_frequency_range (caplog , fwidth , log_level ):
197+ # monitor frequency outside of the simulation's frequency range should throw a warning
198+
199+ size = (1 , 1 , 1 )
200+ src = VolumeSource (
201+ source_time = GaussianPulse (freq0 = 2.0 , fwidth = fwidth ),
202+ size = (0 , 0 , 0 ),
203+ polarization = "Ex" ,
204+ )
205+ mnt = FieldMonitor (size = (0 , 0 , 0 ), name = "freq" , freqs = [1.5 ])
206+ sim = Simulation (size = (1 , 1 , 1 ), grid_size = (0.1 , 0.1 , 0.1 ), monitors = [mnt ], sources = [src ])
190207 assert_log_level (caplog , log_level )
191208
192209
@@ -273,8 +290,13 @@ def test_sim_plane_wave_error():
273290def test_sim_structure_extent (caplog , box_size , log_level ):
274291 """Make sure we warn if structure extends exactly to simulation edges."""
275292
293+ src = VolumeSource (
294+ source_time = GaussianPulse (freq0 = 3e14 , fwidth = 1e13 ),
295+ size = (0 , 0 , 0 ),
296+ polarization = "Ex" ,
297+ )
276298 box = Structure (geometry = Box (size = box_size ), medium = Medium (permittivity = 2 ))
277- sim = Simulation (size = (1 , 1 , 1 ), grid_size = (0.1 , 0.1 , 0.1 ), structures = [box ])
299+ sim = Simulation (size = (1 , 1 , 1 ), grid_size = (0.1 , 0.1 , 0.1 ), structures = [box ], sources = [ src ] )
278300
279301 assert_log_level (caplog , log_level )
280302
@@ -449,6 +471,25 @@ def test_medium_dispersion_create():
449471 struct = Structure (geometry = Box (size = (1 , 1 , 1 )), medium = medium )
450472
451473
474+ def test_sellmeier_from_dispersion ():
475+ n = 3.5
476+ wvl = 0.5
477+ freq = C_0 / wvl
478+ dn_dwvl = - 0.1
479+ with pytest .raises (ValidationError ) as e :
480+ # Check that postivie dispersion raises an error
481+ medium = Sellmeier .from_dispersion (n = n , freq = freq , dn_dwvl = - dn_dwvl )
482+
483+ # Check that medium properties are as epected
484+ medium = Sellmeier .from_dispersion (n = n , freq = freq , dn_dwvl = dn_dwvl )
485+ epses = [medium .eps_model (f ) for f in [0.99 * freq , freq , 1.01 * freq ]]
486+ ns = np .sqrt (epses )
487+ dn_df = (ns [2 ] - ns [0 ]) / 0.02 / freq
488+
489+ assert np .allclose (ns [1 ], n )
490+ assert np .allclose (- dn_df * C_0 / wvl ** 2 , dn_dwvl )
491+
492+
452493def eps_compare (medium : Medium , expected : Dict , tol : float = 1e-5 ):
453494
454495 for freq , val in expected .items ():
@@ -479,15 +520,15 @@ def test_epsilon_eval():
479520 eps_compare (material , expected )
480521
481522 # Constant and eps, zero sigma
482- material = Medium (permittivity = 1.5 ** 2 )
523+ material = Medium (permittivity = 1.5 ** 2 )
483524 expected = {
484525 2e14 : 2.25 ,
485526 5e14 : 2.25 ,
486527 }
487528 eps_compare (material , expected )
488529
489530 # Constant eps and sigma
490- material = Medium (permittivity = 1.5 ** 2 , conductivity = 0.1 )
531+ material = Medium (permittivity = 1.5 ** 2 , conductivity = 0.1 )
491532 expected = {
492533 2e14 : 2.25 + 8.987552009401353j ,
493534 5e14 : 2.25 + 3.5950208037605416j ,
0 commit comments