@@ -906,6 +906,17 @@ def field_data(self) -> td.FieldData:
906
906
)
907
907
return self .simdata (monitor )["fields" ]
908
908
909
+ @pytest .fixture (scope = "class" )
910
+ def field_data_single_frequency (self ) -> td .FieldData :
911
+ """Make random field data with single frequency from an emulated simulation run."""
912
+ monitor = td .FieldMonitor (
913
+ size = (td .inf , td .inf , 0 ),
914
+ freqs = self .freqs [0 ],
915
+ name = "fields" ,
916
+ colocate = True ,
917
+ )
918
+ return self .simdata (monitor )["fields" ]
919
+
909
920
@pytest .fixture (scope = "class" )
910
921
def mode_data (self ) -> td .ModeData :
911
922
"""Make random ModeData from an emulated simulation run."""
@@ -919,18 +930,41 @@ def mode_data(self) -> td.ModeData:
919
930
)
920
931
return self .simdata (monitor )["modes" ]
921
932
933
+ @pytest .fixture (scope = "class" )
934
+ def mode_data_single_frequency (self ) -> td .ModeData :
935
+ """Make random ModeData from an emulated simulation run."""
936
+ monitor = td .ModeMonitor (
937
+ size = (td .inf , td .inf , 0 ),
938
+ freqs = self .freqs [0 ],
939
+ name = "modes" ,
940
+ colocate = True ,
941
+ mode_spec = td .ModeSpec (num_modes = 2 , target_neff = 4.0 ),
942
+ store_fields_direction = "+" ,
943
+ )
944
+ return self .simdata (monitor )["modes" ]
945
+
946
+ @pytest .mark .parametrize ("field_data_fixture" , ["field_data" , "field_data_single_frequency" ])
922
947
@pytest .mark .parametrize ("background_index" , [1 , 2 , 3 ])
923
948
@pytest .mark .parametrize ("freq" , [* list (freqs ), None ])
924
949
@pytest .mark .parametrize ("n_x" , [2 ** 5 , 2 ** 6 ])
925
950
@pytest .mark .parametrize ("n_y" , [2 ** 5 , 2 ** 6 ])
926
951
@pytest .mark .parametrize ("units" , ["mm" , "cm" , "in" , "m" ])
927
952
def test_fielddata_tozbf_readzbf (
928
- self , tmp_path , field_data , background_index , freq , n_x , n_y , units
953
+ self ,
954
+ tmp_path ,
955
+ request ,
956
+ field_data_fixture ,
957
+ background_index ,
958
+ freq ,
959
+ n_x ,
960
+ n_y ,
961
+ units ,
929
962
):
930
963
"""Test that FieldData.to_zbf() -> ZBFData.read_zbf() works"""
931
964
zbf_filename = tmp_path / "testzbf.zbf"
932
965
933
966
# write to zbf and then load it back in
967
+ field_data = request .getfixturevalue (field_data_fixture )
934
968
ex , ey = field_data .to_zbf (
935
969
fname = zbf_filename ,
936
970
background_refractive_index = background_index ,
@@ -960,13 +994,20 @@ def test_fielddata_tozbf_readzbf(
960
994
assert np .allclose (ex .values , zbfdata .Ex )
961
995
assert np .allclose (ey .values , zbfdata .Ey )
962
996
997
+ @pytest .mark .parametrize ("mode_data_fixture" , ["mode_data" , "mode_data_single_frequency" ])
963
998
@pytest .mark .parametrize ("mode_index" , [0 , 1 ])
964
- def test_tozbf_modedata (self , tmp_path , mode_data , mode_index ):
999
+ def test_tozbf_modedata (
1000
+ self ,
1001
+ tmp_path ,
1002
+ request ,
1003
+ mode_data_fixture ,
1004
+ mode_index ,
1005
+ ):
965
1006
"""Tests ModeData.to_zbf()"""
966
1007
zbf_filename = tmp_path / "testzbf_modedata.zbf"
967
1008
968
1009
# write to zbf and then load it back in
969
- ex , ey = mode_data .to_zbf (
1010
+ ex , ey = request . getfixturevalue ( mode_data_fixture ) .to_zbf (
970
1011
fname = zbf_filename ,
971
1012
background_refractive_index = 1 ,
972
1013
freq = self .freq0 ,
0 commit comments