@@ -362,3 +362,60 @@ def test_correct_values(dispersive):
362362
363363 assert np .isclose (si_n + pp_large_sampled , si_index_perturb_n )
364364 assert np .isclose (si_k + pp_small_sampled , si_index_perturb_k )
365+
366+
367+ @pytest .mark .parametrize ("unstructured" , [False , True ])
368+ def test_from_medium_field (unstructured ):
369+ """Test that super_medium field is properly set when calling perturbed_copy."""
370+ # Setup fields to sample at
371+ coords = {"x" : [1 , 2 ], "y" : [3 , 4 ], "z" : [5 , 6 ]}
372+ temperature = td .SpatialDataArray (300 * np .ones ((2 , 2 , 2 )), coords = coords )
373+ electron_density = td .SpatialDataArray (1e18 * np .ones ((2 , 2 , 2 )), coords = coords )
374+ hole_density = td .SpatialDataArray (2e18 * np .ones ((2 , 2 , 2 )), coords = coords )
375+
376+ if unstructured :
377+ temperature = cartesian_to_unstructured (temperature , seed = 7747 )
378+ electron_density = cartesian_to_unstructured (electron_density , seed = 7747 )
379+ hole_density = cartesian_to_unstructured (hole_density , seed = 7747 )
380+
381+ # Test PerturbationMedium
382+ pp_real = td .ParameterPerturbation (
383+ heat = td .LinearHeatPerturbation (
384+ coeff = - 0.01 ,
385+ temperature_ref = 300 ,
386+ temperature_range = (200 , 500 ),
387+ ),
388+ )
389+
390+ pmed = td .PerturbationMedium (permittivity = 10 , permittivity_perturbation = pp_real )
391+
392+ # Test without any perturbation data (returns Medium)
393+ cmed_no_perturb = pmed .perturbed_copy ()
394+ assert isinstance (cmed_no_perturb , td .Medium )
395+ assert cmed_no_perturb .super_medium is pmed
396+ assert hash (cmed_no_perturb .super_medium ) == hash (pmed )
397+
398+ # Test with perturbation data (returns CustomMedium)
399+ cmed_with_perturb = pmed .perturbed_copy (temperature , electron_density , hole_density )
400+ assert isinstance (cmed_with_perturb , td .CustomMedium )
401+ assert cmed_with_perturb .super_medium is pmed
402+ assert hash (cmed_with_perturb .super_medium ) == hash (pmed )
403+
404+ # Test PerturbationPoleResidue
405+ pmed_pole = td .PerturbationPoleResidue (
406+ eps_inf = 10 ,
407+ poles = [(1j , 3 ), (2j , 4 )],
408+ eps_inf_perturbation = pp_real ,
409+ )
410+
411+ # Test without any perturbation data (returns PoleResidue)
412+ cmed_pole_no_perturb = pmed_pole .perturbed_copy ()
413+ assert isinstance (cmed_pole_no_perturb , td .PoleResidue )
414+ assert cmed_pole_no_perturb .super_medium is pmed_pole
415+ assert hash (cmed_pole_no_perturb .super_medium ) == hash (pmed_pole )
416+
417+ # Test with perturbation data (returns CustomPoleResidue)
418+ cmed_pole_with_perturb = pmed_pole .perturbed_copy (temperature , electron_density , hole_density )
419+ assert isinstance (cmed_pole_with_perturb , td .CustomPoleResidue )
420+ assert cmed_pole_with_perturb .super_medium is pmed_pole
421+ assert hash (cmed_pole_with_perturb .super_medium ) == hash (pmed_pole )
0 commit comments