117
117
from .validators import (
118
118
assert_objects_contained_in_sim_bounds ,
119
119
assert_objects_in_sim_bounds ,
120
+ named_obj_descr ,
120
121
validate_mode_objects_symmetry ,
121
122
)
122
123
from .viz import (
@@ -2961,8 +2962,9 @@ def _validate_2d_geometry_has_2d_medium(cls, val, values):
2961
2962
for geom in flatten_groups (structure .geometry ):
2962
2963
zero_dims = geom .zero_dims
2963
2964
if len (zero_dims ) > 0 :
2965
+ obj_descr = named_obj_descr (structure , "structures" , i )
2964
2966
consolidated_logger .warning (
2965
- f"Structure at 'structures[ { i } ]' has geometry with zero size along "
2967
+ f"Structure: { obj_descr } has geometry with zero size along "
2966
2968
f"dimensions { zero_dims } , and with a medium that is not a 'Medium2D'. "
2967
2969
"This is probably not correct, since the resulting simulation will "
2968
2970
"depend on the details of the numerical grid. Consider either "
@@ -3018,10 +3020,11 @@ def _structures_not_close_pml(cls, val, values):
3018
3020
3019
3021
with log as consolidated_logger :
3020
3022
3021
- def warn (istruct , side ):
3023
+ def warn (structure , istruct , side ):
3022
3024
"""Warning message for a structure too close to PML."""
3025
+ obj_descr = named_obj_descr (structure , "structures" , istruct )
3023
3026
consolidated_logger .warning (
3024
- f"Structure at structures[ { istruct } ] was detected as being less "
3027
+ f"Structure: { obj_descr } was detected as being less "
3025
3028
f"than half of a central wavelength from a PML on side { side } . "
3026
3029
"To avoid inaccurate results or divergence, please increase gap between "
3027
3030
"any structures and PML or fully extend structure through the pml." ,
@@ -3044,7 +3047,7 @@ def warn(istruct, side):
3044
3047
and struct_val > sim_val
3045
3048
and abs (sim_val - struct_val ) < lambda0 / 2
3046
3049
):
3047
- warn (istruct , axis + "-min" )
3050
+ warn (structure , istruct , axis + "-min" )
3048
3051
3049
3052
zipped = zip (["x" , "y" , "z" ], sim_bound_max , struct_bound_max , boundaries )
3050
3053
for axis , sim_val , struct_val , boundary in zipped :
@@ -3056,7 +3059,7 @@ def warn(istruct, side):
3056
3059
and struct_val < sim_val
3057
3060
and abs (sim_val - struct_val ) < lambda0 / 2
3058
3061
):
3059
- warn (istruct , axis + "-max" )
3062
+ warn (structure , istruct , axis + "-max" )
3060
3063
3061
3064
return val
3062
3065
@@ -3095,20 +3098,20 @@ def _warn_monitor_mediums_frequency_range(cls, val, values):
3095
3098
medium_str = "The simulation background medium"
3096
3099
custom_loc = ["medium" , "frequency_range" ]
3097
3100
else :
3098
- medium_str = (
3099
- f"The medium associated with structures[{ medium_index - 1 } ]"
3100
- )
3101
+ medium_descr = named_obj_descr (medium , "mediums" , medium_index )
3102
+ medium_str = f"The medium associated with { medium_descr } "
3101
3103
custom_loc = [
3102
3104
"structures" ,
3103
3105
medium_index - 1 ,
3104
3106
"medium" ,
3105
3107
"frequency_range" ,
3106
3108
]
3107
3109
3110
+ monitor_descr = named_obj_descr (monitor , "monitors" , monitor_index )
3108
3111
consolidated_logger .warning (
3109
3112
f"{ medium_str } has a frequency range: ({ sci_fmin_med } , { sci_fmax_med } ) "
3110
- "(Hz) that does not fully cover the frequencies contained in "
3111
- f"monitors[ { monitor_index } ]. "
3113
+ "(Hz) that does not fully cover the frequencies contained "
3114
+ f"in { monitor_descr } . "
3112
3115
"This can cause inaccuracies in the recorded results." ,
3113
3116
custom_loc = custom_loc ,
3114
3117
)
@@ -3806,8 +3809,9 @@ def _validate_custom_source_time(self):
3806
3809
data_times = source .source_time .data_times
3807
3810
mint = np .min (data_times )
3808
3811
maxt = np .max (data_times )
3812
+ obj_descr = named_obj_descr (source , "sources" , idx )
3809
3813
log .warning (
3810
- f"'CustomSourceTime' at 'sources[ { idx } ]' is defined over a time range "
3814
+ f"'CustomSourceTime': { obj_descr } is defined over a time range "
3811
3815
f"'({ mint } , { maxt } )' which does not include any of the 'Simulation' "
3812
3816
f"times '({ 0 , run_time } )'. The envelope will be constant extrapolated "
3813
3817
"from the first or last value in the 'CustomSourceTime', which may not "
@@ -3837,8 +3841,9 @@ def _validate_no_structures_pml(self) -> None:
3837
3841
if not isinstance (bound_edge , Absorber ) and (in_pml_plus or in_pml_mnus ):
3838
3842
warn = True
3839
3843
if warn :
3844
+ obj_descr = named_obj_descr (structure , "structures" , i )
3840
3845
consolidated_logger .warning (
3841
- f"A bound of Simulation.structures[ { i } ] was detected as being "
3846
+ f"A bound of { obj_descr } was detected as being "
3842
3847
"within the simulation PML. We recommend extending structures to "
3843
3848
"infinity or completely outside of the simulation PML to avoid "
3844
3849
"unexpected effects when the structures are not translationally "
@@ -3956,8 +3961,9 @@ def _validate_nonlinear_specs(self) -> None:
3956
3961
if isinstance (monitor , AuxFieldTimeMonitor ):
3957
3962
for aux_field in monitor .fields :
3958
3963
if aux_field not in self .aux_fields :
3964
+ obj_descr = named_obj_descr (monitor , "monitors" , i )
3959
3965
log .warning (
3960
- f"Monitor at 'monitors[ { i } ]' stores field '{ aux_field } ', "
3966
+ f"Monitor: { obj_descr } stores field '{ aux_field } ', "
3961
3967
"which is not used by any of the nonlinear models present "
3962
3968
"in the mediums in the simulation. The resulting data "
3963
3969
"will be zero."
0 commit comments